flow: Make flow_compose() fake packets slightly more realistic.
authorBen Pfaff <blp@nicira.com>
Mon, 19 Dec 2011 22:45:23 +0000 (14:45 -0800)
committerBen Pfaff <blp@nicira.com>
Mon, 19 Dec 2011 22:53:57 +0000 (14:53 -0800)
This makes flow_extract() happier with TCP packets that this function
produces.

Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/flow.c
lib/packets.h

index a491afffc54c50aef07cbe3b961ead3b06cfe542..922412fd8ce53cdb24e32c47ff69b447fc27ed25 100644 (file)
@@ -1020,6 +1020,7 @@ flow_compose(struct ofpbuf *b, const struct flow *flow)
                 b->l4 = tcp = ofpbuf_put_zeros(b, sizeof *tcp);
                 tcp->tcp_src = flow->tp_src;
                 tcp->tcp_dst = flow->tp_dst;
+                tcp->tcp_ctl = TCP_CTL(0, 5);
             } else if (flow->nw_proto == IPPROTO_UDP) {
                 struct udp_header *udp;
 
@@ -1034,6 +1035,9 @@ flow_compose(struct ofpbuf *b, const struct flow *flow)
                 icmp->icmp_code = ntohs(flow->tp_dst);
             }
         }
+
+        ip->ip_tot_len = htons((uint8_t *) b->data + b->size
+                               - (uint8_t *) b->l3);
     } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
         /* XXX */
     } else if (flow->dl_type == htons(ETH_TYPE_ARP)) {
index 9e283a5abd1767ce3abd693bf883d2e5bcb95bde..19b7346baa9f10d47005f4e94b3a86f1499d3ac7 100644 (file)
@@ -357,6 +357,7 @@ BUILD_ASSERT_DECL(UDP_HEADER_LEN == sizeof(struct udp_header));
 #define TCP_ACK 0x10
 #define TCP_URG 0x20
 
+#define TCP_CTL(flags, offset) (htons((flags) | ((offset) << 12)))
 #define TCP_FLAGS(tcp_ctl) (ntohs(tcp_ctl) & 0x003f)
 #define TCP_OFFSET(tcp_ctl) (ntohs(tcp_ctl) >> 12)