static void handle_hotplug_event(struct uloop_fd *u, unsigned int events);
static int system_add_proto_tunnel(const char *name, const uint8_t proto,
const unsigned int link, struct blob_attr **tb);
-static int __system_del_ip_tunnel(const char *name, struct blob_attr **tb);
static char dev_buf[256];
static const char *proc_path = "/proc";
static void
system_set_dev_sysfs(const char *file, const char *ifname, const char *val)
{
+ if (!val)
+ return;
+
write_file(dev_sysfs_path(ifname, file), val);
}
+static void
+system_set_dev_sysfs_int(const char *file, const char *ifname, int val)
+{
+ char buf[16];
+
+ snprintf(buf, sizeof(buf), "%d", val);
+ system_set_dev_sysfs(file, ifname, buf);
+}
+
static int
system_get_dev_sysfs(const char *file, const char *ifname, char *buf, size_t buf_sz)
{
system_set_dev_sysfs("brport/hairpin_mode", dev->ifname, val);
}
+static void system_bridge_set_proxyarp_wifi(struct device *dev, const char *val)
+{
+ system_set_dev_sysfs("brport/proxyarp_wifi", dev->ifname, val);
+}
+
static void system_bridge_set_bpdu_filter(struct device *dev, const char *val)
{
system_set_dev_sysfs("brport/bpdu_filter", dev->ifname, val);
system_set_dev_sysfs("brport/isolated", dev->ifname, val);
}
-static void system_bridge_set_multicast_router(struct device *dev, const char *val, bool bridge)
-{
- system_set_dev_sysfs(bridge ? "bridge/multicast_router" :
- "brport/multicast_router",
- dev->ifname, val);
-}
-
-static void system_bridge_set_robustness(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/multicast_startup_query_count",
- dev->ifname, val);
- system_set_dev_sysfs("bridge/multicast_last_member_count",
- dev->ifname, val);
-}
-
-static void system_bridge_set_query_interval(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/multicast_query_interval",
- dev->ifname, val);
-}
-
-static void system_bridge_set_query_response_interval(struct device *dev, const char *val)
+static void system_bridge_set_multicast_router(struct device *dev, const char *val)
{
- system_set_dev_sysfs("bridge/multicast_query_response_interval",
- dev->ifname, val);
-}
-
-static void system_bridge_set_last_member_interval(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/multicast_last_member_interval",
- dev->ifname, val);
-}
-
-static void system_bridge_set_membership_interval(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/multicast_membership_interval",
- dev->ifname, val);
-}
-
-static void system_bridge_set_other_querier_timeout(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/multicast_querier_interval",
- dev->ifname, val);
-}
-
-static void system_bridge_set_startup_query_interval(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/multicast_startup_query_interval",
- dev->ifname, val);
+ system_set_dev_sysfs("brport/multicast_router", dev->ifname, val);
}
void system_bridge_set_stp_state(struct device *dev, bool val)
system_set_dev_sysfs("bridge/stp_state", dev->ifname, valstr);
}
-static void system_bridge_set_forward_delay(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/forward_delay", dev->ifname, val);
-}
-
-static void system_bridge_set_priority(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/priority", dev->ifname, val);
-}
-
-static void system_bridge_set_ageing_time(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/ageing_time", dev->ifname, val);
-}
-
-static void system_bridge_set_hello_time(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/hello_time", dev->ifname, val);
-}
-
-static void system_bridge_set_max_age(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/max_age", dev->ifname, val);
-}
-
static void system_bridge_set_learning(struct device *dev, const char *val)
{
system_set_dev_sysfs("brport/learning", dev->ifname, val);
system_set_dev_sysfs("brport/unicast_flood", dev->ifname, val);
}
-static void system_bridge_set_vlan_filtering(struct device *dev, const char *val)
-{
- system_set_dev_sysfs("bridge/vlan_filtering", dev->ifname, val);
-}
-
static int system_get_disable_ipv6(struct device *dev, char *buf, const size_t buf_sz)
{
return system_get_dev_sysctl("ipv6/conf", "disable_ipv6",
return nl_wait_for_ack(sock_rtnl);
}
+static struct nl_msg *__system_ifinfo_msg(int af, int index, const char *ifname, uint16_t type, uint16_t flags)
+{
+ struct nl_msg *msg;
+ struct ifinfomsg iim = {
+ .ifi_family = af,
+ .ifi_index = index,
+ };
+
+ msg = nlmsg_alloc_simple(type, flags | NLM_F_REQUEST);
+ if (!msg)
+ return NULL;
+
+ nlmsg_append(msg, &iim, sizeof(iim), 0);
+ if (ifname)
+ nla_put_string(msg, IFLA_IFNAME, ifname);
+
+ return msg;
+}
+
+static struct nl_msg *system_ifinfo_msg(const char *ifname, uint16_t type, uint16_t flags)
+{
+ return __system_ifinfo_msg(AF_UNSPEC, 0, ifname, type, flags);
+}
+
+static int system_link_del(const char *ifname)
+{
+ struct nl_msg *msg;
+
+ msg = system_ifinfo_msg(ifname, RTM_DELLINK, 0);
+ if (!msg)
+ return -1;
+
+ return system_rtnl_call(msg);
+}
+
int system_bridge_delbr(struct device *bridge)
{
- return ioctl(sock_ioctl, SIOCBRDELBR, bridge->ifname);
+ return system_link_del(bridge->ifname);
}
static int system_bridge_if(const char *bridge, struct device *dev, int cmd, void *data)
system_bridge_set_wireless(struct device *bridge, struct device *dev)
{
bool mcast_to_ucast = dev->wireless_ap;
- bool hairpin = true;
+ bool hairpin;
if (bridge->settings.flags & DEV_OPT_MULTICAST_TO_UNICAST &&
!bridge->settings.multicast_to_unicast)
mcast_to_ucast = false;
- if (!mcast_to_ucast || dev->wireless_isolate)
+ hairpin = mcast_to_ucast || dev->wireless_proxyarp;
+ if (dev->wireless_isolate)
hairpin = false;
system_bridge_set_multicast_to_unicast(dev, mcast_to_ucast ? "1" : "0");
system_bridge_set_hairpin_mode(dev, hairpin ? "1" : "0");
+ system_bridge_set_proxyarp_wifi(dev, dev->wireless_proxyarp ? "1" : "0");
}
int system_bridge_addif(struct device *bridge, struct device *dev)
if (dev->settings.flags & DEV_OPT_MULTICAST_ROUTER) {
snprintf(buf, sizeof(buf), "%u", dev->settings.multicast_router);
- system_bridge_set_multicast_router(dev, buf, false);
+ system_bridge_set_multicast_router(dev, buf);
}
if (dev->settings.flags & DEV_OPT_MULTICAST_FAST_LEAVE &&
int system_bridge_vlan(const char *iface, uint16_t vid, bool add, unsigned int vflags)
{
- struct ifinfomsg ifi = { .ifi_family = PF_BRIDGE, };
struct bridge_vlan_info vinfo = { .vid = vid, };
unsigned short flags = 0;
struct nlattr *afspec;
struct nl_msg *nlm;
+ int index;
int ret = 0;
- ifi.ifi_index = if_nametoindex(iface);
- if (!ifi.ifi_index)
+ index = if_nametoindex(iface);
+ if (!index)
return -1;
- nlm = nlmsg_alloc_simple(add ? RTM_SETLINK : RTM_DELLINK, NLM_F_REQUEST);
+ nlm = __system_ifinfo_msg(PF_BRIDGE, index, NULL, add ? RTM_SETLINK : RTM_DELLINK, 0);
if (!nlm)
return -1;
- nlmsg_append(nlm, &ifi, sizeof(ifi), 0);
-
if (vflags & BRVLAN_F_SELF)
flags |= BRIDGE_FLAGS_SELF;
return ret;
}
+int system_bonding_set_device(struct device *dev, struct bonding_config *cfg)
+{
+ const char *ifname = dev->ifname;
+ struct blob_attr *cur;
+ char op = cfg ? '+' : '-';
+ char buf[64];
+ int rem;
+
+ snprintf(dev_buf, sizeof(dev_buf), "%s/class/net/bonding_masters", sysfs_path);
+ snprintf(buf, sizeof(buf), "%c%s", op, ifname);
+ write_file(dev_buf, buf);
+
+ if (!cfg)
+ return 0;
+
+ system_set_dev_sysfs("bonding/mode", ifname, bonding_policy_str[cfg->policy]);
+
+ system_set_dev_sysfs_int("bonding/all_ports_active", ifname, cfg->all_ports_active);
+
+ if (cfg->policy == BONDING_MODE_BALANCE_XOR ||
+ cfg->policy == BONDING_MODE_BALANCE_TLB ||
+ cfg->policy == BONDING_MODE_8023AD)
+ system_set_dev_sysfs("bonding/xmit_hash_policy", ifname, cfg->xmit_hash_policy);
+
+ if (cfg->policy == BONDING_MODE_8023AD) {
+ system_set_dev_sysfs("bonding/ad_actor_system", ifname, cfg->ad_actor_system);
+ system_set_dev_sysfs_int("bonding/ad_actor_sys_prio", ifname, cfg->ad_actor_sys_prio);
+ system_set_dev_sysfs("bonding/ad_select", ifname, cfg->ad_select);
+ system_set_dev_sysfs("bonding/lacp_rate", ifname, cfg->lacp_rate);
+ system_set_dev_sysfs_int("bonding/min_links", ifname, cfg->min_links);
+ }
+
+ if (cfg->policy == BONDING_MODE_BALANCE_RR)
+ system_set_dev_sysfs_int("bonding/packets_per_slave", ifname, cfg->packets_per_port);
+
+ if (cfg->policy == BONDING_MODE_BALANCE_TLB ||
+ cfg->policy == BONDING_MODE_BALANCE_ALB)
+ system_set_dev_sysfs_int("bonding/lp_interval", ifname, cfg->lp_interval);
+
+ if (cfg->policy == BONDING_MODE_BALANCE_TLB)
+ system_set_dev_sysfs_int("bonding/tlb_dynamic_lb", ifname, cfg->dynamic_lb);
+ system_set_dev_sysfs_int("bonding/resend_igmp", ifname, cfg->resend_igmp);
+ system_set_dev_sysfs_int("bonding/num_grat_arp", ifname, cfg->num_peer_notif);
+ system_set_dev_sysfs("bonding/primary_reselect", ifname, cfg->primary_reselect);
+ system_set_dev_sysfs("bonding/fail_over_mac", ifname, cfg->failover_mac);
+
+ system_set_dev_sysfs_int((cfg->monitor_arp ?
+ "bonding/arp_interval" :
+ "bonding/miimon"), ifname, cfg->monitor_interval);
+
+ blobmsg_for_each_attr(cur, cfg->arp_target, rem) {
+ snprintf(buf, sizeof(buf), "+%s", blobmsg_get_string(cur));
+ system_set_dev_sysfs("bonding/arp_ip_target", ifname, buf);
+ }
+
+ system_set_dev_sysfs_int("bonding/arp_all_targets", ifname, cfg->arp_all_targets);
+ if (cfg->policy < BONDING_MODE_8023AD)
+ system_set_dev_sysfs("bonding/arp_validate", ifname, cfg->arp_validate);
+ system_set_dev_sysfs_int("bonding/use_carrier", ifname, cfg->use_carrier);
+ if (!cfg->monitor_arp && cfg->monitor_interval) {
+ system_set_dev_sysfs_int("bonding/updelay", ifname, cfg->updelay);
+ system_set_dev_sysfs_int("bonding/downdelay", ifname, cfg->downdelay);
+ }
+
+ return 0;
+}
+
+int system_bonding_set_port(struct device *dev, struct device *port, bool add, bool primary)
+{
+ const char *port_name = port->ifname;
+ const char op_ch = add ? '+' : '-';
+ char buf[IFNAMSIZ + 1];
+
+ snprintf(buf, sizeof(buf), "%c%s", op_ch, port_name);
+ system_if_down(port);
+ system_set_dev_sysfs("bonding/slaves", dev->ifname, buf);
+ system_if_up(port);
+
+ if (primary)
+ system_set_dev_sysfs("bonding/primary", dev->ifname,
+ add ? port_name : "");
+
+ return 0;
+}
+
int system_if_resolve(struct device *dev)
{
struct ifreq ifr;
return (unsigned long) val * 100;
}
-static void system_bridge_conf_multicast_deps(struct device *bridge,
- struct bridge_config *cfg,
- char *buf,
- int buf_len)
+int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
{
- int val;
-
- if (cfg->flags & BRIDGE_OPT_ROBUSTNESS ||
- cfg->flags & BRIDGE_OPT_QUERY_INTERVAL ||
- cfg->flags & BRIDGE_OPT_QUERY_RESPONSE_INTERVAL) {
- val = cfg->robustness * cfg->query_interval +
- cfg->query_response_interval;
-
- snprintf(buf, buf_len, "%i", val);
- system_bridge_set_membership_interval(bridge, buf);
-
- val = cfg->robustness * cfg->query_interval +
- cfg->query_response_interval / 2;
-
- snprintf(buf, buf_len, "%i", val);
- system_bridge_set_other_querier_timeout(bridge, buf);
- }
+ struct nlattr *linkinfo, *data;
+ struct nl_msg *msg;
+ uint64_t val;
+ int rv;
- if (cfg->flags & BRIDGE_OPT_QUERY_INTERVAL) {
- val = cfg->query_interval / 4;
+ msg = system_ifinfo_msg(bridge->ifname, RTM_NEWLINK, NLM_F_CREATE | NLM_F_EXCL);
+ if (!msg)
+ return -1;
- snprintf(buf, buf_len, "%i", val);
- system_bridge_set_startup_query_interval(bridge, buf);
- }
-}
+ if (!(linkinfo = nla_nest_start(msg, IFLA_LINKINFO)))
+ goto nla_put_failure;
-static void system_bridge_conf_multicast(struct device *bridge,
- struct bridge_config *cfg,
- char *buf,
- int buf_len)
-{
- system_set_dev_sysfs("bridge/multicast_snooping",
- bridge->ifname, cfg->igmp_snoop ? "1" : "0");
+ nla_put_string(msg, IFLA_INFO_KIND, "bridge");
- system_set_dev_sysfs("bridge/multicast_querier",
- bridge->ifname, cfg->multicast_querier ? "1" : "0");
+ if (!(data = nla_nest_start(msg, IFLA_INFO_DATA)))
+ goto nla_put_failure;
- snprintf(buf, buf_len, "%i", cfg->hash_max);
- system_set_dev_sysfs("/bridge/hash_max",
- bridge->ifname, buf);
+ nla_put_u32(msg, IFLA_BR_STP_STATE, cfg->stp);
+ nla_put_u32(msg, IFLA_BR_FORWARD_DELAY, sec_to_jiffies(cfg->forward_delay));
+ nla_put_u8(msg, IFLA_BR_MCAST_SNOOPING, !!cfg->igmp_snoop);
+ nla_put_u8(msg, IFLA_BR_MCAST_QUERIER, !!cfg->multicast_querier);
+ nla_put_u32(msg, IFLA_BR_MCAST_HASH_MAX, cfg->hash_max);
- if (bridge->settings.flags & DEV_OPT_MULTICAST_ROUTER) {
- snprintf(buf, buf_len, "%u", bridge->settings.multicast_router);
- system_bridge_set_multicast_router(bridge, buf, true);
- }
+ if (bridge->settings.flags & DEV_OPT_MULTICAST_ROUTER)
+ nla_put_u8(msg, IFLA_BR_MCAST_ROUTER, !!bridge->settings.multicast_router);
if (cfg->flags & BRIDGE_OPT_ROBUSTNESS) {
- snprintf(buf, buf_len, "%i", cfg->robustness);
- system_bridge_set_robustness(bridge, buf);
+ nla_put_u32(msg, IFLA_BR_MCAST_STARTUP_QUERY_CNT, cfg->robustness);
+ nla_put_u32(msg, IFLA_BR_MCAST_LAST_MEMBER_CNT, cfg->robustness);
}
- if (cfg->flags & BRIDGE_OPT_QUERY_INTERVAL) {
- snprintf(buf, buf_len, "%i", cfg->query_interval);
- system_bridge_set_query_interval(bridge, buf);
- }
+ if (cfg->flags & BRIDGE_OPT_QUERY_INTERVAL)
+ nla_put_u64(msg, IFLA_BR_MCAST_QUERY_INTVL, cfg->query_interval);
- if (cfg->flags & BRIDGE_OPT_QUERY_RESPONSE_INTERVAL) {
- snprintf(buf, buf_len, "%i", cfg->query_response_interval);
- system_bridge_set_query_response_interval(bridge, buf);
- }
+ if (cfg->flags & BRIDGE_OPT_QUERY_RESPONSE_INTERVAL)
+ nla_put_u64(msg, IFLA_BR_MCAST_QUERY_RESPONSE_INTVL, cfg->query_response_interval);
- if (cfg->flags & BRIDGE_OPT_LAST_MEMBER_INTERVAL) {
- snprintf(buf, buf_len, "%i", cfg->last_member_interval);
- system_bridge_set_last_member_interval(bridge, buf);
- }
+ if (cfg->flags & BRIDGE_OPT_LAST_MEMBER_INTERVAL)
+ nla_put_u64(msg, IFLA_BR_MCAST_LAST_MEMBER_INTVL, cfg->last_member_interval);
- system_bridge_conf_multicast_deps(bridge, cfg, buf, buf_len);
-}
+ if (cfg->flags & BRIDGE_OPT_ROBUSTNESS ||
+ cfg->flags & BRIDGE_OPT_QUERY_INTERVAL ||
+ cfg->flags & BRIDGE_OPT_QUERY_RESPONSE_INTERVAL) {
+ val = cfg->robustness * cfg->query_interval +
+ cfg->query_response_interval;
-int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
-{
- char buf[64];
+ nla_put_u64(msg, IFLA_BR_MCAST_MEMBERSHIP_INTVL, val);
- if (ioctl(sock_ioctl, SIOCBRADDBR, bridge->ifname) < 0)
- return -1;
+ val -= cfg->query_response_interval / 2;
- system_bridge_set_stp_state(bridge, cfg->stp);
+ nla_put_u64(msg, IFLA_BR_MCAST_QUERIER_INTVL, val);
+ }
- snprintf(buf, sizeof(buf), "%lu", sec_to_jiffies(cfg->forward_delay));
- system_bridge_set_forward_delay(bridge, buf);
+ if (cfg->flags & BRIDGE_OPT_QUERY_INTERVAL) {
+ val = cfg->query_interval / 4;
- system_bridge_conf_multicast(bridge, cfg, buf, sizeof(buf));
- system_bridge_set_vlan_filtering(bridge, cfg->vlan_filtering ? "1" : "0");
+ nla_put_u64(msg, IFLA_BR_MCAST_STARTUP_QUERY_INTVL, val);
+ }
- snprintf(buf, sizeof(buf), "%d", cfg->priority);
- system_bridge_set_priority(bridge, buf);
+ nla_put_u8(msg, IFLA_BR_VLAN_FILTERING, !!cfg->vlan_filtering);
+ nla_put_u16(msg, IFLA_BR_PRIORITY, cfg->priority);
+ nla_put_u32(msg, IFLA_BR_HELLO_TIME, sec_to_jiffies(cfg->hello_time));
+ nla_put_u32(msg, IFLA_BR_MAX_AGE, sec_to_jiffies(cfg->max_age));
- snprintf(buf, sizeof(buf), "%lu", sec_to_jiffies(cfg->hello_time));
- system_bridge_set_hello_time(bridge, buf);
+ if (cfg->flags & BRIDGE_OPT_AGEING_TIME)
+ nla_put_u32(msg, IFLA_BR_AGEING_TIME, sec_to_jiffies(cfg->ageing_time));
- snprintf(buf, sizeof(buf), "%lu", sec_to_jiffies(cfg->max_age));
- system_bridge_set_max_age(bridge, buf);
+ nla_nest_end(msg, data);
+ nla_nest_end(msg, linkinfo);
- if (cfg->flags & BRIDGE_OPT_AGEING_TIME) {
- snprintf(buf, sizeof(buf), "%lu", sec_to_jiffies(cfg->ageing_time));
- system_bridge_set_ageing_time(bridge, buf);
- }
+ rv = system_rtnl_call(msg);
+ if (rv)
+ D(SYSTEM, "Error adding bridge '%s': %d\n", bridge->ifname, rv);
- return 0;
+ return rv;
+
+nla_put_failure:
+ nlmsg_free(msg);
+ return -ENOMEM;
}
int system_macvlan_add(struct device *macvlan, struct device *dev, struct macvlan_config *cfg)
{
struct nl_msg *msg;
struct nlattr *linkinfo, *data;
- struct ifinfomsg iim = { .ifi_family = AF_UNSPEC, };
int i, rv;
static const struct {
const char *name;
{ "passthru", MACVLAN_MODE_PASSTHRU },
};
- msg = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL);
-
+ msg = system_ifinfo_msg(macvlan->ifname, RTM_NEWLINK, NLM_F_CREATE | NLM_F_EXCL);
if (!msg)
return -1;
- nlmsg_append(msg, &iim, sizeof(iim), 0);
-
if (cfg->flags & MACVLAN_OPT_MACADDR)
nla_put(msg, IFLA_ADDRESS, sizeof(cfg->macaddr), cfg->macaddr);
- nla_put_string(msg, IFLA_IFNAME, macvlan->ifname);
nla_put_u32(msg, IFLA_LINK, dev->ifindex);
if (!(linkinfo = nla_nest_start(msg, IFLA_LINKINFO)))
int system_link_netns_move(struct device *dev, int netns_fd, const char *target_ifname)
{
struct nl_msg *msg;
- struct ifinfomsg iim = {
- .ifi_family = AF_UNSPEC,
- };
+ int index;
if (!dev)
return -1;
- iim.ifi_index = system_if_resolve(dev);
- msg = nlmsg_alloc_simple(RTM_NEWLINK, NLM_F_REQUEST);
-
+ index = system_if_resolve(dev);
+ msg = __system_ifinfo_msg(AF_UNSPEC, index, target_ifname, RTM_NEWLINK, 0);
if (!msg)
return -1;
- nlmsg_append(msg, &iim, sizeof(iim), 0);
- if (target_ifname)
- nla_put_string(msg, IFLA_IFNAME, target_ifname);
-
nla_put_u32(msg, IFLA_NET_NS_FD, netns_fd);
return system_rtnl_call(msg);
}
-static int system_link_del(const char *ifname)
-{
- struct nl_msg *msg;
- struct ifinfomsg iim = {
- .ifi_family = AF_UNSPEC,
- .ifi_index = 0,
- };
-
- msg = nlmsg_alloc_simple(RTM_DELLINK, NLM_F_REQUEST);
-
- if (!msg)
- return -1;
-
- nlmsg_append(msg, &iim, sizeof(iim), 0);
- nla_put_string(msg, IFLA_IFNAME, ifname);
- return system_rtnl_call(msg);
-}
-
int system_macvlan_del(struct device *macvlan)
{
return system_link_del(macvlan->ifname);
return stat(dev_sysfs_path(ifname, "phy80211"), &s) == 0;
}
+static const char *
+system_netdevtype_name(unsigned short dev_type)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(netdev_types); i++) {
+ if (netdev_types[i].id == dev_type)
+ return netdev_types[i].name;
+ }
+
+ /* the last key is used by default */
+ i = ARRAY_SIZE(netdev_types) - 1;
+
+ return netdev_types[i].name;
+}
+
+static void
+system_add_devtype(struct blob_buf *b, const char *ifname)
+{
+ char buf[100];
+ bool found = false;
+
+ if (!system_get_dev_sysfs("uevent", ifname, buf, sizeof(buf))) {
+ const char *info = "DEVTYPE=";
+ char *context = NULL;
+ const char *line = strtok_r(buf, "\r\n", &context);
+
+ while (line != NULL) {
+ char *index = strstr(line, info);
+
+ if (index != NULL) {
+ blobmsg_add_string(b, "devtype", index + strlen(info));
+ found = true;
+ break;
+ }
+
+ line = strtok_r(NULL, "\r\n", &context);
+ }
+ }
+
+ if (!found) {
+ unsigned short number = 0;
+ const char *name = NULL;
+
+ if (!system_get_dev_sysfs("type", ifname, buf, sizeof(buf))) {
+ number = strtoul(buf, NULL, 0);
+ name = system_netdevtype_name(number);
+ blobmsg_add_string(b, "devtype", name);
+ }
+ }
+}
+
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+
+static int32_t
+ethtool_feature_count(const char *ifname)
+{
+ struct {
+ struct ethtool_sset_info hdr;
+ uint32_t buf;
+ } req = {
+ .hdr = {
+ .cmd = ETHTOOL_GSSET_INFO,
+ .sset_mask = 1 << ETH_SS_FEATURES
+ }
+ };
+
+ struct ifreq ifr = {
+ .ifr_data = (void *)&req
+ };
+
+ strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
+
+ if (ioctl(sock_ioctl, SIOCETHTOOL, &ifr) != 0)
+ return -1;
+
+ if (!req.hdr.sset_mask)
+ return 0;
+
+ return req.buf;
+}
+
+static int32_t
+ethtool_feature_index(const char *ifname, const char *keyname)
+{
+ struct ethtool_gstrings *feature_names;
+ struct ifreq ifr = { 0 };
+ int32_t n_features, i;
+
+ n_features = ethtool_feature_count(ifname);
+
+ if (n_features <= 0)
+ return -1;
+
+ feature_names = calloc(1, sizeof(*feature_names) + n_features * ETH_GSTRING_LEN);
+
+ if (!feature_names)
+ return -1;
+
+ feature_names->cmd = ETHTOOL_GSTRINGS;
+ feature_names->string_set = ETH_SS_FEATURES;
+ feature_names->len = n_features;
+
+ strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
+ ifr.ifr_data = (void *)feature_names;
+
+ if (ioctl(sock_ioctl, SIOCETHTOOL, &ifr) != 0) {
+ free(feature_names);
+
+ return -1;
+ }
+
+ for (i = 0; i < feature_names->len; i++)
+ if (!strcmp((char *)&feature_names->data[i * ETH_GSTRING_LEN], keyname))
+ break;
+
+ if (i >= feature_names->len)
+ i = -1;
+
+ free(feature_names);
+
+ return i;
+}
+
+static bool
+ethtool_feature_value(const char *ifname, const char *keyname)
+{
+ struct ethtool_get_features_block *feature_block;
+ struct ethtool_gfeatures *feature_values;
+ struct ifreq ifr = { 0 };
+ int32_t feature_idx;
+ bool active;
+
+ feature_idx = ethtool_feature_index(ifname, keyname);
+
+ if (feature_idx < 0)
+ return false;
+
+ feature_values = calloc(1,
+ sizeof(*feature_values) +
+ sizeof(feature_values->features[0]) * DIV_ROUND_UP(feature_idx, 32));
+
+ if (!feature_values)
+ return false;
+
+ feature_values->cmd = ETHTOOL_GFEATURES;
+ feature_values->size = DIV_ROUND_UP(feature_idx, 32);
+
+ strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
+ ifr.ifr_data = (void *)feature_values;
+
+ if (ioctl(sock_ioctl, SIOCETHTOOL, &ifr) != 0) {
+ free(feature_values);
+
+ return false;
+ }
+
+ feature_block = &feature_values->features[feature_idx / 32];
+ active = feature_block->active & (1U << feature_idx % 32);
+
+ free(feature_values);
+
+ return active;
+}
+
int
system_if_dump_info(struct device *dev, struct blob_buf *b)
{
blobmsg_add_u8(b, "autoneg", !!ecmd.autoneg);
}
+ blobmsg_add_u8(b, "hw-tc-offload",
+ ethtool_feature_value(dev->ifname, "hw-tc-offload"));
+
+ system_add_devtype(b, dev->ifname);
+
return 0;
}
if (rule->flags & IPRULE_SUP_PREFIXLEN)
nla_put_u32(msg, FRA_SUPPRESS_PREFIXLEN, rule->sup_prefixlen);
+ if (rule->flags & IPRULE_UIDRANGE) {
+ struct fib_rule_uid_range uidrange = {
+ .start = rule->uidrange_start,
+ .end = rule->uidrange_end
+ };
+
+ nla_put(msg, FRA_UID_RANGE, sizeof(uidrange), &uidrange);
+ }
+
if (rule->flags & IPRULE_GOTO)
nla_put_u32(msg, FRA_GOTO, rule->gotoid);
return ret;
failure:
- __system_del_ip_tunnel(name, tb);
+ system_link_del(name);
return ret;
}
return -1;
}
-static int __system_del_ip_tunnel(const char *name, struct blob_attr **tb)
-{
- struct blob_attr *cur;
- const char *str;
-
- if (!(cur = tb[TUNNEL_ATTR_TYPE]))
- return -EINVAL;
- str = blobmsg_data(cur);
-
- if (!strcmp(str, "greip") || !strcmp(str, "gretapip") ||
- !strcmp(str, "greip6") || !strcmp(str, "gretapip6") ||
- !strcmp(str, "vtiip") || !strcmp(str, "vtiip6") ||
- !strcmp(str, "vxlan") || !strcmp(str, "vxlan6") ||
- !strcmp(str, "xfrm"))
- return system_link_del(name);
- else
- return tunnel_ioctl(name, SIOCDELTUNNEL, NULL);
-}
-
-int system_del_ip_tunnel(const char *name, struct blob_attr *attr)
+int system_del_ip_tunnel(const struct device *dev)
{
- struct blob_attr *tb[__TUNNEL_ATTR_MAX];
-
- blobmsg_parse(tunnel_attr_list.params, __TUNNEL_ATTR_MAX, tb,
- blob_data(attr), blob_len(attr));
-
- return __system_del_ip_tunnel(name, tb);
+ return system_link_del(dev->ifname);
}
int system_update_ipv6_mtu(struct device *dev, int mtu)
return ret;
}
-int system_add_ip_tunnel(const char *name, struct blob_attr *attr)
+int system_add_ip_tunnel(const struct device *dev, struct blob_attr *attr)
{
struct blob_attr *tb[__TUNNEL_ATTR_MAX];
struct blob_attr *cur;
blobmsg_parse(tunnel_attr_list.params, __TUNNEL_ATTR_MAX, tb,
blob_data(attr), blob_len(attr));
- __system_del_ip_tunnel(name, tb);
+ system_link_del(dev->ifname);
if (!(cur = tb[TUNNEL_ATTR_TYPE]))
return -EINVAL;
}
if (!strcmp(str, "sit"))
- return system_add_sit_tunnel(name, link, tb);
+ return system_add_sit_tunnel(dev->ifname, link, tb);
#ifdef IFLA_IPTUN_MAX
else if (!strcmp(str, "ipip6")) {
- return system_add_ip6_tunnel(name, link, tb);
+ return system_add_ip6_tunnel(dev->ifname, link, tb);
} else if (!strcmp(str, "greip")) {
- return system_add_gre_tunnel(name, "gre", link, tb, false);
+ return system_add_gre_tunnel(dev->ifname, "gre", link, tb, false);
} else if (!strcmp(str, "gretapip")) {
- return system_add_gre_tunnel(name, "gretap", link, tb, false);
+ return system_add_gre_tunnel(dev->ifname, "gretap", link, tb, false);
} else if (!strcmp(str, "greip6")) {
- return system_add_gre_tunnel(name, "ip6gre", link, tb, true);
+ return system_add_gre_tunnel(dev->ifname, "ip6gre", link, tb, true);
} else if (!strcmp(str, "gretapip6")) {
- return system_add_gre_tunnel(name, "ip6gretap", link, tb, true);
+ return system_add_gre_tunnel(dev->ifname, "ip6gretap", link, tb, true);
#ifdef IFLA_VTI_MAX
} else if (!strcmp(str, "vtiip")) {
- return system_add_vti_tunnel(name, "vti", link, tb, false);
+ return system_add_vti_tunnel(dev->ifname, "vti", link, tb, false);
} else if (!strcmp(str, "vtiip6")) {
- return system_add_vti_tunnel(name, "vti6", link, tb, true);
+ return system_add_vti_tunnel(dev->ifname, "vti6", link, tb, true);
#endif
#ifdef IFLA_XFRM_MAX
} else if (!strcmp(str, "xfrm")) {
- return system_add_xfrm_tunnel(name, "xfrm", link, tb);
+ return system_add_xfrm_tunnel(dev->ifname, "xfrm", link, tb);
#endif
#ifdef IFLA_VXLAN_MAX
} else if(!strcmp(str, "vxlan")) {
- return system_add_vxlan(name, link, tb, false);
+ return system_add_vxlan(dev->ifname, link, tb, false);
} else if(!strcmp(str, "vxlan6")) {
- return system_add_vxlan(name, link, tb, true);
+ return system_add_vxlan(dev->ifname, link, tb, true);
#endif
#endif
} else if (!strcmp(str, "ipip")) {
- return system_add_proto_tunnel(name, IPPROTO_IPIP, link, tb);
+ return system_add_proto_tunnel(dev->ifname, IPPROTO_IPIP, link, tb);
}
else
return -EINVAL;