X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=system-linux.c;h=8b9189d27a2b974b043195a894999e5ef793b85e;hb=26486b46eada232ef807f3d969ffdec33d5e4858;hp=e313cbc97934bf37f410e180419fe66bef039f99;hpb=beecba5195b2f1180f0bdfb6f61f0dbd3dff0eba;p=project%2Fnetifd.git diff --git a/system-linux.c b/system-linux.c index e313cbc..8b9189d 100644 --- a/system-linux.c +++ b/system-linux.c @@ -101,7 +101,7 @@ static void system_set_sysctl(const char *path, const char *val) static void system_set_dev_sysctl(const char *path, const char *device, const char *val) { - char buf[256]; + static char buf[256]; snprintf(buf, sizeof(buf), path, val); system_set_sysctl(buf, val); @@ -367,9 +367,12 @@ out: */ void system_if_clear_state(struct device *dev) { - char buf[256]; + static char buf[256]; char *bridge; + if (dev->external) + return; + dev->ifindex = system_if_resolve(dev); if (!dev->ifindex) return; @@ -562,7 +565,17 @@ static int system_addr(struct device *dev, struct device_addr *addr, int cmd) .ifa_index = dev->ifindex, }; - struct nl_msg *msg = nlmsg_alloc_simple(cmd, 0); + struct nl_msg *msg; + + dev = addr->device; + if (dev) { + if (!dev->ifindex) + return -1; + + ifa.ifa_index = dev->ifindex; + } + + msg = nlmsg_alloc_simple(cmd, 0); if (!msg) return -1; @@ -586,6 +599,7 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd) int alen = ((route->flags & DEVADDR_FAMILY) == DEVADDR_INET4) ? 4 : 16; bool have_gw; unsigned int flags = 0; + int ifindex = dev->ifindex; if (alen == 4) have_gw = !!route->nexthop.in.s_addr; @@ -606,11 +620,20 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd) .rtm_scope = scope, .rtm_type = (cmd == RTM_DELROUTE) ? 0: RTN_UNICAST, }; + struct nl_msg *msg; if (cmd == RTM_NEWROUTE) flags |= NLM_F_CREATE | NLM_F_REPLACE; - struct nl_msg *msg = nlmsg_alloc_simple(cmd, flags); + dev = route->device; + if (dev) { + if (!dev->ifindex) + return -1; + + ifindex = dev->ifindex; + } + + msg = nlmsg_alloc_simple(cmd, flags); if (!msg) return -1; @@ -623,7 +646,7 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd) nla_put(msg, RTA_GATEWAY, alen, &route->nexthop); if (route->flags & DEVADDR_DEVICE) - nla_put_u32(msg, RTA_OIF, dev->ifindex); + nla_put_u32(msg, RTA_OIF, ifindex); return system_rtnl_call(msg); }