Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ebt_dnat.c
Go to the documentation of this file.
1 /*
2  * ebt_dnat
3  *
4  * Authors:
5  * Bart De Schuymer <[email protected]>
6  *
7  * June, 2002
8  *
9  */
10 #include <linux/module.h>
11 #include <net/sock.h>
12 #include <linux/netfilter.h>
13 #include <linux/netfilter/x_tables.h>
14 #include <linux/netfilter_bridge/ebtables.h>
16 
17 static unsigned int
18 ebt_dnat_tg(struct sk_buff *skb, const struct xt_action_param *par)
19 {
20  const struct ebt_nat_info *info = par->targinfo;
21 
22  if (!skb_make_writable(skb, 0))
23  return EBT_DROP;
24 
25  memcpy(eth_hdr(skb)->h_dest, info->mac, ETH_ALEN);
26  return info->target;
27 }
28 
29 static int ebt_dnat_tg_check(const struct xt_tgchk_param *par)
30 {
31  const struct ebt_nat_info *info = par->targinfo;
32  unsigned int hook_mask;
33 
34  if (BASE_CHAIN && info->target == EBT_RETURN)
35  return -EINVAL;
36 
37  hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS);
38  if ((strcmp(par->table, "nat") != 0 ||
39  (hook_mask & ~((1 << NF_BR_PRE_ROUTING) |
40  (1 << NF_BR_LOCAL_OUT)))) &&
41  (strcmp(par->table, "broute") != 0 ||
42  hook_mask & ~(1 << NF_BR_BROUTING)))
43  return -EINVAL;
44  if (INVALID_TARGET)
45  return -EINVAL;
46  return 0;
47 }
48 
49 static struct xt_target ebt_dnat_tg_reg __read_mostly = {
50  .name = "dnat",
51  .revision = 0,
52  .family = NFPROTO_BRIDGE,
53  .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING) |
54  (1 << NF_BR_LOCAL_OUT) | (1 << NF_BR_BROUTING),
55  .target = ebt_dnat_tg,
56  .checkentry = ebt_dnat_tg_check,
57  .targetsize = sizeof(struct ebt_nat_info),
58  .me = THIS_MODULE,
59 };
60 
61 static int __init ebt_dnat_init(void)
62 {
63  return xt_register_target(&ebt_dnat_tg_reg);
64 }
65 
66 static void __exit ebt_dnat_fini(void)
67 {
68  xt_unregister_target(&ebt_dnat_tg_reg);
69 }
70 
71 module_init(ebt_dnat_init);
72 module_exit(ebt_dnat_fini);
73 MODULE_DESCRIPTION("Ebtables: Destination MAC address translation");
74 MODULE_LICENSE("GPL");