summaryrefslogtreecommitdiffstats
path: root/pimd/pim_tlv.h
blob: ea2af6457dde5de7aa5a8b750ed7d9582ade78e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * PIM for Quagga
 * Copyright (C) 2008  Everton da Silva Marques
 */

#ifndef PIM_TLV_H
#define PIM_TLV_H

#include <zebra.h>

#include "config.h"
#include "if.h"
#include "linklist.h"

#define PIM_MSG_OPTION_TYPE_HOLDTIME         (1)
#define PIM_MSG_OPTION_TYPE_LAN_PRUNE_DELAY  (2)
#define PIM_MSG_OPTION_TYPE_DR_PRIORITY      (19)
#define PIM_MSG_OPTION_TYPE_GENERATION_ID    (20)
#define PIM_MSG_OPTION_TYPE_DM_STATE_REFRESH (21)
#define PIM_MSG_OPTION_TYPE_ADDRESS_LIST     (24)

typedef uint32_t pim_hello_options;
#define PIM_OPTION_MASK_HOLDTIME                     (1 << 0) /* recv holdtime */
#define PIM_OPTION_MASK_LAN_PRUNE_DELAY              (1 << 1) /* recv lan_prune_delay */
#define PIM_OPTION_MASK_DR_PRIORITY                  (1 << 2) /* recv dr_priority */
#define PIM_OPTION_MASK_GENERATION_ID                (1 << 3) /* recv generation_id */
#define PIM_OPTION_MASK_ADDRESS_LIST                 (1 << 4) /* recv secondary address list */
#define PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION (1 << 5) /* T bit value (valid if recv lan_prune_delay) */

#define PIM_RPT_BIT_MASK      (1 << 0)
#define PIM_WILDCARD_BIT_MASK (1 << 1)

#define PIM_OPTION_SET(options, option_mask) ((options) |= (option_mask))
#define PIM_OPTION_UNSET(options, option_mask) ((options) &= ~(option_mask))
#define PIM_OPTION_IS_SET(options, option_mask) ((options) & (option_mask))

#define PIM_TLV_GET_UINT16(buf)                                                \
	({                                                                     \
		uint16_t _tmp;                                                 \
		memcpy(&_tmp, (buf), sizeof(uint16_t));                        \
		ntohs(_tmp);                                                   \
	})
#define PIM_TLV_GET_UINT32(buf)                                                \
	({                                                                     \
		uint32_t _tmp;                                                 \
		memcpy(&_tmp, (buf), sizeof(uint32_t));                        \
		ntohl(_tmp);                                                   \
	})
#define PIM_TLV_GET_TYPE(buf) PIM_TLV_GET_UINT16(buf)
#define PIM_TLV_GET_LENGTH(buf) PIM_TLV_GET_UINT16(buf)
#define PIM_TLV_GET_HOLDTIME(buf) PIM_TLV_GET_UINT16(buf)
#define PIM_TLV_GET_PROPAGATION_DELAY(buf) (PIM_TLV_GET_UINT16(buf) & 0x7FFF)
#define PIM_TLV_GET_OVERRIDE_INTERVAL(buf) PIM_TLV_GET_UINT16(buf)
#define PIM_TLV_GET_CAN_DISABLE_JOIN_SUPPRESSION(buf) ((*(const uint8_t *)(buf)) & 0x80)
#define PIM_TLV_GET_DR_PRIORITY(buf) PIM_TLV_GET_UINT32(buf)
#define PIM_TLV_GET_GENERATION_ID(buf) PIM_TLV_GET_UINT32(buf)

#define PIM_TLV_TYPE_SIZE               (2)
#define PIM_TLV_LENGTH_SIZE             (2)
#define PIM_TLV_MIN_SIZE                (PIM_TLV_TYPE_SIZE + PIM_TLV_LENGTH_SIZE)
#define PIM_TLV_OPTION_SIZE(option_len) (PIM_TLV_MIN_SIZE + (option_len))

uint8_t *pim_tlv_append_uint16(uint8_t *buf, const uint8_t *buf_pastend,
			       uint16_t option_type, uint16_t option_value);
uint8_t *pim_tlv_append_2uint16(uint8_t *buf, const uint8_t *buf_pastend,
				uint16_t option_type, uint16_t option_value1,
				uint16_t option_value2);
uint8_t *pim_tlv_append_uint32(uint8_t *buf, const uint8_t *buf_pastend,
			       uint16_t option_type, uint32_t option_value);
uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend,
				       struct interface *ifp, int family);

int pim_tlv_parse_holdtime(const char *ifname, pim_addr src_addr,
			   pim_hello_options *hello_options,
			   uint16_t *hello_option_holdtime, uint16_t option_len,
			   const uint8_t *tlv_curr);
int pim_tlv_parse_lan_prune_delay(const char *ifname, pim_addr src_addr,
				  pim_hello_options *hello_options,
				  uint16_t *hello_option_propagation_delay,
				  uint16_t *hello_option_override_interval,
				  uint16_t option_len, const uint8_t *tlv_curr);
int pim_tlv_parse_dr_priority(const char *ifname, pim_addr src_addr,
			      pim_hello_options *hello_options,
			      uint32_t *hello_option_dr_priority,
			      uint16_t option_len, const uint8_t *tlv_curr);
int pim_tlv_parse_generation_id(const char *ifname, pim_addr src_addr,
				pim_hello_options *hello_options,
				uint32_t *hello_option_generation_id,
				uint16_t option_len, const uint8_t *tlv_curr);
int pim_tlv_parse_addr_list(const char *ifname, pim_addr src_addr,
			    pim_hello_options *hello_options,
			    struct list **hello_option_addr_list,
			    uint16_t option_len, const uint8_t *tlv_curr);

int pim_encode_addr_ucast(uint8_t *buf, pim_addr addr);
int pim_encode_addr_ucast_prefix(uint8_t *buf, struct prefix *p);
int pim_encode_addr_group(uint8_t *buf, afi_t afi, int bidir, int scope,
			  pim_addr group);

int pim_parse_addr_ucast(pim_addr *out, const uint8_t *buf, int buf_size,
			 bool *wrong_af);
int pim_parse_addr_ucast_prefix(struct prefix *out, const uint8_t *buf,
				int buf_size);
int pim_parse_addr_group(pim_sgaddr *sg, const uint8_t *buf, int buf_size);
int pim_parse_addr_source(pim_sgaddr *sg, uint8_t *flags, const uint8_t *buf,
			  int buf_size);

#endif /* PIM_TLV_H */