Hi, 

Please keep mailing list.

On 2015年12月11日 19:48, Yury Yurochko wrote:
> Hello!
> Controller crashes if i use msg.data.
> The reason is that msg.data for OFPErrorMsg calculated like:
>     msg.data = msg.buf[ofproto.OFP_ERROR_MSG_SIZE:]
> Here len(buf) is 12 and OFP_ERROR_MSG_SIZE is 12 => msg.data is empty string 
> (see ofproto/ofproto_v1_3_parser.py).

Certainly, OFPErrorMsg length is 12 bytes, msg.data will be empty string,
but, OpenFlow Spec says:
---
OpenFlow Spec 1.3.5

7.4.4 Error Message

The field data is variable in length and interpreted based on the type and 
code. Unless specified
otherwise, the data field contains at least 64 bytes of the failed request that 
caused the error message
to be generated, if the failed request is shorter than 64 bytes it should be 
the full request without any
padding.
---

So I think msg.data should include at least 64 bytes of the failed request by 
default.

On my environment, Ryu outputs the followings if controller recieved 
OFPErrorMsg.
---
EventOFPErrorMsg received.
version=0x4, msg_type=0x1, msg_len=0x4c, xid=0xd0917e2d
 `-- msg_type: OFPT_ERROR(1)
OFPErrorMsg(type=0x4, code=0x9, 
data=b'\x04\x0e\x00\x58\xd0\x91\x7e\x2d\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x2b\x67\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x01\x00\x0c\x80\x00\x18\x04\xc0\xa8\x00\x01\x00\x00\x00\x00')
 |-- type: OFPET_BAD_MATCH(4)
 |-- code: OFPBMC_BAD_PREREQ(9)
 `-- data: version=0x4, msg_type=0xe, msg_len=0x58, xid=0xd0917e2d  # <-- we 
need msg.data to output this line
     `-- msg_type: OFPT_FLOW_MOD(14)
---

If cotroller crashes in your network, how about the attached patch?

Thanks,
Iwase

> 
> Maybe i don't understand some details?
> 
> Sorry for my english.
> 
> Regards,
> Yury Yurochko
>From a93738de34f459d3caf9a4b2d1b7cfc515d951c9 Mon Sep 17 00:00:00 2001
From: IWASE Yusuke <[email protected]>
Date: Mon, 14 Dec 2015 10:52:31 +0900
Subject: [PATCH] ofp_handler: Handle empty data field in OFPErrorMsg

OpenFlow Spec defines that the data field should contain at least
64 bytes of the failed request that caused the error message to be
generated, unless otherwise specified.
But, the data field can be empty in some case, this patch checks
the data field length and skips parsing it if the field does not
contain enough bytes to parse.

Reported-by: Yury Yurochko <[email protected]>
Signed-off-by: IWASE Yusuke <[email protected]>
---
 ryu/controller/ofp_handler.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/ryu/controller/ofp_handler.py b/ryu/controller/ofp_handler.py
index cc64b1f..95f6fd9 100644
--- a/ryu/controller/ofp_handler.py
+++ b/ryu/controller/ofp_handler.py
@@ -251,7 +251,6 @@ class OFPHandler(ryu.base.app_manager.RyuApp):
     def error_msg_handler(self, ev):
         msg = ev.msg
         ofp = msg.datapath.ofproto
-        (version, msg_type, msg_len, xid) = ofproto_parser.header(msg.data)
         self.logger.debug('EventOFPErrorMsg received.')
         self.logger.debug(
             'version=%s, msg_type=%s, msg_len=%s, xid=%s', hex(msg.version),
@@ -265,8 +264,10 @@ class OFPHandler(ryu.base.app_manager.RyuApp):
             ' |-- type: %s', ofp.ofp_error_type_to_str(msg.type))
         self.logger.debug(
             ' |-- code: %s', ofp.ofp_error_code_to_str(msg.type, msg.code))
-        self.logger.debug(
-            ' `-- data: version=%s, msg_type=%s, msg_len=%s, xid=%s',
-            hex(version), hex(msg_type), hex(msg_len), hex(xid))
-        self.logger.debug(
-            '     `-- msg_type: %s', ofp.ofp_msg_type_to_str(msg_type))
+        if len(msg.data) >= ofp.OFP_HEADER_SIZE:
+            (version, msg_type, msg_len, xid) = ofproto_parser.header(msg.data)
+            self.logger.debug(
+                ' `-- data: version=%s, msg_type=%s, msg_len=%s, xid=%s',
+                hex(version), hex(msg_type), hex(msg_len), hex(xid))
+            self.logger.debug(
+                '     `-- msg_type: %s', ofp.ofp_msg_type_to_str(msg_type))
-- 
1.9.1

------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to