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
23 #include <netinet/in.h>
28 #include "pim_igmp_stats.h"
32 The following sizes are likely to support
33 any message sent within local MTU.
35 #define PIM_IGMP_BUFSIZE_READ (20000)
36 #define PIM_IGMP_BUFSIZE_WRITE (20000)
38 #define PIM_IGMP_MEMBERSHIP_QUERY (0x11)
39 #define PIM_IGMP_V1_MEMBERSHIP_REPORT (0x12)
40 #define PIM_IGMP_V2_MEMBERSHIP_REPORT (0x16)
41 #define PIM_IGMP_V2_LEAVE_GROUP (0x17)
42 #define PIM_IGMP_MTRACE_RESPONSE (0x1E)
43 #define PIM_IGMP_MTRACE_QUERY_REQUEST (0x1F)
44 #define PIM_IGMP_V3_MEMBERSHIP_REPORT (0x22)
46 #define IGMP_V3_REPORT_HEADER_SIZE (8)
47 #define IGMP_V3_GROUP_RECORD_MIN_SIZE (8)
48 #define IGMP_V3_MSG_MIN_SIZE \
49 (IGMP_V3_REPORT_HEADER_SIZE + IGMP_V3_GROUP_RECORD_MIN_SIZE)
50 #define IGMP_V12_MSG_SIZE (8)
52 #define IGMP_V3_GROUP_RECORD_TYPE_OFFSET (0)
53 #define IGMP_V3_GROUP_RECORD_AUXDATALEN_OFFSET (1)
54 #define IGMP_V3_GROUP_RECORD_NUMSOURCES_OFFSET (2)
55 #define IGMP_V3_GROUP_RECORD_GROUP_OFFSET (4)
56 #define IGMP_V3_GROUP_RECORD_SOURCE_OFFSET (8)
57 #define IGMP_CHECKSUM_OFFSET (2)
59 #define IGMP_DEFAULT_VERSION (3)
61 #define IGMP_GET_INT16(ptr, output) \
63 output = *(ptr) << 8; \
64 output |= *((ptr) + 1); \
76 struct interface
*interface
;
80 struct thread
*t_igmp_read
; /* read: IGMP sockets */
82 *t_igmp_query_timer
; /* timer: issue IGMP general queries */
83 struct thread
*t_other_querier_timer
; /* timer: other querier present */
84 pim_addr querier_addr
; /* IP address of the querier */
85 int querier_query_interval
; /* QQI */
86 int querier_robustness_variable
; /* QRV */
87 int startup_query_count
;
91 struct igmp_stats igmp_stats
;
97 void pim_igmp_if_init(struct pim_interface
*pim_ifp
, struct interface
*ifp
);
98 void pim_igmp_if_reset(struct pim_interface
*pim_ifp
);
99 void pim_igmp_if_fini(struct pim_interface
*pim_ifp
);
101 struct gm_sock
*pim_igmp_sock_lookup_ifaddr(struct list
*igmp_sock_list
,
102 struct in_addr ifaddr
);
103 struct gm_sock
*pim_igmp_sock_add(struct list
*igmp_sock_list
,
104 struct in_addr ifaddr
, struct interface
*ifp
,
106 void igmp_sock_delete(struct gm_sock
*igmp
);
107 void igmp_sock_free(struct gm_sock
*igmp
);
108 void igmp_sock_delete_all(struct interface
*ifp
);
109 int pim_igmp_packet(struct gm_sock
*igmp
, char *buf
, size_t len
);
110 bool pim_igmp_verify_header(struct ip
*ip_hdr
, size_t len
, size_t *ip_hlen
);
111 void pim_igmp_general_query_on(struct gm_sock
*igmp
);
112 void pim_igmp_general_query_off(struct gm_sock
*igmp
);
113 void pim_igmp_other_querier_timer_on(struct gm_sock
*igmp
);
114 void pim_igmp_other_querier_timer_off(struct gm_sock
*igmp
);
116 int igmp_validate_checksum(char *igmp_msg
, int igmp_msg_len
);
118 #else /* PIM_IPV != 4 */
119 static inline void pim_igmp_if_init(struct pim_interface
*pim_ifp
,
120 struct interface
*ifp
)
124 static inline void pim_igmp_if_fini(struct pim_interface
*pim_ifp
)
128 static inline void pim_igmp_general_query_on(struct gm_sock
*igmp
)
132 static inline void pim_igmp_general_query_off(struct gm_sock
*igmp
)
136 static inline void pim_igmp_other_querier_timer_on(struct gm_sock
*igmp
)
140 static inline void pim_igmp_other_querier_timer_off(struct gm_sock
*igmp
)
143 #endif /* PIM_IPV == 4 */
145 #define IGMP_SOURCE_MASK_FORWARDING (1 << 0)
146 #define IGMP_SOURCE_MASK_DELETE (1 << 1)
147 #define IGMP_SOURCE_MASK_SEND (1 << 2)
148 #define IGMP_SOURCE_TEST_FORWARDING(flags) ((flags) & IGMP_SOURCE_MASK_FORWARDING)
149 #define IGMP_SOURCE_TEST_DELETE(flags) ((flags) & IGMP_SOURCE_MASK_DELETE)
150 #define IGMP_SOURCE_TEST_SEND(flags) ((flags) & IGMP_SOURCE_MASK_SEND)
151 #define IGMP_SOURCE_DO_FORWARDING(flags) ((flags) |= IGMP_SOURCE_MASK_FORWARDING)
152 #define IGMP_SOURCE_DO_DELETE(flags) ((flags) |= IGMP_SOURCE_MASK_DELETE)
153 #define IGMP_SOURCE_DO_SEND(flags) ((flags) |= IGMP_SOURCE_MASK_SEND)
154 #define IGMP_SOURCE_DONT_FORWARDING(flags) ((flags) &= ~IGMP_SOURCE_MASK_FORWARDING)
155 #define IGMP_SOURCE_DONT_DELETE(flags) ((flags) &= ~IGMP_SOURCE_MASK_DELETE)
156 #define IGMP_SOURCE_DONT_SEND(flags) ((flags) &= ~IGMP_SOURCE_MASK_SEND)
159 pim_addr source_addr
;
160 struct thread
*t_source_timer
;
161 struct gm_group
*source_group
; /* back pointer */
162 time_t source_creation
;
163 uint32_t source_flags
;
164 struct channel_oil
*source_channel_oil
;
167 RFC 3376: 6.6.3.2. Building and Sending Group and Source Specific
170 int source_query_retransmit_count
;
175 RFC 3376: 6.2.2. Definition of Group Timers
177 The group timer is only used when a group is in EXCLUDE mode and it
178 represents the time for the *filter-mode* of the group to expire and
179 switch to INCLUDE mode.
181 struct thread
*t_group_timer
;
183 /* Shared between group-specific and
184 group-and-source-specific retransmissions */
185 struct thread
*t_group_query_retransmit_timer
;
187 /* Counter exclusive for group-specific retransmissions
188 (not used by group-and-source-specific retransmissions,
189 since sources have their counters) */
190 int group_specific_query_retransmit_count
;
192 /* compatibility mode - igmp v1, v2 or v3 */
195 int group_filtermode_isexcl
; /* 0=INCLUDE, 1=EXCLUDE */
196 struct list
*group_source_list
; /* list of struct gm_source */
197 time_t group_creation
;
198 struct interface
*interface
;
199 int64_t last_igmp_v1_report_dsec
;
200 int64_t last_igmp_v2_report_dsec
;
206 void igmp_anysource_forward_start(struct pim_instance
*pim
,
207 struct gm_group
*group
);
208 void igmp_anysource_forward_stop(struct gm_group
*group
);
210 void igmp_source_forward_start(struct pim_instance
*pim
,
211 struct gm_source
*source
);
212 void igmp_source_forward_stop(struct gm_source
*source
);
213 void igmp_source_forward_reevaluate_all(struct pim_instance
*pim
);
215 struct gm_group
*find_group_by_addr(struct gm_sock
*igmp
,
216 struct in_addr group_addr
);
217 struct gm_group
*igmp_add_group_by_addr(struct gm_sock
*igmp
,
218 struct in_addr group_addr
);
220 struct gm_source
*igmp_get_source_by_addr(struct gm_group
*group
,
221 struct in_addr src_addr
,
224 void igmp_group_delete_empty_include(struct gm_group
*group
);
226 void igmp_startup_mode_on(struct gm_sock
*igmp
);
228 void igmp_group_timer_on(struct gm_group
*group
, long interval_msec
,
231 void igmp_send_query(int igmp_version
, struct gm_group
*group
, char *query_buf
,
232 int query_buf_size
, int num_sources
,
233 struct in_addr dst_addr
, struct in_addr group_addr
,
234 int query_max_response_time_dsec
, uint8_t s_flag
,
235 struct gm_sock
*igmp
);
236 void igmp_group_delete(struct gm_group
*group
);
238 void igmp_send_query_on_intf(struct interface
*ifp
, int igmp_ver
);
240 #else /* PIM_IPV != 4 */
241 static inline void igmp_startup_mode_on(struct gm_sock
*igmp
)
244 #endif /* PIM_IPV != 4 */
246 #endif /* PIM_IGMP_H */