paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 1 | /* zebra daemon main routine. |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2 | * Copyright (C) 1997, 98 Kunihiro Ishiguro |
| 3 | * |
| 4 | * This file is part of GNU Zebra. |
| 5 | * |
| 6 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2, or (at your option) any |
| 9 | * later version. |
| 10 | * |
| 11 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | * 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <zebra.h> |
| 23 | |
gdt | 5e4fa16 | 2004-03-16 14:38:36 +0000 | [diff] [blame] | 24 | #include <lib/version.h> |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 25 | #include "getopt.h" |
| 26 | #include "command.h" |
| 27 | #include "thread.h" |
| 28 | #include "filter.h" |
| 29 | #include "memory.h" |
| 30 | #include "prefix.h" |
| 31 | #include "log.h" |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 32 | #include "plist.h" |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 33 | #include "privs.h" |
paul | 2d75d05 | 2004-01-19 21:31:15 +0000 | [diff] [blame] | 34 | #include "sigevent.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 35 | |
| 36 | #include "zebra/rib.h" |
| 37 | #include "zebra/zserv.h" |
| 38 | #include "zebra/debug.h" |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 39 | #include "zebra/router-id.h" |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 40 | #include "zebra/irdp.h" |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 41 | #include "zebra/rtadv.h" |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 42 | #include "zebra/zebra_fpm.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 43 | |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 44 | /* Zebra instance */ |
| 45 | struct zebra_t zebrad = |
| 46 | { |
| 47 | .rtm_table_default = 0, |
| 48 | }; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 49 | |
| 50 | /* process id. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 51 | pid_t pid; |
| 52 | |
gdt | 87efd64 | 2004-06-30 17:36:11 +0000 | [diff] [blame] | 53 | /* Pacify zclient.o in libzebra, which expects this variable. */ |
| 54 | struct thread_master *master; |
| 55 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 56 | /* Route retain mode flag. */ |
| 57 | int retain_mode = 0; |
| 58 | |
| 59 | /* Don't delete kernel route. */ |
| 60 | int keep_kernel_mode = 0; |
| 61 | |
hasso | c34b6b5 | 2004-08-31 13:41:49 +0000 | [diff] [blame] | 62 | #ifdef HAVE_NETLINK |
| 63 | /* Receive buffer size for netlink socket */ |
| 64 | u_int32_t nl_rcvbufsize = 0; |
| 65 | #endif /* HAVE_NETLINK */ |
| 66 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 67 | /* Command line options. */ |
| 68 | struct option longopts[] = |
| 69 | { |
| 70 | { "batch", no_argument, NULL, 'b'}, |
| 71 | { "daemon", no_argument, NULL, 'd'}, |
| 72 | { "keep_kernel", no_argument, NULL, 'k'}, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 73 | { "config_file", required_argument, NULL, 'f'}, |
| 74 | { "pid_file", required_argument, NULL, 'i'}, |
Vyacheslav Trushkin | b511468 | 2011-11-25 18:51:48 +0400 | [diff] [blame] | 75 | { "socket", required_argument, NULL, 'z'}, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 76 | { "help", no_argument, NULL, 'h'}, |
| 77 | { "vty_addr", required_argument, NULL, 'A'}, |
| 78 | { "vty_port", required_argument, NULL, 'P'}, |
| 79 | { "retain", no_argument, NULL, 'r'}, |
Paul Jakma | 876b8be | 2006-10-15 23:35:57 +0000 | [diff] [blame] | 80 | { "dryrun", no_argument, NULL, 'C'}, |
hasso | c34b6b5 | 2004-08-31 13:41:49 +0000 | [diff] [blame] | 81 | #ifdef HAVE_NETLINK |
hasso | 583d800 | 2005-01-16 23:34:02 +0000 | [diff] [blame] | 82 | { "nl-bufsize", required_argument, NULL, 's'}, |
hasso | c34b6b5 | 2004-08-31 13:41:49 +0000 | [diff] [blame] | 83 | #endif /* HAVE_NETLINK */ |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 84 | { "user", required_argument, NULL, 'u'}, |
hasso | c065230 | 2004-11-25 19:33:48 +0000 | [diff] [blame] | 85 | { "group", required_argument, NULL, 'g'}, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 86 | { "version", no_argument, NULL, 'v'}, |
| 87 | { 0 } |
| 88 | }; |
| 89 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 90 | zebra_capabilities_t _caps_p [] = |
| 91 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 92 | ZCAP_NET_ADMIN, |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 93 | ZCAP_SYS_ADMIN, |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 94 | ZCAP_NET_RAW, |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | /* zebra privileges to run with */ |
| 98 | struct zebra_privs_t zserv_privs = |
| 99 | { |
paul | d81fadf | 2003-08-14 05:32:12 +0000 | [diff] [blame] | 100 | #if defined(QUAGGA_USER) && defined(QUAGGA_GROUP) |
| 101 | .user = QUAGGA_USER, |
| 102 | .group = QUAGGA_GROUP, |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 103 | #endif |
| 104 | #ifdef VTY_GROUP |
| 105 | .vty_group = VTY_GROUP, |
| 106 | #endif |
| 107 | .caps_p = _caps_p, |
Balaji.G | 837d16c | 2012-09-26 14:09:10 +0530 | [diff] [blame] | 108 | .cap_num_p = array_size(_caps_p), |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 109 | .cap_num_i = 0 |
| 110 | }; |
| 111 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 112 | /* Default configuration file path. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 113 | char config_default[] = SYSCONFDIR DEFAULT_CONFIG_FILE; |
| 114 | |
| 115 | /* Process ID saved for use by init system */ |
hasso | fce954f | 2004-10-07 20:29:24 +0000 | [diff] [blame] | 116 | const char *pid_file = PATH_ZEBRA_PID; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 117 | |
| 118 | /* Help information display. */ |
| 119 | static void |
| 120 | usage (char *progname, int status) |
| 121 | { |
| 122 | if (status != 0) |
| 123 | fprintf (stderr, "Try `%s --help' for more information.\n", progname); |
| 124 | else |
| 125 | { |
hasso | c34b6b5 | 2004-08-31 13:41:49 +0000 | [diff] [blame] | 126 | printf ("Usage : %s [OPTION...]\n\n"\ |
| 127 | "Daemon which manages kernel routing table management and "\ |
| 128 | "redistribution between different routing protocols.\n\n"\ |
| 129 | "-b, --batch Runs in batch mode\n"\ |
| 130 | "-d, --daemon Runs in daemon mode\n"\ |
| 131 | "-f, --config_file Set configuration file name\n"\ |
| 132 | "-i, --pid_file Set process identifier file name\n"\ |
Vyacheslav Trushkin | b511468 | 2011-11-25 18:51:48 +0400 | [diff] [blame] | 133 | "-z, --socket Set path of zebra socket\n"\ |
hasso | c34b6b5 | 2004-08-31 13:41:49 +0000 | [diff] [blame] | 134 | "-k, --keep_kernel Don't delete old routes which installed by "\ |
| 135 | "zebra.\n"\ |
Paul Jakma | 876b8be | 2006-10-15 23:35:57 +0000 | [diff] [blame] | 136 | "-C, --dryrun Check configuration for validity and exit\n"\ |
hasso | c34b6b5 | 2004-08-31 13:41:49 +0000 | [diff] [blame] | 137 | "-A, --vty_addr Set vty's bind address\n"\ |
| 138 | "-P, --vty_port Set vty's port number\n"\ |
| 139 | "-r, --retain When program terminates, retain added route "\ |
| 140 | "by zebra.\n"\ |
hasso | c065230 | 2004-11-25 19:33:48 +0000 | [diff] [blame] | 141 | "-u, --user User to run as\n"\ |
| 142 | "-g, --group Group to run as\n", progname); |
hasso | c34b6b5 | 2004-08-31 13:41:49 +0000 | [diff] [blame] | 143 | #ifdef HAVE_NETLINK |
| 144 | printf ("-s, --nl-bufsize Set netlink receive buffer size\n"); |
| 145 | #endif /* HAVE_NETLINK */ |
| 146 | printf ("-v, --version Print program version\n"\ |
| 147 | "-h, --help Display this help and exit\n"\ |
| 148 | "\n"\ |
| 149 | "Report bugs to %s\n", ZEBRA_BUG_ADDRESS); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | exit (status); |
| 153 | } |
| 154 | |
| 155 | /* SIGHUP handler. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 156 | static void |
paul | 2d75d05 | 2004-01-19 21:31:15 +0000 | [diff] [blame] | 157 | sighup (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 158 | { |
| 159 | zlog_info ("SIGHUP received"); |
| 160 | |
| 161 | /* Reload of config file. */ |
| 162 | ; |
| 163 | } |
| 164 | |
| 165 | /* SIGINT handler. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 166 | static void |
paul | 2d75d05 | 2004-01-19 21:31:15 +0000 | [diff] [blame] | 167 | sigint (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 168 | { |
ajs | 887c44a | 2004-12-03 16:36:46 +0000 | [diff] [blame] | 169 | zlog_notice ("Terminating on signal"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 170 | |
| 171 | if (!retain_mode) |
| 172 | rib_close (); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 173 | #ifdef HAVE_IRDP |
| 174 | irdp_finish(); |
| 175 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 176 | |
| 177 | exit (0); |
| 178 | } |
| 179 | |
| 180 | /* SIGUSR1 handler. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 181 | static void |
paul | 2d75d05 | 2004-01-19 21:31:15 +0000 | [diff] [blame] | 182 | sigusr1 (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 183 | { |
| 184 | zlog_rotate (NULL); |
| 185 | } |
| 186 | |
paul | 2d75d05 | 2004-01-19 21:31:15 +0000 | [diff] [blame] | 187 | struct quagga_signal_t zebra_signals[] = |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 188 | { |
paul | 2d75d05 | 2004-01-19 21:31:15 +0000 | [diff] [blame] | 189 | { |
| 190 | .signal = SIGHUP, |
| 191 | .handler = &sighup, |
| 192 | }, |
| 193 | { |
| 194 | .signal = SIGUSR1, |
| 195 | .handler = &sigusr1, |
| 196 | }, |
| 197 | { |
| 198 | .signal = SIGINT, |
hasso | 8c903fb | 2004-03-17 20:39:18 +0000 | [diff] [blame] | 199 | .handler = &sigint, |
paul | 2d75d05 | 2004-01-19 21:31:15 +0000 | [diff] [blame] | 200 | }, |
hasso | f571dab | 2004-03-22 08:55:25 +0000 | [diff] [blame] | 201 | { |
| 202 | .signal = SIGTERM, |
| 203 | .handler = &sigint, |
| 204 | }, |
paul | 2d75d05 | 2004-01-19 21:31:15 +0000 | [diff] [blame] | 205 | }; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 206 | |
| 207 | /* Main startup routine. */ |
| 208 | int |
| 209 | main (int argc, char **argv) |
| 210 | { |
| 211 | char *p; |
| 212 | char *vty_addr = NULL; |
paul | 4fc4e7a | 2003-01-22 19:47:09 +0000 | [diff] [blame] | 213 | int vty_port = ZEBRA_VTY_PORT; |
Paul Jakma | 876b8be | 2006-10-15 23:35:57 +0000 | [diff] [blame] | 214 | int dryrun = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 215 | int batch_mode = 0; |
| 216 | int daemon_mode = 0; |
| 217 | char *config_file = NULL; |
| 218 | char *progname; |
| 219 | struct thread thread; |
Vyacheslav Trushkin | b511468 | 2011-11-25 18:51:48 +0400 | [diff] [blame] | 220 | char *zserv_path = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 221 | |
| 222 | /* Set umask before anything for security */ |
| 223 | umask (0027); |
| 224 | |
| 225 | /* preserve my name */ |
| 226 | progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); |
| 227 | |
ajs | 274a4a4 | 2004-12-07 15:39:31 +0000 | [diff] [blame] | 228 | zlog_default = openzlog (progname, ZLOG_ZEBRA, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 229 | LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); |
| 230 | |
| 231 | while (1) |
| 232 | { |
| 233 | int opt; |
| 234 | |
hasso | c34b6b5 | 2004-08-31 13:41:49 +0000 | [diff] [blame] | 235 | #ifdef HAVE_NETLINK |
Vyacheslav Trushkin | b511468 | 2011-11-25 18:51:48 +0400 | [diff] [blame] | 236 | opt = getopt_long (argc, argv, "bdkf:i:z:hA:P:ru:g:vs:C", longopts, 0); |
hasso | c34b6b5 | 2004-08-31 13:41:49 +0000 | [diff] [blame] | 237 | #else |
Vyacheslav Trushkin | b511468 | 2011-11-25 18:51:48 +0400 | [diff] [blame] | 238 | opt = getopt_long (argc, argv, "bdkf:i:z:hA:P:ru:g:vC", longopts, 0); |
hasso | c34b6b5 | 2004-08-31 13:41:49 +0000 | [diff] [blame] | 239 | #endif /* HAVE_NETLINK */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 240 | |
| 241 | if (opt == EOF) |
| 242 | break; |
| 243 | |
| 244 | switch (opt) |
| 245 | { |
| 246 | case 0: |
| 247 | break; |
| 248 | case 'b': |
| 249 | batch_mode = 1; |
| 250 | case 'd': |
| 251 | daemon_mode = 1; |
| 252 | break; |
| 253 | case 'k': |
| 254 | keep_kernel_mode = 1; |
| 255 | break; |
Paul Jakma | 876b8be | 2006-10-15 23:35:57 +0000 | [diff] [blame] | 256 | case 'C': |
| 257 | dryrun = 1; |
| 258 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 259 | case 'f': |
| 260 | config_file = optarg; |
| 261 | break; |
| 262 | case 'A': |
| 263 | vty_addr = optarg; |
| 264 | break; |
| 265 | case 'i': |
| 266 | pid_file = optarg; |
| 267 | break; |
Vyacheslav Trushkin | b511468 | 2011-11-25 18:51:48 +0400 | [diff] [blame] | 268 | case 'z': |
| 269 | zserv_path = optarg; |
| 270 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 271 | case 'P': |
paul | 4fc4e7a | 2003-01-22 19:47:09 +0000 | [diff] [blame] | 272 | /* Deal with atoi() returning 0 on failure, and zebra not |
| 273 | listening on zebra port... */ |
| 274 | if (strcmp(optarg, "0") == 0) |
| 275 | { |
| 276 | vty_port = 0; |
| 277 | break; |
| 278 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 279 | vty_port = atoi (optarg); |
Paul Jakma | 0d6b2ee | 2008-05-29 18:29:16 +0000 | [diff] [blame] | 280 | if (vty_port <= 0 || vty_port > 0xffff) |
| 281 | vty_port = ZEBRA_VTY_PORT; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 282 | break; |
| 283 | case 'r': |
| 284 | retain_mode = 1; |
| 285 | break; |
hasso | c34b6b5 | 2004-08-31 13:41:49 +0000 | [diff] [blame] | 286 | #ifdef HAVE_NETLINK |
| 287 | case 's': |
| 288 | nl_rcvbufsize = atoi (optarg); |
| 289 | break; |
| 290 | #endif /* HAVE_NETLINK */ |
hasso | c065230 | 2004-11-25 19:33:48 +0000 | [diff] [blame] | 291 | case 'u': |
| 292 | zserv_privs.user = optarg; |
| 293 | break; |
| 294 | case 'g': |
| 295 | zserv_privs.group = optarg; |
| 296 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 297 | case 'v': |
| 298 | print_version (progname); |
| 299 | exit (0); |
| 300 | break; |
| 301 | case 'h': |
| 302 | usage (progname, 0); |
| 303 | break; |
| 304 | default: |
| 305 | usage (progname, 1); |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /* Make master thread emulator. */ |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 311 | zebrad.master = thread_master_create (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 312 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 313 | /* privs initialise */ |
| 314 | zprivs_init (&zserv_privs); |
| 315 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 316 | /* Vty related initialize. */ |
Balaji.G | 837d16c | 2012-09-26 14:09:10 +0530 | [diff] [blame] | 317 | signal_init (zebrad.master, array_size(zebra_signals), zebra_signals); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 318 | cmd_init (1); |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 319 | vty_init (zebrad.master); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 320 | memory_init (); |
| 321 | |
| 322 | /* Zebra related initialize. */ |
| 323 | zebra_init (); |
| 324 | rib_init (); |
| 325 | zebra_if_init (); |
| 326 | zebra_debug_init (); |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 327 | router_id_init(); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 328 | zebra_vty_init (); |
| 329 | access_list_init (); |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 330 | prefix_list_init (); |
Joachim Nilsson | 36735ed | 2012-05-09 13:38:36 +0200 | [diff] [blame] | 331 | #ifdef RTADV |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 332 | rtadv_init (); |
Joachim Nilsson | 36735ed | 2012-05-09 13:38:36 +0200 | [diff] [blame] | 333 | #endif |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 334 | #ifdef HAVE_IRDP |
| 335 | irdp_init(); |
| 336 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 337 | |
| 338 | /* For debug purpose. */ |
| 339 | /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */ |
| 340 | |
| 341 | /* Make kernel routing socket. */ |
| 342 | kernel_init (); |
| 343 | interface_list (); |
| 344 | route_read (); |
| 345 | |
| 346 | /* Sort VTY commands. */ |
| 347 | sort_node (); |
| 348 | |
| 349 | #ifdef HAVE_SNMP |
| 350 | zebra_snmp_init (); |
| 351 | #endif /* HAVE_SNMP */ |
| 352 | |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 353 | #ifdef HAVE_FPM |
| 354 | zfpm_init (zebrad.master, 1, 0); |
| 355 | #else |
| 356 | zfpm_init (zebrad.master, 0, 0); |
| 357 | #endif |
| 358 | |
Denis Ovsienko | 91b7351 | 2007-09-14 13:31:52 +0000 | [diff] [blame] | 359 | /* Process the configuration file. Among other configuration |
| 360 | * directives we can meet those installing static routes. Such |
| 361 | * requests will not be executed immediately, but queued in |
| 362 | * zebra->ribq structure until we enter the main execution loop. |
| 363 | * The notifications from kernel will show originating PID equal |
| 364 | * to that after daemon() completes (if ever called). |
| 365 | */ |
hasso | 320ec10 | 2004-06-20 19:54:37 +0000 | [diff] [blame] | 366 | vty_read_config (config_file, config_default); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 367 | |
Paul Jakma | 876b8be | 2006-10-15 23:35:57 +0000 | [diff] [blame] | 368 | /* Don't start execution if we are in dry-run mode */ |
| 369 | if (dryrun) |
| 370 | return(0); |
| 371 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 372 | /* Clean up rib. */ |
| 373 | rib_weed_tables (); |
| 374 | |
| 375 | /* Exit when zebra is working in batch mode. */ |
| 376 | if (batch_mode) |
| 377 | exit (0); |
| 378 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 379 | /* Daemonize. */ |
Stephen Hemminger | 065de90 | 2009-08-07 11:13:49 -0700 | [diff] [blame] | 380 | if (daemon_mode && daemon (0, 0) < 0) |
| 381 | { |
| 382 | zlog_err("Zebra daemon failed: %s", strerror(errno)); |
| 383 | exit (1); |
| 384 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 385 | |
| 386 | /* Output pid of zebra. */ |
| 387 | pid_output (pid_file); |
| 388 | |
Denis Ovsienko | 91b7351 | 2007-09-14 13:31:52 +0000 | [diff] [blame] | 389 | /* After we have successfully acquired the pidfile, we can be sure |
| 390 | * about being the only copy of zebra process, which is submitting |
| 391 | * changes to the FIB. |
| 392 | * Clean up zebra-originated routes. The requests will be sent to OS |
| 393 | * immediately, so originating PID in notifications from kernel |
| 394 | * will be equal to the current getpid(). To know about such routes, |
| 395 | * we have to have route_read() called before. |
| 396 | */ |
| 397 | if (! keep_kernel_mode) |
| 398 | rib_sweep_route (); |
| 399 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 400 | /* Needed for BSD routing socket. */ |
| 401 | pid = getpid (); |
| 402 | |
Denis Ovsienko | 97be79f | 2009-07-24 20:45:31 +0400 | [diff] [blame] | 403 | /* This must be done only after locking pidfile (bug #403). */ |
Vyacheslav Trushkin | b511468 | 2011-11-25 18:51:48 +0400 | [diff] [blame] | 404 | zebra_zserv_socket_init (zserv_path); |
Denis Ovsienko | 97be79f | 2009-07-24 20:45:31 +0400 | [diff] [blame] | 405 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 406 | /* Make vty server socket. */ |
paul | 4fc4e7a | 2003-01-22 19:47:09 +0000 | [diff] [blame] | 407 | vty_serv_sock (vty_addr, vty_port, ZEBRA_VTYSH_PATH); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 408 | |
ajs | 887c44a | 2004-12-03 16:36:46 +0000 | [diff] [blame] | 409 | /* Print banner. */ |
| 410 | zlog_notice ("Zebra %s starting: vty@%d", QUAGGA_VERSION, vty_port); |
| 411 | |
paul | b21b19c | 2003-06-15 01:28:29 +0000 | [diff] [blame] | 412 | while (thread_fetch (zebrad.master, &thread)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 413 | thread_call (&thread); |
| 414 | |
| 415 | /* Not reached... */ |
paul | e8e1946 | 2006-01-19 20:16:55 +0000 | [diff] [blame] | 416 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 417 | } |