]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: optimize apply_mask_ipv4()
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 18 Oct 2011 14:33:53 +0000 (18:33 +0400)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 21 Nov 2011 14:32:23 +0000 (18:32 +0400)
lib/prefix.c

index 075c9dabd131c555eea6a0860feb25b259e5ab4a..1ddbbbe7e8df4dde578202bf23de9466c6e96efd 100644 (file)
@@ -545,27 +545,12 @@ ip_masklen (struct in_addr netmask)
   return len;
 }
 
-/* Apply mask to IPv4 prefix. */
+/* Apply mask to IPv4 prefix (network byte order). */
 void
 apply_mask_ipv4 (struct prefix_ipv4 *p)
 {
-  u_char *pnt;
-  int index;
-  int offset;
-
-  index = p->prefixlen / 8;
-
-  if (index < 4)
-    {
-      pnt = (u_char *) &p->prefix;
-      offset = p->prefixlen % 8;
-
-      pnt[index] &= maskbit[offset];
-      index++;
-
-      while (index < 4)
-       pnt[index++] = 0;
-    }
+  assert (p->prefixlen >= 0 && p->prefixlen <= IPV4_MAX_BITLEN);
+  p->prefix.s_addr &= maskbytes_network[p->prefixlen];
 }
 
 /* If prefix is 0.0.0.0/0 then return 1 else return 0. */