HP Tru64 UNIX Technical Updates for the Version 5.1B and Higher Operating System and Patches (February 2010)
The following example shows how to create a module, custom_filter, which filters out a
packet if it matches the selected type of service (TOS) field of the IP header:
#include "sys/errno.h"
#include "net/if.h"
#include "netinet/ip.h"
#include "sys/mbuf.h"
#include "sys/sysconfig.h"
char custom_filter_tos = 255;
static int debug=0;
char custom_filter_version[] = "custom_filter: V1.00";
cfg_subsys_attr_t packetfilter_attributes[] = {
/*
* name of the table
*/
{"version", CFG_ATTR_STRTYPE,
CFG_OP_QUERY,
(caddr_t) custom_filter_version, 2, 100, 0},
/*
* debug state
*/
{"debug", CFG_ATTR_ULONGTYPE,
CFG_OP_CONFIGURE | CFG_OP_QUERY | CFG_OP_RECONFIGURE,
(caddr_t) &debug, 0, ULONG_MAX, 0},
/*
* Tos to filter on
*/
{"tos", CFG_ATTR_UCHARTYPE,
CFG_OP_QUERY | CFG_OP_CONFIGURE,
(caddr_t) &custom_filter_tos, 0, 255, 0},
{"", 0, 0, 0, 0, 0, 0} /* must be the last element */ };
int
custom_filter(struct ip *ip, int hlen, struct ifnet *rcvif,
int direction, struct mbuf **bufp)
{
if( ip->ip_tos == custom_filter_tos ){
mfreem(bufp);
return(1);
}
return(0);
}
custom_filter_configure(
cfg_op_t op,
caddr_t indata,
ulong indata_size,
caddr_t outdata,
ulong outdata_size)
{
extern int (*fr_checkp) (struct ip *ip, int hlen, struct ifnet *rcvif,
int direction, struct mbuf **mbuf);
switch (op) {
case CFG_OP_CONFIGURE:
fr_checkp=custom_filter;
break;
case CFG_OP_UNCONFIGURE:
fr_checkp=NULL;
}
if( debug > 1 )
Operating System and Associated Products Updates 31