-
Notifications
You must be signed in to change notification settings - Fork 0
/
smac_compat.c
427 lines (376 loc) · 9.38 KB
/
smac_compat.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*********************************************************
* Copyright (C) 2005 VMware, Inc. 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 version 2 and no 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*********************************************************/
/*
* smac_compat.c --
*
* This file defines an abstraction layer to handling
* differences among the Linux kernel and avoiding
* symbol match issues.
*/
#include "driver-config.h"
#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/sched.h>
#include <linux/spinlock.h> // for spinlock_t
#include <linux/slab.h>
#include <linux/poll.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/mm.h>
#include "compat_skbuff.h"
#include <linux/sockios.h>
#define __KERNEL_SYSCALLS__
#include <asm/io.h>
#include <linux/proc_fs.h>
#include <linux/file.h>
#include "vnetInt.h"
#include "vmnetInt.h"
#include "smac_compat.h"
#ifdef VMX86_DEVEL
#define DBG 1
#else
#undef DBG
#endif /* VMX86_DEVEL */
/*
*----------------------------------------------------------------------
* SMACL_GetUptime --
*
* Wrapper for jiffies.
*
* Results:
* Uptime in ticks
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
unsigned long SMACINT
SMACL_GetUptime()
{
return jiffies;
}
/*
*----------------------------------------------------------------------
* SMACL_Memcpy --
*
* Wrapper for memcpy().
*
* Results:
* None.
*
* Side effects:
* Copies memory
*
*----------------------------------------------------------------------
*/
void SMACINT
SMACL_Memcpy(void *d, // IN: destination pointer
const void *s, // IN: source pointer
size_t l) // IN: length to copy
{
memcpy(d, s, l);
}
/*
*----------------------------------------------------------------------
* SMACL_Memcmp --
*
* Wrapper for memcmp().
*
* Results:
* refer to documentation for memcmp().
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int SMACINT
SMACL_Memcmp(const void *p1, // IN: pointer to data
const void *p2, // IN: pointer to data
size_t l) // IN: length to compare
{
return memcmp(p1, p2, l);
}
/*
*----------------------------------------------------------------------
* SMACL_Memset --
*
* Wrapper for memset().
*
* Results:
* None.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void SMACINT
SMACL_Memset(void *p1, // IN: pointer to data
int val, // IN: value to set
size_t l) // IN: length to set
{
memset(p1, val, l);
return;
}
/*
*----------------------------------------------------------------------
* SMACL_Alloc --
*
* Wrapper for kmalloc().
*
* Results:
* Pointer to memory if successful, NULL otherwise
*
* Side effects:
* Allocates memory
*
*----------------------------------------------------------------------
*/
void* SMACINT
SMACL_Alloc(size_t size) // IN: size to allocate
{
return kmalloc(size, GFP_ATOMIC);
}
/*
*----------------------------------------------------------------------
* SMACL_Free --
*
* Wrapper for kfree().
*
* Results:
* None.
*
* Side effects:
* Frees memory
*
*----------------------------------------------------------------------
*/
void SMACINT
SMACL_Free(void *ptr) // IN: pointer to free
{
kfree(ptr);
}
/*
*----------------------------------------------------------------------
* SMACL_InitSpinlock --
*
* Wrapper for spin_lock_init().
* The reason we have to use void is to avoid dependency on kernel.
* The spinlock_t structure can change for different compilation options.
*
* Results:
* None.
*
* Side effects:
* see spin_lock_init()
*
*----------------------------------------------------------------------
*/
void SMACINT
SMACL_InitSpinlock(void **s) // IN: spinlock
{
*s = kmalloc(sizeof(spinlock_t), GFP_ATOMIC);
spin_lock_init((spinlock_t *)*s);
}
/*
*----------------------------------------------------------------------
* SMACL_AcquireSpinlock --
*
* Wrapper for spin_lock_irqsave().
*
* Results:
* None.
*
* Side effects:
* Grabs lock (see spin_lock_irqsave())
*
*----------------------------------------------------------------------
*/
void SMACINT
SMACL_AcquireSpinlock(void **s, // IN: spinlock
unsigned long *flags) // IN/OUT: flags
{
unsigned long f = *flags;
spin_lock_irqsave((spinlock_t *)*s, f);
*flags = f;
}
/*
*----------------------------------------------------------------------
* SMACL_ReleaseSpinlock --
*
* Wrapper for spin_unlock_irqrestore().
*
* Results:
* None.
*
* Side effects:
* Ungrabs lock (see spin_unlock_irqrestore())
*
*----------------------------------------------------------------------
*/
void SMACINT
SMACL_ReleaseSpinlock(void **s, // IN: spinlock
unsigned long *flags) // IN/OUT: flags
{
unsigned long f = *flags;
spin_unlock_irqrestore((spinlock_t *)*s, f);
*flags = f;
}
#ifdef DBG
/*
*----------------------------------------------------------------------
* SMACL_Print --
*
* Wrapper for printk().
*
* Results:
* None.
*
* Side effects:
* Creates output
*
*----------------------------------------------------------------------
*/
void SMACINT
SMACL_Print(const char * msg, // IN: format message
...) // IN: params (currently ignored)
{
char buf[512];
int len;
va_list ap;
va_start(ap, msg);
len = vsnprintf(buf, sizeof buf, msg, ap);
va_end(ap);
buf[sizeof buf - 1] = '\0';
printk(KERN_DEBUG "%s", buf);
}
#endif
/*
*----------------------------------------------------------------------
* SMACL_DupPacket --
*
* Wrapper for skb_copy().
*
* Results:
* Pointer to packet if successful, NULL otherwise
*
* Side effects:
* Creates a private duplicate of packet
*
*----------------------------------------------------------------------
*/
struct sk_buff* SMACINT
SMACL_DupPacket(struct sk_buff *skb) // IN: packet to duplicate
{
return skb_copy(skb, GFP_ATOMIC);
}
/*
*----------------------------------------------------------------------
* SMACL_PacketData --
*
* Wrapper to get data from sk_buff. This function might be
* a bit extreme, but it's good to be able to handle changes
* to the layout of the sk_buff struct.
*
* Results:
* Pointer to data in sk_buff.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void* SMACINT
SMACL_PacketData(struct sk_buff *skb) // IN: pointer to packet buffer
{
return skb->data;
}
/*
*----------------------------------------------------------------------
* SMACL_IsSkbHostBound --
*
* Checks if the direction of the packet is host bound.
*
* Results:
* Returns non zero if host bound
* 0 for anything else
i
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
int SMACINT
SMACL_IsSkbHostBound(struct sk_buff* skb) // IN: packet to process
{
return (skb->pkt_type == PACKET_HOST);
}
#ifdef DBG
/*
*----------------------------------------------------------------------
* SMACL_PrintSkb --
*
* Print information about the skb.
*
* Results:
* prints the sk_buff structure
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
void SMACINT
SMACL_PrintSkb(struct sk_buff *skb, // IN: sk_buff structure
char *str) // IN: type of process
{
LOG(4, (KERN_DEBUG "%s pointer %p shared? %d cloned? %d\n",
str, skb, skb_shared(skb), skb_cloned(skb)));
LOG(4, (KERN_DEBUG "next %p, prev %p\n",
skb->next, skb->prev));
LOG(4, (KERN_DEBUG "sock %p, dev %p\n",
skb->sk, skb->dev));
LOG(4, (KERN_DEBUG "pkt_type %x truesize %u protocol %u\n",
skb->pkt_type, skb->truesize, skb->protocol));
LOG(4, (KERN_DEBUG "users %d, tail %p, end %p\n",
atomic_read(&skb->users), compat_skb_tail_pointer(skb),
compat_skb_end_pointer(skb)));
#if 0
#define C skb->mac.raw
if(skb->mac.raw) {
LOG(4, (KERN_DEBUG "dest %02x:%02x:%02x:%02x:%02x:%02x"
" source %02x:%02x:%02x:%02x:%02x:%02x\n",
C[0],C[1],C[2],C[3],C[4],C[5] ,
C[6],C[7],C[8],C[9],C[10],C[11]));
}
#undef C
if(skb->dst) {
LOG(4, (KERN_DEBUG "dst_entry->__refcount %d\n",
atomic_read(&(skb->dst->__refcnt))));
}
#endif
LOG(4, (KERN_DEBUG "dataref %d end\n",
atomic_read(&(skb_shinfo(skb)->dataref))));
}
#endif