This repository has been archived by the owner on May 16, 2023. It is now read-only.
forked from mohnkhan/xavl2tp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathl2tp.h
executable file
·325 lines (289 loc) · 11.4 KB
/
l2tp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
* Layer Two Tunnelling Protocol Daemon
* Copyright (C) 1998 Adtran, Inc.
* Copyright (C) 2002 Jeff McAdams
*
* Mark Spencer
*
* This software is distributed under the terms
* of the GPL, which you should have received
* along with this source.
*
* Protocol and implementation information,
* structures and constants.
*/
/*
typedef unsigned short _u16;
typedef unsigned long long _u64;
*/
#ifndef _L2TP_H
#define _L2TP_H
#define MAXSTRLEN 120 /* Maximum length of common strings */
#include <netinet/in.h>
#include <termios.h>
#include "osport.h"
#include "scheduler.h"
#include "misc.h"
#include "file.h"
#include "call.h"
#include "avp.h"
#include "control.h"
#include "aaa.h"
#include "common.h"
#include "ipsecmast.h"
//TODO: need to make a new l2tp.h for IPv6 and move erverything there.
//RY: start
#include "ipv6file.h"
#include "ipv6misc.h"
#include "ipv6call.h"
#include "ipv6avp.h"
#include "ipv6control.h"
#include "ipv6aaa.h"
//RY: end
#define CONTROL_PIPE "/var/run/xl2tpd/l2tp-control"
#define BINARY "xl2tpd"
#define SERVER_VERSION "xl2tpd-1.1.12"
#define VENDOR_NAME "xelerance.com"
#ifndef PPPD
#define PPPD "/usr/sbin/pppd"
#endif
#define CALL_PPP_OPTS "defaultroute"
#define FIRMWARE_REV 0x0690 /* Revision of our firmware (software, in this case) */
#define DEF_MAX_TUNNELS 32 /* By default only allow this many
tunnels to exist */
#define HELLO_DELAY 30//60, //RY: originally 60 /* How often to send a Hello message */
struct control_hdr
{
_u16 ver; /* Version and more */
_u16 length; /* Length field */
_u16 tid; /* Tunnel ID */
_u16 cid; /* Call ID */
_u16 Ns; /* Next sent */
_u16 Nr; /* Next received */
} __attribute__((packed));
#define CTBIT(ver) (ver & 0x8000) /* Determins if control or not */
#define CLBIT(ver) (ver & 0x4000) /* Length bit present. Must be 1
for control messages */
#define CZBITS(ver) (ver &0x37F8) /* Reserved bits: We must drop
anything with these there */
#define CFBIT(ver) (ver & 0x0800) /* Presence of Ns and Nr fields
flow bit? */
#define CVER(ver) (ver & 0x0007) /* Version of encapsulation */
struct payload_hdr
{
_u16 ver; /* Version and friends */
_u16 length; /* Optional Length */
_u16 tid; /* Tunnel ID */
_u16 cid; /* Caller ID */
_u16 Ns; /* Optional next sent */
_u16 Nr; /* Optional next received */
_u16 o_size; /* Optional offset size */
_u16 o_pad; /* Optional offset padding */
} __attribute__((packed));
#define NZL_TIMEOUT_DIVISOR 4 /* Divide TIMEOUT by this and
you know how often to send
a zero byte packet */
#define PAYLOAD_BUF 10 /* Provide 10 expansion bytes
so we can "decompress" the
payloads and simplify coding */
#if 1
#define DEFAULT_MAX_RETRIES 20 //correct value is 5 from spec mohnkhan /* Recommended value from spec is 5*/
#else
#define DEFAULT_MAX_RETRIES 95 /* give us more time to debug */
#endif
#define DEFAULT_RWS_SIZE 4 /* Default max outstanding
control packets in queue */
#define DEFAULT_TX_BPS 10000000 /* For outgoing calls, report this speed */
#define DEFAULT_RX_BPS 10000000
#define DEFAULT_MAX_BPS 10000000 /* jz: outgoing calls max bps */
#define DEFAULT_MIN_BPS 10000 /* jz: outgoing calls min bps */
#define PAYLOAD_FUDGE 2 /* How many packets we're willing to drop */
#define MIN_PAYLOAD_HDR_LEN 6
#define UDP_LISTEN_PORT 1701
/* FIXME: MAX_RECV_SIZE, what is it? */
#define MAX_RECV_SIZE 4096 /* Biggest packet we'll accept *///TODO: need to check if enlargement is required?
#define OUR_L2TP_VERSION 0x100 /* We support version 1, revision 0 */
#define PTBIT(ver) CTBIT(ver) /* Type bit: Must be zero for us */
#define PLBIT(ver) CLBIT(ver) /* Length specified? */
#define PFBIT(ver) CFBIT(ver) /* Flow control specified? */
#define PVER(ver) CVER(ver) /* Version */
#define PZBITS(ver) (ver & 0x14F8) /* Reserved bits */
#define PRBIT(ver) (ver & 0x2000) /* Reset Sr bit */
#define PSBIT(ver) (ver & 0x0200) /* Offset size bit */
#define PPBIT(ver) (ver & 0x0100) /* Preference bit */
//RY: starts here
struct tunnel6
{
struct call6 *call_head; /* Member calls */
struct tunnel6 *next; /* Allows us to be linked easily */
int fc; /* Framing capabilities of peer */
struct schedule_entry *hello6;
int ourfc; /* Our framing capabilities */
int bc; /* Peer's bearer channels */
int hbit; /* Allow hidden AVP's? */
int ourbc; /* Our bearer channels */
_u64 tb; /* Their tie breaker */
_u64 ourtb; /* Our tie breaker */
int tid; /* Peer's tunnel identifier */
IPsecSAref_t refme; /* IPsec SA particulars */
IPsecSAref_t refhim;
int ourtid; /* Our tunnel identifier */
int qtid; /* TID for disconnection */
int firmware; /* Peer's firmware revision */
#if 0
unsigned int addr; /* Remote address */
unsigned short port; /* Port on remote end */
#else
struct sockaddr_in6 peer; /* Peer's Address */
#endif
int debug; /* Are we debugging or not? */
int nego; /* Show Negotiation? */
int count; /* How many membmer calls? */
int state; /* State of tunnel */
_u16 control_seq_num; /* Sequence for next packet */
_u16 control_rec_seq_num; /* Next expected to receive */
int cLr; /* Last packet received by peer */
char hostname[MAXSTRLEN]; /* Remote hostname */
char vendor[MAXSTRLEN]; /* Vendor of remote product */
struct challenge chal_us; /* Their Challenge to us */
struct challenge chal_them; /* Our challenge to them */
char secret[MAXSTRLEN]; /* Secret to use */
#ifdef SANITY
int sanity; /* check for sanity? */
#endif
int rws; /* Peer's Receive Window Size */
int ourrws; /* Receive Window Size */
struct call6 *self;
struct lns6 *lns; /* LNS that owns us */
struct lac6 *lac; /* LAC that owns us */
};
//RY: ends here
struct tunnel
{
struct call *call_head; /* Member calls */
struct tunnel *next; /* Allows us to be linked easily */
int fc; /* Framing capabilities of peer */
struct schedule_entry *hello;
int ourfc; /* Our framing capabilities */
int bc; /* Peer's bearer channels */
int hbit; /* Allow hidden AVP's? */
int ourbc; /* Our bearer channels */
_u64 tb; /* Their tie breaker */
_u64 ourtb; /* Our tie breaker */
int tid; /* Peer's tunnel identifier */
IPsecSAref_t refme; /* IPsec SA particulars */
IPsecSAref_t refhim;
int ourtid; /* Our tunnel identifier */
int qtid; /* TID for disconnection */
int firmware; /* Peer's firmware revision */
#if 0
unsigned int addr; /* Remote address */
unsigned short port; /* Port on remote end */
#else
struct sockaddr_in peer; /* Peer's Address */
#endif
int debug; /* Are we debugging or not? */
int nego; /* Show Negotiation? */
int count; /* How many membmer calls? */
int state; /* State of tunnel */
_u16 control_seq_num; /* Sequence for next packet */
_u16 control_rec_seq_num; /* Next expected to receive */
int cLr; /* Last packet received by peer */
char hostname[MAXSTRLEN]; /* Remote hostname */
char vendor[MAXSTRLEN]; /* Vendor of remote product */
struct challenge chal_us; /* Their Challenge to us */
struct challenge chal_them; /* Our challenge to them */
char secret[MAXSTRLEN]; /* Secret to use */
#ifdef SANITY
int sanity; /* check for sanity? */
#endif
int rws; /* Peer's Receive Window Size */
int ourrws; /* Receive Window Size */
struct call *self;
struct lns *lns; /* LNS that owns us */
struct lac *lac; /* LAC that owns us */
};
struct tunnel_list
{
struct tunnel *head;
int count;
int calls;
};
//RY: start here
struct tunnel_list6
{
struct tunnel6 *head;
int count;
int calls;
};
//RY: end here
/* Values for version */
#define VER_L2TP 2
#define VER_PPTP 3
/* Some PPP sync<->async stuff */
#define fcstab ppp_crc16_table
#define PPP_FLAG 0x7e
#define PPP_ESCAPE 0x7d
#define PPP_TRANS 0x20
#define PPP_INITFCS 0xffff
#define PPP_GOODFCS 0xf0b8
#define PPP_FCS(fcs,c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
/* Values for Randomness sources */
#define RAND_DEV 0x0
#define RAND_SYS 0x1
#define RAND_EGD 0x2
/* Error Values */
//RY: start
extern struct tunnel_list6 tunnels6;
extern void tunnel_close6 (struct tunnel6 *t);
extern struct tunnel6 *new_tunnel6 ();
extern void destroy_tunnel6 (struct tunnel6 *);
extern struct buffer6 *new_payload6 (struct sockaddr_in6);
extern void recycle_payload6 (struct buffer6 *, struct sockaddr_in6);
extern void add_payload_hdr6 (struct tunnel6 *, struct call6 *, struct buffer6 *);
extern int read_packet6 (struct buffer6 *, int, int);
extern void udp_xmit6 (struct buffer6 *buf, struct tunnel6 *t);
extern int start_pppd6 (struct call6 *c, struct ppp_opts *);
extern void magic_lac_dial6 (void *);
extern void null_handler(int sig);
//RY: end here
extern struct tunnel_list tunnels;
extern void tunnel_close (struct tunnel *t);
extern void network_thread ();
extern int init_network ();
extern int max_tunnels;
extern int kernel_support;
extern int server_socket;
//RY: start
extern int server_socket6;
extern char *dial_no_tmp; /* jz: Dialnumber for Outgoing Call */
//RY: end
extern struct tunnel *new_tunnel ();
extern struct packet_queue xmit_udp;
extern void destroy_tunnel (struct tunnel *);
extern struct buffer *new_payload (struct sockaddr_in);
extern void recycle_payload (struct buffer *, struct sockaddr_in);
extern void add_payload_hdr (struct tunnel *, struct call *, struct buffer *);
extern int read_packet (struct buffer *, int, int);
extern void udp_xmit (struct buffer *buf, struct tunnel *t);
extern void control_xmit (void *);
extern int ppd;
extern int switch_io; /* jz */
extern int control_fd;
extern int start_pppd (struct call *c, struct ppp_opts *);
extern void magic_lac_dial (void *);
extern int get_entropy (unsigned char *, int);
#ifndef MIN
#define MIN(a,b) (((a)<(b)) ? (a) : (b))
#endif
#endif
/*
* This is just some stuff to take
* care of kernel definitions
*/
#ifdef USE_KERNEL
#include <net/if.h>
#include <linux/if_ether.h>
#include <linux/if_pppox.h>
#include <linux/if_pppol2tp.h>
#endif