Skip to content

Commit 0f83e69

Browse files
idoschdavem330
authored andcommitted
vxlan: Add MDB data path support
Integrate MDB support into the Tx path of the VXLAN driver, allowing it to selectively forward IP multicast traffic according to the matched MDB entry. If MDB entries are configured (i.e., 'VXLAN_F_MDB' is set) and the packet is an IP multicast packet, perform up to three different lookups according to the following priority: 1. For an (S, G) entry, using {Source VNI, Source IP, Destination IP}. 2. For a (*, G) entry, using {Source VNI, Destination IP}. 3. For the catchall MDB entry (0.0.0.0 or ::), using the source VNI. The catchall MDB entry is similar to the catchall FDB entry (00:00:00:00:00:00) that is currently used to transmit BUM (broadcast, unknown unicast and multicast) traffic. However, unlike the catchall FDB entry, this entry is only used to transmit unregistered IP multicast traffic that is not link-local. Therefore, when configured, the catchall FDB entry will only transmit BULL (broadcast, unknown unicast, link-local multicast) traffic. The catchall MDB entry is useful in deployments where inter-subnet multicast forwarding is used and not all the VTEPs in a tenant domain are members in all the broadcast domains. In such deployments it is advantageous to transmit BULL (broadcast, unknown unicast and link-local multicast) and unregistered IP multicast traffic on different tunnels. If the same tunnel was used, a VTEP only interested in IP multicast traffic would also pull all the BULL traffic and drop it as it is not a member in the originating broadcast domain [1]. If the packet did not match an MDB entry (or if the packet is not an IP multicast packet), return it to the Tx path, allowing it to be forwarded according to the FDB. If the packet did match an MDB entry, forward it to the associated remote VTEPs. However, if the entry is a (*, G) entry and the associated remote is in INCLUDE mode, then skip over it as the source IP is not in its source list (otherwise the packet would have matched on an (S, G) entry). Similarly, if the associated remote is marked as BLOCKED (can only be set on (S, G) entries), then skip over it as well as the remote is in EXCLUDE mode and the source IP is in its source list. [1] https://datatracker.ietf.org/doc/html/draft-ietf-bess-evpn-irb-mcast#section-2.6 Signed-off-by: Ido Schimmel <[email protected]> Reviewed-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bc6c6b0 commit 0f83e69

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

drivers/net/vxlan/vxlan_core.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,21 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)
27432743
#endif
27442744
}
27452745

2746+
if (vxlan->cfg.flags & VXLAN_F_MDB) {
2747+
struct vxlan_mdb_entry *mdb_entry;
2748+
2749+
rcu_read_lock();
2750+
mdb_entry = vxlan_mdb_entry_skb_get(vxlan, skb, vni);
2751+
if (mdb_entry) {
2752+
netdev_tx_t ret;
2753+
2754+
ret = vxlan_mdb_xmit(vxlan, mdb_entry, skb);
2755+
rcu_read_unlock();
2756+
return ret;
2757+
}
2758+
rcu_read_unlock();
2759+
}
2760+
27462761
eth = eth_hdr(skb);
27472762
f = vxlan_find_mac(vxlan, eth->h_dest, vni);
27482763
did_rsc = false;

drivers/net/vxlan/vxlan_mdb.c

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,120 @@ int vxlan_mdb_del(struct net_device *dev, struct nlattr *tb[],
12981298
return err;
12991299
}
13001300

1301+
struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan,
1302+
struct sk_buff *skb,
1303+
__be32 src_vni)
1304+
{
1305+
struct vxlan_mdb_entry *mdb_entry;
1306+
struct vxlan_mdb_entry_key group;
1307+
1308+
if (!is_multicast_ether_addr(eth_hdr(skb)->h_dest) ||
1309+
is_broadcast_ether_addr(eth_hdr(skb)->h_dest))
1310+
return NULL;
1311+
1312+
/* When not in collect metadata mode, 'src_vni' is zero, but MDB
1313+
* entries are stored with the VNI of the VXLAN device.
1314+
*/
1315+
if (!(vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA))
1316+
src_vni = vxlan->default_dst.remote_vni;
1317+
1318+
memset(&group, 0, sizeof(group));
1319+
group.vni = src_vni;
1320+
1321+
switch (skb->protocol) {
1322+
case htons(ETH_P_IP):
1323+
if (!pskb_may_pull(skb, sizeof(struct iphdr)))
1324+
return NULL;
1325+
group.dst.sa.sa_family = AF_INET;
1326+
group.dst.sin.sin_addr.s_addr = ip_hdr(skb)->daddr;
1327+
group.src.sa.sa_family = AF_INET;
1328+
group.src.sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
1329+
break;
1330+
#if IS_ENABLED(CONFIG_IPV6)
1331+
case htons(ETH_P_IPV6):
1332+
if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
1333+
return NULL;
1334+
group.dst.sa.sa_family = AF_INET6;
1335+
group.dst.sin6.sin6_addr = ipv6_hdr(skb)->daddr;
1336+
group.src.sa.sa_family = AF_INET6;
1337+
group.src.sin6.sin6_addr = ipv6_hdr(skb)->saddr;
1338+
break;
1339+
#endif
1340+
default:
1341+
return NULL;
1342+
}
1343+
1344+
mdb_entry = vxlan_mdb_entry_lookup(vxlan, &group);
1345+
if (mdb_entry)
1346+
return mdb_entry;
1347+
1348+
memset(&group.src, 0, sizeof(group.src));
1349+
mdb_entry = vxlan_mdb_entry_lookup(vxlan, &group);
1350+
if (mdb_entry)
1351+
return mdb_entry;
1352+
1353+
/* No (S, G) or (*, G) found. Look up the all-zeros entry, but only if
1354+
* the destination IP address is not link-local multicast since we want
1355+
* to transmit such traffic together with broadcast and unknown unicast
1356+
* traffic.
1357+
*/
1358+
switch (skb->protocol) {
1359+
case htons(ETH_P_IP):
1360+
if (ipv4_is_local_multicast(group.dst.sin.sin_addr.s_addr))
1361+
return NULL;
1362+
group.dst.sin.sin_addr.s_addr = 0;
1363+
break;
1364+
#if IS_ENABLED(CONFIG_IPV6)
1365+
case htons(ETH_P_IPV6):
1366+
if (ipv6_addr_type(&group.dst.sin6.sin6_addr) &
1367+
IPV6_ADDR_LINKLOCAL)
1368+
return NULL;
1369+
memset(&group.dst.sin6.sin6_addr, 0,
1370+
sizeof(group.dst.sin6.sin6_addr));
1371+
break;
1372+
#endif
1373+
default:
1374+
return NULL;
1375+
}
1376+
1377+
return vxlan_mdb_entry_lookup(vxlan, &group);
1378+
}
1379+
1380+
netdev_tx_t vxlan_mdb_xmit(struct vxlan_dev *vxlan,
1381+
const struct vxlan_mdb_entry *mdb_entry,
1382+
struct sk_buff *skb)
1383+
{
1384+
struct vxlan_mdb_remote *remote, *fremote = NULL;
1385+
__be32 src_vni = mdb_entry->key.vni;
1386+
1387+
list_for_each_entry_rcu(remote, &mdb_entry->remotes, list) {
1388+
struct sk_buff *skb1;
1389+
1390+
if ((vxlan_mdb_is_star_g(&mdb_entry->key) &&
1391+
READ_ONCE(remote->filter_mode) == MCAST_INCLUDE) ||
1392+
(READ_ONCE(remote->flags) & VXLAN_MDB_REMOTE_F_BLOCKED))
1393+
continue;
1394+
1395+
if (!fremote) {
1396+
fremote = remote;
1397+
continue;
1398+
}
1399+
1400+
skb1 = skb_clone(skb, GFP_ATOMIC);
1401+
if (skb1)
1402+
vxlan_xmit_one(skb1, vxlan->dev, src_vni,
1403+
rcu_dereference(remote->rd), false);
1404+
}
1405+
1406+
if (fremote)
1407+
vxlan_xmit_one(skb, vxlan->dev, src_vni,
1408+
rcu_dereference(fremote->rd), false);
1409+
else
1410+
kfree_skb(skb);
1411+
1412+
return NETDEV_TX_OK;
1413+
}
1414+
13011415
static void vxlan_mdb_check_empty(void *ptr, void *arg)
13021416
{
13031417
WARN_ON_ONCE(1);

drivers/net/vxlan/vxlan_private.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ int vxlan_mdb_add(struct net_device *dev, struct nlattr *tb[], u16 nlmsg_flags,
235235
struct netlink_ext_ack *extack);
236236
int vxlan_mdb_del(struct net_device *dev, struct nlattr *tb[],
237237
struct netlink_ext_ack *extack);
238+
struct vxlan_mdb_entry *vxlan_mdb_entry_skb_get(struct vxlan_dev *vxlan,
239+
struct sk_buff *skb,
240+
__be32 src_vni);
241+
netdev_tx_t vxlan_mdb_xmit(struct vxlan_dev *vxlan,
242+
const struct vxlan_mdb_entry *mdb_entry,
243+
struct sk_buff *skb);
238244
int vxlan_mdb_init(struct vxlan_dev *vxlan);
239245
void vxlan_mdb_fini(struct vxlan_dev *vxlan);
240246
#endif

0 commit comments

Comments
 (0)