summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authormvs <mvs@cvs.openbsd.org>2021-07-20 16:44:56 +0000
committermvs <mvs@cvs.openbsd.org>2021-07-20 16:44:56 +0000
commite20b9f1a970d9a730e67d1b41e33b576a45cc69b (patch)
tree7dde46dce317b0e1c970cd440ef4a1eb3b054e67 /sys
parent24bf5c3ffd1adbd7a51ad9edb1d84baa48f6fed5 (diff)
Turn pipex(4) session statistics to per-CPU counters. This makes pipex(4)
more compliant to bluhm@'s work on traffic forwarding parallelization. ok yasuoka@ bluhm@
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if_pppx.c5
-rw-r--r--sys/net/pipex.c95
-rw-r--r--sys/net/pipex_local.h21
3 files changed, 79 insertions, 42 deletions
diff --git a/sys/net/if_pppx.c b/sys/net/if_pppx.c
index 4ddaa76122e..7267ba657bc 100644
--- a/sys/net/if_pppx.c
+++ b/sys/net/if_pppx.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_pppx.c,v 1.110 2021/02/25 02:48:21 dlg Exp $ */
+/* $OpenBSD: if_pppx.c,v 1.111 2021/07/20 16:44:55 mvs Exp $ */
/*
* Copyright (c) 2010 Claudio Jeker <claudio@openbsd.org>
@@ -746,8 +746,7 @@ pppx_del_session(struct pppx_dev *pxd, struct pipex_session_close_req *req)
if (pxi == NULL)
return (EINVAL);
- req->pcr_stat = pxi->pxi_session->stat;
-
+ pipex_export_session_stats(pxi->pxi_session, &req->pcr_stat);
pppx_if_destroy(pxd, pxi);
return (0);
}
diff --git a/sys/net/pipex.c b/sys/net/pipex.c
index a78cbd6e051..c08261f81fb 100644
--- a/sys/net/pipex.c
+++ b/sys/net/pipex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pipex.c,v 1.133 2021/05/15 08:07:20 yasuoka Exp $ */
+/* $OpenBSD: pipex.c,v 1.134 2021/07/20 16:44:55 mvs Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -39,6 +39,7 @@
#include <sys/timeout.h>
#include <sys/kernel.h>
#include <sys/pool.h>
+#include <sys/percpu.h>
#include <net/if.h>
#include <net/if_types.h>
@@ -273,6 +274,8 @@ pipex_init_session(struct pipex_session **rsession,
session->ip_forward = 1;
+ session->stat_counters = counters_alloc(pxc_ncounters);
+
session->ip_address.sin_family = AF_INET;
session->ip_address.sin_len = sizeof(struct sockaddr_in);
session->ip_address.sin_addr = req->pr_ip_address;
@@ -361,6 +364,7 @@ pipex_rele_session(struct pipex_session *session)
{
if (session->mppe_recv.old_session_keys)
pool_put(&mppe_key_pool, session->mppe_recv.old_session_keys);
+ counters_free(session->stat_counters, pxc_ncounters);
pool_put(&pipex_session_pool, session);
}
@@ -466,12 +470,30 @@ pipex_notify_close_session(struct pipex_session *session)
{
NET_ASSERT_LOCKED();
session->state = PIPEX_STATE_CLOSE_WAIT;
- session->stat.idle_time = 0;
+ session->idle_time = 0;
LIST_INSERT_HEAD(&pipex_close_wait_list, session, state_list);
return (0);
}
+void
+pipex_export_session_stats(struct pipex_session *session,
+ struct pipex_statistics *stats)
+{
+ uint64_t counters[pxc_ncounters];
+
+ memset(stats, 0, sizeof(*stats));
+
+ counters_read(session->stat_counters, counters, pxc_ncounters);
+ stats->ipackets = counters[pxc_ipackets];
+ stats->ierrors = counters[pxc_ierrors];
+ stats->ibytes = counters[pxc_ibytes];
+ stats->opackets = counters[pxc_opackets];
+ stats->oerrors = counters[pxc_oerrors];
+ stats->obytes = counters[pxc_obytes];
+ stats->idle_time = session->idle_time;
+}
+
Static int
pipex_config_session(struct pipex_session_config_req *req, void *ownersc)
{
@@ -501,7 +523,7 @@ pipex_get_stat(struct pipex_session_stat_req *req, void *ownersc)
return (EINVAL);
if (session->ownersc != ownersc)
return (EINVAL);
- req->psr_stat = session->stat;
+ pipex_export_session_stats(session, &req->psr_stat);
return (0);
}
@@ -619,8 +641,8 @@ pipex_timer(void *ignored_arg)
if (session->timeout_sec == 0)
continue;
- session->stat.idle_time++;
- if (session->stat.idle_time < session->timeout_sec)
+ session->idle_time++;
+ if (session->idle_time < session->timeout_sec)
continue;
pipex_notify_close_session(session);
@@ -629,8 +651,8 @@ pipex_timer(void *ignored_arg)
case PIPEX_STATE_CLOSE_WAIT:
case PIPEX_STATE_CLOSE_WAIT2:
/* Waiting PIPEXDSESSION from userland */
- session->stat.idle_time++;
- if (session->stat.idle_time < PIPEX_CLOSE_TIMEOUT)
+ session->idle_time++;
+ if (session->idle_time < PIPEX_CLOSE_TIMEOUT)
continue;
/* Release the sessions when timeout */
pipex_unlink_session(session);
@@ -669,7 +691,7 @@ pipex_ip_output(struct mbuf *m0, struct pipex_session *session)
goto dropped;
if (is_idle == 0)
/* update expire time */
- session->stat.idle_time = 0;
+ session->idle_time = 0;
}
/* adjust tcpmss */
@@ -694,7 +716,8 @@ pipex_ip_output(struct mbuf *m0, struct pipex_session *session)
continue;
m = m_copym(m0, 0, M_COPYALL, M_NOWAIT);
if (m == NULL) {
- session_tmp->stat.oerrors++;
+ counters_inc(session->stat_counters,
+ pxc_oerrors);
continue;
}
pipex_ppp_output(m, session_tmp, PPP_IP);
@@ -706,7 +729,7 @@ pipex_ip_output(struct mbuf *m0, struct pipex_session *session)
drop:
m_freem(m0);
dropped:
- session->stat.oerrors++;
+ counters_inc(session->stat_counters, pxc_oerrors);
}
Static void
@@ -760,7 +783,7 @@ pipex_ppp_output(struct mbuf *m0, struct pipex_session *session, int proto)
return;
drop:
m_freem(m0);
- session->stat.oerrors++;
+ counters_inc(session->stat_counters, pxc_oerrors);
}
Static void
@@ -848,7 +871,7 @@ pipex_ppp_input(struct mbuf *m0, struct pipex_session *session, int decrypted)
return;
drop:
m_freem(m0);
- session->stat.ierrors++;
+ counters_inc(session->stat_counters, pxc_ierrors);
}
Static void
@@ -887,7 +910,7 @@ pipex_ip_input(struct mbuf *m0, struct pipex_session *session)
goto drop;
if (is_idle == 0)
/* update expire time */
- session->stat.idle_time = 0;
+ session->idle_time = 0;
}
/* adjust tcpmss */
@@ -912,8 +935,7 @@ pipex_ip_input(struct mbuf *m0, struct pipex_session *session)
#endif
counters_pkt(ifp->if_counters, ifc_ipackets, ifc_ibytes, len);
- session->stat.ipackets++;
- session->stat.ibytes += len;
+ counters_pkt(session->stat_counters, pxc_ipackets, pxc_ibytes, len);
ipv4_input(ifp, m0);
if_put(ifp);
@@ -921,7 +943,7 @@ pipex_ip_input(struct mbuf *m0, struct pipex_session *session)
return;
drop:
m_freem(m0);
- session->stat.ierrors++;
+ counters_inc(session->stat_counters, pxc_ierrors);
}
#ifdef INET6
@@ -961,8 +983,7 @@ pipex_ip6_input(struct mbuf *m0, struct pipex_session *session)
#endif
counters_pkt(ifp->if_counters, ifc_ipackets, ifc_ibytes, len);
- session->stat.ipackets++;
- session->stat.ibytes += len;
+ counters_pkt(session->stat_counters, pxc_ipackets, pxc_ibytes, len);
ipv6_input(ifp, m0);
if_put(ifp);
@@ -970,7 +991,7 @@ pipex_ip6_input(struct mbuf *m0, struct pipex_session *session)
return;
drop:
m_freem(m0);
- session->stat.ierrors++;
+ counters_inc(session->stat_counters, pxc_ierrors);
}
#endif
@@ -1030,7 +1051,7 @@ pipex_common_input(struct pipex_session *session, struct mbuf *m0, int hlen,
drop:
m_freem(m0);
- session->stat.ierrors++;
+ counters_inc(session->stat_counters, pxc_ierrors);
return (NULL);
not_ours:
@@ -1130,7 +1151,7 @@ pipex_pppoe_input(struct mbuf *m0, struct pipex_session *session)
== NULL)
return (NULL);
m_freem(m0);
- session->stat.ierrors++;
+ counters_inc(session->stat_counters, pxc_ierrors);
return (NULL);
}
@@ -1152,7 +1173,7 @@ pipex_pppoe_output(struct mbuf *m0, struct pipex_session *session)
if (m0 == NULL) {
PIPEX_DBG((NULL, LOG_ERR,
"<%s> cannot prepend header.", __func__));
- session->stat.oerrors++;
+ counters_inc(session->stat_counters, pxc_oerrors);
return;
}
padlen = ETHERMIN - m0->m_pkthdr.len;
@@ -1173,11 +1194,11 @@ pipex_pppoe_output(struct mbuf *m0, struct pipex_session *session)
ifp = if_get(session->proto.pppoe.over_ifidx);
if (ifp != NULL) {
ifp->if_output(ifp, m0, &session->peer.sa, NULL);
- session->stat.opackets++;
- session->stat.obytes += len;
+ counters_pkt(session->stat_counters, pxc_opackets,
+ pxc_obytes, len);
} else {
m_freem(m0);
- session->stat.oerrors++;
+ counters_inc(session->stat_counters, pxc_oerrors);
}
if_put(ifp);
}
@@ -1261,13 +1282,13 @@ pipex_pptp_output(struct mbuf *m0, struct pipex_session *session,
ip_send(m0);
if (len > 0) { /* network layer only */
/* countup statistics */
- session->stat.opackets++;
- session->stat.obytes += len;
+ counters_pkt(session->stat_counters, pxc_opackets,
+ pxc_obytes, len);
}
return;
drop:
- session->stat.oerrors++;
+ counters_inc(session->stat_counters, pxc_oerrors);
}
struct pipex_session *
@@ -1472,7 +1493,7 @@ out_seq:
/* FALLTHROUGH */
drop:
m_freem(m0);
- session->stat.ierrors++;
+ counters_inc(session->stat_counters, pxc_ierrors);
return (NULL);
}
@@ -1737,14 +1758,14 @@ pipex_l2tp_output(struct mbuf *m0, struct pipex_session *session)
if (datalen > 0) { /* network layer only */
/* countup statistics */
- session->stat.opackets++;
- session->stat.obytes += datalen;
+ counters_pkt(session->stat_counters, pxc_opackets,
+ pxc_obytes, datalen);
}
return;
drop:
m_freem(m0);
- session->stat.oerrors++;
+ counters_inc(session->stat_counters, pxc_oerrors);
}
struct pipex_session *
@@ -1912,7 +1933,7 @@ out_seq:
/* FALLTHROUGH */
drop:
m_freem(m0);
- session->stat.ierrors++;
+ counters_inc(session->stat_counters, pxc_ierrors);
return (NULL);
}
@@ -2323,7 +2344,7 @@ pipex_mppe_input(struct mbuf *m0, struct pipex_session *session)
return;
drop:
m_freem(m0);
- session->stat.ierrors++;
+ counters_inc(session->stat_counters, pxc_ierrors);
}
Static void
@@ -2412,7 +2433,7 @@ pipex_mppe_output(struct mbuf *m0, struct pipex_session *session,
return;
drop:
- session->stat.oerrors++;
+ counters_inc(session->stat_counters, pxc_oerrors);
}
Static void
@@ -2453,7 +2474,7 @@ pipex_ccp_input(struct mbuf *m0, struct pipex_session *session)
return;
drop:
m_freem(m0);
- session->stat.ierrors++;
+ counters_inc(session->stat_counters, pxc_ierrors);
}
Static int
@@ -2464,7 +2485,7 @@ pipex_ccp_output(struct pipex_session *session, int code, int id)
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL) {
- session->stat.oerrors++;
+ counters_inc(session->stat_counters, pxc_oerrors);
return (1);
}
m->m_pkthdr.len = m->m_len = 4;
diff --git a/sys/net/pipex_local.h b/sys/net/pipex_local.h
index a01fbda0fb5..1727cd74ce4 100644
--- a/sys/net/pipex_local.h
+++ b/sys/net/pipex_local.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pipex_local.h,v 1.41 2021/01/04 12:21:38 mvs Exp $ */
+/* $OpenBSD: pipex_local.h,v 1.42 2021/07/20 16:44:55 mvs Exp $ */
/*
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -148,6 +148,8 @@ struct pipex_l2tp_session {
};
#endif /* PIPEX_L2TP */
+struct cpumem;
+
/* pppac ip-extension sessoin table */
struct pipex_session {
struct radix_node ps4_rn[2];
@@ -166,6 +168,7 @@ struct pipex_session {
#define PIPEX_STATE_CLOSE_WAIT2 0x0003
#define PIPEX_STATE_CLOSED 0x0004
+ uint32_t idle_time; /* [N] idle time in seconds */
uint16_t ip_forward:1, /* [N] {en|dis}ableIP forwarding */
ip6_forward:1, /* [I] {en|dis}able IPv6 forwarding */
is_multicast:1, /* [I] virtual entry for multicast */
@@ -193,7 +196,9 @@ struct pipex_session {
mppe_recv, /* MPPE context for incoming */
mppe_send; /* MPPE context for outgoing */
#endif /*PIPEXMPPE */
- struct pipex_statistics stat; /* [N] statistics */
+
+ struct cpumem *stat_counters;
+
union {
#ifdef PIPEX_PPPOE
struct pipex_pppoe_session pppoe; /* context for PPPoE */
@@ -214,6 +219,16 @@ struct pipex_session {
} peer, local; /* [I] */
};
+enum pipex_counters {
+ pxc_ipackets, /* packets received from tunnel */
+ pxc_ierrors, /* error packets received from tunnel */
+ pxc_ibytes, /* number of received bytes from tunnel */
+ pxc_opackets, /* packets sent to tunnel */
+ pxc_oerrors, /* error packets on sending to tunnel */
+ pxc_obytes, /* number of sent bytes to tunnel */
+ pxc_ncounters
+};
+
/* gre header */
struct pipex_gre_header {
uint16_t flags; /* flags and version*/
@@ -384,6 +399,8 @@ void pipex_rele_session(struct pipex_session *);
int pipex_link_session(struct pipex_session *,
struct ifnet *, void *);
void pipex_unlink_session(struct pipex_session *);
+void pipex_export_session_stats(struct pipex_session *,
+ struct pipex_statistics *);
int pipex_config_session (struct pipex_session_config_req *,
void *);
int pipex_get_stat (struct pipex_session_stat_req *,