Skip to content

Commit e29352f

Browse files
borkmanngregkh
authored andcommitted
net, neigh: Fix NTF_EXT_LEARNED in combination with NTF_USE
[ Upstream commit e4400bb ] The NTF_EXT_LEARNED neigh flag is usually propagated back to user space upon dump of the neighbor table. However, when used in combination with NTF_USE flag this is not the case despite exempting the entry from the garbage collector. This results in inconsistent state since entries are typically marked in neigh->flags with NTF_EXT_LEARNED, but here they are not. Fix it by propagating the creation flag to ___neigh_create(). Before fix: # ./ip/ip n replace 192.168.178.30 dev enp5s0 use extern_learn # ./ip/ip n 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a REACHABLE [...] After fix: # ./ip/ip n replace 192.168.178.30 dev enp5s0 use extern_learn # ./ip/ip n 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a extern_learn REACHABLE [...] Fixes: 9ce33e4 ("neighbour: support for NTF_EXT_LEARNED flag") Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Roopa Prabhu <roopa@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 41fe79c commit e29352f

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

‎net/core/neighbour.c‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ EXPORT_SYMBOL(neigh_ifdown);
380380

381381
static struct neighbour *neigh_alloc(struct neigh_table *tbl,
382382
struct net_device *dev,
383-
bool exempt_from_gc)
383+
u8 flags, bool exempt_from_gc)
384384
{
385385
struct neighbour *n = NULL;
386386
unsigned long now = jiffies;
@@ -413,6 +413,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl,
413413
n->updated = n->used = now;
414414
n->nud_state = NUD_NONE;
415415
n->output = neigh_blackhole;
416+
n->flags = flags;
416417
seqlock_init(&n->hh.hh_lock);
417418
n->parms = neigh_parms_clone(&tbl->parms);
418419
timer_setup(&n->timer, neigh_timer_handler, 0);
@@ -576,19 +577,18 @@ struct neighbour *neigh_lookup_nodev(struct neigh_table *tbl, struct net *net,
576577
}
577578
EXPORT_SYMBOL(neigh_lookup_nodev);
578579

579-
static struct neighbour *___neigh_create(struct neigh_table *tbl,
580-
const void *pkey,
581-
struct net_device *dev,
582-
bool exempt_from_gc, bool want_ref)
580+
static struct neighbour *
581+
___neigh_create(struct neigh_table *tbl, const void *pkey,
582+
struct net_device *dev, u8 flags,
583+
bool exempt_from_gc, bool want_ref)
583584
{
584-
struct neighbour *n1, *rc, *n = neigh_alloc(tbl, dev, exempt_from_gc);
585-
u32 hash_val;
586-
unsigned int key_len = tbl->key_len;
587-
int error;
585+
u32 hash_val, key_len = tbl->key_len;
586+
struct neighbour *n1, *rc, *n;
588587
struct neigh_hash_table *nht;
588+
int error;
589589

590+
n = neigh_alloc(tbl, dev, flags, exempt_from_gc);
590591
trace_neigh_create(tbl, dev, pkey, n, exempt_from_gc);
591-
592592
if (!n) {
593593
rc = ERR_PTR(-ENOBUFS);
594594
goto out;
@@ -675,7 +675,7 @@ static struct neighbour *___neigh_create(struct neigh_table *tbl,
675675
struct neighbour *__neigh_create(struct neigh_table *tbl, const void *pkey,
676676
struct net_device *dev, bool want_ref)
677677
{
678-
return ___neigh_create(tbl, pkey, dev, false, want_ref);
678+
return ___neigh_create(tbl, pkey, dev, 0, false, want_ref);
679679
}
680680
EXPORT_SYMBOL(__neigh_create);
681681

@@ -1950,7 +1950,9 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
19501950

19511951
exempt_from_gc = ndm->ndm_state & NUD_PERMANENT ||
19521952
ndm->ndm_flags & NTF_EXT_LEARNED;
1953-
neigh = ___neigh_create(tbl, dst, dev, exempt_from_gc, true);
1953+
neigh = ___neigh_create(tbl, dst, dev,
1954+
ndm->ndm_flags & NTF_EXT_LEARNED,
1955+
exempt_from_gc, true);
19541956
if (IS_ERR(neigh)) {
19551957
err = PTR_ERR(neigh);
19561958
goto out;

0 commit comments

Comments
 (0)