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
13741374 const struct in6_addr *daddr;
13751375 } v6;
13761376 struct sock *selected_sk;
1377+ u32 ingress_ifindex;
13771378 bool no_reuseport;
13781379 };
13791380
@@ -1436,7 +1437,7 @@ extern struct static_key_false bpf_sk_lookup_enabled; · 56 unmodified lines
14361437 static inline bool bpf_sk_lookup_run_v4(struct net *net, int protocol,
14371438 const __be32 saddr, const __be16 sport,
14381439 const __be32 daddr, const u16 dport,
1439− struct sock **psk)
1440+ const int ifindex, struct sock **psk)
14401441 {
14411442 struct bpf_prog_array *run_array;
14421443 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
14521453 .v4.daddr = daddr,
14531454 .sport = sport,
14541455 .dport = dport,
1456+ .ingress_ifindex = ifindex,
14551457 };
14561458 u32 act;
14571459
@@ -1474,7 +1476,7 @@ static inline bool bpf_sk_lookup_run_v6(struct net *net, int protocol, · 16 unmodified lines
14741476 const __be16 sport,
14751477 const struct in6_addr *daddr,
14761478 const u16 dport,
1477− struct sock **psk)
1479+ const int ifindex, struct sock **psk)
14781480 {
14791481 struct bpf_prog_array *run_array;
14801482 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
14901492 .v6.daddr = daddr,
14911493 .sport = sport,
14921494 .dport = dport,
1495+ .ingress_ifindex = ifindex,
14931496 };
14941497 u32 act;
14951498
include/uapi/linux/bpf.h+1−0
@@ -6316,6 +6316,7 @@ struct bpf_sk_lookup { · 6315 unmodified lines
63166316 __u32 local_ip4; /* Network byte order */
63176317 __u32 local_ip6[4]; /* Network byte order */
63186318 __u32 local_port; /* Host byte order */
6319+ __u32 ingress_ifindex; /* The arriving interface. Determined by inet_iif. */
63196320 };
63206321
63216322 /*

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