mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-20 11:11:24 +00:00
Style cleanup.
Approved by: glebius (mentor)
This commit is contained in:
parent
cd27e26ca7
commit
ae1be01f9e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=169602
@ -38,13 +38,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/systm.h>
|
|
||||||
#include <sys/kernel.h>
|
|
||||||
#include <sys/mbuf.h>
|
|
||||||
#include <sys/malloc.h>
|
|
||||||
#include <sys/ctype.h>
|
|
||||||
#include <sys/errno.h>
|
#include <sys/errno.h>
|
||||||
#include <sys/syslog.h>
|
#include <sys/kernel.h>
|
||||||
|
#include <sys/malloc.h>
|
||||||
|
#include <sys/mbuf.h>
|
||||||
|
|
||||||
#include <netgraph/ng_message.h>
|
#include <netgraph/ng_message.h>
|
||||||
#include <netgraph/ng_parse.h>
|
#include <netgraph/ng_parse.h>
|
||||||
@ -60,13 +57,13 @@ struct hookinfo {
|
|||||||
hook_p dest; /* destination hook */
|
hook_p dest; /* destination hook */
|
||||||
|
|
||||||
int64_t tc; /* commited token bucket counter */
|
int64_t tc; /* commited token bucket counter */
|
||||||
int64_t te; /* exceeded / peak token bucket counter */
|
int64_t te; /* exceeded/peak token bucket counter */
|
||||||
struct timeval lastRefill; /* last token refill time */
|
struct timeval lastRefill; /* last token refill time */
|
||||||
|
|
||||||
struct ng_car_hookconf conf; /* hook configuration */
|
struct ng_car_hookconf conf; /* hook configuration */
|
||||||
struct ng_car_hookstats stats; /* hook stats */
|
struct ng_car_hookstats stats; /* hook stats */
|
||||||
|
|
||||||
struct mbuf* q[NG_CAR_QUEUE_SIZE]; /* circular packet queue */
|
struct mbuf *q[NG_CAR_QUEUE_SIZE]; /* circular packet queue */
|
||||||
int q_first; /* first queue element */
|
int q_first; /* first queue element */
|
||||||
int q_last; /* last queue element */
|
int q_last; /* last queue element */
|
||||||
struct callout q_callout; /* periodic queue processing routine */
|
struct callout q_callout; /* periodic queue processing routine */
|
||||||
@ -188,9 +185,8 @@ ng_car_constructor(node_p node)
|
|||||||
{
|
{
|
||||||
priv_p priv;
|
priv_p priv;
|
||||||
|
|
||||||
/* Initialize private descriptor */
|
/* Initialize private descriptor. */
|
||||||
MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH,
|
priv = malloc(sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
||||||
M_NOWAIT | M_ZERO);
|
|
||||||
if (priv == NULL)
|
if (priv == NULL)
|
||||||
return (ENOMEM);
|
return (ENOMEM);
|
||||||
|
|
||||||
@ -235,7 +231,7 @@ ng_car_constructor(node_p node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a hook
|
* Add a hook.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
ng_car_newhook(node_p node, hook_p hook, const char *name)
|
ng_car_newhook(node_p node, hook_p hook, const char *name)
|
||||||
@ -258,7 +254,7 @@ ng_car_newhook(node_p node, hook_p hook, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Data has arrived
|
* Data has arrived.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
ng_car_rcvdata(hook_p hook, item_p item )
|
ng_car_rcvdata(hook_p hook, item_p item )
|
||||||
@ -287,7 +283,7 @@ ng_car_rcvdata(hook_p hook, item_p item )
|
|||||||
do { \
|
do { \
|
||||||
switch (a) { \
|
switch (a) { \
|
||||||
case NG_CAR_ACTION_FORWARD: \
|
case NG_CAR_ACTION_FORWARD: \
|
||||||
/* Do nothing */ \
|
/* Do nothing. */ \
|
||||||
break; \
|
break; \
|
||||||
case NG_CAR_ACTION_MARK: \
|
case NG_CAR_ACTION_MARK: \
|
||||||
/* XXX find a way to mark packets (mbuf tag?) */ \
|
/* XXX find a way to mark packets (mbuf tag?) */ \
|
||||||
@ -295,78 +291,76 @@ ng_car_rcvdata(hook_p hook, item_p item )
|
|||||||
break; \
|
break; \
|
||||||
case NG_CAR_ACTION_DROP: \
|
case NG_CAR_ACTION_DROP: \
|
||||||
default: \
|
default: \
|
||||||
/* Drop packet and return */ \
|
/* Drop packet and return. */ \
|
||||||
NG_FREE_ITEM(item); \
|
NG_FREE_ITEM(item); \
|
||||||
++hinfo->stats.droped_pkts; \
|
++hinfo->stats.droped_pkts; \
|
||||||
return 0; \
|
return (0); \
|
||||||
} \
|
} \
|
||||||
} \
|
} while (0)
|
||||||
while (0)
|
|
||||||
|
|
||||||
/* Check commited token bucket. */
|
/* Check commited token bucket. */
|
||||||
if (hinfo->tc - m->m_pkthdr.len >= 0) {
|
if (hinfo->tc - m->m_pkthdr.len >= 0) {
|
||||||
/* This packet is green */
|
/* This packet is green. */
|
||||||
++hinfo->stats.green_pkts;
|
++hinfo->stats.green_pkts;
|
||||||
hinfo->tc -= m->m_pkthdr.len;
|
hinfo->tc -= m->m_pkthdr.len;
|
||||||
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.green_action);
|
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.green_action);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Refill only if not green without it. */
|
/* Refill only if not green without it. */
|
||||||
ng_car_refillhook(hinfo);
|
ng_car_refillhook(hinfo);
|
||||||
|
|
||||||
/* Check commited token bucket again after refill. */
|
/* Check commited token bucket again after refill. */
|
||||||
if (hinfo->tc - m->m_pkthdr.len >= 0) {
|
if (hinfo->tc - m->m_pkthdr.len >= 0) {
|
||||||
/* This packet is green */
|
/* This packet is green */
|
||||||
++hinfo->stats.green_pkts;
|
++hinfo->stats.green_pkts;
|
||||||
hinfo->tc -= m->m_pkthdr.len;
|
hinfo->tc -= m->m_pkthdr.len;
|
||||||
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.green_action);
|
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.green_action);
|
||||||
|
|
||||||
/* If not green and mode is SHAPE, enqueue packet. */
|
/* If not green and mode is SHAPE, enqueue packet. */
|
||||||
} else if (hinfo->conf.mode == NG_CAR_SHAPE) {
|
} else if (hinfo->conf.mode == NG_CAR_SHAPE) {
|
||||||
ng_car_enqueue(hinfo, item);
|
ng_car_enqueue(hinfo, item);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
/* If not green and mode is RED, calculate probability. */
|
/* If not green and mode is RED, calculate probability. */
|
||||||
} else if (hinfo->conf.mode == NG_CAR_RED) {
|
} else if (hinfo->conf.mode == NG_CAR_RED) {
|
||||||
/* Is packet is bigger then extended burst? */
|
/* Is packet is bigger then extended burst? */
|
||||||
if (m->m_pkthdr.len - (hinfo->tc - m->m_pkthdr.len)
|
if (m->m_pkthdr.len - (hinfo->tc - m->m_pkthdr.len) >
|
||||||
> hinfo->conf.ebs) {
|
hinfo->conf.ebs) {
|
||||||
/* This packet is definitely red */
|
/* This packet is definitely red. */
|
||||||
++hinfo->stats.red_pkts;
|
++hinfo->stats.red_pkts;
|
||||||
hinfo->te = 0;
|
hinfo->te = 0;
|
||||||
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.red_action);
|
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.red_action);
|
||||||
|
|
||||||
/* Use token bucket to simulate RED-like drop probability. */
|
|
||||||
} else if (hinfo->te + (m->m_pkthdr.len - hinfo->tc)
|
|
||||||
< hinfo->conf.ebs) {
|
|
||||||
/* This packet is yellow */
|
|
||||||
++hinfo->stats.yellow_pkts;
|
|
||||||
hinfo->te += m->m_pkthdr.len - hinfo->tc;
|
|
||||||
hinfo->tc -= m->m_pkthdr.len; /* go to negative tokens */
|
|
||||||
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.yellow_action);
|
|
||||||
|
|
||||||
|
/* Use token bucket to simulate RED-like drop
|
||||||
|
probability. */
|
||||||
|
} else if (hinfo->te + (m->m_pkthdr.len - hinfo->tc) <
|
||||||
|
hinfo->conf.ebs) {
|
||||||
|
/* This packet is yellow */
|
||||||
|
++hinfo->stats.yellow_pkts;
|
||||||
|
hinfo->te += m->m_pkthdr.len - hinfo->tc;
|
||||||
|
/* Go to negative tokens. */
|
||||||
|
hinfo->tc -= m->m_pkthdr.len;
|
||||||
|
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.yellow_action);
|
||||||
|
} else {
|
||||||
|
/* This packet is probaly red. */
|
||||||
|
++hinfo->stats.red_pkts;
|
||||||
|
hinfo->te = 0;
|
||||||
|
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.red_action);
|
||||||
|
}
|
||||||
|
/* If not green and mode is SINGLE/DOUBLE RATE. */
|
||||||
} else {
|
} else {
|
||||||
/* This packet is probaly red */
|
/* Check extended token bucket. */
|
||||||
++hinfo->stats.red_pkts;
|
if (hinfo->te - m->m_pkthdr.len >= 0) {
|
||||||
hinfo->te = 0;
|
/* This packet is yellow */
|
||||||
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.red_action);
|
++hinfo->stats.yellow_pkts;
|
||||||
|
hinfo->te -= m->m_pkthdr.len;
|
||||||
|
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.yellow_action);
|
||||||
|
} else {
|
||||||
|
/* This packet is red */
|
||||||
|
++hinfo->stats.red_pkts;
|
||||||
|
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.red_action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If not green and mode is SINGLE/DOUBLE RATE. */
|
|
||||||
} else {
|
|
||||||
/* Check extended token bucket. */
|
|
||||||
if (hinfo->te - m->m_pkthdr.len >= 0) {
|
|
||||||
/* This packet is yellow */
|
|
||||||
++hinfo->stats.yellow_pkts;
|
|
||||||
hinfo->te -= m->m_pkthdr.len;
|
|
||||||
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.yellow_action);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
/* This packet is red */
|
|
||||||
++hinfo->stats.red_pkts;
|
|
||||||
NG_CAR_PERFORM_MATCH_ACTION(hinfo->conf.red_action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef NG_CAR_PERFORM_MATCH_ACTION
|
#undef NG_CAR_PERFORM_MATCH_ACTION
|
||||||
@ -376,11 +370,11 @@ ng_car_rcvdata(hook_p hook, item_p item )
|
|||||||
++hinfo->stats.errors;
|
++hinfo->stats.errors;
|
||||||
++hinfo->stats.passed_pkts;
|
++hinfo->stats.passed_pkts;
|
||||||
|
|
||||||
return error;
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Receive a control message
|
* Receive a control message.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
ng_car_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
ng_car_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
||||||
@ -505,9 +499,8 @@ ng_car_shutdown(node_p node)
|
|||||||
|
|
||||||
mtx_destroy(&priv->upper.q_mtx);
|
mtx_destroy(&priv->upper.q_mtx);
|
||||||
mtx_destroy(&priv->lower.q_mtx);
|
mtx_destroy(&priv->lower.q_mtx);
|
||||||
NG_NODE_SET_PRIVATE(node, NULL);
|
|
||||||
NG_NODE_UNREF(priv->node);
|
NG_NODE_UNREF(priv->node);
|
||||||
FREE(priv, M_NETGRAPH);
|
free(priv, M_NETGRAPH);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,8 +601,6 @@ ng_car_refillhook(struct hookinfo *h)
|
|||||||
|
|
||||||
/* Remember this moment. */
|
/* Remember this moment. */
|
||||||
h->lastRefill = newt;
|
h->lastRefill = newt;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -646,9 +637,8 @@ ng_car_q_event(node_p node, hook_p hook, void *arg, int arg2)
|
|||||||
|
|
||||||
/* Send packet. */
|
/* Send packet. */
|
||||||
m = hinfo->q[hinfo->q_first];
|
m = hinfo->q[hinfo->q_first];
|
||||||
if ((item = ng_package_data(m, NG_NOFLAGS)) != NULL) {
|
if ((item = ng_package_data(m, NG_NOFLAGS)) != NULL)
|
||||||
NG_FWD_ITEM_HOOK(error, item, hinfo->dest);
|
NG_FWD_ITEM_HOOK(error, item, hinfo->dest);
|
||||||
}
|
|
||||||
|
|
||||||
/* Get next one. */
|
/* Get next one. */
|
||||||
hinfo->q_first++;
|
hinfo->q_first++;
|
||||||
@ -666,10 +656,9 @@ ng_car_q_event(node_p node, hook_p hook, void *arg, int arg2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If something left */
|
/* If something left */
|
||||||
if (hinfo->q_first != hinfo->q_last) {
|
if (hinfo->q_first != hinfo->q_last)
|
||||||
/* schedule queue processing. */
|
/* Schedule queue processing. */
|
||||||
ng_car_schedule(hinfo);
|
ng_car_schedule(hinfo);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -684,18 +673,18 @@ ng_car_enqueue(struct hookinfo *hinfo, item_p item)
|
|||||||
NGI_GET_M(item, m);
|
NGI_GET_M(item, m);
|
||||||
NG_FREE_ITEM(item);
|
NG_FREE_ITEM(item);
|
||||||
|
|
||||||
/* Lock queue mutex */
|
/* Lock queue mutex. */
|
||||||
mtx_lock(&hinfo->q_mtx);
|
mtx_lock(&hinfo->q_mtx);
|
||||||
|
|
||||||
/* Calculate used queue length */
|
/* Calculate used queue length. */
|
||||||
len = hinfo->q_last - hinfo->q_first;
|
len = hinfo->q_last - hinfo->q_first;
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len += NG_CAR_QUEUE_SIZE;
|
len += NG_CAR_QUEUE_SIZE;
|
||||||
|
|
||||||
/* If queue is overflowed or we have no RED tokens */
|
/* If queue is overflowed or we have no RED tokens. */
|
||||||
if ((len >= (NG_CAR_QUEUE_SIZE - 1)) ||
|
if ((len >= (NG_CAR_QUEUE_SIZE - 1)) ||
|
||||||
(hinfo->te + len >= NG_CAR_QUEUE_SIZE)) {
|
(hinfo->te + len >= NG_CAR_QUEUE_SIZE)) {
|
||||||
/* drop packet. */
|
/* Drop packet. */
|
||||||
++hinfo->stats.red_pkts;
|
++hinfo->stats.red_pkts;
|
||||||
NG_FREE_M(m);
|
NG_FREE_M(m);
|
||||||
|
|
||||||
@ -714,15 +703,15 @@ ng_car_enqueue(struct hookinfo *hinfo, item_p item)
|
|||||||
if (len > NG_CAR_QUEUE_MIN_TH)
|
if (len > NG_CAR_QUEUE_MIN_TH)
|
||||||
hinfo->te += len - NG_CAR_QUEUE_MIN_TH;
|
hinfo->te += len - NG_CAR_QUEUE_MIN_TH;
|
||||||
|
|
||||||
/* If this is a first packet it the queue */
|
/* If this is a first packet in the queue. */
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
hinfo->tc -= m->m_pkthdr.len;
|
hinfo->tc -= m->m_pkthdr.len;
|
||||||
|
|
||||||
/* schedule queue processing. */
|
/* Schedule queue processing. */
|
||||||
ng_car_schedule(hinfo);
|
ng_car_schedule(hinfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unlock queue mutex */
|
/* Unlock queue mutex. */
|
||||||
mtx_unlock(&hinfo->q_mtx);
|
mtx_unlock(&hinfo->q_mtx);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user