]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_main.c
0dacee8c2391a794b3d655d966772a27bd66b8b6
[mirror_frr.git] / ospfd / ospf_main.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * OSPFd main routine.
4 * Copyright (C) 1998, 99 Kunihiro Ishiguro, Toshiaki Takada
5 */
6
7 #include <zebra.h>
8
9 #include <lib/version.h>
10 #include "bfd.h"
11 #include "getopt.h"
12 #include "event.h"
13 #include "prefix.h"
14 #include "linklist.h"
15 #include "if.h"
16 #include "vector.h"
17 #include "vty.h"
18 #include "command.h"
19 #include "filter.h"
20 #include "plist.h"
21 #include "stream.h"
22 #include "log.h"
23 #include "memory.h"
24 #include "privs.h"
25 #include "sigevent.h"
26 #include "zclient.h"
27 #include "vrf.h"
28 #include "libfrr.h"
29 #include "routemap.h"
30
31 #include "ospfd/ospfd.h"
32 #include "ospfd/ospf_interface.h"
33 #include "ospfd/ospf_asbr.h"
34 #include "ospfd/ospf_lsa.h"
35 #include "ospfd/ospf_lsdb.h"
36 #include "ospfd/ospf_neighbor.h"
37 #include "ospfd/ospf_dump.h"
38 #include "ospfd/ospf_route.h"
39 #include "ospfd/ospf_zebra.h"
40 #include "ospfd/ospf_vty.h"
41 #include "ospfd/ospf_bfd.h"
42 #include "ospfd/ospf_gr.h"
43 #include "ospfd/ospf_errors.h"
44 #include "ospfd/ospf_ldp_sync.h"
45 #include "ospfd/ospf_routemap_nb.h"
46
47 /* ospfd privileges */
48 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN,
49 ZCAP_SYS_ADMIN};
50
51 struct zebra_privs_t ospfd_privs = {
52 #if defined(FRR_USER) && defined(FRR_GROUP)
53 .user = FRR_USER,
54 .group = FRR_GROUP,
55 #endif
56 #if defined(VTY_GROUP)
57 .vty_group = VTY_GROUP,
58 #endif
59 .caps_p = _caps_p,
60 .cap_num_p = array_size(_caps_p),
61 .cap_num_i = 0};
62
63 /* OSPFd options. */
64 const struct option longopts[] = {
65 {"instance", required_argument, NULL, 'n'},
66 {"apiserver", no_argument, NULL, 'a'},
67 {0}
68 };
69
70 /* OSPFd program name */
71
72 /* Master of threads. */
73 struct event_master *master;
74
75 #ifdef SUPPORT_OSPF_API
76 extern int ospf_apiserver_enable;
77 #endif /* SUPPORT_OSPF_API */
78
79 /* SIGHUP handler. */
80 static void sighup(void)
81 {
82 zlog_info("SIGHUP received");
83 }
84
85 /* SIGINT / SIGTERM handler. */
86 static void sigint(void)
87 {
88 zlog_notice("Terminating on signal");
89 bfd_protocol_integration_set_shutdown(true);
90 ospf_terminate();
91 exit(0);
92 }
93
94 /* SIGUSR1 handler. */
95 static void sigusr1(void)
96 {
97 zlog_rotate();
98 }
99
100 struct frr_signal_t ospf_signals[] = {
101 {
102 .signal = SIGHUP,
103 .handler = &sighup,
104 },
105 {
106 .signal = SIGUSR1,
107 .handler = &sigusr1,
108 },
109 {
110 .signal = SIGINT,
111 .handler = &sigint,
112 },
113 {
114 .signal = SIGTERM,
115 .handler = &sigint,
116 },
117 };
118
119 static const struct frr_yang_module_info *const ospfd_yang_modules[] = {
120 &frr_filter_info,
121 &frr_interface_info,
122 &frr_route_map_info,
123 &frr_vrf_info,
124 &frr_ospf_route_map_info,
125 };
126
127 FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT,
128
129 .proghelp = "Implementation of the OSPFv2 routing protocol.",
130
131 .signals = ospf_signals, .n_signals = array_size(ospf_signals),
132
133 .privs = &ospfd_privs, .yang_modules = ospfd_yang_modules,
134 .n_yang_modules = array_size(ospfd_yang_modules),
135 );
136
137 /* OSPFd main routine. */
138 int main(int argc, char **argv)
139 {
140 #ifdef SUPPORT_OSPF_API
141 /* OSPF apiserver is disabled by default. */
142 ospf_apiserver_enable = 0;
143 #endif /* SUPPORT_OSPF_API */
144
145 frr_preinit(&ospfd_di, argc, argv);
146 frr_opt_add("n:a", longopts,
147 " -n, --instance Set the instance id\n"
148 " -a, --apiserver Enable OSPF apiserver\n");
149
150 while (1) {
151 int opt;
152
153 opt = frr_getopt(argc, argv, NULL);
154
155 if (opt == EOF)
156 break;
157
158 switch (opt) {
159 case 'n':
160 ospfd_di.instance = ospf_instance = atoi(optarg);
161 if (ospf_instance < 1)
162 exit(0);
163 break;
164 case 0:
165 break;
166 #ifdef SUPPORT_OSPF_API
167 case 'a':
168 ospf_apiserver_enable = 1;
169 break;
170 #endif /* SUPPORT_OSPF_API */
171 default:
172 frr_help_exit(1);
173 }
174 }
175
176 /* Invoked by a priviledged user? -- endo. */
177 if (geteuid() != 0) {
178 errno = EPERM;
179 perror(ospfd_di.progname);
180 exit(1);
181 }
182
183 /* OSPF master init. */
184 ospf_master_init(frr_init());
185
186 /* Initializations. */
187 master = om->master;
188
189 /* Library inits. */
190 ospf_debug_init();
191 ospf_vrf_init();
192
193 access_list_init();
194 prefix_list_init();
195
196 /* OSPFd inits. */
197 ospf_if_init();
198 ospf_zebra_init(master, ospf_instance);
199
200 /* OSPF vty inits. */
201 ospf_vty_init();
202 ospf_vty_show_init();
203 ospf_vty_clear_init();
204
205 /* OSPF BFD init */
206 ospf_bfd_init(master);
207
208 /* OSPF LDP IGP Sync init */
209 ospf_ldp_sync_init();
210
211 ospf_route_map_init();
212 ospf_opaque_init();
213 ospf_gr_init();
214 ospf_gr_helper_init();
215
216 /* OSPF errors init */
217 ospf_error_init();
218
219 frr_config_fork();
220 frr_run(master);
221
222 /* Not reached. */
223 return 0;
224 }