@@ -682,13 +682,43 @@ static struct sk_psock *sk_psock_from_strp(struct strparser *strp)
682
682
return container_of (parser , struct sk_psock , parser );
683
683
}
684
684
685
- static void sk_psock_verdict_apply (struct sk_psock * psock ,
686
- struct sk_buff * skb , int verdict )
685
+ static void sk_psock_skb_redirect (struct sk_psock * psock , struct sk_buff * skb )
687
686
{
688
687
struct sk_psock * psock_other ;
689
688
struct sock * sk_other ;
690
689
bool ingress ;
691
690
691
+ sk_other = tcp_skb_bpf_redirect_fetch (skb );
692
+ if (unlikely (!sk_other )) {
693
+ kfree_skb (skb );
694
+ return ;
695
+ }
696
+ psock_other = sk_psock (sk_other );
697
+ if (!psock_other || sock_flag (sk_other , SOCK_DEAD ) ||
698
+ !sk_psock_test_state (psock_other , SK_PSOCK_TX_ENABLED )) {
699
+ kfree_skb (skb );
700
+ return ;
701
+ }
702
+
703
+ ingress = tcp_skb_bpf_ingress (skb );
704
+ if ((!ingress && sock_writeable (sk_other )) ||
705
+ (ingress &&
706
+ atomic_read (& sk_other -> sk_rmem_alloc ) <=
707
+ sk_other -> sk_rcvbuf )) {
708
+ if (!ingress )
709
+ skb_set_owner_w (skb , sk_other );
710
+ skb_queue_tail (& psock_other -> ingress_skb , skb );
711
+ schedule_work (& psock_other -> work );
712
+ } else {
713
+ kfree_skb (skb );
714
+ }
715
+ }
716
+
717
+ static void sk_psock_verdict_apply (struct sk_psock * psock ,
718
+ struct sk_buff * skb , int verdict )
719
+ {
720
+ struct sock * sk_other ;
721
+
692
722
switch (verdict ) {
693
723
case __SK_PASS :
694
724
sk_other = psock -> sk ;
@@ -707,25 +737,8 @@ static void sk_psock_verdict_apply(struct sk_psock *psock,
707
737
}
708
738
goto out_free ;
709
739
case __SK_REDIRECT :
710
- sk_other = tcp_skb_bpf_redirect_fetch (skb );
711
- if (unlikely (!sk_other ))
712
- goto out_free ;
713
- psock_other = sk_psock (sk_other );
714
- if (!psock_other || sock_flag (sk_other , SOCK_DEAD ) ||
715
- !sk_psock_test_state (psock_other , SK_PSOCK_TX_ENABLED ))
716
- goto out_free ;
717
- ingress = tcp_skb_bpf_ingress (skb );
718
- if ((!ingress && sock_writeable (sk_other )) ||
719
- (ingress &&
720
- atomic_read (& sk_other -> sk_rmem_alloc ) <=
721
- sk_other -> sk_rcvbuf )) {
722
- if (!ingress )
723
- skb_set_owner_w (skb , sk_other );
724
- skb_queue_tail (& psock_other -> ingress_skb , skb );
725
- schedule_work (& psock_other -> work );
726
- break ;
727
- }
728
- /* fall-through */
740
+ sk_psock_skb_redirect (psock , skb );
741
+ break ;
729
742
case __SK_DROP :
730
743
/* fall-through */
731
744
default :
0 commit comments