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