From: fendo Date: Mon, 7 Oct 2013 20:49:53 +0000 (+0200) Subject: Merge from master X-Git-Tag: 2.2.1-2sames3.12 X-Git-Url: http://git.sameswireless.fr/l2tpns.git/commitdiff_plain/30b561eb71683b52894abacf0a607d7d6932e4c1?hp=ea2c9385938dc5ee481c9e7e677c03dc869b88cf Merge from master --- diff --git a/Makefile b/Makefile index b19dfcd..7280139 100644 --- a/Makefile +++ b/Makefile @@ -18,12 +18,12 @@ CC = gcc LD = gcc INCLUDES = -I. CPPFLAGS = $(INCLUDES) $(DEFINES) -CFLAGS = -Wall -Wformat-security -Wno-format-zero-length $(OPTIM) +CFLAGS = -Wall -Wformat-security $(OPTIM) LDFLAGS = LDLIBS = INSTALL = install -c -D -o root -g root -l2tpns.LIBS = -lm -lcli -ldl +l2tpns.LIBS = -lcli -ldl OBJS = arp.o cli.o cluster.o constants.o control.o icmp.o l2tpns.o \ ll.o md5.o ppp.o radius.o tbf.o util.o pppoe.o l2tplac.o grpsess.o diff --git a/cli.c b/cli.c index e5ac57c..876ad06 100644 --- a/cli.c +++ b/cli.c @@ -75,61 +75,61 @@ static char *debug_levels[] = { #endif -static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_group(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_tunnels(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_users(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_radius(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_version(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_pool(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_run(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_banana(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_plugins(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_throttle(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_write_memory(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_drop_user(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_drop_tunnel(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_drop_session(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_snoop(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_no_snoop(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_throttle(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_no_throttle(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_debug(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_no_debug(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_set(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_load_plugin(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_remove_plugin(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_uptime(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_shutdown(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_reload(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_setforward(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_rmtlnsconf(struct cli_def *cli, char *command, char **argv, int argc); +static int cmd_show_session(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_group(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_tunnels(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_users(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_radius(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_version(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_pool(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_run(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_banana(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_plugins(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_throttle(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_write_memory(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_drop_user(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_drop_tunnel(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_drop_session(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_snoop(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_no_snoop(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_throttle(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_no_throttle(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_debug(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_no_debug(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_set(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_load_plugin(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_remove_plugin(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_uptime(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_shutdown(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_reload(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_setforward(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_rmtlnsconf(struct cli_def *cli, const char *command, char **argv, int argc); static int regular_stuff(struct cli_def *cli); #ifdef STATISTICS -static int cmd_show_counters(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_clear_counters(struct cli_def *cli, char *command, char **argv, int argc); +static int cmd_show_counters(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_clear_counters(struct cli_def *cli, const char *command, char **argv, int argc); #endif /* STATISTICS */ #ifdef BGP #define MODE_CONFIG_BGP 8 -static int cmd_router_bgp(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_router_bgp_neighbour(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_router_bgp_no_neighbour(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_bgp(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_no_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_restart_bgp(struct cli_def *cli, char *command, char **argv, int argc); +static int cmd_router_bgp(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_router_bgp_neighbour(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_router_bgp_no_neighbour(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_bgp(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_suspend_bgp(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_no_suspend_bgp(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_restart_bgp(struct cli_def *cli, const char *command, char **argv, int argc); #endif /* BGP */ #define MODE_CONFIG_NACL 9 -static int cmd_ip_access_list(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_no_ip_access_list(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_ip_access_list_rule(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_filter(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_no_filter(struct cli_def *cli, char *command, char **argv, int argc); -static int cmd_show_access_list(struct cli_def *cli, char *command, char **argv, int argc); +static int cmd_ip_access_list(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_no_ip_access_list(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_ip_access_list_rule(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_filter(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_no_filter(struct cli_def *cli, const char *command, char **argv, int argc); +static int cmd_show_access_list(struct cli_def *cli, const char *command, char **argv, int argc); /* match if b is a substr of a */ #define MATCH(a,b) (!strncmp((a), (b), strlen(b))) @@ -357,7 +357,7 @@ void cli_do(int sockfd) exit(0); } -static void cli_print_log(struct cli_def *cli, char *string) +static void cli_print_log(struct cli_def *cli, const char *string) { LOG(3, 0, 0, "%s\n", string); } @@ -406,7 +406,7 @@ int cli_arg_help(struct cli_def *cli, int cr_ok, char *entry, ...) return CLI_OK; } -static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_session(struct cli_def *cli, const char *command, char **argv, int argc) { int i; @@ -585,7 +585,7 @@ static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int return CLI_OK; } -static int cmd_show_tunnels(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_tunnels(struct cli_def *cli, const char *command, char **argv, int argc) { int i, x, show_all = 0; char *states[] = { @@ -676,7 +676,7 @@ static int cmd_show_tunnels(struct cli_def *cli, char *command, char **argv, int return CLI_OK; } -static int cmd_show_users(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_users(struct cli_def *cli, const char *command, char **argv, int argc) { char sid[32][8]; char *sargv[32]; @@ -718,7 +718,7 @@ static int cmd_show_users(struct cli_def *cli, char *command, char **argv, int a } #ifdef STATISTICS -static int cmd_show_counters(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_counters(struct cli_def *cli, const char *command, char **argv, int argc) { if (CLI_HELP_REQUESTED) return CLI_HELP_NO_ARGS; @@ -733,7 +733,7 @@ static int cmd_show_counters(struct cli_def *cli, char *command, char **argv, in GET_STAT(tun_tx_bytes), GET_STAT(tun_tx_packets), GET_STAT(tun_tx_errors)); - cli_print(cli, ""); + cli_print(cli, " "); cli_print(cli, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries"); cli_print(cli, "%-10s %10u %10u %10u", "RX", @@ -745,7 +745,7 @@ static int cmd_show_counters(struct cli_def *cli, char *command, char **argv, in GET_STAT(tunnel_tx_packets), GET_STAT(tunnel_tx_errors), GET_STAT(tunnel_retries)); - cli_print(cli, ""); + cli_print(cli, " "); cli_print(cli, "%-30s%-10s", "Counter", "Value"); cli_print(cli, "-----------------------------------------"); @@ -811,14 +811,14 @@ static int cmd_show_counters(struct cli_def *cli, char *command, char **argv, in char *p = strchr(t, '\n'); if (p) *p = 0; - cli_print(cli, ""); + cli_print(cli, " "); cli_print(cli, "Last counter reset %s", t); } return CLI_OK; } -static int cmd_clear_counters(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_clear_counters(struct cli_def *cli, const char *command, char **argv, int argc) { if (CLI_HELP_REQUESTED) return CLI_HELP_NO_ARGS; @@ -831,7 +831,7 @@ static int cmd_clear_counters(struct cli_def *cli, char *command, char **argv, i } #endif /* STATISTICS */ -static int cmd_show_version(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_version(struct cli_def *cli, const char *command, char **argv, int argc) { if (CLI_HELP_REQUESTED) return CLI_HELP_NO_ARGS; @@ -840,7 +840,7 @@ static int cmd_show_version(struct cli_def *cli, char *command, char **argv, int return CLI_OK; } -static int cmd_show_pool(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_pool(struct cli_def *cli, const char *command, char **argv, int argc) { int i; int used = 0, free = 0, show_all = 0; @@ -902,13 +902,13 @@ static int cmd_show_pool(struct cli_def *cli, char *command, char **argv, int ar } static FILE *save_config_fh = 0; -static void print_save_config(struct cli_def *cli, char *string) +static void print_save_config(struct cli_def *cli, const char *string) { if (save_config_fh) fprintf(save_config_fh, "%s\n", string); } -static int cmd_write_memory(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_write_memory(struct cli_def *cli, const char *command, char **argv, int argc) { if (CLI_HELP_REQUESTED) return CLI_HELP_NO_ARGS; @@ -931,7 +931,7 @@ static int cmd_write_memory(struct cli_def *cli, char *command, char **argv, int static char const *show_access_list_rule(int extended, ip_filter_rulet *rule); -static int cmd_show_run(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_run(struct cli_def *cli, const char *command, char **argv, int argc) { int i; char ipv6addr[INET6_ADDRSTRLEN]; @@ -1028,7 +1028,7 @@ static int cmd_show_run(struct cli_def *cli, char *command, char **argv, int arg return CLI_OK; } -static int cmd_show_radius(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_radius(struct cli_def *cli, const char *command, char **argv, int argc) { int i, free = 0, used = 0, show_all = 0; char *states[] = { @@ -1083,7 +1083,7 @@ static int cmd_show_radius(struct cli_def *cli, char *command, char **argv, int return CLI_OK; } -static int cmd_show_plugins(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_plugins(struct cli_def *cli, const char *command, char **argv, int argc) { int i; @@ -1098,7 +1098,7 @@ static int cmd_show_plugins(struct cli_def *cli, char *command, char **argv, int return CLI_OK; } -static int cmd_show_throttle(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_throttle(struct cli_def *cli, const char *command, char **argv, int argc) { int i; @@ -1130,7 +1130,7 @@ static int cmd_show_throttle(struct cli_def *cli, char *command, char **argv, in return CLI_OK; } -static int cmd_show_banana(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_banana(struct cli_def *cli, const char *command, char **argv, int argc) { if (CLI_HELP_REQUESTED) return CLI_HELP_NO_ARGS; @@ -1153,7 +1153,7 @@ static int cmd_show_banana(struct cli_def *cli, char *command, char **argv, int return CLI_OK; } -static int cmd_drop_user(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_drop_user(struct cli_def *cli, const char *command, char **argv, int argc) { int i; sessionidt s; @@ -1194,7 +1194,7 @@ static int cmd_drop_user(struct cli_def *cli, char *command, char **argv, int ar return CLI_OK; } -static int cmd_drop_tunnel(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_drop_tunnel(struct cli_def *cli, const char *command, char **argv, int argc) { int i; tunnelidt t; @@ -1244,7 +1244,7 @@ static int cmd_drop_tunnel(struct cli_def *cli, char *command, char **argv, int return CLI_OK; } -static int cmd_drop_session(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_drop_session(struct cli_def *cli, const char *command, char **argv, int argc) { int i; sessionidt s; @@ -1294,7 +1294,7 @@ static int cmd_drop_session(struct cli_def *cli, char *command, char **argv, int return CLI_OK; } -static int cmd_snoop(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_snoop(struct cli_def *cli, const char *command, char **argv, int argc) { in_addr_t ip; uint16_t port; @@ -1367,7 +1367,7 @@ static int cmd_snoop(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -static int cmd_no_snoop(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_no_snoop(struct cli_def *cli, const char *command, char **argv, int argc) { int i; sessionidt s; @@ -1405,7 +1405,7 @@ static int cmd_no_snoop(struct cli_def *cli, char *command, char **argv, int arg return CLI_OK; } -static int cmd_throttle(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_throttle(struct cli_def *cli, const char *command, char **argv, int argc) { int rate_in = 0; int rate_out = 0; @@ -1533,7 +1533,7 @@ static int cmd_throttle(struct cli_def *cli, char *command, char **argv, int arg return CLI_OK; } -static int cmd_no_throttle(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_no_throttle(struct cli_def *cli, const char *command, char **argv, int argc) { int i; sessionidt s; @@ -1578,7 +1578,7 @@ static int cmd_no_throttle(struct cli_def *cli, char *command, char **argv, int return CLI_OK; } -static int cmd_debug(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_debug(struct cli_def *cli, const char *command, char **argv, int argc) { int i; @@ -1642,7 +1642,7 @@ static int cmd_debug(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -static int cmd_no_debug(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_no_debug(struct cli_def *cli, const char *command, char **argv, int argc) { int i; @@ -1688,7 +1688,7 @@ static int cmd_no_debug(struct cli_def *cli, char *command, char **argv, int arg return CLI_OK; } -static int cmd_load_plugin(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_load_plugin(struct cli_def *cli, const char *command, char **argv, int argc) { int i, firstfree = 0; @@ -1723,7 +1723,7 @@ static int cmd_load_plugin(struct cli_def *cli, char *command, char **argv, int return CLI_OK; } -static int cmd_remove_plugin(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_remove_plugin(struct cli_def *cli, const char *command, char **argv, int argc) { int i; @@ -1784,7 +1784,7 @@ static char *duration(time_t secs) return buf; } -static int cmd_uptime(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_uptime(struct cli_def *cli, const char *command, char **argv, int argc) { FILE *fh; char buf[100], *p = buf, *loads[3]; @@ -1794,7 +1794,7 @@ static int cmd_uptime(struct cli_def *cli, char *command, char **argv, int argc) return CLI_HELP_NO_ARGS; fh = fopen("/proc/loadavg", "r"); - fgets(buf, 100, fh); + p = fgets(buf, 100, fh); fclose(fh); for (i = 0; i < 3; i++) @@ -1820,7 +1820,7 @@ static int cmd_uptime(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -static int cmd_set(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_set(struct cli_def *cli, const char *command, char **argv, int argc) { int i; @@ -1949,7 +1949,7 @@ int regular_stuff(struct cli_def *cli) } #ifdef BGP -static int cmd_router_bgp(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_router_bgp(struct cli_def *cli, const char *command, char **argv, int argc) { int as; @@ -2015,7 +2015,7 @@ static int find_bgp_neighbour(char const *name) return new; } -static int cmd_router_bgp_neighbour(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_router_bgp_neighbour(struct cli_def *cli, const char *command, char **argv, int argc) { int i; int keepalive; @@ -2159,7 +2159,7 @@ static int cmd_router_bgp_neighbour(struct cli_def *cli, char *command, char **a return CLI_OK; } -static int cmd_router_bgp_no_neighbour(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_router_bgp_no_neighbour(struct cli_def *cli, const char *command, char **argv, int argc) { int i; @@ -2191,7 +2191,7 @@ static int cmd_router_bgp_no_neighbour(struct cli_def *cli, char *command, char return CLI_OK; } -static int cmd_show_bgp(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_bgp(struct cli_def *cli, const char *command, char **argv, int argc) { int i; int hdr = 0; @@ -2223,7 +2223,7 @@ static int cmd_show_bgp(struct cli_def *cli, char *command, char **argv, int arg if (!hdr++) { - cli_print(cli, ""); + cli_print(cli, " "); cli_print(cli, "Peer AS Address " "State Retries Retry in Route Pend Timers"); cli_print(cli, "------------------ ----- --------------- " @@ -2246,7 +2246,7 @@ static int cmd_show_bgp(struct cli_def *cli, char *command, char **argv, int arg return CLI_OK; } -static int cmd_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_suspend_bgp(struct cli_def *cli, const char *command, char **argv, int argc) { int i; char *addr; @@ -2279,7 +2279,7 @@ static int cmd_suspend_bgp(struct cli_def *cli, char *command, char **argv, int return CLI_OK; } -static int cmd_no_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_no_suspend_bgp(struct cli_def *cli, const char *command, char **argv, int argc) { int i; char *addr; @@ -2313,7 +2313,7 @@ static int cmd_no_suspend_bgp(struct cli_def *cli, char *command, char **argv, i return CLI_OK; } -static int cmd_restart_bgp(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_restart_bgp(struct cli_def *cli, const char *command, char **argv, int argc) { int i; char *addr; @@ -2441,12 +2441,12 @@ static int access_list(struct cli_def *cli, char **argv, int argc, int add) return CLI_OK; } -static int cmd_ip_access_list(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_ip_access_list(struct cli_def *cli, const char *command, char **argv, int argc) { return access_list(cli, argv, argc, 1); } -static int cmd_no_ip_access_list(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_no_ip_access_list(struct cli_def *cli, const char *command, char **argv, int argc) { return access_list(cli, argv, argc, 0); } @@ -2532,7 +2532,7 @@ static char const *show_access_list_rule(int extended, ip_filter_rulet *rule) return buf; } -static ip_filter_rulet *access_list_rule_ext(struct cli_def *cli, char *command, char **argv, int argc) +static ip_filter_rulet *access_list_rule_ext(struct cli_def *cli, const char *command, char **argv, int argc) { static ip_filter_rulet rule; struct in_addr addr; @@ -2767,7 +2767,7 @@ static ip_filter_rulet *access_list_rule_ext(struct cli_def *cli, char *command, return &rule; } -static ip_filter_rulet *access_list_rule_std(struct cli_def *cli, char *command, char **argv, int argc) +static ip_filter_rulet *access_list_rule_std(struct cli_def *cli, const char *command, char **argv, int argc) { static ip_filter_rulet rule; struct in_addr addr; @@ -2883,7 +2883,7 @@ static ip_filter_rulet *access_list_rule_std(struct cli_def *cli, char *command, return &rule; } -static int cmd_ip_access_list_rule(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_ip_access_list_rule(struct cli_def *cli, const char *command, char **argv, int argc) { int i; ip_filter_rulet *rule = ip_filters[filt].extended @@ -2909,7 +2909,7 @@ static int cmd_ip_access_list_rule(struct cli_def *cli, char *command, char **ar return CLI_OK; } -static int cmd_filter(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_filter(struct cli_def *cli, const char *command, char **argv, int argc) { sessionidt s; int i; @@ -3005,7 +3005,7 @@ static int cmd_filter(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -static int cmd_no_filter(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_no_filter(struct cli_def *cli, const char *command, char **argv, int argc) { int i; sessionidt s; @@ -3050,7 +3050,7 @@ static int cmd_no_filter(struct cli_def *cli, char *command, char **argv, int ar return CLI_OK; } -static int cmd_show_access_list(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_access_list(struct cli_def *cli, const char *command, char **argv, int argc) { int i; @@ -3095,7 +3095,7 @@ static int cmd_show_access_list(struct cli_def *cli, char *command, char **argv, return CLI_OK; } -static int cmd_shutdown(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_shutdown(struct cli_def *cli, const char *command, char **argv, int argc) { if (CLI_HELP_REQUESTED) return CLI_HELP_NO_ARGS; @@ -3104,7 +3104,7 @@ static int cmd_shutdown(struct cli_def *cli, char *command, char **argv, int arg return CLI_OK; } -static int cmd_reload(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_reload(struct cli_def *cli, const char *command, char **argv, int argc) { if (CLI_HELP_REQUESTED) return CLI_HELP_NO_ARGS; @@ -3113,7 +3113,7 @@ static int cmd_reload(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -static int cmd_show_group(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_group(struct cli_def *cli, const char *command, char **argv, int argc) { int i; groupidt g; @@ -3184,7 +3184,7 @@ static int cmd_show_group(struct cli_def *cli, char *command, char **argv, int a return CLI_OK; } -static int cmd_setforward(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_setforward(struct cli_def *cli, const char *command, char **argv, int argc) { int ret; @@ -3234,7 +3234,7 @@ static int cmd_setforward(struct cli_def *cli, char *command, char **argv, int a return CLI_OK; } -static int cmd_show_rmtlnsconf(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_rmtlnsconf(struct cli_def *cli, const char *command, char **argv, int argc) { confrlnsidt idrlns; char strdisp[1024]; diff --git a/cluster.c b/cluster.c index fc4d58a..7768bf2 100644 --- a/cluster.c +++ b/cluster.c @@ -2098,7 +2098,7 @@ shortpacket: //==================================================================================================== -int cmd_show_cluster(struct cli_def *cli, char *command, char **argv, int argc) +int cmd_show_cluster(struct cli_def *cli, const char *command, char **argv, int argc) { int i; diff --git a/cluster.h b/cluster.h index 794cc9d..b1aebaf 100644 --- a/cluster.h +++ b/cluster.h @@ -99,7 +99,7 @@ void cluster_send_ping(time_t basetime); void cluster_heartbeat(void); void cluster_check_master(void); void cluster_check_slaves(void); -int cmd_show_cluster(struct cli_def *cli, char *command, char **argv, int argc); +int cmd_show_cluster(struct cli_def *cli, const char *command, char **argv, int argc); int master_forward_pppoe_packet(uint8_t *data, int size, uint8_t codepad); #endif /* __CLUSTER_H__ */ diff --git a/debian/changelog b/debian/changelog index 07531e8..61a117a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,21 @@ +l2tpns (2.2.1-2sames3.12) UNRELEASED; urgency=low + + * Fix: throttle ipv6 out. + * Fix: remove old IPV6 routes on slave + * Fix: compiling Warning, dpkg-buildflags ... + * Enabled hardened build flags, thanks Moritz Muehlenhoff (closes: #657846) + * Packaging updates + * Move to 3.0 (native) source format + * Bump DH compat level to 8 + * Fix ordering of stdio.h/syslog.h includes (closes: #707385) + * Create accounting_dir in init script if necessary (closes: #418156) + * Bump Standards-Version to 3.9.4.0 + * Add build-arch/build-indep targets to debian/rules + * Fix: compiling Warning + * improved load balancing algorithm. + + -- Fernando Alves Sun, 07 Oct 2013 22:20:53 +0200 + l2tpns (2.2.1-2sames3.11) unstable; urgency=low * improved load balancing algorithm. diff --git a/debian/compat b/debian/compat index b8626c4..45a4fb7 100644 --- a/debian/compat +++ b/debian/compat @@ -1 +1 @@ -4 +8 diff --git a/debian/control b/debian/control index cc11d4b..b60e24f 100644 --- a/debian/control +++ b/debian/control @@ -2,12 +2,12 @@ Source: l2tpns Section: net Priority: optional Maintainer: Jonathan McDowell -Build-Depends: debhelper (>> 4), libcli-dev (>> 1.8.5) -Standards-Version: 3.7.2.0 +Build-Depends: debhelper (>> 8), libcli-dev (>> 1.8.5) +Standards-Version: 3.9.4.0 Package: l2tpns Architecture: any -Depends: ${shlibs:Depends} +Depends: ${shlibs:Depends}, ${misc:Depends} Description: layer 2 tunnelling protocol network server (LNS) l2tpns is a daemon designed to terminate large volumes of layer 2 tunnelling protocol (RFC 2661: L2TP) sessions. diff --git a/debian/init.d b/debian/init.d index 3da046d..737ce46 100644 --- a/debian/init.d +++ b/debian/init.d @@ -19,6 +19,7 @@ DAEMON=/usr/sbin/l2tpns NAME=l2tpns DESC=l2tpns ARGS="-d" +ACCTDIR=$(grep "set accounting_dir" /etc/l2tpns/startup-config | sed -e 's/.* "//' -e 's/".*//') test -f $DAEMON || exit 0 @@ -27,6 +28,9 @@ set -e case "$1" in start) echo -n "Starting $DESC: " + if [ ! -d "$ACCTDIR" ]; then + mkdir -p "$ACCTDIR" + fi start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \ --exec $DAEMON -- $ARGS echo "$NAME." diff --git a/debian/preinst b/debian/preinst deleted file mode 100644 index 61b4735..0000000 --- a/debian/preinst +++ /dev/null @@ -1,13 +0,0 @@ -#! /bin/sh -# preinst script for l2tpns - -set -e - -# dh_installdeb will replace this with shell code automatically -# generated by other debhelper scripts. - -#DEBHELPER# - -exit 0 - - diff --git a/debian/rules b/debian/rules index 0580bd7..cf9fe8d 100755 --- a/debian/rules +++ b/debian/rules @@ -2,9 +2,6 @@ # Sample debian/rules that uses debhelper. # GNU copyright 1997 to 1999 by Joey Hess. -ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS))) - CFLAGS += -g -endif ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) INSTALL_PROGRAM += -s endif @@ -16,8 +13,9 @@ configure-stamp: touch configure-stamp -build: build-stamp - +build: build-arch build-indep +build-arch: build-stamp +build-indep: build-stamp build-stamp: configure-stamp dh_testdir @@ -33,14 +31,14 @@ clean: rm -f build-stamp configure-stamp # Add here commands to clean up after the build process. - -$(MAKE) clean + [ ! -f Makefile ] || $(MAKE) clean dh_clean install: build dh_testdir dh_testroot - dh_clean -k + dh_prep dh_installdirs $(MAKE) install DESTDIR=$(CURDIR)/debian/l2tpns diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/garden.c b/garden.c index 63135ea..863114e 100644 --- a/garden.c +++ b/garden.c @@ -160,7 +160,7 @@ int plugin_become_master(void) for (i = 0; up_commands[i] && *up_commands[i]; i++) { f->log(3, 0, 0, "Running %s\n", up_commands[i]); - system(up_commands[i]); + if (-1 == system(up_commands[i])) f->log(0, 0, 0, "error command %s\n", up_commands[i]); } return PLUGIN_RET_OK; @@ -179,6 +179,7 @@ int garden_session(sessiont *s, int flag, char *newuser) { char cmd[2048]; sessionidt sess; + int status; if (!s) return 0; if (!s->opened) return 0; @@ -194,7 +195,7 @@ int garden_session(sessiont *s, int flag, char *newuser) f->fmtaddr(htonl(s->ip), 0)); f->log(3, sess, s->tunnel, "%s\n", cmd); - system(cmd); + status = system(cmd); s->walled_garden = 1; } else @@ -232,7 +233,7 @@ int garden_session(sessiont *s, int flag, char *newuser) f->log(3, sess, s->tunnel, "%s\n", cmd); while (--count) { - int status = system(cmd); + status = system(cmd); if (WEXITSTATUS(status) != 0) break; } @@ -275,7 +276,7 @@ int plugin_init(struct pluginfuncs *funcs) for (i = 0; down_commands[i] && *down_commands[i]; i++) { f->log(3, 0, 0, "Running %s\n", down_commands[i]); - system(down_commands[i]); + if (-1 == system(down_commands[i])) f->log(0, 0, 0, "error command %s\n", down_commands[i]); } } @@ -292,7 +293,7 @@ void plugin_done() for (i = 0; down_commands[i] && *down_commands[i]; i++) { f->log(3, 0, 0, "Running %s\n", down_commands[i]); - system(down_commands[i]); + if (-1 == system(down_commands[i])) f->log(0, 0, 0, "error command %s\n", down_commands[i]); } } diff --git a/grpsess.c b/grpsess.c index ccaa27c..d3fae30 100644 --- a/grpsess.c +++ b/grpsess.c @@ -520,7 +520,7 @@ sessionidt grp_getnextsession(groupidt g, in_addr_t ip, in_addr_t ip_src) sessionidt s = 0, s2 = 0, s3 = 0; int i; uint32_t ltime_changed = 0, mintxrate = 0xFFFFFFFF, maxtxrate = 0; - uint32_t txrate; + uint32_t txrate = 0; if (g >= MAXGROUPE) return 0; diff --git a/l2tpns.c b/l2tpns.c index 9861e88..867730b 100644 --- a/l2tpns.c +++ b/l2tpns.c @@ -10,6 +10,7 @@ #include #include #define SYSLOG_NAMES +#include #include #include #include @@ -19,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -1010,8 +1010,10 @@ sessionidt sessionbyipv6(struct in6_addr ip) ip.s6_addr[1] == 0x80 && ip.s6_addr16[1] == 0 && ip.s6_addr16[2] == 0 && - ip.s6_addr16[3] == 0)) { - s = lookup_ipmap(*(in_addr_t *) &ip.s6_addr[8]); + ip.s6_addr16[3] == 0)) + { + in_addr_t *pipv4 = (in_addr_t *) &ip.s6_addr[8]; + s = lookup_ipmap(*pipv4); } else { s = lookup_ipv6map(ip); } @@ -1097,7 +1099,7 @@ static void cache_ipv6map(struct in6_addr ip, int prefixlen, sessionidt s) // // CLI list to dump current ipcache. // -int cmd_show_ipcache(struct cli_def *cli, char *command, char **argv, int argc) +int cmd_show_ipcache(struct cli_def *cli, const char *command, char **argv, int argc) { union iphash *d = ip_hash, *e, *f, *g; int i, j, k, l; @@ -1822,6 +1824,8 @@ static void send_ipout(sessionidt s, uint8_t *buf, int len) { sessiont *sp; tunnelidt t; + uint8_t *p; + uint8_t *data = buf; // Keep a copy of the originals. uint8_t b[MAXETHER + 20]; @@ -1844,11 +1848,14 @@ static void send_ipout(sessionidt s, uint8_t *buf, int len) LOG(5, s, t, "Ethernet -> Tunnel (%d bytes)\n", len); // Add on L2TP header - { - uint8_t *p = makeppp(b, sizeof(b), buf, len, s, t, PPPIP, 0, 0, 0); - if (!p) return; - tunnelsend(b, len + (p-b), t); // send it... - } + if (*(uint16_t *) (data + 2) == htons(PKTIPV6)) + p = makeppp(b, sizeof(b), buf, len, s, t, PPPIPV6, 0, 0, 0); // IPV6 + else + p = makeppp(b, sizeof(b), buf, len, s, t, PPPIP, 0, 0, 0); // IPV4 + + if (!p) return; + + tunnelsend(b, len + (p-b), t); // send it... // Snooping this session. if (sp->snoop_ip && sp->snoop_port) @@ -1867,10 +1874,11 @@ static void send_ipout(sessionidt s, uint8_t *buf, int len) static void control16(controlt * c, uint16_t avp, uint16_t val, uint8_t m) { uint16_t l = (m ? 0x8008 : 0x0008); - *(uint16_t *) (c->buf + c->length + 0) = htons(l); - *(uint16_t *) (c->buf + c->length + 2) = htons(0); - *(uint16_t *) (c->buf + c->length + 4) = htons(avp); - *(uint16_t *) (c->buf + c->length + 6) = htons(val); + uint16_t *pint16 = (uint16_t *) (c->buf + c->length + 0); + pint16[0] = htons(l); + pint16[1] = htons(0); + pint16[2] = htons(avp); + pint16[3] = htons(val); c->length += 8; } @@ -1878,10 +1886,12 @@ static void control16(controlt * c, uint16_t avp, uint16_t val, uint8_t m) static void control32(controlt * c, uint16_t avp, uint32_t val, uint8_t m) { uint16_t l = (m ? 0x800A : 0x000A); - *(uint16_t *) (c->buf + c->length + 0) = htons(l); - *(uint16_t *) (c->buf + c->length + 2) = htons(0); - *(uint16_t *) (c->buf + c->length + 4) = htons(avp); - *(uint32_t *) (c->buf + c->length + 6) = htonl(val); + uint16_t *pint16 = (uint16_t *) (c->buf + c->length + 0); + uint32_t *pint32 = (uint32_t *) (c->buf + c->length + 6); + pint16[0] = htons(l); + pint16[1] = htons(0); + pint16[2] = htons(avp); + pint32[0] = htonl(val); c->length += 10; } @@ -1889,9 +1899,10 @@ static void control32(controlt * c, uint16_t avp, uint32_t val, uint8_t m) static void controls(controlt * c, uint16_t avp, char *val, uint8_t m) { uint16_t l = ((m ? 0x8000 : 0) + strlen(val) + 6); - *(uint16_t *) (c->buf + c->length + 0) = htons(l); - *(uint16_t *) (c->buf + c->length + 2) = htons(0); - *(uint16_t *) (c->buf + c->length + 4) = htons(avp); + uint16_t *pint16 = (uint16_t *) (c->buf + c->length + 0); + pint16[0] = htons(l); + pint16[1] = htons(0); + pint16[2] = htons(avp); memcpy(c->buf + c->length + 6, val, strlen(val)); c->length += 6 + strlen(val); } @@ -1900,9 +1911,10 @@ static void controls(controlt * c, uint16_t avp, char *val, uint8_t m) static void controlb(controlt * c, uint16_t avp, uint8_t *val, unsigned int len, uint8_t m) { uint16_t l = ((m ? 0x8000 : 0) + len + 6); - *(uint16_t *) (c->buf + c->length + 0) = htons(l); - *(uint16_t *) (c->buf + c->length + 2) = htons(0); - *(uint16_t *) (c->buf + c->length + 4) = htons(avp); + uint16_t *pint16 = (uint16_t *) (c->buf + c->length + 0); + pint16[0] = htons(l); + pint16[1] = htons(0); + pint16[2] = htons(avp); memcpy(c->buf + c->length + 6, val, len); c->length += 6 + len; } @@ -1947,10 +1959,11 @@ static void controlnull(tunnelidt t) // add a control message to a tunnel, and send if within window static void controladd(controlt *c, sessionidt far, tunnelidt t) { - *(uint16_t *) (c->buf + 2) = htons(c->length); // length - *(uint16_t *) (c->buf + 4) = htons(tunnel[t].far); // tunnel - *(uint16_t *) (c->buf + 6) = htons(far); // session - *(uint16_t *) (c->buf + 8) = htons(tunnel[t].ns); // sequence + uint16_t *pint16 = (uint16_t *) (c->buf + 2); + pint16[0] = htons(c->length); // length + pint16[1] = htons(tunnel[t].far); // tunnel + pint16[2] = htons(far); // session + pint16[3] = htons(tunnel[t].ns); // sequence tunnel[t].ns++; // advance sequence // link in message in to queue if (tunnel[t].controlc) @@ -5075,9 +5088,9 @@ int main(int argc, char *argv[]) case 'd': if (fork()) exit(0); setsid(); - freopen("/dev/null", "r", stdin); - freopen("/dev/null", "w", stdout); - freopen("/dev/null", "w", stderr); + if(!freopen("/dev/null", "r", stdin)) LOG(0, 0, 0, "Error freopen stdin: %s\n", strerror(errno)); + if(!freopen("/dev/null", "w", stdout)) LOG(0, 0, 0, "Error freopen stdout: %s\n", strerror(errno)); + if(!freopen("/dev/null", "w", stderr)) LOG(0, 0, 0, "Error freopen stderr: %s\n", strerror(errno)); break; case 'v': optdebug++; @@ -5128,7 +5141,7 @@ int main(int argc, char *argv[]) LOG(0, 0, 0, "Can't set ulimit: %s\n", strerror(errno)); // Make core dumps go to /tmp - chdir("/tmp"); + if(chdir("/tmp")) LOG(0, 0, 0, "Error chdir /tmp: %s\n", strerror(errno)); } if (config->scheduler_fifo) @@ -5844,6 +5857,10 @@ int load_session(sessionidt s, sessiont *new) uncache_ipmap(session[s].ip); } + // remove old IPV6 routes... + if (session[s].ipv6route.s6_addr[0] && session[s].ipv6prefixlen) + route6set(s, session[s].ipv6route, session[s].ipv6prefixlen, 0); + routed = 0; // add new routes... @@ -6318,7 +6335,7 @@ void become_master(void) } } -int cmd_show_hist_idle(struct cli_def *cli, char *command, char **argv, int argc) +int cmd_show_hist_idle(struct cli_def *cli, const char *command, char **argv, int argc) { int s, i; int count = 0; @@ -6356,7 +6373,7 @@ int cmd_show_hist_idle(struct cli_def *cli, char *command, char **argv, int argc return CLI_OK; } -int cmd_show_hist_open(struct cli_def *cli, char *command, char **argv, int argc) +int cmd_show_hist_open(struct cli_def *cli, const char *command, char **argv, int argc) { int s, i; int count = 0; diff --git a/l2tpns.h b/l2tpns.h index 5dd854f..d28f3e7 100644 --- a/l2tpns.h +++ b/l2tpns.h @@ -991,13 +991,12 @@ void processipout(uint8_t *buf, int len); void snoop_send_packet(uint8_t *packet, uint16_t size, in_addr_t destination, uint16_t port); int find_filter(char const *name, size_t len); int ip_filter(uint8_t *buf, int len, uint8_t filter); -int cmd_show_ipcache(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_hist_idle(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_hist_open(struct cli_def *cli, char *command, char **argv, int argc); +int cmd_show_ipcache(struct cli_def *cli, const char *command, char **argv, int argc); +int cmd_show_hist_idle(struct cli_def *cli, const char *command, char **argv, int argc); +int cmd_show_hist_open(struct cli_def *cli, const char *command, char **argv, int argc); void netlink_addattr(struct nlmsghdr *nh, int type, const void *data, int alen); ssize_t netlink_send(struct nlmsghdr *nh); void cache_ipmap(in_addr_t ip, sessionidt s); - tunnelidt lac_new_tunnel(); void lac_tunnelclear(tunnelidt t); void lac_send_SCCRQ(tunnelidt t, uint8_t * auth, unsigned int auth_len); diff --git a/tbf.c b/tbf.c index 8b488d6..aa9810e 100644 --- a/tbf.c +++ b/tbf.c @@ -310,7 +310,7 @@ int tbf_run_timer(void) return 1; } -int cmd_show_tbf(struct cli_def *cli, char *command, char **argv, int argc) +int cmd_show_tbf(struct cli_def *cli, const char *command, char **argv, int argc) { int i; int count = 0; diff --git a/tbf.h b/tbf.h index 925e4f7..3acc3f8 100644 --- a/tbf.h +++ b/tbf.h @@ -40,6 +40,6 @@ int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, uint8_t *, int free_tbf(int tid); void fsck_tbfs(void); -int cmd_show_tbf(struct cli_def *cli, char *command, char **argv, int argc); +int cmd_show_tbf(struct cli_def *cli, const char *command, char **argv, int argc); #endif /* __TBF_H__ */