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

TOMOYO Linux Cross Reference
Linux/net/bridge/netfilter/ebt_redirect.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_redirect
  4  *
  5  *      Authors:
  6  *      Bart De Schuymer <bdschuym@pandora.be>
  7  *
  8  *  April, 2002
  9  *
 10  */
 11 #include <linux/module.h>
 12 #include <net/sock.h>
 13 #include "../br_private.h"
 14 #include <linux/netfilter.h>
 15 #include <linux/netfilter/x_tables.h>
 16 #include <linux/netfilter_bridge/ebtables.h>
 17 #include <linux/netfilter_bridge/ebt_redirect.h>
 18 
 19 static unsigned int
 20 ebt_redirect_tg(struct sk_buff *skb, const struct xt_action_param *par)
 21 {
 22         const struct ebt_redirect_info *info = par->targinfo;
 23 
 24         if (skb_ensure_writable(skb, 0))
 25                 return EBT_DROP;
 26 
 27         if (xt_hooknum(par) != NF_BR_BROUTING)
 28                 /* rcu_read_lock()ed by nf_hook_thresh */
 29                 ether_addr_copy(eth_hdr(skb)->h_dest,
 30                                 br_port_get_rcu(xt_in(par))->br->dev->dev_addr);
 31         else
 32                 ether_addr_copy(eth_hdr(skb)->h_dest, xt_in(par)->dev_addr);
 33         skb->pkt_type = PACKET_HOST;
 34         return info->target;
 35 }
 36 
 37 static int ebt_redirect_tg_check(const struct xt_tgchk_param *par)
 38 {
 39         const struct ebt_redirect_info *info = par->targinfo;
 40         unsigned int hook_mask;
 41 
 42         if (BASE_CHAIN && info->target == EBT_RETURN)
 43                 return -EINVAL;
 44 
 45         hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS);
 46         if ((strcmp(par->table, "nat") != 0 ||
 47             hook_mask & ~(1 << NF_BR_PRE_ROUTING)) &&
 48             (strcmp(par->table, "broute") != 0 ||
 49             hook_mask & ~(1 << NF_BR_BROUTING)))
 50                 return -EINVAL;
 51         if (ebt_invalid_target(info->target))
 52                 return -EINVAL;
 53         return 0;
 54 }
 55 
 56 static struct xt_target ebt_redirect_tg_reg __read_mostly = {
 57         .name           = "redirect",
 58         .revision       = 0,
 59         .family         = NFPROTO_BRIDGE,
 60         .hooks          = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING) |
 61                           (1 << NF_BR_BROUTING),
 62         .target         = ebt_redirect_tg,
 63         .checkentry     = ebt_redirect_tg_check,
 64         .targetsize     = sizeof(struct ebt_redirect_info),
 65         .me             = THIS_MODULE,
 66 };
 67 
 68 static int __init ebt_redirect_init(void)
 69 {
 70         return xt_register_target(&ebt_redirect_tg_reg);
 71 }
 72 
 73 static void __exit ebt_redirect_fini(void)
 74 {
 75         xt_unregister_target(&ebt_redirect_tg_reg);
 76 }
 77 
 78 module_init(ebt_redirect_init);
 79 module_exit(ebt_redirect_fini);
 80 MODULE_DESCRIPTION("Ebtables: Packet redirection to localhost");
 81 MODULE_LICENSE("GPL");
 82 

~ [ 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