1 /*
2  * PIM for Quagga
3  * Copyright (C) 2008  Everton da Silva Marques
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; see the file COPYING; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #include <zebra.h>
21 
22 #include "log.h"
23 #include "privs.h"
24 #include "version.h"
25 #include <getopt.h>
26 #include "command.h"
27 #include "thread.h"
28 #include <signal.h>
29 
30 #include "memory.h"
31 #include "vrf.h"
32 #include "filter.h"
33 #include "vty.h"
34 #include "sigevent.h"
35 #include "version.h"
36 #include "prefix.h"
37 #include "plist.h"
38 #include "vrf.h"
39 #include "libfrr.h"
40 #include "routemap.h"
41 
42 #include "pimd.h"
43 #include "pim_instance.h"
44 #include "pim_version.h"
45 #include "pim_signals.h"
46 #include "pim_zebra.h"
47 #include "pim_msdp.h"
48 #include "pim_iface.h"
49 #include "pim_bfd.h"
50 #include "pim_mlag.h"
51 #include "pim_errors.h"
52 
53 extern struct host host;
54 
55 struct option longopts[] = {{0}};
56 
57 /* pimd privileges */
58 zebra_capabilities_t _caps_p[] = {
59 	ZCAP_NET_ADMIN, ZCAP_SYS_ADMIN, ZCAP_NET_RAW, ZCAP_BIND,
60 };
61 
62 /* pimd privileges to run with */
63 struct zebra_privs_t pimd_privs = {
64 #if defined(FRR_USER) && defined(FRR_GROUP)
65 	.user = FRR_USER,
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 = array_size(_caps_p),
73 	.cap_num_i = 0};
74 
75 static const struct frr_yang_module_info *const pimd_yang_modules[] = {
76 	&frr_filter_info,
77 	&frr_interface_info,
78 	&frr_route_map_info,
79 	&frr_vrf_info,
80 };
81 
82 FRR_DAEMON_INFO(pimd, PIM, .vty_port = PIMD_VTY_PORT,
83 
84 		.proghelp = "Implementation of the PIM routing protocol.",
85 
86 		.signals = pimd_signals,
87 		.n_signals = 4 /* XXX array_size(pimd_signals) XXX*/,
88 
89 		.privs = &pimd_privs, .yang_modules = pimd_yang_modules,
90 		.n_yang_modules = array_size(pimd_yang_modules), )
91 
92 
main(int argc,char ** argv,char ** envp)93 int main(int argc, char **argv, char **envp)
94 {
95 	frr_preinit(&pimd_di, argc, argv);
96 	frr_opt_add("", longopts, "");
97 
98 	/* this while just reads the options */
99 	while (1) {
100 		int opt;
101 
102 		opt = frr_getopt(argc, argv, NULL);
103 
104 		if (opt == EOF)
105 			break;
106 
107 		switch (opt) {
108 		case 0:
109 			break;
110 		default:
111 			frr_help_exit(1);
112 			break;
113 		}
114 	}
115 
116 	pim_router_init();
117 
118 	/*
119 	 * Initializations
120 	 */
121 	pim_error_init();
122 	pim_vrf_init();
123 	access_list_init();
124 	prefix_list_init();
125 	prefix_list_add_hook(pim_prefix_list_update);
126 	prefix_list_delete_hook(pim_prefix_list_update);
127 
128 	pim_route_map_init();
129 	pim_init();
130 
131 	/*
132 	 * Initialize zclient "update" and "lookup" sockets
133 	 */
134 	if_zapi_callbacks(pim_ifp_create, pim_ifp_up,
135 			  pim_ifp_down, pim_ifp_destroy);
136 	pim_zebra_init();
137 	pim_bfd_init();
138 	pim_mlag_init();
139 
140 	frr_config_fork();
141 
142 #ifdef PIM_DEBUG_BYDEFAULT
143 	zlog_notice("PIM_DEBUG_BYDEFAULT: Enabling all debug commands");
144 	PIM_DO_DEBUG_PIM_EVENTS;
145 	PIM_DO_DEBUG_PIM_PACKETS;
146 	PIM_DO_DEBUG_PIM_TRACE;
147 	PIM_DO_DEBUG_IGMP_EVENTS;
148 	PIM_DO_DEBUG_IGMP_PACKETS;
149 	PIM_DO_DEBUG_IGMP_TRACE;
150 	PIM_DO_DEBUG_ZEBRA;
151 #endif
152 
153 #ifdef PIM_CHECK_RECV_IFINDEX_SANITY
154 	zlog_notice(
155 		"PIM_CHECK_RECV_IFINDEX_SANITY: will match sock/recv ifindex");
156 #ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH
157 	zlog_notice(
158 		"PIM_REPORT_RECV_IFINDEX_MISMATCH: will report sock/recv ifindex mismatch");
159 #endif
160 #endif
161 
162 #ifdef PIM_UNEXPECTED_KERNEL_UPCALL
163 	zlog_notice(
164 		"PIM_UNEXPECTED_KERNEL_UPCALL: report unexpected kernel upcall");
165 #endif
166 
167 	frr_run(router->master);
168 
169 	/* never reached */
170 	return 0;
171 }
172