Re: [RFC NETFILTER 2/4]: Add xt_rateest match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Nov 25 2007 18:11, Patrick McHardy wrote:

>Date: Sun, 25 Nov 2007 18:11:48 +0100
>From: Patrick McHardy <kaber@xxxxxxxxx>
>To: Netfilter Development Mailinglist <netfilter-devel@xxxxxxxxxxxxxxx>
>Subject: [RFC NETFILTER 2/4]: Add xt_rateest match
>
>
>index 0000000..e4e0653
>--- /dev/null
>+++ b/include/linux/netfilter/xt_rateest.h
>@@ -0,0 +1,33 @@
>+#ifndef _XT_RATEEST_MATCH_H
>+#define _XT_RATEEST_MATCH_H
>+
>+enum xt_rateest_match_flags {
>+	XT_RATEEST_MATCH_INVERT	= 0x01,
>+	XT_RATEEST_MATCH_ABS	= 0x02,
>+	XT_RATEEST_MATCH_REL	= 0x04,
>+	XT_RATEEST_MATCH_DELTA	= 0x08,
>+	XT_RATEEST_MATCH_BPS	= 0x10,
>+	XT_RATEEST_MATCH_PPS	= 0x20,
>+};

Perhaps 1<<0, 1<<1, 1<<2, ...?

>+	spin_lock_bh(&info->est1->lock);
>+	rstats	= &info->est1->rstats;
>+	if (info->flags & XT_RATEEST_MATCH_DELTA) {
>+		bps1	= info->bps1 >= rstats->bps ?
>+					info->bps1 - rstats->bps : 0;
>+		pps1	= info->pps1 >= rstats->pps ?
>+					info->pps1 - rstats->pps : 0;
>+	} else {
>+		bps1	= rstats->bps;
>+		pps1	= rstats->pps;
>+	}
>+	spin_unlock_bh(&info->est1->lock);
>+
>+	if (info->flags & XT_RATEEST_MATCH_ABS) {
>+		bps2	= info->bps2;
>+		pps2	= info->pps2;

I think you can cut down on the extra whitespace around = here,
it already lines up nicely anyway.

>+	} else {
>+		spin_lock_bh(&info->est2->lock);
>+		rstats	= &info->est2->rstats;
>+		if (info->flags & XT_RATEEST_MATCH_DELTA) {
>+			bps2	= info->bps2 >= rstats->bps ?
>+						info->bps2 - rstats->bps : 0;
>+			pps2	= info->pps2 >= rstats->pps ?
>+						info->pps2 - rstats->pps : 0;
>+		} else {
>+			bps2	= rstats->bps;
>+			pps2	= rstats->pps;
>+		}
>+		spin_unlock_bh(&info->est2->lock);
>+	}
>+
>+	switch (info->mode) {
>+	case XT_RATEEST_MATCH_LT:
>+		if (info->flags & XT_RATEEST_MATCH_BPS)
>+			ret &= bps1 < bps2;
>+		if (info->flags & XT_RATEEST_MATCH_PPS)
>+			ret &= pps1 < pps2;
>+		break;
>+	case XT_RATEEST_MATCH_GT:
>+		if (info->flags & XT_RATEEST_MATCH_BPS)
>+			ret &= bps1 > bps2;
>+		if (info->flags & XT_RATEEST_MATCH_PPS)
>+			ret &= pps1 > pps2;
>+		break;
>+	case XT_RATEEST_MATCH_EQ:
>+		if (info->flags & XT_RATEEST_MATCH_BPS)
>+			ret &= bps1 == bps2;
>+		if (info->flags & XT_RATEEST_MATCH_PPS)
>+			ret &= pps2 == pps2;
>+		break;
>+	}
>+
>+	ret ^= info->flags & XT_RATEEST_MATCH_INVERT ? true : false;
>+	return ret;
>+}

	return ret ^ !!(info->flags & XT_RATEEST_MATCH_INVERT);

-
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux