]>
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 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with GNU Zebra; see the file COPYING. If not, write to the | |
18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | * Boston, MA 02111-1307, USA. | |
20 | */ | |
21 | ||
22 | #include <zebra.h> | |
3b4cd3a9 | 23 | #include <lib/version.h> |
c3c0ac83 | 24 | #include <stdlib.h> |
508e53e2 | 25 | |
718e3744 | 26 | #include "getopt.h" |
27 | #include "thread.h" | |
28 | #include "log.h" | |
718e3744 | 29 | #include "command.h" |
30 | #include "vty.h" | |
31 | #include "memory.h" | |
fc7948fa | 32 | #include "memory_vty.h" |
508e53e2 | 33 | #include "if.h" |
34 | #include "filter.h" | |
35 | #include "prefix.h" | |
36 | #include "plist.h" | |
edd7c245 | 37 | #include "privs.h" |
e42f5a37 | 38 | #include "sigevent.h" |
87362ceb | 39 | #include "zclient.h" |
6a69b354 | 40 | #include "vrf.h" |
567b877d | 41 | #include "bfd.h" |
4f04a76b | 42 | #include "libfrr.h" |
718e3744 | 43 | |
44 | #include "ospf6d.h" | |
87362ceb DO |
45 | #include "ospf6_top.h" |
46 | #include "ospf6_message.h" | |
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 */ |
508e53e2 | 59 | zebra_capabilities_t _caps_p [] = |
edd7c245 | 60 | { |
ceacedba | 61 | ZCAP_NET_RAW, |
edd7c245 | 62 | ZCAP_BIND |
63 | }; | |
64 | ||
65 | struct zebra_privs_t ospf6d_privs = | |
66 | { | |
b2f36157 DL |
67 | #if defined(FRR_USER) |
68 | .user = FRR_USER, | |
edd7c245 | 69 | #endif |
b2f36157 DL |
70 | #if defined FRR_GROUP |
71 | .group = FRR_GROUP, | |
d81fadfd | 72 | #endif |
73 | #ifdef VTY_GROUP | |
74 | .vty_group = VTY_GROUP, | |
edd7c245 | 75 | #endif |
76 | .caps_p = _caps_p, | |
77 | .cap_num_p = 2, | |
78 | .cap_num_i = 0 | |
79 | }; | |
80 | ||
718e3744 | 81 | /* ospf6d options, we use GNU getopt library. */ |
82 | struct option longopts[] = | |
83 | { | |
718e3744 | 84 | { 0 } |
85 | }; | |
86 | ||
718e3744 | 87 | /* Master of threads. */ |
88 | struct thread_master *master; | |
89 | ||
c143c38b | 90 | static void __attribute__ ((noreturn)) |
ae2254aa TG |
91 | ospf6_exit (int status) |
92 | { | |
d9628728 CF |
93 | struct listnode *node; |
94 | struct interface *ifp; | |
ae2254aa TG |
95 | |
96 | if (ospf6) | |
97 | ospf6_delete (ospf6); | |
98 | ||
567b877d | 99 | bfd_gbl_exit(); |
100 | ||
b2d7c082 | 101 | for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp)) |
d9628728 CF |
102 | if (ifp->info != NULL) |
103 | ospf6_interface_delete(ifp->info); | |
104 | ||
ae2254aa TG |
105 | ospf6_message_terminate (); |
106 | ospf6_asbr_terminate (); | |
107 | ospf6_lsa_terminate (); | |
108 | ||
6a69b354 | 109 | vrf_terminate (); |
ae2254aa TG |
110 | vty_terminate (); |
111 | cmd_terminate (); | |
112 | ||
113 | if (zclient) | |
114 | zclient_free (zclient); | |
115 | ||
116 | if (master) | |
117 | thread_master_free (master); | |
118 | ||
119 | if (zlog_default) | |
120 | closezlog (zlog_default); | |
121 | ||
122 | exit (status); | |
123 | } | |
124 | ||
718e3744 | 125 | /* SIGHUP handler. */ |
6ac29a51 | 126 | static void |
e42f5a37 | 127 | sighup (void) |
718e3744 | 128 | { |
129 | zlog_info ("SIGHUP received"); | |
718e3744 | 130 | } |
131 | ||
132 | /* SIGINT handler. */ | |
6ac29a51 | 133 | static void |
e42f5a37 | 134 | sigint (void) |
718e3744 | 135 | { |
887c44a4 | 136 | zlog_notice ("Terminating on signal SIGINT"); |
ae2254aa | 137 | ospf6_exit (0); |
718e3744 | 138 | } |
139 | ||
140 | /* SIGTERM handler. */ | |
6ac29a51 | 141 | static void |
e42f5a37 | 142 | sigterm (void) |
718e3744 | 143 | { |
887c44a4 | 144 | zlog_notice ("Terminating on signal SIGTERM"); |
ef2d5d10 | 145 | ospf6_clean(); |
ae2254aa | 146 | ospf6_exit (0); |
718e3744 | 147 | } |
148 | ||
149 | /* SIGUSR1 handler. */ | |
6ac29a51 | 150 | static void |
e42f5a37 | 151 | sigusr1 (void) |
718e3744 | 152 | { |
153 | zlog_info ("SIGUSR1 received"); | |
154 | zlog_rotate (NULL); | |
155 | } | |
156 | ||
e42f5a37 | 157 | struct quagga_signal_t ospf6_signals[] = |
718e3744 | 158 | { |
e42f5a37 | 159 | { |
160 | .signal = SIGHUP, | |
161 | .handler = &sighup, | |
162 | }, | |
163 | { | |
164 | .signal = SIGINT, | |
165 | .handler = &sigint, | |
166 | }, | |
167 | { | |
168 | .signal = SIGTERM, | |
169 | .handler = &sigterm, | |
170 | }, | |
171 | { | |
172 | .signal = SIGUSR1, | |
173 | .handler = &sigusr1, | |
174 | }, | |
175 | }; | |
508e53e2 | 176 | |
4f04a76b DL |
177 | FRR_DAEMON_INFO(ospf6d, OSPF6, |
178 | .vty_port = OSPF6_VTY_PORT, | |
179 | ||
180 | .proghelp = "Implementation of the OSPFv3 routing protocol.", | |
181 | ||
182 | .signals = ospf6_signals, | |
183 | .n_signals = array_size(ospf6_signals), | |
184 | ||
185 | .privs = &ospf6d_privs, | |
186 | ) | |
187 | ||
508e53e2 | 188 | /* Main routine of ospf6d. Treatment of argument and starting ospf finite |
718e3744 | 189 | state machine is handled here. */ |
190 | int | |
191 | main (int argc, char *argv[], char *envp[]) | |
192 | { | |
718e3744 | 193 | int opt; |
718e3744 | 194 | struct thread thread; |
718e3744 | 195 | |
4f04a76b | 196 | frr_preinit (&ospf6d_di, argc, argv); |
eb05883f | 197 | frr_opt_add ("", longopts, ""); |
c3c0ac83 | 198 | |
718e3744 | 199 | /* Command line argument treatment. */ |
200 | while (1) | |
201 | { | |
4f04a76b | 202 | opt = frr_getopt (argc, argv, NULL); |
718e3744 | 203 | |
204 | if (opt == EOF) | |
205 | break; | |
206 | ||
207 | switch (opt) | |
208 | { | |
209 | case 0: | |
210 | break; | |
718e3744 | 211 | default: |
4f04a76b | 212 | frr_help_exit (1); |
718e3744 | 213 | break; |
214 | } | |
215 | } | |
216 | ||
6fd16207 VT |
217 | if (geteuid () != 0) |
218 | { | |
219 | errno = EPERM; | |
4f04a76b | 220 | perror (ospf6d_di.progname); |
6fd16207 VT |
221 | exit (1); |
222 | } | |
223 | ||
718e3744 | 224 | /* thread master */ |
4f04a76b | 225 | master = frr_init (); |
2caa9b39 | 226 | |
6a69b354 | 227 | vrf_init (); |
508e53e2 | 228 | access_list_init (); |
229 | prefix_list_init (); | |
230 | ||
231 | /* initialize ospf6 */ | |
232 | ospf6_init (); | |
233 | ||
eb05883f | 234 | frr_config_fork (); |
718e3744 | 235 | |
eb05883f | 236 | frr_vty_serv (); |
718e3744 | 237 | |
238 | /* Print start message */ | |
887c44a4 | 239 | zlog_notice ("OSPF6d (Quagga-%s ospf6d-%s) starts: vty@%d", |
4f04a76b | 240 | FRR_VERSION, OSPF6_DAEMON_VERSION, ospf6d_di.vty_port); |
718e3744 | 241 | |
242 | /* Start finite state machine, here we go! */ | |
243 | while (thread_fetch (master, &thread)) | |
244 | thread_call (&thread); | |
245 | ||
246 | /* Log in case thread failed */ | |
247 | zlog_warn ("Thread failed"); | |
718e3744 | 248 | |
249 | /* Not reached. */ | |
ae2254aa | 250 | ospf6_exit (0); |
718e3744 | 251 | } |
252 | ||
508e53e2 | 253 |