neigh: add support for NDA_VLAN nl attribute

[thaller@redhat.com: modified patch to parse NDA_VLAN and diff vlan]

http://lists.infradead.org/pipermail/libnl/2015-March/001861.html

Signed-off-by: Jonas Johansson <jonasj76@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Jonas Johansson 2015-03-19 20:15:52 +01:00 committed by Thomas Haller
parent c242e25c45
commit 31d7d19393
5 changed files with 33 additions and 0 deletions

View file

@ -20,6 +20,7 @@ enum {
NDA_LLADDR,
NDA_CACHEINFO,
NDA_PROBES,
NDA_VLAN,
__NDA_MAX
};

View file

@ -220,6 +220,7 @@ struct rtnl_neigh
uint32_t n_state_mask;
uint32_t n_flag_mask;
uint32_t n_master;
uint16_t n_vlan;
};

View file

@ -74,6 +74,9 @@ extern int rtnl_neigh_get_type(struct rtnl_neigh *);
extern void rtnl_neigh_set_family(struct rtnl_neigh *, int);
extern int rtnl_neigh_get_family(struct rtnl_neigh *);
extern void rtnl_neigh_set_vlan(struct rtnl_neigh *, int);
extern int rtnl_neigh_get_vlan(struct rtnl_neigh *);
#ifdef __cplusplus
}
#endif

View file

@ -168,6 +168,7 @@
#define NEIGH_ATTR_TYPE 0x80
#define NEIGH_ATTR_PROBES 0x100
#define NEIGH_ATTR_MASTER 0x200
#define NEIGH_ATTR_VLAN 0x400
static struct nl_cache_ops rtnl_neigh_ops;
static struct nl_object_ops neigh_obj_ops;
@ -268,6 +269,7 @@ static int neigh_compare(struct nl_object *_a, struct nl_object *_b,
diff |= NEIGH_DIFF(LLADDR, nl_addr_cmp(a->n_lladdr, b->n_lladdr));
diff |= NEIGH_DIFF(DST, nl_addr_cmp(a->n_dst, b->n_dst));
diff |= NEIGH_DIFF(MASTER, a->n_master != b->n_master);
diff |= NEIGH_DIFF(VLAN, a->n_vlan != b->n_vlan);
if (flags & LOOSE_COMPARISON) {
diff |= NEIGH_DIFF(STATE,
@ -294,6 +296,8 @@ static const struct trans_tbl neigh_attrs[] = {
__ADD(NEIGH_ATTR_FAMILY, family),
__ADD(NEIGH_ATTR_TYPE, type),
__ADD(NEIGH_ATTR_PROBES, probes),
__ADD(NEIGH_ATTR_MASTER, master),
__ADD(NEIGH_ATTR_VLAN, vlan),
};
static char *neigh_attrs2str(int attrs, char *buf, size_t len)
@ -399,6 +403,11 @@ int rtnl_neigh_parse(struct nlmsghdr *n, struct rtnl_neigh **result)
neigh->ce_mask |= NEIGH_ATTR_PROBES;
}
if (tb[NDA_VLAN]) {
neigh->n_vlan = nla_get_u16(tb[NDA_VLAN]);
neigh->ce_mask |= NEIGH_ATTR_VLAN;
}
/*
* Get the bridge index for AF_BRIDGE family entries
*/
@ -596,6 +605,9 @@ static int build_neigh_msg(struct rtnl_neigh *tmpl, int cmd, int flags,
if (tmpl->ce_mask & NEIGH_ATTR_LLADDR)
NLA_PUT_ADDR(msg, NDA_LLADDR, tmpl->n_lladdr);
if (tmpl->ce_mask & NEIGH_ATTR_VLAN)
NLA_PUT_U16(msg, NDA_VLAN, tmpl->n_vlan);
*result = msg;
return 0;
@ -908,6 +920,20 @@ int rtnl_neigh_get_type(struct rtnl_neigh *neigh)
return -1;
}
void rtnl_neigh_set_vlan(struct rtnl_neigh *neigh, int vlan)
{
neigh->n_vlan = vlan;
neigh->ce_mask |= NEIGH_ATTR_VLAN;
}
int rtnl_neigh_get_vlan(struct rtnl_neigh *neigh)
{
if (neigh->ce_mask & NEIGH_ATTR_VLAN)
return neigh->n_vlan;
else
return -1;
}
/** @} */
static struct nl_object_ops neigh_obj_ops = {

View file

@ -858,6 +858,8 @@ local:
libnl_3_2_26 {
global:
rtnl_neigh_get_vlan;
rtnl_neigh_set_vlan;
rtnl_skbedit_get_action;
rtnl_skbedit_get_mark;
rtnl_skbedit_get_priority;