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