@@ -6597,7 +6597,7 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
65976597 else
65986598 sk = __udp4_lib_lookup (net , src4 , tuple -> ipv4 .sport ,
65996599 dst4 , tuple -> ipv4 .dport ,
6600- dif , sdif , & udp_table , NULL );
6600+ dif , sdif , net -> ipv4 . udp_table , NULL );
66016601#if IS_ENABLED (CONFIG_IPV6 )
66026602 } else {
66036603 struct in6_addr * src6 = (struct in6_addr * )& tuple -> ipv6 .saddr ;
@@ -6613,7 +6613,7 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple,
66136613 src6 , tuple -> ipv6 .sport ,
66146614 dst6 , tuple -> ipv6 .dport ,
66156615 dif , sdif ,
6616- & udp_table , NULL );
6616+ net -> ipv4 . udp_table , NULL );
66176617#endif
66186618 }
66196619
@@ -11891,3 +11891,63 @@ static int __init bpf_kfunc_init(void)
1189111891 return ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_XDP , & bpf_kfunc_set_xdp );
1189211892}
1189311893late_initcall (bpf_kfunc_init );
11894+
11895+ __bpf_kfunc_start_defs ();
11896+
11897+ /* bpf_sock_destroy: Destroy the given socket with ECONNABORTED error code.
11898+ *
11899+ * The function expects a non-NULL pointer to a socket, and invokes the
11900+ * protocol specific socket destroy handlers.
11901+ *
11902+ * The helper can only be called from BPF contexts that have acquired the socket
11903+ * locks.
11904+ *
11905+ * Parameters:
11906+ * @sock: Pointer to socket to be destroyed
11907+ *
11908+ * Return:
11909+ * On error, may return EPROTONOSUPPORT, EINVAL.
11910+ * EPROTONOSUPPORT if protocol specific destroy handler is not supported.
11911+ * 0 otherwise
11912+ */
11913+ __bpf_kfunc int bpf_sock_destroy (struct sock_common * sock )
11914+ {
11915+ struct sock * sk = (struct sock * )sock ;
11916+
11917+ /* The locking semantics that allow for synchronous execution of the
11918+ * destroy handlers are only supported for TCP and UDP.
11919+ * Supporting protocols will need to acquire sock lock in the BPF context
11920+ * prior to invoking this kfunc.
11921+ */
11922+ if (!sk -> sk_prot -> diag_destroy || (sk -> sk_protocol != IPPROTO_TCP &&
11923+ sk -> sk_protocol != IPPROTO_UDP ))
11924+ return - EOPNOTSUPP ;
11925+
11926+ return sk -> sk_prot -> diag_destroy (sk , ECONNABORTED );
11927+ }
11928+
11929+ __bpf_kfunc_end_defs ();
11930+
11931+ BTF_KFUNCS_START (bpf_sk_iter_kfunc_ids )
11932+ BTF_ID_FLAGS (func , bpf_sock_destroy , KF_TRUSTED_ARGS )
11933+ BTF_KFUNCS_END (bpf_sk_iter_kfunc_ids )
11934+
11935+ static int tracing_iter_filter (const struct bpf_prog * prog , u32 kfunc_id )
11936+ {
11937+ if (btf_id_set8_contains (& bpf_sk_iter_kfunc_ids , kfunc_id ) &&
11938+ prog -> expected_attach_type != BPF_TRACE_ITER )
11939+ return - EACCES ;
11940+ return 0 ;
11941+ }
11942+
11943+ static const struct btf_kfunc_id_set bpf_sk_iter_kfunc_set = {
11944+ .owner = THIS_MODULE ,
11945+ .set = & bpf_sk_iter_kfunc_ids ,
11946+ .filter = tracing_iter_filter ,
11947+ };
11948+
11949+ static int init_subsystem (void )
11950+ {
11951+ return register_btf_kfunc_id_set (BPF_PROG_TYPE_TRACING , & bpf_sk_iter_kfunc_set );
11952+ }
11953+ late_initcall (init_subsystem );
0 commit comments