blob: 38aed79a1552f600a17491aa3d86df218d1261e8 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * decap.c : IPSec tunnel support
3 *
4 * Copyright (c) 2015 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <vnet/vnet.h>
19#include <vnet/api_errno.h>
20#include <vnet/ip/ip.h>
21#include <vnet/interface.h>
22
23#include <vnet/ipsec/ipsec.h>
24
25u8 *
26format_ipsec_policy_action (u8 * s, va_list * args)
27{
28 u32 i = va_arg (*args, u32);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070029 char *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070030
31 switch (i)
32 {
33#define _(v,f,str) case IPSEC_POLICY_ACTION_##f: t = str; break;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070034 foreach_ipsec_policy_action
Ed Warnickecb9cada2015-12-08 15:45:58 -070035#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070036 default:
37 s = format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -070038 }
39 s = format (s, "%s", t);
40 return s;
41}
42
43uword
44unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
45{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070046 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070047
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070048 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070049#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
50 foreach_ipsec_policy_action
51#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070052 else
Ed Warnickecb9cada2015-12-08 15:45:58 -070053 return 0;
54 return 1;
55}
56
57u8 *
58format_ipsec_crypto_alg (u8 * s, va_list * args)
59{
60 u32 i = va_arg (*args, u32);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070061 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070062
63 switch (i)
64 {
65#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070066 foreach_ipsec_crypto_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -070067#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070068 default:
69 s = format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -070070 }
71 s = format (s, "%s", t);
72 return s;
73}
74
75uword
76unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
77{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070078 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070079
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070080 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070081#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
82 foreach_ipsec_crypto_alg
83#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070084 else
Ed Warnickecb9cada2015-12-08 15:45:58 -070085 return 0;
86 return 1;
87}
88
89u8 *
90format_ipsec_integ_alg (u8 * s, va_list * args)
91{
92 u32 i = va_arg (*args, u32);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070093 u8 *t = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070094
95 switch (i)
96 {
97#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070098 foreach_ipsec_integ_alg
Ed Warnickecb9cada2015-12-08 15:45:58 -070099#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700100 default:
101 s = format (s, "unknown");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102 }
103 s = format (s, "%s", t);
104 return s;
105}
106
107uword
108unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
109{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700110 u32 *r = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700111
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700112 if (0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
114 foreach_ipsec_integ_alg
115#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700116 else
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117 return 0;
118 return 1;
119}
120
121u8 *
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700122format_ipsec_replay_window (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700123{
124 u64 w = va_arg (*args, u64);
125 u8 i;
126
127 for (i = 0; i < 64; i++)
128 {
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700129 s = format (s, "%u", w & (1ULL << i) ? 1 : 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130 }
131
132 return s;
133}
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700134
135/*
136 * fd.io coding-style-patch-verification: ON
137 *
138 * Local Variables:
139 * eval: (c-set-style "gnu")
140 * End:
141 */