- 论坛徽章:
- 0
|
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/udp.h>
#include <linux/icmp.h>
#include <net/icmp.h>
#include <net/ip.h>
#include <net/tcp.h>
#include <net/route.h>
#include <net/dst.h>
#include <net/net_namespace.h>
#include <linux/netfilter/x_tables.h>
#include <linux/netfilter_ipv4/ip_tables.h>
#ifdef CONFIG_BRIDGE_NETFILTER
#include <linux/netfilter_bridge.h>
#endif
MODULE_LICENSE ("GPL");
MODULE_AUTHOR ("zj");
MODULE_DESCRIPTION ("Xtables: packet \"winnuke\" target for IPv4");
static unsigned int
reject_tg (struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
unsigned int hooknum,
const struct xt_target *target, const void *targinfo)
{
const struct iphdr *oiph;
const struct tcphdr *oth;
struct tcphdr _otcph;
oiph = ip_hdr (skb);
printk("reject_tg call success!!!\n");
if (oiph->frag_off & htons (IP_OFFSET))
return NF_DROP;
switch (oiph->protocol)
{
case IPPROTO_TCP:
printk ("TCP PACKET!!!\n");
break;
case IPPROTO_UDP:
printk ("UDP PACKET!!!\n");
return NF_ACCEPT;
break;
case IPPROTO_ICMP:
return NF_ACCEPT;
break;
default:
return NF_ACCEPT;
}
oth = skb_header_pointer (skb, ip_hdrlen (skb), sizeof (_otcph), &_otcph);
if (oth == NULL)
return NF_DROP;
if (oth->urg)
{
printk ("urg ok!!!!!");
return NF_DROP;
}
else
{
printk ("urg ok!!!!!");
printk ("s_port:%d,d_port:%d", oth->source, oth->dest);
}
return NF_ACCEPT;
}
static bool
reject_tg_check(const char *tablename, const void *e_void,
const struct xt_target *target, void *targinfo,
unsigned int hook_mask)
{
printk("check called!!!.\n");
return true;
}
static struct xt_target reject_tg_reg __read_mostly = {
.name = "reject",
.family = PF_INET,
.target = reject_tg,
.hooks = (1 << NF_INET_LOCAL_IN) | (1 << NF_INET_FORWARD) |
(1 << NF_INET_LOCAL_OUT),
.checkentry = reject_tg_check,
.me = THIS_MODULE,
};
static int __init
reject_tg_init (void)
{
printk("insmod success!!\n");
return xt_register_target (&reject_tg_reg);
}
static void __exit
reject_tg_exit (void)
{
printk("rmmod success!!\n");
xt_unregister_target (&reject_tg_reg);
}
module_init (reject_tg_init);
module_exit (reject_tg_exit); |
|
|