]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_main.c
debianpkg: Add debian9 backport to distribution tar
[mirror_frr.git] / ospf6d / ospf6_main.c
1 /*
2 * Copyright (C) 1999 Yasuhiro Ohara
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22 #include <zebra.h>
23 #include <lib/version.h>
24 #include <stdlib.h>
25
26 #include "getopt.h"
27 #include "thread.h"
28 #include "log.h"
29 #include "command.h"
30 #include "vty.h"
31 #include "memory.h"
32 #include "memory_vty.h"
33 #include "if.h"
34 #include "filter.h"
35 #include "prefix.h"
36 #include "plist.h"
37 #include "privs.h"
38 #include "sigevent.h"
39 #include "zclient.h"
40 #include "vrf.h"
41 #include "bfd.h"
42 #include "libfrr.h"
43
44 #include "ospf6d.h"
45 #include "ospf6_top.h"
46 #include "ospf6_message.h"
47 #include "ospf6_asbr.h"
48 #include "ospf6_lsa.h"
49 #include "ospf6_interface.h"
50 #include "ospf6_zebra.h"
51
52 /* Default configuration file name for ospf6d. */
53 #define OSPF6_DEFAULT_CONFIG "ospf6d.conf"
54
55 /* Default port values. */
56 #define OSPF6_VTY_PORT 2606
57
58 /* ospf6d privileges */
59 zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND};
60
61 struct zebra_privs_t ospf6d_privs = {
62 #if defined(FRR_USER)
63 .user = FRR_USER,
64 #endif
65 #if defined FRR_GROUP
66 .group = FRR_GROUP,
67 #endif
68 #ifdef VTY_GROUP
69 .vty_group = VTY_GROUP,
70 #endif
71 .caps_p = _caps_p,
72 .cap_num_p = 2,
73 .cap_num_i = 0};
74
75 /* ospf6d options, we use GNU getopt library. */
76 struct option longopts[] = {{0}};
77
78 /* Master of threads. */
79 struct thread_master *master;
80
81 static void __attribute__((noreturn)) ospf6_exit(int status)
82 {
83 struct listnode *node;
84 struct interface *ifp;
85
86 if (ospf6)
87 ospf6_delete(ospf6);
88
89 bfd_gbl_exit();
90
91 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
92 if (ifp->info != NULL)
93 ospf6_interface_delete(ifp->info);
94
95 ospf6_message_terminate();
96 ospf6_asbr_terminate();
97 ospf6_lsa_terminate();
98
99 vrf_terminate();
100 vty_terminate();
101 cmd_terminate();
102
103 if (zclient)
104 zclient_free(zclient);
105
106 if (master)
107 thread_master_free(master);
108
109 closezlog();
110
111 exit(status);
112 }
113
114 /* SIGHUP handler. */
115 static void sighup(void)
116 {
117 zlog_info("SIGHUP received");
118 }
119
120 /* SIGINT handler. */
121 static void sigint(void)
122 {
123 zlog_notice("Terminating on signal SIGINT");
124 ospf6_exit(0);
125 }
126
127 /* SIGTERM handler. */
128 static void sigterm(void)
129 {
130 zlog_notice("Terminating on signal SIGTERM");
131 ospf6_clean();
132 ospf6_exit(0);
133 }
134
135 /* SIGUSR1 handler. */
136 static void sigusr1(void)
137 {
138 zlog_info("SIGUSR1 received");
139 zlog_rotate();
140 }
141
142 struct quagga_signal_t ospf6_signals[] = {
143 {
144 .signal = SIGHUP,
145 .handler = &sighup,
146 },
147 {
148 .signal = SIGINT,
149 .handler = &sigint,
150 },
151 {
152 .signal = SIGTERM,
153 .handler = &sigterm,
154 },
155 {
156 .signal = SIGUSR1,
157 .handler = &sigusr1,
158 },
159 };
160
161 FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT,
162
163 .proghelp = "Implementation of the OSPFv3 routing protocol.",
164
165 .signals = ospf6_signals,
166 .n_signals = array_size(ospf6_signals),
167
168 .privs = &ospf6d_privs, )
169
170 /* Main routine of ospf6d. Treatment of argument and starting ospf finite
171 state machine is handled here. */
172 int main(int argc, char *argv[], char *envp[])
173 {
174 int opt;
175
176 frr_preinit(&ospf6d_di, argc, argv);
177 frr_opt_add("", longopts, "");
178
179 /* Command line argument treatment. */
180 while (1) {
181 opt = frr_getopt(argc, argv, NULL);
182
183 if (opt == EOF)
184 break;
185
186 switch (opt) {
187 case 0:
188 break;
189 default:
190 frr_help_exit(1);
191 break;
192 }
193 }
194
195 if (geteuid() != 0) {
196 errno = EPERM;
197 perror(ospf6d_di.progname);
198 exit(1);
199 }
200
201 /* thread master */
202 master = frr_init();
203
204 vrf_init();
205 access_list_init();
206 prefix_list_init();
207
208 /* initialize ospf6 */
209 ospf6_init();
210
211 frr_config_fork();
212 frr_run(master);
213
214 /* Not reached. */
215 ospf6_exit(0);
216 }