Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * DECnet       An implementation of the DECnet protocol suite for the LINUX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *              operating system.  DECnet is implemented using the  BSD Socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *              interface as the means of communication with the user level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *              DECnet Routing Functions (Endnode and Router)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * Authors:     Steve Whitehouse <SteveW@ACM.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *              Eduardo Marcelo Serrat <emserrat@geocities.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *              Steve Whitehouse : Fixes to allow "intra-ethernet" and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *                                 "return-to-sender" bits on outgoing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *                                 packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *		Steve Whitehouse : Timeouts for cached routes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *              Steve Whitehouse : Use dst cache for input routes too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *              Steve Whitehouse : Fixed error values in dn_send_skb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *              Steve Whitehouse : Rework routing functions to better fit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *                                 DECnet routing design
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *              Alexey Kuznetsov : New SMP locking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *              Steve Whitehouse : More SMP locking changes & dn_cache_dump()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *              Steve Whitehouse : Prerouting NF hook, now really is prerouting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *				   Fixed possible skb leak in rtnetlink funcs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *              Steve Whitehouse : Dave Miller's dynamic hash table sizing and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *                                 Alexey Kuznetsov's finer grained locking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *                                 from ipv4/route.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *              Steve Whitehouse : Routing is now starting to look like a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  *                                 sensible set of code now, mainly due to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  *                                 my copying the IPv4 routing code. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *                                 hooks here are modified and will continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  *                                 to evolve for a while.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  *              Steve Whitehouse : Real SMP at last :-) Also new netfilter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  *                                 stuff. Look out raw sockets your days
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  *                                 are numbered!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  *              Steve Whitehouse : Added return-to-sender functions. Added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  *                                 backlog congestion level return codes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  *		Steve Whitehouse : Fixed bug where routes were set up with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  *                                 no ref count on net devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  *              Steve Whitehouse : RCU for the route cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  *              Steve Whitehouse : Preparations for the flow cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  *              Steve Whitehouse : Prepare for nonlinear skbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)     (c) 1995-1998 E.M. Serrat		emserrat@geocities.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) *******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include <linux/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include <linux/in_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #include <linux/netfilter_decnet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #include <linux/times.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #include <asm/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #include <net/neighbour.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #include <net/dst.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #include <net/flow.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #include <net/fib_rules.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #include <net/dn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #include <net/dn_dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #include <net/dn_nsp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #include <net/dn_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #include <net/dn_neigh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #include <net/dn_fib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) struct dn_rt_hash_bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	struct dn_route __rcu *chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) extern struct neigh_table dn_neigh_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) static unsigned char dn_hiord_addr[6] = {0xAA,0x00,0x04,0x00,0x00,0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static const int dn_rt_min_delay = 2 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) static const int dn_rt_max_delay = 10 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) static const int dn_rt_mtu_expires = 10 * 60 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) static unsigned long dn_rt_deadline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) static int dn_dst_gc(struct dst_ops *ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) static struct dst_entry *dn_dst_check(struct dst_entry *, __u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) static unsigned int dn_dst_default_advmss(const struct dst_entry *dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) static unsigned int dn_dst_mtu(const struct dst_entry *dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) static void dn_dst_destroy(struct dst_entry *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) static void dn_dst_ifdown(struct dst_entry *, struct net_device *dev, int how);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) static struct dst_entry *dn_dst_negative_advice(struct dst_entry *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) static void dn_dst_link_failure(struct sk_buff *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) static void dn_dst_update_pmtu(struct dst_entry *dst, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 			       struct sk_buff *skb , u32 mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 			       bool confirm_neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) static void dn_dst_redirect(struct dst_entry *dst, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 			    struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) static struct neighbour *dn_dst_neigh_lookup(const struct dst_entry *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 					     struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 					     const void *daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) static int dn_route_input(struct sk_buff *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) static void dn_run_flush(struct timer_list *unused);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) static struct dn_rt_hash_bucket *dn_rt_hash_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) static unsigned int dn_rt_hash_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) static struct timer_list dn_route_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) static DEFINE_TIMER(dn_rt_flush_timer, dn_run_flush);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) int decnet_dst_gc_interval = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) static struct dst_ops dn_dst_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	.family =		PF_DECnet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	.gc_thresh =		128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	.gc =			dn_dst_gc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	.check =		dn_dst_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	.default_advmss =	dn_dst_default_advmss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	.mtu =			dn_dst_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	.cow_metrics =		dst_cow_metrics_generic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	.destroy =		dn_dst_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	.ifdown =		dn_dst_ifdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	.negative_advice =	dn_dst_negative_advice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	.link_failure =		dn_dst_link_failure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	.update_pmtu =		dn_dst_update_pmtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	.redirect =		dn_dst_redirect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	.neigh_lookup =		dn_dst_neigh_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) static void dn_dst_destroy(struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	struct dn_route *rt = (struct dn_route *) dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	if (rt->n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 		neigh_release(rt->n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	dst_destroy_metrics_generic(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) static void dn_dst_ifdown(struct dst_entry *dst, struct net_device *dev, int how)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	if (how) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 		struct dn_route *rt = (struct dn_route *) dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 		struct neighbour *n = rt->n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 		if (n && n->dev == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 			n->dev = dev_net(dev)->loopback_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 			dev_hold(n->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 			dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) static __inline__ unsigned int dn_hash(__le16 src, __le16 dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	__u16 tmp = (__u16 __force)(src ^ dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	tmp ^= (tmp >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	tmp ^= (tmp >> 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	tmp ^= (tmp >> 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	return dn_rt_hash_mask & (unsigned int)tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) static void dn_dst_check_expire(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	struct dn_route *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	struct dn_route __rcu **rtp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	unsigned long expire = 120 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	for (i = 0; i <= dn_rt_hash_mask; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 		rtp = &dn_rt_hash_table[i].chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 		spin_lock(&dn_rt_hash_table[i].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 		while ((rt = rcu_dereference_protected(*rtp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 						lockdep_is_held(&dn_rt_hash_table[i].lock))) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 			if (atomic_read(&rt->dst.__refcnt) > 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 			    (now - rt->dst.lastuse) < expire) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 				rtp = &rt->dn_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 			*rtp = rt->dn_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 			rt->dn_next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 			dst_dev_put(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 			dst_release(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 		spin_unlock(&dn_rt_hash_table[i].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		if ((jiffies - now) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	mod_timer(&dn_route_timer, now + decnet_dst_gc_interval * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) static int dn_dst_gc(struct dst_ops *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	struct dn_route *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	struct dn_route __rcu **rtp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	unsigned long expire = 10 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	for (i = 0; i <= dn_rt_hash_mask; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		spin_lock_bh(&dn_rt_hash_table[i].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		rtp = &dn_rt_hash_table[i].chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		while ((rt = rcu_dereference_protected(*rtp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 						lockdep_is_held(&dn_rt_hash_table[i].lock))) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 			if (atomic_read(&rt->dst.__refcnt) > 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 			    (now - rt->dst.lastuse) < expire) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 				rtp = &rt->dn_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 			*rtp = rt->dn_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 			rt->dn_next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 			dst_dev_put(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 			dst_release(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		spin_unlock_bh(&dn_rt_hash_table[i].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245)  * The decnet standards don't impose a particular minimum mtu, what they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246)  * do insist on is that the routing layer accepts a datagram of at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247)  * 230 bytes long. Here we have to subtract the routing header length from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248)  * 230 to get the minimum acceptable mtu. If there is no neighbour, then we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249)  * assume the worst and use a long header size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251)  * We update both the mtu and the advertised mss (i.e. the segment size we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252)  * advertise to the other end).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) static void dn_dst_update_pmtu(struct dst_entry *dst, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 			       struct sk_buff *skb, u32 mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 			       bool confirm_neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	struct dn_route *rt = (struct dn_route *) dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	struct neighbour *n = rt->n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	u32 min_mtu = 230;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	struct dn_dev *dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	dn = n ? rcu_dereference_raw(n->dev->dn_ptr) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	if (dn && dn->use_long == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 		min_mtu -= 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 		min_mtu -= 21;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	if (dst_metric(dst, RTAX_MTU) > mtu && mtu >= min_mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		if (!(dst_metric_locked(dst, RTAX_MTU))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 			dst_metric_set(dst, RTAX_MTU, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 			dst_set_expires(dst, dn_rt_mtu_expires);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		if (!(dst_metric_locked(dst, RTAX_ADVMSS))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 			u32 mss = mtu - DN_MAX_NSP_DATA_HEADER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			u32 existing_mss = dst_metric_raw(dst, RTAX_ADVMSS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 			if (!existing_mss || existing_mss > mss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 				dst_metric_set(dst, RTAX_ADVMSS, mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) static void dn_dst_redirect(struct dst_entry *dst, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 			    struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290)  * When a route has been marked obsolete. (e.g. routing cache flush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) static struct dst_entry *dn_dst_check(struct dst_entry *dst, __u32 cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) static struct dst_entry *dn_dst_negative_advice(struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) static void dn_dst_link_failure(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) static inline int compare_keys(struct flowidn *fl1, struct flowidn *fl2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	return ((fl1->daddr ^ fl2->daddr) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		(fl1->saddr ^ fl2->saddr) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		(fl1->flowidn_mark ^ fl2->flowidn_mark) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		(fl1->flowidn_scope ^ fl2->flowidn_scope) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		(fl1->flowidn_oif ^ fl2->flowidn_oif) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		(fl1->flowidn_iif ^ fl2->flowidn_iif)) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) static int dn_insert_route(struct dn_route *rt, unsigned int hash, struct dn_route **rp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	struct dn_route *rth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	struct dn_route __rcu **rthp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	rthp = &dn_rt_hash_table[hash].chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	spin_lock_bh(&dn_rt_hash_table[hash].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	while ((rth = rcu_dereference_protected(*rthp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 						lockdep_is_held(&dn_rt_hash_table[hash].lock))) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		if (compare_keys(&rth->fld, &rt->fld)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 			/* Put it first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 			*rthp = rth->dn_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 			rcu_assign_pointer(rth->dn_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 					   dn_rt_hash_table[hash].chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 			rcu_assign_pointer(dn_rt_hash_table[hash].chain, rth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 			dst_hold_and_use(&rth->dst, now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 			spin_unlock_bh(&dn_rt_hash_table[hash].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 			dst_release_immediate(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 			*rp = rth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		rthp = &rth->dn_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	rcu_assign_pointer(rt->dn_next, dn_rt_hash_table[hash].chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	rcu_assign_pointer(dn_rt_hash_table[hash].chain, rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	dst_hold_and_use(&rt->dst, now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	spin_unlock_bh(&dn_rt_hash_table[hash].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	*rp = rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) static void dn_run_flush(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	struct dn_route *rt, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	for (i = 0; i < dn_rt_hash_mask; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		spin_lock_bh(&dn_rt_hash_table[i].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		if ((rt = xchg((struct dn_route **)&dn_rt_hash_table[i].chain, NULL)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 			goto nothing_to_declare;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		for(; rt; rt = next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 			next = rcu_dereference_raw(rt->dn_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 			RCU_INIT_POINTER(rt->dn_next, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			dst_dev_put(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			dst_release(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) nothing_to_declare:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		spin_unlock_bh(&dn_rt_hash_table[i].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) static DEFINE_SPINLOCK(dn_rt_flush_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) void dn_rt_cache_flush(int delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	int user_mode = !in_interrupt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	if (delay < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		delay = dn_rt_min_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	spin_lock_bh(&dn_rt_flush_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	if (del_timer(&dn_rt_flush_timer) && delay > 0 && dn_rt_deadline) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		long tmo = (long)(dn_rt_deadline - now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		if (user_mode && tmo < dn_rt_max_delay - dn_rt_min_delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 			tmo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		if (delay > tmo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 			delay = tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	if (delay <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		spin_unlock_bh(&dn_rt_flush_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		dn_run_flush(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	if (dn_rt_deadline == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		dn_rt_deadline = now + dn_rt_max_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	dn_rt_flush_timer.expires = now + delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	add_timer(&dn_rt_flush_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	spin_unlock_bh(&dn_rt_flush_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414)  * dn_return_short - Return a short packet to its sender
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415)  * @skb: The packet to return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) static int dn_return_short(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	struct dn_skb_cb *cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	unsigned char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	__le16 *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	__le16 *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	/* Add back headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	skb_push(skb, skb->data - skb_network_header(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	/* Skip packet length and point to flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	ptr = skb->data + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	*ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	dst = (__le16 *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	ptr += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	src = (__le16 *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	ptr += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	*ptr = 0; /* Zero hop count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	swap(*src, *dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	skb->pkt_type = PACKET_OUTGOING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	dn_rt_finish_output(skb, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450)  * dn_return_long - Return a long packet to its sender
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451)  * @skb: The long format packet to return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) static int dn_return_long(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	struct dn_skb_cb *cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	unsigned char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	unsigned char *src_addr, *dst_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	unsigned char tmp[ETH_ALEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	/* Add back all headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	skb_push(skb, skb->data - skb_network_header(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	if ((skb = skb_unshare(skb, GFP_ATOMIC)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	/* Ignore packet length and point to flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	ptr = skb->data + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	/* Skip padding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	if (*ptr & DN_RT_F_PF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		char padlen = (*ptr & ~DN_RT_F_PF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		ptr += padlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	*ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	ptr += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	dst_addr = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	ptr += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	src_addr = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	ptr += 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	*ptr = 0; /* Zero hop count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	/* Swap source and destination */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	memcpy(tmp, src_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	memcpy(src_addr, dst_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	memcpy(dst_addr, tmp, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	skb->pkt_type = PACKET_OUTGOING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	dn_rt_finish_output(skb, dst_addr, src_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496)  * dn_route_rx_packet - Try and find a route for an incoming packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497)  * @net: The applicable net namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498)  * @sk: Socket packet transmitted on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499)  * @skb: The packet to find a route for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501)  * Returns: result of input function if route is found, error code otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) static int dn_route_rx_packet(struct net *net, struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	struct dn_skb_cb *cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	if ((err = dn_route_input(skb)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		return dst_input(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	if (decnet_debug_level & 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		char *devname = skb->dev ? skb->dev->name : "???";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		printk(KERN_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 			"DECnet: dn_route_rx_packet: rt_flags=0x%02x dev=%s len=%d src=0x%04hx dst=0x%04hx err=%d type=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 			(int)cb->rt_flags, devname, skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 			le16_to_cpu(cb->src), le16_to_cpu(cb->dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 			err, skb->pkt_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	if ((skb->pkt_type == PACKET_HOST) && (cb->rt_flags & DN_RT_F_RQR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		switch (cb->rt_flags & DN_RT_PKT_MSK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		case DN_RT_PKT_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 			return dn_return_short(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		case DN_RT_PKT_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			return dn_return_long(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) static int dn_route_rx_long(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	unsigned char *ptr = skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	if (!pskb_may_pull(skb, 21)) /* 20 for long header, 1 for shortest nsp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		goto drop_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	skb_pull(skb, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	/* Destination info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	ptr += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	cb->dst = dn_eth2dn(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	if (memcmp(ptr, dn_hiord_addr, 4) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		goto drop_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	ptr += 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	/* Source info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	ptr += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	cb->src = dn_eth2dn(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	if (memcmp(ptr, dn_hiord_addr, 4) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		goto drop_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	ptr += 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	/* Other junk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	ptr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	cb->hops = *ptr++; /* Visit Count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	return NF_HOOK(NFPROTO_DECNET, NF_DN_PRE_ROUTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		       &init_net, NULL, skb, skb->dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		       dn_route_rx_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) drop_it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) static int dn_route_rx_short(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	unsigned char *ptr = skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	if (!pskb_may_pull(skb, 6)) /* 5 for short header + 1 for shortest nsp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		goto drop_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	skb_pull(skb, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	skb_reset_transport_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	cb->dst = *(__le16 *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	ptr += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	cb->src = *(__le16 *)ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	ptr += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	cb->hops = *ptr & 0x3f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	return NF_HOOK(NFPROTO_DECNET, NF_DN_PRE_ROUTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		       &init_net, NULL, skb, skb->dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		       dn_route_rx_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) drop_it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) static int dn_route_discard(struct net *net, struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	 * I know we drop the packet here, but thats considered success in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	 * this case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) static int dn_route_ptp_hello(struct net *net, struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	dn_dev_hello(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	dn_neigh_pointopoint_hello(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	return NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) int dn_route_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	struct dn_skb_cb *cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	unsigned char flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	__u16 len = le16_to_cpu(*(__le16 *)skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	struct dn_dev *dn = rcu_dereference(dev->dn_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	unsigned char padlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	if (!net_eq(dev_net(dev), &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 		goto dump_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	if (dn == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		goto dump_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	if (!pskb_may_pull(skb, 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		goto dump_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	skb_pull(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	if (len > skb->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		goto dump_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	skb_trim(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	flags = *skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	cb->stamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	cb->iif = dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	 * If we have padding, remove it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	if (flags & DN_RT_F_PF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		padlen = flags & ~DN_RT_F_PF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		if (!pskb_may_pull(skb, padlen + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 			goto dump_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		skb_pull(skb, padlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		flags = *skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	skb_reset_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	 * Weed out future version DECnet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	if (flags & DN_RT_F_VER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		goto dump_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	cb->rt_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	if (decnet_debug_level & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		printk(KERN_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 			"dn_route_rcv: got 0x%02x from %s [%d %d %d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 			(int)flags, dev->name, len, skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 			padlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	if (flags & DN_RT_PKT_CNTL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		if (unlikely(skb_linearize(skb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 			goto dump_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		switch (flags & DN_RT_CNTL_MSK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		case DN_RT_PKT_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 			dn_dev_init_pkt(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		case DN_RT_PKT_VERI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 			dn_dev_veri_pkt(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		if (dn->parms.state != DN_DEV_S_RU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			goto dump_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		switch (flags & DN_RT_CNTL_MSK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		case DN_RT_PKT_HELO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 			return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 				       &init_net, NULL, skb, skb->dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 				       dn_route_ptp_hello);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		case DN_RT_PKT_L1RT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		case DN_RT_PKT_L2RT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 			return NF_HOOK(NFPROTO_DECNET, NF_DN_ROUTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 				       &init_net, NULL, skb, skb->dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 				       dn_route_discard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		case DN_RT_PKT_ERTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 			return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 				       &init_net, NULL, skb, skb->dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 				       dn_neigh_router_hello);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		case DN_RT_PKT_EEDH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 			return NF_HOOK(NFPROTO_DECNET, NF_DN_HELLO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 				       &init_net, NULL, skb, skb->dev, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 				       dn_neigh_endnode_hello);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		if (dn->parms.state != DN_DEV_S_RU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			goto dump_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		skb_pull(skb, 1); /* Pull flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		switch (flags & DN_RT_PKT_MSK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		case DN_RT_PKT_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 			return dn_route_rx_long(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		case DN_RT_PKT_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 			return dn_route_rx_short(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) dump_it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) static int dn_output(struct net *net, struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	struct dn_route *rt = (struct dn_route *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	struct net_device *dev = dst->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	if (rt->n == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	cb->src = rt->rt_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	cb->dst = rt->rt_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	 * Always set the Intra-Ethernet bit on all outgoing packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	 * originated on this node. Only valid flag from upper layers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	 * is return-to-sender-requested. Set hop count to 0 too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	cb->rt_flags &= ~DN_RT_F_RQR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	cb->rt_flags |= DN_RT_F_IE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	cb->hops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	return NF_HOOK(NFPROTO_DECNET, NF_DN_LOCAL_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		       &init_net, sk, skb, NULL, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		       dn_to_neigh_output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	net_dbg_ratelimited("dn_output: This should not happen\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) static int dn_forward(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	struct dn_dev *dn_db = rcu_dereference(dst->dev->dn_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	struct dn_route *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	int header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	struct net_device *dev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	if (skb->pkt_type != PACKET_HOST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	/* Ensure that we have enough space for headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	rt = (struct dn_route *)skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	header_len = dn_db->use_long ? 21 : 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	if (skb_cow(skb, LL_RESERVED_SPACE(rt->dst.dev)+header_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	 * Hop count exceeded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	if (++cb->hops > 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	skb->dev = rt->dst.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	 * If packet goes out same interface it came in on, then set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	 * the Intra-Ethernet bit. This has no effect for short
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	 * packets, so we don't need to test for them here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	cb->rt_flags &= ~DN_RT_F_IE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	if (rt->rt_flags & RTCF_DOREDIRECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		cb->rt_flags |= DN_RT_F_IE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	return NF_HOOK(NFPROTO_DECNET, NF_DN_FORWARD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		       &init_net, NULL, skb, dev, skb->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		       dn_to_neigh_output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818)  * Used to catch bugs. This should never normally get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819)  * called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) static int dn_rt_bug_out(struct net *net, struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	net_dbg_ratelimited("dn_rt_bug: skb from:%04x to:%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 			    le16_to_cpu(cb->src), le16_to_cpu(cb->dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) static int dn_rt_bug(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	net_dbg_ratelimited("dn_rt_bug: skb from:%04x to:%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 			    le16_to_cpu(cb->src), le16_to_cpu(cb->dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) static unsigned int dn_dst_default_advmss(const struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	return dn_mss_from_pmtu(dst->dev, dst_mtu(dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) static unsigned int dn_dst_mtu(const struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	unsigned int mtu = dst_metric_raw(dst, RTAX_MTU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	return mtu ? : dst->dev->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) static struct neighbour *dn_dst_neigh_lookup(const struct dst_entry *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 					     struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 					     const void *daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	return __neigh_lookup_errno(&dn_neigh_table, daddr, dst->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) static int dn_rt_set_next_hop(struct dn_route *rt, struct dn_fib_res *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	struct dn_fib_info *fi = res->fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	struct net_device *dev = rt->dst.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	unsigned int mss_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	struct neighbour *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	if (fi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		if (DN_FIB_RES_GW(*res) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		    DN_FIB_RES_NH(*res).nh_scope == RT_SCOPE_LINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 			rt->rt_gateway = DN_FIB_RES_GW(*res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		dst_init_metrics(&rt->dst, fi->fib_metrics, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	rt->rt_type = res->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	if (dev != NULL && rt->n == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		n = __neigh_lookup_errno(&dn_neigh_table, &rt->rt_gateway, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		if (IS_ERR(n))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 			return PTR_ERR(n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		rt->n = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	if (dst_metric(&rt->dst, RTAX_MTU) > rt->dst.dev->mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		dst_metric_set(&rt->dst, RTAX_MTU, rt->dst.dev->mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	mss_metric = dst_metric_raw(&rt->dst, RTAX_ADVMSS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	if (mss_metric) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		unsigned int mss = dn_mss_from_pmtu(dev, dst_mtu(&rt->dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		if (mss_metric > mss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 			dst_metric_set(&rt->dst, RTAX_ADVMSS, mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) static inline int dn_match_addr(__le16 addr1, __le16 addr2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	__u16 tmp = le16_to_cpu(addr1) ^ le16_to_cpu(addr2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	int match = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	while(tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		tmp >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		match--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	return match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) static __le16 dnet_select_source(const struct net_device *dev, __le16 daddr, int scope)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	__le16 saddr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	struct dn_dev *dn_db;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	struct dn_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	int best_match = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	dn_db = rcu_dereference(dev->dn_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	for (ifa = rcu_dereference(dn_db->ifa_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	     ifa != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	     ifa = rcu_dereference(ifa->ifa_next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		if (ifa->ifa_scope > scope)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		if (!daddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			saddr = ifa->ifa_local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		ret = dn_match_addr(daddr, ifa->ifa_local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		if (ret > best_match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 			saddr = ifa->ifa_local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		if (best_match == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 			saddr = ifa->ifa_local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	return saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) static inline __le16 __dn_fib_res_prefsrc(struct dn_fib_res *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	return dnet_select_source(DN_FIB_RES_DEV(*res), DN_FIB_RES_GW(*res), res->scope);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) static inline __le16 dn_fib_rules_map_destination(__le16 daddr, struct dn_fib_res *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	__le16 mask = dnet_make_mask(res->prefixlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	return (daddr&~mask)|res->fi->fib_nh->nh_gw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) static int dn_route_output_slow(struct dst_entry **pprt, const struct flowidn *oldflp, int try_hard)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	struct flowidn fld = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		.daddr = oldflp->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		.saddr = oldflp->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		.flowidn_scope = RT_SCOPE_UNIVERSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		.flowidn_mark = oldflp->flowidn_mark,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		.flowidn_iif = LOOPBACK_IFINDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		.flowidn_oif = oldflp->flowidn_oif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	struct dn_route *rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	struct net_device *dev_out = NULL, *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	struct neighbour *neigh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	unsigned int hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	unsigned int flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	struct dn_fib_res res = { .fi = NULL, .type = RTN_UNICAST };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	int free_res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	__le16 gateway = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	if (decnet_debug_level & 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 		printk(KERN_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		       "dn_route_output_slow: dst=%04x src=%04x mark=%d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		       " iif=%d oif=%d\n", le16_to_cpu(oldflp->daddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 		       le16_to_cpu(oldflp->saddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		       oldflp->flowidn_mark, LOOPBACK_IFINDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 		       oldflp->flowidn_oif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	/* If we have an output interface, verify its a DECnet device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	if (oldflp->flowidn_oif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		dev_out = dev_get_by_index(&init_net, oldflp->flowidn_oif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		if (dev_out && dev_out->dn_ptr == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 			dev_put(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 			dev_out = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		if (dev_out == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	/* If we have a source address, verify that its a local address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	if (oldflp->saddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		err = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		if (dev_out) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 			if (dn_dev_islocal(dev_out, oldflp->saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 				goto source_ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 			dev_put(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		for_each_netdev_rcu(&init_net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 			if (!dev->dn_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 			if (!dn_dev_islocal(dev, oldflp->saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 			if ((dev->flags & IFF_LOOPBACK) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 			    oldflp->daddr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 			    !dn_dev_islocal(dev, oldflp->daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 			dev_out = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		if (dev_out == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		dev_hold(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) source_ok:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	/* No destination? Assume its local */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	if (!fld.daddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		fld.daddr = fld.saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		if (dev_out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 			dev_put(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		dev_out = init_net.loopback_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		if (!dev_out->dn_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		err = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		dev_hold(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		if (!fld.daddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 			fld.daddr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 			fld.saddr = dnet_select_source(dev_out, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 						       RT_SCOPE_HOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 			if (!fld.daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		fld.flowidn_oif = LOOPBACK_IFINDEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		res.type = RTN_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		goto make_route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	if (decnet_debug_level & 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		printk(KERN_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		       "dn_route_output_slow: initial checks complete."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		       " dst=%04x src=%04x oif=%d try_hard=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		       le16_to_cpu(fld.daddr), le16_to_cpu(fld.saddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 		       fld.flowidn_oif, try_hard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	 * N.B. If the kernel is compiled without router support then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	 * dn_fib_lookup() will evaluate to non-zero so this if () block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	 * will always be executed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	err = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	if (try_hard || (err = dn_fib_lookup(&fld, &res)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		struct dn_dev *dn_db;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		if (err != -ESRCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		 * Here the fallback is basically the standard algorithm for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		 * routing in endnodes which is described in the DECnet routing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		 * docs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		 * If we are not trying hard, look in neighbour cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		 * The result is tested to ensure that if a specific output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		 * device/source address was requested, then we honour that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		 * here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		if (!try_hard) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 			neigh = neigh_lookup_nodev(&dn_neigh_table, &init_net, &fld.daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 			if (neigh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 				if ((oldflp->flowidn_oif &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 				    (neigh->dev->ifindex != oldflp->flowidn_oif)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 				    (oldflp->saddr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 				    (!dn_dev_islocal(neigh->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 						     oldflp->saddr)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 					neigh_release(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 					neigh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 					if (dev_out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 						dev_put(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 					if (dn_dev_islocal(neigh->dev, fld.daddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 						dev_out = init_net.loopback_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 						res.type = RTN_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 					} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 						dev_out = neigh->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 					dev_hold(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 					goto select_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 		/* Not there? Perhaps its a local address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		if (dev_out == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 			dev_out = dn_dev_get_default();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 		if (dev_out == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		dn_db = rcu_dereference_raw(dev_out->dn_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		if (!dn_db)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			goto e_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		/* Possible improvement - check all devices for local addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		if (dn_dev_islocal(dev_out, fld.daddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 			dev_put(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 			dev_out = init_net.loopback_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 			dev_hold(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 			res.type = RTN_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 			goto select_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		/* Not local either.... try sending it to the default router */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 		neigh = neigh_clone(dn_db->router);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 		BUG_ON(neigh && neigh->dev != dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		/* Ok then, we assume its directly connected and move on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) select_source:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		if (neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 			gateway = ((struct dn_neigh *)neigh)->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 		if (gateway == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 			gateway = fld.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		if (fld.saddr == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 			fld.saddr = dnet_select_source(dev_out, gateway,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 						       res.type == RTN_LOCAL ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 						       RT_SCOPE_HOST :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 						       RT_SCOPE_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 			if (fld.saddr == 0 && res.type != RTN_LOCAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 				goto e_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		fld.flowidn_oif = dev_out->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 		goto make_route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	free_res = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	if (res.type == RTN_NAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		goto e_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	if (res.type == RTN_LOCAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 		if (!fld.saddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 			fld.saddr = fld.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		if (dev_out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 			dev_put(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		dev_out = init_net.loopback_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		dev_hold(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		if (!dev_out->dn_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 			goto e_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 		fld.flowidn_oif = dev_out->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		if (res.fi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 			dn_fib_info_put(res.fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		res.fi = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 		goto make_route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	if (res.fi->fib_nhs > 1 && fld.flowidn_oif == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 		dn_fib_select_multipath(&fld, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	 * We could add some logic to deal with default routes here and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	 * get rid of some of the special casing above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	if (!fld.saddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		fld.saddr = DN_FIB_RES_PREFSRC(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	if (dev_out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		dev_put(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	dev_out = DN_FIB_RES_DEV(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	dev_hold(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	fld.flowidn_oif = dev_out->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	gateway = DN_FIB_RES_GW(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) make_route:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	if (dev_out->flags & IFF_LOOPBACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		flags |= RTCF_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	rt = dst_alloc(&dn_dst_ops, dev_out, 0, DST_OBSOLETE_NONE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	if (rt == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 		goto e_nobufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	rt->dn_next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	memset(&rt->fld, 0, sizeof(rt->fld));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	rt->fld.saddr        = oldflp->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	rt->fld.daddr        = oldflp->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	rt->fld.flowidn_oif  = oldflp->flowidn_oif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	rt->fld.flowidn_iif  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	rt->fld.flowidn_mark = oldflp->flowidn_mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	rt->rt_saddr      = fld.saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	rt->rt_daddr      = fld.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	rt->rt_gateway    = gateway ? gateway : fld.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	rt->rt_local_src  = fld.saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	rt->rt_dst_map    = fld.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	rt->rt_src_map    = fld.saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	rt->n = neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	neigh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	rt->dst.lastuse = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	rt->dst.output  = dn_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	rt->dst.input   = dn_rt_bug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	rt->rt_flags      = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	if (flags & RTCF_LOCAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 		rt->dst.input = dn_nsp_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	err = dn_rt_set_next_hop(rt, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		goto e_neighbour;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	hash = dn_hash(rt->fld.saddr, rt->fld.daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	/* dn_insert_route() increments dst->__refcnt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	dn_insert_route(rt, hash, (struct dn_route **)pprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	if (neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		neigh_release(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	if (free_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		dn_fib_res_put(&res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	if (dev_out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 		dev_put(dev_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) e_addr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	err = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) e_inval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) e_nobufs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) e_neighbour:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	dst_release_immediate(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	goto e_nobufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)  * N.B. The flags may be moved into the flowi at some future stage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) static int __dn_route_output_key(struct dst_entry **pprt, const struct flowidn *flp, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	unsigned int hash = dn_hash(flp->saddr, flp->daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	struct dn_route *rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	if (!(flags & MSG_TRYHARD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		rcu_read_lock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		for (rt = rcu_dereference_bh(dn_rt_hash_table[hash].chain); rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 			rt = rcu_dereference_bh(rt->dn_next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 			if ((flp->daddr == rt->fld.daddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 			    (flp->saddr == rt->fld.saddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 			    (flp->flowidn_mark == rt->fld.flowidn_mark) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 			    dn_is_output_route(rt) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 			    (rt->fld.flowidn_oif == flp->flowidn_oif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 				dst_hold_and_use(&rt->dst, jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 				rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 				*pprt = &rt->dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	return dn_route_output_slow(pprt, flp, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) static int dn_route_output_key(struct dst_entry **pprt, struct flowidn *flp, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	err = __dn_route_output_key(pprt, flp, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	if (err == 0 && flp->flowidn_proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		*pprt = xfrm_lookup(&init_net, *pprt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 				    flowidn_to_flowi(flp), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 		if (IS_ERR(*pprt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 			err = PTR_ERR(*pprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 			*pprt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) int dn_route_output_sock(struct dst_entry __rcu **pprt, struct flowidn *fl, struct sock *sk, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	err = __dn_route_output_key(pprt, fl, flags & MSG_TRYHARD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	if (err == 0 && fl->flowidn_proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 		*pprt = xfrm_lookup(&init_net, *pprt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 				    flowidn_to_flowi(fl), sk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		if (IS_ERR(*pprt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 			err = PTR_ERR(*pprt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 			*pprt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) static int dn_route_input_slow(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	struct dn_route *rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	struct net_device *in_dev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	struct net_device *out_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	struct dn_dev *dn_db;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	struct neighbour *neigh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	unsigned int hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	int flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	__le16 gateway = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	__le16 local_src = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	struct flowidn fld = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		.daddr = cb->dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 		.saddr = cb->src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		.flowidn_scope = RT_SCOPE_UNIVERSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		.flowidn_mark = skb->mark,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 		.flowidn_iif = skb->dev->ifindex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	struct dn_fib_res res = { .fi = NULL, .type = RTN_UNREACHABLE };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	int free_res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	dev_hold(in_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	if ((dn_db = rcu_dereference(in_dev->dn_ptr)) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	/* Zero source addresses are not allowed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	if (fld.saddr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	 * In this case we've just received a packet from a source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	 * outside ourselves pretending to come from us. We don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	 * allow it any further to prevent routing loops, spoofing and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	 * other nasties. Loopback packets already have the dst attached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	 * so this only affects packets which have originated elsewhere.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	err  = -ENOTUNIQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	if (dn_dev_islocal(in_dev, cb->src))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	err = dn_fib_lookup(&fld, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		if (err != -ESRCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		 * Is the destination us ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		if (!dn_dev_islocal(in_dev, cb->dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 			goto e_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		res.type = RTN_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 		__le16 src_map = fld.saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		free_res = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		out_dev = DN_FIB_RES_DEV(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 		if (out_dev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			net_crit_ratelimited("Bug in dn_route_input_slow() No output device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			goto e_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		dev_hold(out_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 		if (res.r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 			src_map = fld.saddr; /* no NAT support for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		gateway = DN_FIB_RES_GW(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 		if (res.type == RTN_NAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 			fld.daddr = dn_fib_rules_map_destination(fld.daddr, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 			dn_fib_res_put(&res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 			free_res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 			if (dn_fib_lookup(&fld, &res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 				goto e_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 			free_res = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 			if (res.type != RTN_UNICAST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 				goto e_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 			flags |= RTCF_DNAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 			gateway = fld.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		fld.saddr = src_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	switch(res.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	case RTN_UNICAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		 * Forwarding check here, we only check for forwarding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		 * being turned off, if you want to only forward intra
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		 * area, its up to you to set the routing tables up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 		 * correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		if (dn_db->parms.forwarding == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 			goto e_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 		if (res.fi->fib_nhs > 1 && fld.flowidn_oif == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 			dn_fib_select_multipath(&fld, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		 * Check for out_dev == in_dev. We use the RTCF_DOREDIRECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		 * flag as a hint to set the intra-ethernet bit when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		 * forwarding. If we've got NAT in operation, we don't do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		 * this optimisation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		if (out_dev == in_dev && !(flags & RTCF_NAT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 			flags |= RTCF_DOREDIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		local_src = DN_FIB_RES_PREFSRC(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	case RTN_BLACKHOLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	case RTN_UNREACHABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	case RTN_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		flags |= RTCF_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 		fld.saddr = cb->dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 		fld.daddr = cb->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 		/* Routing tables gave us a gateway */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 		if (gateway)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 			goto make_route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 		/* Packet was intra-ethernet, so we know its on-link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 		if (cb->rt_flags & DN_RT_F_IE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 			gateway = cb->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 			goto make_route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 		/* Use the default router if there is one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 		neigh = neigh_clone(dn_db->router);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 		if (neigh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 			gateway = ((struct dn_neigh *)neigh)->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 			goto make_route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 		/* Close eyes and pray */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 		gateway = cb->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 		goto make_route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 		goto e_inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) make_route:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	rt = dst_alloc(&dn_dst_ops, out_dev, 1, DST_OBSOLETE_NONE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	if (rt == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		goto e_nobufs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	rt->dn_next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	memset(&rt->fld, 0, sizeof(rt->fld));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	rt->rt_saddr      = fld.saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	rt->rt_daddr      = fld.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	rt->rt_gateway    = fld.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	if (gateway)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 		rt->rt_gateway = gateway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	rt->rt_local_src  = local_src ? local_src : rt->rt_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	rt->rt_dst_map    = fld.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	rt->rt_src_map    = fld.saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	rt->fld.saddr        = cb->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	rt->fld.daddr        = cb->dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	rt->fld.flowidn_oif  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	rt->fld.flowidn_iif  = in_dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	rt->fld.flowidn_mark = fld.flowidn_mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	rt->n = neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	rt->dst.lastuse = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	rt->dst.output = dn_rt_bug_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	switch (res.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	case RTN_UNICAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 		rt->dst.input = dn_forward;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	case RTN_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 		rt->dst.output = dn_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 		rt->dst.input = dn_nsp_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 		rt->dst.dev = in_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 		flags |= RTCF_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	case RTN_UNREACHABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	case RTN_BLACKHOLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 		rt->dst.input = dst_discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	rt->rt_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	err = dn_rt_set_next_hop(rt, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 		goto e_neighbour;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	hash = dn_hash(rt->fld.saddr, rt->fld.daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	/* dn_insert_route() increments dst->__refcnt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	dn_insert_route(rt, hash, &rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	skb_dst_set(skb, &rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	if (neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 		neigh_release(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	if (free_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 		dn_fib_res_put(&res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	dev_put(in_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	if (out_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 		dev_put(out_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) e_inval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) e_nobufs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) e_neighbour:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	dst_release_immediate(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) static int dn_route_input(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	struct dn_route *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	struct dn_skb_cb *cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	unsigned int hash = dn_hash(cb->src, cb->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	if (skb_dst(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	for(rt = rcu_dereference(dn_rt_hash_table[hash].chain); rt != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	    rt = rcu_dereference(rt->dn_next)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 		if ((rt->fld.saddr == cb->src) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 		    (rt->fld.daddr == cb->dst) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 		    (rt->fld.flowidn_oif == 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 		    (rt->fld.flowidn_mark == skb->mark) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 		    (rt->fld.flowidn_iif == cb->iif)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 			dst_hold_and_use(&rt->dst, jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 			skb_dst_set(skb, (struct dst_entry *)rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	return dn_route_input_slow(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) static int dn_rt_fill_info(struct sk_buff *skb, u32 portid, u32 seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 			   int event, int nowait, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	struct dn_route *rt = (struct dn_route *)skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	struct rtmsg *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	long expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	nlh = nlmsg_put(skb, portid, seq, event, sizeof(*r), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	if (!nlh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	r = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	r->rtm_family = AF_DECnet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	r->rtm_dst_len = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	r->rtm_src_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	r->rtm_tos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	r->rtm_table = RT_TABLE_MAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	r->rtm_type = rt->rt_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	r->rtm_flags = (rt->rt_flags & ~0xFFFF) | RTM_F_CLONED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	r->rtm_scope = RT_SCOPE_UNIVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	r->rtm_protocol = RTPROT_UNSPEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	if (rt->rt_flags & RTCF_NOTIFY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		r->rtm_flags |= RTM_F_NOTIFY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	if (nla_put_u32(skb, RTA_TABLE, RT_TABLE_MAIN) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	    nla_put_le16(skb, RTA_DST, rt->rt_daddr) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	if (rt->fld.saddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 		r->rtm_src_len = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 		if (nla_put_le16(skb, RTA_SRC, rt->fld.saddr) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 			goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	if (rt->dst.dev &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	    nla_put_u32(skb, RTA_OIF, rt->dst.dev->ifindex) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	 * Note to self - change this if input routes reverse direction when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	 * they deal only with inputs and not with replies like they do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	 * currently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	if (nla_put_le16(skb, RTA_PREFSRC, rt->rt_local_src) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	if (rt->rt_daddr != rt->rt_gateway &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	    nla_put_le16(skb, RTA_GATEWAY, rt->rt_gateway) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 	if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 	expires = rt->dst.expires ? rt->dst.expires - jiffies : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	if (rtnl_put_cacheinfo(skb, &rt->dst, 0, expires,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 			       rt->dst.error) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 	if (dn_is_input_route(rt) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	    nla_put_u32(skb, RTA_IIF, rt->fld.flowidn_iif) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 	nlmsg_cancel(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) const struct nla_policy rtm_dn_policy[RTA_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	[RTA_DST]		= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 	[RTA_SRC]		= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	[RTA_IIF]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	[RTA_OIF]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 	[RTA_GATEWAY]		= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 	[RTA_PRIORITY]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	[RTA_PREFSRC]		= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	[RTA_METRICS]		= { .type = NLA_NESTED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	[RTA_MULTIPATH]		= { .type = NLA_NESTED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	[RTA_TABLE]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	[RTA_MARK]		= { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633)  * This is called by both endnodes and routers now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 			     struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	struct net *net = sock_net(in_skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	struct rtmsg *rtm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	struct dn_route *rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	struct dn_skb_cb *cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	struct flowidn fld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	struct nlattr *tb[RTA_MAX+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	if (!net_eq(net, &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	err = nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 				     rtm_dn_policy, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	memset(&fld, 0, sizeof(fld));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	fld.flowidn_proto = DNPROTO_NSP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 		return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	cb = DN_SKB_CB(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	if (tb[RTA_SRC])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 		fld.saddr = nla_get_le16(tb[RTA_SRC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	if (tb[RTA_DST])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 		fld.daddr = nla_get_le16(tb[RTA_DST]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	if (tb[RTA_IIF])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 		fld.flowidn_iif = nla_get_u32(tb[RTA_IIF]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	if (fld.flowidn_iif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 		struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 		dev = __dev_get_by_index(&init_net, fld.flowidn_iif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 		if (!dev || !dev->dn_ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 			kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 		skb->protocol = htons(ETH_P_DNA_RT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 		skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 		cb->src = fld.saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 		cb->dst = fld.daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 		local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		err = dn_route_input(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 		local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		memset(cb, 0, sizeof(struct dn_skb_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 		rt = (struct dn_route *)skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		if (!err && -rt->dst.error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 			err = rt->dst.error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 		if (tb[RTA_OIF])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 			fld.flowidn_oif = nla_get_u32(tb[RTA_OIF]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 		err = dn_route_output_key((struct dst_entry **)&rt, &fld, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	skb->dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	skb_dst_set(skb, &rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	if (rtm->rtm_flags & RTM_F_NOTIFY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 		rt->rt_flags |= RTCF_NOTIFY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	err = dn_rt_fill_info(skb, NETLINK_CB(in_skb).portid, nlh->nlmsg_seq, RTM_NEWROUTE, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 		err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	return rtnl_unicast(skb, &init_net, NETLINK_CB(in_skb).portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)  * For routers, this is called from dn_fib_dump, but for endnodes its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720)  * called directly from the rtnetlink dispatch table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	struct dn_route *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	int h, s_h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	int idx, s_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	struct rtmsg *rtm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	if (!net_eq(net, &init_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	if (nlmsg_len(cb->nlh) < sizeof(struct rtmsg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 	rtm = nlmsg_data(cb->nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	if (!(rtm->rtm_flags & RTM_F_CLONED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 	s_h = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	s_idx = idx = cb->args[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	for(h = 0; h <= dn_rt_hash_mask; h++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 		if (h < s_h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 		if (h > s_h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 			s_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 		rcu_read_lock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 		for(rt = rcu_dereference_bh(dn_rt_hash_table[h].chain), idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 			rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 			rt = rcu_dereference_bh(rt->dn_next), idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 			if (idx < s_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 			skb_dst_set(skb, dst_clone(&rt->dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 			if (dn_rt_fill_info(skb, NETLINK_CB(cb->skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 					cb->nlh->nlmsg_seq, RTM_NEWROUTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 					1, NLM_F_MULTI) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 				skb_dst_drop(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 				rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 				goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 			skb_dst_drop(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 		rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	cb->args[0] = h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	cb->args[1] = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) struct dn_rt_cache_iter_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	int bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) static struct dn_route *dn_rt_cache_get_first(struct seq_file *seq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	struct dn_route *rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	struct dn_rt_cache_iter_state *s = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	for(s->bucket = dn_rt_hash_mask; s->bucket >= 0; --s->bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 		rcu_read_lock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 		rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 		if (rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 		rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	return rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	struct dn_rt_cache_iter_state *s = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	rt = rcu_dereference_bh(rt->dn_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	while (!rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 		rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 		if (--s->bucket < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 		rcu_read_lock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 		rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	return rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) static void *dn_rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	struct dn_route *rt = dn_rt_cache_get_first(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	if (rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 		while(*pos && (rt = dn_rt_cache_get_next(seq, rt)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 			--*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	return *pos ? NULL : rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) static void *dn_rt_cache_seq_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	struct dn_route *rt = dn_rt_cache_get_next(seq, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	return rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) static void dn_rt_cache_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	if (v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 		rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) static int dn_rt_cache_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	struct dn_route *rt = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	char buf1[DN_ASCBUF_LEN], buf2[DN_ASCBUF_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	seq_printf(seq, "%-8s %-7s %-7s %04d %04d %04d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 		   rt->dst.dev ? rt->dst.dev->name : "*",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 		   dn_addr2asc(le16_to_cpu(rt->rt_daddr), buf1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 		   dn_addr2asc(le16_to_cpu(rt->rt_saddr), buf2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 		   atomic_read(&rt->dst.__refcnt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 		   rt->dst.__use, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) static const struct seq_operations dn_rt_cache_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 	.start	= dn_rt_cache_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	.next	= dn_rt_cache_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	.stop	= dn_rt_cache_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	.show	= dn_rt_cache_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) #endif /* CONFIG_PROC_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) void __init dn_route_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 	int i, goal, order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	dn_dst_ops.kmem_cachep =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 		kmem_cache_create("dn_dst_cache", sizeof(struct dn_route), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 				  SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	dst_entries_init(&dn_dst_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 	timer_setup(&dn_route_timer, dn_dst_check_expire, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	add_timer(&dn_route_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	goal = totalram_pages() >> (26 - PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	for(order = 0; (1UL << order) < goal; order++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 		/* NOTHING */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	 * Only want 1024 entries max, since the table is very, very unlikely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	 * to be larger than that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	while(order && ((((1UL << order) * PAGE_SIZE) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 				sizeof(struct dn_rt_hash_bucket)) >= 2048))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 		order--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 		dn_rt_hash_mask = (1UL << order) * PAGE_SIZE /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 			sizeof(struct dn_rt_hash_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 		while(dn_rt_hash_mask & (dn_rt_hash_mask - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 			dn_rt_hash_mask--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 		dn_rt_hash_table = (struct dn_rt_hash_bucket *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 			__get_free_pages(GFP_ATOMIC, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 	} while (dn_rt_hash_table == NULL && --order > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	if (!dn_rt_hash_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 		panic("Failed to allocate DECnet route cache hash table\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 	printk(KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 		"DECnet: Routing cache hash table of %u buckets, %ldKbytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 		dn_rt_hash_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 		(long)(dn_rt_hash_mask*sizeof(struct dn_rt_hash_bucket))/1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 	dn_rt_hash_mask--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 	for(i = 0; i <= dn_rt_hash_mask; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 		spin_lock_init(&dn_rt_hash_table[i].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 		dn_rt_hash_table[i].chain = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 	dn_dst_ops.gc_thresh = (dn_rt_hash_mask + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 	proc_create_seq_private("decnet_cache", 0444, init_net.proc_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 			&dn_rt_cache_seq_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 			sizeof(struct dn_rt_cache_iter_state), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) #ifdef CONFIG_DECNET_ROUTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 	rtnl_register_module(THIS_MODULE, PF_DECnet, RTM_GETROUTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 			     dn_cache_getroute, dn_fib_dump, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	rtnl_register_module(THIS_MODULE, PF_DECnet, RTM_GETROUTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 			     dn_cache_getroute, dn_cache_dump, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) void __exit dn_route_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 	del_timer(&dn_route_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	dn_run_flush(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 	remove_proc_entry("decnet_cache", init_net.proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	dst_entries_destroy(&dn_dst_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) }