ip filter

Folks,
I’m at my wit’s end or near it. I can’t seem to figure out why my simple
IP_IP filter example hoses up the entire io-net subsystem. I can mount and
unmount it and I get some output indicatig that the init function runs, and
the rx_up and rx_down functions run, and get a few packets. I just want to
pass everythig through but this seems not to work. Is this not enough? My
rx_up function just calls tx_up and my rx_down just calls tx_down. hoses up
the system until I umount /dev/io-net/ip_ip0, then it returns to normal. I
build normally with qcc -shared -Vgcc_ntomipsle
ipfilter.c -oipfilter.so -w9. I don’t strip the output. I can see from the
printouts that go out on my serial console that the functions are all
getting called so the problem seems to be that I am not properly passing the
packets through. If someone could comment on what I am doing wrong, I would
be eternally greatful.
Thanks in advance!
Chris


P.S. I can include output from a sample run if anyone thinks this would
help. I suspect I’ve done something ( or rather NOT done something
obvious… )



// ipfilter.c
// a test to see if I can generate an IP filter that hooks into io-net
// and sees all the packets flowing by in both directions.
//
// The general idea is to hook in as a filter just above the
// tulip driver.
//
// Chris Beasley, Berkeley Process Control, Inc. 2001
//

#include <hw/inout.h>
#include <sys/mman.h>

#include <sys/io-net.h>
#include <inttypes.h>
#include <atomic.h>
#include <unistd.h>
#include <stdio.h>
#include <strings.h>
#include <errno.h>
#include <net/if.h>
#include <net/if_types.h>


int my_init( void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options );

void *my_rx_thread( void *arg );
int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl );
int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface );

int my_rx_down( npkt_t *npkt, void *func_hdl );
int my_shutdown1( int registrant_hdl, void *func_hdl );
int my_shutdown2( int registrant_hdl, void *func_hdl );


// Global symbols
void *my_dll_hdl;
io_net_self_t *my_ion;
int my_reg_hdl;
uint16_t my_cell;
uint16_t my_endpoint;

io_net_dll_entry_t io_net_dll_entry =
{
2, // Number of functions
my_init, // init()
NULL // “master” shutdown()
};


// functions that we supply
io_net_registrant_funcs_t my_funcs =
{
_IO_NET_REG_NFUNCS, // nfuncs
my_rx_up, // receive a packet on it’s way up
my_rx_down, // receive a packet on it’s way down
my_tx_done, // release our hold a packet
my_shutdown1, // shutdown1()
my_shutdown2, // shutdown2()
NULL, // dl_advert()
NULL, // devctl()
NULL, // flush()
NULL, // raw_open()
NULL
};

// a description of our driver
io_net_registrant_t my_entry =
{
_REG_FILTER_BELOW, // | _REG_INIT_ONCE, where the f#(% is _init_once
defined!?
“bpc-ip-filter.so”,// our name
“ip”, // our top type
“ip”, // our bottom type
NULL, // global control handle
&my_funcs, // pointer to our functions
0 // #dependencies
};




// The dll functions.
int my_init (void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion, char
*options)
{
printf( “my_init\n” );
my_dll_hdl = dll_hdl;
my_ion = ion;

// Register with io-net
if ((*my_ion → reg)
(my_dll_hdl,
&my_entry,
&my_reg_hdl,
&my_cell,
&my_endpoint) < 0)

{
return( -1 );
}

return (0); // success
}

file://debug functions
int parse_npkt( npkt_t *npkt )
{
uint16_t *type;

if ( npkt->flags & _NPKT_NOT_TXED )
printf( "not transmitted " );
if ( npkt->flags & _NPKT_NO_RES )
printf( "up producer wants packet back NOW " );
if ( npkt->flags & _NPKT_UP )
printf( "up " );
else
printf( "down " );
if ( npkt->flags & _NPKT_MSG )
printf( "message " );
if ( npkt->flags & _NPKT_MSG_DYING )
printf( "dying " );
if ( npkt->flags & _NPKT_BCAST )
printf( "broadcast " );
if ( npkt->flags & _NPKT_MCAST )
printf( "multicast " );
if ( npkt->flags & _NPKT_INTERNAL )
printf( "internal " );
if ( npkt->flags & _NPKT_UP_SPECIFIC )
printf( "up specific " );

type = (uint16_t *)(npkt->buffers.tqh_first->net_iov->iov_base);
switch ( *type )
{
case _IO_NET_MSG_DL_ADVERT:
printf( ":advert " );
break;
case _IO_NET_MSG_ADDR_ADD:
printf( ":message add " );
break;
case _IO_NET_MSG_ADDR_DEL:
printf( ":message del " );
break;
case QNET_IMMSG_IFUP:
printf( ":qnet ifup " );
break;
case QNET_IMMSG_IFDOWN:
printf( ":nqet ifdown " );
break;
case _IO_NET_JOIN_MCAST:
printf( ":join mcast " );
break;
case _IO_NET_REMOVE_MCAST:
printf( ":remove mcast " );
break;
}

printf( “\n\n” );

return 0;
}


int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl )
{
printf( “my_tx_done\n” );

parse_npkt( npkt );

return 0;
}

int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface )
{
printf( “my_rx_up\n” );

parse_npkt( npkt );

(*my_ion->tx_up)( my_reg_hdl, npkt, off, framlen_sub, cell, endpoint,
iface );

return EOK;
}


int my_rx_down( npkt_t *npkt, void *func_hdl )
{
printf( “my_rx_down\n” );

parse_npkt( npkt );

return (*my_ion->tx_down)( my_reg_hdl, npkt );
}

int my_shutdown1( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown1\n” );
return EOK; // return EBUSY if we don’t want them to shut us down yet
}

int my_shutdown2( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown2\n” );
return 0; // at this point, we have no choice and must shutdown
}

Thought this might stimulate more discussion… Anyone have a MINIMAL IP or
EN filter skeleton code?
Here is the output from a run. It hangs up the io-net system until it is
unmounted…

root:/fs2p0>mount -Tio-net $PWD/ipfilter.mip
my_init
my_rx_up
up message :advert

my_rx_down
down

my_rx_down
down message :message add

uymy_rx_down
down

root:/fs2p0>umount /dev/io-net/ip_ip0

my_shutdown1
my_shutdown2

Thanks!
Chris


BPC Software Group <bpc_sw@hotmail.com> wrote in message
news:9ujp3f$miq$1@inn.qnx.com

Folks,
I’m at my wit’s end or near it. I can’t seem to figure out why my simple
IP_IP filter example hoses up the entire io-net subsystem. I can mount
and
unmount it and I get some output indicatig that the init function runs,
and
the rx_up and rx_down functions run, and get a few packets. I just want
to
pass everythig through but this seems not to work. Is this not enough?
My
rx_up function just calls tx_up and my rx_down just calls tx_down. hoses
up
the system until I umount /dev/io-net/ip_ip0, then it returns to normal.
I
build normally with qcc -shared -Vgcc_ntomipsle
ipfilter.c -oipfilter.so -w9. I don’t strip the output. I can see from
the
printouts that go out on my serial console that the functions are all
getting called so the problem seems to be that I am not properly passing
the
packets through. If someone could comment on what I am doing wrong, I
would
be eternally greatful.
Thanks in advance!
Chris


P.S. I can include output from a sample run if anyone thinks this would
help. I suspect I’ve done something ( or rather NOT done something
obvious… )



// ipfilter.c
// a test to see if I can generate an IP filter that hooks into io-net
// and sees all the packets flowing by in both directions.
//
// The general idea is to hook in as a filter just above the
// tulip driver.
//
// Chris Beasley, Berkeley Process Control, Inc. 2001
//

#include <hw/inout.h
#include <sys/mman.h

#include <sys/io-net.h
#include <inttypes.h
#include <atomic.h
#include <unistd.h
#include <stdio.h
#include <strings.h
#include <errno.h
#include <net/if.h
#include <net/if_types.h


int my_init( void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options );

void *my_rx_thread( void *arg );
int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl );
int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface );

int my_rx_down( npkt_t *npkt, void *func_hdl );
int my_shutdown1( int registrant_hdl, void *func_hdl );
int my_shutdown2( int registrant_hdl, void *func_hdl );


// Global symbols
void *my_dll_hdl;
io_net_self_t *my_ion;
int my_reg_hdl;
uint16_t my_cell;
uint16_t my_endpoint;

io_net_dll_entry_t io_net_dll_entry =
{
2, // Number of functions
my_init, // init()
NULL // “master” shutdown()
};


// functions that we supply
io_net_registrant_funcs_t my_funcs =
{
_IO_NET_REG_NFUNCS, // nfuncs
my_rx_up, // receive a packet on it’s way up
my_rx_down, // receive a packet on it’s way down
my_tx_done, // release our hold a packet
my_shutdown1, // shutdown1()
my_shutdown2, // shutdown2()
NULL, // dl_advert()
NULL, // devctl()
NULL, // flush()
NULL, // raw_open()
NULL
};

// a description of our driver
io_net_registrant_t my_entry =
{
_REG_FILTER_BELOW, // | _REG_INIT_ONCE, where the f#(% is _init_once
defined!?
“bpc-ip-filter.so”,// our name
“ip”, // our top type
“ip”, // our bottom type
NULL, // global control handle
&my_funcs, // pointer to our functions
0 // #dependencies
};




// The dll functions.
int my_init (void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion, char
*options)
{
printf( “my_init\n” );
my_dll_hdl = dll_hdl;
my_ion = ion;

// Register with io-net
if ((*my_ion → reg)
(my_dll_hdl,
&my_entry,
&my_reg_hdl,
&my_cell,
&my_endpoint) < 0)

{
return( -1 );
}

return (0); // success
}

file://debug functions
int parse_npkt( npkt_t *npkt )
{
uint16_t *type;

if ( npkt->flags & _NPKT_NOT_TXED )
printf( "not transmitted " );
if ( npkt->flags & _NPKT_NO_RES )
printf( "up producer wants packet back NOW " );
if ( npkt->flags & _NPKT_UP )
printf( "up " );
else
printf( "down " );
if ( npkt->flags & _NPKT_MSG )
printf( "message " );
if ( npkt->flags & _NPKT_MSG_DYING )
printf( "dying " );
if ( npkt->flags & _NPKT_BCAST )
printf( "broadcast " );
if ( npkt->flags & _NPKT_MCAST )
printf( "multicast " );
if ( npkt->flags & _NPKT_INTERNAL )
printf( "internal " );
if ( npkt->flags & _NPKT_UP_SPECIFIC )
printf( "up specific " );

type = (uint16_t *)(npkt->buffers.tqh_first->net_iov->iov_base);
switch ( *type )
{
case _IO_NET_MSG_DL_ADVERT:
printf( ":advert " );
break;
case _IO_NET_MSG_ADDR_ADD:
printf( ":message add " );
break;
case _IO_NET_MSG_ADDR_DEL:
printf( ":message del " );
break;
case QNET_IMMSG_IFUP:
printf( ":qnet ifup " );
break;
case QNET_IMMSG_IFDOWN:
printf( ":nqet ifdown " );
break;
case _IO_NET_JOIN_MCAST:
printf( ":join mcast " );
break;
case _IO_NET_REMOVE_MCAST:
printf( ":remove mcast " );
break;
}

printf( “\n\n” );

return 0;
}


int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl )
{
printf( “my_tx_done\n” );

parse_npkt( npkt );

return 0;
}

int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface )
{
printf( “my_rx_up\n” );

parse_npkt( npkt );

(*my_ion->tx_up)( my_reg_hdl, npkt, off, framlen_sub, cell, endpoint,
iface );

return EOK;
}


int my_rx_down( npkt_t *npkt, void *func_hdl )
{
printf( “my_rx_down\n” );

parse_npkt( npkt );

return (*my_ion->tx_down)( my_reg_hdl, npkt );
}

int my_shutdown1( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown1\n” );
return EOK; // return EBUSY if we don’t want them to shut us down yet
}

int my_shutdown2( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown2\n” );
return 0; // at this point, we have no choice and must shutdown
}

Are you sure you are not modifying any of the Cell,Endpoint,iface parameters
?
I hope you have something like this …

my_rx_down( npkt…) {
:
:
:
:
npi->tx_down(npkt,…);

}
my_rx_up(npkt…) {
:
:
:
:
npi->tx_up(npkt…);
npi->tx_done(npkt…);

}
IF you want you can send me copy of source snippet…where you are facing the
problem…I can look into it.


Sreekanth


“BPC Software Group” <bpc_sw@hotmail.com> wrote in message
news:9um61n$etl$1@inn.qnx.com

Thought this might stimulate more discussion… Anyone have a MINIMAL IP
or
EN filter skeleton code?
Here is the output from a run. It hangs up the io-net system until it is
unmounted…

root:/fs2p0>mount -Tio-net $PWD/ipfilter.mip
my_init
my_rx_up
up message :advert

my_rx_down
down

my_rx_down
down message :message add

uymy_rx_down
down

root:/fs2p0>umount /dev/io-net/ip_ip0

my_shutdown1
my_shutdown2

Thanks!
Chris


BPC Software Group <> bpc_sw@hotmail.com> > wrote in message
news:9ujp3f$miq$> 1@inn.qnx.com> …
Folks,
I’m at my wit’s end or near it. I can’t seem to figure out why my
simple
IP_IP filter example hoses up the entire io-net subsystem. I can mount
and
unmount it and I get some output indicatig that the init function runs,
and
the rx_up and rx_down functions run, and get a few packets. I just want
to
pass everythig through but this seems not to work. Is this not enough?
My
rx_up function just calls tx_up and my rx_down just calls tx_down.
hoses
up
the system until I umount /dev/io-net/ip_ip0, then it returns to normal.
I
build normally with qcc -shared -Vgcc_ntomipsle
ipfilter.c -oipfilter.so -w9. I don’t strip the output. I can see from
the
printouts that go out on my serial console that the functions are all
getting called so the problem seems to be that I am not properly passing
the
packets through. If someone could comment on what I am doing wrong, I
would
be eternally greatful.
Thanks in advance!
Chris


P.S. I can include output from a sample run if anyone thinks this would
help. I suspect I’ve done something ( or rather NOT done something
obvious… )



// ipfilter.c
// a test to see if I can generate an IP filter that hooks into io-net
// and sees all the packets flowing by in both directions.
//
// The general idea is to hook in as a filter just above the
// tulip driver.
//
// Chris Beasley, Berkeley Process Control, Inc. 2001
//

#include <hw/inout.h
#include <sys/mman.h

#include <sys/io-net.h
#include <inttypes.h
#include <atomic.h
#include <unistd.h
#include <stdio.h
#include <strings.h
#include <errno.h
#include <net/if.h
#include <net/if_types.h


int my_init( void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options );

void *my_rx_thread( void *arg );
int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl );
int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface );

int my_rx_down( npkt_t *npkt, void *func_hdl );
int my_shutdown1( int registrant_hdl, void *func_hdl );
int my_shutdown2( int registrant_hdl, void *func_hdl );


// Global symbols
void *my_dll_hdl;
io_net_self_t *my_ion;
int my_reg_hdl;
uint16_t my_cell;
uint16_t my_endpoint;

io_net_dll_entry_t io_net_dll_entry =
{
2, // Number of functions
my_init, // init()
NULL // “master” shutdown()
};


// functions that we supply
io_net_registrant_funcs_t my_funcs =
{
_IO_NET_REG_NFUNCS, // nfuncs
my_rx_up, // receive a packet on it’s way up
my_rx_down, // receive a packet on it’s way down
my_tx_done, // release our hold a packet
my_shutdown1, // shutdown1()
my_shutdown2, // shutdown2()
NULL, // dl_advert()
NULL, // devctl()
NULL, // flush()
NULL, // raw_open()
NULL
};

// a description of our driver
io_net_registrant_t my_entry =
{
_REG_FILTER_BELOW, // | _REG_INIT_ONCE, where the f#(% is
_init_once
defined!?
“bpc-ip-filter.so”,// our name
“ip”, // our top type
“ip”, // our bottom type
NULL, // global control handle
&my_funcs, // pointer to our functions
0 // #dependencies
};




// The dll functions.
int my_init (void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion, char
*options)
{
printf( “my_init\n” );
my_dll_hdl = dll_hdl;
my_ion = ion;

// Register with io-net
if ((*my_ion → reg)
(my_dll_hdl,
&my_entry,
&my_reg_hdl,
&my_cell,
&my_endpoint) < 0)

{
return( -1 );
}

return (0); // success
}

file://debug functions
int parse_npkt( npkt_t *npkt )
{
uint16_t *type;

if ( npkt->flags & _NPKT_NOT_TXED )
printf( "not transmitted " );
if ( npkt->flags & _NPKT_NO_RES )
printf( "up producer wants packet back NOW " );
if ( npkt->flags & _NPKT_UP )
printf( "up " );
else
printf( "down " );
if ( npkt->flags & _NPKT_MSG )
printf( "message " );
if ( npkt->flags & _NPKT_MSG_DYING )
printf( "dying " );
if ( npkt->flags & _NPKT_BCAST )
printf( "broadcast " );
if ( npkt->flags & _NPKT_MCAST )
printf( "multicast " );
if ( npkt->flags & _NPKT_INTERNAL )
printf( "internal " );
if ( npkt->flags & _NPKT_UP_SPECIFIC )
printf( "up specific " );

type = (uint16_t *)(npkt->buffers.tqh_first->net_iov->iov_base);
switch ( *type )
{
case _IO_NET_MSG_DL_ADVERT:
printf( ":advert " );
break;
case _IO_NET_MSG_ADDR_ADD:
printf( ":message add " );
break;
case _IO_NET_MSG_ADDR_DEL:
printf( ":message del " );
break;
case QNET_IMMSG_IFUP:
printf( ":qnet ifup " );
break;
case QNET_IMMSG_IFDOWN:
printf( ":nqet ifdown " );
break;
case _IO_NET_JOIN_MCAST:
printf( ":join mcast " );
break;
case _IO_NET_REMOVE_MCAST:
printf( ":remove mcast " );
break;
}

printf( “\n\n” );

return 0;
}


int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl )
{
printf( “my_tx_done\n” );

parse_npkt( npkt );

return 0;
}

int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface )
{
printf( “my_rx_up\n” );

parse_npkt( npkt );

(*my_ion->tx_up)( my_reg_hdl, npkt, off, framlen_sub, cell, endpoint,
iface );

return EOK;
}


int my_rx_down( npkt_t *npkt, void *func_hdl )
{
printf( “my_rx_down\n” );

parse_npkt( npkt );

return (*my_ion->tx_down)( my_reg_hdl, npkt );
}

int my_shutdown1( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown1\n” );
return EOK; // return EBUSY if we don’t want them to shut us down
yet
}

int my_shutdown2( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown2\n” );
return 0; // at this point, we have no choice and must shutdown
}

\

Thanks for the offer, as you can see I had included the source below.
It turns out I was missing a call to reg_byte_pat() something that is not
spelled out in the DDK docs.
Thanks to Sean Boudreau and Chris McKillop for their assistance.
Chris


Sreekanth <sreekanth@cambira.com> wrote in message
news:9umf10$kdg$1@inn.qnx.com

Are you sure you are not modifying any of the Cell,Endpoint,iface
parameters
?
I hope you have something like this …

my_rx_down( npkt…) {
:
:
:
:
npi->tx_down(npkt,…);

}
my_rx_up(npkt…) {
:
:
:
:
npi->tx_up(npkt…);
npi->tx_done(npkt…);

}
IF you want you can send me copy of source snippet…where you are facing
the
problem…I can look into it.


Sreekanth


“BPC Software Group” <> bpc_sw@hotmail.com> > wrote in message
news:9um61n$etl$> 1@inn.qnx.com> …
Thought this might stimulate more discussion… Anyone have a MINIMAL
IP
or
EN filter skeleton code?
Here is the output from a run. It hangs up the io-net system until it
is
unmounted…

root:/fs2p0>mount -Tio-net $PWD/ipfilter.mip
my_init
my_rx_up
up message :advert

my_rx_down
down

my_rx_down
down message :message add

uymy_rx_down
down

root:/fs2p0>umount /dev/io-net/ip_ip0

my_shutdown1
my_shutdown2

Thanks!
Chris


BPC Software Group <> bpc_sw@hotmail.com> > wrote in message
news:9ujp3f$miq$> 1@inn.qnx.com> …
Folks,
I’m at my wit’s end or near it. I can’t seem to figure out why my
simple
IP_IP filter example hoses up the entire io-net subsystem. I can
mount
and
unmount it and I get some output indicatig that the init function
runs,
and
the rx_up and rx_down functions run, and get a few packets. I just
want
to
pass everythig through but this seems not to work. Is this not
enough?
My
rx_up function just calls tx_up and my rx_down just calls tx_down.
hoses
up
the system until I umount /dev/io-net/ip_ip0, then it returns to
normal.
I
build normally with qcc -shared -Vgcc_ntomipsle
ipfilter.c -oipfilter.so -w9. I don’t strip the output. I can see
from
the
printouts that go out on my serial console that the functions are all
getting called so the problem seems to be that I am not properly
passing
the
packets through. If someone could comment on what I am doing wrong, I
would
be eternally greatful.
Thanks in advance!
Chris


P.S. I can include output from a sample run if anyone thinks this
would
help. I suspect I’ve done something ( or rather NOT done something
obvious… )



// ipfilter.c
// a test to see if I can generate an IP filter that hooks into
io-net
// and sees all the packets flowing by in both directions.
//
// The general idea is to hook in as a filter just above the
// tulip driver.
//
// Chris Beasley, Berkeley Process Control, Inc. 2001
//

#include <hw/inout.h
#include <sys/mman.h

#include <sys/io-net.h
#include <inttypes.h
#include <atomic.h
#include <unistd.h
#include <stdio.h
#include <strings.h
#include <errno.h
#include <net/if.h
#include <net/if_types.h


int my_init( void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options );

void *my_rx_thread( void *arg );
int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl );
int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface );

int my_rx_down( npkt_t *npkt, void *func_hdl );
int my_shutdown1( int registrant_hdl, void *func_hdl );
int my_shutdown2( int registrant_hdl, void *func_hdl );


// Global symbols
void *my_dll_hdl;
io_net_self_t *my_ion;
int my_reg_hdl;
uint16_t my_cell;
uint16_t my_endpoint;

io_net_dll_entry_t io_net_dll_entry =
{
2, // Number of functions
my_init, // init()
NULL // “master” shutdown()
};


// functions that we supply
io_net_registrant_funcs_t my_funcs =
{
_IO_NET_REG_NFUNCS, // nfuncs
my_rx_up, // receive a packet on it’s way up
my_rx_down, // receive a packet on it’s way down
my_tx_done, // release our hold a packet
my_shutdown1, // shutdown1()
my_shutdown2, // shutdown2()
NULL, // dl_advert()
NULL, // devctl()
NULL, // flush()
NULL, // raw_open()
NULL
};

// a description of our driver
io_net_registrant_t my_entry =
{
_REG_FILTER_BELOW, // | _REG_INIT_ONCE, where the f#(% is
_init_once
defined!?
“bpc-ip-filter.so”,// our name
“ip”, // our top type
“ip”, // our bottom type
NULL, // global control handle
&my_funcs, // pointer to our functions
0 // #dependencies
};




// The dll functions.
int my_init (void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion, char
*options)
{
printf( “my_init\n” );
my_dll_hdl = dll_hdl;
my_ion = ion;

// Register with io-net
if ((*my_ion → reg)
(my_dll_hdl,
&my_entry,
&my_reg_hdl,
&my_cell,
&my_endpoint) < 0)

{
return( -1 );
}

return (0); // success
}

file://debug functions
int parse_npkt( npkt_t *npkt )
{
uint16_t *type;

if ( npkt->flags & _NPKT_NOT_TXED )
printf( "not transmitted " );
if ( npkt->flags & _NPKT_NO_RES )
printf( "up producer wants packet back NOW " );
if ( npkt->flags & _NPKT_UP )
printf( "up " );
else
printf( "down " );
if ( npkt->flags & _NPKT_MSG )
printf( "message " );
if ( npkt->flags & _NPKT_MSG_DYING )
printf( "dying " );
if ( npkt->flags & _NPKT_BCAST )
printf( "broadcast " );
if ( npkt->flags & _NPKT_MCAST )
printf( "multicast " );
if ( npkt->flags & _NPKT_INTERNAL )
printf( "internal " );
if ( npkt->flags & _NPKT_UP_SPECIFIC )
printf( "up specific " );

type = (uint16_t *)(npkt->buffers.tqh_first->net_iov->iov_base);
switch ( *type )
{
case _IO_NET_MSG_DL_ADVERT:
printf( ":advert " );
break;
case _IO_NET_MSG_ADDR_ADD:
printf( ":message add " );
break;
case _IO_NET_MSG_ADDR_DEL:
printf( ":message del " );
break;
case QNET_IMMSG_IFUP:
printf( ":qnet ifup " );
break;
case QNET_IMMSG_IFDOWN:
printf( ":nqet ifdown " );
break;
case _IO_NET_JOIN_MCAST:
printf( ":join mcast " );
break;
case _IO_NET_REMOVE_MCAST:
printf( ":remove mcast " );
break;
}

printf( “\n\n” );

return 0;
}


int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl )
{
printf( “my_tx_done\n” );

parse_npkt( npkt );

return 0;
}

int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface )
{
printf( “my_rx_up\n” );

parse_npkt( npkt );

(*my_ion->tx_up)( my_reg_hdl, npkt, off, framlen_sub, cell,
endpoint,
iface );

return EOK;
}


int my_rx_down( npkt_t *npkt, void *func_hdl )
{
printf( “my_rx_down\n” );

parse_npkt( npkt );

return (*my_ion->tx_down)( my_reg_hdl, npkt );
}

int my_shutdown1( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown1\n” );
return EOK; // return EBUSY if we don’t want them to shut us down
yet
}

int my_shutdown2( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown2\n” );
return 0; // at this point, we have no choice and must shutdown
}



\

Sure it is a weird thing cause it is not talked about in any of the
documentation.But you said that the io-net is calling your
function(according to the logs) .If haven’t done reg_byte_pat i am not sure
io-net will call your functions(rx_down and rx_up) .I too faced this
problem and then resolved it by looking at some other code.

Sreekanth


“BPC Software Group” <bpc_sw@hotmail.com> wrote in message
news:9uoccr$38p$1@inn.qnx.com

Thanks for the offer, as you can see I had included the source below.
It turns out I was missing a call to reg_byte_pat() something that is not
spelled out in the DDK docs.
Thanks to Sean Boudreau and Chris McKillop for their assistance.
Chris


Sreekanth <> sreekanth@cambira.com> > wrote in message
news:9umf10$kdg$> 1@inn.qnx.com> …
Are you sure you are not modifying any of the Cell,Endpoint,iface
parameters
?
I hope you have something like this …

my_rx_down( npkt…) {
:
:
:
:
npi->tx_down(npkt,…);

}
my_rx_up(npkt…) {
:
:
:
:
npi->tx_up(npkt…);
npi->tx_done(npkt…);

}
IF you want you can send me copy of source snippet…where you are facing
the
problem…I can look into it.


Sreekanth


“BPC Software Group” <> bpc_sw@hotmail.com> > wrote in message
news:9um61n$etl$> 1@inn.qnx.com> …
Thought this might stimulate more discussion… Anyone have a MINIMAL
IP
or
EN filter skeleton code?
Here is the output from a run. It hangs up the io-net system until it
is
unmounted…

root:/fs2p0>mount -Tio-net $PWD/ipfilter.mip
my_init
my_rx_up
up message :advert

my_rx_down
down

my_rx_down
down message :message add

uymy_rx_down
down

root:/fs2p0>umount /dev/io-net/ip_ip0

my_shutdown1
my_shutdown2

Thanks!
Chris


BPC Software Group <> bpc_sw@hotmail.com> > wrote in message
news:9ujp3f$miq$> 1@inn.qnx.com> …
Folks,
I’m at my wit’s end or near it. I can’t seem to figure out why my
simple
IP_IP filter example hoses up the entire io-net subsystem. I can
mount
and
unmount it and I get some output indicatig that the init function
runs,
and
the rx_up and rx_down functions run, and get a few packets. I just
want
to
pass everythig through but this seems not to work. Is this not
enough?
My
rx_up function just calls tx_up and my rx_down just calls tx_down.
hoses
up
the system until I umount /dev/io-net/ip_ip0, then it returns to
normal.
I
build normally with qcc -shared -Vgcc_ntomipsle
ipfilter.c -oipfilter.so -w9. I don’t strip the output. I can see
from
the
printouts that go out on my serial console that the functions are
all
getting called so the problem seems to be that I am not properly
passing
the
packets through. If someone could comment on what I am doing wrong,
I
would
be eternally greatful.
Thanks in advance!
Chris


P.S. I can include output from a sample run if anyone thinks this
would
help. I suspect I’ve done something ( or rather NOT done something
obvious… )



// ipfilter.c
// a test to see if I can generate an IP filter that hooks into
io-net
// and sees all the packets flowing by in both directions.
//
// The general idea is to hook in as a filter just above the
// tulip driver.
//
// Chris Beasley, Berkeley Process Control, Inc. 2001
//

#include <hw/inout.h
#include <sys/mman.h

#include <sys/io-net.h
#include <inttypes.h
#include <atomic.h
#include <unistd.h
#include <stdio.h
#include <strings.h
#include <errno.h
#include <net/if.h
#include <net/if_types.h


int my_init( void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options );

void *my_rx_thread( void *arg );
int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl );
int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface );

int my_rx_down( npkt_t *npkt, void *func_hdl );
int my_shutdown1( int registrant_hdl, void *func_hdl );
int my_shutdown2( int registrant_hdl, void *func_hdl );


// Global symbols
void *my_dll_hdl;
io_net_self_t *my_ion;
int my_reg_hdl;
uint16_t my_cell;
uint16_t my_endpoint;

io_net_dll_entry_t io_net_dll_entry =
{
2, // Number of functions
my_init, // init()
NULL // “master” shutdown()
};


// functions that we supply
io_net_registrant_funcs_t my_funcs =
{
_IO_NET_REG_NFUNCS, // nfuncs
my_rx_up, // receive a packet on it’s way up
my_rx_down, // receive a packet on it’s way down
my_tx_done, // release our hold a packet
my_shutdown1, // shutdown1()
my_shutdown2, // shutdown2()
NULL, // dl_advert()
NULL, // devctl()
NULL, // flush()
NULL, // raw_open()
NULL
};

// a description of our driver
io_net_registrant_t my_entry =
{
_REG_FILTER_BELOW, // | _REG_INIT_ONCE, where the f#(% is
_init_once
defined!?
“bpc-ip-filter.so”,// our name
“ip”, // our top type
“ip”, // our bottom type
NULL, // global control handle
&my_funcs, // pointer to our functions
0 // #dependencies
};




// The dll functions.
int my_init (void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion,
char
*options)
{
printf( “my_init\n” );
my_dll_hdl = dll_hdl;
my_ion = ion;

// Register with io-net
if ((*my_ion → reg)
(my_dll_hdl,
&my_entry,
&my_reg_hdl,
&my_cell,
&my_endpoint) < 0)

{
return( -1 );
}

return (0); // success
}

file://debug functions
int parse_npkt( npkt_t *npkt )
{
uint16_t *type;

if ( npkt->flags & _NPKT_NOT_TXED )
printf( "not transmitted " );
if ( npkt->flags & _NPKT_NO_RES )
printf( "up producer wants packet back NOW " );
if ( npkt->flags & _NPKT_UP )
printf( "up " );
else
printf( "down " );
if ( npkt->flags & _NPKT_MSG )
printf( "message " );
if ( npkt->flags & _NPKT_MSG_DYING )
printf( "dying " );
if ( npkt->flags & _NPKT_BCAST )
printf( "broadcast " );
if ( npkt->flags & _NPKT_MCAST )
printf( "multicast " );
if ( npkt->flags & _NPKT_INTERNAL )
printf( "internal " );
if ( npkt->flags & _NPKT_UP_SPECIFIC )
printf( "up specific " );

type = (uint16_t *)(npkt->buffers.tqh_first->net_iov->iov_base);
switch ( *type )
{
case _IO_NET_MSG_DL_ADVERT:
printf( ":advert " );
break;
case _IO_NET_MSG_ADDR_ADD:
printf( ":message add " );
break;
case _IO_NET_MSG_ADDR_DEL:
printf( ":message del " );
break;
case QNET_IMMSG_IFUP:
printf( ":qnet ifup " );
break;
case QNET_IMMSG_IFDOWN:
printf( ":nqet ifdown " );
break;
case _IO_NET_JOIN_MCAST:
printf( ":join mcast " );
break;
case _IO_NET_REMOVE_MCAST:
printf( ":remove mcast " );
break;
}

printf( “\n\n” );

return 0;
}


int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl )
{
printf( “my_tx_done\n” );

parse_npkt( npkt );

return 0;
}

int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface )
{
printf( “my_rx_up\n” );

parse_npkt( npkt );

(*my_ion->tx_up)( my_reg_hdl, npkt, off, framlen_sub, cell,
endpoint,
iface );

return EOK;
}


int my_rx_down( npkt_t *npkt, void *func_hdl )
{
printf( “my_rx_down\n” );

parse_npkt( npkt );

return (*my_ion->tx_down)( my_reg_hdl, npkt );
}

int my_shutdown1( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown1\n” );
return EOK; // return EBUSY if we don’t want them to shut us
down
yet
}

int my_shutdown2( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown2\n” );
return 0; // at this point, we have no choice and must shutdown
}





\

Yeah it was weird. I was definitely getting SOME calls to my rx_up and
rx_down functions.
But the stack was pretty hosed. Now that I have reg_byte_pat(…,all) in
there, it works fine.

But I’m planning to try to use reg_byte_pat to look for a particular port.
I’m wondering if this will work.
possibly not because of the variable size of some things that come before
the ( UDP ) port number.

Anyone use reg_byte_pat for anything except “all” packets?
Chris


Sreekanth <sreekanth@cambira.com> wrote in message
news:9uojem$82f$1@inn.qnx.com

Sure it is a weird thing cause it is not talked about in any of the
documentation.But you said that the io-net is calling your
function(according to the logs) .If haven’t done reg_byte_pat i am not
sure
io-net will call your functions(rx_down and rx_up) .I too faced this
problem and then resolved it by looking at some other code.

Sreekanth


“BPC Software Group” <> bpc_sw@hotmail.com> > wrote in message
news:9uoccr$38p$> 1@inn.qnx.com> …
Thanks for the offer, as you can see I had included the source below.
It turns out I was missing a call to reg_byte_pat() something that is
not
spelled out in the DDK docs.
Thanks to Sean Boudreau and Chris McKillop for their assistance.
Chris


Sreekanth <> sreekanth@cambira.com> > wrote in message
news:9umf10$kdg$> 1@inn.qnx.com> …
Are you sure you are not modifying any of the Cell,Endpoint,iface
parameters
?
I hope you have something like this …

my_rx_down( npkt…) {
:
:
:
:
npi->tx_down(npkt,…);

}
my_rx_up(npkt…) {
:
:
:
:
npi->tx_up(npkt…);
npi->tx_done(npkt…);

}
IF you want you can send me copy of source snippet…where you are
facing
the
problem…I can look into it.


Sreekanth


“BPC Software Group” <> bpc_sw@hotmail.com> > wrote in message
news:9um61n$etl$> 1@inn.qnx.com> …
Thought this might stimulate more discussion… Anyone have a
MINIMAL
IP
or
EN filter skeleton code?
Here is the output from a run. It hangs up the io-net system until
it
is
unmounted…

root:/fs2p0>mount -Tio-net $PWD/ipfilter.mip
my_init
my_rx_up
up message :advert

my_rx_down
down

my_rx_down
down message :message add

uymy_rx_down
down

root:/fs2p0>umount /dev/io-net/ip_ip0

my_shutdown1
my_shutdown2

Thanks!
Chris


BPC Software Group <> bpc_sw@hotmail.com> > wrote in message
news:9ujp3f$miq$> 1@inn.qnx.com> …
Folks,
I’m at my wit’s end or near it. I can’t seem to figure out why my
simple
IP_IP filter example hoses up the entire io-net subsystem. I can
mount
and
unmount it and I get some output indicatig that the init function
runs,
and
the rx_up and rx_down functions run, and get a few packets. I
just
want
to
pass everythig through but this seems not to work. Is this not
enough?
My
rx_up function just calls tx_up and my rx_down just calls tx_down.
hoses
up
the system until I umount /dev/io-net/ip_ip0, then it returns to
normal.
I
build normally with qcc -shared -Vgcc_ntomipsle
ipfilter.c -oipfilter.so -w9. I don’t strip the output. I can
see
from
the
printouts that go out on my serial console that the functions are
all
getting called so the problem seems to be that I am not properly
passing
the
packets through. If someone could comment on what I am doing
wrong,
I
would
be eternally greatful.
Thanks in advance!
Chris


P.S. I can include output from a sample run if anyone thinks this
would
help. I suspect I’ve done something ( or rather NOT done
something
obvious… )



// ipfilter.c
// a test to see if I can generate an IP filter that hooks into
io-net
// and sees all the packets flowing by in both directions.
//
// The general idea is to hook in as a filter just above the
// tulip driver.
//
// Chris Beasley, Berkeley Process Control, Inc. 2001
//

#include <hw/inout.h
#include <sys/mman.h

#include <sys/io-net.h
#include <inttypes.h
#include <atomic.h
#include <unistd.h
#include <stdio.h
#include <strings.h
#include <errno.h
#include <net/if.h
#include <net/if_types.h


int my_init( void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options );

void *my_rx_thread( void *arg );
int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl );
int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface );

int my_rx_down( npkt_t *npkt, void *func_hdl );
int my_shutdown1( int registrant_hdl, void *func_hdl );
int my_shutdown2( int registrant_hdl, void *func_hdl );


// Global symbols
void *my_dll_hdl;
io_net_self_t *my_ion;
int my_reg_hdl;
uint16_t my_cell;
uint16_t my_endpoint;

io_net_dll_entry_t io_net_dll_entry =
{
2, // Number of functions
my_init, // init()
NULL // “master” shutdown()
};


// functions that we supply
io_net_registrant_funcs_t my_funcs =
{
_IO_NET_REG_NFUNCS, // nfuncs
my_rx_up, // receive a packet on it’s way up
my_rx_down, // receive a packet on it’s way down
my_tx_done, // release our hold a packet
my_shutdown1, // shutdown1()
my_shutdown2, // shutdown2()
NULL, // dl_advert()
NULL, // devctl()
NULL, // flush()
NULL, // raw_open()
NULL
};

// a description of our driver
io_net_registrant_t my_entry =
{
_REG_FILTER_BELOW, // | _REG_INIT_ONCE, where the f#(% is
_init_once
defined!?
“bpc-ip-filter.so”,// our name
“ip”, // our top type
“ip”, // our bottom type
NULL, // global control handle
&my_funcs, // pointer to our functions
0 // #dependencies
};




// The dll functions.
int my_init (void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion,
char
*options)
{
printf( “my_init\n” );
my_dll_hdl = dll_hdl;
my_ion = ion;

// Register with io-net
if ((*my_ion → reg)
(my_dll_hdl,
&my_entry,
&my_reg_hdl,
&my_cell,
&my_endpoint) < 0)

{
return( -1 );
}

return (0); // success
}

file://debug functions
int parse_npkt( npkt_t *npkt )
{
uint16_t *type;

if ( npkt->flags & _NPKT_NOT_TXED )
printf( "not transmitted " );
if ( npkt->flags & _NPKT_NO_RES )
printf( "up producer wants packet back NOW " );
if ( npkt->flags & _NPKT_UP )
printf( "up " );
else
printf( "down " );
if ( npkt->flags & _NPKT_MSG )
printf( "message " );
if ( npkt->flags & _NPKT_MSG_DYING )
printf( "dying " );
if ( npkt->flags & _NPKT_BCAST )
printf( "broadcast " );
if ( npkt->flags & _NPKT_MCAST )
printf( "multicast " );
if ( npkt->flags & _NPKT_INTERNAL )
printf( "internal " );
if ( npkt->flags & _NPKT_UP_SPECIFIC )
printf( "up specific " );

type = (uint16_t
*)(npkt->buffers.tqh_first->net_iov->iov_base);
switch ( *type )
{
case _IO_NET_MSG_DL_ADVERT:
printf( ":advert " );
break;
case _IO_NET_MSG_ADDR_ADD:
printf( ":message add " );
break;
case _IO_NET_MSG_ADDR_DEL:
printf( ":message del " );
break;
case QNET_IMMSG_IFUP:
printf( ":qnet ifup " );
break;
case QNET_IMMSG_IFDOWN:
printf( ":nqet ifdown " );
break;
case _IO_NET_JOIN_MCAST:
printf( ":join mcast " );
break;
case _IO_NET_REMOVE_MCAST:
printf( ":remove mcast " );
break;
}

printf( “\n\n” );

return 0;
}


int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl )
{
printf( “my_tx_done\n” );

parse_npkt( npkt );

return 0;
}

int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface )
{
printf( “my_rx_up\n” );

parse_npkt( npkt );

(*my_ion->tx_up)( my_reg_hdl, npkt, off, framlen_sub, cell,
endpoint,
iface );

return EOK;
}


int my_rx_down( npkt_t *npkt, void *func_hdl )
{
printf( “my_rx_down\n” );

parse_npkt( npkt );

return (*my_ion->tx_down)( my_reg_hdl, npkt );
}

int my_shutdown1( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown1\n” );
return EOK; // return EBUSY if we don’t want them to shut us
down
yet
}

int my_shutdown2( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown2\n” );
return 0; // at this point, we have no choice and must
shutdown
}







\

I haven’t used it but i have a fair bit of idea as to how to do it ? In the
io-net tx_up io-net simply does a memcmp on the incoming packet(data
portion of npkt) and the pattern (char *pat) that you provide…If the memcmp
returns zero it calls the rx_up function in your code.It is essentially a
very crude form of packet filtering.I am not sure if you can used wild cards
in the pattern because it memcmps rather than do a AND on it. I wish there
were other flags associated with the pattern but there aren’t .

Hope it helps

Sreekanth


“BPC Software Group” <bpc_sw@hotmail.com> wrote in message
news:9uovl8$foa$1@inn.qnx.com

Yeah it was weird. I was definitely getting SOME calls to my rx_up and
rx_down functions.
But the stack was pretty hosed. Now that I have reg_byte_pat(…,all) in
there, it works fine.

But I’m planning to try to use reg_byte_pat to look for a particular port.
I’m wondering if this will work.
possibly not because of the variable size of some things that come before
the ( UDP ) port number.

Anyone use reg_byte_pat for anything except “all” packets?
Chris


Sreekanth <> sreekanth@cambira.com> > wrote in message
news:9uojem$82f$> 1@inn.qnx.com> …
Sure it is a weird thing cause it is not talked about in any of the
documentation.But you said that the io-net is calling your
function(according to the logs) .If haven’t done reg_byte_pat i am not
sure
io-net will call your functions(rx_down and rx_up) .I too faced this
problem and then resolved it by looking at some other code.

Sreekanth


“BPC Software Group” <> bpc_sw@hotmail.com> > wrote in message
news:9uoccr$38p$> 1@inn.qnx.com> …
Thanks for the offer, as you can see I had included the source below.
It turns out I was missing a call to reg_byte_pat() something that is
not
spelled out in the DDK docs.
Thanks to Sean Boudreau and Chris McKillop for their assistance.
Chris


Sreekanth <> sreekanth@cambira.com> > wrote in message
news:9umf10$kdg$> 1@inn.qnx.com> …
Are you sure you are not modifying any of the Cell,Endpoint,iface
parameters
?
I hope you have something like this …

my_rx_down( npkt…) {
:
:
:
:
npi->tx_down(npkt,…);

}
my_rx_up(npkt…) {
:
:
:
:
npi->tx_up(npkt…);
npi->tx_done(npkt…);

}
IF you want you can send me copy of source snippet…where you are
facing
the
problem…I can look into it.


Sreekanth


“BPC Software Group” <> bpc_sw@hotmail.com> > wrote in message
news:9um61n$etl$> 1@inn.qnx.com> …
Thought this might stimulate more discussion… Anyone have a
MINIMAL
IP
or
EN filter skeleton code?
Here is the output from a run. It hangs up the io-net system
until
it
is
unmounted…

root:/fs2p0>mount -Tio-net $PWD/ipfilter.mip
my_init
my_rx_up
up message :advert

my_rx_down
down

my_rx_down
down message :message add

uymy_rx_down
down

root:/fs2p0>umount /dev/io-net/ip_ip0

my_shutdown1
my_shutdown2

Thanks!
Chris


BPC Software Group <> bpc_sw@hotmail.com> > wrote in message
news:9ujp3f$miq$> 1@inn.qnx.com> …
Folks,
I’m at my wit’s end or near it. I can’t seem to figure out why
my
simple
IP_IP filter example hoses up the entire io-net subsystem. I
can
mount
and
unmount it and I get some output indicatig that the init
function
runs,
and
the rx_up and rx_down functions run, and get a few packets. I
just
want
to
pass everythig through but this seems not to work. Is this not
enough?
My
rx_up function just calls tx_up and my rx_down just calls
tx_down.
hoses
up
the system until I umount /dev/io-net/ip_ip0, then it returns to
normal.
I
build normally with qcc -shared -Vgcc_ntomipsle
ipfilter.c -oipfilter.so -w9. I don’t strip the output. I can
see
from
the
printouts that go out on my serial console that the functions
are
all
getting called so the problem seems to be that I am not properly
passing
the
packets through. If someone could comment on what I am doing
wrong,
I
would
be eternally greatful.
Thanks in advance!
Chris


P.S. I can include output from a sample run if anyone thinks
this
would
help. I suspect I’ve done something ( or rather NOT done
something
obvious… )



// ipfilter.c
// a test to see if I can generate an IP filter that hooks into
io-net
// and sees all the packets flowing by in both directions.
//
// The general idea is to hook in as a filter just above the
// tulip driver.
//
// Chris Beasley, Berkeley Process Control, Inc. 2001
//

#include <hw/inout.h
#include <sys/mman.h

#include <sys/io-net.h
#include <inttypes.h
#include <atomic.h
#include <unistd.h
#include <stdio.h
#include <strings.h
#include <errno.h
#include <net/if.h
#include <net/if_types.h


int my_init( void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options );

void *my_rx_thread( void *arg );
int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl );
int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface );

int my_rx_down( npkt_t *npkt, void *func_hdl );
int my_shutdown1( int registrant_hdl, void *func_hdl );
int my_shutdown2( int registrant_hdl, void *func_hdl );


// Global symbols
void *my_dll_hdl;
io_net_self_t *my_ion;
int my_reg_hdl;
uint16_t my_cell;
uint16_t my_endpoint;

io_net_dll_entry_t io_net_dll_entry =
{
2, // Number of functions
my_init, // init()
NULL // “master” shutdown()
};


// functions that we supply
io_net_registrant_funcs_t my_funcs =
{
_IO_NET_REG_NFUNCS, // nfuncs
my_rx_up, // receive a packet on it’s way up
my_rx_down, // receive a packet on it’s way down
my_tx_done, // release our hold a packet
my_shutdown1, // shutdown1()
my_shutdown2, // shutdown2()
NULL, // dl_advert()
NULL, // devctl()
NULL, // flush()
NULL, // raw_open()
NULL
};

// a description of our driver
io_net_registrant_t my_entry =
{
_REG_FILTER_BELOW, // | _REG_INIT_ONCE, where the f#(% is
_init_once
defined!?
“bpc-ip-filter.so”,// our name
“ip”, // our top type
“ip”, // our bottom type
NULL, // global control handle
&my_funcs, // pointer to our functions
0 // #dependencies
};




// The dll functions.
int my_init (void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion,
char
*options)
{
printf( “my_init\n” );
my_dll_hdl = dll_hdl;
my_ion = ion;

// Register with io-net
if ((*my_ion → reg)
(my_dll_hdl,
&my_entry,
&my_reg_hdl,
&my_cell,
&my_endpoint) < 0)

{
return( -1 );
}

return (0); // success
}

file://debug functions
int parse_npkt( npkt_t *npkt )
{
uint16_t *type;

if ( npkt->flags & _NPKT_NOT_TXED )
printf( "not transmitted " );
if ( npkt->flags & _NPKT_NO_RES )
printf( "up producer wants packet back NOW " );
if ( npkt->flags & _NPKT_UP )
printf( "up " );
else
printf( "down " );
if ( npkt->flags & _NPKT_MSG )
printf( "message " );
if ( npkt->flags & _NPKT_MSG_DYING )
printf( "dying " );
if ( npkt->flags & _NPKT_BCAST )
printf( "broadcast " );
if ( npkt->flags & _NPKT_MCAST )
printf( "multicast " );
if ( npkt->flags & _NPKT_INTERNAL )
printf( "internal " );
if ( npkt->flags & _NPKT_UP_SPECIFIC )
printf( "up specific " );

type = (uint16_t
*)(npkt->buffers.tqh_first->net_iov->iov_base);
switch ( *type )
{
case _IO_NET_MSG_DL_ADVERT:
printf( ":advert " );
break;
case _IO_NET_MSG_ADDR_ADD:
printf( ":message add " );
break;
case _IO_NET_MSG_ADDR_DEL:
printf( ":message del " );
break;
case QNET_IMMSG_IFUP:
printf( ":qnet ifup " );
break;
case QNET_IMMSG_IFDOWN:
printf( ":nqet ifdown " );
break;
case _IO_NET_JOIN_MCAST:
printf( ":join mcast " );
break;
case _IO_NET_REMOVE_MCAST:
printf( ":remove mcast " );
break;
}

printf( “\n\n” );

return 0;
}


int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl )
{
printf( “my_tx_done\n” );

parse_npkt( npkt );

return 0;
}

int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface )
{
printf( “my_rx_up\n” );

parse_npkt( npkt );

(*my_ion->tx_up)( my_reg_hdl, npkt, off, framlen_sub, cell,
endpoint,
iface );

return EOK;
}


int my_rx_down( npkt_t *npkt, void *func_hdl )
{
printf( “my_rx_down\n” );

parse_npkt( npkt );

return (*my_ion->tx_down)( my_reg_hdl, npkt );
}

int my_shutdown1( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown1\n” );
return EOK; // return EBUSY if we don’t want them to shut
us
down
yet
}

int my_shutdown2( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown2\n” );
return 0; // at this point, we have no choice and must
shutdown
}









\

Sreekanth <sreekanth@cambira.com> wrote:

I haven’t used it but i have a fair bit of idea as to how to do it ? In the
io-net tx_up io-net simply does a memcmp on the incoming packet(data
portion of npkt) and the pattern (char *pat) that you provide…If the memcmp
returns zero it calls the rx_up function in your code.It is essentially a
very crude form of packet filtering.I am not sure if you can used wild cards
in the pattern because it memcmps rather than do a AND on it. I wish there
were other flags associated with the pattern but there aren’t .

There is “_BYTE_PAT_ALL” defined. That is to say “give me all packets”.
There are modules using byte patten. For example, the ip-en converter,
regist a byte patten with (off=12, len=2, pat=0x0800) and (off=12, len=2,
pat=0x0806) to only accept IP and ARP packet.

-xtang


Hope it helps

Sreekanth



“BPC Software Group” <> bpc_sw@hotmail.com> > wrote in message
news:9uovl8$foa$> 1@inn.qnx.com> …
Yeah it was weird. I was definitely getting SOME calls to my rx_up and
rx_down functions.
But the stack was pretty hosed. Now that I have reg_byte_pat(…,all) in
there, it works fine.

But I’m planning to try to use reg_byte_pat to look for a particular port.
I’m wondering if this will work.
possibly not because of the variable size of some things that come before
the ( UDP ) port number.

Anyone use reg_byte_pat for anything except “all” packets?
Chris


Sreekanth <> sreekanth@cambira.com> > wrote in message
news:9uojem$82f$> 1@inn.qnx.com> …
Sure it is a weird thing cause it is not talked about in any of the
documentation.But you said that the io-net is calling your
function(according to the logs) .If haven’t done reg_byte_pat i am not
sure
io-net will call your functions(rx_down and rx_up) .I too faced this
problem and then resolved it by looking at some other code.

Sreekanth


“BPC Software Group” <> bpc_sw@hotmail.com> > wrote in message
news:9uoccr$38p$> 1@inn.qnx.com> …
Thanks for the offer, as you can see I had included the source below.
It turns out I was missing a call to reg_byte_pat() something that is
not
spelled out in the DDK docs.
Thanks to Sean Boudreau and Chris McKillop for their assistance.
Chris


Sreekanth <> sreekanth@cambira.com> > wrote in message
news:9umf10$kdg$> 1@inn.qnx.com> …
Are you sure you are not modifying any of the Cell,Endpoint,iface
parameters
?
I hope you have something like this …

my_rx_down( npkt…) {
:
:
:
:
npi->tx_down(npkt,…);

}
my_rx_up(npkt…) {
:
:
:
:
npi->tx_up(npkt…);
npi->tx_done(npkt…);

}
IF you want you can send me copy of source snippet…where you are
facing
the
problem…I can look into it.


Sreekanth


“BPC Software Group” <> bpc_sw@hotmail.com> > wrote in message
news:9um61n$etl$> 1@inn.qnx.com> …
Thought this might stimulate more discussion… Anyone have a
MINIMAL
IP
or
EN filter skeleton code?
Here is the output from a run. It hangs up the io-net system
until
it
is
unmounted…

root:/fs2p0>mount -Tio-net $PWD/ipfilter.mip
my_init
my_rx_up
up message :advert

my_rx_down
down

my_rx_down
down message :message add

uymy_rx_down
down

root:/fs2p0>umount /dev/io-net/ip_ip0

my_shutdown1
my_shutdown2

Thanks!
Chris


BPC Software Group <> bpc_sw@hotmail.com> > wrote in message
news:9ujp3f$miq$> 1@inn.qnx.com> …
Folks,
I’m at my wit’s end or near it. I can’t seem to figure out why
my
simple
IP_IP filter example hoses up the entire io-net subsystem. I
can
mount
and
unmount it and I get some output indicatig that the init
function
runs,
and
the rx_up and rx_down functions run, and get a few packets. I
just
want
to
pass everythig through but this seems not to work. Is this not
enough?
My
rx_up function just calls tx_up and my rx_down just calls
tx_down.
hoses
up
the system until I umount /dev/io-net/ip_ip0, then it returns to
normal.
I
build normally with qcc -shared -Vgcc_ntomipsle
ipfilter.c -oipfilter.so -w9. I don’t strip the output. I can
see
from
the
printouts that go out on my serial console that the functions
are
all
getting called so the problem seems to be that I am not properly
passing
the
packets through. If someone could comment on what I am doing
wrong,
I
would
be eternally greatful.
Thanks in advance!
Chris


P.S. I can include output from a sample run if anyone thinks
this
would
help. I suspect I’ve done something ( or rather NOT done
something
obvious… )



// ipfilter.c
// a test to see if I can generate an IP filter that hooks into
io-net
// and sees all the packets flowing by in both directions.
//
// The general idea is to hook in as a filter just above the
// tulip driver.
//
// Chris Beasley, Berkeley Process Control, Inc. 2001
//

#include <hw/inout.h
#include <sys/mman.h

#include <sys/io-net.h
#include <inttypes.h
#include <atomic.h
#include <unistd.h
#include <stdio.h
#include <strings.h
#include <errno.h
#include <net/if.h
#include <net/if_types.h


int my_init( void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options );

void *my_rx_thread( void *arg );
int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl );
int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface );

int my_rx_down( npkt_t *npkt, void *func_hdl );
int my_shutdown1( int registrant_hdl, void *func_hdl );
int my_shutdown2( int registrant_hdl, void *func_hdl );


// Global symbols
void *my_dll_hdl;
io_net_self_t *my_ion;
int my_reg_hdl;
uint16_t my_cell;
uint16_t my_endpoint;

io_net_dll_entry_t io_net_dll_entry =
{
2, // Number of functions
my_init, // init()
NULL // “master” shutdown()
};


// functions that we supply
io_net_registrant_funcs_t my_funcs =
{
_IO_NET_REG_NFUNCS, // nfuncs
my_rx_up, // receive a packet on it’s way up
my_rx_down, // receive a packet on it’s way down
my_tx_done, // release our hold a packet
my_shutdown1, // shutdown1()
my_shutdown2, // shutdown2()
NULL, // dl_advert()
NULL, // devctl()
NULL, // flush()
NULL, // raw_open()
NULL
};

// a description of our driver
io_net_registrant_t my_entry =
{
_REG_FILTER_BELOW, // | _REG_INIT_ONCE, where the f#(% is
_init_once
defined!?
“bpc-ip-filter.so”,// our name
“ip”, // our top type
“ip”, // our bottom type
NULL, // global control handle
&my_funcs, // pointer to our functions
0 // #dependencies
};




// The dll functions.
int my_init (void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion,
char
*options)
{
printf( “my_init\n” );
my_dll_hdl = dll_hdl;
my_ion = ion;

// Register with io-net
if ((*my_ion → reg)
(my_dll_hdl,
&my_entry,
&my_reg_hdl,
&my_cell,
&my_endpoint) < 0)

{
return( -1 );
}

return (0); // success
}

file://debug functions
int parse_npkt( npkt_t *npkt )
{
uint16_t *type;

if ( npkt->flags & _NPKT_NOT_TXED )
printf( "not transmitted " );
if ( npkt->flags & _NPKT_NO_RES )
printf( "up producer wants packet back NOW " );
if ( npkt->flags & _NPKT_UP )
printf( "up " );
else
printf( "down " );
if ( npkt->flags & _NPKT_MSG )
printf( "message " );
if ( npkt->flags & _NPKT_MSG_DYING )
printf( "dying " );
if ( npkt->flags & _NPKT_BCAST )
printf( "broadcast " );
if ( npkt->flags & _NPKT_MCAST )
printf( "multicast " );
if ( npkt->flags & _NPKT_INTERNAL )
printf( "internal " );
if ( npkt->flags & _NPKT_UP_SPECIFIC )
printf( "up specific " );

type = (uint16_t
*)(npkt->buffers.tqh_first->net_iov->iov_base);
switch ( *type )
{
case _IO_NET_MSG_DL_ADVERT:
printf( ":advert " );
break;
case _IO_NET_MSG_ADDR_ADD:
printf( ":message add " );
break;
case _IO_NET_MSG_ADDR_DEL:
printf( ":message del " );
break;
case QNET_IMMSG_IFUP:
printf( ":qnet ifup " );
break;
case QNET_IMMSG_IFDOWN:
printf( ":nqet ifdown " );
break;
case _IO_NET_JOIN_MCAST:
printf( ":join mcast " );
break;
case _IO_NET_REMOVE_MCAST:
printf( ":remove mcast " );
break;
}

printf( “\n\n” );

return 0;
}


int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl )
{
printf( “my_tx_done\n” );

parse_npkt( npkt );

return 0;
}

int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface )
{
printf( “my_rx_up\n” );

parse_npkt( npkt );

(*my_ion->tx_up)( my_reg_hdl, npkt, off, framlen_sub, cell,
endpoint,
iface );

return EOK;
}


int my_rx_down( npkt_t *npkt, void *func_hdl )
{
printf( “my_rx_down\n” );

parse_npkt( npkt );

return (*my_ion->tx_down)( my_reg_hdl, npkt );
}

int my_shutdown1( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown1\n” );
return EOK; // return EBUSY if we don’t want them to shut
us
down
yet
}

int my_shutdown2( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown2\n” );
return 0; // at this point, we have no choice and must
shutdown
}









\

On Thu, 6 Dec 2001 10:15:53 -0800, “BPC Software Group” <bpc_sw@hotmail.com> wrote:

Thanks for the offer, as you can see I had included the source below.
It turns out I was missing a call to reg_byte_pat() something that is not
spelled out in the DDK docs.
Thanks to Sean Boudreau and Chris McKillop for their assistance.
Chris

Hi
I have a customer looking at a similar application, & used your version as a starting
point.
Did you have to make any other changes?
(Apart from adding the reg_byte_pat call just after calling (*my_ion → reg) ?

#include <hw/inout.h
#include <sys/mman.h

#include <sys/io-net.h
#include <inttypes.h
#include <atomic.h
#include <unistd.h
#include <stdio.h
#include <strings.h
#include <errno.h
#include <net/if.h
#include <net/if_types.h


int my_init( void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options );

void *my_rx_thread( void *arg );
int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl );
int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface );

int my_rx_down( npkt_t *npkt, void *func_hdl );
int my_shutdown1( int registrant_hdl, void *func_hdl );
int my_shutdown2( int registrant_hdl, void *func_hdl );


// Global symbols
void *my_dll_hdl;
io_net_self_t *my_ion;
int my_reg_hdl;
uint16_t my_cell;
uint16_t my_endpoint;

io_net_dll_entry_t io_net_dll_entry =
{
2, // Number of functions
my_init, // init()
NULL // “master” shutdown()
};


// functions that we supply
io_net_registrant_funcs_t my_funcs =
{
_IO_NET_REG_NFUNCS, // nfuncs
my_rx_up, // receive a packet on it’s way up
my_rx_down, // receive a packet on it’s way down
my_tx_done, // release our hold a packet
my_shutdown1, // shutdown1()
my_shutdown2, // shutdown2()
NULL, // dl_advert()
NULL, // devctl()
NULL, // flush()
NULL, // raw_open()
NULL
};

// a description of our driver
io_net_registrant_t my_entry =
{
_REG_FILTER_BELOW, // | _REG_INIT_ONCE, where the f#(% is
_init_once
defined!?
“bpc-ip-filter.so”,// our name
“ip”, // our top type
“ip”, // our bottom type
NULL, // global control handle
&my_funcs, // pointer to our functions
0 // #dependencies
};




// The dll functions.
int my_init (void *dll_hdl, dispatch_t *dpp, io_net_self_t *ion, char
*options)
{
printf( “my_init\n” );
my_dll_hdl = dll_hdl;
my_ion = ion;

// Register with io-net
if ((*my_ion → reg)
(my_dll_hdl,
&my_entry,
&my_reg_hdl,
&my_cell,
&my_endpoint) < 0)

{
return( -1 );
}

return (0); // success
}

file://debug functions
int parse_npkt( npkt_t *npkt )
{
uint16_t *type;

if ( npkt->flags & _NPKT_NOT_TXED )
printf( "not transmitted " );
if ( npkt->flags & _NPKT_NO_RES )
printf( "up producer wants packet back NOW " );
if ( npkt->flags & _NPKT_UP )
printf( "up " );
else
printf( "down " );
if ( npkt->flags & _NPKT_MSG )
printf( "message " );
if ( npkt->flags & _NPKT_MSG_DYING )
printf( "dying " );
if ( npkt->flags & _NPKT_BCAST )
printf( "broadcast " );
if ( npkt->flags & _NPKT_MCAST )
printf( "multicast " );
if ( npkt->flags & _NPKT_INTERNAL )
printf( "internal " );
if ( npkt->flags & _NPKT_UP_SPECIFIC )
printf( "up specific " );

type = (uint16_t *)(npkt->buffers.tqh_first->net_iov->iov_base);
switch ( *type )
{
case _IO_NET_MSG_DL_ADVERT:
printf( ":advert " );
break;
case _IO_NET_MSG_ADDR_ADD:
printf( ":message add " );
break;
case _IO_NET_MSG_ADDR_DEL:
printf( ":message del " );
break;
case QNET_IMMSG_IFUP:
printf( ":qnet ifup " );
break;
case QNET_IMMSG_IFDOWN:
printf( ":nqet ifdown " );
break;
case _IO_NET_JOIN_MCAST:
printf( ":join mcast " );
break;
case _IO_NET_REMOVE_MCAST:
printf( ":remove mcast " );
break;
}

printf( “\n\n” );

return 0;
}


int my_tx_done( npkt_t *npkt, void *done_hdl, void *func_hdl )
{
printf( “my_tx_done\n” );

parse_npkt( npkt );

return 0;
}

int my_rx_up( npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface )
{
printf( “my_rx_up\n” );

parse_npkt( npkt );

(*my_ion->tx_up)( my_reg_hdl, npkt, off, framlen_sub, cell,
endpoint,
iface );

return EOK;
}


int my_rx_down( npkt_t *npkt, void *func_hdl )
{
printf( “my_rx_down\n” );

parse_npkt( npkt );

return (*my_ion->tx_down)( my_reg_hdl, npkt );
}

int my_shutdown1( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown1\n” );
return EOK; // return EBUSY if we don’t want them to shut us down
yet
}

int my_shutdown2( int registrant_hdl, void *func_hdl )
{
printf( “my_shutdown2\n” );
return 0; // at this point, we have no choice and must shutdown
}





\