3 * Copyright (C) 2020 Hiroki Shirokura, LINE Corporation
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)
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
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
24 #include <arpa/inet.h>
25 #include <netinet/in.h>
27 #define SRV6_MAX_SIDS 16
33 #define sid2str(sid, str, size) \
34 inet_ntop(AF_INET6, sid, str, size)
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,
63 struct in6_addr segs
[256];
66 struct seg6local_context
{
72 static inline const char *seg6_mode2str(enum seg6_mode_t mode
)
86 static inline bool sid_same(
87 const struct in6_addr
*a
,
88 const struct in6_addr
*b
)
95 return memcmp(a
, b
, sizeof(struct in6_addr
)) == 0;
98 static inline bool sid_diff(
99 const struct in6_addr
*a
,
100 const struct in6_addr
*b
)
102 return !sid_same(a
, b
);
105 static inline bool sid_zero(
106 const struct in6_addr
*a
)
108 struct in6_addr zero
= {};
110 return sid_same(a
, &zero
);
113 static inline void *sid_copy(struct in6_addr
*dst
,
114 const struct in6_addr
*src
)
116 return memcpy(dst
, src
, sizeof(struct in6_addr
));
120 seg6local_action2str(uint32_t action
);
123 seg6local_context2str(char *str
, size_t size
,
124 struct seg6local_context
*ctx
, uint32_t action
);
126 int snprintf_seg6_segs(char *str
,
127 size_t size
, const struct seg6_segs
*segs
);