Skip to content

Commit 1ff23be

Browse files
David Aherndavem330
authored andcommitted
net: l3mdev: Allow send on enslaved interface
Allow udp and raw sockets to send by oif that is an enslaved interface versus the l3mdev/VRF device. For example, this allows BFD to use ifindex from IP_PKTINFO on a receive to send a response without the need to convert to the VRF index. It also allows ping and ping6 to work when specifying an enslaved interface (e.g., ping -I swp1 <ip>) which is a natural use case. Signed-off-by: David Ahern <dsa@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4a65896 commit 1ff23be

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎drivers/net/vrf.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ static int vrf_get_saddr(struct net_device *dev, struct flowi4 *fl4)
648648

649649
fl4->flowi4_flags |= FLOWI_FLAG_SKIP_NH_OIF;
650650
fl4->flowi4_iif = LOOPBACK_IFINDEX;
651+
/* make sure oif is set to VRF device for lookup */
652+
fl4->flowi4_oif = dev->ifindex;
651653
fl4->flowi4_tos = tos & IPTOS_RT_MASK;
652654
fl4->flowi4_scope = ((tos & RTO_ONLINK) ?
653655
RT_SCOPE_LINK : RT_SCOPE_UNIVERSE);

‎net/ipv4/route.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,7 @@ struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
21462146
unsigned int flags = 0;
21472147
struct fib_result res;
21482148
struct rtable *rth;
2149+
int master_idx;
21492150
int orig_oif;
21502151
int err = -ENETUNREACH;
21512152

@@ -2155,6 +2156,9 @@ struct rtable *__ip_route_output_key_hash(struct net *net, struct flowi4 *fl4,
21552156

21562157
orig_oif = fl4->flowi4_oif;
21572158

2159+
master_idx = l3mdev_master_ifindex_by_index(net, fl4->flowi4_oif);
2160+
if (master_idx)
2161+
fl4->flowi4_oif = master_idx;
21582162
fl4->flowi4_iif = LOOPBACK_IFINDEX;
21592163
fl4->flowi4_tos = tos & IPTOS_RT_MASK;
21602164
fl4->flowi4_scope = ((tos & RTO_ONLINK) ?

‎net/l3mdev/l3mdev.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,18 @@ struct dst_entry *l3mdev_get_rt6_dst(struct net *net,
112112
struct dst_entry *dst = NULL;
113113
struct net_device *dev;
114114

115-
dev = dev_get_by_index(net, fl6->flowi6_oif);
116-
if (dev) {
117-
if (netif_is_l3_master(dev) &&
115+
if (fl6->flowi6_oif) {
116+
rcu_read_lock();
117+
118+
dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
119+
if (dev && netif_is_l3_slave(dev))
120+
dev = netdev_master_upper_dev_get_rcu(dev);
121+
122+
if (dev && netif_is_l3_master(dev) &&
118123
dev->l3mdev_ops->l3mdev_get_rt6_dst)
119124
dst = dev->l3mdev_ops->l3mdev_get_rt6_dst(dev, fl6);
120-
dev_put(dev);
125+
126+
rcu_read_unlock();
121127
}
122128

123129
return dst;
@@ -141,6 +147,9 @@ int l3mdev_get_saddr(struct net *net, int ifindex, struct flowi4 *fl4)
141147
rcu_read_lock();
142148

143149
dev = dev_get_by_index_rcu(net, ifindex);
150+
if (dev && netif_is_l3_slave(dev))
151+
dev = netdev_master_upper_dev_get_rcu(dev);
152+
144153
if (dev && netif_is_l3_master(dev) &&
145154
dev->l3mdev_ops->l3mdev_get_saddr)
146155
rc = dev->l3mdev_ops->l3mdev_get_saddr(dev, fl4);

0 commit comments

Comments
 (0)