>From d7b99ac12d8d48ea8f67666ec184061fbdbff9ac Mon Sep 17 00:00:00 2001 From: Isaku Yamahata <[email protected]> Date: Tue, 29 Oct 2013 18:00:16 +0900 Subject: [PATCH] ofproto_parser: dump packets if error is encountered during parse
Signed-off-by: Isaku Yamahata <[email protected]> Signed-off-by: FUJITA Tomonori <[email protected]> --- ryu/ofproto/ofproto_parser.py | 11 ++++++++++- ryu/utils.py | 8 +++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ryu/ofproto/ofproto_parser.py b/ryu/ofproto/ofproto_parser.py index 371cf3f..3b88440 100644 --- a/ryu/ofproto/ofproto_parser.py +++ b/ryu/ofproto/ofproto_parser.py @@ -21,6 +21,7 @@ import sys import functools from ryu import exception +from ryu import utils from ryu.lib import stringify from . import ofproto_common @@ -51,7 +52,15 @@ def msg(datapath, version, msg_type, msg_len, xid, buf): if msg_parser is None: raise exception.OFPUnknownVersion(version=version) - return msg_parser(datapath, version, msg_type, msg_len, xid, buf) + try: + return msg_parser(datapath, version, msg_type, msg_len, xid, buf) + except struct.error: + LOG.exception( + 'Encounter an error during parsing OpenFlow packet from switch.' + 'This implies switch sending a malfold OpenFlow packet.' + 'version 0x%02x msg_type %d msg_len %d xid %d buf %s', + version, msg_type, msg_len, xid, utils.bytearray_to_hex(buf)) + raise def create_list_of_base_attributes(f): diff --git a/ryu/utils.py b/ryu/utils.py index 1e1aa49..1889257 100644 --- a/ryu/utils.py +++ b/ryu/utils.py @@ -94,7 +94,13 @@ def round_up(x, y): def hex_array(data): - return ' '.join(hex(ord(chr)) for chr in data) + """Convert string into array of hexes to be printed.""" + return ' '.join(hex(ord(char)) for char in data) + + +def bytearray_to_hex(data): + """Convert bytearray into array of hexes to be printed.""" + return ' '.join(hex(byte) for byte in data) # the following functions are taken from OpenStack -- 1.7.12.4 (Apple Git-37) ------------------------------------------------------------------------------ Android is increasing in popularity, but the open development platform that developers love is also attractive to malware creators. Download this white paper to learn more about secure code signing practices that can help keep Android apps secure. http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
