All of lore.kernel.org
 help / color / mirror / Atom feed
* [NETFILTER]: xt_conntrack: add port and direction matching
@ 2008-01-24 22:38 Jan Engelhardt
  2008-01-24 22:38 ` [IPTABLES]: libxt_conntrack revision 1 Jan Engelhardt
  2008-01-29 13:08 ` [NETFILTER]: xt_conntrack: add port and direction matching Patrick McHardy
  0 siblings, 2 replies; 17+ messages in thread
From: Jan Engelhardt @ 2008-01-24 22:38 UTC (permalink / raw)
  To: kaber; +Cc: Netfilter Developer Mailing List

commit 7f1764fa749032eb8566226bbd1c5a58a8a5efc6
Author: Jan Engelhardt <jengelh@computergmbh.de>
Date:   Wed Jan 16 18:58:49 2008 +0100

    [NETFILTER]: xt_conntrack: add port and direction matching
    
    Extend the xt_conntrack match revision 1 by port matching (all four
    {orig,repl}{src,dst}) and by packet direction matching.
    
    Signed-off-by: Jan Engelhardt <jengelh@computergmbh.de>

diff --git a/include/linux/netfilter/xt_conntrack.h b/include/linux/netfilter/xt_conntrack.h
index d2492a3..f3fd83e 100644
--- a/include/linux/netfilter/xt_conntrack.h
+++ b/include/linux/netfilter/xt_conntrack.h
@@ -6,9 +6,6 @@
 #define _XT_CONNTRACK_H
 
 #include <linux/netfilter/nf_conntrack_tuple_common.h>
-#ifdef __KERNEL__
-#	include <linux/in.h>
-#endif
 
 #define XT_CONNTRACK_STATE_BIT(ctinfo) (1 << ((ctinfo)%IP_CT_IS_REPLY+1))
 #define XT_CONNTRACK_STATE_INVALID (1 << 0)
@@ -18,14 +15,21 @@
 #define XT_CONNTRACK_STATE_UNTRACKED (1 << (IP_CT_NUMBER + 3))
 
 /* flags, invflags: */
-#define XT_CONNTRACK_STATE	0x01
-#define XT_CONNTRACK_PROTO	0x02
-#define XT_CONNTRACK_ORIGSRC	0x04
-#define XT_CONNTRACK_ORIGDST	0x08
-#define XT_CONNTRACK_REPLSRC	0x10
-#define XT_CONNTRACK_REPLDST	0x20
-#define XT_CONNTRACK_STATUS	0x40
-#define XT_CONNTRACK_EXPIRES	0x80
+enum {
+	XT_CONNTRACK_STATE        = 1 << 0,
+	XT_CONNTRACK_PROTO        = 1 << 1,
+	XT_CONNTRACK_ORIGSRC      = 1 << 2,
+	XT_CONNTRACK_ORIGDST      = 1 << 3,
+	XT_CONNTRACK_REPLSRC      = 1 << 4,
+	XT_CONNTRACK_REPLDST      = 1 << 5,
+	XT_CONNTRACK_STATUS       = 1 << 6,
+	XT_CONNTRACK_EXPIRES      = 1 << 7,
+	XT_CONNTRACK_ORIGSRC_PORT = 1 << 8,
+	XT_CONNTRACK_ORIGDST_PORT = 1 << 9,
+	XT_CONNTRACK_REPLSRC_PORT = 1 << 10,
+	XT_CONNTRACK_REPLDST_PORT = 1 << 11,
+	XT_CONNTRACK_DIRECTION    = 1 << 12,
+};
 
 /* This is exposed to userspace, so remains frozen in time. */
 struct ip_conntrack_old_tuple
@@ -70,8 +74,10 @@ struct xt_conntrack_mtinfo1 {
 	union nf_inet_addr repldst_addr, repldst_mask;
 	u_int32_t expires_min, expires_max;
 	u_int16_t l4proto;
+	__be16 origsrc_port, origdst_port;
+	__be16 replsrc_port, repldst_port;
+	u_int16_t match_flags, invert_flags;
 	u_int8_t state_mask, status_mask;
-	u_int8_t match_flags, invert_flags;
 };
 
 #endif /*_XT_CONNTRACK_H*/
diff --git a/net/netfilter/xt_conntrack.c b/net/netfilter/xt_conntrack.c
index e92190e..8533085 100644
--- a/net/netfilter/xt_conntrack.c
+++ b/net/netfilter/xt_conntrack.c
@@ -4,7 +4,6 @@
  *
  *	(C) 2001  Marc Boucher (marc@mbsi.ca).
  *	Copyright © CC Computer Consultants GmbH, 2007 - 2008
- *	Jan Engelhardt <jengelh@computergmbh.de>
  *
  *	This program is free software; you can redistribute it and/or modify
  *	it under the terms of the GNU General Public License version 2 as
@@ -20,6 +19,7 @@
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
+MODULE_AUTHOR("Jan Engelhardt <jengelh@computergmbh.de>");
 MODULE_DESCRIPTION("Xtables: connection tracking state match");
 MODULE_ALIAS("ipt_conntrack");
 MODULE_ALIAS("ip6t_conntrack");
@@ -166,6 +166,44 @@ conntrack_mt_repldst(const struct nf_conn *ct,
 	       &info->repldst_addr, &info->repldst_mask, family);
 }
 
+static inline bool
+ct_proto_port_check(const struct xt_conntrack_mtinfo1 *info,
+                    const struct nf_conn *ct)
+{
+	const struct nf_conntrack_tuple *tuple;
+
+	tuple = &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple;
+	if ((info->match_flags & XT_CONNTRACK_PROTO) &&
+	    (tuple->dst.protonum == info->l4proto) ^
+	    !(info->invert_flags & XT_CONNTRACK_PROTO))
+		return false;
+
+	/* Shortcut to match all recognized protocols by using ->src.all. */
+	if ((info->match_flags & XT_CONNTRACK_ORIGSRC_PORT) &&
+	    (tuple->src.u.all == info->origsrc_port) ^
+	    !(info->invert_flags & XT_CONNTRACK_ORIGSRC_PORT))
+		return false;
+
+	if ((info->match_flags & XT_CONNTRACK_ORIGDST_PORT) &&
+	    (tuple->dst.u.all == info->origdst_port) ^
+	    !(info->invert_flags & XT_CONNTRACK_ORIGDST_PORT))
+		return false;
+
+	tuple = &ct->tuplehash[IP_CT_DIR_REPLY].tuple;
+
+	if ((info->match_flags & XT_CONNTRACK_REPLSRC_PORT) &&
+	    (tuple->src.u.all == info->replsrc_port) ^
+	    !(info->invert_flags & XT_CONNTRACK_REPLSRC_PORT))
+		return false;
+
+	if ((info->match_flags & XT_CONNTRACK_REPLDST_PORT) &&
+	    (tuple->dst.u.all == info->repldst_port) ^
+	    !(info->invert_flags & XT_CONNTRACK_REPLDST_PORT))
+		return false;
+
+	return true;
+}
+
 static bool
 conntrack_mt(const struct sk_buff *skb, const struct net_device *in,
              const struct net_device *out, const struct xt_match *match,
@@ -200,10 +238,9 @@ conntrack_mt(const struct sk_buff *skb, const struct net_device *in,
 
 	if (ct == NULL)
 		return info->match_flags & XT_CONNTRACK_STATE;
-
-	if ((info->match_flags & XT_CONNTRACK_PROTO) &&
-	    ((ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum ==
-	    info->l4proto) ^ !(info->invert_flags & XT_CONNTRACK_PROTO)))
+	if ((info->match_flags & XT_CONNTRACK_DIRECTION) &&
+	    (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL) ^
+	    !!(info->invert_flags & XT_CONNTRACK_DIRECTION))
 		return false;
 
 	if (info->match_flags & XT_CONNTRACK_ORIGSRC)
@@ -226,6 +263,9 @@ conntrack_mt(const struct sk_buff *skb, const struct net_device *in,
 		    !(info->invert_flags & XT_CONNTRACK_REPLDST))
 			return false;
 
+	if (!ct_proto_port_check(info, ct))
+		return false;
+
 	if ((info->match_flags & XT_CONNTRACK_STATUS) &&
 	    (!!(info->status_mask & ct->status) ^
 	    !(info->invert_flags & XT_CONNTRACK_STATUS)))

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

^ permalink raw reply related	[flat|nested] 17+ messages in thread
* [PATCH 0/27] Netfilter update
@ 2008-01-02 20:18 Jan Engelhardt
  2008-01-02 20:28 ` [PATCH 10/27] xt_conntrack match, revision 1 Jan Engelhardt
  0 siblings, 1 reply; 17+ messages in thread
From: Jan Engelhardt @ 2008-01-02 20:18 UTC (permalink / raw)
  To: kaber; +Cc: Netfilter Developer Mailing List

Hi Patrick,


Please cherrypick (or fetch&merge) from

	git://computergmbh.de/linux netfilter

	commits b6e9a26f05e83d8058f1dc56a45e5f5d533ad373 to
	ff4d6f3afa5c8edb602a50abafb0ae7a2bb6132d (inclusive)

to receive the strawberries listed below (will also be posted as
replies to this mail for easy review from mailclient).
I planned for these to also go in for 2.6.25 already.

Jan Engelhardt (27):
      [NETFILTER]: remove ipt_TOS.c
      [NETFILTER]: Change semantic of mask value in xt_TOS
      [NETFILTER]: Properly set the TOS field in xt_TOS
      [NETFILTER]: Annotate start of kernel fields in NF headers
      [NETFILTER]: Remove CONFIG_COMPAT code in xt_hashlimit, xt_limit
      [NETFILTER]: xt_CONNMARK target, revision 1
      [NETFILTER]: xt_MARK target, revision 2
      [NETFILTER]: xt_connmark match, revision 1
      [NETFILTER]: Extend nf_inet_addr with in{,6}_addr
      [NETFILTER}: xt_conntrack match, revision 1
      [NETFILTER]: xt_hashlimit: use the new union nf_inet_addr
      [NETFILTER]: xt_hashlimit match, revision 1
      [NETFILTER]: xt_helper: Do not bypass RCU
      [NETFILTER]: xt_helper match, revision 1
      [NETFILTER]: xt_length match, revision 1
      [NETFILTER]: xt_mark match, revision 1
      [NETFILTER]: xt_pkttype: Add explicit check for IPv4
      [NETFILTER]: xt_pkttype IPv6 multicast address recognition
      [NETFILTER]: xt_policy: use the new unoin nf_inet_addr
      [NETFILTER]: Update modules' descriptions
      [NETFILTER]: Convert unfixated types to fixated ones.
      [NETFILTER]: Rename ipt_iprange to xt_iprange
      [NETFILTER]: xt_iprange match, revision 1
      [NETFILTER]: Merge ipt_REJECT and ip6t_REJECT into xt_REJECT
      [NETFILTER]: Merge ipt_ah and ip6t_ah into xt_ah
      [NETFILTER]: Unknot xt_ah IPv6 logic
      [NETFILTER]: Update feature-removal-schedule.txt

 Documentation/feature-removal-schedule.txt   |   44 ++
 include/linux/netfilter.h                    |    4 +
 include/linux/netfilter/xt_CONNMARK.h        |    5 +
 include/linux/netfilter/xt_MARK.h            |    4 +
 include/linux/netfilter/xt_RATEEST.h         |    2 +
 include/linux/netfilter/xt_connlimit.h       |    4 +-
 include/linux/netfilter/xt_connmark.h        |    5 +
 include/linux/netfilter/xt_conntrack.h       |   16 +-
 include/linux/netfilter/xt_hashlimit.h       |   39 ++-
 include/linux/netfilter/xt_helper.h          |    6 +
 include/linux/netfilter/xt_iprange.h         |   17 +
 include/linux/netfilter/xt_length.h          |   18 +
 include/linux/netfilter/xt_mac.h             |    4 +-
 include/linux/netfilter/xt_mark.h            |    5 +
 include/linux/netfilter/xt_pkttype.h         |    4 +-
 include/linux/netfilter/xt_policy.h          |   23 +-
 include/linux/netfilter/xt_quota.h           |    2 +
 include/linux/netfilter/xt_rateest.h         |    2 +
 include/linux/netfilter/xt_sctp.h            |    2 +-
 include/linux/netfilter/xt_state.h           |    2 +-
 include/linux/netfilter/xt_statistic.h       |    1 +
 include/linux/netfilter/xt_string.h          |    2 +
 include/linux/netfilter_ipv4/ipt_CLUSTERIP.h |    1 +
 include/linux/netfilter_ipv4/ipt_LOG.h       |    4 +-
 include/linux/netfilter_ipv4/ipt_SAME.h      |    2 +-
 include/linux/netfilter_ipv4/ipt_iprange.h   |    6 +-
 include/linux/netfilter_ipv4/ipt_sctp.h      |    2 +-
 include/linux/netfilter_ipv6/ip6t_LOG.h      |    4 +-
 net/ipv4/netfilter/Kconfig                   |   31 --
 net/ipv4/netfilter/Makefile                  |    3 -
 net/ipv4/netfilter/ipt_CLUSTERIP.c           |    2 +-
 net/ipv4/netfilter/ipt_ECN.c                 |    2 +-
 net/ipv4/netfilter/ipt_LOG.c                 |    2 +-
 net/ipv4/netfilter/ipt_MASQUERADE.c          |    2 +-
 net/ipv4/netfilter/ipt_NETMAP.c              |    2 +-
 net/ipv4/netfilter/ipt_REDIRECT.c            |    2 +-
 net/ipv4/netfilter/ipt_REJECT.c              |  251 ---------
 net/ipv4/netfilter/ipt_TOS.c                 |   82 ---
 net/ipv4/netfilter/ipt_TTL.c                 |    2 +-
 net/ipv4/netfilter/ipt_ULOG.c                |    2 +-
 net/ipv4/netfilter/ipt_addrtype.c            |    2 +-
 net/ipv4/netfilter/ipt_ah.c                  |  105 ----
 net/ipv4/netfilter/ipt_ecn.c                 |    2 +-
 net/ipv4/netfilter/ipt_iprange.c             |   77 ---
 net/ipv4/netfilter/ipt_recent.c              |    2 +-
 net/ipv4/netfilter/ipt_ttl.c                 |    2 +-
 net/ipv6/netfilter/Kconfig                   |   20 -
 net/ipv6/netfilter/Makefile                  |    2 -
 net/ipv6/netfilter/ip6t_HL.c                 |    2 +-
 net/ipv6/netfilter/ip6t_LOG.c                |    2 +-
 net/ipv6/netfilter/ip6t_REJECT.c             |  260 ----------
 net/ipv6/netfilter/ip6t_ah.c                 |  131 -----
 net/ipv6/netfilter/ip6t_eui64.c              |    2 +-
 net/ipv6/netfilter/ip6t_frag.c               |    2 +-
 net/ipv6/netfilter/ip6t_hbh.c                |    2 +-
 net/ipv6/netfilter/ip6t_hl.c                 |    2 +-
 net/ipv6/netfilter/ip6t_ipv6header.c         |    2 +-
 net/ipv6/netfilter/ip6t_mh.c                 |    2 +-
 net/ipv6/netfilter/ip6t_rt.c                 |    2 +-
 net/netfilter/Kconfig                        |   29 +
 net/netfilter/Makefile                       |    3 +
 net/netfilter/xt_CLASSIFY.c                  |    2 +-
 net/netfilter/xt_CONNMARK.c                  |  119 ++++-
 net/netfilter/xt_CONNSECMARK.c               |    2 +-
 net/netfilter/xt_DSCP.c                      |    8 +-
 net/netfilter/xt_MARK.c                      |   76 ++-
 net/netfilter/xt_NFLOG.c                     |    2 +-
 net/netfilter/xt_NFQUEUE.c                   |    2 +-
 net/netfilter/xt_NOTRACK.c                   |    1 +
 net/netfilter/xt_RATEEST.c                   |    2 +-
 net/netfilter/xt_REJECT.c                    |  484 ++++++++++++++++++
 net/netfilter/xt_SECMARK.c                   |    2 +-
 net/netfilter/xt_TCPMSS.c                    |    2 +-
 net/netfilter/xt_TCPOPTSTRIP.c               |    2 +-
 net/netfilter/xt_TRACE.c                     |    1 +
 net/netfilter/xt_ah.c                        |  194 +++++++
 net/netfilter/xt_comment.c                   |    2 +-
 net/netfilter/xt_connbytes.c                 |    2 +-
 net/netfilter/xt_connlimit.c                 |    2 +-
 net/netfilter/xt_connmark.c                  |   86 +++-
 net/netfilter/xt_conntrack.c                 |  209 +++++++-
 net/netfilter/xt_dccp.c                      |    2 +-
 net/netfilter/xt_dscp.c                      |    2 +-
 net/netfilter/xt_esp.c                       |    2 +-
 net/netfilter/xt_hashlimit.c                 |  361 +++++++++++---
 net/netfilter/xt_helper.c                    |  101 ++++-
 net/netfilter/xt_iprange.c                   |  181 +++++++
 net/netfilter/xt_length.c                    |  198 +++++++-
 net/netfilter/xt_limit.c                     |   56 +--
 net/netfilter/xt_mac.c                       |    2 +-
 net/netfilter/xt_mark.c                      |   66 ++-
 net/netfilter/xt_multiport.c                 |    2 +-
 net/netfilter/xt_owner.c                     |    2 +-
 net/netfilter/xt_physdev.c                   |    2 +-
 net/netfilter/xt_pkttype.c                   |   19 +-
 net/netfilter/xt_policy.c                    |   17 +-
 net/netfilter/xt_quota.c                     |    1 +
 net/netfilter/xt_realm.c                     |    2 +-
 net/netfilter/xt_sctp.c                      |    2 +-
 net/netfilter/xt_state.c                     |    2 +
 net/netfilter/xt_statistic.c                 |    2 +-
 net/netfilter/xt_string.c                    |    2 +-
 net/netfilter/xt_tcpmss.c                    |    2 +-
 net/netfilter/xt_tcpudp.c                    |    2 +-
 net/netfilter/xt_time.c                      |    2 +-
 net/netfilter/xt_u32.c                       |    2 +-
 106 files changed, 2177 insertions(+), 1321 deletions(-)
 create mode 100644 include/linux/netfilter/xt_iprange.h
 delete mode 100644 net/ipv4/netfilter/ipt_REJECT.c
 delete mode 100644 net/ipv4/netfilter/ipt_TOS.c
 delete mode 100644 net/ipv4/netfilter/ipt_ah.c
 delete mode 100644 net/ipv4/netfilter/ipt_iprange.c
 delete mode 100644 net/ipv6/netfilter/ip6t_REJECT.c
 delete mode 100644 net/ipv6/netfilter/ip6t_ah.c
 create mode 100644 net/netfilter/xt_REJECT.c
 create mode 100644 net/netfilter/xt_ah.c
 create mode 100644 net/netfilter/xt_iprange.c

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2008-01-29 13:36 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-24 22:38 [NETFILTER]: xt_conntrack: add port and direction matching Jan Engelhardt
2008-01-24 22:38 ` [IPTABLES]: libxt_conntrack revision 1 Jan Engelhardt
2008-01-29 13:20   ` Patrick McHardy
2008-01-29 13:08 ` [NETFILTER]: xt_conntrack: add port and direction matching Patrick McHardy
  -- strict thread matches above, loose matches on Subject: below --
2008-01-02 20:18 [PATCH 0/27] Netfilter update Jan Engelhardt
2008-01-02 20:28 ` [PATCH 10/27] xt_conntrack match, revision 1 Jan Engelhardt
2008-01-04 14:53   ` Patrick McHardy
2008-01-15  6:48     ` Patrick McHardy
2008-01-15 12:31       ` Jan Engelhardt
2008-01-15 14:13         ` Patrick McHardy
2008-01-16 18:02           ` [NETFILTER]: xt_conntrack: add port and direction matching Jan Engelhardt
2008-01-17 13:52             ` Pablo Neira Ayuso
2008-01-17 15:00               ` Jan Engelhardt
2008-01-20 13:00                 ` Patrick McHardy
2008-01-20 13:12                   ` Jan Engelhardt
2008-01-20 13:15                     ` Patrick McHardy
2008-01-20 16:48                       ` Jan Engelhardt
2008-01-20 16:55                         ` Patrick McHardy
2008-01-21  1:14                   ` Pablo Neira Ayuso
2008-01-21  1:15                     ` Jan Engelhardt
2008-01-21  1:18                       ` Pablo Neira Ayuso
2008-01-21  1:31                         ` Jan Engelhardt
2008-01-21  1:19                     ` Patrick McHardy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.