mld.h 2.8 KB

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