Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  Handle firewalling core
0004  *  Linux ethernet bridge
0005  *
0006  *  Authors:
0007  *  Lennert Buytenhek       <buytenh@gnu.org>
0008  *  Bart De Schuymer        <bdschuym@pandora.be>
0009  *
0010  *  Lennert dedicates this file to Kerstin Wurdinger.
0011  */
0012 
0013 #include <linux/module.h>
0014 #include <linux/kernel.h>
0015 #include <linux/in_route.h>
0016 #include <linux/inetdevice.h>
0017 #include <net/route.h>
0018 
0019 #include "br_private.h"
0020 #ifdef CONFIG_SYSCTL
0021 #include <linux/sysctl.h>
0022 #endif
0023 
0024 static void fake_update_pmtu(struct dst_entry *dst, struct sock *sk,
0025                  struct sk_buff *skb, u32 mtu,
0026                  bool confirm_neigh)
0027 {
0028 }
0029 
0030 static void fake_redirect(struct dst_entry *dst, struct sock *sk,
0031               struct sk_buff *skb)
0032 {
0033 }
0034 
0035 static u32 *fake_cow_metrics(struct dst_entry *dst, unsigned long old)
0036 {
0037     return NULL;
0038 }
0039 
0040 static struct neighbour *fake_neigh_lookup(const struct dst_entry *dst,
0041                        struct sk_buff *skb,
0042                        const void *daddr)
0043 {
0044     return NULL;
0045 }
0046 
0047 static unsigned int fake_mtu(const struct dst_entry *dst)
0048 {
0049     return dst->dev->mtu;
0050 }
0051 
0052 static struct dst_ops fake_dst_ops = {
0053     .family     = AF_INET,
0054     .update_pmtu    = fake_update_pmtu,
0055     .redirect   = fake_redirect,
0056     .cow_metrics    = fake_cow_metrics,
0057     .neigh_lookup   = fake_neigh_lookup,
0058     .mtu        = fake_mtu,
0059 };
0060 
0061 /*
0062  * Initialize bogus route table used to keep netfilter happy.
0063  * Currently, we fill in the PMTU entry because netfilter
0064  * refragmentation needs it, and the rt_flags entry because
0065  * ipt_REJECT needs it.  Future netfilter modules might
0066  * require us to fill additional fields.
0067  */
0068 static const u32 br_dst_default_metrics[RTAX_MAX] = {
0069     [RTAX_MTU - 1] = 1500,
0070 };
0071 
0072 void br_netfilter_rtable_init(struct net_bridge *br)
0073 {
0074     struct rtable *rt = &br->fake_rtable;
0075 
0076     atomic_set(&rt->dst.__refcnt, 1);
0077     rt->dst.dev = br->dev;
0078     dst_init_metrics(&rt->dst, br_dst_default_metrics, true);
0079     rt->dst.flags   = DST_NOXFRM | DST_FAKE_RTABLE;
0080     rt->dst.ops = &fake_dst_ops;
0081 }
0082 
0083 int __init br_nf_core_init(void)
0084 {
0085     return dst_entries_init(&fake_dst_ops);
0086 }
0087 
0088 void br_nf_core_fini(void)
0089 {
0090     dst_entries_destroy(&fake_dst_ops);
0091 }