Skip to contentSkip to conversation

Find address type on the packet's interface

PATCH Superseded Laszlo Attila Toth 2 participants 6 messages Nov 20, 2007 – Nov 26, 2007

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

v5 cover Find address type on the packet's interface

Hi Patrick,

This is exactly the same as the previous patchset except the xtables changes:
ipt_addrtype.{c,h} is used, and ipt_addrtype_info for rev 0, ipt_adddrtype_info_v1 for rev 1.

Regards,
Attila

#1 lore raw

PATCH v5 1/2 Find address type on a specific or on any interface

Address type search can be limited to an interface by inet_dev_addr_type function.

---
 include/net/route.h     |    1 +
 net/ipv4/fib_frontend.c |   20 ++++++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)
include/net/route.h +1 -0
index f7ce625..d155c29 100644
@@ -119,6 +119,7 @@ extern unsigned short	ip_rt_frag_needed(struct iphdr *iph, unsigned short new_mt
 extern void		ip_rt_send_redirect(struct sk_buff *skb);
 
 extern unsigned		inet_addr_type(__be32 addr);
+extern unsigned		inet_dev_addr_type(__be32 addr, const struct net_device *dev);
 extern void		ip_rt_multicast_event(struct in_device *);
 extern int		ip_rt_ioctl(unsigned int cmd, void __user *arg);
 extern void		ip_rt_get_source(u8 *src, struct rtable *rt);
net/ipv4/fib_frontend.c +18 -2
index 732d8f0..f116f61 100644
@@ -155,7 +155,11 @@ out:
 	return dev;
 }
 
-unsigned inet_addr_type(__be32 addr)
+/*
+ * Find address type as if only "dev" was present in the system. If
+ * on_dev is NULL then all interfaces are taken into consideration.
+ */
+static inline unsigned __inet_dev_addr_type(__be32 addr, const struct net_device *dev)
 {
 	struct flowi		fl = { .nl_u = { .ip4_u = { .daddr = addr } } };
 	struct fib_result	res;
@@ -175,13 +179,24 @@ unsigned inet_addr_type(__be32 addr)
 	if (local_table) {
 		ret = RTN_UNICAST;
 		if (!local_table->tb_lookup(local_table, &fl, &res)) {
-			ret = res.type;
+			if ((!dev || dev == res.fi->fib_dev))
+				ret = res.type;
 			fib_res_put(&res);
 		}
 	}
 	return ret;
 }
 
+unsigned inet_addr_type(__be32 addr)
+{
+	return __inet_dev_addr_type(addr, NULL);
+}
+
+unsigned inet_dev_addr_type(__be32 addr, const struct net_device *dev)
+{
+       return __inet_dev_addr_type(addr, dev);
+}
+
 /* Given (packet source, input interface) and optional (dst, oif, tos):
    - (main) check, that source is valid i.e. not broadcast or our local
      address.
@@ -925,4 +940,5 @@ void __init ip_fib_init(void)
 }
 
 EXPORT_SYMBOL(inet_addr_type);
+EXPORT_SYMBOL(inet_dev_addr_type);
 EXPORT_SYMBOL(ip_dev_find);
Signature · 1 line
1.5.2.5
#2 lore raw

PATCH v5 2/2 Addrtype match: limit address type checking to an interface

Addrtype match has a new revision (1), which lets address type checking limited to the interface the current packet belongs to. Either incoming or outgoing interface can be used depending on the current hook. In the FORWARD hook two maches should be used if both interfaces have to be checked. The new structure is ipt_addrtype_info_v1.

Revision 0 lets older userspace programs use the match as earlier. ipt_addrtype_info is used.

---
 include/linux/netfilter_ipv4/ipt_addrtype.h |   17 ++++
 net/ipv4/netfilter/ipt_addrtype.c           |  116 +++++++++++++++++++++++----
 2 files changed, 116 insertions(+), 17 deletions(-)
include/linux/netfilter_ipv4/ipt_addrtype.h +17 -0
index 166ed01..3ffb78b 100644
@@ -1,6 +1,22 @@
 #ifndef _IPT_ADDRTYPE_H
 #define _IPT_ADDRTYPE_H
 
+enum
+{
+	IPT_ADDRTYPE_INVERT_SOURCE	= 0x0001,
+	IPT_ADDRTYPE_INVERT_DEST	= 0x0002,
+	IPT_ADDRTYPE_LIMIT_IFACE_IN	= 0x0004,
+	IPT_ADDRTYPE_LIMIT_IFACE_OUT	= 0x0008,
+};
+
+struct ipt_addrtype_info_v1 {
+	u_int16_t	source;		/* source-type mask */
+	u_int16_t	dest;		/* dest-type mask */
+	u_int32_t	flags;
+};
+
+
+/* revision 0 */
 struct ipt_addrtype_info {
 	u_int16_t	source;		/* source-type mask */
 	u_int16_t	dest;		/* dest-type mask */
@@ -8,4 +24,5 @@ struct ipt_addrtype_info {
 	u_int32_t	invert_dest;
 };
 
+
 #endif
net/ipv4/netfilter/ipt_addrtype.c +99 -17

150 lines not on this page · raw message

Signature · 1 line
1.5.2.5
#3 lore raw

PATCH v5 1/1 Address type match: limited to incoming or outgoing interface

Address type checking can be limited to the incoming or outgoing interface depending on the current chain. In the FORWARD chain only one of them is allowed at the same time.

Only revision one is supported.

The man page is updated to print the address types in separate sections instead of a single paragraph.

---
 extensions/libipt_addrtype.c                |  102 +++++++++++++++++++---------
 extensions/libipt_addrtype.man              |   35 +++++++++
 include/linux/netfilter_ipv4/ipt_addrtype.h |   17 ++++
 3 files changed, 122 insertions(+), 32 deletions(-)
linux/netfilter_ipv4/ipt_addrtype.h +17 -0
Index: include/linux/netfilter_ipv4/ipt_addrtype.h
===================================================================
@@ -1,6 +1,22 @@
 #ifndef _IPT_ADDRTYPE_H
 #define _IPT_ADDRTYPE_H
 
+enum
+{
+	IPT_ADDRTYPE_INVERT_SOURCE	= 0x0001,
+	IPT_ADDRTYPE_INVERT_DEST	= 0x0002,
+	IPT_ADDRTYPE_LIMIT_IFACE_IN	= 0x0004,
+	IPT_ADDRTYPE_LIMIT_IFACE_OUT	= 0x0008,
+};
+
+struct ipt_addrtype_info_v1 {
+	u_int16_t	source;		/* source-type mask */
+	u_int16_t	dest;		/* dest-type mask */
+	u_int32_t	flags;
+};
+
+
+/* revision 0 */
 struct ipt_addrtype_info {
 	u_int16_t	source;		/* source-type mask */
 	u_int16_t	dest;		/* dest-type mask */
@@ -8,4 +24,5 @@
 	u_int32_t	invert_dest;
 };
 
+
 #endif
libipt_addrtype.c +70 -32

205 lines not on this page · raw message

libipt_addrtype.man +35 -0
Index: extensions/libipt_addrtype.man
===================================================================
@@ -7,31 +7,66 @@
 .TP
 .BI "UNSPEC"
 an unspecified address (i.e. 0.0.0.0)
+.TP
 .BI "UNICAST"
 an unicast address
+.TP
 .BI "LOCAL"
 a local address
+.TP
 .BI "BROADCAST"
 a broadcast address
+.TP
 .BI "ANYCAST"
 an anycast packet
+.TP
 .BI "MULTICAST"
 a multicast address
+.TP
 .BI "BLACKHOLE"
 a blackhole address
+.TP
 .BI "UNREACHABLE"
 an unreachable address
+.TP
 .BI "PROHIBIT"
 a prohibited address
+.TP
 .BI "THROW"
 FIXME
+.TP
 .BI "NAT"
 FIXME
+.TP
 .BI "XRESOLVE"
 FIXME
 .TP
+Options:
+.TP
 .BI "--src-type " "type"
 Matches if the source address is of given type
 .TP
 .BI "--dst-type " "type"
 Matches if the destination address is of given type
+.TP
+.BI "--limit-iface-in"
+The address type checking can be limited to the interface the packet is coming
+in. This option is only valid in the
+.BR PREROUTING ,
+.B INPUT
+and
+.B FORWARD
+chains. It cannot be specified with the
+.B "--limit-iface-out"
+option.
+.TP
+.BI "--limit-iface-out"
+The address type checiking can be limited to the interface the packet is going
+out. This option is only valid in the
+.BR POSTROUTING ,
+.B OUTPUT
+and
+.B FORWARD
+chains. It cannot be specified with the
+.B --limit-iface-in
+option.
#4 lore raw

Re: [PATCHv5 2/2] Addrtype match: limit address type checking to an interface

In reply to Laszlo Attila Toth
Quoted 8 lines · Laszlo Attila Toth

Addrtype match has a new revision (1), which lets address type checking limited to the interface the current packet belongs to. Either incoming or outgoing interface can be used depending on the current hook. In the FORWARD hook two maches should be used if both interfaces have to be checked. The new structure is ipt_addrtype_info_v1.

Revision 0 lets older userspace programs use the match as earlier. ipt_addrtype_info is used.

I only applied this to spare you a sixth resend, it had overly long lines as well and added a useless module alias for the same name. Anyway, I've fixed up a basically 100% reject with Jan's renaming patch and applied it.

I still don't like the way the interface is specified very much, mainly the fact that with the interface limitation you can't reasonable match on both source and destination type anymore, so I might change this.

#5 lore raw

Re: [PATCHv5 1/2] Find address type on a specific or on any interface

In reply to Laszlo Attila Toth
Quoted 2 lines · Laszlo Attila Toth

Address type search can be limited to an interface by inet_dev_addr_type function.

Applied with some minor fixups:

- fix lines over 80 characters
- use "unsigned int" instead of just "unsigned"
- reorder dev and addr arguments to inet_dev_addr_type since that matches the function name