FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
ipsec_gre_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * ipsec_gre_api.c - ipsec_gre api
4  *
5  * Copyright (c) 2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19 
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22 
23 #include <vnet/interface.h>
24 #include <vnet/api_errno.h>
26 
27 #include <vnet/vnet_msg_enum.h>
28 
29 #define vl_typedefs /* define message structures */
30 #include <vnet/vnet_all_api_h.h>
31 #undef vl_typedefs
32 
33 #define vl_endianfun /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
35 #undef vl_endianfun
36 
37 /* instantiate all the print functions we know about */
38 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
39 #define vl_printfun
40 #include <vnet/vnet_all_api_h.h>
41 #undef vl_printfun
42 
44 
45 #define foreach_vpe_api_msg \
46 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel) \
47 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump)
48 
49 static void
51  mp)
52 {
54  int rv = 0;
56  u32 sw_if_index = ~0;
57 
58  /* Check src & dst are different */
59  if (memcmp (mp->src_address, mp->dst_address, 4) == 0)
60  {
61  rv = VNET_API_ERROR_SAME_SRC_DST;
62  goto out;
63  }
64 
65  clib_memset (a, 0, sizeof (*a));
66 
67  /* ip addresses sent in network byte order */
68  clib_memcpy (&(a->src), mp->src_address, 4);
69  clib_memcpy (&(a->dst), mp->dst_address, 4);
70  a->is_add = mp->is_add;
71  a->lsa = ntohl (mp->local_sa_id);
72  a->rsa = ntohl (mp->remote_sa_id);
73 
74  rv = vnet_ipsec_gre_add_del_tunnel (a, &sw_if_index);
75 
76 out:
77  /* *INDENT-OFF* */
78  REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
79  ({
80  rmp->sw_if_index = ntohl (sw_if_index);
81  }));
82  /* *INDENT-ON* */
83 }
84 
87 {
89 
90  rmp = vl_msg_api_alloc (sizeof (*rmp));
91  clib_memset (rmp, 0, sizeof (*rmp));
92  rmp->_vl_msg_id = ntohs (VL_API_IPSEC_GRE_TUNNEL_DETAILS);
93  clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
94  clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
95  rmp->sw_if_index = htonl (t->sw_if_index);
96  rmp->local_sa_id = htonl (t->local_sa_id);
97  rmp->remote_sa_id = htonl (t->remote_sa_id);
98  rmp->context = context;
99 
100  vl_api_send_msg (reg, (u8 *) rmp);
101 }
102 
105 {
110 
112  if (!reg)
113  return;
114 
115  sw_if_index = ntohl (mp->sw_if_index);
116 
117  if (~0 == sw_if_index)
118  {
119  /* *INDENT-OFF* */
120  pool_foreach (t, igm->tunnels,
121  ({
122  send_ipsec_gre_tunnel_details(t, reg, mp->context);
123  }));
124  /* *INDENT-ON* */
125  }
126  else
127  {
128  if ((sw_if_index >= vec_len (igm->tunnel_index_by_sw_if_index)) ||
129  (~0 == igm->tunnel_index_by_sw_if_index[sw_if_index]))
130  {
131  return;
132  }
135  }
136 }
137 
138 /*
139  * ipsec_gre_api_hookup
140  * Add vpe's API message handlers to the table.
141  * vlib has already mapped shared memory and
142  * added the client registration handlers.
143  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
144  */
145 #define vl_msg_name_crc_list
146 #include <vnet/vnet_all_api_h.h>
147 #undef vl_msg_name_crc_list
148 
149 static void
151 {
152 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
153  foreach_vl_msg_name_crc_ipsec_gre;
154 #undef _
155 }
156 
157 static clib_error_t *
159 {
160  api_main_t *am = &api_main;
161 
162 #define _(N,n) \
163  vl_msg_api_set_handlers(VL_API_##N, #n, \
164  vl_api_##n##_t_handler, \
165  vl_noop_handler, \
166  vl_api_##n##_t_endian, \
167  vl_api_##n##_t_print, \
168  sizeof(vl_api_##n##_t), 1);
170 #undef _
171 
172  /*
173  * Set up the (msg_name, crc, message-id) table
174  */
176 
177  return 0;
178 }
179 
181 
182 /*
183  * fd.io coding-style-patch-verification: ON
184  *
185  * Local Variables:
186  * eval: (c-set-style "gnu")
187  * End:
188  */
Add / del ipsec gre tunnel request.
Definition: ipsec_gre.api:27
ip4_address_t tunnel_dst
tunnel IPv4 dst address
Definition: ipsec_gre.h:55
a
Definition: bitmap.h:538
L2-GRE over IPSec packet processing.
#define REPLY_MACRO2(t, body)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:34
VLIB_API_INIT_FUNCTION(ipsec_gre_api_hookup)
void * vl_msg_api_alloc(int nbytes)
unsigned char u8
Definition: types.h:56
static void vl_api_ipsec_gre_add_del_tunnel_t_handler(vl_api_ipsec_gre_add_del_tunnel_t *mp)
Definition: ipsec_gre_api.c:50
#define clib_memcpy(d, s, n)
Definition: string.h:180
Dump ipsec gre tunnel table.
Definition: ipsec_gre.api:53
ipsec_gre_tunnel_t * tunnels
pool of tunnel instances
Definition: ipsec_gre.h:70
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:490
Reply for add / del ipsec gre tunnel request.
Definition: ipsec_gre.api:42
u32 sw_if_index
Definition: vxlan_gbp.api:37
ipsec_gre_main_t ipsec_gre_main
Definition: ipsec_gre.c:25
static void setup_message_id_table(api_main_t *am)
unsigned int u32
Definition: types.h:88
u32 sw_if_index
hardware interface index
Definition: ipsec_gre.h:60
u32 remote_sa_id
remote IPSec SA id
Definition: ipsec_gre.h:59
IPSec-GRE tunnel add/del arguments.
Definition: ipsec_gre.h:95
static void vl_api_ipsec_gre_tunnel_dump_t_handler(vl_api_ipsec_gre_tunnel_dump_t *mp)
static clib_error_t * ipsec_gre_api_hookup(vlib_main_t *vm)
ipsec gre tunnel operational state response
Definition: ipsec_gre.api:67
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:202
An API client registration, only in vpp/vlib.
Definition: api_common.h:45
u8 is_add
1 - add, 0 - delete
Definition: ipsec_gre.h:97
u32 * tunnel_index_by_sw_if_index
mapping from sw_if_index to tunnel index
Definition: ipsec_gre.h:76
vlib_main_t * vm
Definition: buffer.c:301
static void send_ipsec_gre_tunnel_details(ipsec_gre_tunnel_t *t, vl_api_registration_t *reg, u32 context)
Definition: ipsec_gre_api.c:86
IPSec-GRE state.
Definition: ipsec_gre.h:68
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:56
u32 rsa
remote IPSec SA id
Definition: ipsec_gre.h:102
int vnet_ipsec_gre_add_del_tunnel(vnet_ipsec_gre_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Add or delete ipsec-gre tunnel interface.
Definition: interface.c:94
ip4_address_t src
tunnel IPv4 src address
Definition: ipsec_gre.h:99
#define foreach_vpe_api_msg
Definition: ipsec_gre_api.c:45
IPSec-GRE tunnel parameters.
Definition: ipsec_gre.h:50
u32 local_sa_id
local IPSec SA id
Definition: ipsec_gre.h:58
ip4_address_t dst
tunnel IPv4 dst address
Definition: ipsec_gre.h:100
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
api_main_t api_main
Definition: api_shared.c:35
ip4_address_t tunnel_src
tunnel IPv4 src address
Definition: ipsec_gre.h:54