shithub: riscv

Download patch

ref: 59d4a6261f42044f3c6ba340fc9844524afa1983
parent: f0ac2d01765f938a4f3656efef440cf2c1bca69d
author: cinap_lenrek <[email protected]>
date: Mon Jan 1 16:14:28 EST 2024

ip/dhcpd: don't override local address for gateway case

--- a/sys/src/cmd/ip/dhcpd/dhcpd.c
+++ b/sys/src/cmd/ip/dhcpd/dhcpd.c
@@ -726,20 +726,21 @@
 	bp = rp->bp;
 	up = rp->up;
 
-	localip(up->laddr, ip, rp->ifc);
-
 	flags = nhgets(bp->flags);
 	if(validip(rp->giaddr)){
 		ipmove(up->raddr, rp->giaddr);
 		hnputs(up->rport, 67);
-	} else if(flags & Fbroadcast){
-		ipmove(up->raddr, IPv4bcast);
-		hnputs(up->rport, 68);
 	} else {
-		ipmove(up->raddr, ip);
-		if(bp->htype == 1)
-			arpenter(up->raddr, bp->chaddr, up->laddr);
-		hnputs(up->rport, 68);
+		localip(up->laddr, ip, rp->ifc);
+		if(flags & Fbroadcast){
+			ipmove(up->raddr, IPv4bcast);
+			hnputs(up->rport, 68);
+		} else {
+			ipmove(up->raddr, ip);
+			if(bp->htype == 1)
+				arpenter(up->raddr, bp->chaddr, up->laddr);
+			hnputs(up->rport, 68);
+		}
 	}
 
 	/*
@@ -785,20 +786,21 @@
 	bp = rp->bp;
 	up = rp->up;
 
-	localip(up->laddr, ip, rp->ifc);
-
 	flags = nhgets(bp->flags);
 	if(validip(rp->giaddr)){
 		ipmove(up->raddr, rp->giaddr);
 		hnputs(up->rport, 67);
-	} else if(flags & Fbroadcast){
-		ipmove(up->raddr, IPv4bcast);
-		hnputs(up->rport, 68);
 	} else {
-		ipmove(up->raddr, ip);
-		if(bp->htype == 1)
-			arpenter(up->raddr, bp->chaddr, up->laddr);
-		hnputs(up->rport, 68);
+		localip(up->laddr, ip, rp->ifc);
+		if(flags & Fbroadcast){
+			ipmove(up->raddr, IPv4bcast);
+			hnputs(up->rport, 68);
+		} else {
+			ipmove(up->raddr, ip);
+			if(bp->htype == 1)
+				arpenter(up->raddr, bp->chaddr, up->laddr);
+			hnputs(up->rport, 68);
+		}
 	}
 
 	/*
@@ -844,8 +846,6 @@
 	bp = rp->bp;
 	up = rp->up;
 
-	localip(up->laddr, ip, rp->ifc);
-
 	/*
 	 *  set destination (always broadcast)
 	 */
@@ -853,6 +853,7 @@
 		ipmove(up->raddr, rp->giaddr);
 		hnputs(up->rport, 67);
 	} else {
+		localip(up->laddr, ip, rp->ifc);
 		ipmove(up->raddr, IPv4bcast);
 		hnputs(up->rport, 68);
 	}
@@ -973,20 +974,21 @@
 		rp->p += 128-4;
 	}
 
-	localip(up->laddr, iip->ipaddr, iip->ifc);
-
 	flags = nhgets(bp->flags);
 	if(validip(rp->giaddr)){
 		ipmove(up->raddr, rp->giaddr);
 		hnputs(up->rport, 67);
-	} else if(flags & Fbroadcast){
-		ipmove(up->raddr, IPv4bcast);
-		hnputs(up->rport, 68);
 	} else {
-		v4tov6(up->raddr, bp->yiaddr);
-		if(bp->htype == 1)
-			arpenter(up->raddr, bp->chaddr, up->laddr);
-		hnputs(up->rport, 68);
+		localip(up->laddr, iip->ipaddr, rp->ifc);
+		if(flags & Fbroadcast){
+			ipmove(up->raddr, IPv4bcast);
+			hnputs(up->rport, 68);
+		} else {
+			v4tov6(up->raddr, bp->yiaddr);
+			if(bp->htype == 1)
+				arpenter(up->raddr, bp->chaddr, up->laddr);
+			hnputs(up->rport, 68);
+		}
 	}
 
 	/*