]>
Commit | Line | Data |
---|---|---|
e496b420 HS |
1 | /* |
2 | * SRv6 definitions | |
3 | * Copyright (C) 2020 Hiroki Shirokura, LINE Corporation | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the Free | |
7 | * Software Foundation; either version 2 of the License, or (at your option) | |
8 | * any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
19 | ||
20 | #ifndef _FRR_SRV6_H | |
21 | #define _FRR_SRV6_H | |
22 | ||
23 | #include <zebra.h> | |
f2867068 HS |
24 | #include "prefix.h" |
25 | #include "json.h" | |
26 | ||
e496b420 HS |
27 | #include <arpa/inet.h> |
28 | #include <netinet/in.h> | |
29 | ||
30 | #define SRV6_MAX_SIDS 16 | |
f2867068 | 31 | #define SRV6_LOCNAME_SIZE 256 |
e496b420 HS |
32 | |
33 | #ifdef __cplusplus | |
34 | extern "C" { | |
35 | #endif | |
36 | ||
37 | #define sid2str(sid, str, size) \ | |
38 | inet_ntop(AF_INET6, sid, str, size) | |
39 | ||
40 | enum seg6_mode_t { | |
41 | INLINE, | |
42 | ENCAP, | |
43 | L2ENCAP, | |
44 | }; | |
45 | ||
46 | enum seg6local_action_t { | |
47 | ZEBRA_SEG6_LOCAL_ACTION_UNSPEC = 0, | |
48 | ZEBRA_SEG6_LOCAL_ACTION_END = 1, | |
49 | ZEBRA_SEG6_LOCAL_ACTION_END_X = 2, | |
50 | ZEBRA_SEG6_LOCAL_ACTION_END_T = 3, | |
51 | ZEBRA_SEG6_LOCAL_ACTION_END_DX2 = 4, | |
52 | ZEBRA_SEG6_LOCAL_ACTION_END_DX6 = 5, | |
53 | ZEBRA_SEG6_LOCAL_ACTION_END_DX4 = 6, | |
54 | ZEBRA_SEG6_LOCAL_ACTION_END_DT6 = 7, | |
55 | ZEBRA_SEG6_LOCAL_ACTION_END_DT4 = 8, | |
56 | ZEBRA_SEG6_LOCAL_ACTION_END_B6 = 9, | |
57 | ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP = 10, | |
58 | ZEBRA_SEG6_LOCAL_ACTION_END_BM = 11, | |
59 | ZEBRA_SEG6_LOCAL_ACTION_END_S = 12, | |
60 | ZEBRA_SEG6_LOCAL_ACTION_END_AS = 13, | |
61 | ZEBRA_SEG6_LOCAL_ACTION_END_AM = 14, | |
62 | ZEBRA_SEG6_LOCAL_ACTION_END_BPF = 15, | |
63 | }; | |
64 | ||
65 | struct seg6_segs { | |
66 | size_t num_segs; | |
67 | struct in6_addr segs[256]; | |
68 | }; | |
69 | ||
70 | struct seg6local_context { | |
71 | struct in_addr nh4; | |
72 | struct in6_addr nh6; | |
73 | uint32_t table; | |
74 | }; | |
75 | ||
f2867068 HS |
76 | struct srv6_locator { |
77 | char name[SRV6_LOCNAME_SIZE]; | |
78 | struct prefix_ipv6 prefix; | |
ac6a9479 HS |
79 | |
80 | /* | |
81 | * Bit length of SRv6 locator described in | |
82 | * draft-ietf-bess-srv6-services-05#section-3.2.1 | |
83 | */ | |
84 | uint8_t block_bits_length; | |
85 | uint8_t node_bits_length; | |
f2867068 | 86 | uint8_t function_bits_length; |
ac6a9479 HS |
87 | uint8_t argument_bits_length; |
88 | ||
f2867068 HS |
89 | int algonum; |
90 | uint64_t current; | |
91 | bool status_up; | |
92 | struct list *chunks; | |
93 | ||
94 | QOBJ_FIELDS; | |
95 | }; | |
96 | DECLARE_QOBJ_TYPE(srv6_locator); | |
97 | ||
98 | struct srv6_locator_chunk { | |
ac6a9479 HS |
99 | char locator_name[SRV6_LOCNAME_SIZE]; |
100 | struct prefix_ipv6 prefix; | |
101 | ||
102 | /* | |
103 | * Bit length of SRv6 locator described in | |
104 | * draft-ietf-bess-srv6-services-05#section-3.2.1 | |
105 | */ | |
106 | uint8_t block_bits_length; | |
107 | uint8_t node_bits_length; | |
108 | uint8_t function_bits_length; | |
109 | uint8_t argument_bits_length; | |
110 | ||
111 | /* | |
112 | * For Zclient communication values | |
113 | */ | |
f2867068 HS |
114 | uint8_t keep; |
115 | uint8_t proto; | |
116 | uint16_t instance; | |
117 | uint32_t session_id; | |
f2867068 HS |
118 | }; |
119 | ||
eab0f8f0 HS |
120 | struct nexthop_srv6 { |
121 | /* SRv6 localsid info for Endpoint-behaviour */ | |
122 | enum seg6local_action_t seg6local_action; | |
123 | struct seg6local_context seg6local_ctx; | |
124 | ||
125 | /* SRv6 Headend-behaviour */ | |
126 | struct in6_addr seg6_segs; | |
127 | }; | |
128 | ||
e496b420 HS |
129 | static inline const char *seg6_mode2str(enum seg6_mode_t mode) |
130 | { | |
131 | switch (mode) { | |
132 | case INLINE: | |
133 | return "INLINE"; | |
134 | case ENCAP: | |
135 | return "ENCAP"; | |
136 | case L2ENCAP: | |
137 | return "L2ENCAP"; | |
138 | default: | |
139 | return "unknown"; | |
140 | } | |
141 | } | |
142 | ||
143 | static inline bool sid_same( | |
144 | const struct in6_addr *a, | |
145 | const struct in6_addr *b) | |
146 | { | |
147 | if (!a && !b) | |
148 | return true; | |
149 | else if (!(a && b)) | |
150 | return false; | |
151 | else | |
152 | return memcmp(a, b, sizeof(struct in6_addr)) == 0; | |
153 | } | |
154 | ||
155 | static inline bool sid_diff( | |
156 | const struct in6_addr *a, | |
157 | const struct in6_addr *b) | |
158 | { | |
159 | return !sid_same(a, b); | |
160 | } | |
161 | ||
162 | static inline bool sid_zero( | |
163 | const struct in6_addr *a) | |
164 | { | |
165 | struct in6_addr zero = {}; | |
166 | ||
167 | return sid_same(a, &zero); | |
168 | } | |
169 | ||
170 | static inline void *sid_copy(struct in6_addr *dst, | |
171 | const struct in6_addr *src) | |
172 | { | |
173 | return memcpy(dst, src, sizeof(struct in6_addr)); | |
174 | } | |
175 | ||
176 | const char * | |
177 | seg6local_action2str(uint32_t action); | |
178 | ||
7a4b49bd HS |
179 | const char *seg6local_context2str(char *str, size_t size, |
180 | const struct seg6local_context *ctx, | |
181 | uint32_t action); | |
e496b420 HS |
182 | |
183 | int snprintf_seg6_segs(char *str, | |
184 | size_t size, const struct seg6_segs *segs); | |
185 | ||
f2867068 HS |
186 | extern struct srv6_locator *srv6_locator_alloc(const char *name); |
187 | extern struct srv6_locator_chunk *srv6_locator_chunk_alloc(void); | |
188 | extern void srv6_locator_free(struct srv6_locator *locator); | |
189 | extern void srv6_locator_chunk_free(struct srv6_locator_chunk *chunk); | |
190 | json_object *srv6_locator_chunk_json(const struct srv6_locator_chunk *chunk); | |
191 | json_object *srv6_locator_json(const struct srv6_locator *loc); | |
559f4b2f YS |
192 | json_object *srv6_locator_detailed_json(const struct srv6_locator *loc); |
193 | json_object * | |
194 | srv6_locator_chunk_detailed_json(const struct srv6_locator_chunk *chunk); | |
f2867068 | 195 | |
e496b420 HS |
196 | #ifdef __cplusplus |
197 | } | |
198 | #endif | |
199 | ||
200 | #endif |