pim_tlv.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_TLV_H
  19. #define PIM_TLV_H
  20. #include <zebra.h>
  21. #include "config.h"
  22. #include "if.h"
  23. #include "linklist.h"
  24. #ifdef HAVE_INTTYPES_H
  25. #include <inttypes.h>
  26. #endif /* HAVE_INTTYPES_H */
  27. #define PIM_MSG_OPTION_TYPE_HOLDTIME (1)
  28. #define PIM_MSG_OPTION_TYPE_LAN_PRUNE_DELAY (2)
  29. #define PIM_MSG_OPTION_TYPE_DR_PRIORITY (19)
  30. #define PIM_MSG_OPTION_TYPE_GENERATION_ID (20)
  31. #define PIM_MSG_OPTION_TYPE_DM_STATE_REFRESH (21)
  32. #define PIM_MSG_OPTION_TYPE_ADDRESS_LIST (24)
  33. typedef uint32_t pim_hello_options;
  34. #define PIM_OPTION_MASK_HOLDTIME (1 << 0) /* recv holdtime */
  35. #define PIM_OPTION_MASK_LAN_PRUNE_DELAY (1 << 1) /* recv lan_prune_delay */
  36. #define PIM_OPTION_MASK_DR_PRIORITY (1 << 2) /* recv dr_priority */
  37. #define PIM_OPTION_MASK_GENERATION_ID (1 << 3) /* recv generation_id */
  38. #define PIM_OPTION_MASK_ADDRESS_LIST (1 << 4) /* recv secondary address list */
  39. #define PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION (1 << 5) /* T bit value (valid if recv lan_prune_delay) */
  40. #define PIM_RPT_BIT_MASK (1 << 0)
  41. #define PIM_WILDCARD_BIT_MASK (1 << 1)
  42. #define PIM_OPTION_SET(options, option_mask) ((options) |= (option_mask))
  43. #define PIM_OPTION_UNSET(options, option_mask) ((options) &= ~(option_mask))
  44. #define PIM_OPTION_IS_SET(options, option_mask) ((options) & (option_mask))
  45. #define PIM_TLV_GET_UINT16(buf) ntohs(*(const uint16_t *)(buf))
  46. #define PIM_TLV_GET_UINT32(buf) ntohl(*(const uint32_t *)(buf))
  47. #define PIM_TLV_GET_TYPE(buf) PIM_TLV_GET_UINT16(buf)
  48. #define PIM_TLV_GET_LENGTH(buf) PIM_TLV_GET_UINT16(buf)
  49. #define PIM_TLV_GET_HOLDTIME(buf) PIM_TLV_GET_UINT16(buf)
  50. #define PIM_TLV_GET_PROPAGATION_DELAY(buf) (PIM_TLV_GET_UINT16(buf) & 0x7FFF)
  51. #define PIM_TLV_GET_OVERRIDE_INTERVAL(buf) PIM_TLV_GET_UINT16(buf)
  52. #define PIM_TLV_GET_CAN_DISABLE_JOIN_SUPPRESSION(buf) ((*(const uint8_t *)(buf)) & 0x80)
  53. #define PIM_TLV_GET_DR_PRIORITY(buf) PIM_TLV_GET_UINT32(buf)
  54. #define PIM_TLV_GET_GENERATION_ID(buf) PIM_TLV_GET_UINT32(buf)
  55. #define PIM_TLV_TYPE_SIZE (2)
  56. #define PIM_TLV_LENGTH_SIZE (2)
  57. #define PIM_TLV_MIN_SIZE (PIM_TLV_TYPE_SIZE + PIM_TLV_LENGTH_SIZE)
  58. #define PIM_TLV_OPTION_SIZE(option_len) (PIM_TLV_MIN_SIZE + (option_len))
  59. uint8_t *pim_tlv_append_uint16(uint8_t *buf,
  60. const uint8_t *buf_pastend,
  61. uint16_t option_type,
  62. uint16_t option_value);
  63. uint8_t *pim_tlv_append_2uint16(uint8_t *buf,
  64. const uint8_t *buf_pastend,
  65. uint16_t option_type,
  66. uint16_t option_value1,
  67. uint16_t option_value2);
  68. uint8_t *pim_tlv_append_uint32(uint8_t *buf,
  69. const uint8_t *buf_pastend,
  70. uint16_t option_type,
  71. uint32_t option_value);
  72. uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf,
  73. const uint8_t *buf_pastend,
  74. struct list *ifconnected);
  75. int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr,
  76. pim_hello_options *hello_options,
  77. uint16_t *hello_option_holdtime,
  78. uint16_t option_len,
  79. const uint8_t *tlv_curr);
  80. int pim_tlv_parse_lan_prune_delay(const char *ifname, struct in_addr src_addr,
  81. pim_hello_options *hello_options,
  82. uint16_t *hello_option_propagation_delay,
  83. uint16_t *hello_option_override_interval,
  84. uint16_t option_len,
  85. const uint8_t *tlv_curr);
  86. int pim_tlv_parse_dr_priority(const char *ifname, struct in_addr src_addr,
  87. pim_hello_options *hello_options,
  88. uint32_t *hello_option_dr_priority,
  89. uint16_t option_len,
  90. const uint8_t *tlv_curr);
  91. int pim_tlv_parse_generation_id(const char *ifname, struct in_addr src_addr,
  92. pim_hello_options *hello_options,
  93. uint32_t *hello_option_generation_id,
  94. uint16_t option_len,
  95. const uint8_t *tlv_curr);
  96. int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr,
  97. pim_hello_options *hello_options,
  98. struct list **hello_option_addr_list,
  99. uint16_t option_len,
  100. const uint8_t *tlv_curr);
  101. int pim_parse_addr_ucast(const char *ifname, struct in_addr src_addr,
  102. struct prefix *p,
  103. const uint8_t *buf,
  104. int buf_size);
  105. int pim_parse_addr_group(const char *ifname, struct in_addr src_addr,
  106. struct prefix *p,
  107. const uint8_t *buf,
  108. int buf_size);
  109. int pim_parse_addr_source(const char *ifname,
  110. struct in_addr src_addr,
  111. struct prefix *p,
  112. uint8_t *flags,
  113. const uint8_t *buf,
  114. int buf_size);
  115. #endif /* PIM_TLV_H */