]>
Commit | Line | Data |
---|---|---|
718e3744 | 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 | ||
5e4fa164 | 25 | #include <lib/version.h> |
718e3744 | 26 | #include "getopt.h" |
27 | #include "vector.h" | |
28 | #include "vty.h" | |
29 | #include "command.h" | |
a94434b6 | 30 | #include "memory.h" |
fc7948fa | 31 | #include "memory_vty.h" |
718e3744 | 32 | #include "thread.h" |
33 | #include "log.h" | |
34 | #include "prefix.h" | |
35 | #include "if.h" | |
edd7c245 | 36 | #include "privs.h" |
2d75d052 | 37 | #include "sigevent.h" |
6a69b354 | 38 | #include "vrf.h" |
4f04a76b | 39 | #include "libfrr.h" |
718e3744 | 40 | |
41 | #include "ripngd/ripngd.h" | |
42 | ||
43 | /* Configuration filename and directory. */ | |
718e3744 | 44 | char config_default[] = SYSCONFDIR RIPNG_DEFAULT_CONFIG; |
a94434b6 | 45 | char *config_file = NULL; |
718e3744 | 46 | |
47 | /* RIPngd options. */ | |
48 | struct option longopts[] = | |
49 | { | |
50 | { "daemon", no_argument, NULL, 'd'}, | |
51 | { "config_file", required_argument, NULL, 'f'}, | |
52 | { "pid_file", required_argument, NULL, 'i'}, | |
b5114685 | 53 | { "socket", required_argument, NULL, 'z'}, |
876b8be0 | 54 | { "dryrun", no_argument, NULL, 'C'}, |
718e3744 | 55 | { "retain", no_argument, NULL, 'r'}, |
718e3744 | 56 | { 0 } |
57 | }; | |
58 | ||
edd7c245 | 59 | /* ripngd privileges */ |
60 | zebra_capabilities_t _caps_p [] = | |
61 | { | |
ceacedba | 62 | ZCAP_NET_RAW, |
edd7c245 | 63 | ZCAP_BIND |
64 | }; | |
65 | ||
66 | struct zebra_privs_t ripngd_privs = | |
67 | { | |
b2f36157 DL |
68 | #if defined(FRR_USER) |
69 | .user = FRR_USER, | |
edd7c245 | 70 | #endif |
b2f36157 DL |
71 | #if defined FRR_GROUP |
72 | .group = FRR_GROUP, | |
d81fadfd | 73 | #endif |
74 | #ifdef VTY_GROUP | |
75 | .vty_group = VTY_GROUP, | |
edd7c245 | 76 | #endif |
77 | .caps_p = _caps_p, | |
78 | .cap_num_p = 2, | |
79 | .cap_num_i = 0 | |
80 | }; | |
81 | ||
82 | ||
718e3744 | 83 | /* RIPngd program name */ |
84 | ||
85 | /* Route retain mode flag. */ | |
86 | int retain_mode = 0; | |
87 | ||
88 | /* Master of threads. */ | |
89 | struct thread_master *master; | |
90 | ||
91 | /* Process ID saved for use by init system */ | |
7a1d583c | 92 | const char *pid_file = PATH_RIPNGD_PID; |
718e3744 | 93 | |
718e3744 | 94 | /* SIGHUP handler. */ |
6ac29a51 | 95 | static void |
2d75d052 | 96 | sighup (void) |
718e3744 | 97 | { |
a94434b6 | 98 | zlog_info ("SIGHUP received"); |
99 | ripng_clean (); | |
100 | ripng_reset (); | |
a94434b6 | 101 | |
102 | /* Reload config file. */ | |
320ec10a | 103 | vty_read_config (config_file, config_default); |
a94434b6 | 104 | |
105 | /* Try to return to normal operation. */ | |
718e3744 | 106 | } |
107 | ||
108 | /* SIGINT handler. */ | |
6ac29a51 | 109 | static void |
2d75d052 | 110 | sigint (void) |
718e3744 | 111 | { |
887c44a4 | 112 | zlog_notice ("Terminating on signal"); |
718e3744 | 113 | |
114 | if (! retain_mode) | |
a94434b6 | 115 | ripng_clean (); |
718e3744 | 116 | |
117 | exit (0); | |
118 | } | |
119 | ||
120 | /* SIGUSR1 handler. */ | |
6ac29a51 | 121 | static void |
2d75d052 | 122 | sigusr1 (void) |
718e3744 | 123 | { |
124 | zlog_rotate (NULL); | |
125 | } | |
126 | ||
2d75d052 | 127 | struct quagga_signal_t ripng_signals[] = |
718e3744 | 128 | { |
2d75d052 | 129 | { |
130 | .signal = SIGHUP, | |
131 | .handler = &sighup, | |
132 | }, | |
133 | { | |
134 | .signal = SIGUSR1, | |
135 | .handler = &sigusr1, | |
136 | }, | |
137 | { | |
138 | .signal = SIGINT, | |
139 | .handler = &sigint, | |
140 | }, | |
f571dab0 | 141 | { |
142 | .signal = SIGTERM, | |
143 | .handler = &sigint, | |
144 | }, | |
2d75d052 | 145 | }; |
6b0655a2 | 146 | |
4f04a76b DL |
147 | FRR_DAEMON_INFO(ripngd, RIPNG, |
148 | .vty_port = RIPNG_VTY_PORT, | |
149 | ||
150 | .proghelp = "Implementation of the RIPng routing protocol.", | |
151 | ||
152 | .signals = ripng_signals, | |
153 | .n_signals = array_size(ripng_signals), | |
154 | ||
155 | .privs = &ripngd_privs, | |
156 | ) | |
157 | ||
718e3744 | 158 | /* RIPngd main routine. */ |
159 | int | |
160 | main (int argc, char **argv) | |
161 | { | |
718e3744 | 162 | int daemon_mode = 0; |
718e3744 | 163 | struct thread thread; |
876b8be0 | 164 | int dryrun = 0; |
718e3744 | 165 | |
4f04a76b DL |
166 | frr_preinit (&ripngd_di, argc, argv); |
167 | frr_opt_add ("df:i:z:rC", longopts, | |
168 | " -d, --daemon Runs in daemon mode\n" | |
169 | " -f, --config_file Set configuration file name\n" | |
170 | " -i, --pid_file Set process identifier file name\n" | |
171 | " -z, --socket Set path of zebra socket\n" | |
172 | " -C, --dryrun Check configuration for validity and exit\n" | |
173 | " -r, --retain When program terminates, retain added route by ripd.\n"); | |
718e3744 | 174 | |
175 | while (1) | |
176 | { | |
177 | int opt; | |
178 | ||
4f04a76b | 179 | opt = frr_getopt (argc, argv, NULL); |
718e3744 | 180 | |
181 | if (opt == EOF) | |
182 | break; | |
183 | ||
184 | switch (opt) | |
185 | { | |
186 | case 0: | |
187 | break; | |
188 | case 'd': | |
189 | daemon_mode = 1; | |
190 | break; | |
718e3744 | 191 | case 'f': |
192 | config_file = optarg; | |
193 | break; | |
718e3744 | 194 | case 'i': |
195 | pid_file = optarg; | |
b5114685 VT |
196 | break; |
197 | case 'z': | |
198 | zclient_serv_path_set (optarg); | |
199 | break; | |
718e3744 | 200 | case 'r': |
201 | retain_mode = 1; | |
202 | break; | |
876b8be0 PJ |
203 | case 'C': |
204 | dryrun = 1; | |
205 | break; | |
718e3744 | 206 | default: |
4f04a76b | 207 | frr_help_exit (1); |
718e3744 | 208 | break; |
209 | } | |
210 | } | |
211 | ||
4f04a76b | 212 | master = frr_init (); |
718e3744 | 213 | |
214 | /* Library inits. */ | |
6a69b354 | 215 | vrf_init (); |
718e3744 | 216 | |
217 | /* RIPngd inits. */ | |
218 | ripng_init (); | |
4140ca4d | 219 | zebra_init(master); |
a94434b6 | 220 | ripng_peer_init (); |
221 | ||
718e3744 | 222 | /* Get configuration file. */ |
320ec10a | 223 | vty_read_config (config_file, config_default); |
718e3744 | 224 | |
876b8be0 PJ |
225 | /* Start execution only if not in dry-run mode */ |
226 | if(dryrun) | |
227 | return(0); | |
228 | ||
718e3744 | 229 | /* Change to the daemon program. */ |
065de903 SH |
230 | if (daemon_mode && daemon (0, 0) < 0) |
231 | { | |
232 | zlog_err("RIPNGd daemon failed: %s", strerror(errno)); | |
233 | exit (1); | |
234 | } | |
718e3744 | 235 | |
236 | /* Create VTY socket */ | |
4f04a76b | 237 | frr_vty_serv (RIPNG_VTYSH_PATH); |
718e3744 | 238 | |
239 | /* Process id file create. */ | |
240 | pid_output (pid_file); | |
241 | ||
887c44a4 | 242 | /* Print banner. */ |
4f04a76b | 243 | zlog_notice ("RIPNGd %s starting: vty@%d", FRR_VERSION, ripngd_di.vty_port); |
887c44a4 | 244 | |
718e3744 | 245 | /* Fetch next active thread. */ |
246 | while (thread_fetch (master, &thread)) | |
247 | thread_call (&thread); | |
248 | ||
249 | /* Not reached. */ | |
e8e1946e | 250 | return 0; |
718e3744 | 251 | } |