]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_main.c
Merge branch stable/2.0 into stable/3.0
[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
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22 #include <zebra.h>
23 #include <lib/version.h>
24 #include <stdlib.h>
25
26 #include "getopt.h"
27 #include "thread.h"
28 #include "log.h"
29 #include "command.h"
30 #include "vty.h"
31 #include "memory.h"
32 #include "memory_vty.h"
33 #include "if.h"
34 #include "filter.h"
35 #include "prefix.h"
36 #include "plist.h"
37 #include "privs.h"
38 #include "sigevent.h"
39 #include "zclient.h"
40 #include "vrf.h"
41 #include "bfd.h"
42 #include "libfrr.h"
43
44 #include "ospf6d.h"
45 #include "ospf6_top.h"
46 #include "ospf6_message.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 [] =
60 {
61 ZCAP_NET_RAW,
62 ZCAP_BIND
63 };
64
65 struct zebra_privs_t ospf6d_privs =
66 {
67 #if defined(FRR_USER)
68 .user = FRR_USER,
69 #endif
70 #if defined FRR_GROUP
71 .group = FRR_GROUP,
72 #endif
73 #ifdef VTY_GROUP
74 .vty_group = VTY_GROUP,
75 #endif
76 .caps_p = _caps_p,
77 .cap_num_p = 2,
78 .cap_num_i = 0
79 };
80
81 /* ospf6d options, we use GNU getopt library. */
82 struct option longopts[] =
83 {
84 { 0 }
85 };
86
87 /* Master of threads. */
88 struct thread_master *master;
89
90 static void __attribute__ ((noreturn))
91 ospf6_exit (int status)
92 {
93 struct listnode *node;
94 struct interface *ifp;
95
96 if (ospf6)
97 ospf6_delete (ospf6);
98
99 bfd_gbl_exit();
100
101 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
102 if (ifp->info != NULL)
103 ospf6_interface_delete(ifp->info);
104
105 ospf6_message_terminate ();
106 ospf6_asbr_terminate ();
107 ospf6_lsa_terminate ();
108
109 vrf_terminate ();
110 vty_terminate ();
111 cmd_terminate ();
112
113 if (zclient)
114 zclient_free (zclient);
115
116 if (master)
117 thread_master_free (master);
118
119 closezlog ();
120
121 exit (status);
122 }
123
124 /* SIGHUP handler. */
125 static void
126 sighup (void)
127 {
128 zlog_info ("SIGHUP received");
129 }
130
131 /* SIGINT handler. */
132 static void
133 sigint (void)
134 {
135 zlog_notice ("Terminating on signal SIGINT");
136 ospf6_exit (0);
137 }
138
139 /* SIGTERM handler. */
140 static void
141 sigterm (void)
142 {
143 zlog_notice ("Terminating on signal SIGTERM");
144 ospf6_clean();
145 ospf6_exit (0);
146 }
147
148 /* SIGUSR1 handler. */
149 static void
150 sigusr1 (void)
151 {
152 zlog_info ("SIGUSR1 received");
153 zlog_rotate();
154 }
155
156 struct quagga_signal_t ospf6_signals[] =
157 {
158 {
159 .signal = SIGHUP,
160 .handler = &sighup,
161 },
162 {
163 .signal = SIGINT,
164 .handler = &sigint,
165 },
166 {
167 .signal = SIGTERM,
168 .handler = &sigterm,
169 },
170 {
171 .signal = SIGUSR1,
172 .handler = &sigusr1,
173 },
174 };
175
176 FRR_DAEMON_INFO(ospf6d, OSPF6,
177 .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,
185 )
186
187 /* Main routine of ospf6d. Treatment of argument and starting ospf finite
188 state machine is handled here. */
189 int
190 main (int argc, char *argv[], char *envp[])
191 {
192 int opt;
193
194 frr_preinit (&ospf6d_di, argc, argv);
195 frr_opt_add ("", longopts, "");
196
197 /* Command line argument treatment. */
198 while (1)
199 {
200 opt = frr_getopt (argc, argv, NULL);
201
202 if (opt == EOF)
203 break;
204
205 switch (opt)
206 {
207 case 0:
208 break;
209 default:
210 frr_help_exit (1);
211 break;
212 }
213 }
214
215 if (geteuid () != 0)
216 {
217 errno = EPERM;
218 perror (ospf6d_di.progname);
219 exit (1);
220 }
221
222 /* thread master */
223 master = frr_init ();
224
225 vrf_init ();
226 access_list_init ();
227 prefix_list_init ();
228
229 /* initialize ospf6 */
230 ospf6_init ();
231
232 frr_config_fork ();
233 frr_run (master);
234
235 /* Not reached. */
236 ospf6_exit (0);
237 }
238
239