]> git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_main.c
Merge pull request #5197 from SumitAgarwal123/BFD_ADMIN_DOWN
[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 static struct option longopts[] = {{0}};
45
46 /* ripd privileges */
47 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
48
49 struct zebra_privs_t ripd_privs = {
50 #if defined(FRR_USER)
51 .user = FRR_USER,
52 #endif
53 #if defined FRR_GROUP
54 .group = FRR_GROUP,
55 #endif
56 #ifdef VTY_GROUP
57 .vty_group = VTY_GROUP,
58 #endif
59 .caps_p = _caps_p,
60 .cap_num_p = array_size(_caps_p),
61 .cap_num_i = 0};
62
63 /* Master of threads. */
64 struct thread_master *master;
65
66 static struct frr_daemon_info ripd_di;
67
68 /* SIGHUP handler. */
69 static void sighup(void)
70 {
71 zlog_info("SIGHUP received");
72
73 /* Reload config file. */
74 vty_read_config(NULL, ripd_di.config_file, config_default);
75 }
76
77 /* SIGINT handler. */
78 static void sigint(void)
79 {
80 zlog_notice("Terminating on signal");
81
82 rip_vrf_terminate();
83 if_rmap_terminate();
84 rip_zclient_stop();
85 frr_fini();
86
87 exit(0);
88 }
89
90 /* SIGUSR1 handler. */
91 static void sigusr1(void)
92 {
93 zlog_rotate();
94 }
95
96 static struct quagga_signal_t ripd_signals[] = {
97 {
98 .signal = SIGHUP,
99 .handler = &sighup,
100 },
101 {
102 .signal = SIGUSR1,
103 .handler = &sigusr1,
104 },
105 {
106 .signal = SIGINT,
107 .handler = &sigint,
108 },
109 {
110 .signal = SIGTERM,
111 .handler = &sigint,
112 },
113 };
114
115 static const struct frr_yang_module_info *ripd_yang_modules[] = {
116 &frr_interface_info,
117 &frr_ripd_info,
118 };
119
120 FRR_DAEMON_INFO(ripd, RIP, .vty_port = RIP_VTY_PORT,
121
122 .proghelp = "Implementation of the RIP routing protocol.",
123
124 .signals = ripd_signals, .n_signals = array_size(ripd_signals),
125
126 .privs = &ripd_privs, .yang_modules = ripd_yang_modules,
127 .n_yang_modules = array_size(ripd_yang_modules), )
128
129 #define DEPRECATED_OPTIONS ""
130
131 /* Main routine of ripd. */
132 int main(int argc, char **argv)
133 {
134 frr_preinit(&ripd_di, argc, argv);
135
136 frr_opt_add("" DEPRECATED_OPTIONS, longopts, "");
137
138 /* Command line option parse. */
139 while (1) {
140 int opt;
141
142 opt = frr_getopt(argc, argv, NULL);
143
144 if (opt && opt < 128 && strchr(DEPRECATED_OPTIONS, opt)) {
145 fprintf(stderr,
146 "The -%c option no longer exists.\nPlease refer to the manual.\n",
147 opt);
148 continue;
149 }
150
151 if (opt == EOF)
152 break;
153
154 switch (opt) {
155 case 0:
156 break;
157 default:
158 frr_help_exit(1);
159 break;
160 }
161 }
162
163 /* Prepare master thread. */
164 master = frr_init();
165
166 /* Library initialization. */
167 rip_error_init();
168 keychain_init();
169 rip_vrf_init();
170
171 /* RIP related initialization. */
172 rip_init();
173 rip_if_init();
174 rip_cli_init();
175 rip_zclient_init(master);
176
177 frr_config_fork();
178 frr_run(master);
179
180 /* Not reached. */
181 return (0);
182 }