diff options
Diffstat (limited to 'bgpd/bgp_main.c')
| -rw-r--r-- | bgpd/bgp_main.c | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index 1f2f7f86ce..5ef8154faf 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -68,6 +68,7 @@ static const struct option longopts[] = { "no_kernel", no_argument, NULL, 'n'}, { "user", required_argument, NULL, 'u'}, { "group", required_argument, NULL, 'g'}, + { "skip_runas", no_argument, NULL, 'S'}, { "version", no_argument, NULL, 'v'}, { "dryrun", no_argument, NULL, 'C'}, { "help", no_argument, NULL, 'h'}, @@ -163,6 +164,7 @@ redistribution between different routing protocols.\n\n\ -n, --no_kernel Do not install route to kernel.\n\ -u, --user User to run as\n\ -g, --group Group to run as\n\ +-S, --skip_runas Skip user and group run as\n\ -v, --version Print program version\n\ -C, --dryrun Check configuration for validity and exit\n\ -h, --help Display this help and exit\n\ @@ -200,9 +202,12 @@ sigint (void) zlog_notice ("Terminating on signal"); if (! retain_mode) - bgp_terminate (); + { + bgp_terminate (); + if (bgpd_privs.user) /* NULL if skip_runas flag set */ + zprivs_terminate (&bgpd_privs); + } - zprivs_terminate (&bgpd_privs); bgp_exit (0); exit (0); @@ -227,7 +232,6 @@ bgp_exit (int status) { struct bgp *bgp; struct listnode *node, *nnode; - extern struct zclient *zclient; /* it only makes sense for this to be called on a clean exit */ assert (status == 0); @@ -277,8 +281,8 @@ bgp_exit (int status) bgp_vrf_terminate (); cmd_terminate (); vty_terminate (); - if (zclient) - zclient_free (zclient); + + bgp_zebra_destroy(); if (bgp_nexthop_buf) stream_free (bgp_nexthop_buf); if (bgp_ifindices_buf) @@ -317,6 +321,7 @@ bgp_vrf_enable (vrf_id_t vrf_id, const char *name, void **info) { struct vrf *vrf; struct bgp *bgp; + vrf_id_t old_vrf_id; vrf = vrf_lookup (vrf_id); if (!vrf) // unexpected @@ -328,8 +333,13 @@ bgp_vrf_enable (vrf_id_t vrf_id, const char *name, void **info) bgp = bgp_lookup_by_name(name); if (bgp) { + old_vrf_id = bgp->vrf_id; /* We have instance configured, link to VRF and make it "up". */ bgp_vrf_link (bgp, vrf); + + /* Update any redistribute vrf bitmaps if the vrf_id changed */ + if (old_vrf_id != bgp->vrf_id) + bgp_update_redist_vrf_bitmaps(bgp, old_vrf_id); bgp_instance_up (bgp); } @@ -341,6 +351,7 @@ bgp_vrf_disable (vrf_id_t vrf_id, const char *name, void **info) { struct vrf *vrf; struct bgp *bgp; + vrf_id_t old_vrf_id; if (vrf_id == VRF_DEFAULT) return 0; @@ -355,8 +366,12 @@ bgp_vrf_disable (vrf_id_t vrf_id, const char *name, void **info) bgp = bgp_lookup_by_name(name); if (bgp) { + old_vrf_id = bgp->vrf_id; /* We have instance configured, unlink from VRF and make it "down". */ bgp_vrf_unlink (bgp, vrf); + /* Update any redistribute vrf bitmaps if the vrf_id changed */ + if (old_vrf_id != bgp->vrf_id) + bgp_update_redist_vrf_bitmaps(bgp, old_vrf_id); bgp_instance_down (bgp); } @@ -398,6 +413,7 @@ main (int argc, char **argv) char *progname; struct thread thread; int tmp_port; + int skip_runas = 0; /* Set umask before anything for security */ umask (0027); @@ -405,18 +421,13 @@ main (int argc, char **argv) /* Preserve name of myself. */ progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); - zlog_default = openzlog (progname, ZLOG_BGP, 0, - LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); - zprivs_init (&bgpd_privs); - zlog_set_file (NULL, LOG_DEFAULT_FILENAME, zlog_default->default_lvl); - /* BGP master init. */ bgp_master_init (); /* Command line argument treatment. */ while (1) { - opt = getopt_long (argc, argv, "df:i:z:hp:l:A:P:rnu:g:vC", longopts, 0); + opt = getopt_long (argc, argv, "df:i:z:hp:l:A:P:rnu:g:vCS", longopts, 0); if (opt == EOF) break; @@ -474,6 +485,9 @@ main (int argc, char **argv) case 'g': bgpd_privs.group = optarg; break; + case 'S': /* skip run as = override bgpd_privs */ + skip_runas = 1; + break; case 'v': print_version (progname); exit (0); @@ -490,6 +504,16 @@ main (int argc, char **argv) } } + zlog_default = openzlog (progname, ZLOG_BGP, 0, + LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); + + if (skip_runas) + memset (&bgpd_privs, 0, sizeof (bgpd_privs)); + zprivs_init (&bgpd_privs); + +#if defined(HAVE_CUMULUS) + zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl); +#endif /* Initializations. */ srandom (time (NULL)); |
