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