Show how to supply a struct ng_cmdlist for (de)asciification
of control messages. Suggested by: julian
This commit is contained in:
parent
9f54c05286
commit
fa200997c8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53997
@ -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);
|
||||
|
@ -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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user