1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2020 Hiroki Shirokura, LINE Corporation
14 #include <arpa/inet.h>
15 #include <netinet/in.h>
17 #define SRV6_MAX_SIDS 16
18 #define SRV6_LOCNAME_SIZE 256
24 #define sid2str(sid, str, size) \
25 inet_ntop(AF_INET6, sid, str, size)
33 enum seg6local_action_t
{
34 ZEBRA_SEG6_LOCAL_ACTION_UNSPEC
= 0,
35 ZEBRA_SEG6_LOCAL_ACTION_END
= 1,
36 ZEBRA_SEG6_LOCAL_ACTION_END_X
= 2,
37 ZEBRA_SEG6_LOCAL_ACTION_END_T
= 3,
38 ZEBRA_SEG6_LOCAL_ACTION_END_DX2
= 4,
39 ZEBRA_SEG6_LOCAL_ACTION_END_DX6
= 5,
40 ZEBRA_SEG6_LOCAL_ACTION_END_DX4
= 6,
41 ZEBRA_SEG6_LOCAL_ACTION_END_DT6
= 7,
42 ZEBRA_SEG6_LOCAL_ACTION_END_DT4
= 8,
43 ZEBRA_SEG6_LOCAL_ACTION_END_B6
= 9,
44 ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP
= 10,
45 ZEBRA_SEG6_LOCAL_ACTION_END_BM
= 11,
46 ZEBRA_SEG6_LOCAL_ACTION_END_S
= 12,
47 ZEBRA_SEG6_LOCAL_ACTION_END_AS
= 13,
48 ZEBRA_SEG6_LOCAL_ACTION_END_AM
= 14,
49 ZEBRA_SEG6_LOCAL_ACTION_END_BPF
= 15,
50 ZEBRA_SEG6_LOCAL_ACTION_END_DT46
= 16,
55 struct in6_addr segs
[256];
58 struct seg6local_context
{
65 char name
[SRV6_LOCNAME_SIZE
];
66 struct prefix_ipv6 prefix
;
69 * Bit length of SRv6 locator described in
70 * draft-ietf-bess-srv6-services-05#section-3.2.1
72 uint8_t block_bits_length
;
73 uint8_t node_bits_length
;
74 uint8_t function_bits_length
;
75 uint8_t argument_bits_length
;
83 #define SRV6_LOCATOR_USID (1 << 0) /* The SRv6 Locator is a uSID Locator */
87 DECLARE_QOBJ_TYPE(srv6_locator
);
89 struct srv6_locator_chunk
{
90 char locator_name
[SRV6_LOCNAME_SIZE
];
91 struct prefix_ipv6 prefix
;
94 * Bit length of SRv6 locator described in
95 * draft-ietf-bess-srv6-services-05#section-3.2.1
97 uint8_t block_bits_length
;
98 uint8_t node_bits_length
;
99 uint8_t function_bits_length
;
100 uint8_t argument_bits_length
;
103 * For Zclient communication values
114 * SRv6 Endpoint Behavior codepoints, as defined by IANA in
115 * https://www.iana.org/assignments/segment-routing/segment-routing.xhtml
117 enum srv6_endpoint_behavior_codepoint
{
118 SRV6_ENDPOINT_BEHAVIOR_RESERVED
= 0x0000,
119 SRV6_ENDPOINT_BEHAVIOR_END_DT6
= 0x0012,
120 SRV6_ENDPOINT_BEHAVIOR_END_DT4
= 0x0013,
121 SRV6_ENDPOINT_BEHAVIOR_END_DT46
= 0x0014,
122 SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID
= 0x003E,
123 SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID
= 0x003F,
124 SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID
= 0x0040,
125 SRV6_ENDPOINT_BEHAVIOR_OPAQUE
= 0xFFFF,
128 struct nexthop_srv6
{
129 /* SRv6 localsid info for Endpoint-behaviour */
130 enum seg6local_action_t seg6local_action
;
131 struct seg6local_context seg6local_ctx
;
133 /* SRv6 Headend-behaviour */
134 struct in6_addr seg6_segs
;
137 static inline const char *seg6_mode2str(enum seg6_mode_t mode
)
151 static inline bool sid_same(
152 const struct in6_addr
*a
,
153 const struct in6_addr
*b
)
160 return memcmp(a
, b
, sizeof(struct in6_addr
)) == 0;
163 static inline bool sid_diff(
164 const struct in6_addr
*a
,
165 const struct in6_addr
*b
)
167 return !sid_same(a
, b
);
170 static inline bool sid_zero(
171 const struct in6_addr
*a
)
173 struct in6_addr zero
= {};
175 return sid_same(a
, &zero
);
178 static inline void *sid_copy(struct in6_addr
*dst
,
179 const struct in6_addr
*src
)
181 return memcpy(dst
, src
, sizeof(struct in6_addr
));
185 seg6local_action2str(uint32_t action
);
187 const char *seg6local_context2str(char *str
, size_t size
,
188 const struct seg6local_context
*ctx
,
191 int snprintf_seg6_segs(char *str
,
192 size_t size
, const struct seg6_segs
*segs
);
194 extern struct srv6_locator
*srv6_locator_alloc(const char *name
);
195 extern struct srv6_locator_chunk
*srv6_locator_chunk_alloc(void);
196 extern void srv6_locator_free(struct srv6_locator
*locator
);
197 extern void srv6_locator_chunk_free(struct srv6_locator_chunk
**chunk
);
198 json_object
*srv6_locator_chunk_json(const struct srv6_locator_chunk
*chunk
);
199 json_object
*srv6_locator_json(const struct srv6_locator
*loc
);
200 json_object
*srv6_locator_detailed_json(const struct srv6_locator
*loc
);
202 srv6_locator_chunk_detailed_json(const struct srv6_locator_chunk
*chunk
);