Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

route: support for retrieving a link's permanent address. #362

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/netlink/route/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
31 changes: 31 additions & 0 deletions lib/route/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)))
Expand Down Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please squash the commits. This second commit just fixes a bug in the previous commit.


return 0;
}

Expand Down Expand Up @@ -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] = {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot blindly access the addr array. Must make sure that there are 6 elements there (and do something in case there isn't).

}

if ((link->ce_mask & LINK_ATTR_OPERSTATE) &&
link->l_operstate != IF_OPER_UNKNOWN) {
rtnl_link_operstate2str(link->l_operstate, buf, sizeof(buf));
Expand Down Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compare to rtnl_link_get_addr. That one returns a struct nl_addr type. I think that should also be used for the perm-addr, or why not?

{
return link->perm_addr;
}

/** @} */

/**
Expand Down
1 change: 1 addition & 0 deletions lib/route/nl-route.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also needs to be handled in link_compare().

};

struct rtnl_nh_encap {
Expand Down
1 change: 1 addition & 0 deletions libnl-route-3.sym
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.8 is already released. That means the section "libnl_3_8" must not be changed anymore.

Add a new libnl_3_9 section at the bottom of the file.

rtnl_neigh_get_nhid;
rtnl_neigh_set_nhid;
rtnl_nh_alloc;
Expand Down