]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_main.c
Merge pull request #7368 from eololab/add-pidfile-in-frr.service
[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, ZCAP_SYS_ADMIN};
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 = array_size(_caps_p),
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;
83 struct interface *ifp;
84 struct ospf6 *ospf6;
85 struct listnode *node, *nnode;
86
87 frr_early_fini();
88
89 for (ALL_LIST_ELEMENTS(om6->ospf6, node, nnode, ospf6)) {
90 vrf = vrf_lookup_by_id(ospf6->vrf_id);
91 ospf6_delete(ospf6);
92 ospf6 = NULL;
93 FOR_ALL_INTERFACES (vrf, ifp)
94 if (ifp->info != NULL)
95 ospf6_interface_delete(ifp->info);
96 }
97
98 bfd_gbl_exit();
99
100
101 ospf6_message_terminate();
102 ospf6_asbr_terminate();
103 ospf6_lsa_terminate();
104
105 /* reverse access_list_init */
106 access_list_reset();
107
108 /* reverse prefix_list_init */
109 prefix_list_add_hook(NULL);
110 prefix_list_delete_hook(NULL);
111 prefix_list_reset();
112
113 vrf_terminate();
114
115 if (zclient) {
116 zclient_stop(zclient);
117 zclient_free(zclient);
118 }
119
120 frr_fini();
121 exit(status);
122 }
123
124 /* SIGHUP handler. */
125 static void sighup(void)
126 {
127 zlog_info("SIGHUP received");
128 }
129
130 /* SIGINT handler. */
131 static void sigint(void)
132 {
133 zlog_notice("Terminating on signal SIGINT");
134 ospf6_exit(0);
135 }
136
137 /* SIGTERM handler. */
138 static void sigterm(void)
139 {
140 zlog_notice("Terminating on signal SIGTERM");
141 ospf6_exit(0);
142 }
143
144 /* SIGUSR1 handler. */
145 static void sigusr1(void)
146 {
147 zlog_info("SIGUSR1 received");
148 zlog_rotate();
149 }
150
151 struct quagga_signal_t ospf6_signals[] = {
152 {
153 .signal = SIGHUP,
154 .handler = &sighup,
155 },
156 {
157 .signal = SIGINT,
158 .handler = &sigint,
159 },
160 {
161 .signal = SIGTERM,
162 .handler = &sigterm,
163 },
164 {
165 .signal = SIGUSR1,
166 .handler = &sigusr1,
167 },
168 };
169
170 static const struct frr_yang_module_info *const ospf6d_yang_modules[] = {
171 &frr_filter_info,
172 &frr_interface_info,
173 &frr_route_map_info,
174 &frr_vrf_info,
175 };
176
177 FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT,
178
179 .proghelp = "Implementation of the OSPFv3 routing protocol.",
180
181 .signals = ospf6_signals,
182 .n_signals = array_size(ospf6_signals),
183
184 .privs = &ospf6d_privs, .yang_modules = ospf6d_yang_modules,
185 .n_yang_modules = array_size(ospf6d_yang_modules), )
186
187 /* Main routine of ospf6d. Treatment of argument and starting ospf finite
188 state machine is handled here. */
189 int main(int argc, char *argv[], char *envp[])
190 {
191 int opt;
192
193 frr_preinit(&ospf6d_di, argc, argv);
194 frr_opt_add("", longopts, "");
195
196 /* Command line argument treatment. */
197 while (1) {
198 opt = frr_getopt(argc, argv, NULL);
199
200 if (opt == EOF)
201 break;
202
203 switch (opt) {
204 case 0:
205 break;
206 default:
207 frr_help_exit(1);
208 break;
209 }
210 }
211
212 if (geteuid() != 0) {
213 errno = EPERM;
214 perror(ospf6d_di.progname);
215 exit(1);
216 }
217
218 /* OSPF6 master init. */
219 ospf6_master_init(frr_init());
220
221 /* thread master */
222 master = om6->master;
223
224 vrf_init(NULL, NULL, NULL, NULL, NULL);
225 access_list_init();
226 prefix_list_init();
227
228 /* initialize ospf6 */
229 ospf6_init(master);
230
231 frr_config_fork();
232 frr_run(master);
233
234 /* Not reached. */
235 ospf6_exit(0);
236 }