]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_tib.c
Merge pull request #10726 from chiragshah6/fdev2
[mirror_frr.git] / pimd / pim_tib.c
1 /*
2 * TIB (Tree Information Base) - just PIM <> IGMP/MLD glue for now
3 * Copyright (C) 2022 David Lamparter for NetDEF, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * 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 "pim_tib.h"
23
24 #include "pimd.h"
25 #include "pim_iface.h"
26 #include "pim_upstream.h"
27 #include "pim_oil.h"
28 #include "pim_nht.h"
29
30 static struct channel_oil *
31 tib_sg_oil_setup(struct pim_instance *pim, pim_sgaddr sg, struct interface *oif)
32 {
33 struct pim_interface *pim_oif = oif->info;
34 int input_iface_vif_index = 0;
35 pim_addr vif_source;
36 struct prefix src, grp;
37 struct pim_nexthop nexthop;
38 struct pim_upstream *up = NULL;
39
40 if (!pim_rp_set_upstream_addr(pim, &vif_source, sg.src, sg.grp)) {
41 /* no PIM RP - create a dummy channel oil */
42 return pim_channel_oil_add(pim, &sg, __func__);
43 }
44
45 pim_addr_to_prefix(&src, vif_source); // RP or Src addr
46 pim_addr_to_prefix(&grp, sg.grp);
47
48 up = pim_upstream_find(pim, &sg);
49 if (up) {
50 memcpy(&nexthop, &up->rpf.source_nexthop,
51 sizeof(struct pim_nexthop));
52 pim_ecmp_nexthop_lookup(pim, &nexthop, &src, &grp, 0);
53 if (nexthop.interface)
54 input_iface_vif_index = pim_if_find_vifindex_by_ifindex(
55 pim, nexthop.interface->ifindex);
56 } else
57 input_iface_vif_index =
58 pim_ecmp_fib_lookup_if_vif_index(pim, &src, &grp);
59
60 if (PIM_DEBUG_ZEBRA)
61 zlog_debug("%s: NHT %pSG vif_source %pPAs vif_index:%d",
62 __func__, &sg, &vif_source, input_iface_vif_index);
63
64 if (input_iface_vif_index < 1) {
65 if (PIM_DEBUG_IGMP_TRACE)
66 zlog_debug(
67 "%s %s: could not find input interface for %pSG",
68 __FILE__, __func__, &sg);
69
70 return pim_channel_oil_add(pim, &sg, __func__);
71 }
72
73 /*
74 * Protect IGMP against adding looped MFC entries created by both
75 * source and receiver attached to the same interface. See TODO T22.
76 * Block only when the intf is non DR DR must create upstream.
77 */
78 if ((input_iface_vif_index == pim_oif->mroute_vif_index) &&
79 !(PIM_I_am_DR(pim_oif))) {
80 /* ignore request for looped MFC entry */
81 if (PIM_DEBUG_IGMP_TRACE)
82 zlog_debug(
83 "%s: ignoring request for looped MFC entry (S,G)=%pSG: oif=%s vif_index=%d",
84 __func__, &sg, oif->name,
85 input_iface_vif_index);
86
87 return NULL;
88 }
89
90 return pim_channel_oil_add(pim, &sg, __func__);
91 }
92
93 bool tib_sg_gm_join(struct pim_instance *pim, pim_sgaddr sg,
94 struct interface *oif, struct channel_oil **oilp)
95 {
96 struct pim_interface *pim_oif = oif->info;
97
98 if (!pim_oif) {
99 if (PIM_DEBUG_IGMP_TRACE)
100 zlog_debug("%s: multicast not enabled on oif=%s?",
101 __func__, oif->name);
102 return false;
103 }
104
105 if (!*oilp)
106 *oilp = tib_sg_oil_setup(pim, sg, oif);
107 if (!*oilp)
108 return false;
109
110 if (PIM_I_am_DR(pim_oif) || PIM_I_am_DualActive(pim_oif)) {
111 int result;
112
113 result = pim_channel_add_oif(*oilp, oif,
114 PIM_OIF_FLAG_PROTO_IGMP, __func__);
115 if (result) {
116 if (PIM_DEBUG_MROUTE)
117 zlog_warn("%s: add_oif() failed with return=%d",
118 __func__, result);
119 return false;
120 }
121 } else {
122 if (PIM_DEBUG_IGMP_TRACE)
123 zlog_debug(
124 "%s: %pSG was received on %s interface but we are not DR for that interface",
125 __func__, &sg, oif->name);
126
127 return false;
128 }
129 /*
130 Feed IGMPv3-gathered local membership information into PIM
131 per-interface (S,G) state.
132 */
133 if (!pim_ifchannel_local_membership_add(oif, &sg, false /*is_vxlan*/)) {
134 if (PIM_DEBUG_MROUTE)
135 zlog_warn(
136 "%s: Failure to add local membership for %pSG",
137 __func__, &sg);
138
139 pim_channel_del_oif(*oilp, oif, PIM_OIF_FLAG_PROTO_IGMP,
140 __func__);
141 return false;
142 }
143
144 return true;
145 }
146
147 void tib_sg_gm_prune(struct pim_instance *pim, pim_sgaddr sg,
148 struct interface *oif, struct channel_oil **oilp)
149 {
150 int result;
151
152 /*
153 It appears that in certain circumstances that
154 igmp_source_forward_stop is called when IGMP forwarding
155 was not enabled in oif_flags for this outgoing interface.
156 Possibly because of multiple calls. When that happens, we
157 enter the below if statement and this function returns early
158 which in turn triggers the calling function to assert.
159 Making the call to pim_channel_del_oif and ignoring the return code
160 fixes the issue without ill effect, similar to
161 pim_forward_stop below.
162 */
163 result = pim_channel_del_oif(*oilp, oif, PIM_OIF_FLAG_PROTO_IGMP,
164 __func__);
165 if (result) {
166 if (PIM_DEBUG_IGMP_TRACE)
167 zlog_debug(
168 "%s: pim_channel_del_oif() failed with return=%d",
169 __func__, result);
170 return;
171 }
172
173 /*
174 Feed IGMPv3-gathered local membership information into PIM
175 per-interface (S,G) state.
176 */
177 pim_ifchannel_local_membership_del(oif, &sg);
178 }