From f2e21e67a5eef1dcca21ba9e379debf63ac8120a Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Fri, 18 Apr 2014 19:06:59 +0200 Subject: [PATCH] build: resolve compile error with Linux 3.13 net_random has been removed in commit v3.14-rc1~94^2~191 and replaced by its definition, prandom_u32. prandom_u32 was only introduced in v3.8-rc1~74^2~22, so we will have an extra ifdef for 3.7 support. --- extensions/compat_xtables.h | 4 ++++ extensions/xt_CHAOS.c | 4 ++-- extensions/xt_TARPIT.c | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/extensions/compat_xtables.h b/extensions/compat_xtables.h index 8ad8de4..cb5e61e 100644 --- a/extensions/compat_xtables.h +++ b/extensions/compat_xtables.h @@ -12,6 +12,10 @@ # warning Kernels below 3.7 not supported. #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0) +# define prandom_u32() random32() +#endif + #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) # if !defined(CONFIG_NF_CONNTRACK_MARK) # warning You have CONFIG_NF_CONNTRACK enabled, but CONFIG_NF_CONNTRACK_MARK is not (please enable). diff --git a/extensions/xt_CHAOS.c b/extensions/xt_CHAOS.c index f6a89ca..9c80855 100644 --- a/extensions/xt_CHAOS.c +++ b/extensions/xt_CHAOS.c @@ -68,7 +68,7 @@ xt_chaos_total(struct sk_buff *skb, const struct xt_action_param *par) ret = xm_tcp->match(skb, &local_par); hotdrop = local_par.hotdrop; } - if (!ret || hotdrop || (unsigned int)net_random() > delude_percentage) + if (!ret || hotdrop || (unsigned int)prandom_u32() > delude_percentage) return; destiny = (info->variant == XTCHAOS_TARPIT) ? xt_tarpit : xt_delude; @@ -98,7 +98,7 @@ chaos_tg(struct sk_buff *skb, const struct xt_action_param *par) const struct xt_chaos_tginfo *info = par->targinfo; const struct iphdr *iph = ip_hdr(skb); - if ((unsigned int)net_random() <= reject_percentage) { + if ((unsigned int)prandom_u32() <= reject_percentage) { struct xt_action_param local_par; local_par.in = par->in; local_par.out = par->out; diff --git a/extensions/xt_TARPIT.c b/extensions/xt_TARPIT.c index dc1d866..dbfb834 100644 --- a/extensions/xt_TARPIT.c +++ b/extensions/xt_TARPIT.c @@ -107,8 +107,8 @@ static bool xttarpit_honeypot(struct tcphdr *tcph, const struct tcphdr *oth, tcph->syn = true; tcph->ack = true; tcph->window = oth->window & - ((net_random() & 0x1f) - 0xf); - tcph->seq = htonl(net_random() & ~oth->seq); + ((prandom_u32() & 0x1f) - 0xf); + tcph->seq = htonl(prandom_u32() & ~oth->seq); tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn); } @@ -117,7 +117,7 @@ static bool xttarpit_honeypot(struct tcphdr *tcph, const struct tcphdr *oth, tcph->syn = false; tcph->ack = true; tcph->window = oth->window & - ((net_random() & 0x1f) - 0xf); + ((prandom_u32() & 0x1f) - 0xf); tcph->ack_seq = payload > 100 ? htonl(ntohl(oth->seq) + payload) : oth->seq;