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