Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Feb 2001 17:50:52 +0600 (ALMT)
From:      Boris Popov <bp@butya.kz>
To:        freebsd-arch@freebsd.org
Cc:        freebsd-net@freebsd.org
Subject:   CFR: Sequential mbuf read/write extensions
Message-ID:  <Pine.BSF.4.21.0102061703030.82511-100000@lion.butya.kz>

next in thread | raw e-mail | index | archive | help
[Please trim CC list as necessary]

	Hello,

	Before starting import process for smbfs, I would like to
introduce new API which greatly simplifies process of packaging data into
mbufs and fetching it back (in fact, similar API already presented in the
tree, but it is private to the netncp code and it will be really nice to
share it).

	Basically, it requires additional structure (working context) and
related functions:

struct mbdata {
        struct mbuf *   mb_top;
        struct mbuf *   mb_cur;
        u_char *        mb_pos;
        int             mb_count;
};

	Where mb_top points at the first mbuf in the chain and mb_cur to
the current mbuf. Here is a slightly truncated API to illustrate how it
works:

int  mb_init(struct mbdata *mbp);
int  mb_initm(struct mbdata *mbp, struct mbuf *m);
int  mb_done(struct mbdata *mbp);
int  mb_put_byte(struct mbdata *mbp, u_int8_t x);
int  mb_put_wordbe(struct mbdata *mbp, u_int16_t x);
int  mb_put_wordle(struct mbdata *mbp, u_int16_t x);
int  mb_put_dwordbe(struct mbdata *mbp, u_int32_t x);
int  mb_get_byte(struct mbdata *mbp, u_int8_t *x);
int  mb_get_word(struct mbdata *mbp, u_int16_t *x);
int  mb_get_wordle(struct mbdata *mbp, u_int16_t *x);
int  mb_get_wordbe(struct mbdata *mbp, u_int16_t *x);


	The mb_put* functions allow to append new data to mbuf chain.
These functions take care about necessary mbuf allocations and additional
data conversions. For example, mb_put_wordbe will store a 16 bit integer
in the network format while mb_put_wordle will convert it to the little
endian format if necessary.

	The mb_get* functions allow to fetch data from mbuf chains with
appropriate handling of mbuf borders and data conversions.


	Here is a simple examples (error checks are omitted):

Send:
        error = mb_init(mbp);
        if (error)
                return error;
        mb_put_mem(mbp, SMB_SIGNATURE, SMB_SIGLEN, MB_MSYSTEM);
        mb_put_byte(mbp, cmd);
        mb_put_dwordle(mbp, 1234);
        mb_put_byte(mbp, vcp->vc_hflags);
        mb_fixhdr(mbp);
 	my_great_send_function(mbp->mb_top);
	mb_done(mbp);

Receive:

	mb_initm(mbp, just_received_mbuf_chain);
        mb_get_byte(mbp, &rqp->sr_rpflags);
        mb_get_wordle(mbp, &rqp->sr_rpflags2);
        mb_get_dword(mbp, &tdw);
        mb_get_dword(mbp, &tdw);
        mb_get_dword(mbp, &tdw);
        mb_get_wordle(mbp, &rqp->sr_rptid);
        mb_get_wordle(mbp, &rqp->sr_rppid);
        mb_get_wordle(mbp, &rqp->sr_rpuid);
        mb_get_wordle(mbp, &rqp->sr_rpmid);

	Since currently there isn't many consumers of this code I can
suggest to define an option LIBMBUF in the kernel configuration file and
add KLD libmbuf (with interface libmbuf), so kernel footprint will not be
significantly affected. The names of source and header files are
questionable too and I would appreciate good suggestions (currently they
are subr_mbuf.c and subr_mbuf.h).

	Well, and finally here you will find full source code of proposed
API: http://www.butya.kz/~bp/mbuf/

	Any comments and suggestions are greatly appreciated.

--
Boris Popov
http://www.butya.kz/~bp/



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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0102061703030.82511-100000>