]> git.proxmox.com Git - mirror_frr.git/blame - ripngd/ripng_main.c
bgpd: Auto RD definitions and encoding
[mirror_frr.git] / ripngd / ripng_main.c
CommitLineData
718e3744 1/*
2 * RIPngd main routine.
3 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
896014f4
DL
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 20 */
21
22#include <zebra.h>
23
5e4fa164 24#include <lib/version.h>
718e3744 25#include "getopt.h"
26#include "vector.h"
27#include "vty.h"
28#include "command.h"
a94434b6 29#include "memory.h"
fc7948fa 30#include "memory_vty.h"
718e3744 31#include "thread.h"
32#include "log.h"
33#include "prefix.h"
34#include "if.h"
edd7c245 35#include "privs.h"
2d75d052 36#include "sigevent.h"
6a69b354 37#include "vrf.h"
4f04a76b 38#include "libfrr.h"
718e3744 39
40#include "ripngd/ripngd.h"
41
718e3744 42/* RIPngd options. */
d62a17ae 43struct option longopts[] = {{"retain", no_argument, NULL, 'r'}, {0}};
718e3744 44
edd7c245 45/* ripngd privileges */
d62a17ae 46zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND};
edd7c245 47
d62a17ae 48struct zebra_privs_t ripngd_privs = {
b2f36157 49#if defined(FRR_USER)
d62a17ae 50 .user = FRR_USER,
edd7c245 51#endif
b2f36157 52#if defined FRR_GROUP
d62a17ae 53 .group = FRR_GROUP,
d81fadfd 54#endif
55#ifdef VTY_GROUP
d62a17ae 56 .vty_group = VTY_GROUP,
edd7c245 57#endif
d62a17ae 58 .caps_p = _caps_p,
59 .cap_num_p = 2,
60 .cap_num_i = 0};
edd7c245 61
62
718e3744 63/* RIPngd program name */
64
65/* Route retain mode flag. */
66int retain_mode = 0;
67
68/* Master of threads. */
69struct thread_master *master;
70
eb05883f 71static struct frr_daemon_info ripngd_di;
718e3744 72
718e3744 73/* SIGHUP handler. */
d62a17ae 74static void sighup(void)
718e3744 75{
d62a17ae 76 zlog_info("SIGHUP received");
77 ripng_clean();
78 ripng_reset();
a94434b6 79
d62a17ae 80 /* Reload config file. */
81 vty_read_config(ripngd_di.config_file, config_default);
a94434b6 82
d62a17ae 83 /* Try to return to normal operation. */
718e3744 84}
85
86/* SIGINT handler. */
d62a17ae 87static void sigint(void)
718e3744 88{
d62a17ae 89 zlog_notice("Terminating on signal");
718e3744 90
d62a17ae 91 if (!retain_mode)
92 ripng_clean();
718e3744 93
d62a17ae 94 ripng_zebra_stop();
8879bd22 95 frr_fini();
d62a17ae 96 exit(0);
718e3744 97}
98
99/* SIGUSR1 handler. */
d62a17ae 100static void sigusr1(void)
718e3744 101{
d62a17ae 102 zlog_rotate();
718e3744 103}
104
d62a17ae 105struct quagga_signal_t ripng_signals[] = {
106 {
107 .signal = SIGHUP,
108 .handler = &sighup,
109 },
110 {
111 .signal = SIGUSR1,
112 .handler = &sigusr1,
113 },
114 {
115 .signal = SIGINT,
116 .handler = &sigint,
117 },
118 {
119 .signal = SIGTERM,
120 .handler = &sigint,
121 },
2d75d052 122};
6b0655a2 123
d62a17ae 124FRR_DAEMON_INFO(ripngd, RIPNG, .vty_port = RIPNG_VTY_PORT,
4f04a76b 125
d62a17ae 126 .proghelp = "Implementation of the RIPng routing protocol.",
4f04a76b 127
d62a17ae 128 .signals = ripng_signals,
129 .n_signals = array_size(ripng_signals),
4f04a76b 130
d62a17ae 131 .privs = &ripngd_privs, )
4f04a76b 132
718e3744 133/* RIPngd main routine. */
d62a17ae 134int main(int argc, char **argv)
718e3744 135{
d62a17ae 136 frr_preinit(&ripngd_di, argc, argv);
137 frr_opt_add(
138 "r", longopts,
139 " -r, --retain When program terminates, retain added route by ripd.\n");
140
141 while (1) {
142 int opt;
143
144 opt = frr_getopt(argc, argv, NULL);
145
146 if (opt == EOF)
147 break;
148
149 switch (opt) {
150 case 0:
151 break;
152 case 'r':
153 retain_mode = 1;
154 break;
155 default:
156 frr_help_exit(1);
157 break;
158 }
718e3744 159 }
718e3744 160
d62a17ae 161 master = frr_init();
718e3744 162
d62a17ae 163 /* Library inits. */
164 vrf_init(NULL, NULL, NULL, NULL);
718e3744 165
d62a17ae 166 /* RIPngd inits. */
167 ripng_init();
168 zebra_init(master);
169 ripng_peer_init();
a94434b6 170
d62a17ae 171 frr_config_fork();
172 frr_run(master);
718e3744 173
d62a17ae 174 /* Not reached. */
175 return 0;
718e3744 176}