1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2008 Everton da Silva Marques
7 #ifndef PIM_IFCHANNEL_H
8 #define PIM_IFCHANNEL_H
15 #include "pim_assert.h"
18 #include "pim_upstream.h"
20 enum pim_ifmembership
{ PIM_IFMEMBERSHIP_NOINFO
, PIM_IFMEMBERSHIP_INCLUDE
};
22 enum pim_ifjoin_state
{
26 PIM_IFJOIN_PRUNE_PENDING
,
28 PIM_IFJOIN_PRUNE_PENDING_TMP
,
32 Flag to detect change in CouldAssert(S,G,I)
34 #define PIM_IF_FLAG_MASK_COULD_ASSERT (1 << 0)
35 #define PIM_IF_FLAG_TEST_COULD_ASSERT(flags) ((flags) & PIM_IF_FLAG_MASK_COULD_ASSERT)
36 #define PIM_IF_FLAG_SET_COULD_ASSERT(flags) ((flags) |= PIM_IF_FLAG_MASK_COULD_ASSERT)
37 #define PIM_IF_FLAG_UNSET_COULD_ASSERT(flags) ((flags) &= ~PIM_IF_FLAG_MASK_COULD_ASSERT)
39 Flag to detect change in AssertTrackingDesired(S,G,I)
41 #define PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED (1 << 1)
42 #define PIM_IF_FLAG_TEST_ASSERT_TRACKING_DESIRED(flags) ((flags) & PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED)
43 #define PIM_IF_FLAG_SET_ASSERT_TRACKING_DESIRED(flags) ((flags) |= PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED)
44 #define PIM_IF_FLAG_UNSET_ASSERT_TRACKING_DESIRED(flags) ((flags) &= ~PIM_IF_FLAG_MASK_ASSERT_TRACKING_DESIRED)
47 * Flag to tell us if the ifchannel is (S,G,rpt)
49 #define PIM_IF_FLAG_MASK_S_G_RPT (1 << 2)
50 #define PIM_IF_FLAG_TEST_S_G_RPT(flags) ((flags) & PIM_IF_FLAG_MASK_S_G_RPT)
51 #define PIM_IF_FLAG_SET_S_G_RPT(flags) ((flags) |= PIM_IF_FLAG_MASK_S_G_RPT)
52 #define PIM_IF_FLAG_UNSET_S_G_RPT(flags) ((flags) &= ~PIM_IF_FLAG_MASK_S_G_RPT)
55 * Flag to tell us if the ifchannel is proto PIM
57 #define PIM_IF_FLAG_MASK_PROTO_PIM (1 << 3)
58 #define PIM_IF_FLAG_TEST_PROTO_PIM(flags) ((flags)&PIM_IF_FLAG_MASK_PROTO_PIM)
59 #define PIM_IF_FLAG_SET_PROTO_PIM(flags) ((flags) |= PIM_IF_FLAG_MASK_PROTO_PIM)
60 #define PIM_IF_FLAG_UNSET_PROTO_PIM(flags) \
61 ((flags) &= ~PIM_IF_FLAG_MASK_PROTO_PIM)
63 * Flag to tell us if the ifchannel is proto IGMP
65 #define PIM_IF_FLAG_MASK_PROTO_IGMP (1 << 4)
66 #define PIM_IF_FLAG_TEST_PROTO_IGMP(flags) ((flags)&PIM_IF_FLAG_MASK_PROTO_IGMP)
67 #define PIM_IF_FLAG_SET_PROTO_IGMP(flags) \
68 ((flags) |= PIM_IF_FLAG_MASK_PROTO_IGMP)
69 #define PIM_IF_FLAG_UNSET_PROTO_IGMP(flags) \
70 ((flags) &= ~PIM_IF_FLAG_MASK_PROTO_IGMP)
72 Per-interface (S,G) state
74 struct pim_ifchannel
{
75 RB_ENTRY(rb_ifchannel
) pim_ifp_rb
;
77 struct pim_ifchannel
*parent
;
80 char sg_str
[PIM_SG_LEN
];
81 struct interface
*interface
; /* backpointer to interface */
84 /* IGMPv3 determined interface has local members for (S,G) ? */
85 enum pim_ifmembership local_ifmembership
;
87 /* Per-interface (S,G) Join/Prune State (Section 4.1.4 of RFC4601) */
88 enum pim_ifjoin_state ifjoin_state
;
89 struct thread
*t_ifjoin_expiry_timer
;
90 struct thread
*t_ifjoin_prune_pending_timer
;
91 int64_t ifjoin_creation
; /* Record uptime of ifjoin state */
93 /* Per-interface (S,G) Assert State (Section 4.6.1 of RFC4601) */
94 enum pim_ifassert_state ifassert_state
;
95 struct thread
*t_ifassert_timer
;
96 pim_addr ifassert_winner
;
97 struct pim_assert_metric ifassert_winner_metric
;
98 int64_t ifassert_creation
; /* Record uptime of ifassert state */
99 struct pim_assert_metric ifassert_my_metric
;
101 /* Upstream (S,G) state */
102 struct pim_upstream
*upstream
;
105 RB_HEAD(pim_ifchannel_rb
, pim_ifchannel
);
106 RB_PROTOTYPE(pim_ifchannel_rb
, pim_ifchannel
, pim_ifp_rb
,
107 pim_ifchannel_compare
);
109 void pim_ifchannel_delete(struct pim_ifchannel
*ch
);
110 void pim_ifchannel_delete_all(struct interface
*ifp
);
111 void pim_ifchannel_membership_clear(struct interface
*ifp
);
112 void pim_ifchannel_delete_on_noinfo(struct interface
*ifp
);
113 struct pim_ifchannel
*pim_ifchannel_find(struct interface
*ifp
, pim_sgaddr
*sg
);
114 struct pim_ifchannel
*pim_ifchannel_add(struct interface
*ifp
, pim_sgaddr
*sg
,
115 uint8_t ch_flags
, int up_flags
);
116 void pim_ifchannel_join_add(struct interface
*ifp
, pim_addr neigh_addr
,
117 pim_addr upstream
, pim_sgaddr
*sg
,
118 uint8_t source_flags
, uint16_t holdtime
);
119 void pim_ifchannel_prune(struct interface
*ifp
, pim_addr upstream
,
120 pim_sgaddr
*sg
, uint8_t source_flags
,
122 int pim_ifchannel_local_membership_add(struct interface
*ifp
, pim_sgaddr
*sg
,
124 void pim_ifchannel_local_membership_del(struct interface
*ifp
, pim_sgaddr
*sg
);
126 void pim_ifchannel_ifjoin_switch(const char *caller
, struct pim_ifchannel
*ch
,
127 enum pim_ifjoin_state new_state
);
128 const char *pim_ifchannel_ifjoin_name(enum pim_ifjoin_state ifjoin_state
,
130 const char *pim_ifchannel_ifassert_name(enum pim_ifassert_state ifassert_state
);
132 int pim_ifchannel_isin_oiflist(struct pim_ifchannel
*ch
);
134 void reset_ifassert_state(struct pim_ifchannel
*ch
);
136 void pim_ifchannel_update_could_assert(struct pim_ifchannel
*ch
);
137 void pim_ifchannel_update_my_assert_metric(struct pim_ifchannel
*ch
);
138 void pim_ifchannel_update_assert_tracking_desired(struct pim_ifchannel
*ch
);
140 void pim_ifchannel_scan_forward_start(struct interface
*new_ifp
);
141 void pim_ifchannel_set_star_g_join_state(struct pim_ifchannel
*ch
, int eom
,
144 int pim_ifchannel_compare(const struct pim_ifchannel
*ch1
,
145 const struct pim_ifchannel
*ch2
);
147 void delete_on_noinfo(struct pim_ifchannel
*ch
);
148 #endif /* PIM_IFCHANNEL_H */