From owner-svn-src-all@FreeBSD.ORG Thu Sep 18 09:54:57 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EF559D36; Thu, 18 Sep 2014 09:54:57 +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 C0BFCA67; Thu, 18 Sep 2014 09:54:57 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8I9svIb035140; Thu, 18 Sep 2014 09:54:57 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8I9sv68035138; Thu, 18 Sep 2014 09:54:57 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201409180954.s8I9sv68035138@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Thu, 18 Sep 2014 09:54:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r271751 - head/sys/net X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Sep 2014 09:54:58 -0000 Author: glebius Date: Thu Sep 18 09:54:57 2014 New Revision: 271751 URL: http://svnweb.freebsd.org/changeset/base/271751 Log: Add if_inc_counter(), a generic method to update ifnet(9) counter w/o dereferencing the struct. Sponsored by: Netflix Sponsored by: Nginx, Inc. Modified: head/sys/net/if.c head/sys/net/if_var.h Modified: head/sys/net/if.c ============================================================================== --- head/sys/net/if.c Thu Sep 18 09:49:49 2014 (r271750) +++ head/sys/net/if.c Thu Sep 18 09:54:57 2014 (r271751) @@ -1422,6 +1422,56 @@ if_get_counter_compat(struct ifnet *ifp, } /* + * 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, ifnet_counter cnt, int64_t inc) +{ + + 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; + case IFCOUNTER_OQDROPS: + ifp->if_oqdrops += inc; + break; + case IFCOUNTER_NOPROTO: + ifp->if_noproto += inc; + break; + default: + panic("%s: unknown counter %d", __func__, cnt); + } +} + +/* * Copy data from ifnet to userland API structure if_data. */ void Modified: head/sys/net/if_var.h ============================================================================== --- head/sys/net/if_var.h Thu Sep 18 09:49:49 2014 (r271750) +++ head/sys/net/if_var.h Thu Sep 18 09:54:57 2014 (r271751) @@ -528,6 +528,7 @@ void if_register_com_alloc(u_char type, void if_deregister_com_alloc(u_char type); void if_data_copy(struct ifnet *, struct if_data *); uint64_t if_get_counter_compat(struct ifnet *, ifnet_counter); +void if_inc_counter(struct ifnet *, ifnet_counter, int64_t); #define IF_LLADDR(ifp) \ LLADDR((struct sockaddr_dl *)((ifp)->if_addr->ifa_addr))