From owner-svn-src-stable-10@FreeBSD.ORG Tue Dec 23 09:39:41 2014 Return-Path: Delivered-To: svn-src-stable-10@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B4AC5C87; Tue, 23 Dec 2014 09:39:41 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 A01481CA8; Tue, 23 Dec 2014 09:39:41 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sBN9dfda019618; Tue, 23 Dec 2014 09:39:41 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sBN9dfxK019616; Tue, 23 Dec 2014 09:39:41 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201412230939.sBN9dfxK019616@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Tue, 23 Dec 2014 09:39:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r276124 - stable/10/sys/net X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Dec 2014 09:39:41 -0000 Author: ae Date: Tue Dec 23 09:39:40 2014 New Revision: 276124 URL: https://svnweb.freebsd.org/changeset/base/276124 Log: Add if_inc_counter() and if_get_counter_default() functions that do access to ifnet counters for code compatibility with FreeBSD 11. This is direct commit to stable/10. Discussed with: glebius@, arch@ Modified: stable/10/sys/net/if.c stable/10/sys/net/if_var.h Modified: stable/10/sys/net/if.c ============================================================================== --- stable/10/sys/net/if.c Tue Dec 23 09:31:24 2014 (r276123) +++ stable/10/sys/net/if.c Tue Dec 23 09:39:40 2014 (r276124) @@ -1450,6 +1450,100 @@ if_rtdel(struct radix_node *rn, void *ar } /* + * A compatibility function returns ifnet counter values. + */ +uint64_t +if_get_counter_default(struct ifnet *ifp, ift_counter cnt) +{ + + KASSERT(cnt < IFCOUNTERS, ("%s: invalid cnt %d", __func__, cnt)); + switch (cnt) { + case IFCOUNTER_IPACKETS: + return (ifp->if_ipackets); + case IFCOUNTER_IERRORS: + return (ifp->if_ierrors); + case IFCOUNTER_OPACKETS: + return (ifp->if_opackets); + case IFCOUNTER_OERRORS: + return (ifp->if_oerrors); + case IFCOUNTER_COLLISIONS: + return (ifp->if_collisions); + case IFCOUNTER_IBYTES: + return (ifp->if_ibytes); + case IFCOUNTER_OBYTES: + return (ifp->if_obytes); + case IFCOUNTER_IMCASTS: + return (ifp->if_imcasts); + case IFCOUNTER_OMCASTS: + return (ifp->if_omcasts); + case IFCOUNTER_IQDROPS: + return (ifp->if_iqdrops); +#ifdef _IFI_OQDROPS + case IFCOUNTER_OQDROPS: + return (ifp->if_oqdrops); +#endif + case IFCOUNTER_NOPROTO: + return (ifp->if_noproto); + default: + break; + }; + return (0); +} + +/* + * Increase an ifnet counter. Usually used for counters shared + * between the stack and a driver, but function supports them all. + */ +void +if_inc_counter(struct ifnet *ifp, ift_counter cnt, int64_t inc) +{ + + KASSERT(cnt < IFCOUNTERS, ("%s: invalid cnt %d", __func__, cnt)); + switch (cnt) { + case IFCOUNTER_IPACKETS: + ifp->if_ipackets += inc; + break; + case IFCOUNTER_IERRORS: + ifp->if_ierrors += inc; + break; + case IFCOUNTER_OPACKETS: + ifp->if_opackets += inc; + break; + case IFCOUNTER_OERRORS: + ifp->if_oerrors += inc; + break; + case IFCOUNTER_COLLISIONS: + ifp->if_collisions += inc; + break; + case IFCOUNTER_IBYTES: + ifp->if_ibytes += inc; + break; + case IFCOUNTER_OBYTES: + ifp->if_obytes += inc; + break; + case IFCOUNTER_IMCASTS: + ifp->if_imcasts += inc; + break; + case IFCOUNTER_OMCASTS: + ifp->if_omcasts += inc; + break; + case IFCOUNTER_IQDROPS: + ifp->if_iqdrops += inc; + break; +#ifdef _IFI_OQDROPS + case IFCOUNTER_OQDROPS: + ifp->if_oqdrops += inc; + break; +#endif + case IFCOUNTER_NOPROTO: + ifp->if_noproto += inc; + break; + default: + break; + }; +} + +/* * Wrapper functions for struct ifnet address list locking macros. These are * used by kernel modules to avoid encoding programming interface or binary * interface assumptions that may be violated when kernel-internal locking Modified: stable/10/sys/net/if_var.h ============================================================================== --- stable/10/sys/net/if_var.h Tue Dec 23 09:31:24 2014 (r276123) +++ stable/10/sys/net/if_var.h Tue Dec 23 09:39:40 2014 (r276124) @@ -104,6 +104,22 @@ VNET_DECLARE(struct pfil_head, link_pfil #define V_link_pfil_hook VNET(link_pfil_hook) #endif /* _KERNEL */ +typedef enum { + IFCOUNTER_IPACKETS = 0, + IFCOUNTER_IERRORS, + IFCOUNTER_OPACKETS, + IFCOUNTER_OERRORS, + IFCOUNTER_COLLISIONS, + IFCOUNTER_IBYTES, + IFCOUNTER_OBYTES, + IFCOUNTER_IMCASTS, + IFCOUNTER_OMCASTS, + IFCOUNTER_IQDROPS, + IFCOUNTER_OQDROPS, + IFCOUNTER_NOPROTO, + IFCOUNTERS /* Array size. */ +} ift_counter; + /* * Structure defining a queue for a network interface. */ @@ -981,6 +997,8 @@ typedef void *if_com_alloc_t(u_char type typedef void if_com_free_t(void *com, u_char type); void if_register_com_alloc(u_char type, if_com_alloc_t *a, if_com_free_t *f); void if_deregister_com_alloc(u_char type); +uint64_t if_get_counter_default(struct ifnet *, ift_counter); +void if_inc_counter(struct ifnet *, ift_counter, int64_t); #define IF_LLADDR(ifp) \ LLADDR((struct sockaddr_dl *)((ifp)->if_addr->ifa_addr))