Merge branch 'master' into ppp-new

This commit is contained in:
Sylvain Rochet 2013-01-20 02:57:57 +01:00
commit 69b15c889d
11 changed files with 230 additions and 188 deletions

View File

@ -145,6 +145,18 @@ HISTORY
++ Bugfixes:
2013-01-15: Simon Goldschmidt
* ip4.c: fixed bug #37665 ip_canforward operates on address in wrong byte order
2013-01-15: Simon Goldschmidt
* pbuf.h: fixed bug #38097 pbuf_free_ooseq() warning
2013-01-14: Simon Goldschmidt
* dns.c: fixed bug #37705 Possible memory corruption in DNS query
2013-01-11: Simon Goldschmidt
* raw.c: fixed bug #38066 Raw pcbs can alter packet without eating it
2012-09-26: Simon Goldschmidt
* api_msg.c: fixed bug #37405 'err_tcp()' uses already freed 'netconn' object

View File

@ -1482,7 +1482,7 @@ decode_next:
LWIP_ASSERT("next pbuf was null", q);
options = (u8_t*)q->payload;
} else {
// We've run out of bytes, probably no end marker. Don't proceed.
/* We've run out of bytes, probably no end marker. Don't proceed. */
break;
}
}

View File

@ -573,9 +573,10 @@ dns_send(u8_t numdns, const char* name, u8_t id)
LWIP_ASSERT("dns server has no IP address set", !ip_addr_isany(&dns_servers[numdns]));
/* if here, we have either a new query or a retry on a previous query to process */
p = pbuf_alloc(PBUF_TRANSPORT, SIZEOF_DNS_HDR + DNS_MAX_NAME_LENGTH +
p = pbuf_alloc(PBUF_TRANSPORT, SIZEOF_DNS_HDR + DNS_MAX_NAME_LENGTH + 1 +
SIZEOF_DNS_QUERY, PBUF_RAM);
if (p != NULL) {
u16_t realloc_size;
LWIP_ASSERT("pbuf must be in one piece", p->next == NULL);
/* fill dns header */
hdr = (struct dns_hdr*)p->payload;
@ -607,7 +608,9 @@ dns_send(u8_t numdns, const char* name, u8_t id)
SMEMCPY(query, &qry, SIZEOF_DNS_QUERY);
/* resize pbuf to the exact dns query */
pbuf_realloc(p, (u16_t)((query + SIZEOF_DNS_QUERY) - ((char*)(p->payload))));
realloc_size = (u16_t)((query + SIZEOF_DNS_QUERY) - ((char*)(p->payload)));
LWIP_ASSERT("p->tot_len >= realloc_size", p->tot_len >= realloc_size);
pbuf_realloc(p, realloc_size);
/* connect to the server for faster receiving */
udp_connect(dns_pcb, &dns_servers[numdns], DNS_SERVER_PORT);
@ -860,12 +863,14 @@ memerr:
* Queues a new hostname to resolve and sends out a DNS query for that hostname
*
* @param name the hostname that is to be queried
* @param hostnamelen length of the hostname
* @param found a callback founction to be called on success, failure or timeout
* @param callback_arg argument to pass to the callback function
* @return @return a err_t return code.
*/
static err_t
dns_enqueue(const char *name, dns_found_callback found, void *callback_arg)
dns_enqueue(const char *name, size_t hostnamelen, dns_found_callback found,
void *callback_arg)
{
u8_t i;
u8_t lseq, lseqi;
@ -910,7 +915,7 @@ dns_enqueue(const char *name, dns_found_callback found, void *callback_arg)
pEntry->seqno = dns_seqno++;
pEntry->found = found;
pEntry->arg = callback_arg;
namelen = LWIP_MIN(strlen(name), DNS_MAX_NAME_LENGTH-1);
namelen = LWIP_MIN(hostnamelen, DNS_MAX_NAME_LENGTH-1);
MEMCPY(pEntry->name, name, namelen);
pEntry->name[namelen] = 0;
@ -945,13 +950,18 @@ dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback foun
void *callback_arg)
{
u32_t ipaddr;
size_t hostnamelen;
/* not initialized or no valid server yet, or invalid addr pointer
* or invalid hostname or invalid hostname length */
if ((dns_pcb == NULL) || (addr == NULL) ||
(!hostname) || (!hostname[0]) ||
(strlen(hostname) >= DNS_MAX_NAME_LENGTH)) {
(!hostname) || (!hostname[0])) {
return ERR_ARG;
}
hostnamelen = strlen(hostname);
if (hostnamelen >= DNS_MAX_NAME_LENGTH) {
return ERR_ARG;
}
#if LWIP_HAVE_LOOPIF
if (strcmp(hostname, "localhost")==0) {
@ -972,7 +982,7 @@ dns_gethostbyname(const char *hostname, ip_addr_t *addr, dns_found_callback foun
}
/* queue query with specified callback */
return dns_enqueue(hostname, found, callback_arg);
return dns_enqueue(hostname, hostnamelen, found, callback_arg);
}
#endif /* LWIP_DNS */

View File

@ -277,6 +277,9 @@
#if TCP_SNDQUEUELOWAT >= TCP_SND_QUEUELEN
#error "lwip_sanity_check: WARNING: TCP_SNDQUEUELOWAT must be less than TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if !MEMP_MEM_MALLOC && (PBUF_POOL_BUFSIZE <= (PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))
#error "lwip_sanity_check: WARNING: PBUF_POOL_BUFSIZE does not provide enough space for protocol headers. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if !MEMP_MEM_MALLOC && (TCP_WND > (PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - (PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))))
#error "lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - protocol headers). If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif

View File

@ -153,7 +153,7 @@ ip_route(ip_addr_t *dest)
static int
ip_canforward(struct pbuf *p)
{
u32_t addr = ip4_addr_get_u32(ip_current_dest_addr());
u32_t addr = htonl(ip4_addr_get_u32(ip_current_dest_addr()));
if (p->flags & PBUF_FLAG_LLBCAST) {
/* don't route link-layer broadcasts */

View File

@ -119,6 +119,9 @@ raw_input(struct pbuf *p, struct netif *inp)
{
/* receive callback function available? */
if (pcb->recv.ip4 != NULL) {
#ifndef LWIP_NOASSERT
void* old_payload = p->payload;
#endif
/* the receive callback function did not eat the packet? */
eaten = pcb->recv.ip4(pcb->recv_arg, pcb, p, ip_current_src_addr());
if (eaten != 0) {
@ -132,6 +135,10 @@ raw_input(struct pbuf *p, struct netif *inp)
pcb->next = raw_pcbs;
raw_pcbs = pcb;
}
} else {
/* sanity-check that the receive callback did not alter the pbuf */
LWIP_ASSERT("raw pcb recv callback altered pbuf payload pointer without eating packet",
p->payload == old_payload);
}
}
/* no receive callback function was set for this raw PCB */

View File

@ -845,8 +845,10 @@ err_t
tcp_send_empty_ack(struct tcp_pcb *pcb)
{
struct pbuf *p;
struct tcp_hdr *tcphdr;
u8_t optlen = 0;
#if LWIP_TCP_TIMESTAMPS || CHECKSUM_GEN_TCP
struct tcp_hdr *tcphdr;
#endif /* LWIP_TCP_TIMESTAMPS || CHECKSUM_GEN_TCP */
#if LWIP_TCP_TIMESTAMPS
if (pcb->flags & TF_TIMESTAMP) {
@ -859,7 +861,9 @@ tcp_send_empty_ack(struct tcp_pcb *pcb)
LWIP_DEBUGF(TCP_OUTPUT_DEBUG, ("tcp_output: (ACK) could not allocate pbuf\n"));
return ERR_BUF;
}
#if LWIP_TCP_TIMESTAMPS || CHECKSUM_GEN_TCP
tcphdr = (struct tcp_hdr *)p->payload;
#endif /* LWIP_TCP_TIMESTAMPS || CHECKSUM_GEN_TCP */
LWIP_DEBUGF(TCP_OUTPUT_DEBUG,
("tcp_output: sending ACK for %"U32_F"\n", pcb->rcv_nxt));
/* remove ACK flags from the PCB, as we send an empty ACK now */
@ -1373,7 +1377,9 @@ void
tcp_keepalive(struct tcp_pcb *pcb)
{
struct pbuf *p;
#if CHECKSUM_GEN_TCP
struct tcp_hdr *tcphdr;
#endif /* CHECKSUM_GEN_TCP */
LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: sending KEEPALIVE probe to "));
ipX_addr_debug_print(PCB_ISIPV6(pcb), TCP_DEBUG, &pcb->remote_ip);
@ -1388,10 +1394,12 @@ tcp_keepalive(struct tcp_pcb *pcb)
("tcp_keepalive: could not allocate memory for pbuf\n"));
return;
}
#if CHECKSUM_GEN_TCP
tcphdr = (struct tcp_hdr *)p->payload;
tcphdr->chksum = ipX_chksum_pseudo(PCB_ISIPV6(pcb), p, IP_PROTO_TCP, p->tot_len,
&pcb->local_ip, &pcb->remote_ip);
#endif /* CHECKSUM_GEN_TCP */
TCP_STATS_INC(tcp.xmit);
/* Send output to IP */

View File

@ -509,7 +509,7 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p)
return udp_sendto(pcb, p, ipX_2_ip(&pcb->remote_ip), pcb->remote_port);
}
#if LWIP_CHECKSUM_ON_COPY
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
/** Same as udp_send() but with checksum
*/
err_t
@ -520,7 +520,7 @@ udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
return udp_sendto_chksum(pcb, p, ipX_2_ip(&pcb->remote_ip), pcb->remote_port,
have_chksum, chksum);
}
#endif /* LWIP_CHECKSUM_ON_COPY */
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
/**
* Send data to a specified address using UDP.
@ -543,7 +543,7 @@ err_t
udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
ip_addr_t *dst_ip, u16_t dst_port)
{
#if LWIP_CHECKSUM_ON_COPY
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0);
}
@ -552,7 +552,7 @@ err_t
udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
u16_t dst_port, u8_t have_chksum, u16_t chksum)
{
#endif /* LWIP_CHECKSUM_ON_COPY */
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
struct netif *netif;
ipX_addr_t *dst_ip_route = ip_2_ipX(dst_ip);
@ -585,11 +585,11 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
UDP_STATS_INC(udp.rterr);
return ERR_RTE;
}
#if LWIP_CHECKSUM_ON_COPY
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum);
#else /* LWIP_CHECKSUM_ON_COPY */
#else /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
#endif /* LWIP_CHECKSUM_ON_COPY */
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
}
/**
@ -615,7 +615,7 @@ err_t
udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif)
{
#if LWIP_CHECKSUM_ON_COPY
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0);
}
@ -625,7 +625,7 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
u16_t dst_port, struct netif *netif, u8_t have_chksum,
u16_t chksum)
{
#endif /* LWIP_CHECKSUM_ON_COPY */
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
struct udp_hdr *udphdr;
ip_addr_t *src_ip;
err_t err;

View File

@ -136,7 +136,7 @@ struct pbuf_custom {
#endif /* PBUF_POOL_FREE_OOSEQ */
#if NO_SYS && PBUF_POOL_FREE_OOSEQ
extern volatile u8_t pbuf_free_ooseq_pending;
void pbuf_free_ooseq();
void pbuf_free_ooseq(void);
/** When not using sys_check_timeouts(), call PBUF_CHECK_FREE_OOSEQ()
at regular intervals from main level to check if ooseq pbufs need to be
freed! */

View File

@ -160,7 +160,7 @@ err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p,
ip_addr_t *dst_ip, u16_t dst_port);
err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
#if LWIP_CHECKSUM_ON_COPY
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
err_t udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p,
ip_addr_t *dst_ip, u16_t dst_port,
struct netif *netif, u8_t have_chksum,
@ -170,7 +170,7 @@ err_t udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p,
u8_t have_chksum, u16_t chksum);
err_t udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
u8_t have_chksum, u16_t chksum);
#endif /* LWIP_CHECKSUM_ON_COPY */
#endif /* LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
#define udp_flags(pcb) ((pcb)->flags)
#define udp_setflags(pcb, f) ((pcb)->flags = (f))
@ -192,12 +192,12 @@ struct udp_pcb * udp_new_ip6(void);
udp_sendto(pcb, pbuf, ip6_2_ip(ip6addr), port)
#define udp_sendto_if_ip6(pcb, pbuf, ip6addr, port, netif) \
udp_sendto_if(pcb, pbuf, ip6_2_ip(ip6addr), port, netif)
#if LWIP_CHECKSUM_ON_COPY
#if LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP
#define udp_sendto_chksum_ip6(pcb, pbuf, ip6addr, port, have_chk, chksum) \
udp_sendto_chksum(pcb, pbuf, ip6_2_ip(ip6addr), port, have_chk, chksum)
#define udp_sendto_if_chksum_ip6(pcb, pbuf, ip6addr, port, netif, have_chk, chksum) \
udp_sendto_if_chksum(pcb, pbuf, ip6_2_ip(ip6addr), port, netif, have_chk, chksum)
#endif /*LWIP_CHECKSUM_ON_COPY */
#endif /*LWIP_CHECKSUM_ON_COPY && CHECKSUM_GEN_UDP */
#endif /* LWIP_IPV6 */
#if UDP_DEBUG

View File

@ -11,25 +11,25 @@ static const u8_t broadcast[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
static const u8_t magic_cookie[] = { 0x63, 0x82, 0x53, 0x63 };
static u8_t dhcp_offer[] = {
0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, // To unit
0x00, 0x0F, 0xEE, 0x30, 0xAB, 0x22, // From Remote host
0x08, 0x00, // Protocol: IP
0x45, 0x10, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, 0x36, 0xcc, 0xc3, 0xaa, 0xbd, 0xab, 0xc3, 0xaa, 0xbd, 0xc8, // IP header
0x00, 0x43, 0x00, 0x44, 0x01, 0x34, 0x00, 0x00, // UDP header
0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, /* To unit */
0x00, 0x0F, 0xEE, 0x30, 0xAB, 0x22, /* From Remote host */
0x08, 0x00, /* Protocol: IP */
0x45, 0x10, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, 0x36, 0xcc, 0xc3, 0xaa, 0xbd, 0xab, 0xc3, 0xaa, 0xbd, 0xc8, /* IP header */
0x00, 0x43, 0x00, 0x44, 0x01, 0x34, 0x00, 0x00, /* UDP header */
0x02, // Type == Boot reply
0x01, 0x06, // Hw Ethernet, 6 bytes addrlen
0x00, // 0 hops
0xAA, 0xAA, 0xAA, 0xAA, // Transaction id, will be overwritten
0x00, 0x00, // 0 seconds elapsed
0x00, 0x00, // Flags (unicast)
0x00, 0x00, 0x00, 0x00, // Client ip
0xc3, 0xaa, 0xbd, 0xc8, // Your IP
0xc3, 0xaa, 0xbd, 0xab, // DHCP server ip
0x00, 0x00, 0x00, 0x00, // relay agent
0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // MAC addr + padding
0x02, /* Type == Boot reply */
0x01, 0x06, /* Hw Ethernet, 6 bytes addrlen */
0x00, /* 0 hops */
0xAA, 0xAA, 0xAA, 0xAA, /* Transaction id, will be overwritten */
0x00, 0x00, /* 0 seconds elapsed */
0x00, 0x00, /* Flags (unicast) */
0x00, 0x00, 0x00, 0x00, /* Client ip */
0xc3, 0xaa, 0xbd, 0xc8, /* Your IP */
0xc3, 0xaa, 0xbd, 0xab, /* DHCP server ip */
0x00, 0x00, 0x00, 0x00, /* relay agent */
0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MAC addr + padding */
// Empty server name and boot file name
/* Empty server name and boot file name */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -43,36 +43,36 @@ static u8_t dhcp_offer[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x63, 0x82, 0x53, 0x63, // Magic cookie
0x35, 0x01, 0x02, // Message type: Offer
0x36, 0x04, 0xc3, 0xaa, 0xbd, 0xab, // Server identifier (IP)
0x33, 0x04, 0x00, 0x00, 0x00, 0x78, // Lease time 2 minutes
0x03, 0x04, 0xc3, 0xaa, 0xbd, 0xab, // Router IP
0x01, 0x04, 0xff, 0xff, 0xff, 0x00, // Subnet mask
0xff, // End option
0x63, 0x82, 0x53, 0x63, /* Magic cookie */
0x35, 0x01, 0x02, /* Message type: Offer */
0x36, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* Server identifier (IP) */
0x33, 0x04, 0x00, 0x00, 0x00, 0x78, /* Lease time 2 minutes */
0x03, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* Router IP */
0x01, 0x04, 0xff, 0xff, 0xff, 0x00, /* Subnet mask */
0xff, /* End option */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Padding
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Padding */
};
static u8_t dhcp_ack[] = {
0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, // To unit
0x00, 0x0f, 0xEE, 0x30, 0xAB, 0x22, // From remote host
0x08, 0x00, // Proto IP
0x45, 0x10, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, 0x36, 0xcc, 0xc3, 0xaa, 0xbd, 0xab, 0xc3, 0xaa, 0xbd, 0xc8, // IP header
0x00, 0x43, 0x00, 0x44, 0x01, 0x34, 0x00, 0x00, // UDP header
0x02, // Bootp reply
0x01, 0x06, // Hw type Eth, len 6
0x00, // 0 hops
0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, /* To unit */
0x00, 0x0f, 0xEE, 0x30, 0xAB, 0x22, /* From remote host */
0x08, 0x00, /* Proto IP */
0x45, 0x10, 0x01, 0x48, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, 0x36, 0xcc, 0xc3, 0xaa, 0xbd, 0xab, 0xc3, 0xaa, 0xbd, 0xc8, /* IP header */
0x00, 0x43, 0x00, 0x44, 0x01, 0x34, 0x00, 0x00, /* UDP header */
0x02, /* Bootp reply */
0x01, 0x06, /* Hw type Eth, len 6 */
0x00, /* 0 hops */
0xAA, 0xAA, 0xAA, 0xAA,
0x00, 0x00, // 0 seconds elapsed
0x00, 0x00, // Flags (unicast)
0x00, 0x00, 0x00, 0x00, // Client IP
0xc3, 0xaa, 0xbd, 0xc8, // Your IP
0xc3, 0xaa, 0xbd, 0xab, // DHCP server IP
0x00, 0x00, 0x00, 0x00, // Relay agent
0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Macaddr + padding
0x00, 0x00, /* 0 seconds elapsed */
0x00, 0x00, /* Flags (unicast) */
0x00, 0x00, 0x00, 0x00, /* Client IP */
0xc3, 0xaa, 0xbd, 0xc8, /* Your IP */
0xc3, 0xaa, 0xbd, 0xab, /* DHCP server IP */
0x00, 0x00, 0x00, 0x00, /* Relay agent */
0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Macaddr + padding */
// Empty server name and boot file name
/* Empty server name and boot file name */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -86,31 +86,31 @@ static u8_t dhcp_ack[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x63, 0x82, 0x53, 0x63, // Magic cookie
0x35, 0x01, 0x05, // Dhcp message type ack
0x36, 0x04, 0xc3, 0xaa, 0xbd, 0xab, // DHCP server identifier
0x33, 0x04, 0x00, 0x00, 0x00, 0x78, // Lease time 2 minutes
0x03, 0x04, 0xc3, 0xaa, 0xbd, 0xab, // Router IP
0x01, 0x04, 0xff, 0xff, 0xff, 0x00, // Netmask
0xff, // End marker
0x63, 0x82, 0x53, 0x63, /* Magic cookie */
0x35, 0x01, 0x05, /* Dhcp message type ack */
0x36, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* DHCP server identifier */
0x33, 0x04, 0x00, 0x00, 0x00, 0x78, /* Lease time 2 minutes */
0x03, 0x04, 0xc3, 0xaa, 0xbd, 0xab, /* Router IP */
0x01, 0x04, 0xff, 0xff, 0xff, 0x00, /* Netmask */
0xff, /* End marker */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Padding
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Padding */
};
static const u8_t arpreply[] = {
0x00, 0x23, 0xC1, 0xDE, 0xD0, 0x0D, // dst mac
0x00, 0x32, 0x44, 0x20, 0x01, 0x02, // src mac
0x08, 0x06, // proto arp
0x00, 0x01, // hw eth
0x08, 0x00, // proto ip
0x06, // hw addr len 6
0x04, // proto addr len 4
0x00, 0x02, // arp reply
0x00, 0x32, 0x44, 0x20, 0x01, 0x02, // sender mac
0xc3, 0xaa, 0xbd, 0xc8, // sender ip
0x00, 0x23, 0xC1, 0xDE, 0xD0, 0x0D, // target mac
0x00, 0x00, 0x00, 0x00, // target ip
0x00, 0x23, 0xC1, 0xDE, 0xD0, 0x0D, /* dst mac */
0x00, 0x32, 0x44, 0x20, 0x01, 0x02, /* src mac */
0x08, 0x06, /* proto arp */
0x00, 0x01, /* hw eth */
0x08, 0x00, /* proto ip */
0x06, /* hw addr len 6 */
0x04, /* proto addr len 4 */
0x00, 0x02, /* arp reply */
0x00, 0x32, 0x44, 0x20, 0x01, 0x02, /* sender mac */
0xc3, 0xaa, 0xbd, 0xc8, /* sender ip */
0x00, 0x23, 0xC1, 0xDE, 0xD0, 0x0D, /* target mac */
0x00, 0x00, 0x00, 0x00, /* target ip */
};
static int txpacket;
@ -142,7 +142,7 @@ static void send_pkt(struct netif *netif, const u8_t *data, u32_t len)
struct pbuf *q;
if (debug) {
// Dump data
/* Dump data */
u32_t i;
printf("RX data (len %d)", p->tot_len);
for (i = 0; i < len; i++) {
@ -200,7 +200,7 @@ static void check_pkt(struct pbuf *p, u32_t pos, const u8_t *mem, u32_t len)
p = p->next;
}
fail_if(p == NULL);
fail_unless(pos + len <= p->len); // All data we seek within same pbuf
fail_unless(pos + len <= p->len); /* All data we seek within same pbuf */
data = p->payload;
fail_if(memcmp(&data[pos], mem, len), "data at pos %d, len %d in packet %d did not match", pos, len, txpacket);
@ -218,7 +218,7 @@ static void check_pkt_fuzzy(struct pbuf *p, u32_t startpos, const u8_t *mem, u32
p = p->next;
}
fail_if(p == NULL);
fail_unless(startpos + len <= p->len); // All data we seek within same pbuf
fail_unless(startpos + len <= p->len); /* All data we seek within same pbuf */
found = 0;
data = p->payload;
@ -238,7 +238,7 @@ static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
if (debug) {
struct pbuf *pp = p;
// Dump data
/* Dump data */
printf("TX data (pkt %d, len %d, tick %d)", txpacket, p->tot_len, tick);
do {
int i;
@ -259,29 +259,29 @@ static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
case 2:
{
const u8_t ipproto[] = { 0x08, 0x00 };
const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; // bootp request, eth, hwaddr len 6, 0 hops
const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; /* bootp request, eth, hwaddr len 6, 0 hops */
const u8_t ipaddrs[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
check_pkt(p, 0, broadcast, 6); // eth level dest: broadcast
check_pkt(p, 6, netif->hwaddr, 6); // eth level src: unit mac
check_pkt(p, 0, broadcast, 6); /* eth level dest: broadcast */
check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */
check_pkt(p, 12, ipproto, sizeof(ipproto)); // eth level proto: ip
check_pkt(p, 12, ipproto, sizeof(ipproto)); /* eth level proto: ip */
check_pkt(p, 42, bootp_start, sizeof(bootp_start));
check_pkt(p, 53, ipaddrs, sizeof(ipaddrs));
check_pkt(p, 70, netif->hwaddr, 6); // mac addr inside bootp
check_pkt(p, 70, netif->hwaddr, 6); /* mac addr inside bootp */
check_pkt(p, 278, magic_cookie, sizeof(magic_cookie));
// Check dchp message type, can be at different positions
/* Check dchp message type, can be at different positions */
if (txpacket == 1) {
u8_t dhcp_discover_opt[] = { 0x35, 0x01, 0x01 };
check_pkt_fuzzy(p, 282, dhcp_discover_opt, sizeof(dhcp_discover_opt));
} else if (txpacket == 2) {
u8_t dhcp_request_opt[] = { 0x35, 0x01, 0x03 };
u8_t requested_ipaddr[] = { 0x32, 0x04, 0xc3, 0xaa, 0xbd, 0xc8 }; // Ask for offered IP
u8_t requested_ipaddr[] = { 0x32, 0x04, 0xc3, 0xaa, 0xbd, 0xc8 }; /* Ask for offered IP */
check_pkt_fuzzy(p, 282, dhcp_request_opt, sizeof(dhcp_request_opt));
check_pkt_fuzzy(p, 282, requested_ipaddr, sizeof(requested_ipaddr));
@ -294,10 +294,10 @@ static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
{
const u8_t arpproto[] = { 0x08, 0x06 };
check_pkt(p, 0, broadcast, 6); // eth level dest: broadcast
check_pkt(p, 6, netif->hwaddr, 6); // eth level src: unit mac
check_pkt(p, 0, broadcast, 6); /* eth level dest: broadcast */
check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */
check_pkt(p, 12, arpproto, sizeof(arpproto)); // eth level proto: ip
check_pkt(p, 12, arpproto, sizeof(arpproto)); /* eth level proto: ip */
break;
}
}
@ -306,26 +306,26 @@ static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
case TEST_LWIP_DHCP_NAK:
{
const u8_t ipproto[] = { 0x08, 0x00 };
const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; // bootp request, eth, hwaddr len 6, 0 hops
const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; /* bootp request, eth, hwaddr len 6, 0 hops */
const u8_t ipaddrs[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
const u8_t dhcp_nak_opt[] = { 0x35, 0x01, 0x04 };
const u8_t requested_ipaddr[] = { 0x32, 0x04, 0xc3, 0xaa, 0xbd, 0xc8 }; // offered IP
const u8_t requested_ipaddr[] = { 0x32, 0x04, 0xc3, 0xaa, 0xbd, 0xc8 }; /* offered IP */
fail_unless(txpacket == 4);
check_pkt(p, 0, broadcast, 6); // eth level dest: broadcast
check_pkt(p, 6, netif->hwaddr, 6); // eth level src: unit mac
check_pkt(p, 0, broadcast, 6); /* eth level dest: broadcast */
check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */
check_pkt(p, 12, ipproto, sizeof(ipproto)); // eth level proto: ip
check_pkt(p, 12, ipproto, sizeof(ipproto)); /* eth level proto: ip */
check_pkt(p, 42, bootp_start, sizeof(bootp_start));
check_pkt(p, 53, ipaddrs, sizeof(ipaddrs));
check_pkt(p, 70, netif->hwaddr, 6); // mac addr inside bootp
check_pkt(p, 70, netif->hwaddr, 6); /* mac addr inside bootp */
check_pkt(p, 278, magic_cookie, sizeof(magic_cookie));
check_pkt_fuzzy(p, 282, dhcp_nak_opt, sizeof(dhcp_nak_opt)); // NAK the ack
check_pkt_fuzzy(p, 282, dhcp_nak_opt, sizeof(dhcp_nak_opt)); /* NAK the ack */
check_pkt_fuzzy(p, 282, requested_ipaddr, sizeof(requested_ipaddr));
break;
@ -337,29 +337,29 @@ static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
case 2:
{
const u8_t ipproto[] = { 0x08, 0x00 };
const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; // bootp request, eth, hwaddr len 6, 0 hops
const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; /* bootp request, eth, hwaddr len 6, 0 hops */
const u8_t ipaddrs[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
check_pkt(p, 0, broadcast, 6); // eth level dest: broadcast
check_pkt(p, 6, netif->hwaddr, 6); // eth level src: unit mac
check_pkt(p, 0, broadcast, 6); /* eth level dest: broadcast */
check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */
check_pkt(p, 12, ipproto, sizeof(ipproto)); // eth level proto: ip
check_pkt(p, 12, ipproto, sizeof(ipproto)); /* eth level proto: ip */
check_pkt(p, 42, bootp_start, sizeof(bootp_start));
check_pkt(p, 53, ipaddrs, sizeof(ipaddrs));
check_pkt(p, 70, netif->hwaddr, 6); // mac addr inside bootp
check_pkt(p, 70, netif->hwaddr, 6); /* mac addr inside bootp */
check_pkt(p, 278, magic_cookie, sizeof(magic_cookie));
// Check dchp message type, can be at different positions
/* Check dchp message type, can be at different positions */
if (txpacket == 1) {
u8_t dhcp_discover_opt[] = { 0x35, 0x01, 0x01 };
check_pkt_fuzzy(p, 282, dhcp_discover_opt, sizeof(dhcp_discover_opt));
} else if (txpacket == 2) {
u8_t dhcp_request_opt[] = { 0x35, 0x01, 0x03 };
u8_t requested_ipaddr[] = { 0x32, 0x04, 0x4f, 0x8a, 0x33, 0x05 }; // Ask for offered IP
u8_t requested_ipaddr[] = { 0x32, 0x04, 0x4f, 0x8a, 0x33, 0x05 }; /* Ask for offered IP */
check_pkt_fuzzy(p, 282, dhcp_request_opt, sizeof(dhcp_request_opt));
check_pkt_fuzzy(p, 282, requested_ipaddr, sizeof(requested_ipaddr));
@ -373,34 +373,34 @@ static err_t lwip_tx_func(struct netif *netif, struct pbuf *p)
{
const u8_t arpproto[] = { 0x08, 0x06 };
check_pkt(p, 0, broadcast, 6); // eth level dest: broadcast
check_pkt(p, 6, netif->hwaddr, 6); // eth level src: unit mac
check_pkt(p, 0, broadcast, 6); /* eth level dest: broadcast */
check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */
check_pkt(p, 12, arpproto, sizeof(arpproto)); // eth level proto: ip
check_pkt(p, 12, arpproto, sizeof(arpproto)); /* eth level proto: ip */
break;
}
case 7:
{
const u8_t fake_arp[6] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xab };
const u8_t ipproto[] = { 0x08, 0x00 };
const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; // bootp request, eth, hwaddr len 6, 0 hops
const u8_t bootp_start[] = { 0x01, 0x01, 0x06, 0x00}; /* bootp request, eth, hwaddr len 6, 0 hops */
const u8_t ipaddrs[] = { 0x00, 0x4f, 0x8a, 0x33, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
const u8_t dhcp_request_opt[] = { 0x35, 0x01, 0x03 };
check_pkt(p, 0, fake_arp, 6); // eth level dest: broadcast
check_pkt(p, 6, netif->hwaddr, 6); // eth level src: unit mac
check_pkt(p, 0, fake_arp, 6); /* eth level dest: broadcast */
check_pkt(p, 6, netif->hwaddr, 6); /* eth level src: unit mac */
check_pkt(p, 12, ipproto, sizeof(ipproto)); // eth level proto: ip
check_pkt(p, 12, ipproto, sizeof(ipproto)); /* eth level proto: ip */
check_pkt(p, 42, bootp_start, sizeof(bootp_start));
check_pkt(p, 53, ipaddrs, sizeof(ipaddrs));
check_pkt(p, 70, netif->hwaddr, 6); // mac addr inside bootp
check_pkt(p, 70, netif->hwaddr, 6); /* mac addr inside bootp */
check_pkt(p, 278, magic_cookie, sizeof(magic_cookie));
// Check dchp message type, can be at different positions
/* Check dchp message type, can be at different positions */
check_pkt_fuzzy(p, 282, dhcp_request_opt, sizeof(dhcp_request_opt));
break;
}
@ -438,43 +438,43 @@ START_TEST(test_dhcp)
dhcp_start(&net_test);
fail_unless(txpacket == 1); // DHCP discover sent
xid = net_test.dhcp->xid; // Write bad xid, not using htonl!
fail_unless(txpacket == 1); /* DHCP discover sent */
xid = net_test.dhcp->xid; /* Write bad xid, not using htonl! */
memcpy(&dhcp_offer[46], &xid, 4);
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
// Interface down
/* Interface down */
fail_if(netif_is_up(&net_test));
// IP addresses should be zero
/* IP addresses should be zero */
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr)));
fail_if(memcmp(&gw, &net_test.gw, sizeof(struct ip_addr)));
fail_unless(txpacket == 1, "TX %d packets, expected 1", txpacket); // Nothing more sent
fail_unless(txpacket == 1, "TX %d packets, expected 1", txpacket); /* Nothing more sent */
xid = htonl(net_test.dhcp->xid);
memcpy(&dhcp_offer[46], &xid, 4); // insert correct transaction id
memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
fail_unless(txpacket == 2, "TX %d packets, expected 2", txpacket); // DHCP request sent
xid = net_test.dhcp->xid; // Write bad xid, not using htonl!
fail_unless(txpacket == 2, "TX %d packets, expected 2", txpacket); /* DHCP request sent */
xid = net_test.dhcp->xid; /* Write bad xid, not using htonl! */
memcpy(&dhcp_ack[46], &xid, 4);
send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack));
fail_unless(txpacket == 2, "TX %d packets, still expected 2", txpacket); // No more sent
xid = htonl(net_test.dhcp->xid); // xid updated
memcpy(&dhcp_ack[46], &xid, 4); // insert transaction id
fail_unless(txpacket == 2, "TX %d packets, still expected 2", txpacket); /* No more sent */
xid = htonl(net_test.dhcp->xid); /* xid updated */
memcpy(&dhcp_ack[46], &xid, 4); /* insert transaction id */
send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack));
for (i = 0; i < 20; i++) {
tick_lwip();
}
fail_unless(txpacket == 4, "TX %d packets, expected 4", txpacket); // ARP requests sent
fail_unless(txpacket == 4, "TX %d packets, expected 4", txpacket); /* ARP requests sent */
// Interface up
/* Interface up */
fail_unless(netif_is_up(&net_test));
// Now it should have taken the IP
/* Now it should have taken the IP */
IP4_ADDR(&addr, 195, 170, 189, 200);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&gw, 195, 170, 189, 171);
@ -509,42 +509,42 @@ START_TEST(test_dhcp_nak)
dhcp_start(&net_test);
fail_unless(txpacket == 1); // DHCP discover sent
xid = net_test.dhcp->xid; // Write bad xid, not using htonl!
fail_unless(txpacket == 1); /* DHCP discover sent */
xid = net_test.dhcp->xid; /* Write bad xid, not using htonl! */
memcpy(&dhcp_offer[46], &xid, 4);
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
// Interface down
/* Interface down */
fail_if(netif_is_up(&net_test));
// IP addresses should be zero
/* IP addresses should be zero */
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr)));
fail_if(memcmp(&gw, &net_test.gw, sizeof(struct ip_addr)));
fail_unless(txpacket == 1); // Nothing more sent
fail_unless(txpacket == 1); /* Nothing more sent */
xid = htonl(net_test.dhcp->xid);
memcpy(&dhcp_offer[46], &xid, 4); // insert correct transaction id
memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
fail_unless(txpacket == 2); // DHCP request sent
xid = net_test.dhcp->xid; // Write bad xid, not using htonl!
fail_unless(txpacket == 2); /* DHCP request sent */
xid = net_test.dhcp->xid; /* Write bad xid, not using htonl! */
memcpy(&dhcp_ack[46], &xid, 4);
send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack));
fail_unless(txpacket == 2); // No more sent
xid = htonl(net_test.dhcp->xid); // xid updated
memcpy(&dhcp_ack[46], &xid, 4); // insert transaction id
fail_unless(txpacket == 2); /* No more sent */
xid = htonl(net_test.dhcp->xid); /* xid updated */
memcpy(&dhcp_ack[46], &xid, 4); /* insert transaction id */
send_pkt(&net_test, dhcp_ack, sizeof(dhcp_ack));
fail_unless(txpacket == 3); // ARP request sent
fail_unless(txpacket == 3); /* ARP request sent */
tcase = TEST_LWIP_DHCP_NAK; // Switch testcase
tcase = TEST_LWIP_DHCP_NAK; /* Switch testcase */
// Send arp reply, mark offered IP as taken
/* Send arp reply, mark offered IP as taken */
send_pkt(&net_test, arpreply, sizeof(arpreply));
fail_unless(txpacket == 4); // DHCP nak sent
fail_unless(txpacket == 4); /* DHCP nak sent */
netif_remove(&net_test);
}
@ -691,22 +691,22 @@ START_TEST(test_dhcp_relayed)
0x04, 0x0a, 0xb5, 0x04, 0x01, 0xff };
const u8_t arp_resp[] = {
0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, // DEST
0x00, 0x22, 0x93, 0x5a, 0xf7, 0x60, // SRC
0x08, 0x06, // Type: ARP
0x00, 0x01, // HW: Ethernet
0x08, 0x00, // PROTO: IP
0x06, // HW size
0x04, // PROTO size
0x00, 0x02, // OPCODE: Reply
0x00, 0x23, 0xc1, 0xde, 0xd0, 0x0d, /* DEST */
0x00, 0x22, 0x93, 0x5a, 0xf7, 0x60, /* SRC */
0x08, 0x06, /* Type: ARP */
0x00, 0x01, /* HW: Ethernet */
0x08, 0x00, /* PROTO: IP */
0x06, /* HW size */
0x04, /* PROTO size */
0x00, 0x02, /* OPCODE: Reply */
0x12, 0x34, 0x56, 0x78, 0x9a, 0xab, // Target MAC
0x4f, 0x8a, 0x32, 0x01, // Target IP
0x12, 0x34, 0x56, 0x78, 0x9a, 0xab, /* Target MAC */
0x4f, 0x8a, 0x32, 0x01, /* Target IP */
0x00, 0x23, 0xc1, 0x00, 0x06, 0x50, // src mac
0x4f, 0x8a, 0x33, 0x05, // src ip
0x00, 0x23, 0xc1, 0x00, 0x06, 0x50, /* src mac */
0x4f, 0x8a, 0x33, 0x05, /* src ip */
// Padding follows..
/* Padding follows.. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
@ -729,36 +729,36 @@ START_TEST(test_dhcp_relayed)
dhcp_start(&net_test);
fail_unless(txpacket == 1); // DHCP discover sent
fail_unless(txpacket == 1); /* DHCP discover sent */
// Interface down
/* Interface down */
fail_if(netif_is_up(&net_test));
// IP addresses should be zero
/* IP addresses should be zero */
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr)));
fail_if(memcmp(&gw, &net_test.gw, sizeof(struct ip_addr)));
fail_unless(txpacket == 1); // Nothing more sent
fail_unless(txpacket == 1); /* Nothing more sent */
xid = htonl(net_test.dhcp->xid);
memcpy(&relay_offer[46], &xid, 4); // insert correct transaction id
memcpy(&relay_offer[46], &xid, 4); /* insert correct transaction id */
send_pkt(&net_test, relay_offer, sizeof(relay_offer));
// request sent?
/* request sent? */
fail_unless(txpacket == 2, "txpkt = %d, should be 2", txpacket);
xid = htonl(net_test.dhcp->xid); // xid updated
memcpy(&relay_ack1[46], &xid, 4); // insert transaction id
xid = htonl(net_test.dhcp->xid); /* xid updated */
memcpy(&relay_ack1[46], &xid, 4); /* insert transaction id */
send_pkt(&net_test, relay_ack1, sizeof(relay_ack1));
for (i = 0; i < 25; i++) {
tick_lwip();
}
fail_unless(txpacket == 4, "txpkt should be 5, is %d", txpacket); // ARP requests sent
fail_unless(txpacket == 4, "txpkt should be 5, is %d", txpacket); /* ARP requests sent */
// Interface up
/* Interface up */
fail_unless(netif_is_up(&net_test));
// Now it should have taken the IP
/* Now it should have taken the IP */
IP4_ADDR(&addr, 79, 138, 51, 5);
IP4_ADDR(&netmask, 255, 255, 254, 0);
IP4_ADDR(&gw, 79, 138, 50, 1);
@ -775,15 +775,15 @@ START_TEST(test_dhcp_relayed)
fail_unless(netif_is_up(&net_test));
fail_unless(txpacket == 6, "txpacket = %d", txpacket);
// We need to send arp response here..
/* We need to send arp response here.. */
send_pkt(&net_test, arp_resp, sizeof(arp_resp));
fail_unless(txpacket == 7, "txpacket = %d", txpacket);
fail_unless(netif_is_up(&net_test));
xid = htonl(net_test.dhcp->xid); // xid updated
memcpy(&relay_ack2[46], &xid, 4); // insert transaction id
xid = htonl(net_test.dhcp->xid); /* xid updated */
memcpy(&relay_ack2[46], &xid, 4); /* insert transaction id */
send_pkt(&net_test, relay_ack2, sizeof(relay_ack2));
for (i = 0; i < 100000; i++) {
@ -855,6 +855,8 @@ START_TEST(test_dhcp_nak_no_endmarker)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
u32_t xid;
LWIP_UNUSED_ARG(_i);
tcase = TEST_LWIP_DHCP_NAK_NO_ENDMARKER;
setdebug(0);
@ -867,32 +869,32 @@ START_TEST(test_dhcp_nak_no_endmarker)
dhcp_start(&net_test);
fail_unless(txpacket == 1); // DHCP discover sent
u32_t xid = net_test.dhcp->xid; // Write bad xid, not using htonl!
fail_unless(txpacket == 1); /* DHCP discover sent */
xid = net_test.dhcp->xid; /* Write bad xid, not using htonl! */
memcpy(&dhcp_offer[46], &xid, 4);
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
// Interface down
/* Interface down */
fail_if(netif_is_up(&net_test));
// IP addresses should be zero
/* IP addresses should be zero */
fail_if(memcmp(&addr, &net_test.ip_addr, sizeof(struct ip_addr)));
fail_if(memcmp(&netmask, &net_test.netmask, sizeof(struct ip_addr)));
fail_if(memcmp(&gw, &net_test.gw, sizeof(struct ip_addr)));
fail_unless(txpacket == 1); // Nothing more sent
fail_unless(txpacket == 1); /* Nothing more sent */
xid = htonl(net_test.dhcp->xid);
memcpy(&dhcp_offer[46], &xid, 4); // insert correct transaction id
memcpy(&dhcp_offer[46], &xid, 4); /* insert correct transaction id */
send_pkt(&net_test, dhcp_offer, sizeof(dhcp_offer));
fail_unless(net_test.dhcp->state == DHCP_REQUESTING);
fail_unless(txpacket == 2); // No more sent
xid = htonl(net_test.dhcp->xid); // xid updated
memcpy(&dhcp_nack_no_endmarker[46], &xid, 4); // insert transaction id
fail_unless(txpacket == 2); /* No more sent */
xid = htonl(net_test.dhcp->xid); /* xid updated */
memcpy(&dhcp_nack_no_endmarker[46], &xid, 4); /* insert transaction id */
send_pkt(&net_test, dhcp_nack_no_endmarker, sizeof(dhcp_nack_no_endmarker));
// NAK should put us in another state for a while, no other way detecting it
/* NAK should put us in another state for a while, no other way detecting it */
fail_unless(net_test.dhcp->state != DHCP_REQUESTING);
netif_remove(&net_test);