The structure of an L2TP data packet header varies depending on the
version of the L2TP protocol being used.

struct l2tp_session used to have a build_header callback to abstract
this difference away.  It's clearer to simply choose the correct
function to use when building the data packet (and we save on the
function pointer in the session structure).

This approach does mean dereferencing the parent tunnel structure in
order to determine the tunnel version, but we're doing that in the
transmit path in any case.

Signed-off-by: Tom Parkin <tpar...@katalix.com>
---
 net/l2tp/l2tp_core.c | 10 ++++------
 net/l2tp/l2tp_core.h |  1 -
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index 690dcbc30472..3992af139479 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -1116,7 +1116,10 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct 
sk_buff *skb, int hdr_len
        }
 
        /* Setup L2TP header */
-       session->build_header(session, __skb_push(skb, hdr_len));
+       if (tunnel->version == L2TP_HDR_VER_2)
+               l2tp_build_l2tpv2_header(session, __skb_push(skb, hdr_len));
+       else
+               l2tp_build_l2tpv3_header(session, __skb_push(skb, hdr_len));
 
        /* Reset skb netfilter state */
        memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
@@ -1700,11 +1703,6 @@ struct l2tp_session *l2tp_session_create(int priv_size, 
struct l2tp_tunnel *tunn
                        memcpy(&session->peer_cookie[0], &cfg->peer_cookie[0], 
cfg->peer_cookie_len);
                }
 
-               if (tunnel->version == L2TP_HDR_VER_2)
-                       session->build_header = l2tp_build_l2tpv2_header;
-               else
-                       session->build_header = l2tp_build_l2tpv3_header;
-
                l2tp_session_set_header_len(session, tunnel->version);
 
                refcount_set(&session->ref_count, 1);
diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h
index 0c32981f0cd3..3dfd3ddd28fd 100644
--- a/net/l2tp/l2tp_core.h
+++ b/net/l2tp/l2tp_core.h
@@ -101,7 +101,6 @@ struct l2tp_session {
        struct l2tp_stats       stats;
        struct hlist_node       global_hlist;   /* global hash list node */
 
-       int (*build_header)(struct l2tp_session *session, void *buf);
        void (*recv_skb)(struct l2tp_session *session, struct sk_buff *skb, int 
data_len);
        void (*session_close)(struct l2tp_session *session);
        void (*show)(struct seq_file *m, void *priv);
-- 
2.17.1

Reply via email to