diff --git a/include/netlink/route/link.h b/include/netlink/route/link.h index add464be..620cb7a6 100644 --- a/include/netlink/route/link.h +++ b/include/netlink/route/link.h @@ -245,6 +245,8 @@ extern int rtnl_link_get_ns_fd(struct rtnl_link *); extern void rtnl_link_set_ns_pid(struct rtnl_link *, pid_t); extern pid_t rtnl_link_get_ns_pid(struct rtnl_link *); +extern struct nl_data * rtnl_link_get_perm_addr(struct rtnl_link *); + extern int rtnl_link_enslave_ifindex(struct nl_sock *, int, int); extern int rtnl_link_enslave(struct nl_sock *, struct rtnl_link *, struct rtnl_link *); diff --git a/lib/route/link.c b/lib/route/link.c index ce1355b9..3313f080 100644 --- a/lib/route/link.c +++ b/lib/route/link.c @@ -73,6 +73,7 @@ #define LINK_ATTR_GSO_MAX_SEGS ((uint64_t) 1 << 37) #define LINK_ATTR_GSO_MAX_SIZE ((uint64_t) 1 << 38) #define LINK_ATTR_LINKINFO_SLAVE_KIND ((uint64_t) 1 << 39) +#define LINK_ATTR_PERM_ADDR ((uint64_t) 1 << 40) static struct nl_cache_ops rtnl_link_ops; static struct nl_object_ops link_obj_ops; @@ -280,6 +281,8 @@ static void link_free_data(struct nl_object *c) nl_data_free(link->l_phys_port_id); nl_data_free(link->l_phys_switch_id); + nl_data_free(link->perm_addr); + if (link->ce_mask & LINK_ATTR_VF_LIST) rtnl_link_sriov_free_data(link); @@ -304,6 +307,7 @@ static int link_clone(struct nl_object *_dst, struct nl_object *_src) dst->l_phys_port_id = NULL; dst->l_phys_switch_id = NULL; dst->l_vf_list = NULL; + dst->perm_addr = NULL; if (src->l_addr) if (!(dst->l_addr = nl_addr_clone(src->l_addr))) @@ -355,6 +359,10 @@ static int link_clone(struct nl_object *_dst, struct nl_object *_src) if ((err = rtnl_link_sriov_clone(dst, src)) < 0) return err; + if (src->perm_addr) + if (!(dst->perm_addr = nl_data_clone(src->perm_addr))) + return -NLE_NOMEM; + return 0; } @@ -391,6 +399,7 @@ struct nla_policy rtln_link_policy[IFLA_MAX+1] = { [IFLA_PHYS_SWITCH_ID] = { .type = NLA_UNSPEC }, [IFLA_NET_NS_PID] = { .type = NLA_U32 }, [IFLA_NET_NS_FD] = { .type = NLA_U32 }, + [IFLA_PERM_ADDRESS] = { .type = NLA_BINARY }, }; static struct nla_policy link_info_policy[IFLA_INFO_MAX+1] = { @@ -592,6 +601,11 @@ int rtnl_link_info_parse(struct rtnl_link *link, struct nlattr **tb) link->ce_mask |= LINK_ATTR_NS_PID; } + if (tb[IFLA_PERM_ADDRESS]) { + link->perm_addr = nl_data_alloc_attr(tb[IFLA_PERM_ADDRESS]); + link->ce_mask |= LINK_ATTR_PERM_ADDR; + } + return 0; } @@ -945,6 +959,12 @@ static void link_dump_details(struct nl_object *obj, struct nl_dump_params *p) nl_dump(p, "brd %s ", nl_addr2str(link->l_bcast, buf, sizeof(buf))); + if (link->ce_mask & LINK_ATTR_PERM_ADDR) { + uint8_t *addr = nl_data_get(link->perm_addr); + nl_dump(p, "hw %x:%x:%x:%x:%x:%x ", addr[0], addr[1], addr[2], + addr[3], addr[4], addr[5]); + } + if ((link->ce_mask & LINK_ATTR_OPERSTATE) && link->l_operstate != IF_OPER_UNKNOWN) { rtnl_link_operstate2str(link->l_operstate, buf, sizeof(buf)); @@ -2823,6 +2843,17 @@ pid_t rtnl_link_get_ns_pid(struct rtnl_link *link) return link->l_ns_pid; } +/** + * Return permanent hardware address of link object + * @arg link Link object + * + * @return Permanent hardware address or NULL if not set. + */ +struct nl_data *rtnl_link_get_perm_addr(struct rtnl_link *link) +{ + return link->perm_addr; +} + /** @} */ /** diff --git a/lib/route/nl-route.h b/lib/route/nl-route.h index 28d01662..c27db1ca 100644 --- a/lib/route/nl-route.h +++ b/lib/route/nl-route.h @@ -73,6 +73,7 @@ struct rtnl_link { int l_ns_fd; pid_t l_ns_pid; struct rtnl_link_vf *l_vf_list; + struct nl_data * perm_addr; }; struct rtnl_nh_encap { diff --git a/libnl-route-3.sym b/libnl-route-3.sym index 7e36de1e..f054142b 100644 --- a/libnl-route-3.sym +++ b/libnl-route-3.sym @@ -1292,6 +1292,7 @@ global: rtnl_link_bridge_set_vlan_stats_enabled; rtnl_link_inet6_get_conf; rtnl_link_info_ops_get; + rtnl_link_get_perm_addr; rtnl_neigh_get_nhid; rtnl_neigh_set_nhid; rtnl_nh_alloc;