From patchwork Mon Mar 6 05:25:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 735537 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vc7ct2Cvdz9s7t for ; Mon, 6 Mar 2017 16:29:02 +1100 (AEDT) Received: from localhost ([::1]:41781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklCd-00015y-NP for incoming@patchwork.ozlabs.org; Mon, 06 Mar 2017 00:28:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckl9q-0007f1-6o for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckl9p-0000zN-5U for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41810) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckl9o-0000ym-Sf; Mon, 06 Mar 2017 00:26:05 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9700C0467CE; Mon, 6 Mar 2017 05:26:04 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvtu031786; Mon, 6 Mar 2017 00:26:02 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:37 +0800 Message-Id: <1488777954-4578-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 06 Mar 2017 05:26:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 02/19] eth: Extend vlan stripping functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fleytman , Jason Wang , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Dmitry Fleytman Make VLAN stripping functions return number of bytes copied to given Ethernet header buffer. This information should be used to re-compose packet IOV after VLAN stripping. Cc: qemu-stable@nongnu.org Signed-off-by: Dmitry Fleytman Signed-off-by: Jason Wang --- include/net/eth.h | 4 ++-- net/eth.c | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/net/eth.h b/include/net/eth.h index 2013175..afeb45b 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -331,12 +331,12 @@ eth_get_pkt_tci(const void *p) } } -bool +size_t eth_strip_vlan(const struct iovec *iov, int iovcnt, size_t iovoff, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci); -bool +size_t eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, size_t iovoff, uint16_t vet, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci); diff --git a/net/eth.c b/net/eth.c index df81efb..5b9ba26 100644 --- a/net/eth.c +++ b/net/eth.c @@ -232,7 +232,7 @@ void eth_get_protocols(const struct iovec *iov, int iovcnt, } } -bool +size_t eth_strip_vlan(const struct iovec *iov, int iovcnt, size_t iovoff, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci) @@ -244,7 +244,7 @@ eth_strip_vlan(const struct iovec *iov, int iovcnt, size_t iovoff, new_ehdr, sizeof(*new_ehdr)); if (copied < sizeof(*new_ehdr)) { - return false; + return 0; } switch (be16_to_cpu(new_ehdr->h_proto)) { @@ -254,7 +254,7 @@ eth_strip_vlan(const struct iovec *iov, int iovcnt, size_t iovoff, &vlan_hdr, sizeof(vlan_hdr)); if (copied < sizeof(vlan_hdr)) { - return false; + return 0; } new_ehdr->h_proto = vlan_hdr.h_proto; @@ -268,18 +268,21 @@ eth_strip_vlan(const struct iovec *iov, int iovcnt, size_t iovoff, PKT_GET_VLAN_HDR(new_ehdr), sizeof(vlan_hdr)); if (copied < sizeof(vlan_hdr)) { - return false; + return 0; } *payload_offset += sizeof(vlan_hdr); + + return sizeof(struct eth_header) + sizeof(struct vlan_header); + } else { + return sizeof(struct eth_header); } - return true; default: - return false; + return 0; } } -bool +size_t eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, size_t iovoff, uint16_t vet, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci) @@ -291,7 +294,7 @@ eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, size_t iovoff, new_ehdr, sizeof(*new_ehdr)); if (copied < sizeof(*new_ehdr)) { - return false; + return 0; } if (be16_to_cpu(new_ehdr->h_proto) == vet) { @@ -299,17 +302,17 @@ eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, size_t iovoff, &vlan_hdr, sizeof(vlan_hdr)); if (copied < sizeof(vlan_hdr)) { - return false; + return 0; } new_ehdr->h_proto = vlan_hdr.h_proto; *tci = be16_to_cpu(vlan_hdr.h_tci); *payload_offset = iovoff + sizeof(*new_ehdr) + sizeof(vlan_hdr); - return true; + return sizeof(struct eth_header); } - return false; + return 0; } void