]>
Commit | Line | Data |
---|---|---|
12e41d03 | 1 | /* |
896014f4 DL |
2 | * PIM for Quagga |
3 | * Copyright (C) 2008 Everton da Silva Marques | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
12e41d03 DL |
19 | |
20 | #ifndef PIM_TLV_H | |
21 | #define PIM_TLV_H | |
22 | ||
23 | #include <zebra.h> | |
24 | ||
25 | #include "config.h" | |
26 | #include "if.h" | |
27 | #include "linklist.h" | |
28 | ||
12e41d03 DL |
29 | #define PIM_MSG_OPTION_TYPE_HOLDTIME (1) |
30 | #define PIM_MSG_OPTION_TYPE_LAN_PRUNE_DELAY (2) | |
31 | #define PIM_MSG_OPTION_TYPE_DR_PRIORITY (19) | |
32 | #define PIM_MSG_OPTION_TYPE_GENERATION_ID (20) | |
33 | #define PIM_MSG_OPTION_TYPE_DM_STATE_REFRESH (21) | |
34 | #define PIM_MSG_OPTION_TYPE_ADDRESS_LIST (24) | |
35 | ||
36 | typedef uint32_t pim_hello_options; | |
37 | #define PIM_OPTION_MASK_HOLDTIME (1 << 0) /* recv holdtime */ | |
38 | #define PIM_OPTION_MASK_LAN_PRUNE_DELAY (1 << 1) /* recv lan_prune_delay */ | |
39 | #define PIM_OPTION_MASK_DR_PRIORITY (1 << 2) /* recv dr_priority */ | |
40 | #define PIM_OPTION_MASK_GENERATION_ID (1 << 3) /* recv generation_id */ | |
41 | #define PIM_OPTION_MASK_ADDRESS_LIST (1 << 4) /* recv secondary address list */ | |
42 | #define PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION (1 << 5) /* T bit value (valid if recv lan_prune_delay) */ | |
43 | ||
44 | #define PIM_RPT_BIT_MASK (1 << 0) | |
45 | #define PIM_WILDCARD_BIT_MASK (1 << 1) | |
46 | ||
47 | #define PIM_OPTION_SET(options, option_mask) ((options) |= (option_mask)) | |
48 | #define PIM_OPTION_UNSET(options, option_mask) ((options) &= ~(option_mask)) | |
49 | #define PIM_OPTION_IS_SET(options, option_mask) ((options) & (option_mask)) | |
50 | ||
c181a7d5 QY |
51 | #define PIM_TLV_GET_UINT16(buf) \ |
52 | ({ \ | |
53 | uint16_t _tmp; \ | |
54 | memcpy(&_tmp, (buf), sizeof(uint16_t)); \ | |
55 | ntohs(_tmp); \ | |
56 | }) | |
57 | #define PIM_TLV_GET_UINT32(buf) \ | |
58 | ({ \ | |
59 | uint32_t _tmp; \ | |
60 | memcpy(&_tmp, (buf), sizeof(uint32_t)); \ | |
61 | ntohl(_tmp); \ | |
62 | }) | |
12e41d03 DL |
63 | #define PIM_TLV_GET_TYPE(buf) PIM_TLV_GET_UINT16(buf) |
64 | #define PIM_TLV_GET_LENGTH(buf) PIM_TLV_GET_UINT16(buf) | |
65 | #define PIM_TLV_GET_HOLDTIME(buf) PIM_TLV_GET_UINT16(buf) | |
66 | #define PIM_TLV_GET_PROPAGATION_DELAY(buf) (PIM_TLV_GET_UINT16(buf) & 0x7FFF) | |
67 | #define PIM_TLV_GET_OVERRIDE_INTERVAL(buf) PIM_TLV_GET_UINT16(buf) | |
68 | #define PIM_TLV_GET_CAN_DISABLE_JOIN_SUPPRESSION(buf) ((*(const uint8_t *)(buf)) & 0x80) | |
69 | #define PIM_TLV_GET_DR_PRIORITY(buf) PIM_TLV_GET_UINT32(buf) | |
70 | #define PIM_TLV_GET_GENERATION_ID(buf) PIM_TLV_GET_UINT32(buf) | |
71 | ||
72 | #define PIM_TLV_TYPE_SIZE (2) | |
73 | #define PIM_TLV_LENGTH_SIZE (2) | |
74 | #define PIM_TLV_MIN_SIZE (PIM_TLV_TYPE_SIZE + PIM_TLV_LENGTH_SIZE) | |
75 | #define PIM_TLV_OPTION_SIZE(option_len) (PIM_TLV_MIN_SIZE + (option_len)) | |
76 | ||
d62a17ae | 77 | uint8_t *pim_tlv_append_uint16(uint8_t *buf, const uint8_t *buf_pastend, |
78 | uint16_t option_type, uint16_t option_value); | |
79 | uint8_t *pim_tlv_append_2uint16(uint8_t *buf, const uint8_t *buf_pastend, | |
80 | uint16_t option_type, uint16_t option_value1, | |
12e41d03 | 81 | uint16_t option_value2); |
d62a17ae | 82 | uint8_t *pim_tlv_append_uint32(uint8_t *buf, const uint8_t *buf_pastend, |
83 | uint16_t option_type, uint32_t option_value); | |
84 | uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend, | |
85 | struct list *ifconnected, int family); | |
12e41d03 DL |
86 | |
87 | int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr, | |
88 | pim_hello_options *hello_options, | |
d62a17ae | 89 | uint16_t *hello_option_holdtime, uint16_t option_len, |
12e41d03 DL |
90 | const uint8_t *tlv_curr); |
91 | int pim_tlv_parse_lan_prune_delay(const char *ifname, struct in_addr src_addr, | |
92 | pim_hello_options *hello_options, | |
93 | uint16_t *hello_option_propagation_delay, | |
94 | uint16_t *hello_option_override_interval, | |
d62a17ae | 95 | uint16_t option_len, const uint8_t *tlv_curr); |
12e41d03 DL |
96 | int pim_tlv_parse_dr_priority(const char *ifname, struct in_addr src_addr, |
97 | pim_hello_options *hello_options, | |
98 | uint32_t *hello_option_dr_priority, | |
d62a17ae | 99 | uint16_t option_len, const uint8_t *tlv_curr); |
12e41d03 DL |
100 | int pim_tlv_parse_generation_id(const char *ifname, struct in_addr src_addr, |
101 | pim_hello_options *hello_options, | |
102 | uint32_t *hello_option_generation_id, | |
d62a17ae | 103 | uint16_t option_len, const uint8_t *tlv_curr); |
12e41d03 DL |
104 | int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, |
105 | pim_hello_options *hello_options, | |
106 | struct list **hello_option_addr_list, | |
d62a17ae | 107 | uint16_t option_len, const uint8_t *tlv_curr); |
12e41d03 | 108 | |
d62a17ae | 109 | int pim_encode_addr_ucast(uint8_t *buf, struct prefix *p); |
110 | int pim_encode_addr_group(uint8_t *buf, afi_t afi, int bidir, int scope, | |
111 | struct in_addr group); | |
8f483f92 | 112 | |
d62a17ae | 113 | int pim_parse_addr_ucast(struct prefix *p, const uint8_t *buf, int buf_size); |
114 | int pim_parse_addr_group(struct prefix_sg *sg, const uint8_t *buf, | |
115 | int buf_size); | |
116 | int pim_parse_addr_source(struct prefix_sg *sg, uint8_t *flags, | |
117 | const uint8_t *buf, int buf_size); | |
12e41d03 DL |
118 | |
119 | #endif /* PIM_TLV_H */ |