From: Jason Wang <jasowang@redhat.com>
To: Jean-Christophe Dubois <jcd@tribudubois.net>,
qemu-devel@nongnu.org, peter.maydell@linaro.org
Subject: Re: [Qemu-devel] [PATCH v3 2/5] net: handle optional VLAN header in checksum computation.
Date: Wed, 18 May 2016 11:26:41 +0800 [thread overview]
Message-ID: <573BE0F1.4010808@redhat.com> (raw)
In-Reply-To: <ba335b8b410d26197e423ca854f483a67e631d63.1462736067.git.jcd@tribudubois.net>
On 2016年05月09日 03:41, Jean-Christophe Dubois wrote:
> Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
> ---
>
> Changes since v1:
> * Not present on v1
>
> Changes since v2:
> * Not present on v2
>
> net/checksum.c | 35 +++++++++++++++++++++++++++++++----
> 1 file changed, 31 insertions(+), 4 deletions(-)
>
> diff --git a/net/checksum.c b/net/checksum.c
> index f62b18a..8acd997 100644
> --- a/net/checksum.c
> +++ b/net/checksum.c
> @@ -55,7 +55,7 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
>
> void net_checksum_calculate(uint8_t *data, int length)
> {
> - int ip_len;
> + int ip_hdr_len, ip_len;
> struct ip_header *ip;
>
> /*
> @@ -64,12 +64,39 @@ void net_checksum_calculate(uint8_t *data, int length)
> * struct members (just in case).
> */
>
> - /* Ensure data has complete L2 & L3 headers. */
> - if (length < (sizeof(struct eth_header) + sizeof(struct ip_header))) {
> + /* Ensure we have at least an Eth header */
> + if (length < sizeof(struct eth_header)) {
> return;
> }
>
> - ip = (struct ip_header *)(data + sizeof(struct eth_header));
> + /* Handle the optionnal VLAN headers */
> + switch (lduw_be_p(&PKT_GET_ETH_HDR(data)->h_proto)) {
> + case ETH_P_VLAN:
> + ip_hdr_len = sizeof(struct eth_header) +
> + sizeof(struct vlan_header);
Then "mac_hdr_len" seems much better than "ip_hdr_len".
> + break;
> + case ETH_P_DVLAN:
> + if (lduw_be_p(&PKT_GET_VLAN_HDR(data)->h_proto) == ETH_P_VLAN) {
> + ip_hdr_len = sizeof(struct eth_header) +
> + 2 * sizeof(struct vlan_header);
> + } else {
> + ip_hdr_len = sizeof(struct eth_header) +
> + sizeof(struct vlan_header);
> + }
> + break;
> + default:
> + ip_hdr_len = sizeof(struct eth_header);
> + break;
> + }
> +
> + length -= ip_hdr_len;
> +
> + /* Now check we have an IP header (with an optionnal VLAN header) */
> + if (length < sizeof(struct ip_header)) {
> + return;
> + }
> +
> + ip = (struct ip_header *)(data + ip_hdr_len);
>
> if (IP_HEADER_VERSION(ip) != IP_HEADER_VERSION_4) {
> return; /* not IPv4 */
next prev parent reply other threads:[~2016-05-18 3:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-08 19:40 [Qemu-devel] [PATCH v3 0/5] Add Ethernet device for i.MX6 SOC Jean-Christophe Dubois
2016-05-08 19:40 ` [Qemu-devel] [PATCH v3 1/5] net: improve UDP/TCP checksum computation Jean-Christophe Dubois
2016-05-08 19:41 ` [Qemu-devel] [PATCH v3 2/5] net: handle optional VLAN header in " Jean-Christophe Dubois
2016-05-18 3:26 ` Jason Wang [this message]
2016-05-08 19:41 ` [Qemu-devel] [PATCH v3 3/5] i.MX: move FEC device to a register array structure Jean-Christophe Dubois
2016-05-17 12:47 ` Peter Maydell
2016-05-08 19:41 ` [Qemu-devel] [PATCH v3 4/5] Add ENET/Gbps Ethernet support to FEC device Jean-Christophe Dubois
2016-05-17 12:59 ` Peter Maydell
2016-05-08 19:41 ` [Qemu-devel] [PATCH v3 5/5] Add ENET device to i.MX6 SOC Jean-Christophe Dubois
2016-05-17 13:00 ` [Qemu-devel] [PATCH v3 0/5] Add Ethernet device for " Peter Maydell
2016-05-18 3:10 ` Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=573BE0F1.4010808@redhat.com \
--to=jasowang@redhat.com \
--cc=jcd@tribudubois.net \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.