1 // L2TPNS Command Line Interface
16 #include <arpa/inet.h>
18 #include <sys/socket.h>
19 #include <sys/types.h>
27 #include "constants.h"
37 extern tunnelt
*tunnel
;
38 extern bundlet
*bundle
;
39 extern sessiont
*session
;
40 extern radiust
*radius
;
41 extern ippoolt
*ip_address_pool
;
42 extern struct Tstats
*_statistics
;
43 static struct cli_def
*cli
= NULL
;
44 extern configt
*config
;
45 extern config_descriptt config_values
[];
47 extern struct Tringbuffer
*ringbuffer
;
49 extern struct cli_session_actions
*cli_session_actions
;
50 extern struct cli_tunnel_actions
*cli_tunnel_actions
;
51 extern tbft
*filter_list
;
52 extern ip_filtert
*ip_filters
;
66 static int debug_rb_tail
;
67 static char *debug_levels
[] = {
78 static int cmd_show_session(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
79 static int cmd_show_tunnels(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
80 static int cmd_show_users(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
81 static int cmd_show_radius(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
82 static int cmd_show_version(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
83 static int cmd_show_pool(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
84 static int cmd_show_run(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
85 static int cmd_show_banana(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
86 static int cmd_show_plugins(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
87 static int cmd_show_throttle(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
88 static int cmd_write_memory(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
89 static int cmd_drop_user(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
90 static int cmd_drop_tunnel(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
91 static int cmd_drop_session(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
92 static int cmd_snoop(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
93 static int cmd_no_snoop(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
94 static int cmd_throttle(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
95 static int cmd_no_throttle(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
96 static int cmd_debug(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
97 static int cmd_no_debug(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
98 static int cmd_set(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
99 static int cmd_load_plugin(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
100 static int cmd_remove_plugin(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
101 static int cmd_uptime(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
102 static int cmd_shutdown(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
103 static int cmd_reload(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
104 static int cmd_setforward(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
105 static int cmd_show_rmtlnsconf(struct cli_def
*cli
, const 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
, const char *command
, char **argv
, int argc
);
111 static int cmd_clear_counters(struct cli_def
*cli
, const 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
, const char *command
, char **argv
, int argc
);
117 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
118 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
119 static int cmd_show_bgp(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
120 static int cmd_suspend_bgp(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
121 static int cmd_no_suspend_bgp(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
122 static int cmd_restart_bgp(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
125 #define MODE_CONFIG_NACL 9
126 static int cmd_ip_access_list(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
127 static int cmd_no_ip_access_list(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
128 static int cmd_ip_access_list_rule(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
129 static int cmd_filter(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
130 static int cmd_no_filter(struct cli_def
*cli
, const char *command
, char **argv
, int argc
);
131 static int cmd_show_access_list(struct cli_def
*cli
, const 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)))
140 struct cli_command
*c
;
141 struct cli_command
*c2
;
145 c
= cli_register_command(cli
, NULL
, "show", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
146 cli_register_command(cli
, c
, "banana", cmd_show_banana
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a banana");
148 cli_register_command(cli
, c
, "bgp", cmd_show_bgp
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show BGP status");
150 cli_register_command(cli
, c
, "cluster", cmd_show_cluster
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show cluster information");
151 cli_register_command(cli
, c
, "ipcache", cmd_show_ipcache
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show contents of the IP cache");
152 cli_register_command(cli
, c
, "plugins", cmd_show_plugins
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all installed plugins");
153 cli_register_command(cli
, c
, "pool", cmd_show_pool
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the IP address allocation pool");
154 cli_register_command(cli
, c
, "radius", cmd_show_radius
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show active radius queries");
155 cli_register_command(cli
, c
, "running-config", cmd_show_run
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Show the currently running configuration");
156 cli_register_command(cli
, c
, "remotelns-conf", cmd_show_rmtlnsconf
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Show a list of remote LNS configuration");
157 cli_register_command(cli
, c
, "session", cmd_show_session
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of sessions or details for a single session");
158 cli_register_command(cli
, c
, "tbf", cmd_show_tbf
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all token bucket filters in use");
159 cli_register_command(cli
, c
, "throttle", cmd_show_throttle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all throttled sessions and associated TBFs");
160 cli_register_command(cli
, c
, "tunnels", cmd_show_tunnels
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of tunnels or details for a single tunnel");
161 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");
162 cli_register_command(cli
, c
, "version", cmd_show_version
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show currently running software version");
163 cli_register_command(cli
, c
, "access-list", cmd_show_access_list
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show named access-list");
165 c2
= cli_register_command(cli
, c
, "histogram", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
166 cli_register_command(cli
, c2
, "idle", cmd_show_hist_idle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session idle times");
167 cli_register_command(cli
, c2
, "open", cmd_show_hist_open
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session durations");
170 cli_register_command(cli
, c
, "counters", cmd_show_counters
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Display all the internal counters and running totals");
172 c
= cli_register_command(cli
, NULL
, "clear", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
173 cli_register_command(cli
, c
, "counters", cmd_clear_counters
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Clear internal counters");
176 cli_register_command(cli
, NULL
, "uptime", cmd_uptime
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show uptime and bandwidth utilisation");
177 cli_register_command(cli
, NULL
, "shutdown", cmd_shutdown
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Shutdown l2tpns daemon and exit");
178 cli_register_command(cli
, NULL
, "reload", cmd_reload
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Reload configuration");
180 c
= cli_register_command(cli
, NULL
, "write", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
181 cli_register_command(cli
, c
, "memory", cmd_write_memory
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Save the running config to flash");
182 cli_register_command(cli
, c
, "terminal", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the running config");
184 cli_register_command(cli
, NULL
, "snoop", cmd_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable interception of a session");
185 cli_register_command(cli
, NULL
, "throttle", cmd_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable throttling of a session");
186 cli_register_command(cli
, NULL
, "filter", cmd_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Add filtering to a session");
187 cli_register_command(cli
, NULL
, "debug", cmd_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Set the level of logging that is shown on the console");
190 c
= cli_register_command(cli
, NULL
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
191 cli_register_command(cli
, c
, "bgp", cmd_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Withdraw routes from BGP neighbour");
194 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
195 cli_register_command(cli
, c
, "snoop", cmd_no_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable interception of a session");
196 cli_register_command(cli
, c
, "throttle", cmd_no_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable throttling of a session");
197 cli_register_command(cli
, c
, "filter", cmd_no_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Remove filtering from a session");
198 cli_register_command(cli
, c
, "debug", cmd_no_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Turn off logging of a certain level of debugging");
201 c2
= cli_register_command(cli
, c
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
202 cli_register_command(cli
, c2
, "bgp", cmd_no_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Advertise routes to BGP neighbour");
204 c
= cli_register_command(cli
, NULL
, "restart", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
205 cli_register_command(cli
, c
, "bgp", cmd_restart_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Restart BGP");
207 c
= cli_register_command(cli
, NULL
, "router", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
208 cli_register_command(cli
, c
, "bgp", cmd_router_bgp
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Configure BGP");
210 cli_register_command(cli
, NULL
, "neighbour", cmd_router_bgp_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Configure BGP neighbour");
212 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, NULL
);
213 cli_register_command(cli
, c
, "neighbour", cmd_router_bgp_no_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Remove BGP neighbour");
216 c
= cli_register_command(cli
, NULL
, "drop", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
217 cli_register_command(cli
, c
, "user", cmd_drop_user
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a user");
218 cli_register_command(cli
, c
, "tunnel", cmd_drop_tunnel
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a tunnel and all sessions on that tunnel");
219 cli_register_command(cli
, c
, "session", cmd_drop_session
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a session");
221 c
= cli_register_command(cli
, NULL
, "load", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
222 cli_register_command(cli
, c
, "plugin", cmd_load_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Load a plugin");
224 c
= cli_register_command(cli
, NULL
, "remove", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
225 cli_register_command(cli
, c
, "plugin", cmd_remove_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove a plugin");
227 cli_register_command(cli
, NULL
, "set", cmd_set
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set a configuration variable");
229 cli_register_command(cli
, NULL
, "setforward", cmd_setforward
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set the Remote LNS Forward");
231 c
= cli_register_command(cli
, NULL
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
232 cli_register_command(cli
, c
, "access-list", cmd_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Add named access-list");
234 cli_register_command(cli
, NULL
, "permit", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Permit rule");
235 cli_register_command(cli
, NULL
, "deny", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Deny rule");
237 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_CONFIG
, NULL
);
238 c2
= cli_register_command(cli
, c
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
239 cli_register_command(cli
, c2
, "access-list", cmd_no_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove named access-list");
241 // Enable regular processing
242 cli_regular(cli
, regular_stuff
);
244 if (!(f
= fopen(CLIUSERS
, "r")))
246 LOG(0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
250 while (fgets(buf
, 4096, f
))
253 if (*buf
== '#') continue;
254 if ((p
= strchr(buf
, '\r'))) *p
= 0;
255 if ((p
= strchr(buf
, '\n'))) *p
= 0;
257 if (!(p
= strchr((char *)buf
, ':'))) continue;
259 if (!strcmp(buf
, "enable"))
261 cli_allow_enable(cli
, p
);
262 LOG(3, 0, 0, "Setting enable password\n");
266 cli_allow_user(cli
, buf
, p
);
267 LOG(3, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
274 void cli_init_complete(char *hostname
)
277 struct sockaddr_in addr
;
279 if (hostname
&& *hostname
)
280 cli_set_hostname(cli
, hostname
);
282 cli_set_hostname(cli
, "l2tpns");
284 memset(&addr
, 0, sizeof(addr
));
285 clifd
= socket(PF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
286 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
289 // Set cli fd as non-blocking
290 flags
= fcntl(clifd
, F_GETFL
, 0);
291 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
293 addr
.sin_family
= AF_INET
;
294 addr
.sin_addr
.s_addr
= config
->cli_bind_address
; /* defaults to INADDR_ANY */
295 addr
.sin_port
= htons(23);
296 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
298 LOG(0, 0, 0, "Error binding cli on port 23: %s\n", strerror(errno
));
303 if (listen(clifd
, 10) < 0)
305 LOG(0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
312 void cli_do(int sockfd
)
314 int require_auth
= 1;
315 struct sockaddr_in addr
;
316 socklen_t l
= sizeof(addr
);
318 if (fork_and_close()) return;
319 if (getpeername(sockfd
, (struct sockaddr
*) &addr
, &l
) == 0)
321 require_auth
= addr
.sin_addr
.s_addr
!= inet_addr("127.0.0.1");
322 LOG(require_auth
? 3 : 4, 0, 0, "Accepted connection to CLI from %s\n",
323 fmtaddr(addr
.sin_addr
.s_addr
, 0));
326 LOG(0, 0, 0, "getpeername() failed on cli socket. Requiring authentication: %s\n", strerror(errno
));
330 LOG(3, 0, 0, "CLI is remote, requiring authentication\n");
331 if (!cli
->users
) /* paranoia */
333 LOG(0, 0, 0, "No users for remote authentication! Exiting CLI\n");
339 /* no username/pass required */
344 debug_rb_tail
= ringbuffer
->tail
;
346 memset(&debug_flags
, 0, sizeof(debug_flags
));
347 debug_flags
.critical
= 1;
349 cli_loop(cli
, sockfd
);
352 LOG(require_auth
? 3 : 4, 0, 0, "Closed CLI connection from %s\n",
353 fmtaddr(addr
.sin_addr
.s_addr
, 0));
358 static void cli_print_log(struct cli_def
*cli
, const char *string
)
360 LOG(3, 0, 0, "%s\n", string
);
363 void cli_do_file(FILE *fh
)
365 LOG(3, 0, 0, "Reading configuration file\n");
366 cli_print_callback(cli
, cli_print_log
);
367 cli_file(cli
, fh
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
);
368 cli_print_callback(cli
, NULL
);
371 int cli_arg_help(struct cli_def
*cli
, int cr_ok
, char *entry
, ...)
382 if ((p
= strchr(entry
, '%')) && !strchr(p
+1, '%') && p
[1] == 'd')
384 int v
= va_arg(ap
, int);
385 snprintf(buf
, sizeof(buf
), entry
, v
);
391 desc
= va_arg(ap
, char *);
393 cli_error(cli
, " %-20s %s", p
, desc
);
395 cli_error(cli
, " %s", p
);
397 entry
= desc
? va_arg(ap
, char *) : 0;
402 cli_error(cli
, " <cr>");
407 static int cmd_show_session(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
411 if (CLI_HELP_REQUESTED
)
412 return cli_arg_help(cli
, 1,
413 "<1-%d>", MAXSESSION
-1, "Show specific session by id",
419 // Show individual session
420 for (i
= 0; i
< argc
; i
++)
422 unsigned int s
, b_in
, b_out
;
424 if (s
<= 0 || s
>= MAXSESSION
)
426 cli_print(cli
, "Invalid session id \"%s\"", argv
[i
]);
429 cli_print(cli
, "\r\nSession %d:", s
);
430 cli_print(cli
, "\tUser:\t\t%s", session
[s
].user
[0] ? session
[s
].user
: "none");
431 cli_print(cli
, "\tCalling Num:\t%s", session
[s
].calling
);
432 cli_print(cli
, "\tCalled Num:\t%s", session
[s
].called
);
433 cli_print(cli
, "\tTunnel ID:\t%d", session
[s
].tunnel
);
434 cli_print(cli
, "\tPPP Phase:\t%s", ppp_phase(session
[s
].ppp
.phase
));
435 switch (session
[s
].ppp
.phase
)
438 cli_print(cli
, "\t LCP state:\t%s", ppp_state(session
[s
].ppp
.lcp
));
443 cli_print(cli
, "\t IPCP state:\t%s", ppp_state(session
[s
].ppp
.ipcp
));
444 cli_print(cli
, "\t IPV6CP state:\t%s", ppp_state(session
[s
].ppp
.ipv6cp
));
445 cli_print(cli
, "\t CCP state:\t%s", ppp_state(session
[s
].ppp
.ccp
));
447 cli_print(cli
, "\tIP address:\t%s", fmtaddr(htonl(session
[s
].ip
), 0));
448 cli_print(cli
, "\tUnique SID:\t%u", session
[s
].unique_id
);
449 cli_print(cli
, "\tOpened:\t\t%u seconds", session
[s
].opened
? abs(time_now
- session
[s
].opened
) : 0);
450 cli_print(cli
, "\tIdle time:\t%u seconds", session
[s
].last_packet
? abs(time_now
- session
[s
].last_packet
) : 0);
451 if (session
[s
].session_timeout
)
453 clockt opened
= session
[s
].opened
;
454 if (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
455 opened
= bundle
[session
[s
].bundle
].online_time
;
457 cli_print(cli
, "\tSess Timeout:\t%u seconds", session
[s
].session_timeout
- (opened
? abs(time_now
- opened
) : 0));
460 if (session
[s
].idle_timeout
)
461 cli_print(cli
, "\tIdle Timeout:\t%u seconds", session
[s
].idle_timeout
- (session
[s
].last_data
? abs(time_now
- session
[s
].last_data
) : 0));
463 if (session
[s
].timeout
)
465 cli_print(cli
, "\tRemaining time:\t%u",
466 (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
467 ? (unsigned) (session
[s
].timeout
- bundle
[session
[s
].bundle
].online_time
)
468 : (unsigned) (session
[s
].timeout
- (time_now
- session
[s
].opened
)));
471 cli_print(cli
, "\tBytes In/Out:\t%u/%u", session
[s
].cout
, session
[s
].cin
);
472 cli_print(cli
, "\tPkts In/Out:\t%u/%u", session
[s
].pout
, session
[s
].pin
);
473 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
474 cli_print(cli
, "\tRx Speed:\t%u", session
[s
].rx_connect_speed
);
475 cli_print(cli
, "\tTx Speed:\t%u", session
[s
].tx_connect_speed
);
476 if (session
[s
].filter_in
&& session
[s
].filter_in
<= MAXFILTER
)
477 cli_print(cli
, "\tFilter in:\t%u (%s)", session
[s
].filter_in
, ip_filters
[session
[s
].filter_in
- 1].name
);
478 if (session
[s
].filter_out
&& session
[s
].filter_out
<= MAXFILTER
)
479 cli_print(cli
, "\tFilter out:\t%u (%s)", session
[s
].filter_out
, ip_filters
[session
[s
].filter_out
- 1].name
);
480 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
481 cli_print(cli
, "\tIntercepted:\t%s:%d", fmtaddr(session
[s
].snoop_ip
, 0), session
[s
] .snoop_port
);
483 cli_print(cli
, "\tIntercepted:\tno");
485 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
487 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
488 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
489 t
? "YES" : "no", t
? " (" : "",
490 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
492 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
496 b_in
= session
[s
].tbf_in
;
497 b_out
= session
[s
].tbf_out
;
499 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
500 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
501 "ByteSent", "PackSent", "PackDrop", "PackDelay");
504 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
506 (filter_list
[b_in
].next
? "*" : " "),
507 (b_in
< 100 ? "\t" : ""),
508 filter_list
[b_in
].rate
* 8,
509 filter_list
[b_in
].credit
,
510 filter_list
[b_in
].queued
,
511 filter_list
[b_in
].b_queued
,
512 filter_list
[b_in
].p_queued
,
513 filter_list
[b_in
].b_sent
,
514 filter_list
[b_in
].p_sent
,
515 filter_list
[b_in
].p_dropped
,
516 filter_list
[b_in
].p_delayed
);
519 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
521 (filter_list
[b_out
].next
? "*" : " "),
522 (b_out
< 100 ? "\t" : ""),
523 filter_list
[b_out
].rate
* 8,
524 filter_list
[b_out
].credit
,
525 filter_list
[b_out
].queued
,
526 filter_list
[b_out
].b_queued
,
527 filter_list
[b_out
].p_queued
,
528 filter_list
[b_out
].b_sent
,
529 filter_list
[b_out
].p_sent
,
530 filter_list
[b_out
].p_dropped
,
531 filter_list
[b_out
].p_delayed
);
538 cli_print(cli
, "%5s %7s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %10s %-18s %s",
553 "LAC(L)/RLNS(R)/PPPOE(P)",
556 for (i
= 1; i
< MAXSESSION
; i
++)
559 if (!session
[i
].opened
) continue;
560 if (session
[i
].bundle
&& bundle
[session
[i
].bundle
].num_of_links
> 1)
561 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- bundle
[session
[i
].bundle
].online_time
) : 0;
563 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- (time_now
-session
[i
].opened
)) : 0;
564 cli_print(cli
, "%5d %7d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %3s%-20s %s",
566 session
[i
].forwardtosession
,
568 session
[i
].user
[0] ? session
[i
].user
: "*",
569 fmtaddr(htonl(session
[i
].ip
), 0),
570 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
571 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
572 (session
[i
].walled_garden
) ? "Y" : "N",
573 (session
[i
].ppp
.ipv6cp
== Opened
) ? "Y" : "N",
574 abs(time_now
- (unsigned long)session
[i
].opened
),
575 (unsigned long)session
[i
].cout
,
576 (unsigned long)session
[i
].cin
,
577 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
578 (unsigned long)(rem_time
),
579 (session
[i
].tunnel
== TUNNEL_ID_PPPOE
)?"(P)":(tunnel
[session
[i
].tunnel
].isremotelns
?"(R)":"(L)"),
580 (session
[i
].tunnel
== TUNNEL_ID_PPPOE
)?fmtMacAddr(session
[i
].src_hwaddr
):fmtaddr(htonl(tunnel
[session
[i
].tunnel
].ip
), 1),
581 session
[i
].calling
[0] ? session
[i
].calling
: "*");
586 static int cmd_show_tunnels(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
588 int i
, x
, show_all
= 0;
596 if (CLI_HELP_REQUESTED
)
599 return cli_arg_help(cli
, 1,
600 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
603 return cli_arg_help(cli
, 1,
604 "all", "Show all tunnels, including unused",
605 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
612 if (strcmp(argv
[0], "all") == 0)
618 // Show individual tunnel
619 for (i
= 0; i
< argc
; i
++)
624 if (t
<= 0 || t
>= MAXTUNNEL
)
626 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
629 cli_print(cli
, "\r\nTunnel %d:", t
);
630 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
631 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
632 cli_print(cli
, "\tRemote IP:\t%s", fmtaddr(htonl(tunnel
[t
].ip
), 0));
633 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
634 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
635 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
636 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
637 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
638 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
640 for (x
= 0; x
< MAXSESSION
; x
++)
641 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
642 sprintf(s
, "%s%u ", s
, x
);
644 cli_print(cli
, "\tSessions:\t%s", s
);
650 // Show tunnel summary
651 cli_print(cli
, "%4s %20s %20s %6s %s",
658 for (i
= 1; i
< MAXTUNNEL
; i
++)
661 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
663 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
664 cli_print(cli
, "%4d %20s %20s %6s %6d %s",
666 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
667 fmtaddr(htonl(tunnel
[i
].ip
), 0),
668 states
[tunnel
[i
].state
],
670 ,(i
== TUNNEL_ID_PPPOE
)?"Tunnel pppoe":(tunnel
[i
].isremotelns
?"Tunnel To Remote LNS":"Tunnel To LAC")
677 static int cmd_show_users(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
684 if (CLI_HELP_REQUESTED
)
685 return cli_arg_help(cli
, 1,
686 "USER", "Show details for specific username",
689 for (i
= 0; i
< MAXSESSION
; i
++)
691 if (!session
[i
].opened
) continue;
692 if (!session
[i
].user
[0]) continue;
696 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
698 if (strcmp(argv
[j
], session
[i
].user
) == 0)
700 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
701 sargv
[sargc
] = sid
[sargc
];
709 cli_print(cli
, "%s", session
[i
].user
);
713 return cmd_show_session(cli
, "users", sargv
, sargc
);
719 static int cmd_show_counters(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
721 if (CLI_HELP_REQUESTED
)
722 return CLI_HELP_NO_ARGS
;
724 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Ethernet", "Bytes", "Packets", "Errors", "Dropped");
725 cli_print(cli
, "%-10s %10u %10u %10u %10u", "RX",
726 GET_STAT(tun_rx_bytes
),
727 GET_STAT(tun_rx_packets
),
728 GET_STAT(tun_rx_errors
),
729 GET_STAT(tun_rx_dropped
));
730 cli_print(cli
, "%-10s %10u %10u %10u", "TX",
731 GET_STAT(tun_tx_bytes
),
732 GET_STAT(tun_tx_packets
),
733 GET_STAT(tun_tx_errors
));
736 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
737 cli_print(cli
, "%-10s %10u %10u %10u", "RX",
738 GET_STAT(tunnel_rx_bytes
),
739 GET_STAT(tunnel_rx_packets
),
740 GET_STAT(tunnel_rx_errors
));
741 cli_print(cli
, "%-10s %10u %10u %10u %10u", "TX",
742 GET_STAT(tunnel_tx_bytes
),
743 GET_STAT(tunnel_tx_packets
),
744 GET_STAT(tunnel_tx_errors
),
745 GET_STAT(tunnel_retries
));
748 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
749 cli_print(cli
, "-----------------------------------------");
750 cli_print(cli
, "%-30s%u", "radius_retries", GET_STAT(radius_retries
));
751 cli_print(cli
, "%-30s%u", "arp_sent", GET_STAT(arp_sent
));
752 cli_print(cli
, "%-30s%u", "packets_snooped", GET_STAT(packets_snooped
));
753 cli_print(cli
, "%-30s%u", "tunnel_created", GET_STAT(tunnel_created
));
754 cli_print(cli
, "%-30s%u", "session_created", GET_STAT(session_created
));
755 cli_print(cli
, "%-30s%u", "tunnel_timeout", GET_STAT(tunnel_timeout
));
756 cli_print(cli
, "%-30s%u", "session_timeout", GET_STAT(session_timeout
));
757 cli_print(cli
, "%-30s%u", "radius_timeout", GET_STAT(radius_timeout
));
758 cli_print(cli
, "%-30s%u", "radius_overflow", GET_STAT(radius_overflow
));
759 cli_print(cli
, "%-30s%u", "tunnel_overflow", GET_STAT(tunnel_overflow
));
760 cli_print(cli
, "%-30s%u", "session_overflow", GET_STAT(session_overflow
));
761 cli_print(cli
, "%-30s%u", "ip_allocated", GET_STAT(ip_allocated
));
762 cli_print(cli
, "%-30s%u", "ip_freed", GET_STAT(ip_freed
));
763 cli_print(cli
, "%-30s%u", "cluster_forwarded", GET_STAT(c_forwarded
));
764 cli_print(cli
, "%-30s%u", "recv_forward", GET_STAT(recv_forward
));
765 cli_print(cli
, "%-30s%u", "select_called", GET_STAT(select_called
));
766 cli_print(cli
, "%-30s%u", "multi_read_used", GET_STAT(multi_read_used
));
767 cli_print(cli
, "%-30s%u", "multi_read_exceeded", GET_STAT(multi_read_exceeded
));
771 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
772 cli_print(cli
, "-----------------------------------------");
773 cli_print(cli
, "%-30s%u", "call_processtun", GET_STAT(call_processtun
));
774 cli_print(cli
, "%-30s%u", "call_processipout", GET_STAT(call_processipout
));
775 cli_print(cli
, "%-30s%u", "call_processipv6out", GET_STAT(call_processipv6out
));
776 cli_print(cli
, "%-30s%u", "call_processudp", GET_STAT(call_processudp
));
777 cli_print(cli
, "%-30s%u", "call_processpap", GET_STAT(call_processpap
));
778 cli_print(cli
, "%-30s%u", "call_processchap", GET_STAT(call_processchap
));
779 cli_print(cli
, "%-30s%u", "call_processlcp", GET_STAT(call_processlcp
));
780 cli_print(cli
, "%-30s%u", "call_processipcp", GET_STAT(call_processipcp
));
781 cli_print(cli
, "%-30s%u", "call_processipv6cp", GET_STAT(call_processipv6cp
));
782 cli_print(cli
, "%-30s%u", "call_processipin", GET_STAT(call_processipin
));
783 cli_print(cli
, "%-30s%u", "call_processipv6in", GET_STAT(call_processipv6in
));
784 cli_print(cli
, "%-30s%u", "call_processccp", GET_STAT(call_processccp
));
785 cli_print(cli
, "%-30s%u", "call_processrad", GET_STAT(call_processrad
));
786 cli_print(cli
, "%-30s%u", "call_sendarp", GET_STAT(call_sendarp
));
787 cli_print(cli
, "%-30s%u", "call_sendipcp", GET_STAT(call_sendipcp
));
788 cli_print(cli
, "%-30s%u", "call_sendchap", GET_STAT(call_sendchap
));
789 cli_print(cli
, "%-30s%u", "call_sessionbyip", GET_STAT(call_sessionbyip
));
790 cli_print(cli
, "%-30s%u", "call_sessionbyipv6", GET_STAT(call_sessionbyipv6
));
791 cli_print(cli
, "%-30s%u", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
792 cli_print(cli
, "%-30s%u", "call_tunnelsend", GET_STAT(call_tunnelsend
));
793 cli_print(cli
, "%-30s%u", "call_tunnelkill", GET_STAT(call_tunnelkill
));
794 cli_print(cli
, "%-30s%u", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
795 cli_print(cli
, "%-30s%u", "call_sessionkill", GET_STAT(call_sessionkill
));
796 cli_print(cli
, "%-30s%u", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
797 cli_print(cli
, "%-30s%u", "call_sessionsetup", GET_STAT(call_sessionsetup
));
798 cli_print(cli
, "%-30s%u", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
799 cli_print(cli
, "%-30s%u", "call_free_ip_address", GET_STAT(call_free_ip_address
));
800 cli_print(cli
, "%-30s%u", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
801 cli_print(cli
, "%-30s%u", "call_radiussend", GET_STAT(call_radiussend
));
802 cli_print(cli
, "%-30s%u", "call_radiusretry", GET_STAT(call_radiusretry
));
803 cli_print(cli
, "%-30s%u", "call_random_data", GET_STAT(call_random_data
));
804 #endif /* STAT_CALLS */
807 time_t l
= GET_STAT(last_reset
);
809 char *p
= strchr(t
, '\n');
813 cli_print(cli
, "Last counter reset %s", t
);
819 static int cmd_clear_counters(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
821 if (CLI_HELP_REQUESTED
)
822 return CLI_HELP_NO_ARGS
;
824 memset(_statistics
, 0, sizeof(struct Tstats
));
825 SET_STAT(last_reset
, time(NULL
));
827 cli_print(cli
, "Counters cleared");
830 #endif /* STATISTICS */
832 static int cmd_show_version(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
834 if (CLI_HELP_REQUESTED
)
835 return CLI_HELP_NO_ARGS
;
837 cli_print(cli
, "L2TPNS %s", VERSION
);
841 static int cmd_show_pool(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
844 int used
= 0, free
= 0, show_all
= 0;
846 if (!config
->cluster_iam_master
)
848 cli_print(cli
, "Can't do this on a slave. Do it on %s",
849 fmtaddr(config
->cluster_master_address
, 0));
854 if (CLI_HELP_REQUESTED
)
857 return cli_arg_help(cli
, 1, NULL
);
859 return cli_arg_help(cli
, 1,
860 "all", "Show all pool addresses, including unused",
864 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
868 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
869 for (i
= 0; i
< MAXIPPOOL
; i
++)
871 if (!ip_address_pool
[i
].address
) continue;
872 if (ip_address_pool
[i
].assigned
)
874 cli_print(cli
, "%-15s\tY %8d %s",
875 fmtaddr(htonl(ip_address_pool
[i
].address
), 0),
876 ip_address_pool
[i
].session
,
877 session
[ip_address_pool
[i
].session
].user
);
883 if (ip_address_pool
[i
].last
)
884 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
885 fmtaddr(htonl(ip_address_pool
[i
].address
), 0), "",
886 ip_address_pool
[i
].user
, (int) time_now
- ip_address_pool
[i
].last
);
889 cli_print(cli
, "%-15s\tN", fmtaddr(htonl(ip_address_pool
[i
].address
), 0));
896 cli_print(cli
, "(Not displaying unused addresses)");
898 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
902 static FILE *save_config_fh
= 0;
903 static void print_save_config(struct cli_def
*cli
, const char *string
)
906 fprintf(save_config_fh
, "%s\n", string
);
909 static int cmd_write_memory(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
911 if (CLI_HELP_REQUESTED
)
912 return CLI_HELP_NO_ARGS
;
914 if ((save_config_fh
= fopen(config
->config_file
, "w")))
916 cli_print(cli
, "Writing configuration");
917 cli_print_callback(cli
, print_save_config
);
918 cmd_show_run(cli
, command
, argv
, argc
);
919 cli_print_callback(cli
, NULL
);
920 fclose(save_config_fh
);
925 cli_error(cli
, "Error writing configuration: %s", strerror(errno
));
930 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
);
932 static int cmd_show_run(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
935 char ipv6addr
[INET6_ADDRSTRLEN
];
937 if (CLI_HELP_REQUESTED
)
938 return CLI_HELP_NO_ARGS
;
940 cli_print(cli
, "# Current configuration:");
942 for (i
= 0; config_values
[i
].key
; i
++)
944 void *value
= ((void *)config
) + config_values
[i
].offset
;
945 if (config_values
[i
].type
== STRING
)
946 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *) value
);
947 else if (config_values
[i
].type
== IPv4
)
948 cli_print(cli
, "set %s %s", config_values
[i
].key
, fmtaddr(*(in_addr_t
*) value
, 0));
949 else if (config_values
[i
].type
== IPv6
)
950 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_ntop(AF_INET6
, value
, ipv6addr
, INET6_ADDRSTRLEN
));
951 else if (config_values
[i
].type
== SHORT
)
952 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *) value
);
953 else if (config_values
[i
].type
== BOOL
)
954 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *) value
) ? "yes" : "no");
955 else if (config_values
[i
].type
== INT
)
956 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *) value
);
957 else if (config_values
[i
].type
== UNSIGNED_LONG
)
958 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *) value
);
961 cli_print(cli
, "# Plugins");
962 for (i
= 0; i
< MAXPLUGINS
; i
++)
964 if (*config
->plugins
[i
])
966 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
971 if (config
->as_number
)
976 cli_print(cli
, "# BGP");
977 cli_print(cli
, "router bgp %u", config
->as_number
);
978 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
980 if (!config
->neighbour
[i
].name
[0])
983 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
985 k
= config
->neighbour
[i
].keepalive
;
986 h
= config
->neighbour
[i
].hold
;
993 k
= BGP_KEEPALIVE_TIME
;
999 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
1001 if (config
->neighbour
[i
].update_source
.s_addr
!= INADDR_ANY
)
1002 cli_print(cli
, " neighbour %s update-source %s",
1003 config
->neighbour
[i
].name
,
1004 inet_ntoa(config
->neighbour
[i
].update_source
));
1009 cli_print(cli
, "# Filters");
1010 for (i
= 0; i
< MAXFILTER
; i
++)
1012 ip_filter_rulet
*rules
;
1013 if (!*ip_filters
[i
].name
)
1016 cli_print(cli
, "ip access-list %s %s",
1017 ip_filters
[i
].extended
? "extended" : "standard",
1018 ip_filters
[i
].name
);
1020 rules
= ip_filters
[i
].rules
;
1021 while (rules
->action
)
1022 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1025 cli_print(cli
, "# end");
1029 static int cmd_show_radius(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1031 int i
, free
= 0, used
= 0, show_all
= 0;
1043 if (CLI_HELP_REQUESTED
)
1046 return cli_arg_help(cli
, 1, NULL
);
1048 return cli_arg_help(cli
, 1,
1049 "all", "Show all RADIUS sessions, including unused",
1053 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1057 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1060 for (i
= 1; i
< MAXRADIUS
; i
++)
1062 if (radius
[i
].state
== RADIUSNULL
)
1067 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1069 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1073 states
[radius
[i
].state
],
1079 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1084 static int cmd_show_plugins(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1088 if (CLI_HELP_REQUESTED
)
1089 return CLI_HELP_NO_ARGS
;
1091 cli_print(cli
, "Plugins currently loaded:");
1092 for (i
= 0; i
< MAXPLUGINS
; i
++)
1093 if (*config
->plugins
[i
])
1094 cli_print(cli
, " %s", config
->plugins
[i
]);
1099 static int cmd_show_throttle(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1103 if (CLI_HELP_REQUESTED
)
1104 return CLI_HELP_NO_ARGS
;
1106 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1115 for (i
= 0; i
< MAXSESSION
; i
++)
1117 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1118 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1122 session
[i
].throttle_in
,
1123 session
[i
].throttle_out
,
1125 session
[i
].tbf_out
);
1131 static int cmd_show_banana(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1133 if (CLI_HELP_REQUESTED
)
1134 return CLI_HELP_NO_ARGS
;
1136 cli_print(cli
, " _\n"
1142 " ( \\ `. `-. _,.-:\\\n"
1143 " \\ \\ `. `-._ __..--' ,-';/\n"
1144 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1145 " `. `. `-._ __..--' ,' /\n"
1146 " `. `-_ ``--..'' _.-' ,'\n"
1147 " `-_ `-.___ __,--' ,'\n"
1148 " `-.__ `----\"\"\" __.-'\n"
1149 "hh `--..____..--'");
1154 static int cmd_drop_user(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1159 if (CLI_HELP_REQUESTED
)
1160 return cli_arg_help(cli
, argc
> 1,
1161 "USER", "Username of session to drop", NULL
);
1163 if (!config
->cluster_iam_master
)
1165 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1166 fmtaddr(config
->cluster_master_address
, 0));
1173 cli_error(cli
, "Specify a user to drop");
1177 for (i
= 0; i
< argc
; i
++)
1179 if (!(s
= sessionbyuser(argv
[i
])))
1181 cli_error(cli
, "User %s is not connected", argv
[i
]);
1185 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1187 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1188 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1195 static int cmd_drop_tunnel(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1200 if (CLI_HELP_REQUESTED
)
1201 return cli_arg_help(cli
, argc
> 1,
1202 "<1-%d>", MAXTUNNEL
-1, "Tunnel id 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 tunnel to drop");
1218 for (i
= 0; i
< argc
; i
++)
1220 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1222 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1228 cli_error(cli
, "Tunnel %d is not connected", t
);
1234 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1238 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1239 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1245 static int cmd_drop_session(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1250 if (CLI_HELP_REQUESTED
)
1251 return cli_arg_help(cli
, argc
> 1,
1252 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1254 if (!config
->cluster_iam_master
)
1256 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1257 fmtaddr(config
->cluster_master_address
, 0));
1264 cli_error(cli
, "Specify a session id to drop");
1268 for (i
= 0; i
< argc
; i
++)
1270 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1272 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1276 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1278 cli_print(cli
, "Dropping session %d", s
);
1279 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1281 else if (session
[s
].forwardtosession
&& session
[s
].opened
&& !session
[s
].die
)
1283 cli_print(cli
, "Dropping session %d", s
);
1284 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1288 cli_error(cli
, "Session %d is not active.", s
);
1295 static int cmd_snoop(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1301 if (CLI_HELP_REQUESTED
)
1306 return cli_arg_help(cli
, 0,
1307 "USER", "Username of session to snoop", NULL
);
1310 return cli_arg_help(cli
, 0,
1311 "A.B.C.D", "IP address of snoop destination", NULL
);
1314 return cli_arg_help(cli
, 0,
1315 "N", "Port of snoop destination", NULL
);
1319 return cli_arg_help(cli
, 1, NULL
);
1326 if (!config
->cluster_iam_master
)
1328 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1329 fmtaddr(config
->cluster_master_address
, 0));
1336 cli_error(cli
, "Specify username, ip and port");
1340 if (!(s
= sessionbyuser(argv
[0])))
1342 cli_error(cli
, "User %s is not connected", argv
[0]);
1346 ip
= inet_addr(argv
[1]);
1347 if (!ip
|| ip
== INADDR_NONE
)
1349 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1353 port
= atoi(argv
[2]);
1356 cli_error(cli
, "Invalid port %s", argv
[2]);
1360 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1361 cli_session_actions
[s
].snoop_ip
= ip
;
1362 cli_session_actions
[s
].snoop_port
= port
;
1363 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1368 static int cmd_no_snoop(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1373 if (CLI_HELP_REQUESTED
)
1374 return cli_arg_help(cli
, argc
> 1,
1375 "USER", "Username of session to unsnoop", NULL
);
1377 if (!config
->cluster_iam_master
)
1379 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1380 fmtaddr(config
->cluster_master_address
, 0));
1387 cli_error(cli
, "Specify a user to unsnoop");
1391 for (i
= 0; i
< argc
; i
++)
1393 if (!(s
= sessionbyuser(argv
[i
])))
1395 cli_error(cli
, "User %s is not connected", argv
[i
]);
1399 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1400 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1406 static int cmd_throttle(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1413 throttle USER - throttle in/out to default rate
1414 throttle USER RATE - throttle in/out to default rate
1415 throttle USER in RATE - throttle input only
1416 throttle USER out RATE - throttle output only
1417 throttle USER in RATE out RATE - throttle both
1420 if (CLI_HELP_REQUESTED
)
1425 return cli_arg_help(cli
, 0,
1426 "USER", "Username of session to throttle", NULL
);
1429 return cli_arg_help(cli
, 1,
1430 "RATE", "Rate in kbps (in and out)",
1431 "in", "Select incoming rate",
1432 "out", "Select outgoing rate", NULL
);
1435 return cli_arg_help(cli
, 1,
1436 "in", "Select incoming rate",
1437 "out", "Select outgoing rate", NULL
);
1440 if (isdigit(argv
[1][0]))
1441 return cli_arg_help(cli
, 1, NULL
);
1444 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1447 return cli_arg_help(cli
, argc
> 1, NULL
);
1451 if (!config
->cluster_iam_master
)
1453 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1454 fmtaddr(config
->cluster_master_address
, 0));
1461 cli_error(cli
, "Specify a user to throttle");
1465 if (!(s
= sessionbyuser(argv
[0])))
1467 cli_error(cli
, "User %s is not connected", argv
[0]);
1473 rate_in
= rate_out
= config
->rl_rate
;
1477 rate_in
= rate_out
= atoi(argv
[1]);
1480 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1484 else if (argc
== 3 || argc
== 5)
1487 for (i
= 1; i
< argc
- 1; i
+= 2)
1490 if (MATCH("in", argv
[i
]))
1491 r
= rate_in
= atoi(argv
[i
+1]);
1492 else if (MATCH("out", argv
[i
]))
1493 r
= rate_out
= atoi(argv
[i
+1]);
1497 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1504 cli_error(cli
, "Invalid arguments");
1508 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1510 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1514 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1515 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1516 cli_session_actions
[s
].throttle_in
= rate_in
;
1518 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1519 cli_session_actions
[s
].throttle_out
= rate_out
;
1521 if (cli_session_actions
[s
].throttle_in
== -1 &&
1522 cli_session_actions
[s
].throttle_out
== -1)
1524 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1528 cli_print(cli
, "Throttling user %s", argv
[0]);
1529 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1534 static int cmd_no_throttle(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1539 if (CLI_HELP_REQUESTED
)
1540 return cli_arg_help(cli
, argc
> 1,
1541 "USER", "Username of session to unthrottle", NULL
);
1543 if (!config
->cluster_iam_master
)
1545 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1546 fmtaddr(config
->cluster_master_address
, 0));
1553 cli_error(cli
, "Specify a user to unthrottle");
1557 for (i
= 0; i
< argc
; i
++)
1559 if (!(s
= sessionbyuser(argv
[i
])))
1561 cli_error(cli
, "User %s is not connected", argv
[i
]);
1565 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1567 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1568 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1572 cli_error(cli
, "User %s not throttled", argv
[i
]);
1579 static int cmd_debug(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1583 if (CLI_HELP_REQUESTED
)
1584 return cli_arg_help(cli
, 1,
1585 "all", "Enable debugging for all except \"data\"",
1586 "critical", "", // FIXME: add descriptions
1596 char *p
= (char *) &debug_flags
;
1597 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1601 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1602 (debug_flags
.critical
) ? " critical" : "",
1603 (debug_flags
.error
) ? " error" : "",
1604 (debug_flags
.warning
) ? " warning" : "",
1605 (debug_flags
.info
) ? " info" : "",
1606 (debug_flags
.calls
) ? " calls" : "",
1607 (debug_flags
.data
) ? " data" : "");
1613 cli_print(cli
, "Debugging off");
1617 for (i
= 0; i
< argc
; i
++)
1619 int len
= strlen(argv
[i
]);
1621 if (argv
[i
][0] == 'c' && len
< 2)
1622 len
= 2; /* distinguish [cr]itical from [ca]lls */
1624 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1625 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1626 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1627 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1628 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1629 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1630 if (!strncmp("all", argv
[i
], len
))
1632 memset(&debug_flags
, 1, sizeof(debug_flags
));
1633 debug_flags
.data
= 0;
1637 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1643 static int cmd_no_debug(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1647 if (CLI_HELP_REQUESTED
)
1648 return cli_arg_help(cli
, 1,
1649 "all", "Disable all debugging",
1650 "critical", "", // FIXME: add descriptions
1660 memset(&debug_flags
, 0, sizeof(debug_flags
));
1664 for (i
= 0; i
< argc
; i
++)
1666 int len
= strlen(argv
[i
]);
1668 if (argv
[i
][0] == 'c' && len
< 2)
1669 len
= 2; /* distinguish [cr]itical from [ca]lls */
1671 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1672 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1673 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1674 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1675 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1676 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1677 if (!strncmp("all", argv
[i
], len
))
1679 memset(&debug_flags
, 0, sizeof(debug_flags
));
1683 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1689 static int cmd_load_plugin(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1691 int i
, firstfree
= 0;
1693 if (CLI_HELP_REQUESTED
)
1694 return cli_arg_help(cli
, argc
> 1,
1695 "PLUGIN", "Name of plugin to load", NULL
);
1699 cli_error(cli
, "Specify a plugin to load");
1703 for (i
= 0; i
< MAXPLUGINS
; i
++)
1705 if (!*config
->plugins
[i
] && !firstfree
)
1707 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1709 cli_error(cli
, "Plugin is already loaded");
1716 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1717 config
->reload_config
= 1;
1718 cli_print(cli
, "Loading plugin %s", argv
[0]);
1724 static int cmd_remove_plugin(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1728 if (CLI_HELP_REQUESTED
)
1729 return cli_arg_help(cli
, argc
> 1,
1730 "PLUGIN", "Name of plugin to unload", NULL
);
1734 cli_error(cli
, "Specify a plugin to remove");
1738 for (i
= 0; i
< MAXPLUGINS
; i
++)
1740 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1742 config
->reload_config
= 1;
1743 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1748 cli_error(cli
, "Plugin is not loaded");
1752 static char *duration(time_t secs
)
1754 static char *buf
= NULL
;
1757 if (!buf
) buf
= calloc(64, 1);
1761 int days
= secs
/ 86400;
1762 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1768 int mins
= secs
/ 60;
1769 int hrs
= mins
/ 60;
1772 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1774 else if (secs
>= 60)
1776 int mins
= secs
/ 60;
1777 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1780 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1785 static int cmd_uptime(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1788 char buf
[100], *p
= buf
, *loads
[3];
1789 int i
, num_sessions
= 0;
1791 if (CLI_HELP_REQUESTED
)
1792 return CLI_HELP_NO_ARGS
;
1794 fh
= fopen("/proc/loadavg", "r");
1795 p
= fgets(buf
, 100, fh
);
1798 for (i
= 0; i
< 3; i
++)
1799 loads
[i
] = strdup(strsep(&p
, " "));
1802 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1804 for (i
= 1; i
< MAXSESSION
; i
++)
1805 if (session
[i
].opened
) num_sessions
++;
1807 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1809 duration(time_now
- config
->start_time
),
1811 loads
[0], loads
[1], loads
[2]
1813 for (i
= 0; i
< 3; i
++)
1814 if (loads
[i
]) free(loads
[i
]);
1816 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1821 static int cmd_set(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1825 if (CLI_HELP_REQUESTED
)
1831 int len
= strlen(argv
[0])-1;
1832 for (i
= 0; config_values
[i
].key
; i
++)
1833 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1834 cli_error(cli
, " %s", config_values
[i
].key
);
1840 return cli_arg_help(cli
, 0,
1841 "VALUE", "Value for variable", NULL
);
1845 return cli_arg_help(cli
, 1, NULL
);
1854 cli_error(cli
, "Specify variable and value");
1858 for (i
= 0; config_values
[i
].key
; i
++)
1860 void *value
= ((void *) config
) + config_values
[i
].offset
;
1861 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1863 // Found a value to set
1864 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1865 switch (config_values
[i
].type
)
1868 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1871 *(int *) value
= atoi(argv
[1]);
1874 *(unsigned long *) value
= atol(argv
[1]);
1877 *(short *) value
= atoi(argv
[1]);
1880 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1883 inet_pton(AF_INET6
, argv
[1], value
);
1886 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1892 cli_error(cli
, "Unknown variable type");
1895 config
->reload_config
= 1;
1900 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1904 int regular_stuff(struct cli_def
*cli
)
1910 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1912 char *m
= ringbuffer
->buffer
[i
].message
;
1918 switch (ringbuffer
->buffer
[i
].level
)
1920 case 0: show
= debug_flags
.critical
; break;
1921 case 1: show
= debug_flags
.error
; break;
1922 case 2: show
= debug_flags
.warning
; break;
1923 case 3: show
= debug_flags
.info
; break;
1924 case 4: show
= debug_flags
.calls
; break;
1925 case 5: show
= debug_flags
.data
; break;
1928 if (!show
) continue;
1930 if (!(p
= strchr(m
, '\n')))
1933 cli_error(cli
, "\r%s-%u-%u %.*s",
1934 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1935 ringbuffer
->buffer
[i
].tunnel
,
1936 ringbuffer
->buffer
[i
].session
,
1942 debug_rb_tail
= ringbuffer
->tail
;
1950 static int cmd_router_bgp(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
1954 if (CLI_HELP_REQUESTED
)
1955 return cli_arg_help(cli
, argc
> 1,
1956 "<1-65535>", "Autonomous system number", NULL
);
1958 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1960 cli_error(cli
, "Invalid autonomous system number");
1964 if (bgp_configured
&& as
!= config
->as_number
)
1966 cli_error(cli
, "Can't change local AS on a running system");
1970 config
->as_number
= as
;
1971 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
1976 static int find_bgp_neighbour(char const *name
)
1981 in_addr_t addrs
[4] = { 0 };
1984 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
1987 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
1988 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
1990 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1992 if (!config
->neighbour
[i
].name
[0])
1994 if (new == -1) new = i
;
1998 if (!strcmp(name
, config
->neighbour
[i
].name
))
2001 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
2004 for (a
= h
->h_addr_list
; *a
; a
++)
2007 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2008 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2016 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
2022 if (CLI_HELP_REQUESTED
)
2027 return cli_arg_help(cli
, 0,
2028 "A.B.C.D", "BGP neighbour address",
2029 "NAME", "BGP neighbour name",
2033 return cli_arg_help(cli
, 0,
2034 "remote-as", "Set remote autonomous system number",
2035 "timers", "Set timers",
2036 "update-source", "Set source address to use for the BGP session",
2040 if (MATCH("remote-as", argv
[1]))
2041 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2043 if (MATCH("timers", argv
[1]))
2046 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2049 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2051 if (argc
== 5 && !argv
[4][1])
2052 return cli_arg_help(cli
, 1, NULL
);
2055 if (MATCH("update-source", argv
[1]))
2056 return cli_arg_help(cli
, argc
> 3, "A.B.C.D", "Source IP address", NULL
);
2064 cli_error(cli
, "Invalid arguments");
2068 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2070 cli_error(cli
, "Invalid neighbour");
2076 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2080 if (MATCH("remote-as", argv
[1]))
2082 int as
= atoi(argv
[2]);
2083 if (as
< 0 || as
> 65535)
2085 cli_error(cli
, "Invalid autonomous system number");
2089 if (!config
->neighbour
[i
].name
[0])
2091 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2092 config
->neighbour
[i
].keepalive
= -1;
2093 config
->neighbour
[i
].hold
= -1;
2094 config
->neighbour
[i
].update_source
.s_addr
= INADDR_ANY
;
2097 config
->neighbour
[i
].as
= as
;
2101 if (MATCH("update-source", argv
[1]))
2103 struct in_addr addr
;
2105 if (!config
->neighbour
[i
].name
[0])
2107 cli_error(cli
, "Specify remote-as first");
2111 if (!inet_aton(argv
[2], &addr
))
2113 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[2]);
2117 config
->neighbour
[i
].update_source
= addr
;
2121 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2123 cli_error(cli
, "Invalid arguments");
2127 if (!config
->neighbour
[i
].name
[0])
2129 cli_error(cli
, "Specify remote-as first");
2133 keepalive
= atoi(argv
[2]);
2134 hold
= atoi(argv
[3]);
2136 if (keepalive
< 1 || keepalive
> 65535)
2138 cli_error(cli
, "Invalid keepalive time");
2142 if (hold
< 3 || hold
> 65535)
2144 cli_error(cli
, "Invalid hold time");
2148 if (keepalive
== BGP_KEEPALIVE_TIME
)
2149 keepalive
= -1; // using default value
2151 if (hold
== BGP_HOLD_TIME
)
2154 config
->neighbour
[i
].keepalive
= keepalive
;
2155 config
->neighbour
[i
].hold
= hold
;
2160 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
2164 if (CLI_HELP_REQUESTED
)
2165 return cli_arg_help(cli
, argc
> 0,
2166 "A.B.C.D", "BGP neighbour address",
2167 "NAME", "BGP neighbour name",
2172 cli_error(cli
, "Specify a BGP neighbour");
2176 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2178 cli_error(cli
, "Invalid neighbour");
2182 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2184 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2188 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2192 static int cmd_show_bgp(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
2198 if (!bgp_configured
)
2201 if (CLI_HELP_REQUESTED
)
2202 return cli_arg_help(cli
, 1,
2203 "A.B.C.D", "BGP neighbour address",
2204 "NAME", "BGP neighbour name",
2207 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2208 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2212 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2214 if (!*bgp_peers
[i
].name
)
2217 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2218 if (argc
&& strcmp(addr
, argv
[0]) &&
2219 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2224 cli_print(cli
, " ");
2225 cli_print(cli
, "Peer AS Address "
2226 "State Retries Retry in Route Pend Timers");
2227 cli_print(cli
, "------------------ ----- --------------- "
2228 "----------- ------- -------- ----- ---- ---------");
2231 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2235 bgp_state_str(bgp_peers
[i
].state
),
2236 bgp_peers
[i
].retry_count
,
2237 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2238 bgp_peers
[i
].routing
? "yes" : "no",
2239 bgp_peers
[i
].update_routes
? "yes" : "no",
2240 bgp_peers
[i
].keepalive
,
2247 static int cmd_suspend_bgp(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
2252 if (!bgp_configured
)
2255 if (CLI_HELP_REQUESTED
)
2256 return cli_arg_help(cli
, 1,
2257 "A.B.C.D", "BGP neighbour address",
2258 "NAME", "BGP neighbour name",
2261 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2263 if (bgp_peers
[i
].state
!= Established
)
2266 if (!bgp_peers
[i
].routing
)
2269 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2270 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2273 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2274 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2280 static int cmd_no_suspend_bgp(struct cli_def
*cli
, const 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]) &&
2304 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2307 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2308 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2314 static int cmd_restart_bgp(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
2319 if (!bgp_configured
)
2322 if (CLI_HELP_REQUESTED
)
2323 return cli_arg_help(cli
, 1,
2324 "A.B.C.D", "BGP neighbour address",
2325 "NAME", "BGP neighbour name",
2328 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2330 if (!*bgp_peers
[i
].name
)
2333 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2334 if (argc
&& strcmp(addr
, argv
[0]) &&
2335 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2338 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2339 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2347 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2351 if (CLI_HELP_REQUESTED
)
2356 return cli_arg_help(cli
, 0,
2357 "standard", "Standard syntax",
2358 "extended", "Extended syntax",
2362 return cli_arg_help(cli
, argv
[1][1],
2363 "NAME", "Access-list name",
2367 if (argc
== 3 && !argv
[2][1])
2368 return cli_arg_help(cli
, 1, NULL
);
2376 cli_error(cli
, "Specify access-list type and name");
2380 if (MATCH("standard", argv
[0]))
2382 else if (MATCH("extended", argv
[0]))
2386 cli_error(cli
, "Invalid access-list type");
2390 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2391 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2393 cli_error(cli
, "Invalid access-list name");
2397 filt
= find_filter(argv
[1], strlen(argv
[1]));
2402 cli_error(cli
, "Too many access-lists");
2407 if (!*ip_filters
[filt
].name
)
2409 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2410 strcpy(ip_filters
[filt
].name
, argv
[1]);
2411 ip_filters
[filt
].extended
= extended
;
2413 else if (ip_filters
[filt
].extended
!= extended
)
2415 cli_error(cli
, "Access-list is %s",
2416 ip_filters
[filt
].extended
? "extended" : "standard");
2421 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2425 if (filt
< 0 || !*ip_filters
[filt
].name
)
2427 cli_error(cli
, "Access-list not defined");
2432 if (ip_filters
[filt
].used
)
2434 cli_error(cli
, "Access-list in use");
2438 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2442 static int cmd_ip_access_list(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
2444 return access_list(cli
, argv
, argc
, 1);
2447 static int cmd_no_ip_access_list(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
2449 return access_list(cli
, argv
, argc
, 0);
2452 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2454 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2455 return sprintf(buf
, " any");
2457 if (wild
== INADDR_ANY
)
2458 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2460 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2463 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2467 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2468 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2469 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2470 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2471 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2477 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2479 static char buf
[256];
2482 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2485 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2486 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2489 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2493 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2494 p
+= show_ports(p
, &rule
->src_ports
);
2496 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2497 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2498 p
+= show_ports(p
, &rule
->dst_ports
);
2500 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2502 switch (rule
->tcp_flag_op
)
2504 case FILTER_FLAG_OP_EST
:
2505 p
+= sprintf(p
, " established");
2508 case FILTER_FLAG_OP_ANY
:
2509 case FILTER_FLAG_OP_ALL
:
2510 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2511 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2512 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2513 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2514 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2515 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2516 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2517 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2518 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2519 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2520 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2521 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2522 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2528 p
+= sprintf(p
, " fragments");
2533 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
2535 static ip_filter_rulet rule
;
2536 struct in_addr addr
;
2540 if (CLI_HELP_REQUESTED
)
2544 cli_arg_help(cli
, 0,
2545 "ip", "Match IP packets",
2546 "tcp", "Match TCP packets",
2547 "udp", "Match UDP packets",
2553 // *sigh*, too darned complex
2554 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2560 cli_error(cli
, "Specify rule details");
2564 memset(&rule
, 0, sizeof(rule
));
2565 rule
.action
= (command
[0] == 'p')
2566 ? FILTER_ACTION_PERMIT
2567 : FILTER_ACTION_DENY
;
2569 if (MATCH("ip", argv
[0]))
2570 rule
.proto
= IPPROTO_IP
;
2571 else if (MATCH("udp", argv
[0]))
2572 rule
.proto
= IPPROTO_UDP
;
2573 else if (MATCH("tcp", argv
[0]))
2574 rule
.proto
= IPPROTO_TCP
;
2577 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2581 for (a
= 1, i
= 0; i
< 2; i
++)
2585 ip_filter_portt
*port
;
2590 wild
= &rule
.src_wild
;
2591 port
= &rule
.src_ports
;
2596 wild
= &rule
.dst_wild
;
2597 port
= &rule
.dst_ports
;
2600 cli_error(cli
, "Specify destination");
2605 if (MATCH("any", argv
[a
]))
2608 *wild
= INADDR_BROADCAST
;
2611 else if (MATCH("host", argv
[a
]))
2615 cli_error(cli
, "Specify host ip address");
2619 if (!inet_aton(argv
[a
], &addr
))
2621 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2633 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2637 if (!inet_aton(argv
[a
], &addr
))
2639 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2645 if (!inet_aton(argv
[++a
], &addr
))
2647 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2651 *wild
= addr
.s_addr
;
2655 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2659 if (MATCH("eq", argv
[a
]))
2660 port
->op
= FILTER_PORT_OP_EQ
;
2661 else if (MATCH("neq", argv
[a
]))
2662 port
->op
= FILTER_PORT_OP_NEQ
;
2663 else if (MATCH("gt", argv
[a
]))
2664 port
->op
= FILTER_PORT_OP_GT
;
2665 else if (MATCH("lt", argv
[a
]))
2666 port
->op
= FILTER_PORT_OP_LT
;
2667 else if (MATCH("range", argv
[a
]))
2668 port
->op
= FILTER_PORT_OP_RANGE
;
2675 cli_error(cli
, "Specify port");
2679 if (!(port
->port
= atoi(argv
[a
])))
2681 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2686 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2691 cli_error(cli
, "Specify port");
2695 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2697 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2704 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2706 if (MATCH("established", argv
[a
]))
2708 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2711 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2712 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2714 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2715 ? FILTER_FLAG_OP_ANY
2716 : FILTER_FLAG_OP_ALL
;
2720 cli_error(cli
, "Specify tcp flags");
2724 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2728 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2730 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2731 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2732 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2733 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2734 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2735 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2738 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2747 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2749 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2751 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2761 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2768 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
2770 static ip_filter_rulet rule
;
2771 struct in_addr addr
;
2773 if (CLI_HELP_REQUESTED
)
2777 cli_arg_help(cli
, argv
[0][1],
2778 "A.B.C.D", "Source address",
2779 "any", "Any source address",
2780 "host", "Source host",
2786 if (MATCH("any", argv
[0]))
2788 if (argc
== 2 && !argv
[1][1])
2789 cli_arg_help(cli
, 1, NULL
);
2791 else if (MATCH("host", argv
[0]))
2795 cli_arg_help(cli
, argv
[1][1],
2796 "A.B.C.D", "Host address",
2799 else if (argc
== 3 && !argv
[2][1])
2800 cli_arg_help(cli
, 1, NULL
);
2806 cli_arg_help(cli
, 1,
2807 "A.B.C.D", "Wildcard bits",
2810 else if (argc
== 3 && !argv
[2][1])
2811 cli_arg_help(cli
, 1, NULL
);
2819 cli_error(cli
, "Specify rule details");
2823 memset(&rule
, 0, sizeof(rule
));
2824 rule
.action
= (command
[0] == 'p')
2825 ? FILTER_ACTION_PERMIT
2826 : FILTER_ACTION_DENY
;
2828 rule
.proto
= IPPROTO_IP
;
2829 if (MATCH("any", argv
[0]))
2831 rule
.src_ip
= INADDR_ANY
;
2832 rule
.src_wild
= INADDR_BROADCAST
;
2834 else if (MATCH("host", argv
[0]))
2838 cli_error(cli
, "Specify host ip address");
2842 if (!inet_aton(argv
[1], &addr
))
2844 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2848 rule
.src_ip
= addr
.s_addr
;
2849 rule
.src_wild
= INADDR_ANY
;
2855 cli_error(cli
, "Specify source ip address and wildcard");
2859 if (!inet_aton(argv
[0], &addr
))
2861 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2865 rule
.src_ip
= addr
.s_addr
;
2869 if (!inet_aton(argv
[1], &addr
))
2871 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2875 rule
.src_wild
= addr
.s_addr
;
2878 rule
.src_wild
= INADDR_ANY
;
2884 static int cmd_ip_access_list_rule(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
2887 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2888 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2889 : access_list_rule_std(cli
, command
, argv
, argc
);
2894 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2896 if (!ip_filters
[filt
].rules
[i
].action
)
2898 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2902 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, offsetof(ip_filter_rulet
, counter
)))
2906 cli_error(cli
, "Too many rules");
2910 static int cmd_filter(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
2915 /* filter USER {in|out} FILTER ... */
2916 if (CLI_HELP_REQUESTED
)
2921 return cli_arg_help(cli
, 0,
2922 "USER", "Username of session to filter", NULL
);
2926 return cli_arg_help(cli
, 0,
2927 "in", "Set incoming filter",
2928 "out", "Set outgoing filter", NULL
);
2932 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2933 "NAME", "Filter name", NULL
);
2936 return cli_arg_help(cli
, argc
> 1, NULL
);
2940 if (!config
->cluster_iam_master
)
2942 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2943 fmtaddr(config
->cluster_master_address
, 0));
2948 if (argc
!= 3 && argc
!= 5)
2950 cli_error(cli
, "Specify a user and filters");
2954 if (!(s
= sessionbyuser(argv
[0])))
2956 cli_error(cli
, "User %s is not connected", argv
[0]);
2960 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2961 for (i
= 1; i
< argc
; i
+= 2)
2966 if (MATCH("in", argv
[i
]))
2968 if (session
[s
].filter_in
)
2970 cli_error(cli
, "Input already filtered");
2973 f
= &cli_session_actions
[s
].filter_in
;
2975 else if (MATCH("out", argv
[i
]))
2977 if (session
[s
].filter_out
)
2979 cli_error(cli
, "Output already filtered");
2982 f
= &cli_session_actions
[s
].filter_out
;
2986 cli_error(cli
, "Invalid filter specification");
2990 v
= find_filter(argv
[i
+1], strlen(argv
[i
+1]));
2991 if (v
< 0 || !*ip_filters
[v
].name
)
2993 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
3000 cli_print(cli
, "Filtering user %s", argv
[0]);
3001 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
3006 static int cmd_no_filter(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
3011 if (CLI_HELP_REQUESTED
)
3012 return cli_arg_help(cli
, argc
> 1,
3013 "USER", "Username of session to remove filters from", NULL
);
3015 if (!config
->cluster_iam_master
)
3017 cli_error(cli
, "Can't do this on a slave. Do it on %s",
3018 fmtaddr(config
->cluster_master_address
, 0));
3025 cli_error(cli
, "Specify a user to remove filters from");
3029 for (i
= 0; i
< argc
; i
++)
3031 if (!(s
= sessionbyuser(argv
[i
])))
3033 cli_error(cli
, "User %s is not connected", argv
[i
]);
3037 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3039 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3040 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3044 cli_error(cli
, "User %s not filtered", argv
[i
]);
3051 static int cmd_show_access_list(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
3055 if (CLI_HELP_REQUESTED
)
3056 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3060 cli_error(cli
, "Specify a filter name");
3064 for (i
= 0; i
< argc
; i
++)
3066 int f
= find_filter(argv
[i
], strlen(argv
[i
]));
3067 ip_filter_rulet
*rules
;
3069 if (f
< 0 || !*ip_filters
[f
].name
)
3071 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3076 cli_print(cli
, " ");
3078 cli_print(cli
, "%s IP access list %s",
3079 ip_filters
[f
].extended
? "Extended" : "Standard",
3080 ip_filters
[f
].name
);
3082 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3084 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3086 cli_print(cli
, "%s (%u match%s)", r
,
3087 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3089 cli_print(cli
, "%s", r
);
3096 static int cmd_shutdown(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
3098 if (CLI_HELP_REQUESTED
)
3099 return CLI_HELP_NO_ARGS
;
3101 kill(getppid(), SIGQUIT
);
3105 static int cmd_reload(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
3107 if (CLI_HELP_REQUESTED
)
3108 return CLI_HELP_NO_ARGS
;
3110 kill(getppid(), SIGHUP
);
3114 static int cmd_setforward(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
3118 if (CLI_HELP_REQUESTED
)
3123 return cli_arg_help(cli
, 0,
3124 "MASK", "Users mask to forward (ex: myISP@operator.com)", NULL
);
3127 return cli_arg_help(cli
, 0,
3128 "IP", "IP of the remote LNS(ex: 64.64.64.64)", NULL
);
3131 return cli_arg_help(cli
, 0,
3132 "PORT", "Port of the remote LNS (ex: 1701)", NULL
);
3135 return cli_arg_help(cli
, 0,
3136 "SECRET", "l2tp secret of the remote LNS (ex: mysecretpsw)", NULL
);
3139 return cli_arg_help(cli
, argc
> 1, NULL
);
3145 cli_error(cli
, "Specify variable and value");
3149 // lac_addremotelns(mask, IP_RemoteLNS, Port_RemoteLNS, SecretRemoteLNS)
3150 ret
= lac_addremotelns(argv
[0], argv
[1], argv
[2], argv
[3]);
3154 cli_print(cli
, "setforward %s %s %s %s", argv
[0], argv
[1], argv
[2], argv
[3]);
3156 cli_print(cli
, "%s Updated, the tunnel must be dropped", argv
[0]);
3159 cli_error(cli
, "ERROR setforward %s %s %s %s", argv
[0], argv
[1], argv
[2], argv
[3]);
3164 static int cmd_show_rmtlnsconf(struct cli_def
*cli
, const char *command
, char **argv
, int argc
)
3169 if (CLI_HELP_REQUESTED
)
3171 return cli_arg_help(cli
, 0, "remotelns-conf", "Show a list of remote LNS configurations", NULL
);
3174 for (idrlns
= 0; idrlns
< MAXRLNSTUNNEL
; idrlns
++)
3176 if (lac_cli_show_remotelns(idrlns
, strdisp
) != 0)
3177 cli_print(cli
, "%s", strdisp
);