1 // L2TPNS Command Line Interface
4 char const *cvs_name
= "$Name: $";
5 char const *cvs_id_cli
= "$Id: cli.c,v 1.61 2005-06-04 15:42:35 bodea Exp $";
18 #include <arpa/inet.h>
20 #include <sys/socket.h>
21 #include <sys/types.h>
36 extern tunnelt
*tunnel
;
37 extern sessiont
*session
;
38 extern radiust
*radius
;
39 extern ippoolt
*ip_address_pool
;
40 extern struct Tstats
*_statistics
;
41 static struct cli_def
*cli
= NULL
;
42 extern configt
*config
;
43 extern config_descriptt config_values
[];
45 extern struct Tringbuffer
*ringbuffer
;
47 extern struct cli_session_actions
*cli_session_actions
;
48 extern struct cli_tunnel_actions
*cli_tunnel_actions
;
49 extern tbft
*filter_list
;
50 extern ip_filtert
*ip_filters
;
64 static int debug_rb_tail
;
65 static char *debug_levels
[] = {
76 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
77 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
78 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
79 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
80 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
81 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
82 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
83 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
84 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
85 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
86 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
87 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
88 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
89 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
90 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
91 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
92 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
93 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
94 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
95 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
96 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
97 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
98 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
99 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
101 static int regular_stuff(struct cli_def
*cli
);
102 static void parsemac(char *string
, char mac
[6]);
105 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
106 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
107 #endif /* STATISTICS */
110 #define MODE_CONFIG_BGP 8
111 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
112 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
113 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
114 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
115 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
116 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
117 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
120 #define MODE_CONFIG_NACL 9
121 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
122 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
123 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
124 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
125 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
126 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
128 /* match if b is a substr of a */
129 #define MATCH(a,b) (!strncmp((a), (b), strlen(b)))
131 void init_cli(char *hostname
)
135 struct cli_command
*c
;
136 struct cli_command
*c2
;
138 struct sockaddr_in addr
;
141 if (hostname
&& *hostname
)
142 cli_set_hostname(cli
, hostname
);
144 cli_set_hostname(cli
, "l2tpns");
146 c
= cli_register_command(cli
, NULL
, "show", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
147 cli_register_command(cli
, c
, "banana", cmd_show_banana
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a banana");
149 cli_register_command(cli
, c
, "bgp", cmd_show_bgp
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show BGP status");
151 cli_register_command(cli
, c
, "cluster", cmd_show_cluster
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show cluster information");
152 cli_register_command(cli
, c
, "ipcache", cmd_show_ipcache
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show contents of the IP cache");
153 cli_register_command(cli
, c
, "plugins", cmd_show_plugins
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all installed plugins");
154 cli_register_command(cli
, c
, "pool", cmd_show_pool
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the IP address allocation pool");
155 cli_register_command(cli
, c
, "radius", cmd_show_radius
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show active radius queries");
156 cli_register_command(cli
, c
, "running-config", cmd_show_run
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Show the currently running 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");
178 c
= cli_register_command(cli
, NULL
, "write", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
179 cli_register_command(cli
, c
, "memory", cmd_write_memory
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Save the running config to flash");
180 cli_register_command(cli
, c
, "terminal", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the running config");
182 cli_register_command(cli
, NULL
, "snoop", cmd_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable interception of a session");
183 cli_register_command(cli
, NULL
, "throttle", cmd_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable throttling of a session");
184 cli_register_command(cli
, NULL
, "filter", cmd_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Add filtering to a session");
185 cli_register_command(cli
, NULL
, "debug", cmd_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Set the level of logging that is shown on the console");
188 c
= cli_register_command(cli
, NULL
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
189 cli_register_command(cli
, c
, "bgp", cmd_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Withdraw routes from BGP neighbour");
192 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
193 cli_register_command(cli
, c
, "snoop", cmd_no_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable interception of a session");
194 cli_register_command(cli
, c
, "throttle", cmd_no_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable throttling of a session");
195 cli_register_command(cli
, c
, "filter", cmd_no_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Remove filtering from a session");
196 cli_register_command(cli
, c
, "debug", cmd_no_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Turn off logging of a certain level of debugging");
199 c2
= cli_register_command(cli
, c
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
200 cli_register_command(cli
, c2
, "bgp", cmd_no_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Advertise routes to BGP neighbour");
202 c
= cli_register_command(cli
, NULL
, "restart", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
203 cli_register_command(cli
, c
, "bgp", cmd_restart_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Restart BGP");
205 c
= cli_register_command(cli
, NULL
, "router", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
206 cli_register_command(cli
, c
, "bgp", cmd_router_bgp
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Configure BGP");
208 cli_register_command(cli
, NULL
, "neighbour", cmd_router_bgp_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Configure BGP neighbour");
210 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, NULL
);
211 cli_register_command(cli
, c
, "neighbour", cmd_router_bgp_no_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Remove BGP neighbour");
214 c
= cli_register_command(cli
, NULL
, "drop", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
215 cli_register_command(cli
, c
, "user", cmd_drop_user
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a user");
216 cli_register_command(cli
, c
, "tunnel", cmd_drop_tunnel
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a tunnel and all sessions on that tunnel");
217 cli_register_command(cli
, c
, "session", cmd_drop_session
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a session");
219 c
= cli_register_command(cli
, NULL
, "load", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
220 cli_register_command(cli
, c
, "plugin", cmd_load_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Load a plugin");
222 c
= cli_register_command(cli
, NULL
, "remove", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
223 cli_register_command(cli
, c
, "plugin", cmd_remove_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove a plugin");
225 cli_register_command(cli
, NULL
, "set", cmd_set
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set a configuration variable");
227 c
= cli_register_command(cli
, NULL
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
228 cli_register_command(cli
, c
, "access-list", cmd_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Add named access-list");
230 cli_register_command(cli
, NULL
, "permit", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Permit rule");
231 cli_register_command(cli
, NULL
, "deny", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Deny rule");
233 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_CONFIG
, NULL
);
234 c2
= cli_register_command(cli
, c
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
235 cli_register_command(cli
, c2
, "access-list", cmd_no_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove named access-list");
237 // Enable regular processing
238 cli_regular(cli
, regular_stuff
);
240 if (!(f
= fopen(CLIUSERS
, "r")))
242 LOG(0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
246 while (fgets(buf
, 4096, f
))
249 if (*buf
== '#') continue;
250 if ((p
= strchr(buf
, '\r'))) *p
= 0;
251 if ((p
= strchr(buf
, '\n'))) *p
= 0;
253 if (!(p
= strchr((char *)buf
, ':'))) continue;
255 if (!strcmp(buf
, "enable"))
257 cli_allow_enable(cli
, p
);
258 LOG(3, 0, 0, "Setting enable password\n");
262 cli_allow_user(cli
, buf
, p
);
263 LOG(3, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
269 memset(&addr
, 0, sizeof(addr
));
270 clifd
= socket(PF_INET
, SOCK_STREAM
, 6);
271 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
274 // Set cli fd as non-blocking
275 flags
= fcntl(clifd
, F_GETFL
, 0);
276 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
278 addr
.sin_family
= AF_INET
;
279 addr
.sin_port
= htons(23);
280 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
282 LOG(0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
288 void cli_do(int sockfd
)
290 int require_auth
= 1;
291 struct sockaddr_in addr
;
292 int l
= sizeof(addr
);
294 if (fork_and_close()) return;
295 if (getpeername(sockfd
, (struct sockaddr
*)&addr
, &l
) == 0)
297 require_auth
= addr
.sin_addr
.s_addr
!= inet_addr("127.0.0.1");
298 LOG(require_auth
? 3 : 4, 0, 0, "Accepted connection to CLI from %s\n",
299 fmtaddr(addr
.sin_addr
.s_addr
, 0));
302 LOG(0, 0, 0, "getpeername() failed on cli socket. Requiring authentication: %s\n", strerror(errno
));
306 LOG(3, 0, 0, "CLI is remote, requiring authentication\n");
307 if (!cli
->users
) /* paranoia */
309 LOG(0, 0, 0, "No users for remote authentication! Exiting CLI\n");
315 /* no username/pass required */
320 debug_rb_tail
= ringbuffer
->tail
;
322 memset(&debug_flags
, 0, sizeof(debug_flags
));
323 debug_flags
.critical
= 1;
325 cli_loop(cli
, sockfd
);
328 LOG(require_auth
? 3 : 4, 0, 0, "Closed CLI connection from %s\n",
329 fmtaddr(addr
.sin_addr
.s_addr
, 0));
334 static void cli_print_log(struct cli_def
*cli
, char *string
)
336 LOG(3, 0, 0, "%s\n", string
);
339 void cli_do_file(FILE *fh
)
341 LOG(3, 0, 0, "Reading configuration file\n");
342 cli_print_callback(cli
, cli_print_log
);
343 cli_file(cli
, fh
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
);
344 cli_print_callback(cli
, NULL
);
347 int cli_arg_help(struct cli_def
*cli
, int cr_ok
, char *entry
, ...)
358 if ((p
= strchr(entry
, '%')) && !strchr(p
+1, '%') && p
[1] == 'd')
360 int v
= va_arg(ap
, int);
361 snprintf(buf
, sizeof(buf
), entry
, v
);
367 desc
= va_arg(ap
, char *);
369 cli_error(cli
, " %-20s %s", p
, desc
);
371 cli_error(cli
, " %s", p
);
373 entry
= desc
? va_arg(ap
, char *) : 0;
378 cli_error(cli
, " <cr>");
383 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
387 if (CLI_HELP_REQUESTED
)
388 return cli_arg_help(cli
, 1,
389 "<1-%d>", MAXSESSION
-1, "Show specific session by id",
395 // Show individual session
396 for (i
= 0; i
< argc
; i
++)
398 unsigned int s
, b_in
, b_out
;
400 if (s
<= 0 || s
>= MAXSESSION
)
402 cli_print(cli
, "Invalid session id \"%s\"", argv
[i
]);
405 cli_print(cli
, "\r\nSession %d:", s
);
406 cli_print(cli
, "\tUser:\t\t%s", session
[s
].user
[0] ? session
[s
].user
: "none");
407 cli_print(cli
, "\tCalling Num:\t%s", session
[s
].calling
);
408 cli_print(cli
, "\tCalled Num:\t%s", session
[s
].called
);
409 cli_print(cli
, "\tTunnel ID:\t%d", session
[s
].tunnel
);
410 cli_print(cli
, "\tIP address:\t%s", fmtaddr(htonl(session
[s
].ip
), 0));
411 cli_print(cli
, "\tUnique SID:\t%u", session
[s
].unique_id
);
412 cli_print(cli
, "\tOpened:\t\t%u seconds", abs(time_now
- session
[s
].opened
));
413 cli_print(cli
, "\tIdle time:\t%u seconds", abs(time_now
- session
[s
].last_packet
));
414 cli_print(cli
, "\tNext Recv:\t%u", session
[s
].nr
);
415 cli_print(cli
, "\tNext Send:\t%u", session
[s
].ns
);
416 cli_print(cli
, "\tBytes In/Out:\t%u/%u", session
[s
].cout
, session
[s
].cin
);
417 cli_print(cli
, "\tPkts In/Out:\t%u/%u", session
[s
].pout
, session
[s
].pin
);
418 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
419 cli_print(cli
, "\tRx Speed:\t%u", session
[s
].rx_connect_speed
);
420 cli_print(cli
, "\tTx Speed:\t%u", session
[s
].tx_connect_speed
);
421 if (session
[s
].filter_in
&& session
[s
].filter_in
<= MAXFILTER
)
422 cli_print(cli
, "\tFilter in:\t%u (%s)", session
[s
].filter_in
, ip_filters
[session
[s
].filter_in
- 1].name
);
423 if (session
[s
].filter_out
&& session
[s
].filter_out
<= MAXFILTER
)
424 cli_print(cli
, "\tFilter out:\t%u (%s)", session
[s
].filter_out
, ip_filters
[session
[s
].filter_out
- 1].name
);
425 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
426 cli_print(cli
, "\tIntercepted:\t%s:%d", fmtaddr(session
[s
].snoop_ip
, 0), session
[s
] .snoop_port
);
428 cli_print(cli
, "\tIntercepted:\tno");
430 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
432 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
433 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
434 t
? "YES" : "no", t
? " (" : "",
435 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
437 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
441 b_in
= session
[s
].tbf_in
;
442 b_out
= session
[s
].tbf_out
;
444 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
445 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
446 "ByteSent", "PackSent", "PackDrop", "PackDelay");
449 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
451 (filter_list
[b_in
].next
? "*" : " "),
452 (b_in
< 100 ? "\t" : ""),
453 filter_list
[b_in
].rate
* 8,
454 filter_list
[b_in
].credit
,
455 filter_list
[b_in
].queued
,
456 filter_list
[b_in
].b_queued
,
457 filter_list
[b_in
].p_queued
,
458 filter_list
[b_in
].b_sent
,
459 filter_list
[b_in
].p_sent
,
460 filter_list
[b_in
].p_dropped
,
461 filter_list
[b_in
].p_delayed
);
464 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
466 (filter_list
[b_out
].next
? "*" : " "),
467 (b_out
< 100 ? "\t" : ""),
468 filter_list
[b_out
].rate
* 8,
469 filter_list
[b_out
].credit
,
470 filter_list
[b_out
].queued
,
471 filter_list
[b_out
].b_queued
,
472 filter_list
[b_out
].p_queued
,
473 filter_list
[b_out
].b_sent
,
474 filter_list
[b_out
].p_sent
,
475 filter_list
[b_out
].p_dropped
,
476 filter_list
[b_out
].p_delayed
);
483 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %-15s %s",
499 for (i
= 1; i
< MAXSESSION
; i
++)
501 if (!session
[i
].opened
) continue;
502 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %-15s %s",
505 session
[i
].user
[0] ? session
[i
].user
: "*",
506 fmtaddr(htonl(session
[i
].ip
), 0),
507 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
508 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
509 (session
[i
].walled_garden
) ? "Y" : "N",
510 (session
[i
].flags
& SF_IPV6CP_ACKED
) ? "Y" : "N",
511 abs(time_now
- (unsigned long)session
[i
].opened
),
512 (unsigned long)session
[i
].cout
,
513 (unsigned long)session
[i
].cin
,
514 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
515 fmtaddr(htonl(tunnel
[ session
[i
].tunnel
].ip
), 1),
516 session
[i
].calling
[0] ? session
[i
].calling
: "*");
521 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
523 int i
, x
, show_all
= 0;
531 if (CLI_HELP_REQUESTED
)
534 return cli_arg_help(cli
, 1,
535 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
538 return cli_arg_help(cli
, 1,
539 "all", "Show all tunnels, including unused",
540 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
547 if (strcmp(argv
[0], "all") == 0)
553 // Show individual tunnel
554 for (i
= 0; i
< argc
; i
++)
559 if (t
<= 0 || t
>= MAXTUNNEL
)
561 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
564 cli_print(cli
, "\r\nTunnel %d:", t
);
565 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
566 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
567 cli_print(cli
, "\tRemote IP:\t%s", fmtaddr(htonl(tunnel
[t
].ip
), 0));
568 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
569 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
570 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
571 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
572 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
573 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
575 for (x
= 0; x
< MAXSESSION
; x
++)
576 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
577 sprintf(s
, "%s%u ", s
, x
);
579 cli_print(cli
, "\tSessions:\t%s", s
);
585 // Show tunnel summary
586 cli_print(cli
, "%4s %20s %20s %6s %s",
593 for (i
= 1; i
< MAXTUNNEL
; i
++)
596 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
598 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
599 cli_print(cli
, "%4d %20s %20s %6s %6d",
601 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
602 fmtaddr(htonl(tunnel
[i
].ip
), 0),
603 states
[tunnel
[i
].state
],
610 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
617 if (CLI_HELP_REQUESTED
)
618 return cli_arg_help(cli
, 1,
619 "USER", "Show details for specific username",
622 for (i
= 0; i
< MAXSESSION
; i
++)
624 if (!session
[i
].opened
) continue;
625 if (!session
[i
].user
[0]) continue;
629 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
631 if (strcmp(argv
[j
], session
[i
].user
) == 0)
633 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
634 sargv
[sargc
] = sid
[sargc
];
642 cli_print(cli
, "%s", session
[i
].user
);
646 return cmd_show_session(cli
, "users", sargv
, sargc
);
652 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
654 if (CLI_HELP_REQUESTED
)
655 return CLI_HELP_NO_ARGS
;
657 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Ethernet", "Bytes", "Packets", "Errors", "Dropped");
658 cli_print(cli
, "%-10s %10u %10u %10u %10u", "RX",
659 GET_STAT(tun_rx_bytes
),
660 GET_STAT(tun_rx_packets
),
661 GET_STAT(tun_rx_errors
),
662 GET_STAT(tun_rx_dropped
));
663 cli_print(cli
, "%-10s %10u %10u %10u", "TX",
664 GET_STAT(tun_tx_bytes
),
665 GET_STAT(tun_tx_packets
),
666 GET_STAT(tun_tx_errors
));
669 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
670 cli_print(cli
, "%-10s %10u %10u %10u", "RX",
671 GET_STAT(tunnel_rx_bytes
),
672 GET_STAT(tunnel_rx_packets
),
673 GET_STAT(tunnel_rx_errors
));
674 cli_print(cli
, "%-10s %10u %10u %10u %10u", "TX",
675 GET_STAT(tunnel_tx_bytes
),
676 GET_STAT(tunnel_tx_packets
),
677 GET_STAT(tunnel_tx_errors
),
678 GET_STAT(tunnel_retries
));
681 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
682 cli_print(cli
, "-----------------------------------------");
683 cli_print(cli
, "%-30s%u", "radius_retries", GET_STAT(radius_retries
));
684 cli_print(cli
, "%-30s%u", "arp_sent", GET_STAT(arp_sent
));
685 cli_print(cli
, "%-30s%u", "packets_snooped", GET_STAT(packets_snooped
));
686 cli_print(cli
, "%-30s%u", "tunnel_created", GET_STAT(tunnel_created
));
687 cli_print(cli
, "%-30s%u", "session_created", GET_STAT(session_created
));
688 cli_print(cli
, "%-30s%u", "tunnel_timeout", GET_STAT(tunnel_timeout
));
689 cli_print(cli
, "%-30s%u", "session_timeout", GET_STAT(session_timeout
));
690 cli_print(cli
, "%-30s%u", "radius_timeout", GET_STAT(radius_timeout
));
691 cli_print(cli
, "%-30s%u", "radius_overflow", GET_STAT(radius_overflow
));
692 cli_print(cli
, "%-30s%u", "tunnel_overflow", GET_STAT(tunnel_overflow
));
693 cli_print(cli
, "%-30s%u", "session_overflow", GET_STAT(session_overflow
));
694 cli_print(cli
, "%-30s%u", "ip_allocated", GET_STAT(ip_allocated
));
695 cli_print(cli
, "%-30s%u", "ip_freed", GET_STAT(ip_freed
));
696 cli_print(cli
, "%-30s%u", "cluster_forwarded", GET_STAT(c_forwarded
));
697 cli_print(cli
, "%-30s%u", "recv_forward", GET_STAT(recv_forward
));
698 cli_print(cli
, "%-30s%u", "select_called", GET_STAT(select_called
));
699 cli_print(cli
, "%-30s%u", "multi_read_used", GET_STAT(multi_read_used
));
700 cli_print(cli
, "%-30s%u", "multi_read_exceeded", GET_STAT(multi_read_exceeded
));
704 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
705 cli_print(cli
, "-----------------------------------------");
706 cli_print(cli
, "%-30s%u", "call_processtun", GET_STAT(call_processtun
));
707 cli_print(cli
, "%-30s%u", "call_processipout", GET_STAT(call_processipout
));
708 cli_print(cli
, "%-30s%u", "call_processipv6out", GET_STAT(call_processipv6out
));
709 cli_print(cli
, "%-30s%u", "call_processudp", GET_STAT(call_processudp
));
710 cli_print(cli
, "%-30s%u", "call_processpap", GET_STAT(call_processpap
));
711 cli_print(cli
, "%-30s%u", "call_processchap", GET_STAT(call_processchap
));
712 cli_print(cli
, "%-30s%u", "call_processlcp", GET_STAT(call_processlcp
));
713 cli_print(cli
, "%-30s%u", "call_processipcp", GET_STAT(call_processipcp
));
714 cli_print(cli
, "%-30s%u", "call_processipv6cp", GET_STAT(call_processipv6cp
));
715 cli_print(cli
, "%-30s%u", "call_processipin", GET_STAT(call_processipin
));
716 cli_print(cli
, "%-30s%u", "call_processipv6in", GET_STAT(call_processipv6in
));
717 cli_print(cli
, "%-30s%u", "call_processccp", GET_STAT(call_processccp
));
718 cli_print(cli
, "%-30s%u", "call_processrad", GET_STAT(call_processrad
));
719 cli_print(cli
, "%-30s%u", "call_sendarp", GET_STAT(call_sendarp
));
720 cli_print(cli
, "%-30s%u", "call_sendipcp", GET_STAT(call_sendipcp
));
721 cli_print(cli
, "%-30s%u", "call_sendchap", GET_STAT(call_sendchap
));
722 cli_print(cli
, "%-30s%u", "call_sessionbyip", GET_STAT(call_sessionbyip
));
723 cli_print(cli
, "%-30s%u", "call_sessionbyipv6", GET_STAT(call_sessionbyipv6
));
724 cli_print(cli
, "%-30s%u", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
725 cli_print(cli
, "%-30s%u", "call_tunnelsend", GET_STAT(call_tunnelsend
));
726 cli_print(cli
, "%-30s%u", "call_tunnelkill", GET_STAT(call_tunnelkill
));
727 cli_print(cli
, "%-30s%u", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
728 cli_print(cli
, "%-30s%u", "call_sessionkill", GET_STAT(call_sessionkill
));
729 cli_print(cli
, "%-30s%u", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
730 cli_print(cli
, "%-30s%u", "call_sessionsetup", GET_STAT(call_sessionsetup
));
731 cli_print(cli
, "%-30s%u", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
732 cli_print(cli
, "%-30s%u", "call_free_ip_address", GET_STAT(call_free_ip_address
));
733 cli_print(cli
, "%-30s%u", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
734 cli_print(cli
, "%-30s%u", "call_radiussend", GET_STAT(call_radiussend
));
735 cli_print(cli
, "%-30s%u", "call_radiusretry", GET_STAT(call_radiusretry
));
736 cli_print(cli
, "%-30s%u", "call_random_data", GET_STAT(call_random_data
));
737 #endif /* STAT_CALLS */
740 time_t l
= GET_STAT(last_reset
);
742 char *p
= strchr(t
, '\n');
746 cli_print(cli
, "Last counter reset %s", t
);
752 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
754 if (CLI_HELP_REQUESTED
)
755 return CLI_HELP_NO_ARGS
;
757 memset(_statistics
, 0, sizeof(struct Tstats
));
758 SET_STAT(last_reset
, time(NULL
));
760 cli_print(cli
, "Counters cleared");
763 #endif /* STATISTICS */
765 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
771 if (CLI_HELP_REQUESTED
)
772 return cli_arg_help(cli
, 1,
773 "tag", "Include CVS release tag",
774 "file", "Include file versions",
777 for (i
= 0; i
< argc
; i
++)
778 if (!strcmp(argv
[i
], "tag"))
780 else if (!strcmp(argv
[i
], "file"))
783 cli_print(cli
, "L2TPNS %s", VERSION
);
786 char const *p
= strchr(cvs_name
, ':');
798 e
= strpbrk(p
, " \t$");
799 cli_print(cli
, "Tag: %.*s", (int) (e
? e
- p
+ 1 : strlen(p
)), p
);
804 extern linked_list
*loaded_plugins
;
807 cli_print(cli
, "Files:");
808 cli_print(cli
, " %s", cvs_id_arp
);
810 cli_print(cli
, " %s", cvs_id_bgp
);
812 cli_print(cli
, " %s", cvs_id_cli
);
813 cli_print(cli
, " %s", cvs_id_cluster
);
814 cli_print(cli
, " %s", cvs_id_constants
);
815 cli_print(cli
, " %s", cvs_id_control
);
816 cli_print(cli
, " %s", cvs_id_icmp
);
817 cli_print(cli
, " %s", cvs_id_l2tpns
);
818 cli_print(cli
, " %s", cvs_id_ll
);
819 cli_print(cli
, " %s", cvs_id_md5
);
820 cli_print(cli
, " %s", cvs_id_ppp
);
821 cli_print(cli
, " %s", cvs_id_radius
);
822 cli_print(cli
, " %s", cvs_id_tbf
);
823 cli_print(cli
, " %s", cvs_id_util
);
825 ll_reset(loaded_plugins
);
826 while ((p
= ll_next(loaded_plugins
)))
828 char const **id
= dlsym(p
, "cvs_id");
830 cli_print(cli
, " %s", *id
);
837 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
840 int used
= 0, free
= 0, show_all
= 0;
842 if (!config
->cluster_iam_master
)
844 cli_print(cli
, "Can't do this on a slave. Do it on %s",
845 fmtaddr(config
->cluster_master_address
, 0));
850 if (CLI_HELP_REQUESTED
)
853 return cli_arg_help(cli
, 1, NULL
);
855 return cli_arg_help(cli
, 1,
856 "all", "Show all pool addresses, including unused",
860 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
864 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
865 for (i
= 0; i
< MAXIPPOOL
; i
++)
867 if (!ip_address_pool
[i
].address
) continue;
868 if (ip_address_pool
[i
].assigned
)
870 cli_print(cli
, "%-15s\tY %8d %s",
871 fmtaddr(htonl(ip_address_pool
[i
].address
), 0),
872 ip_address_pool
[i
].session
,
873 session
[ip_address_pool
[i
].session
].user
);
879 if (ip_address_pool
[i
].last
)
880 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
881 fmtaddr(htonl(ip_address_pool
[i
].address
), 0), "",
882 ip_address_pool
[i
].user
, (int) time_now
- ip_address_pool
[i
].last
);
885 cli_print(cli
, "%-15s\tN", fmtaddr(htonl(ip_address_pool
[i
].address
), 0));
892 cli_print(cli
, "(Not displaying unused addresses)");
894 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
898 static FILE *save_config_fh
= 0;
899 static void print_save_config(struct cli_def
*cli
, char *string
)
902 fprintf(save_config_fh
, "%s\n", string
);
905 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
907 if (CLI_HELP_REQUESTED
)
908 return CLI_HELP_NO_ARGS
;
910 if ((save_config_fh
= fopen(config
->config_file
, "w")))
912 cli_print(cli
, "Writing configuration");
913 cli_print_callback(cli
, print_save_config
);
914 cmd_show_run(cli
, command
, argv
, argc
);
915 cli_print_callback(cli
, NULL
);
916 fclose(save_config_fh
);
921 cli_error(cli
, "Error writing configuration: %s", strerror(errno
));
926 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
);
928 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
931 char ipv6addr
[INET6_ADDRSTRLEN
];
933 if (CLI_HELP_REQUESTED
)
934 return CLI_HELP_NO_ARGS
;
936 cli_print(cli
, "# Current configuration:");
938 for (i
= 0; config_values
[i
].key
; i
++)
940 void *value
= ((void *)config
) + config_values
[i
].offset
;
941 if (config_values
[i
].type
== STRING
)
942 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *) value
);
943 else if (config_values
[i
].type
== IPv4
)
944 cli_print(cli
, "set %s %s", config_values
[i
].key
, fmtaddr(*(in_addr_t
*) value
, 0));
945 else if (config_values
[i
].type
== IPv6
)
946 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_ntop(AF_INET6
, value
, ipv6addr
, INET6_ADDRSTRLEN
));
947 else if (config_values
[i
].type
== SHORT
)
948 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *) value
);
949 else if (config_values
[i
].type
== BOOL
)
950 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *) value
) ? "yes" : "no");
951 else if (config_values
[i
].type
== INT
)
952 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *) value
);
953 else if (config_values
[i
].type
== UNSIGNED_LONG
)
954 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *) value
);
955 else if (config_values
[i
].type
== MAC
)
956 cli_print(cli
, "set %s %02x%02x.%02x%02x.%02x%02x", config_values
[i
].key
,
957 *(unsigned short *) (value
+ 0),
958 *(unsigned short *) (value
+ 1),
959 *(unsigned short *) (value
+ 2),
960 *(unsigned short *) (value
+ 3),
961 *(unsigned short *) (value
+ 4),
962 *(unsigned short *) (value
+ 5));
965 cli_print(cli
, "# Plugins");
966 for (i
= 0; i
< MAXPLUGINS
; i
++)
968 if (*config
->plugins
[i
])
970 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
975 if (config
->as_number
)
980 cli_print(cli
, "# BGP");
981 cli_print(cli
, "router bgp %u", config
->as_number
);
982 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
984 if (!config
->neighbour
[i
].name
[0])
987 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
989 k
= config
->neighbour
[i
].keepalive
;
990 h
= config
->neighbour
[i
].hold
;
997 k
= BGP_KEEPALIVE_TIME
;
1003 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
1008 cli_print(cli
, "# Filters");
1009 for (i
= 0; i
< MAXFILTER
; i
++)
1011 ip_filter_rulet
*rules
;
1012 if (!*ip_filters
[i
].name
)
1015 cli_print(cli
, "ip access-list %s %s",
1016 ip_filters
[i
].extended
? "extended" : "standard",
1017 ip_filters
[i
].name
);
1019 rules
= ip_filters
[i
].rules
;
1020 while (rules
->action
)
1021 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1024 cli_print(cli
, "# end");
1028 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1030 int i
, free
= 0, used
= 0, show_all
= 0;
1042 if (CLI_HELP_REQUESTED
)
1045 return cli_arg_help(cli
, 1, NULL
);
1047 return cli_arg_help(cli
, 1,
1048 "all", "Show all RADIUS sessions, including unused",
1052 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1056 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1059 for (i
= 1; i
< MAXRADIUS
; i
++)
1061 if (radius
[i
].state
== RADIUSNULL
)
1066 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1068 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1072 states
[radius
[i
].state
],
1078 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1083 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1087 if (CLI_HELP_REQUESTED
)
1088 return CLI_HELP_NO_ARGS
;
1090 cli_print(cli
, "Plugins currently loaded:");
1091 for (i
= 0; i
< MAXPLUGINS
; i
++)
1092 if (*config
->plugins
[i
])
1093 cli_print(cli
, " %s", config
->plugins
[i
]);
1098 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1102 if (CLI_HELP_REQUESTED
)
1103 return CLI_HELP_NO_ARGS
;
1105 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1114 for (i
= 0; i
< MAXSESSION
; i
++)
1116 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1117 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1121 session
[i
].throttle_in
,
1122 session
[i
].throttle_out
,
1124 session
[i
].tbf_out
);
1130 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1132 if (CLI_HELP_REQUESTED
)
1133 return CLI_HELP_NO_ARGS
;
1135 cli_print(cli
, " _\n"
1141 " ( \\ `. `-. _,.-:\\\n"
1142 " \\ \\ `. `-._ __..--' ,-';/\n"
1143 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1144 " `. `. `-._ __..--' ,' /\n"
1145 " `. `-_ ``--..'' _.-' ,'\n"
1146 " `-_ `-.___ __,--' ,'\n"
1147 " `-.__ `----\"\"\" __.-'\n"
1148 "hh `--..____..--'");
1153 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1158 if (CLI_HELP_REQUESTED
)
1159 return cli_arg_help(cli
, argc
> 1,
1160 "USER", "Username of session to drop", NULL
);
1162 if (!config
->cluster_iam_master
)
1164 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1165 fmtaddr(config
->cluster_master_address
, 0));
1172 cli_error(cli
, "Specify a user to drop");
1176 for (i
= 0; i
< argc
; i
++)
1178 if (!(s
= sessionbyuser(argv
[i
])))
1180 cli_error(cli
, "User %s is not connected", argv
[i
]);
1184 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1186 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1187 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1194 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1199 if (CLI_HELP_REQUESTED
)
1200 return cli_arg_help(cli
, argc
> 1,
1201 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1203 if (!config
->cluster_iam_master
)
1205 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1206 fmtaddr(config
->cluster_master_address
, 0));
1213 cli_error(cli
, "Specify a tunnel to drop");
1217 for (i
= 0; i
< argc
; i
++)
1219 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1221 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1227 cli_error(cli
, "Tunnel %d is not connected", t
);
1233 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1237 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1238 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1244 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1249 if (CLI_HELP_REQUESTED
)
1250 return cli_arg_help(cli
, argc
> 1,
1251 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1253 if (!config
->cluster_iam_master
)
1255 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1256 fmtaddr(config
->cluster_master_address
, 0));
1263 cli_error(cli
, "Specify a session id to drop");
1267 for (i
= 0; i
< argc
; i
++)
1269 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1271 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1275 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1277 cli_print(cli
, "Dropping session %d", s
);
1278 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1282 cli_error(cli
, "Session %d is not active.", s
);
1289 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1295 if (CLI_HELP_REQUESTED
)
1300 return cli_arg_help(cli
, 0,
1301 "USER", "Username of session to snoop", NULL
);
1304 return cli_arg_help(cli
, 0,
1305 "A.B.C.D", "IP address of snoop destination", NULL
);
1308 return cli_arg_help(cli
, 0,
1309 "N", "Port of snoop destination", NULL
);
1313 return cli_arg_help(cli
, 1, NULL
);
1320 if (!config
->cluster_iam_master
)
1322 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1323 fmtaddr(config
->cluster_master_address
, 0));
1330 cli_error(cli
, "Specify username, ip and port");
1334 if (!(s
= sessionbyuser(argv
[0])))
1336 cli_error(cli
, "User %s is not connected", argv
[0]);
1340 ip
= inet_addr(argv
[1]);
1341 if (!ip
|| ip
== INADDR_NONE
)
1343 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1347 port
= atoi(argv
[2]);
1350 cli_error(cli
, "Invalid port %s", argv
[2]);
1354 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1355 cli_session_actions
[s
].snoop_ip
= ip
;
1356 cli_session_actions
[s
].snoop_port
= port
;
1357 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1362 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1367 if (CLI_HELP_REQUESTED
)
1368 return cli_arg_help(cli
, argc
> 1,
1369 "USER", "Username of session to unsnoop", NULL
);
1371 if (!config
->cluster_iam_master
)
1373 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1374 fmtaddr(config
->cluster_master_address
, 0));
1381 cli_error(cli
, "Specify a user to unsnoop");
1385 for (i
= 0; i
< argc
; i
++)
1387 if (!(s
= sessionbyuser(argv
[i
])))
1389 cli_error(cli
, "User %s is not connected", argv
[i
]);
1393 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1394 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1400 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1407 throttle USER - throttle in/out to default rate
1408 throttle USER RATE - throttle in/out to default rate
1409 throttle USER in RATE - throttle input only
1410 throttle USER out RATE - throttle output only
1411 throttle USER in RATE out RATE - throttle both
1414 if (CLI_HELP_REQUESTED
)
1419 return cli_arg_help(cli
, 0,
1420 "USER", "Username of session to throttle", NULL
);
1423 return cli_arg_help(cli
, 1,
1424 "RATE", "Rate in kbps (in and out)",
1425 "in", "Select incoming rate",
1426 "out", "Select outgoing rate", NULL
);
1429 return cli_arg_help(cli
, 1,
1430 "in", "Select incoming rate",
1431 "out", "Select outgoing rate", NULL
);
1434 if (isdigit(argv
[1][0]))
1435 return cli_arg_help(cli
, 1, NULL
);
1438 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1441 return cli_arg_help(cli
, argc
> 1, NULL
);
1445 if (!config
->cluster_iam_master
)
1447 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1448 fmtaddr(config
->cluster_master_address
, 0));
1455 cli_error(cli
, "Specify a user to throttle");
1459 if (!(s
= sessionbyuser(argv
[0])))
1461 cli_error(cli
, "User %s is not connected", argv
[0]);
1467 rate_in
= rate_out
= config
->rl_rate
;
1471 rate_in
= rate_out
= atoi(argv
[1]);
1474 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1478 else if (argc
== 3 || argc
== 5)
1481 for (i
= 1; i
< argc
- 1; i
+= 2)
1484 if (MATCH("in", argv
[i
]))
1485 r
= rate_in
= atoi(argv
[i
+1]);
1486 else if (MATCH("out", argv
[i
]))
1487 r
= rate_out
= atoi(argv
[i
+1]);
1491 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1498 cli_error(cli
, "Invalid arguments");
1502 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1504 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1508 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1509 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1510 cli_session_actions
[s
].throttle_in
= rate_in
;
1512 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1513 cli_session_actions
[s
].throttle_out
= rate_out
;
1515 if (cli_session_actions
[s
].throttle_in
== -1 &&
1516 cli_session_actions
[s
].throttle_out
== -1)
1518 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1522 cli_print(cli
, "Throttling user %s", argv
[0]);
1523 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1528 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1533 if (CLI_HELP_REQUESTED
)
1534 return cli_arg_help(cli
, argc
> 1,
1535 "USER", "Username of session to unthrottle", NULL
);
1537 if (!config
->cluster_iam_master
)
1539 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1540 fmtaddr(config
->cluster_master_address
, 0));
1547 cli_error(cli
, "Specify a user to unthrottle");
1551 for (i
= 0; i
< argc
; i
++)
1553 if (!(s
= sessionbyuser(argv
[i
])))
1555 cli_error(cli
, "User %s is not connected", argv
[i
]);
1559 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1561 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1562 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1566 cli_error(cli
, "User %s not throttled", argv
[i
]);
1573 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1577 if (CLI_HELP_REQUESTED
)
1578 return cli_arg_help(cli
, 1,
1579 "all", "Enable debugging for all except \"data\"",
1580 "critical", "", // FIXME: add descriptions
1590 char *p
= (char *) &debug_flags
;
1591 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1595 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1596 (debug_flags
.critical
) ? " critical" : "",
1597 (debug_flags
.error
) ? " error" : "",
1598 (debug_flags
.warning
) ? " warning" : "",
1599 (debug_flags
.info
) ? " info" : "",
1600 (debug_flags
.calls
) ? " calls" : "",
1601 (debug_flags
.data
) ? " data" : "");
1607 cli_print(cli
, "Debugging off");
1611 for (i
= 0; i
< argc
; i
++)
1613 int len
= strlen(argv
[i
]);
1615 if (argv
[i
][0] == 'c' && len
< 2)
1616 len
= 2; /* distinguish [cr]itical from [ca]lls */
1618 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1619 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1620 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1621 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1622 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1623 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1624 if (!strncmp("all", argv
[i
], len
))
1626 memset(&debug_flags
, 1, sizeof(debug_flags
));
1627 debug_flags
.data
= 0;
1631 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1637 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1641 if (CLI_HELP_REQUESTED
)
1642 return cli_arg_help(cli
, 1,
1643 "all", "Disable all debugging",
1644 "critical", "", // FIXME: add descriptions
1654 memset(&debug_flags
, 0, sizeof(debug_flags
));
1658 for (i
= 0; i
< argc
; i
++)
1660 int len
= strlen(argv
[i
]);
1662 if (argv
[i
][0] == 'c' && len
< 2)
1663 len
= 2; /* distinguish [cr]itical from [ca]lls */
1665 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1666 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1667 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1668 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1669 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1670 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1671 if (!strncmp("all", argv
[i
], len
))
1673 memset(&debug_flags
, 0, sizeof(debug_flags
));
1677 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1683 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1685 int i
, firstfree
= 0;
1687 if (CLI_HELP_REQUESTED
)
1688 return cli_arg_help(cli
, argc
> 1,
1689 "PLUGIN", "Name of plugin to load", NULL
);
1693 cli_error(cli
, "Specify a plugin to load");
1697 for (i
= 0; i
< MAXPLUGINS
; i
++)
1699 if (!*config
->plugins
[i
] && !firstfree
)
1701 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1703 cli_error(cli
, "Plugin is already loaded");
1710 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1711 config
->reload_config
= 1;
1712 cli_print(cli
, "Loading plugin %s", argv
[0]);
1718 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1722 if (CLI_HELP_REQUESTED
)
1723 return cli_arg_help(cli
, argc
> 1,
1724 "PLUGIN", "Name of plugin to unload", NULL
);
1728 cli_error(cli
, "Specify a plugin to remove");
1732 for (i
= 0; i
< MAXPLUGINS
; i
++)
1734 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1736 config
->reload_config
= 1;
1737 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1742 cli_error(cli
, "Plugin is not loaded");
1746 static char *duration(time_t secs
)
1748 static char *buf
= NULL
;
1751 if (!buf
) buf
= calloc(64, 1);
1755 int days
= secs
/ 86400;
1756 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1762 int mins
= secs
/ 60;
1763 int hrs
= mins
/ 60;
1766 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1768 else if (secs
>= 60)
1770 int mins
= secs
/ 60;
1771 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1774 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1779 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1782 char buf
[100], *p
= buf
, *loads
[3];
1783 int i
, num_sessions
= 0;
1785 if (CLI_HELP_REQUESTED
)
1786 return CLI_HELP_NO_ARGS
;
1788 fh
= fopen("/proc/loadavg", "r");
1789 fgets(buf
, 100, fh
);
1792 for (i
= 0; i
< 3; i
++)
1793 loads
[i
] = strdup(strsep(&p
, " "));
1796 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1798 for (i
= 1; i
< MAXSESSION
; i
++)
1799 if (session
[i
].opened
) num_sessions
++;
1801 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1803 duration(time_now
- config
->start_time
),
1805 loads
[0], loads
[1], loads
[2]
1807 for (i
= 0; i
< 3; i
++)
1808 if (loads
[i
]) free(loads
[i
]);
1810 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1815 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1819 if (CLI_HELP_REQUESTED
)
1825 int len
= strlen(argv
[0])-1;
1826 for (i
= 0; config_values
[i
].key
; i
++)
1827 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1828 cli_error(cli
, " %s", config_values
[i
].key
);
1834 return cli_arg_help(cli
, 0,
1835 "VALUE", "Value for variable", NULL
);
1839 return cli_arg_help(cli
, 1, NULL
);
1848 cli_error(cli
, "Specify variable and value");
1852 for (i
= 0; config_values
[i
].key
; i
++)
1854 void *value
= ((void *) config
) + config_values
[i
].offset
;
1855 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1857 // Found a value to set
1858 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1859 switch (config_values
[i
].type
)
1862 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1865 *(int *) value
= atoi(argv
[1]);
1868 *(unsigned long *) value
= atol(argv
[1]);
1871 *(short *) value
= atoi(argv
[1]);
1874 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1877 inet_pton(AF_INET6
, argv
[1], value
);
1880 parsemac(argv
[1], (char *)value
);
1883 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1889 cli_error(cli
, "Unknown variable type");
1892 config
->reload_config
= 1;
1897 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1901 int regular_stuff(struct cli_def
*cli
)
1907 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1909 char *m
= ringbuffer
->buffer
[i
].message
;
1915 switch (ringbuffer
->buffer
[i
].level
)
1917 case 0: show
= debug_flags
.critical
; break;
1918 case 1: show
= debug_flags
.error
; break;
1919 case 2: show
= debug_flags
.warning
; break;
1920 case 3: show
= debug_flags
.info
; break;
1921 case 4: show
= debug_flags
.calls
; break;
1922 case 5: show
= debug_flags
.data
; break;
1925 if (!show
) continue;
1927 if (!(p
= strchr(m
, '\n')))
1930 cli_error(cli
, "\r%s-%u-%u %.*s",
1931 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1932 ringbuffer
->buffer
[i
].tunnel
,
1933 ringbuffer
->buffer
[i
].session
,
1939 debug_rb_tail
= ringbuffer
->tail
;
1947 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1951 if (CLI_HELP_REQUESTED
)
1952 return cli_arg_help(cli
, argc
> 1,
1953 "<1-65535>", "Autonomous system number", NULL
);
1955 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1957 cli_error(cli
, "Invalid autonomous system number");
1961 if (bgp_configured
&& as
!= config
->as_number
)
1963 cli_error(cli
, "Can't change local AS on a running system");
1967 config
->as_number
= as
;
1968 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
1973 static int find_bgp_neighbour(char const *name
)
1978 in_addr_t addrs
[4] = { 0 };
1981 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
1984 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
1985 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
1987 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1989 if (!config
->neighbour
[i
].name
[0])
1991 if (new == -1) new = i
;
1995 if (!strcmp(name
, config
->neighbour
[i
].name
))
1998 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
2001 for (a
= h
->h_addr_list
; *a
; a
++)
2004 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2005 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2013 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2019 if (CLI_HELP_REQUESTED
)
2024 return cli_arg_help(cli
, 0,
2025 "A.B.C.D", "BGP neighbour address",
2026 "NAME", "BGP neighbour name",
2030 return cli_arg_help(cli
, 0,
2031 "remote-as", "Set remote autonomous system number",
2032 "timers", "Set timers",
2036 if (MATCH("remote-as", argv
[1]))
2037 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2039 if (MATCH("timers", argv
[1]))
2042 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2045 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2047 if (argc
== 5 && !argv
[4][1])
2048 return cli_arg_help(cli
, 1, NULL
);
2057 cli_error(cli
, "Invalid arguments");
2061 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2063 cli_error(cli
, "Invalid neighbour");
2069 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2073 if (MATCH("remote-as", argv
[1]))
2075 int as
= atoi(argv
[2]);
2076 if (as
< 0 || as
> 65535)
2078 cli_error(cli
, "Invalid autonomous system number");
2082 if (!config
->neighbour
[i
].name
[0])
2084 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2085 config
->neighbour
[i
].keepalive
= -1;
2086 config
->neighbour
[i
].hold
= -1;
2089 config
->neighbour
[i
].as
= as
;
2093 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2095 cli_error(cli
, "Invalid arguments");
2099 if (!config
->neighbour
[i
].name
[0])
2101 cli_error(cli
, "Specify remote-as first");
2105 keepalive
= atoi(argv
[2]);
2106 hold
= atoi(argv
[3]);
2108 if (keepalive
< 1 || keepalive
> 65535)
2110 cli_error(cli
, "Invalid keepalive time");
2114 if (hold
< 3 || hold
> 65535)
2116 cli_error(cli
, "Invalid hold time");
2120 if (keepalive
== BGP_KEEPALIVE_TIME
)
2121 keepalive
= -1; // using default value
2123 if (hold
== BGP_HOLD_TIME
)
2126 config
->neighbour
[i
].keepalive
= keepalive
;
2127 config
->neighbour
[i
].hold
= hold
;
2132 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2136 if (CLI_HELP_REQUESTED
)
2137 return cli_arg_help(cli
, argc
> 0,
2138 "A.B.C.D", "BGP neighbour address",
2139 "NAME", "BGP neighbour name",
2144 cli_error(cli
, "Specify a BGP neighbour");
2148 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2150 cli_error(cli
, "Invalid neighbour");
2154 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2156 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2160 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2164 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2170 if (!bgp_configured
)
2173 if (CLI_HELP_REQUESTED
)
2174 return cli_arg_help(cli
, 1,
2175 "A.B.C.D", "BGP neighbour address",
2176 "NAME", "BGP neighbour name",
2179 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2180 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2184 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2186 if (!*bgp_peers
[i
].name
)
2189 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2190 if (argc
&& strcmp(addr
, argv
[0]) &&
2191 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2197 cli_print(cli
, "Peer AS Address "
2198 "State Retries Retry in Route Pend Timers");
2199 cli_print(cli
, "------------------ ----- --------------- "
2200 "----------- ------- -------- ----- ---- ---------");
2203 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2207 bgp_state_str(bgp_peers
[i
].state
),
2208 bgp_peers
[i
].retry_count
,
2209 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2210 bgp_peers
[i
].routing
? "yes" : "no",
2211 bgp_peers
[i
].update_routes
? "yes" : "no",
2212 bgp_peers
[i
].keepalive
,
2219 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2224 if (!bgp_configured
)
2227 if (CLI_HELP_REQUESTED
)
2228 return cli_arg_help(cli
, 1,
2229 "A.B.C.D", "BGP neighbour address",
2230 "NAME", "BGP neighbour name",
2233 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2235 if (bgp_peers
[i
].state
!= Established
)
2238 if (!bgp_peers
[i
].routing
)
2241 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2242 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2245 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2246 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2252 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2257 if (!bgp_configured
)
2260 if (CLI_HELP_REQUESTED
)
2261 return cli_arg_help(cli
, 1,
2262 "A.B.C.D", "BGP neighbour address",
2263 "NAME", "BGP neighbour name",
2266 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2268 if (bgp_peers
[i
].state
!= Established
)
2271 if (bgp_peers
[i
].routing
)
2274 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2275 if (argc
&& strcmp(addr
, argv
[0]) &&
2276 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2279 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2280 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2286 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2291 if (!bgp_configured
)
2294 if (CLI_HELP_REQUESTED
)
2295 return cli_arg_help(cli
, 1,
2296 "A.B.C.D", "BGP neighbour address",
2297 "NAME", "BGP neighbour name",
2300 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2302 if (!*bgp_peers
[i
].name
)
2305 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2306 if (argc
&& strcmp(addr
, argv
[0]) &&
2307 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2310 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2311 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2319 static int find_access_list(char const *name
)
2323 for (i
= 0; i
< MAXFILTER
; i
++)
2324 if (!(*ip_filters
[i
].name
&& strcmp(ip_filters
[i
].name
, name
)))
2330 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2334 if (CLI_HELP_REQUESTED
)
2339 return cli_arg_help(cli
, 0,
2340 "standard", "Standard syntax",
2341 "extended", "Extended syntax",
2345 return cli_arg_help(cli
, argv
[1][1],
2346 "NAME", "Access-list name",
2350 if (argc
== 3 && !argv
[2][1])
2351 return cli_arg_help(cli
, 1, NULL
);
2359 cli_error(cli
, "Specify access-list type and name");
2363 if (MATCH("standard", argv
[0]))
2365 else if (MATCH("extended", argv
[0]))
2369 cli_error(cli
, "Invalid access-list type");
2373 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2374 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2376 cli_error(cli
, "Invalid access-list name");
2380 filt
= find_access_list(argv
[1]);
2385 cli_error(cli
, "Too many access-lists");
2390 if (!*ip_filters
[filt
].name
)
2392 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2393 strcpy(ip_filters
[filt
].name
, argv
[1]);
2394 ip_filters
[filt
].extended
= extended
;
2396 else if (ip_filters
[filt
].extended
!= extended
)
2398 cli_error(cli
, "Access-list is %s",
2399 ip_filters
[filt
].extended
? "extended" : "standard");
2404 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2408 if (filt
< 0 || !*ip_filters
[filt
].name
)
2410 cli_error(cli
, "Access-list not defined");
2415 if (ip_filters
[filt
].used
)
2417 cli_error(cli
, "Access-list in use");
2421 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2425 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2427 return access_list(cli
, argv
, argc
, 1);
2430 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2432 return access_list(cli
, argv
, argc
, 0);
2435 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2437 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2438 return sprintf(buf
, " any");
2440 if (wild
== INADDR_ANY
)
2441 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2443 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2446 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2450 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2451 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2452 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2453 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2454 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2460 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2462 static char buf
[256];
2465 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2468 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2469 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2472 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2476 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2477 p
+= show_ports(p
, &rule
->src_ports
);
2479 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2480 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2481 p
+= show_ports(p
, &rule
->dst_ports
);
2483 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2485 switch (rule
->tcp_flag_op
)
2487 case FILTER_FLAG_OP_EST
:
2488 p
+= sprintf(p
, " established");
2491 case FILTER_FLAG_OP_ANY
:
2492 case FILTER_FLAG_OP_ALL
:
2493 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2494 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2495 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2496 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2497 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2498 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2499 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2500 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2501 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2502 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2503 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2504 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2505 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2511 p
+= sprintf(p
, " fragments");
2516 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2518 static ip_filter_rulet rule
;
2519 struct in_addr addr
;
2523 if (CLI_HELP_REQUESTED
)
2527 cli_arg_help(cli
, 0,
2528 "ip", "Match IP packets",
2529 "tcp", "Match TCP packets",
2530 "udp", "Match UDP packets",
2536 // *sigh*, too darned complex
2537 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2543 cli_error(cli
, "Specify rule details");
2547 memset(&rule
, 0, sizeof(rule
));
2548 rule
.action
= (command
[0] == 'p')
2549 ? FILTER_ACTION_PERMIT
2550 : FILTER_ACTION_DENY
;
2552 if (MATCH("ip", argv
[0]))
2553 rule
.proto
= IPPROTO_IP
;
2554 else if (MATCH("udp", argv
[0]))
2555 rule
.proto
= IPPROTO_UDP
;
2556 else if (MATCH("tcp", argv
[0]))
2557 rule
.proto
= IPPROTO_TCP
;
2560 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2564 for (a
= 1, i
= 0; i
< 2; i
++)
2568 ip_filter_portt
*port
;
2573 wild
= &rule
.src_wild
;
2574 port
= &rule
.src_ports
;
2579 wild
= &rule
.dst_wild
;
2580 port
= &rule
.dst_ports
;
2583 cli_error(cli
, "Specify destination");
2588 if (MATCH("any", argv
[a
]))
2591 *wild
= INADDR_BROADCAST
;
2594 else if (MATCH("host", argv
[a
]))
2598 cli_error(cli
, "Specify host ip address");
2602 if (!inet_aton(argv
[a
], &addr
))
2604 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2616 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2620 if (!inet_aton(argv
[a
], &addr
))
2622 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2628 if (!inet_aton(argv
[++a
], &addr
))
2630 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2634 *wild
= addr
.s_addr
;
2638 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2642 if (MATCH("eq", argv
[a
]))
2643 port
->op
= FILTER_PORT_OP_EQ
;
2644 else if (MATCH("neq", argv
[a
]))
2645 port
->op
= FILTER_PORT_OP_NEQ
;
2646 else if (MATCH("gt", argv
[a
]))
2647 port
->op
= FILTER_PORT_OP_GT
;
2648 else if (MATCH("lt", argv
[a
]))
2649 port
->op
= FILTER_PORT_OP_LT
;
2650 else if (MATCH("range", argv
[a
]))
2651 port
->op
= FILTER_PORT_OP_RANGE
;
2658 cli_error(cli
, "Specify port");
2662 if (!(port
->port
= atoi(argv
[a
])))
2664 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2669 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2674 cli_error(cli
, "Specify port");
2678 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2680 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2687 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2689 if (MATCH("established", argv
[a
]))
2691 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2694 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2695 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2697 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2698 ? FILTER_FLAG_OP_ANY
2699 : FILTER_FLAG_OP_ALL
;
2703 cli_error(cli
, "Specify tcp flags");
2707 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2711 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2713 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2714 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2715 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2716 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2717 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2718 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2721 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2730 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2732 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2734 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2744 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2751 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2753 static ip_filter_rulet rule
;
2754 struct in_addr addr
;
2756 if (CLI_HELP_REQUESTED
)
2760 cli_arg_help(cli
, argv
[0][1],
2761 "A.B.C.D", "Source address",
2762 "any", "Any source address",
2763 "host", "Source host",
2769 if (MATCH("any", argv
[0]))
2771 if (argc
== 2 && !argv
[1][1])
2772 cli_arg_help(cli
, 1, NULL
);
2774 else if (MATCH("host", argv
[0]))
2778 cli_arg_help(cli
, argv
[1][1],
2779 "A.B.C.D", "Host address",
2782 else if (argc
== 3 && !argv
[2][1])
2783 cli_arg_help(cli
, 1, NULL
);
2789 cli_arg_help(cli
, 1,
2790 "A.B.C.D", "Wildcard bits",
2793 else if (argc
== 3 && !argv
[2][1])
2794 cli_arg_help(cli
, 1, NULL
);
2802 cli_error(cli
, "Specify rule details");
2806 memset(&rule
, 0, sizeof(rule
));
2807 rule
.action
= (command
[0] == 'p')
2808 ? FILTER_ACTION_PERMIT
2809 : FILTER_ACTION_DENY
;
2811 rule
.proto
= IPPROTO_IP
;
2812 if (MATCH("any", argv
[0]))
2814 rule
.src_ip
= INADDR_ANY
;
2815 rule
.src_wild
= INADDR_BROADCAST
;
2817 else if (MATCH("host", argv
[0]))
2821 cli_error(cli
, "Specify host ip address");
2825 if (!inet_aton(argv
[1], &addr
))
2827 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2831 rule
.src_ip
= addr
.s_addr
;
2832 rule
.src_wild
= INADDR_ANY
;
2838 cli_error(cli
, "Specify source ip address and wildcard");
2842 if (!inet_aton(argv
[0], &addr
))
2844 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2848 rule
.src_ip
= addr
.s_addr
;
2852 if (!inet_aton(argv
[1], &addr
))
2854 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2858 rule
.src_wild
= addr
.s_addr
;
2861 rule
.src_wild
= INADDR_ANY
;
2867 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2870 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2871 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2872 : access_list_rule_std(cli
, command
, argv
, argc
);
2877 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2879 if (!ip_filters
[filt
].rules
[i
].action
)
2881 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2885 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
)))
2889 cli_error(cli
, "Too many rules");
2893 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2898 /* filter USER {in|out} FILTER ... */
2899 if (CLI_HELP_REQUESTED
)
2904 return cli_arg_help(cli
, 0,
2905 "USER", "Username of session to filter", NULL
);
2909 return cli_arg_help(cli
, 0,
2910 "in", "Set incoming filter",
2911 "out", "Set outgoing filter", NULL
);
2915 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2916 "NAME", "Filter name", NULL
);
2919 return cli_arg_help(cli
, argc
> 1, NULL
);
2923 if (!config
->cluster_iam_master
)
2925 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2926 fmtaddr(config
->cluster_master_address
, 0));
2931 if (argc
!= 3 && argc
!= 5)
2933 cli_error(cli
, "Specify a user and filters");
2937 if (!(s
= sessionbyuser(argv
[0])))
2939 cli_error(cli
, "User %s is not connected", argv
[0]);
2943 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2944 for (i
= 1; i
< argc
; i
+= 2)
2949 if (MATCH("in", argv
[i
]))
2951 if (session
[s
].filter_in
)
2953 cli_error(cli
, "Input already filtered");
2956 f
= &cli_session_actions
[s
].filter_in
;
2958 else if (MATCH("out", argv
[i
]))
2960 if (session
[s
].filter_out
)
2962 cli_error(cli
, "Output already filtered");
2965 f
= &cli_session_actions
[s
].filter_out
;
2969 cli_error(cli
, "Invalid filter specification");
2973 v
= find_access_list(argv
[i
+1]);
2974 if (v
< 0 || !*ip_filters
[v
].name
)
2976 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
2983 cli_print(cli
, "Filtering user %s", argv
[0]);
2984 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
2989 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2994 if (CLI_HELP_REQUESTED
)
2995 return cli_arg_help(cli
, argc
> 1,
2996 "USER", "Username of session to remove filters from", NULL
);
2998 if (!config
->cluster_iam_master
)
3000 cli_error(cli
, "Can't do this on a slave. Do it on %s",
3001 fmtaddr(config
->cluster_master_address
, 0));
3008 cli_error(cli
, "Specify a user to remove filters from");
3012 for (i
= 0; i
< argc
; i
++)
3014 if (!(s
= sessionbyuser(argv
[i
])))
3016 cli_error(cli
, "User %s is not connected", argv
[i
]);
3020 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3022 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3023 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3027 cli_error(cli
, "User %s not filtered", argv
[i
]);
3034 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3038 if (CLI_HELP_REQUESTED
)
3039 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3043 cli_error(cli
, "Specify a filter name");
3047 for (i
= 0; i
< argc
; i
++)
3049 int f
= find_access_list(argv
[i
]);
3050 ip_filter_rulet
*rules
;
3052 if (f
< 0 || !*ip_filters
[f
].name
)
3054 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3061 cli_print(cli
, "%s IP access list %s",
3062 ip_filters
[f
].extended
? "Extended" : "Standard",
3063 ip_filters
[f
].name
);
3065 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3067 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3069 cli_print(cli
, "%s (%d match%s)", r
,
3070 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3072 cli_print(cli
, "%s", r
);
3079 // Convert a string in the form of abcd.ef12.3456 into char[6]
3080 void parsemac(char *string
, char mac
[6])
3082 if (sscanf(string
, "%02x%02x.%02x%02x.%02x%02x", (unsigned int *)&mac
[0], (unsigned int *)&mac
[1], (unsigned int *)&mac
[2], (unsigned int *)&mac
[3], (unsigned int *)&mac
[4], (unsigned int *)&mac
[5]) == 6)
3084 if (sscanf(string
, "%02x%02x:%02x%02x:%02x%02x", (unsigned int *)&mac
[0], (unsigned int *)&mac
[1], (unsigned int *)&mac
[2], (unsigned int *)&mac
[3], (unsigned int *)&mac
[4], (unsigned int *)&mac
[5]) == 6)