Discussion:
[PATCH] ofp_handler: Handle empty data field in OFPErrorMsg
(too old to reply)
IWASE Yusuke
2016-02-22 04:20:30 UTC
Permalink
Raw Message
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 switch implementation,
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 <***@brain4net.com>
Signed-off-by: IWASE Yusuke <***@gmail.com>
---
ryu/controller/ofp_handler.py | 43 +++++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/ryu/controller/ofp_handler.py b/ryu/controller/ofp_handler.py
index b3c63df..7ec1c95 100644
--- a/ryu/controller/ofp_handler.py
+++ b/ryu/controller/ofp_handler.py
@@ -243,22 +243,29 @@ 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),
- hex(msg.msg_type), hex(msg.msg_len), hex(msg.xid))
- self.logger.debug(
- ' `-- msg_type: %s', ofp.ofp_msg_type_to_str(msg.msg_type))
- self.logger.debug(
- "OFPErrorMsg(type=%s, code=%s, data=b'%s')", hex(msg.type),
- hex(msg.code), utils.binary_str(msg.data))
- self.logger.debug(
- ' |-- 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))
+ "EventOFPErrorMsg received.\n"
+ "version=%s, msg_type=%s, msg_len=%s, xid=%s\n"
+ " `-- msg_type: %s\n"
+ "OFPErrorMsg(type=%s, code=%s, data=b'%s')\n"
+ " |-- type: %s\n"
+ " |-- code: %s",
+ hex(msg.version), hex(msg.msg_type), hex(msg.msg_len),
+ hex(msg.xid), ofp.ofp_msg_type_to_str(msg.msg_type),
+ hex(msg.type), hex(msg.code), utils.binary_str(msg.data),
+ ofp.ofp_error_type_to_str(msg.type),
+ ofp.ofp_error_code_to_str(msg.type, msg.code))
+ 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\n"
+ " `-- msg_type: %s",
+ hex(version), hex(msg_type), hex(msg_len), hex(xid),
+ ofp.ofp_msg_type_to_str(msg_type))
+ else:
+ self.logger.warning(
+ "The data field sent from the switch is too short: "
+ "len(msg.data) < OFP_HEADER_SIZE\n"
+ "The OpenFlow Spec says that the data field should contain "
+ "at least 64 bytes of the failed request.\n"
+ "Please check the settings or implementation of your switch.")
--
1.9.1
FUJITA Tomonori
2016-02-27 11:57:33 UTC
Permalink
Raw Message
On Mon, 22 Feb 2016 13:20:30 +0900
Post by IWASE Yusuke
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 switch implementation,
this patch checks the data field length and skips parsing it if the
field does not contain enough bytes to parse.
---
ryu/controller/ofp_handler.py | 43 +++++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 18 deletions(-)
Applied, thank you.

Loading...