From d162f3dcfd54c133fdb335a1c1c89223e8e1a1cd Mon Sep 17 00:00:00 2001 From: Matus Fabian Date: Mon, 5 Dec 2016 01:05:35 -0800 Subject: api: set interface MTU API (VPP-442) Change-Id: I67178f2703febb8ad3eb011606cb8a86fab5ee94 Signed-off-by: Matus Fabian --- vnet/vnet/interface.api | 24 ++++++++++++++++++++++++ vnet/vnet/interface_api.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) (limited to 'vnet') diff --git a/vnet/vnet/interface.api b/vnet/vnet/interface.api index acc52a81724..77f5cfe3e2a 100644 --- a/vnet/vnet/interface.api +++ b/vnet/vnet/interface.api @@ -29,3 +29,27 @@ define sw_interface_set_flags_reply i32 retval; }; +/** \brief Set interface MTU + @param client_index - opaque cookie to identify the sender + @param context - sender context, to match reply w/ request + @param sw_if_index - index of the interface to set MTU on + @param mtu - MTU +*/ +define sw_interface_set_mtu +{ + u32 client_index; + u32 context; + u32 sw_if_index; + u16 mtu; +}; + +/** \brief Reply to sw_interface_set_mtu + @param context - sender context which was passed in the request + @param retval - return code of the set flags request +*/ +define sw_interface_set_mtu_reply +{ + u32 context; + i32 retval; +}; + diff --git a/vnet/vnet/interface_api.c b/vnet/vnet/interface_api.c index eeb1d81d4d0..41fded791d9 100644 --- a/vnet/vnet/interface_api.c +++ b/vnet/vnet/interface_api.c @@ -22,6 +22,7 @@ #include #include +#include #include @@ -42,7 +43,8 @@ #include #define foreach_vpe_api_msg \ -_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) +_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \ +_(SW_INTERFACE_SET_MTU, sw_interface_set_mtu) static void vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp) @@ -68,6 +70,50 @@ vl_api_sw_interface_set_flags_t_handler (vl_api_sw_interface_set_flags_t * mp) REPLY_MACRO (VL_API_SW_INTERFACE_SET_FLAGS_REPLY); } +static void +vl_api_sw_interface_set_mtu_t_handler (vl_api_sw_interface_set_mtu_t * mp) +{ + vl_api_sw_interface_set_mtu_reply_t *rmp; + vnet_main_t *vnm = vnet_get_main (); + u32 flags = ETHERNET_INTERFACE_FLAG_MTU; + u32 sw_if_index = ntohl (mp->sw_if_index); + u16 mtu = ntohs (mp->mtu); + ethernet_main_t *em = ðernet_main; + int rv = 0; + + VALIDATE_SW_IF_INDEX (mp); + + vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, sw_if_index); + ethernet_interface_t *eif = ethernet_get_interface (em, sw_if_index); + + if (!eif) + { + rv = VNET_API_ERROR_FEATURE_DISABLED; + goto bad_sw_if_index; + } + + if (mtu < hi->min_supported_packet_bytes) + { + rv = VNET_API_ERROR_INVALID_VALUE; + goto bad_sw_if_index; + } + + if (mtu > hi->max_supported_packet_bytes) + { + rv = VNET_API_ERROR_INVALID_VALUE; + goto bad_sw_if_index; + } + + if (hi->max_packet_bytes != mtu) + { + hi->max_packet_bytes = mtu; + ethernet_set_flags (vnm, sw_if_index, flags); + } + + BAD_SW_IF_INDEX_LABEL; + REPLY_MACRO (VL_API_SW_INTERFACE_SET_MTU_REPLY); +} + /* * vpe_api_hookup -- cgit 1.2.3-korg