forked from Markus-Go/nf-hishape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nf-hishape.h
114 lines (95 loc) · 2.94 KB
/
nf-hishape.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
/*
* Copyright 2007-2008 Deutsches Forschungszentrum fuer Kuenstliche Intelligenz
* or its licensors, as applicable.
*
* You may not use this file except under the terms of the accompanying license.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project: nf-HiShape
* File: nf-hishape.h
* Purpose: header file for the nf-HiShape kernel module and its library/userland tool
* Responsible: Markus Goldstein
* Primary Repository: https://github.com/Markus-Go/nf-hishape
* Web Sites: www.madm.dfki.de, www.goldiges.de
*/
#include <linux/ioctl.h>
//#include <linux/time.h>
//#include <linux/spinlock.h>
#include <linux/param.h>
#include <linux/version.h>
#define MAJOR_NUM 100
#define RAND_MAX_VALUE 255
#define N_RAND 1000
#define MAX_DEVICE_LENGTH 256
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)
#define strncasecmp strnicmp
#endif
// 250 - 4
// 500 - 2
#define QUEUE_SIZE 1024
#define LOOP_MSEC 100
inline static int kbs2msec(int kbs) {
// if(kbs <= 100)
return 500;
// if(kbs <= 1000)
// return (-1000/900)*kbs + 1111;
// return 100;
}
inline static int loops(int kbs) {
return kbs2msec(kbs) / LOOP_MSEC;
}
inline static uint32_t max_len(int kbs) {
return (uint32_t)(kbs * 1024.f * kbs2msec(kbs) / 1000.f);
}
static const int LOOP_JIFFIES = (LOOP_MSEC * HZ / 1000);
/*
* _IOR means that we're creating an ioctl command
* number for passing information from a user process
* to the kernel module.
*
* The first arguments, MAJOR_NUM, is the major device
* number we're using.
*
* The second argument is the number of the command
* (there could be several with different meanings).
*
* The third argument is the type we want to get from
* the process to the kernel.
*/
typedef struct {
uint32_t from, to;
uint32_t limit;
} HiShapeRange;
typedef struct {
int (*okfn)(struct sk_buff *);
struct sk_buff *pskb;
} Packet;
typedef struct {
Packet packets[QUEUE_SIZE];
int head, size;
} PacketQueue;
typedef struct {
// spinlock_t lock;
uint32_t len, maxLen;
uint8_t loops, loop;
PacketQueue queue;
} HiShapeStat;
typedef struct {
uint32_t length;
HiShapeRange* ranges;
} HiShapeRanges;
#define IOCTL_HISHAPE_GET_RANGES _IOR(MAJOR_NUM, 0, HiShapeRanges*)
#define IOCTL_HISHAPE_SET_RANGES _IOR(MAJOR_NUM, 1, HiShapeRanges*)
#define IOCTL_HISHAPE_GET_DEVICE _IOR(MAJOR_NUM, 2, char*)
#define IOCTL_HISHAPE_SET_DEVICE _IOR(MAJOR_NUM, 3, char*)
#define IOCTL_HISHAPE_FLUSH _IOR(MAJOR_NUM, 4, void*)
#define IOCTL_HISHAPE_RESERVE _IOR(MAJOR_NUM, 5, uint32_t)
#define IOCTL_HISHAPE_ADD _IOR(MAJOR_NUM, 6, HiShapeRange*)
#define DEVICE_NAME "nf-hishape"
#define DEVICE_FILE_NAME "/dev/nf-hishape"
#define SUCCESS 0