lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [lwip-devel] byte order, packing, optimizations


From: Stéphane Lesage
Subject: RE: [lwip-devel] byte order, packing, optimizations
Date: Sat, 13 Feb 2010 16:41:01 +0100
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)


Here are some patches:

ip_addr.patch:
- some minor optimizations in ip_addr.h
- rename ip_addr_set to ip_addr_set_safe
- new ip_addr_copy used when possible
- change ip_addr_is_broadcast to a more efficient macro
- optimization in dns.c to use SMEMCPY, and change ntoh(x)==constant to direct comparison x==hton(constant)

<cid:part1.04070907.05070206@free.fr>warnings.patch:
def.c:
#warning LWIP_PLATFORM_BYTESWAP not defined, using defaults for htons,htonl,ntohs,ntohl
inet_chksum.c:
# warning LWIP_CHKSUM and LWIP_CHKSUM_ALGORITHM not defined, using default algorithm 2
#  define LWIP_CHKSUM_ALGORITHM 2
-> algo 2 should be faster on all platforms ?

ip.h.patch:
define ttl and proto fields of ip header as 2 u8_t.




Index: include/ipv4/lwip/ip.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/ipv4/lwip/ip.h,v
retrieving revision 1.37
diff -u -r1.37 ip.h
--- include/ipv4/lwip/ip.h      8 Feb 2010 19:41:53 -0000       1.37
+++ include/ipv4/lwip/ip.h      12 Feb 2010 23:13:24 -0000
@@ -123,8 +123,10 @@
 #define IP_DF 0x4000        /* dont fragment flag */
 #define IP_MF 0x2000        /* more fragments flag */
 #define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
-  /* time to live / protocol*/
-  PACK_STRUCT_FIELD(u16_t _ttl_proto);
+  /* time to live */
+  PACK_STRUCT_FIELD(u8_t _ttl);
+  /* protocol*/
+  PACK_STRUCT_FIELD(u8_t _proto);
   /* checksum */
   PACK_STRUCT_FIELD(u16_t _chksum);
   /* source and destination IP addresses */
@@ -142,17 +144,16 @@
 #define IPH_LEN(hdr) ((hdr)->_len)
 #define IPH_ID(hdr) ((hdr)->_id)
 #define IPH_OFFSET(hdr) ((hdr)->_offset)
-#define IPH_TTL(hdr) (ntohs((hdr)->_ttl_proto) >> 8)
-#define IPH_PROTO(hdr) (ntohs((hdr)->_ttl_proto) & 0xff)
+#define IPH_TTL(hdr) ((hdr)->_ttl)
+#define IPH_PROTO(hdr) ((hdr)->_proto)
 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
 
 #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) 
| ((hl) << 8) | (tos)))
 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
-#define IPH_TTL_PROTO_SET(hdr, ttl, proto) (hdr)->_ttl_proto = 
(htons((u8_t)(proto) | ((u16_t)(ttl) << 8)))
-#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = (htons(IPH_PROTO(hdr) | 
((u16_t)(ttl) << 8)))
-#define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | 
(IPH_TTL(hdr) << 8)))
+#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
+#define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
Index: core/dhcp.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/dhcp.c,v
retrieving revision 1.121
diff -u -r1.121 dhcp.c
--- core/dhcp.c 12 Feb 2010 16:42:02 -0000      1.121
+++ core/dhcp.c 13 Feb 2010 13:54:59 -0000
@@ -246,7 +246,7 @@
     LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): server 
0x%08"X32_F"\n",
       ip4_addr_get_u32(&dhcp->server_ip_addr)));
     /* remember offered address */
-    ip_addr_set(&dhcp->offered_ip_addr, &dhcp->msg_in->yiaddr);
+    ip_addr_copy(&dhcp->offered_ip_addr, &dhcp->msg_in->yiaddr);
     LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): offer for 
0x%08"X32_F"\n",
       ip4_addr_get_u32(&dhcp->offered_ip_addr)));
 
@@ -535,12 +535,12 @@
   }
 
   /* (y)our internet address */
-  ip_addr_set(&dhcp->offered_ip_addr, &dhcp->msg_in->yiaddr);
+  ip_addr_copy(&dhcp->offered_ip_addr, &dhcp->msg_in->yiaddr);
 
 #if LWIP_DHCP_BOOTP_FILE
   /* copy boot server address,
      boot file name copied in dhcp_parse_reply if not overloaded */
-  ip_addr_set(&dhcp->offered_si_addr, &dhcp->msg_in->siaddr);
+  ip_addr_copy(&dhcp->offered_si_addr, &dhcp->msg_in->siaddr);
 #endif /* LWIP_DHCP_BOOTP_FILE */
 
   /* subnet mask given? */
@@ -942,10 +942,10 @@
 
   if (dhcp->subnet_mask_given) {
     /* copy offered network mask */
-    ip_addr_set(&sn_mask, &dhcp->offered_sn_mask);
+    ip_addr_copy(&sn_mask, &dhcp->offered_sn_mask);
   } else {
     /* subnet mask not given, choose a safe subnet mask given the network 
class */
-    u8_t first_octet = (u8_t)ip4_addr1_16(&dhcp->offered_ip_addr);
+    u8_t first_octet = ip4_addr1(&dhcp->offered_ip_addr);
     if (first_octet <= 127) {
       ip4_addr_set_u32(&sn_mask, htonl(0xff000000));
     } else if (first_octet >= 192) {
@@ -955,7 +955,7 @@
     }
   }
 
-  ip_addr_set(&gw_addr, &dhcp->offered_gw_addr);
+  ip_addr_copy(&gw_addr, &dhcp->offered_gw_addr);
   /* gateway address not given? */
   if (ip_addr_isany(&gw_addr)) {
     /* copy network address */
@@ -1665,7 +1665,7 @@
   dhcp->msg_out->flags = 0;
   ip_addr_set_zero(&dhcp->msg_out->ciaddr);
   if (dhcp->state==DHCP_BOUND || dhcp->state==DHCP_RENEWING || 
dhcp->state==DHCP_REBINDING) {
-    ip_addr_set(&dhcp->msg_out->ciaddr, &netif->ip_addr);
+    ip_addr_copy(&dhcp->msg_out->ciaddr, &netif->ip_addr);
   }
   ip_addr_set_zero(&dhcp->msg_out->yiaddr);
   ip_addr_set_zero(&dhcp->msg_out->siaddr);
Index: core/dns.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/dns.c,v
retrieving revision 1.37
diff -u -r1.37 dns.c
--- core/dns.c  13 Feb 2010 14:51:46 -0000      1.37
+++ core/dns.c  13 Feb 2010 15:04:34 -0000
@@ -443,7 +443,7 @@
   entry->name = (char*)entry + sizeof(struct local_hostlist_entry);
   MEMCPY((char*)entry->name, hostname, namelen);
   ((char*)entry->name)[namelen] = 0;
-  ip_addr_set(&entry->addr, addr);
+  ip_addr_copy(&entry->addr, addr);
   entry->next = local_hostlist_dynamic;
   local_hostlist_dynamic = entry;
   return ERR_OK;
@@ -622,7 +622,7 @@
     /* fill dns query */
     qry.type = htons(DNS_RRTYPE_A);
     qry.cls = htons(DNS_RRCLASS_IN);
-    MEMCPY(query, &qry, SIZEOF_DNS_QUERY);
+    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))));
@@ -823,16 +823,15 @@
           pHostname = (char *) dns_parse_name((unsigned char *)pHostname);
 
           /* Check for IP address type and Internet class. Others are 
discarded. */
-          MEMCPY(&ans, pHostname, SIZEOF_DNS_ANSWER);
-          if((ntohs(ans.type) == DNS_RRTYPE_A) && (ntohs(ans.cls) == 
DNS_RRCLASS_IN) &&
-             (ntohs(ans.len) == sizeof(ip_addr_t)) ) {
+          SMEMCPY(&ans, pHostname, SIZEOF_DNS_ANSWER);
+          if((ans.type == htons(DNS_RRTYPE_A)) && (ans.cls == 
htons(DNS_RRCLASS_IN)) && (ans.len == htons(sizeof(ip_addr_t))) ) {
             /* read the answer resource record's TTL, and maximize it if 
needed */
             pEntry->ttl = ntohl(ans.ttl);
             if (pEntry->ttl > DNS_MAX_TTL) {
               pEntry->ttl = DNS_MAX_TTL;
             }
             /* read the IP address after answer resource record's header */
-            MEMCPY( &(pEntry->ipaddr), (pHostname+SIZEOF_DNS_ANSWER), 
sizeof(ip_addr_t));
+            SMEMCPY(&(pEntry->ipaddr), (pHostname+SIZEOF_DNS_ANSWER), 
sizeof(ip_addr_t));
             LWIP_DEBUGF(DNS_DEBUG, ("dns_recv: \"%s\": response = ", 
pEntry->name));
             ip_addr_debug_print(DNS_DEBUG, (&(pEntry->ipaddr)));
             LWIP_DEBUGF(DNS_DEBUG, ("\n"));
Index: core/netif.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/netif.c,v
retrieving revision 1.85
diff -u -r1.85 netif.c
--- core/netif.c        12 Feb 2010 16:50:23 -0000      1.85
+++ core/netif.c        13 Feb 2010 13:55:26 -0000
@@ -347,7 +347,7 @@
           (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr)))) {
         /* The PCB is listening to the old ipaddr and
          * is set to listen to the new one instead */
-        ip_addr_set(&(lpcb->local_ip), ipaddr);
+        ip_addr_copy(&(lpcb->local_ip), ipaddr);
       }
     }
   }
@@ -355,7 +355,7 @@
   snmp_delete_ipaddridx_tree(netif);
   snmp_delete_iprteidx_tree(0,netif);
   /* set new IP address to netif */
-  ip_addr_set(&(netif->ip_addr), ipaddr);
+  ip_addr_copy(&(netif->ip_addr), ipaddr);
   snmp_insert_ipaddridx_tree(netif);
   snmp_insert_iprteidx_tree(0,netif);
 
@@ -378,7 +378,7 @@
 void
 netif_set_gw(struct netif *netif, ip_addr_t *gw)
 {
-  ip_addr_set(&(netif->gw), gw);
+  ip_addr_set_safe(&(netif->gw), gw);
   LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: GW 
address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
     netif->name[0], netif->name[1],
     ip4_addr1_16(&netif->gw),
@@ -401,7 +401,7 @@
 {
   snmp_delete_iprteidx_tree(0, netif);
   /* set new netmask to netif */
-  ip_addr_set(&(netif->netmask), netmask);
+  ip_addr_copy(&(netif->netmask), netmask);
   snmp_insert_iprteidx_tree(0, netif);
   LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: netmask 
of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
     netif->name[0], netif->name[1],
Index: core/raw.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/raw.c,v
retrieving revision 1.28
diff -u -r1.28 raw.c
--- core/raw.c  4 Feb 2010 18:47:44 -0000       1.28
+++ core/raw.c  13 Feb 2010 13:55:30 -0000
@@ -141,7 +141,7 @@
 err_t
 raw_bind(struct raw_pcb *pcb, ip_addr_t *ipaddr)
 {
-  ip_addr_set(&pcb->local_ip, ipaddr);
+  ip_addr_set_safe(&pcb->local_ip, ipaddr);
   return ERR_OK;
 }
 
@@ -161,7 +161,7 @@
 err_t
 raw_connect(struct raw_pcb *pcb, ip_addr_t *ipaddr)
 {
-  ip_addr_set(&pcb->remote_ip, ipaddr);
+  ip_addr_set_safe(&pcb->remote_ip, ipaddr);
   return ERR_OK;
 }
 
Index: core/tcp.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/tcp.c,v
retrieving revision 1.116
diff -u -r1.116 tcp.c
--- core/tcp.c  12 Feb 2010 16:32:31 -0000      1.116
+++ core/tcp.c  13 Feb 2010 13:55:37 -0000
@@ -232,8 +232,8 @@
   } else {
     seqno = pcb->snd_nxt;
     ackno = pcb->rcv_nxt;
-    ip_addr_set(&local_ip, &(pcb->local_ip));
-    ip_addr_set(&remote_ip, &(pcb->remote_ip));
+    ip_addr_copy(&local_ip, &(pcb->local_ip));
+    ip_addr_copy(&remote_ip, &(pcb->remote_ip));
     local_port = pcb->local_port;
     remote_port = pcb->remote_port;
 #if LWIP_CALLBACK_API
@@ -391,7 +391,7 @@
   lpcb->so_options |= SOF_ACCEPTCONN;
   lpcb->ttl = pcb->ttl;
   lpcb->tos = pcb->tos;
-  ip_addr_set(&lpcb->local_ip, &pcb->local_ip);
+  ip_addr_copy(&lpcb->local_ip, &pcb->local_ip);
   TCP_RMV(&tcp_bound_pcbs, pcb);
   memp_free(MEMP_TCP_PCB, pcb);
 #if LWIP_CALLBACK_API
Index: core/tcp_in.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/tcp_in.c,v
retrieving revision 1.134
diff -u -r1.134 tcp_in.c
--- core/tcp_in.c       10 Feb 2010 07:58:01 -0000      1.134
+++ core/tcp_in.c       13 Feb 2010 13:55:54 -0000
@@ -433,9 +433,9 @@
     pcb->accepts_pending++;
 #endif /* TCP_LISTEN_BACKLOG */
     /* Set up the new PCB. */
-    ip_addr_set(&(npcb->local_ip), &(iphdr->dest));
+    ip_addr_copy(&(npcb->local_ip), &(iphdr->dest));
     npcb->local_port = pcb->local_port;
-    ip_addr_set(&(npcb->remote_ip), &(iphdr->src));
+    ip_addr_copy(&(npcb->remote_ip), &(iphdr->src));
     npcb->remote_port = tcphdr->src;
     npcb->state = SYN_RCVD;
     npcb->rcv_nxt = seqno + 1;
Index: core/tcp_out.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/tcp_out.c,v
retrieving revision 1.96
diff -u -r1.96 tcp_out.c
--- core/tcp_out.c      4 Feb 2010 18:47:44 -0000       1.96
+++ core/tcp_out.c      13 Feb 2010 14:01:24 -0000
@@ -703,7 +703,7 @@
     if (netif == NULL) {
       return;
     }
-    ip_addr_set(&(pcb->local_ip), &(netif->ip_addr));
+    ip_addr_copy(&(pcb->local_ip), &(netif->ip_addr));
   }
 
   /* Set retransmission timer running if it is not currently enabled */
Index: core/udp.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/udp.c,v
retrieving revision 1.120
diff -u -r1.120 udp.c
--- core/udp.c  12 Feb 2010 16:30:58 -0000      1.120
+++ core/udp.c  13 Feb 2010 13:56:31 -0000
@@ -618,7 +618,7 @@
 #endif
   }
 
-  ip_addr_set(&pcb->local_ip, ipaddr);
+  ip_addr_set_safe(&pcb->local_ip, ipaddr);
 
   /* no port specified? */
   if (port == 0) {
@@ -689,7 +689,7 @@
     }
   }
 
-  ip_addr_set(&pcb->remote_ip, ipaddr);
+  ip_addr_set_safe(&pcb->remote_ip, ipaddr);
   pcb->remote_port = port;
   pcb->flags |= UDP_FLAGS_CONNECTED;
 /** TODO: this functionality belongs in upper layers */
Index: core/ipv4/icmp.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/ipv4/icmp.c,v
retrieving revision 1.49
diff -u -r1.49 icmp.c
--- core/ipv4/icmp.c    4 Feb 2010 18:47:44 -0000       1.49
+++ core/ipv4/icmp.c    13 Feb 2010 13:56:46 -0000
@@ -184,9 +184,9 @@
     /* We generate an answer by switching the dest and src ip addresses,
      * setting the icmp type to ECHO_RESPONSE and updating the checksum. */
     iecho = (struct icmp_echo_hdr *)p->payload;
-    ip_addr_set(&tmpaddr, &iphdr->src);
-    ip_addr_set(&iphdr->src, &iphdr->dest);
-    ip_addr_set(&iphdr->dest, &tmpaddr);
+    ip_addr_copy(&tmpaddr, &iphdr->src);
+    ip_addr_copy(&iphdr->src, &iphdr->dest);
+    ip_addr_copy(&iphdr->dest, &tmpaddr);
     ICMPH_TYPE_SET(iecho, ICMP_ER);
     /* adjust the checksum */
     if (iecho->chksum >= htons(0xffff - (ICMP_ECHO << 8))) {
Index: core/ipv4/igmp.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/ipv4/igmp.c,v
retrieving revision 1.38
diff -u -r1.38 igmp.c
--- core/ipv4/igmp.c    8 Feb 2010 19:50:49 -0000       1.38
+++ core/ipv4/igmp.c    13 Feb 2010 13:56:51 -0000
@@ -329,7 +329,7 @@
   group = memp_malloc(MEMP_IGMP_GROUP);
   if (group != NULL) {
     group->netif              = ifp;
-    ip_addr_set(&(group->group_address), addr);
+    ip_addr_copy(&(group->group_address), addr);
     group->timer              = 0; /* Not running */
     group->group_state        = IGMP_GROUP_NON_MEMBER;
     group->last_reporter_flag = 0;
@@ -786,16 +786,16 @@
     igmp = p->payload;
     LWIP_ASSERT("igmp_send: check that first pbuf can hold struct igmp_msg",
                (p->len >= sizeof(struct igmp_msg)));
-    ip_addr_set(&src, &((group->netif)->ip_addr));
+    ip_addr_copy(&src, &((group->netif)->ip_addr));
      
     if (type == IGMP_V2_MEMB_REPORT) {
       dest = &(group->group_address);
-      ip_addr_set(&(igmp->igmp_group_address), &(group->group_address));
+      ip_addr_copy(&(igmp->igmp_group_address), &(group->group_address));
       group->last_reporter_flag = 1; /* Remember we were the last to report */
     } else {
       if (type == IGMP_LEAVE_GROUP) {
         dest = &allrouters;
-        ip_addr_set(&(igmp->igmp_group_address), &(group->group_address));
+        ip_addr_copy(&(igmp->igmp_group_address), &(group->group_address));
       }
     }
 
Index: core/ipv4/ip.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/ipv4/ip.c,v
retrieving revision 1.83
diff -u -r1.83 ip.c
--- core/ipv4/ip.c      4 Feb 2010 18:47:44 -0000       1.83
+++ core/ipv4/ip.c      13 Feb 2010 13:57:07 -0000
@@ -557,7 +557,7 @@
 
     IPH_TTL_PROTO_SET(iphdr, ttl, proto);
 
-    ip_addr_set(&(iphdr->dest), dest);
+    ip_addr_copy(&(iphdr->dest), dest);
 
     IPH_VHLTOS_SET(iphdr, 4, ip_hlen / 4, tos);
     IPH_LEN_SET(iphdr, htons(p->tot_len));
@@ -566,9 +566,9 @@
     ++ip_id;
 
     if (ip_addr_isany(src)) {
-      ip_addr_set(&(iphdr->src), &(netif->ip_addr));
+      ip_addr_copy(&(iphdr->src), &(netif->ip_addr));
     } else {
-      ip_addr_set(&(iphdr->src), src);
+      ip_addr_copy(&(iphdr->src), src);
     }
 
     IPH_CHKSUM_SET(iphdr, 0);
Index: core/ipv4/ip_addr.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/ipv4/ip_addr.c,v
retrieving revision 1.30
diff -u -r1.30 ip_addr.c
--- core/ipv4/ip_addr.c 8 Feb 2010 20:14:21 -0000       1.30
+++ core/ipv4/ip_addr.c 13 Feb 2010 13:58:10 -0000
@@ -44,41 +44,6 @@
 const ip_addr_t ip_addr_any = { IPADDR_ANY };
 const ip_addr_t ip_addr_broadcast = { IPADDR_BROADCAST };
 
-/**
- * Determine if an address is a broadcast address on a network interface 
- * 
- * @param addr address to be checked
- * @param netif the network interface against which the address is checked
- * @return returns non-zero if the address is a broadcast address
- */
-u8_t ip_addr_isbroadcast(ip_addr_t *addr, struct netif *netif)
-{
-  u32_t addr2test;
-
-  addr2test = ip4_addr_get_u32(addr);
-  /* all ones (broadcast) or all zeroes (old skool broadcast) */
-  if ((~addr2test == IPADDR_ANY) ||
-      (addr2test == IPADDR_ANY))
-    return 1;
-  /* no broadcast support on this network interface? */
-  else if ((netif->flags & NETIF_FLAG_BROADCAST) == 0)
-    /* the given address cannot be a broadcast address
-     * nor can we check against any broadcast addresses */
-    return 0;
-  /* address matches network interface address exactly? => no broadcast */
-  else if (addr2test == ip4_addr_get_u32(&netif->ip_addr))
-    return 0;
-  /*  on the same (sub) network... */
-  else if (ip_addr_netcmp(addr, &(netif->ip_addr), &(netif->netmask))
-         /* ...and host identifier bits are all ones? =>... */
-          && ((addr2test & ~ip4_addr_get_u32(&netif->netmask)) ==
-           (IPADDR_BROADCAST & ~ip4_addr_get_u32(&netif->netmask))))
-    /* => network broadcast address */
-    return 1;
-  else
-    return 0;
-}
-
 /* Here for now until needed in other places in lwIP */
 #ifndef isprint
 #define in_range(c, lo, up)  ((u8_t)c >= lo && (u8_t)c <= up)
Index: core/snmp/msg_out.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/snmp/msg_out.c,v
retrieving revision 1.18
diff -u -r1.18 msg_out.c
--- core/snmp/msg_out.c 4 Feb 2010 18:47:47 -0000       1.18
+++ core/snmp/msg_out.c 13 Feb 2010 13:56:39 -0000
@@ -230,10 +230,10 @@
     if ((td->enable != 0) && !ip_addr_isany(&td->dip))
     {
       /* network order trap destination */
-      ip_addr_set(&trap_msg.dip, &td->dip);
+      ip_addr_copy(&trap_msg.dip, &td->dip);
       /* lookup current source address for this dst */
       dst_if = ip_route(&td->dip);
-      ip_addr_set(&dst_ip, &dst_if->ip_addr);
+      ip_addr_copy(&dst_ip, &dst_if->ip_addr);
       /* @todo: what about IPv6? */
       trap_msg.sip_raw[0] = ip4_addr1(&dst_ip);
       trap_msg.sip_raw[1] = ip4_addr2(&dst_ip);
Index: include/ipv4/lwip/ip.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/ipv4/lwip/ip.h,v
retrieving revision 1.37
diff -u -r1.37 ip.h
--- include/ipv4/lwip/ip.h      8 Feb 2010 19:41:53 -0000       1.37
+++ include/ipv4/lwip/ip.h      12 Feb 2010 23:13:24 -0000
@@ -123,8 +123,10 @@
 #define IP_DF 0x4000        /* dont fragment flag */
 #define IP_MF 0x2000        /* more fragments flag */
 #define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
-  /* time to live / protocol*/
-  PACK_STRUCT_FIELD(u16_t _ttl_proto);
+  /* time to live */
+  PACK_STRUCT_FIELD(u8_t _ttl);
+  /* protocol*/
+  PACK_STRUCT_FIELD(u8_t _proto);
   /* checksum */
   PACK_STRUCT_FIELD(u16_t _chksum);
   /* source and destination IP addresses */
@@ -142,17 +144,16 @@
 #define IPH_LEN(hdr) ((hdr)->_len)
 #define IPH_ID(hdr) ((hdr)->_id)
 #define IPH_OFFSET(hdr) ((hdr)->_offset)
-#define IPH_TTL(hdr) (ntohs((hdr)->_ttl_proto) >> 8)
-#define IPH_PROTO(hdr) (ntohs((hdr)->_ttl_proto) & 0xff)
+#define IPH_TTL(hdr) ((hdr)->_ttl)
+#define IPH_PROTO(hdr) ((hdr)->_proto)
 #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
 
 #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) 
| ((hl) << 8) | (tos)))
 #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
 #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
 #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
-#define IPH_TTL_PROTO_SET(hdr, ttl, proto) (hdr)->_ttl_proto = 
(htons((u8_t)(proto) | ((u16_t)(ttl) << 8)))
-#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = (htons(IPH_PROTO(hdr) | 
((u16_t)(ttl) << 8)))
-#define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | 
(IPH_TTL(hdr) << 8)))
+#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl = (u8_t)(ttl)
+#define IPH_PROTO_SET(hdr, proto) (hdr)->_proto = (u8_t)(proto)
 #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
 
 /** The interface that provided the packet for the current callback 
invocation. */
Index: include/ipv4/lwip/ip_addr.h
===================================================================
RCS file: /sources/lwip/lwip/src/include/ipv4/lwip/ip_addr.h,v
retrieving revision 1.47
diff -u -r1.47 ip_addr.h
--- include/ipv4/lwip/ip_addr.h 8 Feb 2010 20:14:21 -0000       1.47
+++ include/ipv4/lwip/ip_addr.h 13 Feb 2010 14:40:19 -0000
@@ -123,16 +123,26 @@
 #define IP_LOOPBACKNET      127                 /* official! */
 
 
+#if BYTE_ORDER == BIG_ENDIAN
 #define IP4_ADDR(ipaddr, a,b,c,d) \
-        (ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \
-                               ((u32_t)((b) & 0xff) << 16) | \
-                               ((u32_t)((c) & 0xff) << 8) | \
-                                (u32_t)((d) & 0xff))
+        (ipaddr)->addr = ((u32_t)((a) & 0xff) << 24) | \
+                         ((u32_t)((b) & 0xff) << 16) | \
+                         ((u32_t)((c) & 0xff) << 8)  | \
+                          (u32_t)((d) & 0xff)
+#else
+#define IP4_ADDR(ipaddr, a,b,c,d) \
+        (ipaddr)->addr = ((u32_t)((d) & 0xff) << 24) | \
+                         ((u32_t)((c) & 0xff) << 16) | \
+                         ((u32_t)((b) & 0xff) << 8)  | \
+                          (u32_t)((a) & 0xff)
+#endif
 
+/** Copy adress */
+#define ip_addr_copy(dest, src) ((dest)->addr = (src)->addr)
 /** Safely copy one IP address to another (src may be NULL) */
-#define ip_addr_set(dest, src) ((dest)->addr = \
-                               ((src) == NULL ? 0:\
-                               (src)->addr))
+#define ip_addr_set_safe(dest, src) ((dest)->addr = \
+                                    ((src) == NULL ? 0:\
+                                    (src)->addr))
 /** Set complete address to zero */
 #define ip_addr_set_zero(ipaddr)      ((ipaddr)->addr = 0)
 /** Set address to IPADDR_ANY (no need for htonl()) */
@@ -166,30 +176,28 @@
                                               (mask)->addr))
 #define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
 
-#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
+#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == IPADDR_ANY)
 
-u8_t ip_addr_isbroadcast(ip_addr_t *, struct netif *);
+#define ip_addr_isbroadcast(addr1, netif) ((addr1)->addr == IPADDR_BROADCAST 
|| \
+                                          ((netif->flags & 
NETIF_FLAG_BROADCAST) && \
+                                           (addr1)->addr == 
(netif->ip_addr.addr|(~netif->netmask.addr)) ) )
 
 #define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000UL)) == 
ntohl(0xe0000000UL))
 
 #define ip_addr_islinklocal(addr1) (((addr1)->addr & ntohl(0xffff0000UL)) == 
ntohl(0xa9fe0000UL))
 
 #define ip_addr_debug_print(debug, ipaddr) \
-  LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F,              \
-                      ipaddr != NULL ?                                  \
-                      (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0,  \
-                      ipaddr != NULL ?                                  \
-                      (u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0,  \
-                      ipaddr != NULL ?                                  \
-                      (u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0,   \
-                      ipaddr != NULL ?                                  \
-                      (u16_t)ntohl((ipaddr)->addr) & 0xff : 0))
+  LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F,             \
+                      ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0,       \
+                      ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0,       \
+                      ipaddr != NULL ? ip4_addr3_16(ipaddr) : 0,       \
+                      ipaddr != NULL ? ip4_addr4_16(ipaddr) : 0))
 
 /* Get one byte from the 4-byte address */
-#define ip4_addr1(ipaddr) ((u8_t)(ntohl((ipaddr)->addr) >> 24) & 0xff)
-#define ip4_addr2(ipaddr) ((u8_t)(ntohl((ipaddr)->addr) >> 16) & 0xff)
-#define ip4_addr3(ipaddr) ((u8_t)(ntohl((ipaddr)->addr) >> 8) & 0xff)
-#define ip4_addr4(ipaddr) ((u8_t)(ntohl((ipaddr)->addr)) & 0xff)
+#define ip4_addr1(ipaddr) (((u8_t*)(ipaddr))[0])
+#define ip4_addr2(ipaddr) (((u8_t*)(ipaddr))[1])
+#define ip4_addr3(ipaddr) (((u8_t*)(ipaddr))[2])
+#define ip4_addr4(ipaddr) (((u8_t*)(ipaddr))[3])
 /* These are cast to u16_t, with the intent that they are often arguments
  * to printf using the U16_F format from cc.h. */
 #define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
Index: netif/etharp.c
===================================================================
RCS file: /sources/lwip/lwip/src/netif/etharp.c,v
retrieving revision 1.159
diff -u -r1.159 etharp.c
--- netif/etharp.c      9 Feb 2010 11:38:00 -0000       1.159
+++ netif/etharp.c      13 Feb 2010 13:54:43 -0000
@@ -407,7 +407,7 @@
   /* IP address given? */
   if (ipaddr != NULL) {
     /* set IP address */
-    ip_addr_set(&arp_table[i].ipaddr, ipaddr);
+    ip_addr_copy(&arp_table[i].ipaddr, ipaddr);
   }
   arp_table[i].ctime = 0;
 #if LWIP_NETIF_HWADDRHINT

Index: def.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/def.c,v
retrieving revision 1.1
diff -u -r1.1 def.c
--- def.c       29 Jan 2010 08:20:35 -0000      1.1
+++ def.c       13 Feb 2010 14:03:11 -0000
@@ -54,6 +54,8 @@
 
 #if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN)
 
+#warning LWIP_PLATFORM_BYTESWAP not defined, using defaults for 
htons,htonl,ntohs,ntohl
+
 /**
  * Convert an u16_t from host- to network byte order.
  *
Index: ipv4/inet_chksum.c
===================================================================
RCS file: /sources/lwip/lwip/src/core/ipv4/inet_chksum.c,v
retrieving revision 1.14
diff -u -r1.14 inet_chksum.c
--- ipv4/inet_chksum.c  4 Feb 2010 18:47:44 -0000       1.14
+++ ipv4/inet_chksum.c  12 Feb 2010 23:05:26 -0000
@@ -57,13 +57,10 @@
 #ifndef LWIP_CHKSUM
 # define LWIP_CHKSUM lwip_standard_chksum
 # ifndef LWIP_CHKSUM_ALGORITHM
-#  define LWIP_CHKSUM_ALGORITHM 1
+#  warning LWIP_CHKSUM and LWIP_CHKSUM_ALGORITHM not defined, using default 
algorithm 2
+#  define LWIP_CHKSUM_ALGORITHM 2
 # endif
 #endif
-/* If none set: */
-#ifndef LWIP_CHKSUM_ALGORITHM
-# define LWIP_CHKSUM_ALGORITHM 0
-#endif
 
 /** Like the name says... */
 #if LWIP_PLATFORM_BYTESWAP && (BYTE_ORDER == LITTLE_ENDIAN)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]