]>
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 | ||
7309092b DL |
20 | #include "zebra.h" |
21 | ||
e496b420 HS |
22 | #include "srv6.h" |
23 | #include "log.h" | |
24 | ||
25 | const char *seg6local_action2str(uint32_t action) | |
26 | { | |
27 | switch (action) { | |
28 | case ZEBRA_SEG6_LOCAL_ACTION_END: | |
29 | return "End"; | |
30 | case ZEBRA_SEG6_LOCAL_ACTION_END_X: | |
31 | return "End.X"; | |
32 | case ZEBRA_SEG6_LOCAL_ACTION_END_T: | |
33 | return "End.T"; | |
34 | case ZEBRA_SEG6_LOCAL_ACTION_END_DX2: | |
35 | return "End.DX2"; | |
36 | case ZEBRA_SEG6_LOCAL_ACTION_END_DX6: | |
37 | return "End.DX6"; | |
38 | case ZEBRA_SEG6_LOCAL_ACTION_END_DX4: | |
39 | return "End.DX4"; | |
40 | case ZEBRA_SEG6_LOCAL_ACTION_END_DT6: | |
41 | return "End.DT6"; | |
42 | case ZEBRA_SEG6_LOCAL_ACTION_END_DT4: | |
43 | return "End.DT4"; | |
44 | case ZEBRA_SEG6_LOCAL_ACTION_END_B6: | |
45 | return "End.B6"; | |
46 | case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP: | |
47 | return "End.B6.Encap"; | |
48 | case ZEBRA_SEG6_LOCAL_ACTION_END_BM: | |
49 | return "End.BM"; | |
50 | case ZEBRA_SEG6_LOCAL_ACTION_END_S: | |
51 | return "End.S"; | |
52 | case ZEBRA_SEG6_LOCAL_ACTION_END_AS: | |
53 | return "End.AS"; | |
54 | case ZEBRA_SEG6_LOCAL_ACTION_END_AM: | |
55 | return "End.AM"; | |
56 | case ZEBRA_SEG6_LOCAL_ACTION_UNSPEC: | |
57 | return "unspec"; | |
58 | default: | |
59 | return "unknown"; | |
60 | } | |
61 | } | |
62 | ||
63 | int snprintf_seg6_segs(char *str, | |
64 | size_t size, const struct seg6_segs *segs) | |
65 | { | |
66 | str[0] = '\0'; | |
67 | for (size_t i = 0; i < segs->num_segs; i++) { | |
68 | char addr[INET6_ADDRSTRLEN]; | |
69 | bool not_last = (i + 1) < segs->num_segs; | |
70 | ||
71 | inet_ntop(AF_INET6, &segs->segs[i], addr, sizeof(addr)); | |
72 | strlcat(str, addr, size); | |
73 | strlcat(str, not_last ? "," : "", size); | |
74 | } | |
75 | return strlen(str); | |
76 | } | |
77 | ||
78 | const char *seg6local_context2str(char *str, size_t size, | |
7a4b49bd HS |
79 | const struct seg6local_context *ctx, |
80 | uint32_t action) | |
e496b420 HS |
81 | { |
82 | char b0[128]; | |
83 | ||
84 | switch (action) { | |
85 | ||
86 | case ZEBRA_SEG6_LOCAL_ACTION_END: | |
87 | snprintf(str, size, "USP"); | |
88 | return str; | |
89 | ||
90 | case ZEBRA_SEG6_LOCAL_ACTION_END_X: | |
91 | case ZEBRA_SEG6_LOCAL_ACTION_END_DX6: | |
92 | inet_ntop(AF_INET6, &ctx->nh6, b0, 128); | |
93 | snprintf(str, size, "nh6 %s", b0); | |
94 | return str; | |
95 | ||
96 | case ZEBRA_SEG6_LOCAL_ACTION_END_DX4: | |
97 | inet_ntop(AF_INET, &ctx->nh4, b0, 128); | |
98 | snprintf(str, size, "nh4 %s", b0); | |
99 | return str; | |
100 | ||
101 | case ZEBRA_SEG6_LOCAL_ACTION_END_T: | |
102 | case ZEBRA_SEG6_LOCAL_ACTION_END_DT6: | |
103 | case ZEBRA_SEG6_LOCAL_ACTION_END_DT4: | |
104 | snprintf(str, size, "table %u", ctx->table); | |
105 | return str; | |
106 | ||
107 | case ZEBRA_SEG6_LOCAL_ACTION_END_DX2: | |
108 | case ZEBRA_SEG6_LOCAL_ACTION_END_B6: | |
109 | case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP: | |
110 | case ZEBRA_SEG6_LOCAL_ACTION_END_BM: | |
111 | case ZEBRA_SEG6_LOCAL_ACTION_END_S: | |
112 | case ZEBRA_SEG6_LOCAL_ACTION_END_AS: | |
113 | case ZEBRA_SEG6_LOCAL_ACTION_END_AM: | |
114 | case ZEBRA_SEG6_LOCAL_ACTION_UNSPEC: | |
115 | default: | |
116 | snprintf(str, size, "unknown(%s)", __func__); | |
117 | return str; | |
118 | } | |
119 | } |