Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 390a4bee authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'l3mdev_saddr_op'



David Ahern says:

====================
net: Add saddr op to l3mdev and vrf

First 2 patches are re-sends of patches that got lost in the ethosphere
Tuesday; they were part of the first round of l3mdev conversions.
Next 3 handle the source address lookup for raw and datagram sockets
bound to a VRF device.

The conversion to the get_saddr op also fixes locally originated TCP
packets showing up at the VRF device. The use of the FLOWI_FLAG_L3MDEV_SRC
flag in ip_route_connect_init was causing locally generated packets
to skip the VRF device.

v2
- rebased to top of net-next per device delete fix and hash based
  multipath patches
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 4148987a bb191c3e
Loading
Loading
Loading
Loading
+41 −8
Original line number Diff line number Diff line
@@ -36,11 +36,12 @@
#include <net/addrconf.h>
#include <net/l3mdev.h>

#define RT_FL_TOS(oldflp4) \
	((oldflp4)->flowi4_tos & (IPTOS_RT_MASK | RTO_ONLINK))

#define DRV_NAME	"vrf"
#define DRV_VERSION	"1.0"

#define vrf_is_slave(dev)   ((dev)->flags & IFF_SLAVE)

#define vrf_master_get_rcu(dev) \
	((struct net_device *)rcu_dereference(dev->rx_handler_data))

@@ -208,7 +209,7 @@ static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb,
		.flowi4_oif = vrf_dev->ifindex,
		.flowi4_iif = LOOPBACK_IFINDEX,
		.flowi4_tos = RT_TOS(ip4h->tos),
		.flowi4_flags = FLOWI_FLAG_ANYSRC | FLOWI_FLAG_VRFSRC |
		.flowi4_flags = FLOWI_FLAG_ANYSRC | FLOWI_FLAG_L3MDEV_SRC |
				FLOWI_FLAG_SKIP_NH_OIF,
		.daddr = ip4h->daddr,
	};
@@ -433,7 +434,7 @@ static int do_vrf_add_slave(struct net_device *dev, struct net_device *port_dev)
	if (ret < 0)
		goto out_unregister;

	port_dev->flags |= IFF_SLAVE;
	port_dev->priv_flags |= IFF_L3MDEV_SLAVE;
	__vrf_insert_slave(queue, slave);
	cycle_netdev(port_dev);

@@ -448,7 +449,7 @@ static int do_vrf_add_slave(struct net_device *dev, struct net_device *port_dev)

static int vrf_add_slave(struct net_device *dev, struct net_device *port_dev)
{
	if (netif_is_l3_master(port_dev) || vrf_is_slave(port_dev))
	if (netif_is_l3_master(port_dev) || netif_is_l3_slave(port_dev))
		return -EINVAL;

	return do_vrf_add_slave(dev, port_dev);
@@ -462,7 +463,7 @@ static int do_vrf_del_slave(struct net_device *dev, struct net_device *port_dev)
	struct slave *slave;

	netdev_upper_dev_unlink(port_dev, dev);
	port_dev->flags &= ~IFF_SLAVE;
	port_dev->priv_flags &= ~IFF_L3MDEV_SLAVE;

	netdev_rx_handler_unregister(port_dev);

@@ -545,7 +546,7 @@ static struct rtable *vrf_get_rtable(const struct net_device *dev,
{
	struct rtable *rth = NULL;

	if (!(fl4->flowi4_flags & FLOWI_FLAG_VRFSRC)) {
	if (!(fl4->flowi4_flags & FLOWI_FLAG_L3MDEV_SRC)) {
		struct net_vrf *vrf = netdev_priv(dev);

		rth = vrf->rth;
@@ -555,9 +556,41 @@ static struct rtable *vrf_get_rtable(const struct net_device *dev,
	return rth;
}

/* called under rcu_read_lock */
static void vrf_get_saddr(struct net_device *dev, struct flowi4 *fl4)
{
	struct fib_result res = { .tclassid = 0 };
	struct net *net = dev_net(dev);
	u32 orig_tos = fl4->flowi4_tos;
	u8 flags = fl4->flowi4_flags;
	u8 scope = fl4->flowi4_scope;
	u8 tos = RT_FL_TOS(fl4);

	if (unlikely(!fl4->daddr))
		return;

	fl4->flowi4_flags |= FLOWI_FLAG_SKIP_NH_OIF;
	fl4->flowi4_iif = LOOPBACK_IFINDEX;
	fl4->flowi4_tos = tos & IPTOS_RT_MASK;
	fl4->flowi4_scope = ((tos & RTO_ONLINK) ?
			     RT_SCOPE_LINK : RT_SCOPE_UNIVERSE);

	if (!fib_lookup(net, fl4, &res, 0)) {
		if (res.type == RTN_LOCAL)
			fl4->saddr = res.fi->fib_prefsrc ? : fl4->daddr;
		else
			fib_select_path(net, &res, fl4, -1);
	}

	fl4->flowi4_flags = flags;
	fl4->flowi4_tos = orig_tos;
	fl4->flowi4_scope = scope;
}

static const struct l3mdev_ops vrf_l3mdev_ops = {
	.l3mdev_fib_table	= vrf_fib_table,
	.l3mdev_get_rtable	= vrf_get_rtable,
	.l3mdev_get_saddr	= vrf_get_saddr,
};

static void vrf_get_drvinfo(struct net_device *dev,
@@ -672,7 +705,7 @@ static int vrf_device_event(struct notifier_block *unused,
	if (event == NETDEV_UNREGISTER) {
		struct net_device *vrf_dev;

		if (!vrf_is_slave(dev) || netif_is_l3_master(dev))
		if (!netif_is_l3_slave(dev))
			goto out;

		vrf_dev = netdev_master_upper_dev_get(dev);
+7 −0
Original line number Diff line number Diff line
@@ -1261,6 +1261,7 @@ struct net_device_ops {
 * @IFF_L3MDEV_MASTER: device is an L3 master device
 * @IFF_NO_QUEUE: device can run without qdisc attached
 * @IFF_OPENVSWITCH: device is a Open vSwitch master
 * @IFF_L3MDEV_SLAVE: device is enslaved to an L3 master device
 */
enum netdev_priv_flags {
	IFF_802_1Q_VLAN			= 1<<0,
@@ -1286,6 +1287,7 @@ enum netdev_priv_flags {
	IFF_L3MDEV_MASTER		= 1<<20,
	IFF_NO_QUEUE			= 1<<21,
	IFF_OPENVSWITCH			= 1<<22,
	IFF_L3MDEV_SLAVE		= 1<<23,
};

#define IFF_802_1Q_VLAN			IFF_802_1Q_VLAN
@@ -3830,6 +3832,11 @@ static inline bool netif_is_l3_master(const struct net_device *dev)
	return dev->priv_flags & IFF_L3MDEV_MASTER;
}

static inline bool netif_is_l3_slave(const struct net_device *dev)
{
	return dev->priv_flags & IFF_L3MDEV_SLAVE;
}

static inline bool netif_is_bridge_master(const struct net_device *dev)
{
	return dev->priv_flags & IFF_EBRIDGE;
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ struct flowi_common {
	__u8	flowic_flags;
#define FLOWI_FLAG_ANYSRC		0x01
#define FLOWI_FLAG_KNOWN_NH		0x02
#define FLOWI_FLAG_VRFSRC		0x04
#define FLOWI_FLAG_L3MDEV_SRC		0x04
#define FLOWI_FLAG_SKIP_NH_OIF		0x08
	__u32	flowic_secid;
	struct flowi_tunnel flowic_tun_key;
+2 −0
Original line number Diff line number Diff line
@@ -329,6 +329,8 @@ static inline int fib_multipath_hash(__be32 saddr, __be32 daddr)
}

void fib_select_multipath(struct fib_result *res, int hash);
void fib_select_path(struct net *net, struct fib_result *res,
		     struct flowi4 *fl4, int mp_hash);

/* Exported by fib_trie.c */
void fib_trie_init(void);
+27 −0
Original line number Diff line number Diff line
@@ -17,12 +17,16 @@
 * @l3mdev_fib_table: Get FIB table id to use for lookups
 *
 * @l3mdev_get_rtable: Get cached IPv4 rtable (dst_entry) for device
 *
 * @l3mdev_get_saddr: Get source address for a flow
 */

struct l3mdev_ops {
	u32		(*l3mdev_fib_table)(const struct net_device *dev);
	struct rtable *	(*l3mdev_get_rtable)(const struct net_device *dev,
					     const struct flowi4 *fl4);
	void		(*l3mdev_get_saddr)(struct net_device *dev,
					    struct flowi4 *fl4);
};

#ifdef CONFIG_NET_L3_MASTER_DEV
@@ -100,6 +104,25 @@ static inline bool netif_index_is_l3_master(struct net *net, int ifindex)
	return rc;
}

static inline void l3mdev_get_saddr(struct net *net, int ifindex,
				    struct flowi4 *fl4)
{
	struct net_device *dev;

	if (ifindex) {

		rcu_read_lock();

		dev = dev_get_by_index_rcu(net, ifindex);
		if (dev && netif_is_l3_master(dev) &&
		    dev->l3mdev_ops->l3mdev_get_saddr) {
			dev->l3mdev_ops->l3mdev_get_saddr(dev, fl4);
		}

		rcu_read_unlock();
	}
}

#else

static inline int l3mdev_master_ifindex_rcu(struct net_device *dev)
@@ -144,6 +167,10 @@ static inline bool netif_index_is_l3_master(struct net *net, int ifindex)
	return false;
}

static inline void l3mdev_get_saddr(struct net *net, int ifindex,
				    struct flowi4 *fl4)
{
}
#endif

#endif /* _NET_L3MDEV_H_ */
Loading