1 // L2TPNS Command Line Interface
16 #include <arpa/inet.h>
18 #include <sys/socket.h>
19 #include <sys/types.h>
26 #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
);
106 static int cmd_setforward(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
107 static int cmd_show_rmtlnsconf(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
110 static int regular_stuff(struct cli_def
*cli
);
113 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
114 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
115 #endif /* STATISTICS */
118 #define MODE_CONFIG_BGP 8
119 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
120 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
121 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
122 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
123 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
124 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
125 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
128 #define MODE_CONFIG_NACL 9
129 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
130 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
131 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
132 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
133 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
134 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
136 /* match if b is a substr of a */
137 #define MATCH(a,b) (!strncmp((a), (b), strlen(b)))
143 struct cli_command
*c
;
144 struct cli_command
*c2
;
148 c
= cli_register_command(cli
, NULL
, "show", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
149 cli_register_command(cli
, c
, "banana", cmd_show_banana
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a banana");
151 cli_register_command(cli
, c
, "bgp", cmd_show_bgp
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show BGP status");
153 cli_register_command(cli
, c
, "cluster", cmd_show_cluster
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show cluster information");
154 cli_register_command(cli
, c
, "ipcache", cmd_show_ipcache
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show contents of the IP cache");
155 cli_register_command(cli
, c
, "plugins", cmd_show_plugins
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all installed plugins");
156 cli_register_command(cli
, c
, "pool", cmd_show_pool
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the IP address allocation pool");
157 cli_register_command(cli
, c
, "radius", cmd_show_radius
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show active radius queries");
158 cli_register_command(cli
, c
, "running-config", cmd_show_run
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Show the currently running configuration");
160 cli_register_command(cli
, c
, "remotelns-conf", cmd_show_rmtlnsconf
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Show a list of remote LNS 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");
235 cli_register_command(cli
, NULL
, "setforward", cmd_setforward
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set the Remote LNS Forward");
238 c
= cli_register_command(cli
, NULL
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
239 cli_register_command(cli
, c
, "access-list", cmd_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Add named access-list");
241 cli_register_command(cli
, NULL
, "permit", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Permit rule");
242 cli_register_command(cli
, NULL
, "deny", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Deny rule");
244 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_CONFIG
, NULL
);
245 c2
= cli_register_command(cli
, c
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
246 cli_register_command(cli
, c2
, "access-list", cmd_no_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove named access-list");
248 // Enable regular processing
249 cli_regular(cli
, regular_stuff
);
251 if (!(f
= fopen(CLIUSERS
, "r")))
253 LOG(0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
257 while (fgets(buf
, 4096, f
))
260 if (*buf
== '#') continue;
261 if ((p
= strchr(buf
, '\r'))) *p
= 0;
262 if ((p
= strchr(buf
, '\n'))) *p
= 0;
264 if (!(p
= strchr((char *)buf
, ':'))) continue;
266 if (!strcmp(buf
, "enable"))
268 cli_allow_enable(cli
, p
);
269 LOG(3, 0, 0, "Setting enable password\n");
273 cli_allow_user(cli
, buf
, p
);
274 LOG(3, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
281 void cli_init_complete(char *hostname
)
284 struct sockaddr_in addr
;
286 if (hostname
&& *hostname
)
287 cli_set_hostname(cli
, hostname
);
289 cli_set_hostname(cli
, "l2tpns");
291 memset(&addr
, 0, sizeof(addr
));
292 clifd
= socket(PF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
293 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
296 // Set cli fd as non-blocking
297 flags
= fcntl(clifd
, F_GETFL
, 0);
298 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
300 addr
.sin_family
= AF_INET
;
301 addr
.sin_addr
.s_addr
= config
->cli_bind_address
; /* defaults to INADDR_ANY */
302 addr
.sin_port
= htons(23);
303 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
305 LOG(0, 0, 0, "Error binding cli on port 23: %s\n", strerror(errno
));
310 if (listen(clifd
, 10) < 0)
312 LOG(0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
319 void cli_do(int sockfd
)
321 int require_auth
= 1;
322 struct sockaddr_in addr
;
323 socklen_t l
= sizeof(addr
);
325 if (fork_and_close()) return;
326 if (getpeername(sockfd
, (struct sockaddr
*) &addr
, &l
) == 0)
328 require_auth
= addr
.sin_addr
.s_addr
!= inet_addr("127.0.0.1");
329 LOG(require_auth
? 3 : 4, 0, 0, "Accepted connection to CLI from %s\n",
330 fmtaddr(addr
.sin_addr
.s_addr
, 0));
333 LOG(0, 0, 0, "getpeername() failed on cli socket. Requiring authentication: %s\n", strerror(errno
));
337 LOG(3, 0, 0, "CLI is remote, requiring authentication\n");
338 if (!cli
->users
) /* paranoia */
340 LOG(0, 0, 0, "No users for remote authentication! Exiting CLI\n");
346 /* no username/pass required */
351 debug_rb_tail
= ringbuffer
->tail
;
353 memset(&debug_flags
, 0, sizeof(debug_flags
));
354 debug_flags
.critical
= 1;
356 cli_loop(cli
, sockfd
);
359 LOG(require_auth
? 3 : 4, 0, 0, "Closed CLI connection from %s\n",
360 fmtaddr(addr
.sin_addr
.s_addr
, 0));
365 static void cli_print_log(struct cli_def
*cli
, char *string
)
367 LOG(3, 0, 0, "%s\n", string
);
370 void cli_do_file(FILE *fh
)
372 LOG(3, 0, 0, "Reading configuration file\n");
373 cli_print_callback(cli
, cli_print_log
);
374 cli_file(cli
, fh
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
);
375 cli_print_callback(cli
, NULL
);
378 int cli_arg_help(struct cli_def
*cli
, int cr_ok
, char *entry
, ...)
389 if ((p
= strchr(entry
, '%')) && !strchr(p
+1, '%') && p
[1] == 'd')
391 int v
= va_arg(ap
, int);
392 snprintf(buf
, sizeof(buf
), entry
, v
);
398 desc
= va_arg(ap
, char *);
400 cli_error(cli
, " %-20s %s", p
, desc
);
402 cli_error(cli
, " %s", p
);
404 entry
= desc
? va_arg(ap
, char *) : 0;
409 cli_error(cli
, " <cr>");
414 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
418 if (CLI_HELP_REQUESTED
)
419 return cli_arg_help(cli
, 1,
420 "<1-%d>", MAXSESSION
-1, "Show specific session by id",
426 // Show individual session
427 for (i
= 0; i
< argc
; i
++)
429 unsigned int s
, b_in
, b_out
;
431 if (s
<= 0 || s
>= MAXSESSION
)
433 cli_print(cli
, "Invalid session id \"%s\"", argv
[i
]);
436 cli_print(cli
, "\r\nSession %d:", s
);
437 cli_print(cli
, "\tUser:\t\t%s", session
[s
].user
[0] ? session
[s
].user
: "none");
438 cli_print(cli
, "\tCalling Num:\t%s", session
[s
].calling
);
439 cli_print(cli
, "\tCalled Num:\t%s", session
[s
].called
);
440 cli_print(cli
, "\tTunnel ID:\t%d", session
[s
].tunnel
);
441 cli_print(cli
, "\tPPP Phase:\t%s", ppp_phase(session
[s
].ppp
.phase
));
442 switch (session
[s
].ppp
.phase
)
445 cli_print(cli
, "\t LCP state:\t%s", ppp_state(session
[s
].ppp
.lcp
));
450 cli_print(cli
, "\t IPCP state:\t%s", ppp_state(session
[s
].ppp
.ipcp
));
451 cli_print(cli
, "\t IPV6CP state:\t%s", ppp_state(session
[s
].ppp
.ipv6cp
));
452 cli_print(cli
, "\t CCP state:\t%s", ppp_state(session
[s
].ppp
.ccp
));
454 cli_print(cli
, "\tIP address:\t%s", fmtaddr(htonl(session
[s
].ip
), 0));
455 cli_print(cli
, "\tUnique SID:\t%u", session
[s
].unique_id
);
456 cli_print(cli
, "\tOpened:\t\t%u seconds", session
[s
].opened
? abs(time_now
- session
[s
].opened
) : 0);
457 cli_print(cli
, "\tIdle time:\t%u seconds", session
[s
].last_packet
? abs(time_now
- session
[s
].last_packet
) : 0);
458 if (session
[s
].session_timeout
)
460 clockt opened
= session
[s
].opened
;
461 if (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
462 opened
= bundle
[session
[s
].bundle
].online_time
;
464 cli_print(cli
, "\tSess Timeout:\t%u seconds", session
[s
].session_timeout
- (opened
? abs(time_now
- opened
) : 0));
467 if (session
[s
].idle_timeout
)
468 cli_print(cli
, "\tIdle Timeout:\t%u seconds", session
[s
].idle_timeout
- (session
[s
].last_data
? abs(time_now
- session
[s
].last_data
) : 0));
470 if (session
[s
].timeout
)
472 cli_print(cli
, "\tRemaining time:\t%u",
473 (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
474 ? (unsigned) (session
[s
].timeout
- bundle
[session
[s
].bundle
].online_time
)
475 : (unsigned) (session
[s
].timeout
- (time_now
- session
[s
].opened
)));
478 cli_print(cli
, "\tBytes In/Out:\t%u/%u", session
[s
].cout
, session
[s
].cin
);
479 cli_print(cli
, "\tPkts In/Out:\t%u/%u", session
[s
].pout
, session
[s
].pin
);
480 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
481 cli_print(cli
, "\tRx Speed:\t%u", session
[s
].rx_connect_speed
);
482 cli_print(cli
, "\tTx Speed:\t%u", session
[s
].tx_connect_speed
);
483 if (session
[s
].filter_in
&& session
[s
].filter_in
<= MAXFILTER
)
484 cli_print(cli
, "\tFilter in:\t%u (%s)", session
[s
].filter_in
, ip_filters
[session
[s
].filter_in
- 1].name
);
485 if (session
[s
].filter_out
&& session
[s
].filter_out
<= MAXFILTER
)
486 cli_print(cli
, "\tFilter out:\t%u (%s)", session
[s
].filter_out
, ip_filters
[session
[s
].filter_out
- 1].name
);
487 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
488 cli_print(cli
, "\tIntercepted:\t%s:%d", fmtaddr(session
[s
].snoop_ip
, 0), session
[s
] .snoop_port
);
490 cli_print(cli
, "\tIntercepted:\tno");
492 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
494 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
495 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
496 t
? "YES" : "no", t
? " (" : "",
497 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
499 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
503 b_in
= session
[s
].tbf_in
;
504 b_out
= session
[s
].tbf_out
;
506 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
507 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
508 "ByteSent", "PackSent", "PackDrop", "PackDelay");
511 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
513 (filter_list
[b_in
].next
? "*" : " "),
514 (b_in
< 100 ? "\t" : ""),
515 filter_list
[b_in
].rate
* 8,
516 filter_list
[b_in
].credit
,
517 filter_list
[b_in
].queued
,
518 filter_list
[b_in
].b_queued
,
519 filter_list
[b_in
].p_queued
,
520 filter_list
[b_in
].b_sent
,
521 filter_list
[b_in
].p_sent
,
522 filter_list
[b_in
].p_dropped
,
523 filter_list
[b_in
].p_delayed
);
526 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
528 (filter_list
[b_out
].next
? "*" : " "),
529 (b_out
< 100 ? "\t" : ""),
530 filter_list
[b_out
].rate
* 8,
531 filter_list
[b_out
].credit
,
532 filter_list
[b_out
].queued
,
533 filter_list
[b_out
].b_queued
,
534 filter_list
[b_out
].p_queued
,
535 filter_list
[b_out
].b_sent
,
536 filter_list
[b_out
].p_sent
,
537 filter_list
[b_out
].p_dropped
,
538 filter_list
[b_out
].p_delayed
);
546 cli_print(cli
, "%5s %7s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %10s %-18s %s",
548 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %10s %-15s %s",
567 "LAC(L)/RLNS(R)/PPPOE(P)",
573 for (i
= 1; i
< MAXSESSION
; i
++)
576 if (!session
[i
].opened
) continue;
577 if (session
[i
].bundle
&& bundle
[session
[i
].bundle
].num_of_links
> 1)
578 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- bundle
[session
[i
].bundle
].online_time
) : 0;
580 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- (time_now
-session
[i
].opened
)) : 0;
582 cli_print(cli
, "%5d %7d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %3s%-20s %s",
584 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %3s%-20s %s",
588 session
[i
].forwardtosession
,
591 session
[i
].user
[0] ? session
[i
].user
: "*",
592 fmtaddr(htonl(session
[i
].ip
), 0),
593 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
594 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
595 (session
[i
].walled_garden
) ? "Y" : "N",
596 (session
[i
].ppp
.ipv6cp
== Opened
) ? "Y" : "N",
597 abs(time_now
- (unsigned long)session
[i
].opened
),
598 (unsigned long)session
[i
].cout
,
599 (unsigned long)session
[i
].cin
,
600 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
601 (unsigned long)(rem_time
),
603 (session
[i
].tunnel
== TUNNEL_ID_PPPOE
)?"(P)":(tunnel
[session
[i
].tunnel
].isremotelns
?"(R)":"(L)"),
605 (session
[i
].tunnel
== TUNNEL_ID_PPPOE
)?"(P)":"(L)",
607 (session
[i
].tunnel
== TUNNEL_ID_PPPOE
)?fmtMacAddr(session
[i
].src_hwaddr
):fmtaddr(htonl(tunnel
[session
[i
].tunnel
].ip
), 1),
608 session
[i
].calling
[0] ? session
[i
].calling
: "*");
613 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
615 int i
, x
, show_all
= 0;
623 if (CLI_HELP_REQUESTED
)
626 return cli_arg_help(cli
, 1,
627 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
630 return cli_arg_help(cli
, 1,
631 "all", "Show all tunnels, including unused",
632 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
639 if (strcmp(argv
[0], "all") == 0)
645 // Show individual tunnel
646 for (i
= 0; i
< argc
; i
++)
651 if (t
<= 0 || t
>= MAXTUNNEL
)
653 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
656 cli_print(cli
, "\r\nTunnel %d:", t
);
657 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
658 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
659 cli_print(cli
, "\tRemote IP:\t%s", fmtaddr(htonl(tunnel
[t
].ip
), 0));
660 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
661 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
662 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
663 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
664 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
665 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
667 for (x
= 0; x
< MAXSESSION
; x
++)
668 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
669 sprintf(s
, "%s%u ", s
, x
);
671 cli_print(cli
, "\tSessions:\t%s", s
);
677 // Show tunnel summary
678 cli_print(cli
, "%4s %20s %20s %6s %s",
685 for (i
= 1; i
< MAXTUNNEL
; i
++)
688 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
690 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
691 cli_print(cli
, "%4d %20s %20s %6s %6d %s",
693 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
694 fmtaddr(htonl(tunnel
[i
].ip
), 0),
695 states
[tunnel
[i
].state
],
698 ,(i
== TUNNEL_ID_PPPOE
)?"Tunnel pppoe":(tunnel
[i
].isremotelns
?"Tunnel To Remote LNS":"Tunnel To LAC")
700 ,(i
== TUNNEL_ID_PPPOE
)?"Tunnel pppoe":"Tunnel To LAC"
708 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
715 if (CLI_HELP_REQUESTED
)
716 return cli_arg_help(cli
, 1,
717 "USER", "Show details for specific username",
720 for (i
= 0; i
< MAXSESSION
; i
++)
722 if (!session
[i
].opened
) continue;
723 if (!session
[i
].user
[0]) continue;
727 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
729 if (strcmp(argv
[j
], session
[i
].user
) == 0)
731 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
732 sargv
[sargc
] = sid
[sargc
];
740 cli_print(cli
, "%s", session
[i
].user
);
744 return cmd_show_session(cli
, "users", sargv
, sargc
);
750 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
752 if (CLI_HELP_REQUESTED
)
753 return CLI_HELP_NO_ARGS
;
755 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Ethernet", "Bytes", "Packets", "Errors", "Dropped");
756 cli_print(cli
, "%-10s %10u %10u %10u %10u", "RX",
757 GET_STAT(tun_rx_bytes
),
758 GET_STAT(tun_rx_packets
),
759 GET_STAT(tun_rx_errors
),
760 GET_STAT(tun_rx_dropped
));
761 cli_print(cli
, "%-10s %10u %10u %10u", "TX",
762 GET_STAT(tun_tx_bytes
),
763 GET_STAT(tun_tx_packets
),
764 GET_STAT(tun_tx_errors
));
767 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
768 cli_print(cli
, "%-10s %10u %10u %10u", "RX",
769 GET_STAT(tunnel_rx_bytes
),
770 GET_STAT(tunnel_rx_packets
),
771 GET_STAT(tunnel_rx_errors
));
772 cli_print(cli
, "%-10s %10u %10u %10u %10u", "TX",
773 GET_STAT(tunnel_tx_bytes
),
774 GET_STAT(tunnel_tx_packets
),
775 GET_STAT(tunnel_tx_errors
),
776 GET_STAT(tunnel_retries
));
779 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
780 cli_print(cli
, "-----------------------------------------");
781 cli_print(cli
, "%-30s%u", "radius_retries", GET_STAT(radius_retries
));
782 cli_print(cli
, "%-30s%u", "arp_sent", GET_STAT(arp_sent
));
783 cli_print(cli
, "%-30s%u", "packets_snooped", GET_STAT(packets_snooped
));
784 cli_print(cli
, "%-30s%u", "tunnel_created", GET_STAT(tunnel_created
));
785 cli_print(cli
, "%-30s%u", "session_created", GET_STAT(session_created
));
786 cli_print(cli
, "%-30s%u", "tunnel_timeout", GET_STAT(tunnel_timeout
));
787 cli_print(cli
, "%-30s%u", "session_timeout", GET_STAT(session_timeout
));
788 cli_print(cli
, "%-30s%u", "radius_timeout", GET_STAT(radius_timeout
));
789 cli_print(cli
, "%-30s%u", "radius_overflow", GET_STAT(radius_overflow
));
790 cli_print(cli
, "%-30s%u", "tunnel_overflow", GET_STAT(tunnel_overflow
));
791 cli_print(cli
, "%-30s%u", "session_overflow", GET_STAT(session_overflow
));
792 cli_print(cli
, "%-30s%u", "ip_allocated", GET_STAT(ip_allocated
));
793 cli_print(cli
, "%-30s%u", "ip_freed", GET_STAT(ip_freed
));
794 cli_print(cli
, "%-30s%u", "cluster_forwarded", GET_STAT(c_forwarded
));
795 cli_print(cli
, "%-30s%u", "recv_forward", GET_STAT(recv_forward
));
796 cli_print(cli
, "%-30s%u", "select_called", GET_STAT(select_called
));
797 cli_print(cli
, "%-30s%u", "multi_read_used", GET_STAT(multi_read_used
));
798 cli_print(cli
, "%-30s%u", "multi_read_exceeded", GET_STAT(multi_read_exceeded
));
802 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
803 cli_print(cli
, "-----------------------------------------");
804 cli_print(cli
, "%-30s%u", "call_processtun", GET_STAT(call_processtun
));
805 cli_print(cli
, "%-30s%u", "call_processipout", GET_STAT(call_processipout
));
806 cli_print(cli
, "%-30s%u", "call_processipv6out", GET_STAT(call_processipv6out
));
807 cli_print(cli
, "%-30s%u", "call_processudp", GET_STAT(call_processudp
));
808 cli_print(cli
, "%-30s%u", "call_processpap", GET_STAT(call_processpap
));
809 cli_print(cli
, "%-30s%u", "call_processchap", GET_STAT(call_processchap
));
810 cli_print(cli
, "%-30s%u", "call_processlcp", GET_STAT(call_processlcp
));
811 cli_print(cli
, "%-30s%u", "call_processipcp", GET_STAT(call_processipcp
));
812 cli_print(cli
, "%-30s%u", "call_processipv6cp", GET_STAT(call_processipv6cp
));
813 cli_print(cli
, "%-30s%u", "call_processipin", GET_STAT(call_processipin
));
814 cli_print(cli
, "%-30s%u", "call_processipv6in", GET_STAT(call_processipv6in
));
815 cli_print(cli
, "%-30s%u", "call_processccp", GET_STAT(call_processccp
));
816 cli_print(cli
, "%-30s%u", "call_processrad", GET_STAT(call_processrad
));
817 cli_print(cli
, "%-30s%u", "call_sendarp", GET_STAT(call_sendarp
));
818 cli_print(cli
, "%-30s%u", "call_sendipcp", GET_STAT(call_sendipcp
));
819 cli_print(cli
, "%-30s%u", "call_sendchap", GET_STAT(call_sendchap
));
820 cli_print(cli
, "%-30s%u", "call_sessionbyip", GET_STAT(call_sessionbyip
));
821 cli_print(cli
, "%-30s%u", "call_sessionbyipv6", GET_STAT(call_sessionbyipv6
));
822 cli_print(cli
, "%-30s%u", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
823 cli_print(cli
, "%-30s%u", "call_tunnelsend", GET_STAT(call_tunnelsend
));
824 cli_print(cli
, "%-30s%u", "call_tunnelkill", GET_STAT(call_tunnelkill
));
825 cli_print(cli
, "%-30s%u", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
826 cli_print(cli
, "%-30s%u", "call_sessionkill", GET_STAT(call_sessionkill
));
827 cli_print(cli
, "%-30s%u", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
828 cli_print(cli
, "%-30s%u", "call_sessionsetup", GET_STAT(call_sessionsetup
));
829 cli_print(cli
, "%-30s%u", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
830 cli_print(cli
, "%-30s%u", "call_free_ip_address", GET_STAT(call_free_ip_address
));
831 cli_print(cli
, "%-30s%u", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
832 cli_print(cli
, "%-30s%u", "call_radiussend", GET_STAT(call_radiussend
));
833 cli_print(cli
, "%-30s%u", "call_radiusretry", GET_STAT(call_radiusretry
));
834 cli_print(cli
, "%-30s%u", "call_random_data", GET_STAT(call_random_data
));
835 #endif /* STAT_CALLS */
838 time_t l
= GET_STAT(last_reset
);
840 char *p
= strchr(t
, '\n');
844 cli_print(cli
, "Last counter reset %s", t
);
850 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
852 if (CLI_HELP_REQUESTED
)
853 return CLI_HELP_NO_ARGS
;
855 memset(_statistics
, 0, sizeof(struct Tstats
));
856 SET_STAT(last_reset
, time(NULL
));
858 cli_print(cli
, "Counters cleared");
861 #endif /* STATISTICS */
863 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
865 if (CLI_HELP_REQUESTED
)
866 return CLI_HELP_NO_ARGS
;
868 cli_print(cli
, "L2TPNS %s", VERSION
);
872 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
875 int used
= 0, free
= 0, show_all
= 0;
877 if (!config
->cluster_iam_master
)
879 cli_print(cli
, "Can't do this on a slave. Do it on %s",
880 fmtaddr(config
->cluster_master_address
, 0));
885 if (CLI_HELP_REQUESTED
)
888 return cli_arg_help(cli
, 1, NULL
);
890 return cli_arg_help(cli
, 1,
891 "all", "Show all pool addresses, including unused",
895 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
899 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
900 for (i
= 0; i
< MAXIPPOOL
; i
++)
902 if (!ip_address_pool
[i
].address
) continue;
903 if (ip_address_pool
[i
].assigned
)
905 cli_print(cli
, "%-15s\tY %8d %s",
906 fmtaddr(htonl(ip_address_pool
[i
].address
), 0),
907 ip_address_pool
[i
].session
,
908 session
[ip_address_pool
[i
].session
].user
);
914 if (ip_address_pool
[i
].last
)
915 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
916 fmtaddr(htonl(ip_address_pool
[i
].address
), 0), "",
917 ip_address_pool
[i
].user
, (int) time_now
- ip_address_pool
[i
].last
);
920 cli_print(cli
, "%-15s\tN", fmtaddr(htonl(ip_address_pool
[i
].address
), 0));
927 cli_print(cli
, "(Not displaying unused addresses)");
929 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
933 static FILE *save_config_fh
= 0;
934 static void print_save_config(struct cli_def
*cli
, char *string
)
937 fprintf(save_config_fh
, "%s\n", string
);
940 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
942 if (CLI_HELP_REQUESTED
)
943 return CLI_HELP_NO_ARGS
;
945 if ((save_config_fh
= fopen(config
->config_file
, "w")))
947 cli_print(cli
, "Writing configuration");
948 cli_print_callback(cli
, print_save_config
);
949 cmd_show_run(cli
, command
, argv
, argc
);
950 cli_print_callback(cli
, NULL
);
951 fclose(save_config_fh
);
956 cli_error(cli
, "Error writing configuration: %s", strerror(errno
));
961 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
);
963 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
966 char ipv6addr
[INET6_ADDRSTRLEN
];
968 if (CLI_HELP_REQUESTED
)
969 return CLI_HELP_NO_ARGS
;
971 cli_print(cli
, "# Current configuration:");
973 for (i
= 0; config_values
[i
].key
; i
++)
975 void *value
= ((void *)config
) + config_values
[i
].offset
;
976 if (config_values
[i
].type
== STRING
)
977 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *) value
);
978 else if (config_values
[i
].type
== IPv4
)
979 cli_print(cli
, "set %s %s", config_values
[i
].key
, fmtaddr(*(in_addr_t
*) value
, 0));
980 else if (config_values
[i
].type
== IPv6
)
981 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_ntop(AF_INET6
, value
, ipv6addr
, INET6_ADDRSTRLEN
));
982 else if (config_values
[i
].type
== SHORT
)
983 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *) value
);
984 else if (config_values
[i
].type
== BOOL
)
985 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *) value
) ? "yes" : "no");
986 else if (config_values
[i
].type
== INT
)
987 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *) value
);
988 else if (config_values
[i
].type
== UNSIGNED_LONG
)
989 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *) value
);
992 cli_print(cli
, "# Plugins");
993 for (i
= 0; i
< MAXPLUGINS
; i
++)
995 if (*config
->plugins
[i
])
997 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
1002 if (config
->as_number
)
1007 cli_print(cli
, "# BGP");
1008 cli_print(cli
, "router bgp %u", config
->as_number
);
1009 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1011 if (!config
->neighbour
[i
].name
[0])
1014 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
1016 k
= config
->neighbour
[i
].keepalive
;
1017 h
= config
->neighbour
[i
].hold
;
1024 k
= BGP_KEEPALIVE_TIME
;
1030 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
1032 if (config
->neighbour
[i
].update_source
.s_addr
!= INADDR_ANY
)
1033 cli_print(cli
, " neighbour %s update-source %s",
1034 config
->neighbour
[i
].name
,
1035 inet_ntoa(config
->neighbour
[i
].update_source
));
1040 cli_print(cli
, "# Filters");
1041 for (i
= 0; i
< MAXFILTER
; i
++)
1043 ip_filter_rulet
*rules
;
1044 if (!*ip_filters
[i
].name
)
1047 cli_print(cli
, "ip access-list %s %s",
1048 ip_filters
[i
].extended
? "extended" : "standard",
1049 ip_filters
[i
].name
);
1051 rules
= ip_filters
[i
].rules
;
1052 while (rules
->action
)
1053 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1056 cli_print(cli
, "# end");
1060 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1062 int i
, free
= 0, used
= 0, show_all
= 0;
1074 if (CLI_HELP_REQUESTED
)
1077 return cli_arg_help(cli
, 1, NULL
);
1079 return cli_arg_help(cli
, 1,
1080 "all", "Show all RADIUS sessions, including unused",
1084 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1088 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1091 for (i
= 1; i
< MAXRADIUS
; i
++)
1093 if (radius
[i
].state
== RADIUSNULL
)
1098 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1100 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1104 states
[radius
[i
].state
],
1110 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1115 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1119 if (CLI_HELP_REQUESTED
)
1120 return CLI_HELP_NO_ARGS
;
1122 cli_print(cli
, "Plugins currently loaded:");
1123 for (i
= 0; i
< MAXPLUGINS
; i
++)
1124 if (*config
->plugins
[i
])
1125 cli_print(cli
, " %s", config
->plugins
[i
]);
1130 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1134 if (CLI_HELP_REQUESTED
)
1135 return CLI_HELP_NO_ARGS
;
1137 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1146 for (i
= 0; i
< MAXSESSION
; i
++)
1148 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1149 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1153 session
[i
].throttle_in
,
1154 session
[i
].throttle_out
,
1156 session
[i
].tbf_out
);
1162 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1164 if (CLI_HELP_REQUESTED
)
1165 return CLI_HELP_NO_ARGS
;
1167 cli_print(cli
, " _\n"
1173 " ( \\ `. `-. _,.-:\\\n"
1174 " \\ \\ `. `-._ __..--' ,-';/\n"
1175 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1176 " `. `. `-._ __..--' ,' /\n"
1177 " `. `-_ ``--..'' _.-' ,'\n"
1178 " `-_ `-.___ __,--' ,'\n"
1179 " `-.__ `----\"\"\" __.-'\n"
1180 "hh `--..____..--'");
1185 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1190 if (CLI_HELP_REQUESTED
)
1191 return cli_arg_help(cli
, argc
> 1,
1192 "USER", "Username of session to drop", NULL
);
1194 if (!config
->cluster_iam_master
)
1196 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1197 fmtaddr(config
->cluster_master_address
, 0));
1204 cli_error(cli
, "Specify a user to drop");
1208 for (i
= 0; i
< argc
; i
++)
1210 if (!(s
= sessionbyuser(argv
[i
])))
1212 cli_error(cli
, "User %s is not connected", argv
[i
]);
1216 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1218 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1219 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1226 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1231 if (CLI_HELP_REQUESTED
)
1232 return cli_arg_help(cli
, argc
> 1,
1233 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1235 if (!config
->cluster_iam_master
)
1237 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1238 fmtaddr(config
->cluster_master_address
, 0));
1245 cli_error(cli
, "Specify a tunnel to drop");
1249 for (i
= 0; i
< argc
; i
++)
1251 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1253 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1259 cli_error(cli
, "Tunnel %d is not connected", t
);
1265 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1269 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1270 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1276 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1281 if (CLI_HELP_REQUESTED
)
1282 return cli_arg_help(cli
, argc
> 1,
1283 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1285 if (!config
->cluster_iam_master
)
1287 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1288 fmtaddr(config
->cluster_master_address
, 0));
1295 cli_error(cli
, "Specify a session id to drop");
1299 for (i
= 0; i
< argc
; i
++)
1301 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1303 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1307 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1309 cli_print(cli
, "Dropping session %d", s
);
1310 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1313 else if (session
[s
].forwardtosession
&& session
[s
].opened
&& !session
[s
].die
)
1315 cli_print(cli
, "Dropping session %d", s
);
1316 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1321 cli_error(cli
, "Session %d is not active.", s
);
1328 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1334 if (CLI_HELP_REQUESTED
)
1339 return cli_arg_help(cli
, 0,
1340 "USER", "Username of session to snoop", NULL
);
1343 return cli_arg_help(cli
, 0,
1344 "A.B.C.D", "IP address of snoop destination", NULL
);
1347 return cli_arg_help(cli
, 0,
1348 "N", "Port of snoop destination", NULL
);
1352 return cli_arg_help(cli
, 1, NULL
);
1359 if (!config
->cluster_iam_master
)
1361 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1362 fmtaddr(config
->cluster_master_address
, 0));
1369 cli_error(cli
, "Specify username, ip and port");
1373 if (!(s
= sessionbyuser(argv
[0])))
1375 cli_error(cli
, "User %s is not connected", argv
[0]);
1379 ip
= inet_addr(argv
[1]);
1380 if (!ip
|| ip
== INADDR_NONE
)
1382 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1386 port
= atoi(argv
[2]);
1389 cli_error(cli
, "Invalid port %s", argv
[2]);
1393 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1394 cli_session_actions
[s
].snoop_ip
= ip
;
1395 cli_session_actions
[s
].snoop_port
= port
;
1396 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1401 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1406 if (CLI_HELP_REQUESTED
)
1407 return cli_arg_help(cli
, argc
> 1,
1408 "USER", "Username of session to unsnoop", NULL
);
1410 if (!config
->cluster_iam_master
)
1412 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1413 fmtaddr(config
->cluster_master_address
, 0));
1420 cli_error(cli
, "Specify a user to unsnoop");
1424 for (i
= 0; i
< argc
; i
++)
1426 if (!(s
= sessionbyuser(argv
[i
])))
1428 cli_error(cli
, "User %s is not connected", argv
[i
]);
1432 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1433 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1439 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1446 throttle USER - throttle in/out to default rate
1447 throttle USER RATE - throttle in/out to default rate
1448 throttle USER in RATE - throttle input only
1449 throttle USER out RATE - throttle output only
1450 throttle USER in RATE out RATE - throttle both
1453 if (CLI_HELP_REQUESTED
)
1458 return cli_arg_help(cli
, 0,
1459 "USER", "Username of session to throttle", NULL
);
1462 return cli_arg_help(cli
, 1,
1463 "RATE", "Rate in kbps (in and out)",
1464 "in", "Select incoming rate",
1465 "out", "Select outgoing rate", NULL
);
1468 return cli_arg_help(cli
, 1,
1469 "in", "Select incoming rate",
1470 "out", "Select outgoing rate", NULL
);
1473 if (isdigit(argv
[1][0]))
1474 return cli_arg_help(cli
, 1, NULL
);
1477 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1480 return cli_arg_help(cli
, argc
> 1, NULL
);
1484 if (!config
->cluster_iam_master
)
1486 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1487 fmtaddr(config
->cluster_master_address
, 0));
1494 cli_error(cli
, "Specify a user to throttle");
1498 if (!(s
= sessionbyuser(argv
[0])))
1500 cli_error(cli
, "User %s is not connected", argv
[0]);
1506 rate_in
= rate_out
= config
->rl_rate
;
1510 rate_in
= rate_out
= atoi(argv
[1]);
1513 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1517 else if (argc
== 3 || argc
== 5)
1520 for (i
= 1; i
< argc
- 1; i
+= 2)
1523 if (MATCH("in", argv
[i
]))
1524 r
= rate_in
= atoi(argv
[i
+1]);
1525 else if (MATCH("out", argv
[i
]))
1526 r
= rate_out
= atoi(argv
[i
+1]);
1530 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1537 cli_error(cli
, "Invalid arguments");
1541 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1543 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1547 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1548 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1549 cli_session_actions
[s
].throttle_in
= rate_in
;
1551 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1552 cli_session_actions
[s
].throttle_out
= rate_out
;
1554 if (cli_session_actions
[s
].throttle_in
== -1 &&
1555 cli_session_actions
[s
].throttle_out
== -1)
1557 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1561 cli_print(cli
, "Throttling user %s", argv
[0]);
1562 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1567 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1572 if (CLI_HELP_REQUESTED
)
1573 return cli_arg_help(cli
, argc
> 1,
1574 "USER", "Username of session to unthrottle", NULL
);
1576 if (!config
->cluster_iam_master
)
1578 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1579 fmtaddr(config
->cluster_master_address
, 0));
1586 cli_error(cli
, "Specify a user to unthrottle");
1590 for (i
= 0; i
< argc
; i
++)
1592 if (!(s
= sessionbyuser(argv
[i
])))
1594 cli_error(cli
, "User %s is not connected", argv
[i
]);
1598 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1600 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1601 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1605 cli_error(cli
, "User %s not throttled", argv
[i
]);
1612 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1616 if (CLI_HELP_REQUESTED
)
1617 return cli_arg_help(cli
, 1,
1618 "all", "Enable debugging for all except \"data\"",
1619 "critical", "", // FIXME: add descriptions
1629 char *p
= (char *) &debug_flags
;
1630 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1634 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1635 (debug_flags
.critical
) ? " critical" : "",
1636 (debug_flags
.error
) ? " error" : "",
1637 (debug_flags
.warning
) ? " warning" : "",
1638 (debug_flags
.info
) ? " info" : "",
1639 (debug_flags
.calls
) ? " calls" : "",
1640 (debug_flags
.data
) ? " data" : "");
1646 cli_print(cli
, "Debugging off");
1650 for (i
= 0; i
< argc
; i
++)
1652 int len
= strlen(argv
[i
]);
1654 if (argv
[i
][0] == 'c' && len
< 2)
1655 len
= 2; /* distinguish [cr]itical from [ca]lls */
1657 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1658 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1659 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1660 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1661 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1662 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1663 if (!strncmp("all", argv
[i
], len
))
1665 memset(&debug_flags
, 1, sizeof(debug_flags
));
1666 debug_flags
.data
= 0;
1670 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1676 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1680 if (CLI_HELP_REQUESTED
)
1681 return cli_arg_help(cli
, 1,
1682 "all", "Disable all debugging",
1683 "critical", "", // FIXME: add descriptions
1693 memset(&debug_flags
, 0, sizeof(debug_flags
));
1697 for (i
= 0; i
< argc
; i
++)
1699 int len
= strlen(argv
[i
]);
1701 if (argv
[i
][0] == 'c' && len
< 2)
1702 len
= 2; /* distinguish [cr]itical from [ca]lls */
1704 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1705 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1706 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1707 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1708 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1709 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1710 if (!strncmp("all", argv
[i
], len
))
1712 memset(&debug_flags
, 0, sizeof(debug_flags
));
1716 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1722 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1724 int i
, firstfree
= 0;
1726 if (CLI_HELP_REQUESTED
)
1727 return cli_arg_help(cli
, argc
> 1,
1728 "PLUGIN", "Name of plugin to load", NULL
);
1732 cli_error(cli
, "Specify a plugin to load");
1736 for (i
= 0; i
< MAXPLUGINS
; i
++)
1738 if (!*config
->plugins
[i
] && !firstfree
)
1740 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1742 cli_error(cli
, "Plugin is already loaded");
1749 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1750 config
->reload_config
= 1;
1751 cli_print(cli
, "Loading plugin %s", argv
[0]);
1757 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1761 if (CLI_HELP_REQUESTED
)
1762 return cli_arg_help(cli
, argc
> 1,
1763 "PLUGIN", "Name of plugin to unload", NULL
);
1767 cli_error(cli
, "Specify a plugin to remove");
1771 for (i
= 0; i
< MAXPLUGINS
; i
++)
1773 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1775 config
->reload_config
= 1;
1776 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1781 cli_error(cli
, "Plugin is not loaded");
1785 static char *duration(time_t secs
)
1787 static char *buf
= NULL
;
1790 if (!buf
) buf
= calloc(64, 1);
1794 int days
= secs
/ 86400;
1795 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1801 int mins
= secs
/ 60;
1802 int hrs
= mins
/ 60;
1805 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1807 else if (secs
>= 60)
1809 int mins
= secs
/ 60;
1810 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1813 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1818 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1821 char buf
[100], *p
= buf
, *loads
[3];
1822 int i
, num_sessions
= 0;
1824 if (CLI_HELP_REQUESTED
)
1825 return CLI_HELP_NO_ARGS
;
1827 fh
= fopen("/proc/loadavg", "r");
1828 fgets(buf
, 100, fh
);
1831 for (i
= 0; i
< 3; i
++)
1832 loads
[i
] = strdup(strsep(&p
, " "));
1835 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1837 for (i
= 1; i
< MAXSESSION
; i
++)
1838 if (session
[i
].opened
) num_sessions
++;
1840 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1842 duration(time_now
- config
->start_time
),
1844 loads
[0], loads
[1], loads
[2]
1846 for (i
= 0; i
< 3; i
++)
1847 if (loads
[i
]) free(loads
[i
]);
1849 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1854 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1858 if (CLI_HELP_REQUESTED
)
1864 int len
= strlen(argv
[0])-1;
1865 for (i
= 0; config_values
[i
].key
; i
++)
1866 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1867 cli_error(cli
, " %s", config_values
[i
].key
);
1873 return cli_arg_help(cli
, 0,
1874 "VALUE", "Value for variable", NULL
);
1878 return cli_arg_help(cli
, 1, NULL
);
1887 cli_error(cli
, "Specify variable and value");
1891 for (i
= 0; config_values
[i
].key
; i
++)
1893 void *value
= ((void *) config
) + config_values
[i
].offset
;
1894 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1896 // Found a value to set
1897 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1898 switch (config_values
[i
].type
)
1901 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1904 *(int *) value
= atoi(argv
[1]);
1907 *(unsigned long *) value
= atol(argv
[1]);
1910 *(short *) value
= atoi(argv
[1]);
1913 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1916 inet_pton(AF_INET6
, argv
[1], value
);
1919 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1925 cli_error(cli
, "Unknown variable type");
1928 config
->reload_config
= 1;
1933 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1937 int regular_stuff(struct cli_def
*cli
)
1943 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1945 char *m
= ringbuffer
->buffer
[i
].message
;
1951 switch (ringbuffer
->buffer
[i
].level
)
1953 case 0: show
= debug_flags
.critical
; break;
1954 case 1: show
= debug_flags
.error
; break;
1955 case 2: show
= debug_flags
.warning
; break;
1956 case 3: show
= debug_flags
.info
; break;
1957 case 4: show
= debug_flags
.calls
; break;
1958 case 5: show
= debug_flags
.data
; break;
1961 if (!show
) continue;
1963 if (!(p
= strchr(m
, '\n')))
1966 cli_error(cli
, "\r%s-%u-%u %.*s",
1967 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1968 ringbuffer
->buffer
[i
].tunnel
,
1969 ringbuffer
->buffer
[i
].session
,
1975 debug_rb_tail
= ringbuffer
->tail
;
1983 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1987 if (CLI_HELP_REQUESTED
)
1988 return cli_arg_help(cli
, argc
> 1,
1989 "<1-65535>", "Autonomous system number", NULL
);
1991 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1993 cli_error(cli
, "Invalid autonomous system number");
1997 if (bgp_configured
&& as
!= config
->as_number
)
1999 cli_error(cli
, "Can't change local AS on a running system");
2003 config
->as_number
= as
;
2004 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
2009 static int find_bgp_neighbour(char const *name
)
2014 in_addr_t addrs
[4] = { 0 };
2017 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
2020 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
2021 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
2023 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2025 if (!config
->neighbour
[i
].name
[0])
2027 if (new == -1) new = i
;
2031 if (!strcmp(name
, config
->neighbour
[i
].name
))
2034 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
2037 for (a
= h
->h_addr_list
; *a
; a
++)
2040 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2041 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2049 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2055 if (CLI_HELP_REQUESTED
)
2060 return cli_arg_help(cli
, 0,
2061 "A.B.C.D", "BGP neighbour address",
2062 "NAME", "BGP neighbour name",
2066 return cli_arg_help(cli
, 0,
2067 "remote-as", "Set remote autonomous system number",
2068 "timers", "Set timers",
2069 "update-source", "Set source address to use for the BGP session",
2073 if (MATCH("remote-as", argv
[1]))
2074 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2076 if (MATCH("timers", argv
[1]))
2079 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2082 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2084 if (argc
== 5 && !argv
[4][1])
2085 return cli_arg_help(cli
, 1, NULL
);
2088 if (MATCH("update-source", argv
[1]))
2089 return cli_arg_help(cli
, argc
> 3, "A.B.C.D", "Source IP address", NULL
);
2097 cli_error(cli
, "Invalid arguments");
2101 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2103 cli_error(cli
, "Invalid neighbour");
2109 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2113 if (MATCH("remote-as", argv
[1]))
2115 int as
= atoi(argv
[2]);
2116 if (as
< 0 || as
> 65535)
2118 cli_error(cli
, "Invalid autonomous system number");
2122 if (!config
->neighbour
[i
].name
[0])
2124 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2125 config
->neighbour
[i
].keepalive
= -1;
2126 config
->neighbour
[i
].hold
= -1;
2127 config
->neighbour
[i
].update_source
.s_addr
= INADDR_ANY
;
2130 config
->neighbour
[i
].as
= as
;
2134 if (MATCH("update-source", argv
[1]))
2136 struct in_addr addr
;
2138 if (!config
->neighbour
[i
].name
[0])
2140 cli_error(cli
, "Specify remote-as first");
2144 if (!inet_aton(argv
[2], &addr
))
2146 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[2]);
2150 config
->neighbour
[i
].update_source
= addr
;
2154 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2156 cli_error(cli
, "Invalid arguments");
2160 if (!config
->neighbour
[i
].name
[0])
2162 cli_error(cli
, "Specify remote-as first");
2166 keepalive
= atoi(argv
[2]);
2167 hold
= atoi(argv
[3]);
2169 if (keepalive
< 1 || keepalive
> 65535)
2171 cli_error(cli
, "Invalid keepalive time");
2175 if (hold
< 3 || hold
> 65535)
2177 cli_error(cli
, "Invalid hold time");
2181 if (keepalive
== BGP_KEEPALIVE_TIME
)
2182 keepalive
= -1; // using default value
2184 if (hold
== BGP_HOLD_TIME
)
2187 config
->neighbour
[i
].keepalive
= keepalive
;
2188 config
->neighbour
[i
].hold
= hold
;
2193 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2197 if (CLI_HELP_REQUESTED
)
2198 return cli_arg_help(cli
, argc
> 0,
2199 "A.B.C.D", "BGP neighbour address",
2200 "NAME", "BGP neighbour name",
2205 cli_error(cli
, "Specify a BGP neighbour");
2209 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2211 cli_error(cli
, "Invalid neighbour");
2215 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2217 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2221 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2225 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2231 if (!bgp_configured
)
2234 if (CLI_HELP_REQUESTED
)
2235 return cli_arg_help(cli
, 1,
2236 "A.B.C.D", "BGP neighbour address",
2237 "NAME", "BGP neighbour name",
2240 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2241 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2245 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2247 if (!*bgp_peers
[i
].name
)
2250 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2251 if (argc
&& strcmp(addr
, argv
[0]) &&
2252 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2258 cli_print(cli
, "Peer AS Address "
2259 "State Retries Retry in Route Pend Timers");
2260 cli_print(cli
, "------------------ ----- --------------- "
2261 "----------- ------- -------- ----- ---- ---------");
2264 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2268 bgp_state_str(bgp_peers
[i
].state
),
2269 bgp_peers
[i
].retry_count
,
2270 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2271 bgp_peers
[i
].routing
? "yes" : "no",
2272 bgp_peers
[i
].update_routes
? "yes" : "no",
2273 bgp_peers
[i
].keepalive
,
2280 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2285 if (!bgp_configured
)
2288 if (CLI_HELP_REQUESTED
)
2289 return cli_arg_help(cli
, 1,
2290 "A.B.C.D", "BGP neighbour address",
2291 "NAME", "BGP neighbour name",
2294 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2296 if (bgp_peers
[i
].state
!= Established
)
2299 if (!bgp_peers
[i
].routing
)
2302 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2303 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2306 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2307 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2313 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2318 if (!bgp_configured
)
2321 if (CLI_HELP_REQUESTED
)
2322 return cli_arg_help(cli
, 1,
2323 "A.B.C.D", "BGP neighbour address",
2324 "NAME", "BGP neighbour name",
2327 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2329 if (bgp_peers
[i
].state
!= Established
)
2332 if (bgp_peers
[i
].routing
)
2335 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2336 if (argc
&& strcmp(addr
, argv
[0]) &&
2337 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2340 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2341 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2347 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2352 if (!bgp_configured
)
2355 if (CLI_HELP_REQUESTED
)
2356 return cli_arg_help(cli
, 1,
2357 "A.B.C.D", "BGP neighbour address",
2358 "NAME", "BGP neighbour name",
2361 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2363 if (!*bgp_peers
[i
].name
)
2366 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2367 if (argc
&& strcmp(addr
, argv
[0]) &&
2368 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2371 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2372 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2380 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2384 if (CLI_HELP_REQUESTED
)
2389 return cli_arg_help(cli
, 0,
2390 "standard", "Standard syntax",
2391 "extended", "Extended syntax",
2395 return cli_arg_help(cli
, argv
[1][1],
2396 "NAME", "Access-list name",
2400 if (argc
== 3 && !argv
[2][1])
2401 return cli_arg_help(cli
, 1, NULL
);
2409 cli_error(cli
, "Specify access-list type and name");
2413 if (MATCH("standard", argv
[0]))
2415 else if (MATCH("extended", argv
[0]))
2419 cli_error(cli
, "Invalid access-list type");
2423 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2424 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2426 cli_error(cli
, "Invalid access-list name");
2430 filt
= find_filter(argv
[1], strlen(argv
[1]));
2435 cli_error(cli
, "Too many access-lists");
2440 if (!*ip_filters
[filt
].name
)
2442 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2443 strcpy(ip_filters
[filt
].name
, argv
[1]);
2444 ip_filters
[filt
].extended
= extended
;
2446 else if (ip_filters
[filt
].extended
!= extended
)
2448 cli_error(cli
, "Access-list is %s",
2449 ip_filters
[filt
].extended
? "extended" : "standard");
2454 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2458 if (filt
< 0 || !*ip_filters
[filt
].name
)
2460 cli_error(cli
, "Access-list not defined");
2465 if (ip_filters
[filt
].used
)
2467 cli_error(cli
, "Access-list in use");
2471 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2475 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2477 return access_list(cli
, argv
, argc
, 1);
2480 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2482 return access_list(cli
, argv
, argc
, 0);
2485 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2487 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2488 return sprintf(buf
, " any");
2490 if (wild
== INADDR_ANY
)
2491 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2493 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2496 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2500 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2501 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2502 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2503 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2504 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2510 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2512 static char buf
[256];
2515 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2518 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2519 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2522 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2526 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2527 p
+= show_ports(p
, &rule
->src_ports
);
2529 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2530 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2531 p
+= show_ports(p
, &rule
->dst_ports
);
2533 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2535 switch (rule
->tcp_flag_op
)
2537 case FILTER_FLAG_OP_EST
:
2538 p
+= sprintf(p
, " established");
2541 case FILTER_FLAG_OP_ANY
:
2542 case FILTER_FLAG_OP_ALL
:
2543 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2544 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2545 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2546 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2547 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2548 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2549 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2550 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2551 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2552 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2553 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2554 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2555 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2561 p
+= sprintf(p
, " fragments");
2566 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2568 static ip_filter_rulet rule
;
2569 struct in_addr addr
;
2573 if (CLI_HELP_REQUESTED
)
2577 cli_arg_help(cli
, 0,
2578 "ip", "Match IP packets",
2579 "tcp", "Match TCP packets",
2580 "udp", "Match UDP packets",
2586 // *sigh*, too darned complex
2587 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2593 cli_error(cli
, "Specify rule details");
2597 memset(&rule
, 0, sizeof(rule
));
2598 rule
.action
= (command
[0] == 'p')
2599 ? FILTER_ACTION_PERMIT
2600 : FILTER_ACTION_DENY
;
2602 if (MATCH("ip", argv
[0]))
2603 rule
.proto
= IPPROTO_IP
;
2604 else if (MATCH("udp", argv
[0]))
2605 rule
.proto
= IPPROTO_UDP
;
2606 else if (MATCH("tcp", argv
[0]))
2607 rule
.proto
= IPPROTO_TCP
;
2610 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2614 for (a
= 1, i
= 0; i
< 2; i
++)
2618 ip_filter_portt
*port
;
2623 wild
= &rule
.src_wild
;
2624 port
= &rule
.src_ports
;
2629 wild
= &rule
.dst_wild
;
2630 port
= &rule
.dst_ports
;
2633 cli_error(cli
, "Specify destination");
2638 if (MATCH("any", argv
[a
]))
2641 *wild
= INADDR_BROADCAST
;
2644 else if (MATCH("host", argv
[a
]))
2648 cli_error(cli
, "Specify host ip address");
2652 if (!inet_aton(argv
[a
], &addr
))
2654 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2666 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2670 if (!inet_aton(argv
[a
], &addr
))
2672 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2678 if (!inet_aton(argv
[++a
], &addr
))
2680 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2684 *wild
= addr
.s_addr
;
2688 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2692 if (MATCH("eq", argv
[a
]))
2693 port
->op
= FILTER_PORT_OP_EQ
;
2694 else if (MATCH("neq", argv
[a
]))
2695 port
->op
= FILTER_PORT_OP_NEQ
;
2696 else if (MATCH("gt", argv
[a
]))
2697 port
->op
= FILTER_PORT_OP_GT
;
2698 else if (MATCH("lt", argv
[a
]))
2699 port
->op
= FILTER_PORT_OP_LT
;
2700 else if (MATCH("range", argv
[a
]))
2701 port
->op
= FILTER_PORT_OP_RANGE
;
2708 cli_error(cli
, "Specify port");
2712 if (!(port
->port
= atoi(argv
[a
])))
2714 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2719 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2724 cli_error(cli
, "Specify port");
2728 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2730 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2737 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2739 if (MATCH("established", argv
[a
]))
2741 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2744 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2745 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2747 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2748 ? FILTER_FLAG_OP_ANY
2749 : FILTER_FLAG_OP_ALL
;
2753 cli_error(cli
, "Specify tcp flags");
2757 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2761 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2763 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2764 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2765 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2766 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2767 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2768 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2771 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2780 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2782 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2784 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2794 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2801 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2803 static ip_filter_rulet rule
;
2804 struct in_addr addr
;
2806 if (CLI_HELP_REQUESTED
)
2810 cli_arg_help(cli
, argv
[0][1],
2811 "A.B.C.D", "Source address",
2812 "any", "Any source address",
2813 "host", "Source host",
2819 if (MATCH("any", argv
[0]))
2821 if (argc
== 2 && !argv
[1][1])
2822 cli_arg_help(cli
, 1, NULL
);
2824 else if (MATCH("host", argv
[0]))
2828 cli_arg_help(cli
, argv
[1][1],
2829 "A.B.C.D", "Host address",
2832 else if (argc
== 3 && !argv
[2][1])
2833 cli_arg_help(cli
, 1, NULL
);
2839 cli_arg_help(cli
, 1,
2840 "A.B.C.D", "Wildcard bits",
2843 else if (argc
== 3 && !argv
[2][1])
2844 cli_arg_help(cli
, 1, NULL
);
2852 cli_error(cli
, "Specify rule details");
2856 memset(&rule
, 0, sizeof(rule
));
2857 rule
.action
= (command
[0] == 'p')
2858 ? FILTER_ACTION_PERMIT
2859 : FILTER_ACTION_DENY
;
2861 rule
.proto
= IPPROTO_IP
;
2862 if (MATCH("any", argv
[0]))
2864 rule
.src_ip
= INADDR_ANY
;
2865 rule
.src_wild
= INADDR_BROADCAST
;
2867 else if (MATCH("host", argv
[0]))
2871 cli_error(cli
, "Specify host ip address");
2875 if (!inet_aton(argv
[1], &addr
))
2877 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2881 rule
.src_ip
= addr
.s_addr
;
2882 rule
.src_wild
= INADDR_ANY
;
2888 cli_error(cli
, "Specify source ip address and wildcard");
2892 if (!inet_aton(argv
[0], &addr
))
2894 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2898 rule
.src_ip
= addr
.s_addr
;
2902 if (!inet_aton(argv
[1], &addr
))
2904 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2908 rule
.src_wild
= addr
.s_addr
;
2911 rule
.src_wild
= INADDR_ANY
;
2917 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2920 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2921 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2922 : access_list_rule_std(cli
, command
, argv
, argc
);
2927 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2929 if (!ip_filters
[filt
].rules
[i
].action
)
2931 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2935 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, offsetof(ip_filter_rulet
, counter
)))
2939 cli_error(cli
, "Too many rules");
2943 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2948 /* filter USER {in|out} FILTER ... */
2949 if (CLI_HELP_REQUESTED
)
2954 return cli_arg_help(cli
, 0,
2955 "USER", "Username of session to filter", NULL
);
2959 return cli_arg_help(cli
, 0,
2960 "in", "Set incoming filter",
2961 "out", "Set outgoing filter", NULL
);
2965 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2966 "NAME", "Filter name", NULL
);
2969 return cli_arg_help(cli
, argc
> 1, NULL
);
2973 if (!config
->cluster_iam_master
)
2975 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2976 fmtaddr(config
->cluster_master_address
, 0));
2981 if (argc
!= 3 && argc
!= 5)
2983 cli_error(cli
, "Specify a user and filters");
2987 if (!(s
= sessionbyuser(argv
[0])))
2989 cli_error(cli
, "User %s is not connected", argv
[0]);
2993 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2994 for (i
= 1; i
< argc
; i
+= 2)
2999 if (MATCH("in", argv
[i
]))
3001 if (session
[s
].filter_in
)
3003 cli_error(cli
, "Input already filtered");
3006 f
= &cli_session_actions
[s
].filter_in
;
3008 else if (MATCH("out", argv
[i
]))
3010 if (session
[s
].filter_out
)
3012 cli_error(cli
, "Output already filtered");
3015 f
= &cli_session_actions
[s
].filter_out
;
3019 cli_error(cli
, "Invalid filter specification");
3023 v
= find_filter(argv
[i
+1], strlen(argv
[i
+1]));
3024 if (v
< 0 || !*ip_filters
[v
].name
)
3026 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
3033 cli_print(cli
, "Filtering user %s", argv
[0]);
3034 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
3039 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3044 if (CLI_HELP_REQUESTED
)
3045 return cli_arg_help(cli
, argc
> 1,
3046 "USER", "Username of session to remove filters from", NULL
);
3048 if (!config
->cluster_iam_master
)
3050 cli_error(cli
, "Can't do this on a slave. Do it on %s",
3051 fmtaddr(config
->cluster_master_address
, 0));
3058 cli_error(cli
, "Specify a user to remove filters from");
3062 for (i
= 0; i
< argc
; i
++)
3064 if (!(s
= sessionbyuser(argv
[i
])))
3066 cli_error(cli
, "User %s is not connected", argv
[i
]);
3070 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3072 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3073 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3077 cli_error(cli
, "User %s not filtered", argv
[i
]);
3084 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3088 if (CLI_HELP_REQUESTED
)
3089 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3093 cli_error(cli
, "Specify a filter name");
3097 for (i
= 0; i
< argc
; i
++)
3099 int f
= find_filter(argv
[i
], strlen(argv
[i
]));
3100 ip_filter_rulet
*rules
;
3102 if (f
< 0 || !*ip_filters
[f
].name
)
3104 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3111 cli_print(cli
, "%s IP access list %s",
3112 ip_filters
[f
].extended
? "Extended" : "Standard",
3113 ip_filters
[f
].name
);
3115 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3117 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3119 cli_print(cli
, "%s (%u match%s)", r
,
3120 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3122 cli_print(cli
, "%s", r
);
3129 static int cmd_shutdown(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3131 if (CLI_HELP_REQUESTED
)
3132 return CLI_HELP_NO_ARGS
;
3134 kill(getppid(), SIGQUIT
);
3138 static int cmd_reload(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3140 if (CLI_HELP_REQUESTED
)
3141 return CLI_HELP_NO_ARGS
;
3143 kill(getppid(), SIGHUP
);
3149 static int cmd_setforward(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3153 if (CLI_HELP_REQUESTED
)
3158 return cli_arg_help(cli
, 0,
3159 "MASK", "Users mask to forward (ex: myISP@operator.com)", NULL
);
3162 return cli_arg_help(cli
, 0,
3163 "IP", "IP of the remote LNS(ex: 64.64.64.64)", NULL
);
3166 return cli_arg_help(cli
, 0,
3167 "PORT", "Port of the remote LNS (ex: 1701)", NULL
);
3170 return cli_arg_help(cli
, 0,
3171 "SECRET", "l2tp secret of the remote LNS (ex: mysecretpsw)", NULL
);
3174 return cli_arg_help(cli
, argc
> 1, NULL
);
3180 cli_error(cli
, "Specify variable and value");
3184 // lac_addremotelns(mask, IP_RemoteLNS, Port_RemoteLNS, SecretRemoteLNS)
3185 ret
= lac_addremotelns(argv
[0], argv
[1], argv
[2], argv
[3]);
3189 cli_print(cli
, "setforward %s %s %s %s", argv
[0], argv
[1], argv
[2], argv
[3]);
3191 cli_print(cli
, "%s Updated, the tunnel must be dropped", argv
[0]);
3194 cli_error(cli
, "ERROR setforward %s %s %s %s", argv
[0], argv
[1], argv
[2], argv
[3]);
3199 static int cmd_show_rmtlnsconf(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3204 if (CLI_HELP_REQUESTED
)
3206 return cli_arg_help(cli
, 0, "remotelns-conf", "Show a list of remote LNS configurations", NULL
);
3209 for (idrlns
= 0; idrlns
< MAXRLNSTUNNEL
; idrlns
++)
3211 if (lac_cli_show_remotelns(idrlns
, strdisp
) != 0)
3212 cli_print(cli
, "%s", strdisp
);