vxlan_core: make multicast helper take rip and ifindex explicitly

This patch changes multicast helpers to take rip and ifindex as input.
This is needed in future patches where rip can come from a pervni
structure while the ifindex can come from the vxlan device.

Signed-off-by: Roopa Prabhu <roopa@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Roopa Prabhu 2022-03-01 05:04:32 +00:00 committed by David S. Miller
parent c63053e0cb
commit a9508d121a

View File

@ -1446,8 +1446,11 @@ static bool vxlan_snoop(struct net_device *dev,
} }
/* See if multicast group is already in use by other ID */ /* See if multicast group is already in use by other ID */
static bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev) static bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev,
union vxlan_addr *rip, int rifindex)
{ {
union vxlan_addr *ip = (rip ? : &dev->default_dst.remote_ip);
int ifindex = (rifindex ? : dev->default_dst.remote_ifindex);
struct vxlan_dev *vxlan; struct vxlan_dev *vxlan;
struct vxlan_sock *sock4; struct vxlan_sock *sock4;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
@ -1482,11 +1485,10 @@ static bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev)
#endif #endif
if (!vxlan_addr_equal(&vxlan->default_dst.remote_ip, if (!vxlan_addr_equal(&vxlan->default_dst.remote_ip,
&dev->default_dst.remote_ip)) ip))
continue; continue;
if (vxlan->default_dst.remote_ifindex != if (vxlan->default_dst.remote_ifindex != ifindex)
dev->default_dst.remote_ifindex)
continue; continue;
return true; return true;
@ -1546,12 +1548,13 @@ static void vxlan_sock_release(struct vxlan_dev *vxlan)
/* Update multicast group membership when first VNI on /* Update multicast group membership when first VNI on
* multicast address is brought up * multicast address is brought up
*/ */
static int vxlan_igmp_join(struct vxlan_dev *vxlan) static int vxlan_igmp_join(struct vxlan_dev *vxlan, union vxlan_addr *rip,
int rifindex)
{ {
struct sock *sk; union vxlan_addr *ip = (rip ? : &vxlan->default_dst.remote_ip);
union vxlan_addr *ip = &vxlan->default_dst.remote_ip; int ifindex = (rifindex ? : vxlan->default_dst.remote_ifindex);
int ifindex = vxlan->default_dst.remote_ifindex;
int ret = -EINVAL; int ret = -EINVAL;
struct sock *sk;
if (ip->sa.sa_family == AF_INET) { if (ip->sa.sa_family == AF_INET) {
struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock); struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock);
@ -1579,13 +1582,13 @@ static int vxlan_igmp_join(struct vxlan_dev *vxlan)
return ret; return ret;
} }
/* Inverse of vxlan_igmp_join when last VNI is brought down */ static int vxlan_igmp_leave(struct vxlan_dev *vxlan, union vxlan_addr *rip,
static int vxlan_igmp_leave(struct vxlan_dev *vxlan) int rifindex)
{ {
struct sock *sk; union vxlan_addr *ip = (rip ? : &vxlan->default_dst.remote_ip);
union vxlan_addr *ip = &vxlan->default_dst.remote_ip; int ifindex = (rifindex ? : vxlan->default_dst.remote_ifindex);
int ifindex = vxlan->default_dst.remote_ifindex;
int ret = -EINVAL; int ret = -EINVAL;
struct sock *sk;
if (ip->sa.sa_family == AF_INET) { if (ip->sa.sa_family == AF_INET) {
struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock); struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock);
@ -3024,7 +3027,8 @@ static int vxlan_open(struct net_device *dev)
return ret; return ret;
if (vxlan_addr_multicast(&vxlan->default_dst.remote_ip)) { if (vxlan_addr_multicast(&vxlan->default_dst.remote_ip)) {
ret = vxlan_igmp_join(vxlan); ret = vxlan_igmp_join(vxlan, &vxlan->default_dst.remote_ip,
vxlan->default_dst.remote_ifindex);
if (ret == -EADDRINUSE) if (ret == -EADDRINUSE)
ret = 0; ret = 0;
if (ret) { if (ret) {
@ -3071,8 +3075,9 @@ static int vxlan_stop(struct net_device *dev)
int ret = 0; int ret = 0;
if (vxlan_addr_multicast(&vxlan->default_dst.remote_ip) && if (vxlan_addr_multicast(&vxlan->default_dst.remote_ip) &&
!vxlan_group_used(vn, vxlan)) !vxlan_group_used(vn, vxlan, NULL, 0))
ret = vxlan_igmp_leave(vxlan); ret = vxlan_igmp_leave(vxlan, &vxlan->default_dst.remote_ip,
vxlan->default_dst.remote_ifindex);
del_timer_sync(&vxlan->age_timer); del_timer_sync(&vxlan->age_timer);