linux/net/ipv4/fib_frontend.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * INET		An implementation of the TCP/IP protocol suite for the LINUX
 *		operating system.  INET is implemented using the  BSD Socket
 *		interface as the means of communication with the user level.
 *
 *		IPv4 Forwarding Information Base: FIB frontend.
 *
 * Authors:	Alexey Kuznetsov, <[email protected]>
 */

#include <linux/module.h>
#include <linux/uaccess.h>
#include <linux/bitops.h>
#include <linux/capability.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/errno.h>
#include <linux/in.h>
#include <linux/inet.h>
#include <linux/inetdevice.h>
#include <linux/netdevice.h>
#include <linux/if_addr.h>
#include <linux/if_arp.h>
#include <linux/skbuff.h>
#include <linux/cache.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/slab.h>

#include <net/inet_dscp.h>
#include <net/ip.h>
#include <net/protocol.h>
#include <net/route.h>
#include <net/tcp.h>
#include <net/sock.h>
#include <net/arp.h>
#include <net/ip_fib.h>
#include <net/nexthop.h>
#include <net/rtnetlink.h>
#include <net/xfrm.h>
#include <net/l3mdev.h>
#include <net/lwtunnel.h>
#include <trace/events/fib.h>

#ifndef CONFIG_IP_MULTIPLE_TABLES

static int __net_init fib4_rules_init(struct net *net)
{
	struct fib_table *local_table, *main_table;

	main_table  = fib_trie_table(RT_TABLE_MAIN, NULL);
	if (!main_table)
		return -ENOMEM;

	local_table = fib_trie_table(RT_TABLE_LOCAL, main_table);
	if (!local_table)
		goto fail;

	hlist_add_head_rcu(&local_table->tb_hlist,
				&net->ipv4.fib_table_hash[TABLE_LOCAL_INDEX]);
	hlist_add_head_rcu(&main_table->tb_hlist,
				&net->ipv4.fib_table_hash[TABLE_MAIN_INDEX]);
	return 0;

fail:
	fib_free_table(main_table);
	return -ENOMEM;
}
#else

struct fib_table *fib_new_table(struct net *net, u32 id)
{}
EXPORT_SYMBOL_GPL();

/* caller must hold either rtnl or rcu read lock */
struct fib_table *fib_get_table(struct net *net, u32 id)
{}
#endif /* CONFIG_IP_MULTIPLE_TABLES */

static void fib_replace_table(struct net *net, struct fib_table *old,
			      struct fib_table *new)
{}

int fib_unmerge(struct net *net)
{}

void fib_flush(struct net *net)
{}

/*
 * Find address type as if only "dev" was present in the system. If
 * on_dev is NULL then all interfaces are taken into consideration.
 */
static inline unsigned int __inet_dev_addr_type(struct net *net,
						const struct net_device *dev,
						__be32 addr, u32 tb_id)
{}

unsigned int inet_addr_type_table(struct net *net, __be32 addr, u32 tb_id)
{}
EXPORT_SYMBOL();

unsigned int inet_addr_type(struct net *net, __be32 addr)
{}
EXPORT_SYMBOL();

unsigned int inet_dev_addr_type(struct net *net, const struct net_device *dev,
				__be32 addr)
{}
EXPORT_SYMBOL();

/* inet_addr_type with dev == NULL but using the table from a dev
 * if one is associated
 */
unsigned int inet_addr_type_dev_table(struct net *net,
				      const struct net_device *dev,
				      __be32 addr)
{}
EXPORT_SYMBOL();

__be32 fib_compute_spec_dst(struct sk_buff *skb)
{}

bool fib_info_nh_uses_dev(struct fib_info *fi, const struct net_device *dev)
{}
EXPORT_SYMBOL_GPL();

/* Given (packet source, input interface) and optional (dst, oif, tos):
 * - (main) check, that source is valid i.e. not broadcast or our local
 *   address.
 * - figure out what "logical" interface this packet arrived
 *   and calculate "specific destination" address.
 * - check, that packet arrived from expected physical interface.
 * called with rcu_read_lock()
 */
static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
				 u8 tos, int oif, struct net_device *dev,
				 int rpf, struct in_device *idev, u32 *itag)
{}

/* Ignore rp_filter for packets protected by IPsec. */
int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
			u8 tos, int oif, struct net_device *dev,
			struct in_device *idev, u32 *itag)
{}

static inline __be32 sk_extract_addr(struct sockaddr *addr)
{}

static int put_rtax(struct nlattr *mx, int len, int type, u32 value)
{}

static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt,
				 struct fib_config *cfg)
{}

/*
 * Handle IP routing ioctl calls.
 * These are used to manipulate the routing tables
 */
int ip_rt_ioctl(struct net *net, unsigned int cmd, struct rtentry *rt)
{}

const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] =;

int fib_gw_from_via(struct fib_config *cfg, struct nlattr *nla,
		    struct netlink_ext_ack *extack)
{}

static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
			     struct nlmsghdr *nlh, struct fib_config *cfg,
			     struct netlink_ext_ack *extack)
{}

static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh,
			     struct netlink_ext_ack *extack)
{}

static int inet_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
			     struct netlink_ext_ack *extack)
{}

int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
			  struct fib_dump_filter *filter,
			  struct netlink_callback *cb)
{}
EXPORT_SYMBOL_GPL();

static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
{}

/* Prepare and feed intra-kernel routing request.
 * Really, it should be netlink message, but :-( netlink
 * can be not configured, so that we feed it directly
 * to fib engine. It is legal, because all events occur
 * only when netlink is already locked.
 */
static void fib_magic(int cmd, int type, __be32 dst, int dst_len,
		      struct in_ifaddr *ifa, u32 rt_priority)
{}

void fib_add_ifaddr(struct in_ifaddr *ifa)
{}

void fib_modify_prefix_metric(struct in_ifaddr *ifa, u32 new_metric)
{}

/* Delete primary or secondary address.
 * Optionally, on secondary address promotion consider the addresses
 * from subnet iprim as deleted, even if they are in device list.
 * In this case the secondary ifa can be in device list.
 */
void fib_del_ifaddr(struct in_ifaddr *ifa, struct in_ifaddr *iprim)
{}

static void nl_fib_lookup(struct net *net, struct fib_result_nl *frn)
{}

static void nl_fib_input(struct sk_buff *skb)
{}

static int __net_init nl_fib_lookup_init(struct net *net)
{}

static void nl_fib_lookup_exit(struct net *net)
{}

static void fib_disable_ip(struct net_device *dev, unsigned long event,
			   bool force)
{}

static int fib_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr)
{}

static int fib_netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
{}

static struct notifier_block fib_inetaddr_notifier =;

static struct notifier_block fib_netdev_notifier =;

static int __net_init ip_fib_net_init(struct net *net)
{}

static void ip_fib_net_exit(struct net *net)
{}

static int __net_init fib_net_init(struct net *net)
{}

static void __net_exit fib_net_exit(struct net *net)
{}

static void __net_exit fib_net_exit_batch(struct list_head *net_list)
{}

static struct pernet_operations fib_net_ops =;

void __init ip_fib_init(void)
{}