-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathicmp_ctrl.c
More file actions
70 lines (62 loc) · 1.36 KB
/
icmp_ctrl.c
File metadata and controls
70 lines (62 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/skbuff.h>
#include <linux/proc_fs.h>
#include <linux/if.h>
#include <linux/in.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/netfilter_ipv4.h>
#include <linux/ip.h>
#define PERMIT_PORT 80
static unsigned int test_firewall(unsigned int hooknum ,struct sk_buff **skb,
const struct net_device *in ,
const struct net_device *out,
int(*okfn)(struct sk_buff*))
{
//struct tcphdr *tcph;
struct iphdr *iph;
// struct sk_buff *skb=*pskb;
if((*skb)->protocol==htons(ETH_P_IP))
{
iph=(*skb)->nh.iph;
if (iph->protocol==IPPROTO_ICMP)
{
printk("\nDROP a ICMP Packet");
return NF_DROP;
}
if(iph->protocol==IPPROTO_TCP){
printk("\nPermit a valid access");
return NF_ACCEPT;
}
}
return NF_ACCEPT;
}
static struct nf_hook_ops ipl1 =
{
{NULL,NULL},
test_firewall,
PF_INET,
NF_IP_PRE_ROUTING,
NF_IP_PRI_FILTER -1
};
int init_module()
{
return nf_register_hook(&ipl1);
}
void cleanup_module()
{
printk("goodbye1");
nf_unregister_hook(&ipl1);
}