2 * mss_clamp_api.c - TCP MSS clamping plug-in
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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 */
27 #define REPLY_MSG_ID_BASE cm->msg_id_base
28 #include <vlibapi/api_helper_macros.h>
30 /* API message handler */
32 vl_api_mss_clamp_enable_disable_t_handler (
33 vl_api_mss_clamp_enable_disable_t *mp)
35 mssc_main_t *cm = &mssc_main;
36 vl_api_mss_clamp_enable_disable_reply_t *rmp;
40 sw_if_index = ntohl (mp->sw_if_index);
42 VALIDATE_SW_IF_INDEX (mp);
45 mssc_enable_disable (sw_if_index, mp->ipv4_direction, mp->ipv6_direction,
46 ntohs (mp->ipv4_mss), ntohs (mp->ipv6_mss));
48 BAD_SW_IF_INDEX_LABEL;
49 REPLY_MACRO (VL_API_MSS_CLAMP_ENABLE_DISABLE_REPLY);
53 send_mss_clamp_details (u32 sw_if_index, vl_api_registration_t *rp,
56 mssc_main_t *cm = &mssc_main;
57 vl_api_mss_clamp_details_t *rmp;
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)
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;
78 vl_api_mss_clamp_get_t_handler (vl_api_mss_clamp_get_t *mp)
80 mssc_main_t *cm = &mssc_main;
81 vl_api_mss_clamp_get_reply_t *rmp;
83 u32 sw_if_index = ntohl (mp->sw_if_index);
84 vl_api_registration_t *reg;
86 reg = vl_api_client_index_to_registration (mp->client_index);
90 if (sw_if_index == ~0)
92 if (vec_len (cm->dir_enabled4) == 0)
94 REPLY_MACRO2 (VL_API_MSS_CLAMP_GET_REPLY, ({ rmp->cursor = ~0; }));
98 REPLY_AND_DETAILS_VEC_MACRO (
99 VL_API_MSS_CLAMP_GET_REPLY, cm->dir_enabled4, mp, rmp, rv,
100 ({ send_mss_clamp_details (cursor, reg, mp->context); }));
104 VALIDATE_SW_IF_INDEX (mp);
105 send_mss_clamp_details (sw_if_index, reg, mp->context);
107 BAD_SW_IF_INDEX_LABEL;
108 REPLY_MACRO2 (VL_API_MSS_CLAMP_GET_REPLY, ({ rmp->cursor = ~0; }));
112 /* API definitions */
113 #include <vnet/format_fns.h>
114 #include <mss_clamp/mss_clamp.api.c>
116 /* Set up the API message handling tables */
117 static clib_error_t *
118 mssc_api_hookup (vlib_main_t *vm)
120 mssc_main_t *cm = &mssc_main;
122 cm->msg_id_base = setup_message_id_table ();
126 VLIB_API_INIT_FUNCTION (mssc_api_hookup);
128 VLIB_PLUGIN_REGISTER () = {
129 .version = VPP_BUILD_VER,
130 .description = "TCP MSS clamping plugin",
134 * fd.io coding-style-patch-verification: ON
137 * eval: (c-set-style "gnu")