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