]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_bsm.h
Merge pull request #5430 from taruta811/build-docker-centos
[mirror_frr.git] / pimd / pim_bsm.h
1 /*
2 * pim_bsm.h: PIM BSM handling related
3 *
4 * Copyright (C) 2018-19 Vmware, Inc.
5 * Saravanan K
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 * MA 02110-1301 USA
21 */
22
23 #ifndef __PIM_BSM_H__
24 #define __PIM_BSM_H__
25
26 #include "if.h"
27 #include "vty.h"
28 #include "linklist.h"
29 #include "table.h"
30 #include "pim_rp.h"
31 #include "pim_msg.h"
32
33 /* Defines */
34 #define PIM_GBL_SZ_ID 0 /* global scope zone id set to 0 */
35 #define PIM_BS_TIME 60 /* RFC 5059 - Sec 5 */
36 #define PIM_BSR_DEFAULT_TIMEOUT 130 /* RFC 5059 - Sec 5 */
37
38 /* These structures are only encoded IPv4 specific */
39 #define PIM_BSM_HDR_LEN sizeof(struct bsm_hdr)
40 #define PIM_BSM_GRP_LEN sizeof(struct bsmmsg_grpinfo)
41 #define PIM_BSM_RP_LEN sizeof(struct bsmmsg_rpinfo)
42
43 #define PIM_MIN_BSM_LEN \
44 (PIM_HDR_LEN + PIM_BSM_HDR_LEN + PIM_BSM_GRP_LEN + PIM_BSM_RP_LEN)
45
46 /* Datastructures
47 * ==============
48 */
49
50 /* Non candidate BSR states */
51 enum ncbsr_state {
52 NO_INFO = 0,
53 ACCEPT_ANY,
54 ACCEPT_PREFERRED
55 };
56
57 /* BSM scope - bsm processing is per scope */
58 struct bsm_scope {
59 int sz_id; /* scope zone id */
60 enum ncbsr_state state; /* non candidate BSR state */
61 bool accept_nofwd_bsm; /* no fwd bsm accepted for scope */
62 struct in_addr current_bsr; /* current elected BSR for the sz */
63 uint32_t current_bsr_prio; /* current BSR priority */
64 int64_t current_bsr_first_ts; /* current BSR elected time */
65 int64_t current_bsr_last_ts; /* Last BSM received from E-BSR */
66 uint16_t bsm_frag_tag; /* Last received frag tag from E-BSR */
67 uint8_t hashMasklen; /* Mask in hash calc RFC 7761 4.7.2 */
68 struct pim_instance *pim; /* Back pointer to pim instance */
69 struct list *bsm_list; /* list of bsm frag for frowarding */
70 struct route_table *bsrp_table; /* group2rp mapping rcvd from BSR */
71 struct thread *bs_timer; /* Boot strap timer */
72 struct thread *sz_timer;
73 };
74
75 /* BSM packet - this is stored as list in bsm_list inside scope
76 * This is used for forwarding to new neighbors or restarting mcast routers
77 */
78 struct bsm_info {
79 uint32_t size; /* size of the packet */
80 unsigned char *bsm; /* Actual packet */
81 };
82
83 /* This is the group node of the bsrp table in scope.
84 * this node maintains the list of rp for the group.
85 */
86 struct bsgrp_node {
87 struct prefix group; /* Group range */
88 struct bsm_scope *scope; /* Back ptr to scope */
89 struct list *bsrp_list; /* list of RPs adv by BSR */
90 struct list *partial_bsrp_list; /* maintained until all RPs received */
91 int pend_rp_cnt; /* Total RP - Received RP */
92 uint16_t frag_tag; /* frag tag to identify the fragment */
93 };
94
95 /* This is the list node of bsrp_list and partial bsrp list in
96 * bsgrp_node. Hold info of each RP received for the group
97 */
98 struct bsm_rpinfo {
99 uint32_t hash; /* Hash Value as per RFC 7761 4.7.2 */
100 uint32_t elapse_time; /* upd at expiry of elected RP node */
101 uint16_t rp_prio; /* RP priority */
102 uint16_t rp_holdtime; /* RP holdtime - g2rp timer value */
103 struct in_addr rp_address; /* RP Address */
104 struct bsgrp_node *bsgrp_node; /* Back ptr to bsgrp_node */
105 struct thread *g2rp_timer; /* Run only for elected RP node */
106 };
107
108 /* Structures to extract Bootstrap Message header and Grp to RP Mappings
109 * =====================================================================
110 * BSM Format:
111 *
112 * 0 1 2 3
113 * 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
114 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
115 * |PIM Ver| Type |N| Reserved | Checksum | PIM HDR
116 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
117 * | Fragment Tag | Hash Mask Len | BSR Priority | BS HDR(1)
118 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119 * | BSR Address (Encoded-Unicast format) | BS HDR(2)
120 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
121 * | Group Address 1 (Encoded-Group format) |
122 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
123 * | RP Count 1 | Frag RP Cnt 1 | Reserved |
124 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
125 * | RP Address 1 (Encoded-Unicast format) |
126 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
127 * | RP1 Holdtime | RP1 Priority | Reserved |
128 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
129 * | RP Address 2 (Encoded-Unicast format) |
130 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
131 * | RP2 Holdtime | RP2 Priority | Reserved |
132 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
133 * | . |
134 * | . |
135 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
136 * | RP Address m (Encoded-Unicast format) |
137 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
138 * | RPm Holdtime | RPm Priority | Reserved |
139 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140 * | Group Address 2 (Encoded-Group format) |
141 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142 * | . |
143 * | . |
144 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 * | Group Address n (Encoded-Group format) |
146 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
147 * | RP Count n | Frag RP Cnt n | Reserved |
148 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
149 * | RP Address 1 (Encoded-Unicast format) |
150 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151 * | RP1 Holdtime | RP1 Priority | Reserved |
152 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153 * | RP Address 2 (Encoded-Unicast format) |
154 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
155 * | RP2 Holdtime | RP2 Priority | Reserved |
156 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
157 * | . |
158 * | . |
159 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
160 * | RP Address m (Encoded-Unicast format) |
161 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
162 * | RPm Holdtime | RPm Priority | Reserved |
163 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
164 */
165 struct bsm_hdr {
166 uint16_t frag_tag;
167 uint8_t hm_len;
168 uint8_t bsr_prio;
169 struct pim_encoded_ipv4_unicast bsr_addr;
170 } __attribute__((packed));
171
172 struct bsmmsg_grpinfo {
173 struct pim_encoded_group_ipv4 group;
174 uint8_t rp_count;
175 uint8_t frag_rp_count;
176 uint16_t reserved;
177 } __attribute__((packed));
178
179 struct bsmmsg_rpinfo {
180 struct pim_encoded_ipv4_unicast rpaddr;
181 uint16_t rp_holdtime;
182 uint8_t rp_pri;
183 uint8_t reserved;
184 } __attribute__((packed));
185
186 /* API */
187 void pim_bsm_proc_init(struct pim_instance *pim);
188 void pim_bsm_proc_free(struct pim_instance *pim);
189 void pim_bsm_write_config(struct vty *vty, struct interface *ifp);
190 int pim_bsm_process(struct interface *ifp,
191 struct ip *ip_hdr,
192 uint8_t *buf,
193 uint32_t buf_size,
194 bool no_fwd);
195 bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp);
196 struct bsgrp_node *pim_bsm_get_bsgrp_node(struct bsm_scope *scope,
197 struct prefix *grp);
198 #endif