]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_main.c
Merge pull request #410 from dslicenc/rdnbrd-vrr
[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
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23 #include <zebra.h>
24
25 #include <lib/version.h>
26 #include "getopt.h"
27 #include "vector.h"
28 #include "vty.h"
29 #include "command.h"
30 #include "memory.h"
31 #include "memory_vty.h"
32 #include "thread.h"
33 #include "log.h"
34 #include "prefix.h"
35 #include "if.h"
36 #include "privs.h"
37 #include "sigevent.h"
38 #include "vrf.h"
39 #include "libfrr.h"
40
41 #include "ripngd/ripngd.h"
42
43 /* RIPngd options. */
44 struct option longopts[] =
45 {
46 { "retain", no_argument, NULL, 'r'},
47 { 0 }
48 };
49
50 /* ripngd privileges */
51 zebra_capabilities_t _caps_p [] =
52 {
53 ZCAP_NET_RAW,
54 ZCAP_BIND
55 };
56
57 struct zebra_privs_t ripngd_privs =
58 {
59 #if defined(FRR_USER)
60 .user = FRR_USER,
61 #endif
62 #if defined FRR_GROUP
63 .group = FRR_GROUP,
64 #endif
65 #ifdef VTY_GROUP
66 .vty_group = VTY_GROUP,
67 #endif
68 .caps_p = _caps_p,
69 .cap_num_p = 2,
70 .cap_num_i = 0
71 };
72
73
74 /* RIPngd program name */
75
76 /* Route retain mode flag. */
77 int retain_mode = 0;
78
79 /* Master of threads. */
80 struct thread_master *master;
81
82 static struct frr_daemon_info ripngd_di;
83
84 /* SIGHUP handler. */
85 static void
86 sighup (void)
87 {
88 zlog_info ("SIGHUP received");
89 ripng_clean ();
90 ripng_reset ();
91
92 /* Reload config file. */
93 vty_read_config (ripngd_di.config_file, config_default);
94
95 /* Try to return to normal operation. */
96 }
97
98 /* SIGINT handler. */
99 static void
100 sigint (void)
101 {
102 zlog_notice ("Terminating on signal");
103
104 if (! retain_mode)
105 ripng_clean ();
106
107 exit (0);
108 }
109
110 /* SIGUSR1 handler. */
111 static void
112 sigusr1 (void)
113 {
114 zlog_rotate();
115 }
116
117 struct quagga_signal_t ripng_signals[] =
118 {
119 {
120 .signal = SIGHUP,
121 .handler = &sighup,
122 },
123 {
124 .signal = SIGUSR1,
125 .handler = &sigusr1,
126 },
127 {
128 .signal = SIGINT,
129 .handler = &sigint,
130 },
131 {
132 .signal = SIGTERM,
133 .handler = &sigint,
134 },
135 };
136
137 FRR_DAEMON_INFO(ripngd, RIPNG,
138 .vty_port = RIPNG_VTY_PORT,
139
140 .proghelp = "Implementation of the RIPng routing protocol.",
141
142 .signals = ripng_signals,
143 .n_signals = array_size(ripng_signals),
144
145 .privs = &ripngd_privs,
146 )
147
148 /* RIPngd main routine. */
149 int
150 main (int argc, char **argv)
151 {
152 frr_preinit (&ripngd_di, argc, argv);
153 frr_opt_add ("r", longopts,
154 " -r, --retain When program terminates, retain added route by ripd.\n");
155
156 while (1)
157 {
158 int opt;
159
160 opt = frr_getopt (argc, argv, NULL);
161
162 if (opt == EOF)
163 break;
164
165 switch (opt)
166 {
167 case 0:
168 break;
169 case 'r':
170 retain_mode = 1;
171 break;
172 default:
173 frr_help_exit (1);
174 break;
175 }
176 }
177
178 master = frr_init ();
179
180 /* Library inits. */
181 vrf_init ();
182
183 /* RIPngd inits. */
184 ripng_init ();
185 zebra_init(master);
186 ripng_peer_init ();
187
188 frr_config_fork ();
189 frr_run (master);
190
191 /* Not reached. */
192 return 0;
193 }