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