Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Jul 2000 10:59:17 -0700 (PDT)
From:      Archie Cobbs <archie@whistle.com>
To:        msmith@FreeBSD.ORG (Mike Smith)
Cc:        phk@critter.freebsd.dk (Poul-Henning Kamp), freebsd-hackers@FreeBSD.ORG (FreeBSD Hackers)
Subject:   Re: Module parameters?
Message-ID:  <200007121759.KAA44838@bubba.whistle.com>
In-Reply-To: <200007112254.PAA00718@mass.osd.bsdi.com> from Mike Smith at "Jul 11, 2000 03:54:04 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
Mike Smith writes:
> Archie - I'd really appreciate a pointer to an example of using the 
> ng_parse code to pick up this sort of data, if you can recommend 
> something to help me get my head around it quickly (I've looked but slid 
> off sideways so far...).

Just to clarify.. a couple of things about the ng_parse stuff.
(I'm not claiming this is the right thing to use for modules,
just trying to clarify & give more information about it).

Basically, it contains routines for converting between ASCII and
binary data; there are two main components..

    (a) An infrastructure for doing completely arbitrary conversion,
	provided that you are willing to write your own encode and
	decode routines (i.e., the functions of type ng_parse_t
	and ng_unparse_t, which are pointed to by the struct
	ng_parse_type).

    (b) Several pre-defined parse types, for example:

	Integer types (8, 16, 32, and 64 bit)
	String types (fixed and variable length)
	C arrays (fixed and variable length)
	C structures (including 'variable length structures')

Typically you either use a predefined simple type, or define a new
type by 'subclassing' the pre-defined structure or array types and
supplying some type-specific info that describes the structure or array.

As an example, see the 'struct ng_tee_hookstat' in ng_tee.h:
http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/netgraph/ng_tee.h?rev=1.3

    /* Statistics structure for one hook */
    struct ng_tee_hookstat {
	    u_int64_t       inOctets;
	    u_int64_t       inFrames;
	    u_int64_t       outOctets;
	    u_int64_t       outFrames;
    };

Below it is the NG_TEE_HOOKSTAT_INFO definition which defines the
specifics of the structure for the parse type: four 64 bit fields:

    /* 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 },                                             \
	    }                                                       \
    }

Now look in ng_tee.c where the parse type corresponding to a
'struct ng_tee_hookstat' is defined:
http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/netgraph/ng_tee.c?rev=1.8

    /* 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,
    };

The parse type we're defining is 'ng_tee_hookstat_type' which is
a 'subclass' of ng_parse_struct_type (a predefined type from
ng_parse.c), with the type-specific info 'ng_tee_hookstat_type_info'.

In ASCII form one of these 'struct ng_tee_hookstat' structures might
look like this:

  { inOctets=123 inFrames=27 outOctets=1033 outFrames=328 }

(The syntax for the predefined array and structure types is described
in ng_parse.h).

At some point I'd like to edit the files so that they can be compiled
either in user or kernel mode.

FYI, ng_parse is completely independent from the rest of netgraph
(i.e., the rest of netgraph is not required).

-Archie

___________________________________________________________________________
Archie Cobbs   *   Whistle Communications, Inc.  *   http://www.whistle.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200007121759.KAA44838>