FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
mss_clamp_api.c
Go to the documentation of this file.
1 /*
2  * mss_clamp_api.c - TCP MSS clamping plug-in
3  *
4  * Copyright (c) <current-year> <your-organization>
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/plugin/plugin.h> /* VLIB_PLUGIN_REGISTER */
20 #include <mss_clamp/mss_clamp.h>
21 #include <mss_clamp/mss_clamp.api_enum.h>
22 #include <mss_clamp/mss_clamp.api_types.h>
23 #include <vlibapi/api.h>
24 #include <vlibmemory/api.h>
25 #include <vpp/app/version.h> /* VPP_BUILD_VER */
26 
27 #define REPLY_MSG_ID_BASE cm->msg_id_base
29 
30 /* API message handler */
31 static void
34 {
36  vl_api_mss_clamp_enable_disable_reply_t *rmp;
37  int rv;
39 
40  sw_if_index = ntohl (mp->sw_if_index);
41 
43 
44  rv =
46  ntohs (mp->ipv4_mss), ntohs (mp->ipv6_mss));
47 
49  REPLY_MACRO (VL_API_MSS_CLAMP_ENABLE_DISABLE_REPLY);
50 }
51 
52 static void
54  u32 context)
55 {
58  u16 mss4, mss6;
59  u8 dir4, dir6;
60  int rv;
61 
62  mss4 = mss6 = 0;
63  dir4 = dir6 = MSS_CLAMP_DIR_NONE;
64  rv = mssc_get_mss (sw_if_index, &dir4, &dir6, &mss4, &mss6);
65  if (rv == VNET_API_ERROR_FEATURE_DISABLED)
66  return;
67 
68  REPLY_MACRO_DETAILS4 (VL_API_MSS_CLAMP_DETAILS, rp, context, ({
69  rmp->sw_if_index = htonl (sw_if_index);
70  rmp->ipv4_mss = htons (mss4);
71  rmp->ipv6_mss = htons (mss6);
72  rmp->ipv4_direction = dir4;
73  rmp->ipv6_direction = dir6;
74  }));
75 }
76 
77 static void
79 {
82  int rv = 0;
83  u32 sw_if_index = ntohl (mp->sw_if_index);
85 
87  if (!reg)
88  return;
89 
90  if (sw_if_index == ~0)
91  {
92  if (vec_len (cm->dir_enabled4) == 0)
93  {
94  REPLY_MACRO2 (VL_API_MSS_CLAMP_GET_REPLY, ({ rmp->cursor = ~0; }));
95  return;
96  }
97 
99  VL_API_MSS_CLAMP_GET_REPLY, cm->dir_enabled4, mp, rmp, rv,
100  ({ send_mss_clamp_details (cursor, reg, mp->context); }));
101  }
102  else
103  {
106 
108  REPLY_MACRO2 (VL_API_MSS_CLAMP_GET_REPLY, ({ rmp->cursor = ~0; }));
109  }
110 }
111 
112 /* API definitions */
113 #include <vnet/format_fns.h>
114 #include <mss_clamp/mss_clamp.api.c>
115 
116 /* Set up the API message handling tables */
117 static clib_error_t *
119 {
121 
122  cm->msg_id_base = setup_message_id_table ();
123  return 0;
124 }
125 
127 
129  .version = VPP_BUILD_VER,
130  .description = "TCP MSS clamping plugin",
131 };
132 
133 /*
134  * fd.io coding-style-patch-verification: ON
135  *
136  * Local Variables:
137  * eval: (c-set-style "gnu")
138  * End:
139  */
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
vl_api_client_index_to_registration
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
api.h
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
vl_api_mss_clamp_enable_disable_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: mss_clamp.api:40
vl_api_mss_clamp_details_t
Configured MSS values on an interface.
Definition: mss_clamp.api:89
mss_clamp.h
vl_api_mss_clamp_get_t_handler
static void vl_api_mss_clamp_get_t_handler(vl_api_mss_clamp_get_t *mp)
Definition: mss_clamp_api.c:78
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
vl_api_mss_clamp_details_t::ipv6_direction
vl_api_mss_clamp_dir_t ipv6_direction
Definition: mss_clamp.api:95
REPLY_AND_DETAILS_VEC_MACRO
#define REPLY_AND_DETAILS_VEC_MACRO(t, v, mp, rmp, rv, body)
Definition: api_helper_macros.h:244
vl_api_mss_clamp_details_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: mss_clamp.api:91
vl_api_mss_clamp_get_t::client_index
u32 client_index
Definition: mss_clamp.api:64
vl_api_mss_clamp_details_t::ipv4_mss
u16 ipv4_mss
Definition: mss_clamp.api:92
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vl_api_mss_clamp_get_reply_t
Reply for get TCP MSS Clamping feature settings request.
Definition: mss_clamp.api:75
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
mssc_get_mss
int mssc_get_mss(u32 sw_if_index, u8 *dir4, u8 *dir6, u16 *mss4, u16 *mss6)
Definition: mss_clamp.c:85
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
REPLY_MACRO_DETAILS4
#define REPLY_MACRO_DETAILS4(t, rp, context, body)
Definition: api_helper_macros.h:132
vl_api_mss_clamp_get_t::context
u32 context
Definition: mss_clamp.api:65
mssc_enable_disable
int mssc_enable_disable(u32 sw_if_index, u8 dir4, u8 dir6, u16 mss4, u16 mss6)
Definition: mss_clamp.c:50
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:594
vl_api_mss_clamp_details_t::ipv4_direction
vl_api_mss_clamp_dir_t ipv4_direction
Definition: mss_clamp.api:94
mssc_api_hookup
static clib_error_t * mssc_api_hookup(vlib_main_t *vm)
Definition: mss_clamp_api.c:118
vl_api_mss_clamp_enable_disable_t::ipv6_mss
u16 ipv6_mss
Definition: mss_clamp.api:42
vl_api_mss_clamp_details_t::ipv6_mss
u16 ipv6_mss
Definition: mss_clamp.api:93
vl_api_mss_clamp_enable_disable_t::ipv6_direction
vl_api_mss_clamp_dir_t ipv6_direction
Definition: mss_clamp.api:44
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
plugin.h
format_fns.h
vl_api_mss_clamp_get_reply_t::cursor
u32 cursor
Definition: mss_clamp.api:78
u32
unsigned int u32
Definition: types.h:88
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(mssc_api_hookup)
vl_api_mss_clamp_enable_disable_t::ipv4_direction
vl_api_mss_clamp_dir_t ipv4_direction
Definition: mss_clamp.api:43
api_helper_macros.h
vl_api_mss_clamp_get_t
Get the TCP MSS Clamping feature settings.
Definition: mss_clamp.api:63
vl_api_mss_clamp_get_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: mss_clamp.api:67
vlib_main_t
Definition: main.h:102
mssc_main_t
Definition: mss_clamp.h:29
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vl_api_mss_clamp_enable_disable_t_handler
static void vl_api_mss_clamp_enable_disable_t_handler(vl_api_mss_clamp_enable_disable_t *mp)
Definition: mss_clamp_api.c:32
context
u32 context
Definition: ip.api:852
rv
int __clib_unused rv
Definition: application.c:491
vl_api_mss_clamp_enable_disable_t::ipv4_mss
u16 ipv4_mss
Definition: mss_clamp.api:41
vnet.h
send_mss_clamp_details
static void send_mss_clamp_details(u32 sw_if_index, vl_api_registration_t *rp, u32 context)
Definition: mss_clamp_api.c:53
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
mssc_main
mssc_main_t mssc_main
Definition: mss_clamp.c:23
vl_api_mss_clamp_enable_disable_t
Enable/Disable TCP MSS Clamping feature on an interface.
Definition: mss_clamp.api:37