flush routes after bringing up/down an interface
authorFelix Fietkau <nbd@openwrt.org>
Fri, 14 Oct 2011 02:40:44 +0000 (04:40 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Fri, 14 Oct 2011 02:40:44 +0000 (04:40 +0200)
interface.c
system-dummy.c
system-linux.c
system.h

index 0a85e6f049ebd912bffa20ea4187c6a3770d95da..e0c2c789dcdc402afcd1843f2d85b96695d1c6cb 100644 (file)
@@ -240,6 +240,7 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
                if (iface->state != IFS_SETUP)
                        return;
 
+               system_flush_routes();
                iface->state = IFS_UP;
                iface->start_time = system_get_rtime();
                interface_event(iface, IFEV_UP);
@@ -249,6 +250,7 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
                if (iface->state == IFS_DOWN)
                        return;
 
+               system_flush_routes();
                mark_interface_down(iface);
                interface_handle_config_change(iface);
                if (iface->autostart)
index e6187f3d0b326e3bed3794028924cf32364da5ff..d518d6fb0af0bab47920286bf2b5c71d5ddadd79 100644 (file)
@@ -172,6 +172,11 @@ int system_del_route(struct device *dev, struct device_route *route)
        return 0;
 }
 
+int system_flush_routes(void)
+{
+       return 0;
+}
+
 time_t system_get_rtime(void)
 {
        struct timeval tv;
index cf4e9c7e64c0d4fe6b5dff2e4d4f16f5551867b1..bb834a2d6614a8f4f278c01683379da0ea619b90 100644 (file)
@@ -446,6 +446,25 @@ int system_del_route(struct device *dev, struct device_route *route)
        return system_rt(dev, route, RTM_DELROUTE);
 }
 
+int system_flush_routes(void)
+{
+       const char *names[] = {
+               "/proc/sys/net/ipv4/route/flush",
+               "/proc/sys/net/ipv6/route/flush"
+       };
+       int fd, i;
+
+       for (i = 0; i < ARRAY_SIZE(names); i++) {
+               fd = open(names[i], O_WRONLY);
+               if (fd < 0)
+                       continue;
+
+               write(fd, "-1", 2);
+               close(fd);
+       }
+       return 0;
+}
+
 time_t system_get_rtime(void)
 {
        struct timespec ts;
index 4155281c18fb019788eaabf5b11d4b7b0697b7eb..cfe7c9f3fa1d277a2f2b8da6540a0439260a7ca6 100644 (file)
--- a/system.h
+++ b/system.h
@@ -44,6 +44,7 @@ int system_del_address(struct device *dev, struct device_addr *addr);
 
 int system_add_route(struct device *dev, struct device_route *route);
 int system_del_route(struct device *dev, struct device_route *route);
+int system_flush_routes(void);
 
 time_t system_get_rtime(void);