Hi Ryu folks,
            I'm attempting to write a controller application which needs to
extract the DHCP header from a packet-in using the dhcp parser in Ryu.

I believe I have found a bug in the parser and have provided a possible fix
below.  In addition, I believe there may be a second bug.  I would
appreciate your feedback on both.

The text at the bottom of the email highlights the steps I took which
generate the first bug and the possible fix.

Questions:

a) Are the steps in 3 below correct? If not, can you please provide
feedback?

b) Is the output of 4 below what one should expect?

c) Second bug: In the following snippet (from ryu/lib/packet/dhcp.py), it
appears that "parse_opt" is only set if len(buf) is greater than min_len
(since there are no other instances of parse_opt in this file). In the
event that len(buf) =< min_len, would this not result in an error at the
"return" statement?

...
if len(buf) > min_len:
    parse_opt = options.parser(buf[min_len:])
    length += parse_opt.options_len

return (cls(op, addrconv.mac.bin_to_text(chaddr), parse_opt,
            htype, hlen, hops, xid, secs, flags,
            addrconv.ipv4.bin_to_text(ciaddr),
            addrconv.ipv4.bin_to_text(yiaddr),
            addrconv.ipv4.bin_to_text(siaddr),
            addrconv.ipv4.bin_to_text(giaddr),
            sname.decode('ascii'), boot_file),
       None, buf[length:])
...

Thank you in advance for your assistance,
Ali

==== FIRST BUG REPORT AND PROPOSED FIX ===

1. Action:

Since the switch truncates pkts to the controller, I use the following to
have the switch send the entire packet (I've assumed a max pkt size of 1500
bytes).
...
req = parser.OFPSetConfig(datapath, ofproto_v1_3.OFPC_FRAG_NORMAL, 1500)
datapath.send_msg(req)
...

I also use the following to grab the dhcp header:

...
dhcp_pkt = packet.Packet(pkt.protocols[3], parse_cls=dhcp.dhcp)
...

2. Result:

The following error results:

...
  dhcp_pkt = packet.Packet(pkt.protocols[3], parse_cls=dhcp.dhcp)
  File "/usr/local/lib/python2.7/site-packages/ryu/lib/packet/packet.py",
line 46, in __init__
    self._parser(parse_cls)
  File "/usr/local/lib/python2.7/site-packages/ryu/lib/packet/packet.py",
line 55, in _parser
    if proto:
  File
"/usr/local/lib/python2.7/site-packages/ryu/lib/packet/packet_base.py",
line 46, in __len__
    return self._MIN_LEN
AttributeError: 'dhcp' object has no attribute '_MIN_LEN'
...

3. Action:

I added the following two lines to the start of the dhcp class in the
dhcp.py file around line 135 (PS. These lines also exist in the option
class):

_UNPACK_STR = '!B'
_MIN_LEN = struct.calcsize(_UNPACK_STR)
# existing code is below
_HLEN_UNPACK_STR = '!BBB'
_HLEN_UNPACK_LEN = struct.calcsize(_HLEN_UNPACK_STR)

4. Result

I am now able to extract the dhcp header:

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

Reply via email to