Skip to content

Commit cf14a4d

Browse files
j-c-hDavid S. Miller
authored andcommitted
[L2TP]: Changes to existing ppp and socket kernel headers for L2TP
Add struct sockaddr_pppol2tp to carry L2TP-specific address information for the PPPoX (PPPoL2TP) socket. Unfortunately we can't use the union inside struct sockaddr_pppox because the L2TP-specific data is larger than the current size of the union and we must preserve the size of struct sockaddr_pppox for binary compatibility. Also add a PPPIOCGL2TPSTATS ioctl to allow userspace to obtain L2TP counters and state from the kernel. Add new if_pppol2tp.h header. [ Modified to use aligned_u64 in statistics structure -DaveM ] Signed-off-by: James Chapman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 342f023 commit cf14a4d

File tree

5 files changed

+101
-2
lines changed

5 files changed

+101
-2
lines changed

include/linux/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ unifdef-y += if_fddi.h
225225
unifdef-y += if_frad.h
226226
unifdef-y += if_ltalk.h
227227
unifdef-y += if_link.h
228+
unifdef-y += if_pppol2tp.h
228229
unifdef-y += if_pppox.h
229230
unifdef-y += if_shaper.h
230231
unifdef-y += if_tr.h

include/linux/if_ppp.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ struct ifpppcstatsreq {
110110
struct ppp_comp_stats stats;
111111
};
112112

113+
/* For PPPIOCGL2TPSTATS */
114+
struct pppol2tp_ioc_stats {
115+
__u16 tunnel_id; /* redundant */
116+
__u16 session_id; /* if zero, get tunnel stats */
117+
__u32 using_ipsec:1; /* valid only for session_id == 0 */
118+
aligned_u64 tx_packets;
119+
aligned_u64 tx_bytes;
120+
aligned_u64 tx_errors;
121+
aligned_u64 rx_packets;
122+
aligned_u64 rx_bytes;
123+
aligned_u64 rx_seq_discards;
124+
aligned_u64 rx_oos_packets;
125+
aligned_u64 rx_errors;
126+
};
127+
113128
#define ifr__name b.ifr_ifrn.ifrn_name
114129
#define stats_ptr b.ifr_ifru.ifru_data
115130

@@ -146,6 +161,7 @@ struct ifpppcstatsreq {
146161
#define PPPIOCDISCONN _IO('t', 57) /* disconnect channel */
147162
#define PPPIOCATTCHAN _IOW('t', 56, int) /* attach to ppp channel */
148163
#define PPPIOCGCHAN _IOR('t', 55, int) /* get ppp channel number */
164+
#define PPPIOCGL2TPSTATS _IOR('t', 54, struct pppol2tp_ioc_stats)
149165

150166
#define SIOCGPPPSTATS (SIOCDEVPRIVATE + 0)
151167
#define SIOCGPPPVER (SIOCDEVPRIVATE + 1) /* NEVER change this!! */

include/linux/if_pppol2tp.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/***************************************************************************
2+
* Linux PPP over L2TP (PPPoL2TP) Socket Implementation (RFC 2661)
3+
*
4+
* This file supplies definitions required by the PPP over L2TP driver
5+
* (pppol2tp.c). All version information wrt this file is located in pppol2tp.c
6+
*
7+
* License:
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License
10+
* as published by the Free Software Foundation; either version
11+
* 2 of the License, or (at your option) any later version.
12+
*
13+
*/
14+
15+
#ifndef __LINUX_IF_PPPOL2TP_H
16+
#define __LINUX_IF_PPPOL2TP_H
17+
18+
#include <asm/types.h>
19+
20+
#ifdef __KERNEL__
21+
#include <linux/in.h>
22+
#endif
23+
24+
/* Structure used to connect() the socket to a particular tunnel UDP
25+
* socket.
26+
*/
27+
struct pppol2tp_addr
28+
{
29+
pid_t pid; /* pid that owns the fd.
30+
* 0 => current */
31+
int fd; /* FD of UDP socket to use */
32+
33+
struct sockaddr_in addr; /* IP address and port to send to */
34+
35+
__be16 s_tunnel, s_session; /* For matching incoming packets */
36+
__be16 d_tunnel, d_session; /* For sending outgoing packets */
37+
};
38+
39+
/* Socket options:
40+
* DEBUG - bitmask of debug message categories
41+
* SENDSEQ - 0 => don't send packets with sequence numbers
42+
* 1 => send packets with sequence numbers
43+
* RECVSEQ - 0 => receive packet sequence numbers are optional
44+
* 1 => drop receive packets without sequence numbers
45+
* LNSMODE - 0 => act as LAC.
46+
* 1 => act as LNS.
47+
* REORDERTO - reorder timeout (in millisecs). If 0, don't try to reorder.
48+
*/
49+
enum {
50+
PPPOL2TP_SO_DEBUG = 1,
51+
PPPOL2TP_SO_RECVSEQ = 2,
52+
PPPOL2TP_SO_SENDSEQ = 3,
53+
PPPOL2TP_SO_LNSMODE = 4,
54+
PPPOL2TP_SO_REORDERTO = 5,
55+
};
56+
57+
/* Debug message categories for the DEBUG socket option */
58+
enum {
59+
PPPOL2TP_MSG_DEBUG = (1 << 0), /* verbose debug (if
60+
* compiled in) */
61+
PPPOL2TP_MSG_CONTROL = (1 << 1), /* userspace - kernel
62+
* interface */
63+
PPPOL2TP_MSG_SEQ = (1 << 2), /* sequence numbers */
64+
PPPOL2TP_MSG_DATA = (1 << 3), /* data packets */
65+
};
66+
67+
68+
69+
#endif

include/linux/if_pppox.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <asm/semaphore.h>
2828
#include <linux/ppp_channel.h>
2929
#endif /* __KERNEL__ */
30+
#include <linux/if_pppol2tp.h>
3031

3132
/* For user-space programs to pick up these definitions
3233
* which they wouldn't get otherwise without defining __KERNEL__
@@ -50,8 +51,9 @@ struct pppoe_addr{
5051
* Protocols supported by AF_PPPOX
5152
*/
5253
#define PX_PROTO_OE 0 /* Currently just PPPoE */
53-
#define PX_MAX_PROTO 1
54-
54+
#define PX_PROTO_OL2TP 1 /* Now L2TP also */
55+
#define PX_MAX_PROTO 2
56+
5557
struct sockaddr_pppox {
5658
sa_family_t sa_family; /* address family, AF_PPPOX */
5759
unsigned int sa_protocol; /* protocol identifier */
@@ -60,6 +62,16 @@ struct sockaddr_pppox {
6062
}sa_addr;
6163
}__attribute__ ((packed));
6264

65+
/* The use of the above union isn't viable because the size of this
66+
* struct must stay fixed over time -- applications use sizeof(struct
67+
* sockaddr_pppox) to fill it. We use a protocol specific sockaddr
68+
* type instead.
69+
*/
70+
struct sockaddr_pppol2tp {
71+
sa_family_t sa_family; /* address family, AF_PPPOX */
72+
unsigned int sa_protocol; /* protocol identifier */
73+
struct pppol2tp_addr pppol2tp;
74+
}__attribute__ ((packed));
6375

6476
/*********************************************************************
6577
*

include/linux/socket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ struct ucred {
287287
#define SOL_NETLINK 270
288288
#define SOL_TIPC 271
289289
#define SOL_RXRPC 272
290+
#define SOL_PPPOL2TP 273
290291

291292
/* IPX options */
292293
#define IPX_TYPE 1

0 commit comments

Comments
 (0)