It may be helpful to have access to the ifindex during bpf socket lookup. An example may be to scope certain socket lookup logic to specific interfaces, i.e. an interface may be made exempt from custom lookup code. Add the ifindex of the arriving connection to the bpf_sk_lookup API.
Showing the changes to include (2 of 8 files). Show all
Unified · Split
| @@ -1374,6 +1374,7 @@ struct bpf_sk_lookup_kern { · 1373 unmodified lines | ||
| 1374 | 1374 | const struct in6_addr *daddr; |
| 1375 | 1375 | } v6; |
| 1376 | 1376 | struct sock *selected_sk; |
| 1377 | + u32 ingress_ifindex; | |
| 1377 | 1378 | bool no_reuseport; |
| 1378 | 1379 | }; |
| 1379 | 1380 | |
| @@ -1436,7 +1437,7 @@ extern struct static_key_false bpf_sk_lookup_enabled; · 56 unmodified lines | ||
| 1436 | 1437 | static inline bool bpf_sk_lookup_run_v4(struct net *net, int protocol, |
| 1437 | 1438 | const __be32 saddr, const __be16 sport, |
| 1438 | 1439 | const __be32 daddr, const u16 dport, |
| 1439 | − struct sock **psk) | |
| 1440 | + const int ifindex, struct sock **psk) | |
| 1440 | 1441 | { |
| 1441 | 1442 | struct bpf_prog_array *run_array; |
| 1442 | 1443 | struct sock *selected_sk = NULL; |
| @@ -1452,6 +1453,7 @@ static inline bool bpf_sk_lookup_run_v4(struct net *net, int protocol, · 9 unmodified lines | ||
| 1452 | 1453 | .v4.daddr = daddr, |
| 1453 | 1454 | .sport = sport, |
| 1454 | 1455 | .dport = dport, |
| 1456 | + .ingress_ifindex = ifindex, | |
| 1455 | 1457 | }; |
| 1456 | 1458 | u32 act; |
| 1457 | 1459 | |
| @@ -1474,7 +1476,7 @@ static inline bool bpf_sk_lookup_run_v6(struct net *net, int protocol, · 16 unmodified lines | ||
| 1474 | 1476 | const __be16 sport, |
| 1475 | 1477 | const struct in6_addr *daddr, |
| 1476 | 1478 | const u16 dport, |
| 1477 | − struct sock **psk) | |
| 1479 | + const int ifindex, struct sock **psk) | |
| 1478 | 1480 | { |
| 1479 | 1481 | struct bpf_prog_array *run_array; |
| 1480 | 1482 | struct sock *selected_sk = NULL; |
| @@ -1490,6 +1492,7 @@ static inline bool bpf_sk_lookup_run_v6(struct net *net, int protocol, · 9 unmodified lines | ||
| 1490 | 1492 | .v6.daddr = daddr, |
| 1491 | 1493 | .sport = sport, |
| 1492 | 1494 | .dport = dport, |
| 1495 | + .ingress_ifindex = ifindex, | |
| 1493 | 1496 | }; |
| 1494 | 1497 | u32 act; |
| 1495 | 1498 | |
| @@ -6316,6 +6316,7 @@ struct bpf_sk_lookup { · 6315 unmodified lines | ||
| 6316 | 6316 | __u32 local_ip4; /* Network byte order */ |
| 6317 | 6317 | __u32 local_ip6[4]; /* Network byte order */ |
| 6318 | 6318 | __u32 local_port; /* Host byte order */ |
| 6319 | + __u32 ingress_ifindex; /* The arriving interface. Determined by inet_iif. */ | |
| 6319 | 6320 | }; |
| 6320 | 6321 | |
| 6321 | 6322 | /* |