1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
26e7cb837SYOSHIFUJI Hideaki #ifndef LINUX_MLD_H
36e7cb837SYOSHIFUJI Hideaki #define LINUX_MLD_H
46e7cb837SYOSHIFUJI Hideaki
56e7cb837SYOSHIFUJI Hideaki #include <linux/in6.h>
66e7cb837SYOSHIFUJI Hideaki #include <linux/icmpv6.h>
76e7cb837SYOSHIFUJI Hideaki
86e7cb837SYOSHIFUJI Hideaki /* MLDv1 Query/Report/Done */
96e7cb837SYOSHIFUJI Hideaki struct mld_msg {
106e7cb837SYOSHIFUJI Hideaki struct icmp6hdr mld_hdr;
116e7cb837SYOSHIFUJI Hideaki struct in6_addr mld_mca;
126e7cb837SYOSHIFUJI Hideaki };
136e7cb837SYOSHIFUJI Hideaki
146e7cb837SYOSHIFUJI Hideaki #define mld_type mld_hdr.icmp6_type
156e7cb837SYOSHIFUJI Hideaki #define mld_code mld_hdr.icmp6_code
166e7cb837SYOSHIFUJI Hideaki #define mld_cksum mld_hdr.icmp6_cksum
176e7cb837SYOSHIFUJI Hideaki #define mld_maxdelay mld_hdr.icmp6_maxdelay
186e7cb837SYOSHIFUJI Hideaki #define mld_reserved mld_hdr.icmp6_dataun.un_data16[1]
196e7cb837SYOSHIFUJI Hideaki
206e7cb837SYOSHIFUJI Hideaki /* Multicast Listener Discovery version 2 headers */
216e7cb837SYOSHIFUJI Hideaki /* MLDv2 Report */
226e7cb837SYOSHIFUJI Hideaki struct mld2_grec {
236e7cb837SYOSHIFUJI Hideaki __u8 grec_type;
246e7cb837SYOSHIFUJI Hideaki __u8 grec_auxwords;
256e7cb837SYOSHIFUJI Hideaki __be16 grec_nsrcs;
266e7cb837SYOSHIFUJI Hideaki struct in6_addr grec_mca;
27c61a2a76SGustavo A. R. Silva struct in6_addr grec_src[];
286e7cb837SYOSHIFUJI Hideaki };
296e7cb837SYOSHIFUJI Hideaki
306e7cb837SYOSHIFUJI Hideaki struct mld2_report {
316e7cb837SYOSHIFUJI Hideaki struct icmp6hdr mld2r_hdr;
32c61a2a76SGustavo A. R. Silva struct mld2_grec mld2r_grec[];
336e7cb837SYOSHIFUJI Hideaki };
346e7cb837SYOSHIFUJI Hideaki
356e7cb837SYOSHIFUJI Hideaki #define mld2r_type mld2r_hdr.icmp6_type
366e7cb837SYOSHIFUJI Hideaki #define mld2r_resv1 mld2r_hdr.icmp6_code
376e7cb837SYOSHIFUJI Hideaki #define mld2r_cksum mld2r_hdr.icmp6_cksum
386e7cb837SYOSHIFUJI Hideaki #define mld2r_resv2 mld2r_hdr.icmp6_dataun.un_data16[0]
396e7cb837SYOSHIFUJI Hideaki #define mld2r_ngrec mld2r_hdr.icmp6_dataun.un_data16[1]
406e7cb837SYOSHIFUJI Hideaki
416e7cb837SYOSHIFUJI Hideaki /* MLDv2 Query */
426e7cb837SYOSHIFUJI Hideaki struct mld2_query {
436e7cb837SYOSHIFUJI Hideaki struct icmp6hdr mld2q_hdr;
446e7cb837SYOSHIFUJI Hideaki struct in6_addr mld2q_mca;
456e7cb837SYOSHIFUJI Hideaki #if defined(__LITTLE_ENDIAN_BITFIELD)
466e7cb837SYOSHIFUJI Hideaki __u8 mld2q_qrv:3,
476e7cb837SYOSHIFUJI Hideaki mld2q_suppress:1,
486e7cb837SYOSHIFUJI Hideaki mld2q_resv2:4;
496e7cb837SYOSHIFUJI Hideaki #elif defined(__BIG_ENDIAN_BITFIELD)
506e7cb837SYOSHIFUJI Hideaki __u8 mld2q_resv2:4,
516e7cb837SYOSHIFUJI Hideaki mld2q_suppress:1,
526e7cb837SYOSHIFUJI Hideaki mld2q_qrv:3;
536e7cb837SYOSHIFUJI Hideaki #else
546e7cb837SYOSHIFUJI Hideaki #error "Please fix <asm/byteorder.h>"
556e7cb837SYOSHIFUJI Hideaki #endif
566e7cb837SYOSHIFUJI Hideaki __u8 mld2q_qqic;
576e7cb837SYOSHIFUJI Hideaki __be16 mld2q_nsrcs;
58c61a2a76SGustavo A. R. Silva struct in6_addr mld2q_srcs[];
596e7cb837SYOSHIFUJI Hideaki };
606e7cb837SYOSHIFUJI Hideaki
616e7cb837SYOSHIFUJI Hideaki #define mld2q_type mld2q_hdr.icmp6_type
626e7cb837SYOSHIFUJI Hideaki #define mld2q_code mld2q_hdr.icmp6_code
636e7cb837SYOSHIFUJI Hideaki #define mld2q_cksum mld2q_hdr.icmp6_cksum
646e7cb837SYOSHIFUJI Hideaki #define mld2q_mrc mld2q_hdr.icmp6_maxdelay
656e7cb837SYOSHIFUJI Hideaki #define mld2q_resv1 mld2q_hdr.icmp6_dataun.un_data16[1]
666e7cb837SYOSHIFUJI Hideaki
6789225d1cSDaniel Borkmann /* RFC3810, 5.1.3. Maximum Response Code:
6889225d1cSDaniel Borkmann *
6989225d1cSDaniel Borkmann * If Maximum Response Code >= 32768, Maximum Response Code represents a
7089225d1cSDaniel Borkmann * floating-point value as follows:
7189225d1cSDaniel Borkmann *
7289225d1cSDaniel Borkmann * 0 1 2 3 4 5 6 7 8 9 A B C D E F
7389225d1cSDaniel Borkmann * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
7489225d1cSDaniel Borkmann * |1| exp | mant |
7589225d1cSDaniel Borkmann * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
7689225d1cSDaniel Borkmann */
7789225d1cSDaniel Borkmann #define MLDV2_MRC_EXP(value) (((value) >> 12) & 0x0007)
7889225d1cSDaniel Borkmann #define MLDV2_MRC_MAN(value) ((value) & 0x0fff)
7989225d1cSDaniel Borkmann
8089225d1cSDaniel Borkmann /* RFC3810, 5.1.9. QQIC (Querier's Query Interval Code):
8189225d1cSDaniel Borkmann *
8289225d1cSDaniel Borkmann * If QQIC >= 128, QQIC represents a floating-point value as follows:
8389225d1cSDaniel Borkmann *
8489225d1cSDaniel Borkmann * 0 1 2 3 4 5 6 7
8589225d1cSDaniel Borkmann * +-+-+-+-+-+-+-+-+
8689225d1cSDaniel Borkmann * |1| exp | mant |
8789225d1cSDaniel Borkmann * +-+-+-+-+-+-+-+-+
8889225d1cSDaniel Borkmann */
8989225d1cSDaniel Borkmann #define MLDV2_QQIC_EXP(value) (((value) >> 4) & 0x07)
9089225d1cSDaniel Borkmann #define MLDV2_QQIC_MAN(value) ((value) & 0x0f)
9189225d1cSDaniel Borkmann
9235f7aa53SDaniel Borkmann #define MLD_EXP_MIN_LIMIT 32768UL
9335f7aa53SDaniel Borkmann #define MLDV1_MRD_MAX_COMPAT (MLD_EXP_MIN_LIMIT - 1)
9435f7aa53SDaniel Borkmann
95*f185de28STaehee Yoo #define MLD_MAX_QUEUE 8
96*f185de28STaehee Yoo #define MLD_MAX_SKBS 32
97*f185de28STaehee Yoo
mldv2_mrc(const struct mld2_query * mlh2)98e3f5b170SDaniel Borkmann static inline unsigned long mldv2_mrc(const struct mld2_query *mlh2)
99e3f5b170SDaniel Borkmann {
100e3f5b170SDaniel Borkmann /* RFC3810, 5.1.3. Maximum Response Code */
101e3f5b170SDaniel Borkmann unsigned long ret, mc_mrc = ntohs(mlh2->mld2q_mrc);
102e3f5b170SDaniel Borkmann
10335f7aa53SDaniel Borkmann if (mc_mrc < MLD_EXP_MIN_LIMIT) {
104e3f5b170SDaniel Borkmann ret = mc_mrc;
105e3f5b170SDaniel Borkmann } else {
106e3f5b170SDaniel Borkmann unsigned long mc_man, mc_exp;
107e3f5b170SDaniel Borkmann
108e3f5b170SDaniel Borkmann mc_exp = MLDV2_MRC_EXP(mc_mrc);
109e3f5b170SDaniel Borkmann mc_man = MLDV2_MRC_MAN(mc_mrc);
110e3f5b170SDaniel Borkmann
111e3f5b170SDaniel Borkmann ret = (mc_man | 0x1000) << (mc_exp + 3);
112e3f5b170SDaniel Borkmann }
113e3f5b170SDaniel Borkmann
114e3f5b170SDaniel Borkmann return ret;
115e3f5b170SDaniel Borkmann }
116e3f5b170SDaniel Borkmann
1176e7cb837SYOSHIFUJI Hideaki #endif
118