]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_bsm.h
Merge pull request #13249 from Pdoijode/connected-route-install-fix
[mirror_frr.git] / pimd / pim_bsm.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * pim_bsm.h: PIM BSM handling related
4 *
5 * Copyright (C) 2018-19 Vmware, Inc.
6 * Saravanan K
7 */
8
9 #ifndef __PIM_BSM_H__
10 #define __PIM_BSM_H__
11
12 #include "if.h"
13 #include "vty.h"
14 #include "typesafe.h"
15 #include "table.h"
16 #include "pim_rp.h"
17 #include "pim_msg.h"
18
19 /* Defines */
20 #define PIM_GBL_SZ_ID 0 /* global scope zone id set to 0 */
21 #define PIM_BS_TIME 60 /* RFC 5059 - Sec 5 */
22 #define PIM_BSR_DEFAULT_TIMEOUT 130 /* RFC 5059 - Sec 5 */
23
24 /* These structures are only encoded IPv4 specific */
25 #define PIM_BSM_HDR_LEN sizeof(struct bsm_hdr)
26 #define PIM_BSM_GRP_LEN sizeof(struct bsmmsg_grpinfo)
27 #define PIM_BSM_RP_LEN sizeof(struct bsmmsg_rpinfo)
28
29 #define PIM_MIN_BSM_LEN \
30 (PIM_HDR_LEN + PIM_BSM_HDR_LEN + PIM_BSM_GRP_LEN + PIM_BSM_RP_LEN)
31
32 /* Datastructures
33 * ==============
34 */
35
36 /* Non candidate BSR states */
37 enum ncbsr_state {
38 NO_INFO = 0,
39 ACCEPT_ANY,
40 ACCEPT_PREFERRED
41 };
42
43 PREDECL_DLIST(bsm_frags);
44
45 /* BSM scope - bsm processing is per scope */
46 struct bsm_scope {
47 int sz_id; /* scope zone id */
48 enum ncbsr_state state; /* non candidate BSR state */
49 bool accept_nofwd_bsm; /* no fwd bsm accepted for scope */
50 pim_addr current_bsr; /* current elected BSR for the sz */
51 uint32_t current_bsr_prio; /* current BSR priority */
52 int64_t current_bsr_first_ts; /* current BSR elected time */
53 int64_t current_bsr_last_ts; /* Last BSM received from E-BSR */
54 uint16_t bsm_frag_tag; /* Last received frag tag from E-BSR */
55 uint8_t hashMasklen; /* Mask in hash calc RFC 7761 4.7.2 */
56 struct pim_instance *pim; /* Back pointer to pim instance */
57
58 /* current set of fragments for forwarding */
59 struct bsm_frags_head bsm_frags[1];
60
61 struct route_table *bsrp_table; /* group2rp mapping rcvd from BSR */
62 struct event *bs_timer; /* Boot strap timer */
63 };
64
65 /* BSM packet (= fragment) - this is stored as list in bsm_frags inside scope
66 * This is used for forwarding to new neighbors or restarting mcast routers
67 */
68 struct bsm_frag {
69 struct bsm_frags_item item;
70
71 uint32_t size; /* size of the packet */
72 uint8_t data[0]; /* Actual packet (dyn size) */
73 };
74
75 DECLARE_DLIST(bsm_frags, struct bsm_frag, item);
76
77 PREDECL_SORTLIST_UNIQ(bsm_rpinfos);
78
79 /* This is the group node of the bsrp table in scope.
80 * this node maintains the list of rp for the group.
81 */
82 struct bsgrp_node {
83 struct prefix group; /* Group range */
84 struct bsm_scope *scope; /* Back ptr to scope */
85
86 /* RPs advertised by BSR, and temporary list while receiving new set */
87 struct bsm_rpinfos_head bsrp_list[1];
88 struct bsm_rpinfos_head partial_bsrp_list[1];
89
90 int pend_rp_cnt; /* Total RP - Received RP */
91 uint16_t frag_tag; /* frag tag to identify the fragment */
92 };
93
94 /* Items on [partial_]bsrp_list above.
95 * Holds info of each candidate RP received for the bsgrp_node's prefix.
96 */
97 struct bsm_rpinfo {
98 struct bsm_rpinfos_item item;
99
100 uint32_t hash; /* Hash Value as per RFC 7761 4.7.2 */
101 uint32_t elapse_time; /* upd at expiry of elected RP node */
102 uint16_t rp_prio; /* RP priority */
103 uint16_t rp_holdtime; /* RP holdtime - g2rp timer value */
104 pim_addr rp_address; /* RP Address */
105 struct bsgrp_node *bsgrp_node; /* Back ptr to bsgrp_node */
106 struct event *g2rp_timer; /* Run only for elected RP node */
107 };
108
109 extern int pim_bsm_rpinfo_cmp(const struct bsm_rpinfo *a,
110 const struct bsm_rpinfo *b);
111 DECLARE_SORTLIST_UNIQ(bsm_rpinfos, struct bsm_rpinfo, item, pim_bsm_rpinfo_cmp);
112
113 /* Structures to extract Bootstrap Message header and Grp to RP Mappings
114 * =====================================================================
115 * BSM Format:
116 *
117 * 0 1 2 3
118 * 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
119 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
120 * |PIM Ver| Type |N| Reserved | Checksum | PIM HDR
121 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
122 * | Fragment Tag | Hash Mask Len | BSR Priority | BS HDR(1)
123 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
124 * | BSR Address (Encoded-Unicast format) | BS HDR(2)
125 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
126 * | Group Address 1 (Encoded-Group format) |
127 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128 * | RP Count 1 | Frag RP Cnt 1 | Reserved |
129 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
130 * | RP Address 1 (Encoded-Unicast format) |
131 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
132 * | RP1 Holdtime | RP1 Priority | Reserved |
133 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
134 * | RP Address 2 (Encoded-Unicast format) |
135 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
136 * | RP2 Holdtime | RP2 Priority | Reserved |
137 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
138 * | . |
139 * | . |
140 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141 * | RP Address m (Encoded-Unicast format) |
142 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 * | RPm Holdtime | RPm Priority | Reserved |
144 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 * | Group Address 2 (Encoded-Group format) |
146 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
147 * | . |
148 * | . |
149 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
150 * | Group Address n (Encoded-Group format) |
151 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
152 * | RP Count n | Frag RP Cnt n | Reserved |
153 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
154 * | RP Address 1 (Encoded-Unicast format) |
155 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
156 * | RP1 Holdtime | RP1 Priority | Reserved |
157 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
158 * | RP Address 2 (Encoded-Unicast format) |
159 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
160 * | RP2 Holdtime | RP2 Priority | Reserved |
161 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
162 * | . |
163 * | . |
164 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
165 * | RP Address m (Encoded-Unicast format) |
166 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
167 * | RPm Holdtime | RPm Priority | Reserved |
168 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
169 */
170 struct bsm_hdr {
171 uint16_t frag_tag;
172 uint8_t hm_len;
173 uint8_t bsr_prio;
174 #if PIM_IPV == 4
175 struct pim_encoded_ipv4_unicast bsr_addr;
176 #else
177 struct pim_encoded_ipv6_unicast bsr_addr;
178 #endif
179 } __attribute__((packed));
180
181 struct bsmmsg_grpinfo {
182 #if PIM_IPV == 4
183 struct pim_encoded_group_ipv4 group;
184 #else
185 struct pim_encoded_group_ipv6 group;
186 #endif
187 uint8_t rp_count;
188 uint8_t frag_rp_count;
189 uint16_t reserved;
190 } __attribute__((packed));
191
192 struct bsmmsg_rpinfo {
193 #if PIM_IPV == 4
194 struct pim_encoded_ipv4_unicast rpaddr;
195 #else
196 struct pim_encoded_ipv6_unicast rpaddr;
197 #endif
198 uint16_t rp_holdtime;
199 uint8_t rp_pri;
200 uint8_t reserved;
201 } __attribute__((packed));
202
203 /* API */
204 void pim_bsm_proc_init(struct pim_instance *pim);
205 void pim_bsm_proc_free(struct pim_instance *pim);
206 void pim_bsm_clear(struct pim_instance *pim);
207 void pim_bsm_write_config(struct vty *vty, struct interface *ifp);
208 int pim_bsm_process(struct interface *ifp, pim_sgaddr *sg, uint8_t *buf,
209 uint32_t buf_size, bool no_fwd);
210 bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp);
211 struct bsgrp_node *pim_bsm_get_bsgrp_node(struct bsm_scope *scope,
212 struct prefix *grp);
213 #endif