]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_main.c
*: add indent control files
[mirror_frr.git] / ospf6d / ospf6_main.c
CommitLineData
718e3744 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 *
896014f4
DL
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
718e3744 19 */
20
21#include <zebra.h>
3b4cd3a9 22#include <lib/version.h>
c3c0ac83 23#include <stdlib.h>
508e53e2 24
718e3744 25#include "getopt.h"
26#include "thread.h"
27#include "log.h"
718e3744 28#include "command.h"
29#include "vty.h"
30#include "memory.h"
fc7948fa 31#include "memory_vty.h"
508e53e2 32#include "if.h"
33#include "filter.h"
34#include "prefix.h"
35#include "plist.h"
edd7c245 36#include "privs.h"
e42f5a37 37#include "sigevent.h"
87362ceb 38#include "zclient.h"
6a69b354 39#include "vrf.h"
567b877d 40#include "bfd.h"
4f04a76b 41#include "libfrr.h"
718e3744 42
43#include "ospf6d.h"
87362ceb
DO
44#include "ospf6_top.h"
45#include "ospf6_message.h"
46#include "ospf6_asbr.h"
47#include "ospf6_lsa.h"
d9628728
CF
48#include "ospf6_interface.h"
49#include "ospf6_zebra.h"
718e3744 50
51/* Default configuration file name for ospf6d. */
52#define OSPF6_DEFAULT_CONFIG "ospf6d.conf"
508e53e2 53
718e3744 54/* Default port values. */
55#define OSPF6_VTY_PORT 2606
56
edd7c245 57/* ospf6d privileges */
508e53e2 58zebra_capabilities_t _caps_p [] =
edd7c245 59{
ceacedba 60 ZCAP_NET_RAW,
edd7c245 61 ZCAP_BIND
62};
63
64struct zebra_privs_t ospf6d_privs =
65{
b2f36157
DL
66#if defined(FRR_USER)
67 .user = FRR_USER,
edd7c245 68#endif
b2f36157
DL
69#if defined FRR_GROUP
70 .group = FRR_GROUP,
d81fadfd 71#endif
72#ifdef VTY_GROUP
73 .vty_group = VTY_GROUP,
edd7c245 74#endif
75 .caps_p = _caps_p,
76 .cap_num_p = 2,
77 .cap_num_i = 0
78};
79
718e3744 80/* ospf6d options, we use GNU getopt library. */
81struct option longopts[] =
82{
718e3744 83 { 0 }
84};
85
718e3744 86/* Master of threads. */
87struct thread_master *master;
88
c143c38b 89static void __attribute__ ((noreturn))
ae2254aa
TG
90ospf6_exit (int status)
91{
d9628728
CF
92 struct listnode *node;
93 struct interface *ifp;
ae2254aa
TG
94
95 if (ospf6)
96 ospf6_delete (ospf6);
97
567b877d 98 bfd_gbl_exit();
99
b2d7c082 100 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
d9628728
CF
101 if (ifp->info != NULL)
102 ospf6_interface_delete(ifp->info);
103
ae2254aa
TG
104 ospf6_message_terminate ();
105 ospf6_asbr_terminate ();
106 ospf6_lsa_terminate ();
107
6a69b354 108 vrf_terminate ();
ae2254aa
TG
109 vty_terminate ();
110 cmd_terminate ();
111
112 if (zclient)
e49b20ce
DS
113 {
114 zclient_stop (zclient);
115 zclient_free (zclient);
116 }
ae2254aa
TG
117
118 if (master)
119 thread_master_free (master);
120
bf1013e6 121 closezlog ();
ae2254aa
TG
122
123 exit (status);
124}
125
718e3744 126/* SIGHUP handler. */
6ac29a51 127static void
e42f5a37 128sighup (void)
718e3744 129{
130 zlog_info ("SIGHUP received");
718e3744 131}
132
133/* SIGINT handler. */
6ac29a51 134static void
e42f5a37 135sigint (void)
718e3744 136{
887c44a4 137 zlog_notice ("Terminating on signal SIGINT");
ae2254aa 138 ospf6_exit (0);
718e3744 139}
140
141/* SIGTERM handler. */
6ac29a51 142static void
e42f5a37 143sigterm (void)
718e3744 144{
887c44a4 145 zlog_notice ("Terminating on signal SIGTERM");
ef2d5d10 146 ospf6_clean();
ae2254aa 147 ospf6_exit (0);
718e3744 148}
149
150/* SIGUSR1 handler. */
6ac29a51 151static void
e42f5a37 152sigusr1 (void)
718e3744 153{
154 zlog_info ("SIGUSR1 received");
dd8376fe 155 zlog_rotate();
718e3744 156}
157
e42f5a37 158struct quagga_signal_t ospf6_signals[] =
718e3744 159{
e42f5a37 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};
508e53e2 177
4f04a76b
DL
178FRR_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
508e53e2 189/* Main routine of ospf6d. Treatment of argument and starting ospf finite
718e3744 190 state machine is handled here. */
191int
192main (int argc, char *argv[], char *envp[])
193{
718e3744 194 int opt;
718e3744 195
4f04a76b 196 frr_preinit (&ospf6d_di, argc, argv);
eb05883f 197 frr_opt_add ("", longopts, "");
c3c0ac83 198
718e3744 199 /* Command line argument treatment. */
200 while (1)
201 {
4f04a76b 202 opt = frr_getopt (argc, argv, NULL);
718e3744 203
204 if (opt == EOF)
205 break;
206
207 switch (opt)
208 {
209 case 0:
210 break;
718e3744 211 default:
4f04a76b 212 frr_help_exit (1);
718e3744 213 break;
214 }
215 }
216
6fd16207
VT
217 if (geteuid () != 0)
218 {
219 errno = EPERM;
4f04a76b 220 perror (ospf6d_di.progname);
6fd16207
VT
221 exit (1);
222 }
223
718e3744 224 /* thread master */
4f04a76b 225 master = frr_init ();
2caa9b39 226
6df85364 227 vrf_init (NULL, NULL, NULL, NULL);
508e53e2 228 access_list_init ();
229 prefix_list_init ();
230
231 /* initialize ospf6 */
232 ospf6_init ();
233
eb05883f 234 frr_config_fork ();
16077f2f 235 frr_run (master);
718e3744 236
237 /* Not reached. */
ae2254aa 238 ospf6_exit (0);
718e3744 239}
240
508e53e2 241