Questions about filters

I have successfully created an io-net “pass-through” filter that mounts
and does not interfere with data. One of the problems I am having though
is that it seems to be so non-interfering that the rx_up() and rx_down()
functions are not even being called. I created a couple on ints and the
placed incrementers into the functions so that when I unmounted the
filter it would create a file that tells me how many times the functions
were called. They always end up as zero. I have included the code below
so if anyone can see why the incrementers are not working I would be
greatfull for an answer.

I also have a few other questions:

  1. In this structure if I make it _REG_FILTER_ABOVE io-net will crash
    when I try to mount the filter but the bpf filter is set up this way so
    why would it make mine crash?

io_net_registrant_t test_entry =
{
_REG_FILTER_BELOW, // filter packets before they hit the
converter
“nfm-test.so”, // our name
“en”, // our top type (TCP/IP stack)
“en”, // our bottom type (Ethernet converter)
NULL, // function handle (see the note below)
&test_funcs, // pointer to our functions
0 // #dependencies
};

  1. Also what are the restrictions for the top type and the bottom type?
    I can’t change either of them from en and en.

  2. How can I get printf to display? From what I know about io-net it
    deamonizes immediately and so printf has no console to display at. I’ve
    been using the creation of files for debugging.


    CODE###################################################CODE

#include <sys/io-net.h>
#include <net/if_types.h>
#include <net/if.h>
#include <stdio.h>
#include <errno.h>

void *test_dll_hdl;
io_net_self_t *test_ion;

int test_reg_hdl;
int packet_count_dn;
int packet_count_up;
uint16_t test_cell;
uint16_t test_lan;

//-----------------------------------------------------------

// Forward declarations
static int my_init (void *dll_hdl,
dispatch_t *dpp,
io_net_self_t *ion,
char *options);

static int register_device (void);

static int test_rx_packets (npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface);
static int test_send_packets (npkt_t *npkt, void *func_hdl);
static int test_receive_complete (npkt_t *npkt, void *done_hdl, void
*func_hdl);
static int test_shutdown1 (int registrant_hdl, void *func_hdl);
static int test_shutdown2 (int registrant_hdl, void *func_hdl);
static int test_flush (int registrant_hdl, void *func_hdl);
static int my_destroy(void *dll_hdl);

//-----------------------------------------------------------

// functions that we supply
io_net_registrant_funcs_t test_funcs =
{
5, // nfuncs
test_rx_packets, // rx_up()
test_send_packets, // rx_down()
test_receive_complete, // tx_done()
test_shutdown1, // shutdown1()
test_shutdown2 // shutdown2()
};




// a description of our driver
io_net_registrant_t test_entry =
{
_REG_FILTER_BELOW, // filter packets before they hit the
converter
“nfm-test.so”, // our name
“en”, // our top type (TCP/IP stack)
“en”, // our bottom type (Ethernet converter)
NULL, // function handle (see the note below)
&test_funcs, // pointer to our functions
0 // #dependencies
};


//------------------------------------------------------------------

// This is the function the io-net searches for when this module is
mounted.
io_net_dll_entry_t io_net_dll_entry =
{
2, // Number of functions
my_init, // init()
my_destroy, // “master” shutdown()
};

//------------------------------------------------------------------
/*

  • Initialization function
    */

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

FILE *fp;
test_dll_hdl = dll_hdl;
test_ion = ion;
packet_count_dn = 0;
packet_count_up = 0;

printf(“Starting Registration”);
fp = fopen("/home/router/NickStuff/RegStart", “w”);
fclose(fp);

if (!register_device ()) {
fp = fopen("/home/router/NickStuff/RegError", “w”);
fclose(fp);

return (-1); // couldn’t register, fail;
// errno says why
}

return (0); // success
}

//---------------------------------------------------------------

/**

  • Device registration
    */
    static int
    register_device (void)
    {
    if ((*test_ion → reg)
    (test_dll_hdl,
    &test_entry,

&test_reg_hdl,
&test_cell,
&test_lan) < 0) {

return (0); // failed
}
return (1); // success
}

//--------------------------------------------------------------------

static int test_rx_packets (npkt_t *npkt,
void *func_hdl,
int off,
int framlen_sub,
uint16_t cell,
uint16_t endpoint,
uint16_t iface)
{
packet_count_up++;
return 0;
}


//--------------------------------------------------------------------

static int test_send_packets (npkt_t *npkt, void *func_hdl) {

packet_count_dn++;

return test_ion->tx_done(test_reg_hdl, npkt);

}

//--------------------------------------------------------------------


static int test_receive_complete (npkt_t *npkt, void *done_hdl, void
*func_hdl)
{
return 0;

}

//--------------------------------------------------------------------


static int test_shutdown1 (int registrant_hdl, void *func_hdl)
{
FILE *fp;
fp = fopen("/home/router/NickStuff/PacketCount.txt", “w”);
fprintf(fp, “Count Down = %d\n”, packet_count_dn);
fprintf(fp, “Count Up = %d\n”, packet_count_up);
fclose(fp);

return EOK;
}

//---------------------------------------------------------------------


static int test_shutdown2 (int registrant_hdl, void *func_hdl)
{
return 0;
}

//---------------------------------------------------------------------

static int test_flush (int registrant_hdl, void *func_hdl)
{
return 0;
}

//--------------------------------------------------------------------

static int my_destroy(void *dll_hdl)
{
return EOK;
}

  1. In this structure if I make it _REG_FILTER_ABOVE io-net will crash
    when I try to mount the filter but the bpf filter is set up this way so
    why would it make mine crash?

A filter above lies between the IP_EN and IP. That means top and bottom
types would need to be IP not EN for ABOVE.

  1. Also what are the restrictions for the top type and the bottom type?
    I can’t change either of them from en and en.

They can only match the types of up and down producers you have existing in
your system already, en for ethernet type, I’ll leave ip for you to guess :wink:

  1. How can I get printf to display? From what I know about io-net it
    deamonizes immediately and so printf has no console to display at. I’ve
    been using the creation of files for debugging.

There may be an easier way but we have run io-net & from a command line in a
terminal, mounted it with the various drivers and each of these print to the
stderr which appears on the terminal.

Hope this is helpful.

Poseidon

I use slogf() instead of printf(). This writes the debug strings to slogger.
Then I can view them w/ the sloginfo command.

“Nick Lovejoy” <nlovejoy@syscor.com> wrote in message
news:<3B60A0EA.C675F27C@syscor.com>…

  1. How can I get printf to display? From what I know about io-net it
    deamonizes immediately and so printf has no console to display at. I’ve
    been using the creation of files for debugging.