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"
39 #include <net/route.h>
41 #define CONTROL_PIPE "/var/run/l2tp-control"
42 #define CONTROL_PIPE_MESSAGE_SIZE 1024
44 #define BINARY "xl2tpd"
45 #define SERVER_VERSION "xl2tpd-1.3.0"
46 #define VENDOR_NAME "xelerance.com"
48 #define PPPD "/usr/sbin/pppd"
50 #define CALL_PPP_OPTS "defaultroute"
51 #define FIRMWARE_REV 0x0690 /* Revision of our firmware (software, in this case) */
53 #define HELLO_DELAY 60 /* How often to send a Hello message */
57 _u16 ver
; /* Version and more */
58 _u16 length
; /* Length field */
59 _u16 tid
; /* Tunnel ID */
60 _u16 cid
; /* Call ID */
61 _u16 Ns
; /* Next sent */
62 _u16 Nr
; /* Next received */
63 } __attribute__((packed
));
65 #define CTBIT(ver) (ver & 0x8000) /* Determins if control or not */
66 #define CLBIT(ver) (ver & 0x4000) /* Length bit present. Must be 1
67 for control messages */
69 #define CZBITS(ver) (ver &0x37F8) /* Reserved bits: We must drop
70 anything with these there */
72 #define CFBIT(ver) (ver & 0x0800) /* Presence of Ns and Nr fields
75 #define CVER(ver) (ver & 0x0007) /* Version of encapsulation */
80 _u16 ver
; /* Version and friends */
81 _u16 length
; /* Optional Length */
82 _u16 tid
; /* Tunnel ID */
83 _u16 cid
; /* Caller ID */
84 _u16 Ns
; /* Optional next sent */
85 _u16 Nr
; /* Optional next received */
86 _u16 o_size
; /* Optional offset size */
87 // _u16 o_pad; /* Optional offset padding */
88 } __attribute__((packed
));
90 #define NZL_TIMEOUT_DIVISOR 4 /* Divide TIMEOUT by this and
91 you know how often to send
94 #define PAYLOAD_BUF 10 /* Provide 10 expansion bytes
95 so we can "decompress" the
96 payloads and simplify coding */
98 #define DEFAULT_MAX_RETRIES 5 /* Recommended value from spec */
100 #define DEFAULT_MAX_RETRIES 95 /* give us more time to debug */
103 #define DEFAULT_RWS_SIZE 4 /* Default max outstanding
104 control packets in queue */
105 #define DEFAULT_TX_BPS 10000000 /* For outgoing calls, report this speed */
106 #define DEFAULT_RX_BPS 10000000
107 #define DEFAULT_MAX_BPS 10000000 /* jz: outgoing calls max bps */
108 #define DEFAULT_MIN_BPS 10000 /* jz: outgoing calls min bps */
109 #define PAYLOAD_FUDGE 2 /* How many packets we're willing to drop */
110 #define MIN_PAYLOAD_HDR_LEN 6
112 #define UDP_LISTEN_PORT 1701
113 /* FIXME: MAX_RECV_SIZE, what is it? */
114 #define MAX_RECV_SIZE 4096 /* Biggest packet we'll accept */
116 #define OUR_L2TP_VERSION 0x100 /* We support version 1, revision 0 */
118 #define PTBIT(ver) CTBIT(ver) /* Type bit: Must be zero for us */
119 #define PLBIT(ver) CLBIT(ver) /* Length specified? */
120 #define PFBIT(ver) CFBIT(ver) /* Flow control specified? */
121 #define PVER(ver) CVER(ver) /* Version */
122 #define PZBITS(ver) (ver & 0x14F8) /* Reserved bits */
123 #define PRBIT(ver) (ver & 0x2000) /* Reset Sr bit */
124 #define PSBIT(ver) (ver & 0x0200) /* Offset size bit */
125 #define PPBIT(ver) (ver & 0x0100) /* Preference bit */
129 struct call
*call_head
; /* Member calls */
130 struct tunnel
*next
; /* Allows us to be linked easily */
132 int fc
; /* Framing capabilities of peer */
133 struct schedule_entry
*hello
;
134 int ourfc
; /* Our framing capabilities */
135 int bc
; /* Peer's bearer channels */
136 int hbit
; /* Allow hidden AVP's? */
137 int ourbc
; /* Our bearer channels */
138 _u64 tb
; /* Their tie breaker */
139 _u64 ourtb
; /* Our tie breaker */
140 int tid
; /* Peer's tunnel identifier */
141 IPsecSAref_t refme
; /* IPsec SA particulars */
143 int ourtid
; /* Our tunnel identifier */
144 int qtid
; /* TID for disconnection */
145 int firmware
; /* Peer's firmware revision */
147 unsigned int addr
; /* Remote address */
148 unsigned short port
; /* Port on remote end */
150 struct sockaddr_in peer
; /* Peer's Address */
152 int debug
; /* Are we debugging or not? */
153 int nego
; /* Show Negotiation? */
154 int count
; /* How many membmer calls? */
155 int state
; /* State of tunnel */
156 _u16 control_seq_num
; /* Sequence for next packet */
157 _u16 control_rec_seq_num
; /* Next expected to receive */
158 int cLr
; /* Last packet received by peer */
159 char hostname
[MAXSTRLEN
]; /* Remote hostname */
160 char vendor
[MAXSTRLEN
]; /* Vendor of remote product */
161 struct challenge chal_us
; /* Their Challenge to us */
162 struct challenge chal_them
; /* Our challenge to them */
163 char secret
[MAXSTRLEN
]; /* Secret to use */
165 int sanity
; /* check for sanity? */
167 int rws
; /* Peer's Receive Window Size */
168 int ourrws
; /* Receive Window Size */
169 int rxspeed
; /* Receive bps */
170 int txspeed
; /* Transmit bps */
172 struct lns
*lns
; /* LNS that owns us */
173 struct lac
*lac
; /* LAC that owns us */
174 struct rtentry rt
; /* Route added to destination */
184 /* Values for version */
188 /* Some PPP sync<->async stuff */
189 #define fcstab ppp_crc16_table
191 #define PPP_FLAG 0x7e
192 #define PPP_ESCAPE 0x7d
193 #define PPP_TRANS 0x20
195 #define PPP_INITFCS 0xffff
196 #define PPP_GOODFCS 0xf0b8
197 #define PPP_FCS(fcs,c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
199 /* Values for Randomness sources */
207 extern struct tunnel_list tunnels
;
208 extern void tunnel_close (struct tunnel
*t
);
209 extern void network_thread ();
210 extern int init_network ();
211 extern int kernel_support
;
212 extern int server_socket
;
213 extern struct tunnel
*new_tunnel ();
214 extern struct packet_queue xmit_udp
;
215 extern void destroy_tunnel (struct tunnel
*);
216 extern struct buffer
*new_payload (struct sockaddr_in
);
217 extern void recycle_payload (struct buffer
*, struct sockaddr_in
);
218 extern void add_payload_hdr (struct tunnel
*, struct call
*, struct buffer
*);
219 extern int read_packet (struct buffer
*, int, int);
220 extern void udp_xmit (struct buffer
*buf
, struct tunnel
*t
);
221 extern void control_xmit (void *);
223 extern int switch_io
; /* jz */
224 extern int control_fd
;
225 extern int start_pppd (struct call
*c
, struct ppp_opts
*);
226 extern void magic_lac_dial (void *);
227 extern int get_entropy (unsigned char *, int);
230 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
234 /* Route manipulation */
235 #define sin_addr(s) (((struct sockaddr_in *)(s))->sin_addr)
236 extern int route_add(const struct in_addr inetaddr
, struct rtentry
*rt
);
237 extern int route_del(struct rtentry
*rt
);
240 * This is just some stuff to take
241 * care of kernel definitions
246 #include <linux/if_ether.h>
247 #include <linux/if_pppox.h>
248 #include <linux/if_pppol2tp.h>