FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
tcp_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * tcp_api.c - vnet tcp-layer apis
4  *
5  * Copyright (c) 2017-2019 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/tcp/tcp.h>
24 
25 #include <vnet/ip/ip_types_api.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_tcp_api_msg \
46 _(TCP_CONFIGURE_SRC_ADDRESSES, tcp_configure_src_addresses)
47 
48 static void
51 {
53  vl_api_tcp_configure_src_addresses_reply_t *rmp;
54  u32 vrf_id;
55  int rv;
56  ip46_address_t first_address, last_address;
57  ip46_type_t fa_af, la_af;
58 
59  vrf_id = clib_net_to_host_u32 (mp->vrf_id);
60 
61  fa_af = ip_address_decode (&mp->first_address, &first_address);
62  la_af = ip_address_decode (&mp->last_address, &last_address);
63 
64  if (fa_af != la_af)
65  {
66  rv = VNET_API_ERROR_INVALID_VALUE;
67  goto error;
68  }
69 
70  if (fa_af == IP46_TYPE_IP6)
72  (vm, &first_address.ip6, &last_address.ip6, vrf_id);
73  else
75  (vm, &first_address.ip4, &last_address.ip4, vrf_id);
76 
77 error:
78  REPLY_MACRO (VL_API_TCP_CONFIGURE_SRC_ADDRESSES_REPLY);
79 }
80 
81 #define vl_msg_name_crc_list
82 #include <vnet/tcp/tcp.api.h>
83 #undef vl_msg_name_crc_list
84 
85 static void
87 {
88 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
89  foreach_vl_msg_name_crc_tcp;
90 #undef _
91 }
92 
93 static clib_error_t *
95 {
97 
98 #define _(N,n) \
99  vl_msg_api_set_handlers(VL_API_##N, #n, \
100  vl_api_##n##_t_handler, \
101  vl_noop_handler, \
102  vl_api_##n##_t_endian, \
103  vl_api_##n##_t_print, \
104  sizeof(vl_api_##n##_t), 1);
106 #undef _
107 
108  /*
109  * Set up the (msg_name, crc, message-id) table
110  */
112 
113  return 0;
114 }
115 
117 
118 /*
119  * fd.io coding-style-patch-verification: ON
120  *
121  * Local Variables:
122  * eval: (c-set-style "gnu")
123  * End:
124  */
static void vl_api_tcp_configure_src_addresses_t_handler(vl_api_tcp_configure_src_addresses_t *mp)
Definition: tcp_api.c:50
vl_api_address_t first_address
Definition: tcp.api:42
static clib_error_t * tcp_api_hookup(vlib_main_t *vm)
Definition: tcp_api.c:94
vlib_main_t * vm
Definition: in2out_ed.c:1582
unsigned int u32
Definition: types.h:88
ip46_type_t ip_address_decode(const vl_api_address_t *in, ip46_address_t *out)
Decode/Encode for struct/union types.
Definition: ip_types_api.c:160
#define REPLY_MACRO(t)
vl_api_address_t last_address
Definition: tcp.api:43
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:227
int tcp_configure_v4_source_address_range(vlib_main_t *vm, ip4_address_t *start, ip4_address_t *end, u32 table_id)
Configure an ipv4 source address range.
Definition: tcp_cli.c:377
#define foreach_tcp_api_msg
Definition: tcp_api.c:45
static void setup_message_id_table(api_main_t *am)
Definition: tcp_api.c:86
VLIB_API_INIT_FUNCTION(tcp_api_hookup)
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
Configure TCP source addresses, for active-open TCP sessions.
Definition: tcp.api:38
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:389
u32 vrf_id
Definition: nat.api:944
int tcp_configure_v6_source_address_range(vlib_main_t *vm, ip6_address_t *start, ip6_address_t *end, u32 table_id)
Configure an ipv6 source address range.
Definition: tcp_cli.c:464
ip46_type_t
Definition: ip46_address.h:22