packets: Fix misaligned data accesses for MPLS and SCTP fields.
authorBen Pfaff <blp@nicira.com>
Sat, 5 Apr 2014 18:14:02 +0000 (11:14 -0700)
committerBen Pfaff <blp@nicira.com>
Sat, 5 Apr 2014 18:14:02 +0000 (11:14 -0700)
The other 32-bit data fields in protocol headers were already using
ovs_16aligned_be32, but MPLS and SCTP had been overlooked.  This fixes
the failure of test 681 seen here:
https://buildd.debian.org/status/fetch.php?pkg=openvswitch&arch=sparc&ver=2.1.0%2Bgit20140325-1&stamp=1396438624

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
lib/flow.c
lib/ofp-print.c
lib/packets.c
lib/packets.h

index f1d2cad..8c544cb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -112,11 +112,12 @@ parse_mpls(struct ofpbuf *b, struct flow *flow)
     bool top = true;
 
     while ((mh = ofpbuf_try_pull(b, sizeof *mh))) {
+        ovs_be32 mpls_lse = get_16aligned_be32(&mh->mpls_lse);
         if (top) {
             top = false;
-            flow->mpls_lse = mh->mpls_lse;
+            flow->mpls_lse = mpls_lse;
         }
-        if (mh->mpls_lse & htonl(MPLS_BOS_MASK)) {
+        if (mpls_lse & htonl(MPLS_BOS_MASK)) {
             break;
         }
     }
index 4c89b36..4e57f9e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -77,7 +77,7 @@ ofp_packet_to_string(const void *data, size_t len)
         } else if (flow.nw_proto == IPPROTO_SCTP) {
             struct sctp_header *sh = buf.l4;
             ds_put_format(&ds, " sctp_csum:%"PRIx32,
-                          ntohl(sh->sctp_csum));
+                          ntohl(get_16aligned_be32(&sh->sctp_csum)));
         }
     }
 
index ed3832b..a17983e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -313,7 +313,7 @@ set_mpls_lse(struct ofpbuf *packet, ovs_be32 mpls_lse)
     /* Packet type should be MPLS to set label stack entry. */
     if (is_mpls(packet)) {
         /* Update mpls label stack entry. */
-        mh->mpls_lse = mpls_lse;
+        put_16aligned_be32(&mh->mpls_lse, mpls_lse);
     }
 }
 
@@ -336,7 +336,7 @@ push_mpls(struct ofpbuf *packet, ovs_be16 ethtype, ovs_be32 lse)
     }
 
     /* Push new MPLS shim header onto packet. */
-    mh.mpls_lse = lse;
+    put_16aligned_be32(&mh.mpls_lse, lse);
     push_mpls_lse(packet, &mh);
 }
 
@@ -354,7 +354,7 @@ pop_mpls(struct ofpbuf *packet, ovs_be16 ethtype)
         mh = packet->l2_5;
         len = (char*)packet->l2_5 - (char*)packet->l2;
         set_ethertype(packet, ethtype);
-        if (mh->mpls_lse & htonl(MPLS_BOS_MASK)) {
+        if (get_16aligned_be32(&mh->mpls_lse) & htonl(MPLS_BOS_MASK)) {
             packet->l2_5 = NULL;
         } else {
             packet->l2_5 = (char*)packet->l2_5 + MPLS_HLEN;
@@ -882,15 +882,15 @@ packet_set_sctp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
     ovs_be32 old_csum, old_correct_csum, new_csum;
     uint16_t tp_len = packet->size - ((uint8_t*)sh - (uint8_t*)packet->data);
 
-    old_csum = sh->sctp_csum;
-    sh->sctp_csum = 0;
+    old_csum = get_16aligned_be32(&sh->sctp_csum);
+    put_16aligned_be32(&sh->sctp_csum, 0);
     old_correct_csum = crc32c(packet->l4, tp_len);
 
     sh->sctp_src = src;
     sh->sctp_dst = dst;
 
     new_csum = crc32c(packet->l4, tp_len);
-    sh->sctp_csum = old_csum ^ old_correct_csum ^ new_csum;
+    put_16aligned_be32(&sh->sctp_csum, old_csum ^ old_correct_csum ^ new_csum);
 }
 
 /* If 'packet' is a TCP packet, returns the TCP flags.  Otherwise, returns 0.
index f3e1dfb..a57e070 100644 (file)
@@ -323,7 +323,7 @@ BUILD_ASSERT_DECL(VLAN_ETH_HEADER_LEN == sizeof(struct vlan_eth_header));
 #define MPLS_HLEN           4
 
 struct mpls_hdr {
-    ovs_be32 mpls_lse;
+    ovs_16aligned_be32 mpls_lse;
 };
 BUILD_ASSERT_DECL(MPLS_HLEN == sizeof(struct mpls_hdr));
 
@@ -470,8 +470,8 @@ BUILD_ASSERT_DECL(ICMP_HEADER_LEN == sizeof(struct icmp_header));
 struct sctp_header {
     ovs_be16 sctp_src;
     ovs_be16 sctp_dst;
-    ovs_be32 sctp_vtag;
-    ovs_be32 sctp_csum;
+    ovs_16aligned_be32 sctp_vtag;
+    ovs_16aligned_be32 sctp_csum;
 };
 BUILD_ASSERT_DECL(SCTP_HEADER_LEN == sizeof(struct sctp_header));