Skip to content

Commit

Permalink
Merge branch 'ipv4-Control-SKB-reprioritization-after-forwarding'
Browse files Browse the repository at this point in the history
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: David S. Miller <davem@davemloft.net>
  • Loading branch information
davem330 committed Aug 1, 2018
2 parents 83ba464 + 9bae045 commit 53dd965
Show file tree
Hide file tree
Showing 10 changed files with 379 additions and 79 deletions.
9 changes: 9 additions & 0 deletions Documentation/networking/ip-sysctl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
56 changes: 40 additions & 16 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/net/netevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions include/net/netns/ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions net/ipv4/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion net/ipv4/ip_forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ int ip_forward(struct sk_buff *skb)
!skb_sec_path(skb))
ip_rt_send_redirect(skb);

skb->priority = rt_tos2priority(iph->tos);
if (net->ipv4.sysctl_ip_fwd_update_priority)
skb->priority = rt_tos2priority(iph->tos);

return NF_HOOK(NFPROTO_IPV4, NF_INET_FORWARD,
net, NULL, skb, skb->dev, rt->dst.dev,
Expand Down
26 changes: 26 additions & 0 deletions net/ipv4/sysctl_net_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,23 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
return ret;
}

static int ipv4_fwd_update_priority(struct ctl_table *table, int write,
void __user *buffer,
size_t *lenp, loff_t *ppos)
{
struct net *net;
int ret;

net = container_of(table->data, struct net,
ipv4.sysctl_ip_fwd_update_priority);
ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
if (write && ret == 0)
call_netevent_notifiers(NETEVENT_IPV4_FWD_UPDATE_PRIORITY_UPDATE,
net);

return ret;
}

static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
Expand Down Expand Up @@ -663,6 +680,15 @@ static struct ctl_table ipv4_net_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec,
},
{
.procname = "ip_forward_update_priority",
.data = &init_net.ipv4.sysctl_ip_fwd_update_priority,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = ipv4_fwd_update_priority,
.extra1 = &zero,
.extra2 = &one,
},
{
.procname = "ip_nonlocal_bind",
.data = &init_net.ipv4.sysctl_ip_nonlocal_bind,
Expand Down
65 changes: 3 additions & 62 deletions tools/testing/selftests/drivers/net/mlxsw/qos_dscp_bridge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,6 @@ lib_dir=$(dirname $0)/../../../net/forwarding
NUM_NETIFS=4
source $lib_dir/lib.sh

__dscp_capture_add_del()
{
local add_del=$1; shift
local dev=$1; shift
local base=$1; shift
local dscp;

for prio in {0..7}; do
dscp=$((base + prio))
__icmp_capture_add_del $add_del $dscp "" $dev \
"ip_tos $((dscp << 2))"
done
}

dscp_capture_install()
{
local dev=$1; shift
local base=$1; shift

__dscp_capture_add_del add $dev $base
}

dscp_capture_uninstall()
{
local dev=$1; shift
local base=$1; shift

__dscp_capture_add_del del $dev $base
}

h1_create()
{
local dscp;
Expand Down Expand Up @@ -103,16 +73,6 @@ dscp_map()
done
}

lldpad_wait()
{
local dev=$1; shift

while lldptool -t -i $dev -V APP -c app | grep -q pending; do
echo "$dev: waiting for lldpad to push pending APP updates"
sleep 5
done
}

switch_create()
{
ip link add name br1 type bridge vlan_filtering 1
Expand All @@ -124,22 +84,15 @@ switch_create()

lldptool -T -i $swp1 -V APP $(dscp_map 10) >/dev/null
lldptool -T -i $swp2 -V APP $(dscp_map 20) >/dev/null
lldpad_wait $swp1
lldpad_wait $swp2
lldpad_app_wait_set $swp1
lldpad_app_wait_set $swp2
}

switch_destroy()
{
lldptool -T -i $swp2 -V APP -d $(dscp_map 20) >/dev/null
lldptool -T -i $swp1 -V APP -d $(dscp_map 10) >/dev/null

# Give lldpad a chance to push down the changes. If the device is downed
# too soon, the updates will be left pending, but will have been struck
# off the lldpad's DB already, and we won't be able to tell. Then on
# next test iteration this would cause weirdness as newly-added APP
# rules conflict with the old ones, sometimes getting stuck in an
# "unknown" state.
sleep 5
lldpad_app_wait_del

ip link set dev $swp2 nomaster
ip link set dev $swp1 nomaster
Expand Down Expand Up @@ -172,18 +125,6 @@ cleanup()
vrf_cleanup
}

dscp_fetch_stats()
{
local dev=$1; shift
local base=$1; shift

for prio in {0..7}; do
local dscp=$((base + prio))
local t=$(tc_rule_stats_get $dev $dscp)
echo "[$dscp]=$t "
done
}

ping_ipv4()
{
ping_test $h1 192.0.2.2
Expand Down
Loading

0 comments on commit 53dd965

Please sign in to comment.