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 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
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 */
58 PIM_DEFAULT_T_PERIODIC
; /* Period between Join/Prune Messages */
59 struct pim_assert_metric qpim_infinite_assert_metric
;
60 long qpim_rpf_cache_refresh_delay_msec
= 50;
61 struct thread
*qpim_rpf_cache_refresher
= NULL
;
62 int64_t qpim_rpf_cache_refresh_requests
= 0;
63 int64_t qpim_rpf_cache_refresh_events
= 0;
64 int64_t qpim_rpf_cache_refresh_last
= 0;
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);
88 static int pim_vrf_new(struct vrf
*vrf
)
90 zlog_debug("VRF Created: %s(%d)", vrf
->name
, vrf
->vrf_id
);
94 static int pim_vrf_delete(struct vrf
*vrf
)
96 zlog_debug("VRF Deletion: %s(%d)", vrf
->name
, vrf
->vrf_id
);
100 static int pim_vrf_enable(struct vrf
*vrf
)
103 if (!vrf
) // unexpected
106 if (vrf
->vrf_id
== VRF_DEFAULT
) {
107 pimg
= pim_instance_init(VRF_DEFAULT
, AFI_IP
);
109 zlog_err("%s %s: pim class init failure ", __FILE__
,
110 __PRETTY_FUNCTION__
);
112 * We will crash and burn otherwise
117 pimg
->send_v6_secondary
= 1;
122 static int pim_vrf_disable(struct vrf
*vrf
)
124 if (vrf
->vrf_id
== VRF_DEFAULT
)
127 if (vrf
->vrf_id
== VRF_DEFAULT
)
128 pim_instance_terminate();
130 /* Note: This is a callback, the VRF will be deleted by the caller. */
134 void pim_vrf_init(void)
136 vrf_init(pim_vrf_new
, pim_vrf_enable
, pim_vrf_disable
, pim_vrf_delete
);
139 static void pim_vrf_terminate(void)
144 /* Key generate for pim->rpf_hash */
145 static unsigned int pim_rpf_hash_key(void *arg
)
147 struct pim_nexthop_cache
*r
= (struct pim_nexthop_cache
*)arg
;
149 return jhash_1word(r
->rpf
.rpf_addr
.u
.prefix4
.s_addr
, 0);
152 /* Compare pim->rpf_hash node data */
153 static int pim_rpf_equal(const void *arg1
, const void *arg2
)
155 const struct pim_nexthop_cache
*r1
=
156 (const struct pim_nexthop_cache
*)arg1
;
157 const struct pim_nexthop_cache
*r2
=
158 (const struct pim_nexthop_cache
*)arg2
;
160 return prefix_same(&r1
->rpf
.rpf_addr
, &r2
->rpf
.rpf_addr
);
163 /* Cleanup pim->rpf_hash each node data */
164 static void pim_rp_list_hash_clean(void *data
)
166 struct pim_nexthop_cache
*pnc
;
168 pnc
= (struct pim_nexthop_cache
*)data
;
169 if (pnc
->rp_list
->count
)
170 list_delete_all_node(pnc
->rp_list
);
171 if (pnc
->upstream_list
->count
)
172 list_delete_all_node(pnc
->upstream_list
);
175 void pim_prefix_list_update(struct prefix_list
*plist
)
177 pim_rp_prefix_list_update(plist
);
178 pim_ssm_prefix_list_update(plist
);
179 pim_upstream_spt_prefix_list_update(plist
);
182 static void pim_instance_terminate(void)
184 /* Traverse and cleanup rpf_hash */
185 if (pimg
->rpf_hash
) {
186 hash_clean(pimg
->rpf_hash
, (void *)pim_rp_list_hash_clean
);
187 hash_free(pimg
->rpf_hash
);
188 pimg
->rpf_hash
= NULL
;
191 if (pimg
->ssm_info
) {
192 pim_ssm_terminate(pimg
->ssm_info
);
193 pimg
->ssm_info
= NULL
;
196 XFREE(MTYPE_PIM_PIM_INSTANCE
, pimg
);
199 static void pim_free()
201 pim_ssmpingd_destroy();
205 pim_upstream_terminate();
207 if (qpim_static_route_list
)
208 list_free(qpim_static_route_list
);
213 pim_route_map_terminate();
215 zclient_lookup_free();
217 zprivs_terminate(&pimd_privs
);
220 static struct pim_instance
*pim_instance_init(vrf_id_t vrf_id
, afi_t afi
)
222 struct pim_instance
*pim
;
224 pim
= XCALLOC(MTYPE_PIM_PIM_INSTANCE
, sizeof(struct pim_instance
));
228 pim
->vrf_id
= vrf_id
;
231 pim
->spt
.switchover
= PIM_SPT_IMMEDIATE
;
232 pim
->spt
.plist
= NULL
;
235 hash_create_size(256, pim_rpf_hash_key
, pim_rpf_equal
, NULL
);
238 zlog_debug("%s: NHT rpf hash init ", __PRETTY_FUNCTION__
);
240 pim
->ssm_info
= pim_ssm_init(vrf_id
);
241 if (!pim
->ssm_info
) {
242 pim_instance_terminate();
251 qpim_rp_keep_alive_time
= PIM_RP_KEEPALIVE_PERIOD
;
255 if (!inet_aton(PIM_ALL_PIM_ROUTERS
, &qpim_all_pim_routers_addr
)) {
257 "%s %s: could not solve %s to group address: errno=%d: %s",
258 __FILE__
, __PRETTY_FUNCTION__
, PIM_ALL_PIM_ROUTERS
,
259 errno
, safe_strerror(errno
));
268 qpim_static_route_list
= list_new();
269 if (!qpim_static_route_list
) {
270 zlog_err("%s %s: failure: static_route_list=list_new()",
271 __FILE__
, __PRETTY_FUNCTION__
);
274 qpim_static_route_list
->del
= (void (*)(void *))pim_static_route_free
;
276 pim_mroute_socket_enable();
280 RFC 4601: 4.6.3. Assert Metrics
283 infinite_assert_metric() {
284 return {1,infinity,infinity,0}
287 qpim_infinite_assert_metric
.rpt_bit_flag
= 1;
288 qpim_infinite_assert_metric
.metric_preference
=
289 PIM_ASSERT_METRIC_PREFERENCE_MAX
;
290 qpim_infinite_assert_metric
.route_metric
= PIM_ASSERT_ROUTE_METRIC_MAX
;
291 qpim_infinite_assert_metric
.ip_address
.s_addr
= INADDR_ANY
;
300 struct zclient
*zclient
;
304 /* reverse prefix_list_init */
305 prefix_list_add_hook(NULL
);
306 prefix_list_delete_hook(NULL
);
311 zclient
= pim_zebra_zclient_get();
313 zclient_stop(zclient
);
314 zclient_free(zclient
);