Repository navigation
Commit dbafd7d
bpf: Add bpf_get_listener_sock(struct bpf_sock *sk) helper
Add a new helper "struct bpf_sock *bpf_get_listener_sock(struct bpf_sock *sk)"
which returns a bpf_sock in TCP_LISTEN state. It will trace back to
the listener sk from a request_sock if possible. It returns NULL
for all other cases.
No reference is taken because the helper ensures the sk is
in SOCK_RCU_FREE (where the TCP_LISTEN sock should be in).
Hence, bpf_sk_release() is unnecessary and the verifier does not
allow bpf_sk_release(listen_sk) to be called either.
The following is also allowed because the bpf_prog is run under
rcu_read_lock():
sk = bpf_sk_lookup_tcp();
/* if (!sk) { ... } */
listen_sk = bpf_get_listener_sock(sk);
/* if (!listen_sk) { ... } */
bpf_sk_release(sk);
src_port = listen_sk->src_port; /* Allowed */
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>1 parent 1b98658 commit dbafd7d
2 files changed
Lines changed: 31 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2366 | 2366 | | |
2367 | 2367 | | |
2368 | 2368 | | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
2369 | 2377 | | |
2370 | 2378 | | |
2371 | 2379 | | |
| |||
2465 | 2473 | | |
2466 | 2474 | | |
2467 | 2475 | | |
2468 | | - | |
| 2476 | + | |
| 2477 | + | |
2469 | 2478 | | |
2470 | 2479 | | |
2471 | 2480 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5418 | 5418 | | |
5419 | 5419 | | |
5420 | 5420 | | |
| 5421 | + | |
| 5422 | + | |
| 5423 | + | |
| 5424 | + | |
| 5425 | + | |
| 5426 | + | |
| 5427 | + | |
| 5428 | + | |
| 5429 | + | |
| 5430 | + | |
| 5431 | + | |
| 5432 | + | |
| 5433 | + | |
| 5434 | + | |
| 5435 | + | |
| 5436 | + | |
| 5437 | + | |
5421 | 5438 | | |
5422 | 5439 | | |
5423 | 5440 | | |
| |||
5603 | 5620 | | |
5604 | 5621 | | |
5605 | 5622 | | |
| 5623 | + | |
| 5624 | + | |
5606 | 5625 | | |
5607 | 5626 | | |
5608 | 5627 | | |
| |||
5698 | 5717 | | |
5699 | 5718 | | |
5700 | 5719 | | |
| 5720 | + | |
| 5721 | + | |
5701 | 5722 | | |
5702 | 5723 | | |
5703 | 5724 | | |
| |||
0 commit comments