-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path0001-add-ext-in-sendto-for-low-level-packet-injection.patch
More file actions
88 lines (82 loc) · 2.15 KB
/
0001-add-ext-in-sendto-for-low-level-packet-injection.patch
File metadata and controls
88 lines (82 loc) · 2.15 KB
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
From a66e1b6a1b703e30e0a669ead581a8bf613ad4b4 Mon Sep 17 00:00:00 2001
From: Eduardo Bart <edub4rt@gmail.com>
Date: Wed, 22 Feb 2012 06:16:17 -0200
Subject: [PATCH] add ext in sendto() for low level packet injection
---
net/socket.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/net/socket.c b/net/socket.c
index 28a96af484b..02a6239da3e 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -95,6 +95,7 @@
#include <net/compat.h>
#include <net/wext.h>
#include <net/cls_cgroup.h>
+#include <net/ip.h>
#include <net/sock.h>
#include <linux/netfilter.h>
@@ -1684,6 +1685,53 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
return err;
}
+int rawsendto(int fd, void *buff, size_t len, unsigned flags, struct sockaddr *addr, int addr_len)
+{
+ struct socket *sock;
+ struct sock *sk;
+ struct sk_buff *skb;
+ struct net_device *dev;
+ int fput_needed;
+ int err;
+
+ sock = sockfd_lookup_light(fd, &err, &fput_needed);
+ if(!sock)
+ goto out;
+
+ sk = sock->sk;
+ if(!sk->sk_bound_dev_if) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ dev = dev_get_by_index_rcu(sock_net(sk), sk->sk_bound_dev_if);
+ if(!dev) {
+ err = -ENODEV;
+ goto out;
+ }
+
+ skb = alloc_skb(len, GFP_ATOMIC);
+ if(!skb) {
+ err = -ENOBUFS;
+ goto out;
+ }
+
+ skb->dev = dev;
+ skb->priority = sk->sk_priority;
+ skb->pkt_type = PACKET_HOST;
+ skb->protocol = htons(ETH_P_IP);
+
+ memcpy(skb_put(skb, len), buff, len);
+
+ if(dev_queue_xmit(skb) == NET_XMIT_SUCCESS)
+ err = len;
+ else
+ err = -ENOBUFS;
+out:
+ return err;
+}
+
+
/*
* Send a datagram to a given address. We move the address into kernel
* space and check the user space data area is readable before invoking
@@ -1701,6 +1749,9 @@ SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
struct iovec iov;
int fput_needed;
+ if(flags & 0x20000)
+ return rawsendto(fd, buff, len, flags, addr, addr_len);
+
if (len > INT_MAX)
len = INT_MAX;
sock = sockfd_lookup_light(fd, &err, &fput_needed);
--
2.12.1