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
20 #ifndef PIM_IFCHANNEL_H
21 #define PIM_IFCHANNEL_H
29 #include "pim_upstream.h"
31 enum pim_ifmembership
{ PIM_IFMEMBERSHIP_NOINFO
, PIM_IFMEMBERSHIP_INCLUDE
};
33 enum pim_ifjoin_state
{
37 PIM_IFJOIN_PRUNE_PENDING
,
39 PIM_IFJOIN_PRUNE_PENDING_TMP
,
42 enum pim_ifassert_state
{
44 PIM_IFASSERT_I_AM_WINNER
,
45 PIM_IFASSERT_I_AM_LOSER
48 struct pim_assert_metric
{
49 uint32_t rpt_bit_flag
;
50 uint32_t metric_preference
;
51 uint32_t route_metric
;
52 struct in_addr ip_address
; /* neighbor router that sourced the Assert
57 Flag to detect change in CouldAssert(S,G,I)
59 #define PIM_IF_FLAG_MASK_COULD_ASSERT (1 << 0)
60 #define PIM_IF_FLAG_TEST_COULD_ASSERT(flags) ((flags) & PIM_IF_FLAG_MASK_COULD_ASSERT)
61 #define PIM_IF_FLAG_SET_COULD_ASSERT(flags) ((flags) |= PIM_IF_FLAG_MASK_COULD_ASSERT)
62 #define PIM_IF_FLAG_UNSET_COULD_ASSERT(flags) ((flags) &= ~PIM_IF_FLAG_MASK_COULD_ASSERT)
64 Flag to detect change in AssertTrackingDesired(S,G,I)
66 #define PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED (1 << 1)
67 #define PIM_IF_FLAG_TEST_ASSERT_TRACKING_DESIRED(flags) ((flags) & PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED)
68 #define PIM_IF_FLAG_SET_ASSERT_TRACKING_DESIRED(flags) ((flags) |= PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED)
69 #define PIM_IF_FLAG_UNSET_ASSERT_TRACKING_DESIRED(flags) ((flags) &= ~PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED)
72 * Flag to tell us if the ifchannel is (S,G,rpt)
74 #define PIM_IF_FLAG_MASK_S_G_RPT (1 << 2)
75 #define PIM_IF_FLAG_TEST_S_G_RPT(flags) ((flags) & PIM_IF_FLAG_MASK_S_G_RPT)
76 #define PIM_IF_FLAG_SET_S_G_RPT(flags) ((flags) |= PIM_IF_FLAG_MASK_S_G_RPT)
77 #define PIM_IF_FLAG_UNSET_S_G_RPT(flags) ((flags) &= ~PIM_IF_FLAG_MASK_S_G_RPT)
80 * Flag to tell us if the ifchannel is proto PIM
82 #define PIM_IF_FLAG_MASK_PROTO_PIM (1 << 3)
83 #define PIM_IF_FLAG_TEST_PROTO_PIM(flags) ((flags)&PIM_IF_FLAG_MASK_PROTO_PIM)
84 #define PIM_IF_FLAG_SET_PROTO_PIM(flags) ((flags) |= PIM_IF_FLAG_MASK_PROTO_PIM)
85 #define PIM_IF_FLAG_UNSET_PROTO_PIM(flags) \
86 ((flags) &= ~PIM_IF_FLAG_MASK_PROTO_PIM)
88 * Flag to tell us if the ifchannel is proto IGMP
90 #define PIM_IF_FLAG_MASK_PROTO_IGMP (1 << 4)
91 #define PIM_IF_FLAG_TEST_PROTO_IGMP(flags) ((flags)&PIM_IF_FLAG_MASK_PROTO_IGMP)
92 #define PIM_IF_FLAG_SET_PROTO_IGMP(flags) \
93 ((flags) |= PIM_IF_FLAG_MASK_PROTO_IGMP)
94 #define PIM_IF_FLAG_UNSET_PROTO_IGMP(flags) \
95 ((flags) &= ~PIM_IF_FLAG_MASK_PROTO_IGMP)
97 Per-interface (S,G) state
99 struct pim_ifchannel
{
100 RB_ENTRY(rb_ifchannel
) pim_ifp_rb
;
102 struct pim_ifchannel
*parent
;
103 struct list
*sources
;
105 char sg_str
[PIM_SG_LEN
];
106 struct interface
*interface
; /* backpointer to interface */
109 /* IGMPv3 determined interface has local members for (S,G) ? */
110 enum pim_ifmembership local_ifmembership
;
112 /* Per-interface (S,G) Join/Prune State (Section 4.1.4 of RFC4601) */
113 enum pim_ifjoin_state ifjoin_state
;
114 struct thread
*t_ifjoin_expiry_timer
;
115 struct thread
*t_ifjoin_prune_pending_timer
;
116 int64_t ifjoin_creation
; /* Record uptime of ifjoin state */
118 /* Per-interface (S,G) Assert State (Section 4.6.1 of RFC4601) */
119 enum pim_ifassert_state ifassert_state
;
120 struct thread
*t_ifassert_timer
;
121 struct in_addr ifassert_winner
;
122 struct pim_assert_metric ifassert_winner_metric
;
123 int64_t ifassert_creation
; /* Record uptime of ifassert state */
124 struct pim_assert_metric ifassert_my_metric
;
126 /* Upstream (S,G) state */
127 struct pim_upstream
*upstream
;
130 RB_HEAD(pim_ifchannel_rb
, pim_ifchannel
);
131 RB_PROTOTYPE(pim_ifchannel_rb
, pim_ifchannel
, pim_ifp_rb
,
132 pim_ifchannel_compare
);
134 void pim_ifchannel_delete(struct pim_ifchannel
*ch
);
135 void pim_ifchannel_delete_all(struct interface
*ifp
);
136 void pim_ifchannel_membership_clear(struct interface
*ifp
);
137 void pim_ifchannel_delete_on_noinfo(struct interface
*ifp
);
138 struct pim_ifchannel
*pim_ifchannel_find(struct interface
*ifp
,
139 struct prefix_sg
*sg
);
140 struct pim_ifchannel
*pim_ifchannel_add(struct interface
*ifp
,
141 struct prefix_sg
*sg
, uint8_t ch_flags
,
143 void pim_ifchannel_join_add(struct interface
*ifp
, struct in_addr neigh_addr
,
144 struct in_addr upstream
, struct prefix_sg
*sg
,
145 uint8_t source_flags
, uint16_t holdtime
);
146 void pim_ifchannel_prune(struct interface
*ifp
, struct in_addr upstream
,
147 struct prefix_sg
*sg
, uint8_t source_flags
,
149 int pim_ifchannel_local_membership_add(struct interface
*ifp
,
150 struct prefix_sg
*sg
, bool is_vxlan
);
151 void pim_ifchannel_local_membership_del(struct interface
*ifp
,
152 struct prefix_sg
*sg
);
154 void pim_ifchannel_ifjoin_switch(const char *caller
, struct pim_ifchannel
*ch
,
155 enum pim_ifjoin_state new_state
);
156 const char *pim_ifchannel_ifjoin_name(enum pim_ifjoin_state ifjoin_state
,
158 const char *pim_ifchannel_ifassert_name(enum pim_ifassert_state ifassert_state
);
160 int pim_ifchannel_isin_oiflist(struct pim_ifchannel
*ch
);
162 void reset_ifassert_state(struct pim_ifchannel
*ch
);
164 void pim_ifchannel_update_could_assert(struct pim_ifchannel
*ch
);
165 void pim_ifchannel_update_my_assert_metric(struct pim_ifchannel
*ch
);
166 void pim_ifchannel_update_assert_tracking_desired(struct pim_ifchannel
*ch
);
168 void pim_ifchannel_scan_forward_start(struct interface
*new_ifp
);
169 void pim_ifchannel_set_star_g_join_state(struct pim_ifchannel
*ch
, int eom
,
172 int pim_ifchannel_compare(const struct pim_ifchannel
*ch1
,
173 const struct pim_ifchannel
*ch2
);
175 unsigned int pim_ifchannel_hash_key(const void *arg
);
176 #endif /* PIM_IFCHANNEL_H */