]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
361b5843 | 2 | /* |
3 | * pim_bsm.h: PIM BSM handling related | |
4 | * | |
5 | * Copyright (C) 2018-19 Vmware, Inc. | |
6 | * Saravanan K | |
361b5843 | 7 | */ |
8 | ||
9 | #ifndef __PIM_BSM_H__ | |
10 | #define __PIM_BSM_H__ | |
11 | ||
12 | #include "if.h" | |
13 | #include "vty.h" | |
d4a4525c | 14 | #include "typesafe.h" |
361b5843 | 15 | #include "table.h" |
16 | #include "pim_rp.h" | |
17 | #include "pim_msg.h" | |
18 | ||
19 | /* Defines */ | |
d0e418b4 | 20 | #define PIM_GBL_SZ_ID 0 /* global scope zone id set to 0 */ |
21 | #define PIM_BS_TIME 60 /* RFC 5059 - Sec 5 */ | |
361b5843 | 22 | #define PIM_BSR_DEFAULT_TIMEOUT 130 /* RFC 5059 - Sec 5 */ |
23 | ||
24 | /* These structures are only encoded IPv4 specific */ | |
d0e418b4 | 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) | |
361b5843 | 31 | |
361b5843 | 32 | /* Datastructures |
33 | * ============== | |
34 | */ | |
35 | ||
36 | /* Non candidate BSR states */ | |
d0e418b4 | 37 | enum ncbsr_state { |
361b5843 | 38 | NO_INFO = 0, |
39 | ACCEPT_ANY, | |
40 | ACCEPT_PREFERRED | |
41 | }; | |
42 | ||
d4a4525c DL |
43 | PREDECL_DLIST(bsm_frags); |
44 | ||
361b5843 | 45 | /* BSM scope - bsm processing is per scope */ |
46 | struct bsm_scope { | |
d0e418b4 | 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 */ | |
e309769a | 50 | pim_addr current_bsr; /* current elected BSR for the sz */ |
361b5843 | 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 */ | |
d0e418b4 | 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 */ | |
361b5843 | 56 | struct pim_instance *pim; /* Back pointer to pim instance */ |
d4a4525c DL |
57 | |
58 | /* current set of fragments for forwarding */ | |
59 | struct bsm_frags_head bsm_frags[1]; | |
60 | ||
361b5843 | 61 | struct route_table *bsrp_table; /* group2rp mapping rcvd from BSR */ |
e6685141 | 62 | struct event *bs_timer; /* Boot strap timer */ |
361b5843 | 63 | }; |
64 | ||
d4a4525c | 65 | /* BSM packet (= fragment) - this is stored as list in bsm_frags inside scope |
361b5843 | 66 | * This is used for forwarding to new neighbors or restarting mcast routers |
67 | */ | |
d4a4525c DL |
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) */ | |
361b5843 | 73 | }; |
74 | ||
d4a4525c DL |
75 | DECLARE_DLIST(bsm_frags, struct bsm_frag, item); |
76 | ||
fdab2940 DL |
77 | PREDECL_SORTLIST_UNIQ(bsm_rpinfos); |
78 | ||
361b5843 | 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 { | |
d0e418b4 | 83 | struct prefix group; /* Group range */ |
84 | struct bsm_scope *scope; /* Back ptr to scope */ | |
fdab2940 DL |
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 | ||
d0e418b4 | 90 | int pend_rp_cnt; /* Total RP - Received RP */ |
91 | uint16_t frag_tag; /* frag tag to identify the fragment */ | |
361b5843 | 92 | }; |
93 | ||
fdab2940 DL |
94 | /* Items on [partial_]bsrp_list above. |
95 | * Holds info of each candidate RP received for the bsgrp_node's prefix. | |
361b5843 | 96 | */ |
97 | struct bsm_rpinfo { | |
fdab2940 DL |
98 | struct bsm_rpinfos_item item; |
99 | ||
361b5843 | 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 */ | |
6ed1cea1 | 104 | pim_addr rp_address; /* RP Address */ |
361b5843 | 105 | struct bsgrp_node *bsgrp_node; /* Back ptr to bsgrp_node */ |
e6685141 | 106 | struct event *g2rp_timer; /* Run only for elected RP node */ |
361b5843 | 107 | }; |
108 | ||
fdab2940 DL |
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 | ||
361b5843 | 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; | |
1ae87bdd | 174 | #if PIM_IPV == 4 |
361b5843 | 175 | struct pim_encoded_ipv4_unicast bsr_addr; |
1ae87bdd | 176 | #else |
177 | struct pim_encoded_ipv6_unicast bsr_addr; | |
178 | #endif | |
d0e418b4 | 179 | } __attribute__((packed)); |
361b5843 | 180 | |
181 | struct bsmmsg_grpinfo { | |
81a688bc | 182 | #if PIM_IPV == 4 |
361b5843 | 183 | struct pim_encoded_group_ipv4 group; |
81a688bc | 184 | #else |
185 | struct pim_encoded_group_ipv6 group; | |
186 | #endif | |
361b5843 | 187 | uint8_t rp_count; |
188 | uint8_t frag_rp_count; | |
189 | uint16_t reserved; | |
d0e418b4 | 190 | } __attribute__((packed)); |
361b5843 | 191 | |
192 | struct bsmmsg_rpinfo { | |
1407e40f | 193 | #if PIM_IPV == 4 |
361b5843 | 194 | struct pim_encoded_ipv4_unicast rpaddr; |
1407e40f | 195 | #else |
196 | struct pim_encoded_ipv6_unicast rpaddr; | |
197 | #endif | |
361b5843 | 198 | uint16_t rp_holdtime; |
199 | uint8_t rp_pri; | |
200 | uint8_t reserved; | |
d0e418b4 | 201 | } __attribute__((packed)); |
361b5843 | 202 | |
203 | /* API */ | |
204 | void pim_bsm_proc_init(struct pim_instance *pim); | |
205 | void pim_bsm_proc_free(struct pim_instance *pim); | |
b09bd804 | 206 | void pim_bsm_clear(struct pim_instance *pim); |
16c926c8 | 207 | void pim_bsm_write_config(struct vty *vty, struct interface *ifp); |
76bfa030 MR |
208 | int pim_bsm_process(struct interface *ifp, pim_sgaddr *sg, uint8_t *buf, |
209 | uint32_t buf_size, bool no_fwd); | |
6bb2ef35 | 210 | bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp); |
d0e418b4 | 211 | struct bsgrp_node *pim_bsm_get_bsgrp_node(struct bsm_scope *scope, |
212 | struct prefix *grp); | |
361b5843 | 213 | #endif |