]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim6_main.c
pim6d: get into a kinda-working state wrt. zebra
[mirror_frr.git] / pimd / pim6_main.c
1 /*
2 * PIMv6 main()
3 * Copyright (C) 2021 David Lamparter for NetDEF, Inc.
4 * Copyright (C) 2008 Everton da Silva Marques (pim_main.c)
5 *
6 * This program 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 Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "lib/vrf.h"
24 #include "lib/filter.h"
25 #include "lib/plist.h"
26 #include "lib/routemap.h"
27 #include "lib/routing_nb.h"
28
29 #include "lib/privs.h"
30 #include "lib/sigevent.h"
31 #include "lib/libfrr.h"
32 #include "lib/version.h"
33
34 #include "pimd.h"
35 #include "pim_instance.h"
36 #include "pim_errors.h"
37 #include "pim_iface.h"
38 #include "pim_zebra.h"
39
40 zebra_capabilities_t _caps_p[] = {
41 ZCAP_SYS_ADMIN,
42 ZCAP_NET_ADMIN,
43 ZCAP_NET_RAW,
44 ZCAP_BIND,
45 };
46
47 /* pimd privileges to run with */
48 struct zebra_privs_t pimd_privs = {
49 #if defined(FRR_USER) && defined(FRR_GROUP)
50 .user = FRR_USER,
51 .group = FRR_GROUP,
52 #endif
53 #ifdef VTY_GROUP
54 .vty_group = VTY_GROUP,
55 #endif
56 .caps_p = _caps_p,
57 .cap_num_p = array_size(_caps_p),
58 .cap_num_i = 0,
59 };
60
61 static void pim6_terminate(void);
62
63 static void pim6_sighup(void)
64 {
65 zlog_info("SIGHUP received, ignoring");
66 }
67
68 static void pim6_sigint(void)
69 {
70 zlog_notice("Terminating on signal SIGINT");
71 pim6_terminate();
72 exit(1);
73 }
74
75 static void pim6_sigterm(void)
76 {
77 zlog_notice("Terminating on signal SIGTERM");
78 pim6_terminate();
79 exit(1);
80 }
81
82 static void pim6_sigusr1(void)
83 {
84 zlog_rotate();
85 }
86
87 struct frr_signal_t pim6d_signals[] = {
88 {
89 .signal = SIGHUP,
90 .handler = &pim6_sighup,
91 },
92 {
93 .signal = SIGUSR1,
94 .handler = &pim6_sigusr1,
95 },
96 {
97 .signal = SIGINT,
98 .handler = &pim6_sigint,
99 },
100 {
101 .signal = SIGTERM,
102 .handler = &pim6_sigterm,
103 },
104 };
105
106 static const struct frr_yang_module_info *const pim6d_yang_modules[] = {
107 &frr_filter_info,
108 &frr_interface_info,
109 &frr_route_map_info,
110 &frr_vrf_info,
111 &frr_routing_info,
112 };
113
114 /* clang-format off */
115 FRR_DAEMON_INFO(pim6d, PIM6,
116 .vty_port = 0,
117 .flags = FRR_NO_SPLIT_CONFIG,
118
119 .proghelp = "Protocol Independent Multicast (RFC7761) for IPv6",
120
121 .signals = pim6d_signals,
122 .n_signals = array_size(pim6d_signals),
123
124 .privs = &pimd_privs,
125
126 .yang_modules = pim6d_yang_modules,
127 .n_yang_modules = array_size(pim6d_yang_modules),
128 );
129 /* clang-format on */
130
131
132 int main(int argc, char **argv, char **envp)
133 {
134 static struct option longopts[] = {
135 {},
136 };
137
138 frr_preinit(&pim6d_di, argc, argv);
139 frr_opt_add("", longopts, "");
140
141 /* this while just reads the options */
142 while (1) {
143 int opt;
144
145 opt = frr_getopt(argc, argv, NULL);
146
147 if (opt == EOF)
148 break;
149
150 switch (opt) {
151 case 0:
152 break;
153 default:
154 frr_help_exit(1);
155 }
156 }
157
158 pim_router_init();
159 /* TODO PIM6: temporary enable all debugs, remove later in PIMv6 work */
160 router->debugs = ~0U;
161
162 access_list_init();
163 prefix_list_init();
164
165 /*
166 * Initializations
167 */
168 pim_error_init();
169 pim_vrf_init();
170 #if 0
171 prefix_list_add_hook(pim_prefix_list_update);
172 prefix_list_delete_hook(pim_prefix_list_update);
173
174 pim_route_map_init();
175 pim_init();
176 #endif
177
178 /*
179 * Initialize zclient "update" and "lookup" sockets
180 */
181 pim_iface_init();
182
183 /* TODO PIM6: next line is temporary since pim_cmd_init is disabled */
184 if_cmd_init(NULL);
185
186 pim_zebra_init();
187 #if 0
188 pim_bfd_init();
189 pim_mlag_init();
190
191 hook_register(routing_conf_event,
192 routing_control_plane_protocols_name_validate);
193
194 routing_control_plane_protocols_register_vrf_dependency();
195 #endif
196
197 frr_config_fork();
198 frr_run(router->master);
199
200 /* never reached */
201 return 0;
202 }
203
204 static void pim6_terminate(void)
205 {
206 pim_vrf_terminate();
207 pim_router_terminate();
208
209 prefix_list_reset();
210 access_list_reset();
211
212 frr_fini();
213 }