summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamamoto@valinux.co.jp>2013-09-26 13:08:07 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2013-09-25 22:26:28 -0700
commita53bc8052dea1fa59b5dd5470c1c29b768cd84ce (patch)
treefad2e4383869b46bcfea5f1a08bbe235060dd3de
parent54989c7862269f6bf850297ddef5afe6f2da24eb (diff)
ofproto: fix OF1.0 packet_in parser
OF1.0 spec says OFP_ASSERT(sizeof(struct ofp_packet_in) == 20). It's quite bogus as it assumes a specific class of C implementations. (well, if it was C. it's unclear from the spec itself.) We just use the real size of the structure as this is not C. This agrees with on-wire messages OpenFlow Reference Release and Open vSwitch produce. This should fix a crash Chen Chen reported on ryu-devel recently. Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/ofproto/ofproto_v1_0.py11
-rw-r--r--ryu/ofproto/ofproto_v1_0_parser.py2
2 files changed, 9 insertions, 4 deletions
diff --git a/ryu/ofproto/ofproto_v1_0.py b/ryu/ofproto/ofproto_v1_0.py
index b47d0a14..777a165d 100644
--- a/ryu/ofproto/ofproto_v1_0.py
+++ b/ryu/ofproto/ofproto_v1_0.py
@@ -164,9 +164,14 @@ assert calcsize(OFP_PORT_MOD_PACK_STR) + OFP_HEADER_SIZE == OFP_PORT_MOD_SIZE
OFPR_NO_MATCH = 0 # No matching flow.
OFPR_ACTION = 1 # Action explicitly output to controller.
-OFP_PACKET_IN_PACK_STR = '!IHHBx2x' # the last 2x is for ofp_packet_in::data
-OFP_PACKET_IN_SIZE = 20
-OFP_PACKET_IN_DATA_OFFSET = 18
+# OF1.0 spec says OFP_ASSERT(sizeof(struct ofp_packet_in) == 20).
+# It's quite bogus as it assumes a specific class of C implementations.
+# (well, if it was C. it's unclear from the spec itself.)
+# We just use the real size of the structure as this is not C. This
+# agrees with on-wire messages OpenFlow Reference Release and Open vSwitch
+# produce.
+OFP_PACKET_IN_PACK_STR = '!IHHBx'
+OFP_PACKET_IN_SIZE = 18
assert calcsize(OFP_PACKET_IN_PACK_STR) + OFP_HEADER_SIZE == OFP_PACKET_IN_SIZE
# enum ofp_action_type
diff --git a/ryu/ofproto/ofproto_v1_0_parser.py b/ryu/ofproto/ofproto_v1_0_parser.py
index d1634749..8856fa16 100644
--- a/ryu/ofproto/ofproto_v1_0_parser.py
+++ b/ryu/ofproto/ofproto_v1_0_parser.py
@@ -1730,7 +1730,7 @@ class OFPPacketIn(MsgBase):
msg.reason) = struct.unpack_from(
ofproto_v1_0.OFP_PACKET_IN_PACK_STR,
msg.buf, ofproto_v1_0.OFP_HEADER_SIZE)
- msg.data = msg.buf[ofproto_v1_0.OFP_PACKET_IN_DATA_OFFSET:]
+ msg.data = msg.buf[ofproto_v1_0.OFP_PACKET_IN_SIZE:]
if msg.total_len < len(msg.data):
# discard padding for 8-byte alignment of OFP packet
msg.data = msg.data[:msg.total_len]