From 5c63f81fd40c7d5cc0b6a2506a0b6d1e559cbe57 Mon Sep 17 00:00:00 2001 From: Archie Cobbs Date: Thu, 27 Jan 2000 01:32:53 +0000 Subject: [PATCH] Add control message ASCII conversion for this node type. --- sys/netgraph/ng_tee.c | 44 +++++++++++++++++++++++++++++++++++++++---- sys/netgraph/ng_tee.h | 22 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/sys/netgraph/ng_tee.c b/sys/netgraph/ng_tee.c index 575c8702c7a3..ec774f20d2af 100644 --- a/sys/netgraph/ng_tee.c +++ b/sys/netgraph/ng_tee.c @@ -57,6 +57,7 @@ #include #include #include +#include #include /* Per hook info */ @@ -83,8 +84,43 @@ static ng_newhook_t ngt_newhook; static ng_rcvdata_t ngt_rcvdata; static ng_disconnect_t ngt_disconnect; +/* Parse type for struct ng_tee_hookstat */ +static const struct ng_parse_struct_info + ng_tee_hookstat_type_info = NG_TEE_HOOKSTAT_INFO; +static const struct ng_parse_type ng_tee_hookstat_type = { + &ng_parse_struct_type, + &ng_tee_hookstat_type_info, +}; + +/* Parse type for struct ng_tee_stats */ +static const struct ng_parse_struct_info + ng_tee_stats_type_info = NG_TEE_STATS_INFO(&ng_tee_hookstat_type); +static const struct ng_parse_type ng_tee_stats_type = { + &ng_parse_struct_type, + &ng_tee_stats_type_info, +}; + +/* List of commands and how to convert arguments to/from ASCII */ +static const struct ng_cmdlist ng_tee_cmds[] = { + { + NGM_TEE_COOKIE, + NGM_TEE_GET_STATS, + "getstats", + NULL, + &ng_tee_stats_type + }, + { + NGM_TEE_COOKIE, + NGM_TEE_CLR_STATS, + "clrstats", + NULL, + NULL + }, + { 0 } +}; + /* Netgraph type descriptor */ -static struct ng_type typestruct = { +static struct ng_type ng_tee_typestruct = { NG_VERSION, NG_TEE_NODE_TYPE, NULL, @@ -97,9 +133,9 @@ static struct ng_type typestruct = { ngt_rcvdata, ngt_rcvdata, ngt_disconnect, - NULL + ng_tee_cmds }; -NETGRAPH_INIT(tee, &typestruct); +NETGRAPH_INIT(tee, &ng_tee_typestruct); /* * Node constructor @@ -115,7 +151,7 @@ ngt_constructor(node_p *nodep) return (ENOMEM); bzero(privdata, sizeof(*privdata)); - if ((error = ng_make_node_common(&typestruct, nodep))) { + if ((error = ng_make_node_common(&ng_tee_typestruct, nodep))) { FREE(privdata, M_NETGRAPH); return (error); } diff --git a/sys/netgraph/ng_tee.h b/sys/netgraph/ng_tee.h index 2c1959aa2107..f70b9f3a8684 100644 --- a/sys/netgraph/ng_tee.h +++ b/sys/netgraph/ng_tee.h @@ -61,6 +61,17 @@ struct ng_tee_hookstat { u_int64_t outFrames; }; +/* Keep this in sync with the above structure definition */ +#define NG_TEE_HOOKSTAT_INFO { \ + { \ + { "inOctets", &ng_parse_int64_type }, \ + { "inFrames", &ng_parse_int64_type }, \ + { "outOctets", &ng_parse_int64_type }, \ + { "outFrames", &ng_parse_int64_type }, \ + { NULL }, \ + } \ +} + /* Statistics structure returned by NGM_TEE_GET_STATS */ struct ng_tee_stats { struct ng_tee_hookstat right; @@ -69,6 +80,17 @@ struct ng_tee_stats { struct ng_tee_hookstat left2right; }; +/* Keep this in sync with the above structure definition */ +#define NG_TEE_STATS_INFO(hstype) { \ + { \ + { "right", (hstype) }, \ + { "left", (hstype) }, \ + { "right2left", (hstype) }, \ + { "left2right", (hstype) }, \ + { NULL }, \ + } \ +} + /* Netgraph commands */ enum { NGM_TEE_GET_STATS = 1, /* get stats */