~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/bridge/netfilter/ebt_snat.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  *  ebt_snat
  4  *
  5  *      Authors:
  6  *      Bart De Schuymer <bdschuym@pandora.be>
  7  *
  8  *  June, 2002
  9  *
 10  */
 11 #include <linux/module.h>
 12 #include <net/sock.h>
 13 #include <linux/if_arp.h>
 14 #include <net/arp.h>
 15 #include <linux/netfilter.h>
 16 #include <linux/netfilter/x_tables.h>
 17 #include <linux/netfilter_bridge/ebtables.h>
 18 #include <linux/netfilter_bridge/ebt_nat.h>
 19 
 20 static unsigned int
 21 ebt_snat_tg(struct sk_buff *skb, const struct xt_action_param *par)
 22 {
 23         const struct ebt_nat_info *info = par->targinfo;
 24 
 25         if (skb_ensure_writable(skb, 0))
 26                 return EBT_DROP;
 27 
 28         ether_addr_copy(eth_hdr(skb)->h_source, info->mac);
 29         if (!(info->target & NAT_ARP_BIT) &&
 30             eth_hdr(skb)->h_proto == htons(ETH_P_ARP)) {
 31                 const struct arphdr *ap;
 32                 struct arphdr _ah;
 33 
 34                 ap = skb_header_pointer(skb, 0, sizeof(_ah), &_ah);
 35                 if (ap == NULL)
 36                         return EBT_DROP;
 37                 if (ap->ar_hln != ETH_ALEN)
 38                         goto out;
 39                 if (skb_store_bits(skb, sizeof(_ah), info->mac, ETH_ALEN))
 40                         return EBT_DROP;
 41         }
 42 out:
 43         return info->target | ~EBT_VERDICT_BITS;
 44 }
 45 
 46 static int ebt_snat_tg_check(const struct xt_tgchk_param *par)
 47 {
 48         const struct ebt_nat_info *info = par->targinfo;
 49         int tmp;
 50 
 51         tmp = info->target | ~EBT_VERDICT_BITS;
 52         if (BASE_CHAIN && tmp == EBT_RETURN)
 53                 return -EINVAL;
 54 
 55         if (ebt_invalid_target(tmp))
 56                 return -EINVAL;
 57         tmp = info->target | EBT_VERDICT_BITS;
 58         if ((tmp & ~NAT_ARP_BIT) != ~NAT_ARP_BIT)
 59                 return -EINVAL;
 60         return 0;
 61 }
 62 
 63 static struct xt_target ebt_snat_tg_reg __read_mostly = {
 64         .name           = "snat",
 65         .revision       = 0,
 66         .family         = NFPROTO_BRIDGE,
 67         .table          = "nat",
 68         .hooks          = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_POST_ROUTING),
 69         .target         = ebt_snat_tg,
 70         .checkentry     = ebt_snat_tg_check,
 71         .targetsize     = sizeof(struct ebt_nat_info),
 72         .me             = THIS_MODULE,
 73 };
 74 
 75 static int __init ebt_snat_init(void)
 76 {
 77         return xt_register_target(&ebt_snat_tg_reg);
 78 }
 79 
 80 static void __exit ebt_snat_fini(void)
 81 {
 82         xt_unregister_target(&ebt_snat_tg_reg);
 83 }
 84 
 85 module_init(ebt_snat_init);
 86 module_exit(ebt_snat_fini);
 87 MODULE_DESCRIPTION("Ebtables: Source MAC address translation");
 88 MODULE_LICENSE("GPL");
 89 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php