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