@@ -985,56 +985,39 @@ static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf)
985985 return bufp - optr ;
986986}
987987
988- static void l2tp_xmit_core (struct l2tp_session * session , struct sk_buff * skb , struct flowi * fl )
988+ /* Queue the packet to IP for output: tunnel socket lock must be held */
989+ static int l2tp_xmit_queue (struct l2tp_tunnel * tunnel , struct sk_buff * skb , struct flowi * fl )
989990{
990- struct l2tp_tunnel * tunnel = session -> tunnel ;
991- unsigned int len = skb -> len ;
992- int error ;
991+ int err ;
993992
994- /* Queue the packet to IP for output */
995993 skb -> ignore_df = 1 ;
996994 skb_dst_drop (skb );
997995#if IS_ENABLED (CONFIG_IPV6 )
998996 if (l2tp_sk_is_v6 (tunnel -> sock ))
999- error = inet6_csk_xmit (tunnel -> sock , skb , NULL );
997+ err = inet6_csk_xmit (tunnel -> sock , skb , NULL );
1000998 else
1001999#endif
1002- error = ip_queue_xmit (tunnel -> sock , skb , fl );
1000+ err = ip_queue_xmit (tunnel -> sock , skb , fl );
10031001
1004- /* Update stats */
1005- if (error >= 0 ) {
1006- atomic_long_inc (& tunnel -> stats .tx_packets );
1007- atomic_long_add (len , & tunnel -> stats .tx_bytes );
1008- atomic_long_inc (& session -> stats .tx_packets );
1009- atomic_long_add (len , & session -> stats .tx_bytes );
1010- } else {
1011- atomic_long_inc (& tunnel -> stats .tx_errors );
1012- atomic_long_inc (& session -> stats .tx_errors );
1013- }
1002+ return err >= 0 ? NET_XMIT_SUCCESS : NET_XMIT_DROP ;
10141003}
10151004
1016- /* If caller requires the skb to have a ppp header, the header must be
1017- * inserted in the skb data before calling this function.
1018- */
1019- int l2tp_xmit_skb (struct l2tp_session * session , struct sk_buff * skb )
1005+ static int l2tp_xmit_core (struct l2tp_session * session , struct sk_buff * skb )
10201006{
1021- int data_len = skb -> len ;
10221007 struct l2tp_tunnel * tunnel = session -> tunnel ;
1008+ unsigned int data_len = skb -> len ;
10231009 struct sock * sk = tunnel -> sock ;
1024- struct flowi * fl ;
1025- struct udphdr * uh ;
1026- struct inet_sock * inet ;
1027- int headroom ;
1028- int uhlen = (tunnel -> encap == L2TP_ENCAPTYPE_UDP ) ? sizeof (struct udphdr ) : 0 ;
1029- int udp_len ;
1010+ int headroom , uhlen , udp_len ;
10301011 int ret = NET_XMIT_SUCCESS ;
1012+ struct inet_sock * inet ;
1013+ struct udphdr * uh ;
10311014
10321015 /* Check that there's enough headroom in the skb to insert IP,
10331016 * UDP and L2TP headers. If not enough, expand it to
10341017 * make room. Adjust truesize.
10351018 */
1036- headroom = NET_SKB_PAD + sizeof (struct iphdr ) +
1037- uhlen + session -> hdr_len ;
1019+ uhlen = ( tunnel -> encap == L2TP_ENCAPTYPE_UDP ) ? sizeof (* uh ) : 0 ;
1020+ headroom = NET_SKB_PAD + sizeof ( struct iphdr ) + uhlen + session -> hdr_len ;
10381021 if (skb_cow_head (skb , headroom )) {
10391022 kfree_skb (skb );
10401023 return NET_XMIT_DROP ;
@@ -1048,8 +1031,7 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb)
10481031
10491032 /* Reset skb netfilter state */
10501033 memset (& (IPCB (skb )-> opt ), 0 , sizeof (IPCB (skb )-> opt ));
1051- IPCB (skb )-> flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
1052- IPSKB_REROUTED );
1034+ IPCB (skb )-> flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED | IPSKB_REROUTED );
10531035 nf_reset_ct (skb );
10541036
10551037 bh_lock_sock (sk );
@@ -1069,7 +1051,6 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb)
10691051 }
10701052
10711053 inet = inet_sk (sk );
1072- fl = & inet -> cork .fl ;
10731054 switch (tunnel -> encap ) {
10741055 case L2TP_ENCAPTYPE_UDP :
10751056 /* Setup UDP header */
@@ -1097,12 +1078,34 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb)
10971078 break ;
10981079 }
10991080
1100- l2tp_xmit_core (session , skb , fl );
1081+ ret = l2tp_xmit_queue (tunnel , skb , & inet -> cork .fl );
1082+
11011083out_unlock :
11021084 bh_unlock_sock (sk );
11031085
11041086 return ret ;
11051087}
1088+
1089+ /* If caller requires the skb to have a ppp header, the header must be
1090+ * inserted in the skb data before calling this function.
1091+ */
1092+ int l2tp_xmit_skb (struct l2tp_session * session , struct sk_buff * skb )
1093+ {
1094+ unsigned int len = skb -> len ;
1095+ int ret ;
1096+
1097+ ret = l2tp_xmit_core (session , skb );
1098+ if (ret == NET_XMIT_SUCCESS ) {
1099+ atomic_long_inc (& session -> tunnel -> stats .tx_packets );
1100+ atomic_long_add (len , & session -> tunnel -> stats .tx_bytes );
1101+ atomic_long_inc (& session -> stats .tx_packets );
1102+ atomic_long_add (len , & session -> stats .tx_bytes );
1103+ } else {
1104+ atomic_long_inc (& session -> tunnel -> stats .tx_errors );
1105+ atomic_long_inc (& session -> stats .tx_errors );
1106+ }
1107+ return ret ;
1108+ }
11061109EXPORT_SYMBOL_GPL (l2tp_xmit_skb );
11071110
11081111/*****************************************************************************
0 commit comments