minidlna support now Samsung TV C550/C650 (thx amir909)
[tomato.git] / release / src / router / xl2tpd / l2tp.h
blob6b6d28b90a7313b89a51e821d548f8a319dc8839
1 /*
2 * Layer Two Tunnelling Protocol Daemon
3 * Copyright (C) 1998 Adtran, Inc.
4 * Copyright (C) 2002 Jeff McAdams
6 * Mark Spencer
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;
19 #ifndef _L2TP_H
20 #define _L2TP_H
22 #define MAXSTRLEN 120 /* Maximum length of common strings */
24 #include <netinet/in.h>
25 #include <termios.h>
26 #ifdef OPENBSD
27 # include <util.h>
28 #endif
29 #include "osport.h"
30 #include "scheduler.h"
31 #include "misc.h"
32 #include "file.h"
33 #include "call.h"
34 #include "avp.h"
35 #include "control.h"
36 #include "aaa.h"
37 #include "common.h"
38 #include "ipsecmast.h"
39 #include <net/route.h>
41 #define CONTROL_PIPE "/var/run/l2tp-control"
43 #define BINARY "xl2tpd"
44 #define SERVER_VERSION "xl2tpd-1.2.8"
45 #define VENDOR_NAME "xelerance.com"
46 #ifndef PPPD
47 #define PPPD "/usr/sbin/pppd"
48 #endif
49 #define CALL_PPP_OPTS "defaultroute"
50 #define FIRMWARE_REV 0x0690 /* Revision of our firmware (software, in this case) */
52 #define HELLO_DELAY 60 /* How often to send a Hello message */
54 struct control_hdr
56 _u16 ver; /* Version and more */
57 _u16 length; /* Length field */
58 _u16 tid; /* Tunnel ID */
59 _u16 cid; /* Call ID */
60 _u16 Ns; /* Next sent */
61 _u16 Nr; /* Next received */
62 } __attribute__((packed));
64 #define CTBIT(ver) (ver & 0x8000) /* Determins if control or not */
65 #define CLBIT(ver) (ver & 0x4000) /* Length bit present. Must be 1
66 for control messages */
68 #define CZBITS(ver) (ver &0x37F8) /* Reserved bits: We must drop
69 anything with these there */
71 #define CFBIT(ver) (ver & 0x0800) /* Presence of Ns and Nr fields
72 flow bit? */
74 #define CVER(ver) (ver & 0x0007) /* Version of encapsulation */
77 struct payload_hdr
79 _u16 ver; /* Version and friends */
80 _u16 length; /* Optional Length */
81 _u16 tid; /* Tunnel ID */
82 _u16 cid; /* Caller ID */
83 _u16 Ns; /* Optional next sent */
84 _u16 Nr; /* Optional next received */
85 _u16 o_size; /* Optional offset size */
86 _u16 o_pad; /* Optional offset padding */
87 } __attribute__((packed));
89 #define NZL_TIMEOUT_DIVISOR 4 /* Divide TIMEOUT by this and
90 you know how often to send
91 a zero byte packet */
93 #define PAYLOAD_BUF 10 /* Provide 10 expansion bytes
94 so we can "decompress" the
95 payloads and simplify coding */
96 #if 1
97 #define DEFAULT_MAX_RETRIES 5 /* Recommended value from spec */
98 #else
99 #define DEFAULT_MAX_RETRIES 95 /* give us more time to debug */
100 #endif
102 #define DEFAULT_RWS_SIZE 4 /* Default max outstanding
103 control packets in queue */
104 #define DEFAULT_TX_BPS 10000000 /* For outgoing calls, report this speed */
105 #define DEFAULT_RX_BPS 10000000
106 #define DEFAULT_MAX_BPS 10000000 /* jz: outgoing calls max bps */
107 #define DEFAULT_MIN_BPS 10000 /* jz: outgoing calls min bps */
108 #define PAYLOAD_FUDGE 2 /* How many packets we're willing to drop */
109 #define MIN_PAYLOAD_HDR_LEN 6
111 #define UDP_LISTEN_PORT 1701
112 /* FIXME: MAX_RECV_SIZE, what is it? */
113 #define MAX_RECV_SIZE 4096 /* Biggest packet we'll accept */
115 #define OUR_L2TP_VERSION 0x100 /* We support version 1, revision 0 */
117 #define PTBIT(ver) CTBIT(ver) /* Type bit: Must be zero for us */
118 #define PLBIT(ver) CLBIT(ver) /* Length specified? */
119 #define PFBIT(ver) CFBIT(ver) /* Flow control specified? */
120 #define PVER(ver) CVER(ver) /* Version */
121 #define PZBITS(ver) (ver & 0x14F8) /* Reserved bits */
122 #define PRBIT(ver) (ver & 0x2000) /* Reset Sr bit */
123 #define PSBIT(ver) (ver & 0x0200) /* Offset size bit */
124 #define PPBIT(ver) (ver & 0x0100) /* Preference bit */
126 struct tunnel
128 struct call *call_head; /* Member calls */
129 struct tunnel *next; /* Allows us to be linked easily */
131 int fc; /* Framing capabilities of peer */
132 struct schedule_entry *hello;
133 int ourfc; /* Our framing capabilities */
134 int bc; /* Peer's bearer channels */
135 int hbit; /* Allow hidden AVP's? */
136 int ourbc; /* Our bearer channels */
137 _u64 tb; /* Their tie breaker */
138 _u64 ourtb; /* Our tie breaker */
139 int tid; /* Peer's tunnel identifier */
140 IPsecSAref_t refme; /* IPsec SA particulars */
141 IPsecSAref_t refhim;
142 int ourtid; /* Our tunnel identifier */
143 int qtid; /* TID for disconnection */
144 int firmware; /* Peer's firmware revision */
145 #if 0
146 unsigned int addr; /* Remote address */
147 unsigned short port; /* Port on remote end */
148 #else
149 struct sockaddr_in peer; /* Peer's Address */
150 #endif
151 int debug; /* Are we debugging or not? */
152 int nego; /* Show Negotiation? */
153 int count; /* How many membmer calls? */
154 int state; /* State of tunnel */
155 _u16 control_seq_num; /* Sequence for next packet */
156 _u16 control_rec_seq_num; /* Next expected to receive */
157 int cLr; /* Last packet received by peer */
158 char hostname[MAXSTRLEN]; /* Remote hostname */
159 char vendor[MAXSTRLEN]; /* Vendor of remote product */
160 struct challenge chal_us; /* Their Challenge to us */
161 struct challenge chal_them; /* Our challenge to them */
162 char secret[MAXSTRLEN]; /* Secret to use */
163 #ifdef SANITY
164 int sanity; /* check for sanity? */
165 #endif
166 int rws; /* Peer's Receive Window Size */
167 int ourrws; /* Receive Window Size */
168 int rxspeed; /* Receive bps */
169 int txspeed; /* Transmit bps */
170 struct call *self;
171 struct lns *lns; /* LNS that owns us */
172 struct lac *lac; /* LAC that owns us */
173 struct rtentry rt; /* Route added to destination */
176 struct tunnel_list
178 struct tunnel *head;
179 int count;
180 int calls;
183 /* Values for version */
184 #define VER_L2TP 2
185 #define VER_PPTP 3
187 /* Some PPP sync<->async stuff */
188 #define fcstab ppp_crc16_table
190 #define PPP_FLAG 0x7e
191 #define PPP_ESCAPE 0x7d
192 #define PPP_TRANS 0x20
194 #define PPP_INITFCS 0xffff
195 #define PPP_GOODFCS 0xf0b8
196 #define PPP_FCS(fcs,c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff])
198 /* Values for Randomness sources */
199 #define RAND_DEV 0x0
200 #define RAND_SYS 0x1
201 #define RAND_EGD 0x2
204 /* Error Values */
206 extern struct tunnel_list tunnels;
207 extern void tunnel_close (struct tunnel *t);
208 extern void network_thread ();
209 extern int init_network ();
210 extern int kernel_support;
211 extern int server_socket;
212 extern struct tunnel *new_tunnel ();
213 extern struct packet_queue xmit_udp;
214 extern void destroy_tunnel (struct tunnel *);
215 extern struct buffer *new_payload (struct sockaddr_in);
216 extern void recycle_payload (struct buffer *, struct sockaddr_in);
217 extern void add_payload_hdr (struct tunnel *, struct call *, struct buffer *);
218 extern int read_packet (struct buffer *, int, int);
219 extern void udp_xmit (struct buffer *buf, struct tunnel *t);
220 extern void control_xmit (void *);
221 extern int ppd;
222 extern int switch_io; /* jz */
223 extern int control_fd;
224 extern int start_pppd (struct call *c, struct ppp_opts *);
225 extern void magic_lac_dial (void *);
226 extern int get_entropy (unsigned char *, int);
228 #ifndef MIN
229 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
230 #endif
231 #endif
233 /* Route manipulation */
234 #define sin_addr(s) (((struct sockaddr_in *)(s))->sin_addr)
235 extern int route_add(const struct in_addr inetaddr, struct rtentry *rt);
236 extern int route_del(struct rtentry *rt);
239 * This is just some stuff to take
240 * care of kernel definitions
243 #ifdef USE_KERNEL
244 #include <net/if.h>
245 #include <linux/if_ether.h>
246 #include <linux/if_pppox.h>
247 #include <linux/if_pppol2tp.h>
248 #endif