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