]>
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" | |
52 | #include "ospfd/ospf_zebra.h" | |
53 | #include "ospfd/ospf_vty.h" | |
7f342629 | 54 | #include "ospfd/ospf_bfd.h" |
718e3744 | 55 | |
edd7c245 | 56 | /* ospfd privileges */ |
996c9314 LB |
57 | zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN, |
58 | ZCAP_SYS_ADMIN}; | |
edd7c245 | 59 | |
d62a17ae | 60 | struct zebra_privs_t ospfd_privs = { |
b2f36157 | 61 | #if defined(FRR_USER) && defined(FRR_GROUP) |
d62a17ae | 62 | .user = FRR_USER, |
63 | .group = FRR_GROUP, | |
edd7c245 | 64 | #endif |
65 | #if defined(VTY_GROUP) | |
d62a17ae | 66 | .vty_group = VTY_GROUP, |
edd7c245 | 67 | #endif |
d62a17ae | 68 | .caps_p = _caps_p, |
69 | .cap_num_p = array_size(_caps_p), | |
70 | .cap_num_i = 0}; | |
edd7c245 | 71 | |
718e3744 | 72 | /* OSPFd options. */ |
d62a17ae | 73 | struct option longopts[] = {{"instance", required_argument, NULL, 'n'}, |
74 | {"apiserver", no_argument, NULL, 'a'}, | |
75 | {0}}; | |
718e3744 | 76 | |
77 | /* OSPFd program name */ | |
78 | ||
79 | /* Master of threads. */ | |
80 | struct thread_master *master; | |
81 | ||
d68614db | 82 | #ifdef SUPPORT_OSPF_API |
f4d58ce5 | 83 | extern int ospf_apiserver_enable; |
d68614db | 84 | #endif /* SUPPORT_OSPF_API */ |
c3abdb72 | 85 | |
718e3744 | 86 | /* SIGHUP handler. */ |
d62a17ae | 87 | static void sighup(void) |
718e3744 | 88 | { |
d62a17ae | 89 | zlog_info("SIGHUP received"); |
718e3744 | 90 | } |
91 | ||
88d6cf37 | 92 | /* SIGINT / SIGTERM handler. */ |
d62a17ae | 93 | static void sigint(void) |
718e3744 | 94 | { |
d62a17ae | 95 | zlog_notice("Terminating on signal"); |
96 | ospf_terminate(); | |
718e3744 | 97 | } |
98 | ||
99 | /* SIGUSR1 handler. */ | |
d62a17ae | 100 | static void sigusr1(void) |
718e3744 | 101 | { |
d62a17ae | 102 | zlog_rotate(); |
718e3744 | 103 | } |
104 | ||
d62a17ae | 105 | struct quagga_signal_t ospf_signals[] = { |
106 | { | |
107 | .signal = SIGHUP, | |
108 | .handler = &sighup, | |
109 | }, | |
110 | { | |
111 | .signal = SIGUSR1, | |
112 | .handler = &sigusr1, | |
113 | }, | |
114 | { | |
115 | .signal = SIGINT, | |
116 | .handler = &sigint, | |
117 | }, | |
118 | { | |
119 | .signal = SIGTERM, | |
120 | .handler = &sigint, | |
121 | }, | |
2d75d052 | 122 | }; |
6b0655a2 | 123 | |
d62a17ae | 124 | FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT, |
4f04a76b | 125 | |
d62a17ae | 126 | .proghelp = "Implementation of the OSPFv2 routing protocol.", |
4f04a76b | 127 | |
d62a17ae | 128 | .signals = ospf_signals, .n_signals = array_size(ospf_signals), |
4f04a76b | 129 | |
d62a17ae | 130 | .privs = &ospfd_privs, ) |
4f04a76b | 131 | |
718e3744 | 132 | /* OSPFd main routine. */ |
d62a17ae | 133 | int main(int argc, char **argv) |
718e3744 | 134 | { |
d7c0a89a | 135 | unsigned short instance = 0; |
718e3744 | 136 | |
822d8f55 | 137 | #ifdef SUPPORT_OSPF_API |
d62a17ae | 138 | /* OSPF apiserver is disabled by default. */ |
139 | ospf_apiserver_enable = 0; | |
822d8f55 DL |
140 | #endif /* SUPPORT_OSPF_API */ |
141 | ||
d62a17ae | 142 | frr_preinit(&ospfd_di, argc, argv); |
143 | frr_opt_add("n:a", longopts, | |
144 | " -n, --instance Set the instance id\n" | |
145 | " -a, --apiserver Enable OSPF apiserver\n"); | |
718e3744 | 146 | |
d62a17ae | 147 | while (1) { |
148 | int opt; | |
718e3744 | 149 | |
d62a17ae | 150 | opt = frr_getopt(argc, argv, NULL); |
718e3744 | 151 | |
d62a17ae | 152 | if (opt == EOF) |
153 | break; | |
154 | ||
155 | switch (opt) { | |
156 | case 'n': | |
157 | ospfd_di.instance = instance = atoi(optarg); | |
158 | if (instance < 1) | |
159 | exit(0); | |
160 | break; | |
161 | case 0: | |
162 | break; | |
d68614db | 163 | #ifdef SUPPORT_OSPF_API |
d62a17ae | 164 | case 'a': |
165 | ospf_apiserver_enable = 1; | |
166 | break; | |
d68614db | 167 | #endif /* SUPPORT_OSPF_API */ |
d62a17ae | 168 | default: |
169 | frr_help_exit(1); | |
170 | break; | |
171 | } | |
718e3744 | 172 | } |
718e3744 | 173 | |
d62a17ae | 174 | /* Invoked by a priviledged user? -- endo. */ |
175 | if (geteuid() != 0) { | |
176 | errno = EPERM; | |
177 | perror(ospfd_di.progname); | |
178 | exit(1); | |
179 | } | |
180 | ||
181 | /* OSPF master init. */ | |
182 | ospf_master_init(frr_init()); | |
183 | ||
184 | /* Initializations. */ | |
185 | master = om->master; | |
186 | ||
187 | /* Library inits. */ | |
188 | debug_init(); | |
b5a8894d | 189 | ospf_vrf_init(); |
d62a17ae | 190 | |
191 | access_list_init(); | |
192 | prefix_list_init(); | |
193 | ||
194 | /* OSPFd inits. */ | |
195 | ospf_if_init(); | |
196 | ospf_zebra_init(master, instance); | |
197 | ||
198 | /* OSPF vty inits. */ | |
199 | ospf_vty_init(); | |
200 | ospf_vty_show_init(); | |
201 | ospf_vty_clear_init(); | |
202 | ||
203 | /* OSPF BFD init */ | |
204 | ospf_bfd_init(); | |
205 | ||
206 | ospf_route_map_init(); | |
207 | ospf_opaque_init(); | |
208 | ||
209 | /* Need to initialize the default ospf structure, so the interface mode | |
210 | commands can be duly processed if they are received before 'router | |
211 | ospf', | |
212 | when quagga(ospfd) is restarted */ | |
213 | if (!ospf_get_instance(instance)) { | |
214 | zlog_err("OSPF instance init failed: %s", strerror(errno)); | |
215 | exit(1); | |
216 | } | |
217 | ||
218 | frr_config_fork(); | |
219 | frr_run(master); | |
220 | ||
221 | /* Not reached. */ | |
222 | return (0); | |
223 | } |