mirror of
https://github.com/Waujito/youtubeUnblock.git
synced 2024-12-22 14:26:11 +00:00
Implement packet send
This commit is contained in:
parent
457911abfa
commit
66191b10f7
@ -47,13 +47,6 @@ static int open_raw_socket(void) {
|
|||||||
int one = 1;
|
int one = 1;
|
||||||
optval.kernel = &one;
|
optval.kernel = &one;
|
||||||
|
|
||||||
// ret = sock_setsockopt(rawsocket, IPPROTO_IP, IP_HDRINCL, optval, sizeof(one));
|
|
||||||
// if (ret < 0)
|
|
||||||
// {
|
|
||||||
// pr_alert("setsockopt(IP_HDRINCL, 1) failed\n");
|
|
||||||
// goto err;
|
|
||||||
// }
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
sr_err:
|
sr_err:
|
||||||
sock_release(rawsocket);
|
sock_release(rawsocket);
|
||||||
@ -71,7 +64,6 @@ static int send_raw_socket(const uint8_t *pkt, uint32_t pktlen) {
|
|||||||
|
|
||||||
if (pktlen > AVAILABLE_MTU) {
|
if (pktlen > AVAILABLE_MTU) {
|
||||||
pr_alert("The packet is too big!");
|
pr_alert("The packet is too big!");
|
||||||
return -ENOMEM;
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Split packet!\n");
|
printf("Split packet!\n");
|
||||||
#endif
|
#endif
|
||||||
@ -123,12 +115,6 @@ static int send_raw_socket(const uint8_t *pkt, uint32_t pktlen) {
|
|||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement packet send via kernel
|
|
||||||
//https://stackoverflow.com/questions/25958715/linux-kernel-module-how-to-reinject-packets-the-kernel-considers-as-nf-stolen
|
|
||||||
//https://stackoverflow.com/questions/15934513/cannot-send-out-packets-by-dev-queue-xmit
|
|
||||||
//https://stackoverflow.com/questions/66846959/send-packet-in-linux-kernel
|
|
||||||
return 0;
|
|
||||||
/*
|
|
||||||
struct iphdr *iph;
|
struct iphdr *iph;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
@ -137,15 +123,9 @@ static int send_raw_socket(const uint8_t *pkt, uint32_t pktlen) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sin_port = 0;
|
|
||||||
|
|
||||||
struct tcphdr *tcph;
|
|
||||||
if (tcp4_payload_split((uint8_t *)pkt, pktlen, NULL, NULL, &tcph, NULL, NULL, NULL) == 0)
|
|
||||||
sin_port = tcph->dest;
|
|
||||||
|
|
||||||
struct sockaddr_in daddr = {
|
struct sockaddr_in daddr = {
|
||||||
.sin_family = AF_INET,
|
.sin_family = AF_INET,
|
||||||
.sin_port = sin_port,
|
.sin_port = 0,
|
||||||
.sin_addr = {
|
.sin_addr = {
|
||||||
.s_addr = iph->daddr
|
.s_addr = iph->daddr
|
||||||
}
|
}
|
||||||
@ -158,20 +138,18 @@ static int send_raw_socket(const uint8_t *pkt, uint32_t pktlen) {
|
|||||||
iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, 1);
|
iov_iter_kvec(&msg.msg_iter, READ, &iov, 1, 1);
|
||||||
|
|
||||||
msg.msg_flags = 0;
|
msg.msg_flags = 0;
|
||||||
msg.msg_name = (struct sockaddr *)&daddr;
|
msg.msg_name = &daddr;
|
||||||
msg.msg_namelen = sizeof(daddr);
|
msg.msg_namelen = sizeof(struct sockaddr_in);
|
||||||
msg.msg_control = NULL;
|
msg.msg_control = NULL;
|
||||||
msg.msg_controllen = 0;
|
msg.msg_controllen = 0;
|
||||||
|
|
||||||
mutex_lock(&rslock);
|
mutex_lock(&rslock);
|
||||||
// ret = sock_sendmsg(rawsocket, &msg);
|
ret = kernel_sendmsg(rawsocket, &msg, &iov, 1, pktlen);
|
||||||
ret = kernel_sendmsg(rawsocket, &msg, &iov, 1, 1);
|
|
||||||
mutex_unlock(&rslock);
|
mutex_unlock(&rslock);
|
||||||
|
|
||||||
pr_info("%d\n", ret);
|
pr_info("%d\n", ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
static unsigned int ykb_tg(struct sk_buff *skb, const struct xt_action_param *par)
|
static unsigned int ykb_tg(struct sk_buff *skb, const struct xt_action_param *par)
|
||||||
{
|
{
|
||||||
|
8
mangle.c
8
mangle.c
@ -57,6 +57,7 @@ nfq_tcp_compute_checksum_ipv4(struct tcphdr *tcph, struct iphdr *iph)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define printf pr_info
|
#define printf pr_info
|
||||||
|
#define perror pr_err
|
||||||
#else
|
#else
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <libnetfilter_queue/libnetfilter_queue_ipv4.h>
|
#include <libnetfilter_queue/libnetfilter_queue_ipv4.h>
|
||||||
@ -158,11 +159,10 @@ int ip4_frag(const __u8 *pkt, __u32 buflen, __u32 payload_offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (payload_offset & ((1 << 3) - 1)) {
|
if (payload_offset & ((1 << 3) - 1)) {
|
||||||
#ifdef KERNEL_SPACE
|
#ifdef USER_SPACE
|
||||||
#else
|
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
perror("Payload offset MUST be a multiply of 8!");
|
|
||||||
#endif
|
#endif
|
||||||
|
perror("Payload offset MUST be a multiply of 8!");
|
||||||
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -292,8 +292,6 @@ int tcp4_frag(const __u8 *pkt, __u32 buflen, __u32 payload_offset,
|
|||||||
const char googlevideo_ending[] = "googlevideo.com";
|
const char googlevideo_ending[] = "googlevideo.com";
|
||||||
const int googlevideo_len = 15;
|
const int googlevideo_len = 15;
|
||||||
|
|
||||||
#define GOOGLEVIDEO_MARK 0xfc74
|
|
||||||
|
|
||||||
|
|
||||||
typedef __u8 uint8_t;
|
typedef __u8 uint8_t;
|
||||||
typedef __u32 uint32_t;
|
typedef __u32 uint32_t;
|
||||||
|
4
mangle.h
4
mangle.h
@ -2,6 +2,8 @@
|
|||||||
#define YU_MANGLE_H
|
#define YU_MANGLE_H
|
||||||
#define RAWSOCKET_MARK 0xfc70
|
#define RAWSOCKET_MARK 0xfc70
|
||||||
|
|
||||||
|
#define DEBUG
|
||||||
|
|
||||||
#ifdef KERNEL_SPACE
|
#ifdef KERNEL_SPACE
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
typedef __u8 uint8_t;
|
typedef __u8 uint8_t;
|
||||||
@ -23,6 +25,8 @@ typedef __u32 uint32_t;
|
|||||||
#define IP_MF 0x2000 /* more fragments flag */
|
#define IP_MF 0x2000 /* more fragments flag */
|
||||||
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
|
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
|
||||||
#else
|
#else
|
||||||
|
#define USER_SPACE
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user