@@ -182,6 +182,7 @@ enum {
182182static struct proto * saved_tcpv6_prot __read_mostly ;
183183static DEFINE_SPINLOCK (tcpv6_prot_lock );
184184static struct proto bpf_tcp_prots [SOCKMAP_NUM_PROTS ][SOCKMAP_NUM_CONFIGS ];
185+
185186static void build_protos (struct proto prot [SOCKMAP_NUM_CONFIGS ],
186187 struct proto * base )
187188{
@@ -239,6 +240,13 @@ static int bpf_tcp_init(struct sock *sk)
239240 return 0 ;
240241}
241242
243+ static int __init bpf_sock_init (void )
244+ {
245+ build_protos (bpf_tcp_prots [SOCKMAP_IPV4 ], & tcp_prot );
246+ return 0 ;
247+ }
248+ core_initcall (bpf_sock_init );
249+
242250static void smap_release_sock (struct smap_psock * psock , struct sock * sock );
243251static int free_start_sg (struct sock * sk , struct sk_msg_buff * md , bool charge );
244252
@@ -413,15 +421,6 @@ enum __sk_action {
413421 __SK_NONE ,
414422};
415423
416- static struct tcp_ulp_ops bpf_tcp_ulp_ops __read_mostly = {
417- .name = "bpf_tcp" ,
418- .uid = TCP_ULP_BPF ,
419- .user_visible = false,
420- .owner = NULL ,
421- .init = bpf_tcp_init ,
422- .release = bpf_tcp_release ,
423- };
424-
425424static int memcopy_from_iter (struct sock * sk ,
426425 struct sk_msg_buff * md ,
427426 struct iov_iter * from , int bytes )
@@ -1236,16 +1235,6 @@ static void bpf_tcp_msg_add(struct smap_psock *psock,
12361235 bpf_prog_put (orig_tx_msg );
12371236}
12381237
1239- static int bpf_tcp_ulp_register (void )
1240- {
1241- build_protos (bpf_tcp_prots [SOCKMAP_IPV4 ], & tcp_prot );
1242- /* Once BPF TX ULP is registered it is never unregistered. It
1243- * will be in the ULP list for the lifetime of the system. Doing
1244- * duplicate registers is not a problem.
1245- */
1246- return tcp_register_ulp (& bpf_tcp_ulp_ops );
1247- }
1248-
12491238static int smap_verdict_func (struct smap_psock * psock , struct sk_buff * skb )
12501239{
12511240 struct bpf_prog * prog = READ_ONCE (psock -> bpf_verdict );
@@ -1491,7 +1480,7 @@ static void smap_release_sock(struct smap_psock *psock, struct sock *sock)
14911480{
14921481 if (refcount_dec_and_test (& psock -> refcnt )) {
14931482 if (psock_is_smap_sk (sock ))
1494- tcp_cleanup_ulp (sock );
1483+ bpf_tcp_release (sock );
14951484 write_lock_bh (& sock -> sk_callback_lock );
14961485 smap_stop_sock (psock , sock );
14971486 write_unlock_bh (& sock -> sk_callback_lock );
@@ -1666,10 +1655,6 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr)
16661655 attr -> value_size != 4 || attr -> map_flags & ~SOCK_CREATE_FLAG_MASK )
16671656 return ERR_PTR (- EINVAL );
16681657
1669- err = bpf_tcp_ulp_register ();
1670- if (err && err != - EEXIST )
1671- return ERR_PTR (err );
1672-
16731658 stab = kzalloc (sizeof (* stab ), GFP_USER );
16741659 if (!stab )
16751660 return ERR_PTR (- ENOMEM );
@@ -1951,7 +1936,7 @@ static int __sock_map_ctx_update_elem(struct bpf_map *map,
19511936 if (tx_msg )
19521937 bpf_tcp_msg_add (psock , sock , tx_msg );
19531938 if (new ) {
1954- err = tcp_set_ulp_id (sock , TCP_ULP_BPF );
1939+ err = bpf_tcp_init (sock );
19551940 if (err )
19561941 goto out_free ;
19571942 }
@@ -2187,10 +2172,6 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
21872172 */
21882173 return ERR_PTR (- E2BIG );
21892174
2190- err = bpf_tcp_ulp_register ();
2191- if (err && err != - EEXIST )
2192- return ERR_PTR (err );
2193-
21942175 htab = kzalloc (sizeof (* htab ), GFP_USER );
21952176 if (!htab )
21962177 return ERR_PTR (- ENOMEM );
0 commit comments