From patchwork Tue Jul 10 20:40:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 942188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41QDcS3K7pz9s0W for ; Wed, 11 Jul 2018 06:40:56 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id EFACCD9C; Tue, 10 Jul 2018 20:40:53 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 9E5B6D7E for ; Tue, 10 Jul 2018 20:40:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 17BFD67E for ; Tue, 10 Jul 2018 20:40:51 +0000 (UTC) X-Originating-IP: 208.91.3.26 Received: from sigabrt.benpfaff.org (unknown [208.91.3.26]) (Authenticated sender: blp@ovn.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id ACD6B1BF20B; Tue, 10 Jul 2018 20:40:49 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Tue, 10 Jul 2018 13:40:45 -0700 Message-Id: <20180710204045.17981-1-blp@ovn.org> X-Mailer: git-send-email 2.16.1 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH v2] ovs-ofctl: New helper command "parse-packet". X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org This was useful for testing commit 4fe080160685 ("flow: Fix buffer overread for crafted IPv6 packets."). Signed-off-by: Ben Pfaff Tested-by: Yifeng Sun Reviewed-by: Yifeng Sun --- 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 }, };