1 /* PIM support for VxLAN BUM flooding
3 * Copyright (C) 2019 Cumulus Networks, Inc.
5 * This file is part of FRR.
7 * FRR is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * FRR is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
31 #include "pim_iface.h"
32 #include "pim_memory.h"
34 #include "pim_register.h"
36 #include "pim_upstream.h"
37 #include "pim_ifchannel.h"
39 #include "pim_zebra.h"
40 #include "pim_vxlan.h"
42 /* pim-vxlan global info */
43 struct pim_vxlan vxlan_info
, *pim_vxlan_p
= &vxlan_info
;
45 static void pim_vxlan_work_timer_setup(bool start
);
46 static void pim_vxlan_set_peerlink_rif(struct pim_instance
*pim
,
47 struct interface
*ifp
);
49 /*************************** vxlan work list **********************************
50 * A work list is maintained for staggered generation of pim null register
51 * messages for vxlan SG entries that are in a reg_join state.
53 * A max of 500 NULL registers are generated at one shot. If paused reg
54 * generation continues on the next second and so on till all register
55 * messages have been sent out. And the process is restarted every 60s.
57 * purpose of this null register generation is to setup the SPT and maintain
58 * independent of the presence of overlay BUM traffic.
59 ****************************************************************************/
60 static void pim_vxlan_do_reg_work(void)
62 struct listnode
*listnode
;
64 struct pim_vxlan_sg
*vxlan_sg
;
69 if (sec_count
> PIM_VXLAN_NULL_REG_INTERVAL
) {
71 listnode
= vxlan_info
.next_work
?
72 vxlan_info
.next_work
:
73 vxlan_info
.work_list
->head
;
74 if (PIM_DEBUG_VXLAN
&& listnode
)
75 zlog_debug("vxlan SG work %s",
76 vxlan_info
.next_work
? "continues" : "starts");
78 listnode
= vxlan_info
.next_work
;
81 for (; listnode
; listnode
= listnode
->next
) {
82 vxlan_sg
= (struct pim_vxlan_sg
*)listnode
->data
;
83 if (vxlan_sg
->up
&& (vxlan_sg
->up
->reg_state
== PIM_REG_JOIN
)) {
85 zlog_debug("vxlan SG %s periodic NULL register",
87 pim_null_register_send(vxlan_sg
->up
);
91 if (work_cnt
> vxlan_info
.max_work_cnt
) {
92 vxlan_info
.next_work
= listnode
->next
;
94 zlog_debug("vxlan SG %d work items proc and pause",
102 zlog_debug("vxlan SG %d work items proc", work_cnt
);
104 vxlan_info
.next_work
= NULL
;
107 /* Staggered work related info is initialized when the first work comes
110 static void pim_vxlan_init_work(void)
112 if (vxlan_info
.flags
& PIM_VXLANF_WORK_INITED
)
115 vxlan_info
.max_work_cnt
= PIM_VXLAN_WORK_MAX
;
116 vxlan_info
.flags
|= PIM_VXLANF_WORK_INITED
;
117 vxlan_info
.work_list
= list_new();
118 pim_vxlan_work_timer_setup(TRUE
/* start */);
121 static void pim_vxlan_add_work(struct pim_vxlan_sg
*vxlan_sg
)
123 if (vxlan_sg
->flags
& PIM_VXLAN_SGF_DEL_IN_PROG
) {
125 zlog_debug("vxlan SG %s skip work list; del-in-prog",
130 pim_vxlan_init_work();
132 /* already a part of the work list */
133 if (vxlan_sg
->work_node
)
137 zlog_debug("vxlan SG %s work list add",
139 vxlan_sg
->work_node
= listnode_add(vxlan_info
.work_list
, vxlan_sg
);
140 /* XXX: adjust max_work_cnt if needed */
143 static void pim_vxlan_del_work(struct pim_vxlan_sg
*vxlan_sg
)
145 if (!vxlan_sg
->work_node
)
149 zlog_debug("vxlan SG %s work list del",
152 if (vxlan_sg
->work_node
== vxlan_info
.next_work
)
153 vxlan_info
.next_work
= vxlan_sg
->work_node
->next
;
155 list_delete_node(vxlan_info
.work_list
, vxlan_sg
->work_node
);
156 vxlan_sg
->work_node
= NULL
;
159 void pim_vxlan_update_sg_reg_state(struct pim_instance
*pim
,
160 struct pim_upstream
*up
, bool reg_join
)
162 struct pim_vxlan_sg
*vxlan_sg
;
164 vxlan_sg
= pim_vxlan_sg_find(pim
, &up
->sg
);
168 /* add the vxlan sg entry to a work list for periodic reg joins.
169 * the entry will stay in the list as long as the register state is
173 pim_vxlan_add_work(vxlan_sg
);
175 pim_vxlan_del_work(vxlan_sg
);
178 static int pim_vxlan_work_timer_cb(struct thread
*t
)
180 pim_vxlan_do_reg_work();
181 pim_vxlan_work_timer_setup(true /* start */);
185 /* global 1second timer used for periodic processing */
186 static void pim_vxlan_work_timer_setup(bool start
)
188 THREAD_OFF(vxlan_info
.work_timer
);
190 thread_add_timer(router
->master
, pim_vxlan_work_timer_cb
, NULL
,
191 PIM_VXLAN_WORK_TIME
, &vxlan_info
.work_timer
);
194 /**************************** vxlan origination mroutes ***********************
195 * For every (local-vtep-ip, bum-mcast-grp) registered by evpn an origination
196 * mroute is setup by pimd. The purpose of this mroute is to forward vxlan
197 * encapsulated BUM (broadcast, unknown-unicast and unknown-multicast packets
198 * over the underlay.)
200 * Sample mroute (single VTEP):
201 * (27.0.0.7, 239.1.1.100) Iif: lo Oifs: uplink-1
203 * Sample mroute (anycast VTEP):
204 * (36.0.0.9, 239.1.1.100) Iif: peerlink-3.4094\
205 * Oifs: peerlink-3.4094 uplink-1
206 ***************************************************************************/
207 static void pim_vxlan_orig_mr_up_del(struct pim_vxlan_sg
*vxlan_sg
)
209 struct pim_upstream
*up
= vxlan_sg
->up
;
215 zlog_debug("vxlan SG %s orig mroute-up del",
219 if (up
->flags
& PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_ORIG
) {
220 /* clear out all the vxlan properties */
221 up
->flags
&= ~(PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_ORIG
|
222 PIM_UPSTREAM_FLAG_MASK_STATIC_IIF
|
223 PIM_UPSTREAM_FLAG_MASK_DISABLE_KAT_EXPIRY
|
224 PIM_UPSTREAM_FLAG_MASK_FORCE_PIMREG
|
225 PIM_UPSTREAM_FLAG_MASK_NO_PIMREG_DATA
|
226 PIM_UPSTREAM_FLAG_MASK_ALLOW_IIF_IN_OIL
);
228 /* We bring things to a grinding halt by force expirying
229 * the kat. Doing this will also remove the reference we
230 * created as a "vxlan" source and delete the upstream entry
231 * if there are no other references.
233 if (PIM_UPSTREAM_FLAG_TEST_SRC_STREAM(up
->flags
)) {
234 THREAD_OFF(up
->t_ka_timer
);
235 up
= pim_upstream_keep_alive_timer_proc(up
);
237 /* this is really unexpected as we force vxlan
238 * origination mroutes active sources but just in
241 up
= pim_upstream_del(vxlan_sg
->pim
, up
,
242 __PRETTY_FUNCTION__
);
244 /* if there are other references register the source
248 pim_rpf_update(vxlan_sg
->pim
, up
, NULL
, 1 /* is_new */);
252 static void pim_vxlan_orig_mr_up_iif_update(struct pim_vxlan_sg
*vxlan_sg
)
256 /* update MFC with the new IIF */
257 pim_upstream_fill_static_iif(vxlan_sg
->up
, vxlan_sg
->iif
);
258 vif_index
= pim_if_find_vifindex_by_ifindex(vxlan_sg
->pim
,
259 vxlan_sg
->iif
->ifindex
);
261 pim_scan_individual_oil(vxlan_sg
->up
->channel_oil
,
265 zlog_debug("vxlan SG %s orig mroute-up updated with iif %s vifi %d",
267 vxlan_sg
->iif
?vxlan_sg
->iif
->name
:"-", vif_index
);
271 /* For every VxLAN BUM multicast group we setup a SG-up that has the following
272 * "forced properties" -
273 * 1. Directly connected on a DR interface i.e. we must act as an FHR
274 * 2. We prime the pump i.e. no multicast data is needed to register this
275 * source with the FHR. To do that we send periodic null registers if
276 * the SG entry is in a register-join state. We also prevent expiry of
278 * 3. As this SG is setup without data there is no need to register encapsulate
279 * data traffic. This encapsulation is explicitly skipped for the following
281 * a) Many levels of encapsulation are needed creating MTU disc challenges.
282 * Overlay BUM is encapsulated in a vxlan/UDP/IP header and then
283 * encapsulated again in a pim-register header.
284 * b) On a vxlan-aa setup both switches rx a copy of each BUM packet. if
285 * they both reg encapsulated traffic the RP will accept the duplicates
286 * as there are no RPF checks for this encapsulated data.
287 * a), b) can be workarounded if needed, but there is really no need because
288 * of (2) i.e. the pump is primed without data.
290 static void pim_vxlan_orig_mr_up_add(struct pim_vxlan_sg
*vxlan_sg
)
292 struct pim_upstream
*up
;
302 zlog_debug("vxlan SG %s orig mroute-up add with iif %s",
304 vxlan_sg
->iif
?vxlan_sg
->iif
->name
:"-");
306 PIM_UPSTREAM_FLAG_SET_SRC_VXLAN_ORIG(flags
);
307 /* pin the IIF to lo or peerlink-subinterface and disable NHT */
308 PIM_UPSTREAM_FLAG_SET_STATIC_IIF(flags
);
309 /* Fake traffic by setting SRC_STREAM and starting KAT */
310 /* We intentionally skip updating ref count for SRC_STREAM/FHR.
311 * Setting SRC_VXLAN should have already created a reference
312 * preventing the entry from being deleted
314 PIM_UPSTREAM_FLAG_SET_FHR(flags
);
315 PIM_UPSTREAM_FLAG_SET_SRC_STREAM(flags
);
316 /* Force pimreg even if non-DR. This is needed on a MLAG setup for
319 PIM_UPSTREAM_FLAG_SET_FORCE_PIMREG(flags
);
320 /* prevent KAT expiry. we want the MDT setup even if there is no BUM
323 PIM_UPSTREAM_FLAG_SET_DISABLE_KAT_EXPIRY(flags
);
324 /* SPT for vxlan BUM groups is primed and maintained via NULL
325 * registers so there is no need to reg-encapsulate
326 * vxlan-encapsulated overlay data traffic
328 PIM_UPSTREAM_FLAG_SET_NO_PIMREG_DATA(flags
);
329 /* On a MLAG setup we force a copy to the MLAG peer while also
330 * accepting traffic from the peer. To do this we set peerlink-rif as
331 * the IIF and also add it to the OIL
333 PIM_UPSTREAM_FLAG_SET_ALLOW_IIF_IN_OIL(flags
);
335 /* XXX: todo: defer pim_upstream add if pim is not enabled on the iif */
336 up
= pim_upstream_find(vxlan_sg
->pim
, &vxlan_sg
->sg
);
338 /* if the iif is set to something other than the vxlan_sg->iif
339 * we must dereg the old nexthop and force to new "static"
342 if (!PIM_UPSTREAM_FLAG_TEST_STATIC_IIF(up
->flags
)) {
343 nht_p
.family
= AF_INET
;
344 nht_p
.prefixlen
= IPV4_MAX_BITLEN
;
345 nht_p
.u
.prefix4
= up
->upstream_addr
;
346 pim_delete_tracked_nexthop(vxlan_sg
->pim
,
349 pim_upstream_ref(up
, flags
, __PRETTY_FUNCTION__
);
351 pim_vxlan_orig_mr_up_iif_update(vxlan_sg
);
353 up
= pim_upstream_add(vxlan_sg
->pim
, &vxlan_sg
->sg
,
354 vxlan_sg
->iif
, flags
,
355 __PRETTY_FUNCTION__
, NULL
);
361 zlog_debug("vxlan SG %s orig mroute-up add failed",
366 pim_upstream_keep_alive_timer_start(up
, vxlan_sg
->pim
->keep_alive_time
);
368 /* register the source with the RP */
369 if (up
->reg_state
== PIM_REG_NOINFO
) {
370 pim_register_join(up
);
371 pim_null_register_send(up
);
374 /* update the inherited OIL */
375 pim_upstream_inherited_olist(vxlan_sg
->pim
, up
);
378 static void pim_vxlan_orig_mr_oif_add(struct pim_vxlan_sg
*vxlan_sg
)
380 if (!vxlan_sg
->up
|| !vxlan_sg
->orig_oif
)
384 zlog_debug("vxlan SG %s oif %s add",
385 vxlan_sg
->sg_str
, vxlan_sg
->orig_oif
->name
);
387 vxlan_sg
->flags
|= PIM_VXLAN_SGF_OIF_INSTALLED
;
388 pim_channel_add_oif(vxlan_sg
->up
->channel_oil
,
389 vxlan_sg
->orig_oif
, PIM_OIF_FLAG_PROTO_VXLAN
);
392 static void pim_vxlan_orig_mr_oif_del(struct pim_vxlan_sg
*vxlan_sg
)
394 struct interface
*orig_oif
;
396 orig_oif
= vxlan_sg
->orig_oif
;
397 vxlan_sg
->orig_oif
= NULL
;
399 if (!(vxlan_sg
->flags
& PIM_VXLAN_SGF_OIF_INSTALLED
))
403 zlog_debug("vxlan SG %s oif %s del",
404 vxlan_sg
->sg_str
, orig_oif
->name
);
406 vxlan_sg
->flags
&= ~PIM_VXLAN_SGF_OIF_INSTALLED
;
407 pim_channel_del_oif(vxlan_sg
->up
->channel_oil
,
408 orig_oif
, PIM_OIF_FLAG_PROTO_VXLAN
);
411 static inline struct interface
*pim_vxlan_orig_mr_oif_get(
412 struct pim_instance
*pim
)
414 return (vxlan_mlag
.flags
& PIM_VXLAN_MLAGF_ENABLED
) ?
415 pim
->vxlan
.peerlink_rif
: NULL
;
418 /* Single VTEPs: IIF for the vxlan-origination-mroutes is lo or vrf-dev (if
419 * the mroute is in a non-default vrf).
420 * Anycast VTEPs: IIF is the MLAG ISL/peerlink.
422 static inline struct interface
*pim_vxlan_orig_mr_iif_get(
423 struct pim_instance
*pim
)
425 return ((vxlan_mlag
.flags
& PIM_VXLAN_MLAGF_ENABLED
) &&
426 pim
->vxlan
.peerlink_rif
) ?
427 pim
->vxlan
.peerlink_rif
: pim
->vxlan
.default_iif
;
430 static bool pim_vxlan_orig_mr_add_is_ok(struct pim_vxlan_sg
*vxlan_sg
)
432 struct pim_interface
*pim_ifp
;
434 vxlan_sg
->iif
= pim_vxlan_orig_mr_iif_get(vxlan_sg
->pim
);
438 pim_ifp
= (struct pim_interface
*)vxlan_sg
->iif
->info
;
439 if (!pim_ifp
|| (pim_ifp
->mroute_vif_index
< 0))
445 static void pim_vxlan_orig_mr_install(struct pim_vxlan_sg
*vxlan_sg
)
447 pim_vxlan_orig_mr_up_add(vxlan_sg
);
449 vxlan_sg
->orig_oif
= pim_vxlan_orig_mr_oif_get(vxlan_sg
->pim
);
450 pim_vxlan_orig_mr_oif_add(vxlan_sg
);
453 static void pim_vxlan_orig_mr_add(struct pim_vxlan_sg
*vxlan_sg
)
455 if (!pim_vxlan_orig_mr_add_is_ok(vxlan_sg
))
459 zlog_debug("vxlan SG %s orig-mr add", vxlan_sg
->sg_str
);
461 pim_vxlan_orig_mr_install(vxlan_sg
);
464 static void pim_vxlan_orig_mr_del(struct pim_vxlan_sg
*vxlan_sg
)
467 zlog_debug("vxlan SG %s orig-mr del", vxlan_sg
->sg_str
);
469 pim_vxlan_orig_mr_oif_del(vxlan_sg
);
470 pim_vxlan_orig_mr_up_del(vxlan_sg
);
473 static void pim_vxlan_orig_mr_iif_update(struct hash_backet
*backet
, void *arg
)
475 struct interface
*ifp
= (struct interface
*)arg
;
476 struct pim_vxlan_sg
*vxlan_sg
= (struct pim_vxlan_sg
*)backet
->data
;
477 struct interface
*old_iif
= vxlan_sg
->iif
;
479 if (!pim_vxlan_is_orig_mroute(vxlan_sg
))
483 zlog_debug("vxlan SG %s iif changed from %s to %s",
485 old_iif
? old_iif
->name
: "-",
486 ifp
? ifp
->name
: "-");
488 if (pim_vxlan_orig_mr_add_is_ok(vxlan_sg
)) {
490 /* upstream exists but iif changed */
491 pim_vxlan_orig_mr_up_iif_update(vxlan_sg
);
494 pim_vxlan_orig_mr_install(vxlan_sg
);
497 pim_vxlan_orig_mr_del(vxlan_sg
);
501 /**************************** vxlan termination mroutes ***********************
502 * For every bum-mcast-grp registered by evpn a *G termination
503 * mroute is setup by pimd. The purpose of this mroute is to pull down vxlan
504 * packets with the bum-mcast-grp dip from the underlay and terminate the
505 * tunnel. This is done by including the vxlan termination device (ipmr-lo) in
506 * its OIL. The vxlan de-capsulated packets are subject to subsequent overlay
510 * (0.0.0.0, 239.1.1.100) Iif: uplink-1 Oifs: ipmr-lo, uplink-1
511 *****************************************************************************/
512 struct pim_interface
*pim_vxlan_get_term_ifp(struct pim_instance
*pim
)
514 return pim
->vxlan
.term_if
?
515 (struct pim_interface
*)pim
->vxlan
.term_if
->info
: NULL
;
518 static void pim_vxlan_term_mr_oif_add(struct pim_vxlan_sg
*vxlan_sg
)
520 if (vxlan_sg
->flags
& PIM_VXLAN_SGF_OIF_INSTALLED
)
524 zlog_debug("vxlan SG %s term-oif %s add",
525 vxlan_sg
->sg_str
, vxlan_sg
->term_oif
->name
);
527 if (pim_ifchannel_local_membership_add(vxlan_sg
->term_oif
,
529 vxlan_sg
->flags
|= PIM_VXLAN_SGF_OIF_INSTALLED
;
531 zlog_warn("vxlan SG %s term-oif %s add failed",
532 vxlan_sg
->sg_str
, vxlan_sg
->term_oif
->name
);
536 static void pim_vxlan_term_mr_oif_del(struct pim_vxlan_sg
*vxlan_sg
)
538 if (!(vxlan_sg
->flags
& PIM_VXLAN_SGF_OIF_INSTALLED
))
542 zlog_debug("vxlan SG %s oif %s del",
543 vxlan_sg
->sg_str
, vxlan_sg
->term_oif
->name
);
545 vxlan_sg
->flags
&= ~PIM_VXLAN_SGF_OIF_INSTALLED
;
546 pim_ifchannel_local_membership_del(vxlan_sg
->term_oif
, &vxlan_sg
->sg
);
549 static void pim_vxlan_term_mr_up_add(struct pim_vxlan_sg
*vxlan_sg
)
551 struct pim_upstream
*up
;
560 zlog_debug("vxlan SG %s term mroute-up add",
563 PIM_UPSTREAM_FLAG_SET_SRC_VXLAN_TERM(flags
);
564 /* enable MLAG designated-forwarder election on termination mroutes */
565 PIM_UPSTREAM_FLAG_SET_MLAG_VXLAN(flags
);
567 up
= pim_upstream_add(vxlan_sg
->pim
, &vxlan_sg
->sg
,
568 NULL
/* iif */, flags
,
569 __PRETTY_FUNCTION__
, NULL
);
573 zlog_warn("vxlan SG %s term mroute-up add failed",
578 static void pim_vxlan_term_mr_up_del(struct pim_vxlan_sg
*vxlan_sg
)
580 struct pim_upstream
*up
= vxlan_sg
->up
;
586 zlog_debug("vxlan SG %s term mroute-up del",
589 if (up
->flags
& PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM
) {
590 /* clear out all the vxlan related flags */
591 up
->flags
&= ~(PIM_UPSTREAM_FLAG_MASK_SRC_VXLAN_TERM
|
592 PIM_UPSTREAM_FLAG_MASK_MLAG_VXLAN
);
594 pim_upstream_del(vxlan_sg
->pim
, up
,
595 __PRETTY_FUNCTION__
);
599 static void pim_vxlan_term_mr_add(struct pim_vxlan_sg
*vxlan_sg
)
602 zlog_debug("vxlan SG %s term mroute add", vxlan_sg
->sg_str
);
604 vxlan_sg
->term_oif
= vxlan_sg
->pim
->vxlan
.term_if
;
605 if (!vxlan_sg
->term_oif
)
606 /* defer termination mroute till we have a termination device */
609 pim_vxlan_term_mr_up_add(vxlan_sg
);
610 /* set up local membership for the term-oif */
611 pim_vxlan_term_mr_oif_add(vxlan_sg
);
614 static void pim_vxlan_term_mr_del(struct pim_vxlan_sg
*vxlan_sg
)
617 zlog_debug("vxlan SG %s term mroute del", vxlan_sg
->sg_str
);
619 /* remove local membership associated with the term oif */
620 pim_vxlan_term_mr_oif_del(vxlan_sg
);
621 /* remove references to the upstream entry */
622 pim_vxlan_term_mr_up_del(vxlan_sg
);
625 /************************** vxlan SG cache management ************************/
626 static unsigned int pim_vxlan_sg_hash_key_make(void *p
)
628 struct pim_vxlan_sg
*vxlan_sg
= p
;
630 return (jhash_2words(vxlan_sg
->sg
.src
.s_addr
,
631 vxlan_sg
->sg
.grp
.s_addr
, 0));
634 static bool pim_vxlan_sg_hash_eq(const void *p1
, const void *p2
)
636 const struct pim_vxlan_sg
*sg1
= p1
;
637 const struct pim_vxlan_sg
*sg2
= p2
;
639 return ((sg1
->sg
.src
.s_addr
== sg2
->sg
.src
.s_addr
)
640 && (sg1
->sg
.grp
.s_addr
== sg2
->sg
.grp
.s_addr
));
643 static struct pim_vxlan_sg
*pim_vxlan_sg_new(struct pim_instance
*pim
,
644 struct prefix_sg
*sg
)
646 struct pim_vxlan_sg
*vxlan_sg
;
648 vxlan_sg
= XCALLOC(MTYPE_PIM_VXLAN_SG
, sizeof(*vxlan_sg
));
652 pim_str_sg_set(sg
, vxlan_sg
->sg_str
);
655 zlog_debug("vxlan SG %s alloc", vxlan_sg
->sg_str
);
657 vxlan_sg
= hash_get(pim
->vxlan
.sg_hash
, vxlan_sg
, hash_alloc_intern
);
662 struct pim_vxlan_sg
*pim_vxlan_sg_find(struct pim_instance
*pim
,
663 struct prefix_sg
*sg
)
665 struct pim_vxlan_sg lookup
;
668 return hash_lookup(pim
->vxlan
.sg_hash
, &lookup
);
671 struct pim_vxlan_sg
*pim_vxlan_sg_add(struct pim_instance
*pim
,
672 struct prefix_sg
*sg
)
674 struct pim_vxlan_sg
*vxlan_sg
;
676 vxlan_sg
= pim_vxlan_sg_find(pim
, sg
);
680 vxlan_sg
= pim_vxlan_sg_new(pim
, sg
);
682 if (pim_vxlan_is_orig_mroute(vxlan_sg
))
683 pim_vxlan_orig_mr_add(vxlan_sg
);
685 pim_vxlan_term_mr_add(vxlan_sg
);
690 void pim_vxlan_sg_del(struct pim_instance
*pim
, struct prefix_sg
*sg
)
692 struct pim_vxlan_sg
*vxlan_sg
;
694 vxlan_sg
= pim_vxlan_sg_find(pim
, sg
);
698 vxlan_sg
->flags
|= PIM_VXLAN_SGF_DEL_IN_PROG
;
700 pim_vxlan_del_work(vxlan_sg
);
702 if (pim_vxlan_is_orig_mroute(vxlan_sg
))
703 pim_vxlan_orig_mr_del(vxlan_sg
);
705 pim_vxlan_term_mr_del(vxlan_sg
);
707 hash_release(vxlan_sg
->pim
->vxlan
.sg_hash
, vxlan_sg
);
710 zlog_debug("vxlan SG %s free", vxlan_sg
->sg_str
);
712 XFREE(MTYPE_PIM_VXLAN_SG
, vxlan_sg
);
715 /******************************* MLAG handling *******************************/
716 /* The peerlink sub-interface is added as an OIF to the origination-mroute.
717 * This is done to send a copy of the multicast-vxlan encapsulated traffic
718 * to the MLAG peer which may mroute it over the underlay if there are any
719 * interested receivers.
721 static void pim_vxlan_sg_peerlink_update(struct hash_backet
*backet
, void *arg
)
723 struct interface
*new_oif
= (struct interface
*)arg
;
724 struct pim_vxlan_sg
*vxlan_sg
= (struct pim_vxlan_sg
*)backet
->data
;
726 if (!pim_vxlan_is_orig_mroute(vxlan_sg
))
729 if (vxlan_sg
->orig_oif
== new_oif
)
732 pim_vxlan_orig_mr_oif_del(vxlan_sg
);
734 vxlan_sg
->orig_oif
= new_oif
;
735 pim_vxlan_orig_mr_oif_add(vxlan_sg
);
738 /* In the case of anycast VTEPs the VTEP-PIP must be used as the
741 bool pim_vxlan_get_register_src(struct pim_instance
*pim
,
742 struct pim_upstream
*up
, struct in_addr
*src_p
)
744 if (!(vxlan_mlag
.flags
& PIM_VXLAN_MLAGF_ENABLED
))
747 /* if address is not available suppress the pim-register */
748 if (vxlan_mlag
.reg_addr
.s_addr
== INADDR_ANY
)
751 *src_p
= vxlan_mlag
.reg_addr
;
755 void pim_vxlan_mlag_update(bool enable
, bool peer_state
, uint32_t role
,
756 struct interface
*peerlink_rif
,
757 struct in_addr
*reg_addr
)
759 struct pim_instance
*pim
;
760 struct interface
*old_oif
;
761 struct interface
*new_oif
;
762 char addr_buf
[INET_ADDRSTRLEN
];
763 struct pim_interface
*pim_ifp
= NULL
;
765 if (PIM_DEBUG_VXLAN
) {
766 inet_ntop(AF_INET
, reg_addr
,
767 addr_buf
, INET_ADDRSTRLEN
);
768 zlog_debug("vxlan MLAG update %s state %s role %d rif %s addr %s",
769 enable
? "enable" : "disable",
770 peer_state
? "up" : "down",
772 peerlink_rif
? peerlink_rif
->name
: "-",
776 /* XXX: for now vxlan termination is only possible in the default VRF
777 * when that changes this will need to change to iterate all VRFs
779 pim
= pim_get_pim_instance(VRF_DEFAULT
);
781 old_oif
= pim_vxlan_orig_mr_oif_get(pim
);
784 vxlan_mlag
.flags
|= PIM_VXLAN_MLAGF_ENABLED
;
786 vxlan_mlag
.flags
&= ~PIM_VXLAN_MLAGF_ENABLED
;
788 if (vxlan_mlag
.peerlink_rif
!= peerlink_rif
)
789 vxlan_mlag
.peerlink_rif
= peerlink_rif
;
791 vxlan_mlag
.reg_addr
= *reg_addr
;
792 vxlan_mlag
.peer_state
= peer_state
;
793 vxlan_mlag
.role
= role
;
795 /* process changes */
796 if (vxlan_mlag
.peerlink_rif
)
797 pim_ifp
= (struct pim_interface
*)vxlan_mlag
.peerlink_rif
->info
;
798 if ((vxlan_mlag
.flags
& PIM_VXLAN_MLAGF_ENABLED
) &&
799 pim_ifp
&& (pim_ifp
->mroute_vif_index
> 0))
800 pim_vxlan_set_peerlink_rif(pim
, peerlink_rif
);
802 pim_vxlan_set_peerlink_rif(pim
, NULL
);
804 new_oif
= pim_vxlan_orig_mr_oif_get(pim
);
805 if (old_oif
!= new_oif
)
806 hash_iterate(pim
->vxlan
.sg_hash
, pim_vxlan_sg_peerlink_update
,
810 /****************************** misc callbacks *******************************/
811 void pim_vxlan_config_write(struct vty
*vty
, char *spaces
, int *writes
)
813 char addr_buf
[INET_ADDRSTRLEN
];
815 if ((vxlan_mlag
.flags
& PIM_VXLAN_MLAGF_ENABLED
) &&
816 vxlan_mlag
.peerlink_rif
) {
818 inet_ntop(AF_INET
, &vxlan_mlag
.reg_addr
,
819 addr_buf
, sizeof(addr_buf
));
821 "%sip pim mlag %s role %s state %s addr %s\n",
823 vxlan_mlag
.peerlink_rif
->name
,
824 (vxlan_mlag
.role
== PIM_VXLAN_MLAG_ROLE_PRIMARY
) ?
825 "primary":"secondary",
826 vxlan_mlag
.peer_state
? "up" : "down",
832 static void pim_vxlan_set_default_iif(struct pim_instance
*pim
,
833 struct interface
*ifp
)
835 struct interface
*old_iif
;
837 if (pim
->vxlan
.default_iif
== ifp
)
840 old_iif
= pim
->vxlan
.default_iif
;
842 zlog_debug("%s: vxlan default iif changed from %s to %s",
844 old_iif
? old_iif
->name
: "-",
845 ifp
? ifp
->name
: "-");
847 old_iif
= pim_vxlan_orig_mr_iif_get(pim
);
848 pim
->vxlan
.default_iif
= ifp
;
849 ifp
= pim_vxlan_orig_mr_iif_get(pim
);
854 zlog_debug("%s: vxlan orig iif changed from %s to %s",
855 __PRETTY_FUNCTION__
, old_iif
? old_iif
->name
: "-",
856 ifp
? ifp
->name
: "-");
858 /* add/del upstream entries for the existing vxlan SG when the
859 * interface becomes available
861 if (pim
->vxlan
.sg_hash
)
862 hash_iterate(pim
->vxlan
.sg_hash
,
863 pim_vxlan_orig_mr_iif_update
, ifp
);
866 static void pim_vxlan_set_peerlink_rif(struct pim_instance
*pim
,
867 struct interface
*ifp
)
869 struct interface
*old_iif
;
871 if (pim
->vxlan
.peerlink_rif
== ifp
)
874 old_iif
= pim
->vxlan
.peerlink_rif
;
876 zlog_debug("%s: vxlan peerlink_rif changed from %s to %s",
877 __PRETTY_FUNCTION__
, old_iif
? old_iif
->name
: "-",
878 ifp
? ifp
->name
: "-");
880 old_iif
= pim_vxlan_orig_mr_iif_get(pim
);
881 pim
->vxlan
.peerlink_rif
= ifp
;
882 ifp
= pim_vxlan_orig_mr_iif_get(pim
);
887 zlog_debug("%s: vxlan orig iif changed from %s to %s",
888 __PRETTY_FUNCTION__
, old_iif
? old_iif
->name
: "-",
889 ifp
? ifp
->name
: "-");
891 /* add/del upstream entries for the existing vxlan SG when the
892 * interface becomes available
894 if (pim
->vxlan
.sg_hash
)
895 hash_iterate(pim
->vxlan
.sg_hash
,
896 pim_vxlan_orig_mr_iif_update
, ifp
);
899 void pim_vxlan_add_vif(struct interface
*ifp
)
901 struct pim_interface
*pim_ifp
= ifp
->info
;
902 struct pim_instance
*pim
= pim_ifp
->pim
;
904 if (pim
->vrf_id
!= VRF_DEFAULT
)
907 if (if_is_loopback_or_vrf(ifp
))
908 pim_vxlan_set_default_iif(pim
, ifp
);
910 if (vxlan_mlag
.flags
& PIM_VXLAN_MLAGF_ENABLED
&&
911 (ifp
== vxlan_mlag
.peerlink_rif
))
912 pim_vxlan_set_peerlink_rif(pim
, ifp
);
915 void pim_vxlan_del_vif(struct interface
*ifp
)
917 struct pim_interface
*pim_ifp
= ifp
->info
;
918 struct pim_instance
*pim
= pim_ifp
->pim
;
920 if (pim
->vrf_id
!= VRF_DEFAULT
)
923 if (pim
->vxlan
.default_iif
== ifp
)
924 pim_vxlan_set_default_iif(pim
, NULL
);
926 if (pim
->vxlan
.peerlink_rif
== ifp
)
927 pim_vxlan_set_peerlink_rif(pim
, NULL
);
930 static void pim_vxlan_term_mr_oif_update(struct hash_backet
*backet
, void *arg
)
932 struct interface
*ifp
= (struct interface
*)arg
;
933 struct pim_vxlan_sg
*vxlan_sg
= (struct pim_vxlan_sg
*)backet
->data
;
935 if (pim_vxlan_is_orig_mroute(vxlan_sg
))
938 if (vxlan_sg
->term_oif
== ifp
)
942 zlog_debug("vxlan SG %s term oif changed from %s to %s",
944 vxlan_sg
->term_oif
? vxlan_sg
->term_oif
->name
: "-",
945 ifp
? ifp
->name
: "-");
947 pim_vxlan_term_mr_del(vxlan_sg
);
948 vxlan_sg
->term_oif
= ifp
;
949 pim_vxlan_term_mr_add(vxlan_sg
);
952 void pim_vxlan_add_term_dev(struct pim_instance
*pim
,
953 struct interface
*ifp
)
955 struct pim_interface
*pim_ifp
;
957 if (pim
->vxlan
.term_if
== ifp
)
961 zlog_debug("vxlan term oif changed from %s to %s",
962 pim
->vxlan
.term_if
? pim
->vxlan
.term_if
->name
: "-",
965 /* enable pim on the term ifp */
966 pim_ifp
= (struct pim_interface
*)ifp
->info
;
968 PIM_IF_DO_PIM(pim_ifp
->options
);
970 pim_ifp
= pim_if_new(ifp
, false /*igmp*/, true /*pim*/,
971 false /*pimreg*/, true /*vxlan_term*/);
972 /* ensure that pimreg existss before using the newly created
973 * vxlan termination device
975 pim_if_create_pimreg(pim
);
978 pim
->vxlan
.term_if
= ifp
;
980 if (pim
->vxlan
.sg_hash
)
981 hash_iterate(pim_ifp
->pim
->vxlan
.sg_hash
,
982 pim_vxlan_term_mr_oif_update
, ifp
);
985 void pim_vxlan_del_term_dev(struct pim_instance
*pim
)
987 struct interface
*ifp
= pim
->vxlan
.term_if
;
988 struct pim_interface
*pim_ifp
;
991 zlog_debug("vxlan term oif changed from %s to -", ifp
->name
);
993 pim
->vxlan
.term_if
= NULL
;
995 if (pim
->vxlan
.sg_hash
)
996 hash_iterate(pim
->vxlan
.sg_hash
,
997 pim_vxlan_term_mr_oif_update
, NULL
);
999 pim_ifp
= (struct pim_interface
*)ifp
->info
;
1001 PIM_IF_DONT_PIM(pim_ifp
->options
);
1002 if (!PIM_IF_TEST_IGMP(pim_ifp
->options
))
1008 void pim_vxlan_init(struct pim_instance
*pim
)
1012 snprintf(hash_name
, sizeof(hash_name
),
1013 "PIM %s vxlan SG hash", pim
->vrf
->name
);
1014 pim
->vxlan
.sg_hash
= hash_create(pim_vxlan_sg_hash_key_make
,
1015 pim_vxlan_sg_hash_eq
, hash_name
);
1018 void pim_vxlan_exit(struct pim_instance
*pim
)
1020 if (pim
->vxlan
.sg_hash
) {
1021 hash_clean(pim
->vxlan
.sg_hash
, NULL
);
1022 hash_free(pim
->vxlan
.sg_hash
);
1023 pim
->vxlan
.sg_hash
= NULL
;