]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
We need to flush the ARP table after configuring new routes.
authorRoy Marples <roy@marples.name>
Mon, 15 Sep 2008 19:15:52 +0000 (19:15 +0000)
committerRoy Marples <roy@marples.name>
Mon, 15 Sep 2008 19:15:52 +0000 (19:15 +0000)
configure.c
if-bsd.c
if-linux.c
net.h

index cfcd6e4e31588c7238069f72aaa957f468c4cd73..1dadc1864d6c877758c1cd2c99f7686bff7a060b 100644 (file)
@@ -510,6 +510,8 @@ configure(struct interface *iface, const char *reason)
        iface->addr.s_addr = addr.s_addr;
        iface->net.s_addr = net.s_addr;
        build_routes();
+       if (arp_flush() == -1)
+               syslog(LOG_ERR, "arp_flush: %m");
        if (!iface->state->lease.frominfo)
                if (write_lease(iface, dhcp) == -1)
                        syslog(LOG_ERR, "write_lease: %m");
index 6da4dd2b968cdf55cd690d131c87336068a3773c..576e6f42d5376dd527fc71c7f26a91fb453320d7 100644 (file)
--- a/if-bsd.c
+++ b/if-bsd.c
  * SUCH DAMAGE.
  */
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/sysctl.h>
+#include <sys/types.h>
 
 #include <arpa/inet.h>
 #include <net/if_dl.h>
@@ -187,6 +188,44 @@ if_route(const struct interface *iface, const struct in_addr *dest,
        return retval;
 }
 
+int
+arp_flush(void)
+{
+       int s, mib[6], retval = 0;
+       size_t buffer_len = 0;
+       char *buffer, *e, *p;
+       struct rt_msghdr *rtm;
+
+       if ((s = socket(PF_ROUTE, SOCK_RAW, 0)) == -1)
+               return -1;
+       mib[0] = CTL_NET;
+       mib[1] = PF_ROUTE;
+       mib[2] = 0;
+       mib[3] = AF_INET;
+       mib[4] = NET_RT_FLAGS;
+       mib[5] = RTF_LLINFO;
+       printf ("sizeof %d\n", sizeof(mib));
+       if (sysctl(mib, 6, NULL, &buffer_len, NULL, 0) == -1)
+               return -1;
+       if (buffer_len == 0)
+               return 0;
+       buffer = xmalloc(buffer_len);
+       if (sysctl(mib, 6, buffer, &buffer_len, NULL, 0) == -1)
+               return -1;
+       e = buffer + buffer_len;
+       for (p = buffer; p < e; p += rtm->rtm_msglen) {
+               rtm = (struct rt_msghdr *)(void *)p;
+               rtm->rtm_type = RTM_DELETE;
+               if (write(s, rtm, rtm->rtm_msglen) == -1) {
+                       retval = -1;
+                       break;
+               }
+       }
+       free(buffer);
+       close(s);
+       return retval;
+}
+
 int
 open_link_socket(void)
 {
index 803356ccb727246738d1f9fd06a75c6831f77e36..590bad18ac8083fcde7b9c5130adc2df4b515a97 100644 (file)
@@ -396,6 +396,13 @@ if_route(const struct interface *iface,
        return retval;
 }
 
+/* No need to explicity flush arp on Linux */
+int
+arp_flush(void)
+{
+       return 0;
+}
+
 struct interface *
 discover_interfaces(int argc, char * const *argv)
 {
diff --git a/net.h b/net.h
index 5191a7e7d90f5b79246b90891eb378399a4dad4b..806b5a19e662227347360a402d250dd824913b23 100644 (file)
--- a/net.h
+++ b/net.h
@@ -127,6 +127,7 @@ int if_route(const struct interface *, const struct in_addr *,
        if_route(iface, dest, mask, gate, metric, -1)
 #define del_src_route(iface, dest, mask, gate, metric) \
        if_route(iface, dest, mask, gate, metric, -2)
+int arp_flush(void);
 void free_routes(struct rt *);
 
 int open_udp_socket(struct interface *);