]>
Commit | Line | Data |
---|---|---|
1 | // SPDX-License-Identifier: GPL-2.0-or-later | |
2 | /* | |
3 | * Copyright (C) 1999 Yasuhiro Ohara | |
4 | */ | |
5 | ||
6 | #include <zebra.h> | |
7 | #include <lib/version.h> | |
8 | #include <lib/keychain.h> | |
9 | #include <stdlib.h> | |
10 | ||
11 | #include "getopt.h" | |
12 | #include "thread.h" | |
13 | #include "log.h" | |
14 | #include "command.h" | |
15 | #include "vty.h" | |
16 | #include "memory.h" | |
17 | #include "if.h" | |
18 | #include "filter.h" | |
19 | #include "prefix.h" | |
20 | #include "plist.h" | |
21 | #include "privs.h" | |
22 | #include "sigevent.h" | |
23 | #include "zclient.h" | |
24 | #include "vrf.h" | |
25 | #include "bfd.h" | |
26 | #include "libfrr.h" | |
27 | ||
28 | #include "ospf6d.h" | |
29 | #include "ospf6_top.h" | |
30 | #include "ospf6_message.h" | |
31 | #include "ospf6_network.h" | |
32 | #include "ospf6_asbr.h" | |
33 | #include "ospf6_lsa.h" | |
34 | #include "ospf6_interface.h" | |
35 | #include "ospf6_zebra.h" | |
36 | #include "ospf6_routemap_nb.h" | |
37 | ||
38 | /* Default configuration file name for ospf6d. */ | |
39 | #define OSPF6_DEFAULT_CONFIG "ospf6d.conf" | |
40 | ||
41 | /* Default port values. */ | |
42 | #define OSPF6_VTY_PORT 2606 | |
43 | ||
44 | /* ospf6d privileges */ | |
45 | zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN}; | |
46 | ||
47 | struct zebra_privs_t ospf6d_privs = { | |
48 | #if defined(FRR_USER) | |
49 | .user = FRR_USER, | |
50 | #endif | |
51 | #if defined FRR_GROUP | |
52 | .group = FRR_GROUP, | |
53 | #endif | |
54 | #ifdef VTY_GROUP | |
55 | .vty_group = VTY_GROUP, | |
56 | #endif | |
57 | .caps_p = _caps_p, | |
58 | .cap_num_p = array_size(_caps_p), | |
59 | .cap_num_i = 0}; | |
60 | ||
61 | /* ospf6d options, we use GNU getopt library. */ | |
62 | struct option longopts[] = {{0}}; | |
63 | ||
64 | /* Master of threads. */ | |
65 | struct thread_master *master; | |
66 | ||
67 | static void __attribute__((noreturn)) ospf6_exit(int status) | |
68 | { | |
69 | struct vrf *vrf; | |
70 | struct interface *ifp; | |
71 | struct ospf6 *ospf6; | |
72 | struct listnode *node, *nnode; | |
73 | ||
74 | frr_early_fini(); | |
75 | ||
76 | bfd_protocol_integration_set_shutdown(true); | |
77 | ||
78 | for (ALL_LIST_ELEMENTS(om6->ospf6, node, nnode, ospf6)) { | |
79 | vrf = vrf_lookup_by_id(ospf6->vrf_id); | |
80 | ospf6_delete(ospf6); | |
81 | ospf6 = NULL; | |
82 | FOR_ALL_INTERFACES (vrf, ifp) | |
83 | if (ifp->info != NULL) | |
84 | ospf6_interface_delete(ifp->info); | |
85 | } | |
86 | ||
87 | ospf6_message_terminate(); | |
88 | ospf6_asbr_terminate(); | |
89 | ospf6_lsa_terminate(); | |
90 | ||
91 | /* reverse access_list_init */ | |
92 | access_list_reset(); | |
93 | ||
94 | /* reverse prefix_list_init */ | |
95 | prefix_list_add_hook(NULL); | |
96 | prefix_list_delete_hook(NULL); | |
97 | prefix_list_reset(); | |
98 | ||
99 | vrf_terminate(); | |
100 | ||
101 | if (zclient) { | |
102 | zclient_stop(zclient); | |
103 | zclient_free(zclient); | |
104 | } | |
105 | ||
106 | frr_fini(); | |
107 | exit(status); | |
108 | } | |
109 | ||
110 | /* SIGHUP handler. */ | |
111 | static void sighup(void) | |
112 | { | |
113 | zlog_info("SIGHUP received"); | |
114 | } | |
115 | ||
116 | /* SIGINT handler. */ | |
117 | static void sigint(void) | |
118 | { | |
119 | zlog_notice("Terminating on signal SIGINT"); | |
120 | ospf6_exit(0); | |
121 | } | |
122 | ||
123 | /* SIGTERM handler. */ | |
124 | static void sigterm(void) | |
125 | { | |
126 | zlog_notice("Terminating on signal SIGTERM"); | |
127 | ospf6_exit(0); | |
128 | } | |
129 | ||
130 | /* SIGUSR1 handler. */ | |
131 | static void sigusr1(void) | |
132 | { | |
133 | zlog_info("SIGUSR1 received"); | |
134 | zlog_rotate(); | |
135 | } | |
136 | ||
137 | struct frr_signal_t ospf6_signals[] = { | |
138 | { | |
139 | .signal = SIGHUP, | |
140 | .handler = &sighup, | |
141 | }, | |
142 | { | |
143 | .signal = SIGINT, | |
144 | .handler = &sigint, | |
145 | }, | |
146 | { | |
147 | .signal = SIGTERM, | |
148 | .handler = &sigterm, | |
149 | }, | |
150 | { | |
151 | .signal = SIGUSR1, | |
152 | .handler = &sigusr1, | |
153 | }, | |
154 | }; | |
155 | ||
156 | static const struct frr_yang_module_info *const ospf6d_yang_modules[] = { | |
157 | &frr_filter_info, | |
158 | &frr_interface_info, | |
159 | &frr_route_map_info, | |
160 | &frr_vrf_info, | |
161 | &frr_ospf_route_map_info, | |
162 | &frr_ospf6_route_map_info, | |
163 | }; | |
164 | ||
165 | FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT, | |
166 | ||
167 | .proghelp = "Implementation of the OSPFv3 routing protocol.", | |
168 | ||
169 | .signals = ospf6_signals, | |
170 | .n_signals = array_size(ospf6_signals), | |
171 | ||
172 | .privs = &ospf6d_privs, .yang_modules = ospf6d_yang_modules, | |
173 | .n_yang_modules = array_size(ospf6d_yang_modules), | |
174 | ); | |
175 | ||
176 | /* Main routine of ospf6d. Treatment of argument and starting ospf finite | |
177 | state machine is handled here. */ | |
178 | int main(int argc, char *argv[], char *envp[]) | |
179 | { | |
180 | int opt; | |
181 | ||
182 | frr_preinit(&ospf6d_di, argc, argv); | |
183 | frr_opt_add("", longopts, ""); | |
184 | ||
185 | /* Command line argument treatment. */ | |
186 | while (1) { | |
187 | opt = frr_getopt(argc, argv, NULL); | |
188 | ||
189 | if (opt == EOF) | |
190 | break; | |
191 | ||
192 | switch (opt) { | |
193 | case 0: | |
194 | break; | |
195 | default: | |
196 | frr_help_exit(1); | |
197 | } | |
198 | } | |
199 | ||
200 | if (geteuid() != 0) { | |
201 | errno = EPERM; | |
202 | perror(ospf6d_di.progname); | |
203 | exit(1); | |
204 | } | |
205 | ||
206 | /* OSPF6 master init. */ | |
207 | ospf6_master_init(frr_init()); | |
208 | ||
209 | /* thread master */ | |
210 | master = om6->master; | |
211 | ||
212 | keychain_init(); | |
213 | ospf6_vrf_init(); | |
214 | access_list_init(); | |
215 | prefix_list_init(); | |
216 | ||
217 | /* initialize ospf6 */ | |
218 | ospf6_init(master); | |
219 | ||
220 | frr_config_fork(); | |
221 | frr_run(master); | |
222 | ||
223 | /* Not reached. */ | |
224 | ospf6_exit(0); | |
225 | } |