]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_main.c
Merge remote-tracking branch 'origin/stable/3.0'
[mirror_frr.git] / ripngd / ripng_main.c
1 /*
2 * RIPngd main routine.
3 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <zebra.h>
23
24 #include <lib/version.h>
25 #include "getopt.h"
26 #include "vector.h"
27 #include "vty.h"
28 #include "command.h"
29 #include "memory.h"
30 #include "memory_vty.h"
31 #include "thread.h"
32 #include "log.h"
33 #include "prefix.h"
34 #include "if.h"
35 #include "privs.h"
36 #include "sigevent.h"
37 #include "vrf.h"
38 #include "libfrr.h"
39
40 #include "ripngd/ripngd.h"
41
42 /* RIPngd options. */
43 struct option longopts[] =
44 {
45 { "retain", no_argument, NULL, 'r'},
46 { 0 }
47 };
48
49 /* ripngd privileges */
50 zebra_capabilities_t _caps_p [] =
51 {
52 ZCAP_NET_RAW,
53 ZCAP_BIND
54 };
55
56 struct zebra_privs_t ripngd_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
73 /* RIPngd program name */
74
75 /* Route retain mode flag. */
76 int retain_mode = 0;
77
78 /* Master of threads. */
79 struct thread_master *master;
80
81 static struct frr_daemon_info ripngd_di;
82
83 /* SIGHUP handler. */
84 static void
85 sighup (void)
86 {
87 zlog_info ("SIGHUP received");
88 ripng_clean ();
89 ripng_reset ();
90
91 /* Reload config file. */
92 vty_read_config (ripngd_di.config_file, config_default);
93
94 /* Try to return to normal operation. */
95 }
96
97 /* SIGINT handler. */
98 static void
99 sigint (void)
100 {
101 zlog_notice ("Terminating on signal");
102
103 if (! retain_mode)
104 ripng_clean ();
105
106 exit (0);
107 }
108
109 /* SIGUSR1 handler. */
110 static void
111 sigusr1 (void)
112 {
113 zlog_rotate();
114 }
115
116 struct quagga_signal_t ripng_signals[] =
117 {
118 {
119 .signal = SIGHUP,
120 .handler = &sighup,
121 },
122 {
123 .signal = SIGUSR1,
124 .handler = &sigusr1,
125 },
126 {
127 .signal = SIGINT,
128 .handler = &sigint,
129 },
130 {
131 .signal = SIGTERM,
132 .handler = &sigint,
133 },
134 };
135
136 FRR_DAEMON_INFO(ripngd, RIPNG,
137 .vty_port = RIPNG_VTY_PORT,
138
139 .proghelp = "Implementation of the RIPng routing protocol.",
140
141 .signals = ripng_signals,
142 .n_signals = array_size(ripng_signals),
143
144 .privs = &ripngd_privs,
145 )
146
147 /* RIPngd main routine. */
148 int
149 main (int argc, char **argv)
150 {
151 frr_preinit (&ripngd_di, argc, argv);
152 frr_opt_add ("r", longopts,
153 " -r, --retain When program terminates, retain added route by ripd.\n");
154
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 master = frr_init ();
178
179 /* Library inits. */
180 vrf_init (NULL, NULL, NULL, NULL);
181
182 /* RIPngd inits. */
183 ripng_init ();
184 zebra_init(master);
185 ripng_peer_init ();
186
187 frr_config_fork ();
188 frr_run (master);
189
190 /* Not reached. */
191 return 0;
192 }