]> git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_main.c
Merge remote-tracking branch 'origin/stable/2.0'
[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 exit (0);
104 }
105
106 /* SIGUSR1 handler. */
107 static void
108 sigusr1 (void)
109 {
110 zlog_rotate();
111 }
112
113 static struct quagga_signal_t ripd_signals[] =
114 {
115 {
116 .signal = SIGHUP,
117 .handler = &sighup,
118 },
119 {
120 .signal = SIGUSR1,
121 .handler = &sigusr1,
122 },
123 {
124 .signal = SIGINT,
125 .handler = &sigint,
126 },
127 {
128 .signal = SIGTERM,
129 .handler = &sigint,
130 },
131 };
132
133 FRR_DAEMON_INFO(ripd, RIP,
134 .vty_port = RIP_VTY_PORT,
135
136 .proghelp = "Implementation of the RIP routing protocol.",
137
138 .signals = ripd_signals,
139 .n_signals = array_size(ripd_signals),
140
141 .privs = &ripd_privs,
142 )
143
144 /* Main routine of ripd. */
145 int
146 main (int argc, char **argv)
147 {
148 frr_preinit (&ripd_di, argc, argv);
149 frr_opt_add ("r", longopts,
150 " -r, --retain When program terminates, retain added route by ripd.\n");
151
152 /* Command line option parse. */
153 while (1)
154 {
155 int opt;
156
157 opt = frr_getopt (argc, argv, NULL);
158
159 if (opt == EOF)
160 break;
161
162 switch (opt)
163 {
164 case 0:
165 break;
166 case 'r':
167 retain_mode = 1;
168 break;
169 default:
170 frr_help_exit (1);
171 break;
172 }
173 }
174
175 /* Prepare master thread. */
176 master = frr_init ();
177
178 /* Library initialization. */
179 keychain_init ();
180 vrf_init (NULL, NULL, NULL, NULL);
181
182 /* RIP related initialization. */
183 rip_init ();
184 rip_if_init ();
185 rip_zclient_init(master);
186 rip_peer_init ();
187
188 frr_config_fork ();
189 frr_run (master);
190
191 /* Not reached. */
192 return (0);
193 }