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