blob: cd4a40d77ff8a2cb99c3404a309fb0ce897704a3 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/*
16 * igmp_packet.h: igmp packet format
17 *
18 * Copyright (c) 2011 Eliot Dresselhaus
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39
40#ifndef included_vnet_igmp_packet_h
41#define included_vnet_igmp_packet_h
42
43#include <vnet/ip/ip4_packet.h>
44#include <vnet/ip/ip6_packet.h>
45
46#define foreach_igmp_type \
47 _ (0x11, membership_query) \
48 _ (0x12, membership_report_v1) \
49 _ (0x13, dvmrp) \
50 _ (0x14, pim_v1) \
51 _ (0x15, cisco_trace) \
52 _ (0x16, membership_report_v2) \
53 _ (0x17, leave_group_v2) \
54 _ (0x1e, traceroute_response) \
55 _ (0x1f, traceroute_request) \
56 _ (0x22, membership_report_v3) \
57 _ (0x30, router_advertisement) \
58 _ (0x31, router_solicitation) \
59 _ (0x32, router_termination)
60
Dave Barachd7cb1b52016-12-09 09:52:16 -050061typedef enum
62{
Ed Warnickecb9cada2015-12-08 15:45:58 -070063#define _(n,f) IGMP_TYPE_##f = n,
64 foreach_igmp_type
65#undef _
Neale Ranns947ea622018-06-07 23:48:20 -070066} __attribute__ ((packed)) igmp_type_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070067
Dave Barachd7cb1b52016-12-09 09:52:16 -050068typedef struct
69{
Neale Ranns947ea622018-06-07 23:48:20 -070070 igmp_type_t type;
Ed Warnickecb9cada2015-12-08 15:45:58 -070071
72 u8 code;
73
74 u16 checksum;
75} igmp_header_t;
76
Neale Ranns947ea622018-06-07 23:48:20 -070077/**
78 * Calculate the maximum response time allowed from the header.
79 * - RFC 3367 Section 4.1.1
80 */
81always_inline f64
82igmp_header_get_max_resp_time (const igmp_header_t * header)
Dave Barachd7cb1b52016-12-09 09:52:16 -050083{
Neale Ranns947ea622018-06-07 23:48:20 -070084 f64 qqi;
Ed Warnickecb9cada2015-12-08 15:45:58 -070085
Neale Ranns947ea622018-06-07 23:48:20 -070086 if (header->code < 128)
87 qqi = header->code;
88 else
89 {
90 u8 mant = header->code << 4;
91 u8 exp = (header->code & 0x7) << 1;
92
93 qqi = ((mant | 0x10) << (exp + 3));
94 }
95
96 /* Querier's Query Interval (QQI), is represented in units of seconds */
97 return (qqi / 10);
98}
Ed Warnickecb9cada2015-12-08 15:45:58 -070099
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100100typedef struct
101{
102 /* type 0x11 (IGMPv3) */
103 igmp_header_t header;
104
Neale Ranns947ea622018-06-07 23:48:20 -0700105 ip4_address_t group_address;
Jakub Grajciar7b867a82017-12-08 16:28:42 +0100106
107 /* Reserved, Suppress Router-Side Processing flag and
108 Querier's Robustness Variable RRRRSQQQ. */
109 u8 resv_s_qrv;
110
111 /* Querier's Query Interval Code */
112 u8 qqi_code;
113
114 u16 n_src_addresses;
115 ip4_address_t src_addresses[0];
116} igmp_membership_query_v3_t;
117
Neale Ranns947ea622018-06-07 23:48:20 -0700118always_inline u32
119igmp_membership_query_v3_length (const igmp_membership_query_v3_t * q)
120{
121 return (sizeof (*q) +
122 (sizeof (ip4_address_t) *
123 clib_net_to_host_u16 (q->n_src_addresses)));
124}
125
126always_inline int
127igmp_membership_query_v3_is_geeral (const igmp_membership_query_v3_t * q)
128{
129 return (0 == q->group_address.as_u32);
130}
131
Ed Warnickecb9cada2015-12-08 15:45:58 -0700132#define foreach_igmp_membership_group_v3_type \
Neale Ranns947ea622018-06-07 23:48:20 -0700133 _ (1, mode_is_include) \
134 _ (2, mode_is_exclude) \
135 _ (3, change_to_include) \
136 _ (4, change_to_exclude) \
Ed Warnickecb9cada2015-12-08 15:45:58 -0700137 _ (5, allow_new_sources) \
138 _ (6, block_old_sources)
139
Dave Barachd7cb1b52016-12-09 09:52:16 -0500140typedef enum
141{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700142#define _(n,f) IGMP_MEMBERSHIP_GROUP_##f = n,
143 foreach_igmp_membership_group_v3_type
144#undef _
Neale Ranns947ea622018-06-07 23:48:20 -0700145} __attribute__ ((packed)) igmp_membership_group_v3_type_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146
Dave Barachd7cb1b52016-12-09 09:52:16 -0500147typedef struct
148{
Neale Ranns947ea622018-06-07 23:48:20 -0700149 igmp_membership_group_v3_type_t type;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150
151 /* Number of 32 bit words of aux data after source addresses. */
152 u8 n_aux_u32s;
153
154 /* Number of source addresses that follow. */
155 u16 n_src_addresses;
156
Neale Ranns947ea622018-06-07 23:48:20 -0700157 /* Destination multicast group address. */
158 ip4_address_t group_address;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700159
160 ip4_address_t src_addresses[0];
161} igmp_membership_group_v3_t;
162
Neale Ranns947ea622018-06-07 23:48:20 -0700163always_inline u32
164igmp_membership_group_v3_length (const igmp_membership_group_v3_t * g)
165{
166 return (sizeof (*g) +
167 (sizeof (ip4_address_t) *
168 clib_net_to_host_u16 (g->n_src_addresses)));
169}
170
Ed Warnickecb9cada2015-12-08 15:45:58 -0700171always_inline igmp_membership_group_v3_t *
172igmp_membership_group_v3_next (igmp_membership_group_v3_t * g)
173{
174 return ((void *) g
175 + g->n_src_addresses * sizeof (g->src_addresses[0])
176 + g->n_aux_u32s * sizeof (u32));
177}
178
Dave Barachd7cb1b52016-12-09 09:52:16 -0500179typedef struct
180{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700181 /* Type 0x22. */
182 igmp_header_t header;
183
184 u16 unused;
185
186 /* Number of groups which follow. */
187 u16 n_groups;
188
189 igmp_membership_group_v3_t groups[0];
190} igmp_membership_report_v3_t;
191
Neale Ranns947ea622018-06-07 23:48:20 -0700192always_inline u32
193igmp_membership_report_v3_length (const igmp_membership_report_v3_t * r)
194{
195 const igmp_membership_group_v3_t *g;
196 u32 len, ii, glen;
197
198 len = sizeof (igmp_membership_report_v3_t);
199 g = r->groups;
200
201 for (ii = 0; ii < clib_net_to_host_u16 (r->n_groups); ii++)
202 {
203 glen = igmp_membership_group_v3_length (g);
204 g = (const igmp_membership_group_v3_t *) (((u8 *) g) + glen);
205 len += glen;
206 }
207 return (len);
208}
209
Ed Warnickecb9cada2015-12-08 15:45:58 -0700210/* IP6 flavor of IGMP is called MLD which is embedded in ICMP6. */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500211typedef struct
212{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700213 /* Preceeded by ICMP v6 header. */
214 u16 max_response_delay_in_milliseconds;
215 u16 reserved;
216 ip6_address_t dst;
217} mld_header_t;
218
219#endif /* included_vnet_igmp_packet_h */
Dave Barachd7cb1b52016-12-09 09:52:16 -0500220
221/*
222 * fd.io coding-style-patch-verification: ON
223 *
224 * Local Variables:
225 * eval: (c-set-style "gnu")
226 * End:
227 */