-
Notifications
You must be signed in to change notification settings - Fork 735
/
Copy pathtoa.h
151 lines (132 loc) · 3.5 KB
/
toa.h
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* DPVS is a software load balancer (Virtual Server) based on DPDK.
*
* Copyright (C) 2021 iQIYI (www.iqiyi.com).
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef __NET__TOA_H__
#define __NET__TOA_H__
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/err.h>
#include <linux/time.h>
#include <linux/skbuff.h>
#include <net/tcp.h>
#include <net/inet_common.h>
#include <linux/uaccess.h>
#include <linux/netdevice.h>
#include <net/net_namespace.h>
#include <linux/fs.h>
#include <linux/sysctl.h>
#include <linux/proc_fs.h>
#include <linux/kallsyms.h>
#include <net/ipv6.h>
#include <net/transp_v6.h>
#include <net/sock.h>
#include <linux/netfilter.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)
#include <linux/kprobes.h>
#endif
#define TOA_VERSION "2.0.0.0"
#ifdef TOA_DEBUG_ENABLE
#define TOA_DBG(msg...) \
do { \
printk(KERN_DEBUG "[DEBUG] TOA: " msg); \
} while (0)
#else
#define TOA_DBG(msg...)
#endif
#define TOA_INFO(msg...) \
do { \
if (net_ratelimit()) \
printk(KERN_INFO "TOA: " msg); \
} while (0)
#define TCPOPT_TOA 254
/* MUST be 4n !!!! */
#define TCPOLEN_IP4_TOA 8 /* |opcode|size|ip+port| = 1 + 1 + 6 */
#define TCPOLEN_IP6_TOA 20 /* |opcode|size|ip_of_v6+port| = 1 + 1 + 18 */
/* MUST be 4 bytes alignment */
struct toa_ip4_data {
__u8 opcode;
__u8 opsize;
__u16 port;
__u32 ip;
};
#if (defined(TOA_IPV6_ENABLE) || defined(TOA_NAT64_ENABLE))
struct toa_ip6_data {
__u8 opcode;
__u8 opsize;
__u16 port;
struct in6_addr in6_addr;
};
#endif
#ifdef TOA_NAT64_ENABLE
struct toa_nat64_peer {
struct in6_addr saddr;
__u16 port;
};
/* toa socket options, now only for nat64 */
enum {
TOA_BASE_CTL = 4096,
/* set */
TOA_SO_SET_MAX = TOA_BASE_CTL,
/* get */
TOA_SO_GET_LOOKUP = TOA_BASE_CTL,
TOA_SO_GET_MAX = TOA_SO_GET_LOOKUP,
};
#endif
/*should be larger than enum sock_flags(net/sock.h)*/
enum toa_sock_flags {
#if defined(__x86_64__)
SOCK_NAT64 = 63
#else
SOCK_NAT64 = 31
#endif
};
/* statistics about toa in proc /proc/net/toa_stat */
enum {
SYN_RECV_SOCK_TOA_CNT = 1,
SYN_RECV_SOCK_NO_TOA_CNT,
GETNAME_TOA_OK_CNT,
GETNAME_TOA_MISMATCH_CNT,
GETNAME_TOA_BYPASS_CNT,
GETNAME_TOA_EMPTY_CNT,
#if (defined(TOA_IPV6_ENABLE) || defined(TOA_NAT64_ENABLE))
IP6_ADDR_ALLOC_CNT,
IP6_ADDR_FREE_CNT,
#endif
TOA_STAT_LAST
};
struct toa_stats_entry {
char *name;
int entry;
};
#define TOA_STAT_ITEM(_name, _entry) { \
.name = _name, \
.entry = _entry, \
}
#define TOA_STAT_END { \
NULL, \
0, \
}
struct toa_stat_mib {
unsigned long mibs[TOA_STAT_LAST];
};
#define DEFINE_TOA_STAT(type, name) \
__typeof__(type) *name
#define TOA_INC_STATS(mib, field) \
(per_cpu_ptr(mib, smp_processor_id())->mibs[field]++)
#endif