]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_main.c
*: use rb-trees to store interfaces instead of sorted linked-lists
[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 */
d62a17ae 58zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND};
edd7c245 59
d62a17ae 60struct zebra_privs_t ospf6d_privs = {
b2f36157 61#if defined(FRR_USER)
d62a17ae 62 .user = FRR_USER,
edd7c245 63#endif
b2f36157 64#if defined FRR_GROUP
d62a17ae 65 .group = FRR_GROUP,
d81fadfd 66#endif
67#ifdef VTY_GROUP
d62a17ae 68 .vty_group = VTY_GROUP,
edd7c245 69#endif
d62a17ae 70 .caps_p = _caps_p,
71 .cap_num_p = 2,
72 .cap_num_i = 0};
edd7c245 73
718e3744 74/* ospf6d options, we use GNU getopt library. */
d62a17ae 75struct option longopts[] = {{0}};
718e3744 76
718e3744 77/* Master of threads. */
78struct thread_master *master;
79
d62a17ae 80static void __attribute__((noreturn)) ospf6_exit(int status)
ae2254aa 81{
f4e14fdb 82 struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
d62a17ae 83 struct interface *ifp;
ae2254aa 84
03951374
DL
85 frr_early_fini();
86
d62a17ae 87 if (ospf6)
88 ospf6_delete(ospf6);
ae2254aa 89
d62a17ae 90 bfd_gbl_exit();
567b877d 91
f4e14fdb 92 RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name)
d62a17ae 93 if (ifp->info != NULL)
94 ospf6_interface_delete(ifp->info);
d9628728 95
d62a17ae 96 ospf6_message_terminate();
97 ospf6_asbr_terminate();
98 ospf6_lsa_terminate();
ae2254aa 99
d62a17ae 100 vrf_terminate();
ae2254aa 101
d62a17ae 102 if (zclient) {
103 zclient_stop(zclient);
104 zclient_free(zclient);
105 }
ae2254aa 106
03951374 107 frr_fini();
d62a17ae 108 exit(status);
ae2254aa
TG
109}
110
718e3744 111/* SIGHUP handler. */
d62a17ae 112static void sighup(void)
718e3744 113{
d62a17ae 114 zlog_info("SIGHUP received");
718e3744 115}
116
117/* SIGINT handler. */
d62a17ae 118static void sigint(void)
718e3744 119{
d62a17ae 120 zlog_notice("Terminating on signal SIGINT");
121 ospf6_exit(0);
718e3744 122}
123
124/* SIGTERM handler. */
d62a17ae 125static void sigterm(void)
718e3744 126{
d62a17ae 127 zlog_notice("Terminating on signal SIGTERM");
128 ospf6_clean();
129 ospf6_exit(0);
718e3744 130}
131
132/* SIGUSR1 handler. */
d62a17ae 133static void sigusr1(void)
718e3744 134{
d62a17ae 135 zlog_info("SIGUSR1 received");
136 zlog_rotate();
718e3744 137}
138
d62a17ae 139struct quagga_signal_t ospf6_signals[] = {
140 {
141 .signal = SIGHUP,
142 .handler = &sighup,
143 },
144 {
145 .signal = SIGINT,
146 .handler = &sigint,
147 },
148 {
149 .signal = SIGTERM,
150 .handler = &sigterm,
151 },
152 {
153 .signal = SIGUSR1,
154 .handler = &sigusr1,
155 },
e42f5a37 156};
508e53e2 157
d62a17ae 158FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT,
4f04a76b 159
d62a17ae 160 .proghelp = "Implementation of the OSPFv3 routing protocol.",
4f04a76b 161
d62a17ae 162 .signals = ospf6_signals,
163 .n_signals = array_size(ospf6_signals),
4f04a76b 164
d62a17ae 165 .privs = &ospf6d_privs, )
4f04a76b 166
508e53e2 167/* Main routine of ospf6d. Treatment of argument and starting ospf finite
718e3744 168 state machine is handled here. */
d62a17ae 169int main(int argc, char *argv[], char *envp[])
718e3744 170{
d62a17ae 171 int opt;
172
173 frr_preinit(&ospf6d_di, argc, argv);
174 frr_opt_add("", longopts, "");
718e3744 175
d62a17ae 176 /* Command line argument treatment. */
177 while (1) {
178 opt = frr_getopt(argc, argv, NULL);
508e53e2 179
d62a17ae 180 if (opt == EOF)
181 break;
182
183 switch (opt) {
184 case 0:
185 break;
186 default:
187 frr_help_exit(1);
188 break;
189 }
190 }
191
192 if (geteuid() != 0) {
193 errno = EPERM;
194 perror(ospf6d_di.progname);
195 exit(1);
196 }
197
198 /* thread master */
199 master = frr_init();
200
201 vrf_init(NULL, NULL, NULL, NULL);
202 access_list_init();
203 prefix_list_init();
204
205 /* initialize ospf6 */
206 ospf6_init();
207
208 frr_config_fork();
209 frr_run(master);
210
211 /* Not reached. */
212 ospf6_exit(0);
213}