Commit 264b5f8
committed
net: fib_rules: Fix iif / oif matching on L3 master device
JIRA: https://issues.redhat.com/browse/RHEL-84551
Upstream Status: linux.git
Conflicts:\
- Context differences due to missing upstream commit da76659 ("net:
fib_rules: Add port mask support").
- Chunk in fib_nl2rule_rtnl was moved to fib_nl2rule due to missing
upstream commit 8b49877 ("net: fib_rules: Split fib_nl2rule().").
commit 2d300ce
Author: Ido Schimmel <idosch@nvidia.com>
Date: Mon Apr 14 20:20:21 2025 +0300
net: fib_rules: Fix iif / oif matching on L3 master device
Before commit 40867d7 ("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 40867d7 (v5.4.291):
default dev dummy1 table 100 scope link
default dev dummy1 table 200 scope link
Output after 40867d7:
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: 40867d7 ("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>
Signed-off-by: Antoine Tenart <atenart@redhat.com>1 parent 05a94d4 commit 264b5f8
File tree
5 files changed
+73
-9
lines changed- include/net
- net
- core
- l3mdev
5 files changed
+73
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
62 | 76 | | |
63 | 77 | | |
64 | 78 | | |
| |||
327 | 341 | | |
328 | 342 | | |
329 | 343 | | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
330 | 357 | | |
331 | 358 | | |
332 | 359 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
259 | 277 | | |
260 | 278 | | |
261 | 279 | | |
262 | 280 | | |
263 | 281 | | |
264 | 282 | | |
265 | 283 | | |
266 | | - | |
| 284 | + | |
267 | 285 | | |
268 | 286 | | |
269 | 287 | | |
270 | | - | |
| 288 | + | |
271 | 289 | | |
272 | 290 | | |
273 | 291 | | |
| |||
567 | 585 | | |
568 | 586 | | |
569 | 587 | | |
570 | | - | |
| 588 | + | |
571 | 589 | | |
| 590 | + | |
| 591 | + | |
572 | 592 | | |
573 | 593 | | |
574 | 594 | | |
| |||
577 | 597 | | |
578 | 598 | | |
579 | 599 | | |
580 | | - | |
| 600 | + | |
581 | 601 | | |
| 602 | + | |
| 603 | + | |
582 | 604 | | |
583 | 605 | | |
584 | 606 | | |
| |||
1218 | 1240 | | |
1219 | 1241 | | |
1220 | 1242 | | |
1221 | | - | |
| 1243 | + | |
1222 | 1244 | | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
1223 | 1248 | | |
1224 | | - | |
| 1249 | + | |
1225 | 1250 | | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
1226 | 1254 | | |
1227 | 1255 | | |
1228 | 1256 | | |
| |||
1231 | 1259 | | |
1232 | 1260 | | |
1233 | 1261 | | |
1234 | | - | |
| 1262 | + | |
1235 | 1263 | | |
1236 | | - | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
1237 | 1267 | | |
| 1268 | + | |
| 1269 | + | |
1238 | 1270 | | |
1239 | 1271 | | |
1240 | 1272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
| 280 | + | |
281 | 281 | | |
| 282 | + | |
| 283 | + | |
282 | 284 | | |
283 | 285 | | |
284 | 286 | | |
| |||
0 commit comments