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