]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_main.c
Merge pull request #5666 from donaldsharp/more_nhg_fixes
[mirror_frr.git] / ospf6d / ospf6_main.c
1 /*
2 * Copyright (C) 1999 Yasuhiro Ohara
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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22 #include <lib/version.h>
23 #include <stdlib.h>
24
25 #include "getopt.h"
26 #include "thread.h"
27 #include "log.h"
28 #include "command.h"
29 #include "vty.h"
30 #include "memory.h"
31 #include "if.h"
32 #include "filter.h"
33 #include "prefix.h"
34 #include "plist.h"
35 #include "privs.h"
36 #include "sigevent.h"
37 #include "zclient.h"
38 #include "vrf.h"
39 #include "bfd.h"
40 #include "libfrr.h"
41
42 #include "ospf6d.h"
43 #include "ospf6_top.h"
44 #include "ospf6_message.h"
45 #include "ospf6_network.h"
46 #include "ospf6_asbr.h"
47 #include "ospf6_lsa.h"
48 #include "ospf6_interface.h"
49 #include "ospf6_zebra.h"
50
51 /* Default configuration file name for ospf6d. */
52 #define OSPF6_DEFAULT_CONFIG "ospf6d.conf"
53
54 /* Default port values. */
55 #define OSPF6_VTY_PORT 2606
56
57 /* ospf6d privileges */
58 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND};
59
60 struct zebra_privs_t ospf6d_privs = {
61 #if defined(FRR_USER)
62 .user = FRR_USER,
63 #endif
64 #if defined FRR_GROUP
65 .group = FRR_GROUP,
66 #endif
67 #ifdef VTY_GROUP
68 .vty_group = VTY_GROUP,
69 #endif
70 .caps_p = _caps_p,
71 .cap_num_p = 2,
72 .cap_num_i = 0};
73
74 /* ospf6d options, we use GNU getopt library. */
75 struct option longopts[] = {{0}};
76
77 /* Master of threads. */
78 struct thread_master *master;
79
80 static void __attribute__((noreturn)) ospf6_exit(int status)
81 {
82 struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
83 struct interface *ifp;
84
85 frr_early_fini();
86
87 if (ospf6) {
88 ospf6_delete(ospf6);
89 ospf6 = NULL;
90 }
91
92 bfd_gbl_exit();
93
94 FOR_ALL_INTERFACES (vrf, ifp)
95 if (ifp->info != NULL)
96 ospf6_interface_delete(ifp->info);
97
98 ospf6_message_terminate();
99 ospf6_asbr_terminate();
100 ospf6_lsa_terminate();
101
102 ospf6_serv_close();
103 /* reverse access_list_init */
104 access_list_reset();
105
106 /* reverse prefix_list_init */
107 prefix_list_add_hook(NULL);
108 prefix_list_delete_hook(NULL);
109 prefix_list_reset();
110
111 vrf_terminate();
112
113 if (zclient) {
114 zclient_stop(zclient);
115 zclient_free(zclient);
116 }
117
118 frr_fini();
119 exit(status);
120 }
121
122 /* SIGHUP handler. */
123 static void sighup(void)
124 {
125 zlog_info("SIGHUP received");
126 }
127
128 /* SIGINT handler. */
129 static void sigint(void)
130 {
131 zlog_notice("Terminating on signal SIGINT");
132 ospf6_exit(0);
133 }
134
135 /* SIGTERM handler. */
136 static void sigterm(void)
137 {
138 zlog_notice("Terminating on signal SIGTERM");
139 ospf6_exit(0);
140 }
141
142 /* SIGUSR1 handler. */
143 static void sigusr1(void)
144 {
145 zlog_info("SIGUSR1 received");
146 zlog_rotate();
147 }
148
149 struct quagga_signal_t ospf6_signals[] = {
150 {
151 .signal = SIGHUP,
152 .handler = &sighup,
153 },
154 {
155 .signal = SIGINT,
156 .handler = &sigint,
157 },
158 {
159 .signal = SIGTERM,
160 .handler = &sigterm,
161 },
162 {
163 .signal = SIGUSR1,
164 .handler = &sigusr1,
165 },
166 };
167
168 static const struct frr_yang_module_info *const ospf6d_yang_modules[] = {
169 &frr_interface_info,
170 };
171
172 FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT,
173
174 .proghelp = "Implementation of the OSPFv3 routing protocol.",
175
176 .signals = ospf6_signals,
177 .n_signals = array_size(ospf6_signals),
178
179 .privs = &ospf6d_privs, .yang_modules = ospf6d_yang_modules,
180 .n_yang_modules = array_size(ospf6d_yang_modules), )
181
182 /* Main routine of ospf6d. Treatment of argument and starting ospf finite
183 state machine is handled here. */
184 int main(int argc, char *argv[], char *envp[])
185 {
186 int opt;
187
188 frr_preinit(&ospf6d_di, argc, argv);
189 frr_opt_add("", longopts, "");
190
191 /* Command line argument treatment. */
192 while (1) {
193 opt = frr_getopt(argc, argv, NULL);
194
195 if (opt == EOF)
196 break;
197
198 switch (opt) {
199 case 0:
200 break;
201 default:
202 frr_help_exit(1);
203 break;
204 }
205 }
206
207 if (geteuid() != 0) {
208 errno = EPERM;
209 perror(ospf6d_di.progname);
210 exit(1);
211 }
212
213 /* OSPF6 master init. */
214 ospf6_master_init();
215
216 /* thread master */
217 master = frr_init();
218
219 vrf_init(NULL, NULL, NULL, NULL, NULL);
220 access_list_init();
221 prefix_list_init();
222
223 /* initialize ospf6 */
224 ospf6_init();
225
226 frr_config_fork();
227 frr_run(master);
228
229 /* Not reached. */
230 ospf6_exit(0);
231 }