1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2008 Everton da Silva Marques
10 #include <netinet/in.h>
15 #include "pim_igmp_stats.h"
19 The following sizes are likely to support
20 any message sent within local MTU.
22 #define PIM_IGMP_BUFSIZE_READ (20000)
23 #define PIM_IGMP_BUFSIZE_WRITE (20000)
25 #define PIM_IGMP_MEMBERSHIP_QUERY (0x11)
26 #define PIM_IGMP_V1_MEMBERSHIP_REPORT (0x12)
27 #define PIM_IGMP_V2_MEMBERSHIP_REPORT (0x16)
28 #define PIM_IGMP_V2_LEAVE_GROUP (0x17)
29 #define PIM_IGMP_MTRACE_RESPONSE (0x1E)
30 #define PIM_IGMP_MTRACE_QUERY_REQUEST (0x1F)
31 #define PIM_IGMP_V3_MEMBERSHIP_REPORT (0x22)
33 #define IGMP_V3_REPORT_HEADER_SIZE (8)
34 #define IGMP_V3_GROUP_RECORD_MIN_SIZE (8)
35 #define IGMP_V3_MSG_MIN_SIZE \
36 (IGMP_V3_REPORT_HEADER_SIZE + IGMP_V3_GROUP_RECORD_MIN_SIZE)
37 #define IGMP_V12_MSG_SIZE (8)
39 #define IGMP_V3_GROUP_RECORD_TYPE_OFFSET (0)
40 #define IGMP_V3_GROUP_RECORD_AUXDATALEN_OFFSET (1)
41 #define IGMP_V3_GROUP_RECORD_NUMSOURCES_OFFSET (2)
42 #define IGMP_V3_GROUP_RECORD_GROUP_OFFSET (4)
43 #define IGMP_V3_GROUP_RECORD_SOURCE_OFFSET (8)
44 #define IGMP_CHECKSUM_OFFSET (2)
46 #define IGMP_DEFAULT_VERSION (3)
48 #define IGMP_GET_INT16(ptr, output) \
50 output = *(ptr) << 8; \
51 output |= *((ptr) + 1); \
63 struct interface
*interface
;
67 struct thread
*t_igmp_read
; /* read: IGMP sockets */
69 *t_igmp_query_timer
; /* timer: issue IGMP general queries */
70 struct thread
*t_other_querier_timer
; /* timer: other querier present */
71 pim_addr querier_addr
; /* IP address of the querier */
72 int querier_query_interval
; /* QQI */
73 int querier_robustness_variable
; /* QRV */
74 int startup_query_count
;
78 struct igmp_stats igmp_stats
;
84 void pim_igmp_if_init(struct pim_interface
*pim_ifp
, struct interface
*ifp
);
85 void pim_igmp_if_reset(struct pim_interface
*pim_ifp
);
86 void pim_igmp_if_fini(struct pim_interface
*pim_ifp
);
88 struct gm_sock
*pim_igmp_sock_lookup_ifaddr(struct list
*igmp_sock_list
,
89 struct in_addr ifaddr
);
90 struct gm_sock
*pim_igmp_sock_add(struct list
*igmp_sock_list
,
91 struct in_addr ifaddr
, struct interface
*ifp
,
93 void igmp_sock_delete(struct gm_sock
*igmp
);
94 void igmp_sock_free(struct gm_sock
*igmp
);
95 void igmp_sock_delete_all(struct interface
*ifp
);
96 int pim_igmp_packet(struct gm_sock
*igmp
, char *buf
, size_t len
);
97 bool pim_igmp_verify_header(struct ip
*ip_hdr
, size_t len
, size_t *ip_hlen
);
98 void pim_igmp_general_query_on(struct gm_sock
*igmp
);
99 void pim_igmp_general_query_off(struct gm_sock
*igmp
);
100 void pim_igmp_other_querier_timer_on(struct gm_sock
*igmp
);
101 void pim_igmp_other_querier_timer_off(struct gm_sock
*igmp
);
103 int igmp_validate_checksum(char *igmp_msg
, int igmp_msg_len
);
105 #else /* PIM_IPV != 4 */
106 static inline void pim_igmp_if_init(struct pim_interface
*pim_ifp
,
107 struct interface
*ifp
)
111 static inline void pim_igmp_if_fini(struct pim_interface
*pim_ifp
)
115 static inline void pim_igmp_general_query_on(struct gm_sock
*igmp
)
119 static inline void pim_igmp_general_query_off(struct gm_sock
*igmp
)
123 static inline void pim_igmp_other_querier_timer_on(struct gm_sock
*igmp
)
127 static inline void pim_igmp_other_querier_timer_off(struct gm_sock
*igmp
)
130 #endif /* PIM_IPV == 4 */
132 #define IGMP_SOURCE_MASK_FORWARDING (1 << 0)
133 #define IGMP_SOURCE_MASK_DELETE (1 << 1)
134 #define IGMP_SOURCE_MASK_SEND (1 << 2)
135 #define IGMP_SOURCE_TEST_FORWARDING(flags) ((flags) & IGMP_SOURCE_MASK_FORWARDING)
136 #define IGMP_SOURCE_TEST_DELETE(flags) ((flags) & IGMP_SOURCE_MASK_DELETE)
137 #define IGMP_SOURCE_TEST_SEND(flags) ((flags) & IGMP_SOURCE_MASK_SEND)
138 #define IGMP_SOURCE_DO_FORWARDING(flags) ((flags) |= IGMP_SOURCE_MASK_FORWARDING)
139 #define IGMP_SOURCE_DO_DELETE(flags) ((flags) |= IGMP_SOURCE_MASK_DELETE)
140 #define IGMP_SOURCE_DO_SEND(flags) ((flags) |= IGMP_SOURCE_MASK_SEND)
141 #define IGMP_SOURCE_DONT_FORWARDING(flags) ((flags) &= ~IGMP_SOURCE_MASK_FORWARDING)
142 #define IGMP_SOURCE_DONT_DELETE(flags) ((flags) &= ~IGMP_SOURCE_MASK_DELETE)
143 #define IGMP_SOURCE_DONT_SEND(flags) ((flags) &= ~IGMP_SOURCE_MASK_SEND)
146 pim_addr source_addr
;
147 struct thread
*t_source_timer
;
148 struct gm_group
*source_group
; /* back pointer */
149 time_t source_creation
;
150 uint32_t source_flags
;
151 struct channel_oil
*source_channel_oil
;
154 RFC 3376: 6.6.3.2. Building and Sending Group and Source Specific
157 int source_query_retransmit_count
;
162 RFC 3376: 6.2.2. Definition of Group Timers
164 The group timer is only used when a group is in EXCLUDE mode and it
165 represents the time for the *filter-mode* of the group to expire and
166 switch to INCLUDE mode.
168 struct thread
*t_group_timer
;
170 /* Shared between group-specific and
171 group-and-source-specific retransmissions */
172 struct thread
*t_group_query_retransmit_timer
;
174 /* Counter exclusive for group-specific retransmissions
175 (not used by group-and-source-specific retransmissions,
176 since sources have their counters) */
177 int group_specific_query_retransmit_count
;
179 /* compatibility mode - igmp v1, v2 or v3 */
182 int group_filtermode_isexcl
; /* 0=INCLUDE, 1=EXCLUDE */
183 struct list
*group_source_list
; /* list of struct gm_source */
184 time_t group_creation
;
185 struct interface
*interface
;
186 int64_t last_igmp_v1_report_dsec
;
187 int64_t last_igmp_v2_report_dsec
;
193 void igmp_anysource_forward_start(struct pim_instance
*pim
,
194 struct gm_group
*group
);
195 void igmp_anysource_forward_stop(struct gm_group
*group
);
197 void igmp_source_forward_start(struct pim_instance
*pim
,
198 struct gm_source
*source
);
199 void igmp_source_forward_stop(struct gm_source
*source
);
200 void igmp_source_forward_reevaluate_all(struct pim_instance
*pim
);
202 struct gm_group
*find_group_by_addr(struct gm_sock
*igmp
,
203 struct in_addr group_addr
);
204 struct gm_group
*igmp_add_group_by_addr(struct gm_sock
*igmp
,
205 struct in_addr group_addr
);
207 struct gm_source
*igmp_get_source_by_addr(struct gm_group
*group
,
208 struct in_addr src_addr
,
211 void igmp_group_delete_empty_include(struct gm_group
*group
);
213 void igmp_startup_mode_on(struct gm_sock
*igmp
);
215 void igmp_group_timer_on(struct gm_group
*group
, long interval_msec
,
218 void igmp_send_query(int igmp_version
, struct gm_group
*group
, char *query_buf
,
219 int query_buf_size
, int num_sources
,
220 struct in_addr dst_addr
, struct in_addr group_addr
,
221 int query_max_response_time_dsec
, uint8_t s_flag
,
222 struct gm_sock
*igmp
);
223 void igmp_group_delete(struct gm_group
*group
);
225 void igmp_send_query_on_intf(struct interface
*ifp
, int igmp_ver
);
227 #else /* PIM_IPV != 4 */
228 static inline void igmp_startup_mode_on(struct gm_sock
*igmp
)
231 #endif /* PIM_IPV != 4 */
233 #endif /* PIM_IGMP_H */