3

I have a dhcp packets sniffer, which needs to log if it sees dhcp decline response coming from client.I need to know the scenario where client can send dhcp decline response to dhcp server. I tried to get this reproduce by minimizing small range of ip's at dhcpserver and allocating duplicate static ip's to a client says client_A and running dhclient on client_B.But client_B accepts duplicate ip (ip which is already with ip client_A), instead of sending dhcpdecline response.

Is this a better and guaranteed way to reproduce dhcp decline scenario. Clients I m using are ubuntu and for dhcp server various options are available like vyos/microsoft.

Thanks and advance !!

user2589882
  • 51
  • 1
  • 3

2 Answers2

1

It looks like it should be possible, but it's going to require a bit of fiddling...

As you suggested in the comments, dhclient doesn't validate DHCP server responses for router addresses so I went to the documents and found out what kind of situation might cause dhclient to send a DHCPDECLINE.

Dhclient docs show that dhclient-script is called when a lease is issued:

...network configuration script invoked by dhclient when it gets a lease. If unspecified, the default CLIENTBINDIR/dhclient-script is used. See dhclient-script(8)for a description of this file.

http://manpages.ubuntu.com/manpages/wily/en/man8/dhclient.8.html

Dhclient-script docs show that before configuring the address offered by the DHCP server, dhclient-script ARPs for it and raises a DHCPDECLINE if the address already exists.

Before actually configuring the address, dhclient-script should somehow ARP for it and exit with a nonzero status if it receives a reply. In this case, the client will send a DHCPDECLINE message to the server and acquire a different address.

http://manpages.ubuntu.com/manpages/wily/en/man8/dhclient-script.8.html

I haven't got a copy of Ubuntu to look at at the mo (check your /etc/dhclient-script), but the source code for the Linux dhclient-script can be found here http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/wily/isc-dhcp/wily/view/head:/client/scripts/linux

I'm thinking (but unfortunately can't test it) that you could backup your existing dhclient-script and edit this section

 Must be used on exit.   Invokes the local dhcp client exit hooks, if any.
exit_with_hooks() {
  exit_status=$1
  if [ -f /etc/dhclient-exit-hooks ]; then
    . /etc/dhclient-exit-hooks
  fi
# probably should do something with exit status of the local script
  exit $exit_status
}

I think changing exit $exit_status to exit 1 would cause any DHCP lease to be declined...

Give it a try. If it works as I think it should, it will totally break the DHCP client but should generate a DHCPDECLINE each time you run dhclient.

leftcase
  • 710
  • 3
  • 9
  • 18
  • Tried editing dhclient-script, but no success yet !I was just thinking if there can be a be a way wihout editing source code of any client/server. – user2589882 Feb 17 '16 at 23:24
  • Sorry - my bad. Try a non-zero exit status. (i.e. 1). i'm not sure what will trigger a DHCPDECLINE, and unfortunately don't have a Linux system in front of me to test. – leftcase Feb 17 '16 at 23:38
  • Unfortunately, I can't see a way of changing this without editing the source code. Check the docs - the only way the default DHCP client will refuse to accept a DHCP offer is when an ARP check shows the IP address has already been issued... – leftcase Feb 17 '16 at 23:41
  • Changing script to 1 does not help, tried that as well.Kindly let me know if you get the chance to test this on your system. – user2589882 Feb 17 '16 at 23:52
0

From any traffic-generator create an ethernet IPv4-DHCP message type53 with 04 for Decline and 06 bytes for NAK

Nir
  • 1
  • 1
    that wa snot the question, the opener asked for, WHAT is the reason not howto generate such messages - please improve your answer – djdomi Jul 27 '21 at 08:27