igmp_proto.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @file igmp_proto.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * Definitions for the IGMP protocol.
  25. */
  26. #ifndef BADVPN_MISC_IGMP_PROTO_H
  27. #define BADVPN_MISC_IGMP_PROTO_H
  28. #include <stdint.h>
  29. #define IGMP_TYPE_MEMBERSHIP_QUERY 0x11
  30. #define IGMP_TYPE_V1_MEMBERSHIP_REPORT 0x12
  31. #define IGMP_TYPE_V2_MEMBERSHIP_REPORT 0x16
  32. #define IGMP_TYPE_V3_MEMBERSHIP_REPORT 0x22
  33. #define IGMP_TYPE_V2_LEAVE_GROUP 0x17
  34. #define IGMP_RECORD_TYPE_MODE_IS_INCLUDE 1
  35. #define IGMP_RECORD_TYPE_MODE_IS_EXCLUDE 2
  36. #define IGMP_RECORD_TYPE_CHANGE_TO_INCLUDE_MODE 3
  37. #define IGMP_RECORD_TYPE_CHANGE_TO_EXCLUDE_MODE 4
  38. #define GET_MRC_EXP(_mrc) (((_mrc)&0x70)>>4)
  39. #define GET_MRC_MANT(_mrc) (((_mrc)&0x0F)>>0)
  40. #define GET_MRC_MRT(_mrc) ((_mrc)<128?((uint16_t)(_mrc)):(((uint16_t)(GET_MRC_MANT(_mrc)|0x10))<<(GET_MRC_EXP(_mrc)+3)))
  41. struct igmp_source {
  42. uint32_t addr;
  43. } __attribute__((packed));
  44. struct igmp_base {
  45. uint8_t type;
  46. uint8_t max_resp_code;
  47. uint16_t checksum;
  48. } __attribute__((packed));
  49. struct igmp_v3_query_extra {
  50. uint32_t group;
  51. uint8_t reserved4_suppress1_qrv3;
  52. uint8_t qqic;
  53. uint16_t number_of_sources;
  54. } __attribute__((packed));
  55. struct igmp_v3_report_extra {
  56. uint16_t reserved;
  57. uint16_t number_of_group_records;
  58. } __attribute__((packed));
  59. struct igmp_v3_report_record {
  60. uint8_t type;
  61. uint8_t aux_data_len;
  62. uint16_t number_of_sources;
  63. uint32_t group;
  64. } __attribute__((packed));
  65. struct igmp_v2_extra {
  66. uint32_t group;
  67. } __attribute__((packed));
  68. #endif