Skip to content

Commit f13f3b4

Browse files
idoschPaolo Abeni
authored andcommitted
vxlan: Introduce FDB key structure
In preparation for converting the FDB table to rhashtable, introduce a key structure that includes the MAC address and source VNI. No functional changes intended. Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20250415121143.345227-15-idosch@nvidia.com Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 20c76da commit f13f3b4

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

drivers/net/vxlan/vxlan_core.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
186186
} else if (nh) {
187187
ndm->ndm_family = nh_family;
188188
}
189-
send_eth = !is_zero_ether_addr(fdb->eth_addr);
189+
send_eth = !is_zero_ether_addr(fdb->key.eth_addr);
190190
} else
191191
ndm->ndm_family = AF_BRIDGE;
192192
ndm->ndm_state = fdb->state;
@@ -201,7 +201,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
201201
peernet2id(dev_net(vxlan->dev), vxlan->net)))
202202
goto nla_put_failure;
203203

204-
if (send_eth && nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->eth_addr))
204+
if (send_eth && nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->key.eth_addr))
205205
goto nla_put_failure;
206206
if (nh) {
207207
if (nla_put_u32(skb, NDA_NH_ID, nh_id))
@@ -223,9 +223,9 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
223223
goto nla_put_failure;
224224
}
225225

226-
if ((vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) && fdb->vni &&
226+
if ((vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) && fdb->key.vni &&
227227
nla_put_u32(skb, NDA_SRC_VNI,
228-
be32_to_cpu(fdb->vni)))
228+
be32_to_cpu(fdb->key.vni)))
229229
goto nla_put_failure;
230230

231231
ci.ndm_used = jiffies_to_clock_t(now - READ_ONCE(fdb->used));
@@ -293,8 +293,8 @@ static void vxlan_fdb_switchdev_notifier_info(const struct vxlan_dev *vxlan,
293293
fdb_info->remote_port = rd->remote_port;
294294
fdb_info->remote_vni = rd->remote_vni;
295295
fdb_info->remote_ifindex = rd->remote_ifindex;
296-
memcpy(fdb_info->eth_addr, fdb->eth_addr, ETH_ALEN);
297-
fdb_info->vni = fdb->vni;
296+
memcpy(fdb_info->eth_addr, fdb->key.eth_addr, ETH_ALEN);
297+
fdb_info->vni = fdb->key.vni;
298298
fdb_info->offloaded = rd->offloaded;
299299
fdb_info->added_by_user = fdb->flags & NTF_VXLAN_ADDED_BY_USER;
300300
}
@@ -366,7 +366,7 @@ static void vxlan_fdb_miss(struct vxlan_dev *vxlan, const u8 eth_addr[ETH_ALEN])
366366
};
367367
struct vxlan_rdst remote = { };
368368

369-
memcpy(f.eth_addr, eth_addr, ETH_ALEN);
369+
memcpy(f.key.eth_addr, eth_addr, ETH_ALEN);
370370

371371
vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH, true, NULL);
372372
}
@@ -416,9 +416,9 @@ static struct vxlan_fdb *vxlan_find_mac_rcu(struct vxlan_dev *vxlan,
416416
struct vxlan_fdb *f;
417417

418418
hlist_for_each_entry_rcu(f, head, hlist) {
419-
if (ether_addr_equal(mac, f->eth_addr)) {
419+
if (ether_addr_equal(mac, f->key.eth_addr)) {
420420
if (vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) {
421-
if (vni == f->vni)
421+
if (vni == f->key.vni)
422422
return f;
423423
} else {
424424
return f;
@@ -539,7 +539,7 @@ int vxlan_fdb_replay(const struct net_device *dev, __be32 vni,
539539

540540
spin_lock_bh(&vxlan->hash_lock);
541541
hlist_for_each_entry(f, &vxlan->fdb_list, fdb_node) {
542-
if (f->vni == vni) {
542+
if (f->key.vni == vni) {
543543
list_for_each_entry(rdst, &f->remotes, list) {
544544
rc = vxlan_fdb_notify_one(nb, vxlan, f, rdst,
545545
extack);
@@ -569,7 +569,7 @@ void vxlan_fdb_clear_offload(const struct net_device *dev, __be32 vni)
569569

570570
spin_lock_bh(&vxlan->hash_lock);
571571
hlist_for_each_entry(f, &vxlan->fdb_list, fdb_node) {
572-
if (f->vni == vni) {
572+
if (f->key.vni == vni) {
573573
list_for_each_entry(rdst, &f->remotes, list)
574574
rdst->offloaded = false;
575575
}
@@ -812,15 +812,16 @@ static struct vxlan_fdb *vxlan_fdb_alloc(struct vxlan_dev *vxlan, const u8 *mac,
812812
f = kmalloc(sizeof(*f), GFP_ATOMIC);
813813
if (!f)
814814
return NULL;
815+
memset(&f->key, 0, sizeof(f->key));
815816
f->state = state;
816817
f->flags = ndm_flags;
817818
f->updated = f->used = jiffies;
818-
f->vni = src_vni;
819+
f->key.vni = src_vni;
819820
f->nh = NULL;
820821
RCU_INIT_POINTER(f->vdev, vxlan);
821822
INIT_LIST_HEAD(&f->nh_list);
822823
INIT_LIST_HEAD(&f->remotes);
823-
memcpy(f->eth_addr, mac, ETH_ALEN);
824+
memcpy(f->key.eth_addr, mac, ETH_ALEN);
824825

825826
return f;
826827
}
@@ -959,7 +960,7 @@ static void vxlan_fdb_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f,
959960
{
960961
struct vxlan_rdst *rd;
961962

962-
netdev_dbg(vxlan->dev, "delete %pM\n", f->eth_addr);
963+
netdev_dbg(vxlan->dev, "delete %pM\n", f->key.eth_addr);
963964

964965
--vxlan->addrcnt;
965966
if (do_notify) {
@@ -1031,8 +1032,8 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,
10311032

10321033
if ((flags & NLM_F_REPLACE)) {
10331034
/* Only change unicasts */
1034-
if (!(is_multicast_ether_addr(f->eth_addr) ||
1035-
is_zero_ether_addr(f->eth_addr))) {
1035+
if (!(is_multicast_ether_addr(f->key.eth_addr) ||
1036+
is_zero_ether_addr(f->key.eth_addr))) {
10361037
if (nhid) {
10371038
rc = vxlan_fdb_nh_update(vxlan, f, nhid, extack);
10381039
if (rc < 0)
@@ -1048,8 +1049,8 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,
10481049
}
10491050
}
10501051
if ((flags & NLM_F_APPEND) &&
1051-
(is_multicast_ether_addr(f->eth_addr) ||
1052-
is_zero_ether_addr(f->eth_addr))) {
1052+
(is_multicast_ether_addr(f->key.eth_addr) ||
1053+
is_zero_ether_addr(f->key.eth_addr))) {
10531054
rc = vxlan_fdb_append(f, ip, port, vni, ifindex, &rd);
10541055

10551056
if (rc < 0)
@@ -2853,7 +2854,7 @@ static void vxlan_cleanup(struct timer_list *t)
28532854
spin_lock(&vxlan->hash_lock);
28542855
if (!hlist_unhashed(&f->fdb_node)) {
28552856
netdev_dbg(vxlan->dev, "garbage collect %pM\n",
2856-
f->eth_addr);
2857+
f->key.eth_addr);
28572858
f->state = NUD_STALE;
28582859
vxlan_fdb_destroy(vxlan, f, true, true);
28592860
}
@@ -2972,7 +2973,8 @@ struct vxlan_fdb_flush_desc {
29722973
static bool vxlan_fdb_is_default_entry(const struct vxlan_fdb *f,
29732974
const struct vxlan_dev *vxlan)
29742975
{
2975-
return is_zero_ether_addr(f->eth_addr) && f->vni == vxlan->cfg.vni;
2976+
return is_zero_ether_addr(f->key.eth_addr) &&
2977+
f->key.vni == vxlan->cfg.vni;
29762978
}
29772979

29782980
static bool vxlan_fdb_nhid_matches(const struct vxlan_fdb *f, u32 nhid)
@@ -2995,7 +2997,7 @@ static bool vxlan_fdb_flush_matches(const struct vxlan_fdb *f,
29952997
if (desc->ignore_default_entry && vxlan_fdb_is_default_entry(f, vxlan))
29962998
return false;
29972999

2998-
if (desc->src_vni && f->vni != desc->src_vni)
3000+
if (desc->src_vni && f->key.vni != desc->src_vni)
29993001
return false;
30003002

30013003
if (desc->nhid && !vxlan_fdb_nhid_matches(f, desc->nhid))

drivers/net/vxlan/vxlan_private.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@ struct vxlan_net {
2424
struct notifier_block nexthop_notifier_block;
2525
};
2626

27+
struct vxlan_fdb_key {
28+
u8 eth_addr[ETH_ALEN];
29+
__be32 vni;
30+
};
31+
2732
/* Forwarding table entry */
2833
struct vxlan_fdb {
2934
struct hlist_node hlist; /* linked list of entries */
3035
struct rcu_head rcu;
3136
unsigned long updated; /* jiffies */
3237
unsigned long used;
3338
struct list_head remotes;
34-
u8 eth_addr[ETH_ALEN];
39+
struct vxlan_fdb_key key;
3540
u16 state; /* see ndm_state */
36-
__be32 vni;
3741
u16 flags; /* see ndm_flags and below */
3842
struct list_head nh_list;
3943
struct hlist_node fdb_node;

0 commit comments

Comments
 (0)