From: bodea Date: Thu, 11 Nov 2004 03:07:42 +0000 (+0000) Subject: make BGP keepalive/hold time configurable, revise config syntax X-Git-Tag: release_2_0_6~2 X-Git-Url: http://git.sameswireless.fr/l2tpns.git/commitdiff_plain/74967abeca9a78ad4a1b7a953fd67988cfb67895 make BGP keepalive/hold time configurable, revise config syntax --- diff --git a/Changes b/Changes index 17bfb80..c7c86e1 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,7 @@ +* Thu Nov 11 2004 Brendan O'Dea 2.0.6 +- Make BGP keepalive/hold time configurable +- Revise BGP config to use "router bgp AS" syntax + * Tue Nov 9 2004 Brendan O'Dea 2.0.5 - Handle routing properly in lone-master case - Fix intercepts: don't double-snoop throttled customers, ensure diff --git a/bgp.c b/bgp.c index 5d7c578..2d411e7 100644 --- a/bgp.c +++ b/bgp.c @@ -10,7 +10,7 @@ * nor RFC2385 (which requires a kernel patch on 2.4 kernels). */ -char const *cvs_id_bgp = "$Id: bgp.c,v 1.5 2004/11/05 04:55:26 bodea Exp $"; +char const *cvs_id_bgp = "$Id: bgp.c,v 1.6 2004/11/11 03:07:42 bodea Exp $"; #include #include @@ -34,7 +34,6 @@ static struct bgp_route_list *bgp_insert_route(struct bgp_route_list *head, struct bgp_route_list *new); static void bgp_free_routes(struct bgp_route_list *routes); -static char const *bgp_state_str(enum bgp_state state); static char const *bgp_msg_type_str(u8 type); static int bgp_connect(struct bgp_peer *peer); static int bgp_handle_connect(struct bgp_peer *peer); @@ -47,6 +46,10 @@ static int bgp_send_update(struct bgp_peer *peer); static int bgp_send_notification(struct bgp_peer *peer, u8 code, u8 subcode); static u16 our_as; +static struct bgp_route_list *bgp_routes = 0; + +int bgp_configured = 0; +struct bgp_peer *bgp_peers = 0; /* prepare peer structure, globals */ int bgp_setup(int as) @@ -86,7 +89,7 @@ int bgp_setup(int as) } /* start connection with a peer */ -int bgp_start(struct bgp_peer *peer, char *name, int as, int enable) +int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold, int enable) { struct hostent *h; int ibgp; @@ -118,6 +121,16 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int enable) peer->as = as > 0 ? as : our_as; ibgp = peer->as == our_as; + /* set initial timer values */ + peer->init_keepalive = keepalive == -1 ? BGP_KEEPALIVE_TIME : keepalive; + peer->init_hold = hold == -1 ? BGP_HOLD_TIME : hold; + + if (peer->init_hold < 3) + peer->init_hold = 3; + + if (peer->init_keepalive * 3 > peer->init_hold) + peer->init_keepalive = peer->init_hold / 3; + /* clear buffers, go to Idle state */ peer->next_state = Idle; bgp_clear(peer); @@ -241,9 +254,11 @@ static void bgp_clear(struct bgp_peer *peer) } peer->keepalive_time = 0; - peer->hold = 0; peer->expire_time = 0; + peer->keepalive = peer->init_keepalive; + peer->hold = peer->init_hold; + bgp_free_routes(peer->routes); peer->routes = 0; @@ -588,7 +603,7 @@ int bgp_process(struct bgp_peer *peer, int readable, int writable) if (time_now > peer->retry_time) return bgp_connect(peer); } - else if (time_now > peer->state_time + BGP_KEEPALIVE_TIME) + else if (time_now > peer->state_time + BGP_STATE_TIME) { LOG(1, 0, 0, 0, "%s timer expired for BGP peer %s\n", bgp_state_str(peer->state), peer->name); @@ -610,7 +625,7 @@ static void bgp_free_routes(struct bgp_route_list *routes) } } -static char const *bgp_state_str(enum bgp_state state) +char const *bgp_state_str(enum bgp_state state) { switch (state) { @@ -766,7 +781,7 @@ static int bgp_write(struct bgp_peer *peer) peer->outbuf->done = 0; if (peer->state == Established) - peer->keepalive_time = time_now + BGP_KEEPALIVE_TIME; + peer->keepalive_time = time_now + peer->keepalive; if (peer->state != peer->next_state) { @@ -888,7 +903,7 @@ static int bgp_handle_input(struct bgp_peer *peer) return 0; } - if ((peer->hold = ntohs(data.hold_time)) < 10) + if ((peer->hold = ntohs(data.hold_time)) < 3) { LOG(1, 0, 0, 0, "Bad hold time (%d) from BGP peer %s\n", peer->hold, peer->name); @@ -897,6 +912,10 @@ static int bgp_handle_input(struct bgp_peer *peer) return 0; } + /* adjust our keepalive based on negotiated hold value */ + if (peer->keepalive * 3 > peer->hold) + peer->keepalive = peer->hold / 3; + /* next transition requires an exchange of keepalives */ bgp_send_keepalive(peer); @@ -910,7 +929,7 @@ static int bgp_handle_input(struct bgp_peer *peer) { peer->state = peer->next_state = Established; peer->state_time = time_now; - peer->keepalive_time = time_now + BGP_KEEPALIVE_TIME; + peer->keepalive_time = time_now + peer->keepalive; peer->update_routes = 1; peer->retry_count = 0; peer->retry_time = 0; @@ -972,7 +991,7 @@ static int bgp_send_open(struct bgp_peer *peer) data.version = BGP_VERSION; data.as = htons(our_as); - data.hold_time = htons(BGP_HOLD_TIME); + data.hold_time = htons(peer->hold); data.identifier = my_address; data.opt_len = 0; @@ -1174,159 +1193,3 @@ static int bgp_send_notification(struct bgp_peer *peer, u8 code, u8 subcode) return bgp_write(peer); } - -/* CLI stuff */ - -#include - -int cmd_show_bgp(struct cli_def *cli, char *command, char **argv, int argc) -{ - int i; - int hdr = 0; - char *addr; - - if (!bgp_configured) - return CLI_OK; - - if (CLI_HELP_REQUESTED) - return cli_arg_help(cli, 1, - "A.B.C.D", "BGP peer address", - "NAME", "BGP peer name", - NULL); - - cli_print(cli, "BGPv%d router identifier %s, local AS number %d, " - "hold time %ds", BGP_VERSION, inet_toa(my_address), (int) our_as, - BGP_HOLD_TIME); - - time(&time_now); - - for (i = 0; i < BGP_NUM_PEERS; i++) - { - if (!*bgp_peers[i].name) - continue; - - addr = inet_toa(bgp_peers[i].addr); - if (argc && strcmp(addr, argv[0]) && - strncmp(bgp_peers[i].name, argv[0], strlen(argv[0]))) - continue; - - if (!hdr++) - { - cli_print(cli, ""); - cli_print(cli, "Peer AS Address " - "State Retries Retry in Route Pend"); - cli_print(cli, "------------------ ----- --------------- " - "----------- ------- -------- ----- ----"); - } - - cli_print(cli, "%-18.18s %5d %15s %-11s %7d %7ds %5s %4s", - bgp_peers[i].name, - bgp_peers[i].as, - addr, - bgp_state_str(bgp_peers[i].state), - bgp_peers[i].retry_count, - bgp_peers[i].retry_time ? bgp_peers[i].retry_time - time_now : 0, - bgp_peers[i].routing ? "yes" : "no", - bgp_peers[i].update_routes ? "yes" : "no"); - } - - return CLI_OK; -} - -int cmd_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc) -{ - int i; - char *addr; - - if (!bgp_configured) - return CLI_OK; - - if (CLI_HELP_REQUESTED) - return cli_arg_help(cli, 1, - "A.B.C.D", "BGP peer address", - "NAME", "BGP peer name", - NULL); - - for (i = 0; i < BGP_NUM_PEERS; i++) - { - if (bgp_peers[i].state != Established) - continue; - - if (!bgp_peers[i].routing) - continue; - - addr = inet_toa(bgp_peers[i].addr); - if (argc && strcmp(addr, argv[0]) && strcmp(bgp_peers[i].name, argv[0])) - continue; - - bgp_peers[i].cli_flag = BGP_CLI_SUSPEND; - cli_print(cli, "Suspending peer %s", bgp_peers[i].name); - } - - return CLI_OK; -} - -int cmd_no_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc) -{ - int i; - char *addr; - - if (!bgp_configured) - return CLI_OK; - - if (CLI_HELP_REQUESTED) - return cli_arg_help(cli, 1, - "A.B.C.D", "BGP peer address", - "NAME", "BGP peer name", - NULL); - - for (i = 0; i < BGP_NUM_PEERS; i++) - { - if (bgp_peers[i].state != Established) - continue; - - if (bgp_peers[i].routing) - continue; - - addr = inet_toa(bgp_peers[i].addr); - if (argc && strcmp(addr, argv[0]) && - strncmp(bgp_peers[i].name, argv[0], strlen(argv[0]))) - continue; - - bgp_peers[i].cli_flag = BGP_CLI_ENABLE; - cli_print(cli, "Un-suspending peer %s", bgp_peers[i].name); - } - - return CLI_OK; -} - -int cmd_restart_bgp(struct cli_def *cli, char *command, char **argv, int argc) -{ - int i; - char *addr; - - if (!bgp_configured) - return CLI_OK; - - if (CLI_HELP_REQUESTED) - return cli_arg_help(cli, 1, - "A.B.C.D", "BGP peer address", - "NAME", "BGP peer name", - NULL); - - for (i = 0; i < BGP_NUM_PEERS; i++) - { - if (!*bgp_peers[i].name) - continue; - - addr = inet_toa(bgp_peers[i].addr); - if (argc && strcmp(addr, argv[0]) && - strncmp(bgp_peers[i].name, argv[0], strlen(argv[0]))) - continue; - - bgp_peers[i].cli_flag = BGP_CLI_RESTART; - cli_print(cli, "Restarting peer %s", bgp_peers[i].name); - } - - return CLI_OK; -} diff --git a/bgp.h b/bgp.h index d5c8b8a..ae89b47 100644 --- a/bgp.h +++ b/bgp.h @@ -1,5 +1,5 @@ /* BGPv4 (RFC1771) */ -/* $Id: bgp.h,v 1.2 2004/06/28 02:43:13 fred_nerk Exp $ */ +/* $Id: bgp.h,v 1.3 2004/11/11 03:07:42 bodea Exp $ */ #ifndef __BGP_H__ #define __BGP_H__ @@ -7,6 +7,7 @@ #define BGP_MAX_PACKET_SIZE 4096 #define BGP_HOLD_TIME 180 /* seconds before peer times us out */ #define BGP_KEEPALIVE_TIME 60 /* seconds between messages */ +#define BGP_STATE_TIME 60 /* state transition timeout in seconds */ #define BGP_MAX_RETRY 42 /* maximum number of times to retry */ #define BGP_RETRY_BACKOFF 60 /* number of seconds between retries, cumulative */ @@ -159,7 +160,10 @@ struct bgp_peer { time_t keepalive_time; /* time to send next keepalive */ time_t retry_time; /* time for connection retry */ int retry_count; /* connection retry count */ - int hold; /* hold time from peer */ + int init_keepalive; /* initial keepalive time */ + int init_hold; /* initial hold time */ + int keepalive; /* negotiated keepalive time */ + int hold; /* negotiated hold time */ time_t expire_time; /* time next peer packet expected */ int routing; /* propagate routes */ int update_routes; /* UPDATE required */ @@ -176,14 +180,12 @@ struct bgp_peer { #define BGP_CLI_ENABLE 2 #define BGP_CLI_RESTART 3 -#define BGP_NUM_PEERS 2 extern struct bgp_peer *bgp_peers; -extern struct bgp_route_list *bgp_routes; extern int bgp_configured; /* actions */ int bgp_setup(int as); -int bgp_start(struct bgp_peer *peer, char *name, int as, int enable); +int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold, int enable); void bgp_stop(struct bgp_peer *peer); void bgp_halt(struct bgp_peer *peer); int bgp_restart(struct bgp_peer *peer); @@ -192,12 +194,7 @@ int bgp_del_route(in_addr_t ip, in_addr_t mask); void bgp_enable_routing(int enable); int bgp_select_state(struct bgp_peer *peer); int bgp_process(struct bgp_peer *peer, int readable, int writable); - -/* CLI */ -int cmd_show_bgp(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_no_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_restart_bgp(struct cli_def *cli, char *command, char **argv, int argc); +char const *bgp_state_str(enum bgp_state state); extern char const *cvs_id_bgp; diff --git a/cli.c b/cli.c index 64b2093..63a1554 100644 --- a/cli.c +++ b/cli.c @@ -2,7 +2,7 @@ // vim: sw=8 ts=8 char const *cvs_name = "$Name: $"; -char const *cvs_id_cli = "$Id: cli.c,v 1.24 2004/11/05 04:55:26 bodea Exp $"; +char const *cvs_id_cli = "$Id: cli.c,v 1.25 2004/11/11 03:07:42 bodea Exp $"; #include #include @@ -29,6 +29,7 @@ char const *cvs_id_cli = "$Id: cli.c,v 1.24 2004/11/05 04:55:26 bodea Exp $"; #include "ll.h" #ifdef BGP #include "bgp.h" +#include #endif extern tunnelt *tunnel; @@ -71,35 +72,46 @@ int debug_tunnel; int debug_rb_tail; FILE *save_config_fh; -int cmd_show_session(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_tunnels(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_users(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_radius(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_counters(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_version(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_pool(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_run(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_banana(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_plugins(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_throttle(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_show_cluster(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_write_memory(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_clear_counters(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_drop_user(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_drop_tunnel(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_drop_session(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_snoop(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_no_snoop(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_throttle(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_no_throttle(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_debug(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_no_debug(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_set(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_load_plugin(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_remove_plugin(struct cli_def *cli, char *command, char **argv, int argc); -int cmd_uptime(struct cli_def *cli, char *command, char **argv, int argc); -int regular_stuff(struct cli_def *cli); -void parsemac(char *string, char mac[6]); +static int cmd_show_session(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_counters(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_clear_counters(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 regular_stuff(struct cli_def *cli); +static void parsemac(char *string, char mac[6]); + +#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_exit(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); +#endif /* BGP */ void init_cli(char *hostname) { @@ -155,24 +167,38 @@ void init_cli(char *hostname) cli_register_command(cli, NULL, "throttle", cmd_throttle, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Temporarily enable throttling for a user"); cli_register_command(cli, NULL, "debug", cmd_debug, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Set the level of logging that is shown on the console"); +#ifdef BGP c = cli_register_command(cli, NULL, "suspend", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, NULL); - cli_register_command(cli, c, "bgp", cmd_suspend_bgp, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Withdraw routes from BGP peer"); + cli_register_command(cli, c, "bgp", cmd_suspend_bgp, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Withdraw routes from BGP neighbour"); +#endif /* BGP */ c = cli_register_command(cli, NULL, "no", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL); cli_register_command(cli, c, "snoop", cmd_no_snoop, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Temporarily disable interception for a user"); cli_register_command(cli, c, "throttle", cmd_no_throttle, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Temporarily disable throttling for a user"); cli_register_command(cli, c, "debug", cmd_no_debug, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Turn off logging of a certain level of debugging"); + +#ifdef BGP c2 = cli_register_command(cli, c, "suspend", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, NULL); - cli_register_command(cli, c2, "bgp", cmd_no_suspend_bgp, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Advertise routes to BGP peer"); + cli_register_command(cli, c2, "bgp", cmd_no_suspend_bgp, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Advertise routes to BGP neighbour"); + + c = cli_register_command(cli, NULL, "restart", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, NULL); + cli_register_command(cli, c, "bgp", cmd_restart_bgp, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Restart BGP"); + + c = cli_register_command(cli, NULL, "router", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG, NULL); + cli_register_command(cli, c, "bgp", cmd_router_bgp, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Configure BGP"); + + cli_register_command(cli, NULL, "exit", cmd_router_bgp_exit, PRIVILEGE_PRIVILEGED, MODE_CONFIG_BGP, "Exit from BGP configuration"); + cli_register_command(cli, NULL, "neighbour", cmd_router_bgp_neighbour, PRIVILEGE_PRIVILEGED, MODE_CONFIG_BGP, "Configure BGP neighbour"); + + c = cli_register_command(cli, NULL, "no", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG_BGP, NULL); + cli_register_command(cli, c, "neighbour", cmd_router_bgp_no_neighbour, PRIVILEGE_PRIVILEGED, MODE_CONFIG_BGP, "Remove BGP neighbour"); +#endif /* BGP */ c = cli_register_command(cli, NULL, "drop", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, NULL); cli_register_command(cli, c, "user", cmd_drop_user, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Disconnect a user"); cli_register_command(cli, c, "tunnel", cmd_drop_tunnel, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Disconnect a tunnel and all sessions on that tunnel"); cli_register_command(cli, c, "session", cmd_drop_session, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Disconnect a session"); - c = cli_register_command(cli, NULL, "restart", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, NULL); - cli_register_command(cli, c, "bgp", cmd_restart_bgp, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Restart BGP"); - c = cli_register_command(cli, NULL, "load", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG, NULL); cli_register_command(cli, c, "plugin", cmd_load_plugin, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Load a plugin"); @@ -326,7 +352,7 @@ int cli_arg_help(struct cli_def *cli, int cr_ok, char *entry, ...) return CLI_OK; } -int cmd_show_session(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_session(struct cli_def *cli, char *command, char **argv, int argc) { int i; @@ -463,7 +489,7 @@ int cmd_show_session(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_show_tunnels(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) { int i, x, show_all = 0; char *states[] = { @@ -552,7 +578,7 @@ int cmd_show_tunnels(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_show_users(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) { char sid[32][8]; char *sargv[32]; @@ -593,7 +619,7 @@ int cmd_show_users(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_show_counters(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_show_counters(struct cli_def *cli, char *command, char **argv, int argc) { if (CLI_HELP_REQUESTED) return CLI_HELP_NO_ARGS; @@ -674,7 +700,7 @@ int cmd_show_counters(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_show_version(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) { int tag = 0; int file = 0; @@ -746,7 +772,7 @@ int cmd_show_version(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_show_pool(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) { int i; int used = 0, free = 0, show_all = 0; @@ -808,7 +834,7 @@ void print_save_config(struct cli_def *cli, char *string) fprintf(save_config_fh, "%s\n", string); } -int cmd_write_memory(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) { if (CLI_HELP_REQUESTED) return CLI_HELP_NO_ARGS; @@ -828,7 +854,7 @@ int cmd_write_memory(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_show_run(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) { int i; @@ -871,11 +897,45 @@ int cmd_show_run(struct cli_def *cli, char *command, char **argv, int argc) } } +#ifdef BGP + if (config->as_number) + { + int k; + int h; + + cli_print(cli, "# BGP"); + cli_print(cli, "router bgp %u", config->as_number); + for (i = 0; i < BGP_NUM_PEERS; i++) + { + if (!config->neighbour[i].name[0]) + continue; + + cli_print(cli, " neighbour %s remote-as %u", config->neighbour[i].name, config->neighbour[i].as); + + k = config->neighbour[i].keepalive; + h = config->neighbour[i].hold; + + if (k == -1) + { + if (h == -1) + continue; + + k = BGP_KEEPALIVE_TIME; + } + + if (h == -1) + h = BGP_HOLD_TIME; + + cli_print(cli, " neighbour %s timers %d %d", config->neighbour[i].name, k, h); + } + } +#endif + cli_print(cli, "# end"); return CLI_OK; } -int cmd_show_radius(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) { int i, free = 0, used = 0, show_all = 0; char *states[] = { @@ -929,7 +989,7 @@ int cmd_show_radius(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_show_plugins(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) { int i; @@ -944,7 +1004,7 @@ int cmd_show_plugins(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_show_throttle(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) { int i; @@ -976,7 +1036,7 @@ int cmd_show_throttle(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_show_banana(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) { if (CLI_HELP_REQUESTED) return CLI_HELP_NO_ARGS; @@ -999,7 +1059,7 @@ int cmd_show_banana(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_clear_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) { if (CLI_HELP_REQUESTED) return CLI_HELP_NO_ARGS; @@ -1009,7 +1069,7 @@ int cmd_clear_counters(struct cli_def *cli, char *command, char **argv, int argc return CLI_OK; } -int cmd_drop_user(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) { int i; sessionidt s; @@ -1048,7 +1108,7 @@ int cmd_drop_user(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_drop_tunnel(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) { int i; tunnelidt t; @@ -1096,7 +1156,7 @@ int cmd_drop_tunnel(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_drop_session(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) { int i; sessionidt s; @@ -1139,7 +1199,7 @@ int cmd_drop_session(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_snoop(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_snoop(struct cli_def *cli, char *command, char **argv, int argc) { ipt ip; u16 port; @@ -1210,7 +1270,7 @@ int cmd_snoop(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_no_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) { int i; sessionidt s; @@ -1246,7 +1306,7 @@ int cmd_no_snoop(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_throttle(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_throttle(struct cli_def *cli, char *command, char **argv, int argc) { int rate_in = 0; int rate_out = 0; @@ -1373,7 +1433,7 @@ int cmd_throttle(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_no_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) { int i; sessionidt s; @@ -1416,7 +1476,7 @@ int cmd_no_throttle(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_debug(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_debug(struct cli_def *cli, char *command, char **argv, int argc) { int i; @@ -1480,7 +1540,7 @@ int cmd_debug(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_no_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) { int i; @@ -1526,7 +1586,7 @@ int cmd_no_debug(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_load_plugin(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) { int i, firstfree = 0; @@ -1561,7 +1621,7 @@ int cmd_load_plugin(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_remove_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) { int i; @@ -1622,7 +1682,7 @@ char *duration(time_t secs) return buf; } -int cmd_uptime(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_uptime(struct cli_def *cli, char *command, char **argv, int argc) { FILE *fh; char buf[100], *p = buf, *loads[3]; @@ -1658,7 +1718,7 @@ int cmd_uptime(struct cli_def *cli, char *command, char **argv, int argc) return CLI_OK; } -int cmd_set(struct cli_def *cli, char *command, char **argv, int argc) +static int cmd_set(struct cli_def *cli, char *command, char **argv, int argc) { int i; @@ -1792,6 +1852,387 @@ int regular_stuff(struct cli_def *cli) return CLI_OK; } +#ifdef BGP +static int cmd_router_bgp(struct cli_def *cli, char *command, char **argv, int argc) +{ + int as; + + if (CLI_HELP_REQUESTED) + return cli_arg_help(cli, argc > 1, + "<1-65535>", "Autonomous system number", NULL); + + if (argc != 1 || (as = atoi(argv[0])) < 1 || as > 65535) + { + cli_print(cli, "Invalid autonomous system number"); + return CLI_OK; + } + + if (bgp_configured && as != config->as_number) + { + cli_print(cli, "Can't change local AS on a running system"); + return CLI_OK; + } + + config->as_number = as; + cli_set_configmode(cli, MODE_CONFIG_BGP, "router"); + + return CLI_OK; +} + +static int cmd_router_bgp_exit(struct cli_def *cli, char *command, char **argv, int argc) +{ + if (CLI_HELP_REQUESTED) + return CLI_HELP_NO_ARGS; + + cli_set_configmode(cli, MODE_CONFIG, NULL); + return CLI_OK; +} + +static int find_bgp_neighbour(char *name) +{ + int i; + int new = -1; + struct hostent *h; + in_addr_t addrs[4] = { 0 }; + char **a; + + if (!(h = gethostbyname(name)) || h->h_addrtype != AF_INET) + return -2; + + for (i = 0; i < sizeof(addrs) / sizeof(*addrs) && h->h_addr_list[i]; i++) + memcpy(&addrs[i], h->h_addr_list[i], sizeof(*addrs)); + + for (i = 0; i < BGP_NUM_PEERS; i++) + { + if (!config->neighbour[i].name[0]) + { + if (new == -1) new = i; + continue; + } + + if (!strcmp(name, config->neighbour[i].name)) + return i; + + if (!(h = gethostbyname(config->neighbour[i].name)) || h->h_addrtype != AF_INET) + continue; + + for (a = h->h_addr_list; *a; a++) + { + int j; + for (j = 0; j < sizeof(addrs) / sizeof(*addrs) && addrs[j]; j++) + if (!memcmp(&addrs[j], *a, sizeof(*addrs))) + return i; + } + } + + return new; +} + +static int cmd_router_bgp_neighbour(struct cli_def *cli, char *command, char **argv, int argc) +{ + int i; + int keepalive; + int hold; + + if (CLI_HELP_REQUESTED) + { + switch (argc) + { + case 1: + return cli_arg_help(cli, 0, + "A.B.C.D", "BGP neighbour address", + "NAME", "BGP neighbour name", + NULL); + + case 2: + return cli_arg_help(cli, 0, + "remote-as", "Set remote autonomous system number", + "timers", "Set timers", + NULL); + + default: + if (!strncmp("remote-as", argv[1], strlen(argv[1]))) + return cli_arg_help(cli, argv[2][1], "<1-65535>", "Autonomous system number", NULL); + + if (!strncmp("timers", argv[1], strlen(argv[1]))) + { + if (argc == 3) + return cli_arg_help(cli, 0, "<1-65535>", "Keepalive time", NULL); + + if (argc == 4) + return cli_arg_help(cli, argv[3][1], "<3-65535>", "Hold time", NULL); + + if (argc == 5 && !argv[4][1]) + return cli_arg_help(cli, 1, NULL); + } + + return CLI_OK; + } + } + + if (argc < 3) + { + cli_print(cli, "Invalid arguments"); + return CLI_OK; + } + + if ((i = find_bgp_neighbour(argv[0])) == -2) + { + cli_print(cli, "Invalid neighbour"); + return CLI_OK; + } + + if (i == -1) + { + cli_print(cli, "Too many neighbours (max %d)", BGP_NUM_PEERS); + return CLI_OK; + } + + if (!strncmp("remote-as", argv[1], strlen(argv[1]))) + { + int as = atoi(argv[2]); + if (as < 0 || as > 65535) + { + cli_print(cli, "Invalid autonomous system number"); + return CLI_OK; + } + + if (!config->neighbour[i].name[0]) + { + snprintf(config->neighbour[i].name, sizeof(config->neighbour[i].name), argv[0]); + config->neighbour[i].keepalive = -1; + config->neighbour[i].hold = -1; + } + + config->neighbour[i].as = as; + return CLI_OK; + } + + if (argc != 4 || strncmp("timers", argv[1], strlen(argv[1]))) + { + cli_print(cli, "Invalid arguments"); + return CLI_OK; + } + + if (!config->neighbour[i].name[0]) + { + cli_print(cli, "Specify remote-as first"); + return CLI_OK; + } + + keepalive = atoi(argv[2]); + hold = atoi(argv[3]); + + if (keepalive < 1 || keepalive > 65535) + { + cli_print(cli, "Invalid keepalive time"); + return CLI_OK; + } + + if (hold < 3 || hold > 65535) + { + cli_print(cli, "Invalid hold time"); + return CLI_OK; + } + + if (keepalive == BGP_KEEPALIVE_TIME) + keepalive = -1; // using default value + + if (hold == BGP_HOLD_TIME) + hold = -1; + + config->neighbour[i].keepalive = keepalive; + config->neighbour[i].hold = hold; + + return CLI_OK; +} + +static int cmd_router_bgp_no_neighbour(struct cli_def *cli, char *command, char **argv, int argc) +{ + int i; + + if (CLI_HELP_REQUESTED) + return cli_arg_help(cli, argc > 0, + "A.B.C.D", "BGP neighbour address", + "NAME", "BGP neighbour name", + NULL); + + if (argc != 1) + { + cli_print(cli, "Specify a BGP neighbour"); + return CLI_OK; + } + + if ((i = find_bgp_neighbour(argv[0])) == -2) + { + cli_print(cli, "Invalid neighbour"); + return CLI_OK; + } + + if (i < 0 || !config->neighbour[i].name[0]) + { + cli_print(cli, "Neighbour %s not configured", argv[0]); + return CLI_OK; + } + + memset(&config->neighbour[i], 0, sizeof(config->neighbour[i])); + return CLI_OK; +} + +static int cmd_show_bgp(struct cli_def *cli, char *command, char **argv, int argc) +{ + int i; + int hdr = 0; + char *addr; + + if (!bgp_configured) + return CLI_OK; + + if (CLI_HELP_REQUESTED) + return cli_arg_help(cli, 1, + "A.B.C.D", "BGP neighbour address", + "NAME", "BGP neighbour name", + NULL); + + cli_print(cli, "BGPv%d router identifier %s, local AS number %d", + BGP_VERSION, inet_toa(my_address), (int) config->as_number); + + time(&time_now); + + for (i = 0; i < BGP_NUM_PEERS; i++) + { + if (!*bgp_peers[i].name) + continue; + + addr = inet_toa(bgp_peers[i].addr); + if (argc && strcmp(addr, argv[0]) && + strncmp(bgp_peers[i].name, argv[0], strlen(argv[0]))) + continue; + + if (!hdr++) + { + cli_print(cli, ""); + cli_print(cli, "Peer AS Address " + "State Retries Retry in Route Pend Timers"); + cli_print(cli, "------------------ ----- --------------- " + "----------- ------- -------- ----- ---- ---------"); + } + + cli_print(cli, "%-18.18s %5d %15s %-11s %7d %7ds %5s %4s %4d %4d", + bgp_peers[i].name, + bgp_peers[i].as, + addr, + bgp_state_str(bgp_peers[i].state), + bgp_peers[i].retry_count, + bgp_peers[i].retry_time ? bgp_peers[i].retry_time - time_now : 0, + bgp_peers[i].routing ? "yes" : "no", + bgp_peers[i].update_routes ? "yes" : "no", + bgp_peers[i].keepalive, + bgp_peers[i].hold); + } + + return CLI_OK; +} + +static int cmd_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc) +{ + int i; + char *addr; + + if (!bgp_configured) + return CLI_OK; + + if (CLI_HELP_REQUESTED) + return cli_arg_help(cli, 1, + "A.B.C.D", "BGP neighbour address", + "NAME", "BGP neighbour name", + NULL); + + for (i = 0; i < BGP_NUM_PEERS; i++) + { + if (bgp_peers[i].state != Established) + continue; + + if (!bgp_peers[i].routing) + continue; + + addr = inet_toa(bgp_peers[i].addr); + if (argc && strcmp(addr, argv[0]) && strcmp(bgp_peers[i].name, argv[0])) + continue; + + bgp_peers[i].cli_flag = BGP_CLI_SUSPEND; + cli_print(cli, "Suspending peer %s", bgp_peers[i].name); + } + + return CLI_OK; +} + +static int cmd_no_suspend_bgp(struct cli_def *cli, char *command, char **argv, int argc) +{ + int i; + char *addr; + + if (!bgp_configured) + return CLI_OK; + + if (CLI_HELP_REQUESTED) + return cli_arg_help(cli, 1, + "A.B.C.D", "BGP neighbour address", + "NAME", "BGP neighbour name", + NULL); + + for (i = 0; i < BGP_NUM_PEERS; i++) + { + if (bgp_peers[i].state != Established) + continue; + + if (bgp_peers[i].routing) + continue; + + addr = inet_toa(bgp_peers[i].addr); + if (argc && strcmp(addr, argv[0]) && + strncmp(bgp_peers[i].name, argv[0], strlen(argv[0]))) + continue; + + bgp_peers[i].cli_flag = BGP_CLI_ENABLE; + cli_print(cli, "Un-suspending peer %s", bgp_peers[i].name); + } + + return CLI_OK; +} + +static int cmd_restart_bgp(struct cli_def *cli, char *command, char **argv, int argc) +{ + int i; + char *addr; + + if (!bgp_configured) + return CLI_OK; + + if (CLI_HELP_REQUESTED) + return cli_arg_help(cli, 1, + "A.B.C.D", "BGP neighbour address", + "NAME", "BGP neighbour name", + NULL); + + for (i = 0; i < BGP_NUM_PEERS; i++) + { + if (!*bgp_peers[i].name) + continue; + + addr = inet_toa(bgp_peers[i].addr); + if (argc && strcmp(addr, argv[0]) && + strncmp(bgp_peers[i].name, argv[0], strlen(argv[0]))) + continue; + + bgp_peers[i].cli_flag = BGP_CLI_RESTART; + cli_print(cli, "Restarting peer %s", bgp_peers[i].name); + } + + return CLI_OK; +} +#endif /* BGP*/ + // Convert a string in the form of abcd.ef12.3456 into char[6] void parsemac(char *string, char mac[6]) { diff --git a/cluster.h b/cluster.h index 5c5f117..15301d3 100644 --- a/cluster.h +++ b/cluster.h @@ -1,5 +1,5 @@ // L2TPNS Clustering Stuff -// $Id: cluster.h,v 1.5 2004/07/08 16:54:35 bodea Exp $ +// $Id: cluster.h,v 1.6 2004/11/11 03:07:42 bodea Exp $ #ifndef __CLUSTER_H__ #define __CLUSTER_H__ @@ -79,6 +79,6 @@ void cluster_send_ping(time_t basetime); void cluster_heartbeat(void); void cluster_check_master(void); void cluster_check_slaves(void); -int show_cluster(struct cli_def *cli, char *command, char **argv, int argc); +int cmd_show_cluster(struct cli_def *cli, char *command, char **argv, int argc); #endif /* __CLUSTER_H__ */ diff --git a/l2tpns.c b/l2tpns.c index 5171caf..93f5285 100644 --- a/l2tpns.c +++ b/l2tpns.c @@ -4,7 +4,7 @@ // Copyright (c) 2002 FireBrick (Andrews & Arnold Ltd / Watchfront Ltd) - GPL licenced // vim: sw=8 ts=8 -char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.47 2004/11/09 08:05:02 bodea Exp $"; +char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.48 2004/11/11 03:07:42 bodea Exp $"; #include #include @@ -49,6 +49,10 @@ char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.47 2004/11/09 08:05:02 bodea Exp #include "util.h" #include "tbf.h" +#ifdef BGP +#include "bgp.h" +#endif /* BGP */ + // Globals struct configt *config = NULL; // all configuration int tunfd = -1; // tun interface file handle. (network device) @@ -82,13 +86,6 @@ char *_program_name = NULL; linked_list *loaded_plugins; linked_list *plugins[MAX_PLUGIN_TYPES]; -#ifdef BGP -#include "bgp.h" -struct bgp_peer *bgp_peers = 0; -struct bgp_route_list *bgp_routes = 0; -int bgp_configured = 0; -#endif /* BGP */ - #define membersize(STRUCT, MEMBER) sizeof(((STRUCT *)0)->MEMBER) #define CONFIG(NAME, MEMBER, TYPE) { NAME, offsetof(struct configt, MEMBER), membersize(struct configt, MEMBER), TYPE } @@ -123,13 +120,6 @@ struct config_descriptt config_values[] = { CONFIG("cluster_interface", cluster_interface, STRING), CONFIG("cluster_hb_interval", cluster_hb_interval, INT), CONFIG("cluster_hb_timeout", cluster_hb_timeout, INT), -#ifdef BGP - CONFIG("as_number", as_number, SHORT), - CONFIG("bgp_peer1", bgp_peer[0], STRING), - CONFIG("bgp_peer1_as", bgp_peer_as[0], SHORT), - CONFIG("bgp_peer2", bgp_peer[1], STRING), - CONFIG("bgp_peer2_as", bgp_peer_as[1], SHORT), -#endif /* BGP */ { NULL, 0, 0, 0 }, }; @@ -2585,22 +2575,14 @@ void initdata(int optdebug, char *optconfig) _statistics->start_time = _statistics->last_reset = time(NULL); #ifdef BGP - if (!(bgp_peers = shared_malloc(sizeof(struct bgp_peer) * BGP_NUM_PEERS))) - { - LOG(0, 0, 0, 0, "Error doing malloc for bgp: %s\n", strerror(errno)); - exit(1); - } + if (!(bgp_peers = shared_malloc(sizeof(struct bgp_peer) * BGP_NUM_PEERS))) + { + LOG(0, 0, 0, 0, "Error doing malloc for bgp: %s\n", strerror(errno)); + exit(1); + } #endif /* BGP */ } -void initiptables(void) -{ - /* Flush the tables here so that we have a clean slate */ - -// Not needed. 'nat' is setup by garden.c -// mangle isn't used (as throttling is done by tbf inhouse). -} - int assign_ip_address(sessionidt s) { u32 i; @@ -2935,7 +2917,7 @@ void dump_acct_info() // Main program int main(int argc, char *argv[]) { - int o; + int i; int optdebug = 0; char *optconfig = CONFIGFILE; @@ -2944,9 +2926,9 @@ int main(int argc, char *argv[]) time(&basetime); // start clock // scan args - while ((o = getopt(argc, argv, "dvc:h:")) >= 0) + while ((i = getopt(argc, argv, "dvc:h:")) >= 0) { - switch (o) + switch (i) { case 'd': if (fork()) exit(0); @@ -2983,7 +2965,6 @@ int main(int argc, char *argv[]) signal(SIGALRM, sigalrm_handler); siginterrupt(SIGALRM, 0); - initiptables(); initplugins(); initdata(optdebug, optconfig); @@ -3038,13 +3019,13 @@ int main(int argc, char *argv[]) signal(SIGPIPE, SIG_IGN); bgp_setup(config->as_number); bgp_add_route(config->bind_address, 0xffffffff); - if (*config->bgp_peer[0]) - bgp_start(&bgp_peers[0], config->bgp_peer[0], - config->bgp_peer_as[0], 0); /* 0 = routing disabled */ - - if (*config->bgp_peer[1]) - bgp_start(&bgp_peers[1], config->bgp_peer[1], - config->bgp_peer_as[1], 0); + for (i = 0; i < BGP_NUM_PEERS; i++) + { + if (config->neighbour[i].name[0]) + bgp_start(&bgp_peers[i], config->neighbour[i].name, + config->neighbour[i].as, config->neighbour[i].keepalive, + config->neighbour[i].hold, 0); /* 0 = routing disabled */ + } #endif /* BGP */ inittun(); @@ -3082,12 +3063,9 @@ int main(int argc, char *argv[]) #ifdef BGP /* try to shut BGP down cleanly; with luck the sockets will be writable since we're out of the select */ - { - int i; - for (i = 0; i < BGP_NUM_PEERS; i++) - if (bgp_peers[i].state == Established) - bgp_stop(&bgp_peers[i]); - } + for (i = 0; i < BGP_NUM_PEERS; i++) + if (bgp_peers[i].state == Established) + bgp_stop(&bgp_peers[i]); #endif /* BGP */ /* remove plugins (so cleanup code gets run) */ @@ -3944,27 +3922,6 @@ void processcontrol(u8 * buf, int len, struct sockaddr_in *addr) free(resp); } -/* - * HACK - * Go through all of the tunnels and do some cleanups - */ -void tunnel_clean() -{ - int i; - - LOG(1, 0, 0, 0, "Cleaning tunnels array\n"); - - for (i = 1; i < MAXTUNNEL; i++) - { - if (!tunnel[i].ip - || !*tunnel[i].hostname - || (tunnel[i].state == TUNNELDIE && tunnel[i].die >= time_now)) - { - tunnelclear(i); - } - } -} - void tunnelclear(tunnelidt t) { if (!t) return; diff --git a/l2tpns.h b/l2tpns.h index ddc0884..887f981 100644 --- a/l2tpns.h +++ b/l2tpns.h @@ -1,5 +1,5 @@ // L2TPNS Global Stuff -// $Id: l2tpns.h,v 1.32 2004/11/10 03:30:29 bodea Exp $ +// $Id: l2tpns.h,v 1.33 2004/11/11 03:07:43 bodea Exp $ #ifndef __L2TPNS_H__ #define __L2TPNS_H__ @@ -15,7 +15,7 @@ #include #include -#define VERSION "2.0.5" +#define VERSION "2.0.6" // Limits #define MAXTUNNEL 500 // could be up to 65535 @@ -460,9 +460,14 @@ struct configt int cluster_hb_timeout; // How many missed heartbeats trigger an election. #ifdef BGP +#define BGP_NUM_PEERS 2 u16 as_number; - char bgp_peer[2][64]; - u16 bgp_peer_as[2]; + struct { + char name[64]; + u16 as; + int keepalive; + int hold; + } neighbour[BGP_NUM_PEERS]; #endif }; diff --git a/l2tpns.spec b/l2tpns.spec index 505d2f4..7552710 100644 --- a/l2tpns.spec +++ b/l2tpns.spec @@ -1,6 +1,6 @@ Summary: A high-speed clustered L2TP LNS Name: l2tpns -Version: 2.0.5 +Version: 2.0.6 Release: 1 Copyright: GPL Group: System Environment/Daemons @@ -41,8 +41,11 @@ rm -rf %{buildroot} %attr(755,root,root) /usr/lib/l2tpns %changelog +* Thu Nov 11 2004 Brendan O'Dea 2.0.6 +- 2.0.6 release, see /usr/share/doc/l2tpns-2.0.6/Changes + * Tue Nov 9 2004 Brendan O'Dea 2.0.5 -- 2.0.5 release, see /usr/share/doc/l2tpns-2.0.5/Changes +- 2.0.5 release * Mon Nov 8 2004 Brendan O'Dea 2.0.4 - 2.0.4 release