1/* IP tables module for matching the value of the IPv4 DSCP field 2 * 3 * ipt_dscp.c,v 1.3 2002/08/05 19:00:21 laforge Exp 4 * 5 * (C) 2002 by Harald Welte <laforge@gnumonks.org> 6 * 7 * This software is distributed under the terms GNU GPL 8 */ 9 10#include <linux/module.h> 11#include <linux/skbuff.h> 12 13#include <linux/netfilter_ipv4/ipt_dscp.h> 14#include <linux/netfilter_ipv4/ip_tables.h> 15 16MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>"); 17MODULE_DESCRIPTION("IP tables DSCP matching module"); 18MODULE_LICENSE("GPL"); 19 20static int match(const struct sk_buff *skb, const struct net_device *in, 21 const struct net_device *out, const void *matchinfo, 22 int offset, const void *hdr, u_int16_t datalen, 23 int *hotdrop) 24{ 25 const struct ipt_dscp_info *info = matchinfo; 26 const struct iphdr *iph = skb->nh.iph; 27 28 u_int8_t sh_dscp = ((info->dscp << IPT_DSCP_SHIFT) & IPT_DSCP_MASK); 29 30 return ((iph->tos&IPT_DSCP_MASK) == sh_dscp) ^ info->invert; 31} 32 33static int checkentry(const char *tablename, const struct ipt_ip *ip, 34 void *matchinfo, unsigned int matchsize, 35 unsigned int hook_mask) 36{ 37 if (matchsize != IPT_ALIGN(sizeof(struct ipt_dscp_info))) 38 return 0; 39 40 return 1; 41} 42 43static struct ipt_match dscp_match = { { NULL, NULL }, "dscp", &match, 44 &checkentry, NULL, THIS_MODULE }; 45 46static int __init init(void) 47{ 48 return ipt_register_match(&dscp_match); 49} 50 51static void __exit fini(void) 52{ 53 ipt_unregister_match(&dscp_match); 54 55} 56 57module_init(init); 58module_exit(fini); 59