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,
20 $QuaggaId: $Format:%an, %ai, %h$ $
27 #include "pim_macro.h"
30 #include "pim_iface.h"
31 #include "pim_ifchannel.h"
33 #define PIM_IFP_I_am_DR(pim_ifp) ((pim_ifp)->pim_dr_addr.s_addr == (pim_ifp)->primary_address.s_addr)
36 DownstreamJPState(S,G,I) is the per-interface state machine for
37 receiving (S,G) Join/Prune messages.
39 DownstreamJPState(S,G,I) is either Join or Prune-Pending ?
41 static int downstream_jpstate_isjoined(const struct pim_ifchannel *ch)
43 return ch->ifjoin_state != PIM_IFJOIN_NOINFO;
47 The clause "local_receiver_include(S,G,I)" is true if the IGMP/MLD
48 module or other local membership mechanism has determined that local
49 members on interface I desire to receive traffic sent specifically
52 static int local_receiver_include(const struct pim_ifchannel *ch)
54 /* local_receiver_include(S,G,I) ? */
55 return ch->local_ifmembership == PIM_IFMEMBERSHIP_INCLUDE;
59 RFC 4601: 4.1.6. State Summarization Macros
61 The set "joins(S,G)" is the set of all interfaces on which the
62 router has received (S,G) Joins:
65 { all interfaces I such that
66 DownstreamJPState(S,G,I) is either Join or Prune-Pending }
68 DownstreamJPState(S,G,I) is either Join or Prune-Pending ?
70 int pim_macro_chisin_joins(const struct pim_ifchannel *ch)
72 return downstream_jpstate_isjoined(ch);
76 RFC 4601: 4.6.5. Assert State Macros
78 The set "lost_assert(S,G)" is the set of all interfaces on which the
79 router has received (S,G) joins but has lost an (S,G) assert.
82 { all interfaces I such that
83 lost_assert(S,G,I) == TRUE }
85 bool lost_assert(S,G,I) {
86 if ( RPF_interface(S) == I ) {
89 return ( AssertWinner(S,G,I) != NULL AND
90 AssertWinner(S,G,I) != me AND
91 (AssertWinnerMetric(S,G,I) is better
92 than spt_assert_metric(S,I) )
96 AssertWinner(S,G,I) is the IP source address of the Assert(S,G)
97 packet that won an Assert.
99 int pim_macro_ch_lost_assert(const struct pim_ifchannel *ch)
101 struct interface *ifp;
102 struct pim_interface *pim_ifp;
103 struct pim_assert_metric spt_assert_metric;
109 pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
110 pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
111 zlog_warn("%s: (S,G)=(%s,%s): null interface",
114 return 0; /* false */
117 /* RPF_interface(S) == I ? */
118 if (ch->upstream->rpf.source_nexthop.interface == ifp)
119 return 0; /* false */
125 pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
126 pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
127 zlog_warn("%s: (S,G)=(%s,%s): multicast not enabled on interface %s",
129 src_str, grp_str, ifp->name);
130 return 0; /* false */
133 if (PIM_INADDR_IS_ANY(ch->ifassert_winner))
134 return 0; /* false */
136 /* AssertWinner(S,G,I) == me ? */
137 if (ch->ifassert_winner.s_addr == pim_ifp->primary_address.s_addr)
138 return 0; /* false */
140 spt_assert_metric = pim_macro_spt_assert_metric(&ch->upstream->rpf,
141 pim_ifp->primary_address);
143 return pim_assert_metric_better(&ch->ifassert_winner_metric,
148 RFC 4601: 4.1.6. State Summarization Macros
151 { all interfaces I such that:
152 ( (I_am_DR( I ) AND lost_assert(S,G,I) == FALSE )
153 OR AssertWinner(S,G,I) == me )
154 AND local_receiver_include(S,G,I) }
156 AssertWinner(S,G,I) is the IP source address of the Assert(S,G)
157 packet that won an Assert.
159 int pim_macro_chisin_pim_include(const struct pim_ifchannel *ch)
161 struct pim_interface *pim_ifp = ch->interface->info;
166 pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
167 pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
168 zlog_warn("%s: (S,G)=(%s,%s): multicast not enabled on interface %s",
170 src_str, grp_str, ch->interface->name);
171 return 0; /* false */
174 /* local_receiver_include(S,G,I) ? */
175 if (!local_receiver_include(ch))
176 return 0; /* false */
178 /* OR AssertWinner(S,G,I) == me ? */
179 if (ch->ifassert_winner.s_addr == pim_ifp->primary_address.s_addr)
184 PIM_IFP_I_am_DR(pim_ifp)
186 /* lost_assert(S,G,I) == FALSE ? */
187 (!pim_macro_ch_lost_assert(ch))
191 int pim_macro_chisin_joins_or_include(const struct pim_ifchannel *ch)
193 if (pim_macro_chisin_joins(ch))
196 return pim_macro_chisin_pim_include(ch);
200 RFC 4601: 4.6.1. (S,G) Assert Message State Machine
204 AND (RPF_interface(S) != I)
205 AND (I in ( ( joins(*,*,RP(G)) (+) joins(*,G) (-) prunes(S,G,rpt) )
206 (+) ( pim_include(*,G) (-) pim_exclude(S,G) )
208 (+) joins(S,G) (+) pim_include(S,G) ) )
210 CouldAssert(S,G,I) is true for downstream interfaces that would be in
211 the inherited_olist(S,G) if (S,G) assert information was not taken
214 CouldAssert(S,G,I) may be affected by changes in the following:
216 pim_ifp->primary_address
218 ch->ifassert_winner_metric
220 ch->local_ifmembership
222 ch->upstream->rpf.source_nexthop.mrib_metric_preference
223 ch->upstream->rpf.source_nexthop.mrib_route_metric
224 ch->upstream->rpf.source_nexthop.interface
226 int pim_macro_ch_could_assert_eval(const struct pim_ifchannel *ch)
228 struct interface *ifp;
230 /* SPTbit(S,G) is always true for PIM-SSM-Only Routers */
236 pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
237 pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
238 zlog_warn("%s: (S,G)=(%s,%s): null interface",
241 return 0; /* false */
244 /* RPF_interface(S) != I ? */
245 if (ch->upstream->rpf.source_nexthop.interface == ifp)
246 return 0; /* false */
248 /* I in joins(S,G) (+) pim_include(S,G) ? */
249 return pim_macro_chisin_joins_or_include(ch);
253 RFC 4601: 4.6.3. Assert Metrics
255 spt_assert_metric(S,I) gives the assert metric we use if we're
256 sending an assert based on active (S,G) forwarding state:
259 spt_assert_metric(S,I) {
260 return {0,MRIB.pref(S),MRIB.metric(S),my_ip_address(I)}
263 struct pim_assert_metric pim_macro_spt_assert_metric(const struct pim_rpf *rpf,
264 struct in_addr ifaddr)
266 struct pim_assert_metric metric;
268 metric.rpt_bit_flag = 0;
269 metric.metric_preference = rpf->source_nexthop.mrib_metric_preference;
270 metric.route_metric = rpf->source_nexthop.mrib_route_metric;
271 metric.ip_address = ifaddr;
277 RFC 4601: 4.6.3. Assert Metrics
279 An assert metric for (S,G) to include in (or compare against) an
280 Assert message sent on interface I should be computed using the
281 following pseudocode:
283 assert_metric my_assert_metric(S,G,I) {
284 if( CouldAssert(S,G,I) == TRUE ) {
285 return spt_assert_metric(S,I)
286 } else if( CouldAssert(*,G,I) == TRUE ) {
287 return rpt_assert_metric(G,I)
289 return infinite_assert_metric()
293 struct pim_assert_metric pim_macro_ch_my_assert_metric_eval(const struct pim_ifchannel *ch)
295 struct pim_interface *pim_ifp;
297 pim_ifp = ch->interface->info;
300 if (PIM_IF_FLAG_TEST_COULD_ASSERT(ch->flags)) {
301 return pim_macro_spt_assert_metric(&ch->upstream->rpf, pim_ifp->primary_address);
305 return qpim_infinite_assert_metric;
309 RFC 4601 4.2. Data Packet Forwarding Rules
310 RFC 4601 4.8.2. PIM-SSM-Only Routers
313 inherited_olist(S,G) =
314 joins(S,G) (+) pim_include(S,G) (-) lost_assert(S,G)
316 static int pim_macro_chisin_inherited_olist(const struct pim_ifchannel *ch)
318 if (pim_macro_ch_lost_assert(ch))
319 return 0; /* false */
321 return pim_macro_chisin_joins_or_include(ch);
325 RFC 4601 4.2. Data Packet Forwarding Rules
326 RFC 4601 4.8.2. PIM-SSM-Only Routers
328 Additionally, the Packet forwarding rules of Section 4.2 can be
329 simplified in a PIM-SSM-only router:
331 iif is the incoming interface of the packet.
333 if (iif == RPF_interface(S) AND UpstreamJPState(S,G) == Joined) {
334 oiflist = inherited_olist(S,G)
335 } else if (iif is in inherited_olist(S,G)) {
336 send Assert(S,G) on iif
338 oiflist = oiflist (-) iif
339 forward packet on all interfaces in oiflist
342 inherited_olist(S,G) =
343 joins(S,G) (+) pim_include(S,G) (-) lost_assert(S,G)
346 - The following test is performed as response to WRONGVIF kernel
348 if (iif is in inherited_olist(S,G)) {
349 send Assert(S,G) on iif
351 See pim_mroute.c mroute_msg().
353 int pim_macro_chisin_oiflist(const struct pim_ifchannel *ch)
355 if (ch->upstream->join_state != PIM_UPSTREAM_JOINED) {
356 /* oiflist is NULL */
357 return 0; /* false */
360 /* oiflist = oiflist (-) iif */
361 if (ch->interface == ch->upstream->rpf.source_nexthop.interface)
362 return 0; /* false */
364 return pim_macro_chisin_inherited_olist(ch);
368 RFC 4601: 4.6.1. (S,G) Assert Message State Machine
370 AssertTrackingDesired(S,G,I) =
371 (I in ( ( joins(*,*,RP(G)) (+) joins(*,G) (-) prunes(S,G,rpt) )
372 (+) ( pim_include(*,G) (-) pim_exclude(S,G) )
375 OR (local_receiver_include(S,G,I) == TRUE
376 AND (I_am_DR(I) OR (AssertWinner(S,G,I) == me)))
377 OR ((RPF_interface(S) == I) AND (JoinDesired(S,G) == TRUE))
378 OR ((RPF_interface(RP(G)) == I) AND (JoinDesired(*,G) == TRUE)
379 AND (SPTbit(S,G) == FALSE))
381 AssertTrackingDesired(S,G,I) is true on any interface in which an
382 (S,G) assert might affect our behavior.
384 int pim_macro_assert_tracking_desired_eval(const struct pim_ifchannel *ch)
386 struct pim_interface *pim_ifp;
387 struct interface *ifp;
393 pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
394 pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
395 zlog_warn("%s: (S,G)=(%s,%s): null interface",
398 return 0; /* false */
405 pim_inet4_dump("<src?>", ch->source_addr, src_str, sizeof(src_str));
406 pim_inet4_dump("<grp?>", ch->group_addr, grp_str, sizeof(grp_str));
407 zlog_warn("%s: (S,G)=(%s,%s): multicast not enabled on interface %s",
409 src_str, grp_str, ch->interface->name);
410 return 0; /* false */
413 /* I in joins(S,G) ? */
414 if (pim_macro_chisin_joins(ch))
417 /* local_receiver_include(S,G,I) ? */
418 if (local_receiver_include(ch)) {
420 if (PIM_IFP_I_am_DR(pim_ifp))
423 /* AssertWinner(S,G,I) == me ? */
424 if (ch->ifassert_winner.s_addr == pim_ifp->primary_address.s_addr)
428 /* RPF_interface(S) == I ? */
429 if (ch->upstream->rpf.source_nexthop.interface == ifp) {
430 /* JoinDesired(S,G) ? */
431 if (PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(ch->upstream->flags))
435 return 0; /* false */