]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_main.c
*: add frr_run()
[mirror_frr.git] / isisd / isis_main.c
CommitLineData
eb5d44eb 1/*
2 * IS-IS Rout(e)ing protocol - isis_main.c
3 *
4 * Copyright (C) 2001,2002 Sampo Saaristo
5 * Tampere University of Technology
6 * Institute of Communications Engineering
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public Licenseas published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
eb5d44eb 23#include <zebra.h>
eb5d44eb 24
25#include "getopt.h"
26#include "thread.h"
27#include "log.h"
5e4fa164 28#include <lib/version.h>
eb5d44eb 29#include "command.h"
30#include "vty.h"
31#include "memory.h"
fc7948fa 32#include "memory_vty.h"
eb5d44eb 33#include "stream.h"
34#include "if.h"
9e867fe6 35#include "privs.h"
2d75d052 36#include "sigevent.h"
c729c650 37#include "filter.h"
f3ccedaa 38#include "plist.h"
48d8bea8 39#include "zclient.h"
6a69b354 40#include "vrf.h"
676a4ea3 41#include "qobj.h"
4f04a76b 42#include "libfrr.h"
eb5d44eb 43
44#include "isisd/dict.h"
eb5d44eb 45#include "isisd/isis_constants.h"
46#include "isisd/isis_common.h"
47#include "isisd/isis_flags.h"
48#include "isisd/isis_circuit.h"
49#include "isisd/isisd.h"
50#include "isisd/isis_dynhn.h"
3f045a08
JB
51#include "isisd/isis_spf.h"
52#include "isisd/isis_route.h"
f3ccedaa 53#include "isisd/isis_routemap.h"
3f045a08 54#include "isisd/isis_zebra.h"
f8c06e2c
OD
55#include "isisd/isis_tlv.h"
56#include "isisd/isis_te.h"
eb5d44eb 57
58/* Default configuration file name */
59#define ISISD_DEFAULT_CONFIG "isisd.conf"
60/* Default vty port */
fc58e874 61#define ISISD_VTY_PORT 2608
eb5d44eb 62
9e867fe6 63/* isisd privileges */
f390d2c7 64zebra_capabilities_t _caps_p[] = {
ceacedba 65 ZCAP_NET_RAW,
9e867fe6 66 ZCAP_BIND
67};
68
f390d2c7 69struct zebra_privs_t isisd_privs = {
b2f36157
DL
70#if defined(FRR_USER)
71 .user = FRR_USER,
9e867fe6 72#endif
b2f36157
DL
73#if defined FRR_GROUP
74 .group = FRR_GROUP,
9e867fe6 75#endif
76#ifdef VTY_GROUP
77 .vty_group = VTY_GROUP,
78#endif
79 .caps_p = _caps_p,
3f045a08 80 .cap_num_p = sizeof (_caps_p) / sizeof (*_caps_p),
9e867fe6 81 .cap_num_i = 0
82};
83
eb5d44eb 84/* isisd options */
f390d2c7 85struct option longopts[] = {
f390d2c7 86 {0}
eb5d44eb 87};
88
eb5d44eb 89/* Master of threads. */
90struct thread_master *master;
91
eb5d44eb 92/* for reload */
37da8c01 93char _cwd[MAXPATHLEN];
94char _progpath[MAXPATHLEN];
eb5d44eb 95int _argc;
96char **_argv;
97char **_envp;
98
41b36e90
PJ
99/*
100 * Prototypes.
101 */
102void reload(void);
103void sighup(void);
104void sigint(void);
105void sigterm(void);
106void sigusr1(void);
107
108
eb5d44eb 109void
110reload ()
111{
529d65b3 112 zlog_debug ("Reload");
eb5d44eb 113 /* FIXME: Clean up func call here */
cdb6ee94 114 vty_reset ();
3f045a08 115 (void) isisd_privs.change (ZPRIVS_RAISE);
eb5d44eb 116 execve (_progpath, _argv, _envp);
3f045a08
JB
117 zlog_err ("Reload failed: cannot exec %s: %s", _progpath,
118 safe_strerror (errno));
eb5d44eb 119}
120
35dece84 121static __attribute__((__noreturn__)) void
eb5d44eb 122terminate (int i)
123{
124 exit (i);
125}
126
127/*
128 * Signal handlers
129 */
2d75d052 130
f390d2c7 131void
2d75d052 132sighup (void)
eb5d44eb 133{
529d65b3 134 zlog_debug ("SIGHUP received");
eb5d44eb 135 reload ();
136
137 return;
138}
139
35dece84 140__attribute__((__noreturn__)) void
2d75d052 141sigint (void)
eb5d44eb 142{
887c44a4 143 zlog_notice ("Terminating on signal SIGINT");
eb5d44eb 144 terminate (0);
eb5d44eb 145}
146
35dece84 147__attribute__((__noreturn__)) void
2d75d052 148sigterm (void)
eb5d44eb 149{
887c44a4 150 zlog_notice ("Terminating on signal SIGTERM");
eb5d44eb 151 terminate (0);
152}
153
154void
2d75d052 155sigusr1 (void)
eb5d44eb 156{
529d65b3 157 zlog_debug ("SIGUSR1 received");
eb5d44eb 158 zlog_rotate (NULL);
159}
160
2d75d052 161struct quagga_signal_t isisd_signals[] =
f390d2c7 162{
163 {
164 .signal = SIGHUP,
165 .handler = &sighup,
166 },
2d75d052 167 {
f390d2c7 168 .signal = SIGUSR1,
169 .handler = &sigusr1,
170 },
2d75d052 171 {
f390d2c7 172 .signal = SIGINT,
173 .handler = &sigint,
174 },
2d75d052 175 {
f390d2c7 176 .signal = SIGTERM,
177 .handler = &sigterm,
178 },
2d75d052 179};
eb5d44eb 180
4f04a76b
DL
181FRR_DAEMON_INFO(isisd, ISIS,
182 .vty_port = ISISD_VTY_PORT,
183
184 .proghelp = "Implementation of the IS-IS routing protocol.",
185 .copyright = "Copyright (c) 2001-2002 Sampo Saaristo,"
186 " Ofer Wald and Hannes Gredler",
187
188 .signals = isisd_signals,
189 .n_signals = array_size(isisd_signals),
190
191 .privs = &isisd_privs,
192)
193
eb5d44eb 194/*
195 * Main routine of isisd. Parse arguments and handle IS-IS state machine.
196 */
f390d2c7 197int
eb5d44eb 198main (int argc, char **argv, char **envp)
199{
4f04a76b 200 int opt;
eb5d44eb 201
eb5d44eb 202 /* for reload */
203 _argc = argc;
204 _argv = argv;
205 _envp = envp;
7a49a5b5
DS
206 if (getcwd (_cwd, sizeof (_cwd)) == NULL)
207 {
208 zlog_err ("ISISd: Unable to determine CWD: %d", errno);
209 exit (1);
210 }
211
eb5d44eb 212 if (*argv[0] == '.')
213 snprintf (_progpath, sizeof (_progpath), "%s/%s", _cwd, _argv[0]);
214 else
215 snprintf (_progpath, sizeof (_progpath), "%s", argv[0]);
f390d2c7 216
4f04a76b 217 frr_preinit (&isisd_di, argc, argv);
eb05883f 218 frr_opt_add ("", longopts, "");
4f04a76b 219
eb5d44eb 220 /* Command line argument treatment. */
f390d2c7 221 while (1)
eb5d44eb 222 {
4f04a76b 223 opt = frr_getopt (argc, argv, NULL);
f390d2c7 224
eb5d44eb 225 if (opt == EOF)
f390d2c7 226 break;
227
228 switch (opt)
229 {
230 case 0:
231 break;
f390d2c7 232 default:
4f04a76b 233 frr_help_exit (1);
f390d2c7 234 break;
235 }
eb5d44eb 236 }
f390d2c7 237
857b5446 238 vty_config_lockless ();
eb5d44eb 239 /* thread master */
4f04a76b 240 master = frr_init ();
eb5d44eb 241
242 /*
243 * initializations
244 */
c729c650 245 access_list_init();
6a69b354 246 vrf_init ();
f3ccedaa 247 prefix_list_init();
eb5d44eb 248 isis_init ();
3f045a08
JB
249 isis_circuit_init ();
250 isis_spf_cmds_init ();
f3ccedaa
CF
251 isis_redist_init ();
252 isis_route_map_init();
f8c06e2c 253 isis_mpls_te_init();
3f045a08
JB
254
255 /* create the global 'isis' instance */
256 isis_new (1);
257
4140ca4d 258 isis_zebra_init(master);
3f045a08 259
eb05883f 260 frr_config_fork ();
16077f2f 261 frr_run (master);
eb5d44eb 262
263 /* Not reached. */
264 exit (0);
265}