Date: Sat, 30 Jan 1999 13:21:39 -0800 (PST) From: Archie Cobbs <archie@whistle.com> To: phk@critter.freebsd.dk (Poul-Henning Kamp) Cc: julian@whistle.com, net@FreeBSD.ORG Subject: Re: netgraph... Message-ID: <199901302121.NAA10729@bubba.whistle.com> In-Reply-To: <11086.917730231@critter.freebsd.dk> from Poul-Henning Kamp at "Jan 30, 99 10:03:51 pm"
next in thread | previous in thread | raw e-mail | index | archive | help
Poul-Henning Kamp writes:
> Yeah, I saw it, and I'm convince that no matter how smart we do it,
> it will end up being almost enough, and take up just as much space
> to code.
That's what I said too. Also, why invent a new language for
specifying the translation? That's another step away from KISS.
Anyway, I think we almost all agree :-) See how this sounds.
We add three new control messages:
NGM_ASCII_CTRL_MSG
NGM_ENCODE_ASCII
NGM_DECODE_ASCII
NGM_ASCII_CTRL_MSG takes an ASCII formatted control message as argument.
The node parses it and takes the corresponding action.
NGM_ENCODE_ASCII and NGM_DECODE_ASCII convert between ASCII and
binary formats for a control message.
It is completely up to the node how it wants to implement this
stuff, but it could look something like this..
static struct ng_mesg *my_private_decoder(const char *string);
static char *my_private_encoder(const struct ng_mesg *msg);
int
my_rcv_ctrl_msg_method(node_p here, struct ng_mesg *msg, .... )
{
...
case NGM_ASCII_CTRL_MSG:
struct ng_mesg *binary_msg = my_private_decoder(msg->data);
error = my_rcv_ctrl_msg_method(here, binary_msg, ... )
break;
case NGM_DECODE_ASCII:
struct ng_mesg *binary_msg = my_private_decoder(string);
NG_MKRESPONSE(resp, ... )
bcopy(resp->data, binary_msg, msglen);
break;
case NGM_ENCODE_ASCII:
char *ascii;
ascii = my_private_encoder((struct ng_mesg *) msg->data);
NG_MKRESPONSE(resp, ... )
bcopy(resp->data, ascii, strlen(ascii) + 1);
break;
...
}
Now notice, if we exported my_private_decoder() and my_private_encoder()
as normal node methods, then the NGM_ASCII_CTRL_MSG case could be
completely handled by the generic code, and individual nodes would
not even have to directly handle it. I think this would be the
simplest way to do it.. thoughts?
-Archie
___________________________________________________________________________
Archie Cobbs * Whistle Communications, Inc. * http://www.whistle.com
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199901302121.NAA10729>
