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
);
1042 if (config
->neighbour
[i
].update_source
.s_addr
!= INADDR_ANY
)
1043 cli_print(cli
, " neighbour %s update-source %s",
1044 config
->neighbour
[i
].name
,
1045 inet_ntoa(config
->neighbour
[i
].update_source
));
1050 cli_print(cli
, "# Filters");
1051 for (i
= 0; i
< MAXFILTER
; i
++)
1053 ip_filter_rulet
*rules
;
1054 if (!*ip_filters
[i
].name
)
1057 cli_print(cli
, "ip access-list %s %s",
1058 ip_filters
[i
].extended
? "extended" : "standard",
1059 ip_filters
[i
].name
);
1061 rules
= ip_filters
[i
].rules
;
1062 while (rules
->action
)
1063 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1066 cli_print(cli
, "# end");
1070 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1072 int i
, free
= 0, used
= 0, show_all
= 0;
1084 if (CLI_HELP_REQUESTED
)
1087 return cli_arg_help(cli
, 1, NULL
);
1089 return cli_arg_help(cli
, 1,
1090 "all", "Show all RADIUS sessions, including unused",
1094 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1098 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1101 for (i
= 1; i
< MAXRADIUS
; i
++)
1103 if (radius
[i
].state
== RADIUSNULL
)
1108 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1110 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1114 states
[radius
[i
].state
],
1120 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1125 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1129 if (CLI_HELP_REQUESTED
)
1130 return CLI_HELP_NO_ARGS
;
1132 cli_print(cli
, "Plugins currently loaded:");
1133 for (i
= 0; i
< MAXPLUGINS
; i
++)
1134 if (*config
->plugins
[i
])
1135 cli_print(cli
, " %s", config
->plugins
[i
]);
1140 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1144 if (CLI_HELP_REQUESTED
)
1145 return CLI_HELP_NO_ARGS
;
1147 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1156 for (i
= 0; i
< MAXSESSION
; i
++)
1158 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1159 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1163 session
[i
].throttle_in
,
1164 session
[i
].throttle_out
,
1166 session
[i
].tbf_out
);
1172 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1174 if (CLI_HELP_REQUESTED
)
1175 return CLI_HELP_NO_ARGS
;
1177 cli_print(cli
, " _\n"
1183 " ( \\ `. `-. _,.-:\\\n"
1184 " \\ \\ `. `-._ __..--' ,-';/\n"
1185 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1186 " `. `. `-._ __..--' ,' /\n"
1187 " `. `-_ ``--..'' _.-' ,'\n"
1188 " `-_ `-.___ __,--' ,'\n"
1189 " `-.__ `----\"\"\" __.-'\n"
1190 "hh `--..____..--'");
1195 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1200 if (CLI_HELP_REQUESTED
)
1201 return cli_arg_help(cli
, argc
> 1,
1202 "USER", "Username of session to drop", NULL
);
1204 if (!config
->cluster_iam_master
)
1206 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1207 fmtaddr(config
->cluster_master_address
, 0));
1214 cli_error(cli
, "Specify a user to drop");
1218 for (i
= 0; i
< argc
; i
++)
1220 if (!(s
= sessionbyuser(argv
[i
])))
1222 cli_error(cli
, "User %s is not connected", argv
[i
]);
1226 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1228 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1229 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1236 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1241 if (CLI_HELP_REQUESTED
)
1242 return cli_arg_help(cli
, argc
> 1,
1243 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1245 if (!config
->cluster_iam_master
)
1247 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1248 fmtaddr(config
->cluster_master_address
, 0));
1255 cli_error(cli
, "Specify a tunnel to drop");
1259 for (i
= 0; i
< argc
; i
++)
1261 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1263 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1269 cli_error(cli
, "Tunnel %d is not connected", t
);
1275 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1279 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1280 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1286 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1291 if (CLI_HELP_REQUESTED
)
1292 return cli_arg_help(cli
, argc
> 1,
1293 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1295 if (!config
->cluster_iam_master
)
1297 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1298 fmtaddr(config
->cluster_master_address
, 0));
1305 cli_error(cli
, "Specify a session id to drop");
1309 for (i
= 0; i
< argc
; i
++)
1311 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1313 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1317 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1319 cli_print(cli
, "Dropping session %d", s
);
1320 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1324 cli_error(cli
, "Session %d is not active.", s
);
1331 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1337 if (CLI_HELP_REQUESTED
)
1342 return cli_arg_help(cli
, 0,
1343 "USER", "Username of session to snoop", NULL
);
1346 return cli_arg_help(cli
, 0,
1347 "A.B.C.D", "IP address of snoop destination", NULL
);
1350 return cli_arg_help(cli
, 0,
1351 "N", "Port of snoop destination", NULL
);
1355 return cli_arg_help(cli
, 1, NULL
);
1362 if (!config
->cluster_iam_master
)
1364 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1365 fmtaddr(config
->cluster_master_address
, 0));
1372 cli_error(cli
, "Specify username, ip and port");
1376 if (!(s
= sessionbyuser(argv
[0])))
1378 cli_error(cli
, "User %s is not connected", argv
[0]);
1382 ip
= inet_addr(argv
[1]);
1383 if (!ip
|| ip
== INADDR_NONE
)
1385 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1389 port
= atoi(argv
[2]);
1392 cli_error(cli
, "Invalid port %s", argv
[2]);
1396 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1397 cli_session_actions
[s
].snoop_ip
= ip
;
1398 cli_session_actions
[s
].snoop_port
= port
;
1399 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1404 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1409 if (CLI_HELP_REQUESTED
)
1410 return cli_arg_help(cli
, argc
> 1,
1411 "USER", "Username of session to unsnoop", NULL
);
1413 if (!config
->cluster_iam_master
)
1415 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1416 fmtaddr(config
->cluster_master_address
, 0));
1423 cli_error(cli
, "Specify a user to unsnoop");
1427 for (i
= 0; i
< argc
; i
++)
1429 if (!(s
= sessionbyuser(argv
[i
])))
1431 cli_error(cli
, "User %s is not connected", argv
[i
]);
1435 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1436 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1442 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1449 throttle USER - throttle in/out to default rate
1450 throttle USER RATE - throttle in/out to default rate
1451 throttle USER in RATE - throttle input only
1452 throttle USER out RATE - throttle output only
1453 throttle USER in RATE out RATE - throttle both
1456 if (CLI_HELP_REQUESTED
)
1461 return cli_arg_help(cli
, 0,
1462 "USER", "Username of session to throttle", NULL
);
1465 return cli_arg_help(cli
, 1,
1466 "RATE", "Rate in kbps (in and out)",
1467 "in", "Select incoming rate",
1468 "out", "Select outgoing rate", NULL
);
1471 return cli_arg_help(cli
, 1,
1472 "in", "Select incoming rate",
1473 "out", "Select outgoing rate", NULL
);
1476 if (isdigit(argv
[1][0]))
1477 return cli_arg_help(cli
, 1, NULL
);
1480 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1483 return cli_arg_help(cli
, argc
> 1, NULL
);
1487 if (!config
->cluster_iam_master
)
1489 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1490 fmtaddr(config
->cluster_master_address
, 0));
1497 cli_error(cli
, "Specify a user to throttle");
1501 if (!(s
= sessionbyuser(argv
[0])))
1503 cli_error(cli
, "User %s is not connected", argv
[0]);
1509 rate_in
= rate_out
= config
->rl_rate
;
1513 rate_in
= rate_out
= atoi(argv
[1]);
1516 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1520 else if (argc
== 3 || argc
== 5)
1523 for (i
= 1; i
< argc
- 1; i
+= 2)
1526 if (MATCH("in", argv
[i
]))
1527 r
= rate_in
= atoi(argv
[i
+1]);
1528 else if (MATCH("out", argv
[i
]))
1529 r
= rate_out
= atoi(argv
[i
+1]);
1533 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1540 cli_error(cli
, "Invalid arguments");
1544 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1546 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1550 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1551 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1552 cli_session_actions
[s
].throttle_in
= rate_in
;
1554 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1555 cli_session_actions
[s
].throttle_out
= rate_out
;
1557 if (cli_session_actions
[s
].throttle_in
== -1 &&
1558 cli_session_actions
[s
].throttle_out
== -1)
1560 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1564 cli_print(cli
, "Throttling user %s", argv
[0]);
1565 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1570 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1575 if (CLI_HELP_REQUESTED
)
1576 return cli_arg_help(cli
, argc
> 1,
1577 "USER", "Username of session to unthrottle", NULL
);
1579 if (!config
->cluster_iam_master
)
1581 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1582 fmtaddr(config
->cluster_master_address
, 0));
1589 cli_error(cli
, "Specify a user to unthrottle");
1593 for (i
= 0; i
< argc
; i
++)
1595 if (!(s
= sessionbyuser(argv
[i
])))
1597 cli_error(cli
, "User %s is not connected", argv
[i
]);
1601 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1603 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1604 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1608 cli_error(cli
, "User %s not throttled", argv
[i
]);
1615 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1619 if (CLI_HELP_REQUESTED
)
1620 return cli_arg_help(cli
, 1,
1621 "all", "Enable debugging for all except \"data\"",
1622 "critical", "", // FIXME: add descriptions
1632 char *p
= (char *) &debug_flags
;
1633 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1637 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1638 (debug_flags
.critical
) ? " critical" : "",
1639 (debug_flags
.error
) ? " error" : "",
1640 (debug_flags
.warning
) ? " warning" : "",
1641 (debug_flags
.info
) ? " info" : "",
1642 (debug_flags
.calls
) ? " calls" : "",
1643 (debug_flags
.data
) ? " data" : "");
1649 cli_print(cli
, "Debugging off");
1653 for (i
= 0; i
< argc
; i
++)
1655 int len
= strlen(argv
[i
]);
1657 if (argv
[i
][0] == 'c' && len
< 2)
1658 len
= 2; /* distinguish [cr]itical from [ca]lls */
1660 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1661 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1662 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1663 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1664 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1665 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1666 if (!strncmp("all", argv
[i
], len
))
1668 memset(&debug_flags
, 1, sizeof(debug_flags
));
1669 debug_flags
.data
= 0;
1673 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1679 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1683 if (CLI_HELP_REQUESTED
)
1684 return cli_arg_help(cli
, 1,
1685 "all", "Disable all debugging",
1686 "critical", "", // FIXME: add descriptions
1696 memset(&debug_flags
, 0, sizeof(debug_flags
));
1700 for (i
= 0; i
< argc
; i
++)
1702 int len
= strlen(argv
[i
]);
1704 if (argv
[i
][0] == 'c' && len
< 2)
1705 len
= 2; /* distinguish [cr]itical from [ca]lls */
1707 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1708 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1709 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1710 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1711 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1712 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1713 if (!strncmp("all", argv
[i
], len
))
1715 memset(&debug_flags
, 0, sizeof(debug_flags
));
1719 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1725 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1727 int i
, firstfree
= 0;
1729 if (CLI_HELP_REQUESTED
)
1730 return cli_arg_help(cli
, argc
> 1,
1731 "PLUGIN", "Name of plugin to load", NULL
);
1735 cli_error(cli
, "Specify a plugin to load");
1739 for (i
= 0; i
< MAXPLUGINS
; i
++)
1741 if (!*config
->plugins
[i
] && !firstfree
)
1743 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1745 cli_error(cli
, "Plugin is already loaded");
1752 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1753 config
->reload_config
= 1;
1754 cli_print(cli
, "Loading plugin %s", argv
[0]);
1760 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1764 if (CLI_HELP_REQUESTED
)
1765 return cli_arg_help(cli
, argc
> 1,
1766 "PLUGIN", "Name of plugin to unload", NULL
);
1770 cli_error(cli
, "Specify a plugin to remove");
1774 for (i
= 0; i
< MAXPLUGINS
; i
++)
1776 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1778 config
->reload_config
= 1;
1779 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1784 cli_error(cli
, "Plugin is not loaded");
1788 static char *duration(time_t secs
)
1790 static char *buf
= NULL
;
1793 if (!buf
) buf
= calloc(64, 1);
1797 int days
= secs
/ 86400;
1798 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1804 int mins
= secs
/ 60;
1805 int hrs
= mins
/ 60;
1808 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1810 else if (secs
>= 60)
1812 int mins
= secs
/ 60;
1813 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1816 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1821 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1824 char buf
[100], *p
= buf
, *loads
[3];
1825 int i
, num_sessions
= 0;
1827 if (CLI_HELP_REQUESTED
)
1828 return CLI_HELP_NO_ARGS
;
1830 fh
= fopen("/proc/loadavg", "r");
1831 fgets(buf
, 100, fh
);
1834 for (i
= 0; i
< 3; i
++)
1835 loads
[i
] = strdup(strsep(&p
, " "));
1838 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1840 for (i
= 1; i
< MAXSESSION
; i
++)
1841 if (session
[i
].opened
) num_sessions
++;
1843 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1845 duration(time_now
- config
->start_time
),
1847 loads
[0], loads
[1], loads
[2]
1849 for (i
= 0; i
< 3; i
++)
1850 if (loads
[i
]) free(loads
[i
]);
1852 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1857 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1861 if (CLI_HELP_REQUESTED
)
1867 int len
= strlen(argv
[0])-1;
1868 for (i
= 0; config_values
[i
].key
; i
++)
1869 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1870 cli_error(cli
, " %s", config_values
[i
].key
);
1876 return cli_arg_help(cli
, 0,
1877 "VALUE", "Value for variable", NULL
);
1881 return cli_arg_help(cli
, 1, NULL
);
1890 cli_error(cli
, "Specify variable and value");
1894 for (i
= 0; config_values
[i
].key
; i
++)
1896 void *value
= ((void *) config
) + config_values
[i
].offset
;
1897 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1899 // Found a value to set
1900 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1901 switch (config_values
[i
].type
)
1904 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1907 *(int *) value
= atoi(argv
[1]);
1910 *(unsigned long *) value
= atol(argv
[1]);
1913 *(short *) value
= atoi(argv
[1]);
1916 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1919 inet_pton(AF_INET6
, argv
[1], value
);
1922 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1928 cli_error(cli
, "Unknown variable type");
1931 config
->reload_config
= 1;
1936 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1940 int regular_stuff(struct cli_def
*cli
)
1946 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1948 char *m
= ringbuffer
->buffer
[i
].message
;
1954 switch (ringbuffer
->buffer
[i
].level
)
1956 case 0: show
= debug_flags
.critical
; break;
1957 case 1: show
= debug_flags
.error
; break;
1958 case 2: show
= debug_flags
.warning
; break;
1959 case 3: show
= debug_flags
.info
; break;
1960 case 4: show
= debug_flags
.calls
; break;
1961 case 5: show
= debug_flags
.data
; break;
1964 if (!show
) continue;
1966 if (!(p
= strchr(m
, '\n')))
1969 cli_error(cli
, "\r%s-%u-%u %.*s",
1970 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1971 ringbuffer
->buffer
[i
].tunnel
,
1972 ringbuffer
->buffer
[i
].session
,
1978 debug_rb_tail
= ringbuffer
->tail
;
1986 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1990 if (CLI_HELP_REQUESTED
)
1991 return cli_arg_help(cli
, argc
> 1,
1992 "<1-65535>", "Autonomous system number", NULL
);
1994 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1996 cli_error(cli
, "Invalid autonomous system number");
2000 if (bgp_configured
&& as
!= config
->as_number
)
2002 cli_error(cli
, "Can't change local AS on a running system");
2006 config
->as_number
= as
;
2007 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
2012 static int find_bgp_neighbour(char const *name
)
2017 in_addr_t addrs
[4] = { 0 };
2020 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
2023 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
2024 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
2026 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2028 if (!config
->neighbour
[i
].name
[0])
2030 if (new == -1) new = i
;
2034 if (!strcmp(name
, config
->neighbour
[i
].name
))
2037 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
2040 for (a
= h
->h_addr_list
; *a
; a
++)
2043 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2044 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2052 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2058 if (CLI_HELP_REQUESTED
)
2063 return cli_arg_help(cli
, 0,
2064 "A.B.C.D", "BGP neighbour address",
2065 "NAME", "BGP neighbour name",
2069 return cli_arg_help(cli
, 0,
2070 "remote-as", "Set remote autonomous system number",
2071 "timers", "Set timers",
2072 "update-source", "Set source address to use for the BGP session",
2076 if (MATCH("remote-as", argv
[1]))
2077 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2079 if (MATCH("timers", argv
[1]))
2082 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2085 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2087 if (argc
== 5 && !argv
[4][1])
2088 return cli_arg_help(cli
, 1, NULL
);
2091 if (MATCH("update-source", argv
[1]))
2092 return cli_arg_help(cli
, argc
> 3, "A.B.C.D", "Source IP address", NULL
);
2100 cli_error(cli
, "Invalid arguments");
2104 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2106 cli_error(cli
, "Invalid neighbour");
2112 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2116 if (MATCH("remote-as", argv
[1]))
2118 int as
= atoi(argv
[2]);
2119 if (as
< 0 || as
> 65535)
2121 cli_error(cli
, "Invalid autonomous system number");
2125 if (!config
->neighbour
[i
].name
[0])
2127 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2128 config
->neighbour
[i
].keepalive
= -1;
2129 config
->neighbour
[i
].hold
= -1;
2130 config
->neighbour
[i
].update_source
.s_addr
= INADDR_ANY
;
2133 config
->neighbour
[i
].as
= as
;
2137 if (MATCH("update-source", argv
[1]))
2139 struct in_addr addr
;
2141 if (!config
->neighbour
[i
].name
[0])
2143 cli_error(cli
, "Specify remote-as first");
2147 if (!inet_aton(argv
[2], &addr
))
2149 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[2]);
2153 config
->neighbour
[i
].update_source
= addr
;
2157 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2159 cli_error(cli
, "Invalid arguments");
2163 if (!config
->neighbour
[i
].name
[0])
2165 cli_error(cli
, "Specify remote-as first");
2169 keepalive
= atoi(argv
[2]);
2170 hold
= atoi(argv
[3]);
2172 if (keepalive
< 1 || keepalive
> 65535)
2174 cli_error(cli
, "Invalid keepalive time");
2178 if (hold
< 3 || hold
> 65535)
2180 cli_error(cli
, "Invalid hold time");
2184 if (keepalive
== BGP_KEEPALIVE_TIME
)
2185 keepalive
= -1; // using default value
2187 if (hold
== BGP_HOLD_TIME
)
2190 config
->neighbour
[i
].keepalive
= keepalive
;
2191 config
->neighbour
[i
].hold
= hold
;
2196 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2200 if (CLI_HELP_REQUESTED
)
2201 return cli_arg_help(cli
, argc
> 0,
2202 "A.B.C.D", "BGP neighbour address",
2203 "NAME", "BGP neighbour name",
2208 cli_error(cli
, "Specify a BGP neighbour");
2212 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2214 cli_error(cli
, "Invalid neighbour");
2218 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2220 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2224 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2228 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2234 if (!bgp_configured
)
2237 if (CLI_HELP_REQUESTED
)
2238 return cli_arg_help(cli
, 1,
2239 "A.B.C.D", "BGP neighbour address",
2240 "NAME", "BGP neighbour name",
2243 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2244 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2248 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2250 if (!*bgp_peers
[i
].name
)
2253 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2254 if (argc
&& strcmp(addr
, argv
[0]) &&
2255 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2261 cli_print(cli
, "Peer AS Address "
2262 "State Retries Retry in Route Pend Timers");
2263 cli_print(cli
, "------------------ ----- --------------- "
2264 "----------- ------- -------- ----- ---- ---------");
2267 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2271 bgp_state_str(bgp_peers
[i
].state
),
2272 bgp_peers
[i
].retry_count
,
2273 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2274 bgp_peers
[i
].routing
? "yes" : "no",
2275 bgp_peers
[i
].update_routes
? "yes" : "no",
2276 bgp_peers
[i
].keepalive
,
2283 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2288 if (!bgp_configured
)
2291 if (CLI_HELP_REQUESTED
)
2292 return cli_arg_help(cli
, 1,
2293 "A.B.C.D", "BGP neighbour address",
2294 "NAME", "BGP neighbour name",
2297 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2299 if (bgp_peers
[i
].state
!= Established
)
2302 if (!bgp_peers
[i
].routing
)
2305 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2306 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2309 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2310 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2316 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2321 if (!bgp_configured
)
2324 if (CLI_HELP_REQUESTED
)
2325 return cli_arg_help(cli
, 1,
2326 "A.B.C.D", "BGP neighbour address",
2327 "NAME", "BGP neighbour name",
2330 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2332 if (bgp_peers
[i
].state
!= Established
)
2335 if (bgp_peers
[i
].routing
)
2338 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2339 if (argc
&& strcmp(addr
, argv
[0]) &&
2340 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2343 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2344 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2350 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2355 if (!bgp_configured
)
2358 if (CLI_HELP_REQUESTED
)
2359 return cli_arg_help(cli
, 1,
2360 "A.B.C.D", "BGP neighbour address",
2361 "NAME", "BGP neighbour name",
2364 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2366 if (!*bgp_peers
[i
].name
)
2369 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2370 if (argc
&& strcmp(addr
, argv
[0]) &&
2371 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2374 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2375 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2383 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2387 if (CLI_HELP_REQUESTED
)
2392 return cli_arg_help(cli
, 0,
2393 "standard", "Standard syntax",
2394 "extended", "Extended syntax",
2398 return cli_arg_help(cli
, argv
[1][1],
2399 "NAME", "Access-list name",
2403 if (argc
== 3 && !argv
[2][1])
2404 return cli_arg_help(cli
, 1, NULL
);
2412 cli_error(cli
, "Specify access-list type and name");
2416 if (MATCH("standard", argv
[0]))
2418 else if (MATCH("extended", argv
[0]))
2422 cli_error(cli
, "Invalid access-list type");
2426 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2427 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2429 cli_error(cli
, "Invalid access-list name");
2433 filt
= find_filter(argv
[1], strlen(argv
[1]));
2438 cli_error(cli
, "Too many access-lists");
2443 if (!*ip_filters
[filt
].name
)
2445 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2446 strcpy(ip_filters
[filt
].name
, argv
[1]);
2447 ip_filters
[filt
].extended
= extended
;
2449 else if (ip_filters
[filt
].extended
!= extended
)
2451 cli_error(cli
, "Access-list is %s",
2452 ip_filters
[filt
].extended
? "extended" : "standard");
2457 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2461 if (filt
< 0 || !*ip_filters
[filt
].name
)
2463 cli_error(cli
, "Access-list not defined");
2468 if (ip_filters
[filt
].used
)
2470 cli_error(cli
, "Access-list in use");
2474 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2478 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2480 return access_list(cli
, argv
, argc
, 1);
2483 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2485 return access_list(cli
, argv
, argc
, 0);
2488 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2490 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2491 return sprintf(buf
, " any");
2493 if (wild
== INADDR_ANY
)
2494 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2496 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2499 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2503 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2504 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2505 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2506 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2507 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2513 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2515 static char buf
[256];
2518 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2521 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2522 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2525 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2529 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2530 p
+= show_ports(p
, &rule
->src_ports
);
2532 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2533 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2534 p
+= show_ports(p
, &rule
->dst_ports
);
2536 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2538 switch (rule
->tcp_flag_op
)
2540 case FILTER_FLAG_OP_EST
:
2541 p
+= sprintf(p
, " established");
2544 case FILTER_FLAG_OP_ANY
:
2545 case FILTER_FLAG_OP_ALL
:
2546 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2547 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2548 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2549 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2550 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2551 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2552 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2553 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2554 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2555 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2556 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2557 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2558 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2564 p
+= sprintf(p
, " fragments");
2569 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2571 static ip_filter_rulet rule
;
2572 struct in_addr addr
;
2576 if (CLI_HELP_REQUESTED
)
2580 cli_arg_help(cli
, 0,
2581 "ip", "Match IP packets",
2582 "tcp", "Match TCP packets",
2583 "udp", "Match UDP packets",
2589 // *sigh*, too darned complex
2590 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2596 cli_error(cli
, "Specify rule details");
2600 memset(&rule
, 0, sizeof(rule
));
2601 rule
.action
= (command
[0] == 'p')
2602 ? FILTER_ACTION_PERMIT
2603 : FILTER_ACTION_DENY
;
2605 if (MATCH("ip", argv
[0]))
2606 rule
.proto
= IPPROTO_IP
;
2607 else if (MATCH("udp", argv
[0]))
2608 rule
.proto
= IPPROTO_UDP
;
2609 else if (MATCH("tcp", argv
[0]))
2610 rule
.proto
= IPPROTO_TCP
;
2613 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2617 for (a
= 1, i
= 0; i
< 2; i
++)
2621 ip_filter_portt
*port
;
2626 wild
= &rule
.src_wild
;
2627 port
= &rule
.src_ports
;
2632 wild
= &rule
.dst_wild
;
2633 port
= &rule
.dst_ports
;
2636 cli_error(cli
, "Specify destination");
2641 if (MATCH("any", argv
[a
]))
2644 *wild
= INADDR_BROADCAST
;
2647 else if (MATCH("host", argv
[a
]))
2651 cli_error(cli
, "Specify host ip address");
2655 if (!inet_aton(argv
[a
], &addr
))
2657 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2669 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2673 if (!inet_aton(argv
[a
], &addr
))
2675 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2681 if (!inet_aton(argv
[++a
], &addr
))
2683 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2687 *wild
= addr
.s_addr
;
2691 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2695 if (MATCH("eq", argv
[a
]))
2696 port
->op
= FILTER_PORT_OP_EQ
;
2697 else if (MATCH("neq", argv
[a
]))
2698 port
->op
= FILTER_PORT_OP_NEQ
;
2699 else if (MATCH("gt", argv
[a
]))
2700 port
->op
= FILTER_PORT_OP_GT
;
2701 else if (MATCH("lt", argv
[a
]))
2702 port
->op
= FILTER_PORT_OP_LT
;
2703 else if (MATCH("range", argv
[a
]))
2704 port
->op
= FILTER_PORT_OP_RANGE
;
2711 cli_error(cli
, "Specify port");
2715 if (!(port
->port
= atoi(argv
[a
])))
2717 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2722 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2727 cli_error(cli
, "Specify port");
2731 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2733 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2740 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2742 if (MATCH("established", argv
[a
]))
2744 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2747 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2748 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2750 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2751 ? FILTER_FLAG_OP_ANY
2752 : FILTER_FLAG_OP_ALL
;
2756 cli_error(cli
, "Specify tcp flags");
2760 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2764 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2766 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2767 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2768 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2769 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2770 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2771 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2774 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2783 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2785 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2787 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2797 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2804 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2806 static ip_filter_rulet rule
;
2807 struct in_addr addr
;
2809 if (CLI_HELP_REQUESTED
)
2813 cli_arg_help(cli
, argv
[0][1],
2814 "A.B.C.D", "Source address",
2815 "any", "Any source address",
2816 "host", "Source host",
2822 if (MATCH("any", argv
[0]))
2824 if (argc
== 2 && !argv
[1][1])
2825 cli_arg_help(cli
, 1, NULL
);
2827 else if (MATCH("host", argv
[0]))
2831 cli_arg_help(cli
, argv
[1][1],
2832 "A.B.C.D", "Host address",
2835 else if (argc
== 3 && !argv
[2][1])
2836 cli_arg_help(cli
, 1, NULL
);
2842 cli_arg_help(cli
, 1,
2843 "A.B.C.D", "Wildcard bits",
2846 else if (argc
== 3 && !argv
[2][1])
2847 cli_arg_help(cli
, 1, NULL
);
2855 cli_error(cli
, "Specify rule details");
2859 memset(&rule
, 0, sizeof(rule
));
2860 rule
.action
= (command
[0] == 'p')
2861 ? FILTER_ACTION_PERMIT
2862 : FILTER_ACTION_DENY
;
2864 rule
.proto
= IPPROTO_IP
;
2865 if (MATCH("any", argv
[0]))
2867 rule
.src_ip
= INADDR_ANY
;
2868 rule
.src_wild
= INADDR_BROADCAST
;
2870 else if (MATCH("host", argv
[0]))
2874 cli_error(cli
, "Specify host ip address");
2878 if (!inet_aton(argv
[1], &addr
))
2880 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2884 rule
.src_ip
= addr
.s_addr
;
2885 rule
.src_wild
= INADDR_ANY
;
2891 cli_error(cli
, "Specify source ip address and wildcard");
2895 if (!inet_aton(argv
[0], &addr
))
2897 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2901 rule
.src_ip
= addr
.s_addr
;
2905 if (!inet_aton(argv
[1], &addr
))
2907 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2911 rule
.src_wild
= addr
.s_addr
;
2914 rule
.src_wild
= INADDR_ANY
;
2920 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2923 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2924 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2925 : access_list_rule_std(cli
, command
, argv
, argc
);
2930 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2932 if (!ip_filters
[filt
].rules
[i
].action
)
2934 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2938 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, offsetof(ip_filter_rulet
, counter
)))
2942 cli_error(cli
, "Too many rules");
2946 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2951 /* filter USER {in|out} FILTER ... */
2952 if (CLI_HELP_REQUESTED
)
2957 return cli_arg_help(cli
, 0,
2958 "USER", "Username of session to filter", NULL
);
2962 return cli_arg_help(cli
, 0,
2963 "in", "Set incoming filter",
2964 "out", "Set outgoing filter", NULL
);
2968 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2969 "NAME", "Filter name", NULL
);
2972 return cli_arg_help(cli
, argc
> 1, NULL
);
2976 if (!config
->cluster_iam_master
)
2978 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2979 fmtaddr(config
->cluster_master_address
, 0));
2984 if (argc
!= 3 && argc
!= 5)
2986 cli_error(cli
, "Specify a user and filters");
2990 if (!(s
= sessionbyuser(argv
[0])))
2992 cli_error(cli
, "User %s is not connected", argv
[0]);
2996 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2997 for (i
= 1; i
< argc
; i
+= 2)
3002 if (MATCH("in", argv
[i
]))
3004 if (session
[s
].filter_in
)
3006 cli_error(cli
, "Input already filtered");
3009 f
= &cli_session_actions
[s
].filter_in
;
3011 else if (MATCH("out", argv
[i
]))
3013 if (session
[s
].filter_out
)
3015 cli_error(cli
, "Output already filtered");
3018 f
= &cli_session_actions
[s
].filter_out
;
3022 cli_error(cli
, "Invalid filter specification");
3026 v
= find_filter(argv
[i
+1], strlen(argv
[i
+1]));
3027 if (v
< 0 || !*ip_filters
[v
].name
)
3029 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
3036 cli_print(cli
, "Filtering user %s", argv
[0]);
3037 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
3042 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3047 if (CLI_HELP_REQUESTED
)
3048 return cli_arg_help(cli
, argc
> 1,
3049 "USER", "Username of session to remove filters from", NULL
);
3051 if (!config
->cluster_iam_master
)
3053 cli_error(cli
, "Can't do this on a slave. Do it on %s",
3054 fmtaddr(config
->cluster_master_address
, 0));
3061 cli_error(cli
, "Specify a user to remove filters from");
3065 for (i
= 0; i
< argc
; i
++)
3067 if (!(s
= sessionbyuser(argv
[i
])))
3069 cli_error(cli
, "User %s is not connected", argv
[i
]);
3073 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3075 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3076 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3080 cli_error(cli
, "User %s not filtered", argv
[i
]);
3087 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3091 if (CLI_HELP_REQUESTED
)
3092 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3096 cli_error(cli
, "Specify a filter name");
3100 for (i
= 0; i
< argc
; i
++)
3102 int f
= find_filter(argv
[i
], strlen(argv
[i
]));
3103 ip_filter_rulet
*rules
;
3105 if (f
< 0 || !*ip_filters
[f
].name
)
3107 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3114 cli_print(cli
, "%s IP access list %s",
3115 ip_filters
[f
].extended
? "Extended" : "Standard",
3116 ip_filters
[f
].name
);
3118 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3120 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3122 cli_print(cli
, "%s (%u match%s)", r
,
3123 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3125 cli_print(cli
, "%s", r
);
3132 static int cmd_shutdown(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3134 if (CLI_HELP_REQUESTED
)
3135 return CLI_HELP_NO_ARGS
;
3137 kill(getppid(), SIGQUIT
);
3141 static int cmd_reload(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3143 if (CLI_HELP_REQUESTED
)
3144 return CLI_HELP_NO_ARGS
;
3146 kill(getppid(), SIGHUP
);