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