Simplify code in stream_recv().
[sliver-openvswitch.git] / lib / flow.c
index c0f07a2..70a9c4b 100644 (file)
@@ -38,7 +38,7 @@
 #include <string.h>
 #include "hash.h"
 #include "ofpbuf.h"
-#include "openflow.h"
+#include "openflow/openflow.h"
 #include "packets.h"
 
 #include "vlog.h"
@@ -76,6 +76,12 @@ pull_udp(struct ofpbuf *packet)
     return ofpbuf_try_pull(packet, UDP_HEADER_LEN);
 }
 
+static struct icmp_header *
+pull_icmp(struct ofpbuf *packet) 
+{
+    return ofpbuf_try_pull(packet, ICMP_HEADER_LEN);
+}
+
 static struct eth_header *
 pull_eth(struct ofpbuf *packet) 
 {
@@ -144,7 +150,7 @@ flow_extract(struct ofpbuf *packet, uint16_t in_port, struct flow *flow)
             struct vlan_header *vh = pull_vlan(&b);
             if (vh) {
                 flow->dl_type = vh->vlan_next_type;
-                flow->dl_vlan = vh->vlan_tci & htons(VLAN_VID);
+                flow->dl_vlan = vh->vlan_tci & htons(VLAN_VID_MASK);
             }
         }
         memcpy(flow->dl_src, eth->eth_src, ETH_ADDR_LEN);
@@ -181,6 +187,17 @@ flow_extract(struct ofpbuf *packet, uint16_t in_port, struct flow *flow)
                              * this packet has an L4 header. */
                             flow->nw_proto = 0;
                         }
+                    } else if (flow->nw_proto == IP_TYPE_ICMP) {
+                        const struct icmp_header *icmp = pull_icmp(&b);
+                        if (icmp) {
+                            flow->icmp_type = htons(icmp->icmp_type);
+                            flow->icmp_code = htons(icmp->icmp_code);
+                            packet->l7 = b.data;
+                        } else {
+                            /* Avoid tricking other code into thinking that
+                             * this packet has an L4 header. */
+                            flow->nw_proto = 0;
+                        }
                     }
                 } else {
                     retval = 1;