2 * MLD protocol definitions
3 * Copyright (C) 2022 David Lamparter for NetDEF, Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
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
20 #ifndef _PIM6_MLD_PROTOCOL_H
21 #define _PIM6_MLD_PROTOCOL_H
26 /* There is a struct icmp6_hdr provided by OS, but it includes 4 bytes of data.
27 * Not helpful for us if we want to put the MLD struct after it.
30 struct icmp6_plain_hdr
{
35 static_assert(sizeof(struct icmp6_plain_hdr
) == 4, "struct mismatch");
36 static_assert(alignof(struct icmp6_plain_hdr
) <= 4, "struct mismatch");
38 /* for MLDv1 query, report and leave all use the same packet format */
40 uint16_t max_resp_code
;
44 static_assert(sizeof(struct mld_v1_pkt
) == 20, "struct mismatch");
45 static_assert(alignof(struct mld_v1_pkt
) <= 4, "struct mismatch");
48 struct mld_v2_query_hdr
{
49 uint16_t max_resp_code
;
55 struct in6_addr srcs
[0];
57 static_assert(sizeof(struct mld_v2_query_hdr
) == 24, "struct mismatch");
58 static_assert(alignof(struct mld_v2_query_hdr
) <= 4, "struct mismatch");
61 struct mld_v2_report_hdr
{
65 static_assert(sizeof(struct mld_v2_report_hdr
) == 4, "struct mismatch");
66 static_assert(alignof(struct mld_v2_report_hdr
) <= 4, "struct mismatch");
69 struct mld_v2_rec_hdr
{
74 struct in6_addr srcs
[0];
76 static_assert(sizeof(struct mld_v2_rec_hdr
) == 20, "struct mismatch");
77 static_assert(alignof(struct mld_v2_rec_hdr
) <= 4, "struct mismatch");
79 /* clang-format off */
81 ICMP6_MLD_QUERY
= 130,
82 ICMP6_MLD_V1_REPORT
= 131,
83 ICMP6_MLD_V1_DONE
= 132,
84 ICMP6_MLD_V2_REPORT
= 143,
87 enum mld_v2_rec_type
{
88 MLD_RECTYPE_IS_INCLUDE
= 1,
89 MLD_RECTYPE_IS_EXCLUDE
= 2,
90 MLD_RECTYPE_CHANGE_TO_INCLUDE
= 3,
91 MLD_RECTYPE_CHANGE_TO_EXCLUDE
= 4,
92 MLD_RECTYPE_ALLOW_NEW_SOURCES
= 5,
93 MLD_RECTYPE_BLOCK_OLD_SOURCES
= 6,
97 /* helper functions */
99 static inline unsigned int mld_max_resp_decode(uint16_t wire
)
101 uint16_t code
= ntohs(wire
);
106 exp
= (code
>> 12) & 0x7;
107 return ((code
& 0xfff) | 0x1000) << (exp
+ 3);
110 static inline uint16_t mld_max_resp_encode(uint32_t value
)
118 exp
= 16 - __builtin_clz(value
);
119 code
= (value
>> (exp
+ 3)) & 0xfff;
120 code
|= 0x8000 | (exp
<< 12);
125 #endif /* _PIM6_MLD_PROTOCOL_H */