X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=system-linux.c;h=0277886e17a56d6fb4f65397b19dbe3cbb6bf64b;hp=f38aaed584ead695df6ca139174a1585690db552;hb=af3cadb6a46ba93e8a729e71d82b176275931e62;hpb=e41382c92e9e83ad754a060e63efa43c753095f1 diff --git a/system-linux.c b/system-linux.c index f38aaed..0277886 100644 --- a/system-linux.c +++ b/system-linux.c @@ -543,16 +543,20 @@ out: static void handle_hotplug_msg(char *data, int size) { - const char *subsystem = NULL, *interface = NULL; + const char *subsystem = NULL, *interface = NULL, *interface_old = NULL; char *cur, *end, *sep; struct device *dev; int skip; - bool add; + bool add, move = false; if (!strncmp(data, "add@", 4)) add = true; else if (!strncmp(data, "remove@", 7)) add = false; + else if (!strncmp(data, "move@", 5)) { + add = true; + move = true; + } else return; @@ -573,12 +577,32 @@ handle_hotplug_msg(char *data, int size) subsystem = sep + 1; if (strcmp(subsystem, "net") != 0) return; + } else if (!strcmp(cur, "DEVPATH_OLD")) { + interface_old = strrchr(sep + 1, '/'); + if (interface_old) + interface_old++; } - if (subsystem && interface) + } + + if (subsystem && interface) { + if (move && interface_old) + goto move; + else goto found; } + return; +move: + dev = device_find(interface_old); + if (!dev) + goto found; + + if (dev->type != &simple_device_type) + goto found; + + device_set_present(dev, false); + found: dev = device_find(interface); if (!dev) @@ -1362,7 +1386,7 @@ system_if_get_settings(struct device *dev, struct device_settings *s) } if (!system_get_neigh4locktime(dev, buf, sizeof(buf))) { - s->neigh4locktime = strtoul(buf, NULL, 0); + s->neigh4locktime = strtol(buf, NULL, 0); s->flags |= DEV_OPT_NEIGHLOCKTIME; } @@ -1388,7 +1412,7 @@ system_if_get_settings(struct device *dev, struct device_settings *s) } static void -system_if_set_rps_xps_val(const char *path, int val) +system_if_set_rps_xps_val(const char *path, char *fmt, int val) { char val_buf[8]; glob_t gl; @@ -1397,7 +1421,7 @@ system_if_set_rps_xps_val(const char *path, int val) if (glob(path, 0, NULL, &gl)) return; - snprintf(val_buf, sizeof(val_buf), "%x", val); + snprintf(val_buf, sizeof(val_buf), fmt, val); for (i = 0; i < gl.gl_pathc; i++) system_set_sysctl(gl.gl_pathv[i], val_buf); @@ -1408,17 +1432,23 @@ static void system_if_apply_rps_xps(struct device *dev, struct device_settings *s) { long n_cpus = sysconf(_SC_NPROCESSORS_ONLN); - int val; + int val, rps_val, rps_flow_cnt, xps_val; if (n_cpus < 2) return; val = (1 << n_cpus) - 1; + rps_val = s->rps_val ? s->rps_val : val; snprintf(dev_buf, sizeof(dev_buf), "/sys/class/net/%s/queues/*/rps_cpus", dev->ifname); - system_if_set_rps_xps_val(dev_buf, s->rps ? val : 0); + system_if_set_rps_xps_val(dev_buf, "%x", s->rps ? rps_val : 0); + rps_flow_cnt = s->rps_flow_cnt ? s->rps_flow_cnt : 0; + snprintf(dev_buf, sizeof(dev_buf), "/sys/class/net/%s/queues/*/rps_flow_cnt", dev->ifname); + system_if_set_rps_xps_val(dev_buf, "%d", s->rps ? rps_flow_cnt : 0); + + xps_val = s->xps_val ? s->xps_val : val; snprintf(dev_buf, sizeof(dev_buf), "/sys/class/net/%s/queues/*/xps_cpus", dev->ifname); - system_if_set_rps_xps_val(dev_buf, s->xps ? val : 0); + system_if_set_rps_xps_val(dev_buf, "%x", s->xps ? xps_val : 0); } void @@ -1476,7 +1506,7 @@ system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned system_set_neigh6reachabletime(dev, buf); } if (s->flags & DEV_OPT_NEIGHLOCKTIME & apply_mask) { - snprintf(buf, sizeof(buf), "%u", s->neigh4locktime); + snprintf(buf, sizeof(buf), "%d", s->neigh4locktime); system_set_neigh4locktime(dev, buf); } if (s->flags & DEV_OPT_NEIGHGCSTALETIME & apply_mask) { @@ -2322,45 +2352,68 @@ static int system_add_ip6_tunnel(const char *name, const unsigned int link, } #ifdef IFLA_IPTUN_FMR_MAX - if ((cur = tb[TUNNEL_ATTR_FMRS])) { + if ((cur = tb[TUNNEL_ATTR_DATA])) { struct nlattr *fmrs = nla_nest_start(nlm, IFLA_IPTUN_FMRS); + struct blob_attr *dcur; + unsigned drem, fmrcnt = 0; - struct blob_attr *fmr; - unsigned rem, fmrcnt = 0; - blobmsg_for_each_attr(fmr, cur, rem) { - if (blobmsg_type(fmr) != BLOBMSG_TYPE_STRING) + blobmsg_for_each_attr(dcur, cur, drem) { + if (blobmsg_type(dcur) != BLOBMSG_TYPE_ARRAY || + strcmp(blobmsg_name(dcur), "fmrs") || + blobmsg_check_array(dcur, BLOBMSG_TYPE_UNSPEC) <= 0) continue; - unsigned ip4len, ip6len, ealen, offset = 6; - char ip6buf[48]; - char ip4buf[16]; + struct blob_attr *rcur; + unsigned rrem; + blobmsg_for_each_attr(rcur, dcur, rrem) { + struct blob_attr *tb_fmr[__FMR_DATA_ATTR_MAX], *tb_cur; + struct in6_addr ip6prefix; + struct in_addr ip4prefix; + unsigned ip4len, ip6len, ealen, offset; + + blobmsg_parse(fmr_data_attr_list.params, __FMR_DATA_ATTR_MAX, tb_fmr, + blobmsg_data(rcur), blobmsg_len(rcur)); + + if (!(tb_cur = tb_fmr[FMR_DATA_PREFIX6]) || + !parse_ip_and_netmask(AF_INET6, + blobmsg_data(tb_cur), &ip6prefix, + &ip6len)) { + ret = -EINVAL; + goto failure; + } - if (sscanf(blobmsg_get_string(fmr), "%47[^/]/%u,%15[^/]/%u,%u,%u", - ip6buf, &ip6len, ip4buf, &ip4len, &ealen, &offset) < 5) { - ret = -EINVAL; - goto failure; - } + if (!(tb_cur = tb_fmr[FMR_DATA_PREFIX4]) || + !parse_ip_and_netmask(AF_INET, + blobmsg_data(tb_cur), &ip4prefix, + &ip4len)) { + ret = -EINVAL; + goto failure; + } - struct in6_addr ip6prefix; - struct in_addr ip4prefix; - if (inet_pton(AF_INET6, ip6buf, &ip6prefix) != 1 || - inet_pton(AF_INET, ip4buf, &ip4prefix) != 1) { - ret = -EINVAL; - goto failure; - } + if (!(tb_cur = tb_fmr[FMR_DATA_EALEN])) { + ret = -EINVAL; + goto failure; + } + ealen = blobmsg_get_u32(tb_cur); - struct nlattr *rule = nla_nest_start(nlm, ++fmrcnt); + if (!(tb_cur = tb_fmr[FMR_DATA_OFFSET])) { + ret = -EINVAL; + goto failure; + } + offset = blobmsg_get_u32(tb_cur); - nla_put(nlm, IFLA_IPTUN_FMR_IP6_PREFIX, sizeof(ip6prefix), &ip6prefix); - nla_put(nlm, IFLA_IPTUN_FMR_IP4_PREFIX, sizeof(ip4prefix), &ip4prefix); - nla_put_u8(nlm, IFLA_IPTUN_FMR_IP6_PREFIX_LEN, ip6len); - nla_put_u8(nlm, IFLA_IPTUN_FMR_IP4_PREFIX_LEN, ip4len); - nla_put_u8(nlm, IFLA_IPTUN_FMR_EA_LEN, ealen); - nla_put_u8(nlm, IFLA_IPTUN_FMR_OFFSET, offset); + struct nlattr *rule = nla_nest_start(nlm, ++fmrcnt); - nla_nest_end(nlm, rule); - } + nla_put(nlm, IFLA_IPTUN_FMR_IP6_PREFIX, sizeof(ip6prefix), &ip6prefix); + nla_put(nlm, IFLA_IPTUN_FMR_IP4_PREFIX, sizeof(ip4prefix), &ip4prefix); + nla_put_u8(nlm, IFLA_IPTUN_FMR_IP6_PREFIX_LEN, ip6len); + nla_put_u8(nlm, IFLA_IPTUN_FMR_IP4_PREFIX_LEN, ip4len); + nla_put_u8(nlm, IFLA_IPTUN_FMR_EA_LEN, ealen); + nla_put_u8(nlm, IFLA_IPTUN_FMR_OFFSET, offset); + nla_nest_end(nlm, rule); + } + } nla_nest_end(nlm, fmrs); } #endif @@ -2788,6 +2841,17 @@ static int system_add_vxlan(const char *name, const unsigned int link, struct bl } nla_put_u16(msg, IFLA_VXLAN_PORT, htons(port)); + if ((cur = tb_data[VXLAN_DATA_ATTR_RXCSUM])) { + bool rxcsum = blobmsg_get_bool(cur); + nla_put_u8(msg, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, !rxcsum); + } + + if ((cur = tb_data[VXLAN_DATA_ATTR_TXCSUM])) { + bool txcsum = blobmsg_get_bool(cur); + nla_put_u8(msg, IFLA_VXLAN_UDP_CSUM, txcsum); + nla_put_u8(msg, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, !txcsum); + } + if ((cur = tb[TUNNEL_ATTR_TOS])) { char *str = blobmsg_get_string(cur); unsigned tos = 1;