Skip to content

Commit 3dc20f4

Browse files
borkmanndavem330
authored andcommitted
net, neigh: Enable state migration between NUD_PERMANENT and NTF_USE
Currently, it is not possible to migrate a neighbor entry between NUD_PERMANENT state and NTF_USE flag with a dynamic NUD state from a user space control plane. Similarly, it is not possible to add/remove NTF_EXT_LEARNED flag from an existing neighbor entry in combination with NTF_USE flag. This is due to the latter directly calling into neigh_event_send() without any meta data updates as happening in __neigh_update(). Thus, to enable this use case, extend the latter with a NEIGH_UPDATE_F_USE flag where we break the NUD_PERMANENT state in particular so that a latter neigh_event_send() is able to re-resolve a neighbor entry. Before fix, NUD_PERMANENT -> NUD_* & NTF_USE: # ./ip/ip n replace 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a # ./ip/ip n 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a PERMANENT [...] # ./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 PERMANENT [...] As can be seen, despite the admin-triggered replace, the entry remains in the NUD_PERMANENT state. After fix, NUD_PERMANENT -> NUD_* & NTF_USE: # ./ip/ip n replace 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a # ./ip/ip n 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a PERMANENT [...] # ./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 [...] # ./ip/ip n 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a extern_learn STALE [...] # ./ip/ip n replace 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a # ./ip/ip n 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a PERMANENT [...] After the fix, the admin-triggered replace switches to a dynamic state from the NTF_USE flag which triggered a new neighbor resolution. Likewise, we can transition back from there, if needed, into NUD_PERMANENT. Similar before/after behavior can be observed for below transitions: Before fix, NTF_USE -> NTF_USE | NTF_EXT_LEARNED -> NTF_USE: # ./ip/ip n replace 192.168.178.30 dev enp5s0 use # ./ip/ip n 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a REACHABLE [...] # ./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, NTF_USE -> NTF_USE | NTF_EXT_LEARNED -> NTF_USE: # ./ip/ip n replace 192.168.178.30 dev enp5s0 use # ./ip/ip n 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a REACHABLE [...] # ./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 [...] # ./ip/ip n replace 192.168.178.30 dev enp5s0 use # ./ip/ip n 192.168.178.30 dev enp5s0 lladdr f4:8c:50:5e:71:9a REACHABLE [..] Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Roopa Prabhu <roopa@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e4400bb commit 3dc20f4

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

include/net/neighbour.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ static inline void *neighbour_priv(const struct neighbour *n)
253253
#define NEIGH_UPDATE_F_OVERRIDE 0x00000001
254254
#define NEIGH_UPDATE_F_WEAK_OVERRIDE 0x00000002
255255
#define NEIGH_UPDATE_F_OVERRIDE_ISROUTER 0x00000004
256+
#define NEIGH_UPDATE_F_USE 0x10000000
256257
#define NEIGH_UPDATE_F_EXT_LEARNED 0x20000000
257258
#define NEIGH_UPDATE_F_ISROUTER 0x40000000
258259
#define NEIGH_UPDATE_F_ADMIN 0x80000000

net/core/neighbour.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ static void neigh_update_hhs(struct neighbour *neigh)
12171217
lladdr instead of overriding it
12181218
if it is different.
12191219
NEIGH_UPDATE_F_ADMIN means that the change is administrative.
1220-
1220+
NEIGH_UPDATE_F_USE means that the entry is user triggered.
12211221
NEIGH_UPDATE_F_OVERRIDE_ISROUTER allows to override existing
12221222
NTF_ROUTER flag.
12231223
NEIGH_UPDATE_F_ISROUTER indicates if the neighbour is known as
@@ -1255,6 +1255,12 @@ static int __neigh_update(struct neighbour *neigh, const u8 *lladdr,
12551255
goto out;
12561256

12571257
ext_learn_change = neigh_update_ext_learned(neigh, flags, &notify);
1258+
if (flags & NEIGH_UPDATE_F_USE) {
1259+
new = old & ~NUD_PERMANENT;
1260+
neigh->nud_state = new;
1261+
err = 0;
1262+
goto out;
1263+
}
12581264

12591265
if (!(new & NUD_VALID)) {
12601266
neigh_del_timer(neigh);
@@ -1963,22 +1969,20 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
19631969

19641970
if (protocol)
19651971
neigh->protocol = protocol;
1966-
19671972
if (ndm->ndm_flags & NTF_EXT_LEARNED)
19681973
flags |= NEIGH_UPDATE_F_EXT_LEARNED;
1969-
19701974
if (ndm->ndm_flags & NTF_ROUTER)
19711975
flags |= NEIGH_UPDATE_F_ISROUTER;
1976+
if (ndm->ndm_flags & NTF_USE)
1977+
flags |= NEIGH_UPDATE_F_USE;
19721978

1973-
if (ndm->ndm_flags & NTF_USE) {
1979+
err = __neigh_update(neigh, lladdr, ndm->ndm_state, flags,
1980+
NETLINK_CB(skb).portid, extack);
1981+
if (!err && ndm->ndm_flags & NTF_USE) {
19741982
neigh_event_send(neigh, NULL);
19751983
err = 0;
1976-
} else
1977-
err = __neigh_update(neigh, lladdr, ndm->ndm_state, flags,
1978-
NETLINK_CB(skb).portid, extack);
1979-
1984+
}
19801985
neigh_release(neigh);
1981-
19821986
out:
19831987
return err;
19841988
}

0 commit comments

Comments
 (0)