netfilter: arptables: add mcmangle target
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/3 netfilter: arptables: add mcmangle target
This patch adds the mcmangle target for arptables which allows altering the source hardware address in ARP with a multicast hardware address. This target can be used to make a switch flood packets to the ports that use the same MAC multicast address. This is useful to deploy load-sharing clusters in environments in which the switch does not provide a way to flood packets to several ports.
Since all the nodes receives the same packets, each decides if it handles the packet based on hashing approach (See the `cluster' iptables match that comes with this patchset).
Theoretically, the use of the reserved VRRP hardware address should be fine for this, however, switches generally treat this hardware address space as normal unicast hardware address. Thus, in practise, it is not possible to have two nodes with the same VRRP hardware address.
Please, note that this target violates RFC 1812 (section 3.3.2) since an ethernet device must not use a multicast link address.
An example of the use of this target:
arptables -I OUTPUT -o eth0 -j mcmangle --h-length 6 \ --mc-mangle-mac 01:00:5e:00:01:01 --mc-mangle-dev eth0 arptables -I INPUT -i eth0 --h-length 6 --destination-mac \ 01:00:5e:00:01:01 -j mangle --mangle-mac-d 00:zz:yy:xx:5a:27
Where 00:zz:yy:xx:5a:27 is the original hardware address of this node. Note that the mcmangle target registers an entry in the multicast list that is required to get this working:
$ cat /proc/net/dev_mcast | grep eth0 | head -1 2 eth0 1 0 01005e000101
You need the PKTTYPE iptables target (included in this patchset) to set skb->type to PACKET_HOST. Otherwise, you would be only able to ICMP ping nodes in the network ;).
---
include/linux/netfilter_arp/arpt_mcmangle.h | 14 ++++ net/ipv4/netfilter/Kconfig | 12 +++ net/ipv4/netfilter/Makefile | 1 net/ipv4/netfilter/arpt_mcmangle.c | 98 +++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 0 deletions(-) create mode 100644 include/linux/netfilter_arp/arpt_mcmangle.h create mode 100644 net/ipv4/netfilter/arpt_mcmangle.c
include/linux/netfilter_arp/arpt_mcmangle.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _ARPT_MCMANGLE_H +#define _ARPT_MCMANGLE_H +#include <linux/netfilter_arp/arp_tables.h> + +struct net_device ; + +struct arpt_mcmangle +{ +char ifname[IFNAMSIZ ]; +char mc_devaddr[ETH_ALEN ]; +struct net_device __attribute__((aligned (8 ))) *dev; +}; + +#endif /* _ARPT_MANGLE_H */
net/ipv4/netfilter/Kconfig +12 -0
@@ -392,6 +392,18 @@ config IP_NF_ARP_MANGLE Allows altering the ARP packet payload: source and destination hardware and network addresses. +config IP_NF_ARP_MCMANGLE + tristate "ARP multicast address mangling" + help + Allows altering the source unicast hardware address in ARP messages + with a multicast hardware address. This target is useful to make a + switch flood to all ports whose ethernet device have a multicast + hardware address. Please, see that this target violates RFC 1812 + (section 3.3.2) since an ethernet device must not use a multicast + link address. + + To compile it as a module, choose M here. If unsure, say N. + endif # IP_NF_ARPTABLES endmenu
net/ipv4/netfilter/Makefile +1 -0
@@ -67,6 +67,7 @@ obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o # generic ARP tables obj-$(CONFIG_IP_NF_ARPTABLES) += arp_tables.o obj-$(CONFIG_IP_NF_ARP_MANGLE) += arpt_mangle.o +obj-$(CONFIG_IP_NF_ARP_MCMANGLE) += arpt_mcmangle.o # just filtering instance of ARP tables for now obj-$(CONFIG_IP_NF_ARPFILTER) += arptable_filter.o
net/ipv4/netfilter/arpt_mcmangle.c new file +98 -0
98 lines not on this page · raw message
Pablo Neira Ayuso
maintainerPATCH 2/3 netfilter: xtables: add PKTTYPE target
This patch adds the PKTTYPE target which can be used to mangle the skbuff packet type field. This target is useful in conjunction with the arptables mcmangle target to TCP working again when a multicast hardware address is used. An example of its use:
iptables -I PREROUTING ! -s 224.0.0.0/4 -t mangle \ -m pkttype --pkt-type multicast \ -j PKTTYPE --to-pkt-type unicast
Given the following arptables rule-set:
arptables -I OUTPUT -o eth0 -j mcmangle --h-length 6 \ --mc-mangle-mac 01:00:5e:00:01:01 --mc-mangle-dev eth0 arptables -I INPUT --h-length 6 --destination-mac 01:00:5e:00:01:01 \ -j mangle --mangle-mac-d 00:zz:yy:xx:5a:27
See arptables mcmangle target for further information.
---
include/linux/netfilter/xt_PKTTYPE.h | 8 +++++ net/netfilter/Kconfig | 18 ++++++++++++ net/netfilter/Makefile | 1 + net/netfilter/xt_PKTTYPE.c | 50 ++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 0 deletions(-) create mode 100644 include/linux/netfilter/xt_PKTTYPE.h create mode 100644 net/netfilter/xt_PKTTYPE.c
include/linux/netfilter/xt_PKTTYPE.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef _XT_PKTTYPE_TARGET_H +#define _XT_PKTTYPE_TARGET_H + +struct xt_pkttype_target_info { +u_int8_t pkt_type; +}; + +#endif /* _XT_PKTTYPE_TARGET_H */
net/netfilter/Kconfig +18 -0
@@ -405,6 +405,24 @@ config NETFILTER_XT_TARGET_NOTRACK If you want to compile it as a module, say M here and read <file:Documentation/kbuild/modules.txt>. If unsure, say `N'. +config NETFILTER_XT_TARGET_PKTTYPE + tristate '"PKTTYPE" target support' + depends on IP_NF_RAW || IP6_NF_RAW + depends on NETFILTER_ADVANCED + help + The PKTTYPE target allows you to change the link layer packet type. + This target is useful if you have set up a multicast MAC address (via + arptables) for a given interface and you want the packets to reach + the layer 4 stack (which would drop packet tagged as multicast + from the link layer). + + This target can be used in conjunction with arptables and the cluster + match to setup cluster of stateful firewalls which are connected + through a switch. + + If you want to compile it as a module, say M here and read + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'. + config NETFILTER_XT_TARGET_RATEEST tristate '"RATEEST" target support' depends on NETFILTER_ADVANCED
net/netfilter/Makefile +1 -0
@@ -49,6 +49,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_MARK) += xt_MARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o obj-$(CONFIG_NETFILTER_XT_TARGET_NOTRACK) += xt_NOTRACK.o +obj-$(CONFIG_NETFILTER_XT_TARGET_PKTTYPE) += xt_PKTTYPE.o obj-$(CONFIG_NETFILTER_XT_TARGET_RATEEST) += xt_RATEEST.o obj-$(CONFIG_NETFILTER_XT_TARGET_SECMARK) += xt_SECMARK.o obj-$(CONFIG_NETFILTER_XT_TARGET_TPROXY) += xt_TPROXY.o
net/netfilter/xt_PKTTYPE.c new file +50 -0
50 lines not on this page · raw message
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: xtables: add cluster match
In reply to Pablo Neira AyusoThis patch adds the iptables cluster match. This match can be used to deploy gateway and back-end load-sharing clusters.
Assuming that all the nodes see all packets (see arptables mcmangle target and PKTTYPE iptables targets on how to do that), the cluster match decides if this node has to handle a packet given:
jhash(source IP) % total_nodes == node_id
For related connections, the master conntrack is used. An example of its use for a gateway cluster, in one of the cluster nodes:
iptables -I PREROUTING -t mangle -i eth1 -m cluster \ --cluster-total-nodes 2 --cluster-local-node 1 \ --cluster-proc-name eth1 -j MARK --set-mark 0xffff iptables -A PREROUTING -t mangle -i eth1 \ -m mark ! --mark 0xffff -j DROP iptables -A PREROUTING -t mangle -i eth2 -m cluster \ --cluster-total-nodes 2 --cluster-local-node 1 \ --cluster-proc-name eth2 -j MARK --set-mark 0xffff iptables -A PREROUTING -t mangle -i eth2 \ -m mark ! --mark 0xffff -j DROP
And the following rule-set to make all nodes see all the packets:
arptables -I OUTPUT -o eth1 -j mcmangle --h-length 6 \ --mc-mangle-mac 01:00:5e:00:01:01 --mc-mangle-dev eth1 arptables -I INPUT -i eth1 --h-length 6 \ --destination-mac 01:00:5e:00:01:01 \ -j mangle --mangle-mac-d 00:zz:yy:xx:5a:27 arptables -I OUTPUT -o eth2 -j mcmangle --h-length 6 \ --mc-mangle-mac 01:00:5e:00:01:02 --mc-mangle-dev eth2 arptables -I INPUT -i eth2 --h-length 6 \ --destination-mac 01:00:5e:00:01:02 \ -j mangle --mangle-mac-d 00:zz:yy:xx:5a:27
iptables -I PREROUTING ! -s 224.0.0.0/4 -t mangle \ -m pkttype --pkt-type multicast \ -j PKTTYPE --to-pkt-type unicast
In the case of TCP connections, pickup facility has to be disabled to avoid marking TCP ACK packets coming in the reply direction as valid.
echo 0 > /proc/sys/net/netfilter/nf_conntrack_tcp_loose
The match also provides a /proc entry under:
/proc/sys/net/netfilter/cluster/$PROC_NAME
where PROC_NAME is set via --cluster-proc-name. This is useful to include possible cluster reconfigurations via fail-over scripts. Assuming that this node 1, if node 2 is down, you can add node 2 to your node-mask as follows:
echo +2 > /proc/sys/net/netfilter/cluster/$PROC_NAME
---
include/linux/netfilter/xt_cluster.h | 21 ++ net/netfilter/Kconfig | 17 ++ net/netfilter/Makefile | 1 net/netfilter/xt_cluster.c | 323 ++++++++++++++++++++++++++++++++++ 4 files changed, 362 insertions(+), 0 deletions(-) create mode 100644 include/linux/netfilter/xt_cluster.h create mode 100644 net/netfilter/xt_cluster.c
include/linux/netfilter/xt_cluster.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef _XT_CLUSTER_MATCH_H +#define _XT_CLUSTER_MATCH_H + +struct proc_dir_entry ; + +enum xt_cluster_flags { +XT_CLUSTER_F_INV =0 , +}; + +struct xt_cluster_match_info { +u_int16_t total_nodes; +u_int16_t node_id; +u_int32_t hash_seed; +char proc_name[16 ]; +u_int32_t flags; + +/* Used internally by the kernel */ +void *data __attribute__((aligned (8 ))); +}; + +#endif /* _XT_CLUSTER_MATCH_H */
net/netfilter/Kconfig +17 -0
@@ -506,6 +506,23 @@ config NETFILTER_XT_TARGET_TCPOPTSTRIP This option adds a "TCPOPTSTRIP" target, which allows you to strip TCP options from TCP packets. +config NETFILTER_XT_MATCH_CLUSTER + tristate '"cluster" match support' + depends on NETFILTER_ADVANCED + ---help--- + This option allows you to build work-load-sharing clusters of + network servers/stateful firewalls without having a dedicated + load-balancing router/server/switch. Basically, this match returns + true when the packet must be handled by this cluster node. Thus, + all nodes see all packets and this match decides which node handles + what packets. The work-load sharing algorithm is based on source + address hashing. + + If you say Y here, try `iptables -m cluster --help` for + more information. See the PKTTYPE target and the mcmangle arptables + target on how to make your nodes see all packets. You can also have + a look at man iptables(8) for some examples on the usage. + config NETFILTER_XT_MATCH_COMMENT tristate '"comment" match support' depends on NETFILTER_ADVANCED
net/netfilter/Makefile +1 -0
@@ -58,6 +58,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP) += xt_TCPOPTSTRIP.o obj-$(CONFIG_NETFILTER_XT_TARGET_TRACE) += xt_TRACE.o # matches +obj-$(CONFIG_NETFILTER_XT_MATCH_CLUSTER) += xt_cluster.o obj-$(CONFIG_NETFILTER_XT_MATCH_COMMENT) += xt_comment.o obj-$(CONFIG_NETFILTER_XT_MATCH_CONNBYTES) += xt_connbytes.o obj-$(CONFIG_NETFILTER_XT_MATCH_CONNLIMIT) += xt_connlimit.o
net/netfilter/xt_cluster.c new file +323 -0
323 lines not on this page · raw message