]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_main.c
Merge remote-tracking branch 'origin/master' into babel
[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 zclient_free (zclient);
114
115 if (master)
116 thread_master_free (master);
117
118 closezlog ();
119
120 exit (status);
121 }
122
123 /* SIGHUP handler. */
124 static void
125 sighup (void)
126 {
127 zlog_info ("SIGHUP received");
128 }
129
130 /* SIGINT handler. */
131 static void
132 sigint (void)
133 {
134 zlog_notice ("Terminating on signal SIGINT");
135 ospf6_exit (0);
136 }
137
138 /* SIGTERM handler. */
139 static void
140 sigterm (void)
141 {
142 zlog_notice ("Terminating on signal SIGTERM");
143 ospf6_clean();
144 ospf6_exit (0);
145 }
146
147 /* SIGUSR1 handler. */
148 static void
149 sigusr1 (void)
150 {
151 zlog_info ("SIGUSR1 received");
152 zlog_rotate();
153 }
154
155 struct quagga_signal_t ospf6_signals[] =
156 {
157 {
158 .signal = SIGHUP,
159 .handler = &sighup,
160 },
161 {
162 .signal = SIGINT,
163 .handler = &sigint,
164 },
165 {
166 .signal = SIGTERM,
167 .handler = &sigterm,
168 },
169 {
170 .signal = SIGUSR1,
171 .handler = &sigusr1,
172 },
173 };
174
175 FRR_DAEMON_INFO(ospf6d, OSPF6,
176 .vty_port = OSPF6_VTY_PORT,
177
178 .proghelp = "Implementation of the OSPFv3 routing protocol.",
179
180 .signals = ospf6_signals,
181 .n_signals = array_size(ospf6_signals),
182
183 .privs = &ospf6d_privs,
184 )
185
186 /* Main routine of ospf6d. Treatment of argument and starting ospf finite
187 state machine is handled here. */
188 int
189 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 {
199 opt = frr_getopt (argc, argv, NULL);
200
201 if (opt == EOF)
202 break;
203
204 switch (opt)
205 {
206 case 0:
207 break;
208 default:
209 frr_help_exit (1);
210 break;
211 }
212 }
213
214 if (geteuid () != 0)
215 {
216 errno = EPERM;
217 perror (ospf6d_di.progname);
218 exit (1);
219 }
220
221 /* thread master */
222 master = frr_init ();
223
224 vrf_init (NULL, NULL, NULL, NULL);
225 access_list_init ();
226 prefix_list_init ();
227
228 /* initialize ospf6 */
229 ospf6_init ();
230
231 frr_config_fork ();
232 frr_run (master);
233
234 /* Not reached. */
235 ospf6_exit (0);
236 }
237
238