aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2014-09-18 09:54:57 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2014-09-18 09:54:57 +0000
commit0b7b006c7f6ad77fab45eb89d281e0f35bdf944b (patch)
treea82c2953eeb2500e6aa798d4beb4446072ec0566 /sys
parent6dfc9e44fa9a6779b90664b2105cb324c445ae5f (diff)
downloadsrc-0b7b006c7f6ad77fab45eb89d281e0f35bdf944b.tar.gz
src-0b7b006c7f6ad77fab45eb89d281e0f35bdf944b.zip
Add if_inc_counter(), a generic method to update ifnet(9) counter
w/o dereferencing the struct. Sponsored by: Netflix Sponsored by: Nginx, Inc.
Notes
Notes: svn path=/head/; revision=271751
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if.c50
-rw-r--r--sys/net/if_var.h1
2 files changed, 51 insertions, 0 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 017af336d2b6..4dbe4ebc0a83 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1422,6 +1422,56 @@ if_get_counter_compat(struct ifnet *ifp, ifnet_counter cnt)
}
/*
+ * 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
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 09f41b8097e9..949063163997 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -528,6 +528,7 @@ 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);
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))