1 // L2TPNS Command Line Interface
4 char const *cvs_name
= "$Name: $";
5 char const *cvs_id_cli
= "$Id: cli.c,v 1.76 2006/12/18 12:08:28 bodea Exp $";
19 #include <arpa/inet.h>
21 #include <sys/socket.h>
22 #include <sys/types.h>
29 #include "constants.h"
38 extern tunnelt
*tunnel
;
39 extern bundlet
*bundle
;
40 extern sessiont
*session
;
41 extern radiust
*radius
;
42 extern ippoolt
*ip_address_pool
;
43 extern struct Tstats
*_statistics
;
44 static struct cli_def
*cli
= NULL
;
45 extern configt
*config
;
46 extern config_descriptt config_values
[];
48 extern struct Tringbuffer
*ringbuffer
;
50 extern struct cli_session_actions
*cli_session_actions
;
51 extern struct cli_tunnel_actions
*cli_tunnel_actions
;
52 extern tbft
*filter_list
;
53 extern ip_filtert
*ip_filters
;
67 static int debug_rb_tail
;
68 static char *debug_levels
[] = {
79 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
80 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
81 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
82 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
83 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
84 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
85 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
86 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
87 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
88 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
89 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
90 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
91 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
92 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
93 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
94 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
95 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
96 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
97 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
98 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
99 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
100 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
101 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
102 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
103 static int cmd_shutdown(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
104 static int cmd_reload(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
107 static int regular_stuff(struct cli_def
*cli
);
110 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
111 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
112 #endif /* STATISTICS */
115 #define MODE_CONFIG_BGP 8
116 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
117 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
118 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
119 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
120 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
121 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
122 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
125 #define MODE_CONFIG_NACL 9
126 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
127 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
128 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
129 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
130 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
131 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
133 /* match if b is a substr of a */
134 #define MATCH(a,b) (!strncmp((a), (b), strlen(b)))
136 void init_cli(char *hostname
)
140 struct cli_command
*c
;
141 struct cli_command
*c2
;
143 struct sockaddr_in addr
;
146 if (hostname
&& *hostname
)
147 cli_set_hostname(cli
, hostname
);
149 cli_set_hostname(cli
, "l2tpns");
151 c
= cli_register_command(cli
, NULL
, "show", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
152 cli_register_command(cli
, c
, "banana", cmd_show_banana
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a banana");
154 cli_register_command(cli
, c
, "bgp", cmd_show_bgp
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show BGP status");
156 cli_register_command(cli
, c
, "cluster", cmd_show_cluster
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show cluster information");
157 cli_register_command(cli
, c
, "ipcache", cmd_show_ipcache
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show contents of the IP cache");
158 cli_register_command(cli
, c
, "plugins", cmd_show_plugins
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all installed plugins");
159 cli_register_command(cli
, c
, "pool", cmd_show_pool
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the IP address allocation pool");
160 cli_register_command(cli
, c
, "radius", cmd_show_radius
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show active radius queries");
161 cli_register_command(cli
, c
, "running-config", cmd_show_run
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Show the currently running configuration");
162 cli_register_command(cli
, c
, "session", cmd_show_session
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of sessions or details for a single session");
163 cli_register_command(cli
, c
, "tbf", cmd_show_tbf
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all token bucket filters in use");
164 cli_register_command(cli
, c
, "throttle", cmd_show_throttle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all throttled sessions and associated TBFs");
165 cli_register_command(cli
, c
, "tunnels", cmd_show_tunnels
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of tunnels or details for a single tunnel");
166 cli_register_command(cli
, c
, "users", cmd_show_users
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of all connected users or details of selected user");
167 cli_register_command(cli
, c
, "version", cmd_show_version
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show currently running software version");
168 cli_register_command(cli
, c
, "access-list", cmd_show_access_list
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show named access-list");
170 c2
= cli_register_command(cli
, c
, "histogram", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
171 cli_register_command(cli
, c2
, "idle", cmd_show_hist_idle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session idle times");
172 cli_register_command(cli
, c2
, "open", cmd_show_hist_open
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session durations");
175 cli_register_command(cli
, c
, "counters", cmd_show_counters
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Display all the internal counters and running totals");
177 c
= cli_register_command(cli
, NULL
, "clear", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
178 cli_register_command(cli
, c
, "counters", cmd_clear_counters
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Clear internal counters");
181 cli_register_command(cli
, NULL
, "uptime", cmd_uptime
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show uptime and bandwidth utilisation");
182 cli_register_command(cli
, NULL
, "shutdown", cmd_shutdown
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Shutdown l2tpns daemon and exit");
183 cli_register_command(cli
, NULL
, "reload", cmd_reload
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Reload configuration");
185 c
= cli_register_command(cli
, NULL
, "write", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
186 cli_register_command(cli
, c
, "memory", cmd_write_memory
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Save the running config to flash");
187 cli_register_command(cli
, c
, "terminal", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the running config");
189 cli_register_command(cli
, NULL
, "snoop", cmd_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable interception of a session");
190 cli_register_command(cli
, NULL
, "throttle", cmd_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable throttling of a session");
191 cli_register_command(cli
, NULL
, "filter", cmd_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Add filtering to a session");
192 cli_register_command(cli
, NULL
, "debug", cmd_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Set the level of logging that is shown on the console");
195 c
= cli_register_command(cli
, NULL
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
196 cli_register_command(cli
, c
, "bgp", cmd_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Withdraw routes from BGP neighbour");
199 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
200 cli_register_command(cli
, c
, "snoop", cmd_no_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable interception of a session");
201 cli_register_command(cli
, c
, "throttle", cmd_no_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable throttling of a session");
202 cli_register_command(cli
, c
, "filter", cmd_no_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Remove filtering from a session");
203 cli_register_command(cli
, c
, "debug", cmd_no_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Turn off logging of a certain level of debugging");
206 c2
= cli_register_command(cli
, c
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
207 cli_register_command(cli
, c2
, "bgp", cmd_no_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Advertise routes to BGP neighbour");
209 c
= cli_register_command(cli
, NULL
, "restart", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
210 cli_register_command(cli
, c
, "bgp", cmd_restart_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Restart BGP");
212 c
= cli_register_command(cli
, NULL
, "router", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
213 cli_register_command(cli
, c
, "bgp", cmd_router_bgp
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Configure BGP");
215 cli_register_command(cli
, NULL
, "neighbour", cmd_router_bgp_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Configure BGP neighbour");
217 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, NULL
);
218 cli_register_command(cli
, c
, "neighbour", cmd_router_bgp_no_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Remove BGP neighbour");
221 c
= cli_register_command(cli
, NULL
, "drop", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
222 cli_register_command(cli
, c
, "user", cmd_drop_user
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a user");
223 cli_register_command(cli
, c
, "tunnel", cmd_drop_tunnel
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a tunnel and all sessions on that tunnel");
224 cli_register_command(cli
, c
, "session", cmd_drop_session
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a session");
226 c
= cli_register_command(cli
, NULL
, "load", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
227 cli_register_command(cli
, c
, "plugin", cmd_load_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Load a plugin");
229 c
= cli_register_command(cli
, NULL
, "remove", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
230 cli_register_command(cli
, c
, "plugin", cmd_remove_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove a plugin");
232 cli_register_command(cli
, NULL
, "set", cmd_set
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set a configuration variable");
234 c
= cli_register_command(cli
, NULL
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
235 cli_register_command(cli
, c
, "access-list", cmd_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Add named access-list");
237 cli_register_command(cli
, NULL
, "permit", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Permit rule");
238 cli_register_command(cli
, NULL
, "deny", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Deny rule");
240 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_CONFIG
, NULL
);
241 c2
= cli_register_command(cli
, c
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
242 cli_register_command(cli
, c2
, "access-list", cmd_no_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove named access-list");
244 // Enable regular processing
245 cli_regular(cli
, regular_stuff
);
247 if (!(f
= fopen(CLIUSERS
, "r")))
249 LOG(0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
253 while (fgets(buf
, 4096, f
))
256 if (*buf
== '#') continue;
257 if ((p
= strchr(buf
, '\r'))) *p
= 0;
258 if ((p
= strchr(buf
, '\n'))) *p
= 0;
260 if (!(p
= strchr((char *)buf
, ':'))) continue;
262 if (!strcmp(buf
, "enable"))
264 cli_allow_enable(cli
, p
);
265 LOG(3, 0, 0, "Setting enable password\n");
269 cli_allow_user(cli
, buf
, p
);
270 LOG(3, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
276 memset(&addr
, 0, sizeof(addr
));
277 clifd
= socket(PF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
278 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
281 // Set cli fd as non-blocking
282 flags
= fcntl(clifd
, F_GETFL
, 0);
283 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
285 addr
.sin_family
= AF_INET
;
286 addr
.sin_port
= htons(23);
287 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
289 LOG(0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
295 void cli_do(int sockfd
)
297 int require_auth
= 1;
298 struct sockaddr_in addr
;
299 socklen_t l
= sizeof(addr
);
301 if (fork_and_close()) return;
302 if (getpeername(sockfd
, (struct sockaddr
*) &addr
, &l
) == 0)
304 require_auth
= addr
.sin_addr
.s_addr
!= inet_addr("127.0.0.1");
305 LOG(require_auth
? 3 : 4, 0, 0, "Accepted connection to CLI from %s\n",
306 fmtaddr(addr
.sin_addr
.s_addr
, 0));
309 LOG(0, 0, 0, "getpeername() failed on cli socket. Requiring authentication: %s\n", strerror(errno
));
313 LOG(3, 0, 0, "CLI is remote, requiring authentication\n");
314 if (!cli
->users
) /* paranoia */
316 LOG(0, 0, 0, "No users for remote authentication! Exiting CLI\n");
322 /* no username/pass required */
327 debug_rb_tail
= ringbuffer
->tail
;
329 memset(&debug_flags
, 0, sizeof(debug_flags
));
330 debug_flags
.critical
= 1;
332 cli_loop(cli
, sockfd
);
335 LOG(require_auth
? 3 : 4, 0, 0, "Closed CLI connection from %s\n",
336 fmtaddr(addr
.sin_addr
.s_addr
, 0));
341 static void cli_print_log(struct cli_def
*cli
, char *string
)
343 LOG(3, 0, 0, "%s\n", string
);
346 void cli_do_file(FILE *fh
)
348 LOG(3, 0, 0, "Reading configuration file\n");
349 cli_print_callback(cli
, cli_print_log
);
350 cli_file(cli
, fh
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
);
351 cli_print_callback(cli
, NULL
);
354 int cli_arg_help(struct cli_def
*cli
, int cr_ok
, char *entry
, ...)
365 if ((p
= strchr(entry
, '%')) && !strchr(p
+1, '%') && p
[1] == 'd')
367 int v
= va_arg(ap
, int);
368 snprintf(buf
, sizeof(buf
), entry
, v
);
374 desc
= va_arg(ap
, char *);
376 cli_error(cli
, " %-20s %s", p
, desc
);
378 cli_error(cli
, " %s", p
);
380 entry
= desc
? va_arg(ap
, char *) : 0;
385 cli_error(cli
, " <cr>");
390 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
394 if (CLI_HELP_REQUESTED
)
395 return cli_arg_help(cli
, 1,
396 "<1-%d>", MAXSESSION
-1, "Show specific session by id",
402 // Show individual session
403 for (i
= 0; i
< argc
; i
++)
405 unsigned int s
, b_in
, b_out
;
407 if (s
<= 0 || s
>= MAXSESSION
)
409 cli_print(cli
, "Invalid session id \"%s\"", argv
[i
]);
412 cli_print(cli
, "\r\nSession %d:", s
);
413 cli_print(cli
, "\tUser:\t\t%s", session
[s
].user
[0] ? session
[s
].user
: "none");
414 cli_print(cli
, "\tCalling Num:\t%s", session
[s
].calling
);
415 cli_print(cli
, "\tCalled Num:\t%s", session
[s
].called
);
416 cli_print(cli
, "\tTunnel ID:\t%d", session
[s
].tunnel
);
417 cli_print(cli
, "\tPPP Phase:\t%s", ppp_phase(session
[s
].ppp
.phase
));
418 switch (session
[s
].ppp
.phase
)
421 cli_print(cli
, "\t LCP state:\t%s", ppp_state(session
[s
].ppp
.lcp
));
426 cli_print(cli
, "\t IPCP state:\t%s", ppp_state(session
[s
].ppp
.ipcp
));
427 cli_print(cli
, "\t IPV6CP state:\t%s", ppp_state(session
[s
].ppp
.ipv6cp
));
428 cli_print(cli
, "\t CCP state:\t%s", ppp_state(session
[s
].ppp
.ccp
));
430 cli_print(cli
, "\tIP address:\t%s", fmtaddr(htonl(session
[s
].ip
), 0));
431 cli_print(cli
, "\tUnique SID:\t%u", session
[s
].unique_id
);
432 cli_print(cli
, "\tOpened:\t\t%u seconds", session
[s
].opened
? abs(time_now
- session
[s
].opened
) : 0);
433 cli_print(cli
, "\tIdle time:\t%u seconds", session
[s
].last_packet
? abs(time_now
- session
[s
].last_packet
) : 0);
434 if (session
[s
].session_timeout
)
436 clockt opened
= session
[s
].opened
;
437 if (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
438 opened
= bundle
[session
[s
].bundle
].online_time
;
440 cli_print(cli
, "\tSess Timeout:\t%u seconds", session
[s
].session_timeout
- (opened
? abs(time_now
- opened
) : 0));
443 if (session
[s
].idle_timeout
)
444 cli_print(cli
, "\tIdle Timeout:\t%u seconds", session
[s
].idle_timeout
- (session
[s
].last_data
? abs(time_now
- session
[s
].last_data
) : 0));
446 if (session
[s
].timeout
)
448 cli_print(cli
, "\tRemaining time:\t%u",
449 (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
450 ? (unsigned) (session
[s
].timeout
- bundle
[session
[s
].bundle
].online_time
)
451 : (unsigned) (session
[s
].timeout
- (time_now
- session
[s
].opened
)));
454 cli_print(cli
, "\tBytes In/Out:\t%u/%u", session
[s
].cout
, session
[s
].cin
);
455 cli_print(cli
, "\tPkts In/Out:\t%u/%u", session
[s
].pout
, session
[s
].pin
);
456 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
457 cli_print(cli
, "\tRx Speed:\t%u", session
[s
].rx_connect_speed
);
458 cli_print(cli
, "\tTx Speed:\t%u", session
[s
].tx_connect_speed
);
459 if (session
[s
].filter_in
&& session
[s
].filter_in
<= MAXFILTER
)
460 cli_print(cli
, "\tFilter in:\t%u (%s)", session
[s
].filter_in
, ip_filters
[session
[s
].filter_in
- 1].name
);
461 if (session
[s
].filter_out
&& session
[s
].filter_out
<= MAXFILTER
)
462 cli_print(cli
, "\tFilter out:\t%u (%s)", session
[s
].filter_out
, ip_filters
[session
[s
].filter_out
- 1].name
);
463 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
464 cli_print(cli
, "\tIntercepted:\t%s:%d", fmtaddr(session
[s
].snoop_ip
, 0), session
[s
] .snoop_port
);
466 cli_print(cli
, "\tIntercepted:\tno");
468 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
470 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
471 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
472 t
? "YES" : "no", t
? " (" : "",
473 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
475 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
479 b_in
= session
[s
].tbf_in
;
480 b_out
= session
[s
].tbf_out
;
482 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
483 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
484 "ByteSent", "PackSent", "PackDrop", "PackDelay");
487 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
489 (filter_list
[b_in
].next
? "*" : " "),
490 (b_in
< 100 ? "\t" : ""),
491 filter_list
[b_in
].rate
* 8,
492 filter_list
[b_in
].credit
,
493 filter_list
[b_in
].queued
,
494 filter_list
[b_in
].b_queued
,
495 filter_list
[b_in
].p_queued
,
496 filter_list
[b_in
].b_sent
,
497 filter_list
[b_in
].p_sent
,
498 filter_list
[b_in
].p_dropped
,
499 filter_list
[b_in
].p_delayed
);
502 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
504 (filter_list
[b_out
].next
? "*" : " "),
505 (b_out
< 100 ? "\t" : ""),
506 filter_list
[b_out
].rate
* 8,
507 filter_list
[b_out
].credit
,
508 filter_list
[b_out
].queued
,
509 filter_list
[b_out
].b_queued
,
510 filter_list
[b_out
].p_queued
,
511 filter_list
[b_out
].b_sent
,
512 filter_list
[b_out
].p_sent
,
513 filter_list
[b_out
].p_dropped
,
514 filter_list
[b_out
].p_delayed
);
521 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %10s %-15s %s",
538 for (i
= 1; i
< MAXSESSION
; i
++)
541 if (!session
[i
].opened
) continue;
542 if (session
[i
].bundle
&& bundle
[session
[i
].bundle
].num_of_links
> 1)
543 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- bundle
[session
[i
].bundle
].online_time
) : 0;
545 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- (time_now
-session
[i
].opened
)) : 0;
547 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %-15s %s",
550 session
[i
].user
[0] ? session
[i
].user
: "*",
551 fmtaddr(htonl(session
[i
].ip
), 0),
552 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
553 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
554 (session
[i
].walled_garden
) ? "Y" : "N",
555 (session
[i
].ppp
.ipv6cp
== Opened
) ? "Y" : "N",
556 abs(time_now
- (unsigned long)session
[i
].opened
),
557 (unsigned long)session
[i
].cout
,
558 (unsigned long)session
[i
].cin
,
559 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
560 (unsigned long)(rem_time
),
561 fmtaddr(htonl(tunnel
[ session
[i
].tunnel
].ip
), 1),
562 session
[i
].calling
[0] ? session
[i
].calling
: "*");
567 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
569 int i
, x
, show_all
= 0;
577 if (CLI_HELP_REQUESTED
)
580 return cli_arg_help(cli
, 1,
581 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
584 return cli_arg_help(cli
, 1,
585 "all", "Show all tunnels, including unused",
586 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
593 if (strcmp(argv
[0], "all") == 0)
599 // Show individual tunnel
600 for (i
= 0; i
< argc
; i
++)
605 if (t
<= 0 || t
>= MAXTUNNEL
)
607 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
610 cli_print(cli
, "\r\nTunnel %d:", t
);
611 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
612 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
613 cli_print(cli
, "\tRemote IP:\t%s", fmtaddr(htonl(tunnel
[t
].ip
), 0));
614 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
615 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
616 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
617 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
618 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
619 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
621 for (x
= 0; x
< MAXSESSION
; x
++)
622 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
623 sprintf(s
, "%s%u ", s
, x
);
625 cli_print(cli
, "\tSessions:\t%s", s
);
631 // Show tunnel summary
632 cli_print(cli
, "%4s %20s %20s %6s %s",
639 for (i
= 1; i
< MAXTUNNEL
; i
++)
642 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
644 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
645 cli_print(cli
, "%4d %20s %20s %6s %6d",
647 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
648 fmtaddr(htonl(tunnel
[i
].ip
), 0),
649 states
[tunnel
[i
].state
],
656 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
663 if (CLI_HELP_REQUESTED
)
664 return cli_arg_help(cli
, 1,
665 "USER", "Show details for specific username",
668 for (i
= 0; i
< MAXSESSION
; i
++)
670 if (!session
[i
].opened
) continue;
671 if (!session
[i
].user
[0]) continue;
675 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
677 if (strcmp(argv
[j
], session
[i
].user
) == 0)
679 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
680 sargv
[sargc
] = sid
[sargc
];
688 cli_print(cli
, "%s", session
[i
].user
);
692 return cmd_show_session(cli
, "users", sargv
, sargc
);
698 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
700 if (CLI_HELP_REQUESTED
)
701 return CLI_HELP_NO_ARGS
;
703 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Ethernet", "Bytes", "Packets", "Errors", "Dropped");
704 cli_print(cli
, "%-10s %10u %10u %10u %10u", "RX",
705 GET_STAT(tun_rx_bytes
),
706 GET_STAT(tun_rx_packets
),
707 GET_STAT(tun_rx_errors
),
708 GET_STAT(tun_rx_dropped
));
709 cli_print(cli
, "%-10s %10u %10u %10u", "TX",
710 GET_STAT(tun_tx_bytes
),
711 GET_STAT(tun_tx_packets
),
712 GET_STAT(tun_tx_errors
));
715 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
716 cli_print(cli
, "%-10s %10u %10u %10u", "RX",
717 GET_STAT(tunnel_rx_bytes
),
718 GET_STAT(tunnel_rx_packets
),
719 GET_STAT(tunnel_rx_errors
));
720 cli_print(cli
, "%-10s %10u %10u %10u %10u", "TX",
721 GET_STAT(tunnel_tx_bytes
),
722 GET_STAT(tunnel_tx_packets
),
723 GET_STAT(tunnel_tx_errors
),
724 GET_STAT(tunnel_retries
));
727 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
728 cli_print(cli
, "-----------------------------------------");
729 cli_print(cli
, "%-30s%u", "radius_retries", GET_STAT(radius_retries
));
730 cli_print(cli
, "%-30s%u", "arp_sent", GET_STAT(arp_sent
));
731 cli_print(cli
, "%-30s%u", "packets_snooped", GET_STAT(packets_snooped
));
732 cli_print(cli
, "%-30s%u", "tunnel_created", GET_STAT(tunnel_created
));
733 cli_print(cli
, "%-30s%u", "session_created", GET_STAT(session_created
));
734 cli_print(cli
, "%-30s%u", "tunnel_timeout", GET_STAT(tunnel_timeout
));
735 cli_print(cli
, "%-30s%u", "session_timeout", GET_STAT(session_timeout
));
736 cli_print(cli
, "%-30s%u", "radius_timeout", GET_STAT(radius_timeout
));
737 cli_print(cli
, "%-30s%u", "radius_overflow", GET_STAT(radius_overflow
));
738 cli_print(cli
, "%-30s%u", "tunnel_overflow", GET_STAT(tunnel_overflow
));
739 cli_print(cli
, "%-30s%u", "session_overflow", GET_STAT(session_overflow
));
740 cli_print(cli
, "%-30s%u", "ip_allocated", GET_STAT(ip_allocated
));
741 cli_print(cli
, "%-30s%u", "ip_freed", GET_STAT(ip_freed
));
742 cli_print(cli
, "%-30s%u", "cluster_forwarded", GET_STAT(c_forwarded
));
743 cli_print(cli
, "%-30s%u", "recv_forward", GET_STAT(recv_forward
));
744 cli_print(cli
, "%-30s%u", "select_called", GET_STAT(select_called
));
745 cli_print(cli
, "%-30s%u", "multi_read_used", GET_STAT(multi_read_used
));
746 cli_print(cli
, "%-30s%u", "multi_read_exceeded", GET_STAT(multi_read_exceeded
));
750 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
751 cli_print(cli
, "-----------------------------------------");
752 cli_print(cli
, "%-30s%u", "call_processtun", GET_STAT(call_processtun
));
753 cli_print(cli
, "%-30s%u", "call_processipout", GET_STAT(call_processipout
));
754 cli_print(cli
, "%-30s%u", "call_processipv6out", GET_STAT(call_processipv6out
));
755 cli_print(cli
, "%-30s%u", "call_processudp", GET_STAT(call_processudp
));
756 cli_print(cli
, "%-30s%u", "call_processpap", GET_STAT(call_processpap
));
757 cli_print(cli
, "%-30s%u", "call_processchap", GET_STAT(call_processchap
));
758 cli_print(cli
, "%-30s%u", "call_processlcp", GET_STAT(call_processlcp
));
759 cli_print(cli
, "%-30s%u", "call_processipcp", GET_STAT(call_processipcp
));
760 cli_print(cli
, "%-30s%u", "call_processipv6cp", GET_STAT(call_processipv6cp
));
761 cli_print(cli
, "%-30s%u", "call_processipin", GET_STAT(call_processipin
));
762 cli_print(cli
, "%-30s%u", "call_processipv6in", GET_STAT(call_processipv6in
));
763 cli_print(cli
, "%-30s%u", "call_processccp", GET_STAT(call_processccp
));
764 cli_print(cli
, "%-30s%u", "call_processrad", GET_STAT(call_processrad
));
765 cli_print(cli
, "%-30s%u", "call_sendarp", GET_STAT(call_sendarp
));
766 cli_print(cli
, "%-30s%u", "call_sendipcp", GET_STAT(call_sendipcp
));
767 cli_print(cli
, "%-30s%u", "call_sendchap", GET_STAT(call_sendchap
));
768 cli_print(cli
, "%-30s%u", "call_sessionbyip", GET_STAT(call_sessionbyip
));
769 cli_print(cli
, "%-30s%u", "call_sessionbyipv6", GET_STAT(call_sessionbyipv6
));
770 cli_print(cli
, "%-30s%u", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
771 cli_print(cli
, "%-30s%u", "call_tunnelsend", GET_STAT(call_tunnelsend
));
772 cli_print(cli
, "%-30s%u", "call_tunnelkill", GET_STAT(call_tunnelkill
));
773 cli_print(cli
, "%-30s%u", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
774 cli_print(cli
, "%-30s%u", "call_sessionkill", GET_STAT(call_sessionkill
));
775 cli_print(cli
, "%-30s%u", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
776 cli_print(cli
, "%-30s%u", "call_sessionsetup", GET_STAT(call_sessionsetup
));
777 cli_print(cli
, "%-30s%u", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
778 cli_print(cli
, "%-30s%u", "call_free_ip_address", GET_STAT(call_free_ip_address
));
779 cli_print(cli
, "%-30s%u", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
780 cli_print(cli
, "%-30s%u", "call_radiussend", GET_STAT(call_radiussend
));
781 cli_print(cli
, "%-30s%u", "call_radiusretry", GET_STAT(call_radiusretry
));
782 cli_print(cli
, "%-30s%u", "call_random_data", GET_STAT(call_random_data
));
783 #endif /* STAT_CALLS */
786 time_t l
= GET_STAT(last_reset
);
788 char *p
= strchr(t
, '\n');
792 cli_print(cli
, "Last counter reset %s", t
);
798 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
800 if (CLI_HELP_REQUESTED
)
801 return CLI_HELP_NO_ARGS
;
803 memset(_statistics
, 0, sizeof(struct Tstats
));
804 SET_STAT(last_reset
, time(NULL
));
806 cli_print(cli
, "Counters cleared");
809 #endif /* STATISTICS */
811 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
817 if (CLI_HELP_REQUESTED
)
818 return cli_arg_help(cli
, 1,
819 "tag", "Include CVS release tag",
820 "file", "Include file versions",
823 for (i
= 0; i
< argc
; i
++)
824 if (!strcmp(argv
[i
], "tag"))
826 else if (!strcmp(argv
[i
], "file"))
829 cli_print(cli
, "L2TPNS %s", VERSION
);
832 char const *p
= strchr(cvs_name
, ':');
844 e
= strpbrk(p
, " \t$");
845 cli_print(cli
, "Tag: %.*s", (int) (e
? e
- p
+ 1 : strlen(p
)), p
);
850 extern linked_list
*loaded_plugins
;
853 cli_print(cli
, "Files:");
854 cli_print(cli
, " %s", cvs_id_arp
);
856 cli_print(cli
, " %s", cvs_id_bgp
);
858 cli_print(cli
, " %s", cvs_id_cli
);
859 cli_print(cli
, " %s", cvs_id_cluster
);
860 cli_print(cli
, " %s", cvs_id_constants
);
861 cli_print(cli
, " %s", cvs_id_control
);
862 cli_print(cli
, " %s", cvs_id_icmp
);
863 cli_print(cli
, " %s", cvs_id_l2tpns
);
864 cli_print(cli
, " %s", cvs_id_ll
);
865 cli_print(cli
, " %s", cvs_id_ppp
);
866 cli_print(cli
, " %s", cvs_id_radius
);
867 cli_print(cli
, " %s", cvs_id_tbf
);
868 cli_print(cli
, " %s", cvs_id_util
);
870 ll_reset(loaded_plugins
);
871 while ((p
= ll_next(loaded_plugins
)))
873 char const **id
= dlsym(p
, "cvs_id");
875 cli_print(cli
, " %s", *id
);
882 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
885 int used
= 0, free
= 0, show_all
= 0;
887 if (!config
->cluster_iam_master
)
889 cli_print(cli
, "Can't do this on a slave. Do it on %s",
890 fmtaddr(config
->cluster_master_address
, 0));
895 if (CLI_HELP_REQUESTED
)
898 return cli_arg_help(cli
, 1, NULL
);
900 return cli_arg_help(cli
, 1,
901 "all", "Show all pool addresses, including unused",
905 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
909 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
910 for (i
= 0; i
< MAXIPPOOL
; i
++)
912 if (!ip_address_pool
[i
].address
) continue;
913 if (ip_address_pool
[i
].assigned
)
915 cli_print(cli
, "%-15s\tY %8d %s",
916 fmtaddr(htonl(ip_address_pool
[i
].address
), 0),
917 ip_address_pool
[i
].session
,
918 session
[ip_address_pool
[i
].session
].user
);
924 if (ip_address_pool
[i
].last
)
925 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
926 fmtaddr(htonl(ip_address_pool
[i
].address
), 0), "",
927 ip_address_pool
[i
].user
, (int) time_now
- ip_address_pool
[i
].last
);
930 cli_print(cli
, "%-15s\tN", fmtaddr(htonl(ip_address_pool
[i
].address
), 0));
937 cli_print(cli
, "(Not displaying unused addresses)");
939 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
943 static FILE *save_config_fh
= 0;
944 static void print_save_config(struct cli_def
*cli
, char *string
)
947 fprintf(save_config_fh
, "%s\n", string
);
950 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
952 if (CLI_HELP_REQUESTED
)
953 return CLI_HELP_NO_ARGS
;
955 if ((save_config_fh
= fopen(config
->config_file
, "w")))
957 cli_print(cli
, "Writing configuration");
958 cli_print_callback(cli
, print_save_config
);
959 cmd_show_run(cli
, command
, argv
, argc
);
960 cli_print_callback(cli
, NULL
);
961 fclose(save_config_fh
);
966 cli_error(cli
, "Error writing configuration: %s", strerror(errno
));
971 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
);
973 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
976 char ipv6addr
[INET6_ADDRSTRLEN
];
978 if (CLI_HELP_REQUESTED
)
979 return CLI_HELP_NO_ARGS
;
981 cli_print(cli
, "# Current configuration:");
983 for (i
= 0; config_values
[i
].key
; i
++)
985 void *value
= ((void *)config
) + config_values
[i
].offset
;
986 if (config_values
[i
].type
== STRING
)
987 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *) value
);
988 else if (config_values
[i
].type
== IPv4
)
989 cli_print(cli
, "set %s %s", config_values
[i
].key
, fmtaddr(*(in_addr_t
*) value
, 0));
990 else if (config_values
[i
].type
== IPv6
)
991 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_ntop(AF_INET6
, value
, ipv6addr
, INET6_ADDRSTRLEN
));
992 else if (config_values
[i
].type
== SHORT
)
993 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *) value
);
994 else if (config_values
[i
].type
== BOOL
)
995 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *) value
) ? "yes" : "no");
996 else if (config_values
[i
].type
== INT
)
997 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *) value
);
998 else if (config_values
[i
].type
== UNSIGNED_LONG
)
999 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *) value
);
1002 cli_print(cli
, "# Plugins");
1003 for (i
= 0; i
< MAXPLUGINS
; i
++)
1005 if (*config
->plugins
[i
])
1007 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
1012 if (config
->as_number
)
1017 cli_print(cli
, "# BGP");
1018 cli_print(cli
, "router bgp %u", config
->as_number
);
1019 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1021 if (!config
->neighbour
[i
].name
[0])
1024 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
1026 k
= config
->neighbour
[i
].keepalive
;
1027 h
= config
->neighbour
[i
].hold
;
1034 k
= BGP_KEEPALIVE_TIME
;
1040 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
1045 cli_print(cli
, "# Filters");
1046 for (i
= 0; i
< MAXFILTER
; i
++)
1048 ip_filter_rulet
*rules
;
1049 if (!*ip_filters
[i
].name
)
1052 cli_print(cli
, "ip access-list %s %s",
1053 ip_filters
[i
].extended
? "extended" : "standard",
1054 ip_filters
[i
].name
);
1056 rules
= ip_filters
[i
].rules
;
1057 while (rules
->action
)
1058 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1061 cli_print(cli
, "# end");
1065 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1067 int i
, free
= 0, used
= 0, show_all
= 0;
1079 if (CLI_HELP_REQUESTED
)
1082 return cli_arg_help(cli
, 1, NULL
);
1084 return cli_arg_help(cli
, 1,
1085 "all", "Show all RADIUS sessions, including unused",
1089 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1093 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1096 for (i
= 1; i
< MAXRADIUS
; i
++)
1098 if (radius
[i
].state
== RADIUSNULL
)
1103 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1105 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1109 states
[radius
[i
].state
],
1115 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1120 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1124 if (CLI_HELP_REQUESTED
)
1125 return CLI_HELP_NO_ARGS
;
1127 cli_print(cli
, "Plugins currently loaded:");
1128 for (i
= 0; i
< MAXPLUGINS
; i
++)
1129 if (*config
->plugins
[i
])
1130 cli_print(cli
, " %s", config
->plugins
[i
]);
1135 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1139 if (CLI_HELP_REQUESTED
)
1140 return CLI_HELP_NO_ARGS
;
1142 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1151 for (i
= 0; i
< MAXSESSION
; i
++)
1153 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1154 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1158 session
[i
].throttle_in
,
1159 session
[i
].throttle_out
,
1161 session
[i
].tbf_out
);
1167 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1169 if (CLI_HELP_REQUESTED
)
1170 return CLI_HELP_NO_ARGS
;
1172 cli_print(cli
, " _\n"
1178 " ( \\ `. `-. _,.-:\\\n"
1179 " \\ \\ `. `-._ __..--' ,-';/\n"
1180 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1181 " `. `. `-._ __..--' ,' /\n"
1182 " `. `-_ ``--..'' _.-' ,'\n"
1183 " `-_ `-.___ __,--' ,'\n"
1184 " `-.__ `----\"\"\" __.-'\n"
1185 "hh `--..____..--'");
1190 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1195 if (CLI_HELP_REQUESTED
)
1196 return cli_arg_help(cli
, argc
> 1,
1197 "USER", "Username of session to drop", NULL
);
1199 if (!config
->cluster_iam_master
)
1201 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1202 fmtaddr(config
->cluster_master_address
, 0));
1209 cli_error(cli
, "Specify a user to drop");
1213 for (i
= 0; i
< argc
; i
++)
1215 if (!(s
= sessionbyuser(argv
[i
])))
1217 cli_error(cli
, "User %s is not connected", argv
[i
]);
1221 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1223 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1224 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1231 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1236 if (CLI_HELP_REQUESTED
)
1237 return cli_arg_help(cli
, argc
> 1,
1238 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1240 if (!config
->cluster_iam_master
)
1242 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1243 fmtaddr(config
->cluster_master_address
, 0));
1250 cli_error(cli
, "Specify a tunnel to drop");
1254 for (i
= 0; i
< argc
; i
++)
1256 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1258 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1264 cli_error(cli
, "Tunnel %d is not connected", t
);
1270 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1274 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1275 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1281 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1286 if (CLI_HELP_REQUESTED
)
1287 return cli_arg_help(cli
, argc
> 1,
1288 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1290 if (!config
->cluster_iam_master
)
1292 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1293 fmtaddr(config
->cluster_master_address
, 0));
1300 cli_error(cli
, "Specify a session id to drop");
1304 for (i
= 0; i
< argc
; i
++)
1306 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1308 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1312 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1314 cli_print(cli
, "Dropping session %d", s
);
1315 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1319 cli_error(cli
, "Session %d is not active.", s
);
1326 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1332 if (CLI_HELP_REQUESTED
)
1337 return cli_arg_help(cli
, 0,
1338 "USER", "Username of session to snoop", NULL
);
1341 return cli_arg_help(cli
, 0,
1342 "A.B.C.D", "IP address of snoop destination", NULL
);
1345 return cli_arg_help(cli
, 0,
1346 "N", "Port of snoop destination", NULL
);
1350 return cli_arg_help(cli
, 1, NULL
);
1357 if (!config
->cluster_iam_master
)
1359 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1360 fmtaddr(config
->cluster_master_address
, 0));
1367 cli_error(cli
, "Specify username, ip and port");
1371 if (!(s
= sessionbyuser(argv
[0])))
1373 cli_error(cli
, "User %s is not connected", argv
[0]);
1377 ip
= inet_addr(argv
[1]);
1378 if (!ip
|| ip
== INADDR_NONE
)
1380 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1384 port
= atoi(argv
[2]);
1387 cli_error(cli
, "Invalid port %s", argv
[2]);
1391 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1392 cli_session_actions
[s
].snoop_ip
= ip
;
1393 cli_session_actions
[s
].snoop_port
= port
;
1394 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1399 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1404 if (CLI_HELP_REQUESTED
)
1405 return cli_arg_help(cli
, argc
> 1,
1406 "USER", "Username of session to unsnoop", NULL
);
1408 if (!config
->cluster_iam_master
)
1410 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1411 fmtaddr(config
->cluster_master_address
, 0));
1418 cli_error(cli
, "Specify a user to unsnoop");
1422 for (i
= 0; i
< argc
; i
++)
1424 if (!(s
= sessionbyuser(argv
[i
])))
1426 cli_error(cli
, "User %s is not connected", argv
[i
]);
1430 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1431 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1437 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1444 throttle USER - throttle in/out to default rate
1445 throttle USER RATE - throttle in/out to default rate
1446 throttle USER in RATE - throttle input only
1447 throttle USER out RATE - throttle output only
1448 throttle USER in RATE out RATE - throttle both
1451 if (CLI_HELP_REQUESTED
)
1456 return cli_arg_help(cli
, 0,
1457 "USER", "Username of session to throttle", NULL
);
1460 return cli_arg_help(cli
, 1,
1461 "RATE", "Rate in kbps (in and out)",
1462 "in", "Select incoming rate",
1463 "out", "Select outgoing rate", NULL
);
1466 return cli_arg_help(cli
, 1,
1467 "in", "Select incoming rate",
1468 "out", "Select outgoing rate", NULL
);
1471 if (isdigit(argv
[1][0]))
1472 return cli_arg_help(cli
, 1, NULL
);
1475 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1478 return cli_arg_help(cli
, argc
> 1, NULL
);
1482 if (!config
->cluster_iam_master
)
1484 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1485 fmtaddr(config
->cluster_master_address
, 0));
1492 cli_error(cli
, "Specify a user to throttle");
1496 if (!(s
= sessionbyuser(argv
[0])))
1498 cli_error(cli
, "User %s is not connected", argv
[0]);
1504 rate_in
= rate_out
= config
->rl_rate
;
1508 rate_in
= rate_out
= atoi(argv
[1]);
1511 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1515 else if (argc
== 3 || argc
== 5)
1518 for (i
= 1; i
< argc
- 1; i
+= 2)
1521 if (MATCH("in", argv
[i
]))
1522 r
= rate_in
= atoi(argv
[i
+1]);
1523 else if (MATCH("out", argv
[i
]))
1524 r
= rate_out
= atoi(argv
[i
+1]);
1528 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1535 cli_error(cli
, "Invalid arguments");
1539 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1541 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1545 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1546 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1547 cli_session_actions
[s
].throttle_in
= rate_in
;
1549 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1550 cli_session_actions
[s
].throttle_out
= rate_out
;
1552 if (cli_session_actions
[s
].throttle_in
== -1 &&
1553 cli_session_actions
[s
].throttle_out
== -1)
1555 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1559 cli_print(cli
, "Throttling user %s", argv
[0]);
1560 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1565 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1570 if (CLI_HELP_REQUESTED
)
1571 return cli_arg_help(cli
, argc
> 1,
1572 "USER", "Username of session to unthrottle", NULL
);
1574 if (!config
->cluster_iam_master
)
1576 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1577 fmtaddr(config
->cluster_master_address
, 0));
1584 cli_error(cli
, "Specify a user to unthrottle");
1588 for (i
= 0; i
< argc
; i
++)
1590 if (!(s
= sessionbyuser(argv
[i
])))
1592 cli_error(cli
, "User %s is not connected", argv
[i
]);
1596 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1598 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1599 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1603 cli_error(cli
, "User %s not throttled", argv
[i
]);
1610 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1614 if (CLI_HELP_REQUESTED
)
1615 return cli_arg_help(cli
, 1,
1616 "all", "Enable debugging for all except \"data\"",
1617 "critical", "", // FIXME: add descriptions
1627 char *p
= (char *) &debug_flags
;
1628 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1632 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1633 (debug_flags
.critical
) ? " critical" : "",
1634 (debug_flags
.error
) ? " error" : "",
1635 (debug_flags
.warning
) ? " warning" : "",
1636 (debug_flags
.info
) ? " info" : "",
1637 (debug_flags
.calls
) ? " calls" : "",
1638 (debug_flags
.data
) ? " data" : "");
1644 cli_print(cli
, "Debugging off");
1648 for (i
= 0; i
< argc
; i
++)
1650 int len
= strlen(argv
[i
]);
1652 if (argv
[i
][0] == 'c' && len
< 2)
1653 len
= 2; /* distinguish [cr]itical from [ca]lls */
1655 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1656 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1657 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1658 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1659 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1660 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1661 if (!strncmp("all", argv
[i
], len
))
1663 memset(&debug_flags
, 1, sizeof(debug_flags
));
1664 debug_flags
.data
= 0;
1668 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1674 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1678 if (CLI_HELP_REQUESTED
)
1679 return cli_arg_help(cli
, 1,
1680 "all", "Disable all debugging",
1681 "critical", "", // FIXME: add descriptions
1691 memset(&debug_flags
, 0, sizeof(debug_flags
));
1695 for (i
= 0; i
< argc
; i
++)
1697 int len
= strlen(argv
[i
]);
1699 if (argv
[i
][0] == 'c' && len
< 2)
1700 len
= 2; /* distinguish [cr]itical from [ca]lls */
1702 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1703 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1704 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1705 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1706 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1707 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1708 if (!strncmp("all", argv
[i
], len
))
1710 memset(&debug_flags
, 0, sizeof(debug_flags
));
1714 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1720 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1722 int i
, firstfree
= 0;
1724 if (CLI_HELP_REQUESTED
)
1725 return cli_arg_help(cli
, argc
> 1,
1726 "PLUGIN", "Name of plugin to load", NULL
);
1730 cli_error(cli
, "Specify a plugin to load");
1734 for (i
= 0; i
< MAXPLUGINS
; i
++)
1736 if (!*config
->plugins
[i
] && !firstfree
)
1738 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1740 cli_error(cli
, "Plugin is already loaded");
1747 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1748 config
->reload_config
= 1;
1749 cli_print(cli
, "Loading plugin %s", argv
[0]);
1755 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1759 if (CLI_HELP_REQUESTED
)
1760 return cli_arg_help(cli
, argc
> 1,
1761 "PLUGIN", "Name of plugin to unload", NULL
);
1765 cli_error(cli
, "Specify a plugin to remove");
1769 for (i
= 0; i
< MAXPLUGINS
; i
++)
1771 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1773 config
->reload_config
= 1;
1774 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1779 cli_error(cli
, "Plugin is not loaded");
1783 static char *duration(time_t secs
)
1785 static char *buf
= NULL
;
1788 if (!buf
) buf
= calloc(64, 1);
1792 int days
= secs
/ 86400;
1793 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1799 int mins
= secs
/ 60;
1800 int hrs
= mins
/ 60;
1803 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1805 else if (secs
>= 60)
1807 int mins
= secs
/ 60;
1808 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1811 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1816 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1819 char buf
[100], *p
= buf
, *loads
[3];
1820 int i
, num_sessions
= 0;
1822 if (CLI_HELP_REQUESTED
)
1823 return CLI_HELP_NO_ARGS
;
1825 fh
= fopen("/proc/loadavg", "r");
1826 fgets(buf
, 100, fh
);
1829 for (i
= 0; i
< 3; i
++)
1830 loads
[i
] = strdup(strsep(&p
, " "));
1833 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1835 for (i
= 1; i
< MAXSESSION
; i
++)
1836 if (session
[i
].opened
) num_sessions
++;
1838 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1840 duration(time_now
- config
->start_time
),
1842 loads
[0], loads
[1], loads
[2]
1844 for (i
= 0; i
< 3; i
++)
1845 if (loads
[i
]) free(loads
[i
]);
1847 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1852 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1856 if (CLI_HELP_REQUESTED
)
1862 int len
= strlen(argv
[0])-1;
1863 for (i
= 0; config_values
[i
].key
; i
++)
1864 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1865 cli_error(cli
, " %s", config_values
[i
].key
);
1871 return cli_arg_help(cli
, 0,
1872 "VALUE", "Value for variable", NULL
);
1876 return cli_arg_help(cli
, 1, NULL
);
1885 cli_error(cli
, "Specify variable and value");
1889 for (i
= 0; config_values
[i
].key
; i
++)
1891 void *value
= ((void *) config
) + config_values
[i
].offset
;
1892 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1894 // Found a value to set
1895 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1896 switch (config_values
[i
].type
)
1899 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1902 *(int *) value
= atoi(argv
[1]);
1905 *(unsigned long *) value
= atol(argv
[1]);
1908 *(short *) value
= atoi(argv
[1]);
1911 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1914 inet_pton(AF_INET6
, argv
[1], value
);
1917 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1923 cli_error(cli
, "Unknown variable type");
1926 config
->reload_config
= 1;
1931 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1935 int regular_stuff(struct cli_def
*cli
)
1941 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1943 char *m
= ringbuffer
->buffer
[i
].message
;
1949 switch (ringbuffer
->buffer
[i
].level
)
1951 case 0: show
= debug_flags
.critical
; break;
1952 case 1: show
= debug_flags
.error
; break;
1953 case 2: show
= debug_flags
.warning
; break;
1954 case 3: show
= debug_flags
.info
; break;
1955 case 4: show
= debug_flags
.calls
; break;
1956 case 5: show
= debug_flags
.data
; break;
1959 if (!show
) continue;
1961 if (!(p
= strchr(m
, '\n')))
1964 cli_error(cli
, "\r%s-%u-%u %.*s",
1965 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1966 ringbuffer
->buffer
[i
].tunnel
,
1967 ringbuffer
->buffer
[i
].session
,
1973 debug_rb_tail
= ringbuffer
->tail
;
1981 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1985 if (CLI_HELP_REQUESTED
)
1986 return cli_arg_help(cli
, argc
> 1,
1987 "<1-65535>", "Autonomous system number", NULL
);
1989 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1991 cli_error(cli
, "Invalid autonomous system number");
1995 if (bgp_configured
&& as
!= config
->as_number
)
1997 cli_error(cli
, "Can't change local AS on a running system");
2001 config
->as_number
= as
;
2002 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
2007 static int find_bgp_neighbour(char const *name
)
2012 in_addr_t addrs
[4] = { 0 };
2015 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
2018 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
2019 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
2021 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2023 if (!config
->neighbour
[i
].name
[0])
2025 if (new == -1) new = i
;
2029 if (!strcmp(name
, config
->neighbour
[i
].name
))
2032 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
2035 for (a
= h
->h_addr_list
; *a
; a
++)
2038 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2039 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2047 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2053 if (CLI_HELP_REQUESTED
)
2058 return cli_arg_help(cli
, 0,
2059 "A.B.C.D", "BGP neighbour address",
2060 "NAME", "BGP neighbour name",
2064 return cli_arg_help(cli
, 0,
2065 "remote-as", "Set remote autonomous system number",
2066 "timers", "Set timers",
2070 if (MATCH("remote-as", argv
[1]))
2071 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2073 if (MATCH("timers", argv
[1]))
2076 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2079 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2081 if (argc
== 5 && !argv
[4][1])
2082 return cli_arg_help(cli
, 1, NULL
);
2091 cli_error(cli
, "Invalid arguments");
2095 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2097 cli_error(cli
, "Invalid neighbour");
2103 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2107 if (MATCH("remote-as", argv
[1]))
2109 int as
= atoi(argv
[2]);
2110 if (as
< 0 || as
> 65535)
2112 cli_error(cli
, "Invalid autonomous system number");
2116 if (!config
->neighbour
[i
].name
[0])
2118 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2119 config
->neighbour
[i
].keepalive
= -1;
2120 config
->neighbour
[i
].hold
= -1;
2123 config
->neighbour
[i
].as
= as
;
2127 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2129 cli_error(cli
, "Invalid arguments");
2133 if (!config
->neighbour
[i
].name
[0])
2135 cli_error(cli
, "Specify remote-as first");
2139 keepalive
= atoi(argv
[2]);
2140 hold
= atoi(argv
[3]);
2142 if (keepalive
< 1 || keepalive
> 65535)
2144 cli_error(cli
, "Invalid keepalive time");
2148 if (hold
< 3 || hold
> 65535)
2150 cli_error(cli
, "Invalid hold time");
2154 if (keepalive
== BGP_KEEPALIVE_TIME
)
2155 keepalive
= -1; // using default value
2157 if (hold
== BGP_HOLD_TIME
)
2160 config
->neighbour
[i
].keepalive
= keepalive
;
2161 config
->neighbour
[i
].hold
= hold
;
2166 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2170 if (CLI_HELP_REQUESTED
)
2171 return cli_arg_help(cli
, argc
> 0,
2172 "A.B.C.D", "BGP neighbour address",
2173 "NAME", "BGP neighbour name",
2178 cli_error(cli
, "Specify a BGP neighbour");
2182 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2184 cli_error(cli
, "Invalid neighbour");
2188 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2190 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2194 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2198 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2204 if (!bgp_configured
)
2207 if (CLI_HELP_REQUESTED
)
2208 return cli_arg_help(cli
, 1,
2209 "A.B.C.D", "BGP neighbour address",
2210 "NAME", "BGP neighbour name",
2213 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2214 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2218 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2220 if (!*bgp_peers
[i
].name
)
2223 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2224 if (argc
&& strcmp(addr
, argv
[0]) &&
2225 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2231 cli_print(cli
, "Peer AS Address "
2232 "State Retries Retry in Route Pend Timers");
2233 cli_print(cli
, "------------------ ----- --------------- "
2234 "----------- ------- -------- ----- ---- ---------");
2237 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2241 bgp_state_str(bgp_peers
[i
].state
),
2242 bgp_peers
[i
].retry_count
,
2243 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2244 bgp_peers
[i
].routing
? "yes" : "no",
2245 bgp_peers
[i
].update_routes
? "yes" : "no",
2246 bgp_peers
[i
].keepalive
,
2253 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2258 if (!bgp_configured
)
2261 if (CLI_HELP_REQUESTED
)
2262 return cli_arg_help(cli
, 1,
2263 "A.B.C.D", "BGP neighbour address",
2264 "NAME", "BGP neighbour name",
2267 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2269 if (bgp_peers
[i
].state
!= Established
)
2272 if (!bgp_peers
[i
].routing
)
2275 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2276 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2279 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2280 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2286 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2291 if (!bgp_configured
)
2294 if (CLI_HELP_REQUESTED
)
2295 return cli_arg_help(cli
, 1,
2296 "A.B.C.D", "BGP neighbour address",
2297 "NAME", "BGP neighbour name",
2300 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2302 if (bgp_peers
[i
].state
!= Established
)
2305 if (bgp_peers
[i
].routing
)
2308 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2309 if (argc
&& strcmp(addr
, argv
[0]) &&
2310 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2313 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2314 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2320 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2325 if (!bgp_configured
)
2328 if (CLI_HELP_REQUESTED
)
2329 return cli_arg_help(cli
, 1,
2330 "A.B.C.D", "BGP neighbour address",
2331 "NAME", "BGP neighbour name",
2334 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2336 if (!*bgp_peers
[i
].name
)
2339 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2340 if (argc
&& strcmp(addr
, argv
[0]) &&
2341 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2344 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2345 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2353 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2357 if (CLI_HELP_REQUESTED
)
2362 return cli_arg_help(cli
, 0,
2363 "standard", "Standard syntax",
2364 "extended", "Extended syntax",
2368 return cli_arg_help(cli
, argv
[1][1],
2369 "NAME", "Access-list name",
2373 if (argc
== 3 && !argv
[2][1])
2374 return cli_arg_help(cli
, 1, NULL
);
2382 cli_error(cli
, "Specify access-list type and name");
2386 if (MATCH("standard", argv
[0]))
2388 else if (MATCH("extended", argv
[0]))
2392 cli_error(cli
, "Invalid access-list type");
2396 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2397 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2399 cli_error(cli
, "Invalid access-list name");
2403 filt
= find_filter(argv
[1], strlen(argv
[1]));
2408 cli_error(cli
, "Too many access-lists");
2413 if (!*ip_filters
[filt
].name
)
2415 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2416 strcpy(ip_filters
[filt
].name
, argv
[1]);
2417 ip_filters
[filt
].extended
= extended
;
2419 else if (ip_filters
[filt
].extended
!= extended
)
2421 cli_error(cli
, "Access-list is %s",
2422 ip_filters
[filt
].extended
? "extended" : "standard");
2427 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2431 if (filt
< 0 || !*ip_filters
[filt
].name
)
2433 cli_error(cli
, "Access-list not defined");
2438 if (ip_filters
[filt
].used
)
2440 cli_error(cli
, "Access-list in use");
2444 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2448 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2450 return access_list(cli
, argv
, argc
, 1);
2453 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2455 return access_list(cli
, argv
, argc
, 0);
2458 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2460 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2461 return sprintf(buf
, " any");
2463 if (wild
== INADDR_ANY
)
2464 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2466 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2469 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2473 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2474 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2475 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2476 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2477 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2483 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2485 static char buf
[256];
2488 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2491 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2492 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2495 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2499 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2500 p
+= show_ports(p
, &rule
->src_ports
);
2502 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2503 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2504 p
+= show_ports(p
, &rule
->dst_ports
);
2506 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2508 switch (rule
->tcp_flag_op
)
2510 case FILTER_FLAG_OP_EST
:
2511 p
+= sprintf(p
, " established");
2514 case FILTER_FLAG_OP_ANY
:
2515 case FILTER_FLAG_OP_ALL
:
2516 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2517 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2518 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2519 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2520 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2521 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2522 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2523 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2524 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2525 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2526 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2527 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2528 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2534 p
+= sprintf(p
, " fragments");
2539 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2541 static ip_filter_rulet rule
;
2542 struct in_addr addr
;
2546 if (CLI_HELP_REQUESTED
)
2550 cli_arg_help(cli
, 0,
2551 "ip", "Match IP packets",
2552 "tcp", "Match TCP packets",
2553 "udp", "Match UDP packets",
2559 // *sigh*, too darned complex
2560 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2566 cli_error(cli
, "Specify rule details");
2570 memset(&rule
, 0, sizeof(rule
));
2571 rule
.action
= (command
[0] == 'p')
2572 ? FILTER_ACTION_PERMIT
2573 : FILTER_ACTION_DENY
;
2575 if (MATCH("ip", argv
[0]))
2576 rule
.proto
= IPPROTO_IP
;
2577 else if (MATCH("udp", argv
[0]))
2578 rule
.proto
= IPPROTO_UDP
;
2579 else if (MATCH("tcp", argv
[0]))
2580 rule
.proto
= IPPROTO_TCP
;
2583 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2587 for (a
= 1, i
= 0; i
< 2; i
++)
2591 ip_filter_portt
*port
;
2596 wild
= &rule
.src_wild
;
2597 port
= &rule
.src_ports
;
2602 wild
= &rule
.dst_wild
;
2603 port
= &rule
.dst_ports
;
2606 cli_error(cli
, "Specify destination");
2611 if (MATCH("any", argv
[a
]))
2614 *wild
= INADDR_BROADCAST
;
2617 else if (MATCH("host", argv
[a
]))
2621 cli_error(cli
, "Specify host ip address");
2625 if (!inet_aton(argv
[a
], &addr
))
2627 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2639 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2643 if (!inet_aton(argv
[a
], &addr
))
2645 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2651 if (!inet_aton(argv
[++a
], &addr
))
2653 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2657 *wild
= addr
.s_addr
;
2661 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2665 if (MATCH("eq", argv
[a
]))
2666 port
->op
= FILTER_PORT_OP_EQ
;
2667 else if (MATCH("neq", argv
[a
]))
2668 port
->op
= FILTER_PORT_OP_NEQ
;
2669 else if (MATCH("gt", argv
[a
]))
2670 port
->op
= FILTER_PORT_OP_GT
;
2671 else if (MATCH("lt", argv
[a
]))
2672 port
->op
= FILTER_PORT_OP_LT
;
2673 else if (MATCH("range", argv
[a
]))
2674 port
->op
= FILTER_PORT_OP_RANGE
;
2681 cli_error(cli
, "Specify port");
2685 if (!(port
->port
= atoi(argv
[a
])))
2687 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2692 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2697 cli_error(cli
, "Specify port");
2701 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2703 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2710 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2712 if (MATCH("established", argv
[a
]))
2714 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2717 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2718 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2720 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2721 ? FILTER_FLAG_OP_ANY
2722 : FILTER_FLAG_OP_ALL
;
2726 cli_error(cli
, "Specify tcp flags");
2730 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2734 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2736 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2737 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2738 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2739 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2740 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2741 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2744 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2753 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2755 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2757 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2767 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2774 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2776 static ip_filter_rulet rule
;
2777 struct in_addr addr
;
2779 if (CLI_HELP_REQUESTED
)
2783 cli_arg_help(cli
, argv
[0][1],
2784 "A.B.C.D", "Source address",
2785 "any", "Any source address",
2786 "host", "Source host",
2792 if (MATCH("any", argv
[0]))
2794 if (argc
== 2 && !argv
[1][1])
2795 cli_arg_help(cli
, 1, NULL
);
2797 else if (MATCH("host", argv
[0]))
2801 cli_arg_help(cli
, argv
[1][1],
2802 "A.B.C.D", "Host address",
2805 else if (argc
== 3 && !argv
[2][1])
2806 cli_arg_help(cli
, 1, NULL
);
2812 cli_arg_help(cli
, 1,
2813 "A.B.C.D", "Wildcard bits",
2816 else if (argc
== 3 && !argv
[2][1])
2817 cli_arg_help(cli
, 1, NULL
);
2825 cli_error(cli
, "Specify rule details");
2829 memset(&rule
, 0, sizeof(rule
));
2830 rule
.action
= (command
[0] == 'p')
2831 ? FILTER_ACTION_PERMIT
2832 : FILTER_ACTION_DENY
;
2834 rule
.proto
= IPPROTO_IP
;
2835 if (MATCH("any", argv
[0]))
2837 rule
.src_ip
= INADDR_ANY
;
2838 rule
.src_wild
= INADDR_BROADCAST
;
2840 else if (MATCH("host", argv
[0]))
2844 cli_error(cli
, "Specify host ip address");
2848 if (!inet_aton(argv
[1], &addr
))
2850 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2854 rule
.src_ip
= addr
.s_addr
;
2855 rule
.src_wild
= INADDR_ANY
;
2861 cli_error(cli
, "Specify source ip address and wildcard");
2865 if (!inet_aton(argv
[0], &addr
))
2867 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2871 rule
.src_ip
= addr
.s_addr
;
2875 if (!inet_aton(argv
[1], &addr
))
2877 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2881 rule
.src_wild
= addr
.s_addr
;
2884 rule
.src_wild
= INADDR_ANY
;
2890 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2893 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2894 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2895 : access_list_rule_std(cli
, command
, argv
, argc
);
2900 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2902 if (!ip_filters
[filt
].rules
[i
].action
)
2904 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2908 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, offsetof(ip_filter_rulet
, counter
)))
2912 cli_error(cli
, "Too many rules");
2916 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2921 /* filter USER {in|out} FILTER ... */
2922 if (CLI_HELP_REQUESTED
)
2927 return cli_arg_help(cli
, 0,
2928 "USER", "Username of session to filter", NULL
);
2932 return cli_arg_help(cli
, 0,
2933 "in", "Set incoming filter",
2934 "out", "Set outgoing filter", NULL
);
2938 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2939 "NAME", "Filter name", NULL
);
2942 return cli_arg_help(cli
, argc
> 1, NULL
);
2946 if (!config
->cluster_iam_master
)
2948 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2949 fmtaddr(config
->cluster_master_address
, 0));
2954 if (argc
!= 3 && argc
!= 5)
2956 cli_error(cli
, "Specify a user and filters");
2960 if (!(s
= sessionbyuser(argv
[0])))
2962 cli_error(cli
, "User %s is not connected", argv
[0]);
2966 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2967 for (i
= 1; i
< argc
; i
+= 2)
2972 if (MATCH("in", argv
[i
]))
2974 if (session
[s
].filter_in
)
2976 cli_error(cli
, "Input already filtered");
2979 f
= &cli_session_actions
[s
].filter_in
;
2981 else if (MATCH("out", argv
[i
]))
2983 if (session
[s
].filter_out
)
2985 cli_error(cli
, "Output already filtered");
2988 f
= &cli_session_actions
[s
].filter_out
;
2992 cli_error(cli
, "Invalid filter specification");
2996 v
= find_filter(argv
[i
+1], strlen(argv
[i
+1]));
2997 if (v
< 0 || !*ip_filters
[v
].name
)
2999 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
3006 cli_print(cli
, "Filtering user %s", argv
[0]);
3007 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
3012 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3017 if (CLI_HELP_REQUESTED
)
3018 return cli_arg_help(cli
, argc
> 1,
3019 "USER", "Username of session to remove filters from", NULL
);
3021 if (!config
->cluster_iam_master
)
3023 cli_error(cli
, "Can't do this on a slave. Do it on %s",
3024 fmtaddr(config
->cluster_master_address
, 0));
3031 cli_error(cli
, "Specify a user to remove filters from");
3035 for (i
= 0; i
< argc
; i
++)
3037 if (!(s
= sessionbyuser(argv
[i
])))
3039 cli_error(cli
, "User %s is not connected", argv
[i
]);
3043 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3045 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3046 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3050 cli_error(cli
, "User %s not filtered", argv
[i
]);
3057 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3061 if (CLI_HELP_REQUESTED
)
3062 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3066 cli_error(cli
, "Specify a filter name");
3070 for (i
= 0; i
< argc
; i
++)
3072 int f
= find_filter(argv
[i
], strlen(argv
[i
]));
3073 ip_filter_rulet
*rules
;
3075 if (f
< 0 || !*ip_filters
[f
].name
)
3077 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3084 cli_print(cli
, "%s IP access list %s",
3085 ip_filters
[f
].extended
? "Extended" : "Standard",
3086 ip_filters
[f
].name
);
3088 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3090 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3092 cli_print(cli
, "%s (%u match%s)", r
,
3093 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3095 cli_print(cli
, "%s", r
);
3102 static int cmd_shutdown(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3104 if (CLI_HELP_REQUESTED
)
3105 return CLI_HELP_NO_ARGS
;
3107 kill(getppid(), SIGQUIT
);
3111 static int cmd_reload(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3113 if (CLI_HELP_REQUESTED
)
3114 return CLI_HELP_NO_ARGS
;
3116 kill(getppid(), SIGHUP
);