]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_tlv.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / pimd / pim_tlv.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * PIM for Quagga
4 * Copyright (C) 2008 Everton da Silva Marques
5 */
6
7 #ifndef PIM_TLV_H
8 #define PIM_TLV_H
9
10 #include <zebra.h>
11
12 #include "config.h"
13 #include "if.h"
14 #include "linklist.h"
15
16 #define PIM_MSG_OPTION_TYPE_HOLDTIME (1)
17 #define PIM_MSG_OPTION_TYPE_LAN_PRUNE_DELAY (2)
18 #define PIM_MSG_OPTION_TYPE_DR_PRIORITY (19)
19 #define PIM_MSG_OPTION_TYPE_GENERATION_ID (20)
20 #define PIM_MSG_OPTION_TYPE_DM_STATE_REFRESH (21)
21 #define PIM_MSG_OPTION_TYPE_ADDRESS_LIST (24)
22
23 typedef uint32_t pim_hello_options;
24 #define PIM_OPTION_MASK_HOLDTIME (1 << 0) /* recv holdtime */
25 #define PIM_OPTION_MASK_LAN_PRUNE_DELAY (1 << 1) /* recv lan_prune_delay */
26 #define PIM_OPTION_MASK_DR_PRIORITY (1 << 2) /* recv dr_priority */
27 #define PIM_OPTION_MASK_GENERATION_ID (1 << 3) /* recv generation_id */
28 #define PIM_OPTION_MASK_ADDRESS_LIST (1 << 4) /* recv secondary address list */
29 #define PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION (1 << 5) /* T bit value (valid if recv lan_prune_delay) */
30
31 #define PIM_RPT_BIT_MASK (1 << 0)
32 #define PIM_WILDCARD_BIT_MASK (1 << 1)
33
34 #define PIM_OPTION_SET(options, option_mask) ((options) |= (option_mask))
35 #define PIM_OPTION_UNSET(options, option_mask) ((options) &= ~(option_mask))
36 #define PIM_OPTION_IS_SET(options, option_mask) ((options) & (option_mask))
37
38 #define PIM_TLV_GET_UINT16(buf) \
39 ({ \
40 uint16_t _tmp; \
41 memcpy(&_tmp, (buf), sizeof(uint16_t)); \
42 ntohs(_tmp); \
43 })
44 #define PIM_TLV_GET_UINT32(buf) \
45 ({ \
46 uint32_t _tmp; \
47 memcpy(&_tmp, (buf), sizeof(uint32_t)); \
48 ntohl(_tmp); \
49 })
50 #define PIM_TLV_GET_TYPE(buf) PIM_TLV_GET_UINT16(buf)
51 #define PIM_TLV_GET_LENGTH(buf) PIM_TLV_GET_UINT16(buf)
52 #define PIM_TLV_GET_HOLDTIME(buf) PIM_TLV_GET_UINT16(buf)
53 #define PIM_TLV_GET_PROPAGATION_DELAY(buf) (PIM_TLV_GET_UINT16(buf) & 0x7FFF)
54 #define PIM_TLV_GET_OVERRIDE_INTERVAL(buf) PIM_TLV_GET_UINT16(buf)
55 #define PIM_TLV_GET_CAN_DISABLE_JOIN_SUPPRESSION(buf) ((*(const uint8_t *)(buf)) & 0x80)
56 #define PIM_TLV_GET_DR_PRIORITY(buf) PIM_TLV_GET_UINT32(buf)
57 #define PIM_TLV_GET_GENERATION_ID(buf) PIM_TLV_GET_UINT32(buf)
58
59 #define PIM_TLV_TYPE_SIZE (2)
60 #define PIM_TLV_LENGTH_SIZE (2)
61 #define PIM_TLV_MIN_SIZE (PIM_TLV_TYPE_SIZE + PIM_TLV_LENGTH_SIZE)
62 #define PIM_TLV_OPTION_SIZE(option_len) (PIM_TLV_MIN_SIZE + (option_len))
63
64 uint8_t *pim_tlv_append_uint16(uint8_t *buf, const uint8_t *buf_pastend,
65 uint16_t option_type, uint16_t option_value);
66 uint8_t *pim_tlv_append_2uint16(uint8_t *buf, const uint8_t *buf_pastend,
67 uint16_t option_type, uint16_t option_value1,
68 uint16_t option_value2);
69 uint8_t *pim_tlv_append_uint32(uint8_t *buf, const uint8_t *buf_pastend,
70 uint16_t option_type, uint32_t option_value);
71 uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend,
72 struct interface *ifp, int family);
73
74 int pim_tlv_parse_holdtime(const char *ifname, pim_addr src_addr,
75 pim_hello_options *hello_options,
76 uint16_t *hello_option_holdtime, uint16_t option_len,
77 const uint8_t *tlv_curr);
78 int pim_tlv_parse_lan_prune_delay(const char *ifname, pim_addr src_addr,
79 pim_hello_options *hello_options,
80 uint16_t *hello_option_propagation_delay,
81 uint16_t *hello_option_override_interval,
82 uint16_t option_len, const uint8_t *tlv_curr);
83 int pim_tlv_parse_dr_priority(const char *ifname, pim_addr src_addr,
84 pim_hello_options *hello_options,
85 uint32_t *hello_option_dr_priority,
86 uint16_t option_len, const uint8_t *tlv_curr);
87 int pim_tlv_parse_generation_id(const char *ifname, pim_addr src_addr,
88 pim_hello_options *hello_options,
89 uint32_t *hello_option_generation_id,
90 uint16_t option_len, const uint8_t *tlv_curr);
91 int pim_tlv_parse_addr_list(const char *ifname, pim_addr src_addr,
92 pim_hello_options *hello_options,
93 struct list **hello_option_addr_list,
94 uint16_t option_len, const uint8_t *tlv_curr);
95
96 int pim_encode_addr_ucast(uint8_t *buf, pim_addr addr);
97 int pim_encode_addr_ucast_prefix(uint8_t *buf, struct prefix *p);
98 int pim_encode_addr_group(uint8_t *buf, afi_t afi, int bidir, int scope,
99 pim_addr group);
100
101 int pim_parse_addr_ucast(pim_addr *out, const uint8_t *buf, int buf_size,
102 bool *wrong_af);
103 int pim_parse_addr_ucast_prefix(struct prefix *out, const uint8_t *buf,
104 int buf_size);
105 int pim_parse_addr_group(pim_sgaddr *sg, const uint8_t *buf, int buf_size);
106 int pim_parse_addr_source(pim_sgaddr *sg, uint8_t *flags, const uint8_t *buf,
107 int buf_size);
108
109 #endif /* PIM_TLV_H */