linux-kernelorg-stable/include/net
Ido Schimmel 2d300ce0b7 net: fib_rules: Fix iif / oif matching on L3 master device
Before commit 40867d74c3 ("net: Add l3mdev index to flow struct and
avoid oif reset for port devices") it was possible to use FIB rules to
match on a L3 domain. This was done by having a FIB rule match on iif /
oif being a L3 master device. It worked because prior to the FIB rule
lookup the iif / oif fields in the flow structure were reset to the
index of the L3 master device to which the input / output device was
enslaved to.

The above scheme made it impossible to match on the original input /
output device. Therefore, cited commit stopped overwriting the iif / oif
fields in the flow structure and instead stored the index of the
enslaving L3 master device in a new field ('flowi_l3mdev') in the flow
structure.

While the change enabled new use cases, it broke the original use case
of matching on a L3 domain. Fix this by interpreting the iif / oif
matching on a L3 master device as a match against the L3 domain. In
other words, if the iif / oif in the FIB rule points to a L3 master
device, compare the provided index against 'flowi_l3mdev' rather than
'flowi_{i,o}if'.

Before cited commit, a FIB rule that matched on 'iif vrf1' would only
match incoming traffic from devices enslaved to 'vrf1'. With the
proposed change (i.e., comparing against 'flowi_l3mdev'), the rule would
also match traffic originating from a socket bound to 'vrf1'. Avoid that
by adding a new flow flag ('FLOWI_FLAG_L3MDEV_OIF') that indicates if
the L3 domain was derived from the output interface or the input
interface (when not set) and take this flag into account when evaluating
the FIB rule against the flow structure.

Avoid unnecessary checks in the data path by detecting that a rule
matches on a L3 master device when the rule is installed and marking it
as such.

Tested using the following script [1].

Output before 40867d74c3 (v5.4.291):

default dev dummy1 table 100 scope link
default dev dummy1 table 200 scope link

Output after 40867d74c374:

default dev dummy1 table 300 scope link
default dev dummy1 table 300 scope link

Output with this patch:

default dev dummy1 table 100 scope link
default dev dummy1 table 200 scope link

[1]
 #!/bin/bash

 ip link add name vrf1 up type vrf table 10
 ip link add name dummy1 up master vrf1 type dummy

 sysctl -wq net.ipv4.conf.all.forwarding=1
 sysctl -wq net.ipv4.conf.all.rp_filter=0

 ip route add table 100 default dev dummy1
 ip route add table 200 default dev dummy1
 ip route add table 300 default dev dummy1

 ip rule add prio 0 oif vrf1 table 100
 ip rule add prio 1 iif vrf1 table 200
 ip rule add prio 2 table 300

 ip route get 192.0.2.1 oif dummy1 fibmatch
 ip route get 192.0.2.1 iif dummy1 from 198.51.100.1 fibmatch

Fixes: 40867d74c3 ("net: Add l3mdev index to flow struct and avoid oif reset for port devices")
Reported-by: hanhuihui <hanhuihui5@huawei.com>
Closes: https://lore.kernel.org/netdev/ec671c4f821a4d63904d0da15d604b75@huawei.com/
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Acked-by: David Ahern <dsahern@kernel.org>
Link: https://patch.msgid.link/20250414172022.242991-2-idosch@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-04-15 17:54:56 -07:00
..
9p
bluetooth Bluetooth: MGMT: Add LL Privacy Setting 2025-03-25 15:22:49 -04:00
caif
iucv
libeth libeth: move idpf_rx_csum_decoded and idpf_rx_extracted 2025-02-14 10:58:08 -08:00
mana RDMA v6.15 merge window pull request 2025-03-29 11:12:28 -07:00
netfilter netfilter pull request 25-03-23 2025-03-25 08:29:13 -07:00
netns Revert "udp_tunnel: GRO optimizations" 2025-03-25 09:15:07 -07:00
nfc
page_pool net: move mp dev config validation to __net_mp_open_rxq() 2025-04-04 07:35:38 -07:00
phonet
sctp Including fixes from netfilter. 2025-04-10 08:52:18 -07:00
tc_act
6lowpan.h
Space.h
act_api.h
addrconf.h
af_ieee802154.h
af_rxrpc.h rxrpc: Allow the app to store private data on peer structs 2025-03-10 09:47:15 +00:00
af_unix.h unix: fix up for "apparmor: add fine grained af_unix mediation" 2025-03-26 09:31:18 -07:00
af_vsock.h
ah.h
amt.h
arp.h
atmclip.h
ax25.h ax25: Remove broken autobind 2025-03-24 10:26:53 +00:00
ax88796.h
bareudp.h
bond_3ad.h
bond_alb.h
bond_options.h
bonding.h bonding: check xdp prog when set bond mode 2025-03-25 08:00:09 -07:00
bpf_sk_storage.h
busy_poll.h net: gro: decouple GRO from the NAPI layer 2025-02-27 14:03:14 +01:00
calipso.h
cfg80211-wext.h
cfg80211.h wifi: cfg80211: expose cfg80211_chandef_get_width() 2025-03-12 09:50:24 +01:00
cfg802154.h
checksum.h
cipso_ipv4.h
cls_cgroup.h
codel.h
codel_impl.h
codel_qdisc.h
compat.h
datalink.h
dcbevent.h
dcbnl.h
devlink.h
dropreason-core.h tcp: add four drop reasons to tcp_check_req() 2025-03-03 15:44:19 -08:00
dropreason.h wifi: mac80211: Drop cooked monitor support 2025-02-11 11:58:17 +01:00
dsa.h
dsa_stubs.h
dscp.h
dsfield.h
dst.h
dst_cache.h
dst_metadata.h net: Add options as a flexible array to struct ip_tunnel_info 2025-02-20 13:17:16 -08:00
dst_ops.h
eee.h
erspan.h
esp.h
espintcp.h
ethoc.h
failover.h
fib_notifier.h
fib_rules.h net: fib_rules: Fix iif / oif matching on L3 master device 2025-04-15 17:54:56 -07:00
firewire.h
flow.h net: fib_rules: Fix iif / oif matching on L3 master device 2025-04-15 17:54:56 -07:00
flow_dissector.h
flow_offload.h
fou.h
fq.h
fq_impl.h
garp.h
gen_stats.h
genetlink.h
geneve.h
gre.h
gro.h net: gro: expose GRO init/cleanup to use outside of NAPI 2025-02-27 14:03:14 +01:00
gro_cells.h
gso.h
gtp.h
gue.h
handshake.h
hotdata.h net: introduce per netns packet chains 2025-03-24 13:58:22 -07:00
hwbm.h
icmp.h
ieee8021q.h
ieee80211_radiotap.h
ieee802154_netdev.h
if_inet6.h
ife.h
inet6_connection_sock.h tcp/dccp: Remove inet_connection_sock_af_ops.addr2sockaddr(). 2025-03-24 12:10:13 -07:00
inet6_hashtables.h tcp: convert to dev_net_rcu() 2025-03-03 15:44:19 -08:00
inet_common.h
inet_connection_sock.h tcp/dccp: remove icsk->icsk_ack.timeout 2025-03-25 10:34:33 -07:00
inet_dscp.h
inet_ecn.h
inet_frag.h inet: frags: change inet_frag_kill() to defer refcount updates 2025-03-18 13:18:36 +01:00
inet_hashtables.h inet: call inet6_ehashfn() once from inet6_hash_connect() 2025-03-06 15:26:02 -08:00
inet_sock.h
inet_timewait_sock.h
inetpeer.h
ioam6.h
ip.h net: use netif_disable_lro in ipv6_add_dev 2025-04-03 15:32:08 -07:00
ip6_checksum.h
ip6_fib.h
ip6_route.h
ip6_tunnel.h
ip_fib.h ipv4: fib: Allocate fib_info_hash[] during netns initialisation. 2025-03-03 15:04:09 -08:00
ip_tunnels.h net: ip_tunnel: Use link netns in newlink() of rtnl_link_ops 2025-02-21 15:28:02 -08:00
ip_vs.h
ipcomp.h xfrm: ipcomp: Use crypto_acomp interface 2025-03-21 17:36:49 +08:00
ipconfig.h
ipv6.h ipv6: fix _DEVADD() and _DEVUPD() macros 2025-03-25 07:31:24 -07:00
ipv6_frag.h inet: frags: change inet_frag_kill() to defer refcount updates 2025-03-18 13:18:36 +01:00
ipv6_stubs.h
iw_handler.h
kcm.h
l3mdev.h net: fib_rules: Fix iif / oif matching on L3 master device 2025-04-15 17:54:56 -07:00
lag.h
lapb.h
llc.h
llc_c_ac.h
llc_c_ev.h
llc_c_st.h
llc_conn.h
llc_if.h
llc_pdu.h
llc_s_ac.h
llc_s_ev.h
llc_s_st.h
llc_sap.h
lwtunnel.h inet: fix lwtunnel_valid_encap_type() lock imbalance 2025-03-05 19:16:56 -08:00
mac80211.h wifi: mac80211: add ieee80211_iter_chan_contexts_mtx 2025-02-26 15:48:47 +01:00
mac802154.h
macsec.h
mctp.h net: mctp: Remove unnecessary cast in mctp_cb 2025-03-21 18:18:12 +01:00
mctpdevice.h
mip6.h
mld.h
mpls.h
mpls_iptunnel.h
mptcp.h mptcp: sysctl: add available_path_managers 2025-03-20 10:14:49 +01:00
mrp.h
ncsi.h
ndisc.h
neighbour.h
neighbour_tables.h
net_debug.h
net_failover.h
net_namespace.h net: introduce per netns packet chains 2025-03-24 13:58:22 -07:00
net_ratelimit.h
net_shaper.h
net_trackers.h
netdev_lock.h netdevsim: add dummy device notifiers 2025-04-03 15:32:08 -07:00
netdev_netlink.h net: add granular lock for the netdev netlink socket 2025-03-12 13:32:35 -07:00
netdev_queues.h net: report csum_complete via qstats 2025-02-12 16:37:35 -08:00
netdev_rx_queue.h net: designate queue -> napi linking as "ops protected" 2025-03-25 10:06:49 -07:00
netevent.h
netkit.h
netlabel.h
netlink.h netlink: Add nla_put_empty_nest helper 2025-02-17 16:46:03 -08:00
netmem.h net: generalise net_iov chunk owners 2025-02-06 16:27:30 -08:00
netprio_cgroup.h
netrom.h
nexthop.h
nl802154.h
nsh.h
p8022.h
pfcp.h
pie.h
ping.h
pkt_cls.h
pkt_sched.h
pptp.h
proto_memory.h
protocol.h
psample.h
psnap.h
raw.h
rawv6.h
red.h
regulatory.h
request_sock.h
rose.h
route.h ipv4: add RCU protection to ip4_dst_hoplimit() 2025-02-06 16:14:14 -08:00
rpl.h
rps.h net: rfs: hash function change 2025-03-25 08:24:13 -07:00
rsi_91x.h
rstreason.h
rtnetlink.h rtnetlink: Remove "net" from newlink params 2025-02-21 15:28:03 -08:00
rtnh.h
sch_generic.h net: sched: Fix truncation of offloaded action statistics 2025-02-05 18:32:06 -08:00
scm.h
secure_seq.h
seg6.h
seg6_hmac.h
seg6_local.h
selftests.h
slhc_vj.h
smc.h
snmp.h percpu: use TYPEOF_UNQUAL() in variable declarations 2025-03-16 22:05:53 -07:00
sock.h net: Fix null-ptr-deref by sock_lock_init_class_and_name() and rmmod. 2025-04-09 19:11:55 -07:00
sock_reuseport.h
stp.h
strparser.h
switchdev.h
tc_wrapper.h
tcp.h Revert "tcp: avoid atomic operations on sk->sk_rmem_alloc" 2025-03-31 16:53:54 -07:00
tcp_ao.h
tcp_states.h
tcx.h
timewait_sock.h
tipc.h
tls.h
tls_prot.h
tls_toe.h
transp_v6.h
tso.h
tun_proto.h
udp.h Revert "udp_tunnel: GRO optimizations" 2025-03-25 09:15:07 -07:00
udp_tunnel.h Revert "udp_tunnel: GRO optimizations" 2025-03-25 09:15:07 -07:00
udplite.h
vsock_addr.h
vxlan.h
wext.h
x25.h
x25device.h
xdp.h xdp: remove xdp_alloc_skb_bulk() 2025-02-27 14:03:52 +01:00
xdp_priv.h
xdp_sock.h xsk: Add launch time hardware offload support to XDP Tx metadata 2025-02-20 15:13:45 -08:00
xdp_sock_drv.h xsk: Add launch time hardware offload support to XDP Tx metadata 2025-02-20 15:13:45 -08:00
xfrm.h xfrm: check for PMTU in tunnel mode for packet offload 2025-02-21 08:08:15 +01:00
xsk_buff_pool.h xsk: add helper to get &xdp_desc's DMA and meta pointer in one go 2025-02-10 17:54:43 -08:00