datapath: Set the correct bits for OFPAT_SET_NW_TOS action.
[sliver-openvswitch.git] / lib / dpif-netdev.c
index e6cf8fd..d576c73 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009 Nicira Networks.
+ * Copyright (c) 2009, 2010 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -664,6 +664,7 @@ dp_netdev_lookup_flow(const struct dp_netdev *dp, const flow_t *key)
 {
     struct dp_netdev_flow *flow;
 
+    assert(!key->reserved[0] && !key->reserved[1] && !key->reserved[2]);
     HMAP_FOR_EACH_WITH_HASH (flow, struct dp_netdev_flow, node,
                              flow_hash(key, 0), &dp->flow_table) {
         if (flow_equal(&flow->key, key)) {
@@ -806,6 +807,7 @@ add_flow(struct dpif *dpif, struct odp_flow *odp_flow)
 
     flow = xcalloc(1, sizeof *flow);
     flow->key = odp_flow->key;
+    memset(flow->key.reserved, 0, sizeof flow->key.reserved);
 
     error = set_flow_actions(flow, odp_flow);
     if (error) {
@@ -1178,8 +1180,8 @@ dp_netdev_set_nw_tos(struct ofpbuf *packet, flow_t *key,
         struct ip_header *nh = packet->l3;
         uint8_t *field = &nh->ip_tos;
 
-        /* We only set the lower 6 bits. */
-        uint8_t new = (a->nw_tos & 0x3f) | (nh->ip_tos & 0xc0);
+        /* Set the DSCP bits and preserve the ECN bits. */
+        uint8_t new = (a->nw_tos & IP_DSCP_MASK) | (nh->ip_tos & IP_ECN_MASK);
 
         nh->ip_csum = recalc_csum16(nh->ip_csum, htons((uint16_t)*field),
                 htons((uint16_t)a->nw_tos));