From: Thomas Huth <thuth@redhat.com>
To: Samuel Thibault <samuel.thibault@ens-lyon.org>, qemu-devel@nongnu.org
Cc: zhanghailiang <zhang.zhanghailiang@huawei.com>,
Li Zhijian <lizhijian@cn.fujitsu.com>,
Stefan Hajnoczi <stefanha@gmail.com>,
Jason Wang <jasowang@redhat.com>,
Dave Gilbert <dgilbert@redhat.com>,
Vasiliy Tolstov <v.tolstov@selfip.ru>,
Huangpeng <peter.huangpeng@huawei.com>,
Gonglei <arei.gonglei@huawei.com>,
Jan Kiszka <jan.kiszka@siemens.com>,
Guillaume Subiron <maethor@subiron.org>
Subject: Re: [Qemu-devel] [PATCHv7 4/9] slirp: Factorizing tcpiphdr structure with an union
Date: Fri, 19 Feb 2016 14:44:59 +0100 [thread overview]
Message-ID: <56C71C5B.1040805@redhat.com> (raw)
In-Reply-To: <e9b57bb9d1b749fe7858d42bce620e64e1046fa3.1455471945.git.samuel.thibault@ens-lyon.org>
On 14.02.2016 18:47, Samuel Thibault wrote:
> From: Guillaume Subiron <maethor@subiron.org>
>
> This patch factorizes the tcpiphdr structure to put the IPv4 fields in
> an union, for addition of version 6 in further patch.
> Using some macros, retrocompatibility of the existing code is assured.
>
> This patch also fixes the SLIRP_MSIZE and margin computation in various
> functions, and makes them compatible with the new tcpiphdr structure,
> whose size will be bigger than sizeof(struct tcphdr) + sizeof(struct ip)
>
> Signed-off-by: Guillaume Subiron <maethor@subiron.org>
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> ---
> slirp/if.h | 4 ++--
> slirp/mbuf.c | 3 ++-
> slirp/slirp.c | 15 ++++++++-------
> slirp/socket.c | 13 ++++++++++++-
> slirp/tcp_input.c | 31 ++++++++++++++++++++-----------
> slirp/tcp_output.c | 18 +++++++++++++-----
> slirp/tcp_subr.c | 31 ++++++++++++++++++++++---------
> slirp/tcpip.h | 31 +++++++++++++++++++++++--------
> 8 files changed, 102 insertions(+), 44 deletions(-)
>
> diff --git a/slirp/if.h b/slirp/if.h
> index 3327023..c7a5c57 100644
> --- a/slirp/if.h
> +++ b/slirp/if.h
> @@ -17,7 +17,7 @@
> #define IF_MRU 1500
> #define IF_COMP IF_AUTOCOMP /* Flags for compression */
>
> -/* 2 for alignment, 14 for ethernet, 40 for TCP/IP */
> -#define IF_MAXLINKHDR (2 + 14 + 40)
> +/* 2 for alignment, 14 for ethernet */
> +#define IF_MAXLINKHDR (2 + ETH_HLEN)
>
> #endif
> diff --git a/slirp/mbuf.c b/slirp/mbuf.c
> index c959758..f081c69 100644
> --- a/slirp/mbuf.c
> +++ b/slirp/mbuf.c
> @@ -24,7 +24,8 @@
> * Find a nice value for msize
> * XXX if_maxlinkhdr already in mtu
Maybe you should now remove the XXX line, now that the size of the
TCP/IP headers is counted via IF_MTU instead?
> */
> -#define SLIRP_MSIZE (IF_MTU + IF_MAXLINKHDR + offsetof(struct mbuf, m_dat) + 6)
> +#define SLIRP_MSIZE\
> + (offsetof(struct mbuf, m_dat) + IF_MAXLINKHDR + TCPIPHDR_DELTA + IF_MTU)
>
> void
> m_init(Slirp *slirp)
...
> diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
> index 5f845da..26b0c8b 100644
> --- a/slirp/tcp_input.c
> +++ b/slirp/tcp_input.c
> @@ -256,11 +256,6 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso)
> }
> slirp = m->slirp;
>
> - /*
> - * Get IP and TCP header together in first mbuf.
> - * Note: IP leaves IP header in first mbuf.
> - */
> - ti = mtod(m, struct tcpiphdr *);
> if (iphlen > sizeof(struct ip )) {
> ip_stripoptions(m, (struct mbuf *)0);
> iphlen=sizeof(struct ip );
> @@ -277,14 +272,28 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso)
> save_ip.ip_len+= iphlen;
>
> /*
> + * Get IP and TCP header together in first mbuf.
> + * Note: IP leaves IP header in first mbuf.
> + */
> + m->m_data -= sizeof(struct tcpiphdr) - (sizeof(struct ip)
> + + sizeof(struct tcphdr));
> + m->m_len += sizeof(struct tcpiphdr) - (sizeof(struct ip)
> + + sizeof(struct tcphdr));
I'm somewhat having a hard time to understand the "+ sizeof(struct
tcphdr))" here.
In the tcp_output.c code, there is this:
m->m_data += sizeof(struct tcpiphdr) - sizeof(struct tcphdr)
- sizeof(struct ip);
So with my limited point of view, I'd rather expect this here in
tcp_input.c:
m->m_data -= sizeof(struct tcpiphdr) - (sizeof(struct ip)
- sizeof(struct tcphdr));
i.e. "-" instead of "+" here ----------------^
Could you maybe elaborate a little bit on the above calculation? Or is
it just a bug?
> + ti = mtod(m, struct tcpiphdr *);
> +
> + /*
> * Checksum extended TCP header and data.
> */
> - tlen = ((struct ip *)ti)->ip_len;
> - tcpiphdr2qlink(ti)->next = tcpiphdr2qlink(ti)->prev = NULL;
> - memset(&ti->ti_i.ih_mbuf, 0 , sizeof(struct mbuf_ptr));
> - ti->ti_x1 = 0;
> + tlen = ip->ip_len;
> + tcpiphdr2qlink(ti)->next = tcpiphdr2qlink(ti)->prev = NULL;
> + memset(&ti->ih_mbuf, 0 , sizeof(struct mbuf_ptr));
> + memset(&ti->ti, 0, sizeof(ti->ti));
> + ti->ti_x0 = 0;
> + ti->ti_src = save_ip.ip_src;
> + ti->ti_dst = save_ip.ip_dst;
> + ti->ti_pr = save_ip.ip_p;
> ti->ti_len = htons((uint16_t)tlen);
> - len = sizeof(struct ip ) + tlen;
> + len = ((sizeof(struct tcpiphdr) - sizeof(struct tcphdr)) + tlen);
> if(cksum(m, len)) {
> goto drop;
> }
> @@ -1475,7 +1484,7 @@ tcp_mss(struct tcpcb *tp, u_int offer)
> DEBUG_ARG("tp = %p", tp);
> DEBUG_ARG("offer = %d", offer);
>
> - mss = min(IF_MTU, IF_MRU) - sizeof(struct tcpiphdr);
> + mss = min(IF_MTU, IF_MRU) - sizeof(struct tcphdr) + sizeof(struct ip);
> if (offer)
> mss = min(mss, offer);
> mss = max(mss, 32);
> diff --git a/slirp/tcp_output.c b/slirp/tcp_output.c
> index 34e4d2e..7fc6a87 100644
> --- a/slirp/tcp_output.c
> +++ b/slirp/tcp_output.c
> @@ -448,15 +448,23 @@ send:
> */
> m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */
>
> - {
> + struct tcpiphdr tcpiph_save = *(mtod(m, struct tcpiphdr *));
> + m->m_data += sizeof(struct tcpiphdr) - sizeof(struct tcphdr)
> + - sizeof(struct ip);
> + m->m_len -= sizeof(struct tcpiphdr) - sizeof(struct tcphdr)
> + - sizeof(struct ip);
> + struct ip *ip = mtod(m, struct ip *);
>
> - ((struct ip *)ti)->ip_len = m->m_len;
> + ip->ip_len = m->m_len;
> + ip->ip_dst = tcpiph_save.ti_dst;
> + ip->ip_src = tcpiph_save.ti_src;
> + ip->ip_p = tcpiph_save.ti_pr;
>
> - ((struct ip *)ti)->ip_ttl = IPDEFTTL;
> - ((struct ip *)ti)->ip_tos = so->so_iptos;
> + ip->ip_ttl = IPDEFTTL;
> + ip->ip_tos = so->so_iptos;
>
> error = ip_output(so, m);
> - }
> +
> if (error) {
> out:
> return (error);
Thomas
next prev parent reply other threads:[~2016-02-19 13:45 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-14 17:47 [Qemu-devel] [PATCHv8 0/9] slirp: Adding IPv6 support to Qemu -net user mode Samuel Thibault
2016-02-14 17:47 ` [Qemu-devel] [PATCHv7 1/9] slirp: Adding IPv6, ICMPv6 Echo and NDP autoconfiguration Samuel Thibault
2016-02-16 11:36 ` Thomas Huth
2016-02-19 13:57 ` Thomas Huth
2016-02-14 17:47 ` [Qemu-devel] [PATCHv7 2/9] slirp: Adding ICMPv6 error sending Samuel Thibault
2016-02-16 12:21 ` Thomas Huth
2016-02-14 17:47 ` [Qemu-devel] [PATCHv7 3/9] slirp: Adding IPv6 UDP support Samuel Thibault
2016-02-16 12:28 ` Thomas Huth
2016-02-14 17:47 ` [Qemu-devel] [PATCHv7 4/9] slirp: Factorizing tcpiphdr structure with an union Samuel Thibault
2016-02-19 0:36 ` Samuel Thibault
2016-02-19 13:44 ` Thomas Huth [this message]
2016-02-22 1:48 ` Samuel Thibault
2016-02-22 7:56 ` Thomas Huth
2016-02-22 10:20 ` Samuel Thibault
2016-02-14 17:47 ` [Qemu-devel] [PATCHv7 5/9] slirp: Generalizing and neutralizing various TCP functions before adding IPv6 stuff Samuel Thibault
2016-02-17 8:25 ` Thomas Huth
2016-02-14 17:47 ` [Qemu-devel] [PATCHv7 6/9] slirp: Reindent after refactoring Samuel Thibault
2016-02-17 9:03 ` Thomas Huth
2016-02-14 17:47 ` [Qemu-devel] [PATCHv7 7/9] slirp: Handle IPv6 in TCP functions Samuel Thibault
2016-02-17 9:18 ` Thomas Huth
2016-02-17 9:30 ` Samuel Thibault
2016-02-14 17:47 ` [Qemu-devel] [PATCHv7 8/9] slirp: Adding IPv6 address for DNS relay Samuel Thibault
2016-02-17 9:28 ` Thomas Huth
2016-02-17 9:36 ` Samuel Thibault
2016-02-19 0:26 ` Samuel Thibault
2016-02-14 17:47 ` [Qemu-devel] [PATCHv7 9/9] qapi-schema, qemu-options & slirp: Adding Qemu options for IPv6 addresses Samuel Thibault
2016-02-17 11:59 ` Thomas Huth
2016-02-19 0:35 ` Samuel Thibault
2016-02-16 8:47 ` [Qemu-devel] [PATCH] slirp: Add IPv6 support to the TFTP code Thomas Huth
2016-02-16 10:30 ` Samuel Thibault
2016-02-16 12:09 ` Thomas Huth
2016-02-17 8:40 ` [Qemu-devel] [PATCH v2] " Thomas Huth
2016-02-17 8:42 ` Samuel Thibault
-- strict thread matches above, loose matches on Subject: below --
2016-02-08 10:28 [Qemu-devel] [PATCHv7 0/9] slirp: Adding IPv6 support to Qemu -net user mode Samuel Thibault
2016-02-08 10:28 ` [Qemu-devel] [PATCHv7 4/9] slirp: Factorizing tcpiphdr structure with an union Samuel Thibault
2016-02-10 8:05 ` Thomas Huth
2016-02-10 9:28 ` Samuel Thibault
2016-02-10 10:08 ` Thomas Huth
2016-02-10 12:20 ` Samuel Thibault
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=56C71C5B.1040805@redhat.com \
--to=thuth@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=dgilbert@redhat.com \
--cc=jan.kiszka@siemens.com \
--cc=jasowang@redhat.com \
--cc=lizhijian@cn.fujitsu.com \
--cc=maethor@subiron.org \
--cc=peter.huangpeng@huawei.com \
--cc=qemu-devel@nongnu.org \
--cc=samuel.thibault@ens-lyon.org \
--cc=stefanha@gmail.com \
--cc=v.tolstov@selfip.ru \
--cc=zhang.zhanghailiang@huawei.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).