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 0a85e6f..e0c2c78 100644 (file)
@@ -240,6 +240,7 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
                if (iface->state != IFS_SETUP)
                        return;
 
                if (iface->state != IFS_SETUP)
                        return;
 
+               system_flush_routes();
                iface->state = IFS_UP;
                iface->start_time = system_get_rtime();
                interface_event(iface, IFEV_UP);
                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;
 
                if (iface->state == IFS_DOWN)
                        return;
 
+               system_flush_routes();
                mark_interface_down(iface);
                interface_handle_config_change(iface);
                if (iface->autostart)
                mark_interface_down(iface);
                interface_handle_config_change(iface);
                if (iface->autostart)
index e6187f3..d518d6f 100644 (file)
@@ -172,6 +172,11 @@ int system_del_route(struct device *dev, struct device_route *route)
        return 0;
 }
 
        return 0;
 }
 
+int system_flush_routes(void)
+{
+       return 0;
+}
+
 time_t system_get_rtime(void)
 {
        struct timeval tv;
 time_t system_get_rtime(void)
 {
        struct timeval tv;
index cf4e9c7..bb834a2 100644 (file)
@@ -446,6 +446,25 @@ int system_del_route(struct device *dev, struct device_route *route)
        return system_rt(dev, route, RTM_DELROUTE);
 }
 
        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;
 time_t system_get_rtime(void)
 {
        struct timespec ts;
index 4155281..cfe7c9f 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_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);
 
 
 time_t system_get_rtime(void);