Skip to contentSkip to conversation

Introducing the timer target and match

PATCH In review Josh Samuelson 1 participant 1 message Jun 28, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 Introducing the timer target and match

Greetings again,

This patch adds a TIMER target and a timer match.

Quoting the man page for the target:

This is used to allow you to add a packet's source or destination, MAC or IPv4 address to a named table which has a corresponding timeout value associated with it. New packets matching the target will refresh the timeout value for an entry in the named table. The timeout value can also be refreshed by echoing the MAC or IPv4 address to /proc/net/ipt_TIMER/name. The live timeout values can also be read from the same proc file.

Quoting the man page for the match:

This matches a packet if its address exists in the named TIMER target table. The TIMER table properties will determine whether the source or destination, MAC or IPv4 address of the packet is checked.

Since this patch deals with raw MAC addresses and the concern that was brought up on the list [1], does it appear that I handled that properly?

The patch should apply to 2.6.12 and iptables v1.3.1. Though I'll be away from my email for the next week, I would appreciate any feedback. Questions? Comments? Useful/not?

[1]
http://lists.netfilter.org/pipermail/netfilter-devel/2005-April/019503.html

Cheers,
Josh

include/linux/netfilter_ipv4/ipt_TIMER.h +71 -0
diff -Nru a/include/linux/netfilter_ipv4/ipt_TIMER.h b/include/linux/netfilter_ipv4/ipt_TIMER.h
@@ -0,0 +1,71 @@
+#ifndef _IPT_TIMER_H
+#define _IPT_TIMER_H
+
+#define TIMER_NAME_LEN 128
+
+typedef enum { IPT_TIMER_MAC, IPT_TIMER_IPV4, IPT_TIMER_MAX } ipt_timer_t;
+
+#ifdef __KERNEL__
+
+struct ipt_timer_mac
+{
+	u_int8_t raw[MAX_ADDR_LEN];
+	u_int32_t len;
+};
+
+struct ipt_timer
+{
+	struct list_head list;
+	struct timer_list timer;
+	union
+	{
+		struct ipt_timer_mac mac;
+		u_int32_t ip;
+	} type;
+};
+
+#endif
+
+struct ipt_timer_t_info
+{
+#ifdef __KERNEL__
+	struct list_head list,
+			 *htable;
+	struct proc_dir_entry *pde;
+#else
+	struct
+	{
+		void *next,
+		     *prev;
+	} list,
+	  *htable;
+	void *pde;
+#endif
+	void *me;
+	char name[TIMER_NAME_LEN],
+	     dst;
+	ipt_timer_t type;
+	unsigned int htable_size,
+		     htable_rand,
+		     timeout,
+		     use;
+};
+
+struct ipt_timer_m_info
+{
+	char name[TIMER_NAME_LEN];
+	u_int8_t invert;
+};
+
+#ifdef __KERNEL__
+extern rwlock_t ipt_timer_lock;
+extern int ipt_get_addr(struct ipt_timer_t_info *ttinfo,
+	struct ipt_timer *ta,
+	const struct sk_buff *skb,
+	const struct net_device *nd);
+extern struct ipt_timer *ipt_timer_find(struct ipt_timer_t_info *ttinfo,
+	const struct ipt_timer *ta);
+extern struct ipt_timer_t_info *ipt_timer_t_find(const char *name);
+#endif
+
+#endif /* _IPT_TIMER_H */
net/ipv4/netfilter/Kconfig +29 -0
diff -Nru a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
@@ -375,6 +375,17 @@
 	  destination IP' or `500pps from any given source IP'  with a single
 	  IPtables rule.
 
+config IP_NF_MATCH_TIMER
+	tristate "MAC/IPv4 address timer match support"
+	depends on IP_NF_IPTABLES && IP_NF_TARGET_TIMER && EXPERIMENTAL
+	help
+	  This option adds the ability to match a packet if its address
+	  exists in the named TIMER target table.  The TIMER table
+	  properties will determine whether the source or destination,
+	  MAC or IPv4 address of the packet is checked.
+
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 # `filter', generic and specific targets
 config IP_NF_FILTER
 	tristate "Packet filtering"
@@ -445,6 +456,24 @@
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config IP_NF_TARGET_TIMER
+	tristate "MAC/IPv4 address timer target support"
+	depends on IP_NF_IPTABLES && EXPERIMENTAL
+	help
+	  This option adds a 'TIMER' target which allows you to add
+	  a packet's source or destionation, MAC or IPv4 address to a named
+	  table which has a corresponding timeout value associated with it.
+	  New packets matching the target will refresh the timeout value
+	  for an entry in the named table.  The timeout value can also be
+	  refreshed by echoing the MAC or IPv4 address to
+	  /proc/net/ipt_TIMER/name.  The live timeout values can also
+	  be read from the same proc file.
+
+	  See "MAC/IPv4 address timer match support" to match packets from
+	  entries in this target table.
+
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 # NAT + specific targets
 config IP_NF_NAT
 	tristate "Full NAT"
net/ipv4/netfilter/Makefile +2 -0
diff -Nru a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile
@@ -59,6 +59,7 @@
 obj-$(CONFIG_IP_NF_MATCH_ADDRTYPE) += ipt_addrtype.o
 obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
 obj-$(CONFIG_IP_NF_MATCH_COMMENT) += ipt_comment.o
+obj-$(CONFIG_IP_NF_MATCH_TIMER) += ipt_timer.o
 
 # targets
 obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
@@ -76,6 +77,7 @@
 obj-$(CONFIG_IP_NF_TARGET_CONNMARK) += ipt_CONNMARK.o
 obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
 obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt_TCPMSS.o
+obj-$(CONFIG_IP_NF_TARGET_TIMER) += ipt_TIMER.o
 obj-$(CONFIG_IP_NF_TARGET_NOTRACK) += ipt_NOTRACK.o
 obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o
 
net/ipv4/netfilter/ipt_TIMER.c +760 -0

760 lines not on this page · raw message

net/ipv4/netfilter/ipt_timer.c +89 -0

89 lines not on this page · raw message

extensions/Makefile +1 -1
diff -Nru a/extensions/Makefile b/extensions/Makefile
@@ -5,7 +5,7 @@
 # header files are present in the include/linux directory of this iptables
 # package (HW)
 #
-PF_EXT_SLIB:=ah addrtype comment connlimit connmark conntrack dscp ecn esp hashlimit helper icmp iprange length limit mac mark multiport owner physdev pkttype realm rpc sctp standard state tcp tcpmss tos ttl udp unclean CLASSIFY CONNMARK DNAT DSCP ECN LOG MARK MASQUERADE MIRROR NETMAP NOTRACK REDIRECT REJECT SAME SNAT TARPIT TCPMSS TOS TRACE TTL ULOG
+PF_EXT_SLIB:=ah addrtype comment connlimit connmark conntrack dscp ecn esp hashlimit helper icmp iprange length limit mac mark multiport owner physdev pkttype realm rpc sctp standard state tcp tcpmss timer tos ttl udp unclean CLASSIFY CONNMARK DNAT DSCP ECN LOG MARK MASQUERADE MIRROR NETMAP NOTRACK REDIRECT REJECT SAME SNAT TARPIT TCPMSS TIMER TOS TRACE TTL ULOG
 PF6_EXT_SLIB:=eui64 hl icmpv6 length limit mac mark multiport owner physdev standard tcp udp HL LOG MARK TRACE
 
 # Optionals
extensions/libipt_TIMER.c +218 -0

218 lines not on this page · raw message

extensions/libipt_TIMER.man +39 -0
diff -Nru a/extensions/libipt_TIMER.man b/extensions/libipt_TIMER.man
@@ -0,0 +1,39 @@
+This is used to allow you to add a packet's source or
+destination, MAC or IPv4 address to a named table which
+has a corresponding timeout value associated with it.
+New packets matching the target will refresh the timeout
+value for an entry in the named table.  The timeout value
+can also be refreshed by echoing the MAC or IPv4 address to
+/proc/net/ipt_TIMER/name.  The live timeout values can also
+be read from the same proc file.
+.TP
+.BI "REQUIRED OPTIONS"
+.RS
+.TP .4i
+.BI "--TIMER-name " "name"
+The name of a TIMER target can be up to 127 characters.
+.TP
+.BI "--TIMER-timeout " "timeout"
+The named table will have this value as its timeout.
+.RE
+.TP
+.BI "REQUIRED TYPE, ONLY ONE SHOULD BE SPECIFIED"
+.RS
+.TP .4i
+.BI "--TIMER-mac"
+The named TIMER target table will keep track of MAC addresses.
+.TP
+.BI "--TIMER-ipv4"
+The named TIMER target table will keep track of IPv4 addresses.
+.RE
+.TP
+.BI "OPTIONAL"
+.RS
+.TP .4i
+.BI "--TIMER-htable-size" "n"
+The named TIMER target will have "n" hash buckets allocated to it.
+.TP
+.BI "--TIMER-dst"
+Optional flag to add the packet destination address in the
+TIMER target table.  The default is to add the source address.
+.RE
extensions/libipt_timer.c +139 -0

139 lines not on this page · raw message

extensions/libipt_timer.man +9 -0
diff -Nru a/extensions/libipt_timer.man b/extensions/libipt_timer.man
@@ -0,0 +1,9 @@
+This matches a packet if its address exists in the named TIMER
+target table.  The TIMER table properties will determine whether
+the source or destination, MAC or IPv4 address of the packet is
+checked.
+.TP
+.BI "--timer-name " "[!] name"
+Where name is a TIMER target table name.  If "!" is specified,
+the rule will match if the packet address is not found in the
+named TIMER table.