/* Copyright (C) 2020-2021 MaxLinear, Inc. Copyright (C) 2016-2020 Intel Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . SPDX-License-Identifier: GPL-2.0-only */ #include #include #include #include #include #include #include #include "../br_private.h" static unsigned int ebt_forward_tg(struct sk_buff *skb, const struct xt_action_param *par) { const struct ebt_forward_info *info = par->targinfo; struct net_bridge_port *p; const struct net_device *in = xt_in(par); if (skb_ensure_writable(skb, 0)) return EBT_DROP; list_for_each_entry_rcu(p, &br_port_get_rcu(in)->br->port_list, list) { if(strcmp(info->dst, p->dev->name) == 0) { skb->bridge_forward_port = p; goto out; } } out: return info->target; } static int ebt_forward_tg_check(const struct xt_tgchk_param *par) { const struct ebt_forward_info *info = par->targinfo; unsigned int hook_mask; if (BASE_CHAIN && info->target == EBT_RETURN) return -EINVAL; hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS); if ((strcmp(par->table, "nat") != 0 || (hook_mask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) && (strcmp(par->table, "broute") != 0 || hook_mask & ~(1 << NF_BR_BROUTING))) return -EINVAL; if (ebt_invalid_target(info->target)) return -EINVAL; return 0; } static struct xt_target ebt_forward_tg_reg __read_mostly = { .name = "forward", .revision = 0, .family = NFPROTO_BRIDGE, .hooks = (1 << NF_BR_NUMHOOKS) | (1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | (1 << NF_BR_BROUTING), .target = ebt_forward_tg, .checkentry = ebt_forward_tg_check, .targetsize = sizeof(struct ebt_forward_info), .me = THIS_MODULE, }; static int __init ebt_forward_init(void) { return xt_register_target(&ebt_forward_tg_reg); } static void __exit ebt_forward_fini(void) { xt_unregister_target(&ebt_forward_tg_reg); } module_init(ebt_forward_init); module_exit(ebt_forward_fini); MODULE_DESCRIPTION("Ebtables: forwarding override extension"); MODULE_LICENSE("GPL");