forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/net/l2tp/l2tp_core.c
....@@ -1,5 +1,5 @@
1
-/*
2
- * L2TP core.
1
+// SPDX-License-Identifier: GPL-2.0-only
2
+/* L2TP core.
33 *
44 * Copyright (c) 2008,2009,2010 Katalix Systems Ltd
55 *
....@@ -12,10 +12,6 @@
1212 * Michal Ostrowski <mostrows@speakeasy.net>
1313 * Arnaldo Carvalho de Melo <acme@xconectiva.com.br>
1414 * David S. Miller (davem@redhat.com)
15
- *
16
- * This program is free software; you can redistribute it and/or modify
17
- * it under the terms of the GNU General Public License version 2 as
18
- * published by the Free Software Foundation.
1915 */
2016
2117 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -65,6 +61,10 @@
6561 #include <linux/atomic.h>
6662
6763 #include "l2tp_core.h"
64
+#include "trace.h"
65
+
66
+#define CREATE_TRACE_POINTS
67
+#include "trace.h"
6868
6969 #define L2TP_DRV_VERSION "V2.0"
7070
....@@ -97,7 +97,7 @@
9797 unsigned long expires;
9898 };
9999
100
-#define L2TP_SKB_CB(skb) ((struct l2tp_skb_cb *) &skb->cb[sizeof(struct inet_skb_parm)])
100
+#define L2TP_SKB_CB(skb) ((struct l2tp_skb_cb *)&(skb)->cb[sizeof(struct inet_skb_parm)])
101101
102102 static struct workqueue_struct *l2tp_wq;
103103
....@@ -105,8 +105,10 @@
105105 static unsigned int l2tp_net_id;
106106 struct l2tp_net {
107107 struct list_head l2tp_tunnel_list;
108
+ /* Lock for write access to l2tp_tunnel_list */
108109 spinlock_t l2tp_tunnel_list_lock;
109110 struct hlist_head l2tp_session_hlist[L2TP_HASH_SIZE_2];
111
+ /* Lock for write access to l2tp_session_hlist */
110112 spinlock_t l2tp_session_hlist_lock;
111113 };
112114
....@@ -118,15 +120,8 @@
118120 }
119121 #endif
120122
121
-static inline struct l2tp_tunnel *l2tp_tunnel(struct sock *sk)
122
-{
123
- return sk->sk_user_data;
124
-}
125
-
126123 static inline struct l2tp_net *l2tp_pernet(const struct net *net)
127124 {
128
- BUG_ON(!net);
129
-
130125 return net_generic(net, l2tp_net_id);
131126 }
132127
....@@ -139,7 +134,6 @@
139134 l2tp_session_id_hash_2(struct l2tp_net *pn, u32 session_id)
140135 {
141136 return &pn->l2tp_session_hlist[hash_32(session_id, L2TP_HASH_BITS_2)];
142
-
143137 }
144138
145139 /* Session hash list.
....@@ -154,12 +148,58 @@
154148 return &tunnel->session_hlist[hash_32(session_id, L2TP_HASH_BITS)];
155149 }
156150
157
-void l2tp_tunnel_free(struct l2tp_tunnel *tunnel)
151
+static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel)
158152 {
153
+ trace_free_tunnel(tunnel);
159154 sock_put(tunnel->sock);
160155 /* the tunnel is freed in the socket destructor */
161156 }
162
-EXPORT_SYMBOL(l2tp_tunnel_free);
157
+
158
+static void l2tp_session_free(struct l2tp_session *session)
159
+{
160
+ trace_free_session(session);
161
+ if (session->tunnel)
162
+ l2tp_tunnel_dec_refcount(session->tunnel);
163
+ kfree(session);
164
+}
165
+
166
+struct l2tp_tunnel *l2tp_sk_to_tunnel(struct sock *sk)
167
+{
168
+ struct l2tp_tunnel *tunnel = sk->sk_user_data;
169
+
170
+ if (tunnel)
171
+ if (WARN_ON(tunnel->magic != L2TP_TUNNEL_MAGIC))
172
+ return NULL;
173
+
174
+ return tunnel;
175
+}
176
+EXPORT_SYMBOL_GPL(l2tp_sk_to_tunnel);
177
+
178
+void l2tp_tunnel_inc_refcount(struct l2tp_tunnel *tunnel)
179
+{
180
+ refcount_inc(&tunnel->ref_count);
181
+}
182
+EXPORT_SYMBOL_GPL(l2tp_tunnel_inc_refcount);
183
+
184
+void l2tp_tunnel_dec_refcount(struct l2tp_tunnel *tunnel)
185
+{
186
+ if (refcount_dec_and_test(&tunnel->ref_count))
187
+ l2tp_tunnel_free(tunnel);
188
+}
189
+EXPORT_SYMBOL_GPL(l2tp_tunnel_dec_refcount);
190
+
191
+void l2tp_session_inc_refcount(struct l2tp_session *session)
192
+{
193
+ refcount_inc(&session->ref_count);
194
+}
195
+EXPORT_SYMBOL_GPL(l2tp_session_inc_refcount);
196
+
197
+void l2tp_session_dec_refcount(struct l2tp_session *session)
198
+{
199
+ if (refcount_dec_and_test(&session->ref_count))
200
+ l2tp_session_free(session);
201
+}
202
+EXPORT_SYMBOL_GPL(l2tp_session_dec_refcount);
163203
164204 /* Lookup a tunnel. A new reference is held on the returned tunnel. */
165205 struct l2tp_tunnel *l2tp_tunnel_get(const struct net *net, u32 tunnel_id)
....@@ -347,6 +387,8 @@
347387 hlist_add_head(&session->hlist, head);
348388 write_unlock_bh(&tunnel->hlist_lock);
349389
390
+ trace_register_session(session);
391
+
350392 return 0;
351393
352394 err_tlock_pnlock:
....@@ -375,10 +417,6 @@
375417 skb_queue_walk_safe(&session->reorder_q, skbp, tmp) {
376418 if (L2TP_SKB_CB(skbp)->ns > ns) {
377419 __skb_queue_before(&session->reorder_q, skbp, skb);
378
- l2tp_dbg(session, L2TP_MSG_SEQ,
379
- "%s: pkt %hu, inserted before %hu, reorder_q len=%d\n",
380
- session->name, ns, L2TP_SKB_CB(skbp)->ns,
381
- skb_queue_len(&session->reorder_q));
382420 atomic_long_inc(&session->stats.rx_oos_packets);
383421 goto out;
384422 }
....@@ -411,13 +449,11 @@
411449 /* Bump our Nr */
412450 session->nr++;
413451 session->nr &= session->nr_max;
414
-
415
- l2tp_dbg(session, L2TP_MSG_SEQ, "%s: updated nr to %hu\n",
416
- session->name, session->nr);
452
+ trace_session_seqnum_update(session);
417453 }
418454
419455 /* call private receive handler */
420
- if (session->recv_skb != NULL)
456
+ if (session->recv_skb)
421457 (*session->recv_skb)(session, skb, L2TP_SKB_CB(skb)->length);
422458 else
423459 kfree_skb(skb);
....@@ -438,37 +474,27 @@
438474 start:
439475 spin_lock_bh(&session->reorder_q.lock);
440476 skb_queue_walk_safe(&session->reorder_q, skb, tmp) {
441
- if (time_after(jiffies, L2TP_SKB_CB(skb)->expires)) {
477
+ struct l2tp_skb_cb *cb = L2TP_SKB_CB(skb);
478
+
479
+ /* If the packet has been pending on the queue for too long, discard it */
480
+ if (time_after(jiffies, cb->expires)) {
442481 atomic_long_inc(&session->stats.rx_seq_discards);
443482 atomic_long_inc(&session->stats.rx_errors);
444
- l2tp_dbg(session, L2TP_MSG_SEQ,
445
- "%s: oos pkt %u len %d discarded (too old), waiting for %u, reorder_q_len=%d\n",
446
- session->name, L2TP_SKB_CB(skb)->ns,
447
- L2TP_SKB_CB(skb)->length, session->nr,
448
- skb_queue_len(&session->reorder_q));
483
+ trace_session_pkt_expired(session, cb->ns);
449484 session->reorder_skip = 1;
450485 __skb_unlink(skb, &session->reorder_q);
451486 kfree_skb(skb);
452487 continue;
453488 }
454489
455
- if (L2TP_SKB_CB(skb)->has_seq) {
490
+ if (cb->has_seq) {
456491 if (session->reorder_skip) {
457
- l2tp_dbg(session, L2TP_MSG_SEQ,
458
- "%s: advancing nr to next pkt: %u -> %u",
459
- session->name, session->nr,
460
- L2TP_SKB_CB(skb)->ns);
461492 session->reorder_skip = 0;
462
- session->nr = L2TP_SKB_CB(skb)->ns;
493
+ session->nr = cb->ns;
494
+ trace_session_seqnum_reset(session);
463495 }
464
- if (L2TP_SKB_CB(skb)->ns != session->nr) {
465
- l2tp_dbg(session, L2TP_MSG_SEQ,
466
- "%s: holding oos pkt %u len %d, waiting for %u, reorder_q_len=%d\n",
467
- session->name, L2TP_SKB_CB(skb)->ns,
468
- L2TP_SKB_CB(skb)->length, session->nr,
469
- skb_queue_len(&session->reorder_q));
496
+ if (cb->ns != session->nr)
470497 goto out;
471
- }
472498 }
473499 __skb_unlink(skb, &session->reorder_q);
474500
....@@ -501,14 +527,13 @@
501527 */
502528 static int l2tp_recv_data_seq(struct l2tp_session *session, struct sk_buff *skb)
503529 {
504
- if (!l2tp_seq_check_rx_window(session, L2TP_SKB_CB(skb)->ns)) {
530
+ struct l2tp_skb_cb *cb = L2TP_SKB_CB(skb);
531
+
532
+ if (!l2tp_seq_check_rx_window(session, cb->ns)) {
505533 /* Packet sequence number is outside allowed window.
506534 * Discard it.
507535 */
508
- l2tp_dbg(session, L2TP_MSG_SEQ,
509
- "%s: pkt %u len %d discarded, outside window, nr=%u\n",
510
- session->name, L2TP_SKB_CB(skb)->ns,
511
- L2TP_SKB_CB(skb)->length, session->nr);
536
+ trace_session_pkt_outside_rx_window(session, cb->ns);
512537 goto discard;
513538 }
514539
....@@ -525,10 +550,10 @@
525550 * is seen. After nr_oos_count_max in-sequence packets, reset the
526551 * sequence number to re-enable packet reception.
527552 */
528
- if (L2TP_SKB_CB(skb)->ns == session->nr) {
553
+ if (cb->ns == session->nr) {
529554 skb_queue_tail(&session->reorder_q, skb);
530555 } else {
531
- u32 nr_oos = L2TP_SKB_CB(skb)->ns;
556
+ u32 nr_oos = cb->ns;
532557 u32 nr_next = (session->nr_oos + 1) & session->nr_max;
533558
534559 if (nr_oos == nr_next)
....@@ -539,17 +564,10 @@
539564 session->nr_oos = nr_oos;
540565 if (session->nr_oos_count > session->nr_oos_count_max) {
541566 session->reorder_skip = 1;
542
- l2tp_dbg(session, L2TP_MSG_SEQ,
543
- "%s: %d oos packets received. Resetting sequence numbers\n",
544
- session->name, session->nr_oos_count);
545567 }
546568 if (!session->reorder_skip) {
547569 atomic_long_inc(&session->stats.rx_seq_discards);
548
- l2tp_dbg(session, L2TP_MSG_SEQ,
549
- "%s: oos pkt %u len %d discarded, waiting for %u, reorder_q_len=%d\n",
550
- session->name, L2TP_SKB_CB(skb)->ns,
551
- L2TP_SKB_CB(skb)->length, session->nr,
552
- skb_queue_len(&session->reorder_q));
570
+ trace_session_pkt_oos(session, cb->ns);
553571 goto discard;
554572 }
555573 skb_queue_tail(&session->reorder_q, skb);
....@@ -627,15 +645,13 @@
627645 {
628646 struct l2tp_tunnel *tunnel = session->tunnel;
629647 int offset;
630
- u32 ns, nr;
631648
632649 /* Parse and check optional cookie */
633650 if (session->peer_cookie_len > 0) {
634651 if (memcmp(ptr, &session->peer_cookie[0], session->peer_cookie_len)) {
635
- l2tp_info(tunnel, L2TP_MSG_DATA,
636
- "%s: cookie mismatch (%u/%u). Discarding.\n",
637
- tunnel->name, tunnel->tunnel_id,
638
- session->session_id);
652
+ pr_debug_ratelimited("%s: cookie mismatch (%u/%u). Discarding.\n",
653
+ tunnel->name, tunnel->tunnel_id,
654
+ session->session_id);
639655 atomic_long_inc(&session->stats.rx_cookie_discards);
640656 goto discard;
641657 }
....@@ -649,49 +665,35 @@
649665 * the control of the LNS. If no sequence numbers present but
650666 * we were expecting them, discard frame.
651667 */
652
- ns = nr = 0;
653668 L2TP_SKB_CB(skb)->has_seq = 0;
654669 if (tunnel->version == L2TP_HDR_VER_2) {
655670 if (hdrflags & L2TP_HDRFLAG_S) {
656
- ns = ntohs(*(__be16 *) ptr);
657
- ptr += 2;
658
- nr = ntohs(*(__be16 *) ptr);
659
- ptr += 2;
660
-
661671 /* Store L2TP info in the skb */
662
- L2TP_SKB_CB(skb)->ns = ns;
672
+ L2TP_SKB_CB(skb)->ns = ntohs(*(__be16 *)ptr);
663673 L2TP_SKB_CB(skb)->has_seq = 1;
674
+ ptr += 2;
675
+ /* Skip past nr in the header */
676
+ ptr += 2;
664677
665
- l2tp_dbg(session, L2TP_MSG_SEQ,
666
- "%s: recv data ns=%u, nr=%u, session nr=%u\n",
667
- session->name, ns, nr, session->nr);
668678 }
669679 } else if (session->l2specific_type == L2TP_L2SPECTYPE_DEFAULT) {
670
- u32 l2h = ntohl(*(__be32 *) ptr);
680
+ u32 l2h = ntohl(*(__be32 *)ptr);
671681
672682 if (l2h & 0x40000000) {
673
- ns = l2h & 0x00ffffff;
674
-
675683 /* Store L2TP info in the skb */
676
- L2TP_SKB_CB(skb)->ns = ns;
684
+ L2TP_SKB_CB(skb)->ns = l2h & 0x00ffffff;
677685 L2TP_SKB_CB(skb)->has_seq = 1;
678
-
679
- l2tp_dbg(session, L2TP_MSG_SEQ,
680
- "%s: recv data ns=%u, session nr=%u\n",
681
- session->name, ns, session->nr);
682686 }
683687 ptr += 4;
684688 }
685689
686690 if (L2TP_SKB_CB(skb)->has_seq) {
687
- /* Received a packet with sequence numbers. If we're the LNS,
691
+ /* Received a packet with sequence numbers. If we're the LAC,
688692 * check if we sre sending sequence numbers and if not,
689693 * configure it so.
690694 */
691
- if ((!session->lns_mode) && (!session->send_seq)) {
692
- l2tp_info(session, L2TP_MSG_SEQ,
693
- "%s: requested to enable seq numbers by LNS\n",
694
- session->name);
695
+ if (!session->lns_mode && !session->send_seq) {
696
+ trace_session_seqnum_lns_enable(session);
695697 session->send_seq = 1;
696698 l2tp_session_set_header_len(session, tunnel->version);
697699 }
....@@ -700,9 +702,8 @@
700702 * If user has configured mandatory sequence numbers, discard.
701703 */
702704 if (session->recv_seq) {
703
- l2tp_warn(session, L2TP_MSG_SEQ,
704
- "%s: recv data has no seq numbers when required. Discarding.\n",
705
- session->name);
705
+ pr_debug_ratelimited("%s: recv data has no seq numbers when required. Discarding.\n",
706
+ session->name);
706707 atomic_long_inc(&session->stats.rx_seq_discards);
707708 goto discard;
708709 }
....@@ -712,16 +713,13 @@
712713 * If we're the LNS and we're sending sequence numbers, the
713714 * LAC is broken. Discard the frame.
714715 */
715
- if ((!session->lns_mode) && (session->send_seq)) {
716
- l2tp_info(session, L2TP_MSG_SEQ,
717
- "%s: requested to disable seq numbers by LNS\n",
718
- session->name);
716
+ if (!session->lns_mode && session->send_seq) {
717
+ trace_session_seqnum_lns_disable(session);
719718 session->send_seq = 0;
720719 l2tp_session_set_header_len(session, tunnel->version);
721720 } else if (session->send_seq) {
722
- l2tp_warn(session, L2TP_MSG_SEQ,
723
- "%s: recv data has no seq numbers when required. Discarding.\n",
724
- session->name);
721
+ pr_debug_ratelimited("%s: recv data has no seq numbers when required. Discarding.\n",
722
+ session->name);
725723 atomic_long_inc(&session->stats.rx_seq_discards);
726724 goto discard;
727725 }
....@@ -775,20 +773,18 @@
775773 atomic_long_inc(&session->stats.rx_errors);
776774 kfree_skb(skb);
777775 }
778
-EXPORT_SYMBOL(l2tp_recv_common);
776
+EXPORT_SYMBOL_GPL(l2tp_recv_common);
779777
780778 /* Drop skbs from the session's reorder_q
781779 */
782
-static int l2tp_session_queue_purge(struct l2tp_session *session)
780
+static void l2tp_session_queue_purge(struct l2tp_session *session)
783781 {
784782 struct sk_buff *skb = NULL;
785
- BUG_ON(!session);
786
- BUG_ON(session->magic != L2TP_SESSION_MAGIC);
783
+
787784 while ((skb = skb_dequeue(&session->reorder_q))) {
788785 atomic_long_inc(&session->stats.rx_errors);
789786 kfree_skb(skb);
790787 }
791
- return 0;
792788 }
793789
794790 /* Internal UDP receive frame. Do the real work of receiving an L2TP data frame
....@@ -813,47 +809,32 @@
813809
814810 /* Short packet? */
815811 if (!pskb_may_pull(skb, L2TP_HDR_SIZE_MAX)) {
816
- l2tp_info(tunnel, L2TP_MSG_DATA,
817
- "%s: recv short packet (len=%d)\n",
818
- tunnel->name, skb->len);
819
- goto error;
820
- }
821
-
822
- /* Trace packet contents, if enabled */
823
- if (tunnel->debug & L2TP_MSG_DATA) {
824
- length = min(32u, skb->len);
825
- if (!pskb_may_pull(skb, length))
826
- goto error;
827
-
828
- pr_debug("%s: recv\n", tunnel->name);
829
- print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, skb->data, length);
812
+ pr_debug_ratelimited("%s: recv short packet (len=%d)\n",
813
+ tunnel->name, skb->len);
814
+ goto invalid;
830815 }
831816
832817 /* Point to L2TP header */
833
- optr = ptr = skb->data;
818
+ optr = skb->data;
819
+ ptr = skb->data;
834820
835821 /* Get L2TP header flags */
836
- hdrflags = ntohs(*(__be16 *) ptr);
822
+ hdrflags = ntohs(*(__be16 *)ptr);
837823
838824 /* Check protocol version */
839825 version = hdrflags & L2TP_HDR_VER_MASK;
840826 if (version != tunnel->version) {
841
- l2tp_info(tunnel, L2TP_MSG_DATA,
842
- "%s: recv protocol version mismatch: got %d expected %d\n",
843
- tunnel->name, version, tunnel->version);
844
- goto error;
827
+ pr_debug_ratelimited("%s: recv protocol version mismatch: got %d expected %d\n",
828
+ tunnel->name, version, tunnel->version);
829
+ goto invalid;
845830 }
846831
847832 /* Get length of L2TP packet */
848833 length = skb->len;
849834
850835 /* If type is control packet, it is handled by userspace. */
851
- if (hdrflags & L2TP_HDRFLAG_T) {
852
- l2tp_dbg(tunnel, L2TP_MSG_DATA,
853
- "%s: recv control packet, len=%d\n",
854
- tunnel->name, length);
855
- goto error;
856
- }
836
+ if (hdrflags & L2TP_HDRFLAG_T)
837
+ goto pass;
857838
858839 /* Skip flags */
859840 ptr += 2;
....@@ -864,14 +845,14 @@
864845 ptr += 2;
865846
866847 /* Extract tunnel and session ID */
867
- tunnel_id = ntohs(*(__be16 *) ptr);
848
+ tunnel_id = ntohs(*(__be16 *)ptr);
868849 ptr += 2;
869
- session_id = ntohs(*(__be16 *) ptr);
850
+ session_id = ntohs(*(__be16 *)ptr);
870851 ptr += 2;
871852 } else {
872853 ptr += 2; /* skip reserved bits */
873854 tunnel_id = tunnel->tunnel_id;
874
- session_id = ntohl(*(__be32 *) ptr);
855
+ session_id = ntohl(*(__be32 *)ptr);
875856 ptr += 4;
876857 }
877858
....@@ -882,16 +863,15 @@
882863 l2tp_session_dec_refcount(session);
883864
884865 /* Not found? Pass to userspace to deal with */
885
- l2tp_info(tunnel, L2TP_MSG_DATA,
886
- "%s: no session found (%u/%u). Passing up.\n",
887
- tunnel->name, tunnel_id, session_id);
888
- goto error;
866
+ pr_debug_ratelimited("%s: no session found (%u/%u). Passing up.\n",
867
+ tunnel->name, tunnel_id, session_id);
868
+ goto pass;
889869 }
890870
891871 if (tunnel->version == L2TP_HDR_VER_3 &&
892872 l2tp_v3_ensure_opt_in_linear(session, skb, &ptr, &optr)) {
893873 l2tp_session_dec_refcount(session);
894
- goto error;
874
+ goto invalid;
895875 }
896876
897877 l2tp_recv_common(session, skb, ptr, optr, hdrflags, length);
....@@ -899,7 +879,10 @@
899879
900880 return 0;
901881
902
-error:
882
+invalid:
883
+ atomic_long_inc(&tunnel->stats.rx_invalid);
884
+
885
+pass:
903886 /* Put UDP header back */
904887 __skb_push(skb, sizeof(struct udphdr));
905888
....@@ -916,12 +899,17 @@
916899 {
917900 struct l2tp_tunnel *tunnel;
918901
902
+ /* Note that this is called from the encap_rcv hook inside an
903
+ * RCU-protected region, but without the socket being locked.
904
+ * Hence we use rcu_dereference_sk_user_data to access the
905
+ * tunnel data structure rather the usual l2tp_sk_to_tunnel
906
+ * accessor function.
907
+ */
919908 tunnel = rcu_dereference_sk_user_data(sk);
920
- if (tunnel == NULL)
909
+ if (!tunnel)
921910 goto pass_up;
922
-
923
- l2tp_dbg(tunnel, L2TP_MSG_DATA, "%s: received %d bytes\n",
924
- tunnel->name, skb->len);
911
+ if (WARN_ON(tunnel->magic != L2TP_TUNNEL_MAGIC))
912
+ goto pass_up;
925913
926914 if (l2tp_udp_recv_core(tunnel, skb))
927915 goto pass_up;
....@@ -960,8 +948,7 @@
960948 *bufp++ = 0;
961949 session->ns++;
962950 session->ns &= 0xffff;
963
- l2tp_dbg(session, L2TP_MSG_SEQ, "%s: updated ns to %u\n",
964
- session->name, session->ns);
951
+ trace_session_seqnum_update(session);
965952 }
966953
967954 return bufp - optr;
....@@ -978,13 +965,13 @@
978965 */
979966 if (tunnel->encap == L2TP_ENCAPTYPE_UDP) {
980967 u16 flags = L2TP_HDR_VER_3;
981
- *((__be16 *) bufp) = htons(flags);
968
+ *((__be16 *)bufp) = htons(flags);
982969 bufp += 2;
983
- *((__be16 *) bufp) = 0;
970
+ *((__be16 *)bufp) = 0;
984971 bufp += 2;
985972 }
986973
987
- *((__be32 *) bufp) = htonl(session->peer_session_id);
974
+ *((__be32 *)bufp) = htonl(session->peer_session_id);
988975 bufp += 4;
989976 if (session->cookie_len) {
990977 memcpy(bufp, &session->cookie[0], session->cookie_len);
....@@ -997,9 +984,7 @@
997984 l2h = 0x40000000 | session->ns;
998985 session->ns++;
999986 session->ns &= 0xffffff;
1000
- l2tp_dbg(session, L2TP_MSG_SEQ,
1001
- "%s: updated ns to %u\n",
1002
- session->name, session->ns);
987
+ trace_session_seqnum_update(session);
1003988 }
1004989
1005990 *((__be32 *)bufp) = htonl(l2h);
....@@ -1009,87 +994,54 @@
1009994 return bufp - optr;
1010995 }
1011996
1012
-static void l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
1013
- struct flowi *fl, size_t data_len)
997
+/* Queue the packet to IP for output: tunnel socket lock must be held */
998
+static int l2tp_xmit_queue(struct l2tp_tunnel *tunnel, struct sk_buff *skb, struct flowi *fl)
1014999 {
1015
- struct l2tp_tunnel *tunnel = session->tunnel;
1016
- unsigned int len = skb->len;
1017
- int error;
1000
+ int err;
10181001
1019
- /* Debug */
1020
- if (session->send_seq)
1021
- l2tp_dbg(session, L2TP_MSG_DATA, "%s: send %zd bytes, ns=%u\n",
1022
- session->name, data_len, session->ns - 1);
1023
- else
1024
- l2tp_dbg(session, L2TP_MSG_DATA, "%s: send %zd bytes\n",
1025
- session->name, data_len);
1026
-
1027
- if (session->debug & L2TP_MSG_DATA) {
1028
- int uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
1029
- unsigned char *datap = skb->data + uhlen;
1030
-
1031
- pr_debug("%s: xmit\n", session->name);
1032
- print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
1033
- datap, min_t(size_t, 32, len - uhlen));
1034
- }
1035
-
1036
- /* Queue the packet to IP for output */
10371002 skb->ignore_df = 1;
10381003 skb_dst_drop(skb);
10391004 #if IS_ENABLED(CONFIG_IPV6)
10401005 if (l2tp_sk_is_v6(tunnel->sock))
1041
- error = inet6_csk_xmit(tunnel->sock, skb, NULL);
1006
+ err = inet6_csk_xmit(tunnel->sock, skb, NULL);
10421007 else
10431008 #endif
1044
- error = ip_queue_xmit(tunnel->sock, skb, fl);
1009
+ err = ip_queue_xmit(tunnel->sock, skb, fl);
10451010
1046
- /* Update stats */
1047
- if (error >= 0) {
1048
- atomic_long_inc(&tunnel->stats.tx_packets);
1049
- atomic_long_add(len, &tunnel->stats.tx_bytes);
1050
- atomic_long_inc(&session->stats.tx_packets);
1051
- atomic_long_add(len, &session->stats.tx_bytes);
1052
- } else {
1053
- atomic_long_inc(&tunnel->stats.tx_errors);
1054
- atomic_long_inc(&session->stats.tx_errors);
1055
- }
1011
+ return err >= 0 ? NET_XMIT_SUCCESS : NET_XMIT_DROP;
10561012 }
10571013
1058
-/* If caller requires the skb to have a ppp header, the header must be
1059
- * inserted in the skb data before calling this function.
1060
- */
1061
-int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len)
1014
+static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, unsigned int *len)
10621015 {
1063
- int data_len = skb->len;
10641016 struct l2tp_tunnel *tunnel = session->tunnel;
1017
+ unsigned int data_len = skb->len;
10651018 struct sock *sk = tunnel->sock;
1066
- struct flowi *fl;
1067
- struct udphdr *uh;
1068
- struct inet_sock *inet;
1069
- int headroom;
1070
- int uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(struct udphdr) : 0;
1071
- int udp_len;
1019
+ int headroom, uhlen, udp_len;
10721020 int ret = NET_XMIT_SUCCESS;
1021
+ struct inet_sock *inet;
1022
+ struct udphdr *uh;
10731023
10741024 /* Check that there's enough headroom in the skb to insert IP,
10751025 * UDP and L2TP headers. If not enough, expand it to
10761026 * make room. Adjust truesize.
10771027 */
1078
- headroom = NET_SKB_PAD + sizeof(struct iphdr) +
1079
- uhlen + hdr_len;
1028
+ uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(*uh) : 0;
1029
+ headroom = NET_SKB_PAD + sizeof(struct iphdr) + uhlen + session->hdr_len;
10801030 if (skb_cow_head(skb, headroom)) {
10811031 kfree_skb(skb);
10821032 return NET_XMIT_DROP;
10831033 }
10841034
10851035 /* Setup L2TP header */
1086
- session->build_header(session, __skb_push(skb, hdr_len));
1036
+ if (tunnel->version == L2TP_HDR_VER_2)
1037
+ l2tp_build_l2tpv2_header(session, __skb_push(skb, session->hdr_len));
1038
+ else
1039
+ l2tp_build_l2tpv3_header(session, __skb_push(skb, session->hdr_len));
10871040
10881041 /* Reset skb netfilter state */
10891042 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
1090
- IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
1091
- IPSKB_REROUTED);
1092
- nf_reset(skb);
1043
+ IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED | IPSKB_REROUTED);
1044
+ nf_reset_ct(skb);
10931045
10941046 bh_lock_sock(sk);
10951047 if (sock_owned_by_user(sk)) {
....@@ -1107,8 +1059,12 @@
11071059 goto out_unlock;
11081060 }
11091061
1062
+ /* Report transmitted length before we add encap header, which keeps
1063
+ * statistics consistent for both UDP and IP encap tx/rx paths.
1064
+ */
1065
+ *len = skb->len;
1066
+
11101067 inet = inet_sk(sk);
1111
- fl = &inet->cork.fl;
11121068 switch (tunnel->encap) {
11131069 case L2TP_ENCAPTYPE_UDP:
11141070 /* Setup UDP header */
....@@ -1117,7 +1073,7 @@
11171073 uh = udp_hdr(skb);
11181074 uh->source = inet->inet_sport;
11191075 uh->dest = inet->inet_dport;
1120
- udp_len = uhlen + hdr_len + data_len;
1076
+ udp_len = uhlen + session->hdr_len + data_len;
11211077 uh->len = htons(udp_len);
11221078
11231079 /* Calculate UDP checksum if configured to do so */
....@@ -1128,18 +1084,40 @@
11281084 &sk->sk_v6_daddr, udp_len);
11291085 else
11301086 #endif
1131
- udp_set_csum(sk->sk_no_check_tx, skb, inet->inet_saddr,
1132
- inet->inet_daddr, udp_len);
1087
+ udp_set_csum(sk->sk_no_check_tx, skb, inet->inet_saddr,
1088
+ inet->inet_daddr, udp_len);
11331089 break;
11341090
11351091 case L2TP_ENCAPTYPE_IP:
11361092 break;
11371093 }
11381094
1139
- l2tp_xmit_core(session, skb, fl, data_len);
1095
+ ret = l2tp_xmit_queue(tunnel, skb, &inet->cork.fl);
1096
+
11401097 out_unlock:
11411098 bh_unlock_sock(sk);
11421099
1100
+ return ret;
1101
+}
1102
+
1103
+/* If caller requires the skb to have a ppp header, the header must be
1104
+ * inserted in the skb data before calling this function.
1105
+ */
1106
+int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb)
1107
+{
1108
+ unsigned int len = 0;
1109
+ int ret;
1110
+
1111
+ ret = l2tp_xmit_core(session, skb, &len);
1112
+ if (ret == NET_XMIT_SUCCESS) {
1113
+ atomic_long_inc(&session->tunnel->stats.tx_packets);
1114
+ atomic_long_add(len, &session->tunnel->stats.tx_bytes);
1115
+ atomic_long_inc(&session->stats.tx_packets);
1116
+ atomic_long_add(len, &session->stats.tx_bytes);
1117
+ } else {
1118
+ atomic_long_inc(&session->tunnel->stats.tx_errors);
1119
+ atomic_long_inc(&session->stats.tx_errors);
1120
+ }
11431121 return ret;
11441122 }
11451123 EXPORT_SYMBOL_GPL(l2tp_xmit_skb);
....@@ -1154,12 +1132,10 @@
11541132 */
11551133 static void l2tp_tunnel_destruct(struct sock *sk)
11561134 {
1157
- struct l2tp_tunnel *tunnel = l2tp_tunnel(sk);
1135
+ struct l2tp_tunnel *tunnel = l2tp_sk_to_tunnel(sk);
11581136
1159
- if (tunnel == NULL)
1137
+ if (!tunnel)
11601138 goto end;
1161
-
1162
- l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing...\n", tunnel->name);
11631139
11641140 /* Disable udp encapsulation */
11651141 switch (tunnel->encap) {
....@@ -1186,6 +1162,30 @@
11861162 return;
11871163 }
11881164
1165
+/* Remove an l2tp session from l2tp_core's hash lists. */
1166
+static void l2tp_session_unhash(struct l2tp_session *session)
1167
+{
1168
+ struct l2tp_tunnel *tunnel = session->tunnel;
1169
+
1170
+ /* Remove the session from core hashes */
1171
+ if (tunnel) {
1172
+ /* Remove from the per-tunnel hash */
1173
+ write_lock_bh(&tunnel->hlist_lock);
1174
+ hlist_del_init(&session->hlist);
1175
+ write_unlock_bh(&tunnel->hlist_lock);
1176
+
1177
+ /* For L2TPv3 we have a per-net hash: remove from there, too */
1178
+ if (tunnel->version != L2TP_HDR_VER_2) {
1179
+ struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net);
1180
+
1181
+ spin_lock_bh(&pn->l2tp_session_hlist_lock);
1182
+ hlist_del_init_rcu(&session->global_hlist);
1183
+ spin_unlock_bh(&pn->l2tp_session_hlist_lock);
1184
+ synchronize_rcu();
1185
+ }
1186
+ }
1187
+}
1188
+
11891189 /* When the tunnel is closed, all the attached sessions need to go too.
11901190 */
11911191 static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel)
....@@ -1195,36 +1195,16 @@
11951195 struct hlist_node *tmp;
11961196 struct l2tp_session *session;
11971197
1198
- BUG_ON(tunnel == NULL);
1199
-
1200
- l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing all sessions...\n",
1201
- tunnel->name);
1202
-
12031198 write_lock_bh(&tunnel->hlist_lock);
12041199 tunnel->acpt_newsess = false;
12051200 for (hash = 0; hash < L2TP_HASH_SIZE; hash++) {
12061201 again:
12071202 hlist_for_each_safe(walk, tmp, &tunnel->session_hlist[hash]) {
12081203 session = hlist_entry(walk, struct l2tp_session, hlist);
1209
-
1210
- l2tp_info(session, L2TP_MSG_CONTROL,
1211
- "%s: closing session\n", session->name);
1212
-
12131204 hlist_del_init(&session->hlist);
12141205
1215
- if (test_and_set_bit(0, &session->dead))
1216
- goto again;
1217
-
12181206 write_unlock_bh(&tunnel->hlist_lock);
1219
-
1220
- __l2tp_session_unhash(session);
1221
- l2tp_session_queue_purge(session);
1222
-
1223
- if (session->session_close != NULL)
1224
- (*session->session_close)(session);
1225
-
1226
- l2tp_session_dec_refcount(session);
1227
-
1207
+ l2tp_session_delete(session);
12281208 write_lock_bh(&tunnel->hlist_lock);
12291209
12301210 /* Now restart from the beginning of this hash
....@@ -1241,7 +1221,7 @@
12411221 /* Tunnel socket destroy hook for UDP encapsulation */
12421222 static void l2tp_udp_encap_destroy(struct sock *sk)
12431223 {
1244
- struct l2tp_tunnel *tunnel = l2tp_tunnel(sk);
1224
+ struct l2tp_tunnel *tunnel = l2tp_sk_to_tunnel(sk);
12451225
12461226 if (tunnel)
12471227 l2tp_tunnel_delete(tunnel);
....@@ -1291,10 +1271,10 @@
12911271 * exit hook.
12921272 */
12931273 static int l2tp_tunnel_sock_create(struct net *net,
1294
- u32 tunnel_id,
1295
- u32 peer_tunnel_id,
1296
- struct l2tp_tunnel_cfg *cfg,
1297
- struct socket **sockp)
1274
+ u32 tunnel_id,
1275
+ u32 peer_tunnel_id,
1276
+ struct l2tp_tunnel_cfg *cfg,
1277
+ struct socket **sockp)
12981278 {
12991279 int err = -EINVAL;
13001280 struct socket *sock = NULL;
....@@ -1312,9 +1292,9 @@
13121292 memcpy(&udp_conf.peer_ip6, cfg->peer_ip6,
13131293 sizeof(udp_conf.peer_ip6));
13141294 udp_conf.use_udp6_tx_checksums =
1315
- ! cfg->udp6_zero_tx_checksums;
1295
+ !cfg->udp6_zero_tx_checksums;
13161296 udp_conf.use_udp6_rx_checksums =
1317
- ! cfg->udp6_zero_rx_checksums;
1297
+ !cfg->udp6_zero_rx_checksums;
13181298 } else
13191299 #endif
13201300 {
....@@ -1339,7 +1319,7 @@
13391319 struct sockaddr_l2tpip6 ip6_addr = {0};
13401320
13411321 err = sock_create_kern(net, AF_INET6, SOCK_DGRAM,
1342
- IPPROTO_L2TP, &sock);
1322
+ IPPROTO_L2TP, &sock);
13431323 if (err < 0)
13441324 goto out;
13451325
....@@ -1347,7 +1327,7 @@
13471327 memcpy(&ip6_addr.l2tp_addr, cfg->local_ip6,
13481328 sizeof(ip6_addr.l2tp_addr));
13491329 ip6_addr.l2tp_conn_id = tunnel_id;
1350
- err = kernel_bind(sock, (struct sockaddr *) &ip6_addr,
1330
+ err = kernel_bind(sock, (struct sockaddr *)&ip6_addr,
13511331 sizeof(ip6_addr));
13521332 if (err < 0)
13531333 goto out;
....@@ -1357,7 +1337,7 @@
13571337 sizeof(ip6_addr.l2tp_addr));
13581338 ip6_addr.l2tp_conn_id = peer_tunnel_id;
13591339 err = kernel_connect(sock,
1360
- (struct sockaddr *) &ip6_addr,
1340
+ (struct sockaddr *)&ip6_addr,
13611341 sizeof(ip6_addr), 0);
13621342 if (err < 0)
13631343 goto out;
....@@ -1367,14 +1347,14 @@
13671347 struct sockaddr_l2tpip ip_addr = {0};
13681348
13691349 err = sock_create_kern(net, AF_INET, SOCK_DGRAM,
1370
- IPPROTO_L2TP, &sock);
1350
+ IPPROTO_L2TP, &sock);
13711351 if (err < 0)
13721352 goto out;
13731353
13741354 ip_addr.l2tp_family = AF_INET;
13751355 ip_addr.l2tp_addr = cfg->local_ip;
13761356 ip_addr.l2tp_conn_id = tunnel_id;
1377
- err = kernel_bind(sock, (struct sockaddr *) &ip_addr,
1357
+ err = kernel_bind(sock, (struct sockaddr *)&ip_addr,
13781358 sizeof(ip_addr));
13791359 if (err < 0)
13801360 goto out;
....@@ -1382,7 +1362,7 @@
13821362 ip_addr.l2tp_family = AF_INET;
13831363 ip_addr.l2tp_addr = cfg->peer_ip;
13841364 ip_addr.l2tp_conn_id = peer_tunnel_id;
1385
- err = kernel_connect(sock, (struct sockaddr *) &ip_addr,
1365
+ err = kernel_connect(sock, (struct sockaddr *)&ip_addr,
13861366 sizeof(ip_addr), 0);
13871367 if (err < 0)
13881368 goto out;
....@@ -1395,7 +1375,7 @@
13951375
13961376 out:
13971377 *sockp = sock;
1398
- if ((err < 0) && sock) {
1378
+ if (err < 0 && sock) {
13991379 kernel_sock_shutdown(sock, SHUT_RDWR);
14001380 sock_release(sock);
14011381 *sockp = NULL;
....@@ -1406,17 +1386,18 @@
14061386
14071387 static struct lock_class_key l2tp_socket_class;
14081388
1409
-int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg, struct l2tp_tunnel **tunnelp)
1389
+int l2tp_tunnel_create(int fd, int version, u32 tunnel_id, u32 peer_tunnel_id,
1390
+ struct l2tp_tunnel_cfg *cfg, struct l2tp_tunnel **tunnelp)
14101391 {
14111392 struct l2tp_tunnel *tunnel = NULL;
14121393 int err;
14131394 enum l2tp_encap_type encap = L2TP_ENCAPTYPE_UDP;
14141395
1415
- if (cfg != NULL)
1396
+ if (cfg)
14161397 encap = cfg->encap;
14171398
1418
- tunnel = kzalloc(sizeof(struct l2tp_tunnel), GFP_KERNEL);
1419
- if (tunnel == NULL) {
1399
+ tunnel = kzalloc(sizeof(*tunnel), GFP_KERNEL);
1400
+ if (!tunnel) {
14201401 err = -ENOMEM;
14211402 goto err;
14221403 }
....@@ -1424,15 +1405,11 @@
14241405 tunnel->version = version;
14251406 tunnel->tunnel_id = tunnel_id;
14261407 tunnel->peer_tunnel_id = peer_tunnel_id;
1427
- tunnel->debug = L2TP_DEFAULT_DEBUG_FLAGS;
14281408
14291409 tunnel->magic = L2TP_TUNNEL_MAGIC;
14301410 sprintf(&tunnel->name[0], "tunl %u", tunnel_id);
14311411 rwlock_init(&tunnel->hlist_lock);
14321412 tunnel->acpt_newsess = true;
1433
-
1434
- if (cfg != NULL)
1435
- tunnel->debug = cfg->debug;
14361413
14371414 tunnel->encap = encap;
14381415
....@@ -1503,21 +1480,21 @@
15031480 tunnel->l2tp_net = net;
15041481 pn = l2tp_pernet(net);
15051482
1483
+ sk = sock->sk;
1484
+ sock_hold(sk);
1485
+ tunnel->sock = sk;
1486
+
15061487 spin_lock_bh(&pn->l2tp_tunnel_list_lock);
15071488 list_for_each_entry(tunnel_walk, &pn->l2tp_tunnel_list, list) {
15081489 if (tunnel_walk->tunnel_id == tunnel->tunnel_id) {
15091490 spin_unlock_bh(&pn->l2tp_tunnel_list_lock);
1510
-
1491
+ sock_put(sk);
15111492 ret = -EEXIST;
15121493 goto err_sock;
15131494 }
15141495 }
15151496 list_add_rcu(&tunnel->list, &pn->l2tp_tunnel_list);
15161497 spin_unlock_bh(&pn->l2tp_tunnel_list_lock);
1517
-
1518
- sk = sock->sk;
1519
- sock_hold(sk);
1520
- tunnel->sock = sk;
15211498
15221499 if (tunnel->encap == L2TP_ENCAPTYPE_UDP) {
15231500 struct udp_tunnel_sock_cfg udp_cfg = {
....@@ -1537,6 +1514,8 @@
15371514 lockdep_set_class_and_name(&sk->sk_lock.slock, &l2tp_socket_class,
15381515 "l2tp_sock");
15391516 sk->sk_allocation = GFP_ATOMIC;
1517
+
1518
+ trace_register_tunnel(tunnel);
15401519
15411520 if (tunnel->fd >= 0)
15421521 sockfd_put(sock);
....@@ -1558,73 +1537,25 @@
15581537 void l2tp_tunnel_delete(struct l2tp_tunnel *tunnel)
15591538 {
15601539 if (!test_and_set_bit(0, &tunnel->dead)) {
1540
+ trace_delete_tunnel(tunnel);
15611541 l2tp_tunnel_inc_refcount(tunnel);
15621542 queue_work(l2tp_wq, &tunnel->del_work);
15631543 }
15641544 }
15651545 EXPORT_SYMBOL_GPL(l2tp_tunnel_delete);
15661546
1567
-/* Really kill the session.
1568
- */
1569
-void l2tp_session_free(struct l2tp_session *session)
1570
-{
1571
- struct l2tp_tunnel *tunnel = session->tunnel;
1572
-
1573
- BUG_ON(refcount_read(&session->ref_count) != 0);
1574
-
1575
- if (tunnel) {
1576
- BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC);
1577
- l2tp_tunnel_dec_refcount(tunnel);
1578
- }
1579
-
1580
- kfree(session);
1581
-}
1582
-EXPORT_SYMBOL_GPL(l2tp_session_free);
1583
-
1584
-/* Remove an l2tp session from l2tp_core's hash lists.
1585
- * Provides a tidyup interface for pseudowire code which can't just route all
1586
- * shutdown via. l2tp_session_delete and a pseudowire-specific session_close
1587
- * callback.
1588
- */
1589
-void __l2tp_session_unhash(struct l2tp_session *session)
1590
-{
1591
- struct l2tp_tunnel *tunnel = session->tunnel;
1592
-
1593
- /* Remove the session from core hashes */
1594
- if (tunnel) {
1595
- /* Remove from the per-tunnel hash */
1596
- write_lock_bh(&tunnel->hlist_lock);
1597
- hlist_del_init(&session->hlist);
1598
- write_unlock_bh(&tunnel->hlist_lock);
1599
-
1600
- /* For L2TPv3 we have a per-net hash: remove from there, too */
1601
- if (tunnel->version != L2TP_HDR_VER_2) {
1602
- struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net);
1603
- spin_lock_bh(&pn->l2tp_session_hlist_lock);
1604
- hlist_del_init_rcu(&session->global_hlist);
1605
- spin_unlock_bh(&pn->l2tp_session_hlist_lock);
1606
- synchronize_rcu();
1607
- }
1608
- }
1609
-}
1610
-EXPORT_SYMBOL_GPL(__l2tp_session_unhash);
1611
-
1612
-/* This function is used by the netlink SESSION_DELETE command and by
1613
- pseudowire modules.
1614
- */
1615
-int l2tp_session_delete(struct l2tp_session *session)
1547
+void l2tp_session_delete(struct l2tp_session *session)
16161548 {
16171549 if (test_and_set_bit(0, &session->dead))
1618
- return 0;
1550
+ return;
16191551
1620
- __l2tp_session_unhash(session);
1552
+ trace_delete_session(session);
1553
+ l2tp_session_unhash(session);
16211554 l2tp_session_queue_purge(session);
1622
- if (session->session_close != NULL)
1555
+ if (session->session_close)
16231556 (*session->session_close)(session);
16241557
16251558 l2tp_session_dec_refcount(session);
1626
-
1627
- return 0;
16281559 }
16291560 EXPORT_SYMBOL_GPL(l2tp_session_delete);
16301561
....@@ -1643,16 +1574,16 @@
16431574 if (session->tunnel->encap == L2TP_ENCAPTYPE_UDP)
16441575 session->hdr_len += 4;
16451576 }
1646
-
16471577 }
16481578 EXPORT_SYMBOL_GPL(l2tp_session_set_header_len);
16491579
1650
-struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg)
1580
+struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id,
1581
+ u32 peer_session_id, struct l2tp_session_cfg *cfg)
16511582 {
16521583 struct l2tp_session *session;
16531584
1654
- session = kzalloc(sizeof(struct l2tp_session) + priv_size, GFP_KERNEL);
1655
- if (session != NULL) {
1585
+ session = kzalloc(sizeof(*session) + priv_size, GFP_KERNEL);
1586
+ if (session) {
16561587 session->magic = L2TP_SESSION_MAGIC;
16571588 session->tunnel = tunnel;
16581589
....@@ -1677,12 +1608,8 @@
16771608 INIT_HLIST_NODE(&session->hlist);
16781609 INIT_HLIST_NODE(&session->global_hlist);
16791610
1680
- /* Inherit debug options from tunnel */
1681
- session->debug = tunnel->debug;
1682
-
16831611 if (cfg) {
16841612 session->pwtype = cfg->pw_type;
1685
- session->debug = cfg->debug;
16861613 session->send_seq = cfg->send_seq;
16871614 session->recv_seq = cfg->recv_seq;
16881615 session->lns_mode = cfg->lns_mode;
....@@ -1693,11 +1620,6 @@
16931620 session->peer_cookie_len = cfg->peer_cookie_len;
16941621 memcpy(&session->peer_cookie[0], &cfg->peer_cookie[0], cfg->peer_cookie_len);
16951622 }
1696
-
1697
- if (tunnel->version == L2TP_HDR_VER_2)
1698
- session->build_header = l2tp_build_l2tpv2_header;
1699
- else
1700
- session->build_header = l2tp_build_l2tpv3_header;
17011623
17021624 l2tp_session_set_header_len(session, tunnel->version);
17031625