version 1.1, 2012/02/21 17:26:12
|
version 1.1.1.4, 2016/11/02 10:09:10
|
Line 35 Software Foundation, Inc., 59 Temple Place - Suite 330
|
Line 35 Software Foundation, Inc., 59 Temple Place - Suite 330
|
#include "routemap.h" |
#include "routemap.h" |
#include "filter.h" |
#include "filter.h" |
#include "plist.h" |
#include "plist.h" |
|
#include "stream.h" |
|
#include "vrf.h" |
|
#include "workqueue.h" |
|
|
#include "bgpd/bgpd.h" |
#include "bgpd/bgpd.h" |
#include "bgpd/bgp_attr.h" |
#include "bgpd/bgp_attr.h" |
Line 47 Software Foundation, Inc., 59 Temple Place - Suite 330
|
Line 50 Software Foundation, Inc., 59 Temple Place - Suite 330
|
#include "bgpd/bgp_clist.h" |
#include "bgpd/bgp_clist.h" |
#include "bgpd/bgp_debug.h" |
#include "bgpd/bgp_debug.h" |
#include "bgpd/bgp_filter.h" |
#include "bgpd/bgp_filter.h" |
|
#include "bgpd/bgp_zebra.h" |
|
|
/* bgpd options, we use GNU getopt library. */ |
/* bgpd options, we use GNU getopt library. */ |
static const struct option longopts[] = |
static const struct option longopts[] = |
Line 54 static const struct option longopts[] =
|
Line 58 static const struct option longopts[] =
|
{ "daemon", no_argument, NULL, 'd'}, |
{ "daemon", no_argument, NULL, 'd'}, |
{ "config_file", required_argument, NULL, 'f'}, |
{ "config_file", required_argument, NULL, 'f'}, |
{ "pid_file", required_argument, NULL, 'i'}, |
{ "pid_file", required_argument, NULL, 'i'}, |
|
{ "socket", required_argument, NULL, 'z'}, |
{ "bgp_port", required_argument, NULL, 'p'}, |
{ "bgp_port", required_argument, NULL, 'p'}, |
{ "listenon", required_argument, NULL, 'l'}, |
{ "listenon", required_argument, NULL, 'l'}, |
{ "vty_addr", required_argument, NULL, 'A'}, |
{ "vty_addr", required_argument, NULL, 'A'}, |
Line 101 char config_default[] = SYSCONFDIR BGP_DEFAULT_CONFIG;
|
Line 106 char config_default[] = SYSCONFDIR BGP_DEFAULT_CONFIG;
|
/* Route retain mode flag. */ |
/* Route retain mode flag. */ |
static int retain_mode = 0; |
static int retain_mode = 0; |
|
|
/* Master of threads. */ |
|
struct thread_master *master; |
|
|
|
/* Manually specified configuration file name. */ |
/* Manually specified configuration file name. */ |
char *config_file = NULL; |
char *config_file = NULL; |
|
|
Line 119 static zebra_capabilities_t _caps_p [] =
|
Line 121 static zebra_capabilities_t _caps_p [] =
|
{ |
{ |
ZCAP_BIND, |
ZCAP_BIND, |
ZCAP_NET_RAW, |
ZCAP_NET_RAW, |
|
ZCAP_NET_ADMIN, |
}; |
}; |
|
|
struct zebra_privs_t bgpd_privs = |
struct zebra_privs_t bgpd_privs = |
Line 131 struct zebra_privs_t bgpd_privs =
|
Line 134 struct zebra_privs_t bgpd_privs =
|
.vty_group = VTY_GROUP, |
.vty_group = VTY_GROUP, |
#endif |
#endif |
.caps_p = _caps_p, |
.caps_p = _caps_p, |
.cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]), | .cap_num_p = array_size(_caps_p), |
.cap_num_i = 0, |
.cap_num_i = 0, |
}; |
}; |
|
|
Line 149 redistribution between different routing protocols.\n\
|
Line 152 redistribution between different routing protocols.\n\
|
-d, --daemon Runs in daemon mode\n\ |
-d, --daemon Runs in daemon mode\n\ |
-f, --config_file Set configuration file name\n\ |
-f, --config_file Set configuration file name\n\ |
-i, --pid_file Set process identifier file name\n\ |
-i, --pid_file Set process identifier file name\n\ |
|
-z, --socket Set path of zebra socket\n\ |
-p, --bgp_port Set bgp protocol's port number\n\ |
-p, --bgp_port Set bgp protocol's port number\n\ |
-l, --listenon Listen on specified address (implies -n)\n\ |
-l, --listenon Listen on specified address (implies -n)\n\ |
-A, --vty_addr Set vty's bind address\n\ |
-A, --vty_addr Set vty's bind address\n\ |
Line 166 Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
|
Line 170 Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
|
|
|
exit (status); |
exit (status); |
} |
} |
| |
/* SIGHUP handler. */ |
/* SIGHUP handler. */ |
void |
void |
sighup (void) |
sighup (void) |
Line 193 sigint (void)
|
Line 197 sigint (void)
|
{ |
{ |
zlog_notice ("Terminating on signal"); |
zlog_notice ("Terminating on signal"); |
|
|
if (! retain_mode) | if (! retain_mode) |
bgp_terminate (); | { |
| bgp_terminate (); |
| zprivs_terminate (&bgpd_privs); |
| } |
|
|
bgp_exit (0); |
bgp_exit (0); |
} |
} |
Line 220 bgp_exit (int status)
|
Line 227 bgp_exit (int status)
|
struct listnode *node, *nnode; |
struct listnode *node, *nnode; |
int *socket; |
int *socket; |
struct interface *ifp; |
struct interface *ifp; |
extern struct zclient *zclient; |
|
extern struct zclient *zlookup; |
extern struct zclient *zlookup; |
|
|
/* it only makes sense for this to be called on a clean exit */ |
/* it only makes sense for this to be called on a clean exit */ |
Line 230 bgp_exit (int status)
|
Line 236 bgp_exit (int status)
|
for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) |
for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) |
bgp_delete (bgp); |
bgp_delete (bgp); |
list_free (bm->bgp); |
list_free (bm->bgp); |
| bm->bgp = NULL; |
| |
| /* |
| * bgp_delete can re-allocate the process queues after they were |
| * deleted in bgp_terminate. delete them again. |
| * |
| * It might be better to ensure the RIBs (including static routes) |
| * are cleared by bgp_terminate() during its call to bgp_cleanup_routes(), |
| * which currently only deletes the kernel routes. |
| */ |
| if (bm->process_main_queue) |
| { |
| work_queue_free (bm->process_main_queue); |
| bm->process_main_queue = NULL; |
| } |
| if (bm->process_rsclient_queue) |
| { |
| work_queue_free (bm->process_rsclient_queue); |
| bm->process_rsclient_queue = NULL; |
| } |
| |
/* reverse bgp_master_init */ |
/* reverse bgp_master_init */ |
for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, socket)) |
for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, socket)) |
{ |
{ |
Line 242 bgp_exit (int status)
|
Line 268 bgp_exit (int status)
|
/* reverse bgp_zebra_init/if_init */ |
/* reverse bgp_zebra_init/if_init */ |
if (retain_mode) |
if (retain_mode) |
if_add_hook (IF_DELETE_HOOK, NULL); |
if_add_hook (IF_DELETE_HOOK, NULL); |
for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) | for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) |
{ |
{ |
struct listnode *c_node, *c_nnode; |
struct listnode *c_node, *c_nnode; |
struct connected *c; |
struct connected *c; |
|
|
for (ALL_LIST_ELEMENTS (ifp->connected, c_node, c_nnode, c)) |
for (ALL_LIST_ELEMENTS (ifp->connected, c_node, c_nnode, c)) |
bgp_connected_delete (c); |
bgp_connected_delete (c); |
|
|
if_delete (ifp); |
|
} |
} |
list_free (iflist); |
|
|
|
/* reverse bgp_attr_init */ |
/* reverse bgp_attr_init */ |
bgp_attr_finish (); |
bgp_attr_finish (); |
Line 287 bgp_exit (int status)
|
Line 310 bgp_exit (int status)
|
/* reverse community_list_init */ |
/* reverse community_list_init */ |
community_list_terminate (bgp_clist); |
community_list_terminate (bgp_clist); |
|
|
|
vrf_terminate (); |
cmd_terminate (); |
cmd_terminate (); |
vty_terminate (); |
vty_terminate (); |
if (zclient) | bgp_address_destroy(); |
zclient_free (zclient); | bgp_scan_destroy(); |
| bgp_zebra_destroy(); |
if (zlookup) |
if (zlookup) |
zclient_free (zlookup); |
zclient_free (zlookup); |
|
if (bgp_nexthop_buf) |
|
stream_free (bgp_nexthop_buf); |
|
|
/* reverse bgp_master_init */ |
/* reverse bgp_master_init */ |
if (master) | if (bm->master) |
thread_master_free (master); | thread_master_free (bm->master); |
|
|
if (zlog_default) |
if (zlog_default) |
closezlog (zlog_default); |
closezlog (zlog_default); |
Line 306 bgp_exit (int status)
|
Line 333 bgp_exit (int status)
|
|
|
exit (status); |
exit (status); |
} |
} |
| |
/* Main routine of bgpd. Treatment of argument and start bgp finite |
/* Main routine of bgpd. Treatment of argument and start bgp finite |
state machine is handled at here. */ |
state machine is handled at here. */ |
int |
int |
Line 335 main (int argc, char **argv)
|
Line 362 main (int argc, char **argv)
|
/* Command line argument treatment. */ |
/* Command line argument treatment. */ |
while (1) |
while (1) |
{ |
{ |
opt = getopt_long (argc, argv, "df:i:hp:l:A:P:rnu:g:vC", longopts, 0); | opt = getopt_long (argc, argv, "df:i:z:hp:l:A:P:rnu:g:vC", longopts, 0); |
|
|
if (opt == EOF) |
if (opt == EOF) |
break; |
break; |
Line 353 main (int argc, char **argv)
|
Line 380 main (int argc, char **argv)
|
case 'i': |
case 'i': |
pid_file = optarg; |
pid_file = optarg; |
break; |
break; |
|
case 'z': |
|
zclient_serv_path_set (optarg); |
|
break; |
case 'p': |
case 'p': |
tmp_port = atoi (optarg); |
tmp_port = atoi (optarg); |
if (tmp_port <= 0 || tmp_port > 0xffff) |
if (tmp_port <= 0 || tmp_port > 0xffff) |
Line 406 main (int argc, char **argv)
|
Line 436 main (int argc, char **argv)
|
} |
} |
} |
} |
|
|
/* Make thread master. */ |
|
master = bm->master; |
|
|
|
/* Initializations. */ |
/* Initializations. */ |
srand (time (NULL)); | srandom (time (NULL)); |
signal_init (master, Q_SIGC(bgp_signals), bgp_signals); | signal_init (bm->master, array_size(bgp_signals), bgp_signals); |
zprivs_init (&bgpd_privs); |
zprivs_init (&bgpd_privs); |
cmd_init (1); |
cmd_init (1); |
vty_init (master); | vty_init (bm->master); |
memory_init (); |
memory_init (); |
|
vrf_init (); |
|
|
/* BGP related initialization. */ |
/* BGP related initialization. */ |
bgp_init (); |
bgp_init (); |
|
|
/* Sort CLI commands. */ |
|
sort_node (); |
|
|
|
/* Parse config file. */ |
/* Parse config file. */ |
vty_read_config (config_file, config_default); |
vty_read_config (config_file, config_default); |
|
|
Line 445 main (int argc, char **argv)
|
Line 470 main (int argc, char **argv)
|
vty_serv_sock (vty_addr, vty_port, BGP_VTYSH_PATH); |
vty_serv_sock (vty_addr, vty_port, BGP_VTYSH_PATH); |
|
|
/* Print banner. */ |
/* Print banner. */ |
zlog_notice ("BGPd %s starting: vty@%d, bgp@%s:%d", QUAGGA_VERSION, | zlog_notice ("BGPd %s starting: vty@%d, bgp@%s:%d pid %d", QUAGGA_VERSION, |
vty_port, |
vty_port, |
(bm->address ? bm->address : "<all>"), |
(bm->address ? bm->address : "<all>"), |
bm->port); | bm->port, |
| getpid ()); |
|
|
/* Start finite state machine, here we go! */ |
/* Start finite state machine, here we go! */ |
while (thread_fetch (master, &thread)) | while (thread_fetch (bm->master, &thread)) |
thread_call (&thread); |
thread_call (&thread); |
|
|
/* Not reached. */ |
/* Not reached. */ |