History

bpf: Add ingress_ifindex to bpf_sk_lookup

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.

Mark Pashmfouroush committed 5 years ago

Commit f8931561 parent 1a8b5978 files · +30 −18Browse files

Showing the changes to include (2 of 8 files). Show all

Unified · Split

2 files
  1. include/linux/filter.h +5 −2
  2. include/uapi/linux/bpf.h +1 −0
include/linux/filter.h+5−2
@@ -1374,6 +1374,7 @@ struct bpf_sk_lookup_kern { · 1373 unmodified lines
1374 const struct in6_addr *daddr;1374 const struct in6_addr *daddr;
1375 } v6;1375 } v6;
1376 struct sock *selected_sk;1376 struct sock *selected_sk;
1377 u32 ingress_ifindex;
1377 bool no_reuseport;1378 bool no_reuseport;
1378};1379};
1379 1380
@@ -1436,7 +1437,7 @@ extern struct static_key_false bpf_sk_lookup_enabled; · 56 unmodified lines
1436static inline bool bpf_sk_lookup_run_v4(struct net *net, int protocol,1437static inline bool bpf_sk_lookup_run_v4(struct net *net, int protocol,
1437 const __be32 saddr, const __be16 sport,1438 const __be32 saddr, const __be16 sport,
1438 const __be32 daddr, const u16 dport,1439 const __be32 daddr, const u16 dport,
1439 struct sock **psk)1440 const int ifindex, struct sock **psk)
1440{1441{
1441 struct bpf_prog_array *run_array;1442 struct bpf_prog_array *run_array;
1442 struct sock *selected_sk = NULL;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 .v4.daddr = daddr,1453 .v4.daddr = daddr,
1453 .sport = sport,1454 .sport = sport,
1454 .dport = dport,1455 .dport = dport,
1456 .ingress_ifindex = ifindex,
1455 };1457 };
1456 u32 act;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 const __be16 sport,1476 const __be16 sport,
1475 const struct in6_addr *daddr,1477 const struct in6_addr *daddr,
1476 const u16 dport,1478 const u16 dport,
1477 struct sock **psk)1479 const int ifindex, struct sock **psk)
1478{1480{
1479 struct bpf_prog_array *run_array;1481 struct bpf_prog_array *run_array;
1480 struct sock *selected_sk = NULL;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 .v6.daddr = daddr,1492 .v6.daddr = daddr,
1491 .sport = sport,1493 .sport = sport,
1492 .dport = dport,1494 .dport = dport,
1495 .ingress_ifindex = ifindex,
1493 };1496 };
1494 u32 act;1497 u32 act;
1495 1498
include/uapi/linux/bpf.h+1−0
@@ -6316,6 +6316,7 @@ struct bpf_sk_lookup { · 6315 unmodified lines
6316 __u32 local_ip4; /* Network byte order */6316 __u32 local_ip4; /* Network byte order */
6317 __u32 local_ip6[4]; /* Network byte order */6317 __u32 local_ip6[4]; /* Network byte order */
6318 __u32 local_port; /* Host byte order */6318 __u32 local_port; /* Host byte order */
6319 __u32 ingress_ifindex; /* The arriving interface. Determined by inet_iif. */
6319};6320};
6320 6321
6321/*6322/*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t