ref: 5a2c3580fc1b0ca53deb62c1b3e0391ce3895dd8
parent: 4e61bc282c2869ae8442e356ffd2da3a3818dd51
author: cinap_lenrek <[email protected]>
date: Sat Sep 1 11:08:40 EDT 2018
ip/dhcpd: bring back interface address for arpenter() the arp table is per interface, so it is possible to have the same netwrok on multiple physical interfaces, tho with different source ip address. one example would be a ethernet and a wlan interface. the mac addresses on these mediums can differ (arp proxying taking place). so provide our source address on the interface we received the request on. the previous change used the ifcaddr; which is correct; but due to a oversight in the kernel, had to match the ip of the arp entry. source address will always work.
--- a/sys/src/cmd/ip/dhcpd/dhcpd.c
+++ b/sys/src/cmd/ip/dhcpd/dhcpd.c
@@ -165,7 +165,7 @@
void addropt(Req*, int, uchar*);
void addrsopt(Req*, int, uchar**, int);
-void arpenter(uchar*, uchar*);
+void arpenter(uchar*, uchar*, uchar*);
void bootp(Req*);
void byteopt(Req*, int, uchar);
void dhcp(Req*);
@@ -746,7 +746,7 @@
} else {
ipmove(up->raddr, ip);
if(bp->htype == 1)
- arpenter(up->raddr, bp->chaddr);
+ arpenter(up->raddr, bp->chaddr, up->laddr);
hnputs(up->rport, 68);
}
@@ -805,7 +805,7 @@
} else {
ipmove(up->raddr, ip);
if(bp->htype == 1)
- arpenter(up->raddr, bp->chaddr);
+ arpenter(up->raddr, bp->chaddr, up->laddr);
hnputs(up->rport, 68);
}
@@ -993,7 +993,7 @@
} else {
v4tov6(up->raddr, bp->yiaddr);
if(bp->htype == 1)
- arpenter(up->raddr, bp->chaddr);
+ arpenter(up->raddr, bp->chaddr, up->laddr);
hnputs(up->rport, 68);
}
@@ -1576,19 +1576,20 @@
}
void
-arpenter(uchar *ip, uchar *ether)
+arpenter(uchar *ip, uchar *mac, uchar *src)
{
- int f;
char buf[256];
+ int fd, n;
- sprint(buf, "%s/arp", net);
- f = open(buf, OWRITE);
- if(f < 0){
- syslog(debug, blog, "open %s: %r", buf);
+ snprint(buf, sizeof buf, "%s/arp", net);
+ if((fd = open(buf, OWRITE)) < 0){
+ warning("couldn't open %s: %r", buf);
return;
}
- fprint(f, "add ether %I %E", ip, ether);
- close(f);
+ n = snprint(buf, sizeof buf, "add ether %I %E %I\n", ip, mac, src);
+ if(write(fd, buf, n) != n)
+ warning("arpenter: %s: %r", buf);
+ close(fd);
}
char *dhcpmsgname[] =