]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_main.c
Merge remote-tracking branch 'origin/master' into EIGRP
[mirror_frr.git] / ospfd / ospf_main.c
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 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23 #include <zebra.h>
24
25 #include <lib/version.h>
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"
39 #include "memory_vty.h"
40 #include "privs.h"
41 #include "sigevent.h"
42 #include "zclient.h"
43 #include "vrf.h"
44 #include "libfrr.h"
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"
53 #include "ospfd/ospf_zebra.h"
54 #include "ospfd/ospf_vty.h"
55 #include "ospfd/ospf_bfd.h"
56
57 /* ospfd privileges */
58 zebra_capabilities_t _caps_p [] =
59 {
60 ZCAP_NET_RAW,
61 ZCAP_BIND,
62 ZCAP_NET_ADMIN,
63 };
64
65 struct zebra_privs_t ospfd_privs =
66 {
67 #if defined(FRR_USER) && defined(FRR_GROUP)
68 .user = FRR_USER,
69 .group = FRR_GROUP,
70 #endif
71 #if defined(VTY_GROUP)
72 .vty_group = VTY_GROUP,
73 #endif
74 .caps_p = _caps_p,
75 .cap_num_p = array_size(_caps_p),
76 .cap_num_i = 0
77 };
78
79 /* OSPFd options. */
80 struct option longopts[] =
81 {
82 { "instance", required_argument, NULL, 'n'},
83 { "apiserver", no_argument, NULL, 'a'},
84 { 0 }
85 };
86
87 /* OSPFd program name */
88
89 /* Master of threads. */
90 struct thread_master *master;
91
92 #ifdef SUPPORT_OSPF_API
93 extern int ospf_apiserver_enable;
94 #endif /* SUPPORT_OSPF_API */
95
96 /* SIGHUP handler. */
97 static void
98 sighup (void)
99 {
100 zlog_info("SIGHUP received");
101 }
102
103 /* SIGINT / SIGTERM handler. */
104 static void
105 sigint (void)
106 {
107 zlog_notice ("Terminating on signal");
108 ospf_terminate ();
109 }
110
111 /* SIGUSR1 handler. */
112 static void
113 sigusr1 (void)
114 {
115 zlog_rotate();
116 }
117
118 struct quagga_signal_t ospf_signals[] =
119 {
120 {
121 .signal = SIGHUP,
122 .handler = &sighup,
123 },
124 {
125 .signal = SIGUSR1,
126 .handler = &sigusr1,
127 },
128 {
129 .signal = SIGINT,
130 .handler = &sigint,
131 },
132 {
133 .signal = SIGTERM,
134 .handler = &sigint,
135 },
136 };
137
138 FRR_DAEMON_INFO(ospfd, OSPF,
139 .vty_port = OSPF_VTY_PORT,
140
141 .proghelp = "Implementation of the OSPFv2 routing protocol.",
142
143 .signals = ospf_signals,
144 .n_signals = array_size(ospf_signals),
145
146 .privs = &ospfd_privs,
147 )
148
149 /* OSPFd main routine. */
150 int
151 main (int argc, char **argv)
152 {
153 u_short instance = 0;
154
155 #ifdef SUPPORT_OSPF_API
156 /* OSPF apiserver is disabled by default. */
157 ospf_apiserver_enable = 0;
158 #endif /* SUPPORT_OSPF_API */
159
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");
164
165 while (1)
166 {
167 int opt;
168
169 opt = frr_getopt (argc, argv, NULL);
170
171 if (opt == EOF)
172 break;
173
174 switch (opt)
175 {
176 case 'n':
177 ospfd_di.instance = instance = atoi(optarg);
178 if (instance < 1)
179 exit(0);
180 break;
181 case 0:
182 break;
183 #ifdef SUPPORT_OSPF_API
184 case 'a':
185 ospf_apiserver_enable = 1;
186 break;
187 #endif /* SUPPORT_OSPF_API */
188 default:
189 frr_help_exit (1);
190 break;
191 }
192 }
193
194 /* Invoked by a priviledged user? -- endo. */
195 if (geteuid () != 0)
196 {
197 errno = EPERM;
198 perror (ospfd_di.progname);
199 exit (1);
200 }
201
202 /* OSPF master init. */
203 ospf_master_init (frr_init ());
204
205 /* Initializations. */
206 master = om->master;
207
208 /* Library inits. */
209 debug_init ();
210 vrf_init ();
211
212 access_list_init ();
213 prefix_list_init ();
214
215 /* OSPFd inits. */
216 ospf_if_init ();
217 ospf_zebra_init(master, instance);
218
219 /* OSPF vty inits. */
220 ospf_vty_init ();
221 ospf_vty_show_init ();
222 ospf_vty_clear_init ();
223
224 /* OSPF BFD init */
225 ospf_bfd_init();
226
227 ospf_route_map_init ();
228 ospf_opaque_init ();
229
230 /* Need to initialize the default ospf structure, so the interface mode
231 commands can be duly processed if they are received before 'router ospf',
232 when quagga(ospfd) is restarted */
233 if (!ospf_get_instance(instance))
234 {
235 zlog_err("OSPF instance init failed: %s", strerror(errno));
236 exit (1);
237 }
238
239 frr_config_fork();
240 frr_run (master);
241
242 /* Not reached. */
243 return (0);
244 }
245