]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_main.c
vtysh: Sort ordering of vtysh_cmd.c
[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)
113 zclient_free (zclient);
114
115 if (master)
116 thread_master_free (master);
117
bf1013e6 118 closezlog ();
ae2254aa
TG
119
120 exit (status);
121}
122
718e3744 123/* SIGHUP handler. */
6ac29a51 124static void
e42f5a37 125sighup (void)
718e3744 126{
127 zlog_info ("SIGHUP received");
718e3744 128}
129
130/* SIGINT handler. */
6ac29a51 131static void
e42f5a37 132sigint (void)
718e3744 133{
887c44a4 134 zlog_notice ("Terminating on signal SIGINT");
ae2254aa 135 ospf6_exit (0);
718e3744 136}
137
138/* SIGTERM handler. */
6ac29a51 139static void
e42f5a37 140sigterm (void)
718e3744 141{
887c44a4 142 zlog_notice ("Terminating on signal SIGTERM");
ef2d5d10 143 ospf6_clean();
ae2254aa 144 ospf6_exit (0);
718e3744 145}
146
147/* SIGUSR1 handler. */
6ac29a51 148static void
e42f5a37 149sigusr1 (void)
718e3744 150{
151 zlog_info ("SIGUSR1 received");
dd8376fe 152 zlog_rotate();
718e3744 153}
154
e42f5a37 155struct quagga_signal_t ospf6_signals[] =
718e3744 156{
e42f5a37 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};
508e53e2 174
4f04a76b
DL
175FRR_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
508e53e2 186/* Main routine of ospf6d. Treatment of argument and starting ospf finite
718e3744 187 state machine is handled here. */
188int
189main (int argc, char *argv[], char *envp[])
190{
718e3744 191 int opt;
718e3744 192
4f04a76b 193 frr_preinit (&ospf6d_di, argc, argv);
eb05883f 194 frr_opt_add ("", longopts, "");
c3c0ac83 195
718e3744 196 /* Command line argument treatment. */
197 while (1)
198 {
4f04a76b 199 opt = frr_getopt (argc, argv, NULL);
718e3744 200
201 if (opt == EOF)
202 break;
203
204 switch (opt)
205 {
206 case 0:
207 break;
718e3744 208 default:
4f04a76b 209 frr_help_exit (1);
718e3744 210 break;
211 }
212 }
213
6fd16207
VT
214 if (geteuid () != 0)
215 {
216 errno = EPERM;
4f04a76b 217 perror (ospf6d_di.progname);
6fd16207
VT
218 exit (1);
219 }
220
718e3744 221 /* thread master */
4f04a76b 222 master = frr_init ();
2caa9b39 223
6df85364 224 vrf_init (NULL, NULL, NULL, NULL);
508e53e2 225 access_list_init ();
226 prefix_list_init ();
227
228 /* initialize ospf6 */
229 ospf6_init ();
230
eb05883f 231 frr_config_fork ();
16077f2f 232 frr_run (master);
718e3744 233
234 /* Not reached. */
ae2254aa 235 ospf6_exit (0);
718e3744 236}
237
508e53e2 238