Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ebt_arpreply |
| 3 | * |
| 4 | * Authors: |
| 5 | * Grzegorz Borowiak <grzes@gnu.univ.gda.pl> |
| 6 | * Bart De Schuymer <bdschuym@pandora.be> |
| 7 | * |
| 8 | * August, 2003 |
| 9 | * |
| 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/if_arp.h> |
| 12 | #include <net/arp.h> |
| 13 | #include <linux/module.h> |
Jan Engelhardt | 18219d3 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 14 | #include <linux/netfilter/x_tables.h> |
| 15 | #include <linux/netfilter_bridge/ebtables.h> |
| 16 | #include <linux/netfilter_bridge/ebt_arpreply.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Jan Engelhardt | 2d06d4a | 2008-10-08 11:35:15 +0200 | [diff] [blame] | 18 | static unsigned int |
| 19 | ebt_arpreply_tg(struct sk_buff *skb, const struct net_device *in, |
| 20 | const struct net_device *out, unsigned int hook_nr, |
| 21 | const struct xt_target *target, const void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | { |
Jan Engelhardt | abfdf1c | 2008-01-31 03:59:24 -0800 | [diff] [blame] | 23 | struct ebt_arpreply_info *info = (void *)data; |
| 24 | const __be32 *siptr, *diptr; |
| 25 | __be32 _sip, _dip; |
| 26 | const struct arphdr *ap; |
| 27 | struct arphdr _ah; |
| 28 | const unsigned char *shp; |
| 29 | unsigned char _sha[ETH_ALEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah); |
| 32 | if (ap == NULL) |
| 33 | return EBT_DROP; |
| 34 | |
| 35 | if (ap->ar_op != htons(ARPOP_REQUEST) || |
| 36 | ap->ar_hln != ETH_ALEN || |
| 37 | ap->ar_pro != htons(ETH_P_IP) || |
| 38 | ap->ar_pln != 4) |
| 39 | return EBT_CONTINUE; |
| 40 | |
| 41 | shp = skb_header_pointer(skb, sizeof(_ah), ETH_ALEN, &_sha); |
| 42 | if (shp == NULL) |
| 43 | return EBT_DROP; |
| 44 | |
| 45 | siptr = skb_header_pointer(skb, sizeof(_ah) + ETH_ALEN, |
| 46 | sizeof(_sip), &_sip); |
| 47 | if (siptr == NULL) |
| 48 | return EBT_DROP; |
| 49 | |
| 50 | diptr = skb_header_pointer(skb, |
| 51 | sizeof(_ah) + 2 * ETH_ALEN + sizeof(_sip), |
| 52 | sizeof(_dip), &_dip); |
| 53 | if (diptr == NULL) |
| 54 | return EBT_DROP; |
| 55 | |
| 56 | arp_send(ARPOP_REPLY, ETH_P_ARP, *siptr, (struct net_device *)in, |
YOSHIFUJI Hideaki | 9d6f229 | 2007-02-09 23:24:35 +0900 | [diff] [blame] | 57 | *diptr, shp, info->mac, shp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | return info->target; |
| 60 | } |
| 61 | |
Jan Engelhardt | 2d06d4a | 2008-10-08 11:35:15 +0200 | [diff] [blame] | 62 | static bool |
| 63 | ebt_arpreply_tg_check(const char *tablename, const void *entry, |
| 64 | const struct xt_target *target, void *data, |
| 65 | unsigned int hookmask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Jan Engelhardt | abfdf1c | 2008-01-31 03:59:24 -0800 | [diff] [blame] | 67 | const struct ebt_arpreply_info *info = data; |
Jan Engelhardt | 2d06d4a | 2008-10-08 11:35:15 +0200 | [diff] [blame] | 68 | const struct ebt_entry *e = entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | if (BASE_CHAIN && info->target == EBT_RETURN) |
Jan Engelhardt | 19eda87 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 71 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | if (e->ethproto != htons(ETH_P_ARP) || |
| 73 | e->invflags & EBT_IPROTO) |
Jan Engelhardt | 19eda87 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 74 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | CLEAR_BASE_CHAIN_BIT; |
| 76 | if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) |
Jan Engelhardt | 19eda87 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 77 | return false; |
| 78 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Jan Engelhardt | 043ef46 | 2008-10-08 11:35:15 +0200 | [diff] [blame^] | 81 | static struct xt_target ebt_arpreply_tg_reg __read_mostly = { |
| 82 | .name = "arpreply", |
Jan Engelhardt | 001a18d | 2008-10-08 11:35:14 +0200 | [diff] [blame] | 83 | .revision = 0, |
| 84 | .family = NFPROTO_BRIDGE, |
Jan Engelhardt | 2d06d4a | 2008-10-08 11:35:15 +0200 | [diff] [blame] | 85 | .target = ebt_arpreply_tg, |
| 86 | .checkentry = ebt_arpreply_tg_check, |
Jan Engelhardt | 18219d3 | 2008-10-08 11:35:13 +0200 | [diff] [blame] | 87 | .targetsize = XT_ALIGN(sizeof(struct ebt_arpreply_info)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | .me = THIS_MODULE, |
| 89 | }; |
| 90 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 91 | static int __init ebt_arpreply_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Jan Engelhardt | 043ef46 | 2008-10-08 11:35:15 +0200 | [diff] [blame^] | 93 | return xt_register_target(&ebt_arpreply_tg_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 96 | static void __exit ebt_arpreply_fini(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
Jan Engelhardt | 043ef46 | 2008-10-08 11:35:15 +0200 | [diff] [blame^] | 98 | xt_unregister_target(&ebt_arpreply_tg_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Andrew Morton | 65b4b4e | 2006-03-28 16:37:06 -0800 | [diff] [blame] | 101 | module_init(ebt_arpreply_init); |
| 102 | module_exit(ebt_arpreply_fini); |
Jan Engelhardt | f776c4c | 2008-01-31 04:00:30 -0800 | [diff] [blame] | 103 | MODULE_DESCRIPTION("Ebtables: ARP reply target"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | MODULE_LICENSE("GPL"); |