[ovs-dev] [PATCH v2] ovs-ofctl: New helper command "parse-packet".
Yifeng Sun
pkusunyifeng at gmail.com
Thu Jul 12 22:11:14 UTC 2018
Thanks. It worked like a charm.
Tested-by: Yifeng Sun <pkusunyifeng at gmail.com>
Reviewed-by: Yifeng Sun <pkusunyifeng at gmail.com>
On Tue, Jul 10, 2018 at 1:40 PM, Ben Pfaff <blp at ovn.org> wrote:
> This was useful for testing commit 4fe080160685 ("flow: Fix buffer overread
> for crafted IPv6 packets.").
>
> Signed-off-by: Ben Pfaff <blp at ovn.org>
> ---
> v1->v2: Updated commit message.
>
> utilities/ovs-ofctl.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
> index 0cd0fcb63e4b..ee08178d8fff 100644
> --- a/utilities/ovs-ofctl.c
> +++ b/utilities/ovs-ofctl.c
> @@ -4802,6 +4802,24 @@ ofctl_compose_packet(struct ovs_cmdl_context *ctx)
> }
> }
>
> +/* "parse-packet" reads an Ethernet packet from stdin and prints it out
> its
> + * extracted flow fields. */
> +static void
> +ofctl_parse_packet(struct ovs_cmdl_context *ctx OVS_UNUSED)
> +{
> + char packet[65535];
> + ssize_t size = read(STDIN_FILENO, packet, sizeof packet);
> + if (size < 0) {
> + ovs_fatal(errno, "failed to read packet from stdin");
> + }
> +
> + /* Make a copy of the packet in allocated memory to better allow
> Valgrind
> + * and Address Sanitizer to catch out-of-range access. */
> + void *packet_copy = xmemdup(packet, size);
> + ofp_print_packet(stdout, packet_copy, size, 0);
> + free(packet_copy);
> +}
> +
> static const struct ovs_cmdl_command all_commands[] = {
> { "show", "switch",
> 1, 1, ofctl_show, OVS_RO },
> @@ -4936,6 +4954,7 @@ static const struct ovs_cmdl_command all_commands[]
> = {
> { "encode-hello", NULL, 1, 1, ofctl_encode_hello, OVS_RW },
> { "parse-key-value", NULL, 1, INT_MAX, ofctl_parse_key_value, OVS_RW
> },
> { "compose-packet", NULL, 1, 2, ofctl_compose_packet, OVS_RO },
> + { "parse-packet", NULL, 0, 0, ofctl_parse_packet, OVS_RO },
>
> { NULL, NULL, 0, 0, NULL, OVS_RO },
> };
> --
> 2.16.1
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
More information about the dev
mailing list