e2ef57a181ba9fd3b71c6765c826f92c20dc8e8c
1 // L2TPNS Command Line Interface
2 // $Id: cli.c,v 1.1 2003/12/16 07:07:39 fred_nerk Exp $
12 #include <arpa/inet.h>
14 #include <sys/socket.h>
15 #include <sys/types.h>
25 extern tunnelt
*tunnel
;
26 extern sessiont
*session
;
27 extern radiust
*radius
;
28 extern ippoolt
*ip_address_pool
;
29 extern struct Tstats
*_statistics
;
31 struct cli_def
*cli
= NULL
;
33 extern int clifd
, udpfd
, tapfd
, snoopfd
, radfd
, ifrfd
, cluster_sockfd
;
34 extern sessionidt
*cli_session_kill
;
35 extern tunnelidt
*cli_tunnel_kill
;
36 extern tbft
*filter_buckets
;
38 extern struct Tringbuffer
*ringbuffer
;
41 char *rcs_id
= "$Id: cli.c,v 1.1 2003/12/16 07:07:39 fred_nerk Exp $";
43 char *debug_levels
[] = {
66 int cmd_show_session(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
67 int cmd_show_tunnels(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
68 int cmd_show_users(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
69 int cmd_show_counters(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
70 int cmd_show_version(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
71 int cmd_show_pool(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
72 int cmd_show_banana(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
73 int cmd_clear_counters(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
74 int cmd_drop_user(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
75 int cmd_drop_tunnel(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
76 int cmd_drop_session(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
77 int cmd_snoop(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
78 int cmd_no_snoop(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
79 int cmd_throttle(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
80 int cmd_no_throttle(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
81 int cmd_debug(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
82 int cmd_no_debug(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
83 int cmd_watch_session(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
84 int cmd_watch_tunnel(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
);
85 int regular_stuff(struct cli_def
*cli
, FILE *w
);
91 struct cli_command
*c
;
93 struct sockaddr_in addr
;
97 c
= cli_register_command(cli
, NULL
, "show", NULL
, NULL
);
98 cli_register_command(cli
, c
, "session", cmd_show_session
, "Show a list of sessions");
99 cli_register_command(cli
, c
, "tunnels", cmd_show_tunnels
, NULL
);
100 cli_register_command(cli
, c
, "users", cmd_show_users
, NULL
);
101 cli_register_command(cli
, c
, "version", cmd_show_version
, NULL
);
102 cli_register_command(cli
, c
, "banana", cmd_show_banana
, "Show a banana");
103 cli_register_command(cli
, c
, "pool", cmd_show_pool
, NULL
);
106 cli_register_command(cli
, c
, "counters", cmd_show_counters
, NULL
);
108 c
= cli_register_command(cli
, NULL
, "clear", NULL
, NULL
);
109 cli_register_command(cli
, c
, "counters", cmd_clear_counters
, NULL
);
112 cli_register_command(cli
, NULL
, "snoop", cmd_snoop
, NULL
);
113 cli_register_command(cli
, NULL
, "throttle", cmd_throttle
, NULL
);
115 c
= cli_register_command(cli
, NULL
, "no", NULL
, NULL
);
116 cli_register_command(cli
, c
, "snoop", cmd_no_snoop
, NULL
);
117 cli_register_command(cli
, c
, "throttle", cmd_no_throttle
, NULL
);
118 cli_register_command(cli
, c
, "debug", cmd_no_debug
, NULL
);
120 c
= cli_register_command(cli
, NULL
, "drop", NULL
, NULL
);
121 cli_register_command(cli
, c
, "user", cmd_drop_user
, NULL
);
122 cli_register_command(cli
, c
, "tunnel", cmd_drop_tunnel
, NULL
);
123 cli_register_command(cli
, c
, "session", cmd_drop_session
, NULL
);
125 cli_register_command(cli
, NULL
, "debug", cmd_debug
, "Specify a debugging level");
127 c
= cli_register_command(cli
, NULL
, "watch", NULL
, NULL
);
128 cli_register_command(cli
, c
, "session", cmd_watch_session
, "Dump logs for a tunnel");
129 cli_register_command(cli
, c
, "tunnel", cmd_watch_tunnel
, "Dump logs for a tunnel");
131 // Enable regular processing
132 cli_regular(cli
, regular_stuff
);
134 if (!(f
= fopen(CLIUSERS
, "r")))
136 log(0, 0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
140 while (fgets(buf
, 4096, f
))
143 if (*buf
== '#') continue;
144 if ((p
= strchr(buf
, '\r'))) *p
= 0;
145 if ((p
= strchr(buf
, '\n'))) *p
= 0;
147 if (!(p
= strchr((char *)buf
, ':'))) continue;
149 cli_allow_user(cli
, buf
, p
);
150 log(3, 0, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
155 memset(&addr
, 0, sizeof(addr
));
156 clifd
= socket(PF_INET
, SOCK_STREAM
, 6);
157 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
160 // Set cli fd as non-blocking
161 flags
= fcntl(clifd
, F_GETFL
, 0);
162 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
164 addr
.sin_family
= AF_INET
;
165 addr
.sin_port
= htons(23);
166 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
168 log(0, 0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
174 void cli_do(int sockfd
)
176 if ((cli_pid
= fork())) return;
179 if (udpfd
) close(udpfd
); udpfd
= 0;
180 if (tapfd
) close(tapfd
); tapfd
= 0;
181 if (snoopfd
) close(snoopfd
); snoopfd
= 0;
182 if (radfd
) close(radfd
); radfd
= 0;
183 if (ifrfd
) close(ifrfd
); ifrfd
= 0;
184 if (cluster_sockfd
) close(cluster_sockfd
); cluster_sockfd
= 0;
185 if (clifd
) close(clifd
); clifd
= 0;
187 signal(SIGPIPE
, SIG_DFL
);
188 signal(SIGCHLD
, SIG_DFL
);
189 signal(SIGHUP
, SIG_DFL
);
190 signal(SIGUSR1
, SIG_DFL
);
191 signal(SIGQUIT
, SIG_DFL
);
192 signal(SIGKILL
, SIG_DFL
);
193 signal(SIGALRM
, SIG_DFL
);
195 log(3, 0, 0, 0, "Accepted connection to CLI\n");
200 debug_rb_tail
= ringbuffer
->tail
;
202 memset(&debug_flags
, 0, sizeof(debug_flags
));
203 debug_flags
.critical
= 1;
205 cli_loop(cli
, sockfd
, "l2tpns> ");
208 log(3, 0, 0, 0, "Closed CLI connection\n");
212 int cmd_show_session(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
220 // Show individual session
221 for (i
= 0; i
< argc
; i
++)
225 if (!s
|| s
> MAXSESSION
)
227 fprintf(w
, "Invalid session id \"%s\"\r\n", argv
[i
]);
230 fprintf(w
, "\r\nSession %d:\r\n", s
);
231 fprintf(w
, " User: %s\r\n", session
[s
].user
[0] ? session
[s
].user
: "none");
232 fprintf(w
, " Calling Num: %s\r\n", session
[s
].calling
);
233 fprintf(w
, " Called Num: %s\r\n", session
[s
].called
);
234 fprintf(w
, " Tunnel ID: %d\r\n", session
[s
].tunnel
);
235 fprintf(w
, " IP address: %s\r\n", inet_toa(htonl(session
[s
].ip
)));
236 fprintf(w
, " HSD sid: %lu\r\n", session
[s
].sid
);
237 fprintf(w
, " Idle time: %u seconds\r\n", abs(time_now
- session
[s
].last_packet
));
238 fprintf(w
, " Next Recv: %u\r\n", session
[s
].nr
);
239 fprintf(w
, " Next Send: %u\r\n", session
[s
].ns
);
240 fprintf(w
, " Bytes In/Out: %lu/%lu\r\n", (unsigned long)session
[s
].cin
, (unsigned long)session
[s
].cout
);
241 fprintf(w
, " Pkts In/Out: %lu/%lu\r\n", (unsigned long)session
[s
].pin
, (unsigned long)session
[s
].pout
);
242 fprintf(w
, " Radius Session: %u\r\n", session
[s
].radius
);
243 fprintf(w
, " Rx Speed: %lu\r\n", session
[s
].rx_connect_speed
);
244 fprintf(w
, " Tx Speed: %lu\r\n", session
[s
].tx_connect_speed
);
245 fprintf(w
, " Intercepted: %s\r\n", session
[s
].snoop
? "YES" : "no");
246 fprintf(w
, " Throttled: %s\r\n", session
[s
].throttle
? "YES" : "no");
247 fprintf(w
, " Walled Garden: %s\r\n", session
[s
].walled_garden
? "YES" : "no");
248 fprintf(w
, " Filter Bucket: %s\r\n", session
[s
].tbf
? filter_buckets
[session
[s
].tbf
].handle
: "none");
254 fprintf(w
, " %s %4s %-32s %-15s %s %s %s %10s %10s %10s %4s %-15s %s\r\n",
268 for (i
= 0; i
< MAXSESSION
; i
++)
270 char *userip
, *tunnelip
;
271 if (!session
[i
].opened
) continue;
272 userip
= strdup(inet_toa(htonl(session
[i
].ip
)));
273 tunnelip
= strdup(inet_toa(htonl(tunnel
[ session
[i
].tunnel
].ip
)));
274 fprintf(w
, "%5d %4d %-32s %-15s %s %s %s %10lu %10lu %10lu %4u %-15s %s\r\n",
277 session
[i
].user
[0] ? session
[i
].user
: "*",
279 (session
[i
].snoop
) ? "Y" : "N",
280 (session
[i
].throttle
) ? "Y" : "N",
281 (session
[i
].walled_garden
) ? "Y" : "N",
282 (unsigned long)session
[i
].opened
,
283 (unsigned long)session
[i
].cout
,
284 (unsigned long)session
[i
].cin
,
285 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
287 session
[i
].calling
[0] ? session
[i
].calling
: "*");
288 if (userip
) free(userip
);
289 if (tunnelip
) free(tunnelip
);
294 int cmd_show_tunnels(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
302 // Show individual tunnel
303 for (i
= 0; i
< argc
; i
++)
308 if (!t
|| t
> MAXTUNNEL
)
310 fprintf(w
, "Invalid tunnel id \"%s\"\r\n", argv
[i
]);
313 fprintf(w
, "\r\nTunnel %d:\r\n", t
);
314 fprintf(w
, " Hostname: %s\r\n", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
315 fprintf(w
, " Remote IP: %s\r\n", inet_toa(htonl(tunnel
[t
].ip
)));
316 fprintf(w
, " Remote Port: %d\r\n", tunnel
[t
].port
);
317 fprintf(w
, " Rx Window: %u\r\n", tunnel
[t
].window
);
318 fprintf(w
, " Next Recv: %u\r\n", tunnel
[t
].nr
);
319 fprintf(w
, " Next Send: %u\r\n", tunnel
[t
].ns
);
320 fprintf(w
, " Queue Len: %u\r\n", tunnel
[t
].controlc
);
321 fprintf(w
, " Last Packet Age:%u\r\n", (unsigned)(time_now
- tunnel
[t
].last
));
323 for (x
= 0; x
< MAXSESSION
; x
++)
324 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
325 sprintf(s
, "%s%u ", s
, x
);
326 fprintf(w
, " Sessions: %s\r\n", s
);
331 // Show tunnel summary
332 fprintf(w
, "%s %s %s %s\r\n",
337 for (i
= 0; i
< MAXTUNNEL
; i
++)
340 if (!tunnel
[i
].ip
|| tunnel
[i
].die
|| !tunnel
[i
].hostname
[0]) continue;
342 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
343 fprintf(w
, "%d %s %s %d\r\n",
346 inet_toa(htonl(tunnel
[i
].ip
)),
352 int cmd_show_users(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
355 for (i
= 0; i
< MAXSESSION
; i
++)
357 if (!session
[i
].opened
) continue;
358 if (!session
[i
].user
[0]) continue;
365 int cmd_show_counters(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
367 fprintf(w
, "%-10s %-8s %-10s %-8s\r\n", "Ethernet", "Bytes", "Packets", "Errors");
368 fprintf(w
, "%-10s %8lu %8lu %8lu\r\n", "RX",
369 GET_STAT(tap_rx_bytes
),
370 GET_STAT(tap_rx_packets
),
371 GET_STAT(tap_rx_errors
));
372 fprintf(w
, "%-10s %8lu %8lu %8lu\r\n", "TX",
373 GET_STAT(tap_tx_bytes
),
374 GET_STAT(tap_tx_packets
),
375 GET_STAT(tap_tx_errors
));
378 fprintf(w
, "%-10s %-8s %-10s %-8s %-8s\r\n", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
379 fprintf(w
, "%-10s %8lu %8lu %8lu %8lu\r\n", "RX",
380 GET_STAT(tunnel_rx_bytes
),
381 GET_STAT(tunnel_rx_packets
),
382 GET_STAT(tunnel_rx_errors
),
384 fprintf(w
, "%-10s %8lu %8lu %8lu %8lu\r\n", "TX",
385 GET_STAT(tunnel_tx_bytes
),
386 GET_STAT(tunnel_tx_packets
),
387 GET_STAT(tunnel_rx_errors
),
388 GET_STAT(tunnel_retries
));
391 fprintf(w
, "%-30s%-10s\r\n", "Counter", "Value");
392 fprintf(w
, "-----------------------------------------\r\n");
393 fprintf(w
, "%-30s%lu\r\n", "radius_retries", GET_STAT(radius_retries
));
394 fprintf(w
, "%-30s%lu\r\n", "arp_errors", GET_STAT(arp_errors
));
395 fprintf(w
, "%-30s%lu\r\n", "arp_replies", GET_STAT(arp_replies
));
396 fprintf(w
, "%-30s%lu\r\n", "arp_discarded", GET_STAT(arp_discarded
));
397 fprintf(w
, "%-30s%lu\r\n", "arp_sent", GET_STAT(arp_sent
));
398 fprintf(w
, "%-30s%lu\r\n", "arp_recv", GET_STAT(arp_recv
));
399 fprintf(w
, "%-30s%lu\r\n", "packets_snooped", GET_STAT(packets_snooped
));
400 fprintf(w
, "%-30s%lu\r\n", "tunnel_created", GET_STAT(tunnel_created
));
401 fprintf(w
, "%-30s%lu\r\n", "session_created", GET_STAT(session_created
));
402 fprintf(w
, "%-30s%lu\r\n", "tunnel_timeout", GET_STAT(tunnel_timeout
));
403 fprintf(w
, "%-30s%lu\r\n", "session_timeout", GET_STAT(session_timeout
));
404 fprintf(w
, "%-30s%lu\r\n", "radius_timeout", GET_STAT(radius_timeout
));
405 fprintf(w
, "%-30s%lu\r\n", "radius_overflow", GET_STAT(radius_overflow
));
406 fprintf(w
, "%-30s%lu\r\n", "tunnel_overflow", GET_STAT(tunnel_overflow
));
407 fprintf(w
, "%-30s%lu\r\n", "session_overflow", GET_STAT(session_overflow
));
408 fprintf(w
, "%-30s%lu\r\n", "ip_allocated", GET_STAT(ip_allocated
));
409 fprintf(w
, "%-30s%lu\r\n", "ip_freed", GET_STAT(ip_freed
));
412 fprintf(w
, "\n%-30s%-10s\r\n", "Counter", "Value");
413 fprintf(w
, "-----------------------------------------\r\n");
414 fprintf(w
, "%-30s%lu\r\n", "call_processtap", GET_STAT(call_processtap
));
415 fprintf(w
, "%-30s%lu\r\n", "call_processarp", GET_STAT(call_processarp
));
416 fprintf(w
, "%-30s%lu\r\n", "call_processipout", GET_STAT(call_processipout
));
417 fprintf(w
, "%-30s%lu\r\n", "call_processudp", GET_STAT(call_processudp
));
418 fprintf(w
, "%-30s%lu\r\n", "call_processpap", GET_STAT(call_processpap
));
419 fprintf(w
, "%-30s%lu\r\n", "call_processchap", GET_STAT(call_processchap
));
420 fprintf(w
, "%-30s%lu\r\n", "call_processlcp", GET_STAT(call_processlcp
));
421 fprintf(w
, "%-30s%lu\r\n", "call_processipcp", GET_STAT(call_processipcp
));
422 fprintf(w
, "%-30s%lu\r\n", "call_processipin", GET_STAT(call_processipin
));
423 fprintf(w
, "%-30s%lu\r\n", "call_processccp", GET_STAT(call_processccp
));
424 fprintf(w
, "%-30s%lu\r\n", "call_processrad", GET_STAT(call_processrad
));
425 fprintf(w
, "%-30s%lu\r\n", "call_sendarp", GET_STAT(call_sendarp
));
426 fprintf(w
, "%-30s%lu\r\n", "call_sendipcp", GET_STAT(call_sendipcp
));
427 fprintf(w
, "%-30s%lu\r\n", "call_sendchap", GET_STAT(call_sendchap
));
428 fprintf(w
, "%-30s%lu\r\n", "call_sessionbyip", GET_STAT(call_sessionbyip
));
429 fprintf(w
, "%-30s%lu\r\n", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
430 fprintf(w
, "%-30s%lu\r\n", "call_tunnelsend", GET_STAT(call_tunnelsend
));
431 fprintf(w
, "%-30s%lu\r\n", "call_tunnelkill", GET_STAT(call_tunnelkill
));
432 fprintf(w
, "%-30s%lu\r\n", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
433 fprintf(w
, "%-30s%lu\r\n", "call_sessionkill", GET_STAT(call_sessionkill
));
434 fprintf(w
, "%-30s%lu\r\n", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
435 fprintf(w
, "%-30s%lu\r\n", "call_sessionsetup", GET_STAT(call_sessionsetup
));
436 fprintf(w
, "%-30s%lu\r\n", "call_assign_ip_address",GET_STAT(call_assign_ip_address
));
437 fprintf(w
, "%-30s%lu\r\n", "call_free_ip_address", GET_STAT(call_free_ip_address
));
438 fprintf(w
, "%-30s%lu\r\n", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
439 fprintf(w
, "%-30s%lu\r\n", "call_radiussend", GET_STAT(call_radiussend
));
440 fprintf(w
, "%-30s%lu\r\n", "call_radiusretry", GET_STAT(call_radiusretry
));
445 int cmd_show_version(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
447 fprintf(w
, "L2TPNS %s\r\n", VERSION
);
448 fprintf(w
, "ID: %s\r\n", rcs_id
);
451 int cmd_show_pool(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
454 int used
= 0, free
= 0;
456 fprintf(w
, "%-15s %4s %8s %s\r\n", "IP Address", "Used", "Session", "User");
457 for (i
= 0; i
< MAXIPPOOL
; i
++)
461 if (!ip_address_pool
[i
].address
) continue;
462 if (ip_address_pool
[i
].assigned
)
465 s
= sessionbyip(ip_address_pool
[i
].address
);
472 fprintf(w
, "%-15s %4s %8d %s\r\n",
473 inet_toa(ip_address_pool
[i
].address
),
478 fprintf(w
, "\r\nFree: %d\r\nUsed: %d\r\n", free
, used
);
481 int cmd_show_banana(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
489 " ( \\ `. `-. _,.-:\\\r\n"
490 " \\ \\ `. `-._ __..--' ,-';/\r\n"
491 " \\ `. `-. `-..___..---' _.--' ,'/\r\n"
492 " `. `. `-._ __..--' ,' /\r\n"
493 " `. `-_ ``--..'' _.-' ,'\r\n"
494 " `-_ `-.___ __,--' ,'\r\n"
495 " `-.__ `----\"\"\" __.-'\r\n"
496 "hh `--..____..--'\r\n", w
);
501 int cmd_clear_counters(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
503 fprintf(w
, "Counters cleared\r\n");
504 SET_STAT(last_reset
, time(NULL
));
508 int cmd_drop_user(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
515 fprintf(w
, "Specify a user to drop\r\n");
518 for (i
= 0; i
< argc
; i
++)
520 if (strchr(argv
[i
], '?'))
522 fprintf(w
, "username ...");
527 for (i
= 0; i
< argc
; i
++)
529 if (!(s
= sessionbyuser(argv
[i
])))
531 fprintf(w
, "User %s is not connected\r\n", argv
[i
]);
535 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
539 fprintf(w
, "Dropping user %s\r\n", session
[s
].user
);
540 for (x
= 0; x
< MAXSESSION
; x
++)
542 if (!cli_session_kill
[x
])
544 cli_session_kill
[x
] = s
;
554 int cmd_drop_tunnel(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
561 fprintf(w
, "Specify a tunnel to drop\r\n");
564 for (i
= 0; i
< argc
; i
++)
566 if (strchr(argv
[i
], '?'))
568 fprintf(w
, "tunnel_id ...");
573 for (i
= 0; i
< argc
; i
++)
577 if ((tid
= atol(argv
[i
])) <= 0 || (tid
> MAXTUNNEL
))
579 fprintf(w
, "Invalid tunnel ID (%d - %d)\r\n", 0, MAXTUNNEL
);
585 fprintf(w
, "Tunnel %d is not connected\r\n", tid
);
591 fprintf(w
, "Tunnel %d is already being shut down\r\n", tid
);
595 for (x
= 0; x
< MAXTUNNEL
; x
++)
597 if (!cli_tunnel_kill
[x
])
599 cli_tunnel_kill
[x
] = tid
;
600 fprintf(w
, "Tunnel %d shut down (%s)\r\n", tid
, tunnel
[tid
].hostname
);
609 int cmd_drop_session(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
616 fprintf(w
, "Specify a session id to drop\r\n");
619 for (i
= 0; i
< argc
; i
++)
621 if (strchr(argv
[i
], '?'))
623 fprintf(w
, "session_id ...");
628 for (i
= 0; i
< argc
; i
++)
630 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
632 fprintf(w
, "Invalid session ID (%d - %d)\r\n", 0, MAXSESSION
);
636 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
639 for (x
= 0; x
< MAXSESSION
; x
++)
641 if (!cli_session_kill
[x
])
643 cli_session_kill
[x
] = s
;
647 fprintf(w
, "Dropping session %d\r\n", s
);
651 fprintf(w
, "Session %d is not active.\r\n", s
);
658 int cmd_snoop(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
665 fprintf(w
, "Specify a user\r\n");
668 for (i
= 0; i
< argc
; i
++)
670 if (strchr(argv
[i
], '?'))
672 fprintf(w
, "username ...");
677 for (i
= 0; i
< argc
; i
++)
679 if (!(s
= sessionbyuser(argv
[i
])))
681 fprintf(w
, "User %s is not connected\r\n", argv
[i
]);
684 session
[s
].snoop
= 1;
686 fprintf(w
, "Snooping user %s\r\n", argv
[i
]);
691 int cmd_no_snoop(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
698 fprintf(w
, "Specify a user\r\n");
701 for (i
= 0; i
< argc
; i
++)
703 if (strchr(argv
[i
], '?'))
705 fprintf(w
, "username ...");
710 for (i
= 0; i
< argc
; i
++)
712 if (!(s
= sessionbyuser(argv
[i
])))
714 fprintf(w
, "User %s is not connected\r\n", argv
[i
]);
717 session
[s
].snoop
= 0;
719 fprintf(w
, "Not snooping user %s\r\n", argv
[i
]);
724 int cmd_throttle(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
731 fprintf(w
, "Specify a user\r\n");
734 for (i
= 0; i
< argc
; i
++)
736 if (strchr(argv
[i
], '?'))
738 fprintf(w
, "username ...");
743 for (i
= 0; i
< argc
; i
++)
745 if (!(s
= sessionbyuser(argv
[i
])))
747 fprintf(w
, "User %s is not connected\r\n", argv
[i
]);
750 throttle_session(s
, 1);
752 fprintf(w
, "throttling user %s\r\n", argv
[i
]);
757 int cmd_no_throttle(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
764 fprintf(w
, "Specify a user\r\n");
767 for (i
= 0; i
< argc
; i
++)
769 if (strchr(argv
[i
], '?'))
771 fprintf(w
, "username ...");
776 for (i
= 0; i
< argc
; i
++)
778 if (!(s
= sessionbyuser(argv
[i
])))
780 fprintf(w
, "User %s is not connected\r\n", argv
[i
]);
783 throttle_session(s
, 0);
785 fprintf(w
, "unthrottling user %s\r\n", argv
[i
]);
790 int cmd_debug(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
796 fprintf(w
, "Currently debugging: ");
797 if (debug_flags
.critical
) fprintf(w
, "critical ");
798 if (debug_flags
.error
) fprintf(w
, "error ");
799 if (debug_flags
.warning
) fprintf(w
, "warning ");
800 if (debug_flags
.info
) fprintf(w
, "info ");
801 if (debug_flags
.calls
) fprintf(w
, "calls ");
802 if (debug_flags
.data
) fprintf(w
, "data ");
807 for (i
= 0; i
< argc
; i
++)
811 fprintf(w
, "Possible debugging states are:\r\n");
812 fprintf(w
, " critical\r\n");
813 fprintf(w
, " error\r\n");
814 fprintf(w
, " warning\r\n");
815 fprintf(w
, " info\r\n");
816 fprintf(w
, " calls\r\n");
817 fprintf(w
, " data\r\n");
822 for (i
= 0; i
< argc
; i
++)
824 if (strcasecmp(argv
[i
], "critical") == 0) debug_flags
.critical
= 1;
825 if (strcasecmp(argv
[i
], "error") == 0) debug_flags
.error
= 1;
826 if (strcasecmp(argv
[i
], "warning") == 0) debug_flags
.warning
= 1;
827 if (strcasecmp(argv
[i
], "info") == 0) debug_flags
.info
= 1;
828 if (strcasecmp(argv
[i
], "calls") == 0) debug_flags
.calls
= 1;
829 if (strcasecmp(argv
[i
], "data") == 0) debug_flags
.data
= 1;
830 if (strcasecmp(argv
[i
], "all") == 0)
832 memset(&debug_flags
, 1, sizeof(debug_flags
));
833 debug_flags
.data
= 0;
840 int cmd_no_debug(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
844 for (i
= 0; i
< argc
; i
++)
846 if (strcasecmp(argv
[i
], "critical") == 0) debug_flags
.critical
= 0;
847 if (strcasecmp(argv
[i
], "error") == 0) debug_flags
.error
= 0;
848 if (strcasecmp(argv
[i
], "warning") == 0) debug_flags
.warning
= 0;
849 if (strcasecmp(argv
[i
], "info") == 0) debug_flags
.info
= 0;
850 if (strcasecmp(argv
[i
], "calls") == 0) debug_flags
.calls
= 0;
851 if (strcasecmp(argv
[i
], "data") == 0) debug_flags
.data
= 0;
852 if (strcasecmp(argv
[i
], "all") == 0) memset(&debug_flags
, 0, sizeof(debug_flags
));
858 int cmd_watch_session(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
864 fprintf(w
, "Specify a single session to debug (0 to disable)\r\n");
870 fprintf(w
, "No longer debugging session %d\r\n", debug_session
);
872 if (s
) fprintf(w
, "Debugging session %d.\r\n", s
);
878 int cmd_watch_tunnel(struct cli_def
*cli
, FILE *w
, char *command
, char **argv
, int argc
)
884 fprintf(w
, "Specify a single tunnel to debug (0 to disable)\r\n");
890 fprintf(w
, "No longer debugging tunnel %d\r\n", debug_tunnel
);
892 if (s
) fprintf(w
, "Debugging tunnel %d.\r\n", s
);
898 int regular_stuff(struct cli_def
*cli
, FILE *w
)
900 int i
= debug_rb_tail
;
903 while (i
!= ringbuffer
->tail
)
905 int show_message
= 0;
907 if (*ringbuffer
->buffer
[i
].message
)
909 // Always show messages if we are doing general debug
910 if (ringbuffer
->buffer
[i
].level
== 0 && debug_flags
.critical
) show_message
= 1;
911 if (ringbuffer
->buffer
[i
].level
== 1 && debug_flags
.error
) show_message
= 1;
912 if (ringbuffer
->buffer
[i
].level
== 2 && debug_flags
.warning
) show_message
= 1;
913 if (ringbuffer
->buffer
[i
].level
== 3 && debug_flags
.info
) show_message
= 1;
914 if (ringbuffer
->buffer
[i
].level
== 4 && debug_flags
.calls
) show_message
= 1;
915 if (ringbuffer
->buffer
[i
].level
== 5 && debug_flags
.data
) show_message
= 1;
920 ipt address
= ntohl(ringbuffer
->buffer
[i
].address
);
924 memcpy(&addr
, &address
, sizeof(ringbuffer
->buffer
[i
].address
));
925 ipaddr
= inet_ntoa(addr
);
927 fprintf(w
, "%s-%s-%u-%u %s\r",
928 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
930 ringbuffer
->buffer
[i
].tunnel
,
931 ringbuffer
->buffer
[i
].session
,
932 ringbuffer
->buffer
[i
].message
);
935 if (++i
== ringbuffer
->tail
) break;
936 if (i
== RINGBUFFER_SIZE
) i
= 0;
939 debug_rb_tail
= ringbuffer
->tail
;