]> git.proxmox.com Git - mirror_qemu.git/blobdiff - slirp/tcp_output.c
Merge remote-tracking branch 'remotes/thibault/tags/samuel-thibault' into staging
[mirror_qemu.git] / slirp / tcp_output.c
index 0d6011ac642c39411c4e1970898262f8770171fe..99b0a9b1cb43c9cbe36d8d3b6ba73385d4278a4a 100644 (file)
@@ -38,6 +38,7 @@
  * terms and conditions of the copyright.
  */
 
+#include "qemu/osdep.h"
 #include <slirp.h>
 
 static const u_char  tcp_outflags[TCP_NSTATES] = {
@@ -47,6 +48,7 @@ static const u_char  tcp_outflags[TCP_NSTATES] = {
 };
 
 
+#undef MAX_TCPOPTLEN
 #define MAX_TCPOPTLEN  32      /* max # bytes that go in options */
 
 /*
@@ -59,13 +61,15 @@ tcp_output(struct tcpcb *tp)
        register long len, win;
        int off, flags, error;
        register struct mbuf *m;
-       register struct tcpiphdr *ti;
+       register struct tcpiphdr *ti, tcpiph_save;
+       struct ip *ip;
+       struct ip6 *ip6;
        u_char opt[MAX_TCPOPTLEN];
        unsigned optlen, hdrlen;
        int idle, sendalot;
 
        DEBUG_CALL("tcp_output");
-       DEBUG_ARG("tp = %lx", (long )tp);
+       DEBUG_ARG("tp = %p", tp);
 
        /*
         * Determine length of data that should be transmitted,
@@ -263,11 +267,11 @@ send:
        if (flags & TH_SYN) {
                tp->snd_nxt = tp->iss;
                if ((tp->t_flags & TF_NOOPT) == 0) {
-                       u_int16_t mss;
+                       uint16_t mss;
 
                        opt[0] = TCPOPT_MAXSEG;
                        opt[1] = 4;
-                       mss = htons((u_int16_t) tcp_mss(tp, 0));
+                       mss = htons((uint16_t) tcp_mss(tp, 0));
                        memcpy((caddr_t)(opt + 2), (caddr_t)&mss, sizeof(mss));
                        optlen = 4;
                }
@@ -364,10 +368,10 @@ send:
                win = (long)TCP_MAXWIN << tp->rcv_scale;
        if (win < (long)(tp->rcv_adv - tp->rcv_nxt))
                win = (long)(tp->rcv_adv - tp->rcv_nxt);
-       ti->ti_win = htons((u_int16_t) (win>>tp->rcv_scale));
+       ti->ti_win = htons((uint16_t) (win>>tp->rcv_scale));
 
        if (SEQ_GT(tp->snd_up, tp->snd_una)) {
-               ti->ti_urp = htons((u_int16_t)(tp->snd_up - ntohl(ti->ti_seq)));
+               ti->ti_urp = htons((uint16_t)(tp->snd_up - ntohl(ti->ti_seq)));
                ti->ti_flags |= TH_URG;
        } else
                /*
@@ -383,7 +387,7 @@ send:
         * checksum extended header and data.
         */
        if (len + optlen)
-               ti->ti_len = htons((u_int16_t)(sizeof (struct tcphdr) +
+               ti->ti_len = htons((uint16_t)(sizeof (struct tcphdr) +
                    optlen + len));
        ti->ti_sum = cksum(m, (int)(hdrlen + len));
 
@@ -445,16 +449,45 @@ send:
         * the template, but need a way to checksum without them.
         */
        m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */
+       tcpiph_save = *mtod(m, struct tcpiphdr *);
+
+       switch (so->so_ffamily) {
+       case AF_INET:
+           m->m_data += sizeof(struct tcpiphdr) - sizeof(struct tcphdr)
+                                                - sizeof(struct ip);
+           m->m_len  -= sizeof(struct tcpiphdr) - sizeof(struct tcphdr)
+                                                - sizeof(struct ip);
+           ip = mtod(m, struct ip *);
+
+           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;
+
+           ip->ip_ttl = IPDEFTTL;
+           ip->ip_tos = so->so_iptos;
+           error = ip_output(so, m);
+           break;
+
+       case AF_INET6:
+           m->m_data += sizeof(struct tcpiphdr) - sizeof(struct tcphdr)
+                                                - sizeof(struct ip6);
+           m->m_len  -= sizeof(struct tcpiphdr) - sizeof(struct tcphdr)
+                                                - sizeof(struct ip6);
+           ip6 = mtod(m, struct ip6 *);
+
+           ip6->ip_pl = tcpiph_save.ti_len;
+           ip6->ip_dst = tcpiph_save.ti_dst6;
+           ip6->ip_src = tcpiph_save.ti_src6;
+           ip6->ip_nh = tcpiph_save.ti_nh6;
+
+           error = ip6_output(so, m, 0);
+           break;
+
+       default:
+           g_assert_not_reached();
+       }
 
-    {
-
-       ((struct ip *)ti)->ip_len = m->m_len;
-
-       ((struct ip *)ti)->ip_ttl = IPDEFTTL;
-       ((struct ip *)ti)->ip_tos = so->so_iptos;
-
-       error = ip_output(so, m);
-    }
        if (error) {
 out:
                return (error);