Line data Source code
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 : #include "pim_nb.h"
40 : #include "pim6_cmd.h"
41 : #include "pim6_mld.h"
42 :
43 : zebra_capabilities_t _caps_p[] = {
44 : ZCAP_SYS_ADMIN,
45 : ZCAP_NET_ADMIN,
46 : ZCAP_NET_RAW,
47 : ZCAP_BIND,
48 : };
49 :
50 : /* pimd privileges to run with */
51 : struct zebra_privs_t pimd_privs = {
52 : #if defined(FRR_USER) && defined(FRR_GROUP)
53 : .user = FRR_USER,
54 : .group = FRR_GROUP,
55 : #endif
56 : #ifdef VTY_GROUP
57 : .vty_group = VTY_GROUP,
58 : #endif
59 : .caps_p = _caps_p,
60 : .cap_num_p = array_size(_caps_p),
61 : .cap_num_i = 0,
62 : };
63 :
64 : static void pim6_terminate(void);
65 :
66 0 : static void pim6_sighup(void)
67 : {
68 0 : zlog_info("SIGHUP received, ignoring");
69 0 : }
70 :
71 0 : static void pim6_sigint(void)
72 : {
73 0 : zlog_notice("Terminating on signal SIGINT");
74 0 : pim6_terminate();
75 0 : exit(1);
76 : }
77 :
78 2 : static void pim6_sigterm(void)
79 : {
80 2 : zlog_notice("Terminating on signal SIGTERM");
81 2 : pim6_terminate();
82 2 : exit(1);
83 : }
84 :
85 0 : static void pim6_sigusr1(void)
86 : {
87 0 : zlog_rotate();
88 0 : }
89 :
90 : struct frr_signal_t pim6d_signals[] = {
91 : {
92 : .signal = SIGHUP,
93 : .handler = &pim6_sighup,
94 : },
95 : {
96 : .signal = SIGUSR1,
97 : .handler = &pim6_sigusr1,
98 : },
99 : {
100 : .signal = SIGINT,
101 : .handler = &pim6_sigint,
102 : },
103 : {
104 : .signal = SIGTERM,
105 : .handler = &pim6_sigterm,
106 : },
107 : };
108 :
109 : static const struct frr_yang_module_info *const pim6d_yang_modules[] = {
110 : &frr_filter_info,
111 : &frr_interface_info,
112 : &frr_route_map_info,
113 : &frr_vrf_info,
114 : &frr_routing_info,
115 : &frr_pim_info,
116 : &frr_pim_rp_info,
117 : &frr_gmp_info,
118 : };
119 :
120 : /* clang-format off */
121 2 : FRR_DAEMON_INFO(pim6d, PIM6,
122 : .vty_port = PIM6D_VTY_PORT,
123 : .proghelp = "Protocol Independent Multicast (RFC7761) for IPv6",
124 :
125 : .signals = pim6d_signals,
126 : .n_signals = array_size(pim6d_signals),
127 :
128 : .privs = &pimd_privs,
129 :
130 : .yang_modules = pim6d_yang_modules,
131 : .n_yang_modules = array_size(pim6d_yang_modules),
132 : );
133 : /* clang-format on */
134 :
135 2 : int main(int argc, char **argv, char **envp)
136 : {
137 2 : static struct option longopts[] = {
138 : {},
139 : };
140 :
141 2 : frr_preinit(&pim6d_di, argc, argv);
142 2 : frr_opt_add("", longopts, "");
143 :
144 : /* this while just reads the options */
145 2 : while (1) {
146 2 : int opt;
147 :
148 2 : opt = frr_getopt(argc, argv, NULL);
149 :
150 2 : if (opt == EOF)
151 : break;
152 :
153 0 : switch (opt) {
154 : case 0:
155 : break;
156 0 : default:
157 0 : frr_help_exit(1);
158 : }
159 : }
160 :
161 2 : pim_router_init();
162 :
163 2 : access_list_init();
164 2 : prefix_list_init();
165 :
166 : /*
167 : * Initializations
168 : */
169 2 : pim_error_init();
170 2 : pim_vrf_init();
171 : #if 0
172 : prefix_list_add_hook(pim_prefix_list_update);
173 : prefix_list_delete_hook(pim_prefix_list_update);
174 :
175 : pim_route_map_init();
176 : #endif
177 2 : pim_init();
178 : /*
179 : * Initialize zclient "update" and "lookup" sockets
180 : */
181 2 : pim_iface_init();
182 :
183 2 : gm_cli_init();
184 :
185 2 : pim_zebra_init();
186 : #if 0
187 : pim_bfd_init();
188 : pim_mlag_init();
189 : #endif
190 :
191 2 : hook_register(routing_conf_event,
192 : routing_control_plane_protocols_name_validate);
193 :
194 2 : routing_control_plane_protocols_register_vrf_dependency();
195 :
196 2 : frr_config_fork();
197 2 : frr_run(router->master);
198 :
199 : /* never reached */
200 0 : return 0;
201 : }
202 :
203 2 : static void pim6_terminate(void)
204 : {
205 2 : pim_vrf_terminate();
206 2 : pim_router_terminate();
207 :
208 2 : prefix_list_reset();
209 2 : access_list_reset();
210 :
211 2 : frr_fini();
212 2 : }
|