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