summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Temerkhanov <s.temerkhanov@gmail.com>2015-04-08 09:41:22 +0300
committercodewalker <codewalker@hardkernel.com>2017-06-01 11:47:07 +0300
commit34d47bb3e56944e3ba632a20095fb93434ddea81 (patch)
tree5b7f0868816bcf4302f18edce279f1a3f7568709
parent205c7b3259559283161703a1a200b787c2c445a5 (diff)
downloadu-boot-34d47bb3e56944e3ba632a20095fb93434ddea81.tar.xz
BACKPORT: net: Fix incorrect DHCP/BOOTP packets on 64-bit systems
This commit fixes incorrect DHCP/BOOTP packet layout caused by 'ulong' type size difference on 64 and 32-bit architectures. It also renames NetReadLong()/NetCopyLong() to net_read_u32/net_copy_u32() accordingly. Change-Id: Ic62bc12069cf60aa347d1541acc9f6e8c5c576df Signed-off-by: Radha Mohan Chintakuntla <rchintakuntla@cavium.com> Signed-off-by: Sergey Temerkhanov <s.temerkhanov@gmail.com> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Acked-by: Simon Glass <sjg@chromium.org> Signed-off-by: Dongjin Kim <tobetter@gmail.com>
-rw-r--r--include/net.h10
-rw-r--r--net/bootp.c20
-rw-r--r--net/bootp.h5
3 files changed, 17 insertions, 18 deletions
diff --git a/include/net.h b/include/net.h
index 18d279ebe7..6bc6cceba0 100644
--- a/include/net.h
+++ b/include/net.h
@@ -338,7 +338,7 @@ struct icmp_hdr {
ushort id;
ushort sequence;
} echo;
- ulong gateway;
+ u32 gateway;
struct {
ushort unused;
ushort mtu;
@@ -580,9 +580,9 @@ static inline IPaddr_t NetReadIP(void *from)
}
/* return ulong *in network byteorder* */
-static inline ulong NetReadLong(ulong *from)
+static inline u32 NetReadLong(u32 *from)
{
- ulong l;
+ u32 l;
memcpy((void *)&l, (void *)from, sizeof(l));
return l;
@@ -601,9 +601,9 @@ static inline void NetCopyIP(void *to, void *from)
}
/* copy ulong */
-static inline void NetCopyLong(ulong *to, ulong *from)
+static inline void NetCopyLong(u32 *to, u32 *from)
{
- memcpy((void *)to, (void *)from, sizeof(ulong));
+ memcpy((void *)to, (void *)from, sizeof(u32));
}
/**
diff --git a/net/bootp.c b/net/bootp.c
index 81066015f1..bf5d71eea0 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -51,7 +51,7 @@
#define CONFIG_BOOTP_ID_CACHE_SIZE 4
#endif
-ulong bootp_ids[CONFIG_BOOTP_ID_CACHE_SIZE];
+u32 bootp_ids[CONFIG_BOOTP_ID_CACHE_SIZE];
unsigned int bootp_num_ids;
int BootpTry;
ulong bootp_start;
@@ -59,7 +59,7 @@ ulong bootp_timeout;
#if defined(CONFIG_CMD_DHCP)
static dhcp_state_t dhcp_state = INIT;
-static unsigned long dhcp_leasetime;
+static u32 dhcp_leasetime;
static IPaddr_t NetDHCPServerIP;
static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
unsigned len);
@@ -125,7 +125,7 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
retval = -4;
else if (bp->bp_hlen != HWL_ETHER)
retval = -5;
- else if (!bootp_match_id(NetReadLong((ulong *)&bp->bp_id)))
+ else if (!bootp_match_id(NetReadLong((u32 *)&bp->bp_id)))
retval = -6;
debug("Filtering pkt = %d\n", retval);
@@ -350,7 +350,7 @@ BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
BootpCopyNetParams(bp); /* Store net parameters from reply */
/* Retrieve extended information (we must parse the vendor area) */
- if (NetReadLong((ulong *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
+ if (NetReadLong((u32 *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
BootpVendorProcess((uchar *)&bp->bp_vend[4], len);
NetSetTimeout(0, (thand_f *)0);
@@ -661,7 +661,7 @@ BootpRequest(void)
#ifdef CONFIG_BOOTP_RANDOM_DELAY
ulong rand_ms;
#endif
- ulong BootpID;
+ u32 BootpID;
bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start");
#if defined(CONFIG_CMD_DHCP)
@@ -770,7 +770,7 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
case 2: /* Time offset */
to_ptr = &NetTimeOffset;
- NetCopyLong((ulong *)to_ptr, (ulong *)(popt + 2));
+ NetCopyLong((u32 *)to_ptr, (u32 *)(popt + 2));
NetTimeOffset = ntohl(NetTimeOffset);
break;
#endif
@@ -806,7 +806,7 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
break;
#endif
case 51:
- NetCopyLong(&dhcp_leasetime, (ulong *) (popt + 2));
+ NetCopyLong(&dhcp_leasetime, (u32 *) (popt + 2));
break;
case 53: /* Ignore Message Type Option */
break;
@@ -860,7 +860,7 @@ static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
static int DhcpMessageType(unsigned char *popt)
{
- if (NetReadLong((ulong *)popt) != htonl(BOOTP_VENDOR_MAGIC))
+ if (NetReadLong((u32 *)popt) != htonl(BOOTP_VENDOR_MAGIC))
return -1;
popt += 4;
@@ -970,7 +970,7 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
debug("TRANSITIONING TO REQUESTING STATE\n");
dhcp_state = REQUESTING;
- if (NetReadLong((ulong *)&bp->bp_vend[0]) ==
+ if (NetReadLong((u32 *)&bp->bp_vend[0]) ==
htonl(BOOTP_VENDOR_MAGIC))
DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
@@ -986,7 +986,7 @@ DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
debug("DHCP State: REQUESTING\n");
if (DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK) {
- if (NetReadLong((ulong *)&bp->bp_vend[0]) ==
+ if (NetReadLong((u32 *)&bp->bp_vend[0]) ==
htonl(BOOTP_VENDOR_MAGIC))
DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
/* Store net params from reply */
diff --git a/net/bootp.h b/net/bootp.h
index 3b95a0a2de..4efee0a9de 100644
--- a/net/bootp.h
+++ b/net/bootp.h
@@ -38,7 +38,7 @@ struct Bootp_t {
uchar bp_hlen; /* Hardware address length */
# define HWL_ETHER 6
uchar bp_hops; /* Hop count (gateway thing) */
- ulong bp_id; /* Transaction ID */
+ u32 bp_id; /* Transaction ID */
ushort bp_secs; /* Seconds since boot */
ushort bp_spare1; /* Alignment */
IPaddr_t bp_ciaddr; /* Client IP address */
@@ -59,11 +59,10 @@ struct Bootp_t {
*/
/* bootp.c */
-extern ulong BootpID; /* ID of cur BOOTP request */
+extern u32 BootpID; /* ID of cur BOOTP request */
extern char BootFile[128]; /* Boot file name */
extern int BootpTry;
-
/* Send a BOOTP request */
extern void BootpReset(void);
extern void BootpRequest(void);