summaryrefslogtreecommitdiffstats
path: root/sys/netgraph
diff options
context:
space:
mode:
authorjkim <jkim@FreeBSD.org>2016-05-26 18:57:26 +0000
committerjkim <jkim@FreeBSD.org>2016-05-26 18:57:26 +0000
commit5cd86d07c0483562c2955f71f1f2d0888acb8809 (patch)
tree91b8f8e2a3cb3f23151e6f5291517450fa7dc82c /sys/netgraph
parent6a450d405601a2fe1ac4163596a9f1f097938a67 (diff)
downloadFreeBSD-src-5cd86d07c0483562c2955f71f1f2d0888acb8809.zip
FreeBSD-src-5cd86d07c0483562c2955f71f1f2d0888acb8809.tar.gz
Use bit_count(3) instead of four bitcount32() calls.
Reviewed by: asomers, ngie Differential Revision: https://reviews.freebsd.org/D6543
Diffstat (limited to 'sys/netgraph')
-rw-r--r--sys/netgraph/netflow/netflow.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/sys/netgraph/netflow/netflow.c b/sys/netgraph/netflow/netflow.c
index 84dee47..2d74eb3 100644
--- a/sys/netgraph/netflow/netflow.c
+++ b/sys/netgraph/netflow/netflow.c
@@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
#include "opt_inet6.h"
#include "opt_route.h"
#include <sys/param.h>
+#include <sys/bitstring.h>
#include <sys/systm.h>
#include <sys/counter.h>
#include <sys/kernel.h>
@@ -147,6 +148,19 @@ ip6_hash(struct flow6_rec *r)
r->dst.r_dst6.__u6_addr.__u6_addr32[3]);
}
}
+
+static inline int
+ip6_masklen(struct in6_addr *saddr, struct rt_addrinfo *info)
+{
+ const int nbits = sizeof(*saddr) * NBBY;
+ int mlen;
+
+ if (info->rti_addrs & RTA_NETMASK)
+ bit_count((bitstr_t *)saddr, 0, nbits, &mlen);
+ else
+ mlen = nbits;
+ return (mlen);
+}
#endif
/*
@@ -399,11 +413,6 @@ hash_insert(priv_p priv, struct flow_hash_entry *hsh, struct flow_rec *r,
}
#ifdef INET6
-/* XXX: make normal function, instead of.. */
-#define ipv6_masklen(x) bitcount32((x).__u6_addr.__u6_addr32[0]) + \
- bitcount32((x).__u6_addr.__u6_addr32[1]) + \
- bitcount32((x).__u6_addr.__u6_addr32[2]) + \
- bitcount32((x).__u6_addr.__u6_addr32[3])
static int
hash6_insert(priv_p priv, struct flow_hash_entry *hsh6, struct flow6_rec *r,
int plen, uint8_t flags, uint8_t tcp_flags)
@@ -460,11 +469,7 @@ hash6_insert(priv_p priv, struct flow_hash_entry *hsh6, struct flow6_rec *r,
fle6->f.n.next_hop6 =
((struct sockaddr_in6 *)&rt_gateway)->sin6_addr;
- if (info.rti_addrs & RTA_NETMASK)
- fle6->f.dst_mask =
- ipv6_masklen(sin6_mask.sin6_addr);
- else
- fle6->f.dst_mask = 128;
+ fle6->f.dst_mask = ip6_masklen(&sin6_mask.sin6_addr, &info);
rib_free_info(&info);
}
@@ -483,13 +488,8 @@ hash6_insert(priv_p priv, struct flow_hash_entry *hsh6, struct flow6_rec *r,
info.rti_info[RTAX_NETMASK] = (struct sockaddr *)&sin6_mask;
if (rib_lookup_info(r->fib, (struct sockaddr *)&sin6, 0, 0,
- &info) == 0) {
- if (info.rti_addrs & RTA_NETMASK)
- fle6->f.src_mask =
- ipv6_masklen(sin6_mask.sin6_addr);
- else
- fle6->f.src_mask = 128;
- }
+ &info) == 0)
+ fle6->f.src_mask = ip6_masklen(&sin6_mask.sin6_addr, &info);
}
/* Push new flow at the and of hash. */
@@ -497,7 +497,6 @@ hash6_insert(priv_p priv, struct flow_hash_entry *hsh6, struct flow6_rec *r,
return (0);
}
-#undef ipv6_masklen
#endif
OpenPOWER on IntegriCloud