]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
2 | * OSPFd main routine. | |
3 | * Copyright (C) 1998, 99 Kunihiro Ishiguro, Toshiaki Takada | |
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 | * | |
896014f4 DL |
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 | |
718e3744 | 20 | */ |
21 | ||
22 | #include <zebra.h> | |
23 | ||
5e4fa164 | 24 | #include <lib/version.h> |
659f4e40 | 25 | #include "bfd.h" |
718e3744 | 26 | #include "getopt.h" |
27 | #include "thread.h" | |
28 | #include "prefix.h" | |
29 | #include "linklist.h" | |
30 | #include "if.h" | |
31 | #include "vector.h" | |
32 | #include "vty.h" | |
33 | #include "command.h" | |
34 | #include "filter.h" | |
35 | #include "plist.h" | |
36 | #include "stream.h" | |
37 | #include "log.h" | |
38 | #include "memory.h" | |
edd7c245 | 39 | #include "privs.h" |
2d75d052 | 40 | #include "sigevent.h" |
b5114685 | 41 | #include "zclient.h" |
6a69b354 | 42 | #include "vrf.h" |
4f04a76b | 43 | #include "libfrr.h" |
91835f1f | 44 | #include "routemap.h" |
718e3744 | 45 | |
46 | #include "ospfd/ospfd.h" | |
47 | #include "ospfd/ospf_interface.h" | |
48 | #include "ospfd/ospf_asbr.h" | |
49 | #include "ospfd/ospf_lsa.h" | |
50 | #include "ospfd/ospf_lsdb.h" | |
51 | #include "ospfd/ospf_neighbor.h" | |
52 | #include "ospfd/ospf_dump.h" | |
19c0412a | 53 | #include "ospfd/ospf_route.h" |
718e3744 | 54 | #include "ospfd/ospf_zebra.h" |
55 | #include "ospfd/ospf_vty.h" | |
7f342629 | 56 | #include "ospfd/ospf_bfd.h" |
10514170 | 57 | #include "ospfd/ospf_gr.h" |
313d7993 | 58 | #include "ospfd/ospf_errors.h" |
132a782e | 59 | #include "ospfd/ospf_ldp_sync.h" |
a623b526 | 60 | #include "ospfd/ospf_routemap_nb.h" |
718e3744 | 61 | |
edd7c245 | 62 | /* ospfd privileges */ |
996c9314 LB |
63 | zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN, |
64 | ZCAP_SYS_ADMIN}; | |
edd7c245 | 65 | |
d62a17ae | 66 | struct zebra_privs_t ospfd_privs = { |
b2f36157 | 67 | #if defined(FRR_USER) && defined(FRR_GROUP) |
d62a17ae | 68 | .user = FRR_USER, |
69 | .group = FRR_GROUP, | |
edd7c245 | 70 | #endif |
71 | #if defined(VTY_GROUP) | |
d62a17ae | 72 | .vty_group = VTY_GROUP, |
edd7c245 | 73 | #endif |
d62a17ae | 74 | .caps_p = _caps_p, |
75 | .cap_num_p = array_size(_caps_p), | |
76 | .cap_num_i = 0}; | |
edd7c245 | 77 | |
718e3744 | 78 | /* OSPFd options. */ |
2b64873d DL |
79 | const struct option longopts[] = { |
80 | {"instance", required_argument, NULL, 'n'}, | |
81 | {"apiserver", no_argument, NULL, 'a'}, | |
82 | {0} | |
83 | }; | |
718e3744 | 84 | |
85 | /* OSPFd program name */ | |
86 | ||
87 | /* Master of threads. */ | |
88 | struct thread_master *master; | |
89 | ||
d68614db | 90 | #ifdef SUPPORT_OSPF_API |
f4d58ce5 | 91 | extern int ospf_apiserver_enable; |
d68614db | 92 | #endif /* SUPPORT_OSPF_API */ |
c3abdb72 | 93 | |
718e3744 | 94 | /* SIGHUP handler. */ |
d62a17ae | 95 | static void sighup(void) |
718e3744 | 96 | { |
d62a17ae | 97 | zlog_info("SIGHUP received"); |
718e3744 | 98 | } |
99 | ||
88d6cf37 | 100 | /* SIGINT / SIGTERM handler. */ |
d62a17ae | 101 | static void sigint(void) |
718e3744 | 102 | { |
d62a17ae | 103 | zlog_notice("Terminating on signal"); |
659f4e40 | 104 | bfd_protocol_integration_set_shutdown(true); |
d62a17ae | 105 | ospf_terminate(); |
41b21bfa | 106 | exit(0); |
718e3744 | 107 | } |
108 | ||
109 | /* SIGUSR1 handler. */ | |
d62a17ae | 110 | static void sigusr1(void) |
718e3744 | 111 | { |
d62a17ae | 112 | zlog_rotate(); |
718e3744 | 113 | } |
114 | ||
7cc91e67 | 115 | struct frr_signal_t ospf_signals[] = { |
d62a17ae | 116 | { |
117 | .signal = SIGHUP, | |
118 | .handler = &sighup, | |
119 | }, | |
120 | { | |
121 | .signal = SIGUSR1, | |
122 | .handler = &sigusr1, | |
123 | }, | |
124 | { | |
125 | .signal = SIGINT, | |
126 | .handler = &sigint, | |
127 | }, | |
128 | { | |
129 | .signal = SIGTERM, | |
130 | .handler = &sigint, | |
131 | }, | |
2d75d052 | 132 | }; |
6b0655a2 | 133 | |
0d8c7a26 | 134 | static const struct frr_yang_module_info *const ospfd_yang_modules[] = { |
c2aab693 | 135 | &frr_filter_info, |
a4bed468 | 136 | &frr_interface_info, |
91835f1f | 137 | &frr_route_map_info, |
6fd8972a | 138 | &frr_vrf_info, |
a623b526 | 139 | &frr_ospf_route_map_info, |
8fcdd0d6 RW |
140 | }; |
141 | ||
d62a17ae | 142 | FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT, |
4f04a76b | 143 | |
d62a17ae | 144 | .proghelp = "Implementation of the OSPFv2 routing protocol.", |
4f04a76b | 145 | |
d62a17ae | 146 | .signals = ospf_signals, .n_signals = array_size(ospf_signals), |
4f04a76b | 147 | |
8fcdd0d6 | 148 | .privs = &ospfd_privs, .yang_modules = ospfd_yang_modules, |
80413c20 DL |
149 | .n_yang_modules = array_size(ospfd_yang_modules), |
150 | ); | |
4f04a76b | 151 | |
718e3744 | 152 | /* OSPFd main routine. */ |
d62a17ae | 153 | int main(int argc, char **argv) |
718e3744 | 154 | { |
822d8f55 | 155 | #ifdef SUPPORT_OSPF_API |
d62a17ae | 156 | /* OSPF apiserver is disabled by default. */ |
157 | ospf_apiserver_enable = 0; | |
822d8f55 DL |
158 | #endif /* SUPPORT_OSPF_API */ |
159 | ||
d62a17ae | 160 | frr_preinit(&ospfd_di, argc, argv); |
161 | frr_opt_add("n:a", longopts, | |
162 | " -n, --instance Set the instance id\n" | |
163 | " -a, --apiserver Enable OSPF apiserver\n"); | |
718e3744 | 164 | |
d62a17ae | 165 | while (1) { |
166 | int opt; | |
718e3744 | 167 | |
d62a17ae | 168 | opt = frr_getopt(argc, argv, NULL); |
718e3744 | 169 | |
d62a17ae | 170 | if (opt == EOF) |
171 | break; | |
172 | ||
173 | switch (opt) { | |
174 | case 'n': | |
409f98ab IR |
175 | ospfd_di.instance = ospf_instance = atoi(optarg); |
176 | if (ospf_instance < 1) | |
d62a17ae | 177 | exit(0); |
178 | break; | |
179 | case 0: | |
180 | break; | |
d68614db | 181 | #ifdef SUPPORT_OSPF_API |
d62a17ae | 182 | case 'a': |
183 | ospf_apiserver_enable = 1; | |
184 | break; | |
d68614db | 185 | #endif /* SUPPORT_OSPF_API */ |
d62a17ae | 186 | default: |
187 | frr_help_exit(1); | |
d62a17ae | 188 | } |
718e3744 | 189 | } |
718e3744 | 190 | |
d62a17ae | 191 | /* Invoked by a priviledged user? -- endo. */ |
192 | if (geteuid() != 0) { | |
193 | errno = EPERM; | |
194 | perror(ospfd_di.progname); | |
195 | exit(1); | |
196 | } | |
197 | ||
198 | /* OSPF master init. */ | |
199 | ospf_master_init(frr_init()); | |
200 | ||
201 | /* Initializations. */ | |
202 | master = om->master; | |
203 | ||
204 | /* Library inits. */ | |
6243a7b5 | 205 | ospf_debug_init(); |
b5a8894d | 206 | ospf_vrf_init(); |
d62a17ae | 207 | |
208 | access_list_init(); | |
209 | prefix_list_init(); | |
210 | ||
211 | /* OSPFd inits. */ | |
212 | ospf_if_init(); | |
409f98ab | 213 | ospf_zebra_init(master, ospf_instance); |
d62a17ae | 214 | |
215 | /* OSPF vty inits. */ | |
216 | ospf_vty_init(); | |
217 | ospf_vty_show_init(); | |
218 | ospf_vty_clear_init(); | |
219 | ||
220 | /* OSPF BFD init */ | |
659f4e40 | 221 | ospf_bfd_init(master); |
d62a17ae | 222 | |
132a782e | 223 | /* OSPF LDP IGP Sync init */ |
224 | ospf_ldp_sync_init(); | |
225 | ||
d62a17ae | 226 | ospf_route_map_init(); |
227 | ospf_opaque_init(); | |
10514170 | 228 | ospf_gr_init(); |
51f8588e | 229 | ospf_gr_helper_init(); |
d62a17ae | 230 | |
5ad4c39c QY |
231 | /* OSPF errors init */ |
232 | ospf_error_init(); | |
233 | ||
d62a17ae | 234 | frr_config_fork(); |
235 | frr_run(master); | |
236 | ||
237 | /* Not reached. */ | |
95f7965d | 238 | return 0; |
d62a17ae | 239 | } |