]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_sr.h
Merge pull request #12934 from LabNConsulting/ziemba/rfapi-memleak-cleanup-12478
[mirror_frr.git] / isisd / isis_sr.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
26f6acaf 2/*
f2333421 3 * This is an implementation of Segment Routing for IS-IS as per RFC 8667
26f6acaf 4 *
f2333421 5 * Copyright (C) 2019 Orange http://www.orange.com
26f6acaf
RW
6 *
7 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
8 * Contributor: Renato Westphal <renato@opensourcerouting.org> for NetDEF
26f6acaf
RW
9 */
10
11#ifndef _FRR_ISIS_SR_H
12#define _FRR_ISIS_SR_H
13
14#include "lib/linklist.h"
15#include "lib/mpls.h"
16#include "lib/nexthop.h"
17#include "lib/typesafe.h"
18
19#include "isisd/isis_tlvs.h"
20
21/*
22 * Segment Routing information is transported through the following Sub-TLVs:
23 *
24 * Sub-TLV Name Value TLVs
25 * ---------------------------------------------------------------------
26 * SID Label 1
27 *
28 * Prefix Segment Identifier 3 135, 235, 236 and 237
29 *
30 * Adjacency Segment Identifier 31 22, 23, 141, 222 and 223
31 * LAN Adjacency Segment Identifier 32 22, 23, 141, 222 and 223
32 *
33 * Segment Routing Capability 2 242
34 * Segment Routing Algorithm 19 242
35 * Node Maximum Stack Depth (MSD) 23 242
36 *
37 * Sub-TLV definitions, serialization and de-serialization are defined
38 * in isis_tlvs.[c,h].
39 */
40
41#define SRGB_LOWER_BOUND 16000
42#define SRGB_UPPER_BOUND 23999
d8391312
OD
43#define SRLB_LOWER_BOUND 15000
44#define SRLB_UPPER_BOUND 15999
26f6acaf 45
f2333421 46/* Segment Routing Data Base (SRDB) RB-Tree structure */
960b9a53 47PREDECL_RBTREE_UNIQ(srdb_prefix_cfg);
26f6acaf 48
d47d6089
RW
49/*
50 * Segment Routing Prefix-SID information.
51 *
52 * This structure is intended to be embedded inside other structures that
53 * might or might not contain Prefix-SID information.
54 */
55struct isis_sr_psid_info {
56 /* Prefix-SID Sub-TLV information. */
57 struct isis_prefix_sid sid;
58
59 /* Resolved input/output label. */
60 mpls_label_t label;
61
62 /* Indicates whether the Prefix-SID is present or not. */
63 bool present;
64};
65
d8391312
OD
66/* Segment Routing Local Block allocation */
67struct sr_local_block {
58fbcdf2 68 bool active;
d8391312
OD
69 uint32_t start;
70 uint32_t end;
71 uint32_t current;
72 uint32_t max_block;
73 uint64_t *used_mark;
74};
75#define SRLB_BLOCK_SIZE 64
76
f2333421 77/* Segment Routing Adjacency-SID type. */
26f6acaf
RW
78enum sr_adj_type {
79 ISIS_SR_ADJ_NORMAL = 0,
80 ISIS_SR_LAN_BACKUP,
81};
82
f2333421 83/* Segment Routing Adjacency. */
26f6acaf
RW
84struct sr_adjacency {
85 /* Adjacency type. */
86 enum sr_adj_type type;
87
054fda12
RW
88 /* Adjacency-SID input label. */
89 mpls_label_t input_label;
90
f2333421 91 /* Adjacency-SID nexthop information. */
26f6acaf
RW
92 struct {
93 int family;
94 union g_addr address;
26f6acaf
RW
95 } nexthop;
96
054fda12
RW
97 /* Adjacency-SID TI-LFA backup nexthops. */
98 struct list *backup_nexthops;
99
f2333421 100 /* (LAN-)Adjacency-SID Sub-TLV. */
26f6acaf
RW
101 union {
102 struct isis_adj_sid *adj_sid;
103 struct isis_lan_adj_sid *ladj_sid;
104 } u;
105
106 /* Back pointer to IS-IS adjacency. */
107 struct isis_adjacency *adj;
108};
109
f2333421 110/* SID type. NOTE: these values must be in sync with the YANG module. */
26f6acaf
RW
111enum sr_sid_value_type {
112 SR_SID_VALUE_TYPE_INDEX = 0,
113 SR_SID_VALUE_TYPE_ABSOLUTE = 1,
114};
115
b407c77a
OD
116#define IS_SID_VALUE(flag) CHECK_FLAG(flag, ISIS_PREFIX_SID_VALUE)
117
f2333421 118/* Last Hop Behavior. NOTE: these values must be in sync with the YANG module */
26f6acaf
RW
119enum sr_last_hop_behavior {
120 SR_LAST_HOP_BEHAVIOR_EXP_NULL = 0,
121 SR_LAST_HOP_BEHAVIOR_NO_PHP = 1,
122 SR_LAST_HOP_BEHAVIOR_PHP = 2,
123};
124
f2333421 125/* Segment Routing Prefix-SID configuration. */
26f6acaf 126struct sr_prefix_cfg {
f2333421 127 /* SRDB RB-tree entry. */
cab10e86 128 struct srdb_prefix_cfg_item entry;
26f6acaf
RW
129
130 /* IP prefix. */
131 struct prefix prefix;
132
133 /* SID value. */
134 uint32_t sid;
135
136 /* SID value type. */
137 enum sr_sid_value_type sid_type;
138
139 /* SID last hop behavior. */
140 enum sr_last_hop_behavior last_hop_behavior;
141
01983712
RW
142 /* Indicates whether the node flag must be explicitly unset. */
143 bool n_flag_clear;
144
26f6acaf
RW
145 /* Does this Prefix-SID refer to a loopback address (Node-SID)? */
146 bool node_sid;
147
148 /* Backpointer to IS-IS area. */
149 struct isis_area *area;
150};
151
f2333421 152/* Per-area IS-IS Segment Routing Data Base (SRDB). */
26f6acaf 153struct isis_sr_db {
f2333421 154 /* Global Operational status of Segment Routing. */
26f6acaf
RW
155 bool enabled;
156
58fbcdf2
OD
157 /* Thread timer to start Label Manager */
158 struct thread *t_start_lm;
159
f2333421 160 /* List of local Adjacency-SIDs. */
26f6acaf
RW
161 struct list *adj_sids;
162
58fbcdf2 163 /* Management of SRLB & SRGB allocation */
d8391312 164 struct sr_local_block srlb;
58fbcdf2 165 bool srgb_active;
d8391312 166
f2333421 167 /* Area Segment Routing configuration. */
26f6acaf
RW
168 struct {
169 /* Administrative status of Segment Routing. */
170 bool enabled;
171
172 /* Segment Routing Global Block lower & upper bound. */
173 uint32_t srgb_lower_bound;
174 uint32_t srgb_upper_bound;
175
d8391312
OD
176 /* Segment Routing Local Block lower & upper bound. */
177 uint32_t srlb_lower_bound;
178 uint32_t srlb_upper_bound;
179
26f6acaf
RW
180 /* Maximum SID Depth supported by the node. */
181 uint8_t msd;
182
183 /* Prefix-SID mappings. */
cab10e86 184 struct srdb_prefix_cfg_head prefix_sids;
26f6acaf
RW
185 } config;
186};
187
188/* Prototypes. */
d47d6089
RW
189extern struct isis_sr_block *isis_sr_find_srgb(struct lspdb_head *lspdb,
190 const uint8_t *sysid);
191extern mpls_label_t sr_prefix_in_label(struct isis_area *area,
192 struct isis_prefix_sid *psid,
193 bool local);
194extern mpls_label_t sr_prefix_out_label(struct lspdb_head *lspdb, int family,
195 struct isis_prefix_sid *psid,
196 const uint8_t *nh_sysid, bool last_hop);
26f6acaf
RW
197extern int isis_sr_cfg_srgb_update(struct isis_area *area, uint32_t lower_bound,
198 uint32_t upper_bound);
d8391312
OD
199extern int isis_sr_cfg_srlb_update(struct isis_area *area, uint32_t lower_bound,
200 uint32_t upper_bound);
26f6acaf
RW
201extern struct sr_prefix_cfg *
202isis_sr_cfg_prefix_add(struct isis_area *area, const struct prefix *prefix);
203extern void isis_sr_cfg_prefix_del(struct sr_prefix_cfg *pcfg);
204extern struct sr_prefix_cfg *
205isis_sr_cfg_prefix_find(struct isis_area *area, union prefixconstptr prefix);
206extern void isis_sr_prefix_cfg2subtlv(const struct sr_prefix_cfg *pcfg,
207 bool external,
208 struct isis_prefix_sid *psid);
054fda12
RW
209extern void sr_adj_sid_add_single(struct isis_adjacency *adj, int family,
210 bool backup, struct list *nexthops);
211extern struct sr_adjacency *isis_sr_adj_sid_find(struct isis_adjacency *adj,
212 int family,
213 enum sr_adj_type type);
214extern void isis_area_delete_backup_adj_sids(struct isis_area *area, int level);
d47d6089
RW
215extern char *sr_op2str(char *buf, size_t size, mpls_label_t label_in,
216 mpls_label_t label_out);
26f6acaf
RW
217extern int isis_sr_start(struct isis_area *area);
218extern void isis_sr_stop(struct isis_area *area);
219extern void isis_sr_area_init(struct isis_area *area);
220extern void isis_sr_area_term(struct isis_area *area);
221extern void isis_sr_init(void);
222extern void isis_sr_term(void);
223
224#endif /* _FRR_ISIS_SR_H */