19 October 2010

Option 82 Decoding

When looking at DHCP leases, one sometimes may need to be able to
decode the option 82 (op82) string passed to the DHCP server.  In
the examples below, the op82 string is provided as the
'relay-agent-remote-id''.  The value provided, however, isn't
intuitively clear:

        01:01:00:00:ac:08:20:56:22:dd:01:ae 

Before going any further, op82dec.pl (on the Tools page) is specifically
capable of handling translation of op82 suboption 2 strings.  This is
mentioned as the following may seem somewhat esoteric and lengthy.
With that out of the way, back to our op82 string.  Each colon (:)
delimitted value represents a particular portion of the dhcp relay
agent information:

    (Desc = Description; ST = Start; LEN = Length)

DescBYTE STBYTE LEN
port type (01)01
version (01)11
reserved (00)21
reserved (00)31
NAS IP (ac:08:20:56)44
NAS Port (22:dd:01:ae)84

For our purposes, the first 4 bytes are inconsequential.  The next 4
bytes, (4 - 7) are the IP address of the DHCP relay agent.  To translate
the value into something usable, we need to translate each byte from
HEX to DEC and substitute decimals for the colons.  Thus 'ac:08:20:56'
begets IP address '172.8.32.86', wherein:

        H  => D
        ac => 172
        08 =>   8
        20 =>  32
        56 =>  86

The last 4 bytes of the op82 string, NAS Port (bytes 8 - 11), detail
the device interface (slot/module/port), VPI, and VCI:

NAS Port DescBYTE STBYTE LEN
interface (22)01
VPI (dd)11
VCI (01:ae)22

Before decoding the interface, the VPI and VCI values are simple HEX
to DEC conversions, with VPI being 1 byte in length (byte 9 of op82)
and VCI being 2 bytes (bytes 10 - 11 of op82).  The VCI decimal value,
being 2 bytes is determined by concatenating the bytes together before
conversion.  This begets:

        H    => D
          dd => 221 (VPI)
        01ae => 430 (VCI)

As for the interface, being only 1 byte in length, the values for its
breakdown are done via bits:

Interface DescBIT STBIT LEN
slot04
module41
port53

So to determine each value, first the conversion of HEX to DEC:

        H  => D
        22 => 34

Then, converting the decimal (DEC) value to binary (BIN):

        D  => B
        34 => 00100010

Each range of bits alloted for the interface are parts numerically
separate within the overall 8 bit binary value, thus:

        slot/module/port => 0010/0/010

This provides a DEC value for each:

        P       B       D
        slot => 0010 => 2
        mod  => 0    => 0
        port => 010  => 2

In putting all of the above components together, we now have a fully
converted option 82 string:

          op82 string:  01:01:00:00:ac:08:20:56:22:dd:01:ae
               NAS IP:  172.8.32.86
        Slot/Mod/Port:  2/0/2
                  VPI:  221
                  VCI:  430

No comments: