Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net/npf npf_generic_fsm and npf_tcp_fsm: use uint8_t and...
details: https://anonhg.NetBSD.org/src/rev/86f975057fb7
branches: trunk
changeset: 791111:86f975057fb7
user: rmind <rmind%NetBSD.org@localhost>
date: Mon Nov 04 22:17:21 2013 +0000
description:
npf_generic_fsm and npf_tcp_fsm: use uint8_t and make the arrays more dense.
diffstat:
sys/net/npf/npf_impl.h | 4 ++--
sys/net/npf/npf_state.c | 9 ++++-----
sys/net/npf/npf_state_tcp.c | 23 ++++++++++-------------
3 files changed, 16 insertions(+), 20 deletions(-)
diffs (143 lines):
diff -r 1ff80e3492c4 -r 86f975057fb7 sys/net/npf/npf_impl.h
--- a/sys/net/npf/npf_impl.h Mon Nov 04 21:59:15 2013 +0000
+++ b/sys/net/npf/npf_impl.h Mon Nov 04 22:17:21 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_impl.h,v 1.35 2013/10/29 16:39:10 rmind Exp $ */
+/* $NetBSD: npf_impl.h,v 1.36 2013/11/04 22:17:21 rmind Exp $ */
/*-
* Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
@@ -120,7 +120,7 @@
typedef struct {
kmutex_t nst_lock;
- int nst_state;
+ u_int nst_state;
npf_tcpstate_t nst_tcpst[2];
} npf_state_t;
diff -r 1ff80e3492c4 -r 86f975057fb7 sys/net/npf/npf_state.c
--- a/sys/net/npf/npf_state.c Mon Nov 04 21:59:15 2013 +0000
+++ b/sys/net/npf/npf_state.c Mon Nov 04 22:17:21 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_state.c,v 1.14 2013/02/09 03:35:32 rmind Exp $ */
+/* $NetBSD: npf_state.c,v 1.15 2013/11/04 22:17:21 rmind Exp $ */
/*-
* Copyright (c) 2010-2012 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_state.c,v 1.14 2013/02/09 03:35:32 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_state.c,v 1.15 2013/11/04 22:17:21 rmind Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -54,7 +54,7 @@
#define NPF_ANY_SESSION_ESTABLISHED 2
#define NPF_ANY_SESSION_NSTATES 3
-static const int npf_generic_fsm[NPF_ANY_SESSION_NSTATES][2] = {
+static const uint8_t npf_generic_fsm[NPF_ANY_SESSION_NSTATES][2] = {
[NPF_ANY_SESSION_CLOSED] = {
[NPF_FLOW_FORW] = NPF_ANY_SESSION_NEW,
},
@@ -124,7 +124,6 @@
void
npf_state_destroy(npf_state_t *nst)
{
-
nst->nst_state = 0;
mutex_destroy(&nst->nst_lock);
}
@@ -170,7 +169,7 @@
int
npf_state_etime(const npf_state_t *nst, const int proto)
{
- const int state = nst->nst_state;
+ const u_int state = nst->nst_state;
int timeout = 0;
switch (proto) {
diff -r 1ff80e3492c4 -r 86f975057fb7 sys/net/npf/npf_state_tcp.c
--- a/sys/net/npf/npf_state_tcp.c Mon Nov 04 21:59:15 2013 +0000
+++ b/sys/net/npf/npf_state_tcp.c Mon Nov 04 22:17:21 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: npf_state_tcp.c,v 1.12 2012/12/24 19:05:45 rmind Exp $ */
+/* $NetBSD: npf_state_tcp.c,v 1.13 2013/11/04 22:17:21 rmind Exp $ */
/*-
* Copyright (c) 2010-2012 The NetBSD Foundation, Inc.
@@ -34,16 +34,11 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_state_tcp.c,v 1.12 2012/12/24 19:05:45 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_state_tcp.c,v 1.13 2013/11/04 22:17:21 rmind Exp $");
#include <sys/param.h>
#include <sys/types.h>
-#ifndef _KERNEL
-#include <stdio.h>
-#include <stdbool.h>
-#include <inttypes.h>
-#endif
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/tcp_seq.h>
@@ -54,7 +49,7 @@
* NPF TCP states. Note: these states are different from the TCP FSM
* states of RFC 793. The packet filter is a man-in-the-middle.
*/
-#define NPF_TCPS_OK (-1)
+#define NPF_TCPS_OK 255
#define NPF_TCPS_CLOSED 0
#define NPF_TCPS_SYN_SENT 1
#define NPF_TCPS_SIMSYN_SENT 2
@@ -110,7 +105,7 @@
#define TCPFC_COUNT 5
static inline u_int
-npf_tcpfl2case(const int tcpfl)
+npf_tcpfl2case(const u_int tcpfl)
{
u_int i, c;
@@ -150,7 +145,7 @@
* Note that this state is different from the state in each end (host).
*/
-static const int npf_tcp_fsm[NPF_TCP_NSTATES][2][TCPFC_COUNT] = {
+static const uint8_t npf_tcp_fsm[NPF_TCP_NSTATES][2][TCPFC_COUNT] = {
[NPF_TCPS_CLOSED] = {
[NPF_FLOW_FORW] = {
/* Handshake (1): initial SYN. */
@@ -368,6 +363,7 @@
/* Done. */
return true;
}
+
if (fstate->nst_end == 0) {
/*
* Should be a SYN-ACK reply to SYN. If SYN is not set,
@@ -464,14 +460,15 @@
npf_state_tcp(npf_cache_t *npc, nbuf_t *nbuf, npf_state_t *nst, int di)
{
const struct tcphdr * const th = npc->npc_l4.tcp;
- const int tcpfl = th->th_flags, state = nst->nst_state;
- int nstate;
+ const u_int tcpfl = th->th_flags, state = nst->nst_state;
+ u_int nstate;
KASSERT(nst->nst_state == 0 || mutex_owned(&nst->nst_lock));
+ KASSERT(nst->nst_state < NPF_TCP_NSTATES);
/* Look for a transition to a new state. */
if (__predict_true((tcpfl & TH_RST) == 0)) {
- const int flagcase = npf_tcpfl2case(tcpfl);
+ const u_int flagcase = npf_tcpfl2case(tcpfl);
nstate = npf_tcp_fsm[state][di][flagcase];
} else if (state == NPF_TCPS_TIME_WAIT) {
/* Prevent TIME-WAIT assassination (RFC 1337). */
Home |
Main Index |
Thread Index |
Old Index