FD.io VPP  v20.01-46-g7006026de
Vector Packet Processing
gtpu_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * gtpu_api.c - gtpu api
4  *
5  * Copyright (c) 2017 Intel 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/interface.h>
21 #include <vnet/api_errno.h>
22 #include <vnet/feature/feature.h>
23 #include <vnet/fib/fib_table.h>
24 
25 #include <vppinfra/byte_order.h>
26 #include <vlibmemory/api.h>
27 #include <vnet/ip/ip_types_api.h>
28 #include <gtpu/gtpu.h>
29 
30 #include <vnet/format_fns.h>
31 #include <gtpu/gtpu.api_enum.h>
32 #include <gtpu/gtpu.api_types.h>
33 
34 #define REPLY_MSG_ID_BASE gtm->msg_id_base
36 
37 static void
40 {
41  vl_api_sw_interface_set_gtpu_bypass_reply_t *rmp;
42  int rv = 0;
43  u32 sw_if_index = ntohl (mp->sw_if_index);
44  gtpu_main_t *gtm = &gtpu_main;
45 
47 
48  vnet_int_gtpu_bypass_mode (sw_if_index, mp->is_ipv6, mp->enable);
50 
51  REPLY_MACRO (VL_API_SW_INTERFACE_SET_GTPU_BYPASS_REPLY);
52 }
53 
56 {
58  int rv = 0;
59  ip4_main_t *im = &ip4_main;
60  gtpu_main_t *gtm = &gtpu_main;
61 
62  uword *p = hash_get (im->fib_index_by_table_id, ntohl (mp->encap_vrf_id));
63  if (!p)
64  {
65  rv = VNET_API_ERROR_NO_SUCH_FIB;
66  goto out;
67  }
68 
70  .is_add = mp->is_add,
71  .mcast_sw_if_index = ntohl (mp->mcast_sw_if_index),
72  .encap_fib_index = p[0],
73  .decap_next_index = ntohl (mp->decap_next_index),
74  .teid = ntohl (mp->teid),
75  };
78 
79  /* Check src & dst are different */
80  if (ip46_address_cmp (&a.dst, &a.src) == 0)
81  {
82  rv = VNET_API_ERROR_SAME_SRC_DST;
83  goto out;
84  }
85  if (ip46_address_is_multicast (&a.dst) &&
87  {
88  rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
89  goto out;
90  }
91 
92  u32 sw_if_index = ~0;
93  rv = vnet_gtpu_add_del_tunnel (&a, &sw_if_index);
94 
95 out:
96  /* *INDENT-OFF* */
97  REPLY_MACRO2(VL_API_GTPU_ADD_DEL_TUNNEL_REPLY,
98  ({
99  rmp->sw_if_index = ntohl (sw_if_index);
100  }));
101  /* *INDENT-ON* */
102 }
103 
104 static void send_gtpu_tunnel_details
106 {
108  gtpu_main_t *gtm = &gtpu_main;
109  ip4_main_t *im4 = &ip4_main;
110  ip6_main_t *im6 = &ip6_main;
112 
113  rmp = vl_msg_api_alloc (sizeof (*rmp));
114  clib_memset (rmp, 0, sizeof (*rmp));
115  rmp->_vl_msg_id = ntohs (VL_API_GTPU_TUNNEL_DETAILS + gtm->msg_id_base);
116 
118  &rmp->src_address);
119  ip_address_encode (&t->dst, is_ipv6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
120  &rmp->dst_address);
121 
122  rmp->encap_vrf_id =
123  is_ipv6 ? htonl (im6->fibs[t->encap_fib_index].ft_table_id) :
124  htonl (im4->fibs[t->encap_fib_index].ft_table_id);
125  rmp->mcast_sw_if_index = htonl (t->mcast_sw_if_index);
126  rmp->teid = htonl (t->teid);
127  rmp->decap_next_index = htonl (t->decap_next_index);
128  rmp->sw_if_index = htonl (t->sw_if_index);
129  rmp->context = context;
130 
131  vl_api_send_msg (reg, (u8 *) rmp);
132 }
133 
134 static void
136 {
138  gtpu_main_t *gtm = &gtpu_main;
139  gtpu_tunnel_t *t;
141 
143  if (!reg)
144  return;
145 
146  sw_if_index = ntohl (mp->sw_if_index);
147 
148  if (~0 == sw_if_index)
149  {
150  /* *INDENT-OFF* */
151  pool_foreach (t, gtm->tunnels,
152  ({
153  send_gtpu_tunnel_details(t, reg, mp->context);
154  }));
155  /* *INDENT-ON* */
156  }
157  else
158  {
159  if ((sw_if_index >= vec_len (gtm->tunnel_index_by_sw_if_index)) ||
160  (~0 == gtm->tunnel_index_by_sw_if_index[sw_if_index]))
161  {
162  return;
163  }
165  send_gtpu_tunnel_details (t, reg, mp->context);
166  }
167 }
168 
169 #include <gtpu/gtpu.api.c>
170 static clib_error_t *
172 {
173  gtpu_main_t *gtm = &gtpu_main;
174 
176  return 0;
177 }
178 
180 
181 /*
182  * fd.io coding-style-patch-verification: ON
183  *
184  * Local Variables:
185  * eval: (c-set-style "gnu")
186  * End:
187  */
vl_api_interface_index_t sw_if_index
Definition: gtpu.api:54
vl_api_address_t src_address
Definition: gtpu.api:36
vl_api_address_t src_address
Definition: gtpu.api:84
static uword ip46_address_is_multicast(const ip46_address_t *a)
Definition: ip46_address.h:154
a
Definition: bitmap.h:538
static void send_gtpu_tunnel_details(gtpu_tunnel_t *t, vl_api_registration_t *reg, u32 context)
Definition: gtpu_api.c:105
u32 teid
Definition: gtpu.h:138
u32 * tunnel_index_by_sw_if_index
Definition: gtpu.h:221
#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:35
static u8 ip46_address_is_ip4(const ip46_address_t *ip46)
Definition: ip46_address.h:55
void * vl_msg_api_alloc(int nbytes)
unsigned char u8
Definition: types.h:56
static void vl_api_sw_interface_set_gtpu_bypass_t_handler(vl_api_sw_interface_set_gtpu_bypass_t *mp)
Definition: gtpu_api.c:39
static clib_error_t * gtpu_api_hookup(vlib_main_t *vm)
Definition: gtpu_api.c:171
static void vl_api_gtpu_add_del_tunnel_t_handler(vl_api_gtpu_add_del_tunnel_t *mp)
Definition: gtpu_api.c:55
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:498
vl_api_interface_index_t sw_if_index
Definition: gre.api:59
int vnet_gtpu_add_del_tunnel(vnet_gtpu_add_del_tunnel_args_t *a, u32 *sw_if_indexp)
Definition: gtpu.c:373
ip46_address_t src
Definition: gtpu.h:141
u16 msg_id_base
Definition: gtpu.h:229
static int ip46_address_cmp(const ip46_address_t *ip46_1, const ip46_address_t *ip46_2)
Definition: ip46_address.h:80
reply for set or delete an GTPU tunnel
Definition: gtpu.api:50
unsigned int u32
Definition: types.h:88
gtpu_main_t gtpu_main
Definition: gtpu.c:36
ip46_type_t ip_address_decode(const vl_api_address_t *in, ip46_address_t *out)
Definition: ip_types_api.c:161
vl_api_interface_index_t sw_if_index
Definition: gtpu.api:103
#define hash_get(h, key)
Definition: hash.h:249
uword * fib_index_by_table_id
Hash table mapping table id to fib index.
Definition: ip4.h:131
u32 decap_next_index
Definition: gtpu.h:148
vl_api_interface_index_t mcast_sw_if_index
Definition: gtpu.api:38
#define REPLY_MACRO(t)
ip6_main_t ip6_main
Definition: ip6_forward.c:2703
Interface set gtpu-bypass request.
Definition: gtpu.api:99
vlib_main_t * vm
Definition: in2out_ed.c:1810
ip46_address_t dst
Definition: gtpu.h:142
An API client registration, only in vpp/vlib.
Definition: api_common.h:46
#define BAD_SW_IF_INDEX_LABEL
static uword vnet_sw_if_index_is_api_valid(u32 sw_if_index)
vl_api_address_t dst_address
Definition: gtpu.api:85
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:92
u32 sw_if_index
Definition: gtpu.h:154
vl_api_interface_index_t sw_if_index
Definition: gtpu.api:83
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:57
static void vl_api_gtpu_tunnel_dump_t_handler(vl_api_gtpu_tunnel_dump_t *mp)
Definition: gtpu_api.c:135
VLIB_API_INIT_FUNCTION(gtpu_api_hookup)
IPv4 main type.
Definition: ip4.h:105
vl_api_interface_index_t sw_if_index
Definition: gtpu.api:66
void vnet_int_gtpu_bypass_mode(u32 sw_if_index, u8 is_ip6, u8 is_enable)
Definition: gtpu.c:928
u32 encap_fib_index
Definition: gtpu.h:151
dump details of an GTPU tunnel
Definition: gtpu.api:80
vl_api_interface_index_t mcast_sw_if_index
Definition: gtpu.api:86
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u64 uword
Definition: types.h:112
void ip_address_encode(const ip46_address_t *in, ip46_type_t type, vl_api_address_t *out)
Definition: ip_types_api.c:178
gtpu_tunnel_t * tunnels
Definition: gtpu.h:203
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1079
struct fib_table_t_ * fibs
Vector of FIBs.
Definition: ip4.h:110
vl_api_address_t dst_address
Definition: gtpu.api:37
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
Definition: nat_api.c:3410
Set or delete an GTPU tunnel.
Definition: gtpu.api:31
Dump GTPU tunnel.
Definition: gtpu.api:62
struct fib_table_t_ * fibs
Definition: ip6.h:183
u32 mcast_sw_if_index
Definition: gtpu.h:145
#define VALIDATE_SW_IF_INDEX(mp)
u8 is_ipv6
Definition: acl_types.api:38