aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-09-04 12:09:32 -0400
committerDave Barach <openvpp@barachs.net>2019-09-07 01:26:58 +0000
commitc4abafd83df38051765352785b146277734701f4 (patch)
tree12633dc1337661d1c4d408df2d1bca67e1d940bc /src
parentb736e75d5bb2d132fb00c35b6aabaa52e5f624ad (diff)
ip: fix udp/tcp checksum corner cases
When checksumming chained buffers with odd lengths: insert a NULL byte, or the calculation fails. Type: fix Signed-off-by: Dave Barach <dave@barachs.net> Signed-off-by: John Lo <loj@cisco.com> Change-Id: I380f7c42897bdb28c8c29aa1c4cdaaa849cc9ecc
Diffstat (limited to 'src')
-rw-r--r--src/plugins/oddbuf/CMakeLists.txt33
-rw-r--r--src/plugins/oddbuf/node.c215
-rw-r--r--src/plugins/oddbuf/oddbuf.api51
-rw-r--r--src/plugins/oddbuf/oddbuf.c288
-rw-r--r--src/plugins/oddbuf/oddbuf.h60
-rw-r--r--src/plugins/oddbuf/oddbuf_all_api_h.h19
-rw-r--r--src/plugins/oddbuf/oddbuf_msg_enum.h31
-rw-r--r--src/plugins/oddbuf/oddbuf_periodic.c117
-rw-r--r--src/plugins/oddbuf/oddbuf_test.c173
-rw-r--r--src/vlib/cli.c17
-rw-r--r--src/vnet/ip/ip4_forward.c18
-rw-r--r--src/vnet/ip/ip6_forward.c18
12 files changed, 1035 insertions, 5 deletions
diff --git a/src/plugins/oddbuf/CMakeLists.txt b/src/plugins/oddbuf/CMakeLists.txt
new file mode 100644
index 00000000000..06f8e6f7e61
--- /dev/null
+++ b/src/plugins/oddbuf/CMakeLists.txt
@@ -0,0 +1,33 @@
+
+# Copyright (c) <current-year> <your-organization>
+# 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.
+
+add_vpp_plugin(oddbuf
+ SOURCES
+ oddbuf.c
+ node.c
+ oddbuf.h
+
+ MULTIARCH_SOURCES
+ node.c
+
+ API_FILES
+ oddbuf.api
+
+ INSTALL_HEADERS
+ oddbuf_all_api_h.h
+ oddbuf_msg_enum.h
+
+ API_TEST_SOURCES
+ oddbuf_test.c
+)
diff --git a/src/plugins/oddbuf/node.c b/src/plugins/oddbuf/node.c
new file mode 100644
index 00000000000..d495abaf950
--- /dev/null
+++ b/src/plugins/oddbuf/node.c
@@ -0,0 +1,215 @@
+/*
+ * node.c - skeleton vpp engine plug-in dual-loop node skeleton
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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 <vlib/vlib.h>
+#include <vnet/vnet.h>
+#include <vnet/pg/pg.h>
+#include <vppinfra/error.h>
+#include <oddbuf/oddbuf.h>
+
+typedef struct
+{
+ u32 sw_if_index;
+ u32 next_index;
+ u16 udp_checksum;
+} oddbuf_trace_t;
+
+#ifndef CLIB_MARCH_VARIANT
+
+/* packet trace format function */
+static u8 *
+format_oddbuf_trace (u8 * s, va_list * args)
+{
+ CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
+ CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
+ oddbuf_trace_t *t = va_arg (*args, oddbuf_trace_t *);
+
+ s = format (s, "ODDBUF: sw_if_index %d, next index %d, udp checksum %04x\n",
+ t->sw_if_index, t->next_index, (u32) t->udp_checksum);
+ return s;
+}
+
+vlib_node_registration_t oddbuf_node;
+
+#endif /* CLIB_MARCH_VARIANT */
+
+#define foreach_oddbuf_error \
+_(SWAPPED, "Mac swap packets processed")
+
+typedef enum
+{
+#define _(sym,str) ODDBUF_ERROR_##sym,
+ foreach_oddbuf_error
+#undef _
+ ODDBUF_N_ERROR,
+} oddbuf_error_t;
+
+#ifndef CLIB_MARCH_VARIANT
+static char *oddbuf_error_strings[] = {
+#define _(sym,string) string,
+ foreach_oddbuf_error
+#undef _
+};
+#endif /* CLIB_MARCH_VARIANT */
+
+typedef enum
+{
+ ODDBUF_NEXT_DROP,
+ ODDBUF_N_NEXT,
+} oddbuf_next_t;
+
+
+always_inline uword
+oddbuf_inline (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame,
+ int is_ip4, int is_trace)
+{
+ oddbuf_main_t *om = &oddbuf_main;
+ u32 n_left_from, *from;
+ vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
+ vlib_buffer_t *b0, *b0next;
+ u32 bi;
+ u16 nexts[VLIB_FRAME_SIZE], *next;
+ u16 save_current_length;
+ u32 next0;
+ u8 *src, *dst;
+ int i;
+ ethernet_header_t *eh;
+ ip4_header_t *ip;
+ udp_header_t *udp;
+
+
+ from = vlib_frame_vector_args (frame);
+ n_left_from = frame->n_vectors;
+
+ vlib_get_buffers (vm, from, bufs, n_left_from);
+ b = bufs;
+ next = nexts;
+
+ while (n_left_from > 0)
+ {
+ b0 = b[0];
+ vnet_feature_next (&next0, b0);
+ nexts[0] = next0;
+
+ if (vlib_buffer_alloc (vm, &bi, 1) != 1)
+ {
+ clib_warning ("Buffer alloc fail, skipping");
+ goto skip;
+ }
+
+ if (om->first_chunk_offset)
+ {
+ memmove (b0->data + b0->current_data + om->first_chunk_offset,
+ b0->data + b0->current_data, b0->current_length);
+ b0->current_data += om->first_chunk_offset;
+ }
+
+ eh = vlib_buffer_get_current (b0);
+ ip = (ip4_header_t *) (eh + 1);
+ udp = (udp_header_t *) (ip4_next_header (ip));
+
+ if (1)
+ {
+ save_current_length = vlib_buffer_length_in_chain (vm, b0);
+
+ b0next = vlib_get_buffer (vm, bi);
+ b0->flags |= VLIB_BUFFER_NEXT_PRESENT;
+ b0->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID;
+ b0->next_buffer = bi;
+
+ src = b0->data + b0->current_data + b0->current_length -
+ om->n_to_copy;
+ b0next->current_data = om->second_chunk_offset;
+ b0next->current_length = om->n_to_copy;
+ dst = b0next->data + b0next->current_data;
+
+ for (i = 0; i < om->n_to_copy; i++)
+ dst[i] = src[i];
+
+ b0->current_length -= om->n_to_copy;
+ b0next->current_length = om->n_to_copy;
+
+ if (vlib_buffer_length_in_chain (vm, b0) != save_current_length)
+ clib_warning ("OOPS, length incorrect after chunk split...");
+ }
+
+ udp->checksum = 0;
+ udp->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ip);
+
+ if (is_trace)
+ {
+ if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
+ {
+ oddbuf_trace_t *t =
+ vlib_add_trace (vm, node, b[0], sizeof (*t));
+ t->next_index = next[0];
+ t->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
+ t->udp_checksum = clib_net_to_host_u16 (udp->checksum);
+ }
+ }
+
+ skip:
+ b += 1;
+ next += 1;
+ n_left_from -= 1;
+ }
+
+ vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
+
+ return frame->n_vectors;
+}
+
+VLIB_NODE_FN (oddbuf_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
+ return oddbuf_inline (vm, node, frame, 1 /* is_ip4 */ ,
+ 1 /* is_trace */ );
+ else
+ return oddbuf_inline (vm, node, frame, 1 /* is_ip4 */ ,
+ 0 /* is_trace */ );
+}
+
+/* *INDENT-OFF* */
+#ifndef CLIB_MARCH_VARIANT
+VLIB_REGISTER_NODE (oddbuf_node) =
+{
+ .name = "oddbuf",
+ .vector_size = sizeof (u32),
+ .format_trace = format_oddbuf_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+
+ .n_errors = ARRAY_LEN(oddbuf_error_strings),
+ .error_strings = oddbuf_error_strings,
+
+ .n_next_nodes = ODDBUF_N_NEXT,
+
+ /* edit / add dispositions here */
+ .next_nodes = {
+ [ODDBUF_NEXT_DROP] = "error-drop",
+ },
+};
+#endif /* CLIB_MARCH_VARIANT */
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/plugins/oddbuf/oddbuf.api b/src/plugins/oddbuf/oddbuf.api
new file mode 100644
index 00000000000..32f91548ea2
--- /dev/null
+++ b/src/plugins/oddbuf/oddbuf.api
@@ -0,0 +1,51 @@
+/*
+ * oddbuf.api - binary API skeleton
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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.
+ */
+
+/**
+ * @file oddbuf.api
+ * @brief VPP control-plane API messages.
+ *
+ * This file defines VPP control-plane binary API messages which are generally
+ * called through a shared memory interface.
+ */
+
+/* Version and type recitations */
+
+option version = "0.1.0";
+import "vnet/interface_types.api";
+
+
+/** @brief API to enable / disable oddbuf on an interface
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param enable_disable - 1 to enable, 0 to disable the feature
+ @param sw_if_index - interface handle
+*/
+
+autoreply define oddbuf_enable_disable {
+ /* Client identifier, set from api_main.my_client_index */
+ u32 client_index;
+
+ /* Arbitrary context, so client can match reply to request */
+ u32 context;
+
+ /* Enable / disable the feature */
+ bool enable_disable;
+
+ /* Interface handle */
+ vl_api_interface_index_t sw_if_index;
+};
diff --git a/src/plugins/oddbuf/oddbuf.c b/src/plugins/oddbuf/oddbuf.c
new file mode 100644
index 00000000000..db2e682a676
--- /dev/null
+++ b/src/plugins/oddbuf/oddbuf.c
@@ -0,0 +1,288 @@
+/*
+ * oddbuf.c - skeleton vpp engine plug-in
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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 <vnet/vnet.h>
+#include <vnet/plugin/plugin.h>
+#include <oddbuf/oddbuf.h>
+
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+#include <vpp/app/version.h>
+#include <stdbool.h>
+
+/* define message IDs */
+#include <oddbuf/oddbuf_msg_enum.h>
+
+/* define message structures */
+#define vl_typedefs
+#include <oddbuf/oddbuf_all_api_h.h>
+#undef vl_typedefs
+
+/* define generated endian-swappers */
+#define vl_endianfun
+#include <oddbuf/oddbuf_all_api_h.h>
+#undef vl_endianfun
+
+/* instantiate all the print functions we know about */
+#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
+#define vl_printfun
+#include <oddbuf/oddbuf_all_api_h.h>
+#undef vl_printfun
+
+/* Get the API version number */
+#define vl_api_version(n,v) static u32 api_version=(v);
+#include <oddbuf/oddbuf_all_api_h.h>
+#undef vl_api_version
+
+#define REPLY_MSG_ID_BASE omp->msg_id_base
+#include <vlibapi/api_helper_macros.h>
+
+oddbuf_main_t oddbuf_main;
+
+/* List of message types that this plugin understands */
+
+#define foreach_oddbuf_plugin_api_msg \
+_(ODDBUF_ENABLE_DISABLE, oddbuf_enable_disable)
+
+/* Action function shared between message handler and debug CLI */
+
+int
+oddbuf_enable_disable (oddbuf_main_t * omp, u32 sw_if_index,
+ int enable_disable)
+{
+ vnet_sw_interface_t *sw;
+ int rv = 0;
+
+ /* Utterly wrong? */
+ if (pool_is_free_index (omp->vnet_main->interface_main.sw_interfaces,
+ sw_if_index))
+ return VNET_API_ERROR_INVALID_SW_IF_INDEX;
+
+ /* Not a physical port? */
+ sw = vnet_get_sw_interface (omp->vnet_main, sw_if_index);
+ if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
+ return VNET_API_ERROR_INVALID_SW_IF_INDEX;
+
+ vnet_feature_enable_disable ("device-input", "oddbuf",
+ sw_if_index, enable_disable, 0, 0);
+
+ return rv;
+}
+
+static clib_error_t *
+oddbuf_enable_disable_command_fn (vlib_main_t * vm,
+ unformat_input_t * input,
+ vlib_cli_command_t * cmd)
+{
+ oddbuf_main_t *omp = &oddbuf_main;
+ u32 sw_if_index = ~0;
+ int enable_disable = 1;
+
+ int rv;
+
+ while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (input, "disable"))
+ enable_disable = 0;
+ else if (unformat (input, "%U", unformat_vnet_sw_interface,
+ omp->vnet_main, &sw_if_index))
+ ;
+ else
+ break;
+ }
+
+ if (sw_if_index == ~0)
+ return clib_error_return (0, "Please specify an interface...");
+
+ rv = oddbuf_enable_disable (omp, sw_if_index, enable_disable);
+
+ switch (rv)
+ {
+ case 0:
+ break;
+
+ case VNET_API_ERROR_INVALID_SW_IF_INDEX:
+ return clib_error_return
+ (0, "Invalid interface, only works on physical ports");
+ break;
+
+ case VNET_API_ERROR_UNIMPLEMENTED:
+ return clib_error_return (0,
+ "Device driver doesn't support redirection");
+ break;
+
+ default:
+ return clib_error_return (0, "oddbuf_enable_disable returned %d", rv);
+ }
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (oddbuf_enable_disable_command, static) =
+{
+ .path = "oddbuf enable-disable",
+ .short_help =
+ "oddbuf enable-disable <interface-name> [disable]",
+ .function = oddbuf_enable_disable_command_fn,
+};
+/* *INDENT-ON* */
+
+/* API message handler */
+static void vl_api_oddbuf_enable_disable_t_handler
+ (vl_api_oddbuf_enable_disable_t * mp)
+{
+ vl_api_oddbuf_enable_disable_reply_t *rmp;
+ oddbuf_main_t *omp = &oddbuf_main;
+ int rv;
+
+ rv = oddbuf_enable_disable (omp, ntohl (mp->sw_if_index),
+ (int) (mp->enable_disable));
+
+ REPLY_MACRO (VL_API_ODDBUF_ENABLE_DISABLE_REPLY);
+}
+
+/* Set up the API message handling tables */
+static clib_error_t *
+oddbuf_plugin_api_hookup (vlib_main_t * vm)
+{
+ oddbuf_main_t *omp = &oddbuf_main;
+#define _(N,n) \
+ vl_msg_api_set_handlers((VL_API_##N + omp->msg_id_base), \
+ #n, \
+ vl_api_##n##_t_handler, \
+ vl_noop_handler, \
+ vl_api_##n##_t_endian, \
+ vl_api_##n##_t_print, \
+ sizeof(vl_api_##n##_t), 1);
+ foreach_oddbuf_plugin_api_msg;
+#undef _
+
+ return 0;
+}
+
+#define vl_msg_name_crc_list
+#include <oddbuf/oddbuf_all_api_h.h>
+#undef vl_msg_name_crc_list
+
+static void
+setup_message_id_table (oddbuf_main_t * omp, api_main_t * am)
+{
+#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + omp->msg_id_base);
+ foreach_vl_msg_name_crc_oddbuf;
+#undef _
+}
+
+static clib_error_t *
+oddbuf_init (vlib_main_t * vm)
+{
+ oddbuf_main_t *om = &oddbuf_main;
+ clib_error_t *error = 0;
+ u8 *name;
+
+ om->vlib_main = vm;
+ om->vnet_main = vnet_get_main ();
+
+ name = format (0, "oddbuf_%08x%c", api_version, 0);
+
+ /* Ask for a correctly-sized block of API message decode slots */
+ om->msg_id_base = vl_msg_api_get_msg_ids
+ ((char *) name, VL_MSG_FIRST_AVAILABLE);
+
+ error = oddbuf_plugin_api_hookup (vm);
+
+ /* Add our API messages to the global name_crc hash table */
+ setup_message_id_table (om, &api_main);
+
+ /* Basic setup */
+ om->n_to_copy = 1;
+ om->second_chunk_offset = 1;
+ om->first_chunk_offset = 0;
+
+ vec_free (name);
+
+ return error;
+}
+
+VLIB_INIT_FUNCTION (oddbuf_init);
+
+/* *INDENT-OFF* */
+VNET_FEATURE_INIT (oddbuf, static) =
+{
+ .arc_name = "device-input",
+ .node_name = "oddbuf",
+ .runs_before = VNET_FEATURES ("ethernet-input"),
+};
+/* *INDENT-ON */
+
+/* *INDENT-OFF* */
+VLIB_PLUGIN_REGISTER () =
+{
+ .version = VPP_BUILD_VER,
+ .description = "Awkward chained buffer geometry generator",
+ .default_disabled = 1,
+};
+/* *INDENT-ON* */
+
+
+static clib_error_t *
+oddbuf_config_command_fn (vlib_main_t * vm,
+ unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+ oddbuf_main_t *omp = &oddbuf_main;
+ unformat_input_t _line_input, *line_input = &_line_input;
+
+ /* Get a line of input. */
+ if (!unformat_user (input, unformat_line_input, line_input))
+ return 0;
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (line_input, "n_to_copy %d", &omp->n_to_copy))
+ ;
+ else if (unformat (line_input, "offset %d", &omp->second_chunk_offset))
+ ;
+ else if (unformat (line_input, "first_offset %d",
+ &omp->first_chunk_offset))
+ ;
+ else
+ break;
+ }
+
+ unformat_free (line_input);
+
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (oddbuf_config_command, static) =
+{
+ .path = "oddbuf configure",
+ .short_help =
+ "oddbuf configure n_to_copy <nn> offset <nn> first_offset <nn>",
+ .function = oddbuf_config_command_fn,
+};
+/* *INDENT-ON* */
+
+
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/plugins/oddbuf/oddbuf.h b/src/plugins/oddbuf/oddbuf.h
new file mode 100644
index 00000000000..1aa51e4fe07
--- /dev/null
+++ b/src/plugins/oddbuf/oddbuf.h
@@ -0,0 +1,60 @@
+
+/*
+ * oddbuf.h - skeleton vpp engine plug-in header file
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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.
+ */
+#ifndef __included_oddbuf_h__
+#define __included_oddbuf_h__
+
+#include <vnet/vnet.h>
+#include <vnet/ip/ip.h>
+#include <vnet/udp/udp.h>
+#include <vnet/ethernet/ethernet.h>
+
+#include <vppinfra/hash.h>
+#include <vppinfra/error.h>
+
+typedef struct
+{
+ /* API message ID base */
+ u16 msg_id_base;
+
+ /* on/off switch for the periodic function */
+ u8 periodic_timer_enabled;
+
+ /* config parameters */
+ int n_to_copy;
+ int second_chunk_offset;
+ int first_chunk_offset;
+
+ /* convenience */
+ vlib_main_t *vlib_main;
+ vnet_main_t *vnet_main;
+ ethernet_main_t *ethernet_main;
+} oddbuf_main_t;
+
+extern oddbuf_main_t oddbuf_main;
+
+extern vlib_node_registration_t oddbuf_node;
+
+#endif /* __included_oddbuf_h__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/plugins/oddbuf/oddbuf_all_api_h.h b/src/plugins/oddbuf/oddbuf_all_api_h.h
new file mode 100644
index 00000000000..64a1a6bf951
--- /dev/null
+++ b/src/plugins/oddbuf/oddbuf_all_api_h.h
@@ -0,0 +1,19 @@
+
+/*
+ * oddbuf_all_api_h.h - skeleton vpp engine plug-in api #include file
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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 the generated file, see BUILT_SOURCES in Makefile.am */
+#include <oddbuf/oddbuf.api.h>
diff --git a/src/plugins/oddbuf/oddbuf_msg_enum.h b/src/plugins/oddbuf/oddbuf_msg_enum.h
new file mode 100644
index 00000000000..8e324d67c55
--- /dev/null
+++ b/src/plugins/oddbuf/oddbuf_msg_enum.h
@@ -0,0 +1,31 @@
+
+/*
+ * oddbuf_msg_enum.h - skeleton vpp engine plug-in message enumeration
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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.
+ */
+#ifndef included_oddbuf_msg_enum_h
+#define included_oddbuf_msg_enum_h
+
+#include <vppinfra/byte_order.h>
+
+#define vl_msg_id(n,h) n,
+typedef enum {
+#include <oddbuf/oddbuf_all_api_h.h>
+ /* We'll want to know how many messages IDs we need... */
+ VL_MSG_FIRST_AVAILABLE,
+} vl_msg_id_t;
+#undef vl_msg_id
+
+#endif /* included_oddbuf_msg_enum_h */
diff --git a/src/plugins/oddbuf/oddbuf_periodic.c b/src/plugins/oddbuf/oddbuf_periodic.c
new file mode 100644
index 00000000000..c88e74915a6
--- /dev/null
+++ b/src/plugins/oddbuf/oddbuf_periodic.c
@@ -0,0 +1,117 @@
+/*
+ * oddbuf_periodic.c - skeleton plug-in periodic function
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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 <vlib/vlib.h>
+#include <vppinfra/error.h>
+#include <oddbuf/oddbuf.h>
+
+static void
+handle_event1 (oddbuf_main_t * pm, f64 now, uword event_data)
+{
+ clib_warning ("received ODDBUF_EVENT1");
+}
+
+static void
+handle_event2 (oddbuf_main_t * pm, f64 now, uword event_data)
+{
+ clib_warning ("received ODDBUF_EVENT2");
+}
+
+static void
+handle_periodic_enable_disable (oddbuf_main_t * pm, f64 now, uword event_data)
+{
+ clib_warning ("Periodic timeouts now %s",
+ event_data ? "enabled" : "disabled");
+ pm->periodic_timer_enabled = event_data;
+}
+
+static void
+handle_timeout (oddbuf_main_t * pm, f64 now)
+{
+ clib_warning ("timeout at %.2f", now);
+}
+
+static uword
+oddbuf_periodic_process (vlib_main_t * vm,
+ vlib_node_runtime_t * rt, vlib_frame_t * f)
+{
+ oddbuf_main_t *pm = &oddbuf_main;
+ f64 now;
+ f64 timeout = 10.0;
+ uword *event_data = 0;
+ uword event_type;
+ int i;
+
+ while (1)
+ {
+ if (pm->periodic_timer_enabled)
+ vlib_process_wait_for_event_or_clock (vm, timeout);
+ else
+ vlib_process_wait_for_event (vm);
+
+ now = vlib_time_now (vm);
+
+ event_type = vlib_process_get_events (vm, (uword **) & event_data);
+
+ switch (event_type)
+ {
+ /* Handle ODDBUF_EVENT1 */
+ case ODDBUF_EVENT1:
+ for (i = 0; i < vec_len (event_data); i++)
+ handle_event1 (pm, now, event_data[i]);
+ break;
+
+ /* Handle ODDBUF_EVENT2 */
+ case ODDBUF_EVENT2:
+ for (i = 0; i < vec_len (event_data); i++)
+ handle_event2 (pm, now, event_data[i]);
+ break;
+ /* Handle the periodic timer on/off event */
+ case ODDBUF_EVENT_PERIODIC_ENABLE_DISABLE:
+ for (i = 0; i < vec_len (event_data); i++)
+ handle_periodic_enable_disable (pm, now, event_data[i]);
+ break;
+
+ /* Handle periodic timeouts */
+ case ~0:
+ handle_timeout (pm, now);
+ break;
+ }
+ vec_reset_length (event_data);
+ }
+ return 0; /* or not */
+}
+
+void
+oddbuf_create_periodic_process (oddbuf_main_t * omp)
+{
+ /* Already created the process node? */
+ if (omp->periodic_node_index > 0)
+ return;
+
+ /* No, create it now and make a note of the node index */
+ omp->periodic_node_index = vlib_process_create (omp->vlib_main, "oddbuf-periodic-process", oddbuf_periodic_process, 16 /* log2_n_stack_bytes */
+ );
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/plugins/oddbuf/oddbuf_test.c b/src/plugins/oddbuf/oddbuf_test.c
new file mode 100644
index 00000000000..a9c846559c8
--- /dev/null
+++ b/src/plugins/oddbuf/oddbuf_test.c
@@ -0,0 +1,173 @@
+/*
+ * oddbuf.c - skeleton vpp-api-test plug-in
+ *
+ * Copyright (c) <current-year> <your-organization>
+ * 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 <vat/vat.h>
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+#include <vppinfra/error.h>
+#include <stdbool.h>
+
+uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
+
+/* Declare message IDs */
+#include <oddbuf/oddbuf_msg_enum.h>
+
+/* define message structures */
+#define vl_typedefs
+#include <oddbuf/oddbuf_all_api_h.h>
+#undef vl_typedefs
+
+/* declare message handlers for each api */
+
+#define vl_endianfun /* define message structures */
+#include <oddbuf/oddbuf_all_api_h.h>
+#undef vl_endianfun
+
+/* instantiate all the print functions we know about */
+#define vl_print(handle, ...)
+#define vl_printfun
+#include <oddbuf/oddbuf_all_api_h.h>
+#undef vl_printfun
+
+/* Get the API version number. */
+#define vl_api_version(n,v) static u32 api_version=(v);
+#include <oddbuf/oddbuf_all_api_h.h>
+#undef vl_api_version
+
+
+typedef struct
+{
+ /* API message ID base */
+ u16 msg_id_base;
+ vat_main_t *vat_main;
+} oddbuf_test_main_t;
+
+oddbuf_test_main_t oddbuf_test_main;
+
+#define __plugin_msg_base oddbuf_test_main.msg_id_base
+#include <vlibapi/vat_helper_macros.h>
+
+#define foreach_standard_reply_retval_handler \
+_(oddbuf_enable_disable_reply)
+
+#define _(n) \
+ static void vl_api_##n##_t_handler \
+ (vl_api_##n##_t * mp) \
+ { \
+ vat_main_t * vam = oddbuf_test_main.vat_main; \
+ i32 retval = ntohl(mp->retval); \
+ if (vam->async_mode) { \
+ vam->async_errors += (retval < 0); \
+ } else { \
+ vam->retval = retval; \
+ vam->result_ready = 1; \
+ } \
+ }
+foreach_standard_reply_retval_handler;
+#undef _
+
+/*
+ * Table of message reply handlers, must include boilerplate handlers
+ * we just generated
+ */
+#define foreach_vpe_api_reply_msg \
+_(ODDBUF_ENABLE_DISABLE_REPLY, oddbuf_enable_disable_reply)
+
+
+static int
+api_oddbuf_enable_disable (vat_main_t * vam)
+{
+ unformat_input_t *i = vam->input;
+ int enable_disable = 1;
+ u32 sw_if_index = ~0;
+ vl_api_oddbuf_enable_disable_t *mp;
+ int ret;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
+ ;
+ else if (unformat (i, "sw_if_index %d", &sw_if_index))
+ ;
+ else if (unformat (i, "disable"))
+ enable_disable = 0;
+ else
+ break;
+ }
+
+ if (sw_if_index == ~0)
+ {
+ errmsg ("missing interface name / explicit sw_if_index number \n");
+ return -99;
+ }
+
+ /* Construct the API message */
+ M (ODDBUF_ENABLE_DISABLE, mp);
+ mp->sw_if_index = ntohl (sw_if_index);
+ mp->enable_disable = enable_disable;
+
+ /* send it... */
+ S (mp);
+
+ /* Wait for a reply... */
+ W (ret);
+ return ret;
+}
+
+/*
+ * List of messages that the api test plugin sends,
+ * and that the data plane plugin processes
+ */
+#define foreach_vpe_api_msg \
+_(oddbuf_enable_disable, "<intfc> [disable]")
+
+static void
+oddbuf_api_hookup (vat_main_t * vam)
+{
+ oddbuf_test_main_t *otmp = &oddbuf_test_main;
+ /* Hook up handlers for replies from the data plane plug-in */
+#define _(N,n) \
+ vl_msg_api_set_handlers((VL_API_##N + otmp->msg_id_base), \
+ #n, \
+ vl_api_##n##_t_handler, \
+ vl_noop_handler, \
+ vl_api_##n##_t_endian, \
+ vl_api_##n##_t_print, \
+ sizeof(vl_api_##n##_t), 1);
+ foreach_vpe_api_reply_msg;
+#undef _
+
+ /* API messages we can send */
+#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
+ foreach_vpe_api_msg;
+#undef _
+
+ /* Help strings */
+#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
+ foreach_vpe_api_msg;
+#undef _
+}
+
+VAT_PLUGIN_REGISTER (oddbuf);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vlib/cli.c b/src/vlib/cli.c
index 60895bacb1c..131a5931ac2 100644
--- a/src/vlib/cli.c
+++ b/src/vlib/cli.c
@@ -1709,6 +1709,23 @@ VLIB_CLI_COMMAND (elog_trace_command, static) =
/* *INDENT-ON* */
static clib_error_t *
+suspend_command_fn (vlib_main_t * vm,
+ unformat_input_t * input, vlib_cli_command_t * cmd)
+{
+ vlib_process_suspend (vm, 30e-3);
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (suspend_command, static) =
+{
+ .path = "suspend",
+ .short_help = "suspend debug CLI for 30ms",
+ .function = suspend_command_fn,
+};
+/* *INDENT-ON* */
+
+static clib_error_t *
vlib_cli_init (vlib_main_t * vm)
{
vlib_cli_main_t *cm = &vm->cli_main;
diff --git a/src/vnet/ip/ip4_forward.c b/src/vnet/ip/ip4_forward.c
index caf02d118cb..ecb35955798 100644
--- a/src/vnet/ip/ip4_forward.c
+++ b/src/vnet/ip/ip4_forward.c
@@ -1303,7 +1303,8 @@ ip4_tcp_udp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
u32 ip_header_length, payload_length_host_byte_order;
u32 n_this_buffer, n_bytes_left, n_ip_bytes_this_buffer;
u16 sum16;
- void *data_this_buffer;
+ u8 *data_this_buffer;
+ u8 length_odd;
/* Initialize checksum with ip header. */
ip_header_length = ip4_header_bytes (ip0);
@@ -1327,7 +1328,7 @@ ip4_tcp_udp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
ip_csum_with_carry (sum0, clib_mem_unaligned (&ip0->src_address, u64));
n_bytes_left = n_this_buffer = payload_length_host_byte_order;
- data_this_buffer = (void *) ip0 + ip_header_length;
+ data_this_buffer = (u8 *) ip0 + ip_header_length;
n_ip_bytes_this_buffer =
p0->current_length - (((u8 *) ip0 - p0->data) - p0->current_data);
if (n_this_buffer + ip_header_length > n_ip_bytes_this_buffer)
@@ -1335,6 +1336,7 @@ ip4_tcp_udp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
n_this_buffer = n_ip_bytes_this_buffer > ip_header_length ?
n_ip_bytes_this_buffer - ip_header_length : 0;
}
+
while (1)
{
sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
@@ -1346,13 +1348,23 @@ ip4_tcp_udp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT))
return 0xfefe;
+ length_odd = (n_this_buffer & 1);
+
p0 = vlib_get_buffer (vm, p0->next_buffer);
data_this_buffer = vlib_buffer_get_current (p0);
n_this_buffer = clib_min (p0->current_length, n_bytes_left);
+
+ if (PREDICT_FALSE (length_odd))
+ {
+ /* Prepend a 0 or the resulting checksum will be incorrect. */
+ data_this_buffer--;
+ n_this_buffer++;
+ n_bytes_left++;
+ data_this_buffer[0] = 0;
+ }
}
sum16 = ~ip_csum_fold (sum0);
-
return sum16;
}
diff --git a/src/vnet/ip/ip6_forward.c b/src/vnet/ip/ip6_forward.c
index 252bdf975be..067db77c412 100644
--- a/src/vnet/ip/ip6_forward.c
+++ b/src/vnet/ip/ip6_forward.c
@@ -1017,7 +1017,8 @@ ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
u16 sum16, payload_length_host_byte_order;
u32 i, n_this_buffer, n_bytes_left;
u32 headers_size = sizeof (ip0[0]);
- void *data_this_buffer;
+ u8 *data_this_buffer;
+ u8 length_odd;
ASSERT (bogus_lengthp);
*bogus_lengthp = 0;
@@ -1025,7 +1026,7 @@ ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
/* Initialize checksum with ip header. */
sum0 = ip0->payload_length + clib_host_to_net_u16 (ip0->protocol);
payload_length_host_byte_order = clib_net_to_host_u16 (ip0->payload_length);
- data_this_buffer = (void *) (ip0 + 1);
+ data_this_buffer = (u8 *) (ip0 + 1);
for (i = 0; i < ARRAY_LEN (ip0->src_address.as_uword); i++)
{
@@ -1078,14 +1079,27 @@ ip6_tcp_udp_icmp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
if (n_bytes_left == 0)
break;
+ ASSERT (p0->flags & VLIB_BUFFER_NEXT_PRESENT);
if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT))
{
*bogus_lengthp = 1;
return 0xfefe;
}
+
+ length_odd = (n_this_buffer & 1);
+
p0 = vlib_get_buffer (vm, p0->next_buffer);
data_this_buffer = vlib_buffer_get_current (p0);
n_this_buffer = clib_min (p0->current_length, n_bytes_left);
+
+ if (PREDICT_FALSE (length_odd))
+ {
+ /* Prepend a 0 or the resulting checksum will be incorrect. */
+ data_this_buffer--;
+ n_this_buffer++;
+ n_bytes_left++;
+ data_this_buffer[0] = 0;
+ }
}
sum16 = ~ip_csum_fold (sum0);