]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_main.c
Merge branch 'master' of https://github.com/dwalton76/frr into bgpd-ipv4-plus-label...
[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 [] =
59 {
60 ZCAP_NET_RAW,
61 ZCAP_BIND
62 };
63
64 struct zebra_privs_t ospf6d_privs =
65 {
66 #if defined(FRR_USER)
67 .user = FRR_USER,
68 #endif
69 #if defined FRR_GROUP
70 .group = FRR_GROUP,
71 #endif
72 #ifdef VTY_GROUP
73 .vty_group = VTY_GROUP,
74 #endif
75 .caps_p = _caps_p,
76 .cap_num_p = 2,
77 .cap_num_i = 0
78 };
79
80 /* ospf6d options, we use GNU getopt library. */
81 struct option longopts[] =
82 {
83 { 0 }
84 };
85
86 /* Master of threads. */
87 struct thread_master *master;
88
89 static void __attribute__ ((noreturn))
90 ospf6_exit (int status)
91 {
92 struct listnode *node;
93 struct interface *ifp;
94
95 if (ospf6)
96 ospf6_delete (ospf6);
97
98 bfd_gbl_exit();
99
100 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
101 if (ifp->info != NULL)
102 ospf6_interface_delete(ifp->info);
103
104 ospf6_message_terminate ();
105 ospf6_asbr_terminate ();
106 ospf6_lsa_terminate ();
107
108 vrf_terminate ();
109 vty_terminate ();
110 cmd_terminate ();
111
112 if (zclient)
113 {
114 zclient_stop (zclient);
115 zclient_free (zclient);
116 }
117
118 if (master)
119 thread_master_free (master);
120
121 closezlog ();
122
123 exit (status);
124 }
125
126 /* SIGHUP handler. */
127 static void
128 sighup (void)
129 {
130 zlog_info ("SIGHUP received");
131 }
132
133 /* SIGINT handler. */
134 static void
135 sigint (void)
136 {
137 zlog_notice ("Terminating on signal SIGINT");
138 ospf6_exit (0);
139 }
140
141 /* SIGTERM handler. */
142 static void
143 sigterm (void)
144 {
145 zlog_notice ("Terminating on signal SIGTERM");
146 ospf6_clean();
147 ospf6_exit (0);
148 }
149
150 /* SIGUSR1 handler. */
151 static void
152 sigusr1 (void)
153 {
154 zlog_info ("SIGUSR1 received");
155 zlog_rotate();
156 }
157
158 struct quagga_signal_t ospf6_signals[] =
159 {
160 {
161 .signal = SIGHUP,
162 .handler = &sighup,
163 },
164 {
165 .signal = SIGINT,
166 .handler = &sigint,
167 },
168 {
169 .signal = SIGTERM,
170 .handler = &sigterm,
171 },
172 {
173 .signal = SIGUSR1,
174 .handler = &sigusr1,
175 },
176 };
177
178 FRR_DAEMON_INFO(ospf6d, OSPF6,
179 .vty_port = OSPF6_VTY_PORT,
180
181 .proghelp = "Implementation of the OSPFv3 routing protocol.",
182
183 .signals = ospf6_signals,
184 .n_signals = array_size(ospf6_signals),
185
186 .privs = &ospf6d_privs,
187 )
188
189 /* Main routine of ospf6d. Treatment of argument and starting ospf finite
190 state machine is handled here. */
191 int
192 main (int argc, char *argv[], char *envp[])
193 {
194 int opt;
195
196 frr_preinit (&ospf6d_di, argc, argv);
197 frr_opt_add ("", longopts, "");
198
199 /* Command line argument treatment. */
200 while (1)
201 {
202 opt = frr_getopt (argc, argv, NULL);
203
204 if (opt == EOF)
205 break;
206
207 switch (opt)
208 {
209 case 0:
210 break;
211 default:
212 frr_help_exit (1);
213 break;
214 }
215 }
216
217 if (geteuid () != 0)
218 {
219 errno = EPERM;
220 perror (ospf6d_di.progname);
221 exit (1);
222 }
223
224 /* thread master */
225 master = frr_init ();
226
227 vrf_init (NULL, NULL, NULL, NULL);
228 access_list_init ();
229 prefix_list_init ();
230
231 /* initialize ospf6 */
232 ospf6_init ();
233
234 frr_config_fork ();
235 frr_run (master);
236
237 /* Not reached. */
238 ospf6_exit (0);
239 }
240
241