Repository navigation
Expand file tree
/
Copy pathhello_func_test.c
More file actions
78 lines (58 loc) · 1.57 KB
/
Copy pathhello_func_test.c
File metadata and controls
78 lines (58 loc) · 1.57 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
71
72
73
74
75
76
77
#include <linux/module.h>
#include <linux/init.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/net_namespace.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <rohc/rohc_comp.h>
#include <rohc/rohc.h>
static struct nf_hook_ops nfho;
static int gen_false_random_num(const struct rohc_comp *const comp,
void *const user_context);
static unsigned int hook_func (void *priv,
struct sk_buff *skb,
const struct nf_hook_state *state) {
struct iphdr *iph;
struct tcphdr *tph;
struct rohc_comp *compressor;
iph = ip_hdr(skb);
tph = tcp_hdr(skb);
pr_info("Packet !\n");
if (!skb)
return NF_ACCEPT;
if (iph->protocol == IPPROTO_TCP) {
if (tph) {
pr_info("compressor\n");
compressor = rohc_comp_new2(ROHC_SMALL_CID, ROHC_SMALL_CID_MAX,
gen_false_random_num, NULL);
if (compressor == NULL) {
pr_info("failed\n");
return NF_DROP;
}
rohc_comp_free(compressor);
}
else
return NF_DROP;
}
return NF_ACCEPT;
}
static int gen_false_random_num(const struct rohc_comp *const comp,
void *const user_context) {
return 0;
}
static int __init my_init(void) {
nfho.hook = hook_func;
nfho.hooknum = NF_INET_LOCAL_IN;
nfho.pf = NFPROTO_IPV4;
nfho.priority = NF_IP_PRI_CONNTRACK_CONFIRM - 1;
nfho.priv = NULL;
nf_register_net_hook(&init_net, &nfho);
return 0;
}
static void __exit my_exit(void) {
nf_unregister_net_hook(&init_net, &nfho);
}
module_init(my_init);
module_exit(my_exit);