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

Commit 53dd9652 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'ipv4-Control-SKB-reprioritization-after-forwarding'



Petr Machata says:

====================
ipv4: Control SKB reprioritization after forwarding

After IPv4 packets are forwarded, the priority of the corresponding SKB
is updated according to the TOS field of IPv4 header. This overrides any
prioritization done earlier by e.g. an skbedit action or ingress-qos-map
defined at a vlan device.

Such overriding may not always be desirable. Even if the packet ends up
being routed, which implies this is an L3 network node, an administrator
may wish to preserve whatever prioritization was done earlier on in the
pipeline.

Therefore this patch set introduces a sysctl that controls this
behavior, net.ipv4.ip_forward_update_priority. It's value is 1 by
default to preserve the current behavior.

All of the above is implemented in patch #1.

Value changes prompt a new NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE
notification, so that the drivers can hook up whatever logic may depend
on this value. That is implemented in patch #2.

In patches #3 and #4, mlxsw is adapted to recognize the sysctl. On
initialization, the RGCR register that handles router configuration is
set in accordance with the sysctl. The new notification is listened to
and RGCR is reconfigured as necessary.

In patches #5 to #7, a selftest is added to verify that mlxsw reflects
the sysctl value as necessary. The test is expressed in terms of the
recently-introduced ieee_setapp support, and works by observing how DSCP
value gets rewritten depending on packet priority. For this reason, the
test is added to the subdirectory drivers/net/mlxsw. Even though it's
not particularly specific to mlxsw, it's not suitable for running on
soft devices (which don't support the ieee_setapp et.al.).

Changes from v1 to v2:

- In patch #1, init sysctl_ip_fwd_update_priority to 1 instead of true.

Changes from RFC to v1:

- Fix wrong sysctl name in ip-sysctl.txt
- Add notifications
- Add mlxsw support
- Add self test
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 83ba4645 9bae0451
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -81,6 +81,15 @@ fib_multipath_hash_policy - INTEGER
	0 - Layer 3
	1 - Layer 4

ip_forward_update_priority - INTEGER
	Whether to update SKB priority from "TOS" field in IPv4 header after it
	is forwarded. The new SKB priority is mapped from TOS field value
	according to an rt_tos2priority table (see e.g. man tc-prio).
	Default: 1 (Update priority.)
	Possible values:
	0 - Do not update priority.
	1 - Update priority.

route/max_size - INTEGER
	Maximum number of routes allowed in the kernel.  Increase
	this when using large numbers of interfaces and/or routes.
+40 −16
Original line number Diff line number Diff line
@@ -2436,17 +2436,48 @@ static void mlxsw_sp_router_mp_hash_event_work(struct work_struct *work)
	kfree(net_work);
}

static int __mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp);

static void mlxsw_sp_router_update_priority_work(struct work_struct *work)
{
	struct mlxsw_sp_netevent_work *net_work =
		container_of(work, struct mlxsw_sp_netevent_work, work);
	struct mlxsw_sp *mlxsw_sp = net_work->mlxsw_sp;

	__mlxsw_sp_router_init(mlxsw_sp);
	kfree(net_work);
}

static int mlxsw_sp_router_schedule_work(struct net *net,
					 struct notifier_block *nb,
					 void (*cb)(struct work_struct *))
{
	struct mlxsw_sp_netevent_work *net_work;
	struct mlxsw_sp_router *router;

	if (!net_eq(net, &init_net))
		return NOTIFY_DONE;

	net_work = kzalloc(sizeof(*net_work), GFP_ATOMIC);
	if (!net_work)
		return NOTIFY_BAD;

	router = container_of(nb, struct mlxsw_sp_router, netevent_nb);
	INIT_WORK(&net_work->work, cb);
	net_work->mlxsw_sp = router->mlxsw_sp;
	mlxsw_core_schedule_work(&net_work->work);
	return NOTIFY_DONE;
}

static int mlxsw_sp_router_netevent_event(struct notifier_block *nb,
					  unsigned long event, void *ptr)
{
	struct mlxsw_sp_netevent_work *net_work;
	struct mlxsw_sp_port *mlxsw_sp_port;
	struct mlxsw_sp_router *router;
	struct mlxsw_sp *mlxsw_sp;
	unsigned long interval;
	struct neigh_parms *p;
	struct neighbour *n;
	struct net *net;

	switch (event) {
	case NETEVENT_DELAY_PROBE_TIME_UPDATE:
@@ -2500,20 +2531,12 @@ static int mlxsw_sp_router_netevent_event(struct notifier_block *nb,
		break;
	case NETEVENT_IPV4_MPATH_HASH_UPDATE:
	case NETEVENT_IPV6_MPATH_HASH_UPDATE:
		net = ptr;
		return mlxsw_sp_router_schedule_work(ptr, nb,
				mlxsw_sp_router_mp_hash_event_work);

		if (!net_eq(net, &init_net))
			return NOTIFY_DONE;

		net_work = kzalloc(sizeof(*net_work), GFP_ATOMIC);
		if (!net_work)
			return NOTIFY_BAD;

		router = container_of(nb, struct mlxsw_sp_router, netevent_nb);
		INIT_WORK(&net_work->work, mlxsw_sp_router_mp_hash_event_work);
		net_work->mlxsw_sp = router->mlxsw_sp;
		mlxsw_core_schedule_work(&net_work->work);
		break;
	case NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE:
		return mlxsw_sp_router_schedule_work(ptr, nb,
				mlxsw_sp_router_update_priority_work);
	}

	return NOTIFY_DONE;
@@ -7382,6 +7405,7 @@ static int mlxsw_sp_dscp_init(struct mlxsw_sp *mlxsw_sp)

static int __mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)
{
	bool usp = init_net.ipv4.sysctl_ip_fwd_update_priority;
	char rgcr_pl[MLXSW_REG_RGCR_LEN];
	u64 max_rifs;
	int err;
@@ -7392,7 +7416,7 @@ static int __mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)

	mlxsw_reg_rgcr_pack(rgcr_pl, true, true);
	mlxsw_reg_rgcr_max_router_interfaces_set(rgcr_pl, max_rifs);
	mlxsw_reg_rgcr_usp_set(rgcr_pl, true);
	mlxsw_reg_rgcr_usp_set(rgcr_pl, usp);
	err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(rgcr), rgcr_pl);
	if (err)
		return err;
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ enum netevent_notif_type {
	NETEVENT_DELAY_PROBE_TIME_UPDATE, /* arg is struct neigh_parms ptr */
	NETEVENT_IPV4_MPATH_HASH_UPDATE, /* arg is struct net ptr */
	NETEVENT_IPV6_MPATH_HASH_UPDATE, /* arg is struct net ptr */
	NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE, /* arg is struct net ptr */
};

int register_netevent_notifier(struct notifier_block *nb);
+1 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ struct netns_ipv4 {
	int sysctl_ip_default_ttl;
	int sysctl_ip_no_pmtu_disc;
	int sysctl_ip_fwd_use_pmtu;
	int sysctl_ip_fwd_update_priority;
	int sysctl_ip_nonlocal_bind;
	/* Shall we try to damage output packets if routing dev changes? */
	int sysctl_ip_dynaddr;
+1 −0
Original line number Diff line number Diff line
@@ -1801,6 +1801,7 @@ static __net_init int inet_init_net(struct net *net)
	 * We set them here, in case sysctl is not compiled.
	 */
	net->ipv4.sysctl_ip_default_ttl = IPDEFTTL;
	net->ipv4.sysctl_ip_fwd_update_priority = 1;
	net->ipv4.sysctl_ip_dynaddr = 0;
	net->ipv4.sysctl_ip_early_demux = 1;
	net->ipv4.sysctl_udp_early_demux = 1;
Loading