From 105aa81d1ff989366e31a631b8e25a78566f88d1 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 31 Oct 2007 00:13:07 +0000 Subject: [PATCH] dhcpc debug git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@357 42af7a65-404d-4744-a932-0658087f49c3 --- arch/sim/src/up_internal.h | 2 +- arch/sim/src/up_tapdev.c | 73 +++++++++++++++++++++---------- arch/sim/src/up_uipdriver.c | 87 ++++++++++++++++++++++++++----------- examples/uip/main.c | 4 +- include/net/uip/uip.h | 67 ++++++++++++++++++---------- net/connect.c | 2 +- net/recvfrom.c | 2 +- net/uip/uip-arp.c | 6 +-- net/uip/uip-udpconn.c | 81 ++++++++++++++++++++++++---------- net/uip/uip.c | 40 ++++++++--------- 10 files changed, 242 insertions(+), 122 deletions(-) diff --git a/arch/sim/src/up_internal.h b/arch/sim/src/up_internal.h index 1d08f83817..42b368d671 100644 --- a/arch/sim/src/up_internal.h +++ b/arch/sim/src/up_internal.h @@ -113,7 +113,7 @@ extern char *up_deviceimage(void); extern unsigned long up_getwalltime( void ); extern void tapdev_init(void); extern unsigned int tapdev_read(unsigned char *buf, unsigned int buflen); -extern void tapdev_send(char *buf, unsigned int buflen); +extern void tapdev_send(unsigned char *buf, unsigned int buflen); #endif /* up_uipdriver.c *********************************************************/ diff --git a/arch/sim/src/up_tapdev.c b/arch/sim/src/up_tapdev.c index bf9d9db81a..1961cfbaea 100644 --- a/arch/sim/src/up_tapdev.c +++ b/arch/sim/src/up_tapdev.c @@ -85,6 +85,17 @@ extern int lib_rawprintf(const char *format, ...); * Private Types ****************************************************************************/ +/* Warning: This is very much Linux version specific! */ + +struct sel_arg_struct +{ + unsigned long n; + fd_set *inp; + fd_set *outp; + fd_set *exp; + struct timeval *tvp; +}; + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -156,19 +167,35 @@ static inline int up_ioctl(int fd, unsigned int cmd, unsigned long arg) return (int)result; } -static inline int up_select(int n, fd_set *inp, fd_set *outp, fd_set *exp, struct timeval *tvp) +static inline int up_select(struct sel_arg_struct *arg) { ssize_t result; __asm__ volatile ("int $0x80" \ : "=a" (result) \ - : "0" (SELECT),"b" ((long)(n)),"c" ((long)(inp)), \ - "d" ((long)(outp)),"S" ((long)(exp)), "D"((long)tvp) \ + : "0" (SELECT),"b" ((struct sel_arg_struct *)(arg)) : "memory"); return (int)result; } +#ifdef TAPDEV_DEBUG +static inline void dump_ethhdr(const char *msg, unsigned char *buf, int buflen) +{ + lib_rawprintf("TAPDEV: %s %d bytes\n", msg, buflen); + lib_rawprintf(" %02x:%02x:%02x:%02x:%02x:%02x %02x:%02x:%02x:%02x:%02x:%02x %02x%02x\n", + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], + buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], +#if UIP_BYTE_ORDER == UIP_LITTLE_ENDIAN + buf[12], buf[13]); +#else + buf[13], buf[12]); +#endif +} +#else +# define dump_ethhdr(m,b,l) +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -197,7 +224,7 @@ void tapdev_init(void) struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP|IFF_NO_PI; - ret = up_ioctl(gtapdevfd, TUNSETIFF, (unsigned long *) &ifr); + ret = up_ioctl(gtapdevfd, TUNSETIFF, (unsigned long) &ifr); if (ret < 0) { lib_rawprintf("TAPDEV: ioctl failed: %d\n", -ret ); @@ -213,23 +240,33 @@ void tapdev_init(void) unsigned int tapdev_read(unsigned char *buf, unsigned int buflen) { - fd_set fdset; - struct timeval tv; - int ret; + struct sel_arg_struct arg; + fd_set fdset; + struct timeval tv; + int ret; /* We can't do anything if we failed to open the tap device */ + if (gtapdevfd < 0) { return 0; } - tv.tv_sec = 0; + /* Wait for data on the tap device (or a timeout) */ + + tv.tv_sec = 0; tv.tv_usec = 1000; FD_ZERO(&fdset); FD_SET(gtapdevfd, &fdset); - ret = up_select(gtapdevfd + 1, &fdset, NULL, NULL, &tv); + arg.n = gtapdevfd + 1; + arg.inp = &fdset; + arg.outp = NULL; + arg.exp = NULL; + arg.tvp = &tv; + + ret = up_select(&arg); if(ret == 0) { return 0; @@ -242,22 +279,11 @@ unsigned int tapdev_read(unsigned char *buf, unsigned int buflen) return 0; } -#ifdef TAPDEV_DEBUG - lib_rawprintf("TAPDEV: read %d bytes\n", ret); - { - int i; - for(i = 0; i < 20; i++) - { - lib_rawprintf("%02x ", buf[i]); - } - lib_rawprintf("\n"); - } -#endif - + dump_ethhdr("read", buf, ret); return ret; } -void tapdev_send(char *buf, unsigned int buflen) +void tapdev_send(unsigned char *buf, unsigned int buflen) { int ret; #ifdef TAPDEV_DEBUG @@ -274,9 +300,10 @@ void tapdev_send(char *buf, unsigned int buflen) ret = up_write(gtapdevfd, buf, buflen); if (ret < 0) { - lib_rawprintf("TAPDEV: write"); + lib_rawprintf("TAPDEV: write failed: %d", -ret); exit(1); } + dump_ethhdr("write", buf, buflen); } #endif /* linux */ diff --git a/arch/sim/src/up_uipdriver.c b/arch/sim/src/up_uipdriver.c index b49e772e01..a3f641a36f 100644 --- a/arch/sim/src/up_uipdriver.c +++ b/arch/sim/src/up_uipdriver.c @@ -46,6 +46,8 @@ #include #include +#include +#include #include #include @@ -102,6 +104,15 @@ void timer_reset(struct timer *t) t->start += t->interval; } +#ifdef CONFIG_NET_PROMISCUOUS +# define uipdriver_comparemac(a,b) (0) +#else +static inline int uip_comparemac(struct uip_eth_addr *paddr1, struct uip_eth_addr *paddr2) +{ + return memcmp(paddr1, paddr2, sizeof(struct uip_eth_addr)); +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -110,40 +121,65 @@ void uipdriver_loop(void) { int i; + /* tapdev_read will return 0 on a timeout event and >0 on a data received event */ + g_sim_dev.d_len = tapdev_read((unsigned char*)g_sim_dev.d_buf, UIP_BUFSIZE); + + /* Disable preemption through to the following so that it behaves a little more + * like an interrupt (otherwise, the following logic gets pre-empted an behaves + * oddly. + */ + + sched_lock(); if (g_sim_dev.d_len > 0) { - if (BUF->type == htons(UIP_ETHTYPE_IP)) + /* Data received event. Check for valid Ethernet header with destination == our + * MAC address + */ + + if (g_sim_dev.d_len > UIP_LLH_LEN && uip_comparemac( &BUF->dest, &g_sim_dev.d_mac) == 0) { - uip_arp_ipin(); - uip_input(&g_sim_dev); + /* We only accept IP packets of the configured type and ARP packets */ - /* If the above function invocation resulted in data that - * should be sent out on the network, the global variable - * d_len is set to a value > 0. - */ - - if (g_sim_dev.d_len > 0) +#ifdef CONFIG_NET_IPv6 + if (BUF->type == htons(UIP_ETHTYPE_IP6)) +#else + if (BUF->type == htons(UIP_ETHTYPE_IP)) +#endif { - uip_arp_out(&g_sim_dev); - tapdev_send((char*)g_sim_dev.d_buf, g_sim_dev.d_len); + uip_arp_ipin(); + uip_input(&g_sim_dev); + + /* If the above function invocation resulted in data that + * should be sent out on the network, the global variable + * d_len is set to a value > 0. + */ + + if (g_sim_dev.d_len > 0) + { + uip_arp_out(&g_sim_dev); + tapdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); + } } - } - else if (BUF->type == htons(UIP_ETHTYPE_ARP)) - { - uip_arp_arpin(&g_sim_dev); - - /* If the above function invocation resulted in data that - * should be sent out on the network, the global variable - * d_len is set to a value > 0. - */ - - if (g_sim_dev.d_len > 0) + else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { - tapdev_send((char*)g_sim_dev.d_buf, g_sim_dev.d_len); + uip_arp_arpin(&g_sim_dev); + + /* If the above function invocation resulted in data that + * should be sent out on the network, the global variable + * d_len is set to a value > 0. + */ + + if (g_sim_dev.d_len > 0) + { + tapdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); + } } } } + + /* Otherwise, it must be a timeout event */ + else if (timer_expired(&g_periodic_timer)) { timer_reset(&g_periodic_timer); @@ -159,7 +195,7 @@ void uipdriver_loop(void) if (g_sim_dev.d_len > 0) { uip_arp_out(&g_sim_dev); - tapdev_send((char*)g_sim_dev.d_buf, g_sim_dev.d_len); + tapdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } } @@ -176,7 +212,7 @@ void uipdriver_loop(void) if (g_sim_dev.d_len > 0) { uip_arp_out(&g_sim_dev); - tapdev_send((char*)g_sim_dev.d_buf, g_sim_dev.d_len); + tapdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } } #endif /* CONFIG_NET_UDP */ @@ -189,6 +225,7 @@ void uipdriver_loop(void) uip_arp_timer(); } } + sched_unlock(); } int uipdriver_init(void) diff --git a/examples/uip/main.c b/examples/uip/main.c index 9cddb0ab98..f71a9a6dc5 100644 --- a/examples/uip/main.c +++ b/examples/uip/main.c @@ -57,7 +57,7 @@ * our project as defined in the config//defconfig file */ -#define CONFIG_EXAMPLE_UIP_WEBSERVER 1 /* For now */ +#define CONFIG_EXAMPLE_UIP_DHCPC 1 /* For now */ #if defined(CONFIG_EXAMPLE_UIP_SMTP) # include @@ -135,6 +135,7 @@ int user_start(int argc, char *argv[]) uip_getmacaddr("eth0", mac); #endif +#if !defined(CONFIG_EXAMPLE_UIP_DHCPC) /* Set up our host address */ uip_ipaddr(addr.s_addr, 192, 168, 0, 128 ); @@ -149,6 +150,7 @@ int user_start(int argc, char *argv[]) uip_ipaddr(addr.s_addr, 255, 255, 255, 0); uip_setnetmask("eth0", &addr); +#endif #if defined(CONFIG_EXAMPLE_UIP_WEBSERVER) httpd_init(); diff --git a/include/net/uip/uip.h b/include/net/uip/uip.h index dfc0bf337d..3b2c90299c 100644 --- a/include/net/uip/uip.h +++ b/include/net/uip/uip.h @@ -121,7 +121,7 @@ #define UIP_PROTO_UDP 17 #define UIP_PROTO_ICMP6 58 -/* Header sizes. */ +/* Header sizes */ #ifdef CONFIG_NET_IPv6 # define UIP_IPH_LEN 40 @@ -302,8 +302,8 @@ struct uip_tcpip_hdr uint8 ttl; uint8 proto; uint16 ipchksum; - in_addr_t srcipaddr; - in_addr_t destipaddr; + uint16 srcipaddr[2]; + uint16 destipaddr[2]; #endif /* CONFIG_NET_IPv6 */ @@ -350,8 +350,8 @@ struct uip_icmpip_hdr uint8 ttl; uint8 proto; uint16 ipchksum; - in_addr_t srcipaddr; - in_addr_t destipaddr; + uint16 srcipaddr[2]; + uint16 destipaddr[2]; #endif /* CONFIG_NET_IPv6 */ @@ -406,8 +406,8 @@ struct uip_udpip_hdr uint8 ttl; uint8 proto; uint16 ipchksum; - in_addr_t srcipaddr; - in_addr_t destipaddr; + uint16 srcipaddr[2]; + uint16 destipaddr[2]; #endif /* CONFIG_NET_IPv6 */ @@ -833,20 +833,28 @@ extern void uip_udpdisable(struct uip_udp_conn *conn); addr = HTONL((addr0) << 24 | (addr1) << 16 | (addr2) << 8 | (addr3)); \ } while(0) +/* Convert an IPv4 address of the form uint16[2] to an in_addr_t */ + +#ifdef CONFIG_ENDIAN_BIG +# define uip_ip4addr_conv(addr) (((in_addr_t)((uint16*)addr)[1] << 16) | (in_addr_t)((uint16*)addr)[0]) +#else +# define uip_ip4addr_conv(addr) (((in_addr_t)((uint16*)addr)[0] << 16) | (in_addr_t)((uint16*)addr)[1]) +#endif + /* Construct an IPv6 address from eight 16-bit words. * * This function constructs an IPv6 address. */ #define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \ - ((uint16 *)(addr))[0] = HTONS((addr0)); \ - ((uint16 *)(addr))[1] = HTONS((addr1)); \ - ((uint16 *)(addr))[2] = HTONS((addr2)); \ - ((uint16 *)(addr))[3] = HTONS((addr3)); \ - ((uint16 *)(addr))[4] = HTONS((addr4)); \ - ((uint16 *)(addr))[5] = HTONS((addr5)); \ - ((uint16 *)(addr))[6] = HTONS((addr6)); \ - ((uint16 *)(addr))[7] = HTONS((addr7)); \ + ((uint16*)(addr))[0] = HTONS((addr0)); \ + ((uint16*)(addr))[1] = HTONS((addr1)); \ + ((uint16*)(addr))[2] = HTONS((addr2)); \ + ((uint16*)(addr))[3] = HTONS((addr3)); \ + ((uint16*)(addr))[4] = HTONS((addr4)); \ + ((uint16*)(addr))[5] = HTONS((addr5)); \ + ((uint16*)(addr))[6] = HTONS((addr6)); \ + ((uint16*)(addr))[7] = HTONS((addr7)); \ } while(0) /* Copy an IP address to another IP address. @@ -865,12 +873,18 @@ extern void uip_udpdisable(struct uip_udp_conn *conn); */ #ifndef CONFIG_NET_IPv6 -#define uip_ipaddr_copy(dest, src) \ - do { \ - (dest) = (in_addr_t)(src); \ - } while(0) +# define uip_ipaddr_copy(dest, src) \ + do { \ + (dest) = (in_addr_t)(src); \ + } while(0) +# define uiphdr_ipaddr_copy(dest, src) \ + do { \ + ((uint16*)(dest))[0] = ((uint16*)(src))[0]; \ + ((uint16*)(dest))[1] = ((uint16*)(src))[1]; \ + } while(0) #else /* !CONFIG_NET_IPv6 */ -#define uip_ipaddr_copy(dest, src) memcpy(&dest, &src, sizeof(uip_ip6addr_t)) +# define uip_ipaddr_copy(dest, src) memcpy(&dest, &src, sizeof(uip_ip6addr_t)) +# define uiphdr_ipaddr_copy(dest, src) uip_ipaddr_copy(dest, src) #endif /* !CONFIG_NET_IPv6 */ /* Compare two IP addresses @@ -889,9 +903,11 @@ extern void uip_udpdisable(struct uip_udp_conn *conn); */ #ifndef CONFIG_NET_IPv6 -# define uip_ipaddr_cmp(addr1, addr2) (addr1 == addr2) +# define uip_ipaddr_cmp(addr1, addr2) (addr1 == addr2) +# define uiphdr_ipaddr_cmp(addr1, addr2) uip_ipaddr_cmp(uip_ip4addr_conv(addr1), uip_ip4addr_conv(addr2)) #else /* !CONFIG_NET_IPv6 */ -# define uip_ipaddr_cmp(addr1, addr2) (memcmp(&addr1, &addr2, sizeof(uip_ip6addr_t)) == 0) +# define uip_ipaddr_cmp(addr1, addr2) (memcmp(&addr1, &addr2, sizeof(uip_ip6addr_t)) == 0) +# define uiphdr_ipaddr_cmp(addr1, addr2) uip_ipaddr_cmp(addr, addr2) #endif /* !CONFIG_NET_IPv6 */ /* Compare two IP addresses with netmasks @@ -915,8 +931,11 @@ extern void uip_udpdisable(struct uip_udp_conn *conn); * mask The netmask. */ -#define uip_ipaddr_maskcmp(addr1, addr2, mask) \ - (((in_addr_t)addr1 & (in_addr_t)mask) == ((in_addr_t)addr2 & (in_addr_t)mask)) +#ifndef CONFIG_NET_IPv6 +# define uip_ipaddr_maskcmp(addr1, addr2, mask) \ + ((uip_ip4addr_conv(addr1) & (in_addr_t)mask) == ((in_addr_t)addr2 & (in_addr_t)mask)) +#else /* !CONFIG_NET_IPv6 */ +#endif /* !CONFIG_NET_IPv6 */ /* Mask out the network part of an IP address. * diff --git a/net/connect.c b/net/connect.c index 786a0e4e71..579972d994 100644 --- a/net/connect.c +++ b/net/connect.c @@ -217,7 +217,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) /* Get the connection reference from the socket */ conn = psock->s_conn; - if (conn) /* Should alwasy be non-NULL */ + if (conn) /* Should always be non-NULL */ { /* Perform the uIP connection operation */ diff --git a/net/recvfrom.c b/net/recvfrom.c index 8548924ec0..c13ada6e6d 100644 --- a/net/recvfrom.c +++ b/net/recvfrom.c @@ -516,7 +516,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, if (_SS_ISCONNECTED(psock->s_flags)) { - /* The SOCK_STREAM must be connect in order to recive */ + /* The SOCK_STREAM must be connected in order to receive */ return -ENOTCONN; } diff --git a/net/uip/uip-arp.c b/net/uip/uip-arp.c index 90ff6047e1..87e48a6099 100644 --- a/net/uip/uip-arp.c +++ b/net/uip/uip-arp.c @@ -74,8 +74,8 @@ struct ethip_hdr uint8 ttl; uint8 proto; uint16 ipchksum; - in_addr_t srcipaddr; - in_addr_t destipaddr; + uint16 srcipaddr[2]; + uint16 destipaddr[2]; }; #define ARP_REQUEST 1 @@ -352,7 +352,7 @@ void uip_arp_out(struct uip_driver_s *dev) /* First check if destination is a local broadcast. */ - if (uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr)) + if (uiphdr_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr)) { memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, IFHWADDRLEN); } diff --git a/net/uip/uip-udpconn.c b/net/uip/uip-udpconn.c index 329852499a..e1cb174187 100644 --- a/net/uip/uip-udpconn.c +++ b/net/uip/uip-udpconn.c @@ -118,16 +118,15 @@ static inline void _uip_semtake(sem_t *sem) * ****************************************************************************/ -static inline struct uip_udp_conn *uip_find_conn( uint16 portno ) +static struct uip_udp_conn *uip_find_conn( uint16 portno ) { - uint16 nlastport = htons(g_last_udp_port); int i; /* Now search each connection structure.*/ for (i = 0; i < UIP_UDP_CONNS; i++) { - if (g_udp_connections[ i ].lport == nlastport) + if (g_udp_connections[ i ].lport == portno) { return &g_udp_connections[ i ]; } @@ -288,6 +287,35 @@ void uip_udppoll(struct uip_driver_s *dev, unsigned int conn) uip_interrupt(dev, UIP_UDP_TIMER); } +/**************************************************************************** + * Name: uip_udpbind() + * + * Description: + * This function implements the UIP specific parts of the standard UDP + * bind() operation. + * + * Assumptions: + * This function is called from normal user level code. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IPv6 +int uip_udpbind(struct uip_udp_conn *conn, const struct sockaddr_in6 *addr) +#else +int uip_udpbind(struct uip_udp_conn *conn, const struct sockaddr_in *addr) +#endif +{ + int ret = -EADDRINUSE; + irqstate_t flags = irqsave(); + if (!uip_find_conn(g_last_udp_port)) + { + conn->lport = HTONS(g_last_udp_port); + ret = OK; + } + irqrestore(flags); + return ret; +} + /**************************************************************************** * Name: uip_udpconnect() * @@ -314,33 +342,39 @@ int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in6 *addr) int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in *addr) #endif { - irqstate_t flags; + /* Has this structure already been bound to a local port? */ - /* Find an unused local port number. Loop until we find a valid listen port - * number that is not being used by any other connection. - */ - - flags = irqsave(); - do + if (!conn->lport) { - /* Guess that the next available port number will be the one after - * the last port number assigned. + /* No..Find an unused local port number. Loop until we find a valid + * listen port number that is not being used by any other connection. */ - ++g_last_udp_port; - - /* Make sure that the port number is within range */ - if (g_last_udp_port >= 32000) + irqstate_t flags = irqsave(); + do { - g_last_udp_port = 4096; + /* Guess that the next available port number will be the one after + * the last port number assigned. + */ + + ++g_last_udp_port; + + /* Make sure that the port number is within range */ + + if (g_last_udp_port >= 32000) + { + g_last_udp_port = 4096; + } } + while (uip_find_conn(g_last_udp_port)); + + /* Initialize and return the connection structure, bind it to the + * port number + */ + + conn->lport = HTONS(g_last_udp_port); + irqrestore(flags); } - while (uip_find_conn(g_last_udp_port)); - - /* Initialize and return the connection structure, bind it to the port number */ - - conn->lport = HTONS(g_last_udp_port); - irqrestore(flags); if (addr) { @@ -352,6 +386,7 @@ int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in *addr) conn->rport = 0; uip_ipaddr_copy(conn->ripaddr, all_zeroes_addr); } + conn->ttl = UIP_TTL; return OK; } diff --git a/net/uip/uip.c b/net/uip/uip.c index 3c8e8001e4..2791400671 100644 --- a/net/uip/uip.c +++ b/net/uip/uip.c @@ -340,7 +340,7 @@ uint16 uip_ipchksum(struct uip_driver_s *dev) uint16 sum; sum = chksum(0, &dev->d_buf[UIP_LLH_LEN], UIP_IPH_LEN); - dbg("uip_ipchksum: sum 0x%04x\n", sum); + dbg("Checksum 0x%04x\n", sum); return (sum == 0) ? 0xffff : htons(sum); } #endif @@ -420,8 +420,8 @@ static uint8 uip_reass(void) * fragment into the buffer. */ - if (uip_addr_cmp(BUF->srcipaddr, FBUF->srcipaddr) && - uip_addr_cmp(BUF->destipaddr == FBUF->destipaddr) && + if (uiphdr_addr_cmp(BUF->srcipaddr, FBUF->srcipaddr) && + uiphdr_addr_cmp(BUF->destipaddr == FBUF->destipaddr) && BUF->ipid[0] == FBUF->ipid[0] && BUF->ipid[1] == FBUF->ipid[1]) { len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4; @@ -871,7 +871,7 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag) /* Check if the packet is destined for our IP address. */ #ifndef CONFIG_NET_IPv6 - if (!uip_ipaddr_cmp(BUF->destipaddr, dev->d_ipaddr)) + if (!uip_ipaddr_cmp(uip_ip4addr_conv(BUF->destipaddr), dev->d_ipaddr)) { UIP_STAT(++uip_stat.ip.drop); goto drop; @@ -970,8 +970,8 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag) /* Swap IP addresses. */ - uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr); - uip_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr); + uiphdr_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr); + uiphdr_ipaddr_copy(BUF->srcipaddr, &dev->d_ipaddr); UIP_STAT(++uip_stat.icmp.sent); goto send; @@ -980,7 +980,7 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag) #else /* !CONFIG_NET_IPv6 */ /* This is IPv6 ICMPv6 processing code. */ - dbg("icmp6_input: length %d\n", dev->d_len); + dbg("ICMP6 input length %d\n", dev->d_len); if (BUF->proto != UIP_PROTO_ICMP6) { @@ -1003,7 +1003,7 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag) if (ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) { /* Save the sender's address in our neighbor list. */ - uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2])); + uiphdr_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2])); } /* We should now send a neighbor advertisement back to where the @@ -1013,8 +1013,8 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag) ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0; - uip_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr); - uip_ipaddr_copy(ICMPBUF->srcipaddr, dev->d_ipaddr); + uiphdr_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr); + uiphdr_ipaddr_copy(ICMPBUF->srcipaddr, dev->d_ipaddr); ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS; ICMPBUF->options[1] = 1; /* Options length, 1 = 8 bytes. */ memcpy(&(ICMPBUF->options[2]), &dev->d_mac, IFHWADDRLEN); @@ -1032,8 +1032,8 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag) ICMPBUF->type = ICMP6_ECHO_REPLY; - uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr); - uip_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr); + uiphdr_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr); + uiphdr_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr); ICMPBUF->icmpchksum = 0; ICMPBUF->icmpchksum = ~uip_icmp6chksum(dev); @@ -1042,7 +1042,7 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag) } else { - dbg("Unknown icmp6 message type %d\n", ICMPBUF->type); + dbg("Unknown ICMP6 message: %d\n", ICMPBUF->type); UIP_STAT(++uip_stat.icmp.drop); UIP_STAT(++uip_stat.icmp.typeerr); UIP_LOG("icmp: unknown ICMP message."); @@ -1118,8 +1118,8 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag) BUF->srcport = uip_udp_conn->lport; BUF->destport = uip_udp_conn->rport; - uip_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr); - uip_ipaddr_copy(BUF->destipaddr, uip_udp_conn->ripaddr); + uiphdr_ipaddr_copy(BUF->srcipaddr, &dev->d_ipaddr); + uiphdr_ipaddr_copy(BUF->destipaddr, &uip_udp_conn->ripaddr); dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN]; @@ -1231,8 +1231,8 @@ void uip_interrupt(struct uip_driver_s *dev, uint8 flag) BUF->destport = tmp16; /* Swap IP addresses. */ - uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr); - uip_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr); + uiphdr_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr); + uiphdr_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr); /* And send out the RST packet! */ goto tcp_send_noconn; @@ -1850,8 +1850,8 @@ tcp_send_synack: BUF->srcport = uip_connr->lport; BUF->destport = uip_connr->rport; - uip_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr); - uip_ipaddr_copy(BUF->destipaddr, uip_connr->ripaddr); + uiphdr_ipaddr_copy(BUF->srcipaddr, &dev->d_ipaddr); + uiphdr_ipaddr_copy(BUF->destipaddr, &uip_connr->ripaddr); if (uip_connr->tcpstateflags & UIP_STOPPED) { @@ -1902,7 +1902,7 @@ tcp_send_synack: /* Calculate IP checksum. */ BUF->ipchksum = 0; BUF->ipchksum = ~(uip_ipchksum(dev)); - dbg("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum(dev)); + dbg("ip_send_nolen checksum: 0x%04x\n", uip_ipchksum(dev)); #endif /* CONFIG_NET_IPv6 */ UIP_STAT(++uip_stat.tcp.sent);