1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * pim_bsm.h: PIM BSM handling related
5 * Copyright (C) 2018-19 Vmware, Inc.
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 */
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)
29 #define PIM_MIN_BSM_LEN \
30 (PIM_HDR_LEN + PIM_BSM_HDR_LEN + PIM_BSM_GRP_LEN + PIM_BSM_RP_LEN)
36 /* Non candidate BSR states */
43 PREDECL_DLIST(bsm_frags
);
45 /* BSM scope - bsm processing is per 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 */
58 /* current set of fragments for forwarding */
59 struct bsm_frags_head bsm_frags
[1];
61 struct route_table
*bsrp_table
; /* group2rp mapping rcvd from BSR */
62 struct event
*bs_timer
; /* Boot strap timer */
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
69 struct bsm_frags_item item
;
71 uint32_t size
; /* size of the packet */
72 uint8_t data
[0]; /* Actual packet (dyn size) */
75 DECLARE_DLIST(bsm_frags
, struct bsm_frag
, item
);
77 PREDECL_SORTLIST_UNIQ(bsm_rpinfos
);
79 /* This is the group node of the bsrp table in scope.
80 * this node maintains the list of rp for the group.
83 struct prefix group
; /* Group range */
84 struct bsm_scope
*scope
; /* Back ptr to scope */
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];
90 int pend_rp_cnt
; /* Total RP - Received RP */
91 uint16_t frag_tag
; /* frag tag to identify the fragment */
94 /* Items on [partial_]bsrp_list above.
95 * Holds info of each candidate RP received for the bsgrp_node's prefix.
98 struct bsm_rpinfos_item item
;
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 */
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
);
113 /* Structures to extract Bootstrap Message header and Grp to RP Mappings
114 * =====================================================================
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141 * | RP Address m (Encoded-Unicast format) |
142 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 * | RPm Holdtime | RPm Priority | Reserved |
144 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 * | Group Address 2 (Encoded-Group format) |
146 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
164 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
165 * | RP Address m (Encoded-Unicast format) |
166 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
167 * | RPm Holdtime | RPm Priority | Reserved |
168 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
175 struct pim_encoded_ipv4_unicast bsr_addr
;
177 struct pim_encoded_ipv6_unicast bsr_addr
;
179 } __attribute__((packed
));
181 struct bsmmsg_grpinfo
{
183 struct pim_encoded_group_ipv4 group
;
185 struct pim_encoded_group_ipv6 group
;
188 uint8_t frag_rp_count
;
190 } __attribute__((packed
));
192 struct bsmmsg_rpinfo
{
194 struct pim_encoded_ipv4_unicast rpaddr
;
196 struct pim_encoded_ipv6_unicast rpaddr
;
198 uint16_t rp_holdtime
;
201 } __attribute__((packed
));
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
,