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