]> git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_main.c
Merge pull request #5163 from ton31337/fix/do_not_reconnect_if_prefix_overflow_7.1
[mirror_frr.git] / ripd / rip_main.c
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 *
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
19 */
20
21 #include <zebra.h>
22
23 #include <lib/version.h>
24 #include "getopt.h"
25 #include "thread.h"
26 #include "command.h"
27 #include "memory.h"
28 #include "memory_vty.h"
29 #include "prefix.h"
30 #include "filter.h"
31 #include "keychain.h"
32 #include "log.h"
33 #include "privs.h"
34 #include "sigevent.h"
35 #include "zclient.h"
36 #include "vrf.h"
37 #include "if_rmap.h"
38 #include "libfrr.h"
39
40 #include "ripd/ripd.h"
41 #include "ripd/rip_errors.h"
42
43 /* ripd options. */
44 #if CONFDATE > 20190521
45 CPP_NOTICE("-r / --retain has reached deprecation EOL, remove")
46 #endif
47 static struct option longopts[] = {{"retain", no_argument, NULL, 'r'}, {0}};
48
49 /* ripd privileges */
50 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
51
52 struct zebra_privs_t ripd_privs = {
53 #if defined(FRR_USER)
54 .user = FRR_USER,
55 #endif
56 #if defined FRR_GROUP
57 .group = FRR_GROUP,
58 #endif
59 #ifdef VTY_GROUP
60 .vty_group = VTY_GROUP,
61 #endif
62 .caps_p = _caps_p,
63 .cap_num_p = array_size(_caps_p),
64 .cap_num_i = 0};
65
66 /* Master of threads. */
67 struct thread_master *master;
68
69 static struct frr_daemon_info ripd_di;
70
71 /* SIGHUP handler. */
72 static void sighup(void)
73 {
74 zlog_info("SIGHUP received");
75
76 /* Reload config file. */
77 vty_read_config(NULL, ripd_di.config_file, config_default);
78 }
79
80 /* SIGINT handler. */
81 static void sigint(void)
82 {
83 zlog_notice("Terminating on signal");
84
85 rip_vrf_terminate();
86 if_rmap_terminate();
87 rip_zclient_stop();
88 frr_fini();
89
90 exit(0);
91 }
92
93 /* SIGUSR1 handler. */
94 static void sigusr1(void)
95 {
96 zlog_rotate();
97 }
98
99 static 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 };
117
118 static const struct frr_yang_module_info *ripd_yang_modules[] = {
119 &frr_interface_info,
120 &frr_ripd_info,
121 };
122
123 FRR_DAEMON_INFO(ripd, RIP, .vty_port = RIP_VTY_PORT,
124
125 .proghelp = "Implementation of the RIP routing protocol.",
126
127 .signals = ripd_signals, .n_signals = array_size(ripd_signals),
128
129 .privs = &ripd_privs, .yang_modules = ripd_yang_modules,
130 .n_yang_modules = array_size(ripd_yang_modules), )
131
132 #if CONFDATE > 20190521
133 CPP_NOTICE("-r / --retain has reached deprecation EOL, remove")
134 #endif
135 #define DEPRECATED_OPTIONS "r"
136
137 /* Main routine of ripd. */
138 int main(int argc, char **argv)
139 {
140 frr_preinit(&ripd_di, argc, argv);
141
142 frr_opt_add("" DEPRECATED_OPTIONS, longopts, "");
143
144 /* Command line option parse. */
145 while (1) {
146 int opt;
147
148 opt = frr_getopt(argc, argv, NULL);
149
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
157 if (opt == EOF)
158 break;
159
160 switch (opt) {
161 case 0:
162 break;
163 default:
164 frr_help_exit(1);
165 break;
166 }
167 }
168
169 /* Prepare master thread. */
170 master = frr_init();
171
172 /* Library initialization. */
173 rip_error_init();
174 keychain_init();
175 rip_vrf_init();
176
177 /* RIP related initialization. */
178 rip_init();
179 rip_if_init();
180 rip_cli_init();
181 rip_zclient_init(master);
182
183 frr_config_fork();
184 frr_run(master);
185
186 /* Not reached. */
187 return (0);
188 }