5 * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
6 * Bart De Schuymer <bdschuym@pandora.be>
11 #include <linux/if_arp.h>
13 #include <linux/module.h>
14 #include <linux/netfilter/x_tables.h>
15 #include <linux/netfilter_bridge/ebtables.h>
16 #include <linux/netfilter_bridge/ebt_arpreply.h>
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
)
23 struct ebt_arpreply_info
*info
= (void *)data
;
24 const __be32
*siptr
, *diptr
;
26 const struct arphdr
*ap
;
28 const unsigned char *shp
;
29 unsigned char _sha
[ETH_ALEN
];
31 ap
= skb_header_pointer(skb
, 0, sizeof(_ah
), &_ah
);
35 if (ap
->ar_op
!= htons(ARPOP_REQUEST
) ||
36 ap
->ar_hln
!= ETH_ALEN
||
37 ap
->ar_pro
!= htons(ETH_P_IP
) ||
41 shp
= skb_header_pointer(skb
, sizeof(_ah
), ETH_ALEN
, &_sha
);
45 siptr
= skb_header_pointer(skb
, sizeof(_ah
) + ETH_ALEN
,
50 diptr
= skb_header_pointer(skb
,
51 sizeof(_ah
) + 2 * ETH_ALEN
+ sizeof(_sip
),
56 arp_send(ARPOP_REPLY
, ETH_P_ARP
, *siptr
, (struct net_device
*)in
,
57 *diptr
, shp
, info
->mac
, shp
);
63 ebt_arpreply_tg_check(const char *tablename
, const void *entry
,
64 const struct xt_target
*target
, void *data
,
65 unsigned int hookmask
)
67 const struct ebt_arpreply_info
*info
= data
;
68 const struct ebt_entry
*e
= entry
;
70 if (BASE_CHAIN
&& info
->target
== EBT_RETURN
)
72 if (e
->ethproto
!= htons(ETH_P_ARP
) ||
73 e
->invflags
& EBT_IPROTO
)
76 if (strcmp(tablename
, "nat") || hookmask
& ~(1 << NF_BR_PRE_ROUTING
))
81 static struct xt_target ebt_arpreply_tg_reg __read_mostly
= {
84 .family
= NFPROTO_BRIDGE
,
85 .target
= ebt_arpreply_tg
,
86 .checkentry
= ebt_arpreply_tg_check
,
87 .targetsize
= XT_ALIGN(sizeof(struct ebt_arpreply_info
)),
91 static int __init
ebt_arpreply_init(void)
93 return xt_register_target(&ebt_arpreply_tg_reg
);
96 static void __exit
ebt_arpreply_fini(void)
98 xt_unregister_target(&ebt_arpreply_tg_reg
);
101 module_init(ebt_arpreply_init
);
102 module_exit(ebt_arpreply_fini
);
103 MODULE_DESCRIPTION("Ebtables: ARP reply target");
104 MODULE_LICENSE("GPL");