]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_main.c
bgpd: Auto RD definitions and encoding
[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[] = {{"retain", no_argument, NULL, 'r'}, {0}};
44
45 /* ripngd privileges */
46 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND};
47
48 struct zebra_privs_t ripngd_privs = {
49 #if defined(FRR_USER)
50 .user = FRR_USER,
51 #endif
52 #if defined FRR_GROUP
53 .group = FRR_GROUP,
54 #endif
55 #ifdef VTY_GROUP
56 .vty_group = VTY_GROUP,
57 #endif
58 .caps_p = _caps_p,
59 .cap_num_p = 2,
60 .cap_num_i = 0};
61
62
63 /* RIPngd program name */
64
65 /* Route retain mode flag. */
66 int retain_mode = 0;
67
68 /* Master of threads. */
69 struct thread_master *master;
70
71 static struct frr_daemon_info ripngd_di;
72
73 /* SIGHUP handler. */
74 static void sighup(void)
75 {
76 zlog_info("SIGHUP received");
77 ripng_clean();
78 ripng_reset();
79
80 /* Reload config file. */
81 vty_read_config(ripngd_di.config_file, config_default);
82
83 /* Try to return to normal operation. */
84 }
85
86 /* SIGINT handler. */
87 static void sigint(void)
88 {
89 zlog_notice("Terminating on signal");
90
91 if (!retain_mode)
92 ripng_clean();
93
94 ripng_zebra_stop();
95 frr_fini();
96 exit(0);
97 }
98
99 /* SIGUSR1 handler. */
100 static void sigusr1(void)
101 {
102 zlog_rotate();
103 }
104
105 struct quagga_signal_t ripng_signals[] = {
106 {
107 .signal = SIGHUP,
108 .handler = &sighup,
109 },
110 {
111 .signal = SIGUSR1,
112 .handler = &sigusr1,
113 },
114 {
115 .signal = SIGINT,
116 .handler = &sigint,
117 },
118 {
119 .signal = SIGTERM,
120 .handler = &sigint,
121 },
122 };
123
124 FRR_DAEMON_INFO(ripngd, RIPNG, .vty_port = RIPNG_VTY_PORT,
125
126 .proghelp = "Implementation of the RIPng routing protocol.",
127
128 .signals = ripng_signals,
129 .n_signals = array_size(ripng_signals),
130
131 .privs = &ripngd_privs, )
132
133 /* RIPngd main routine. */
134 int main(int argc, char **argv)
135 {
136 frr_preinit(&ripngd_di, argc, argv);
137 frr_opt_add(
138 "r", longopts,
139 " -r, --retain When program terminates, retain added route by ripd.\n");
140
141 while (1) {
142 int opt;
143
144 opt = frr_getopt(argc, argv, NULL);
145
146 if (opt == EOF)
147 break;
148
149 switch (opt) {
150 case 0:
151 break;
152 case 'r':
153 retain_mode = 1;
154 break;
155 default:
156 frr_help_exit(1);
157 break;
158 }
159 }
160
161 master = frr_init();
162
163 /* Library inits. */
164 vrf_init(NULL, NULL, NULL, NULL);
165
166 /* RIPngd inits. */
167 ripng_init();
168 zebra_init(master);
169 ripng_peer_init();
170
171 frr_config_fork();
172 frr_run(master);
173
174 /* Not reached. */
175 return 0;
176 }