2 * Layer Two Tunnelling Protocol Daemon
3 * Copyright (C) 1998 Adtran, Inc.
4 * Copyright (C) 2002 Jeff McAdams
8 * This software is distributed under the terms
9 * of the GPL, which you should have received
10 * along with this source.
12 * Protocol and implementation information,
13 * structures and constants.
16 typedef unsigned short _u16;
17 typedef unsigned long long _u64;
22 #define MAXSTRLEN 120 /* Maximum length of common strings */
24 #include <netinet/in.h>
30 #include "scheduler.h"
38 #include "ipsecmast.h"
40 #define CONTROL_PIPE "/var/run/xl2tpd/l2tp-control"
42 #define BINARY "xl2tpd"
43 #define SERVER_VERSION "xl2tpd-1.2.6"
44 #define VENDOR_NAME "xelerance.com"
46 #define PPPD "/usr/sbin/pppd"
48 #define CALL_PPP_OPTS "defaultroute"
49 #define FIRMWARE_REV 0x0690 /* Revision of our firmware (software, in this case) */
51 #define HELLO_DELAY 60 /* How often to send a Hello message */
55 _u16 ver
; /* Version and more */
56 _u16 length
; /* Length field */
57 _u16 tid
; /* Tunnel ID */
58 _u16 cid
; /* Call ID */
59 _u16 Ns
; /* Next sent */
60 _u16 Nr
; /* Next received */
61 } __attribute__((packed
));
63 #define CTBIT(ver) (ver & 0x8000) /* Determins if control or not */
64 #define CLBIT(ver) (ver & 0x4000) /* Length bit present. Must be 1
65 for control messages */
67 #define CZBITS(ver) (ver &0x37F8) /* Reserved bits: We must drop
68 anything with these there */
70 #define CFBIT(ver) (ver & 0x0800) /* Presence of Ns and Nr fields
73 #define CVER(ver) (ver & 0x0007) /* Version of encapsulation */
78 _u16 ver
; /* Version and friends */
79 _u16 length
; /* Optional Length */
80 _u16 tid
; /* Tunnel ID */
81 _u16 cid
; /* Caller ID */
82 _u16 Ns
; /* Optional next sent */
83 _u16 Nr
; /* Optional next received */
84 _u16 o_size
; /* Optional offset size */
85 _u16 o_pad
; /* Optional offset padding */
86 } __attribute__((packed
));
88 #define NZL_TIMEOUT_DIVISOR 4 /* Divide TIMEOUT by this and
89 you know how often to send
92 #define PAYLOAD_BUF 10 /* Provide 10 expansion bytes
93 so we can "decompress" the
94 payloads and simplify coding */
96 #define DEFAULT_MAX_RETRIES 5 /* Recommended value from spec */
98 #define DEFAULT_MAX_RETRIES 95 /* give us more time to debug */
101 #define DEFAULT_RWS_SIZE 4 /* Default max outstanding
102 control packets in queue */
103 #define DEFAULT_TX_BPS 10000000 /* For outgoing calls, report this speed */
104 #define DEFAULT_RX_BPS 10000000
105 #define DEFAULT_MAX_BPS 10000000 /* jz: outgoing calls max bps */
106 #define DEFAULT_MIN_BPS 10000 /* jz: outgoing calls min bps */
107 #define PAYLOAD_FUDGE 2 /* How many packets we're willing to drop */
108 #define MIN_PAYLOAD_HDR_LEN 6
110 #define UDP_LISTEN_PORT 1701
111 /* FIXME: MAX_RECV_SIZE, what is it? */
112 #define MAX_RECV_SIZE 4096 /* Biggest packet we'll accept */
114 #define OUR_L2TP_VERSION 0x100 /* We support version 1, revision 0 */
116 #define PTBIT(ver) CTBIT(ver) /* Type bit: Must be zero for us */
117 #define PLBIT(ver) CLBIT(ver) /* Length specified? */
118 #define PFBIT(ver) CFBIT(ver) /* Flow control specified? */
119 #define PVER(ver) CVER(ver) /* Version */
120 #define PZBITS(ver) (ver & 0x14F8) /* Reserved bits */
121 #define PRBIT(ver) (ver & 0x2000) /* Reset Sr bit */
122 #define PSBIT(ver) (ver & 0x0200) /* Offset size bit */
123 #define PPBIT(ver) (ver & 0x0100) /* Preference bit */
127 struct call
*call_head
; /* Member calls */
128 struct tunnel
*next
; /* Allows us to be linked easily */
130 int fc
; /* Framing capabilities of peer */
131 struct schedule_entry
*hello
;
132 int ourfc
; /* Our framing capabilities */
133 int bc
; /* Peer's bearer channels */
134 int hbit
; /* Allow hidden AVP's? */
135 int ourbc
; /* Our bearer channels */
136 _u64 tb
; /* Their tie breaker */
137 _u64 ourtb
; /* Our tie breaker */
138 int tid
; /* Peer's tunnel identifier */
139 IPsecSAref_t refme
; /* IPsec SA particulars */
141 int ourtid
; /* Our tunnel identifier */
142 int qtid
; /* TID for disconnection */
143 int firmware
; /* Peer's firmware revision */
145 unsigned int addr
; /* Remote address */
146 unsigned short port
; /* Port on remote end */
148 struct sockaddr_in peer
; /* Peer's Address */
150 int debug
; /* Are we debugging or not? */
151 int nego
; /* Show Negotiation? */
152 int count
; /* How many membmer calls? */
153 int state
; /* State of tunnel */
154 _u16 control_seq_num
; /* Sequence for next packet */
155 _u16 control_rec_seq_num
; /* Next expected to receive */
156 int cLr
; /* Last packet received by peer */
157 char hostname
[MAXSTRLEN
]; /* Remote hostname */
158 char vendor
[MAXSTRLEN
]; /* Vendor of remote product */
159 struct challenge chal_us
; /* Their Challenge to us */
160 struct challenge chal_them
; /* Our challenge to them */
161 char secret
[MAXSTRLEN
]; /* Secret to use */
163 int sanity
; /* check for sanity? */
165 int rws
; /* Peer's Receive Window Size */
166 int ourrws
; /* Receive Window Size */
167 int rxspeed
; /* Receive bps */
168 int txspeed
; /* Transmit bps */
170 struct lns
*lns
; /* LNS that owns us */
171 struct lac
*lac
; /* LAC that owns us */
181 /* Values for version */
185 /* Some PPP sync<->async stuff */
186 #define fcstab ppp_crc16_table
188 #define PPP_FLAG 0x7e
189 #define PPP_ESCAPE 0x7d
190 #define PPP_TRANS 0x20
192 #define PPP_INITFCS 0xffff
193 #define PPP_GOODFCS 0xf0b8
194 #define PPP_FCS(fcs,c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
196 /* Values for Randomness sources */
204 extern struct tunnel_list tunnels
;
205 extern void tunnel_close (struct tunnel
*t
);
206 extern void network_thread ();
207 extern int init_network ();
208 extern int kernel_support
;
209 extern int server_socket
;
210 extern struct tunnel
*new_tunnel ();
211 extern struct packet_queue xmit_udp
;
212 extern void destroy_tunnel (struct tunnel
*);
213 extern struct buffer
*new_payload (struct sockaddr_in
);
214 extern void recycle_payload (struct buffer
*, struct sockaddr_in
);
215 extern void add_payload_hdr (struct tunnel
*, struct call
*, struct buffer
*);
216 extern int read_packet (struct buffer
*, int, int);
217 extern void udp_xmit (struct buffer
*buf
, struct tunnel
*t
);
218 extern void control_xmit (void *);
220 extern int switch_io
; /* jz */
221 extern int control_fd
;
222 extern int start_pppd (struct call
*c
, struct ppp_opts
*);
223 extern void magic_lac_dial (void *);
224 extern int get_entropy (unsigned char *, int);
227 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
233 * This is just some stuff to take
234 * care of kernel definitions
239 #include <linux/if_ether.h>
240 #include <linux/if_pppox.h>
241 #include <linux/if_pppol2tp.h>