[U-Boot] [PATCH] net: bootp: Ignore packets whose yiaddr is 0

Peng Fan van.freenix at gmail.com
Mon Jan 4 03:49:56 CET 2016


When doing `dhcp`, there is a bad dhcp server in my network
which always reply dhcp request with yiaddr 0, which cause
uboot can not successfully get ipaddr from the good dhcp server.
But the Linux PC can get the ip address even if there is a bad
dhcp server. This patch is to fix that even if there is a bad
dhcp server, uboot can still get ipaddr and tftp work ok.

The way is to ignore the packets from the bad dhcp server by filtering
out the yiaddr whose value is 0.

Signed-off-by: Peng Fan <peng.fan at nxp.com>
Cc: Joe Hershberger <joe.hershberger at ni.com>
---
 net/bootp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/bootp.c b/net/bootp.c
index 8aeddb0..ff2ebbe 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -992,6 +992,9 @@ static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 	if (check_reply_packet(pkt, dest, src, len))
 		return;
 
+	if (net_read_ip(&bp->bp_yiaddr).s_addr == 0)
+		return;
+
 	debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: "
 	      "%d\n", src, dest, len, dhcp_state);
 
-- 
2.6.2



More information about the U-Boot mailing list