diff options
Diffstat (limited to 'bgpd')
-rw-r--r-- | bgpd/bgp_connection.c | 2 | ||||
-rw-r--r-- | bgpd/bgp_dump.c | 24 | ||||
-rw-r--r-- | bgpd/bgp_engine.h | 40 | ||||
-rw-r--r-- | bgpd/bgp_main.c | 62 | ||||
-rw-r--r-- | bgpd/bgp_session.c | 4 | ||||
-rw-r--r-- | bgpd/bgp_session.h | 4 | ||||
-rw-r--r-- | bgpd/bgp_vty.c | 160 |
7 files changed, 170 insertions, 126 deletions
diff --git a/bgpd/bgp_connection.c b/bgpd/bgp_connection.c index 151d3309..560bac4d 100644 --- a/bgpd/bgp_connection.c +++ b/bgpd/bgp_connection.c @@ -155,7 +155,7 @@ bgp_connection_init_new(bgp_connection connection, bgp_session session, /* Link back to session, point at its mutex and point session here */ connection->session = session ; - connection->p_mutex = &session->mutex ; + connection->p_mutex = session->mutex ; connection->lock_count = 0 ; /* no question about it */ connection->paf = AF_UNSPEC ; diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index 3bc318a5..112cfd34 100644 --- a/bgpd/bgp_dump.c +++ b/bgpd/bgp_dump.c @@ -21,6 +21,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include <zebra.h> #include "log.h" +#include "vty.h" #include "stream.h" #include "sockunion.h" #include "command.h" @@ -28,6 +29,8 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "thread.h" #include "linklist.h" #include "bgpd/bgp_table.h" +#include "qpath.h" +#include "qstring.h" #include "bgpd/bgpd.h" #include "bgpd/bgp_route.h" @@ -97,8 +100,8 @@ bgp_dump_open_file (struct bgp_dump *bgp_dump) int ret; time_t clock; struct tm tm; - char fullpath[MAXPATHLEN]; - char realpath[MAXPATHLEN]; + qpath path ; + qstring name ; mode_t oldumask; time (&clock); @@ -106,11 +109,17 @@ bgp_dump_open_file (struct bgp_dump *bgp_dump) if (bgp_dump->filename[0] != DIRECTORY_SEP) { - sprintf (fullpath, "%s/%s", vty_get_cwd (), bgp_dump->filename); - ret = strftime (realpath, MAXPATHLEN, fullpath, &tm); + path = vty_getcwd(NULL) ; + qpath_append_str(path, bgp_dump->filename) ; } else - ret = strftime (realpath, MAXPATHLEN, bgp_dump->filename, &tm); + path = qpath_set(NULL, bgp_dump->filename) ; + + name = qs_new_size(NULL, qpath_len(path) + 60) ; + + ret = strftime (qs_char_nn(name), qs_len_nn(name), qpath_string(path), &tm); + + qpath_free(path) ; if (ret == 0) { @@ -123,11 +132,12 @@ bgp_dump_open_file (struct bgp_dump *bgp_dump) oldumask = umask(0777 & ~LOGFILE_MASK); - bgp_dump->fp = fopen (realpath, "w"); + bgp_dump->fp = fopen (qs_char_nn(name), "w"); if (bgp_dump->fp == NULL) { - zlog_warn("bgp_dump_open_file: %s: %s", realpath, errtoa(errno, 0).str); + zlog_warn("bgp_dump_open_file: %s: %s", qs_char_nn(name), + errtoa(errno, 0).str); umask(oldumask); return NULL; } diff --git a/bgpd/bgp_engine.h b/bgpd/bgp_engine.h index bedfc18e..821d8127 100644 --- a/bgpd/bgp_engine.h +++ b/bgpd/bgp_engine.h @@ -31,19 +31,31 @@ #include "lib/log.h" /*============================================================================== - * DEBUG setting + * BGP_ENGINE_DEBUG setting + * + * Set to 1 if defined, but blank. + * Set to QDEBUG if not defined. + * + * Force to 0 if BGP_ENGINE_NO_DEBUG is defined and not zero. + * + * So: defaults to same as QDEBUG, but no matter what QDEBUG is set to: + * + * * can set BGP_ENGINE_DEBUG == 0 to turn off debug + * * or set BGP_ENGINE_DEBUG != 0 to turn on debug + * * or set BGP_ENGINE_NO_DEBUG != to force debug off */ - -#ifdef BGP_ENGINE_DEBUG /* Can be forced from outside */ -# if BGP_ENGINE_DEBUG -# define BGP_ENGINE_DEBUG 1 /* Force 1 or 0 */ -#else -# define BGP_ENGINE_DEBUG 0 +#ifdef BGP_ENGINE_DEBUG /* If defined, make it 1 or 0 */ +# if IS_BLANK_OPTION(BGP_ENGINE_DEBUG) +# undef BGP_ENGINE_DEBUG +# define BGP_ENGINE_DEBUG 1 # endif -#else -# ifdef QDEBUG -# define BGP_ENGINE_DEBUG 1 /* Follow QDEBUG */ -#else +#else /* If not defined, follow QDEBUG */ +# define BGP_ENGINE_DEBUG QDEBUG +#endif + +#ifdef BGP_ENGINE_NO_DEBUG /* Override, if defined */ +# if IS_NOT_ZERO_OPTION(BGP_ENGINE_NO_DEBUG) +# undef BGP_ENGINE_DEBUG # define BGP_ENGINE_DEBUG 0 # endif #endif @@ -80,7 +92,7 @@ bgp_queue_logging(const char* name, mqueue_queue mq, struct queue_stats* stats) ++stats->count ; - qpt_mutex_lock(&mq->mutex) ; + qpt_mutex_lock(mq->mutex) ; if (mq->count > stats->max) stats->max = mq->count ; @@ -91,7 +103,7 @@ bgp_queue_logging(const char* name, mqueue_queue mq, struct queue_stats* stats) if (stats->count < 1000) { - qpt_mutex_unlock(&mq->mutex) ; + qpt_mutex_unlock(mq->mutex) ; return ; } ; @@ -106,7 +118,7 @@ bgp_queue_logging(const char* name, mqueue_queue mq, struct queue_stats* stats) assert(my_count == mq->count) ; - qpt_mutex_unlock(&mq->mutex) ; + qpt_mutex_unlock(mq->mutex) ; average = stats->total * 1000 ; average = (average / stats->count) + 5 ; diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index 6bbc8197..82db783a 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -18,15 +18,15 @@ along with GNU Zebra; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <zebra.h> -#include <stdbool.h> +#include "zebra.h" +#include "misc.h" #include "vector.h" #include "vty.h" #include "command.h" #include "getopt.h" #include "thread.h" -#include <lib/version.h> +#include "lib/version.h" #include "memory.h" #include "prefix.h" #include "log.h" @@ -118,13 +118,13 @@ static zebra_capabilities_t _caps_p [] = struct zebra_privs_t bgpd_privs = { #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP) - .user = QUAGGA_USER, - .group = QUAGGA_GROUP, + .user = QUAGGA_USER, + .group = QUAGGA_GROUP, #endif #ifdef VTY_GROUP .vty_group = VTY_GROUP, #endif - .caps_p = _caps_p, + .caps_p = _caps_p, .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]), .cap_num_i = 0, }; @@ -184,7 +184,7 @@ void sigusr2 (void); /* prototypes */ static void bgp_exit (int); -static void init_second_stage(int pthreads); +static void init_second_stage(bool pthreads); static void bgp_in_thread_init(void); static void routing_start(void) ; static void routing_finish(void) ; @@ -206,10 +206,6 @@ static struct quagga_signal_t bgp_signals[] = .handler = &sigusr1, }, { - .signal = SIGUSR2, - .handler = &sigusr2, - }, - { .signal = SIGINT, .handler = &sigint, }, @@ -261,17 +257,6 @@ sigusr1 (void) zlog_rotate (NULL); } -/* SIGUSR2 handler. */ -void -sigusr2 (void) -{ - /* Used to signal message queues */ - if (qpthreads_enabled) - return; - else - exit(1); -} - /*------------------------------------------------------------------------------ * Final exit code... * @@ -392,8 +377,8 @@ bgp_exit (int status) * * 1. if it's there, invoke the command in the usual way * - * 2. if it's not there, invoke the command but with a NULL set of arguments, - * which signals the "default" nature of the call. + * 2. if it's not there, invoke the command but with a *negative* count of + * arguments, which signals the "default" nature of the call. * * This mechanism is used so that the "threaded_cmd" is the time at which * second stage initialisation is done. (But only once -- not on rereading @@ -408,8 +393,8 @@ DEFUN_HID_CALL (threaded, "threaded", "Use pthreads\n") { - if (argv != NULL) - config_threaded = 1 ; /* Explicit command => turn on threading */ + if (argc == 0) + config_threaded = true ; /* Explicit command => turn on threading */ if (!done_2nd_stage_init) init_second_stage(config_threaded) ; @@ -425,7 +410,7 @@ DEFUN_HID_CALL (threaded, * the message queues are available for the configuration data. */ static void -init_second_stage(int pthreads) +init_second_stage(bool pthreads) { assert(!done_2nd_stage_init) ; @@ -435,13 +420,13 @@ init_second_stage(int pthreads) bgp_peer_index_mutex_init(); /* Make nexus for main thread, always needed */ - cli_nexus = qpn_init_new(cli_nexus, 1); /* main thread */ + cli_nexus = qpn_init_new(cli_nexus, true); /* main thread */ /* if using pthreads create additional nexus */ if (qpthreads_enabled) { - bgp_nexus = qpn_init_new(bgp_nexus, 0); - routing_nexus = qpn_init_new(routing_nexus, 0); + bgp_nexus = qpn_init_new(bgp_nexus, false); + routing_nexus = qpn_init_new(routing_nexus, false); } else { @@ -499,9 +484,8 @@ main (int argc, char **argv) /* Set umask before anything for security */ umask (0027); -#ifdef QDEBUG - fprintf(stderr, "%s\n", debug_banner); -#endif + if (qdebug) + fprintf(stderr, "%s\n", debug_banner); qlib_init_first_stage(); @@ -603,7 +587,11 @@ main (int argc, char **argv) /* Initializations. */ srand (time (NULL)); signal_init (master, Q_SIGC(bgp_signals), bgp_signals); - zprivs_init (&bgpd_privs); + + cmd_getcwd() ; /* while have privilege */ + + zprivs_init (&bgpd_privs); /* lowers privileges */ + cmd_init (1); install_element (CONFIG_NODE, &threaded_cmd); vty_init (master); @@ -652,9 +640,9 @@ main (int argc, char **argv) vty_start(vty_addr, vty_port, BGP_VTYSH_PATH); /* Print banner. */ -#ifdef QDEBUG - zlog_notice("%s", debug_banner); -#endif + if (qdebug) + zlog_notice("%s", debug_banner); + zlog_notice ("BGPd %s%s starting: vty@%d, bgp@%s:%d", QUAGGA_VERSION, (qpthreads_enabled ? " pthreaded" : ""), diff --git a/bgpd/bgp_session.c b/bgpd/bgp_session.c index 681075da..0c021b0f 100644 --- a/bgpd/bgp_session.c +++ b/bgpd/bgp_session.c @@ -124,7 +124,7 @@ bgp_session_init_new(bgp_peer peer) session = XCALLOC(MTYPE_BGP_SESSION, sizeof(struct bgp_session)) ; - qpt_mutex_init_new(&session->mutex, qpt_mutex_recursive) ; + qpt_mutex_init_new(session->mutex, qpt_mutex_recursive) ; session->peer = peer ; bgp_peer_lock(peer) ; /* Account for the session->peer pointer */ @@ -240,7 +240,7 @@ bgp_session_delete(bgp_peer peer) BGP_SESSION_UNLOCK(session) ; /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ - qpt_mutex_destroy(&session->mutex, 0) ; + qpt_mutex_destroy(session->mutex, 0) ; /* Proceed to dismantle the session. */ diff --git a/bgpd/bgp_session.h b/bgpd/bgp_session.h index e1a4c51b..cc8acc19 100644 --- a/bgpd/bgp_session.h +++ b/bgpd/bgp_session.h @@ -304,12 +304,12 @@ MQB_ARGS_SIZE_OK(bgp_session_ttl_args) ; inline static void BGP_SESSION_LOCK(bgp_session session) { - qpt_mutex_lock(&session->mutex) ; + qpt_mutex_lock(session->mutex) ; } ; inline static void BGP_SESSION_UNLOCK(bgp_session session) { - qpt_mutex_unlock(&session->mutex) ; + qpt_mutex_unlock(session->mutex) ; } ; /*============================================================================== diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 9195b9f3..dc72f6e7 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -314,12 +314,13 @@ DEFUN_DEPRECATED (neighbor_version, } /* "router bgp" commands. */ -DEFUN (router_bgp, - router_bgp_cmd, - "router bgp " CMD_AS_RANGE, - ROUTER_STR - BGP_STR - AS_STR) +DEFUN_ATTR (router_bgp, + router_bgp_cmd, + "router bgp " CMD_AS_RANGE, + ROUTER_STR + BGP_STR + AS_STR, + CMD_ATTR_NODE + BGP_NODE) { int ret; as_t as; @@ -338,9 +339,11 @@ DEFUN (router_bgp, vty_out (vty, "Please specify 'bgp multiple-instance' first%s", VTY_NEWLINE); return CMD_WARNING; + case BGP_ERR_AS_MISMATCH: vty_out (vty, "BGP is already running; AS is %u%s", as, VTY_NEWLINE); return CMD_WARNING; + case BGP_ERR_INSTANCE_MISMATCH: vty_out (vty, "BGP view name and AS number mismatch%s", VTY_NEWLINE); vty_out (vty, "BGP instance is already running; AS is %u%s", @@ -354,14 +357,15 @@ DEFUN (router_bgp, return CMD_SUCCESS; } -ALIAS (router_bgp, - router_bgp_view_cmd, - "router bgp " CMD_AS_RANGE " view WORD", - ROUTER_STR - BGP_STR - AS_STR - "BGP view\n" - "view name\n") +ALIAS_ATTR (router_bgp, + router_bgp_view_cmd, + "router bgp " CMD_AS_RANGE " view WORD", + ROUTER_STR + BGP_STR + AS_STR + "BGP view\n" + "view name\n", + CMD_ATTR_NODE + BGP_NODE) /* "no router bgp" commands. */ DEFUN (no_router_bgp, @@ -4008,90 +4012,118 @@ DEFUN (no_neighbor_allowas_in, } /* Address family configuration. */ -DEFUN (address_family_ipv4, - address_family_ipv4_cmd, - "address-family ipv4", - "Enter Address Family command mode\n" - "Address family\n") +DEFUN_ATTR (address_family_ipv4, + address_family_ipv4_cmd, + "address-family ipv4", + "Enter Address Family command mode\n" + "Address family\n", + CMD_ATTR_NODE + BGP_IPV4_NODE) { vty->node = BGP_IPV4_NODE ; return CMD_SUCCESS; } -DEFUN (address_family_ipv4_safi, - address_family_ipv4_safi_cmd, - "address-family ipv4 (unicast|multicast)", - "Enter Address Family command mode\n" - "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n") +DEFUN_ATTR (address_family_ipv4_safi_unicast, + address_family_ipv4_safi_unicast_cmd, + "address-family ipv4 unicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family modifier\n", + CMD_ATTR_NODE + BGP_IPV4_NODE) { - if (strncmp (argv[0], "m", 1) == 0) - vty->node = BGP_IPV4M_NODE ; - else - vty->node = BGP_IPV4_NODE ; + vty->node = BGP_IPV4_NODE ; + return CMD_SUCCESS; +} +DEFUN_ATTR (address_family_ipv4_safi_multicast, + address_family_ipv4_safi_multicast_cmd, + "address-family ipv4 multicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family modifier\n", + CMD_ATTR_NODE + BGP_IPV4M_NODE) +{ + vty->node = BGP_IPV4M_NODE ; return CMD_SUCCESS; } -DEFUN (address_family_ipv6, - address_family_ipv6_cmd, - "address-family ipv6", - "Enter Address Family command mode\n" - "Address family\n") +DEFUN_ATTR (address_family_ipv6, + address_family_ipv6_cmd, + "address-family ipv6", + "Enter Address Family command mode\n" + "Address family\n", + CMD_ATTR_NODE + BGP_IPV6_NODE) { vty->node = BGP_IPV6_NODE ; return CMD_SUCCESS; } -DEFUN (address_family_ipv6_safi, - address_family_ipv6_safi_cmd, - "address-family ipv6 (unicast|multicast)", - "Enter Address Family command mode\n" - "Address family\n" - "Address Family modifier\n" - "Address Family modifier\n") +DEFUN_ATTR (address_family_ipv6_safi_unicast, + address_family_ipv6_safi_unicast_cmd, + "address-family ipv6 unicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family modifier\n", + CMD_ATTR_NODE + BGP_IPV6_NODE) { - if (strncmp (argv[0], "m", 1) == 0) - vty->node = BGP_IPV6M_NODE ; - else - vty->node = BGP_IPV6_NODE ; + vty->node = BGP_IPV6_NODE ; + return CMD_SUCCESS; +} +DEFUN_ATTR (address_family_ipv6_safi_multicast, + address_family_ipv6_safi_multicast_cmd, + "address-family ipv6 multicast", + "Enter Address Family command mode\n" + "Address family\n" + "Address Family modifier\n", + CMD_ATTR_NODE + BGP_IPV6M_NODE) +{ + vty->node = BGP_IPV6M_NODE ; return CMD_SUCCESS; } -DEFUN (address_family_vpnv4, - address_family_vpnv4_cmd, - "address-family vpnv4", - "Enter Address Family command mode\n" - "Address family\n") +DEFUN_ATTR (address_family_vpnv4, + address_family_vpnv4_cmd, + "address-family vpnv4", + "Enter Address Family command mode\n" + "Address family\n", + CMD_ATTR_NODE + BGP_VPNV4_NODE) { vty->node = BGP_VPNV4_NODE ; return CMD_SUCCESS; } -ALIAS (address_family_vpnv4, +ALIAS_ATTR (address_family_vpnv4, address_family_vpnv4_unicast_cmd, "address-family vpnv4 unicast", "Enter Address Family command mode\n" "Address family\n" - "Address Family Modifier\n") + "Address Family Modifier\n", + CMD_ATTR_NODE + BGP_VPNV4_NODE) -DEFUN (exit_address_family, - exit_address_family_cmd, - "exit-address-family", - "Exit from Address Family configuration mode\n") +DEFUN_ATTR (exit_address_family, + exit_address_family_cmd, + "exit-address-family", + "Exit from Address Family configuration mode\n", + CMD_ATTR_NODE + BGP_NODE) { node_type_t node = vty->node ; - if (node == BGP_IPV4_NODE + if ( node == BGP_IPV4_NODE || node == BGP_IPV4M_NODE || node == BGP_VPNV4_NODE || node == BGP_IPV6_NODE || node == BGP_IPV6M_NODE) - vty->node = BGP_NODE ; - return CMD_SUCCESS; -} + { + vty->node = BGP_NODE ; + return CMD_SUCCESS ; + } + else + { + vty_out(vty, "%% No address family to leave\n") ; + return CMD_WARNING ; + } ; +} ; /* BGP clear sort. */ enum clear_sort @@ -9626,10 +9658,12 @@ bgp_vty_init (void) /* address-family commands. */ install_element (BGP_NODE, &address_family_ipv4_cmd); - install_element (BGP_NODE, &address_family_ipv4_safi_cmd); + install_element (BGP_NODE, &address_family_ipv4_safi_unicast_cmd); + install_element (BGP_NODE, &address_family_ipv4_safi_multicast_cmd); #ifdef HAVE_IPV6 install_element (BGP_NODE, &address_family_ipv6_cmd); - install_element (BGP_NODE, &address_family_ipv6_safi_cmd); + install_element (BGP_NODE, &address_family_ipv6_safi_unicast_cmd); + install_element (BGP_NODE, &address_family_ipv6_safi_multicast_cmd); #endif /* HAVE_IPV6 */ install_element (BGP_NODE, &address_family_vpnv4_cmd); install_element (BGP_NODE, &address_family_vpnv4_unicast_cmd); |