]> git.proxmox.com Git - mirror_frr.git/blame - ripd/rip_main.c
Merge pull request #5363 from donaldsharp/71_pim_crash_rp
[mirror_frr.git] / ripd / rip_main.c
CommitLineData
718e3744 1/* RIPd main routine.
2 * Copyright (C) 1997, 98 Kunihiro Ishiguro <kunihiro@zebra.org>
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>
22
5e4fa164 23#include <lib/version.h>
718e3744 24#include "getopt.h"
25#include "thread.h"
26#include "command.h"
27#include "memory.h"
fc7948fa 28#include "memory_vty.h"
718e3744 29#include "prefix.h"
30#include "filter.h"
31#include "keychain.h"
32#include "log.h"
edd7c245 33#include "privs.h"
2d75d052 34#include "sigevent.h"
b5114685 35#include "zclient.h"
6a69b354 36#include "vrf.h"
8f88441d 37#include "if_rmap.h"
4f04a76b 38#include "libfrr.h"
718e3744 39
40#include "ripd/ripd.h"
518e377f 41#include "ripd/rip_errors.h"
718e3744 42
43/* ripd options. */
c8dde10f
QY
44#if CONFDATE > 20190521
45 CPP_NOTICE("-r / --retain has reached deprecation EOL, remove")
46#endif
d62a17ae 47static struct option longopts[] = {{"retain", no_argument, NULL, 'r'}, {0}};
718e3744 48
edd7c245 49/* ripd privileges */
ae7b826a 50zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
edd7c245 51
d62a17ae 52struct zebra_privs_t ripd_privs = {
b2f36157 53#if defined(FRR_USER)
d62a17ae 54 .user = FRR_USER,
edd7c245 55#endif
b2f36157 56#if defined FRR_GROUP
d62a17ae 57 .group = FRR_GROUP,
d81fadfd 58#endif
59#ifdef VTY_GROUP
d62a17ae 60 .vty_group = VTY_GROUP,
edd7c245 61#endif
d62a17ae 62 .caps_p = _caps_p,
ae7b826a 63 .cap_num_p = array_size(_caps_p),
d62a17ae 64 .cap_num_i = 0};
edd7c245 65
718e3744 66/* Master of threads. */
67struct thread_master *master;
68
eb05883f 69static struct frr_daemon_info ripd_di;
718e3744 70
718e3744 71/* SIGHUP handler. */
d62a17ae 72static void sighup(void)
718e3744 73{
d62a17ae 74 zlog_info("SIGHUP received");
718e3744 75
d62a17ae 76 /* Reload config file. */
1c2facd1 77 vty_read_config(NULL, ripd_di.config_file, config_default);
718e3744 78}
79
80/* SIGINT handler. */
d62a17ae 81static void sigint(void)
718e3744 82{
d62a17ae 83 zlog_notice("Terminating on signal");
718e3744 84
ae7b826a 85 rip_vrf_terminate();
8f88441d 86 if_rmap_terminate();
d62a17ae 87 rip_zclient_stop();
8879bd22 88 frr_fini();
a2f9eb82 89
d62a17ae 90 exit(0);
718e3744 91}
92
93/* SIGUSR1 handler. */
d62a17ae 94static void sigusr1(void)
718e3744 95{
d62a17ae 96 zlog_rotate();
718e3744 97}
98
d62a17ae 99static struct quagga_signal_t ripd_signals[] = {
100 {
101 .signal = SIGHUP,
102 .handler = &sighup,
103 },
104 {
105 .signal = SIGUSR1,
106 .handler = &sigusr1,
107 },
108 {
109 .signal = SIGINT,
110 .handler = &sigint,
111 },
112 {
113 .signal = SIGTERM,
114 .handler = &sigint,
115 },
116};
4f04a76b 117
8fcdd0d6 118static const struct frr_yang_module_info *ripd_yang_modules[] = {
a4bed468 119 &frr_interface_info,
707656ec 120 &frr_ripd_info,
8fcdd0d6
RW
121};
122
d62a17ae 123FRR_DAEMON_INFO(ripd, RIP, .vty_port = RIP_VTY_PORT,
718e3744 124
d62a17ae 125 .proghelp = "Implementation of the RIP routing protocol.",
718e3744 126
d62a17ae 127 .signals = ripd_signals, .n_signals = array_size(ripd_signals),
718e3744 128
8fcdd0d6
RW
129 .privs = &ripd_privs, .yang_modules = ripd_yang_modules,
130 .n_yang_modules = array_size(ripd_yang_modules), )
d62a17ae 131
c8dde10f
QY
132#if CONFDATE > 20190521
133CPP_NOTICE("-r / --retain has reached deprecation EOL, remove")
134#endif
135#define DEPRECATED_OPTIONS "r"
136
d62a17ae 137/* Main routine of ripd. */
138int main(int argc, char **argv)
139{
140 frr_preinit(&ripd_di, argc, argv);
c8dde10f
QY
141
142 frr_opt_add("" DEPRECATED_OPTIONS, longopts, "");
d62a17ae 143
144 /* Command line option parse. */
145 while (1) {
146 int opt;
147
148 opt = frr_getopt(argc, argv, NULL);
149
c8dde10f
QY
150 if (opt && opt < 128 && strchr(DEPRECATED_OPTIONS, opt)) {
151 fprintf(stderr,
152 "The -%c option no longer exists.\nPlease refer to the manual.\n",
153 opt);
154 continue;
155 }
156
d62a17ae 157 if (opt == EOF)
158 break;
159
160 switch (opt) {
161 case 0:
162 break;
d62a17ae 163 default:
164 frr_help_exit(1);
165 break;
166 }
718e3744 167 }
718e3744 168
d62a17ae 169 /* Prepare master thread. */
170 master = frr_init();
718e3744 171
d62a17ae 172 /* Library initialization. */
518e377f 173 rip_error_init();
d62a17ae 174 keychain_init();
ae7b826a 175 rip_vrf_init();
718e3744 176
d62a17ae 177 /* RIP related initialization. */
178 rip_init();
179 rip_if_init();
707656ec 180 rip_cli_init();
d62a17ae 181 rip_zclient_init(master);
718e3744 182
d62a17ae 183 frr_config_fork();
184 frr_run(master);
718e3744 185
d62a17ae 186 /* Not reached. */
187 return (0);
718e3744 188}