Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef LINUX_MLD_H
0003 #define LINUX_MLD_H
0004 
0005 #include <linux/in6.h>
0006 #include <linux/icmpv6.h>
0007 
0008 /* MLDv1 Query/Report/Done */
0009 struct mld_msg {
0010     struct icmp6hdr     mld_hdr;
0011     struct in6_addr     mld_mca;
0012 };
0013 
0014 #define mld_type        mld_hdr.icmp6_type
0015 #define mld_code        mld_hdr.icmp6_code
0016 #define mld_cksum       mld_hdr.icmp6_cksum
0017 #define mld_maxdelay        mld_hdr.icmp6_maxdelay
0018 #define mld_reserved        mld_hdr.icmp6_dataun.un_data16[1]
0019 
0020 /* Multicast Listener Discovery version 2 headers */
0021 /* MLDv2 Report */
0022 struct mld2_grec {
0023     __u8        grec_type;
0024     __u8        grec_auxwords;
0025     __be16      grec_nsrcs;
0026     struct in6_addr grec_mca;
0027     struct in6_addr grec_src[];
0028 };
0029 
0030 struct mld2_report {
0031     struct icmp6hdr     mld2r_hdr;
0032     struct mld2_grec    mld2r_grec[];
0033 };
0034 
0035 #define mld2r_type      mld2r_hdr.icmp6_type
0036 #define mld2r_resv1     mld2r_hdr.icmp6_code
0037 #define mld2r_cksum     mld2r_hdr.icmp6_cksum
0038 #define mld2r_resv2     mld2r_hdr.icmp6_dataun.un_data16[0]
0039 #define mld2r_ngrec     mld2r_hdr.icmp6_dataun.un_data16[1]
0040 
0041 /* MLDv2 Query */
0042 struct mld2_query {
0043     struct icmp6hdr     mld2q_hdr;
0044     struct in6_addr     mld2q_mca;
0045 #if defined(__LITTLE_ENDIAN_BITFIELD)
0046     __u8            mld2q_qrv:3,
0047                 mld2q_suppress:1,
0048                 mld2q_resv2:4;
0049 #elif defined(__BIG_ENDIAN_BITFIELD)
0050     __u8            mld2q_resv2:4,
0051                 mld2q_suppress:1,
0052                 mld2q_qrv:3;
0053 #else
0054 #error "Please fix <asm/byteorder.h>"
0055 #endif
0056     __u8            mld2q_qqic;
0057     __be16          mld2q_nsrcs;
0058     struct in6_addr     mld2q_srcs[];
0059 };
0060 
0061 #define mld2q_type      mld2q_hdr.icmp6_type
0062 #define mld2q_code      mld2q_hdr.icmp6_code
0063 #define mld2q_cksum     mld2q_hdr.icmp6_cksum
0064 #define mld2q_mrc       mld2q_hdr.icmp6_maxdelay
0065 #define mld2q_resv1     mld2q_hdr.icmp6_dataun.un_data16[1]
0066 
0067 /* RFC3810, 5.1.3. Maximum Response Code:
0068  *
0069  * If Maximum Response Code >= 32768, Maximum Response Code represents a
0070  * floating-point value as follows:
0071  *
0072  *  0 1 2 3 4 5 6 7 8 9 A B C D E F
0073  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
0074  * |1| exp |          mant         |
0075  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
0076  */
0077 #define MLDV2_MRC_EXP(value)    (((value) >> 12) & 0x0007)
0078 #define MLDV2_MRC_MAN(value)    ((value) & 0x0fff)
0079 
0080 /* RFC3810, 5.1.9. QQIC (Querier's Query Interval Code):
0081  *
0082  * If QQIC >= 128, QQIC represents a floating-point value as follows:
0083  *
0084  *  0 1 2 3 4 5 6 7
0085  * +-+-+-+-+-+-+-+-+
0086  * |1| exp | mant  |
0087  * +-+-+-+-+-+-+-+-+
0088  */
0089 #define MLDV2_QQIC_EXP(value)   (((value) >> 4) & 0x07)
0090 #define MLDV2_QQIC_MAN(value)   ((value) & 0x0f)
0091 
0092 #define MLD_EXP_MIN_LIMIT   32768UL
0093 #define MLDV1_MRD_MAX_COMPAT    (MLD_EXP_MIN_LIMIT - 1)
0094 
0095 #define MLD_MAX_QUEUE       8
0096 #define MLD_MAX_SKBS        32
0097 
0098 static inline unsigned long mldv2_mrc(const struct mld2_query *mlh2)
0099 {
0100     /* RFC3810, 5.1.3. Maximum Response Code */
0101     unsigned long ret, mc_mrc = ntohs(mlh2->mld2q_mrc);
0102 
0103     if (mc_mrc < MLD_EXP_MIN_LIMIT) {
0104         ret = mc_mrc;
0105     } else {
0106         unsigned long mc_man, mc_exp;
0107 
0108         mc_exp = MLDV2_MRC_EXP(mc_mrc);
0109         mc_man = MLDV2_MRC_MAN(mc_mrc);
0110 
0111         ret = (mc_man | 0x1000) << (mc_exp + 3);
0112     }
0113 
0114     return ret;
0115 }
0116 
0117 #endif