20ec1fe327f7894ce67ef3e12c6942ee83537172
[l2tpns.git] / l2tpns.h
1 // L2TPNS Global Stuff
2 // $Id: l2tpns.h,v 1.62 2005/04/18 04:18:15 bodea Exp $
3
4 #ifndef __L2TPNS_H__
5 #define __L2TPNS_H__
6
7 #include <netinet/in.h>
8 #include <execinfo.h>
9 #include <stdio.h>
10 #include <signal.h>
11 #include <stdlib.h>
12 #include <netinet/in.h>
13 #include <sys/socket.h>
14 #include <arpa/inet.h>
15 #include <sys/types.h>
16 #include <libcli.h>
17
18 #define VERSION "2.1.0"
19
20 // Limits
21 #define MAXTUNNEL 500 // could be up to 65535
22 #define MAXSESSION 60000 // could be up to 65535
23 #define MAXTBFS 6000 // Maximum token bucket filters. Might need up to 2 * session.
24
25 #define RADIUS_SHIFT 5
26 #define RADIUS_MASK ((unsigned short)(((unsigned short)~0) >> (16 - RADIUS_SHIFT)))
27 #define MAXRADIUS ((unsigned long)(1L << RADIUS_SHIFT) * 255)
28
29 #define T_UNDEF (0xffff) // A tunnel ID that won't ever be used. Mark session as undefined.
30 #define T_FREE (0) // A tunnel ID that won't ever be used. Mark session as free.
31
32 #define MAXCONTROL 1000 // max length control message we ever send...
33 #define MAXETHER (1500+18) // max packet we try sending to tun
34 #define MAXTEL 96 // telephone number
35 #define MAXUSER 128 // username
36 #define MAXPASS 128 // password
37 #define MAXPLUGINS 20 // maximum number of plugins to load
38 #define MAXRADSERVER 10 // max radius servers
39 #define MAXROUTE 10 // max static routes per session
40 #define MAXIPPOOL 131072 // max number of ip addresses in pool
41 #define RINGBUFFER_SIZE 10000 // Number of ringbuffer entries to allocate
42 #define MAX_LOG_LENGTH 512 // Maximum size of log message
43 #define ECHO_TIMEOUT 60 // Time between last packet sent and LCP ECHO generation
44 #define IDLE_TIMEOUT 240 // Time between last packet sent and LCP ECHO generation
45 #define BUSY_WAIT_TIME 3000 // 5 minutes in 1/10th seconds to wait for radius to cleanup on shutdown
46
47 // Constants
48 #ifndef ETCDIR
49 #define ETCDIR "/etc/l2tpns"
50 #endif
51
52 #ifndef LIBDIR
53 #define LIBDIR "/usr/lib/l2tpns"
54 #endif
55
56 #ifndef PLUGINDIR
57 #define PLUGINDIR LIBDIR // Plugins
58 #endif
59
60 #ifndef PLUGINCONF
61 #define PLUGINCONF ETCDIR // Plugin config dir
62 #endif
63
64 #ifndef FLASHDIR
65 #define FLASHDIR ETCDIR
66 #endif
67
68 #define TUNDEVICE "/dev/net/tun"
69 #define RANDOMDEVICE "/dev/urandom" // default, not as secure as /dev/random but non-blocking
70 #define CONFIGFILE FLASHDIR "/startup-config" // Configuration file
71 #define CLIUSERS FLASHDIR "/users" // CLI Users file
72 #define IPPOOLFILE FLASHDIR "/ip_pool" // Address pool configuration
73 #define ACCT_TIME 3000 // 5 minute accounting interval
74 #define ACCT_SHUT_TIME 600 // 1 minute for counters of shutdown sessions
75 #define L2TPPORT 1701 // L2TP port
76 #define RADPORT 1645 // old radius port...
77 #define PKTARP 0x0806 // ARP packet type
78 #define PKTIP 0x0800 // IPv4 packet type
79 #define PKTIPV6 0x86DD // IPv6 packet type
80 #define PPPPAP 0xC023
81 #define PPPCHAP 0xC223
82 #define PPPLCP 0xC021
83 #define PPPIPCP 0x8021
84 #define PPPIPV6CP 0x8057
85 #define PPPCCP 0x80FD
86 #define PPPIP 0x0021
87 #define PPPIPV6 0x0057
88 #define PPPMP 0x003D
89 #define MIN_IP_SIZE 0x19
90
91 enum {
92 ConfigReq = 1,
93 ConfigAck,
94 ConfigNak,
95 ConfigRej,
96 TerminateReq,
97 TerminateAck,
98 CodeRej,
99 ProtocolRej,
100 EchoReq,
101 EchoReply,
102 DiscardRequest,
103 IdentRequest
104 };
105
106 enum {
107 AccessRequest = 1,
108 AccessAccept,
109 AccessReject,
110 AccountingRequest,
111 AccountingResponse,
112 AccessChallenge = 11
113 };
114
115 // Types
116 typedef uint16_t sessionidt;
117 typedef uint16_t tunnelidt;
118 typedef uint32_t clockt;
119 typedef uint8_t hasht[16];
120
121 // CLI actions
122 struct cli_session_actions {
123 char action;
124 in_addr_t snoop_ip;
125 uint16_t snoop_port;
126 int throttle_in;
127 int throttle_out;
128 int filter_in;
129 int filter_out;
130 };
131
132 #define CLI_SESS_KILL 0x01
133 #define CLI_SESS_SNOOP 0x02
134 #define CLI_SESS_NOSNOOP 0x04
135 #define CLI_SESS_THROTTLE 0x08
136 #define CLI_SESS_NOTHROTTLE 0x10
137 #define CLI_SESS_FILTER 0x20
138 #define CLI_SESS_NOFILTER 0x40
139
140 struct cli_tunnel_actions {
141 char action;
142 };
143
144 #define CLI_TUN_KILL 0x01
145
146 // structures
147 typedef struct // route
148 {
149 in_addr_t ip;
150 in_addr_t mask;
151 }
152 routet;
153
154 typedef struct controls // control message
155 {
156 struct controls *next; // next in queue
157 uint16_t length; // length
158 uint8_t buf[MAXCONTROL];
159 }
160 controlt;
161
162 typedef struct
163 {
164 sessionidt next; // next session in linked list
165 sessionidt far; // far end session ID
166 tunnelidt tunnel; // near end tunnel ID
167 in_addr_t ip; // IP of session set by RADIUS response (host byte order).
168 int ip_pool_index; // index to IP pool
169 unsigned long unique_id; // unique session id
170 uint16_t nr; // next receive
171 uint16_t ns; // next send
172 uint32_t magic; // ppp magic number
173 uint32_t cin, cout; // byte counts
174 uint32_t pin, pout; // packet counts
175 uint32_t total_cin; // This counter is never reset while a session is open
176 uint32_t total_cout; // This counter is never reset while a session is open
177 uint32_t id; // session id
178 uint16_t throttle_in; // upstream throttle rate (kbps)
179 uint16_t throttle_out; // downstream throttle rate
180 clockt opened; // when started
181 clockt die; // being closed, when to finally free
182 time_t last_packet; // Last packet from the user (used for idle timeouts)
183 in_addr_t dns1, dns2; // DNS servers
184 routet route[MAXROUTE]; // static routes
185 uint16_t radius; // which radius session is being used (0 for not waiting on authentication)
186 uint16_t mru; // maximum receive unit
187 uint16_t tbf_in; // filter bucket for throttling in from the user.
188 uint16_t tbf_out; // filter bucket for throttling out to the user.
189 uint8_t l2tp_flags; // various bit flags from the ICCN on the l2tp tunnel.
190 uint8_t reserved_old_snoop; // No longer used - remove at some time
191 uint8_t walled_garden; // is this session gardened?
192 uint8_t flags1; // additional flags (currently unused);
193 char random_vector[MAXTEL];
194 int random_vector_length;
195 char user[MAXUSER]; // user (needed in seesion for radius stop messages)
196 char called[MAXTEL]; // called number
197 char calling[MAXTEL]; // calling number
198 uint32_t tx_connect_speed;
199 uint32_t rx_connect_speed;
200 uint32_t flags; // Various session flags.
201 in_addr_t snoop_ip; // Interception destination IP
202 uint16_t snoop_port; // Interception destination port
203 uint16_t sid; // near end session id.
204 uint8_t filter_in; // input filter index (to ip_filters[N-1]; 0 if none)
205 uint8_t filter_out; // output filter index
206 struct in6_addr ipv6route; // Static IPv6 route
207 uint8_t ipv6prefixlen; // IPv6 route prefix length
208 char reserved[1]; // Space to expand structure without changing HB_VERSION
209 }
210 sessiont;
211
212 #define SF_IPCP_ACKED 1 // Has this session seen an IPCP Ack?
213 #define SF_LCP_ACKED 2 // LCP negotiated
214 #define SF_CCP_ACKED 4 // CCP negotiated
215 #define SF_IPV6CP_ACKED 8 // IPv6 negotiated
216 #define SF_IPV6_NACKED 16 // IPv6 rejected
217 #define SF_IPV6_ROUTED 32 // advertised v6 route
218
219 #define AUTHPAP 1 // allow PAP
220 #define AUTHCHAP 2 // allow CHAP
221
222 typedef struct
223 {
224 // byte counters
225 uint32_t cin;
226 uint32_t cout;
227
228 // DoS prevention
229 clockt last_packet_out;
230 uint32_t packets_out;
231 uint32_t packets_dropped;
232 } sessionlocalt;
233
234 #define SESSIONPFC 1 // PFC negotiated flags
235 #define SESSIONACFC 2 // ACFC negotiated flags
236
237 // 168 bytes per tunnel
238 typedef struct
239 {
240 tunnelidt far; // far end tunnel ID
241 in_addr_t ip; // Ip for far end
242 uint16_t port; // port for far end
243 uint16_t window; // Rx window
244 uint16_t nr; // next receive
245 uint16_t ns; // next send
246 int state; // current state (tunnelstate enum)
247 clockt last; // when last control message sent (used for resend timeout)
248 clockt retry; // when to try resenting pending control
249 clockt die; // being closed, when to finally free
250 clockt lastrec; // when the last control message was received
251 char hostname[128]; // tunnel hostname
252 char vendor[128]; // LAC vendor
253 uint8_t try; // number of retrys on a control message
254 uint16_t controlc; // outstaind messages in queue
255 controlt *controls; // oldest message
256 controlt *controle; // newest message
257 }
258 tunnelt;
259
260 // 180 bytes per radius session
261 typedef struct // outstanding RADIUS requests
262 {
263 sessionidt session; // which session this applies to
264 hasht auth; // request authenticator
265 clockt retry; // when to try next
266 char calling[MAXTEL]; // calling number
267 char pass[129]; // password
268 uint8_t id; // ID for PPP response
269 uint8_t try; // which try we are on
270 uint8_t state; // state of radius requests
271 uint8_t chap; // set if CHAP used (is CHAP identifier)
272 }
273 radiust;
274
275 typedef struct
276 {
277 in_addr_t address; // Host byte order..
278 char assigned; // 1 if assigned, 0 if free
279 sessionidt session;
280 clockt last; // last used
281 char user[129]; // user (try to have ip addresses persistent)
282 }
283 ippoolt;
284
285 #ifdef RINGBUFFER
286 struct Tringbuffer
287 {
288 struct {
289 char level;
290 sessionidt session;
291 tunnelidt tunnel;
292 char message[MAX_LOG_LENGTH];
293 } buffer[RINGBUFFER_SIZE];
294 int head;
295 int tail;
296 };
297 #endif
298
299 /*
300 * Possible tunnel states
301 * TUNNELFREE -> TUNNELOPEN -> TUNNELDIE -> TUNNELFREE
302 */
303 enum
304 {
305 TUNNELFREE, // Not in use
306 TUNNELOPEN, // Active tunnel
307 TUNNELDIE, // Currently closing
308 TUNNELOPENING, // Busy opening
309 TUNNELUNDEF, // Undefined
310 };
311
312 enum
313 {
314 RADIUSNULL, // Not in use
315 RADIUSCHAP, // sending CHAP down PPP
316 RADIUSAUTH, // sending auth to RADIUS server
317 RADIUSIPCP, // sending IPCP to end user
318 RADIUSSTART, // sending start accounting to RADIUS server
319 RADIUSSTOP, // sending stop accounting to RADIUS server
320 RADIUSWAIT, // waiting timeout before available, in case delayed replies
321 RADIUSDEAD, // errored while talking to radius server.
322 };
323
324 struct Tstats
325 {
326 time_t start_time;
327 time_t last_reset;
328
329 uint32_t tun_rx_packets;
330 uint32_t tun_tx_packets;
331 uint32_t tun_rx_bytes;
332 uint32_t tun_tx_bytes;
333 uint32_t tun_rx_errors;
334 uint32_t tun_tx_errors;
335 uint32_t tun_rx_dropped;
336
337 uint32_t tunnel_rx_packets;
338 uint32_t tunnel_tx_packets;
339 uint32_t tunnel_rx_bytes;
340 uint32_t tunnel_tx_bytes;
341 uint32_t tunnel_rx_errors;
342 uint32_t tunnel_tx_errors;
343
344 uint32_t tunnel_retries;
345 uint32_t radius_retries;
346
347 uint32_t arp_sent;
348
349 uint32_t packets_snooped;
350
351 uint32_t tunnel_created;
352 uint32_t session_created;
353 uint32_t tunnel_timeout;
354 uint32_t session_timeout;
355 uint32_t radius_timeout;
356 uint32_t radius_overflow;
357 uint32_t tunnel_overflow;
358 uint32_t session_overflow;
359
360 uint32_t ip_allocated;
361 uint32_t ip_freed;
362
363 uint32_t c_forwarded;
364 uint32_t recv_forward;
365
366 uint32_t select_called;
367 uint32_t multi_read_used;
368 uint32_t multi_read_exceeded;
369
370 #ifdef STATISTICS
371 uint32_t call_processtun;
372 uint32_t call_processipout;
373 uint32_t call_processipv6out;
374 uint32_t call_processudp;
375 uint32_t call_sessionbyip;
376 uint32_t call_sessionbyipv6;
377 uint32_t call_sessionbyuser;
378 uint32_t call_sendarp;
379 uint32_t call_sendipcp;
380 uint32_t call_processipv6cp;
381 uint32_t call_tunnelsend;
382 uint32_t call_sessionkill;
383 uint32_t call_sessionshutdown;
384 uint32_t call_tunnelkill;
385 uint32_t call_tunnelshutdown;
386 uint32_t call_assign_ip_address;
387 uint32_t call_free_ip_address;
388 uint32_t call_dump_acct_info;
389 uint32_t call_sessionsetup;
390 uint32_t call_processpap;
391 uint32_t call_processchap;
392 uint32_t call_processlcp;
393 uint32_t call_processipcp;
394 uint32_t call_processipin;
395 uint32_t call_processipv6in;
396 uint32_t call_processccp;
397 uint32_t call_sendchap;
398 uint32_t call_processrad;
399 uint32_t call_radiussend;
400 uint32_t call_radiusretry;
401 uint32_t call_random_data;
402 #endif
403 };
404
405 #ifdef STATISTICS
406
407 #ifdef STAT_CALLS
408 #define CSTAT(x) STAT(call_ ## x)
409 #else
410 #define CSTAT(x)
411 #endif
412
413 #define STAT(x) (_statistics->x++)
414 #define INC_STAT(x,y) (_statistics->x += (y))
415 #define GET_STAT(x) (_statistics->x)
416 #define SET_STAT(x, y) (_statistics->x = (y))
417 #else
418 #define CSTAT(x)
419 #define STAT(x)
420 #define INC_STAT(x,y)
421 #define GET_STAT(x) 0
422 #define SET_STAT(x, y)
423 #endif
424
425 typedef struct
426 {
427 int debug; // debugging level
428 time_t start_time; // time when l2tpns was started
429 char bandwidth[256]; // current bandwidth
430 char pid_file[256]; // file to write PID to on startup
431 int wrote_pid;
432 clockt current_time; // 1/10ths of a second since the process started.
433 // means that we can only run a given process
434 // for 13 years without re-starting!
435
436 char config_file[128];
437 int reload_config; // flag to re-read config (set by cli)
438 int cleanup_interval; // interval between regular cleanups (in seconds)
439 int multi_read_count; // amount of packets to read per fd in processing loop
440
441 char tundevice[10]; // tun device name
442 char log_filename[128];
443 char l2tpsecret[64];
444
445 char random_device[256]; // random device path, defaults to RANDOMDEVICE
446
447 char radiussecret[64];
448 int radius_accounting;
449 in_addr_t radiusserver[MAXRADSERVER]; // radius servers
450 uint16_t radiusport[MAXRADSERVER]; // radius base ports
451 uint8_t numradiusservers; // radius server count
452 short num_radfds; // Number of radius filehandles allocated
453
454 char radius_authtypes_s[32]; // list of valid authentication types (chap, pap) in order of preference
455 int radius_authtypes;
456 int radius_authprefer;
457
458 in_addr_t default_dns1, default_dns2;
459
460 unsigned long rl_rate; // default throttle rate
461 int num_tbfs; // number of throttle buckets
462
463 char accounting_dir[128];
464 in_addr_t bind_address;
465 in_addr_t peer_address;
466 int send_garp; // Set to true to garp for vip address on startup
467
468 int target_uid;
469 int dump_speed;
470 char plugins[64][MAXPLUGINS];
471 char old_plugins[64][MAXPLUGINS];
472
473 int next_tbf; // Next HTB id available to use
474 int scheduler_fifo; // If the system has multiple CPUs, use FIFO scheduling policy for this process.
475 int lock_pages; // Lock pages into memory.
476 int icmp_rate; // Max number of ICMP unreachable per second to send
477 int max_packets; // DoS prevention: per session limit of packets/0.1s
478
479 in_addr_t cluster_address; // Multicast address of cluster.
480 // Send to this address to have everyone hear.
481 char cluster_interface[64]; // Which interface to listen for multicast on.
482 int cluster_iam_master; // Are we the cluster master???
483 int cluster_iam_uptodate; // Set if we've got a full set of state from the master.
484 in_addr_t cluster_master_address; // The network address of the cluster master.
485 // Zero if i am the cluster master.
486 int cluster_seq_number; // Sequence number of the next heartbeat we'll send out
487 // (or the seq number we're next expecting if we're a slave).
488 int cluster_undefined_sessions; // How many sessions we're yet to receive from the master.
489 int cluster_undefined_tunnels; // How many tunnels we're yet to receive from the master.
490 int cluster_highest_sessionid;
491 int cluster_highest_tunnelid;
492 clockt cluster_last_hb; // Last time we saw a heartbeat from the master.
493 int cluster_num_changes; // Number of changes queued.
494
495 int cluster_hb_interval; // How often to send a heartbeat.
496 int cluster_hb_timeout; // How many missed heartbeats trigger an election.
497 uint64_t cluster_table_version; // # state changes processed by cluster
498
499 struct in6_addr ipv6_prefix; // Our IPv6 network pool.
500
501 #ifdef BGP
502 #define BGP_NUM_PEERS 2
503 uint16_t as_number;
504 struct {
505 char name[64];
506 uint16_t as;
507 int keepalive;
508 int hold;
509 } neighbour[BGP_NUM_PEERS];
510 #endif
511 } configt;
512
513 enum config_typet { INT, STRING, UNSIGNED_LONG, SHORT, BOOL, IPv4, IPv6, MAC };
514 typedef struct
515 {
516 char *key;
517 int offset;
518 int size;
519 enum config_typet type;
520 } config_descriptt;
521
522 typedef struct
523 {
524 uint8_t op; // operation
525 #define FILTER_PORT_OP_NONE 0 // all ports match
526 #define FILTER_PORT_OP_EQ 1
527 #define FILTER_PORT_OP_NEQ 2
528 #define FILTER_PORT_OP_GT 3
529 #define FILTER_PORT_OP_LT 4
530 #define FILTER_PORT_OP_RANGE 5
531 uint16_t port; // port (host byte order)
532 uint16_t port2; // range
533 } ip_filter_portt;
534
535 typedef struct
536 {
537 int action; // permit/deny
538 #define FILTER_ACTION_DENY 1
539 #define FILTER_ACTION_PERMIT 2
540 uint8_t proto; // protocol: IPPROTO_* (netinet/in.h)
541 in_addr_t src_ip; // source ip (network byte order)
542 in_addr_t src_wild;
543 ip_filter_portt src_ports;
544 in_addr_t dst_ip; // dest ip
545 in_addr_t dst_wild;
546 ip_filter_portt dst_ports;
547 uint8_t frag; // apply to non-initial fragments
548 uint8_t tcp_flag_op; // match type: any, all, established
549 #define FILTER_FLAG_OP_ANY 1
550 #define FILTER_FLAG_OP_ALL 2
551 #define FILTER_FLAG_OP_EST 3
552 uint8_t tcp_sflags; // flags set
553 uint8_t tcp_cflags; // flags clear
554 uint32_t counter; // match count
555 } ip_filter_rulet;
556
557 #define TCP_FLAG_FIN 0x01
558 #define TCP_FLAG_SYN 0x02
559 #define TCP_FLAG_RST 0x04
560 #define TCP_FLAG_PSH 0x08
561 #define TCP_FLAG_ACK 0x10
562 #define TCP_FLAG_URG 0x20
563
564 #define MAXFILTER 32
565 #define MAXFILTER_RULES 32
566 typedef struct
567 {
568 char name[32]; // ACL name
569 int extended; // type: 0 = standard, 1 = extended
570 ip_filter_rulet rules[MAXFILTER_RULES];
571 int used; // session ref count
572 } ip_filtert;
573
574 // arp.c
575 void sendarp(int ifr_idx, const unsigned char* mac, in_addr_t ip);
576
577
578 // ppp.c
579 void processpap(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
580 void processchap(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
581 void processlcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
582 void processipcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
583 void processipv6cp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
584 void processipin(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
585 void processipv6in(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
586 void processccp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
587 void sendchap(tunnelidt t, sessionidt s);
588 uint8_t *makeppp(uint8_t *b, int size, uint8_t *p, int l, tunnelidt t, sessionidt s, uint16_t mtype);
589 void initlcp(tunnelidt t, sessionidt s);
590 void send_ipin(sessionidt s, uint8_t *buf, int len);
591
592
593 // radius.c
594 void initrad(void);
595 void radiussend(uint16_t r, uint8_t state);
596 void processrad(uint8_t *buf, int len, char socket_index);
597 void radiusretry(uint16_t r);
598 uint16_t radiusnew(sessionidt s);
599 void radiusclear(uint16_t r, sessionidt s);
600
601
602 // l2tpns.c
603 clockt backoff(uint8_t try);
604 void send_ipv6_ra(tunnelidt t, sessionidt s, struct in6_addr *ip);
605 void route6set(sessionidt s, struct in6_addr ip, int prefixlen, int add);
606 sessionidt sessionbyip(in_addr_t ip);
607 sessionidt sessionbyipv6(struct in6_addr ip);
608 sessionidt sessionbyuser(char *username);
609 void random_data(uint8_t *buf, int len);
610 void sessionkill(sessionidt s, char *reason);
611 void sessionshutdown(sessionidt s, char *reason, int result, int error);
612 void send_garp(in_addr_t ip);
613 void tunnelsend(uint8_t *buf, uint16_t l, tunnelidt t);
614 void sendipcp(tunnelidt t, sessionidt s);
615 void processudp(uint8_t *buf, int len, struct sockaddr_in *addr);
616 void snoop_send_packet(char *packet, uint16_t size, in_addr_t destination, uint16_t port);
617 int ip_filter(uint8_t *buf, int len, uint8_t filter);
618 int cmd_show_ipcache(struct cli_def *cli, char *command, char **argv, int argc);
619 int cmd_show_hist_idle(struct cli_def *cli, char *command, char **argv, int argc);
620 int cmd_show_hist_open(struct cli_def *cli, char *command, char **argv, int argc);
621
622 #undef LOG
623 #undef LOG_HEX
624 #define LOG(D, s, t, f, ...) ({ if (D <= config->debug) _log(D, s, t, f, ## __VA_ARGS__); })
625 #define LOG_HEX(D, t, d, s) ({ if (D <= config->debug) _log_hex(D, t, d, s); })
626
627 void _log(int level, sessionidt s, tunnelidt t, const char *format, ...) __attribute__((format (printf, 4, 5)));
628 void _log_hex(int level, const char *title, const char *data, int maxsize);
629
630 int sessionsetup(tunnelidt t, sessionidt s);
631 int run_plugins(int plugin_type, void *data);
632 void rebuild_address_pool(void);
633 void throttle_session(sessionidt s, int rate_in, int rate_out);
634 int load_session(sessionidt, sessiont *);
635 void become_master(void); // We're the master; kick off any required master initializations.
636
637
638 // cli.c
639 void init_cli(char *hostname);
640 void cli_do_file(FILE *fh);
641 void cli_do(int sockfd);
642 int cli_arg_help(struct cli_def *cli, int cr_ok, char *entry, ...);
643
644
645 // icmp.c
646 void host_unreachable(in_addr_t destination, uint16_t id, in_addr_t source, char *packet, int packet_len);
647
648
649 extern tunnelt *tunnel;
650 extern sessiont *session;
651 extern sessionlocalt *sess_local;
652 extern ippoolt *ip_address_pool;
653 #define sessionfree (session[0].next)
654
655 #define log_backtrace(count, max) \
656 if (count++ < max) { \
657 void *array[20]; \
658 char **strings; \
659 int size, i; \
660 LOG(0, 0, t, "Backtrace follows"); \
661 size = backtrace(array, 10); \
662 strings = backtrace_symbols(array, size); \
663 if (strings) for (i = 0; i < size; i++) \
664 { \
665 LOG(0, 0, t, "%s\n", strings[i]); \
666 } \
667 free(strings); \
668 }
669
670
671 extern configt *config;
672 extern time_t basetime; // Time when this process started.
673 extern time_t time_now; // Seconds since EPOCH.
674 extern uint32_t last_id;
675 extern struct Tstats *_statistics;
676 extern in_addr_t my_address;
677 extern int tun_write(uint8_t *data, int size);
678 extern int clifd;
679
680
681 #define TIME (config->current_time)
682
683 // macros for handling help in cli commands
684 #define CLI_HELP_REQUESTED (argc > 0 && argv[argc-1][strlen(argv[argc-1])-1] == '?')
685 #define CLI_HELP_NO_ARGS (argc > 1 || argv[0][1]) ? CLI_OK : cli_arg_help(cli, 1, NULL)
686
687 // CVS identifiers (for "show version file")
688 extern char const *cvs_id_arp;
689 extern char const *cvs_id_cli;
690 extern char const *cvs_id_cluster;
691 extern char const *cvs_id_constants;
692 extern char const *cvs_id_control;
693 extern char const *cvs_id_icmp;
694 extern char const *cvs_id_l2tpns;
695 extern char const *cvs_id_ll;
696 extern char const *cvs_id_md5;
697 extern char const *cvs_id_ppp;
698 extern char const *cvs_id_radius;
699 extern char const *cvs_id_tbf;
700 extern char const *cvs_id_util;
701
702 #endif /* __L2TPNS_H__ */