Commit aff598ca authored by David S. Miller's avatar David S. Miller

Merge branch 'l2tp-cleanup-checkpatch-pl-warnings'

Tom Parkin says:

====================
l2tp: cleanup checkpatch.pl warnings

l2tp hasn't been kept up to date with the static analysis checks offered
by checkpatch.pl.

This series addresses a range of minor issues which don't involve large
changes to code structure.  The changes include:

 * tweaks to use of whitespace, comment style, line breaks,
   and indentation

 * two minor modifications to code to use a function or macro suggested
   by checkpatch

v1 -> v2

 * combine related patches (patches fixing whitespace issues, patches
   addressing comment style)

 * respin the single large patchset into a multiple smaller series for
   easier review
====================
Reviewed-by: default avatarJames Chapman <jchapman@katalix.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 637989b5 efcd8c85
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
/* /* L2TP core.
* L2TP core.
* *
* Copyright (c) 2008,2009,2010 Katalix Systems Ltd * Copyright (c) 2008,2009,2010 Katalix Systems Ltd
* *
...@@ -94,7 +93,7 @@ struct l2tp_skb_cb { ...@@ -94,7 +93,7 @@ struct l2tp_skb_cb {
unsigned long expires; unsigned long expires;
}; };
#define L2TP_SKB_CB(skb) ((struct l2tp_skb_cb *) &skb->cb[sizeof(struct inet_skb_parm)]) #define L2TP_SKB_CB(skb) ((struct l2tp_skb_cb *)&(skb)->cb[sizeof(struct inet_skb_parm)])
static struct workqueue_struct *l2tp_wq; static struct workqueue_struct *l2tp_wq;
...@@ -102,8 +101,10 @@ static struct workqueue_struct *l2tp_wq; ...@@ -102,8 +101,10 @@ static struct workqueue_struct *l2tp_wq;
static unsigned int l2tp_net_id; static unsigned int l2tp_net_id;
struct l2tp_net { struct l2tp_net {
struct list_head l2tp_tunnel_list; struct list_head l2tp_tunnel_list;
/* Lock for write access to l2tp_tunnel_list */
spinlock_t l2tp_tunnel_list_lock; spinlock_t l2tp_tunnel_list_lock;
struct hlist_head l2tp_session_hlist[L2TP_HASH_SIZE_2]; struct hlist_head l2tp_session_hlist[L2TP_HASH_SIZE_2];
/* Lock for write access to l2tp_session_hlist */
spinlock_t l2tp_session_hlist_lock; spinlock_t l2tp_session_hlist_lock;
}; };
...@@ -134,7 +135,6 @@ static inline struct hlist_head * ...@@ -134,7 +135,6 @@ static inline struct hlist_head *
l2tp_session_id_hash_2(struct l2tp_net *pn, u32 session_id) l2tp_session_id_hash_2(struct l2tp_net *pn, u32 session_id)
{ {
return &pn->l2tp_session_hlist[hash_32(session_id, L2TP_HASH_BITS_2)]; return &pn->l2tp_session_hlist[hash_32(session_id, L2TP_HASH_BITS_2)];
} }
/* Session hash list. /* Session hash list.
...@@ -648,9 +648,9 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -648,9 +648,9 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
L2TP_SKB_CB(skb)->has_seq = 0; L2TP_SKB_CB(skb)->has_seq = 0;
if (tunnel->version == L2TP_HDR_VER_2) { if (tunnel->version == L2TP_HDR_VER_2) {
if (hdrflags & L2TP_HDRFLAG_S) { if (hdrflags & L2TP_HDRFLAG_S) {
ns = ntohs(*(__be16 *) ptr); ns = ntohs(*(__be16 *)ptr);
ptr += 2; ptr += 2;
nr = ntohs(*(__be16 *) ptr); nr = ntohs(*(__be16 *)ptr);
ptr += 2; ptr += 2;
/* Store L2TP info in the skb */ /* Store L2TP info in the skb */
...@@ -662,7 +662,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -662,7 +662,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
session->name, ns, nr, session->nr); session->name, ns, nr, session->nr);
} }
} else if (session->l2specific_type == L2TP_L2SPECTYPE_DEFAULT) { } else if (session->l2specific_type == L2TP_L2SPECTYPE_DEFAULT) {
u32 l2h = ntohl(*(__be32 *) ptr); u32 l2h = ntohl(*(__be32 *)ptr);
if (l2h & 0x40000000) { if (l2h & 0x40000000) {
ns = l2h & 0x00ffffff; ns = l2h & 0x00ffffff;
...@@ -679,7 +679,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -679,7 +679,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
} }
if (L2TP_SKB_CB(skb)->has_seq) { if (L2TP_SKB_CB(skb)->has_seq) {
/* Received a packet with sequence numbers. If we're the LNS, /* Received a packet with sequence numbers. If we're the LAC,
* check if we sre sending sequence numbers and if not, * check if we sre sending sequence numbers and if not,
* configure it so. * configure it so.
*/ */
...@@ -777,6 +777,7 @@ EXPORT_SYMBOL(l2tp_recv_common); ...@@ -777,6 +777,7 @@ EXPORT_SYMBOL(l2tp_recv_common);
static int l2tp_session_queue_purge(struct l2tp_session *session) static int l2tp_session_queue_purge(struct l2tp_session *session)
{ {
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
BUG_ON(!session); BUG_ON(!session);
BUG_ON(session->magic != L2TP_SESSION_MAGIC); BUG_ON(session->magic != L2TP_SESSION_MAGIC);
while ((skb = skb_dequeue(&session->reorder_q))) { while ((skb = skb_dequeue(&session->reorder_q))) {
...@@ -828,7 +829,7 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) ...@@ -828,7 +829,7 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb)
optr = ptr = skb->data; optr = ptr = skb->data;
/* Get L2TP header flags */ /* Get L2TP header flags */
hdrflags = ntohs(*(__be16 *) ptr); hdrflags = ntohs(*(__be16 *)ptr);
/* Check protocol version */ /* Check protocol version */
version = hdrflags & L2TP_HDR_VER_MASK; version = hdrflags & L2TP_HDR_VER_MASK;
...@@ -859,14 +860,14 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) ...@@ -859,14 +860,14 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb)
ptr += 2; ptr += 2;
/* Extract tunnel and session ID */ /* Extract tunnel and session ID */
tunnel_id = ntohs(*(__be16 *) ptr); tunnel_id = ntohs(*(__be16 *)ptr);
ptr += 2; ptr += 2;
session_id = ntohs(*(__be16 *) ptr); session_id = ntohs(*(__be16 *)ptr);
ptr += 2; ptr += 2;
} else { } else {
ptr += 2; /* skip reserved bits */ ptr += 2; /* skip reserved bits */
tunnel_id = tunnel->tunnel_id; tunnel_id = tunnel->tunnel_id;
session_id = ntohl(*(__be32 *) ptr); session_id = ntohl(*(__be32 *)ptr);
ptr += 4; ptr += 4;
} }
...@@ -971,13 +972,13 @@ static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf) ...@@ -971,13 +972,13 @@ static int l2tp_build_l2tpv3_header(struct l2tp_session *session, void *buf)
*/ */
if (tunnel->encap == L2TP_ENCAPTYPE_UDP) { if (tunnel->encap == L2TP_ENCAPTYPE_UDP) {
u16 flags = L2TP_HDR_VER_3; u16 flags = L2TP_HDR_VER_3;
*((__be16 *) bufp) = htons(flags); *((__be16 *)bufp) = htons(flags);
bufp += 2; bufp += 2;
*((__be16 *) bufp) = 0; *((__be16 *)bufp) = 0;
bufp += 2; bufp += 2;
} }
*((__be32 *) bufp) = htonl(session->peer_session_id); *((__be32 *)bufp) = htonl(session->peer_session_id);
bufp += 4; bufp += 4;
if (session->cookie_len) { if (session->cookie_len) {
memcpy(bufp, &session->cookie[0], session->cookie_len); memcpy(bufp, &session->cookie[0], session->cookie_len);
...@@ -1121,8 +1122,8 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len ...@@ -1121,8 +1122,8 @@ int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len
&sk->sk_v6_daddr, udp_len); &sk->sk_v6_daddr, udp_len);
else else
#endif #endif
udp_set_csum(sk->sk_no_check_tx, skb, inet->inet_saddr, udp_set_csum(sk->sk_no_check_tx, skb, inet->inet_saddr,
inet->inet_daddr, udp_len); inet->inet_daddr, udp_len);
break; break;
case L2TP_ENCAPTYPE_IP: case L2TP_ENCAPTYPE_IP:
...@@ -1284,10 +1285,10 @@ static void l2tp_tunnel_del_work(struct work_struct *work) ...@@ -1284,10 +1285,10 @@ static void l2tp_tunnel_del_work(struct work_struct *work)
* exit hook. * exit hook.
*/ */
static int l2tp_tunnel_sock_create(struct net *net, static int l2tp_tunnel_sock_create(struct net *net,
u32 tunnel_id, u32 tunnel_id,
u32 peer_tunnel_id, u32 peer_tunnel_id,
struct l2tp_tunnel_cfg *cfg, struct l2tp_tunnel_cfg *cfg,
struct socket **sockp) struct socket **sockp)
{ {
int err = -EINVAL; int err = -EINVAL;
struct socket *sock = NULL; struct socket *sock = NULL;
...@@ -1305,9 +1306,9 @@ static int l2tp_tunnel_sock_create(struct net *net, ...@@ -1305,9 +1306,9 @@ static int l2tp_tunnel_sock_create(struct net *net,
memcpy(&udp_conf.peer_ip6, cfg->peer_ip6, memcpy(&udp_conf.peer_ip6, cfg->peer_ip6,
sizeof(udp_conf.peer_ip6)); sizeof(udp_conf.peer_ip6));
udp_conf.use_udp6_tx_checksums = udp_conf.use_udp6_tx_checksums =
! cfg->udp6_zero_tx_checksums; !cfg->udp6_zero_tx_checksums;
udp_conf.use_udp6_rx_checksums = udp_conf.use_udp6_rx_checksums =
! cfg->udp6_zero_rx_checksums; !cfg->udp6_zero_rx_checksums;
} else } else
#endif #endif
{ {
...@@ -1332,7 +1333,7 @@ static int l2tp_tunnel_sock_create(struct net *net, ...@@ -1332,7 +1333,7 @@ static int l2tp_tunnel_sock_create(struct net *net,
struct sockaddr_l2tpip6 ip6_addr = {0}; struct sockaddr_l2tpip6 ip6_addr = {0};
err = sock_create_kern(net, AF_INET6, SOCK_DGRAM, err = sock_create_kern(net, AF_INET6, SOCK_DGRAM,
IPPROTO_L2TP, &sock); IPPROTO_L2TP, &sock);
if (err < 0) if (err < 0)
goto out; goto out;
...@@ -1340,7 +1341,7 @@ static int l2tp_tunnel_sock_create(struct net *net, ...@@ -1340,7 +1341,7 @@ static int l2tp_tunnel_sock_create(struct net *net,
memcpy(&ip6_addr.l2tp_addr, cfg->local_ip6, memcpy(&ip6_addr.l2tp_addr, cfg->local_ip6,
sizeof(ip6_addr.l2tp_addr)); sizeof(ip6_addr.l2tp_addr));
ip6_addr.l2tp_conn_id = tunnel_id; ip6_addr.l2tp_conn_id = tunnel_id;
err = kernel_bind(sock, (struct sockaddr *) &ip6_addr, err = kernel_bind(sock, (struct sockaddr *)&ip6_addr,
sizeof(ip6_addr)); sizeof(ip6_addr));
if (err < 0) if (err < 0)
goto out; goto out;
...@@ -1350,7 +1351,7 @@ static int l2tp_tunnel_sock_create(struct net *net, ...@@ -1350,7 +1351,7 @@ static int l2tp_tunnel_sock_create(struct net *net,
sizeof(ip6_addr.l2tp_addr)); sizeof(ip6_addr.l2tp_addr));
ip6_addr.l2tp_conn_id = peer_tunnel_id; ip6_addr.l2tp_conn_id = peer_tunnel_id;
err = kernel_connect(sock, err = kernel_connect(sock,
(struct sockaddr *) &ip6_addr, (struct sockaddr *)&ip6_addr,
sizeof(ip6_addr), 0); sizeof(ip6_addr), 0);
if (err < 0) if (err < 0)
goto out; goto out;
...@@ -1360,14 +1361,14 @@ static int l2tp_tunnel_sock_create(struct net *net, ...@@ -1360,14 +1361,14 @@ static int l2tp_tunnel_sock_create(struct net *net,
struct sockaddr_l2tpip ip_addr = {0}; struct sockaddr_l2tpip ip_addr = {0};
err = sock_create_kern(net, AF_INET, SOCK_DGRAM, err = sock_create_kern(net, AF_INET, SOCK_DGRAM,
IPPROTO_L2TP, &sock); IPPROTO_L2TP, &sock);
if (err < 0) if (err < 0)
goto out; goto out;
ip_addr.l2tp_family = AF_INET; ip_addr.l2tp_family = AF_INET;
ip_addr.l2tp_addr = cfg->local_ip; ip_addr.l2tp_addr = cfg->local_ip;
ip_addr.l2tp_conn_id = tunnel_id; ip_addr.l2tp_conn_id = tunnel_id;
err = kernel_bind(sock, (struct sockaddr *) &ip_addr, err = kernel_bind(sock, (struct sockaddr *)&ip_addr,
sizeof(ip_addr)); sizeof(ip_addr));
if (err < 0) if (err < 0)
goto out; goto out;
...@@ -1375,7 +1376,7 @@ static int l2tp_tunnel_sock_create(struct net *net, ...@@ -1375,7 +1376,7 @@ static int l2tp_tunnel_sock_create(struct net *net,
ip_addr.l2tp_family = AF_INET; ip_addr.l2tp_family = AF_INET;
ip_addr.l2tp_addr = cfg->peer_ip; ip_addr.l2tp_addr = cfg->peer_ip;
ip_addr.l2tp_conn_id = peer_tunnel_id; ip_addr.l2tp_conn_id = peer_tunnel_id;
err = kernel_connect(sock, (struct sockaddr *) &ip_addr, err = kernel_connect(sock, (struct sockaddr *)&ip_addr,
sizeof(ip_addr), 0); sizeof(ip_addr), 0);
if (err < 0) if (err < 0)
goto out; goto out;
...@@ -1399,7 +1400,8 @@ static int l2tp_tunnel_sock_create(struct net *net, ...@@ -1399,7 +1400,8 @@ static int l2tp_tunnel_sock_create(struct net *net,
static struct lock_class_key l2tp_socket_class; static struct lock_class_key l2tp_socket_class;
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) 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)
{ {
struct l2tp_tunnel *tunnel = NULL; struct l2tp_tunnel *tunnel = NULL;
int err; int err;
...@@ -1593,6 +1595,7 @@ void __l2tp_session_unhash(struct l2tp_session *session) ...@@ -1593,6 +1595,7 @@ void __l2tp_session_unhash(struct l2tp_session *session)
/* For L2TPv3 we have a per-net hash: remove from there, too */ /* For L2TPv3 we have a per-net hash: remove from there, too */
if (tunnel->version != L2TP_HDR_VER_2) { if (tunnel->version != L2TP_HDR_VER_2) {
struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net);
spin_lock_bh(&pn->l2tp_session_hlist_lock); spin_lock_bh(&pn->l2tp_session_hlist_lock);
hlist_del_init_rcu(&session->global_hlist); hlist_del_init_rcu(&session->global_hlist);
spin_unlock_bh(&pn->l2tp_session_hlist_lock); spin_unlock_bh(&pn->l2tp_session_hlist_lock);
...@@ -1603,7 +1606,7 @@ void __l2tp_session_unhash(struct l2tp_session *session) ...@@ -1603,7 +1606,7 @@ void __l2tp_session_unhash(struct l2tp_session *session)
EXPORT_SYMBOL_GPL(__l2tp_session_unhash); EXPORT_SYMBOL_GPL(__l2tp_session_unhash);
/* This function is used by the netlink SESSION_DELETE command and by /* This function is used by the netlink SESSION_DELETE command and by
pseudowire modules. * pseudowire modules.
*/ */
int l2tp_session_delete(struct l2tp_session *session) int l2tp_session_delete(struct l2tp_session *session)
{ {
...@@ -1636,11 +1639,11 @@ void l2tp_session_set_header_len(struct l2tp_session *session, int version) ...@@ -1636,11 +1639,11 @@ void l2tp_session_set_header_len(struct l2tp_session *session, int version)
if (session->tunnel->encap == L2TP_ENCAPTYPE_UDP) if (session->tunnel->encap == L2TP_ENCAPTYPE_UDP)
session->hdr_len += 4; session->hdr_len += 4;
} }
} }
EXPORT_SYMBOL_GPL(l2tp_session_set_header_len); EXPORT_SYMBOL_GPL(l2tp_session_set_header_len);
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) 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)
{ {
struct l2tp_session *session; struct l2tp_session *session;
......
/* SPDX-License-Identifier: GPL-2.0-only */ /* SPDX-License-Identifier: GPL-2.0-only */
/* /* L2TP internal definitions.
* L2TP internal definitions.
* *
* Copyright (c) 2008,2009 Katalix Systems Ltd * Copyright (c) 2008,2009 Katalix Systems Ltd
*/ */
...@@ -22,11 +21,11 @@ ...@@ -22,11 +21,11 @@
/* Per tunnel, session hash table size */ /* Per tunnel, session hash table size */
#define L2TP_HASH_BITS 4 #define L2TP_HASH_BITS 4
#define L2TP_HASH_SIZE (1 << L2TP_HASH_BITS) #define L2TP_HASH_SIZE BIT(L2TP_HASH_BITS)
/* System-wide, session hash table size */ /* System-wide, session hash table size */
#define L2TP_HASH_BITS_2 8 #define L2TP_HASH_BITS_2 8
#define L2TP_HASH_SIZE_2 (1 << L2TP_HASH_BITS_2) #define L2TP_HASH_SIZE_2 BIT(L2TP_HASH_BITS_2)
struct sk_buff; struct sk_buff;
...@@ -49,32 +48,26 @@ struct l2tp_tunnel; ...@@ -49,32 +48,26 @@ struct l2tp_tunnel;
*/ */
struct l2tp_session_cfg { struct l2tp_session_cfg {
enum l2tp_pwtype pw_type; enum l2tp_pwtype pw_type;
unsigned int recv_seq:1; /* expect receive packets with unsigned int recv_seq:1; /* expect receive packets with sequence numbers? */
* sequence numbers? */ unsigned int send_seq:1; /* send packets with sequence numbers? */
unsigned int send_seq:1; /* send packets with sequence unsigned int lns_mode:1; /* behave as LNS?
* numbers? */ * LAC enables sequence numbers under LNS control.
unsigned int lns_mode:1; /* behave as LNS? LAC enables */
* sequence numbers under int debug; /* bitmask of debug message categories */
* control of LNS. */
int debug; /* bitmask of debug message
* categories */
u16 l2specific_type; /* Layer 2 specific type */ u16 l2specific_type; /* Layer 2 specific type */
u8 cookie[8]; /* optional cookie */ u8 cookie[8]; /* optional cookie */
int cookie_len; /* 0, 4 or 8 bytes */ int cookie_len; /* 0, 4 or 8 bytes */
u8 peer_cookie[8]; /* peer's cookie */ u8 peer_cookie[8]; /* peer's cookie */
int peer_cookie_len; /* 0, 4 or 8 bytes */ int peer_cookie_len; /* 0, 4 or 8 bytes */
int reorder_timeout; /* configured reorder timeout int reorder_timeout; /* configured reorder timeout (in jiffies) */
* (in jiffies) */
char *ifname; char *ifname;
}; };
struct l2tp_session { struct l2tp_session {
int magic; /* should be int magic; /* should be L2TP_SESSION_MAGIC */
* L2TP_SESSION_MAGIC */
long dead; long dead;
struct l2tp_tunnel *tunnel; /* back pointer to tunnel struct l2tp_tunnel *tunnel; /* back pointer to tunnel context */
* context */
u32 session_id; u32 session_id;
u32 peer_session_id; u32 peer_session_id;
u8 cookie[8]; u8 cookie[8];
...@@ -89,42 +82,37 @@ struct l2tp_session { ...@@ -89,42 +82,37 @@ struct l2tp_session {
u32 nr_max; /* max NR. Depends on tunnel */ u32 nr_max; /* max NR. Depends on tunnel */
u32 nr_window_size; /* NR window size */ u32 nr_window_size; /* NR window size */
u32 nr_oos; /* NR of last OOS packet */ u32 nr_oos; /* NR of last OOS packet */
int nr_oos_count; /* For OOS recovery */ int nr_oos_count; /* for OOS recovery */
int nr_oos_count_max; int nr_oos_count_max;
struct hlist_node hlist; /* Hash list node */ struct hlist_node hlist; /* hash list node */
refcount_t ref_count; refcount_t ref_count;
char name[32]; /* for logging */ char name[32]; /* for logging */
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
unsigned int recv_seq:1; /* expect receive packets with unsigned int recv_seq:1; /* expect receive packets with sequence numbers? */
* sequence numbers? */ unsigned int send_seq:1; /* send packets with sequence numbers? */
unsigned int send_seq:1; /* send packets with sequence unsigned int lns_mode:1; /* behave as LNS?
* numbers? */ * LAC enables sequence numbers under LNS control.
unsigned int lns_mode:1; /* behave as LNS? LAC enables */
* sequence numbers under int debug; /* bitmask of debug message categories */
* control of LNS. */ int reorder_timeout; /* configured reorder timeout (in jiffies) */
int debug; /* bitmask of debug message
* categories */
int reorder_timeout; /* configured reorder timeout
* (in jiffies) */
int reorder_skip; /* set if skip to next nr */ int reorder_skip; /* set if skip to next nr */
enum l2tp_pwtype pwtype; enum l2tp_pwtype pwtype;
struct l2tp_stats stats; struct l2tp_stats stats;
struct hlist_node global_hlist; /* Global hash list node */ struct hlist_node global_hlist; /* global hash list node */
int (*build_header)(struct l2tp_session *session, void *buf); int (*build_header)(struct l2tp_session *session, void *buf);
void (*recv_skb)(struct l2tp_session *session, struct sk_buff *skb, int data_len); void (*recv_skb)(struct l2tp_session *session, struct sk_buff *skb, int data_len);
void (*session_close)(struct l2tp_session *session); void (*session_close)(struct l2tp_session *session);
void (*show)(struct seq_file *m, void *priv); void (*show)(struct seq_file *m, void *priv);
u8 priv[]; /* private data */ u8 priv[]; /* private data */
}; };
/* Describes the tunnel. It contains info to track all the associated /* Describes the tunnel. It contains info to track all the associated
* sessions so incoming packets can be sorted out * sessions so incoming packets can be sorted out
*/ */
struct l2tp_tunnel_cfg { struct l2tp_tunnel_cfg {
int debug; /* bitmask of debug message int debug; /* bitmask of debug message categories */
* categories */
enum l2tp_encap_type encap; enum l2tp_encap_type encap;
/* Used only for kernel-created sockets */ /* Used only for kernel-created sockets */
...@@ -148,31 +136,29 @@ struct l2tp_tunnel { ...@@ -148,31 +136,29 @@ struct l2tp_tunnel {
struct rcu_head rcu; struct rcu_head rcu;
rwlock_t hlist_lock; /* protect session_hlist */ rwlock_t hlist_lock; /* protect session_hlist */
bool acpt_newsess; /* Indicates whether this bool acpt_newsess; /* indicates whether this tunnel accepts
* tunnel accepts new sessions. * new sessions. Protected by hlist_lock.
* Protected by hlist_lock.
*/ */
struct hlist_head session_hlist[L2TP_HASH_SIZE]; struct hlist_head session_hlist[L2TP_HASH_SIZE];
/* hashed list of sessions, /* hashed list of sessions, hashed by id */
* hashed by id */
u32 tunnel_id; u32 tunnel_id;
u32 peer_tunnel_id; u32 peer_tunnel_id;
int version; /* 2=>L2TPv2, 3=>L2TPv3 */ int version; /* 2=>L2TPv2, 3=>L2TPv3 */
char name[20]; /* for logging */ char name[20]; /* for logging */
int debug; /* bitmask of debug message int debug; /* bitmask of debug message categories */
* categories */
enum l2tp_encap_type encap; enum l2tp_encap_type encap;
struct l2tp_stats stats; struct l2tp_stats stats;
struct list_head list; /* Keep a list of all tunnels */ struct list_head list; /* list node on per-namespace list of tunnels */
struct net *l2tp_net; /* the net we belong to */ struct net *l2tp_net; /* the net we belong to */
refcount_t ref_count; refcount_t ref_count;
void (*old_sk_destruct)(struct sock *); void (*old_sk_destruct)(struct sock *sk);
struct sock *sock; /* Parent socket */ struct sock *sock; /* parent socket */
int fd; /* Parent fd, if tunnel socket int fd; /* parent fd, if tunnel socket was created
* was created by userspace */ * by userspace
*/
struct work_struct del_work; struct work_struct del_work;
}; };
......
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /* L2TP subsystem debugfs
* L2TP subsystem debugfs
* *
* Copyright (c) 2010 Katalix Systems Ltd * Copyright (c) 2010 Katalix Systems Ltd
*/ */
...@@ -63,7 +62,6 @@ static void l2tp_dfs_next_session(struct l2tp_dfs_seq_data *pd) ...@@ -63,7 +62,6 @@ static void l2tp_dfs_next_session(struct l2tp_dfs_seq_data *pd)
pd->session_idx = 0; pd->session_idx = 0;
l2tp_dfs_next_tunnel(pd); l2tp_dfs_next_tunnel(pd);
} }
} }
static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs) static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs)
...@@ -90,7 +88,6 @@ static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs) ...@@ -90,7 +88,6 @@ static void *l2tp_dfs_seq_start(struct seq_file *m, loff_t *offs)
return pd; return pd;
} }
static void *l2tp_dfs_seq_next(struct seq_file *m, void *v, loff_t *pos) static void *l2tp_dfs_seq_next(struct seq_file *m, void *v, loff_t *pos)
{ {
(*pos)++; (*pos)++;
...@@ -148,7 +145,7 @@ static void l2tp_dfs_seq_tunnel_show(struct seq_file *m, void *v) ...@@ -148,7 +145,7 @@ static void l2tp_dfs_seq_tunnel_show(struct seq_file *m, void *v)
const struct ipv6_pinfo *np = inet6_sk(tunnel->sock); const struct ipv6_pinfo *np = inet6_sk(tunnel->sock);
seq_printf(m, " from %pI6c to %pI6c\n", seq_printf(m, " from %pI6c to %pI6c\n",
&np->saddr, &tunnel->sock->sk_v6_daddr); &np->saddr, &tunnel->sock->sk_v6_daddr);
} else } else
#endif #endif
seq_printf(m, " from %pI4 to %pI4\n", seq_printf(m, " from %pI4 to %pI4\n",
...@@ -202,7 +199,7 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v) ...@@ -202,7 +199,7 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v)
seq_printf(m, "%02x%02x%02x%02x", seq_printf(m, "%02x%02x%02x%02x",
session->cookie[4], session->cookie[5], session->cookie[4], session->cookie[5],
session->cookie[6], session->cookie[7]); session->cookie[6], session->cookie[7]);
seq_printf(m, "\n"); seq_puts(m, "\n");
} }
if (session->peer_cookie_len) { if (session->peer_cookie_len) {
seq_printf(m, " peer cookie %02x%02x%02x%02x", seq_printf(m, " peer cookie %02x%02x%02x%02x",
...@@ -212,7 +209,7 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v) ...@@ -212,7 +209,7 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v)
seq_printf(m, "%02x%02x%02x%02x", seq_printf(m, "%02x%02x%02x%02x",
session->peer_cookie[4], session->peer_cookie[5], session->peer_cookie[4], session->peer_cookie[5],
session->peer_cookie[6], session->peer_cookie[7]); session->peer_cookie[6], session->peer_cookie[7]);
seq_printf(m, "\n"); seq_puts(m, "\n");
} }
seq_printf(m, " %hu/%hu tx %ld/%ld/%ld rx %ld/%ld/%ld\n", seq_printf(m, " %hu/%hu tx %ld/%ld/%ld rx %ld/%ld/%ld\n",
......
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /* L2TPv3 ethernet pseudowire driver
* L2TPv3 ethernet pseudowire driver
* *
* Copyright (c) 2008,2009,2010 Katalix Systems Ltd * Copyright (c) 2008,2009,2010 Katalix Systems Ltd
*/ */
...@@ -51,7 +50,6 @@ struct l2tp_eth_sess { ...@@ -51,7 +50,6 @@ struct l2tp_eth_sess {
struct net_device __rcu *dev; struct net_device __rcu *dev;
}; };
static int l2tp_eth_dev_init(struct net_device *dev) static int l2tp_eth_dev_init(struct net_device *dev)
{ {
eth_hw_addr_random(dev); eth_hw_addr_random(dev);
...@@ -94,13 +92,12 @@ static void l2tp_eth_get_stats64(struct net_device *dev, ...@@ -94,13 +92,12 @@ static void l2tp_eth_get_stats64(struct net_device *dev,
{ {
struct l2tp_eth *priv = netdev_priv(dev); struct l2tp_eth *priv = netdev_priv(dev);
stats->tx_bytes = (unsigned long) atomic_long_read(&priv->tx_bytes); stats->tx_bytes = (unsigned long)atomic_long_read(&priv->tx_bytes);
stats->tx_packets = (unsigned long) atomic_long_read(&priv->tx_packets); stats->tx_packets = (unsigned long)atomic_long_read(&priv->tx_packets);
stats->tx_dropped = (unsigned long) atomic_long_read(&priv->tx_dropped); stats->tx_dropped = (unsigned long)atomic_long_read(&priv->tx_dropped);
stats->rx_bytes = (unsigned long) atomic_long_read(&priv->rx_bytes); stats->rx_bytes = (unsigned long)atomic_long_read(&priv->rx_bytes);
stats->rx_packets = (unsigned long) atomic_long_read(&priv->rx_packets); stats->rx_packets = (unsigned long)atomic_long_read(&priv->rx_packets);
stats->rx_errors = (unsigned long) atomic_long_read(&priv->rx_errors); stats->rx_errors = (unsigned long)atomic_long_read(&priv->rx_errors);
} }
static const struct net_device_ops l2tp_eth_netdev_ops = { static const struct net_device_ops l2tp_eth_netdev_ops = {
...@@ -348,13 +345,11 @@ static int l2tp_eth_create(struct net *net, struct l2tp_tunnel *tunnel, ...@@ -348,13 +345,11 @@ static int l2tp_eth_create(struct net *net, struct l2tp_tunnel *tunnel,
return rc; return rc;
} }
static const struct l2tp_nl_cmd_ops l2tp_eth_nl_cmd_ops = { static const struct l2tp_nl_cmd_ops l2tp_eth_nl_cmd_ops = {
.session_create = l2tp_eth_create, .session_create = l2tp_eth_create,
.session_delete = l2tp_session_delete, .session_delete = l2tp_session_delete,
}; };
static int __init l2tp_eth_init(void) static int __init l2tp_eth_init(void)
{ {
int err = 0; int err = 0;
......
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /* L2TPv3 IP encapsulation support
* L2TPv3 IP encapsulation support
* *
* Copyright (c) 2008,2009,2010 Katalix Systems Ltd * Copyright (c) 2008,2009,2010 Katalix Systems Ltd
*/ */
...@@ -126,7 +125,7 @@ static int l2tp_ip_recv(struct sk_buff *skb) ...@@ -126,7 +125,7 @@ static int l2tp_ip_recv(struct sk_buff *skb)
/* Point to L2TP header */ /* Point to L2TP header */
optr = ptr = skb->data; optr = ptr = skb->data;
session_id = ntohl(*((__be32 *) ptr)); session_id = ntohl(*((__be32 *)ptr));
ptr += 4; ptr += 4;
/* RFC3931: L2TP/IP packets have the first 4 bytes containing /* RFC3931: L2TP/IP packets have the first 4 bytes containing
...@@ -176,7 +175,7 @@ static int l2tp_ip_recv(struct sk_buff *skb) ...@@ -176,7 +175,7 @@ static int l2tp_ip_recv(struct sk_buff *skb)
if ((skb->data[0] & 0xc0) != 0xc0) if ((skb->data[0] & 0xc0) != 0xc0)
goto discard; goto discard;
tunnel_id = ntohl(*(__be32 *) &skb->data[4]); tunnel_id = ntohl(*(__be32 *)&skb->data[4]);
iph = (struct iphdr *)skb_network_header(skb); iph = (struct iphdr *)skb_network_header(skb);
read_lock_bh(&l2tp_ip_lock); read_lock_bh(&l2tp_ip_lock);
...@@ -260,7 +259,7 @@ static void l2tp_ip_destroy_sock(struct sock *sk) ...@@ -260,7 +259,7 @@ static void l2tp_ip_destroy_sock(struct sock *sk)
static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
{ {
struct inet_sock *inet = inet_sk(sk); struct inet_sock *inet = inet_sk(sk);
struct sockaddr_l2tpip *addr = (struct sockaddr_l2tpip *) uaddr; struct sockaddr_l2tpip *addr = (struct sockaddr_l2tpip *)uaddr;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
int ret; int ret;
int chk_addr_ret; int chk_addr_ret;
...@@ -316,7 +315,7 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) ...@@ -316,7 +315,7 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
static int l2tp_ip_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) static int l2tp_ip_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
{ {
struct sockaddr_l2tpip *lsa = (struct sockaddr_l2tpip *) uaddr; struct sockaddr_l2tpip *lsa = (struct sockaddr_l2tpip *)uaddr;
int rc; int rc;
if (addr_len < sizeof(*lsa)) if (addr_len < sizeof(*lsa))
...@@ -375,6 +374,7 @@ static int l2tp_ip_getname(struct socket *sock, struct sockaddr *uaddr, ...@@ -375,6 +374,7 @@ static int l2tp_ip_getname(struct socket *sock, struct sockaddr *uaddr,
lsa->l2tp_addr.s_addr = inet->inet_daddr; lsa->l2tp_addr.s_addr = inet->inet_daddr;
} else { } else {
__be32 addr = inet->inet_rcv_saddr; __be32 addr = inet->inet_rcv_saddr;
if (!addr) if (!addr)
addr = inet->inet_saddr; addr = inet->inet_saddr;
lsa->l2tp_conn_id = lsk->conn_id; lsa->l2tp_conn_id = lsk->conn_id;
...@@ -422,6 +422,7 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -422,6 +422,7 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
/* Get and verify the address. */ /* Get and verify the address. */
if (msg->msg_name) { if (msg->msg_name) {
DECLARE_SOCKADDR(struct sockaddr_l2tpip *, lip, msg->msg_name); DECLARE_SOCKADDR(struct sockaddr_l2tpip *, lip, msg->msg_name);
rc = -EINVAL; rc = -EINVAL;
if (msg->msg_namelen < sizeof(*lip)) if (msg->msg_namelen < sizeof(*lip))
goto out; goto out;
...@@ -456,7 +457,7 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -456,7 +457,7 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
skb_reset_transport_header(skb); skb_reset_transport_header(skb);
/* Insert 0 session_id */ /* Insert 0 session_id */
*((__be32 *) skb_put(skb, 4)) = 0; *((__be32 *)skb_put(skb, 4)) = 0;
/* Copy user data into skb */ /* Copy user data into skb */
rc = memcpy_from_msg(skb_put(skb, len), msg, len); rc = memcpy_from_msg(skb_put(skb, len), msg, len);
...@@ -467,7 +468,7 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -467,7 +468,7 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
fl4 = &inet->cork.fl.u.ip4; fl4 = &inet->cork.fl.u.ip4;
if (connected) if (connected)
rt = (struct rtable *) __sk_dst_check(sk, 0); rt = (struct rtable *)__sk_dst_check(sk, 0);
rcu_read_lock(); rcu_read_lock();
if (rt == NULL) { if (rt == NULL) {
......
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
/* /* L2TPv3 IP encapsulation support for IPv6
* L2TPv3 IP encapsulation support for IPv6
* *
* Copyright (c) 2012 Katalix Systems Ltd * Copyright (c) 2012 Katalix Systems Ltd
*/ */
...@@ -38,7 +37,8 @@ struct l2tp_ip6_sock { ...@@ -38,7 +37,8 @@ struct l2tp_ip6_sock {
u32 peer_conn_id; u32 peer_conn_id;
/* ipv6_pinfo has to be the last member of l2tp_ip6_sock, see /* ipv6_pinfo has to be the last member of l2tp_ip6_sock, see
inet6_sk_generic */ * inet6_sk_generic
*/
struct ipv6_pinfo inet6; struct ipv6_pinfo inet6;
}; };
...@@ -138,7 +138,7 @@ static int l2tp_ip6_recv(struct sk_buff *skb) ...@@ -138,7 +138,7 @@ static int l2tp_ip6_recv(struct sk_buff *skb)
/* Point to L2TP header */ /* Point to L2TP header */
optr = ptr = skb->data; optr = ptr = skb->data;
session_id = ntohl(*((__be32 *) ptr)); session_id = ntohl(*((__be32 *)ptr));
ptr += 4; ptr += 4;
/* RFC3931: L2TP/IP packets have the first 4 bytes containing /* RFC3931: L2TP/IP packets have the first 4 bytes containing
...@@ -188,7 +188,7 @@ static int l2tp_ip6_recv(struct sk_buff *skb) ...@@ -188,7 +188,7 @@ static int l2tp_ip6_recv(struct sk_buff *skb)
if ((skb->data[0] & 0xc0) != 0xc0) if ((skb->data[0] & 0xc0) != 0xc0)
goto discard; goto discard;
tunnel_id = ntohl(*(__be32 *) &skb->data[4]); tunnel_id = ntohl(*(__be32 *)&skb->data[4]);
iph = ipv6_hdr(skb); iph = ipv6_hdr(skb);
read_lock_bh(&l2tp_ip6_lock); read_lock_bh(&l2tp_ip6_lock);
...@@ -276,7 +276,7 @@ static int l2tp_ip6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) ...@@ -276,7 +276,7 @@ static int l2tp_ip6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
{ {
struct inet_sock *inet = inet_sk(sk); struct inet_sock *inet = inet_sk(sk);
struct ipv6_pinfo *np = inet6_sk(sk); struct ipv6_pinfo *np = inet6_sk(sk);
struct sockaddr_l2tpip6 *addr = (struct sockaddr_l2tpip6 *) uaddr; struct sockaddr_l2tpip6 *addr = (struct sockaddr_l2tpip6 *)uaddr;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
__be32 v4addr = 0; __be32 v4addr = 0;
int bound_dev_if; int bound_dev_if;
...@@ -375,8 +375,8 @@ static int l2tp_ip6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) ...@@ -375,8 +375,8 @@ static int l2tp_ip6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
static int l2tp_ip6_connect(struct sock *sk, struct sockaddr *uaddr, static int l2tp_ip6_connect(struct sock *sk, struct sockaddr *uaddr,
int addr_len) int addr_len)
{ {
struct sockaddr_l2tpip6 *lsa = (struct sockaddr_l2tpip6 *) uaddr; struct sockaddr_l2tpip6 *lsa = (struct sockaddr_l2tpip6 *)uaddr;
struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr; struct sockaddr_in6 *usin = (struct sockaddr_in6 *)uaddr;
struct in6_addr *daddr; struct in6_addr *daddr;
int addr_type; int addr_type;
int rc; int rc;
...@@ -519,7 +519,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -519,7 +519,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
int err; int err;
/* Rough check on arithmetic overflow, /* Rough check on arithmetic overflow,
better check is made in ip6_append_data(). * better check is made in ip6_append_data().
*/ */
if (len > INT_MAX) if (len > INT_MAX)
return -EMSGSIZE; return -EMSGSIZE;
...@@ -528,9 +528,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -528,9 +528,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
if (msg->msg_flags & MSG_OOB) if (msg->msg_flags & MSG_OOB)
return -EOPNOTSUPP; return -EOPNOTSUPP;
/* /* Get and verify the address */
* Get and verify the address.
*/
memset(&fl6, 0, sizeof(fl6)); memset(&fl6, 0, sizeof(fl6));
fl6.flowi6_mark = sk->sk_mark; fl6.flowi6_mark = sk->sk_mark;
...@@ -548,15 +546,14 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -548,15 +546,14 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
daddr = &lsa->l2tp_addr; daddr = &lsa->l2tp_addr;
if (np->sndflow) { if (np->sndflow) {
fl6.flowlabel = lsa->l2tp_flowinfo & IPV6_FLOWINFO_MASK; fl6.flowlabel = lsa->l2tp_flowinfo & IPV6_FLOWINFO_MASK;
if (fl6.flowlabel&IPV6_FLOWLABEL_MASK) { if (fl6.flowlabel & IPV6_FLOWLABEL_MASK) {
flowlabel = fl6_sock_lookup(sk, fl6.flowlabel); flowlabel = fl6_sock_lookup(sk, fl6.flowlabel);
if (IS_ERR(flowlabel)) if (IS_ERR(flowlabel))
return -EINVAL; return -EINVAL;
} }
} }
/* /* Otherwise it will be difficult to maintain
* Otherwise it will be difficult to maintain
* sk->sk_dst_cache. * sk->sk_dst_cache.
*/ */
if (sk->sk_state == TCP_ESTABLISHED && if (sk->sk_state == TCP_ESTABLISHED &&
...@@ -594,7 +591,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -594,7 +591,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
if (IS_ERR(flowlabel)) if (IS_ERR(flowlabel))
return -EINVAL; return -EINVAL;
} }
if (!(opt->opt_nflen|opt->opt_flen)) if (!(opt->opt_nflen | opt->opt_flen))
opt = NULL; opt = NULL;
} }
......
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
/* /* L2TP netlink layer, for management
* L2TP netlink layer, for management
* *
* Copyright (c) 2008,2009,2010 Katalix Systems Ltd * Copyright (c) 2008,2009,2010 Katalix Systems Ltd
* *
...@@ -27,7 +26,6 @@ ...@@ -27,7 +26,6 @@
#include "l2tp_core.h" #include "l2tp_core.h"
static struct genl_family l2tp_nl_family; static struct genl_family l2tp_nl_family;
static const struct genl_multicast_group l2tp_multicast_group[] = { static const struct genl_multicast_group l2tp_multicast_group[] = {
...@@ -167,71 +165,63 @@ static int l2tp_nl_cmd_tunnel_create(struct sk_buff *skb, struct genl_info *info ...@@ -167,71 +165,63 @@ static int l2tp_nl_cmd_tunnel_create(struct sk_buff *skb, struct genl_info *info
struct l2tp_tunnel_cfg cfg = { 0, }; struct l2tp_tunnel_cfg cfg = { 0, };
struct l2tp_tunnel *tunnel; struct l2tp_tunnel *tunnel;
struct net *net = genl_info_net(info); struct net *net = genl_info_net(info);
struct nlattr **attrs = info->attrs;
if (!info->attrs[L2TP_ATTR_CONN_ID]) { if (!attrs[L2TP_ATTR_CONN_ID]) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_CONN_ID]); tunnel_id = nla_get_u32(attrs[L2TP_ATTR_CONN_ID]);
if (!info->attrs[L2TP_ATTR_PEER_CONN_ID]) { if (!attrs[L2TP_ATTR_PEER_CONN_ID]) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
peer_tunnel_id = nla_get_u32(info->attrs[L2TP_ATTR_PEER_CONN_ID]); peer_tunnel_id = nla_get_u32(attrs[L2TP_ATTR_PEER_CONN_ID]);
if (!info->attrs[L2TP_ATTR_PROTO_VERSION]) { if (!attrs[L2TP_ATTR_PROTO_VERSION]) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
proto_version = nla_get_u8(info->attrs[L2TP_ATTR_PROTO_VERSION]); proto_version = nla_get_u8(attrs[L2TP_ATTR_PROTO_VERSION]);
if (!info->attrs[L2TP_ATTR_ENCAP_TYPE]) { if (!attrs[L2TP_ATTR_ENCAP_TYPE]) {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
cfg.encap = nla_get_u16(info->attrs[L2TP_ATTR_ENCAP_TYPE]); cfg.encap = nla_get_u16(attrs[L2TP_ATTR_ENCAP_TYPE]);
fd = -1; fd = -1;
if (info->attrs[L2TP_ATTR_FD]) { if (attrs[L2TP_ATTR_FD]) {
fd = nla_get_u32(info->attrs[L2TP_ATTR_FD]); fd = nla_get_u32(attrs[L2TP_ATTR_FD]);
} else { } else {
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
if (info->attrs[L2TP_ATTR_IP6_SADDR] && if (attrs[L2TP_ATTR_IP6_SADDR] && attrs[L2TP_ATTR_IP6_DADDR]) {
info->attrs[L2TP_ATTR_IP6_DADDR]) { cfg.local_ip6 = nla_data(attrs[L2TP_ATTR_IP6_SADDR]);
cfg.local_ip6 = nla_data( cfg.peer_ip6 = nla_data(attrs[L2TP_ATTR_IP6_DADDR]);
info->attrs[L2TP_ATTR_IP6_SADDR]);
cfg.peer_ip6 = nla_data(
info->attrs[L2TP_ATTR_IP6_DADDR]);
} else } else
#endif #endif
if (info->attrs[L2TP_ATTR_IP_SADDR] && if (attrs[L2TP_ATTR_IP_SADDR] && attrs[L2TP_ATTR_IP_DADDR]) {
info->attrs[L2TP_ATTR_IP_DADDR]) { cfg.local_ip.s_addr = nla_get_in_addr(attrs[L2TP_ATTR_IP_SADDR]);
cfg.local_ip.s_addr = nla_get_in_addr( cfg.peer_ip.s_addr = nla_get_in_addr(attrs[L2TP_ATTR_IP_DADDR]);
info->attrs[L2TP_ATTR_IP_SADDR]);
cfg.peer_ip.s_addr = nla_get_in_addr(
info->attrs[L2TP_ATTR_IP_DADDR]);
} else { } else {
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
if (info->attrs[L2TP_ATTR_UDP_SPORT]) if (attrs[L2TP_ATTR_UDP_SPORT])
cfg.local_udp_port = nla_get_u16(info->attrs[L2TP_ATTR_UDP_SPORT]); cfg.local_udp_port = nla_get_u16(attrs[L2TP_ATTR_UDP_SPORT]);
if (info->attrs[L2TP_ATTR_UDP_DPORT]) if (attrs[L2TP_ATTR_UDP_DPORT])
cfg.peer_udp_port = nla_get_u16(info->attrs[L2TP_ATTR_UDP_DPORT]); cfg.peer_udp_port = nla_get_u16(attrs[L2TP_ATTR_UDP_DPORT]);
cfg.use_udp_checksums = nla_get_flag( cfg.use_udp_checksums = nla_get_flag(attrs[L2TP_ATTR_UDP_CSUM]);
info->attrs[L2TP_ATTR_UDP_CSUM]);
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
cfg.udp6_zero_tx_checksums = nla_get_flag( cfg.udp6_zero_tx_checksums = nla_get_flag(attrs[L2TP_ATTR_UDP_ZERO_CSUM6_TX]);
info->attrs[L2TP_ATTR_UDP_ZERO_CSUM6_TX]); cfg.udp6_zero_rx_checksums = nla_get_flag(attrs[L2TP_ATTR_UDP_ZERO_CSUM6_RX]);
cfg.udp6_zero_rx_checksums = nla_get_flag(
info->attrs[L2TP_ATTR_UDP_ZERO_CSUM6_RX]);
#endif #endif
} }
if (info->attrs[L2TP_ATTR_DEBUG]) if (attrs[L2TP_ATTR_DEBUG])
cfg.debug = nla_get_u32(info->attrs[L2TP_ATTR_DEBUG]); cfg.debug = nla_get_u32(attrs[L2TP_ATTR_DEBUG]);
ret = -EINVAL; ret = -EINVAL;
switch (cfg.encap) { switch (cfg.encap) {
...@@ -570,6 +560,7 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf ...@@ -570,6 +560,7 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf
if (info->attrs[L2TP_ATTR_COOKIE]) { if (info->attrs[L2TP_ATTR_COOKIE]) {
u16 len = nla_len(info->attrs[L2TP_ATTR_COOKIE]); u16 len = nla_len(info->attrs[L2TP_ATTR_COOKIE]);
if (len > 8) { if (len > 8) {
ret = -EINVAL; ret = -EINVAL;
goto out_tunnel; goto out_tunnel;
...@@ -579,6 +570,7 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf ...@@ -579,6 +570,7 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf
} }
if (info->attrs[L2TP_ATTR_PEER_COOKIE]) { if (info->attrs[L2TP_ATTR_PEER_COOKIE]) {
u16 len = nla_len(info->attrs[L2TP_ATTR_PEER_COOKIE]); u16 len = nla_len(info->attrs[L2TP_ATTR_PEER_COOKIE]);
if (len > 8) { if (len > 8) {
ret = -EINVAL; ret = -EINVAL;
goto out_tunnel; goto out_tunnel;
...@@ -715,8 +707,7 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl ...@@ -715,8 +707,7 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl
if (nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) || if (nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id) || nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id) ||
nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id) || nla_put_u32(skb, L2TP_ATTR_PEER_CONN_ID, tunnel->peer_tunnel_id) ||
nla_put_u32(skb, L2TP_ATTR_PEER_SESSION_ID, nla_put_u32(skb, L2TP_ATTR_PEER_SESSION_ID, session->peer_session_id) ||
session->peer_session_id) ||
nla_put_u32(skb, L2TP_ATTR_DEBUG, session->debug) || nla_put_u32(skb, L2TP_ATTR_DEBUG, session->debug) ||
nla_put_u16(skb, L2TP_ATTR_PW_TYPE, session->pwtype)) nla_put_u16(skb, L2TP_ATTR_PW_TYPE, session->pwtype))
goto nla_put_failure; goto nla_put_failure;
...@@ -724,11 +715,9 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl ...@@ -724,11 +715,9 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl
if ((session->ifname[0] && if ((session->ifname[0] &&
nla_put_string(skb, L2TP_ATTR_IFNAME, session->ifname)) || nla_put_string(skb, L2TP_ATTR_IFNAME, session->ifname)) ||
(session->cookie_len && (session->cookie_len &&
nla_put(skb, L2TP_ATTR_COOKIE, session->cookie_len, nla_put(skb, L2TP_ATTR_COOKIE, session->cookie_len, session->cookie)) ||
&session->cookie[0])) ||
(session->peer_cookie_len && (session->peer_cookie_len &&
nla_put(skb, L2TP_ATTR_PEER_COOKIE, session->peer_cookie_len, nla_put(skb, L2TP_ATTR_PEER_COOKIE, session->peer_cookie_len, session->peer_cookie)) ||
&session->peer_cookie[0])) ||
nla_put_u8(skb, L2TP_ATTR_RECV_SEQ, session->recv_seq) || nla_put_u8(skb, L2TP_ATTR_RECV_SEQ, session->recv_seq) ||
nla_put_u8(skb, L2TP_ATTR_SEND_SEQ, session->send_seq) || nla_put_u8(skb, L2TP_ATTR_SEND_SEQ, session->send_seq) ||
nla_put_u8(skb, L2TP_ATTR_LNS_MODE, session->lns_mode) || nla_put_u8(skb, L2TP_ATTR_LNS_MODE, session->lns_mode) ||
......
...@@ -117,8 +117,7 @@ struct pppol2tp_session { ...@@ -117,8 +117,7 @@ struct pppol2tp_session {
int owner; /* pid that opened the socket */ int owner; /* pid that opened the socket */
struct mutex sk_lock; /* Protects .sk */ struct mutex sk_lock; /* Protects .sk */
struct sock __rcu *sk; /* Pointer to the session struct sock __rcu *sk; /* Pointer to the session PPPoX socket */
* PPPoX socket */
struct sock *__sk; /* Copy of .sk, for cleanup */ struct sock *__sk; /* Copy of .sk, for cleanup */
struct rcu_head rcu; /* For asynchronous release */ struct rcu_head rcu; /* For asynchronous release */
}; };
...@@ -351,7 +350,7 @@ static int pppol2tp_sendmsg(struct socket *sock, struct msghdr *m, ...@@ -351,7 +350,7 @@ static int pppol2tp_sendmsg(struct socket *sock, struct msghdr *m,
*/ */
static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb) static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
{ {
struct sock *sk = (struct sock *) chan->private; struct sock *sk = (struct sock *)chan->private;
struct l2tp_session *session; struct l2tp_session *session;
struct l2tp_tunnel *tunnel; struct l2tp_tunnel *tunnel;
int uhlen, headroom; int uhlen, headroom;
...@@ -928,6 +927,7 @@ static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr, ...@@ -928,6 +927,7 @@ static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
inet = inet_sk(tunnel->sock); inet = inet_sk(tunnel->sock);
if ((tunnel->version == 2) && (tunnel->sock->sk_family == AF_INET)) { if ((tunnel->version == 2) && (tunnel->sock->sk_family == AF_INET)) {
struct sockaddr_pppol2tp sp; struct sockaddr_pppol2tp sp;
len = sizeof(sp); len = sizeof(sp);
memset(&sp, 0, len); memset(&sp, 0, len);
sp.sa_family = AF_PPPOX; sp.sa_family = AF_PPPOX;
...@@ -984,6 +984,7 @@ static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr, ...@@ -984,6 +984,7 @@ static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
#endif #endif
} else if (tunnel->version == 3) { } else if (tunnel->version == 3) {
struct sockaddr_pppol2tpv3 sp; struct sockaddr_pppol2tpv3 sp;
len = sizeof(sp); len = sizeof(sp);
memset(&sp, 0, len); memset(&sp, 0, len);
sp.sa_family = AF_PPPOX; sp.sa_family = AF_PPPOX;
...@@ -1343,7 +1344,7 @@ static int pppol2tp_session_getsockopt(struct sock *sk, ...@@ -1343,7 +1344,7 @@ static int pppol2tp_session_getsockopt(struct sock *sk,
break; break;
case PPPOL2TP_SO_REORDERTO: case PPPOL2TP_SO_REORDERTO:
*val = (int) jiffies_to_msecs(session->reorder_timeout); *val = (int)jiffies_to_msecs(session->reorder_timeout);
l2tp_info(session, L2TP_MSG_CONTROL, l2tp_info(session, L2TP_MSG_CONTROL,
"%s: get reorder_timeout=%d\n", session->name, *val); "%s: get reorder_timeout=%d\n", session->name, *val);
break; break;
...@@ -1407,7 +1408,7 @@ static int pppol2tp_getsockopt(struct socket *sock, int level, int optname, ...@@ -1407,7 +1408,7 @@ static int pppol2tp_getsockopt(struct socket *sock, int level, int optname,
if (put_user(len, optlen)) if (put_user(len, optlen))
goto end_put_sess; goto end_put_sess;
if (copy_to_user((void __user *) optval, &val, len)) if (copy_to_user((void __user *)optval, &val, len))
goto end_put_sess; goto end_put_sess;
err = 0; err = 0;
...@@ -1551,6 +1552,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v) ...@@ -1551,6 +1552,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
if (tunnel->sock) { if (tunnel->sock) {
struct inet_sock *inet = inet_sk(tunnel->sock); struct inet_sock *inet = inet_sk(tunnel->sock);
ip = ntohl(inet->inet_saddr); ip = ntohl(inet->inet_saddr);
port = ntohs(inet->inet_sport); port = ntohs(inet->inet_sport);
} }
...@@ -1564,8 +1566,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v) ...@@ -1564,8 +1566,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
user_data_ok = 'N'; user_data_ok = 'N';
} }
seq_printf(m, " SESSION '%s' %08X/%d %04X/%04X -> " seq_printf(m, " SESSION '%s' %08X/%d %04X/%04X -> %04X/%04X %d %c\n",
"%04X/%04X %d %c\n",
session->name, ip, port, session->name, ip, port,
tunnel->tunnel_id, tunnel->tunnel_id,
session->session_id, session->session_id,
...@@ -1604,8 +1605,7 @@ static int pppol2tp_seq_show(struct seq_file *m, void *v) ...@@ -1604,8 +1605,7 @@ static int pppol2tp_seq_show(struct seq_file *m, void *v)
seq_puts(m, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION "\n"); seq_puts(m, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION "\n");
seq_puts(m, "TUNNEL name, user-data-ok session-count\n"); seq_puts(m, "TUNNEL name, user-data-ok session-count\n");
seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n"); seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
seq_puts(m, " SESSION name, addr/port src-tid/sid " seq_puts(m, " SESSION name, addr/port src-tid/sid dest-tid/sid state user-data-ok\n");
"dest-tid/sid state user-data-ok\n");
seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n"); seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n");
seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n"); seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
goto out; goto out;
...@@ -1638,7 +1638,7 @@ static __net_init int pppol2tp_init_net(struct net *net) ...@@ -1638,7 +1638,7 @@ static __net_init int pppol2tp_init_net(struct net *net)
int err = 0; int err = 0;
pde = proc_create_net("pppol2tp", 0444, net->proc_net, pde = proc_create_net("pppol2tp", 0444, net->proc_net,
&pppol2tp_seq_ops, sizeof(struct pppol2tp_seq_data)); &pppol2tp_seq_ops, sizeof(struct pppol2tp_seq_data));
if (!pde) { if (!pde) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment