Blob Blame History Raw
From 9ad199184959deac21b3dbf0efbbb3d23f6baed1 Mon Sep 17 00:00:00 2001
Message-Id: <9ad199184959deac21b3dbf0efbbb3d23f6baed1.1599568829.git.lorenzo.bianconi@redhat.com>
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Date: Wed, 26 Aug 2020 12:15:46 +0200
Subject: [PATCH] Introduce DHCPDECLINE msg support to OVN DHCP server

According to the RFC2131 (https://tools.ietf.org/html/rfc2131), if the
server server receives a DHCPDECLINE message, the client has discovered
through some other means that the suggested network address is already
in use. The server SHOULD notify the local system administrator of a
possible configuration problem.

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
---
 controller/pinctrl.c |  6 ++++++
 lib/ovn-l7.h         |  1 +
 tests/ovn.at         | 13 +++++++++++++
 3 files changed, 20 insertions(+)

--- a/controller/pinctrl.c
+++ b/controller/pinctrl.c
@@ -1889,6 +1889,12 @@ pinctrl_handle_put_dhcp_opts(
 
         break;
     }
+    case OVN_DHCP_MSG_DECLINE:
+        if (request_ip == *offer_ip) {
+            VLOG_INFO("DHCPDECLINE from "ETH_ADDR_FMT ", "IP_FMT" duplicated",
+                      ETH_ADDR_ARGS(in_flow->dl_src), IP_ARGS(*offer_ip));
+        }
+        goto exit;
     default: {
         static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
         VLOG_WARN_RL(&rl, "Invalid DHCP message type: %d", *in_dhcp_msg_type);
--- a/lib/ovn-l7.h
+++ b/lib/ovn-l7.h
@@ -180,6 +180,7 @@ struct dhcp_opt6_header {
 };
 
 /* These are not defined in ovs/lib/dhcp.h, hence defining here. */
+#define OVN_DHCP_MSG_DECLINE        4
 #define OVN_DHCP_MSG_RELEASE        7
 #define OVN_DHCP_MSG_INFORM         8
 
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -5332,6 +5332,10 @@ test_dhcp() {
         reply_dst_ip=${offer_ip}
     fi
 
+    if test "$dhcp_type" == "04"; then
+        ciaddr=$offer_ip
+    fi
+
     local request=ffffffffffff${src_mac}08004510${ip_len}0000000080110000${src_ip}${dst_ip}
     # udp header and dhcp header
     request=${request}00440043${udp_len}0000
@@ -5897,6 +5901,15 @@ AT_CHECK([cat 2.packets | cut -c -48], [
 cat 2.expected | cut -c 53- > expout
 AT_CHECK([cat 2.packets | cut -c 53-], [0], [expout])
 
+# test DHCPDECLINE
+offer_ip=`ip_to_hex 10 0 0 4`
+server_ip=`ip_to_hex 10 0 0 1`
+ciaddr=`ip_to_hex 0 0 0 0`
+request_ip=0
+expected_dhcp_opts=""
+test_dhcp 1 f00000000001 04 0 $ciaddr $offer_ip $request_ip 0 ff1000000001 $server_ip 02 $expected_dhcp_opts
+AT_CHECK([fgrep -iq 'DHCPDECLINE from f0:00:00:00:00:01, 10.0.0.4 duplicated' hv1/ovn-controller.log], [0], [])
+
 OVN_CLEANUP([hv1])
 
 AT_CLEANUP