请问xtang及各位高手关于filter模块的问题

我写了一个IO-NET的filter模块,但是io-net -dpcnet -p/full-path/myfilter.so if=en0 一运行,io-net process就退出了。 我为了调试方便,在init函数里第一旬就加了一个printf(“ok”);但是无输出结果。why?

一是可以试试 printf(“ok\n”);

二是可以用 syslog()/slogf() 来试试。

谢谢。
我的操作如下:DL_DEBUG=1 io-net
mount -Tio-net nfm-myfilter.so
can’t mount (/)
possible reason:No such process
io-net进程已经退出。
我在http://www-nrg.ee.lbl.gov/nrg.html下了一个bpf,好像不是基于io-net的. 不知道您有没有FILTER方面的code,能否发一份给我,将不胜感激。pyxuanchunxiao@yahoo.com.cn

不是说用Full path 吗?

mount -o if=en0 -Tio-net /fullpath/nfm-myfilter.so

我把它cp到了/lib/dll下,我的程序如下:
#include “rawapplication.h”

io_net_dll_entry_t io_net_dll_entry={
2,
my_init,
NULL };

io_net_registrant_funcs_t null_funcs=
{
10, // nfuncs
null_receive_packets, // rx_up()
null_rx_down, // rx_down()
null_tx_done, // tx_done()
NULL, // shutdown1()
NULL, // shutdown2()
NULL, // dl_advert()
NULL, //DEVCTL
NULL, //FLUSH
NULL,// raw_open()
NULL//raw_umount_ok
};

// a description of our driver
io_net_registrant_t null_entry =
{
_REG_FILTER_ABOVE, // we’re an “filter” producer
“nfm-myfilter.so”, // our name
“en”,// our top type
“en”, // our bottom type (none)
NULL, // function handle (see the note below)
&null_funcs, // pointer to our functions
0 // #dependencies
};


int my_init(void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion, char *options)//dpp用来实现资源管理器
{


null_dll_hdl = dll_hdl;
null_ion = ion;

printf(“okokokok\n”);

if (!null_register_device())
{
return (-1); // couldn’t register, fail;

}

null_advertise (null_reg_hdl, null_entry.func_hdl);
return (0);
}
int null_register_device(void)
{
if ((null_ion->reg)(null_dll_hdl, &null_entry,&null_reg_hdl,&null_cell,&null_lan)<0)
{

return (0); // failed
}
printf(“cell number %d”,null_cell);
printf(“cell number %d”,null_lan);
return (1); // success
}


int null_advertise (int reg_hdl, void *func_hdl)
{
npkt_t *npkt;
net_buf_t *nb;
net_iov_t *iov;
io_net_msg_dl_advert_t *ap;

// 1) Allocate a packet; we’ll use this for communications
// with io-net.
if ((npkt = null_ion->alloc_up_npkt (sizeof (*nb) + sizeof (*iov),(void **) &nb)) == NULL)
{
return (0);
}
//if ((npkt = null_ion->alloc_down_npkt (null_reg_hdl,sizeof (*nb) + sizeof (*iov),
// (void **) &nb)) == NULL) {
// return (0);
//}


// 2) Allocate room for the advertisement message.
if ((ap = null_ion->alloc (sizeof (*ap), 0)) == NULL) {
null_ion->free (npkt);
return (0);
}
// 3) Set up the packet into the queue.
TAILQ_INSERT_HEAD (&npkt->buffers, nb, ptrs);

iov = (net_iov_t *) (nb + 1);
nb → niov = 1;
nb → net_iov = iov;
iov → iov_base = ap;
iov → iov_len = sizeof (*ap);

// 4) Generate the info for the advertisement message.
memset (ap, 0x00, sizeof (*ap));
ap → type = _IO_NET_MSG_DL_ADVERT;
ap → iflags = (IFF_SIMPLEX | IFF_BROADCAST |
IFF_MULTICAST | IFF_RUNNING);
ap → mtu_min = 0;
ap → mtu_max = MTUSIZE;
ap → mtu_preferred = MTUSIZE;
sprintf (ap → up_type, “en%d”, null_lan);
strcpy (ap → dl.sdl_data, ap → up_type);

ap → dl.sdl_len = sizeof (struct sockaddr_dl);
ap → dl.sdl_family = AF_DLI;
ap → dl.sdl_index = null_lan;
ap → dl.sdl_type = IFT_ETHER;

// Not terminated:
ap → dl.sdl_nlen = strlen (ap → dl.sdl_data);
ap → dl.sdl_alen = 6;
memcpy (ap → dl.sdl_data + ap → dl.sdl_nlen,
“\x00\x0c\x29\x9d\xb5\xfc”, 6);

// 5) Bind the advertisement message to the packet; note
// the use of the _NPKT_MSG flag to indicate to the
// upper modules that this is a message intended for
// them. It isn’t just a “regular” packet.
npkt → org_data = ap;
npkt → flags |= _NPKT_MSG;
npkt ->cell=0;
npkt ->endpoint=0;
npkt → iface = 0;
npkt → framelen = sizeof (*ap);

if (null_ion->reg_tx_done (null_reg_hdl, npkt, NULL) == -1) {
null_ion->free (ap);
null_ion->free (npkt);
return (0);
}

// 6) Complete the transaction.
//null_ion->tx_down (null_reg_hdl, npkt);
if(null_ion->tx_up (null_reg_hdl, npkt,0,0,null_cell,null_lan,0) == 0) {
null_ion->tx_done (null_reg_hdl, npkt);
}
return (0);
}

为什么一运行到load symbol,io-net就马上退出。io_net_dll_entry加不上。
希望能给以指点。

Filter模块不需要advertise的,另外,shutdown1()和shutdown2()好象不可以为NULL吧。

修改了还是不行,我用DL_DEBUG=1 io-net运行,再mount总出现提示attemp load of libsocket.so.2
load_elf32…
can’t mount
possible reason:No such process