From owner-svn-src-head@freebsd.org Thu May 26 18:57:27 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C6DB3B4B375; Thu, 26 May 2016 18:57:27 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7F32218B5; Thu, 26 May 2016 18:57:27 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4QIvQ6v074168; Thu, 26 May 2016 18:57:26 GMT (envelope-from jkim@FreeBSD.org) Received: (from jkim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4QIvQpN074167; Thu, 26 May 2016 18:57:26 GMT (envelope-from jkim@FreeBSD.org) Message-Id: <201605261857.u4QIvQpN074167@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jkim set sender to jkim@FreeBSD.org using -f From: Jung-uk Kim Date: Thu, 26 May 2016 18:57:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300771 - head/sys/netgraph/netflow X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 May 2016 18:57:27 -0000 Author: jkim Date: Thu May 26 18:57:26 2016 New Revision: 300771 URL: https://svnweb.freebsd.org/changeset/base/300771 Log: Use bit_count(3) instead of four bitcount32() calls. Reviewed by: asomers, ngie Differential Revision: https://reviews.freebsd.org/D6543 Modified: head/sys/netgraph/netflow/netflow.c Modified: head/sys/netgraph/netflow/netflow.c ============================================================================== --- head/sys/netgraph/netflow/netflow.c Thu May 26 18:52:49 2016 (r300770) +++ head/sys/netgraph/netflow/netflow.c Thu May 26 18:57:26 2016 (r300771) @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include "opt_inet6.h" #include "opt_route.h" #include +#include #include #include #include @@ -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_has } #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_ha 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_ha 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_ha return (0); } -#undef ipv6_masklen #endif