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 cli_print(cli
, "\tBytes In/Out:\t%u/%u", session
[s
].cout
, session
[s
].cin
);
447 cli_print(cli
, "\tPkts In/Out:\t%u/%u", session
[s
].pout
, session
[s
].pin
);
448 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
449 cli_print(cli
, "\tRx Speed:\t%u", session
[s
].rx_connect_speed
);
450 cli_print(cli
, "\tTx Speed:\t%u", session
[s
].tx_connect_speed
);
451 if (session
[s
].filter_in
&& session
[s
].filter_in
<= MAXFILTER
)
452 cli_print(cli
, "\tFilter in:\t%u (%s)", session
[s
].filter_in
, ip_filters
[session
[s
].filter_in
- 1].name
);
453 if (session
[s
].filter_out
&& session
[s
].filter_out
<= MAXFILTER
)
454 cli_print(cli
, "\tFilter out:\t%u (%s)", session
[s
].filter_out
, ip_filters
[session
[s
].filter_out
- 1].name
);
455 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
456 cli_print(cli
, "\tIntercepted:\t%s:%d", fmtaddr(session
[s
].snoop_ip
, 0), session
[s
] .snoop_port
);
458 cli_print(cli
, "\tIntercepted:\tno");
460 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
462 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
463 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
464 t
? "YES" : "no", t
? " (" : "",
465 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
467 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
471 b_in
= session
[s
].tbf_in
;
472 b_out
= session
[s
].tbf_out
;
474 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
475 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
476 "ByteSent", "PackSent", "PackDrop", "PackDelay");
479 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
481 (filter_list
[b_in
].next
? "*" : " "),
482 (b_in
< 100 ? "\t" : ""),
483 filter_list
[b_in
].rate
* 8,
484 filter_list
[b_in
].credit
,
485 filter_list
[b_in
].queued
,
486 filter_list
[b_in
].b_queued
,
487 filter_list
[b_in
].p_queued
,
488 filter_list
[b_in
].b_sent
,
489 filter_list
[b_in
].p_sent
,
490 filter_list
[b_in
].p_dropped
,
491 filter_list
[b_in
].p_delayed
);
494 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
496 (filter_list
[b_out
].next
? "*" : " "),
497 (b_out
< 100 ? "\t" : ""),
498 filter_list
[b_out
].rate
* 8,
499 filter_list
[b_out
].credit
,
500 filter_list
[b_out
].queued
,
501 filter_list
[b_out
].b_queued
,
502 filter_list
[b_out
].p_queued
,
503 filter_list
[b_out
].b_sent
,
504 filter_list
[b_out
].p_sent
,
505 filter_list
[b_out
].p_dropped
,
506 filter_list
[b_out
].p_delayed
);
513 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %-15s %s",
529 for (i
= 1; i
< MAXSESSION
; i
++)
531 if (!session
[i
].opened
) continue;
532 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %-15s %s",
535 session
[i
].user
[0] ? session
[i
].user
: "*",
536 fmtaddr(htonl(session
[i
].ip
), 0),
537 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
538 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
539 (session
[i
].walled_garden
) ? "Y" : "N",
540 (session
[i
].ppp
.ipv6cp
== Opened
) ? "Y" : "N",
541 abs(time_now
- (unsigned long)session
[i
].opened
),
542 (unsigned long)session
[i
].cout
,
543 (unsigned long)session
[i
].cin
,
544 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
545 fmtaddr(htonl(tunnel
[ session
[i
].tunnel
].ip
), 1),
546 session
[i
].calling
[0] ? session
[i
].calling
: "*");
551 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
553 int i
, x
, show_all
= 0;
561 if (CLI_HELP_REQUESTED
)
564 return cli_arg_help(cli
, 1,
565 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
568 return cli_arg_help(cli
, 1,
569 "all", "Show all tunnels, including unused",
570 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
577 if (strcmp(argv
[0], "all") == 0)
583 // Show individual tunnel
584 for (i
= 0; i
< argc
; i
++)
589 if (t
<= 0 || t
>= MAXTUNNEL
)
591 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
594 cli_print(cli
, "\r\nTunnel %d:", t
);
595 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
596 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
597 cli_print(cli
, "\tRemote IP:\t%s", fmtaddr(htonl(tunnel
[t
].ip
), 0));
598 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
599 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
600 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
601 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
602 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
603 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
605 for (x
= 0; x
< MAXSESSION
; x
++)
606 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
607 sprintf(s
, "%s%u ", s
, x
);
609 cli_print(cli
, "\tSessions:\t%s", s
);
615 // Show tunnel summary
616 cli_print(cli
, "%4s %20s %20s %6s %s",
623 for (i
= 1; i
< MAXTUNNEL
; i
++)
626 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
628 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
629 cli_print(cli
, "%4d %20s %20s %6s %6d",
631 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
632 fmtaddr(htonl(tunnel
[i
].ip
), 0),
633 states
[tunnel
[i
].state
],
640 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
647 if (CLI_HELP_REQUESTED
)
648 return cli_arg_help(cli
, 1,
649 "USER", "Show details for specific username",
652 for (i
= 0; i
< MAXSESSION
; i
++)
654 if (!session
[i
].opened
) continue;
655 if (!session
[i
].user
[0]) continue;
659 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
661 if (strcmp(argv
[j
], session
[i
].user
) == 0)
663 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
664 sargv
[sargc
] = sid
[sargc
];
672 cli_print(cli
, "%s", session
[i
].user
);
676 return cmd_show_session(cli
, "users", sargv
, sargc
);
682 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
684 if (CLI_HELP_REQUESTED
)
685 return CLI_HELP_NO_ARGS
;
687 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Ethernet", "Bytes", "Packets", "Errors", "Dropped");
688 cli_print(cli
, "%-10s %10u %10u %10u %10u", "RX",
689 GET_STAT(tun_rx_bytes
),
690 GET_STAT(tun_rx_packets
),
691 GET_STAT(tun_rx_errors
),
692 GET_STAT(tun_rx_dropped
));
693 cli_print(cli
, "%-10s %10u %10u %10u", "TX",
694 GET_STAT(tun_tx_bytes
),
695 GET_STAT(tun_tx_packets
),
696 GET_STAT(tun_tx_errors
));
699 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
700 cli_print(cli
, "%-10s %10u %10u %10u", "RX",
701 GET_STAT(tunnel_rx_bytes
),
702 GET_STAT(tunnel_rx_packets
),
703 GET_STAT(tunnel_rx_errors
));
704 cli_print(cli
, "%-10s %10u %10u %10u %10u", "TX",
705 GET_STAT(tunnel_tx_bytes
),
706 GET_STAT(tunnel_tx_packets
),
707 GET_STAT(tunnel_tx_errors
),
708 GET_STAT(tunnel_retries
));
711 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
712 cli_print(cli
, "-----------------------------------------");
713 cli_print(cli
, "%-30s%u", "radius_retries", GET_STAT(radius_retries
));
714 cli_print(cli
, "%-30s%u", "arp_sent", GET_STAT(arp_sent
));
715 cli_print(cli
, "%-30s%u", "packets_snooped", GET_STAT(packets_snooped
));
716 cli_print(cli
, "%-30s%u", "tunnel_created", GET_STAT(tunnel_created
));
717 cli_print(cli
, "%-30s%u", "session_created", GET_STAT(session_created
));
718 cli_print(cli
, "%-30s%u", "tunnel_timeout", GET_STAT(tunnel_timeout
));
719 cli_print(cli
, "%-30s%u", "session_timeout", GET_STAT(session_timeout
));
720 cli_print(cli
, "%-30s%u", "radius_timeout", GET_STAT(radius_timeout
));
721 cli_print(cli
, "%-30s%u", "radius_overflow", GET_STAT(radius_overflow
));
722 cli_print(cli
, "%-30s%u", "tunnel_overflow", GET_STAT(tunnel_overflow
));
723 cli_print(cli
, "%-30s%u", "session_overflow", GET_STAT(session_overflow
));
724 cli_print(cli
, "%-30s%u", "ip_allocated", GET_STAT(ip_allocated
));
725 cli_print(cli
, "%-30s%u", "ip_freed", GET_STAT(ip_freed
));
726 cli_print(cli
, "%-30s%u", "cluster_forwarded", GET_STAT(c_forwarded
));
727 cli_print(cli
, "%-30s%u", "recv_forward", GET_STAT(recv_forward
));
728 cli_print(cli
, "%-30s%u", "select_called", GET_STAT(select_called
));
729 cli_print(cli
, "%-30s%u", "multi_read_used", GET_STAT(multi_read_used
));
730 cli_print(cli
, "%-30s%u", "multi_read_exceeded", GET_STAT(multi_read_exceeded
));
734 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
735 cli_print(cli
, "-----------------------------------------");
736 cli_print(cli
, "%-30s%u", "call_processtun", GET_STAT(call_processtun
));
737 cli_print(cli
, "%-30s%u", "call_processipout", GET_STAT(call_processipout
));
738 cli_print(cli
, "%-30s%u", "call_processipv6out", GET_STAT(call_processipv6out
));
739 cli_print(cli
, "%-30s%u", "call_processudp", GET_STAT(call_processudp
));
740 cli_print(cli
, "%-30s%u", "call_processpap", GET_STAT(call_processpap
));
741 cli_print(cli
, "%-30s%u", "call_processchap", GET_STAT(call_processchap
));
742 cli_print(cli
, "%-30s%u", "call_processlcp", GET_STAT(call_processlcp
));
743 cli_print(cli
, "%-30s%u", "call_processipcp", GET_STAT(call_processipcp
));
744 cli_print(cli
, "%-30s%u", "call_processipv6cp", GET_STAT(call_processipv6cp
));
745 cli_print(cli
, "%-30s%u", "call_processipin", GET_STAT(call_processipin
));
746 cli_print(cli
, "%-30s%u", "call_processipv6in", GET_STAT(call_processipv6in
));
747 cli_print(cli
, "%-30s%u", "call_processccp", GET_STAT(call_processccp
));
748 cli_print(cli
, "%-30s%u", "call_processrad", GET_STAT(call_processrad
));
749 cli_print(cli
, "%-30s%u", "call_sendarp", GET_STAT(call_sendarp
));
750 cli_print(cli
, "%-30s%u", "call_sendipcp", GET_STAT(call_sendipcp
));
751 cli_print(cli
, "%-30s%u", "call_sendchap", GET_STAT(call_sendchap
));
752 cli_print(cli
, "%-30s%u", "call_sessionbyip", GET_STAT(call_sessionbyip
));
753 cli_print(cli
, "%-30s%u", "call_sessionbyipv6", GET_STAT(call_sessionbyipv6
));
754 cli_print(cli
, "%-30s%u", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
755 cli_print(cli
, "%-30s%u", "call_tunnelsend", GET_STAT(call_tunnelsend
));
756 cli_print(cli
, "%-30s%u", "call_tunnelkill", GET_STAT(call_tunnelkill
));
757 cli_print(cli
, "%-30s%u", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
758 cli_print(cli
, "%-30s%u", "call_sessionkill", GET_STAT(call_sessionkill
));
759 cli_print(cli
, "%-30s%u", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
760 cli_print(cli
, "%-30s%u", "call_sessionsetup", GET_STAT(call_sessionsetup
));
761 cli_print(cli
, "%-30s%u", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
762 cli_print(cli
, "%-30s%u", "call_free_ip_address", GET_STAT(call_free_ip_address
));
763 cli_print(cli
, "%-30s%u", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
764 cli_print(cli
, "%-30s%u", "call_radiussend", GET_STAT(call_radiussend
));
765 cli_print(cli
, "%-30s%u", "call_radiusretry", GET_STAT(call_radiusretry
));
766 cli_print(cli
, "%-30s%u", "call_random_data", GET_STAT(call_random_data
));
767 #endif /* STAT_CALLS */
770 time_t l
= GET_STAT(last_reset
);
772 char *p
= strchr(t
, '\n');
776 cli_print(cli
, "Last counter reset %s", t
);
782 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
784 if (CLI_HELP_REQUESTED
)
785 return CLI_HELP_NO_ARGS
;
787 memset(_statistics
, 0, sizeof(struct Tstats
));
788 SET_STAT(last_reset
, time(NULL
));
790 cli_print(cli
, "Counters cleared");
793 #endif /* STATISTICS */
795 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
801 if (CLI_HELP_REQUESTED
)
802 return cli_arg_help(cli
, 1,
803 "tag", "Include CVS release tag",
804 "file", "Include file versions",
807 for (i
= 0; i
< argc
; i
++)
808 if (!strcmp(argv
[i
], "tag"))
810 else if (!strcmp(argv
[i
], "file"))
813 cli_print(cli
, "L2TPNS %s", VERSION
);
816 char const *p
= strchr(cvs_name
, ':');
828 e
= strpbrk(p
, " \t$");
829 cli_print(cli
, "Tag: %.*s", (int) (e
? e
- p
+ 1 : strlen(p
)), p
);
834 extern linked_list
*loaded_plugins
;
837 cli_print(cli
, "Files:");
838 cli_print(cli
, " %s", cvs_id_arp
);
840 cli_print(cli
, " %s", cvs_id_bgp
);
842 cli_print(cli
, " %s", cvs_id_cli
);
843 cli_print(cli
, " %s", cvs_id_cluster
);
844 cli_print(cli
, " %s", cvs_id_constants
);
845 cli_print(cli
, " %s", cvs_id_control
);
846 cli_print(cli
, " %s", cvs_id_icmp
);
847 cli_print(cli
, " %s", cvs_id_l2tpns
);
848 cli_print(cli
, " %s", cvs_id_ll
);
849 cli_print(cli
, " %s", cvs_id_ppp
);
850 cli_print(cli
, " %s", cvs_id_radius
);
851 cli_print(cli
, " %s", cvs_id_tbf
);
852 cli_print(cli
, " %s", cvs_id_util
);
854 ll_reset(loaded_plugins
);
855 while ((p
= ll_next(loaded_plugins
)))
857 char const **id
= dlsym(p
, "cvs_id");
859 cli_print(cli
, " %s", *id
);
866 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
869 int used
= 0, free
= 0, show_all
= 0;
871 if (!config
->cluster_iam_master
)
873 cli_print(cli
, "Can't do this on a slave. Do it on %s",
874 fmtaddr(config
->cluster_master_address
, 0));
879 if (CLI_HELP_REQUESTED
)
882 return cli_arg_help(cli
, 1, NULL
);
884 return cli_arg_help(cli
, 1,
885 "all", "Show all pool addresses, including unused",
889 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
893 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
894 for (i
= 0; i
< MAXIPPOOL
; i
++)
896 if (!ip_address_pool
[i
].address
) continue;
897 if (ip_address_pool
[i
].assigned
)
899 cli_print(cli
, "%-15s\tY %8d %s",
900 fmtaddr(htonl(ip_address_pool
[i
].address
), 0),
901 ip_address_pool
[i
].session
,
902 session
[ip_address_pool
[i
].session
].user
);
908 if (ip_address_pool
[i
].last
)
909 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
910 fmtaddr(htonl(ip_address_pool
[i
].address
), 0), "",
911 ip_address_pool
[i
].user
, (int) time_now
- ip_address_pool
[i
].last
);
914 cli_print(cli
, "%-15s\tN", fmtaddr(htonl(ip_address_pool
[i
].address
), 0));
921 cli_print(cli
, "(Not displaying unused addresses)");
923 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
927 static FILE *save_config_fh
= 0;
928 static void print_save_config(struct cli_def
*cli
, char *string
)
931 fprintf(save_config_fh
, "%s\n", string
);
934 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
936 if (CLI_HELP_REQUESTED
)
937 return CLI_HELP_NO_ARGS
;
939 if ((save_config_fh
= fopen(config
->config_file
, "w")))
941 cli_print(cli
, "Writing configuration");
942 cli_print_callback(cli
, print_save_config
);
943 cmd_show_run(cli
, command
, argv
, argc
);
944 cli_print_callback(cli
, NULL
);
945 fclose(save_config_fh
);
950 cli_error(cli
, "Error writing configuration: %s", strerror(errno
));
955 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
);
957 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
960 char ipv6addr
[INET6_ADDRSTRLEN
];
962 if (CLI_HELP_REQUESTED
)
963 return CLI_HELP_NO_ARGS
;
965 cli_print(cli
, "# Current configuration:");
967 for (i
= 0; config_values
[i
].key
; i
++)
969 void *value
= ((void *)config
) + config_values
[i
].offset
;
970 if (config_values
[i
].type
== STRING
)
971 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *) value
);
972 else if (config_values
[i
].type
== IPv4
)
973 cli_print(cli
, "set %s %s", config_values
[i
].key
, fmtaddr(*(in_addr_t
*) value
, 0));
974 else if (config_values
[i
].type
== IPv6
)
975 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_ntop(AF_INET6
, value
, ipv6addr
, INET6_ADDRSTRLEN
));
976 else if (config_values
[i
].type
== SHORT
)
977 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *) value
);
978 else if (config_values
[i
].type
== BOOL
)
979 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *) value
) ? "yes" : "no");
980 else if (config_values
[i
].type
== INT
)
981 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *) value
);
982 else if (config_values
[i
].type
== UNSIGNED_LONG
)
983 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *) value
);
986 cli_print(cli
, "# Plugins");
987 for (i
= 0; i
< MAXPLUGINS
; i
++)
989 if (*config
->plugins
[i
])
991 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
996 if (config
->as_number
)
1001 cli_print(cli
, "# BGP");
1002 cli_print(cli
, "router bgp %u", config
->as_number
);
1003 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1005 if (!config
->neighbour
[i
].name
[0])
1008 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
1010 k
= config
->neighbour
[i
].keepalive
;
1011 h
= config
->neighbour
[i
].hold
;
1018 k
= BGP_KEEPALIVE_TIME
;
1024 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
1029 cli_print(cli
, "# Filters");
1030 for (i
= 0; i
< MAXFILTER
; i
++)
1032 ip_filter_rulet
*rules
;
1033 if (!*ip_filters
[i
].name
)
1036 cli_print(cli
, "ip access-list %s %s",
1037 ip_filters
[i
].extended
? "extended" : "standard",
1038 ip_filters
[i
].name
);
1040 rules
= ip_filters
[i
].rules
;
1041 while (rules
->action
)
1042 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1045 cli_print(cli
, "# end");
1049 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1051 int i
, free
= 0, used
= 0, show_all
= 0;
1063 if (CLI_HELP_REQUESTED
)
1066 return cli_arg_help(cli
, 1, NULL
);
1068 return cli_arg_help(cli
, 1,
1069 "all", "Show all RADIUS sessions, including unused",
1073 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1077 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1080 for (i
= 1; i
< MAXRADIUS
; i
++)
1082 if (radius
[i
].state
== RADIUSNULL
)
1087 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1089 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1093 states
[radius
[i
].state
],
1099 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1104 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1108 if (CLI_HELP_REQUESTED
)
1109 return CLI_HELP_NO_ARGS
;
1111 cli_print(cli
, "Plugins currently loaded:");
1112 for (i
= 0; i
< MAXPLUGINS
; i
++)
1113 if (*config
->plugins
[i
])
1114 cli_print(cli
, " %s", config
->plugins
[i
]);
1119 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1123 if (CLI_HELP_REQUESTED
)
1124 return CLI_HELP_NO_ARGS
;
1126 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1135 for (i
= 0; i
< MAXSESSION
; i
++)
1137 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1138 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1142 session
[i
].throttle_in
,
1143 session
[i
].throttle_out
,
1145 session
[i
].tbf_out
);
1151 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1153 if (CLI_HELP_REQUESTED
)
1154 return CLI_HELP_NO_ARGS
;
1156 cli_print(cli
, " _\n"
1162 " ( \\ `. `-. _,.-:\\\n"
1163 " \\ \\ `. `-._ __..--' ,-';/\n"
1164 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1165 " `. `. `-._ __..--' ,' /\n"
1166 " `. `-_ ``--..'' _.-' ,'\n"
1167 " `-_ `-.___ __,--' ,'\n"
1168 " `-.__ `----\"\"\" __.-'\n"
1169 "hh `--..____..--'");
1174 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1179 if (CLI_HELP_REQUESTED
)
1180 return cli_arg_help(cli
, argc
> 1,
1181 "USER", "Username of session to drop", NULL
);
1183 if (!config
->cluster_iam_master
)
1185 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1186 fmtaddr(config
->cluster_master_address
, 0));
1193 cli_error(cli
, "Specify a user to drop");
1197 for (i
= 0; i
< argc
; i
++)
1199 if (!(s
= sessionbyuser(argv
[i
])))
1201 cli_error(cli
, "User %s is not connected", argv
[i
]);
1205 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1207 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1208 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1215 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1220 if (CLI_HELP_REQUESTED
)
1221 return cli_arg_help(cli
, argc
> 1,
1222 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1224 if (!config
->cluster_iam_master
)
1226 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1227 fmtaddr(config
->cluster_master_address
, 0));
1234 cli_error(cli
, "Specify a tunnel to drop");
1238 for (i
= 0; i
< argc
; i
++)
1240 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1242 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1248 cli_error(cli
, "Tunnel %d is not connected", t
);
1254 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1258 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1259 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1265 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1270 if (CLI_HELP_REQUESTED
)
1271 return cli_arg_help(cli
, argc
> 1,
1272 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1274 if (!config
->cluster_iam_master
)
1276 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1277 fmtaddr(config
->cluster_master_address
, 0));
1284 cli_error(cli
, "Specify a session id to drop");
1288 for (i
= 0; i
< argc
; i
++)
1290 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1292 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1296 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1298 cli_print(cli
, "Dropping session %d", s
);
1299 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1303 cli_error(cli
, "Session %d is not active.", s
);
1310 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1316 if (CLI_HELP_REQUESTED
)
1321 return cli_arg_help(cli
, 0,
1322 "USER", "Username of session to snoop", NULL
);
1325 return cli_arg_help(cli
, 0,
1326 "A.B.C.D", "IP address of snoop destination", NULL
);
1329 return cli_arg_help(cli
, 0,
1330 "N", "Port of snoop destination", NULL
);
1334 return cli_arg_help(cli
, 1, NULL
);
1341 if (!config
->cluster_iam_master
)
1343 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1344 fmtaddr(config
->cluster_master_address
, 0));
1351 cli_error(cli
, "Specify username, ip and port");
1355 if (!(s
= sessionbyuser(argv
[0])))
1357 cli_error(cli
, "User %s is not connected", argv
[0]);
1361 ip
= inet_addr(argv
[1]);
1362 if (!ip
|| ip
== INADDR_NONE
)
1364 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1368 port
= atoi(argv
[2]);
1371 cli_error(cli
, "Invalid port %s", argv
[2]);
1375 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1376 cli_session_actions
[s
].snoop_ip
= ip
;
1377 cli_session_actions
[s
].snoop_port
= port
;
1378 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1383 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1388 if (CLI_HELP_REQUESTED
)
1389 return cli_arg_help(cli
, argc
> 1,
1390 "USER", "Username of session to unsnoop", NULL
);
1392 if (!config
->cluster_iam_master
)
1394 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1395 fmtaddr(config
->cluster_master_address
, 0));
1402 cli_error(cli
, "Specify a user to unsnoop");
1406 for (i
= 0; i
< argc
; i
++)
1408 if (!(s
= sessionbyuser(argv
[i
])))
1410 cli_error(cli
, "User %s is not connected", argv
[i
]);
1414 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1415 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1421 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1428 throttle USER - throttle in/out to default rate
1429 throttle USER RATE - throttle in/out to default rate
1430 throttle USER in RATE - throttle input only
1431 throttle USER out RATE - throttle output only
1432 throttle USER in RATE out RATE - throttle both
1435 if (CLI_HELP_REQUESTED
)
1440 return cli_arg_help(cli
, 0,
1441 "USER", "Username of session to throttle", NULL
);
1444 return cli_arg_help(cli
, 1,
1445 "RATE", "Rate in kbps (in and out)",
1446 "in", "Select incoming rate",
1447 "out", "Select outgoing rate", NULL
);
1450 return cli_arg_help(cli
, 1,
1451 "in", "Select incoming rate",
1452 "out", "Select outgoing rate", NULL
);
1455 if (isdigit(argv
[1][0]))
1456 return cli_arg_help(cli
, 1, NULL
);
1459 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1462 return cli_arg_help(cli
, argc
> 1, NULL
);
1466 if (!config
->cluster_iam_master
)
1468 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1469 fmtaddr(config
->cluster_master_address
, 0));
1476 cli_error(cli
, "Specify a user to throttle");
1480 if (!(s
= sessionbyuser(argv
[0])))
1482 cli_error(cli
, "User %s is not connected", argv
[0]);
1488 rate_in
= rate_out
= config
->rl_rate
;
1492 rate_in
= rate_out
= atoi(argv
[1]);
1495 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1499 else if (argc
== 3 || argc
== 5)
1502 for (i
= 1; i
< argc
- 1; i
+= 2)
1505 if (MATCH("in", argv
[i
]))
1506 r
= rate_in
= atoi(argv
[i
+1]);
1507 else if (MATCH("out", argv
[i
]))
1508 r
= rate_out
= atoi(argv
[i
+1]);
1512 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1519 cli_error(cli
, "Invalid arguments");
1523 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1525 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1529 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1530 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1531 cli_session_actions
[s
].throttle_in
= rate_in
;
1533 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1534 cli_session_actions
[s
].throttle_out
= rate_out
;
1536 if (cli_session_actions
[s
].throttle_in
== -1 &&
1537 cli_session_actions
[s
].throttle_out
== -1)
1539 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1543 cli_print(cli
, "Throttling user %s", argv
[0]);
1544 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1549 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1554 if (CLI_HELP_REQUESTED
)
1555 return cli_arg_help(cli
, argc
> 1,
1556 "USER", "Username of session to unthrottle", NULL
);
1558 if (!config
->cluster_iam_master
)
1560 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1561 fmtaddr(config
->cluster_master_address
, 0));
1568 cli_error(cli
, "Specify a user to unthrottle");
1572 for (i
= 0; i
< argc
; i
++)
1574 if (!(s
= sessionbyuser(argv
[i
])))
1576 cli_error(cli
, "User %s is not connected", argv
[i
]);
1580 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1582 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1583 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1587 cli_error(cli
, "User %s not throttled", argv
[i
]);
1594 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1598 if (CLI_HELP_REQUESTED
)
1599 return cli_arg_help(cli
, 1,
1600 "all", "Enable debugging for all except \"data\"",
1601 "critical", "", // FIXME: add descriptions
1611 char *p
= (char *) &debug_flags
;
1612 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1616 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1617 (debug_flags
.critical
) ? " critical" : "",
1618 (debug_flags
.error
) ? " error" : "",
1619 (debug_flags
.warning
) ? " warning" : "",
1620 (debug_flags
.info
) ? " info" : "",
1621 (debug_flags
.calls
) ? " calls" : "",
1622 (debug_flags
.data
) ? " data" : "");
1628 cli_print(cli
, "Debugging off");
1632 for (i
= 0; i
< argc
; i
++)
1634 int len
= strlen(argv
[i
]);
1636 if (argv
[i
][0] == 'c' && len
< 2)
1637 len
= 2; /* distinguish [cr]itical from [ca]lls */
1639 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1640 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1641 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1642 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1643 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1644 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1645 if (!strncmp("all", argv
[i
], len
))
1647 memset(&debug_flags
, 1, sizeof(debug_flags
));
1648 debug_flags
.data
= 0;
1652 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1658 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1662 if (CLI_HELP_REQUESTED
)
1663 return cli_arg_help(cli
, 1,
1664 "all", "Disable all debugging",
1665 "critical", "", // FIXME: add descriptions
1675 memset(&debug_flags
, 0, sizeof(debug_flags
));
1679 for (i
= 0; i
< argc
; i
++)
1681 int len
= strlen(argv
[i
]);
1683 if (argv
[i
][0] == 'c' && len
< 2)
1684 len
= 2; /* distinguish [cr]itical from [ca]lls */
1686 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1687 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1688 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1689 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1690 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1691 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1692 if (!strncmp("all", argv
[i
], len
))
1694 memset(&debug_flags
, 0, sizeof(debug_flags
));
1698 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1704 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1706 int i
, firstfree
= 0;
1708 if (CLI_HELP_REQUESTED
)
1709 return cli_arg_help(cli
, argc
> 1,
1710 "PLUGIN", "Name of plugin to load", NULL
);
1714 cli_error(cli
, "Specify a plugin to load");
1718 for (i
= 0; i
< MAXPLUGINS
; i
++)
1720 if (!*config
->plugins
[i
] && !firstfree
)
1722 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1724 cli_error(cli
, "Plugin is already loaded");
1731 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1732 config
->reload_config
= 1;
1733 cli_print(cli
, "Loading plugin %s", argv
[0]);
1739 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1743 if (CLI_HELP_REQUESTED
)
1744 return cli_arg_help(cli
, argc
> 1,
1745 "PLUGIN", "Name of plugin to unload", NULL
);
1749 cli_error(cli
, "Specify a plugin to remove");
1753 for (i
= 0; i
< MAXPLUGINS
; i
++)
1755 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1757 config
->reload_config
= 1;
1758 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1763 cli_error(cli
, "Plugin is not loaded");
1767 static char *duration(time_t secs
)
1769 static char *buf
= NULL
;
1772 if (!buf
) buf
= calloc(64, 1);
1776 int days
= secs
/ 86400;
1777 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1783 int mins
= secs
/ 60;
1784 int hrs
= mins
/ 60;
1787 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1789 else if (secs
>= 60)
1791 int mins
= secs
/ 60;
1792 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1795 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1800 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1803 char buf
[100], *p
= buf
, *loads
[3];
1804 int i
, num_sessions
= 0;
1806 if (CLI_HELP_REQUESTED
)
1807 return CLI_HELP_NO_ARGS
;
1809 fh
= fopen("/proc/loadavg", "r");
1810 fgets(buf
, 100, fh
);
1813 for (i
= 0; i
< 3; i
++)
1814 loads
[i
] = strdup(strsep(&p
, " "));
1817 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1819 for (i
= 1; i
< MAXSESSION
; i
++)
1820 if (session
[i
].opened
) num_sessions
++;
1822 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1824 duration(time_now
- config
->start_time
),
1826 loads
[0], loads
[1], loads
[2]
1828 for (i
= 0; i
< 3; i
++)
1829 if (loads
[i
]) free(loads
[i
]);
1831 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1836 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1840 if (CLI_HELP_REQUESTED
)
1846 int len
= strlen(argv
[0])-1;
1847 for (i
= 0; config_values
[i
].key
; i
++)
1848 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1849 cli_error(cli
, " %s", config_values
[i
].key
);
1855 return cli_arg_help(cli
, 0,
1856 "VALUE", "Value for variable", NULL
);
1860 return cli_arg_help(cli
, 1, NULL
);
1869 cli_error(cli
, "Specify variable and value");
1873 for (i
= 0; config_values
[i
].key
; i
++)
1875 void *value
= ((void *) config
) + config_values
[i
].offset
;
1876 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1878 // Found a value to set
1879 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1880 switch (config_values
[i
].type
)
1883 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1886 *(int *) value
= atoi(argv
[1]);
1889 *(unsigned long *) value
= atol(argv
[1]);
1892 *(short *) value
= atoi(argv
[1]);
1895 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1898 inet_pton(AF_INET6
, argv
[1], value
);
1901 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1907 cli_error(cli
, "Unknown variable type");
1910 config
->reload_config
= 1;
1915 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1919 int regular_stuff(struct cli_def
*cli
)
1925 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1927 char *m
= ringbuffer
->buffer
[i
].message
;
1933 switch (ringbuffer
->buffer
[i
].level
)
1935 case 0: show
= debug_flags
.critical
; break;
1936 case 1: show
= debug_flags
.error
; break;
1937 case 2: show
= debug_flags
.warning
; break;
1938 case 3: show
= debug_flags
.info
; break;
1939 case 4: show
= debug_flags
.calls
; break;
1940 case 5: show
= debug_flags
.data
; break;
1943 if (!show
) continue;
1945 if (!(p
= strchr(m
, '\n')))
1948 cli_error(cli
, "\r%s-%u-%u %.*s",
1949 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1950 ringbuffer
->buffer
[i
].tunnel
,
1951 ringbuffer
->buffer
[i
].session
,
1957 debug_rb_tail
= ringbuffer
->tail
;
1965 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1969 if (CLI_HELP_REQUESTED
)
1970 return cli_arg_help(cli
, argc
> 1,
1971 "<1-65535>", "Autonomous system number", NULL
);
1973 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1975 cli_error(cli
, "Invalid autonomous system number");
1979 if (bgp_configured
&& as
!= config
->as_number
)
1981 cli_error(cli
, "Can't change local AS on a running system");
1985 config
->as_number
= as
;
1986 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
1991 static int find_bgp_neighbour(char const *name
)
1996 in_addr_t addrs
[4] = { 0 };
1999 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
2002 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
2003 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
2005 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2007 if (!config
->neighbour
[i
].name
[0])
2009 if (new == -1) new = i
;
2013 if (!strcmp(name
, config
->neighbour
[i
].name
))
2016 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
2019 for (a
= h
->h_addr_list
; *a
; a
++)
2022 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2023 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2031 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2037 if (CLI_HELP_REQUESTED
)
2042 return cli_arg_help(cli
, 0,
2043 "A.B.C.D", "BGP neighbour address",
2044 "NAME", "BGP neighbour name",
2048 return cli_arg_help(cli
, 0,
2049 "remote-as", "Set remote autonomous system number",
2050 "timers", "Set timers",
2054 if (MATCH("remote-as", argv
[1]))
2055 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2057 if (MATCH("timers", argv
[1]))
2060 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2063 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2065 if (argc
== 5 && !argv
[4][1])
2066 return cli_arg_help(cli
, 1, NULL
);
2075 cli_error(cli
, "Invalid arguments");
2079 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2081 cli_error(cli
, "Invalid neighbour");
2087 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2091 if (MATCH("remote-as", argv
[1]))
2093 int as
= atoi(argv
[2]);
2094 if (as
< 0 || as
> 65535)
2096 cli_error(cli
, "Invalid autonomous system number");
2100 if (!config
->neighbour
[i
].name
[0])
2102 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2103 config
->neighbour
[i
].keepalive
= -1;
2104 config
->neighbour
[i
].hold
= -1;
2107 config
->neighbour
[i
].as
= as
;
2111 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2113 cli_error(cli
, "Invalid arguments");
2117 if (!config
->neighbour
[i
].name
[0])
2119 cli_error(cli
, "Specify remote-as first");
2123 keepalive
= atoi(argv
[2]);
2124 hold
= atoi(argv
[3]);
2126 if (keepalive
< 1 || keepalive
> 65535)
2128 cli_error(cli
, "Invalid keepalive time");
2132 if (hold
< 3 || hold
> 65535)
2134 cli_error(cli
, "Invalid hold time");
2138 if (keepalive
== BGP_KEEPALIVE_TIME
)
2139 keepalive
= -1; // using default value
2141 if (hold
== BGP_HOLD_TIME
)
2144 config
->neighbour
[i
].keepalive
= keepalive
;
2145 config
->neighbour
[i
].hold
= hold
;
2150 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2154 if (CLI_HELP_REQUESTED
)
2155 return cli_arg_help(cli
, argc
> 0,
2156 "A.B.C.D", "BGP neighbour address",
2157 "NAME", "BGP neighbour name",
2162 cli_error(cli
, "Specify a BGP neighbour");
2166 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2168 cli_error(cli
, "Invalid neighbour");
2172 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2174 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2178 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2182 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2188 if (!bgp_configured
)
2191 if (CLI_HELP_REQUESTED
)
2192 return cli_arg_help(cli
, 1,
2193 "A.B.C.D", "BGP neighbour address",
2194 "NAME", "BGP neighbour name",
2197 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2198 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2202 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2204 if (!*bgp_peers
[i
].name
)
2207 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2208 if (argc
&& strcmp(addr
, argv
[0]) &&
2209 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2215 cli_print(cli
, "Peer AS Address "
2216 "State Retries Retry in Route Pend Timers");
2217 cli_print(cli
, "------------------ ----- --------------- "
2218 "----------- ------- -------- ----- ---- ---------");
2221 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2225 bgp_state_str(bgp_peers
[i
].state
),
2226 bgp_peers
[i
].retry_count
,
2227 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2228 bgp_peers
[i
].routing
? "yes" : "no",
2229 bgp_peers
[i
].update_routes
? "yes" : "no",
2230 bgp_peers
[i
].keepalive
,
2237 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2242 if (!bgp_configured
)
2245 if (CLI_HELP_REQUESTED
)
2246 return cli_arg_help(cli
, 1,
2247 "A.B.C.D", "BGP neighbour address",
2248 "NAME", "BGP neighbour name",
2251 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2253 if (bgp_peers
[i
].state
!= Established
)
2256 if (!bgp_peers
[i
].routing
)
2259 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2260 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2263 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2264 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2270 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2275 if (!bgp_configured
)
2278 if (CLI_HELP_REQUESTED
)
2279 return cli_arg_help(cli
, 1,
2280 "A.B.C.D", "BGP neighbour address",
2281 "NAME", "BGP neighbour name",
2284 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2286 if (bgp_peers
[i
].state
!= Established
)
2289 if (bgp_peers
[i
].routing
)
2292 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2293 if (argc
&& strcmp(addr
, argv
[0]) &&
2294 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2297 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2298 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2304 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2309 if (!bgp_configured
)
2312 if (CLI_HELP_REQUESTED
)
2313 return cli_arg_help(cli
, 1,
2314 "A.B.C.D", "BGP neighbour address",
2315 "NAME", "BGP neighbour name",
2318 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2320 if (!*bgp_peers
[i
].name
)
2323 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2324 if (argc
&& strcmp(addr
, argv
[0]) &&
2325 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2328 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2329 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2337 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2341 if (CLI_HELP_REQUESTED
)
2346 return cli_arg_help(cli
, 0,
2347 "standard", "Standard syntax",
2348 "extended", "Extended syntax",
2352 return cli_arg_help(cli
, argv
[1][1],
2353 "NAME", "Access-list name",
2357 if (argc
== 3 && !argv
[2][1])
2358 return cli_arg_help(cli
, 1, NULL
);
2366 cli_error(cli
, "Specify access-list type and name");
2370 if (MATCH("standard", argv
[0]))
2372 else if (MATCH("extended", argv
[0]))
2376 cli_error(cli
, "Invalid access-list type");
2380 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2381 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2383 cli_error(cli
, "Invalid access-list name");
2387 filt
= find_filter(argv
[1], strlen(argv
[1]));
2392 cli_error(cli
, "Too many access-lists");
2397 if (!*ip_filters
[filt
].name
)
2399 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2400 strcpy(ip_filters
[filt
].name
, argv
[1]);
2401 ip_filters
[filt
].extended
= extended
;
2403 else if (ip_filters
[filt
].extended
!= extended
)
2405 cli_error(cli
, "Access-list is %s",
2406 ip_filters
[filt
].extended
? "extended" : "standard");
2411 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2415 if (filt
< 0 || !*ip_filters
[filt
].name
)
2417 cli_error(cli
, "Access-list not defined");
2422 if (ip_filters
[filt
].used
)
2424 cli_error(cli
, "Access-list in use");
2428 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2432 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2434 return access_list(cli
, argv
, argc
, 1);
2437 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2439 return access_list(cli
, argv
, argc
, 0);
2442 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2444 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2445 return sprintf(buf
, " any");
2447 if (wild
== INADDR_ANY
)
2448 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2450 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2453 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2457 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2458 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2459 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2460 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2461 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2467 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2469 static char buf
[256];
2472 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2475 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2476 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2479 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2483 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2484 p
+= show_ports(p
, &rule
->src_ports
);
2486 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2487 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2488 p
+= show_ports(p
, &rule
->dst_ports
);
2490 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2492 switch (rule
->tcp_flag_op
)
2494 case FILTER_FLAG_OP_EST
:
2495 p
+= sprintf(p
, " established");
2498 case FILTER_FLAG_OP_ANY
:
2499 case FILTER_FLAG_OP_ALL
:
2500 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2501 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2502 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2503 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2504 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2505 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2506 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2507 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2508 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2509 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2510 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2511 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2512 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2518 p
+= sprintf(p
, " fragments");
2523 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2525 static ip_filter_rulet rule
;
2526 struct in_addr addr
;
2530 if (CLI_HELP_REQUESTED
)
2534 cli_arg_help(cli
, 0,
2535 "ip", "Match IP packets",
2536 "tcp", "Match TCP packets",
2537 "udp", "Match UDP packets",
2543 // *sigh*, too darned complex
2544 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2550 cli_error(cli
, "Specify rule details");
2554 memset(&rule
, 0, sizeof(rule
));
2555 rule
.action
= (command
[0] == 'p')
2556 ? FILTER_ACTION_PERMIT
2557 : FILTER_ACTION_DENY
;
2559 if (MATCH("ip", argv
[0]))
2560 rule
.proto
= IPPROTO_IP
;
2561 else if (MATCH("udp", argv
[0]))
2562 rule
.proto
= IPPROTO_UDP
;
2563 else if (MATCH("tcp", argv
[0]))
2564 rule
.proto
= IPPROTO_TCP
;
2567 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2571 for (a
= 1, i
= 0; i
< 2; i
++)
2575 ip_filter_portt
*port
;
2580 wild
= &rule
.src_wild
;
2581 port
= &rule
.src_ports
;
2586 wild
= &rule
.dst_wild
;
2587 port
= &rule
.dst_ports
;
2590 cli_error(cli
, "Specify destination");
2595 if (MATCH("any", argv
[a
]))
2598 *wild
= INADDR_BROADCAST
;
2601 else if (MATCH("host", argv
[a
]))
2605 cli_error(cli
, "Specify host ip address");
2609 if (!inet_aton(argv
[a
], &addr
))
2611 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2623 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2627 if (!inet_aton(argv
[a
], &addr
))
2629 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2635 if (!inet_aton(argv
[++a
], &addr
))
2637 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2641 *wild
= addr
.s_addr
;
2645 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2649 if (MATCH("eq", argv
[a
]))
2650 port
->op
= FILTER_PORT_OP_EQ
;
2651 else if (MATCH("neq", argv
[a
]))
2652 port
->op
= FILTER_PORT_OP_NEQ
;
2653 else if (MATCH("gt", argv
[a
]))
2654 port
->op
= FILTER_PORT_OP_GT
;
2655 else if (MATCH("lt", argv
[a
]))
2656 port
->op
= FILTER_PORT_OP_LT
;
2657 else if (MATCH("range", argv
[a
]))
2658 port
->op
= FILTER_PORT_OP_RANGE
;
2665 cli_error(cli
, "Specify port");
2669 if (!(port
->port
= atoi(argv
[a
])))
2671 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2676 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2681 cli_error(cli
, "Specify port");
2685 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2687 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2694 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2696 if (MATCH("established", argv
[a
]))
2698 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2701 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2702 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2704 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2705 ? FILTER_FLAG_OP_ANY
2706 : FILTER_FLAG_OP_ALL
;
2710 cli_error(cli
, "Specify tcp flags");
2714 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2718 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2720 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2721 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2722 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2723 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2724 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2725 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2728 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2737 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2739 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2741 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2751 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2758 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2760 static ip_filter_rulet rule
;
2761 struct in_addr addr
;
2763 if (CLI_HELP_REQUESTED
)
2767 cli_arg_help(cli
, argv
[0][1],
2768 "A.B.C.D", "Source address",
2769 "any", "Any source address",
2770 "host", "Source host",
2776 if (MATCH("any", argv
[0]))
2778 if (argc
== 2 && !argv
[1][1])
2779 cli_arg_help(cli
, 1, NULL
);
2781 else if (MATCH("host", argv
[0]))
2785 cli_arg_help(cli
, argv
[1][1],
2786 "A.B.C.D", "Host address",
2789 else if (argc
== 3 && !argv
[2][1])
2790 cli_arg_help(cli
, 1, NULL
);
2796 cli_arg_help(cli
, 1,
2797 "A.B.C.D", "Wildcard bits",
2800 else if (argc
== 3 && !argv
[2][1])
2801 cli_arg_help(cli
, 1, NULL
);
2809 cli_error(cli
, "Specify rule details");
2813 memset(&rule
, 0, sizeof(rule
));
2814 rule
.action
= (command
[0] == 'p')
2815 ? FILTER_ACTION_PERMIT
2816 : FILTER_ACTION_DENY
;
2818 rule
.proto
= IPPROTO_IP
;
2819 if (MATCH("any", argv
[0]))
2821 rule
.src_ip
= INADDR_ANY
;
2822 rule
.src_wild
= INADDR_BROADCAST
;
2824 else if (MATCH("host", argv
[0]))
2828 cli_error(cli
, "Specify host ip address");
2832 if (!inet_aton(argv
[1], &addr
))
2834 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2838 rule
.src_ip
= addr
.s_addr
;
2839 rule
.src_wild
= INADDR_ANY
;
2845 cli_error(cli
, "Specify source ip address and wildcard");
2849 if (!inet_aton(argv
[0], &addr
))
2851 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2855 rule
.src_ip
= addr
.s_addr
;
2859 if (!inet_aton(argv
[1], &addr
))
2861 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2865 rule
.src_wild
= addr
.s_addr
;
2868 rule
.src_wild
= INADDR_ANY
;
2874 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2877 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2878 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2879 : access_list_rule_std(cli
, command
, argv
, argc
);
2884 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2886 if (!ip_filters
[filt
].rules
[i
].action
)
2888 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2892 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, offsetof(ip_filter_rulet
, counter
)))
2896 cli_error(cli
, "Too many rules");
2900 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2905 /* filter USER {in|out} FILTER ... */
2906 if (CLI_HELP_REQUESTED
)
2911 return cli_arg_help(cli
, 0,
2912 "USER", "Username of session to filter", NULL
);
2916 return cli_arg_help(cli
, 0,
2917 "in", "Set incoming filter",
2918 "out", "Set outgoing filter", NULL
);
2922 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2923 "NAME", "Filter name", NULL
);
2926 return cli_arg_help(cli
, argc
> 1, NULL
);
2930 if (!config
->cluster_iam_master
)
2932 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2933 fmtaddr(config
->cluster_master_address
, 0));
2938 if (argc
!= 3 && argc
!= 5)
2940 cli_error(cli
, "Specify a user and filters");
2944 if (!(s
= sessionbyuser(argv
[0])))
2946 cli_error(cli
, "User %s is not connected", argv
[0]);
2950 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2951 for (i
= 1; i
< argc
; i
+= 2)
2956 if (MATCH("in", argv
[i
]))
2958 if (session
[s
].filter_in
)
2960 cli_error(cli
, "Input already filtered");
2963 f
= &cli_session_actions
[s
].filter_in
;
2965 else if (MATCH("out", argv
[i
]))
2967 if (session
[s
].filter_out
)
2969 cli_error(cli
, "Output already filtered");
2972 f
= &cli_session_actions
[s
].filter_out
;
2976 cli_error(cli
, "Invalid filter specification");
2980 v
= find_filter(argv
[i
+1], strlen(argv
[i
+1]));
2981 if (v
< 0 || !*ip_filters
[v
].name
)
2983 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
2990 cli_print(cli
, "Filtering user %s", argv
[0]);
2991 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
2996 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3001 if (CLI_HELP_REQUESTED
)
3002 return cli_arg_help(cli
, argc
> 1,
3003 "USER", "Username of session to remove filters from", NULL
);
3005 if (!config
->cluster_iam_master
)
3007 cli_error(cli
, "Can't do this on a slave. Do it on %s",
3008 fmtaddr(config
->cluster_master_address
, 0));
3015 cli_error(cli
, "Specify a user to remove filters from");
3019 for (i
= 0; i
< argc
; i
++)
3021 if (!(s
= sessionbyuser(argv
[i
])))
3023 cli_error(cli
, "User %s is not connected", argv
[i
]);
3027 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3029 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3030 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3034 cli_error(cli
, "User %s not filtered", argv
[i
]);
3041 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3045 if (CLI_HELP_REQUESTED
)
3046 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3050 cli_error(cli
, "Specify a filter name");
3054 for (i
= 0; i
< argc
; i
++)
3056 int f
= find_filter(argv
[i
], strlen(argv
[i
]));
3057 ip_filter_rulet
*rules
;
3059 if (f
< 0 || !*ip_filters
[f
].name
)
3061 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3068 cli_print(cli
, "%s IP access list %s",
3069 ip_filters
[f
].extended
? "Extended" : "Standard",
3070 ip_filters
[f
].name
);
3072 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3074 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3076 cli_print(cli
, "%s (%u match%s)", r
,
3077 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3079 cli_print(cli
, "%s", r
);
3086 static int cmd_shutdown(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3088 if (CLI_HELP_REQUESTED
)
3089 return CLI_HELP_NO_ARGS
;
3091 kill(getppid(), SIGQUIT
);
3095 static int cmd_reload(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3097 if (CLI_HELP_REQUESTED
)
3098 return CLI_HELP_NO_ARGS
;
3100 kill(getppid(), SIGHUP
);