From owner-freebsd-net@FreeBSD.ORG Thu Nov 20 17:33:42 2014 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx2.freebsd.org (mx2.freebsd.org [8.8.178.116]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 35E1B610; Thu, 20 Nov 2014 17:33:42 +0000 (UTC) Received: from butcher-nb.yandex.net (hub.freebsd.org [IPv6:2001:1900:2254:206c::16:88]) by mx2.freebsd.org (Postfix) with ESMTP id 7C59C706; Thu, 20 Nov 2014 17:33:40 +0000 (UTC) Message-ID: <546E25D1.7020900@FreeBSD.org> Date: Thu, 20 Nov 2014 20:33:05 +0300 From: "Andrey V. Elsukov" User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: freebsd-arch@freebsd.org, "freebsd-net@freebsd.org" Subject: [RFC] add macros for ifnet statistic accounting Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Nov 2014 17:33:42 -0000 Hi All, we already did some changes in network stack in head/, that made ability for merging changes into stable branches much harder. What you think about adding the following macro to head/: --- if_var.h (revision 274736) +++ if_var.h (working copy) @@ -111,6 +111,10 @@ typedef enum { IFCOUNTERS /* Array size. */ } ift_counter; +#define IFSTAT_ADD(ifp, name, value) \ + if_inc_counter((ifp), IFCOUNTER_ ## name, (value)) +#define IFSTAT_INC(ifp, name) IFSTAT_ADD(ifp, name, 1) + typedef struct ifnet * if_t; typedef void (*if_start_fn_t)(if_t); And then make a direct commit to stable/* branches like this: --- if_var.h (revision 274750) +++ if_var.h (working copy) @@ -104,6 +104,23 @@ VNET_DECLARE(struct pfil_head, link_pfil_hook); /* #define V_link_pfil_hook VNET(link_pfil_hook) #endif /* _KERNEL */ +#define IFSTAT_ADD(ifp, name, value) \ + IFSTAT_ ## name ## _ADD(ifp, value) +#define IFSTAT_INC(ifp, name) IFSTAT_ADD(ifp, name, 1) + +#define IFSTAT_IPACKETS_ADD(ifp, inc) (ifp)->if_ipackets += (inc) +#define IFSTAT_IERRORS_ADD(ifp, inc) (ifp)->if_ierrors += (inc) +#define IFSTAT_OPACKETS_ADD(ifp, inc) (ifp)->if_opackets += (inc) +#define IFSTAT_OERRORS_ADD(ifp, inc) (ifp)->if_oerrors += (inc) +#define IFSTAT_COLLISIONS_ADD(ifp, inc) (ifp)->if_collisions += (inc) +#define IFSTAT_IBYTES_ADD(ifp, inc) (ifp)->if_ibytes += (inc) +#define IFSTAT_OBYTES_ADD(ifp, inc) (ifp)->if_obytes += (inc) +#define IFSTAT_IMCASTS_ADD(ifp, inc) (ifp)->if_imcasts += (inc) +#define IFSTAT_OMCASTS_ADD(ifp, inc) (ifp)->if_omcasts += (inc) +#define IFSTAT_IQDROPS_ADD(ifp, inc) (ifp)->if_iqdrops += (inc) +#define IFSTAT_OQDROPS_ADD(ifp, inc) /* NOP */ +#define IFSTAT_NOPROTO_ADD(ifp, inc) (ifp)->if_noproto += (inc) + /* * Structure defining a queue for a network interface. */ This can make merging a little bit easier, at least for generic code in the network stack. -- WBR, Andrey V. Elsukov