]> git.proxmox.com Git - mirror_frr.git/blob - lib/srv6.h
Merge pull request #5761 from qlyoung/fix-bgp-gr-cruft
[mirror_frr.git] / lib / srv6.h
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>
24 #include <arpa/inet.h>
25 #include <netinet/in.h>
26
27 #define SRV6_MAX_SIDS 16
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #define sid2str(sid, str, size) \
34 inet_ntop(AF_INET6, sid, str, size)
35
36 enum seg6_mode_t {
37 INLINE,
38 ENCAP,
39 L2ENCAP,
40 };
41
42 enum seg6local_action_t {
43 ZEBRA_SEG6_LOCAL_ACTION_UNSPEC = 0,
44 ZEBRA_SEG6_LOCAL_ACTION_END = 1,
45 ZEBRA_SEG6_LOCAL_ACTION_END_X = 2,
46 ZEBRA_SEG6_LOCAL_ACTION_END_T = 3,
47 ZEBRA_SEG6_LOCAL_ACTION_END_DX2 = 4,
48 ZEBRA_SEG6_LOCAL_ACTION_END_DX6 = 5,
49 ZEBRA_SEG6_LOCAL_ACTION_END_DX4 = 6,
50 ZEBRA_SEG6_LOCAL_ACTION_END_DT6 = 7,
51 ZEBRA_SEG6_LOCAL_ACTION_END_DT4 = 8,
52 ZEBRA_SEG6_LOCAL_ACTION_END_B6 = 9,
53 ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP = 10,
54 ZEBRA_SEG6_LOCAL_ACTION_END_BM = 11,
55 ZEBRA_SEG6_LOCAL_ACTION_END_S = 12,
56 ZEBRA_SEG6_LOCAL_ACTION_END_AS = 13,
57 ZEBRA_SEG6_LOCAL_ACTION_END_AM = 14,
58 ZEBRA_SEG6_LOCAL_ACTION_END_BPF = 15,
59 };
60
61 struct seg6_segs {
62 size_t num_segs;
63 struct in6_addr segs[256];
64 };
65
66 struct seg6local_context {
67 struct in_addr nh4;
68 struct in6_addr nh6;
69 uint32_t table;
70 };
71
72 static inline const char *seg6_mode2str(enum seg6_mode_t mode)
73 {
74 switch (mode) {
75 case INLINE:
76 return "INLINE";
77 case ENCAP:
78 return "ENCAP";
79 case L2ENCAP:
80 return "L2ENCAP";
81 default:
82 return "unknown";
83 }
84 }
85
86 static inline bool sid_same(
87 const struct in6_addr *a,
88 const struct in6_addr *b)
89 {
90 if (!a && !b)
91 return true;
92 else if (!(a && b))
93 return false;
94 else
95 return memcmp(a, b, sizeof(struct in6_addr)) == 0;
96 }
97
98 static inline bool sid_diff(
99 const struct in6_addr *a,
100 const struct in6_addr *b)
101 {
102 return !sid_same(a, b);
103 }
104
105 static inline bool sid_zero(
106 const struct in6_addr *a)
107 {
108 struct in6_addr zero = {};
109
110 return sid_same(a, &zero);
111 }
112
113 static inline void *sid_copy(struct in6_addr *dst,
114 const struct in6_addr *src)
115 {
116 return memcpy(dst, src, sizeof(struct in6_addr));
117 }
118
119 const char *
120 seg6local_action2str(uint32_t action);
121
122 const char *
123 seg6local_context2str(char *str, size_t size,
124 struct seg6local_context *ctx, uint32_t action);
125
126 int snprintf_seg6_segs(char *str,
127 size_t size, const struct seg6_segs *segs);
128
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif