]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
2 | * Copyright (C) 1999 Yasuhiro Ohara | |
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 | * | |
896014f4 DL |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 19 | */ |
20 | ||
21 | #include <zebra.h> | |
3b4cd3a9 | 22 | #include <lib/version.h> |
c3c0ac83 | 23 | #include <stdlib.h> |
508e53e2 | 24 | |
718e3744 | 25 | #include "getopt.h" |
26 | #include "thread.h" | |
27 | #include "log.h" | |
718e3744 | 28 | #include "command.h" |
29 | #include "vty.h" | |
30 | #include "memory.h" | |
fc7948fa | 31 | #include "memory_vty.h" |
508e53e2 | 32 | #include "if.h" |
33 | #include "filter.h" | |
34 | #include "prefix.h" | |
35 | #include "plist.h" | |
edd7c245 | 36 | #include "privs.h" |
e42f5a37 | 37 | #include "sigevent.h" |
87362ceb | 38 | #include "zclient.h" |
6a69b354 | 39 | #include "vrf.h" |
567b877d | 40 | #include "bfd.h" |
4f04a76b | 41 | #include "libfrr.h" |
718e3744 | 42 | |
43 | #include "ospf6d.h" | |
87362ceb DO |
44 | #include "ospf6_top.h" |
45 | #include "ospf6_message.h" | |
d51884e6 | 46 | #include "ospf6_network.h" |
87362ceb DO |
47 | #include "ospf6_asbr.h" |
48 | #include "ospf6_lsa.h" | |
d9628728 CF |
49 | #include "ospf6_interface.h" |
50 | #include "ospf6_zebra.h" | |
718e3744 | 51 | |
52 | /* Default configuration file name for ospf6d. */ | |
53 | #define OSPF6_DEFAULT_CONFIG "ospf6d.conf" | |
508e53e2 | 54 | |
718e3744 | 55 | /* Default port values. */ |
56 | #define OSPF6_VTY_PORT 2606 | |
57 | ||
edd7c245 | 58 | /* ospf6d privileges */ |
d62a17ae | 59 | zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND}; |
edd7c245 | 60 | |
d62a17ae | 61 | struct zebra_privs_t ospf6d_privs = { |
b2f36157 | 62 | #if defined(FRR_USER) |
d62a17ae | 63 | .user = FRR_USER, |
edd7c245 | 64 | #endif |
b2f36157 | 65 | #if defined FRR_GROUP |
d62a17ae | 66 | .group = FRR_GROUP, |
d81fadfd | 67 | #endif |
68 | #ifdef VTY_GROUP | |
d62a17ae | 69 | .vty_group = VTY_GROUP, |
edd7c245 | 70 | #endif |
d62a17ae | 71 | .caps_p = _caps_p, |
72 | .cap_num_p = 2, | |
73 | .cap_num_i = 0}; | |
edd7c245 | 74 | |
718e3744 | 75 | /* ospf6d options, we use GNU getopt library. */ |
d62a17ae | 76 | struct option longopts[] = {{0}}; |
718e3744 | 77 | |
718e3744 | 78 | /* Master of threads. */ |
79 | struct thread_master *master; | |
80 | ||
d62a17ae | 81 | static void __attribute__((noreturn)) ospf6_exit(int status) |
ae2254aa | 82 | { |
f4e14fdb | 83 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); |
d62a17ae | 84 | struct interface *ifp; |
ae2254aa | 85 | |
03951374 DL |
86 | frr_early_fini(); |
87 | ||
18f286ad | 88 | if (ospf6) { |
d62a17ae | 89 | ospf6_delete(ospf6); |
18f286ad PG |
90 | ospf6 = NULL; |
91 | } | |
ae2254aa | 92 | |
d62a17ae | 93 | bfd_gbl_exit(); |
567b877d | 94 | |
451fda4f | 95 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 96 | if (ifp->info != NULL) |
97 | ospf6_interface_delete(ifp->info); | |
d9628728 | 98 | |
d62a17ae | 99 | ospf6_message_terminate(); |
100 | ospf6_asbr_terminate(); | |
101 | ospf6_lsa_terminate(); | |
ae2254aa | 102 | |
d51884e6 | 103 | ospf6_serv_close(); |
856ae1eb CS |
104 | /* reverse access_list_init */ |
105 | access_list_reset(); | |
106 | ||
107 | /* reverse prefix_list_init */ | |
108 | prefix_list_add_hook(NULL); | |
109 | prefix_list_delete_hook(NULL); | |
110 | prefix_list_reset(); | |
111 | ||
d62a17ae | 112 | vrf_terminate(); |
ae2254aa | 113 | |
d62a17ae | 114 | if (zclient) { |
115 | zclient_stop(zclient); | |
116 | zclient_free(zclient); | |
117 | } | |
ae2254aa | 118 | |
03951374 | 119 | frr_fini(); |
d62a17ae | 120 | exit(status); |
ae2254aa TG |
121 | } |
122 | ||
718e3744 | 123 | /* SIGHUP handler. */ |
d62a17ae | 124 | static void sighup(void) |
718e3744 | 125 | { |
d62a17ae | 126 | zlog_info("SIGHUP received"); |
718e3744 | 127 | } |
128 | ||
129 | /* SIGINT handler. */ | |
d62a17ae | 130 | static void sigint(void) |
718e3744 | 131 | { |
d62a17ae | 132 | zlog_notice("Terminating on signal SIGINT"); |
133 | ospf6_exit(0); | |
718e3744 | 134 | } |
135 | ||
136 | /* SIGTERM handler. */ | |
d62a17ae | 137 | static void sigterm(void) |
718e3744 | 138 | { |
d62a17ae | 139 | zlog_notice("Terminating on signal SIGTERM"); |
d62a17ae | 140 | ospf6_exit(0); |
718e3744 | 141 | } |
142 | ||
143 | /* SIGUSR1 handler. */ | |
d62a17ae | 144 | static void sigusr1(void) |
718e3744 | 145 | { |
d62a17ae | 146 | zlog_info("SIGUSR1 received"); |
147 | zlog_rotate(); | |
718e3744 | 148 | } |
149 | ||
d62a17ae | 150 | struct quagga_signal_t ospf6_signals[] = { |
151 | { | |
152 | .signal = SIGHUP, | |
153 | .handler = &sighup, | |
154 | }, | |
155 | { | |
156 | .signal = SIGINT, | |
157 | .handler = &sigint, | |
158 | }, | |
159 | { | |
160 | .signal = SIGTERM, | |
161 | .handler = &sigterm, | |
162 | }, | |
163 | { | |
164 | .signal = SIGUSR1, | |
165 | .handler = &sigusr1, | |
166 | }, | |
e42f5a37 | 167 | }; |
508e53e2 | 168 | |
8fcdd0d6 | 169 | static const struct frr_yang_module_info *ospf6d_yang_modules[] = { |
a4bed468 | 170 | &frr_interface_info, |
8fcdd0d6 RW |
171 | }; |
172 | ||
d62a17ae | 173 | FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT, |
4f04a76b | 174 | |
d62a17ae | 175 | .proghelp = "Implementation of the OSPFv3 routing protocol.", |
4f04a76b | 176 | |
d62a17ae | 177 | .signals = ospf6_signals, |
178 | .n_signals = array_size(ospf6_signals), | |
4f04a76b | 179 | |
8fcdd0d6 RW |
180 | .privs = &ospf6d_privs, .yang_modules = ospf6d_yang_modules, |
181 | .n_yang_modules = array_size(ospf6d_yang_modules), ) | |
4f04a76b | 182 | |
508e53e2 | 183 | /* Main routine of ospf6d. Treatment of argument and starting ospf finite |
718e3744 | 184 | state machine is handled here. */ |
d62a17ae | 185 | int main(int argc, char *argv[], char *envp[]) |
718e3744 | 186 | { |
d62a17ae | 187 | int opt; |
188 | ||
189 | frr_preinit(&ospf6d_di, argc, argv); | |
190 | frr_opt_add("", longopts, ""); | |
718e3744 | 191 | |
d62a17ae | 192 | /* Command line argument treatment. */ |
193 | while (1) { | |
194 | opt = frr_getopt(argc, argv, NULL); | |
508e53e2 | 195 | |
d62a17ae | 196 | if (opt == EOF) |
197 | break; | |
198 | ||
199 | switch (opt) { | |
200 | case 0: | |
201 | break; | |
202 | default: | |
203 | frr_help_exit(1); | |
204 | break; | |
205 | } | |
206 | } | |
207 | ||
208 | if (geteuid() != 0) { | |
209 | errno = EPERM; | |
210 | perror(ospf6d_di.progname); | |
211 | exit(1); | |
212 | } | |
213 | ||
78c6ba61 CS |
214 | /* OSPF6 master init. */ |
215 | ospf6_master_init(); | |
216 | ||
d62a17ae | 217 | /* thread master */ |
218 | master = frr_init(); | |
219 | ||
ecbc5a37 | 220 | vrf_init(NULL, NULL, NULL, NULL, NULL); |
d62a17ae | 221 | access_list_init(); |
222 | prefix_list_init(); | |
223 | ||
224 | /* initialize ospf6 */ | |
225 | ospf6_init(); | |
226 | ||
227 | frr_config_fork(); | |
228 | frr_run(master); | |
229 | ||
230 | /* Not reached. */ | |
231 | ospf6_exit(0); | |
232 | } |