mld.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef LINUX_MLD_H
  3. #define LINUX_MLD_H
  4. #include <linux/in6.h>
  5. #include <linux/icmpv6.h>
  6. /* MLDv1 Query/Report/Done */
  7. struct mld_msg {
  8. struct icmp6hdr mld_hdr;
  9. struct in6_addr mld_mca;
  10. };
  11. #define mld_type mld_hdr.icmp6_type
  12. #define mld_code mld_hdr.icmp6_code
  13. #define mld_cksum mld_hdr.icmp6_cksum
  14. #define mld_maxdelay mld_hdr.icmp6_maxdelay
  15. #define mld_reserved mld_hdr.icmp6_dataun.un_data16[1]
  16. /* Multicast Listener Discovery version 2 headers */
  17. /* MLDv2 Report */
  18. struct mld2_grec {
  19. __u8 grec_type;
  20. __u8 grec_auxwords;
  21. __be16 grec_nsrcs;
  22. struct in6_addr grec_mca;
  23. struct in6_addr grec_src[0];
  24. };
  25. struct mld2_report {
  26. struct icmp6hdr mld2r_hdr;
  27. struct mld2_grec mld2r_grec[0];
  28. };
  29. #define mld2r_type mld2r_hdr.icmp6_type
  30. #define mld2r_resv1 mld2r_hdr.icmp6_code
  31. #define mld2r_cksum mld2r_hdr.icmp6_cksum
  32. #define mld2r_resv2 mld2r_hdr.icmp6_dataun.un_data16[0]
  33. #define mld2r_ngrec mld2r_hdr.icmp6_dataun.un_data16[1]
  34. /* MLDv2 Query */
  35. struct mld2_query {
  36. struct icmp6hdr mld2q_hdr;
  37. struct in6_addr mld2q_mca;
  38. #if defined(__LITTLE_ENDIAN_BITFIELD)
  39. __u8 mld2q_qrv:3,
  40. mld2q_suppress:1,
  41. mld2q_resv2:4;
  42. #elif defined(__BIG_ENDIAN_BITFIELD)
  43. __u8 mld2q_resv2:4,
  44. mld2q_suppress:1,
  45. mld2q_qrv:3;
  46. #else
  47. #error "Please fix <asm/byteorder.h>"
  48. #endif
  49. __u8 mld2q_qqic;
  50. __be16 mld2q_nsrcs;
  51. struct in6_addr mld2q_srcs[0];
  52. };
  53. #define mld2q_type mld2q_hdr.icmp6_type
  54. #define mld2q_code mld2q_hdr.icmp6_code
  55. #define mld2q_cksum mld2q_hdr.icmp6_cksum
  56. #define mld2q_mrc mld2q_hdr.icmp6_maxdelay
  57. #define mld2q_resv1 mld2q_hdr.icmp6_dataun.un_data16[1]
  58. /* RFC3810, 5.1.3. Maximum Response Code:
  59. *
  60. * If Maximum Response Code >= 32768, Maximum Response Code represents a
  61. * floating-point value as follows:
  62. *
  63. * 0 1 2 3 4 5 6 7 8 9 A B C D E F
  64. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  65. * |1| exp | mant |
  66. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  67. */
  68. #define MLDV2_MRC_EXP(value) (((value) >> 12) & 0x0007)
  69. #define MLDV2_MRC_MAN(value) ((value) & 0x0fff)
  70. /* RFC3810, 5.1.9. QQIC (Querier's Query Interval Code):
  71. *
  72. * If QQIC >= 128, QQIC represents a floating-point value as follows:
  73. *
  74. * 0 1 2 3 4 5 6 7
  75. * +-+-+-+-+-+-+-+-+
  76. * |1| exp | mant |
  77. * +-+-+-+-+-+-+-+-+
  78. */
  79. #define MLDV2_QQIC_EXP(value) (((value) >> 4) & 0x07)
  80. #define MLDV2_QQIC_MAN(value) ((value) & 0x0f)
  81. #define MLD_EXP_MIN_LIMIT 32768UL
  82. #define MLDV1_MRD_MAX_COMPAT (MLD_EXP_MIN_LIMIT - 1)
  83. static inline unsigned long mldv2_mrc(const struct mld2_query *mlh2)
  84. {
  85. /* RFC3810, 5.1.3. Maximum Response Code */
  86. unsigned long ret, mc_mrc = ntohs(mlh2->mld2q_mrc);
  87. if (mc_mrc < MLD_EXP_MIN_LIMIT) {
  88. ret = mc_mrc;
  89. } else {
  90. unsigned long mc_man, mc_exp;
  91. mc_exp = MLDV2_MRC_EXP(mc_mrc);
  92. mc_man = MLDV2_MRC_MAN(mc_mrc);
  93. ret = (mc_man | 0x1000) << (mc_exp + 3);
  94. }
  95. return ret;
  96. }
  97. #endif