pim_igmp.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. PIM for Quagga
  3. Copyright (C) 2008 Everton da Silva Marques
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING; if not, write to the
  14. Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  15. MA 02110-1301 USA
  16. $QuaggaId: $Format:%an, %ai, %h$ $
  17. */
  18. #ifndef PIM_IGMP_H
  19. #define PIM_IGMP_H
  20. #include <netinet/in.h>
  21. #include <zebra.h>
  22. #include "vty.h"
  23. #include "linklist.h"
  24. /*
  25. The following sizes are likely to support
  26. any message sent within local MTU.
  27. */
  28. #define PIM_IGMP_BUFSIZE_READ (20000)
  29. #define PIM_IGMP_BUFSIZE_WRITE (20000)
  30. #define PIM_IGMP_MEMBERSHIP_QUERY (0x11)
  31. #define PIM_IGMP_V1_MEMBERSHIP_REPORT (0x12)
  32. #define PIM_IGMP_V2_MEMBERSHIP_REPORT (0x16)
  33. #define PIM_IGMP_V2_LEAVE_GROUP (0x17)
  34. #define PIM_IGMP_V3_MEMBERSHIP_REPORT (0x22)
  35. #define IGMP_V3_REPORT_HEADER_SIZE (8)
  36. #define IGMP_V3_GROUP_RECORD_MIN_SIZE (8)
  37. #define IGMP_V3_MSG_MIN_SIZE (IGMP_V3_REPORT_HEADER_SIZE + \
  38. IGMP_V3_GROUP_RECORD_MIN_SIZE)
  39. #define IGMP_V12_MSG_SIZE (8)
  40. #define IGMP_V3_GROUP_RECORD_TYPE_OFFSET (0)
  41. #define IGMP_V3_GROUP_RECORD_AUXDATALEN_OFFSET (1)
  42. #define IGMP_V3_GROUP_RECORD_NUMSOURCES_OFFSET (2)
  43. #define IGMP_V3_GROUP_RECORD_GROUP_OFFSET (4)
  44. #define IGMP_V3_GROUP_RECORD_SOURCE_OFFSET (8)
  45. /* RFC 3376: 8.1. Robustness Variable - Default: 2 */
  46. #define IGMP_DEFAULT_ROBUSTNESS_VARIABLE (2)
  47. /* RFC 3376: 8.2. Query Interval - Default: 125 seconds */
  48. #define IGMP_GENERAL_QUERY_INTERVAL (125)
  49. /* RFC 3376: 8.3. Query Response Interval - Default: 100 deciseconds */
  50. #define IGMP_QUERY_MAX_RESPONSE_TIME_DSEC (100)
  51. /* RFC 3376: 8.8. Last Member Query Interval - Default: 10 deciseconds */
  52. #define IGMP_SPECIFIC_QUERY_MAX_RESPONSE_TIME_DSEC (10)
  53. struct igmp_join {
  54. struct in_addr group_addr;
  55. struct in_addr source_addr;
  56. int sock_fd;
  57. time_t sock_creation;
  58. };
  59. struct igmp_sock {
  60. int fd;
  61. struct interface *interface;
  62. struct in_addr ifaddr;
  63. time_t sock_creation;
  64. struct thread *t_igmp_read; /* read: IGMP sockets */
  65. struct thread *t_igmp_query_timer; /* timer: issue IGMP general queries */
  66. struct thread *t_other_querier_timer; /* timer: other querier present */
  67. int querier_query_interval; /* QQI */
  68. int querier_robustness_variable; /* QRV */
  69. int startup_query_count;
  70. struct list *igmp_group_list; /* list of struct igmp_group */
  71. };
  72. struct igmp_sock *pim_igmp_sock_lookup_ifaddr(struct list *igmp_sock_list,
  73. struct in_addr ifaddr);
  74. struct igmp_sock *igmp_sock_lookup_by_fd(struct list *igmp_sock_list,
  75. int fd);
  76. struct igmp_sock *pim_igmp_sock_add(struct list *igmp_sock_list,
  77. struct in_addr ifaddr,
  78. struct interface *ifp);
  79. void igmp_sock_delete(struct igmp_sock *igmp);
  80. void igmp_sock_free(struct igmp_sock *igmp);
  81. int pim_igmp_packet(struct igmp_sock *igmp, char *buf, size_t len);
  82. void pim_igmp_general_query_on(struct igmp_sock *igmp);
  83. void pim_igmp_general_query_off(struct igmp_sock *igmp);
  84. void pim_igmp_other_querier_timer_on(struct igmp_sock *igmp);
  85. void pim_igmp_other_querier_timer_off(struct igmp_sock *igmp);
  86. #define IGMP_SOURCE_MASK_FORWARDING (1 << 0)
  87. #define IGMP_SOURCE_MASK_DELETE (1 << 1)
  88. #define IGMP_SOURCE_MASK_SEND (1 << 2)
  89. #define IGMP_SOURCE_TEST_FORWARDING(flags) ((flags) & IGMP_SOURCE_MASK_FORWARDING)
  90. #define IGMP_SOURCE_TEST_DELETE(flags) ((flags) & IGMP_SOURCE_MASK_DELETE)
  91. #define IGMP_SOURCE_TEST_SEND(flags) ((flags) & IGMP_SOURCE_MASK_SEND)
  92. #define IGMP_SOURCE_DO_FORWARDING(flags) ((flags) |= IGMP_SOURCE_MASK_FORWARDING)
  93. #define IGMP_SOURCE_DO_DELETE(flags) ((flags) |= IGMP_SOURCE_MASK_DELETE)
  94. #define IGMP_SOURCE_DO_SEND(flags) ((flags) |= IGMP_SOURCE_MASK_SEND)
  95. #define IGMP_SOURCE_DONT_FORWARDING(flags) ((flags) &= ~IGMP_SOURCE_MASK_FORWARDING)
  96. #define IGMP_SOURCE_DONT_DELETE(flags) ((flags) &= ~IGMP_SOURCE_MASK_DELETE)
  97. #define IGMP_SOURCE_DONT_SEND(flags) ((flags) &= ~IGMP_SOURCE_MASK_SEND)
  98. struct igmp_source {
  99. struct in_addr source_addr;
  100. struct thread *t_source_timer;
  101. struct igmp_group *source_group; /* back pointer */
  102. time_t source_creation;
  103. uint32_t source_flags;
  104. struct channel_oil *source_channel_oil;
  105. /*
  106. RFC 3376: 6.6.3.2. Building and Sending Group and Source Specific Queries
  107. */
  108. int source_query_retransmit_count;
  109. };
  110. struct igmp_group {
  111. /*
  112. RFC 3376: 6.2.2. Definition of Group Timers
  113. The group timer is only used when a group is in EXCLUDE mode and it
  114. represents the time for the *filter-mode* of the group to expire and
  115. switch to INCLUDE mode.
  116. */
  117. struct thread *t_group_timer;
  118. /* Shared between group-specific and
  119. group-and-source-specific retransmissions */
  120. struct thread *t_group_query_retransmit_timer;
  121. /* Counter exclusive for group-specific retransmissions
  122. (not used by group-and-source-specific retransmissions,
  123. since sources have their counters) */
  124. int group_specific_query_retransmit_count;
  125. struct in_addr group_addr;
  126. int group_filtermode_isexcl; /* 0=INCLUDE, 1=EXCLUDE */
  127. struct list *group_source_list; /* list of struct igmp_source */
  128. time_t group_creation;
  129. struct igmp_sock *group_igmp_sock; /* back pointer */
  130. int64_t last_igmp_v1_report_dsec;
  131. int64_t last_igmp_v2_report_dsec;
  132. };
  133. struct igmp_group *igmp_add_group_by_addr(struct igmp_sock *igmp,
  134. struct in_addr group_addr);
  135. void igmp_group_delete_empty_include(struct igmp_group *group);
  136. void igmp_startup_mode_on(struct igmp_sock *igmp);
  137. void igmp_group_timer_on(struct igmp_group *group,
  138. long interval_msec, const char *ifname);
  139. struct igmp_source *
  140. source_new (struct igmp_group *group,
  141. struct in_addr src_addr);
  142. #endif /* PIM_IGMP_H */