From ca3f00d45e72c4b28b2ce39afc9543fa2f225020 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 14 Oct 2011 04:40:44 +0200 Subject: [PATCH] flush routes after bringing up/down an interface --- interface.c | 2 ++ system-dummy.c | 5 +++++ system-linux.c | 19 +++++++++++++++++++ system.h | 1 + 4 files changed, 27 insertions(+) diff --git a/interface.c b/interface.c index 0a85e6f..e0c2c78 100644 --- a/interface.c +++ b/interface.c @@ -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) diff --git a/system-dummy.c b/system-dummy.c index e6187f3..d518d6f 100644 --- a/system-dummy.c +++ b/system-dummy.c @@ -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; diff --git a/system-linux.c b/system-linux.c index cf4e9c7..bb834a2 100644 --- a/system-linux.c +++ b/system-linux.c @@ -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; diff --git a/system.h b/system.h index 4155281..cfe7c9f 100644 --- 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); -- 2.11.0