3 Copyright (C) 2008 Everton da Silva Marques
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.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
34 #include "pim_iface.h"
35 #include "pim_zebra.h"
39 #include "pim_upstream.h"
41 #include "pim_ssmpingd.h"
42 #include "pim_static.h"
45 #include "pim_zlookup.h"
48 const char *const PIM_ALL_SYSTEMS
= MCAST_ALL_SYSTEMS
;
49 const char *const PIM_ALL_ROUTERS
= MCAST_ALL_ROUTERS
;
50 const char *const PIM_ALL_PIM_ROUTERS
= MCAST_ALL_PIM_ROUTERS
;
51 const char *const PIM_ALL_IGMP_ROUTERS
= MCAST_ALL_IGMP_ROUTERS
;
53 struct thread_master
*master
= NULL
;
54 uint32_t qpim_debugs
= 0;
55 int qpim_mroute_socket_fd
= -1;
56 int64_t qpim_mroute_socket_creation
= 0; /* timestamp of creation */
57 int qpim_t_periodic
= PIM_DEFAULT_T_PERIODIC
; /* Period between Join/Prune Messages */
58 struct pim_assert_metric qpim_infinite_assert_metric
;
59 long qpim_rpf_cache_refresh_delay_msec
= 50;
60 struct thread
*qpim_rpf_cache_refresher
= NULL
;
61 int64_t qpim_rpf_cache_refresh_requests
= 0;
62 int64_t qpim_rpf_cache_refresh_events
= 0;
63 int64_t qpim_rpf_cache_refresh_last
= 0;
64 struct in_addr qpim_inaddr_any
;
65 struct list
*qpim_ssmpingd_list
= NULL
;
66 struct in_addr qpim_ssmpingd_group_addr
;
67 int64_t qpim_scan_oil_events
= 0;
68 int64_t qpim_scan_oil_last
= 0;
69 int64_t qpim_mroute_add_events
= 0;
70 int64_t qpim_mroute_add_last
= 0;
71 int64_t qpim_mroute_del_events
= 0;
72 int64_t qpim_mroute_del_last
= 0;
73 struct list
*qpim_static_route_list
= NULL
;
74 unsigned int qpim_keep_alive_time
= PIM_KEEPALIVE_PERIOD
;
75 signed int qpim_rp_keep_alive_time
= 0;
76 int64_t qpim_nexthop_lookups
= 0;
77 int qpim_packet_process
= PIM_DEFAULT_PACKET_PROCESS
;
78 uint8_t qpim_ecmp_enable
= 0;
79 uint8_t qpim_ecmp_rebalance_enable
= 0;
80 struct pim_instance
*pimg
= NULL
;
82 int32_t qpim_register_suppress_time
= PIM_REGISTER_SUPPRESSION_TIME_DEFAULT
;
83 int32_t qpim_register_probe_time
= PIM_REGISTER_PROBE_TIME_DEFAULT
;
85 static struct pim_instance
*pim_instance_init (vrf_id_t vrf_id
, afi_t afi
);
86 static void pim_instance_terminate (void);
89 pim_vrf_new (struct vrf
*vrf
)
91 zlog_debug ("VRF Created: %s(%d)", vrf
->name
, vrf
->vrf_id
);
96 pim_vrf_delete (struct vrf
*vrf
)
98 zlog_debug ("VRF Deletion: %s(%d)", vrf
->name
, vrf
->vrf_id
);
103 pim_vrf_enable (struct vrf
*vrf
)
106 if (!vrf
) // unexpected
109 if (vrf
->vrf_id
== VRF_DEFAULT
)
111 pimg
= pim_instance_init (VRF_DEFAULT
, AFI_IP
);
114 zlog_err ("%s %s: pim class init failure ", __FILE__
,
115 __PRETTY_FUNCTION__
);
117 * We will crash and burn otherwise
122 pimg
->send_v6_secondary
= 1;
129 pim_vrf_disable (struct vrf
*vrf
)
131 if (vrf
->vrf_id
== VRF_DEFAULT
)
134 if (vrf
->vrf_id
== VRF_DEFAULT
)
135 pim_instance_terminate ();
137 /* Note: This is a callback, the VRF will be deleted by the caller. */
144 vrf_add_hook (VRF_NEW_HOOK
, pim_vrf_new
);
145 vrf_add_hook (VRF_ENABLE_HOOK
, pim_vrf_enable
);
146 vrf_add_hook (VRF_DISABLE_HOOK
, pim_vrf_disable
);
147 vrf_add_hook (VRF_DELETE_HOOK
, pim_vrf_delete
);
153 pim_vrf_terminate (void)
155 vrf_add_hook (VRF_NEW_HOOK
, NULL
);
156 vrf_add_hook (VRF_ENABLE_HOOK
, NULL
);
157 vrf_add_hook (VRF_DISABLE_HOOK
, NULL
);
158 vrf_add_hook (VRF_DELETE_HOOK
, NULL
);
163 /* Key generate for pim->rpf_hash */
165 pim_rpf_hash_key (void *arg
)
167 struct pim_nexthop_cache
*r
= (struct pim_nexthop_cache
*) arg
;
169 return jhash_1word (r
->rpf
.rpf_addr
.u
.prefix4
.s_addr
, 0);
172 /* Compare pim->rpf_hash node data */
174 pim_rpf_equal (const void *arg1
, const void *arg2
)
176 const struct pim_nexthop_cache
*r1
=
177 (const struct pim_nexthop_cache
*) arg1
;
178 const struct pim_nexthop_cache
*r2
=
179 (const struct pim_nexthop_cache
*) arg2
;
181 return prefix_same (&r1
->rpf
.rpf_addr
, &r2
->rpf
.rpf_addr
);
184 /* Cleanup pim->rpf_hash each node data */
186 pim_rp_list_hash_clean (void *data
)
188 struct pim_nexthop_cache
*pnc
;
190 pnc
= (struct pim_nexthop_cache
*) data
;
191 if (pnc
->rp_list
->count
)
192 list_delete_all_node (pnc
->rp_list
);
193 if (pnc
->upstream_list
->count
)
194 list_delete_all_node (pnc
->upstream_list
);
198 pim_prefix_list_update (struct prefix_list
*plist
)
200 pim_rp_prefix_list_update (plist
);
201 pim_ssm_prefix_list_update (plist
);
202 pim_upstream_spt_prefix_list_update (plist
);
206 pim_instance_terminate (void)
208 /* Traverse and cleanup rpf_hash */
211 hash_clean (pimg
->rpf_hash
, (void *) pim_rp_list_hash_clean
);
212 hash_free (pimg
->rpf_hash
);
213 pimg
->rpf_hash
= NULL
;
218 pim_ssm_terminate (pimg
->ssm_info
);
219 pimg
->ssm_info
= NULL
;
222 XFREE (MTYPE_PIM_PIM_INSTANCE
, pimg
);
225 static void pim_free()
227 pim_ssmpingd_destroy();
229 pim_oil_terminate ();
231 pim_upstream_terminate ();
233 if (qpim_static_route_list
)
234 list_free(qpim_static_route_list
);
239 pim_route_map_terminate();
241 zclient_lookup_free ();
243 zprivs_terminate(&pimd_privs
);
246 static struct pim_instance
*
247 pim_instance_init (vrf_id_t vrf_id
, afi_t afi
)
249 struct pim_instance
*pim
;
251 pim
= XCALLOC (MTYPE_PIM_PIM_INSTANCE
, sizeof (struct pim_instance
));
255 pim
->vrf_id
= vrf_id
;
258 pim
->spt
.switchover
= PIM_SPT_IMMEDIATE
;
259 pim
->spt
.plist
= NULL
;
261 pim
->rpf_hash
= hash_create_size (256, pim_rpf_hash_key
, pim_rpf_equal
);
264 zlog_debug ("%s: NHT rpf hash init ", __PRETTY_FUNCTION__
);
266 pim
->ssm_info
= pim_ssm_init (vrf_id
);
267 if (!pim
->ssm_info
) {
268 pim_instance_terminate ();
277 qpim_rp_keep_alive_time
= PIM_RP_KEEPALIVE_PERIOD
;
281 if (!inet_aton(PIM_ALL_PIM_ROUTERS
, &qpim_all_pim_routers_addr
)) {
282 zlog_err("%s %s: could not solve %s to group address: errno=%d: %s",
283 __FILE__
, __PRETTY_FUNCTION__
,
284 PIM_ALL_PIM_ROUTERS
, errno
, safe_strerror(errno
));
291 pim_upstream_init ();
293 qpim_static_route_list
= list_new();
294 if (!qpim_static_route_list
) {
295 zlog_err("%s %s: failure: static_route_list=list_new()",
296 __FILE__
, __PRETTY_FUNCTION__
);
299 qpim_static_route_list
->del
= (void (*)(void *)) pim_static_route_free
;
301 pim_mroute_socket_enable();
303 qpim_inaddr_any
.s_addr
= PIM_NET_INADDR_ANY
;
306 RFC 4601: 4.6.3. Assert Metrics
309 infinite_assert_metric() {
310 return {1,infinity,infinity,0}
313 qpim_infinite_assert_metric
.rpt_bit_flag
= 1;
314 qpim_infinite_assert_metric
.metric_preference
= PIM_ASSERT_METRIC_PREFERENCE_MAX
;
315 qpim_infinite_assert_metric
.route_metric
= PIM_ASSERT_ROUTE_METRIC_MAX
;
316 qpim_infinite_assert_metric
.ip_address
= qpim_inaddr_any
;
327 /* reverse prefix_list_init */
328 prefix_list_add_hook (NULL
);
329 prefix_list_delete_hook (NULL
);
330 prefix_list_reset ();
332 pim_vrf_terminate ();