Line data Source code
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 "prefix.h"
29 : #include "filter.h"
30 : #include "keychain.h"
31 : #include "log.h"
32 : #include "privs.h"
33 : #include "sigevent.h"
34 : #include "zclient.h"
35 : #include "vrf.h"
36 : #include "if_rmap.h"
37 : #include "libfrr.h"
38 : #include "routemap.h"
39 :
40 : #include "ripd/ripd.h"
41 : #include "ripd/rip_nb.h"
42 : #include "ripd/rip_errors.h"
43 :
44 : /* ripd options. */
45 : static struct option longopts[] = {{0}};
46 :
47 : /* ripd privileges */
48 : zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
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 = array_size(_caps_p),
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 0 : static void sighup(void)
71 : {
72 0 : zlog_info("SIGHUP received");
73 :
74 : /* Reload config file. */
75 0 : vty_read_config(NULL, ripd_di.config_file, config_default);
76 0 : }
77 :
78 : /* SIGINT handler. */
79 1 : static void sigint(void)
80 : {
81 1 : zlog_notice("Terminating on signal");
82 :
83 1 : rip_vrf_terminate();
84 1 : if_rmap_terminate();
85 1 : rip_zclient_stop();
86 1 : frr_fini();
87 :
88 1 : exit(0);
89 : }
90 :
91 : /* SIGUSR1 handler. */
92 0 : static void sigusr1(void)
93 : {
94 0 : zlog_rotate();
95 0 : }
96 :
97 : static struct frr_signal_t ripd_signals[] = {
98 : {
99 : .signal = SIGHUP,
100 : .handler = &sighup,
101 : },
102 : {
103 : .signal = SIGUSR1,
104 : .handler = &sigusr1,
105 : },
106 : {
107 : .signal = SIGINT,
108 : .handler = &sigint,
109 : },
110 : {
111 : .signal = SIGTERM,
112 : .handler = &sigint,
113 : },
114 : };
115 :
116 : static const struct frr_yang_module_info *const ripd_yang_modules[] = {
117 : &frr_filter_info,
118 : &frr_interface_info,
119 : &frr_ripd_info,
120 : &frr_route_map_info,
121 : &frr_vrf_info,
122 : };
123 :
124 1 : FRR_DAEMON_INFO(ripd, RIP, .vty_port = RIP_VTY_PORT,
125 :
126 : .proghelp = "Implementation of the RIP routing protocol.",
127 :
128 : .signals = ripd_signals, .n_signals = array_size(ripd_signals),
129 :
130 : .privs = &ripd_privs, .yang_modules = ripd_yang_modules,
131 : .n_yang_modules = array_size(ripd_yang_modules),
132 : );
133 :
134 : #define DEPRECATED_OPTIONS ""
135 :
136 : /* Main routine of ripd. */
137 1 : int main(int argc, char **argv)
138 : {
139 1 : frr_preinit(&ripd_di, argc, argv);
140 :
141 1 : frr_opt_add("" DEPRECATED_OPTIONS, longopts, "");
142 :
143 : /* Command line option parse. */
144 1 : while (1) {
145 1 : int opt;
146 :
147 1 : opt = frr_getopt(argc, argv, NULL);
148 :
149 1 : if (opt && opt < 128 && strchr(DEPRECATED_OPTIONS, opt)) {
150 0 : fprintf(stderr,
151 : "The -%c option no longer exists.\nPlease refer to the manual.\n",
152 : opt);
153 0 : continue;
154 : }
155 :
156 1 : if (opt == EOF)
157 : break;
158 :
159 0 : switch (opt) {
160 : case 0:
161 : break;
162 0 : default:
163 0 : frr_help_exit(1);
164 : }
165 : }
166 :
167 : /* Prepare master thread. */
168 1 : master = frr_init();
169 :
170 : /* Library initialization. */
171 1 : rip_error_init();
172 1 : keychain_init();
173 1 : rip_vrf_init();
174 :
175 : /* RIP related initialization. */
176 1 : rip_init();
177 1 : rip_if_init();
178 1 : rip_cli_init();
179 1 : rip_zclient_init(master);
180 :
181 1 : frr_config_fork();
182 1 : frr_run(master);
183 :
184 : /* Not reached. */
185 0 : return 0;
186 : }
|