forked from UW-WiNGS/virtnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtCoding.c
64 lines (52 loc) · 1.83 KB
/
virtCoding.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
/*
* Copyright (C) 2014 Joshua Hare, Lance Hartung, and Suman Banerjee.
*
* 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.
*
* 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
*/
#include <linux/skbuff.h>
#include <linux/raid/xor.h> /* Optimized XOR code */
#include "virtCoding.h"
/*
* dest->len must be large enough to hold src->len or at least have enough
* tailroom so that it can expand to hold src->len.
*/
int xor_sk_buff(struct sk_buff *dest, struct sk_buff *src, int offset)
{
int bytes = src->len - offset;
#if 0
void *dest_ptr = dest->data + offset;
void *src_ptr = src->data + offset;
#endif
unsigned char *dest_ptr = dest->data + offset;
unsigned char *src_ptr = src->data + offset;
int i;
int diff = src->len - dest->len;
if(diff > 0) {
unsigned char *space;
if(WARN_ON(skb_tailroom(dest) < diff))
return 0;
space = skb_put(dest, diff);
memset(space, 0, diff);
}
for(i = 0; i < bytes; i++) {
dest_ptr[i] ^= src_ptr[i];
}
#if 0
/* I would prefer to use this optimized XOR code, but I believe it assumes
* that the data fit nicely into words. */
xor_blocks(1, bytes, dest_ptr, &src_ptr);
#endif
return bytes;
}