3 * Copyright (C) 2008 Everton da Silva Marques
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.
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.
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
23 #include <netinet/in.h>
25 #include "pim_jp_agg.h"
27 #define PIM_HDR_LEN sizeof(struct pim_msg_header)
30 ---------- ------------------
36 http://www.iana.org/assignments/address-family-numbers
38 enum pim_msg_address_family
{
39 PIM_MSG_ADDRESS_FAMILY_RESERVED
,
40 PIM_MSG_ADDRESS_FAMILY_IPV4
,
41 PIM_MSG_ADDRESS_FAMILY_IPV6
,
46 * =========================
47 * PIM Header definition as per RFC 5059. N bit introduced to indicate
48 * do-not-forward option in PIM Boot strap Message.
50 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
51 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 * |PIM Ver| Type |N| Reserved | Checksum |
53 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 struct pim_msg_header
{
56 #if (BYTE_ORDER == LITTLE_ENDIAN)
60 uint8_t Nbit
: 1; /* No Fwd Bit */
61 #elif (BYTE_ORDER == BIG_ENDIAN)
64 uint8_t Nbit
: 1; /* No Fwd Bit */
67 #error"Please set byte order"
70 } __attribute__((packed
));
72 struct pim_encoded_ipv4_unicast
{
76 } __attribute__((packed
));
79 * Encoded Group format. RFC 4601 Sec 4.9.1
81 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
82 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83 * | Addr Family | Encoding Type |B| Reserved |Z| Mask Len |
84 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
85 * | Group multicast Address
86 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+...
88 struct pim_encoded_group_ipv4
{
91 #if (BYTE_ORDER == LITTLE_ENDIAN)
92 uint8_t sz
: 1; /* scope zone bit */
93 uint8_t reserved
: 6; /* Reserved */
94 uint8_t bidir
: 1; /* Bidir bit */
95 #elif (BYTE_ORDER == BIG_ENDIAN)
96 uint8_t bidir
: 1; /* Bidir bit */
97 uint8_t reserved
: 6; /* Reserved */
98 uint8_t sz
: 1; /* scope zone bit */
100 #error"Please set byte order"
104 } __attribute__((packed
));
108 * Encoded Source format. RFC 4601 Sec 4.9.1
110 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
111 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112 * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len |
113 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
115 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-...
117 struct pim_encoded_source_ipv4
{
123 } __attribute__((packed
));
125 struct pim_jp_groups
{
126 struct pim_encoded_group_ipv4 g
;
129 struct pim_encoded_source_ipv4 s
[1];
130 } __attribute__((packed
));
133 struct pim_msg_header header
;
134 struct pim_encoded_ipv4_unicast addr
;
138 struct pim_jp_groups groups
[1];
139 } __attribute__((packed
));
141 void pim_msg_build_header(uint8_t *pim_msg
, size_t pim_msg_size
,
142 uint8_t pim_msg_type
, bool no_fwd
);
143 uint8_t *pim_msg_addr_encode_ipv4_ucast(uint8_t *buf
, struct in_addr addr
);
144 uint8_t *pim_msg_addr_encode_ipv4_group(uint8_t *buf
, struct in_addr addr
);
146 #define PIM_ENCODE_SPARSE_BIT 0x04
147 #define PIM_ENCODE_WC_BIT 0x02
148 #define PIM_ENCODE_RPT_BIT 0x01
149 uint8_t *pim_msg_addr_encode_ipv4_source(uint8_t *buf
, struct in_addr addr
,
153 size_t pim_msg_get_jp_group_size(struct list
*sources
);
154 size_t pim_msg_build_jp_groups(struct pim_jp_groups
*grp
,
155 struct pim_jp_agg_group
*sgs
, size_t size
);
156 #endif /* PIM_MSG_H */