|
74 | 74 | #include <net/lwtunnel.h>
|
75 | 75 | #include <net/ipv6_stubs.h>
|
76 | 76 | #include <net/bpf_sk_storage.h>
|
| 77 | +#include <net/transp_v6.h> |
77 | 78 |
|
78 | 79 | /**
|
79 | 80 | * sk_filter_trim_cap - run a packet through a socket filter
|
@@ -9307,3 +9308,64 @@ const struct bpf_func_proto bpf_skc_to_tcp6_sock_proto = {
|
9307 | 9308 | .check_btf_id = check_arg_btf_id,
|
9308 | 9309 | .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_TCP6],
|
9309 | 9310 | };
|
| 9311 | + |
| 9312 | +BPF_CALL_1(bpf_skc_to_tcp_sock, struct sock *, sk) |
| 9313 | +{ |
| 9314 | + if (sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP) |
| 9315 | + return (unsigned long)sk; |
| 9316 | + |
| 9317 | + return (unsigned long)NULL; |
| 9318 | +} |
| 9319 | + |
| 9320 | +const struct bpf_func_proto bpf_skc_to_tcp_sock_proto = { |
| 9321 | + .func = bpf_skc_to_tcp_sock, |
| 9322 | + .gpl_only = false, |
| 9323 | + .ret_type = RET_PTR_TO_BTF_ID_OR_NULL, |
| 9324 | + .arg1_type = ARG_PTR_TO_BTF_ID, |
| 9325 | + .check_btf_id = check_arg_btf_id, |
| 9326 | + .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_TCP], |
| 9327 | +}; |
| 9328 | + |
| 9329 | +BPF_CALL_1(bpf_skc_to_tcp_timewait_sock, struct sock *, sk) |
| 9330 | +{ |
| 9331 | + if (sk->sk_prot == &tcp_prot && sk->sk_state == TCP_TIME_WAIT) |
| 9332 | + return (unsigned long)sk; |
| 9333 | + |
| 9334 | +#if IS_BUILTIN(CONFIG_IPV6) |
| 9335 | + if (sk->sk_prot == &tcpv6_prot && sk->sk_state == TCP_TIME_WAIT) |
| 9336 | + return (unsigned long)sk; |
| 9337 | +#endif |
| 9338 | + |
| 9339 | + return (unsigned long)NULL; |
| 9340 | +} |
| 9341 | + |
| 9342 | +const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto = { |
| 9343 | + .func = bpf_skc_to_tcp_timewait_sock, |
| 9344 | + .gpl_only = false, |
| 9345 | + .ret_type = RET_PTR_TO_BTF_ID_OR_NULL, |
| 9346 | + .arg1_type = ARG_PTR_TO_BTF_ID, |
| 9347 | + .check_btf_id = check_arg_btf_id, |
| 9348 | + .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_TCP_TW], |
| 9349 | +}; |
| 9350 | + |
| 9351 | +BPF_CALL_1(bpf_skc_to_tcp_request_sock, struct sock *, sk) |
| 9352 | +{ |
| 9353 | + if (sk->sk_prot == &tcp_prot && sk->sk_state == TCP_NEW_SYN_RECV) |
| 9354 | + return (unsigned long)sk; |
| 9355 | + |
| 9356 | +#if IS_BUILTIN(CONFIG_IPV6) |
| 9357 | + if (sk->sk_prot == &tcpv6_prot && sk->sk_state == TCP_NEW_SYN_RECV) |
| 9358 | + return (unsigned long)sk; |
| 9359 | +#endif |
| 9360 | + |
| 9361 | + return (unsigned long)NULL; |
| 9362 | +} |
| 9363 | + |
| 9364 | +const struct bpf_func_proto bpf_skc_to_tcp_request_sock_proto = { |
| 9365 | + .func = bpf_skc_to_tcp_request_sock, |
| 9366 | + .gpl_only = false, |
| 9367 | + .ret_type = RET_PTR_TO_BTF_ID_OR_NULL, |
| 9368 | + .arg1_type = ARG_PTR_TO_BTF_ID, |
| 9369 | + .check_btf_id = check_arg_btf_id, |
| 9370 | + .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_TCP_REQ], |
| 9371 | +}; |
0 commit comments