Created
January 5, 2014 13:47
-
-
Save malfaux/8268446 to your computer and use it in GitHub Desktop.
xtables RAWNAT patch to allow easy round-robin of udp/tcp data between multiple local processes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /home/build/aur/xtables-addons/orig-src/src/xtables-addons-1.46/extensions/xt_RAWNAT.c 2012-08-23 16:54:21.000000000 +0300 | |
+++ /home/build/aur/xtables-addons/src/xtables-addons-1.46/extensions/xt_RAWNAT.c 2012-11-30 18:13:18.000000000 +0200 | |
@@ -154,7 +154,30 @@ | |
__be32 new_addr; | |
iph = ip_hdr(*pskb); | |
- new_addr = remask(iph->daddr, info->addr.ip, info->mask); | |
+ if(info->mask < 32) { | |
+ void *transport_hdr = (void *)iph + ip_hdrlen(*pskb); | |
+ struct tcphdr *tcph; | |
+ struct udphdr *udph; | |
+ register __u32 hash_val = iph->saddr; | |
+ | |
+ switch (iph->protocol) { | |
+ case IPPROTO_TCP: | |
+ tcph = transport_hdr; | |
+ hash_val ^= tcph->source << 16; | |
+ break; | |
+ case IPPROTO_UDP: | |
+ case IPPROTO_UDPLITE: | |
+ udph = transport_hdr; | |
+ hash_val ^= udph->source << 16; | |
+ break; | |
+ } | |
+ hash_val ^= (hash_val << 16); | |
+ hash_val ^= (hash_val << 8); | |
+ | |
+ new_addr = remask(hash_val , info->addr.ip, info->mask); | |
+ } else { | |
+ new_addr = remask(iph->saddr, info->addr.ip, info->mask); | |
+ } | |
if (iph->daddr == new_addr) | |
return XT_CONTINUE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment