]> git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_main.c
*: reindent
[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
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22 #include <zebra.h>
23
24 #include <lib/version.h>
25 #include "getopt.h"
26 #include "thread.h"
27 #include "command.h"
28 #include "memory.h"
29 #include "memory_vty.h"
30 #include "prefix.h"
31 #include "filter.h"
32 #include "keychain.h"
33 #include "log.h"
34 #include "privs.h"
35 #include "sigevent.h"
36 #include "zclient.h"
37 #include "vrf.h"
38 #include "libfrr.h"
39
40 #include "ripd/ripd.h"
41
42 /* ripd options. */
43 static struct option longopts[] = {{"retain", no_argument, NULL, 'r'}, {0}};
44
45 /* ripd privileges */
46 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND};
47
48 struct zebra_privs_t ripd_privs = {
49 #if defined(FRR_USER)
50 .user = FRR_USER,
51 #endif
52 #if defined FRR_GROUP
53 .group = FRR_GROUP,
54 #endif
55 #ifdef VTY_GROUP
56 .vty_group = VTY_GROUP,
57 #endif
58 .caps_p = _caps_p,
59 .cap_num_p = 2,
60 .cap_num_i = 0};
61
62 /* Route retain mode flag. */
63 int retain_mode = 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 rip_clean();
75 rip_reset();
76 zlog_info("ripd restarting!");
77
78 /* Reload config file. */
79 vty_read_config(ripd_di.config_file, config_default);
80
81 /* Try to return to normal operation. */
82 }
83
84 /* SIGINT handler. */
85 static void sigint(void)
86 {
87 zlog_notice("Terminating on signal");
88
89 if (!retain_mode)
90 rip_clean();
91
92 exit(0);
93 }
94
95 /* SIGUSR1 handler. */
96 static void sigusr1(void)
97 {
98 zlog_rotate();
99 }
100
101 static struct quagga_signal_t ripd_signals[] = {
102 {
103 .signal = SIGHUP,
104 .handler = &sighup,
105 },
106 {
107 .signal = SIGUSR1,
108 .handler = &sigusr1,
109 },
110 {
111 .signal = SIGINT,
112 .handler = &sigint,
113 },
114 {
115 .signal = SIGTERM,
116 .handler = &sigint,
117 },
118 };
119
120 FRR_DAEMON_INFO(ripd, RIP, .vty_port = RIP_VTY_PORT,
121
122 .proghelp = "Implementation of the RIP routing protocol.",
123
124 .signals = ripd_signals, .n_signals = array_size(ripd_signals),
125
126 .privs = &ripd_privs, )
127
128 /* Main routine of ripd. */
129 int main(int argc, char **argv)
130 {
131 frr_preinit(&ripd_di, argc, argv);
132 frr_opt_add(
133 "r", longopts,
134 " -r, --retain When program terminates, retain added route by ripd.\n");
135
136 /* Command line option parse. */
137 while (1) {
138 int opt;
139
140 opt = frr_getopt(argc, argv, NULL);
141
142 if (opt == EOF)
143 break;
144
145 switch (opt) {
146 case 0:
147 break;
148 case 'r':
149 retain_mode = 1;
150 break;
151 default:
152 frr_help_exit(1);
153 break;
154 }
155 }
156
157 /* Prepare master thread. */
158 master = frr_init();
159
160 /* Library initialization. */
161 keychain_init();
162 vrf_init();
163
164 /* RIP related initialization. */
165 rip_init();
166 rip_if_init();
167 rip_zclient_init(master);
168 rip_peer_init();
169
170 frr_config_fork();
171 frr_run(master);
172
173 /* Not reached. */
174 return (0);
175 }