46#include <sys/kernel.h>
47#include <sys/malloc.h>
55#include <netinet/in.h>
56#include <netinet/in_systm.h>
57#include <netinet/ip.h>
77 struct p_head packet_head;
90 struct timeval qin_utime;
110#define FIFO_VTIME_SORT(plen) \
111 if (hinfo->cfg.wfq && hinfo->cfg.bandwidth) { \
112 ngp_f->vtime.tv_usec = now->tv_usec + ((uint64_t) (plen) \
113 + priv->overhead ) * hinfo->run.fifo_queues * \
114 8000000 / hinfo->cfg.bandwidth; \
115 ngp_f->vtime.tv_sec = now->tv_sec + \
116 ngp_f->vtime.tv_usec / 1000000; \
117 ngp_f->vtime.tv_usec = ngp_f->vtime.tv_usec % 1000000; \
118 TAILQ_FOREACH(ngp_f1, &hinfo->fifo_head, fifo_le) \
119 if (ngp_f1->vtime.tv_sec > ngp_f->vtime.tv_sec || \
120 (ngp_f1->vtime.tv_sec == ngp_f->vtime.tv_sec && \
121 ngp_f1->vtime.tv_usec > ngp_f->vtime.tv_usec)) \
123 if (ngp_f1 == NULL) \
124 TAILQ_INSERT_TAIL(&hinfo->fifo_head, ngp_f, fifo_le); \
126 TAILQ_INSERT_BEFORE(ngp_f1, ngp_f, fifo_le); \
128 TAILQ_INSERT_TAIL(&hinfo->fifo_head, ngp_f, fifo_le); \
211 .name =
"getclrstats",
256 priv = malloc(
sizeof(*
priv), M_NG_PIPE, M_ZERO | M_WAITOK);
287 hinfo->cfg.qin_size_limit = 50;
289 hinfo->cfg.droptail = 1;
290 TAILQ_INIT(&hinfo->fifo_head);
291 TAILQ_INIT(&hinfo->qout_head);
301 struct ng_mesg *msg, *flow_msg;
306 int prev_down, now_down,
cmd;
317 sizeof(*
stats), M_NOWAIT);
324 sizeof(
stats->downstream));
326 sizeof(
stats->upstream));
376 if (cfg->
delay == -1)
378 else if (cfg->
delay > 0 && cfg->
delay < 10000000)
390 priv->overhead = 8+4+12;
402 priv->header_offset = 0;
416 if (prev_down != now_down) {
425 if (flow_msg != NULL)
433 if (flow_msg != NULL)
460 if (new->ber == -1) {
463 free(hinfo->ber_p, M_NG_PIPE);
466 }
else if (new->ber >= 1 && new->ber <= 1000000000000) {
467 static const uint64_t one = 0x1000000000000;
471 if (hinfo->ber_p == NULL)
474 M_NG_PIPE, M_WAITOK);
475 current->
ber =
new->ber;
486 p0 = one - one /
new->ber;
489 hinfo->ber_p[fsize] = p;
490 for (i = 0; i < 8; i++)
491 p = (p * (p0 & 0xffff) >> 48) +
492 (p * ((p0 >> 16) & 0xffff) >> 32) +
493 (p * (p0 >> 32) >> 16);
497 if (new->qin_size_limit == -1)
499 else if (new->qin_size_limit >= 5)
502 if (new->qout_size_limit == -1)
504 else if (new->qout_size_limit >= 5)
507 if (new->duplicate == -1)
509 else if (new->duplicate > 0 && new->duplicate <= 50)
529 current->
drr =
new->drr;
544 if (new->bandwidth == -1) {
549 }
else if (new->bandwidth >= 100 && new->bandwidth <= 1000000000)
568 struct ip *ip = (
struct ip *)(mtod(m, u_char *) + offset);
570 if (m->m_len <
sizeof(
struct ip) + offset ||
571 ip->ip_v != 4 || ip->ip_hl << 2 !=
sizeof(
struct ip))
574 i = ((u_int64_t) ip->ip_src.s_addr ^
575 ((u_int64_t) ip->ip_src.s_addr << 13) ^
576 ((u_int64_t) ip->ip_dst.s_addr << 7) ^
577 ((u_int64_t) ip->ip_dst.s_addr << 19));
578 return (i ^ (i >> 32));
593 struct timeval uuptime;
594 struct timeval *now = &uuptime;
595 struct ngp_fifo *ngp_f = NULL, *ngp_f1;
606 if (hinfo->run.qin_frames == 0 && hinfo->run.qout_frames == 0 &&
615 plen =
NGI_M(item)->m_pkthdr.len;
620 hinfo->
stats.out_disc_frames++;
621 hinfo->
stats.out_disc_octets += plen;
623 hinfo->
stats.fwd_frames++;
624 hinfo->
stats.fwd_octets += plen;
635 if (hinfo->run.qin_frames == 0) {
636 struct timeval *when = &hinfo->qin_utime;
637 if (when->tv_sec < now->tv_sec || (when->tv_sec == now->tv_sec
638 && when->tv_usec < now->tv_usec)) {
639 when->tv_sec = now->tv_sec;
640 when->tv_usec = now->tv_usec;
645 ngp_h = uma_zalloc(
ngp_zone, M_NOWAIT);
646 KASSERT((ngp_h != NULL), (
"ngp_h zalloc failed (1)"));
648 KASSERT(m != NULL, (
"NGI_GET_M failed"));
658 TAILQ_FOREACH(ngp_f, &hinfo->fifo_head, fifo_le)
659 if (hash == ngp_f->hash)
662 ngp_f = uma_zalloc(
ngp_zone, M_NOWAIT);
663 KASSERT(ngp_h != NULL, (
"ngp_h zalloc failed (2)"));
664 TAILQ_INIT(&ngp_f->packet_head);
667 ngp_f->rr_deficit = hinfo->cfg.drr;
668 hinfo->run.fifo_queues++;
669 TAILQ_INSERT_TAIL(&ngp_f->packet_head, ngp_h, ngp_link);
672 TAILQ_INSERT_TAIL(&ngp_f->packet_head, ngp_h, ngp_link);
675 hinfo->run.qin_frames++;
676 hinfo->run.qin_octets += m->m_pkthdr.len;
679 if (hinfo->run.qin_frames > hinfo->cfg.qin_size_limit) {
684 TAILQ_FOREACH(ngp_f1, &hinfo->fifo_head, fifo_le)
685 if (ngp_f1->packets > longest) {
686 longest = ngp_f1->packets;
691 if (hinfo->cfg.drophead)
692 ngp_h = TAILQ_FIRST(&ngp_f->packet_head);
694 ngp_h = TAILQ_LAST(&ngp_f->packet_head, p_head);
695 TAILQ_REMOVE(&ngp_f->packet_head, ngp_h, ngp_link);
698 hinfo->run.qin_octets -= m1->m_pkthdr.len;
699 hinfo->
stats.in_disc_octets += m1->m_pkthdr.len;
701 if (--(ngp_f->packets) == 0) {
702 TAILQ_REMOVE(&hinfo->fifo_head, ngp_f, fifo_le);
704 hinfo->run.fifo_queues--;
706 hinfo->run.qin_frames--;
707 hinfo->
stats.in_disc_frames++;
732 static uint64_t rand, oldrand;
738 struct timeval *when;
749 while ((ngp_f = TAILQ_FIRST(&hinfo->fifo_head))) {
750 when = &hinfo->qin_utime;
751 if (when->tv_sec > now->tv_sec || (when->tv_sec == now->tv_sec
752 && when->tv_usec > now->tv_usec))
755 ngp_h = TAILQ_FIRST(&ngp_f->packet_head);
759 if (hinfo->cfg.drr) {
760 if (ngp_f->rr_deficit >= m->m_pkthdr.len) {
761 ngp_f->rr_deficit -= m->m_pkthdr.len;
763 ngp_f->rr_deficit += hinfo->cfg.drr;
764 TAILQ_REMOVE(&hinfo->fifo_head, ngp_f, fifo_le);
765 TAILQ_INSERT_TAIL(&hinfo->fifo_head,
775 if (hinfo->cfg.duplicate &&
776 random() % 100 <= hinfo->cfg.duplicate) {
777 ngp_h = uma_zalloc(
ngp_zone, M_NOWAIT);
778 KASSERT(ngp_h != NULL, (
"ngp_h zalloc failed (3)"));
779 m = m_dup(m, M_NOWAIT);
780 KASSERT(m != NULL, (
"m_dup failed"));
783 TAILQ_REMOVE(&ngp_f->packet_head, ngp_h, ngp_link);
784 hinfo->run.qin_frames--;
785 hinfo->run.qin_octets -= m->m_pkthdr.len;
790 if (hinfo->cfg.bandwidth) {
791 hinfo->qin_utime.tv_usec +=
792 ((uint64_t) m->m_pkthdr.len +
priv->overhead ) *
793 8000000 / hinfo->cfg.bandwidth;
794 hinfo->qin_utime.tv_sec +=
795 hinfo->qin_utime.tv_usec / 1000000;
796 hinfo->qin_utime.tv_usec =
797 hinfo->qin_utime.tv_usec % 1000000;
800 when->tv_sec = hinfo->qin_utime.tv_sec;
801 when->tv_usec = hinfo->qin_utime.tv_usec;
804 if (ngp_f->packets) {
805 if (hinfo->cfg.wfq) {
806 TAILQ_REMOVE(&hinfo->fifo_head, ngp_f, fifo_le);
808 &ngp_f->packet_head)->m->m_pkthdr.len)
811 TAILQ_REMOVE(&hinfo->fifo_head, ngp_f, fifo_le);
813 hinfo->run.fifo_queues--;
817 if (hinfo->cfg.ber) {
820 if (((oldrand ^ rand) << 17) >=
821 hinfo->ber_p[
priv->overhead + m->m_pkthdr.len]) {
822 hinfo->
stats.out_disc_frames++;
823 hinfo->
stats.out_disc_octets += m->m_pkthdr.len;
831 if (hinfo->cfg.qout_size_limit &&
832 hinfo->run.qout_frames>=hinfo->cfg.qout_size_limit) {
833 hinfo->
stats.out_disc_frames++;
834 hinfo->
stats.out_disc_octets += m->m_pkthdr.len;
841 when->tv_usec +=
priv->delay;
842 when->tv_sec += when->tv_usec / 1000000;
843 when->tv_usec = when->tv_usec % 1000000;
846 TAILQ_INSERT_TAIL(&hinfo->qout_head, ngp_h, ngp_link);
847 hinfo->run.qout_frames++;
848 hinfo->run.qout_octets += m->m_pkthdr.len;
852 while ((ngp_h = TAILQ_FIRST(&hinfo->qout_head))) {
855 if (when->tv_sec > now->tv_sec ||
856 (when->tv_sec == now->tv_sec &&
857 when->tv_usec > now->tv_usec))
861 plen = m->m_pkthdr.len;
862 hinfo->run.qout_frames--;
863 hinfo->run.qout_octets -= plen;
866 TAILQ_REMOVE(&hinfo->qout_head, ngp_h, ngp_link);
871 hinfo->
stats.out_disc_frames++;
872 hinfo->
stats.out_disc_octets += plen;
874 hinfo->
stats.fwd_frames++;
875 hinfo->
stats.fwd_octets += plen;
879 if ((hinfo->run.qin_frames != 0 || hinfo->run.qout_frames != 0) &&
880 !
priv->timer_scheduled) {
882 priv->timer_scheduled = 1;
896 priv->timer_scheduled = 0;
917 if (
priv->timer_scheduled)
928 free(
priv, M_NG_PIPE);
942 KASSERT(hinfo != NULL, (
"%s: null info", __FUNCTION__));
946 while ((ngp_f = TAILQ_FIRST(&hinfo->fifo_head))) {
947 while ((ngp_h = TAILQ_FIRST(&ngp_f->packet_head))) {
948 TAILQ_REMOVE(&ngp_f->packet_head, ngp_h, ngp_link);
952 TAILQ_REMOVE(&hinfo->fifo_head, ngp_f, fifo_le);
957 while ((ngp_h = TAILQ_FIRST(&hinfo->qout_head))) {
958 TAILQ_REMOVE(&hinfo->qout_head, ngp_h, ngp_link);
965 free(hinfo->ber_p, M_NG_PIPE);
978 sizeof (
struct ngp_fifo)), NULL, NULL, NULL, NULL,
981 panic(
"ng_pipe: couldn't allocate descriptor zone");
#define NG_HOOK_NODE(hook)
int ng_rcvmsg_t(node_p node, item_p item, hook_p lasthook)
#define NG_FWD_ITEM_HOOK(error, item, hook)
int ng_disconnect_t(hook_p hook)
#define NG_NODE_SET_PRIVATE(node, val)
#define NG_RESPOND_MSG(error, here, item, resp)
int ng_rmhook_self(hook_p hook)
#define NG_NODE_FORCE_WRITER(node)
#define NG_NODE_UNREF(node)
#define NG_HOOK_SET_PRIVATE(hook, val)
#define ng_callout_init(c)
int ng_rcvdata_t(hook_p hook, item_p item)
int ng_shutdown_t(node_p node)
int ng_uncallout(struct callout *c, node_p node)
#define NG_FREE_ITEM(item)
int ng_constructor_t(node_p node)
#define NG_SEND_DATA(error, hook, m, x)
int ng_bypass(hook_p hook1, hook_p hook2)
#define NGI_GET_MSG(i, m)
#define NG_NODE_PRIVATE(node)
#define NG_SEND_MSG_HOOK(error, here, msg, hook, retaddr)
int ng_callout(struct callout *c, node_p node, hook_p hook, int ticks, ng_item_fn *fn, void *arg1, int arg2)
int ng_newhook_t(node_p node, hook_p hook, const char *name)
#define NG_HOOK_PRIVATE(hook)
#define NG_MKRESPONSE(rsp, msg, len, how)
#define NG_MKMESSAGE(msg, cookie, cmdid, len, how)
const struct ng_parse_type ng_parse_struct_type
static ng_constructor_t ngp_constructor
static const struct ng_parse_struct_field ng_pipe_hookrun_type_fields[]
static ng_newhook_t ngp_newhook
static const struct ng_parse_type ng_pipe_hookrun_type
static const struct ng_parse_struct_field ng_pipe_run_type_fields[]
static void pipe_dequeue(struct hookinfo *, struct timeval *)
static const struct ng_parse_type ng_pipe_run_type
static void parse_cfg(struct ng_pipe_hookcfg *, struct ng_pipe_hookcfg *, struct hookinfo *, priv_p)
static const struct ng_parse_type ng_pipe_hookcfg_type
static const struct ng_parse_type ng_pipe_cfg_type
static ng_disconnect_t ngp_disconnect
static MALLOC_DEFINE(M_NG_PIPE, "ng_pipe", "ng_pipe")
struct node_priv * priv_p
static const struct ng_parse_struct_field ng_pipe_stats_type_fields[]
TAILQ_HEAD(p_head, ngp_hdr)
static const struct ng_parse_struct_field ng_pipe_cfg_type_fields[]
static ng_rcvdata_t ngp_rcvdata
static struct ng_type ng_pipe_typestruct
static const struct ng_parse_struct_field ng_pipe_hookstat_type_fields[]
static int ip_hash(struct mbuf *m, int offset)
static ng_shutdown_t ngp_shutdown
static const struct ng_cmdlist ngp_cmds[]
#define FIFO_VTIME_SORT(plen)
static uma_zone_t ngp_zone
static void ngp_callout(node_p, hook_p, void *, int)
static ng_rcvmsg_t ngp_rcvmsg
static int ngp_modevent(module_t, int, void *)
static const struct ng_parse_type ng_pipe_stats_type
static const struct ng_parse_type ng_pipe_hookstat_type
NETGRAPH_INIT(pipe, &ng_pipe_typestruct)
static const struct ng_parse_struct_field ng_pipe_hookcfg_type_fields[]
#define NG_PIPE_HOOK_LOWER
#define NG_PIPE_HOOKSTAT_INFO
#define NG_PIPE_NODE_TYPE
#define NG_PIPE_HOOKCFG_INFO
#define NG_PIPE_HOOK_UPPER
#define NG_PIPE_HOOKRUN_INFO
#define NG_PIPE_STATS_INFO(hstype)
#define NG_PIPE_CFG_INFO(hstype)
#define NG_PIPE_RUN_INFO(hstype)
typedef TAILQ_ENTRY(sscfu_sig) sscfu_sigq_link_t
struct ng_car_hookstats stats
struct ng_mesg::ng_msghdr header
struct ng_pipe_hookcfg upstream
struct ng_pipe_hookcfg downstream
u_int32_t qout_size_limit
struct ng_pipe_hookrun upstream
struct ng_pipe_hookrun downstream