-
Notifications
You must be signed in to change notification settings - Fork 458
/
Copy pathkube_ovn_fastpath.c
113 lines (100 loc) · 3.01 KB
/
kube_ovn_fastpath.c
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/udp.h>
#include <linux/tcp.h>
#include <linux/string.h>
unsigned int hook_func(void *priv,
struct sk_buff *skb, const struct nf_hook_state *state)
{
struct iphdr *ip_header = NULL;
struct udphdr *udp_header = NULL;
struct tcphdr *tcp_header = NULL;
if (!skb){
return NF_ACCEPT;
}
if (state->net == &init_net) {
// for Geneve Tunnel traffic, DO NOT traverse netfilter
ip_header = ip_hdr(skb);
if (NULL != ip_header) {
if (IPPROTO_UDP == ip_header->protocol) {
udp_header = (struct udphdr *)skb_transport_header(skb);
if (ntohs(udp_header->dest) == 6081 || ntohs(udp_header->source) == 6081) {
state->okfn(state->net, state->sk, skb);
return NF_STOLEN;
}
} else {
// for STT Tunnel traffic, DO NOT traverse netfilter
if (IPPROTO_TCP == ip_header->protocol && state->hook != NF_INET_LOCAL_IN) {
tcp_header = (struct tcphdr *)skb_transport_header(skb);
if (ntohs(tcp_header->dest) == 7471) {
state->okfn(state->net, state->sk, skb);
return NF_STOLEN;
}
}
}
}
return NF_ACCEPT;
}
if (state->net != &init_net) {
// for Container traffic, DO NOT traverse netfilter
state->okfn(state->net, state->sk, skb);
return NF_STOLEN;
}
return NF_ACCEPT;
}
static const struct nf_hook_ops fast_path_nf_ops[] = {
{
.hook = hook_func,
.pf = PF_INET,
.hooknum = NF_INET_LOCAL_IN,
.priority = NF_IP_PRI_FIRST,
},
{
.hook = hook_func,
.pf = PF_INET,
.hooknum = NF_INET_LOCAL_OUT,
.priority = NF_IP_PRI_FIRST,
},
{
.hook = hook_func,
.pf = PF_INET,
.hooknum = NF_INET_POST_ROUTING,
.priority = NF_IP_PRI_FIRST,
},
{
.hook = hook_func,
.pf = PF_INET,
.hooknum = NF_INET_PRE_ROUTING,
.priority = NF_IP_PRI_FIRST,
},
};
static int __net_init __fast_path_init(struct net *net)
{
return nf_register_net_hooks(net, fast_path_nf_ops, 4);
}
static void __net_exit __fast_path_cleanup(struct net *net)
{
nf_unregister_net_hooks(net, fast_path_nf_ops, 4);
}
static struct pernet_operations fast_path_ops = {
.init = __fast_path_init,
.exit = __fast_path_cleanup,
};
static int __init fast_path_init(void)
{
printk("init_module,kube_ovn_fast_path\n");
return register_pernet_subsys(&fast_path_ops);
}
/* Cleanup routine */
static void __exit fast_path_cleanup(void)
{
printk("cleanup_module,kube_ovn_fast_path\n");
unregister_pernet_subsys(&fast_path_ops);
}
module_init(fast_path_init);
module_exit(fast_path_cleanup);
MODULE_LICENSE("GPL");