From owner-freebsd-net Tue Feb 6 3:51:35 2001 Delivered-To: freebsd-net@freebsd.org Received: from relay.butya.kz (butya-gw.butya.kz [212.154.129.94]) by hub.freebsd.org (Postfix) with ESMTP id 2180B37B401; Tue, 6 Feb 2001 03:51:05 -0800 (PST) Received: by relay.butya.kz (Postfix, from userid 1000) id E602728E45; Tue, 6 Feb 2001 17:50:52 +0600 (ALMT) Received: from localhost (localhost [127.0.0.1]) by relay.butya.kz (Postfix) with ESMTP id 7408928DEE; Tue, 6 Feb 2001 17:50:52 +0600 (ALMT) Date: Tue, 6 Feb 2001 17:50:52 +0600 (ALMT) From: Boris Popov To: freebsd-arch@freebsd.org Cc: freebsd-net@freebsd.org Subject: CFR: Sequential mbuf read/write extensions Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org [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-net" in the body of the message