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