Skip to content

Commit

Permalink
neighbor: Add protocol attribute
Browse files Browse the repository at this point in the history
Similar to routes and rules, add protocol attribute to neighbor entries
for easier tracking of how each was created.

Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David Ahern authored and David S. Miller committed Dec 16, 2018
1 parent 11fb60d commit df9b0e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/net/neighbour.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ struct neighbour {
__u8 nud_state;
__u8 type;
__u8 dead;
u8 protocol;
seqlock_t ha_lock;
unsigned char ha[ALIGN(MAX_ADDR_LEN, sizeof(unsigned long))] __aligned(8);
struct hh_cache hh;
Expand All @@ -173,6 +174,7 @@ struct pneigh_entry {
possible_net_t net;
struct net_device *dev;
u8 flags;
u8 protocol;
u8 key[0];
};

Expand Down
1 change: 1 addition & 0 deletions include/uapi/linux/neighbour.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum {
NDA_MASTER,
NDA_LINK_NETNSID,
NDA_SRC_VNI,
NDA_PROTOCOL, /* Originator of entry */
__NDA_MAX
};

Expand Down
24 changes: 23 additions & 1 deletion net/core/neighbour.c
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,7 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
struct net_device *dev = NULL;
struct neighbour *neigh;
void *dst, *lladdr;
u8 protocol = 0;
int err;

ASSERT_RTNL();
Expand Down Expand Up @@ -1867,13 +1868,23 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
dst = nla_data(tb[NDA_DST]);
lladdr = tb[NDA_LLADDR] ? nla_data(tb[NDA_LLADDR]) : NULL;

if (tb[NDA_PROTOCOL]) {
if (nla_len(tb[NDA_PROTOCOL]) != sizeof(u8)) {
NL_SET_ERR_MSG(extack, "Invalid protocol attribute");
goto out;
}
protocol = nla_get_u8(tb[NDA_PROTOCOL]);
}

if (ndm->ndm_flags & NTF_PROXY) {
struct pneigh_entry *pn;

err = -ENOBUFS;
pn = pneigh_lookup(tbl, net, dst, dev, 1);
if (pn) {
pn->flags = ndm->ndm_flags;
if (protocol)
pn->protocol = protocol;
err = 0;
}
goto out;
Expand Down Expand Up @@ -1924,6 +1935,10 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
} else
err = __neigh_update(neigh, lladdr, ndm->ndm_state, flags,
NETLINK_CB(skb).portid, extack);

if (protocol)
neigh->protocol = protocol;

neigh_release(neigh);

out:
Expand Down Expand Up @@ -2417,6 +2432,9 @@ static int neigh_fill_info(struct sk_buff *skb, struct neighbour *neigh,
nla_put(skb, NDA_CACHEINFO, sizeof(ci), &ci))
goto nla_put_failure;

if (neigh->protocol && nla_put_u8(skb, NDA_PROTOCOL, neigh->protocol))
goto nla_put_failure;

nlmsg_end(skb, nlh);
return 0;

Expand Down Expand Up @@ -2448,6 +2466,9 @@ static int pneigh_fill_info(struct sk_buff *skb, struct pneigh_entry *pn,
if (nla_put(skb, NDA_DST, tbl->key_len, pn->key))
goto nla_put_failure;

if (pn->protocol && nla_put_u8(skb, NDA_PROTOCOL, pn->protocol))
goto nla_put_failure;

nlmsg_end(skb, nlh);
return 0;

Expand Down Expand Up @@ -3103,7 +3124,8 @@ static inline size_t neigh_nlmsg_size(void)
+ nla_total_size(MAX_ADDR_LEN) /* NDA_DST */
+ nla_total_size(MAX_ADDR_LEN) /* NDA_LLADDR */
+ nla_total_size(sizeof(struct nda_cacheinfo))
+ nla_total_size(4); /* NDA_PROBES */
+ nla_total_size(4) /* NDA_PROBES */
+ nla_total_size(1); /* NDA_PROTOCOL */
}

static void __neigh_notify(struct neighbour *n, int type, int flags,
Expand Down

0 comments on commit df9b0e3

Please sign in to comment.