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