[Kea-users] Option 82 hackery

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Kea-users] Option 82 hackery

Tony Finch
Tomek asked me to post to the Kea list about the option 82 handling we are
using on our old isc-dhcpd servers. This part of our configuration was
written by Bob Franklin, the head of our network systems team. The idea is
to work out what kind of switch added the option 82, and pretty-print the
contents of the option into the logs. There is a fair amount of heuristic
guesswork, and it is tuned to the mix of switches we have on our edge
networks. Be warned it is quite long and repetitive!

#
#  Log DHCP agent (option 82) details added by switches. This is tricky
#  because different vendors and configurations can return information
#  in conflicting formats and it's difficult to work out what format
#  the information is in, so we make some assumptions.
#

if exists agent.remote-id {
  if not (option dhcp-message-type = 8) {
    # Not a DHCPINFORM request.
    if substring(option agent.remote-id, 0, 1) = 1 {
      # The first byte of the remote ID is 1. That's unlikely to be an
      # IP address and, if it were a MAC address it would be multicast,
      # so it is probably a hostname from a Cisco switch.
      log(
        info,
        concat(
          "agent information ",
          binary-to-ascii(10, 8, ".", leased-address),
          " to ",
          binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)),
          " on ",
          substring(option agent.remote-id, 2,
            extract-int(substring(option agent.remote-id, 1, 1), 8)),
          " port ",
          binary-to-ascii(10, 8, "", substring(option agent.circuit-id, 4, 1)),
          "/",
          binary-to-ascii(10, 8, "", substring(option agent.circuit-id, 5, 1)),
          " VLAN ",
          binary-to-ascii(10, 16, "", substring(option agent.circuit-id, 2, 2))));

    } elsif substring(option agent.remote-id, 4, 2) = "" {
      # If the length of the remote ID is less than 6, we probably have an IP
      # address from an HP.
      log(
        info,
        concat(
          "agent information ",
          binary-to-ascii(10, 8, ".", leased-address),
          " to ",
          binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)),
          " on ",
          binary-to-ascii(10, 8, ".", option agent.remote-id),
          " port ",
          binary-to-ascii(10, 8, "-", option agent.circuit-id)));

    } else {
      # otherwise, we probably have an HP MAC address, so just print the
      # remote ID as colon-separated hex; this doesn't hurt for anything
      # else, anyway, as we can always translate it.
      log(
        info,
        concat(
          "agent information ",
          binary-to-ascii(10, 8, ".", leased-address),
          " to ",
          binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)),
          " on ",
          binary-to-ascii(16, 8, ":", option agent.remote-id),
          " port ",
          binary-to-ascii(10, 8, "-", option agent.circuit-id)));
    }
  } else {
    # Same again, but for DHCPINFORM requests. In this case there is
    # no leased-address, so we pick the client IP address out of the
    # packet.
    if substring(option agent.remote-id, 0, 1) = 1 {
      # The first byte of the remote ID is 1. That's unlikely to be an
      # IP address and, if it were a MAC address it would be multicast,
      # so it is probably a hostname from a Cisco switch.
      log(
        info,
        concat(
          "agent information ",
          binary-to-ascii(10, 8, ".", packet(12, 4)),
          " to ",
          binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)),
          " on ",
          substring(option agent.remote-id, 2,
            extract-int(substring(option agent.remote-id, 1, 1), 8)),
          " port ",
          binary-to-ascii(10, 8, "", substring(option agent.circuit-id, 4, 1)),
          "/",
          binary-to-ascii(10, 8, "", substring(option agent.circuit-id, 5, 1)),
          " VLAN ",
          binary-to-ascii(10, 16, "", substring(option agent.circuit-id, 2, 2))));

    } elsif substring(option agent.remote-id, 4, 2) = "" {
      # If the length of the remote ID is less than 6, we probably have an IP
      # address from an HP.
      log(
        info,
        concat(
          "agent information ",
          binary-to-ascii(10, 8, ".", packet(12, 4)),
          " to ",
          binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)),
          " on ",
          binary-to-ascii(10, 8, ".", option agent.remote-id),
          " port ",
          binary-to-ascii(10, 8, "-", option agent.circuit-id)));

    } else {
      # otherwise, we probably have an HP MAC address, so just print the
      # remote ID as colon-separated hex; this doesn't hurt for anything
      # else, anyway, as we can always translate it.
      log(
        info,
        concat(
          "agent information ",
          binary-to-ascii(10, 8, ".", packet(12, 4)),
          " to ",
          binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)),
          " on ",
          binary-to-ascii(16, 8, ":", option agent.remote-id),
          " port ",
          binary-to-ascii(10, 8, "-", option agent.circuit-id)));
    }
  }
}



Tony.
--
f.anthony.n.finch  <[hidden email]>  http://dotat.at/  -  I xn--zr8h punycode
Viking, North Utsire: Northerly 5 or 6, backing westerly 3 or 4, occasionally
5 later. Rough. Showers later. Good.
_______________________________________________
Kea-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/kea-users