Skip to content

Commit

Permalink
route/link: add accessor API for IPv6 flags
Browse files Browse the repository at this point in the history
Add functions to access the IPv6 specific flags of a link object.
Also the functions for IPv6 link flags translation are now exported, similar
to the non IPv6 specific translation functions.

#136
  • Loading branch information
Markus Trapp authored and thom311 committed May 3, 2017
1 parent 8aca21d commit b9a5a83
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
10 changes: 10 additions & 0 deletions include/netlink/route/link/inet6.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ extern int rtnl_link_inet6_get_addr_gen_mode(struct rtnl_link *,
extern int rtnl_link_inet6_set_addr_gen_mode(struct rtnl_link *,
uint8_t);

extern int rtnl_link_inet6_get_flags(struct rtnl_link *,
uint32_t *);

extern int rtnl_link_inet6_set_flags(struct rtnl_link *,
uint32_t);

/* Link Flags Translations */
extern char * rtnl_link_inet6_flags2str(int, char *, size_t);
extern int rtnl_link_inet6_str2flags(const char *);

#ifdef __cplusplus
}
#endif
Expand Down
51 changes: 49 additions & 2 deletions lib/route/link/inet6.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,17 @@ static const struct trans_tbl inet6_flags[] = {
__ADD(IF_READY, ready),
};

static char *inet6_flags2str(int flags, char *buf, size_t len)
char *rtnl_link_inet6_flags2str(int flags, char *buf, size_t len)
{
return __flags2str(flags, buf, len, inet6_flags,
ARRAY_SIZE(inet6_flags));
}

int rtnl_link_inet6_str2flags(const char *name)
{
return __str2flags(name, inet6_flags, ARRAY_SIZE(inet6_flags));
}

static const struct trans_tbl inet6_devconf[] = {
__ADD(DEVCONF_FORWARDING, forwarding),
__ADD(DEVCONF_HOPLIMIT, hoplimit),
Expand Down Expand Up @@ -322,7 +327,7 @@ static void inet6_dump_details(struct rtnl_link *link,
nl_size2str(i6->i6_cacheinfo.max_reasm_len, buf, sizeof(buf)));

nl_dump(p, " <%s>\n",
inet6_flags2str(i6->i6_flags, buf, sizeof(buf)));
rtnl_link_inet6_flags2str(i6->i6_flags, buf, sizeof(buf)));


nl_dump_line(p, " create-stamp %.2fs reachable-time %s",
Expand Down Expand Up @@ -534,6 +539,48 @@ static struct rtnl_link_af_ops inet6_ops = {
.ao_protinfo_policy = &protinfo_policy,
};

/**
* Return IPv6 specific flags
* @arg link Link object
* @arg out_flags Flags on success
*
* Returns the link's IPv6 flags.
*
* @return 0 on success
* @return -NLE_NOATTR configuration setting not available
*/
int rtnl_link_inet6_get_flags(struct rtnl_link *link, uint32_t* out_flags)
{
struct inet6_data *id = NULL;

if (!(id = rtnl_link_af_data(link, &inet6_ops)))
return -NLE_NOATTR;

*out_flags = id->i6_flags;
return 0;
}

/**
* Set IPv6 specific flags
* @arg link Link object
* @arg flags Flags to set
*
* Sets the link's IPv6 specific flags. Overwrites currently set flags.
*
* @return 0 on success
* @return -NLE_NOMEM could not allocate inet6 data
*/
int rtnl_link_inet6_set_flags(struct rtnl_link *link, uint32_t flags)
{
struct inet6_data *id;

if (!(id = rtnl_link_af_alloc(link, &inet6_ops)))
return -NLE_NOMEM;

id->i6_flags = flags;
return 0;
}

/**
* Get IPv6 tokenized interface identifier
* @arg link Link object
Expand Down
7 changes: 7 additions & 0 deletions libnl-route-3.sym
Original file line number Diff line number Diff line change
Expand Up @@ -1032,3 +1032,10 @@ global:
rtnl_u32_set_selector;
} libnl_3_2_28;

libnl_3_4 {
global:
rtnl_link_inet6_flags2str;
rtnl_link_inet6_str2flags;
rtnl_link_inet6_get_flags;
rtnl_link_inet6_set_flags;
} libnl_3_2_29;

0 comments on commit b9a5a83

Please sign in to comment.