]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_main.c
Merge pull request #1833 from opensourcerouting/fix-vtysh-output-init
[mirror_frr.git] / ospfd / ospf_main.c
1 /*
2 * OSPFd main routine.
3 * Copyright (C) 1998, 99 Kunihiro Ishiguro, Toshiaki Takada
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <zebra.h>
23
24 #include <lib/version.h>
25 #include "getopt.h"
26 #include "thread.h"
27 #include "prefix.h"
28 #include "linklist.h"
29 #include "if.h"
30 #include "vector.h"
31 #include "vty.h"
32 #include "command.h"
33 #include "filter.h"
34 #include "plist.h"
35 #include "stream.h"
36 #include "log.h"
37 #include "memory.h"
38 #include "memory_vty.h"
39 #include "privs.h"
40 #include "sigevent.h"
41 #include "zclient.h"
42 #include "vrf.h"
43 #include "libfrr.h"
44
45 #include "ospfd/ospfd.h"
46 #include "ospfd/ospf_interface.h"
47 #include "ospfd/ospf_asbr.h"
48 #include "ospfd/ospf_lsa.h"
49 #include "ospfd/ospf_lsdb.h"
50 #include "ospfd/ospf_neighbor.h"
51 #include "ospfd/ospf_dump.h"
52 #include "ospfd/ospf_zebra.h"
53 #include "ospfd/ospf_vty.h"
54 #include "ospfd/ospf_bfd.h"
55
56 /* ospfd privileges */
57 zebra_capabilities_t _caps_p[] = {
58 ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN, ZCAP_SYS_ADMIN
59 };
60
61 struct zebra_privs_t ospfd_privs = {
62 #if defined(FRR_USER) && defined(FRR_GROUP)
63 .user = FRR_USER,
64 .group = FRR_GROUP,
65 #endif
66 #if defined(VTY_GROUP)
67 .vty_group = VTY_GROUP,
68 #endif
69 .caps_p = _caps_p,
70 .cap_num_p = array_size(_caps_p),
71 .cap_num_i = 0};
72
73 /* OSPFd options. */
74 struct option longopts[] = {{"instance", required_argument, NULL, 'n'},
75 {"apiserver", no_argument, NULL, 'a'},
76 {0}};
77
78 /* OSPFd program name */
79
80 /* Master of threads. */
81 struct thread_master *master;
82
83 #ifdef SUPPORT_OSPF_API
84 extern int ospf_apiserver_enable;
85 #endif /* SUPPORT_OSPF_API */
86
87 /* SIGHUP handler. */
88 static void sighup(void)
89 {
90 zlog_info("SIGHUP received");
91 }
92
93 /* SIGINT / SIGTERM handler. */
94 static void sigint(void)
95 {
96 zlog_notice("Terminating on signal");
97 ospf_terminate();
98 }
99
100 /* SIGUSR1 handler. */
101 static void sigusr1(void)
102 {
103 zlog_rotate();
104 }
105
106 struct quagga_signal_t ospf_signals[] = {
107 {
108 .signal = SIGHUP,
109 .handler = &sighup,
110 },
111 {
112 .signal = SIGUSR1,
113 .handler = &sigusr1,
114 },
115 {
116 .signal = SIGINT,
117 .handler = &sigint,
118 },
119 {
120 .signal = SIGTERM,
121 .handler = &sigint,
122 },
123 };
124
125 FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT,
126
127 .proghelp = "Implementation of the OSPFv2 routing protocol.",
128
129 .signals = ospf_signals, .n_signals = array_size(ospf_signals),
130
131 .privs = &ospfd_privs, )
132
133 /* OSPFd main routine. */
134 int main(int argc, char **argv)
135 {
136 u_short instance = 0;
137
138 #ifdef SUPPORT_OSPF_API
139 /* OSPF apiserver is disabled by default. */
140 ospf_apiserver_enable = 0;
141 #endif /* SUPPORT_OSPF_API */
142
143 frr_preinit(&ospfd_di, argc, argv);
144 frr_opt_add("n:a", longopts,
145 " -n, --instance Set the instance id\n"
146 " -a, --apiserver Enable OSPF apiserver\n");
147
148 while (1) {
149 int opt;
150
151 opt = frr_getopt(argc, argv, NULL);
152
153 if (opt == EOF)
154 break;
155
156 switch (opt) {
157 case 'n':
158 ospfd_di.instance = instance = atoi(optarg);
159 if (instance < 1)
160 exit(0);
161 break;
162 case 0:
163 break;
164 #ifdef SUPPORT_OSPF_API
165 case 'a':
166 ospf_apiserver_enable = 1;
167 break;
168 #endif /* SUPPORT_OSPF_API */
169 default:
170 frr_help_exit(1);
171 break;
172 }
173 }
174
175 /* Invoked by a priviledged user? -- endo. */
176 if (geteuid() != 0) {
177 errno = EPERM;
178 perror(ospfd_di.progname);
179 exit(1);
180 }
181
182 /* OSPF master init. */
183 ospf_master_init(frr_init());
184
185 /* Initializations. */
186 master = om->master;
187
188 /* Library inits. */
189 debug_init();
190 ospf_vrf_init();
191
192 access_list_init();
193 prefix_list_init();
194
195 /* OSPFd inits. */
196 ospf_if_init();
197 ospf_zebra_init(master, instance);
198
199 /* OSPF vty inits. */
200 ospf_vty_init();
201 ospf_vty_show_init();
202 ospf_vty_clear_init();
203
204 /* OSPF BFD init */
205 ospf_bfd_init();
206
207 ospf_route_map_init();
208 ospf_opaque_init();
209
210 /* Need to initialize the default ospf structure, so the interface mode
211 commands can be duly processed if they are received before 'router
212 ospf',
213 when quagga(ospfd) is restarted */
214 if (!ospf_get_instance(instance)) {
215 zlog_err("OSPF instance init failed: %s", strerror(errno));
216 exit(1);
217 }
218
219 frr_config_fork();
220 frr_run(master);
221
222 /* Not reached. */
223 return (0);
224 }