]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_main.c
Merge pull request #12075 from donaldsharp/highline
[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>
b25bd2ad 23#include <lib/keychain.h>
c3c0ac83 24#include <stdlib.h>
508e53e2 25
718e3744 26#include "getopt.h"
27#include "thread.h"
28#include "log.h"
718e3744 29#include "command.h"
30#include "vty.h"
31#include "memory.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"
d51884e6 46#include "ospf6_network.h"
87362ceb
DO
47#include "ospf6_asbr.h"
48#include "ospf6_lsa.h"
d9628728
CF
49#include "ospf6_interface.h"
50#include "ospf6_zebra.h"
078110ca 51#include "ospf6_routemap_nb.h"
718e3744 52
53/* Default configuration file name for ospf6d. */
54#define OSPF6_DEFAULT_CONFIG "ospf6d.conf"
508e53e2 55
718e3744 56/* Default port values. */
57#define OSPF6_VTY_PORT 2606
58
edd7c245 59/* ospf6d privileges */
7df1f362 60zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
edd7c245 61
d62a17ae 62struct zebra_privs_t ospf6d_privs = {
b2f36157 63#if defined(FRR_USER)
d62a17ae 64 .user = FRR_USER,
edd7c245 65#endif
b2f36157 66#if defined FRR_GROUP
d62a17ae 67 .group = FRR_GROUP,
d81fadfd 68#endif
69#ifdef VTY_GROUP
d62a17ae 70 .vty_group = VTY_GROUP,
edd7c245 71#endif
d62a17ae 72 .caps_p = _caps_p,
7df1f362 73 .cap_num_p = array_size(_caps_p),
d62a17ae 74 .cap_num_i = 0};
edd7c245 75
718e3744 76/* ospf6d options, we use GNU getopt library. */
d62a17ae 77struct option longopts[] = {{0}};
718e3744 78
718e3744 79/* Master of threads. */
80struct thread_master *master;
81
d62a17ae 82static void __attribute__((noreturn)) ospf6_exit(int status)
ae2254aa 83{
c5d28568 84 struct vrf *vrf;
d62a17ae 85 struct interface *ifp;
beadc736 86 struct ospf6 *ospf6;
87 struct listnode *node, *nnode;
ae2254aa 88
03951374
DL
89 frr_early_fini();
90
c97b34cf
IR
91 bfd_protocol_integration_set_shutdown(true);
92
beadc736 93 for (ALL_LIST_ELEMENTS(om6->ospf6, node, nnode, ospf6)) {
c5d28568 94 vrf = vrf_lookup_by_id(ospf6->vrf_id);
d3136990
IR
95 ospf6_delete(ospf6);
96 ospf6 = NULL;
beadc736 97 FOR_ALL_INTERFACES (vrf, ifp)
98 if (ifp->info != NULL)
99 ospf6_interface_delete(ifp->info);
beadc736 100 }
ae2254aa 101
d62a17ae 102 ospf6_message_terminate();
103 ospf6_asbr_terminate();
104 ospf6_lsa_terminate();
ae2254aa 105
856ae1eb
CS
106 /* reverse access_list_init */
107 access_list_reset();
108
109 /* reverse prefix_list_init */
110 prefix_list_add_hook(NULL);
111 prefix_list_delete_hook(NULL);
112 prefix_list_reset();
113
d62a17ae 114 vrf_terminate();
ae2254aa 115
d62a17ae 116 if (zclient) {
117 zclient_stop(zclient);
118 zclient_free(zclient);
119 }
ae2254aa 120
03951374 121 frr_fini();
d62a17ae 122 exit(status);
ae2254aa
TG
123}
124
718e3744 125/* SIGHUP handler. */
d62a17ae 126static void sighup(void)
718e3744 127{
d62a17ae 128 zlog_info("SIGHUP received");
718e3744 129}
130
131/* SIGINT handler. */
d62a17ae 132static void sigint(void)
718e3744 133{
d62a17ae 134 zlog_notice("Terminating on signal SIGINT");
135 ospf6_exit(0);
718e3744 136}
137
138/* SIGTERM handler. */
d62a17ae 139static void sigterm(void)
718e3744 140{
d62a17ae 141 zlog_notice("Terminating on signal SIGTERM");
d62a17ae 142 ospf6_exit(0);
718e3744 143}
144
145/* SIGUSR1 handler. */
d62a17ae 146static void sigusr1(void)
718e3744 147{
d62a17ae 148 zlog_info("SIGUSR1 received");
149 zlog_rotate();
718e3744 150}
151
7cc91e67 152struct frr_signal_t ospf6_signals[] = {
d62a17ae 153 {
154 .signal = SIGHUP,
155 .handler = &sighup,
156 },
157 {
158 .signal = SIGINT,
159 .handler = &sigint,
160 },
161 {
162 .signal = SIGTERM,
163 .handler = &sigterm,
164 },
165 {
166 .signal = SIGUSR1,
167 .handler = &sigusr1,
168 },
e42f5a37 169};
508e53e2 170
0d8c7a26 171static const struct frr_yang_module_info *const ospf6d_yang_modules[] = {
c2aab693 172 &frr_filter_info,
a4bed468 173 &frr_interface_info,
91835f1f 174 &frr_route_map_info,
6fd8972a 175 &frr_vrf_info,
078110ca
SP
176 &frr_ospf_route_map_info,
177 &frr_ospf6_route_map_info,
8fcdd0d6
RW
178};
179
d62a17ae 180FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT,
4f04a76b 181
d62a17ae 182 .proghelp = "Implementation of the OSPFv3 routing protocol.",
4f04a76b 183
d62a17ae 184 .signals = ospf6_signals,
185 .n_signals = array_size(ospf6_signals),
4f04a76b 186
8fcdd0d6 187 .privs = &ospf6d_privs, .yang_modules = ospf6d_yang_modules,
80413c20
DL
188 .n_yang_modules = array_size(ospf6d_yang_modules),
189);
4f04a76b 190
508e53e2 191/* Main routine of ospf6d. Treatment of argument and starting ospf finite
718e3744 192 state machine is handled here. */
d62a17ae 193int main(int argc, char *argv[], char *envp[])
718e3744 194{
d62a17ae 195 int opt;
196
197 frr_preinit(&ospf6d_di, argc, argv);
198 frr_opt_add("", longopts, "");
718e3744 199
d62a17ae 200 /* Command line argument treatment. */
201 while (1) {
202 opt = frr_getopt(argc, argv, NULL);
508e53e2 203
d62a17ae 204 if (opt == EOF)
205 break;
206
207 switch (opt) {
208 case 0:
209 break;
210 default:
211 frr_help_exit(1);
d62a17ae 212 }
213 }
214
215 if (geteuid() != 0) {
216 errno = EPERM;
217 perror(ospf6d_di.progname);
218 exit(1);
219 }
220
78c6ba61 221 /* OSPF6 master init. */
beadc736 222 ospf6_master_init(frr_init());
78c6ba61 223
d62a17ae 224 /* thread master */
beadc736 225 master = om6->master;
d62a17ae 226
b25bd2ad 227 keychain_init();
4e8ccd92 228 ospf6_vrf_init();
d62a17ae 229 access_list_init();
230 prefix_list_init();
231
232 /* initialize ospf6 */
beadc736 233 ospf6_init(master);
d62a17ae 234
235 frr_config_fork();
236 frr_run(master);
237
238 /* Not reached. */
239 ospf6_exit(0);
240}