]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
cf9b9f77 OD |
2 | /* |
3 | * This is an implementation of Segment Routing | |
6f751f14 OD |
4 | * as per RFC 8665 - OSPF Extensions for Segment Routing |
5 | * and RFC 8476 - Signaling Maximum SID Depth (MSD) Using OSPF | |
cf9b9f77 OD |
6 | * |
7 | * Module name: Segment Routing header definitions | |
8 | * | |
9 | * Author: Olivier Dugeon <olivier.dugeon@orange.com> | |
10 | * Author: Anselme Sawadogo <anselmesawadogo@gmail.com> | |
11 | * | |
6f751f14 | 12 | * Copyright (C) 2016 - 2020 Orange Labs http://www.orange.com |
cf9b9f77 OD |
13 | */ |
14 | ||
15 | #ifndef _FRR_OSPF_SR_H | |
16 | #define _FRR_OSPF_SR_H | |
17 | ||
cf9b9f77 OD |
18 | /* macros and constants for segment routing */ |
19 | #define SET_RANGE_SIZE_MASK 0xffffff00 | |
20 | #define GET_RANGE_SIZE_MASK 0x00ffffff | |
21 | #define SET_LABEL_MASK 0xffffff00 | |
22 | #define GET_LABEL_MASK 0x00ffffff | |
23 | #define SET_RANGE_SIZE(range_size) ((range_size << 8) & SET_RANGE_SIZE_MASK) | |
24 | #define GET_RANGE_SIZE(range_size) ((range_size >> 8) & GET_RANGE_SIZE_MASK) | |
25 | #define SET_LABEL(label) ((label << 8) & SET_LABEL_MASK) | |
26 | #define GET_LABEL(label) ((label >> 8) & GET_LABEL_MASK) | |
27 | ||
6c57d010 FR |
28 | /* smallest configurable SRGB / SRLB sizes */ |
29 | #define MIN_SRLB_SIZE 16 | |
30 | #define MIN_SRGB_SIZE 16 | |
cf9b9f77 | 31 | |
6f751f14 | 32 | /* Segment Routing TLVs as per RFC 8665 */ |
cf9b9f77 OD |
33 | |
34 | /* Segment ID could be a Label (3 bytes) or an Index (4 bytes) */ | |
cf9b9f77 | 35 | #define SID_LABEL 3 |
d922605d | 36 | #define SID_LABEL_SIZE(U) (U - 1) |
cf9b9f77 | 37 | #define SID_INDEX 4 |
d922605d | 38 | #define SID_INDEX_SIZE(U) (U) |
cf9b9f77 | 39 | |
b37eb79c OD |
40 | /* Macro to log debug message */ |
41 | #define osr_debug(...) \ | |
42 | do { \ | |
43 | if (IS_DEBUG_OSPF_SR) \ | |
44 | zlog_debug(__VA_ARGS__); \ | |
45 | } while (0) | |
46 | ||
43e7abb5 OD |
47 | /* Macro to check if SR Prefix has no valid route */ |
48 | #define IS_NO_ROUTE(srp) ((srp->route == NULL) || (srp->route->paths == NULL) \ | |
49 | || list_isempty(srp->route->paths)) | |
50 | ||
cf9b9f77 OD |
51 | /* SID/Label Sub TLV - section 2.1 */ |
52 | #define SUBTLV_SID_LABEL 1 | |
bc298f5d | 53 | #define SUBTLV_SID_LABEL_SIZE 4 |
cf9b9f77 OD |
54 | struct subtlv_sid_label { |
55 | /* Length is 3 (20 rightmost bits MPLS label) or 4 (32 bits SID) */ | |
56 | struct tlv_header header; | |
93f0a26e | 57 | uint32_t value; |
cf9b9f77 OD |
58 | }; |
59 | ||
60 | /* | |
61 | * Following section defines Segment Routing TLV (tag, length, value) | |
62 | * structures, used in Router Information Opaque LSA. | |
63 | */ | |
64 | ||
65 | /* RI SR-Algorithm TLV - section 3.1 */ | |
66 | #define RI_SR_TLV_SR_ALGORITHM 8 | |
67 | struct ri_sr_tlv_sr_algorithm { | |
68 | struct tlv_header header; | |
69 | #define SR_ALGORITHM_SPF 0 | |
70 | #define SR_ALGORITHM_STRICT_SPF 1 | |
71 | #define SR_ALGORITHM_UNSET 255 | |
72 | #define ALGORITHM_COUNT 4 | |
73 | /* Only 4 algorithms supported in this code */ | |
93f0a26e | 74 | uint8_t value[ALGORITHM_COUNT]; |
cf9b9f77 OD |
75 | }; |
76 | ||
6f751f14 OD |
77 | /* RI SID/Label Range TLV used for SRGB & SRLB - section 3.2 & 3.3 */ |
78 | #define RI_SR_TLV_SRGB_LABEL_RANGE 9 | |
79 | #define RI_SR_TLV_SRLB_LABEL_RANGE 14 | |
8db278b5 | 80 | #define RI_SR_TLV_LABEL_RANGE_SIZE 12 |
cf9b9f77 OD |
81 | struct ri_sr_tlv_sid_label_range { |
82 | struct tlv_header header; | |
83 | /* Only 24 upper most bits are significant */ | |
84 | #define SID_RANGE_LABEL_LENGTH 3 | |
93f0a26e | 85 | uint32_t size; |
cf9b9f77 OD |
86 | /* A SID/Label sub-TLV will follow. */ |
87 | struct subtlv_sid_label lower; | |
88 | }; | |
89 | ||
6f751f14 | 90 | /* RI Node/MSD TLV as per RFC 8476 */ |
cf9b9f77 | 91 | #define RI_SR_TLV_NODE_MSD 12 |
8db278b5 | 92 | #define RI_SR_TLV_NODE_MSD_SIZE 4 |
cf9b9f77 OD |
93 | struct ri_sr_tlv_node_msd { |
94 | struct tlv_header header; | |
93f0a26e OD |
95 | uint8_t subtype; /* always = 1 */ |
96 | uint8_t value; | |
97 | uint16_t padding; | |
cf9b9f77 OD |
98 | }; |
99 | ||
100 | /* | |
101 | * Following section defines Segment Routing TLV (tag, length, value) | |
102 | * structures, used in Extended Prefix/Link Opaque LSA. | |
103 | */ | |
104 | ||
105 | /* Adj-SID and LAN-Ajd-SID subtlvs' flags */ | |
106 | #define EXT_SUBTLV_LINK_ADJ_SID_BFLG 0x80 | |
107 | #define EXT_SUBTLV_LINK_ADJ_SID_VFLG 0x40 | |
108 | #define EXT_SUBTLV_LINK_ADJ_SID_LFLG 0x20 | |
109 | #define EXT_SUBTLV_LINK_ADJ_SID_SFLG 0x10 | |
110 | ||
111 | /* Prefix SID subtlv Flags */ | |
112 | #define EXT_SUBTLV_PREFIX_SID_NPFLG 0x40 | |
113 | #define EXT_SUBTLV_PREFIX_SID_MFLG 0x20 | |
114 | #define EXT_SUBTLV_PREFIX_SID_EFLG 0x10 | |
115 | #define EXT_SUBTLV_PREFIX_SID_VFLG 0x08 | |
116 | #define EXT_SUBTLV_PREFIX_SID_LFLG 0x04 | |
117 | ||
118 | /* SID/Label Binding subtlv Flags */ | |
119 | #define EXT_SUBTLV_SID_BINDING_MFLG 0x80 | |
120 | ||
121 | /* Extended Prefix Range TLV - section 4 */ | |
122 | #define EXT_TLV_PREF_RANGE 2 | |
123 | #define EXT_SUBTLV_PREFIX_RANGE_SIZE 12 | |
124 | struct ext_tlv_prefix_range { | |
125 | struct tlv_header header; | |
93f0a26e OD |
126 | uint8_t pref_length; |
127 | uint8_t af; | |
128 | uint16_t range_size; | |
129 | uint8_t flags; | |
130 | uint8_t reserved[3]; | |
cf9b9f77 OD |
131 | struct in_addr address; |
132 | }; | |
133 | ||
134 | /* Prefix SID Sub-TLV - section 5 */ | |
135 | #define EXT_SUBTLV_PREFIX_SID 2 | |
136 | #define EXT_SUBTLV_PREFIX_SID_SIZE 8 | |
137 | struct ext_subtlv_prefix_sid { | |
138 | struct tlv_header header; | |
93f0a26e OD |
139 | uint8_t flags; |
140 | uint8_t reserved; | |
141 | uint8_t mtid; | |
142 | uint8_t algorithm; | |
143 | uint32_t value; | |
cf9b9f77 OD |
144 | }; |
145 | ||
146 | /* Adj-SID Sub-TLV - section 6.1 */ | |
147 | #define EXT_SUBTLV_ADJ_SID 2 | |
148 | #define EXT_SUBTLV_ADJ_SID_SIZE 8 | |
149 | struct ext_subtlv_adj_sid { | |
150 | struct tlv_header header; | |
93f0a26e OD |
151 | uint8_t flags; |
152 | uint8_t reserved; | |
153 | uint8_t mtid; | |
154 | uint8_t weight; | |
155 | uint32_t value; | |
cf9b9f77 OD |
156 | }; |
157 | ||
158 | /* LAN Adj-SID Sub-TLV - section 6.2 */ | |
159 | #define EXT_SUBTLV_LAN_ADJ_SID 3 | |
160 | #define EXT_SUBTLV_LAN_ADJ_SID_SIZE 12 | |
161 | struct ext_subtlv_lan_adj_sid { | |
162 | struct tlv_header header; | |
93f0a26e OD |
163 | uint8_t flags; |
164 | uint8_t reserved; | |
165 | uint8_t mtid; | |
166 | uint8_t weight; | |
cf9b9f77 | 167 | struct in_addr neighbor_id; |
93f0a26e | 168 | uint32_t value; |
cf9b9f77 OD |
169 | }; |
170 | ||
171 | /* | |
172 | * Following section define structure used to manage Segment Routing | |
173 | * information and TLVs / SubTLVs | |
174 | */ | |
6f751f14 OD |
175 | /* Default min and size of SR Global Block label range */ |
176 | #define DEFAULT_SRGB_LABEL 16000 | |
177 | #define DEFAULT_SRGB_SIZE 8000 | |
6443a4be | 178 | #define DEFAULT_SRGB_END (DEFAULT_SRGB_LABEL + DEFAULT_SRGB_SIZE - 1) |
6f751f14 OD |
179 | |
180 | /* Default min and size of SR Local Block label range */ | |
181 | #define DEFAULT_SRLB_LABEL 15000 | |
182 | #define DEFAULT_SRLB_SIZE 1000 | |
6443a4be | 183 | #define DEFAULT_SRLB_END (DEFAULT_SRLB_LABEL + DEFAULT_SRLB_SIZE - 1) |
cf9b9f77 | 184 | |
6f751f14 OD |
185 | /* Structure aggregating SR Range Block info retrieved from an lsa */ |
186 | struct sr_block { | |
93f0a26e OD |
187 | uint32_t range_size; |
188 | uint32_t lower_bound; | |
cf9b9f77 OD |
189 | }; |
190 | ||
6f751f14 OD |
191 | /* Segment Routing Global Block allocation */ |
192 | struct sr_global_block { | |
193 | bool reserved; | |
194 | uint32_t start; | |
195 | uint32_t size; | |
196 | }; | |
197 | ||
198 | /* Segment Routing Local Block allocation */ | |
199 | struct sr_local_block { | |
200 | bool reserved; | |
201 | uint32_t start; | |
202 | uint32_t end; | |
203 | uint32_t current; | |
204 | uint32_t max_block; | |
205 | uint64_t *used_mark; | |
206 | }; | |
207 | #define SRLB_BLOCK_SIZE 64 | |
208 | ||
cf9b9f77 | 209 | /* SID type to make difference between loopback interfaces and others */ |
b37eb79c | 210 | enum sid_type { PREF_SID, LOCAL_SID, ADJ_SID, LAN_ADJ_SID }; |
cf9b9f77 | 211 | |
d81b8e0e | 212 | /* Status of Segment Routing: Off (Disable), On (Enable), (Up) Started */ |
2110d03e | 213 | enum sr_status { SR_OFF, SR_ON, SR_UP }; |
d81b8e0e | 214 | |
cf9b9f77 OD |
215 | /* Structure aggregating all OSPF Segment Routing information for the node */ |
216 | struct ospf_sr_db { | |
d81b8e0e OD |
217 | /* Status of Segment Routing */ |
218 | enum sr_status status; | |
cf9b9f77 | 219 | |
cf9b9f77 | 220 | /* Flooding Scope: Area = 10 or AS = 11 */ |
93f0a26e | 221 | uint8_t scope; |
cf9b9f77 OD |
222 | |
223 | /* FRR SR node */ | |
224 | struct sr_node *self; | |
225 | ||
226 | /* List of neighbour SR nodes */ | |
227 | struct hash *neighbors; | |
228 | ||
cf9b9f77 OD |
229 | /* Local SR info announced in Router Info LSA */ |
230 | ||
231 | /* Algorithms supported by the node */ | |
93f0a26e | 232 | uint8_t algo[ALGORITHM_COUNT]; |
cf9b9f77 OD |
233 | /* |
234 | * Segment Routing Global Block i.e. label range | |
235 | * Only one range supported in this code | |
236 | */ | |
6f751f14 | 237 | struct sr_global_block srgb; |
d81b8e0e | 238 | |
6f751f14 OD |
239 | /* Segment Routing Local Block */ |
240 | struct sr_local_block srlb; | |
d81b8e0e | 241 | |
cf9b9f77 | 242 | /* Maximum SID Depth supported by the node */ |
93f0a26e | 243 | uint8_t msd; |
6f751f14 OD |
244 | |
245 | /* Thread timer to start Label Manager */ | |
246 | struct thread *t_start_lm; | |
cf9b9f77 OD |
247 | }; |
248 | ||
249 | /* Structure aggregating all received SR info from LSAs by node */ | |
250 | struct sr_node { | |
251 | struct in_addr adv_router; /* used to identify sender of LSA */ | |
252 | /* 24-bit Opaque-ID field value according to RFC 7684 specification */ | |
93f0a26e | 253 | uint32_t instance; |
cf9b9f77 | 254 | |
93f0a26e | 255 | uint8_t algo[ALGORITHM_COUNT]; /* Algorithms supported by the node */ |
6f751f14 OD |
256 | struct sr_block srgb; /* Segment Routing Global Block */ |
257 | struct sr_block srlb; /* Segment Routing Local Block */ | |
258 | uint8_t msd; /* Maximum SID Depth */ | |
cf9b9f77 OD |
259 | |
260 | /* List of Prefix & Link advertise by this node */ | |
261 | struct list *ext_prefix; /* For Node SID */ | |
edb368e9 | 262 | struct list *ext_link; /* For Adjacency SID */ |
cf9b9f77 OD |
263 | |
264 | /* Pointer to FRR SR-Node or NULL if it is not a neighbor */ | |
265 | struct sr_node *neighbor; | |
266 | }; | |
267 | ||
cf9b9f77 OD |
268 | /* Segment Routing - NHLFE info: support IPv4 Only */ |
269 | struct sr_nhlfe { | |
cf9b9f77 OD |
270 | struct in_addr nexthop; |
271 | ifindex_t ifindex; | |
272 | mpls_label_t label_in; | |
273 | mpls_label_t label_out; | |
274 | }; | |
275 | ||
276 | /* Structure aggregating all Segment Routing Link information */ | |
277 | /* Link are generally advertised by pair: primary + backup */ | |
278 | struct sr_link { | |
279 | struct in_addr adv_router; /* used to identify sender of LSA */ | |
280 | /* 24-bit Opaque-ID field value according to RFC 7684 specification */ | |
93f0a26e | 281 | uint32_t instance; |
cf9b9f77 | 282 | |
cc1725bd G |
283 | /* Addressed (remote) router id */ |
284 | struct in_addr remote_id; | |
285 | ||
b37eb79c OD |
286 | /* Interface address */ |
287 | struct in_addr itf_addr; | |
288 | ||
cf9b9f77 | 289 | /* Flags to manage this link parameters. */ |
7743f2f8 | 290 | uint8_t flags[2]; |
cf9b9f77 OD |
291 | |
292 | /* Segment Routing ID */ | |
93f0a26e | 293 | uint32_t sid[2]; |
cf9b9f77 OD |
294 | enum sid_type type; |
295 | ||
b37eb79c | 296 | /* SR NHLFE (Primary + Backup) for this link */ |
cf9b9f77 OD |
297 | struct sr_nhlfe nhlfe[2]; |
298 | ||
299 | /* Back pointer to SR Node which advertise this Link */ | |
300 | struct sr_node *srn; | |
301 | }; | |
302 | ||
303 | /* Structure aggregating all Segment Routing Prefix information */ | |
304 | struct sr_prefix { | |
305 | struct in_addr adv_router; /* used to identify sender of LSA */ | |
306 | /* 24-bit Opaque-ID field value according to RFC 7684 specification */ | |
93f0a26e | 307 | uint32_t instance; |
cf9b9f77 | 308 | |
b37eb79c OD |
309 | /* Prefix itself */ |
310 | struct prefix_ipv4 prefv4; | |
311 | ||
cf9b9f77 | 312 | /* Flags to manage this prefix parameters. */ |
7743f2f8 | 313 | uint8_t flags; |
cf9b9f77 OD |
314 | |
315 | /* Segment Routing ID */ | |
93f0a26e | 316 | uint32_t sid; |
cf9b9f77 OD |
317 | enum sid_type type; |
318 | ||
b37eb79c OD |
319 | /* Incoming label for this prefix */ |
320 | mpls_label_t label_in; | |
321 | ||
322 | /* Back pointer to OSPF Route for remote prefix */ | |
b61264a8 | 323 | struct ospf_route *route; |
b37eb79c OD |
324 | |
325 | /* NHLFE for local prefix */ | |
cf9b9f77 OD |
326 | struct sr_nhlfe nhlfe; |
327 | ||
328 | /* Back pointer to SR Node which advertise this Prefix */ | |
329 | struct sr_node *srn; | |
cf9b9f77 OD |
330 | }; |
331 | ||
332 | /* Prototypes definition */ | |
333 | /* Segment Routing initialisation functions */ | |
334 | extern int ospf_sr_init(void); | |
335 | extern void ospf_sr_term(void); | |
bcf4475e | 336 | extern void ospf_sr_finish(void); |
6f751f14 OD |
337 | /* Segment Routing label allocation functions */ |
338 | extern mpls_label_t ospf_sr_local_block_request_label(void); | |
339 | extern int ospf_sr_local_block_release_label(mpls_label_t label); | |
cf9b9f77 OD |
340 | /* Segment Routing LSA update & delete functions */ |
341 | extern void ospf_sr_ri_lsa_update(struct ospf_lsa *lsa); | |
342 | extern void ospf_sr_ri_lsa_delete(struct ospf_lsa *lsa); | |
7743f2f8 OD |
343 | extern void ospf_sr_ext_link_lsa_update(struct ospf_lsa *lsa); |
344 | extern void ospf_sr_ext_link_lsa_delete(struct ospf_lsa *lsa); | |
345 | extern void ospf_sr_ext_prefix_lsa_update(struct ospf_lsa *lsa); | |
346 | extern void ospf_sr_ext_prefix_lsa_delete(struct ospf_lsa *lsa); | |
21baf89a OD |
347 | /* Segment Routing Extending Link management */ |
348 | struct ext_itf; | |
349 | extern void ospf_sr_ext_itf_add(struct ext_itf *exti); | |
350 | extern void ospf_sr_ext_itf_delete(struct ext_itf *exti); | |
cf9b9f77 | 351 | /* Segment Routing configuration functions */ |
7743f2f8 | 352 | extern void ospf_sr_config_write_router(struct vty *vty); |
b61264a8 OD |
353 | extern void ospf_sr_update_local_prefix(struct interface *ifp, |
354 | struct prefix *p); | |
cf9b9f77 | 355 | /* Segment Routing re-routing function */ |
b37eb79c | 356 | extern void ospf_sr_update_task(struct ospf *ospf); |
7fd0729f G |
357 | |
358 | /* Support for TI-LFA */ | |
359 | extern mpls_label_t ospf_sr_get_prefix_sid_by_id(struct in_addr *id); | |
cc1725bd G |
360 | extern mpls_label_t ospf_sr_get_adj_sid_by_id(struct in_addr *root_id, |
361 | struct in_addr *neighbor_id); | |
7fd0729f G |
362 | extern struct sr_node *ospf_sr_node_create(struct in_addr *rid); |
363 | ||
cf9b9f77 | 364 | #endif /* _FRR_OSPF_SR_H */ |