Add arptables mangle module
Subsystems (2)
Hello Dave,
The patch below adds the arptables 'mangle' module, which allows changing the source/dst hardware/protocol address.
I've added protocol length checking, since this is useful for bridged arp packets. It's useless for non-bridged packets though.
I'm away for two weeks starting this Saturday, so if any alterations have to be made, it'll have to wait until then.
cheers,
Bart
net/ipv4/netfilter/arp_tables.c renamed from net/ipv4/netfilter/arp_tables.c.old +9 -0
@@ -136,6 +136,15 @@ static inline int arp_packet_match(constdprintf ("ARP hardware address length mismatch.\n" );dprintf ("ar_hln: %02x info->arhln: %02x info->arhln_mask: %02x\n" , arphdr->ar_hln, arpinfo->arhln, arpinfo->arhln_mask); +return 0 ; + } + +if (FWINV ((arphdr->ar_pln & arpinfo->arpln_mask) != arpinfo->arpln, +ARPT_INV_ARPPLN )) { +dprintf ("ARP protocol address length mismatch.\n" ); +dprintf ("ar_pln: %02x info->arpln: %02x info->arhpn_mask: %02x\n" , + arphdr->ar_pln, arpinfo->arpln, arpinfo->arpln_mask); +return 0 ; } src_devaddr = arpptr;
include/linux/netfilter_arp/arp_tables.h renamed from include/linux/netfilter_arp/arp_tables.h.old +3 -5
@@ -38,6 +38,7 @@ struct arpt_arp {/* Device hw address length, src+target device addresses */ u_int8_t arhln, arhln_mask; +u_int8_t arpln, arpln_mask;struct arpt_devaddr_info src_devaddr;struct arpt_devaddr_info tgt_devaddr;
@@ -48,10 +49,6 @@ struct arpt_arp {u_int16_t arhrd, arhrd_mask;u_int16_t arpro, arpro_mask; -/* The protocol address length is only accepted if it is 4 -* so there is no use in offering a way to do filtering on it. -*/ -char iniface[IFNAMSIZ ], outiface[IFNAMSIZ ];unsigned char iniface_mask[IFNAMSIZ ], outiface_mask[IFNAMSIZ ];
@@ -111,7 +108,8 @@ struct arpt_counters#define ARPT_INV_ARPHRD 0x0080/* Invert the sense of ARP HRD. */ #define ARPT_INV_ARPPRO 0x0100/* Invert the sense of ARP PRO. */ #define ARPT_INV_ARPHLN 0x0200/* Invert the sense of ARP HLN. */ -#define ARPT_INV_MASK 0x03FF/* All possible flag bits mask. */ +#define ARPT_INV_ARPPLN 0x0400/* Invert the sense of ARP HLN. */ +#define ARPT_INV_MASK 0x07FF/* All possible flag bits mask. */ /* This structure defines each of the firewall rules. Consists of 3 parts which are 1) general ARP header stuff 2) match specific
net/ipv4/netfilter/Makefile renamed from net/ipv4/netfilter/Makefile.old +1 -0
@@ -79,6 +79,7 @@ obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt # generic ARP tables obj-$(CONFIG_IP_NF_ARPTABLES) += arp_tables.o +obj-$(CONFIG_IP_NF_ARP_MANGLE) += arpt_mangle.o # just filtering instance of ARP tables for now obj-$(CONFIG_IP_NF_ARPFILTER) += arptable_filter.o
net/ipv4/netfilter/Kconfig renamed from net/ipv4/netfilter/Kconfig.old +7 -0
@@ -540,6 +540,13 @@ config IP_NF_ARPFILTER tristate "ARP packet filtering" depends on IP_NF_ARPTABLES +config IP_NF_ARP_MANGLE + tristate "ARP payload mangling" + depends on IP_NF_ARPTABLES + help + Allows altering the ARP packet payload: source and destination + hardware and network addresses. + # Backwards compatibility modules: only if you don't build in the others. config IP_NF_COMPAT_IPCHAINS tristate "ipchains (2.2-style) support"
net/ipv4/netfilter/arpt_mangle.c new file +101 -0
101 lines not on this page · raw message
include/linux/netfilter_arp/arpt_mangle.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef _ARPT_MANGLE_H +#define _ARPT_MANGLE_H +#include <linux/netfilter_arp/arp_tables.h> + +#define ARPT_MANGLE_ADDR_LEN_MAX sizeof(struct in_addr) +struct arpt_mangle +{ +char src_devaddr[ARPT_DEV_ADDR_LEN_MAX ]; +char tgt_devaddr[ARPT_DEV_ADDR_LEN_MAX ]; +union { +struct in_addr src_ip; + } u_s; +union { +struct in_addr tgt_ip; + } u_t; +u_int8_t flags; +int target; +}; + +#define ARPT_MANGLE_SDEV 0x01 +#define ARPT_MANGLE_TDEV 0x02 +#define ARPT_MANGLE_SIP 0x04 +#define ARPT_MANGLE_TIP 0x08 +#define ARPT_MANGLE_MASK 0x0f + +#endif /* _ARPT_MANGLE_H */
From: Bart De Schuymer <[email protected]>
Date: Wed, 25 Jun 2003 20:56:31 +0200
I've added protocol length checking, since this is useful for bridged arp packets. It's useless for non-bridged packets though.
This is going to break any user tools people might be using. Please delete this part of the patch so we can discuss it seperately.
I have no problem with the mangle module addition.