Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vxlan_multicast: Move multicast helpers to a separate file

subsequent patches will add more helpers.

Signed-off-by: Roopa Prabhu <roopa@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Roopa Prabhu and committed by
David S. Miller
a498c595 7b8135f4

+142 -124
+1 -1
drivers/net/vxlan/Makefile
··· 4 4 5 5 obj-$(CONFIG_VXLAN) += vxlan.o 6 6 7 - vxlan-objs := vxlan_core.o 7 + vxlan-objs := vxlan_core.o vxlan_multicast.o
-123
drivers/net/vxlan/vxlan_core.c
··· 1445 1445 return false; 1446 1446 } 1447 1447 1448 - /* See if multicast group is already in use by other ID */ 1449 - static bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev, 1450 - union vxlan_addr *rip, int rifindex) 1451 - { 1452 - union vxlan_addr *ip = (rip ? : &dev->default_dst.remote_ip); 1453 - int ifindex = (rifindex ? : dev->default_dst.remote_ifindex); 1454 - struct vxlan_dev *vxlan; 1455 - struct vxlan_sock *sock4; 1456 - #if IS_ENABLED(CONFIG_IPV6) 1457 - struct vxlan_sock *sock6; 1458 - #endif 1459 - unsigned short family = dev->default_dst.remote_ip.sa.sa_family; 1460 - 1461 - sock4 = rtnl_dereference(dev->vn4_sock); 1462 - 1463 - /* The vxlan_sock is only used by dev, leaving group has 1464 - * no effect on other vxlan devices. 1465 - */ 1466 - if (family == AF_INET && sock4 && refcount_read(&sock4->refcnt) == 1) 1467 - return false; 1468 - #if IS_ENABLED(CONFIG_IPV6) 1469 - sock6 = rtnl_dereference(dev->vn6_sock); 1470 - if (family == AF_INET6 && sock6 && refcount_read(&sock6->refcnt) == 1) 1471 - return false; 1472 - #endif 1473 - 1474 - list_for_each_entry(vxlan, &vn->vxlan_list, next) { 1475 - if (!netif_running(vxlan->dev) || vxlan == dev) 1476 - continue; 1477 - 1478 - if (family == AF_INET && 1479 - rtnl_dereference(vxlan->vn4_sock) != sock4) 1480 - continue; 1481 - #if IS_ENABLED(CONFIG_IPV6) 1482 - if (family == AF_INET6 && 1483 - rtnl_dereference(vxlan->vn6_sock) != sock6) 1484 - continue; 1485 - #endif 1486 - 1487 - if (!vxlan_addr_equal(&vxlan->default_dst.remote_ip, 1488 - ip)) 1489 - continue; 1490 - 1491 - if (vxlan->default_dst.remote_ifindex != ifindex) 1492 - continue; 1493 - 1494 - return true; 1495 - } 1496 - 1497 - return false; 1498 - } 1499 - 1500 1448 static bool __vxlan_sock_release_prep(struct vxlan_sock *vs) 1501 1449 { 1502 1450 struct vxlan_net *vn; ··· 1491 1543 kfree(sock6); 1492 1544 } 1493 1545 #endif 1494 - } 1495 - 1496 - /* Update multicast group membership when first VNI on 1497 - * multicast address is brought up 1498 - */ 1499 - static int vxlan_igmp_join(struct vxlan_dev *vxlan, union vxlan_addr *rip, 1500 - int rifindex) 1501 - { 1502 - union vxlan_addr *ip = (rip ? : &vxlan->default_dst.remote_ip); 1503 - int ifindex = (rifindex ? : vxlan->default_dst.remote_ifindex); 1504 - int ret = -EINVAL; 1505 - struct sock *sk; 1506 - 1507 - if (ip->sa.sa_family == AF_INET) { 1508 - struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock); 1509 - struct ip_mreqn mreq = { 1510 - .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr, 1511 - .imr_ifindex = ifindex, 1512 - }; 1513 - 1514 - sk = sock4->sock->sk; 1515 - lock_sock(sk); 1516 - ret = ip_mc_join_group(sk, &mreq); 1517 - release_sock(sk); 1518 - #if IS_ENABLED(CONFIG_IPV6) 1519 - } else { 1520 - struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock); 1521 - 1522 - sk = sock6->sock->sk; 1523 - lock_sock(sk); 1524 - ret = ipv6_stub->ipv6_sock_mc_join(sk, ifindex, 1525 - &ip->sin6.sin6_addr); 1526 - release_sock(sk); 1527 - #endif 1528 - } 1529 - 1530 - return ret; 1531 - } 1532 - 1533 - static int vxlan_igmp_leave(struct vxlan_dev *vxlan, union vxlan_addr *rip, 1534 - int rifindex) 1535 - { 1536 - union vxlan_addr *ip = (rip ? : &vxlan->default_dst.remote_ip); 1537 - int ifindex = (rifindex ? : vxlan->default_dst.remote_ifindex); 1538 - int ret = -EINVAL; 1539 - struct sock *sk; 1540 - 1541 - if (ip->sa.sa_family == AF_INET) { 1542 - struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock); 1543 - struct ip_mreqn mreq = { 1544 - .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr, 1545 - .imr_ifindex = ifindex, 1546 - }; 1547 - 1548 - sk = sock4->sock->sk; 1549 - lock_sock(sk); 1550 - ret = ip_mc_leave_group(sk, &mreq); 1551 - release_sock(sk); 1552 - #if IS_ENABLED(CONFIG_IPV6) 1553 - } else { 1554 - struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock); 1555 - 1556 - sk = sock6->sock->sk; 1557 - lock_sock(sk); 1558 - ret = ipv6_stub->ipv6_sock_mc_drop(sk, ifindex, 1559 - &ip->sin6.sin6_addr); 1560 - release_sock(sk); 1561 - #endif 1562 - } 1563 - 1564 - return ret; 1565 1546 } 1566 1547 1567 1548 static bool vxlan_remcsum(struct vxlanhdr *unparsed,
+134
drivers/net/vxlan/vxlan_multicast.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Vxlan multicast group handling 4 + * 5 + */ 6 + #include <linux/kernel.h> 7 + #include <net/net_namespace.h> 8 + #include <net/sock.h> 9 + #include <linux/igmp.h> 10 + #include <net/vxlan.h> 11 + 12 + #include "vxlan_private.h" 13 + 14 + /* Update multicast group membership when first VNI on 15 + * multicast address is brought up 16 + */ 17 + int vxlan_igmp_join(struct vxlan_dev *vxlan, union vxlan_addr *rip, 18 + int rifindex) 19 + { 20 + union vxlan_addr *ip = (rip ? : &vxlan->default_dst.remote_ip); 21 + int ifindex = (rifindex ? : vxlan->default_dst.remote_ifindex); 22 + int ret = -EINVAL; 23 + struct sock *sk; 24 + 25 + if (ip->sa.sa_family == AF_INET) { 26 + struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock); 27 + struct ip_mreqn mreq = { 28 + .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr, 29 + .imr_ifindex = ifindex, 30 + }; 31 + 32 + sk = sock4->sock->sk; 33 + lock_sock(sk); 34 + ret = ip_mc_join_group(sk, &mreq); 35 + release_sock(sk); 36 + #if IS_ENABLED(CONFIG_IPV6) 37 + } else { 38 + struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock); 39 + 40 + sk = sock6->sock->sk; 41 + lock_sock(sk); 42 + ret = ipv6_stub->ipv6_sock_mc_join(sk, ifindex, 43 + &ip->sin6.sin6_addr); 44 + release_sock(sk); 45 + #endif 46 + } 47 + 48 + return ret; 49 + } 50 + 51 + int vxlan_igmp_leave(struct vxlan_dev *vxlan, union vxlan_addr *rip, 52 + int rifindex) 53 + { 54 + union vxlan_addr *ip = (rip ? : &vxlan->default_dst.remote_ip); 55 + int ifindex = (rifindex ? : vxlan->default_dst.remote_ifindex); 56 + int ret = -EINVAL; 57 + struct sock *sk; 58 + 59 + if (ip->sa.sa_family == AF_INET) { 60 + struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock); 61 + struct ip_mreqn mreq = { 62 + .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr, 63 + .imr_ifindex = ifindex, 64 + }; 65 + 66 + sk = sock4->sock->sk; 67 + lock_sock(sk); 68 + ret = ip_mc_leave_group(sk, &mreq); 69 + release_sock(sk); 70 + #if IS_ENABLED(CONFIG_IPV6) 71 + } else { 72 + struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock); 73 + 74 + sk = sock6->sock->sk; 75 + lock_sock(sk); 76 + ret = ipv6_stub->ipv6_sock_mc_drop(sk, ifindex, 77 + &ip->sin6.sin6_addr); 78 + release_sock(sk); 79 + #endif 80 + } 81 + 82 + return ret; 83 + } 84 + 85 + /* See if multicast group is already in use by other ID */ 86 + bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev, 87 + union vxlan_addr *rip, int rifindex) 88 + { 89 + union vxlan_addr *ip = (rip ? : &dev->default_dst.remote_ip); 90 + int ifindex = (rifindex ? : dev->default_dst.remote_ifindex); 91 + struct vxlan_dev *vxlan; 92 + struct vxlan_sock *sock4; 93 + #if IS_ENABLED(CONFIG_IPV6) 94 + struct vxlan_sock *sock6; 95 + #endif 96 + unsigned short family = dev->default_dst.remote_ip.sa.sa_family; 97 + 98 + sock4 = rtnl_dereference(dev->vn4_sock); 99 + 100 + /* The vxlan_sock is only used by dev, leaving group has 101 + * no effect on other vxlan devices. 102 + */ 103 + if (family == AF_INET && sock4 && refcount_read(&sock4->refcnt) == 1) 104 + return false; 105 + 106 + #if IS_ENABLED(CONFIG_IPV6) 107 + sock6 = rtnl_dereference(dev->vn6_sock); 108 + if (family == AF_INET6 && sock6 && refcount_read(&sock6->refcnt) == 1) 109 + return false; 110 + #endif 111 + 112 + list_for_each_entry(vxlan, &vn->vxlan_list, next) { 113 + if (!netif_running(vxlan->dev) || vxlan == dev) 114 + continue; 115 + 116 + if (family == AF_INET && 117 + rtnl_dereference(vxlan->vn4_sock) != sock4) 118 + continue; 119 + #if IS_ENABLED(CONFIG_IPV6) 120 + if (family == AF_INET6 && 121 + rtnl_dereference(vxlan->vn6_sock) != sock6) 122 + continue; 123 + #endif 124 + if (!vxlan_addr_equal(&vxlan->default_dst.remote_ip, ip)) 125 + continue; 126 + 127 + if (vxlan->default_dst.remote_ifindex != ifindex) 128 + continue; 129 + 130 + return true; 131 + } 132 + 133 + return false; 134 + }
+7
drivers/net/vxlan/vxlan_private.h
··· 112 112 __u32 ifindex, __u16 ndm_flags, u32 nhid, 113 113 bool swdev_notify, struct netlink_ext_ack *extack); 114 114 115 + /* vxlan_multicast.c */ 116 + int vxlan_igmp_join(struct vxlan_dev *vxlan, union vxlan_addr *rip, 117 + int rifindex); 118 + int vxlan_igmp_leave(struct vxlan_dev *vxlan, union vxlan_addr *rip, 119 + int rifindex); 120 + bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev, 121 + union vxlan_addr *rip, int rifindex); 115 122 #endif