Sample source/logger.c

From ImageStream Router Documentation

Revision as of 16:09, 19 May 2009 by Syoder (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
/*************************************************************************/
/* (C)1999-2009 ImageStream Internet Solutions, Inc. All rights reserved */
/* worldwide.                                                            */
/*************************************************************************/

#define KERNEL 1
#define USER 0
#define MODULE
// Needed to compile on Alpha.
#include<asm/current.h>
#include "all.h"

#define MOD_VER "1.00"
#define MOD_DESC "SAND Packet Logging Chain"

MODULE_AUTHOR("Scott Yoder <syoder@imagestream.com>");
MODULE_DESCRIPTION(MOD_DESC);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
module_param_string(identifier, "logger", IFNAMSIZ, 0);
MODULE_PARM_DESC(identifier, "chain identifier");
#else
MODULE_PARM(identifier, "1-5c" __MODULE_STRING(IFNAMSIZ));
#endif

static char identifier[IFNAMSIZ] = { "logger" };
static SAND_USER_CHAIN logger_uc;

int sand_packet_logger_uc(SAND_CHAIN *chain, void **data)
{
        struct sk_buff *skb = (struct sk_buff *)*data;
        int len, i;
        unsigned char *ptr, *name;

        if (skb->dev)
                name = skb->dev->name;
        else
                name = "Unknown";
        len = skb->len;
        ptr = skb->data;
        printk("%s %s(%d): ",  name, (chain->type == SAND_CHAIN_TX) ? "Tx" : "Rx", len);
        for (i=0;i<len;i++)
                printk("%02x ", *ptr++);
        printk("\n");

        return 0; /* Always successful */
}

int sand_packet_logger_init(SAND_CHAIN *chain)
{
        MOD_INC_USE_COUNT;
        return 0; /* Always successful */
}
int sand_packet_logger_cleanup(SAND_CHAIN *chain)
{
        MOD_DEC_USE_COUNT;
        return 0; /* Always successful */
}

/***********************************************************************/
/*                            Module Initialization                    */
/***********************************************************************/

int init_module (void)
{
        int retval;
        memset(&logger_uc, 0, sizeof(SAND_USER_CHAIN));

        logger_uc.function = sand_packet_logger_uc;
        logger_uc.init = sand_packet_logger_init;
        logger_uc.cleanup = sand_packet_logger_cleanup;
        memcpy(logger_uc.identifier, identifier, 16);

        if ((retval = sand_register_user_chain(&logger_uc)) != 0)
                return retval;

        SAND_DEBUG(0, 1, "%s %s\n", MOD_DESC, SAND_COPYRIGHT);
        SAND_DEBUG(1, 1, "%s version %s installed.\n", MOD_DESC, MOD_VER);
        return 0;
}

void cleanup_module(void)
{
        sand_unregister_user_chain(&logger_uc);
        SAND_DEBUG(1, 1, "Unloaded %s module.\n", MOD_DESC);
}
Personal tools
Router software releases