Skip to content

Commit

Permalink
NULL Check
Browse files Browse the repository at this point in the history
  • Loading branch information
a-r-g-v committed Aug 22, 2016
1 parent 90ca397 commit 8fde5b9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions post.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <net/checksum.h>
#define DRIVER_AUTHOR "a_r_g_v"
#define DRIVER_DESC "sugoi"
#define ADD_VLAN 50

static struct nf_hook_ops arp_in_nfho;
static struct nf_hook_ops arp_out_nfho;
Expand Down Expand Up @@ -77,12 +78,18 @@ static unsigned int arp_in_hook_func(void *priv,
// TCP Rewrite Checksum
if(iph->protocol == 0x6) {
struct tcphdr *tcph = tcp_hdr(skb);
if(tcph == NULL || tcph->check == NULL) {
return NF_ACCEPT;
}
csum_replace2(&tcph->check, iph->daddr, htonl(daddr));
//printk(KERN_INFO "[After TCP DEST] tcp_check: %08x, old_check: %08x \n", tcph->check, old_check);
}
// UDP Rewrite Checksum
else if (iph->protocol == 17) {
struct udphdr *udph = udp_hdr(skb);
if(udph == NULL || udph->check == NULL) {
return NF_ACCEPT;
}
csum_replace2(&udph->check, iph->daddr, htonl(daddr));
//printk(KERN_INFO "[After UDP DEST] udp_check: %08x, old_check: %08x \n", udph->check, old_check);
}
Expand All @@ -100,11 +107,17 @@ static unsigned int arp_in_hook_func(void *priv,
// TCP, Calucate Checksum
if(iph->protocol == 0x6) {
struct tcphdr *tcph = tcp_hdr(skb);
if(tcph == NULL || tcph->check == NULL) {
return NF_ACCEPT;
}
csum_replace2(&tcph->check, iph->saddr, htonl(saddr));
//printk(KERN_INFO "[After TCP SRC] tcp_check: %08x, old_check: %08x \n", tcph->check, old_check);
// UDP, Calucate Checksum
} else if (iph->protocol == 17) {
struct udphdr *udph = udp_hdr(skb);
if(udph == NULL || udph->check == NULL) {
return NF_ACCEPT;
}
csum_replace2(&udph->check, iph->saddr, htonl(saddr));
//printk(KERN_INFO "[After UDP SRC] udp_check: %08x, old_check: %08x \n", udph->check, old_check);
}
Expand All @@ -114,7 +127,7 @@ static unsigned int arp_in_hook_func(void *priv,
}
if(flag){

skb->vlan_tci += 2015;
skb->vlan_tci += 2000 + ADD_VLAN;
}


Expand Down Expand Up @@ -143,7 +156,7 @@ static unsigned int arp_in_hook_func(void *priv,
arpb->saddr[0] == 192 && arpb->saddr[1] == 168) {
arpb->daddr[0] = arpb->saddr[0] = 10;
arpb->daddr[1] = arpb->saddr[1] = team_id;
skb->vlan_tci += 2015;
skb->vlan_tci += 2000 + ADD_VLAN;
}

//printk(KERN_INFO "[After ARP IN] daddr %pI4, saddr %pI4 in:%s vlan_id: %d, team_id: %d \n", arpb->daddr, arpb->saddr, state->in->name, vlan_id, team_id);
Expand All @@ -165,7 +178,7 @@ static unsigned int arp_out_hook_func(void *priv,
// IP
if (ehdr->h_proto == 0x0008) {
struct iphdr *iph = ip_hdr(skb);
if (iph == NULL) {
if (iph == NULL || iph->daddr == NULL || iph->saddr == NULL) {
return NF_ACCEPT;
}

Expand Down Expand Up @@ -198,19 +211,25 @@ static unsigned int arp_out_hook_func(void *priv,
csum_replace2(&iph->check, iph->saddr, htonl(saddr));
if(iph->protocol == 0x6) {
struct tcphdr *tcph = tcp_hdr(skb);
csum_replace2(&tcph->check, iph->daddr, htonl(daddr));
if (tcph == NULL || tcph->check == NULL ) {
return NF_ACCEPT;
}
csum_replace2(&tcph->check, iph->saddr, htonl(saddr));
//printk(KERN_INFO "[After TCP DEST] tcp_check: %08x, old_check: %08x \n", tcph->check, old_check);
} else if (iph->protocol == 17) {
struct udphdr *udph = udp_hdr(skb);
csum_replace2(&udph->check, iph->daddr, htonl(daddr));
if (udph == NULL || udph->check == NULL ) {
return NF_ACCEPT;
}
csum_replace2(&udph->check, iph->saddr, htonl(saddr));
//printk(KERN_INFO "[After UDP DEST] udp_check: %08x, old_check: %08x \n", udph->check, old_check);
}
iph->saddr = htonl(saddr);
flag = true;

}
if(flag) {
skb->vlan_tci -= 15;
skb->vlan_tci -= ADD_VLAN;
}
if (vlan_id >= 2000) {
skb->vlan_tci -= 2000;
Expand Down Expand Up @@ -243,7 +262,7 @@ static unsigned int arp_out_hook_func(void *priv,
arpb->saddr[0] == 10 && arpb->saddr[1] >= 0 && arpb->saddr[1] <= 15 ) {
arpb->daddr[0] = arpb->saddr[0] = 192;
arpb->daddr[1] = arpb->saddr[1] = 168;
skb->vlan_tci -= 15;
skb->vlan_tci -= ADD_VLAN;
}


Expand Down
Binary file modified post.ko
Binary file not shown.
Binary file modified post.mod.o
Binary file not shown.
Binary file modified post.o
Binary file not shown.

0 comments on commit 8fde5b9

Please sign in to comment.