From bf55e9931ce203049385fbf55dde291ead556679 Mon Sep 17 00:00:00 2001 From: Neale Ranns Date: Thu, 4 Oct 2018 06:40:30 -0700 Subject: mss_clamp: TCP MSS clamping plugin Type: feature Configure TCP MSS clamping on an interface as follows: set interface tcp-mss-clamp [rx|tx] ip4 [enable|disable|rx|tx] ip4-mss ip6 [enable|disable|rx|tx] ip6-mss Change-Id: I45b04e50a0b70a33e14a9066f981c651292ebffb Signed-off-by: Neale Ranns Signed-off-by: Paul Vinciguerra Signed-off-by: Miklos Tirpak Signed-off-by: Matthew Smith --- src/plugins/mss_clamp/mss_clamp_api.c | 136 ++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/plugins/mss_clamp/mss_clamp_api.c (limited to 'src/plugins/mss_clamp/mss_clamp_api.c') diff --git a/src/plugins/mss_clamp/mss_clamp_api.c b/src/plugins/mss_clamp/mss_clamp_api.c new file mode 100644 index 00000000000..cb47cd6ce06 --- /dev/null +++ b/src/plugins/mss_clamp/mss_clamp_api.c @@ -0,0 +1,136 @@ +/* + * mss_clamp_api.c - TCP MSS clamping plug-in + * + * Copyright (c) + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include /* VLIB_PLUGIN_REGISTER */ +#include +#include +#include +#include +#include +#include /* VPP_BUILD_VER */ + +#define REPLY_MSG_ID_BASE cm->msg_id_base +#include + +/* API message handler */ +static void +vl_api_mss_clamp_enable_disable_t_handler ( + vl_api_mss_clamp_enable_disable_t *mp) +{ + mssc_main_t *cm = &mssc_main; + vl_api_mss_clamp_enable_disable_reply_t *rmp; + int rv; + + VALIDATE_SW_IF_INDEX (mp); + + rv = mssc_enable_disable (ntohl (mp->sw_if_index), mp->ipv4_direction, + mp->ipv6_direction, ntohs (mp->ipv4_mss), + ntohs (mp->ipv6_mss)); + + BAD_SW_IF_INDEX_LABEL; + REPLY_MACRO (VL_API_MSS_CLAMP_ENABLE_DISABLE_REPLY); +} + +static void +send_mss_clamp_details (u32 sw_if_index, vl_api_registration_t *rp, + u32 context) +{ + mssc_main_t *cm = &mssc_main; + vl_api_mss_clamp_details_t *rmp; + u16 mss4, mss6; + u8 dir4, dir6; + int rv; + + mss4 = mss6 = 0; + dir4 = dir6 = MSS_CLAMP_DIR_NONE; + rv = mssc_get_mss (sw_if_index, &dir4, &dir6, &mss4, &mss6); + if (rv == VNET_API_ERROR_FEATURE_DISABLED) + return; + + REPLY_MACRO_DETAILS4 (VL_API_MSS_CLAMP_DETAILS, rp, context, ({ + rmp->sw_if_index = htonl (sw_if_index); + rmp->ipv4_mss = htons (mss4); + rmp->ipv6_mss = htons (mss6); + rmp->ipv4_direction = dir4; + rmp->ipv6_direction = dir6; + })); +} + +static void +vl_api_mss_clamp_get_t_handler (vl_api_mss_clamp_get_t *mp) +{ + mssc_main_t *cm = &mssc_main; + vl_api_mss_clamp_get_reply_t *rmp; + int rv = 0; + u32 sw_if_index = ntohl (mp->sw_if_index); + vl_api_registration_t *reg; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + if (sw_if_index == ~0) + { + if (vec_len (cm->dir_enabled4) == 0) + { + REPLY_MACRO2 (VL_API_MSS_CLAMP_GET_REPLY, ({ rmp->cursor = ~0; })); + return; + } + + REPLY_AND_DETAILS_MACRO ( + VL_API_MSS_CLAMP_GET_REPLY, cm->dir_enabled4, + ({ send_mss_clamp_details (cursor, reg, mp->context); })); + } + else + { + VALIDATE_SW_IF_INDEX (mp); + send_mss_clamp_details (sw_if_index, reg, mp->context); + + BAD_SW_IF_INDEX_LABEL; + REPLY_MACRO2 (VL_API_MSS_CLAMP_GET_REPLY, ({ rmp->cursor = ~0; })); + } +} + +/* API definitions */ +#include +#include + +/* Set up the API message handling tables */ +static clib_error_t * +mssc_api_hookup (vlib_main_t *vm) +{ + mssc_main_t *cm = &mssc_main; + + cm->msg_id_base = setup_message_id_table (); + return 0; +} + +VLIB_API_INIT_FUNCTION (mssc_api_hookup); + +VLIB_PLUGIN_REGISTER () = { + .version = VPP_BUILD_VER, + .description = "TCP MSS clamping plugin", +}; + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ -- cgit 1.2.3-korg