]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: optimize IPV4_ADDR_[SAME|COPY]()
authorJorge Boncompte <jbonor@gmail.com>
Wed, 9 Aug 2017 11:57:49 +0000 (13:57 +0200)
committerJorge Boncompte <jbonor@gmail.com>
Thu, 17 Aug 2017 15:58:35 +0000 (17:58 +0200)
Change all callers of IPV4_ADDR_SAME() to pass a pointer to a struct in_addr

Use assignment and comparison instead of memcpy() and memcmp(). Avoids function
calls. Faster.

Signed-off-by: Jorge Boncompte <jbonor@gmail.com>
bgpd/rfapi/rfapi_import.c
eigrpd/eigrp_packet.c
lib/prefix.c
lib/prefix.h
ospfd/ospf_packet.c
zebra/zebra_rib.c
zebra/zebra_static.c

index 7e0ed9150bb8f04b2a4d75d3c8d0fe30d677677e..d63975a22bff02105ede300fb0d467b0dbfd905f 100644 (file)
@@ -1224,8 +1224,8 @@ static int rfapiVpnBiSamePtUn(struct bgp_info *bi1, struct bgp_info *bi2)
 
        switch (pfx_un1.family) {
        case AF_INET:
-               if (!IPV4_ADDR_SAME(&pfx_un1.u.prefix4.s_addr,
-                                   &pfx_un2.u.prefix4.s_addr))
+               if (!IPV4_ADDR_SAME(&pfx_un1.u.prefix4,
+                                   &pfx_un2.u.prefix4))
                        return 0;
                break;
        case AF_INET6:
index dfc7463025d77a77b3a5b9a7f482b4a0f06a2bf6..45c2dd8edc3773d7eadf65c7d4529001c9a960ec 100644 (file)
@@ -530,7 +530,7 @@ int eigrp_read(struct thread *thread)
 
        /* Self-originated packet should be discarded silently. */
        if (eigrp_if_lookup_by_local_addr(eigrp, NULL, iph->ip_src)
-           || (IPV4_ADDR_SAME(&iph->ip_src.s_addr, &ei->address->u.prefix4))) {
+           || (IPV4_ADDR_SAME(&iph->ip_src, &ei->address->u.prefix4))) {
                if (IS_DEBUG_EIGRP_TRANSMIT(0, RECV))
                        zlog_debug(
                                "eigrp_read[%s]: Dropping self-originated packet",
index de521b2e3e0949ec7a0e5f4f91a1508f2e86c8fd..2f61eb6e8b0f04874225e0c34dd88a268bb74635 100644 (file)
@@ -497,8 +497,7 @@ int 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;
                if (p1->family == AF_INET6)
                        if (IPV6_ADDR_SAME(&p1->u.prefix6.s6_addr,
index f0644ea88e9dbb238e4900dc012ffe938b464603..bc4abb492a0cca31e59c61838ecb3901eed35d20 100644 (file)
@@ -241,8 +241,20 @@ union prefixconstptr {
 #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)
+
+static inline bool ipv4_addr_same(const struct in_addr *a,
+                                 const struct in_addr *b)
+{
+       return (a->s_addr == b->s_addr);
+}
+#define IPV4_ADDR_SAME(A,B)  ipv4_addr_same((A), (B))
+
+static inline void ipv4_addr_copy(struct in_addr *dst,
+                                 const struct in_addr *src)
+{
+       dst->s_addr = src->s_addr;
+}
+#define IPV4_ADDR_COPY(D,S)  ipv4_addr_copy((D), (S))
 
 #define IPV4_NET0(a)    ((((u_int32_t) (a)) & 0xff000000) == 0x00000000)
 #define IPV4_NET127(a)  ((((u_int32_t) (a)) & 0xff000000) == 0x7f000000)
index ac2406ec2d363f5733d495e2b73359606ac6f10c..36f9a6757a1d4bb34bca4ff3deb5685157a87e9a 100644 (file)
@@ -3938,7 +3938,7 @@ void 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.");
        }
 
index b27201616dafaee60996a5f323a50b7761276c8e..dc61ea5e40c14a3211c89af7b8ba7393071af4e0 100644 (file)
@@ -2352,7 +2352,7 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type,
                                break;
                        }
                        for (ALL_NEXTHOPS(re->nexthop, nexthop))
-                               if (IPV4_ADDR_SAME(&nexthop->gate.ipv4, gate)
+                               if (IPV4_ADDR_SAME(&nexthop->gate.ipv4, &gate->ipv4)
                                    || IPV6_ADDR_SAME(&nexthop->gate.ipv6,
                                                      gate)) {
                                        same = re;
index dba228ea350df68c7d0ba04840a54dc8d95305c9..6815916faf8d08b91e232f6b0d80be2b30e8d51f 100644 (file)
@@ -398,7 +398,7 @@ int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p,
        for (si = rn->info; si; si = si->next) {
                if (type == si->type
                    && (!gate || ((afi == AFI_IP
-                                  && IPV4_ADDR_SAME(gate, &si->addr.ipv4))
+                                  && IPV4_ADDR_SAME(&gate->ipv4, &si->addr.ipv4))
                                  || (afi == AFI_IP6
                                      && IPV6_ADDR_SAME(gate, &si->addr.ipv6))))
                    && (!strcmp (ifname ? ifname : "", si->ifname))) {
@@ -515,7 +515,7 @@ int static_delete_route(afi_t afi, safi_t safi, u_char type, struct prefix *p,
        for (si = rn->info; si; si = si->next)
                if (type == si->type
                    && (!gate || ((afi == AFI_IP
-                                  && IPV4_ADDR_SAME(gate, &si->addr.ipv4))
+                                  && IPV4_ADDR_SAME(&gate->ipv4, &si->addr.ipv4))
                                  || (afi == AFI_IP6
                                      && IPV6_ADDR_SAME(gate, &si->addr.ipv6))))
                    && (!strcmp(ifname ? ifname : "", si->ifname))