br_nf_core.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Handle firewalling core
  4. * Linux ethernet bridge
  5. *
  6. * Authors:
  7. * Lennert Buytenhek <buytenh@gnu.org>
  8. * Bart De Schuymer <bdschuym@pandora.be>
  9. *
  10. * Lennert dedicates this file to Kerstin Wurdinger.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/in_route.h>
  15. #include <linux/inetdevice.h>
  16. #include <net/route.h>
  17. #include "br_private.h"
  18. #ifdef CONFIG_SYSCTL
  19. #include <linux/sysctl.h>
  20. #endif
  21. static void fake_update_pmtu(struct dst_entry *dst, struct sock *sk,
  22. struct sk_buff *skb, u32 mtu,
  23. bool confirm_neigh)
  24. {
  25. }
  26. static void fake_redirect(struct dst_entry *dst, struct sock *sk,
  27. struct sk_buff *skb)
  28. {
  29. }
  30. static u32 *fake_cow_metrics(struct dst_entry *dst, unsigned long old)
  31. {
  32. return NULL;
  33. }
  34. static struct neighbour *fake_neigh_lookup(const struct dst_entry *dst,
  35. struct sk_buff *skb,
  36. const void *daddr)
  37. {
  38. return NULL;
  39. }
  40. static unsigned int fake_mtu(const struct dst_entry *dst)
  41. {
  42. return dst->dev->mtu;
  43. }
  44. static struct dst_ops fake_dst_ops = {
  45. .family = AF_INET,
  46. .update_pmtu = fake_update_pmtu,
  47. .redirect = fake_redirect,
  48. .cow_metrics = fake_cow_metrics,
  49. .neigh_lookup = fake_neigh_lookup,
  50. .mtu = fake_mtu,
  51. };
  52. /*
  53. * Initialize bogus route table used to keep netfilter happy.
  54. * Currently, we fill in the PMTU entry because netfilter
  55. * refragmentation needs it, and the rt_flags entry because
  56. * ipt_REJECT needs it. Future netfilter modules might
  57. * require us to fill additional fields.
  58. */
  59. static const u32 br_dst_default_metrics[RTAX_MAX] = {
  60. [RTAX_MTU - 1] = 1500,
  61. };
  62. void br_netfilter_rtable_init(struct net_bridge *br)
  63. {
  64. struct rtable *rt = &br->fake_rtable;
  65. rcuref_init(&rt->dst.__rcuref, 1);
  66. rt->dst.dev = br->dev;
  67. dst_init_metrics(&rt->dst, br_dst_default_metrics, true);
  68. rt->dst.flags = DST_NOXFRM | DST_FAKE_RTABLE;
  69. rt->dst.ops = &fake_dst_ops;
  70. }
  71. int __init br_nf_core_init(void)
  72. {
  73. return dst_entries_init(&fake_dst_ops);
  74. }
  75. void br_nf_core_fini(void)
  76. {
  77. dst_entries_destroy(&fake_dst_ops);
  78. }