[quagga-dev 9316] [PATCH 25/25] lib: optimize IPV4_ADDR_[SAME|COPY]()

Jorge Boncompte [DTI2] jorge at dti2.net
Mon May 7 18:53:15 BST 2012


From: "Jorge Boncompte [DTI2]" <jorge at dti2.net>

* lib/prefix.c: (prefix_same) changed to use prefix4 field.
* ospfd/ospf_packet.c: (ospf_ls_upd_send) changed to use prefix4 field.

  Now that all callers use the prefix4 field...

* lib/prefix.h: use assignment and comparison instead of memcpy() and
  memcmp(). Avoids function calls. Much faster.

Signed-off-by: Jorge Boncompte [DTI2] <jorge at dti2.net>
---
 lib/prefix.c        |    2 +-
 lib/prefix.h        |    4 ++--
 ospfd/ospf_packet.c |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/prefix.c b/lib/prefix.c
index a3b1adf..48b3f5b 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -281,7 +281,7 @@ prefix_same (const struct prefix *p1, const struct prefix *p2)
   if (p1->family == p2->family && p1->prefixlen == p2->prefixlen)
     {
       if (p1->family == AF_INET)
-	if (IPV4_ADDR_SAME (&p1->u.prefix4.s_addr, &p2->u.prefix4.s_addr))
+	if (IPV4_ADDR_SAME (&p1->u.prefix4, &p2->u.prefix4))
 	  return 1;
 #ifdef HAVE_IPV6
       if (p1->family == AF_INET6 )
diff --git a/lib/prefix.h b/lib/prefix.h
index 7f0d360..a97ff24 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -106,8 +106,8 @@ struct prefix_rd
 #define IPV4_MAX_BITLEN    32
 #define IPV4_MAX_PREFIXLEN 32
 #define IPV4_ADDR_CMP(D,S)   memcmp ((D), (S), IPV4_MAX_BYTELEN)
-#define IPV4_ADDR_SAME(D,S)  (memcmp ((D), (S), IPV4_MAX_BYTELEN) == 0)
-#define IPV4_ADDR_COPY(D,S)  memcpy ((D), (S), IPV4_MAX_BYTELEN)
+#define IPV4_ADDR_SAME(D,S)  ((D)->s_addr == (S)->s_addr)
+#define IPV4_ADDR_COPY(D,S)  ((D)->s_addr = (S)->s_addr)
 
 #define IPV4_NET0(a)    ((((u_int32_t) (a)) & 0xff000000) == 0x00000000)
 #define IPV4_NET127(a)  ((((u_int32_t) (a)) & 0xff000000) == 0x7f000000)
diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index 351fb21..03494d1 100644
--- a/ospfd/ospf_packet.c
+++ b/ospfd/ospf_packet.c
@@ -3815,7 +3815,7 @@ ospf_ls_upd_send (struct ospf_neighbor *nbr, struct list *update, int flag)
     {
       if (flag == OSPF_SEND_PACKET_INDIRECT)
 	zlog_warn ("* LS-Update is directly sent on NBMA network.");
-      if (IPV4_ADDR_SAME(&oi->address->u.prefix4, &p.prefix.s_addr))
+      if (IPV4_ADDR_SAME(&oi->address->u.prefix4, &p.prefix))
 	zlog_warn ("* LS-Update is sent to myself.");
     }
 
-- 
1.7.8.3





More information about the Quagga-dev mailing list