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.
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>
ushort id;
ushort sequence;
} echo;
ushort id;
ushort sequence;
} echo;
struct {
ushort unused;
ushort mtu;
struct {
ushort unused;
ushort mtu;
}
/* return ulong *in network byteorder* */
}
/* return ulong *in network byteorder* */
-static inline ulong net_read_long(ulong *from)
+static inline u32 net_read_u32(u32 *from)
memcpy((void *)&l, (void *)from, sizeof(l));
return l;
memcpy((void *)&l, (void *)from, sizeof(l));
return l;
-static inline void net_copy_long(ulong *to, ulong *from)
+static inline void net_copy_u32(u32 *to, u32 *from)
- memcpy((void *)to, (void *)from, sizeof(ulong));
+ memcpy((void *)to, (void *)from, sizeof(u32));
#define CONFIG_BOOTP_ID_CACHE_SIZE 4
#endif
#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 bootp_try;
ulong bootp_start;
unsigned int bootp_num_ids;
int bootp_try;
ulong bootp_start;
#if defined(CONFIG_CMD_DHCP)
static dhcp_state_t dhcp_state = INIT;
#if defined(CONFIG_CMD_DHCP)
static dhcp_state_t dhcp_state = INIT;
-static unsigned long dhcp_leasetime;
+static u32 dhcp_leasetime;
static struct in_addr dhcp_server_ip;
static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
unsigned src, unsigned len);
static struct in_addr dhcp_server_ip;
static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
unsigned src, unsigned len);
retval = -4;
else if (bp->bp_hlen != HWL_ETHER)
retval = -5;
retval = -4;
else if (bp->bp_hlen != HWL_ETHER)
retval = -5;
- else if (!bootp_match_id(net_read_long((ulong *)&bp->bp_id)))
+ else if (!bootp_match_id(net_read_u32(&bp->bp_id)))
retval = -6;
debug("Filtering pkt = %d\n", retval);
retval = -6;
debug("Filtering pkt = %d\n", retval);
store_net_params(bp); /* Store net parameters from reply */
/* Retrieve extended information (we must parse the vendor area) */
store_net_params(bp); /* Store net parameters from reply */
/* Retrieve extended information (we must parse the vendor area) */
- if (net_read_long((ulong *)&bp->bp_vend[0]) ==
- htonl(BOOTP_VENDOR_MAGIC))
+ if (net_read_u32((u32 *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
bootp_process_vendor((uchar *)&bp->bp_vend[4], len);
net_set_timeout_handler(0, (thand_f *)0);
bootp_process_vendor((uchar *)&bp->bp_vend[4], len);
net_set_timeout_handler(0, (thand_f *)0);
#ifdef CONFIG_BOOTP_RANDOM_DELAY
ulong rand_ms;
#endif
#ifdef CONFIG_BOOTP_RANDOM_DELAY
ulong rand_ms;
#endif
struct in_addr zero_ip;
struct in_addr bcast_ip;
struct in_addr zero_ip;
struct in_addr bcast_ip;
#ifdef CONFIG_BOOTP_RANDOM_ID
bootp_id = rand();
#else
#ifdef CONFIG_BOOTP_RANDOM_ID
bootp_id = rand();
#else
- bootp_id = ((ulong)net_ethaddr[2] << 24)
- | ((ulong)net_ethaddr[3] << 16)
- | ((ulong)net_ethaddr[4] << 8)
- | (ulong)net_ethaddr[5];
+ bootp_id = ((u32)net_ethaddr[2] << 24)
+ | ((u32)net_ethaddr[3] << 16)
+ | ((u32)net_ethaddr[4] << 8)
+ | (u32)net_ethaddr[5];
bootp_id += get_timer(0);
bootp_id = htonl(bootp_id);
#endif
bootp_add_id(bootp_id);
bootp_id += get_timer(0);
bootp_id = htonl(bootp_id);
#endif
bootp_add_id(bootp_id);
- net_copy_long(&bp->bp_id, &bootp_id);
+ net_copy_u32(&bp->bp_id, &bootp_id);
/*
* Calculate proper packet lengths taking into account the
/*
* Calculate proper packet lengths taking into account the
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
case 2: /* Time offset */
to_ptr = &net_ntp_time_offset;
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
case 2: /* Time offset */
to_ptr = &net_ntp_time_offset;
- net_copy_long((ulong *)to_ptr, (ulong *)(popt + 2));
+ net_copy_u32((u32 *)to_ptr, (u32 *)(popt + 2));
net_ntp_time_offset = ntohl(net_ntp_time_offset);
break;
#endif
net_ntp_time_offset = ntohl(net_ntp_time_offset);
break;
#endif
- net_copy_long(&dhcp_leasetime, (ulong *)(popt + 2));
+ net_copy_u32(&dhcp_leasetime, (u32 *)(popt + 2));
break;
case 53: /* Ignore Message Type Option */
break;
break;
case 53: /* Ignore Message Type Option */
break;
static int dhcp_message_type(unsigned char *popt)
{
static int dhcp_message_type(unsigned char *popt)
{
- if (net_read_long((ulong *)popt) != htonl(BOOTP_VENDOR_MAGIC))
+ if (net_read_u32((u32 *)popt) != htonl(BOOTP_VENDOR_MAGIC))
* ID is the id of the OFFER packet
*/
* ID is the id of the OFFER packet
*/
- net_copy_long(&bp->bp_id, &bp_offer->bp_id);
+ net_copy_u32(&bp->bp_id, &bp_offer->bp_id);
/*
* Copy options from OFFER packet if present
/*
* Copy options from OFFER packet if present
debug("TRANSITIONING TO REQUESTING STATE\n");
dhcp_state = REQUESTING;
debug("TRANSITIONING TO REQUESTING STATE\n");
dhcp_state = REQUESTING;
- if (net_read_long((ulong *)&bp->bp_vend[0]) ==
+ if (net_read_u32((u32 *)&bp->bp_vend[0]) ==
htonl(BOOTP_VENDOR_MAGIC))
dhcp_process_options((u8 *)&bp->bp_vend[4], bp);
htonl(BOOTP_VENDOR_MAGIC))
dhcp_process_options((u8 *)&bp->bp_vend[4], bp);
debug("DHCP State: REQUESTING\n");
if (dhcp_message_type((u8 *)bp->bp_vend) == DHCP_ACK) {
debug("DHCP State: REQUESTING\n");
if (dhcp_message_type((u8 *)bp->bp_vend) == DHCP_ACK) {
- if (net_read_long((ulong *)&bp->bp_vend[0]) ==
+ if (net_read_u32((u32 *)&bp->bp_vend[0]) ==
htonl(BOOTP_VENDOR_MAGIC))
dhcp_process_options((u8 *)&bp->bp_vend[4], bp);
/* Store net params from reply */
htonl(BOOTP_VENDOR_MAGIC))
dhcp_process_options((u8 *)&bp->bp_vend[4], bp);
/* Store net params from reply */
uchar bp_hlen; /* Hardware address length */
# define HWL_ETHER 6
uchar bp_hops; /* Hop count (gateway thing) */
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 */
struct in_addr bp_ciaddr; /* Client IP address */
ushort bp_secs; /* Seconds since boot */
ushort bp_spare1; /* Alignment */
struct in_addr bp_ciaddr; /* Client IP address */
-extern ulong bootp_id; /* ID of cur BOOTP request */
+extern u32 bootp_id; /* ID of cur BOOTP request */