From: Justin Cinkelj <justin.cink...@xlab.si>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

dhcp: set src and dest IP in DHCP release packet

DHCP release packet should have valid IP header. There is no need
to use INADDR_ANY/INADDR_BROADCAST as src/dest address.

Signed-off-by: Justin Cinkelj <justin.cink...@xlab.si>
Message-Id: <20161123132746.27570-2-justin.cink...@xlab.si>

---
diff --git a/core/dhcp.cc b/core/dhcp.cc
--- a/core/dhcp.cc
+++ b/core/dhcp.cc
@@ -197,7 +197,7 @@ namespace dhcp {
         *options++ = DHCP_OPTION_END;

         dhcp_len += options - options_start;
-        build_udp_ip_headers(dhcp_len);
+        build_udp_ip_headers(dhcp_len, INADDR_ANY, INADDR_BROADCAST);
     }

     void dhcp_mbuf::compose_request(struct ifnet* ifp,
@@ -239,7 +239,7 @@ namespace dhcp {
         *options++ = DHCP_OPTION_END;

         dhcp_len += options - options_start;
-        build_udp_ip_headers(dhcp_len);
+        build_udp_ip_headers(dhcp_len, INADDR_ANY, INADDR_BROADCAST);
     }

     void dhcp_mbuf::compose_release(struct ifnet* ifp,
@@ -275,7 +275,7 @@ namespace dhcp {
         *options++ = DHCP_OPTION_END;

         dhcp_len += options - options_start;
-        build_udp_ip_headers(dhcp_len);
+        build_udp_ip_headers(dhcp_len, yip_n, sip_n);
     }

     u32 dhcp_mbuf::get_xid()
@@ -456,7 +456,7 @@ namespace dhcp {
         return pos + 2 + len;
     }

-    void dhcp_mbuf::build_udp_ip_headers(size_t dhcp_len)
+ void dhcp_mbuf::build_udp_ip_headers(size_t dhcp_len, in_addr_t src_addr, in_addr_t dest_addr)
     {
         struct ip* ip = pip();
         struct udphdr* udp = pudp();
@@ -473,8 +473,8 @@ namespace dhcp {
         ip->ip_ttl = 128;
         ip->ip_p = IPPROTO_UDP;
         ip->ip_sum = 0;
-        ip->ip_src.s_addr = INADDR_ANY;
-        ip->ip_dst.s_addr = INADDR_BROADCAST;
+        ip->ip_src.s_addr = src_addr;
+        ip->ip_dst.s_addr = dest_addr;
         ip->ip_sum = in_cksum(_m, min_ip_len);

         // UDP
diff --git a/include/osv/dhcp.hh b/include/osv/dhcp.hh
--- a/include/osv/dhcp.hh
+++ b/include/osv/dhcp.hh
@@ -168,7 +168,7 @@ namespace dhcp {
         u8* add_option(u8* pos, u8 type, u8 len, u8 data); // memset

         // Packet assembly
-        void build_udp_ip_headers(size_t dhcp_len);
+ void build_udp_ip_headers(size_t dhcp_len, in_addr_t src_addr, in_addr_t dest_addr);

         // mbuf related
         void allocate_mbuf();

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to