blob: 9602cb1c7b9c343f911151b5fbb0f9d3812b8575 [file] [log] [blame]
Everton Marques871dbcf2009-08-11 15:43:05 -03001/*
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
16 along with this program; see the file COPYING; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18 MA 02110-1301 USA
19
20 $QuaggaId: $Format:%an, %ai, %h$ $
21*/
22
23#ifndef PIM_TLV_H
24#define PIM_TLV_H
25
26#include <zebra.h>
27
28#include "config.h"
29#include "if.h"
30#include "linklist.h"
31
32#ifdef HAVE_INTTYPES_H
33#include <inttypes.h>
34#endif /* HAVE_INTTYPES_H */
35
36#define PIM_MSG_OPTION_TYPE_HOLDTIME (1)
37#define PIM_MSG_OPTION_TYPE_LAN_PRUNE_DELAY (2)
38#define PIM_MSG_OPTION_TYPE_DR_PRIORITY (19)
39#define PIM_MSG_OPTION_TYPE_GENERATION_ID (20)
40#define PIM_MSG_OPTION_TYPE_DM_STATE_REFRESH (21)
41#define PIM_MSG_OPTION_TYPE_ADDRESS_LIST (24)
42
43typedef uint32_t pim_hello_options;
44#define PIM_OPTION_MASK_HOLDTIME (1 << 0) /* recv holdtime */
45#define PIM_OPTION_MASK_LAN_PRUNE_DELAY (1 << 1) /* recv lan_prune_delay */
46#define PIM_OPTION_MASK_DR_PRIORITY (1 << 2) /* recv dr_priority */
47#define PIM_OPTION_MASK_GENERATION_ID (1 << 3) /* recv generation_id */
48#define PIM_OPTION_MASK_ADDRESS_LIST (1 << 4) /* recv secondary address list */
49#define PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION (1 << 5) /* T bit value (valid if recv lan_prune_delay) */
50
51#define PIM_RPT_BIT_MASK (1 << 0)
52#define PIM_WILDCARD_BIT_MASK (1 << 1)
53
54#define PIM_OPTION_SET(options, option_mask) ((options) |= (option_mask))
55#define PIM_OPTION_UNSET(options, option_mask) ((options) &= ~(option_mask))
56#define PIM_OPTION_IS_SET(options, option_mask) ((options) & (option_mask))
57
58#define PIM_TLV_GET_UINT16(buf) ntohs(*(const uint16_t *)(buf))
59#define PIM_TLV_GET_UINT32(buf) ntohl(*(const uint32_t *)(buf))
60#define PIM_TLV_GET_TYPE(buf) PIM_TLV_GET_UINT16(buf)
61#define PIM_TLV_GET_LENGTH(buf) PIM_TLV_GET_UINT16(buf)
62#define PIM_TLV_GET_HOLDTIME(buf) PIM_TLV_GET_UINT16(buf)
63#define PIM_TLV_GET_PROPAGATION_DELAY(buf) (PIM_TLV_GET_UINT16(buf) & 0x7FFF)
64#define PIM_TLV_GET_OVERRIDE_INTERVAL(buf) PIM_TLV_GET_UINT16(buf)
65#define PIM_TLV_GET_CAN_DISABLE_JOIN_SUPPRESSION(buf) ((*(const uint8_t *)(buf)) & 0x80)
66#define PIM_TLV_GET_DR_PRIORITY(buf) PIM_TLV_GET_UINT32(buf)
67#define PIM_TLV_GET_GENERATION_ID(buf) PIM_TLV_GET_UINT32(buf)
68
69#define PIM_TLV_TYPE_SIZE (2)
70#define PIM_TLV_LENGTH_SIZE (2)
71#define PIM_TLV_MIN_SIZE (PIM_TLV_TYPE_SIZE + PIM_TLV_LENGTH_SIZE)
72#define PIM_TLV_OPTION_SIZE(option_len) (PIM_TLV_MIN_SIZE + (option_len))
73
74char *pim_tlv_append_uint16(char *buf,
75 const char *buf_pastend,
76 uint16_t option_type,
77 uint16_t option_value);
78char *pim_tlv_append_2uint16(char *buf,
79 const char *buf_pastend,
80 uint16_t option_type,
81 uint16_t option_value1,
82 uint16_t option_value2);
83char *pim_tlv_append_uint32(char *buf,
84 const char *buf_pastend,
85 uint16_t option_type,
86 uint32_t option_value);
87char *pim_tlv_append_addrlist_ucast(char *buf,
88 const char *buf_pastend,
89 struct list *ifconnected);
90
91int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr,
92 pim_hello_options *hello_options,
93 uint16_t *hello_option_holdtime,
94 uint16_t option_len,
95 const char *tlv_curr);
96int pim_tlv_parse_lan_prune_delay(const char *ifname, struct in_addr src_addr,
97 pim_hello_options *hello_options,
98 uint16_t *hello_option_propagation_delay,
99 uint16_t *hello_option_override_interval,
100 uint16_t option_len,
101 const char *tlv_curr);
102int pim_tlv_parse_dr_priority(const char *ifname, struct in_addr src_addr,
103 pim_hello_options *hello_options,
104 uint32_t *hello_option_dr_priority,
105 uint16_t option_len,
106 const char *tlv_curr);
107int pim_tlv_parse_generation_id(const char *ifname, struct in_addr src_addr,
108 pim_hello_options *hello_options,
109 uint32_t *hello_option_generation_id,
110 uint16_t option_len,
111 const char *tlv_curr);
112int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr,
113 pim_hello_options *hello_options,
114 struct list **hello_option_addr_list,
115 uint16_t option_len,
116 const char *tlv_curr);
117
118int pim_parse_addr_ucast(const char *ifname, struct in_addr src_addr,
119 struct prefix *p,
120 const char *buf,
121 int buf_size);
122int pim_parse_addr_group(const char *ifname, struct in_addr src_addr,
123 struct prefix *p,
124 const char *buf,
125 int buf_size);
126int pim_parse_addr_source(const char *ifname,
127 struct in_addr src_addr,
128 struct prefix *p,
129 uint8_t *flags,
130 const char *buf,
131 int buf_size);
132
133#endif /* PIM_TLV_H */