@@ -225,13 +225,24 @@ static struct sk_psock *sock_map_psock_get_checked(struct sock *sk)
225225 return psock ;
226226}
227227
228+ static bool sock_map_redirect_allowed (const struct sock * sk );
229+
228230static int sock_map_link (struct bpf_map * map , struct sock * sk )
229231{
230- struct bpf_prog * msg_parser , * stream_parser , * stream_verdict ;
231232 struct sk_psock_progs * progs = sock_map_progs (map );
233+ struct bpf_prog * stream_verdict = NULL ;
234+ struct bpf_prog * stream_parser = NULL ;
235+ struct bpf_prog * msg_parser = NULL ;
232236 struct sk_psock * psock ;
233237 int ret ;
234238
239+ /* Only sockets we can redirect into/from in BPF need to hold
240+ * refs to parser/verdict progs and have their sk_data_ready
241+ * and sk_write_space callbacks overridden.
242+ */
243+ if (!sock_map_redirect_allowed (sk ))
244+ goto no_progs ;
245+
235246 stream_verdict = READ_ONCE (progs -> stream_verdict );
236247 if (stream_verdict ) {
237248 stream_verdict = bpf_prog_inc_not_zero (stream_verdict );
@@ -257,6 +268,7 @@ static int sock_map_link(struct bpf_map *map, struct sock *sk)
257268 }
258269 }
259270
271+ no_progs :
260272 psock = sock_map_psock_get_checked (sk );
261273 if (IS_ERR (psock )) {
262274 ret = PTR_ERR (psock );
@@ -316,27 +328,6 @@ static int sock_map_link(struct bpf_map *map, struct sock *sk)
316328 return ret ;
317329}
318330
319- static int sock_map_link_no_progs (struct bpf_map * map , struct sock * sk )
320- {
321- struct sk_psock * psock ;
322- int ret ;
323-
324- psock = sock_map_psock_get_checked (sk );
325- if (IS_ERR (psock ))
326- return PTR_ERR (psock );
327-
328- if (!psock ) {
329- psock = sk_psock_init (sk , map -> numa_node );
330- if (IS_ERR (psock ))
331- return PTR_ERR (psock );
332- }
333-
334- ret = sock_map_init_proto (sk , psock );
335- if (ret < 0 )
336- sk_psock_put (sk , psock );
337- return ret ;
338- }
339-
340331static void sock_map_free (struct bpf_map * map )
341332{
342333 struct bpf_stab * stab = container_of (map , struct bpf_stab , map );
@@ -467,8 +458,6 @@ static int sock_map_get_next_key(struct bpf_map *map, void *key, void *next)
467458 return 0 ;
468459}
469460
470- static bool sock_map_redirect_allowed (const struct sock * sk );
471-
472461static int sock_map_update_common (struct bpf_map * map , u32 idx ,
473462 struct sock * sk , u64 flags )
474463{
@@ -488,14 +477,7 @@ static int sock_map_update_common(struct bpf_map *map, u32 idx,
488477 if (!link )
489478 return - ENOMEM ;
490479
491- /* Only sockets we can redirect into/from in BPF need to hold
492- * refs to parser/verdict progs and have their sk_data_ready
493- * and sk_write_space callbacks overridden.
494- */
495- if (sock_map_redirect_allowed (sk ))
496- ret = sock_map_link (map , sk );
497- else
498- ret = sock_map_link_no_progs (map , sk );
480+ ret = sock_map_link (map , sk );
499481 if (ret < 0 )
500482 goto out_free ;
501483
@@ -1000,14 +982,7 @@ static int sock_hash_update_common(struct bpf_map *map, void *key,
1000982 if (!link )
1001983 return - ENOMEM ;
1002984
1003- /* Only sockets we can redirect into/from in BPF need to hold
1004- * refs to parser/verdict progs and have their sk_data_ready
1005- * and sk_write_space callbacks overridden.
1006- */
1007- if (sock_map_redirect_allowed (sk ))
1008- ret = sock_map_link (map , sk );
1009- else
1010- ret = sock_map_link_no_progs (map , sk );
985+ ret = sock_map_link (map , sk );
1011986 if (ret < 0 )
1012987 goto out_free ;
1013988
0 commit comments