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