]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_igmp.h
Merge pull request #10770 from chiragshah6/evpn_dev3
[mirror_frr.git] / pimd / pim_igmp.h
1 /*
2 * PIM for Quagga
3 * Copyright (C) 2008 Everton da Silva Marques
4 *
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.
9 *
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.
14 *
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
18 */
19
20 #ifndef PIM_IGMP_H
21 #define PIM_IGMP_H
22
23 #include <netinet/in.h>
24
25 #include <zebra.h>
26 #include "vty.h"
27 #include "linklist.h"
28 #include "pim_igmp_stats.h"
29 #include "pim_str.h"
30
31 /*
32 The following sizes are likely to support
33 any message sent within local MTU.
34 */
35 #define PIM_IGMP_BUFSIZE_READ (20000)
36 #define PIM_IGMP_BUFSIZE_WRITE (20000)
37
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)
45
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)
51
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)
58
59 /* RFC 3376: 8.1. Robustness Variable - Default: 2 */
60 #define IGMP_DEFAULT_ROBUSTNESS_VARIABLE (2)
61
62 /* RFC 3376: 8.2. Query Interval - Default: 125 seconds */
63 #define IGMP_GENERAL_QUERY_INTERVAL (125)
64
65 /* RFC 3376: 8.3. Query Response Interval - Default: 100 deciseconds */
66 #define IGMP_QUERY_MAX_RESPONSE_TIME_DSEC (100)
67
68 /* RFC 3376: 8.8. Last Member Query Interval - Default: 10 deciseconds */
69 #define IGMP_SPECIFIC_QUERY_MAX_RESPONSE_TIME_DSEC (10)
70
71 #define IGMP_DEFAULT_VERSION (3)
72
73 #define IGMP_GET_INT16(ptr, output) \
74 do { \
75 output = *(ptr) << 8; \
76 output |= *((ptr) + 1); \
77 } while (0)
78
79 struct gm_join {
80 pim_addr group_addr;
81 pim_addr source_addr;
82 int sock_fd;
83 time_t sock_creation;
84 };
85
86 struct gm_sock {
87 int fd;
88 struct interface *interface;
89 pim_addr ifaddr;
90 time_t sock_creation;
91
92 struct thread *t_igmp_read; /* read: IGMP sockets */
93 struct thread
94 *t_igmp_query_timer; /* timer: issue IGMP general queries */
95 struct thread *t_other_querier_timer; /* timer: other querier present */
96 pim_addr querier_addr; /* IP address of the querier */
97 int querier_query_interval; /* QQI */
98 int querier_robustness_variable; /* QRV */
99 int startup_query_count;
100
101 bool mtrace_only;
102
103 struct igmp_stats igmp_stats;
104 };
105
106 struct pim_interface;
107
108 #if PIM_IPV == 4
109 void pim_igmp_if_init(struct pim_interface *pim_ifp, struct interface *ifp);
110 void pim_igmp_if_reset(struct pim_interface *pim_ifp);
111 void pim_igmp_if_fini(struct pim_interface *pim_ifp);
112
113 struct gm_sock *pim_igmp_sock_lookup_ifaddr(struct list *igmp_sock_list,
114 struct in_addr ifaddr);
115 struct gm_sock *pim_igmp_sock_add(struct list *igmp_sock_list,
116 struct in_addr ifaddr, struct interface *ifp,
117 bool mtrace_only);
118 void igmp_sock_delete(struct gm_sock *igmp);
119 void igmp_sock_free(struct gm_sock *igmp);
120 void igmp_sock_delete_all(struct interface *ifp);
121 int pim_igmp_packet(struct gm_sock *igmp, char *buf, size_t len);
122 bool pim_igmp_verify_header(struct ip *ip_hdr, size_t len, size_t *ip_hlen);
123 void pim_igmp_general_query_on(struct gm_sock *igmp);
124 void pim_igmp_general_query_off(struct gm_sock *igmp);
125 void pim_igmp_other_querier_timer_on(struct gm_sock *igmp);
126 void pim_igmp_other_querier_timer_off(struct gm_sock *igmp);
127
128 int igmp_validate_checksum(char *igmp_msg, int igmp_msg_len);
129
130 #else /* PIM_IPV != 4 */
131 static inline void pim_igmp_if_init(struct pim_interface *pim_ifp,
132 struct interface *ifp)
133 {
134 }
135
136 static inline void pim_igmp_if_fini(struct pim_interface *pim_ifp)
137 {
138 }
139
140 static inline void pim_igmp_general_query_on(struct gm_sock *igmp)
141 {
142 }
143
144 static inline void pim_igmp_general_query_off(struct gm_sock *igmp)
145 {
146 }
147
148 static inline void pim_igmp_other_querier_timer_on(struct gm_sock *igmp)
149 {
150 }
151
152 static inline void pim_igmp_other_querier_timer_off(struct gm_sock *igmp)
153 {
154 }
155 #endif /* PIM_IPV == 4 */
156
157 #define IGMP_SOURCE_MASK_FORWARDING (1 << 0)
158 #define IGMP_SOURCE_MASK_DELETE (1 << 1)
159 #define IGMP_SOURCE_MASK_SEND (1 << 2)
160 #define IGMP_SOURCE_TEST_FORWARDING(flags) ((flags) & IGMP_SOURCE_MASK_FORWARDING)
161 #define IGMP_SOURCE_TEST_DELETE(flags) ((flags) & IGMP_SOURCE_MASK_DELETE)
162 #define IGMP_SOURCE_TEST_SEND(flags) ((flags) & IGMP_SOURCE_MASK_SEND)
163 #define IGMP_SOURCE_DO_FORWARDING(flags) ((flags) |= IGMP_SOURCE_MASK_FORWARDING)
164 #define IGMP_SOURCE_DO_DELETE(flags) ((flags) |= IGMP_SOURCE_MASK_DELETE)
165 #define IGMP_SOURCE_DO_SEND(flags) ((flags) |= IGMP_SOURCE_MASK_SEND)
166 #define IGMP_SOURCE_DONT_FORWARDING(flags) ((flags) &= ~IGMP_SOURCE_MASK_FORWARDING)
167 #define IGMP_SOURCE_DONT_DELETE(flags) ((flags) &= ~IGMP_SOURCE_MASK_DELETE)
168 #define IGMP_SOURCE_DONT_SEND(flags) ((flags) &= ~IGMP_SOURCE_MASK_SEND)
169
170 struct gm_source {
171 pim_addr source_addr;
172 struct thread *t_source_timer;
173 struct gm_group *source_group; /* back pointer */
174 time_t source_creation;
175 uint32_t source_flags;
176 struct channel_oil *source_channel_oil;
177
178 /*
179 RFC 3376: 6.6.3.2. Building and Sending Group and Source Specific
180 Queries
181 */
182 int source_query_retransmit_count;
183 };
184
185 struct gm_group {
186 /*
187 RFC 3376: 6.2.2. Definition of Group Timers
188
189 The group timer is only used when a group is in EXCLUDE mode and it
190 represents the time for the *filter-mode* of the group to expire and
191 switch to INCLUDE mode.
192 */
193 struct thread *t_group_timer;
194
195 /* Shared between group-specific and
196 group-and-source-specific retransmissions */
197 struct thread *t_group_query_retransmit_timer;
198
199 /* Counter exclusive for group-specific retransmissions
200 (not used by group-and-source-specific retransmissions,
201 since sources have their counters) */
202 int group_specific_query_retransmit_count;
203
204 /* compatibility mode - igmp v1, v2 or v3 */
205 int igmp_version;
206 pim_addr group_addr;
207 int group_filtermode_isexcl; /* 0=INCLUDE, 1=EXCLUDE */
208 struct list *group_source_list; /* list of struct gm_source */
209 time_t group_creation;
210 struct interface *interface;
211 int64_t last_igmp_v1_report_dsec;
212 int64_t last_igmp_v2_report_dsec;
213 };
214
215 #if PIM_IPV == 4
216 struct pim_instance;
217
218 void igmp_anysource_forward_start(struct pim_instance *pim,
219 struct gm_group *group);
220 void igmp_anysource_forward_stop(struct gm_group *group);
221
222 void igmp_source_forward_start(struct pim_instance *pim,
223 struct gm_source *source);
224 void igmp_source_forward_stop(struct gm_source *source);
225 void igmp_source_forward_reevaluate_all(struct pim_instance *pim);
226
227 struct gm_group *find_group_by_addr(struct gm_sock *igmp,
228 struct in_addr group_addr);
229 struct gm_group *igmp_add_group_by_addr(struct gm_sock *igmp,
230 struct in_addr group_addr);
231
232 struct gm_source *igmp_get_source_by_addr(struct gm_group *group,
233 struct in_addr src_addr,
234 bool *created);
235
236 void igmp_group_delete_empty_include(struct gm_group *group);
237
238 void igmp_startup_mode_on(struct gm_sock *igmp);
239
240 void igmp_group_timer_on(struct gm_group *group, long interval_msec,
241 const char *ifname);
242
243 void igmp_send_query(int igmp_version, struct gm_group *group, char *query_buf,
244 int query_buf_size, int num_sources,
245 struct in_addr dst_addr, struct in_addr group_addr,
246 int query_max_response_time_dsec, uint8_t s_flag,
247 struct gm_sock *igmp);
248 void igmp_group_delete(struct gm_group *group);
249
250 void igmp_send_query_on_intf(struct interface *ifp, int igmp_ver);
251
252 #else /* PIM_IPV != 4 */
253 static inline void igmp_startup_mode_on(struct gm_sock *igmp)
254 {
255 }
256 #endif /* PIM_IPV != 4 */
257
258 #endif /* PIM_IGMP_H */