xref: /freebsd/sys/netgraph/ng_l2tp.h (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1 /*-
2  * Copyright (c) 2001-2002 Packet Design, LLC.
3  * All rights reserved.
4  *
5  * Subject to the following obligations and disclaimer of warranty,
6  * use and redistribution of this software, in source or object code
7  * forms, with or without modifications are expressly permitted by
8  * Packet Design; provided, however, that:
9  *
10  *    (i)  Any and all reproductions of the source or object code
11  *         must include the copyright notice above and the following
12  *         disclaimer of warranties; and
13  *    (ii) No rights are granted, in any manner or form, to use
14  *         Packet Design trademarks, including the mark "PACKET DESIGN"
15  *         on advertising, endorsements, or otherwise except as such
16  *         appears in the above copyright notice or in the software.
17  *
18  * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
19  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
20  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
21  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
22  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
23  * OR NON-INFRINGEMENT.  PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
24  * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
25  * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
26  * RELIABILITY OR OTHERWISE.  IN NO EVENT SHALL PACKET DESIGN BE
27  * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
28  * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
29  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
30  * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
31  * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
32  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
34  * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
35  * THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * Author: Archie Cobbs <archie@freebsd.org>
38  */
39 
40 #ifndef _NETGRAPH_NG_L2TP_H_
41 #define _NETGRAPH_NG_L2TP_H_
42 
43 /* Node type name and magic cookie */
44 #define NG_L2TP_NODE_TYPE	"l2tp"
45 #define NGM_L2TP_COOKIE		1091515793
46 
47 /* Hook names */
48 #define NG_L2TP_HOOK_CTRL	"ctrl"		/* control channel hook */
49 #define NG_L2TP_HOOK_LOWER	"lower"		/* hook to lower layers */
50 
51 /* Session hooks: prefix plus hex session ID, e.g., "session_3e14" */
52 #define NG_L2TP_HOOK_SESSION_P	"session_"	/* session data hook (prefix) */
53 #define NG_L2TP_HOOK_SESSION_F	"session_%04x"	/* session data hook (format) */
54 
55 /* Set initial sequence numbers to not yet enabled node. */
56 struct ng_l2tp_seq_config {
57 	u_int16_t	ns;		/* sequence number to send next */
58 	u_int16_t	nr;		/* sequence number to be recved next */
59 	u_int16_t	rack;		/* last 'nr' received */
60 	u_int16_t	xack;		/* last 'nr' sent */
61 };
62 
63 /* Keep this in sync with the above structure definition. */
64 #define	NG_L2TP_SEQ_CONFIG_TYPE_INFO	{			\
65 	  { "ns",		&ng_parse_uint16_type	},	\
66 	  { "nr",		&ng_parse_uint16_type	},	\
67 	  { NULL }						\
68 }
69 
70 /* Configuration for a node */
71 struct ng_l2tp_config {
72 	u_char		enabled;	/* enables traffic flow */
73 	u_char		match_id;	/* tunnel id must match 'tunnel_id' */
74 	u_int16_t	tunnel_id;	/* local tunnel id */
75 	u_int16_t	peer_id;	/* peer's tunnel id */
76 	u_int16_t	peer_win;	/* peer's max recv window size */
77 	u_int16_t	rexmit_max;	/* max retransmits before failure */
78 	u_int16_t	rexmit_max_to;	/* max delay between retransmits */
79 };
80 
81 /* Keep this in sync with the above structure definition */
82 #define NG_L2TP_CONFIG_TYPE_INFO	{			\
83 	  { "enabled",		&ng_parse_uint8_type	},	\
84 	  { "match_id",		&ng_parse_uint8_type	},	\
85 	  { "tunnel_id",	&ng_parse_hint16_type	},	\
86 	  { "peer_id",		&ng_parse_hint16_type	},	\
87 	  { "peer_win",		&ng_parse_uint16_type	},	\
88 	  { "rexmit_max",	&ng_parse_uint16_type	},	\
89 	  { "rexmit_max_to",	&ng_parse_uint16_type	},	\
90 	  { NULL }						\
91 }
92 
93 /* Configuration for a session hook */
94 struct ng_l2tp_sess_config {
95 	u_int16_t	session_id;	/* local session id */
96 	u_int16_t	peer_id;	/* peer's session id */
97 	u_char		control_dseq;	/* whether we control data sequencing */
98 	u_char		enable_dseq;	/* whether to enable data sequencing */
99 	u_char		include_length;	/* whether to include length field */
100 };
101 
102 /* Keep this in sync with the above structure definition */
103 #define NG_L2TP_SESS_CONFIG_TYPE_INFO	{			\
104 	  { "session_id",	&ng_parse_hint16_type	},	\
105 	  { "peer_id",		&ng_parse_hint16_type	},	\
106 	  { "control_dseq",	&ng_parse_uint8_type	},	\
107 	  { "enable_dseq",	&ng_parse_uint8_type	},	\
108 	  { "include_length",	&ng_parse_uint8_type	},	\
109 	  { NULL }						\
110 }
111 
112 /* Statistics struct */
113 struct ng_l2tp_stats {
114 	u_int32_t xmitPackets;		/* number of packets xmit */
115 	u_int32_t xmitOctets;		/* number of octets xmit */
116 	u_int32_t xmitZLBs;		/* ack-only packets transmitted */
117 	u_int32_t xmitDrops;		/* xmits dropped due to full window */
118 	u_int32_t xmitTooBig;		/* ctrl pkts dropped because too big */
119 	u_int32_t xmitInvalid;		/* ctrl packets with no session ID */
120 	u_int32_t xmitDataTooBig;	/* data pkts dropped because too big */
121 	u_int32_t xmitRetransmits;	/* retransmitted packets */
122 	u_int32_t recvPackets;		/* number of packets rec'd */
123 	u_int32_t recvOctets;		/* number of octets rec'd */
124 	u_int32_t recvRunts;		/* too short packets rec'd */
125 	u_int32_t recvInvalid;		/* invalid packets rec'd */
126 	u_int32_t recvWrongTunnel;	/* packets rec'd with wrong tunnel id */
127 	u_int32_t recvUnknownSID;	/* pkts rec'd with unknown session id */
128 	u_int32_t recvBadAcks;		/* ctrl pkts rec'd with invalid 'nr' */
129 	u_int32_t recvOutOfOrder;	/* out of order ctrl pkts rec'd */
130 	u_int32_t recvDuplicates;	/* duplicate ctrl pkts rec'd */
131 	u_int32_t recvDataDrops;	/* dup/out of order data pkts rec'd */
132 	u_int32_t recvZLBs;		/* ack-only packets rec'd */
133 	u_int32_t memoryFailures;	/* times we couldn't allocate memory */
134 };
135 
136 /* Keep this in sync with the above structure definition */
137 #define NG_L2TP_STATS_TYPE_INFO	{			\
138 	  { "xmitPackets",	&ng_parse_uint32_type	},	\
139 	  { "xmitOctets",	&ng_parse_uint32_type	},	\
140 	  { "xmitZLBs",		&ng_parse_uint32_type	},	\
141 	  { "xmitDrops",	&ng_parse_uint32_type	},	\
142 	  { "xmitTooBig",	&ng_parse_uint32_type	},	\
143 	  { "xmitInvalid",	&ng_parse_uint32_type	},	\
144 	  { "xmitDataTooBig",	&ng_parse_uint32_type	},	\
145 	  { "xmitRetransmits",	&ng_parse_uint32_type	},	\
146 	  { "recvPackets",	&ng_parse_uint32_type	},	\
147 	  { "recvOctets",	&ng_parse_uint32_type	},	\
148 	  { "recvRunts",	&ng_parse_uint32_type	},	\
149 	  { "recvInvalid",	&ng_parse_uint32_type	},	\
150 	  { "recvWrongTunnel",	&ng_parse_uint32_type	},	\
151 	  { "recvUnknownSID",	&ng_parse_uint32_type	},	\
152 	  { "recvBadAcks",	&ng_parse_uint32_type	},	\
153 	  { "recvOutOfOrder",	&ng_parse_uint32_type	},	\
154 	  { "recvDuplicates",	&ng_parse_uint32_type	},	\
155 	  { "recvDataDrops",	&ng_parse_uint32_type	},	\
156 	  { "recvZLBs",		&ng_parse_uint32_type	},	\
157 	  { "memoryFailures",	&ng_parse_uint32_type	},	\
158 	  { NULL }						\
159 }
160 
161 /* Session statistics struct. */
162 struct ng_l2tp_session_stats {
163 	u_int64_t xmitPackets;		/* number of packets xmit */
164 	u_int64_t xmitOctets;		/* number of octets xmit */
165 	u_int64_t recvPackets;		/* number of packets received */
166 	u_int64_t recvOctets;		/* number of octets received */
167 };
168 
169 /* Keep this in sync with the above structure definition. */
170 #define NG_L2TP_SESSION_STATS_TYPE_INFO	{			\
171 	  { "xmitPackets",	&ng_parse_uint64_type	},	\
172 	  { "xmitOctets",	&ng_parse_uint64_type	},	\
173 	  { "recvPackets",	&ng_parse_uint64_type	},	\
174 	  { "recvOctets",	&ng_parse_uint64_type	},	\
175 	  { NULL }						\
176 }
177 
178 /* Netgraph commands */
179 enum {
180 	NGM_L2TP_SET_CONFIG = 1,	/* supply a struct ng_l2tp_config */
181 	NGM_L2TP_GET_CONFIG,		/* returns a struct ng_l2tp_config */
182 	NGM_L2TP_SET_SESS_CONFIG,	/* supply struct ng_l2tp_sess_config */
183 	NGM_L2TP_GET_SESS_CONFIG,	/* supply a session id (u_int16_t) */
184 	NGM_L2TP_GET_STATS,		/* returns struct ng_l2tp_stats */
185 	NGM_L2TP_CLR_STATS,		/* clears stats */
186 	NGM_L2TP_GETCLR_STATS,		/* returns & clears stats */
187 	NGM_L2TP_GET_SESSION_STATS,	/* returns session stats */
188 	NGM_L2TP_CLR_SESSION_STATS,	/* clears session stats */
189 	NGM_L2TP_GETCLR_SESSION_STATS,	/* returns & clears session stats */
190 	NGM_L2TP_ACK_FAILURE,		/* sent *from* node after ack timeout */
191 	NGM_L2TP_SET_SEQ		/* supply a struct ng_l2tp_seq_config */
192 };
193 
194 #endif /* _NETGRAPH_NG_L2TP_H_ */
195