Date: Tue, 23 Dec 2014 09:39:41 +0000 (UTC) From: "Andrey V. Elsukov" <ae@FreeBSD.org> 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 Message-ID: <201412230939.sBN9dfxK019616@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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))
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201412230939.sBN9dfxK019616>