diff options
author | archie <archie@FreeBSD.org> | 1999-12-01 19:40:37 +0000 |
---|---|---|
committer | archie <archie@FreeBSD.org> | 1999-12-01 19:40:37 +0000 |
commit | a5c64fe8bbf78d360a1400b91af82ca843efc407 (patch) | |
tree | 6899eb342e2764f9f2a76fd966e71dc263272985 /sys | |
parent | 579c93e79305fd5f203f4fb5546c42fa53c347c0 (diff) | |
download | FreeBSD-src-a5c64fe8bbf78d360a1400b91af82ca843efc407.zip FreeBSD-src-a5c64fe8bbf78d360a1400b91af82ca843efc407.tar.gz |
Show how to supply a struct ng_cmdlist for (de)asciification
of control messages.
Suggested by: julian
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netgraph/ng_sample.c | 41 | ||||
-rw-r--r-- | sys/netgraph/ng_sample.h | 15 |
2 files changed, 49 insertions, 7 deletions
diff --git a/sys/netgraph/ng_sample.c b/sys/netgraph/ng_sample.c index 688cd81..5269954 100644 --- a/sys/netgraph/ng_sample.c +++ b/sys/netgraph/ng_sample.c @@ -45,10 +45,12 @@ #include <sys/kernel.h> #include <sys/mbuf.h> #include <sys/malloc.h> +#include <sys/ctype.h> #include <sys/errno.h> #include <sys/syslog.h> #include <netgraph/ng_message.h> +#include <netgraph/ng_parse.h> #include <netgraph/ng_sample.h> #include <netgraph/netgraph.h> @@ -66,6 +68,33 @@ static ng_rcvdata_t ng_xxx_rcvdata; /* note these are both ng_rcvdata_t */ static ng_rcvdata_t ng_xxx_rcvdataq; /* note these are both ng_rcvdata_t */ static ng_disconnect_t ng_xxx_disconnect; +/* Parse type for struct ngxxxstat */ +static const struct ng_parse_struct_info + ng_xxx_stat_type_info = NG_XXX_STATS_TYPE_INFO; +static const struct ng_parse_type ng_xxx_stat_type = { + &ng_parse_struct_type, + &ng_xxx_stat_type_info +}; + +/* List of commands and how to convert arguments to/from ASCII */ +static const struct ng_cmdlist ng_xxx_cmdlist[] = { + { + NGM_XXX_COOKIE, + NGM_XXX_GET_STATUS, + "getstatus", + NULL, + &ng_xxx_stat_type, + }, + { + NGM_XXX_COOKIE, + NGM_XXX_SET_FLAG, + "setflag", + &ng_parse_int32_type, + NULL + }, + { 0 } +}; + /* Netgraph node type descriptor */ static struct ng_type typestruct = { NG_VERSION, @@ -80,7 +109,7 @@ static struct ng_type typestruct = { ng_xxx_rcvdata, ng_xxx_rcvdataq, ng_xxx_disconnect, - NULL + ng_xxx_cmdlist }; NETGRAPH_INIT(xxx, &typestruct); @@ -161,8 +190,6 @@ ng_xxx_newhook(node_p node, hook_p hook, const char *name) { const xxx_p xxxp = node->private; const char *cp; - char c = '\0'; - int digits = 0; int dlci = 0; int chan; @@ -297,12 +324,12 @@ static int ng_xxx_rcvdata(hook_p hook, struct mbuf *m, meta_p meta) { int dlci = -2; - int error; if (hook->private) { /* - * If it's dlci 1023, requeue it so that it's handled at a lower priority. - * This is how a node decides to defer a data message. + * If it's dlci 1023, requeue it so that it's handled + * at a lower priority. This is how a node decides to + * defer a data message. */ dlci = ((struct XXX_hookinfo *) hook->private)->dlci; if (dlci == 1023) { @@ -433,7 +460,7 @@ static int ng_xxx_disconnect(hook_p hook) { if (hook->private) - ((struct XXX_hookinfo *) (hook->private))->hook == NULL; + ((struct XXX_hookinfo *) (hook->private))->hook = NULL; if (hook->node->numhooks == 0) ng_rmnode(hook->node); return (0); diff --git a/sys/netgraph/ng_sample.h b/sys/netgraph/ng_sample.h index 5d2df45..faa539c 100644 --- a/sys/netgraph/ng_sample.h +++ b/sys/netgraph/ng_sample.h @@ -72,4 +72,19 @@ struct ngxxxstat { u_int packets_out; /* packets out towards downstream */ }; +/* + * This is used to define the 'parse type' for a struct ngxxxstat, which + * is bascially a description of how to convert a binary struct ngxxxstat + * to an ASCII string and back. See ng_parse.h for more info. + * + * This needs to be kept in sync with the above structure definition + */ +#define NG_XXX_STATS_TYPE_INFO { \ + { \ + { "packets_in", &ng_parse_int32_type }, \ + { "packets_out", &ng_parse_int32_type }, \ + { NULL }, \ + } \ +} + #endif /* _NETGRAPH_SAMPLE_H_ */ |