]> git.proxmox.com Git - mirror_frr.git/blame - lib/srv6.c
Merge pull request #8759 from idryzhov/ospf6-vrf-fix
[mirror_frr.git] / lib / srv6.c
CommitLineData
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
25const 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
63int 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
78const char *seg6local_context2str(char *str, size_t size,
79 struct seg6local_context *ctx, uint32_t action)
80{
81 char b0[128];
82
83 switch (action) {
84
85 case ZEBRA_SEG6_LOCAL_ACTION_END:
86 snprintf(str, size, "USP");
87 return str;
88
89 case ZEBRA_SEG6_LOCAL_ACTION_END_X:
90 case ZEBRA_SEG6_LOCAL_ACTION_END_DX6:
91 inet_ntop(AF_INET6, &ctx->nh6, b0, 128);
92 snprintf(str, size, "nh6 %s", b0);
93 return str;
94
95 case ZEBRA_SEG6_LOCAL_ACTION_END_DX4:
96 inet_ntop(AF_INET, &ctx->nh4, b0, 128);
97 snprintf(str, size, "nh4 %s", b0);
98 return str;
99
100 case ZEBRA_SEG6_LOCAL_ACTION_END_T:
101 case ZEBRA_SEG6_LOCAL_ACTION_END_DT6:
102 case ZEBRA_SEG6_LOCAL_ACTION_END_DT4:
103 snprintf(str, size, "table %u", ctx->table);
104 return str;
105
106 case ZEBRA_SEG6_LOCAL_ACTION_END_DX2:
107 case ZEBRA_SEG6_LOCAL_ACTION_END_B6:
108 case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP:
109 case ZEBRA_SEG6_LOCAL_ACTION_END_BM:
110 case ZEBRA_SEG6_LOCAL_ACTION_END_S:
111 case ZEBRA_SEG6_LOCAL_ACTION_END_AS:
112 case ZEBRA_SEG6_LOCAL_ACTION_END_AM:
113 case ZEBRA_SEG6_LOCAL_ACTION_UNSPEC:
114 default:
115 snprintf(str, size, "unknown(%s)", __func__);
116 return str;
117 }
118}