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