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 struct pim_instance
*pimg
= NULL
;
80 int32_t qpim_register_suppress_time
= PIM_REGISTER_SUPPRESSION_TIME_DEFAULT
;
81 int32_t qpim_register_probe_time
= PIM_REGISTER_PROBE_TIME_DEFAULT
;
83 static struct pim_instance
*pim_instance_init (vrf_id_t vrf_id
, afi_t afi
);
84 static void pim_instance_terminate (void);
87 pim_vrf_new (struct vrf
*vrf
)
89 zlog_debug ("VRF Created: %s(%d)", vrf
->name
, vrf
->vrf_id
);
94 pim_vrf_delete (struct vrf
*vrf
)
96 zlog_debug ("VRF Deletion: %s(%d)", vrf
->name
, vrf
->vrf_id
);
101 pim_vrf_enable (struct vrf
*vrf
)
104 if (!vrf
) // unexpected
107 if (vrf
->vrf_id
== VRF_DEFAULT
)
109 pimg
= pim_instance_init (VRF_DEFAULT
, AFI_IP
);
111 zlog_err ("%s %s: pim class init failure ", __FILE__
,
112 __PRETTY_FUNCTION__
);
118 pim_vrf_disable (struct vrf
*vrf
)
120 if (vrf
->vrf_id
== VRF_DEFAULT
)
123 if (vrf
->vrf_id
== VRF_DEFAULT
)
124 pim_instance_terminate ();
126 /* Note: This is a callback, the VRF will be deleted by the caller. */
133 vrf_add_hook (VRF_NEW_HOOK
, pim_vrf_new
);
134 vrf_add_hook (VRF_ENABLE_HOOK
, pim_vrf_enable
);
135 vrf_add_hook (VRF_DISABLE_HOOK
, pim_vrf_disable
);
136 vrf_add_hook (VRF_DELETE_HOOK
, pim_vrf_delete
);
142 pim_vrf_terminate (void)
144 vrf_add_hook (VRF_NEW_HOOK
, NULL
);
145 vrf_add_hook (VRF_ENABLE_HOOK
, NULL
);
146 vrf_add_hook (VRF_DISABLE_HOOK
, NULL
);
147 vrf_add_hook (VRF_DELETE_HOOK
, NULL
);
152 /* Key generate for pim->rpf_hash */
154 pim_rpf_hash_key (void *arg
)
156 struct pim_nexthop_cache
*r
= (struct pim_nexthop_cache
*) arg
;
158 return jhash_1word (r
->rpf
.rpf_addr
.u
.prefix4
.s_addr
, 0);
161 /* Compare pim->rpf_hash node data */
163 pim_rpf_equal (const void *arg1
, const void *arg2
)
165 const struct pim_nexthop_cache
*r1
=
166 (const struct pim_nexthop_cache
*) arg1
;
167 const struct pim_nexthop_cache
*r2
=
168 (const struct pim_nexthop_cache
*) arg2
;
170 return prefix_same (&r1
->rpf
.rpf_addr
, &r2
->rpf
.rpf_addr
);
173 /* Cleanup pim->rpf_hash each node data */
175 pim_rp_list_hash_clean (void *data
)
177 struct pim_nexthop_cache
*pnc
;
179 pnc
= (struct pim_nexthop_cache
*) data
;
180 if (pnc
->rp_list
->count
)
181 list_delete_all_node (pnc
->rp_list
);
182 if (pnc
->upstream_list
->count
)
183 list_delete_all_node (pnc
->upstream_list
);
187 pim_prefix_list_update (struct prefix_list
*plist
)
189 pim_rp_prefix_list_update (plist
);
190 pim_ssm_prefix_list_update (plist
);
194 pim_instance_terminate (void)
196 /* Traverse and cleanup rpf_hash */
197 if (pimg
&& pimg
->rpf_hash
)
199 hash_clean (pimg
->rpf_hash
, (void *) pim_rp_list_hash_clean
);
200 hash_free (pimg
->rpf_hash
);
202 pim_ssm_terminate (pimg
->ssm_info
);
204 XFREE (MTYPE_PIM_PIM_INSTANCE
, pimg
);
207 static void pim_free()
209 pim_ssmpingd_destroy();
211 pim_oil_terminate ();
213 pim_upstream_terminate ();
215 if (qpim_static_route_list
)
216 list_free(qpim_static_route_list
);
221 pim_route_map_terminate();
223 zclient_lookup_free ();
225 zprivs_terminate(&pimd_privs
);
228 static struct pim_instance
*
229 pim_instance_init (vrf_id_t vrf_id
, afi_t afi
)
231 struct pim_instance
*pim
;
233 pim
= XCALLOC (MTYPE_PIM_PIM_INSTANCE
, sizeof (struct pim_instance
));
237 pim
->vrf_id
= vrf_id
;
240 pim
->rpf_hash
= hash_create_size (256, pim_rpf_hash_key
, pim_rpf_equal
);
243 zlog_debug ("%s: NHT rpf hash init ", __PRETTY_FUNCTION__
);
245 pim
->ssm_info
= pim_ssm_init (vrf_id
);
246 if (!pim
->ssm_info
) {
247 pim_instance_terminate ();
256 qpim_rp_keep_alive_time
= PIM_RP_KEEPALIVE_PERIOD
;
260 if (!inet_aton(PIM_ALL_PIM_ROUTERS
, &qpim_all_pim_routers_addr
)) {
261 zlog_err("%s %s: could not solve %s to group address: errno=%d: %s",
262 __FILE__
, __PRETTY_FUNCTION__
,
263 PIM_ALL_PIM_ROUTERS
, errno
, safe_strerror(errno
));
270 pim_upstream_init ();
272 qpim_static_route_list
= list_new();
273 if (!qpim_static_route_list
) {
274 zlog_err("%s %s: failure: static_route_list=list_new()",
275 __FILE__
, __PRETTY_FUNCTION__
);
278 qpim_static_route_list
->del
= (void (*)(void *)) pim_static_route_free
;
280 pim_mroute_socket_enable();
282 qpim_inaddr_any
.s_addr
= PIM_NET_INADDR_ANY
;
285 RFC 4601: 4.6.3. Assert Metrics
288 infinite_assert_metric() {
289 return {1,infinity,infinity,0}
292 qpim_infinite_assert_metric
.rpt_bit_flag
= 1;
293 qpim_infinite_assert_metric
.metric_preference
= PIM_ASSERT_METRIC_PREFERENCE_MAX
;
294 qpim_infinite_assert_metric
.route_metric
= PIM_ASSERT_ROUTE_METRIC_MAX
;
295 qpim_infinite_assert_metric
.ip_address
= qpim_inaddr_any
;
306 /* reverse prefix_list_init */
307 prefix_list_add_hook (NULL
);
308 prefix_list_delete_hook (NULL
);
309 prefix_list_reset ();
311 pim_vrf_terminate ();