]> git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_main.c
Merge pull request #13598 from opensourcerouting/fix/typo_vtysh
[mirror_frr.git] / ripd / rip_main.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* RIPd main routine.
3 * Copyright (C) 1997, 98 Kunihiro Ishiguro <kunihiro@zebra.org>
4 */
5
6 #include <zebra.h>
7
8 #include <lib/version.h>
9 #include "getopt.h"
10 #include "frrevent.h"
11 #include "command.h"
12 #include "memory.h"
13 #include "prefix.h"
14 #include "filter.h"
15 #include "keychain.h"
16 #include "log.h"
17 #include "privs.h"
18 #include "sigevent.h"
19 #include "zclient.h"
20 #include "vrf.h"
21 #include "if_rmap.h"
22 #include "libfrr.h"
23 #include "routemap.h"
24 #include "bfd.h"
25
26 #include "ripd/ripd.h"
27 #include "ripd/rip_bfd.h"
28 #include "ripd/rip_nb.h"
29 #include "ripd/rip_errors.h"
30
31 /* ripd options. */
32 static struct option longopts[] = {{0}};
33
34 /* ripd privileges */
35 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
36
37 uint32_t zebra_ecmp_count = MULTIPATH_NUM;
38
39 struct zebra_privs_t ripd_privs = {
40 #if defined(FRR_USER)
41 .user = FRR_USER,
42 #endif
43 #if defined FRR_GROUP
44 .group = FRR_GROUP,
45 #endif
46 #ifdef VTY_GROUP
47 .vty_group = VTY_GROUP,
48 #endif
49 .caps_p = _caps_p,
50 .cap_num_p = array_size(_caps_p),
51 .cap_num_i = 0};
52
53 /* Master of threads. */
54 struct event_loop *master;
55
56 static struct frr_daemon_info ripd_di;
57
58 /* SIGHUP handler. */
59 static void sighup(void)
60 {
61 zlog_info("SIGHUP received");
62
63 /* Reload config file. */
64 vty_read_config(NULL, ripd_di.config_file, config_default);
65 }
66
67 /* SIGINT handler. */
68 static void sigint(void)
69 {
70 zlog_notice("Terminating on signal");
71
72 bfd_protocol_integration_set_shutdown(true);
73 rip_vrf_terminate();
74 if_rmap_terminate();
75 rip_zclient_stop();
76 frr_fini();
77
78 exit(0);
79 }
80
81 /* SIGUSR1 handler. */
82 static void sigusr1(void)
83 {
84 zlog_rotate();
85 }
86
87 static struct frr_signal_t ripd_signals[] = {
88 {
89 .signal = SIGHUP,
90 .handler = &sighup,
91 },
92 {
93 .signal = SIGUSR1,
94 .handler = &sigusr1,
95 },
96 {
97 .signal = SIGINT,
98 .handler = &sigint,
99 },
100 {
101 .signal = SIGTERM,
102 .handler = &sigint,
103 },
104 };
105
106 static const struct frr_yang_module_info *const ripd_yang_modules[] = {
107 &frr_filter_info,
108 &frr_interface_info,
109 &frr_ripd_info,
110 &frr_route_map_info,
111 &frr_vrf_info,
112 };
113
114 FRR_DAEMON_INFO(ripd, RIP, .vty_port = RIP_VTY_PORT,
115
116 .proghelp = "Implementation of the RIP routing protocol.",
117
118 .signals = ripd_signals, .n_signals = array_size(ripd_signals),
119
120 .privs = &ripd_privs, .yang_modules = ripd_yang_modules,
121 .n_yang_modules = array_size(ripd_yang_modules),
122 );
123
124 #define DEPRECATED_OPTIONS ""
125
126 /* Main routine of ripd. */
127 int main(int argc, char **argv)
128 {
129 frr_preinit(&ripd_di, argc, argv);
130
131 frr_opt_add("" DEPRECATED_OPTIONS, longopts, "");
132
133 /* Command line option parse. */
134 while (1) {
135 int opt;
136
137 opt = frr_getopt(argc, argv, NULL);
138
139 if (opt && opt < 128 && strchr(DEPRECATED_OPTIONS, opt)) {
140 fprintf(stderr,
141 "The -%c option no longer exists.\nPlease refer to the manual.\n",
142 opt);
143 continue;
144 }
145
146 if (opt == EOF)
147 break;
148
149 switch (opt) {
150 case 0:
151 break;
152 default:
153 frr_help_exit(1);
154 }
155 }
156
157 /* Prepare master thread. */
158 master = frr_init();
159
160 /* Library initialization. */
161 rip_error_init();
162 keychain_init();
163 rip_vrf_init();
164
165 /* RIP related initialization. */
166 rip_init();
167 rip_if_init();
168 rip_cli_init();
169 rip_zclient_init(master);
170 rip_bfd_init(master);
171
172 frr_config_fork();
173 frr_run(master);
174
175 /* Not reached. */
176 return 0;
177 }