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)  *	IPv6 Address [auto]configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *	Linux INET6 implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *	Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *	Pedro Roque		<roque@di.fc.ul.pt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *	Alexey Kuznetsov	<kuznet@ms2.inr.ac.ru>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) 
^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)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *	Janos Farkas			:	delete timer on ifdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *	<chexum@bankinf.banki.hu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *	Andi Kleen			:	kill double kfree on module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *						unload.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *	Maciej W. Rozycki		:	FDDI support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *	sekiya@USAGI			:	Don't send too many RS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *						packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *	yoshfuji@USAGI			:       Fixed interval between DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *						packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *	YOSHIFUJI Hideaki @USAGI	:	improved accuracy of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *						address validation timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *	YOSHIFUJI Hideaki @USAGI	:	Privacy Extensions (RFC3041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *						support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *	Yuji SEKIYA @USAGI		:	Don't assign a same IPv6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *						address on a same interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  *	YOSHIFUJI Hideaki @USAGI	:	ARCnet support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  *	YOSHIFUJI Hideaki @USAGI	:	convert /proc/net/if_inet6 to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *						seq_file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  *	YOSHIFUJI Hideaki @USAGI	:	improved source address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  *						selection; consider scope,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  *						status etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #define pr_fmt(fmt) "IPv6: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <linux/if_addr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <linux/if_arcnet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <linux/if_infiniband.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/inetdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #include <linux/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #include <net/snmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #include <net/6lowpan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) #include <net/firewire.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) #include <net/ndisc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #include <net/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #include <net/l3mdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #include <linux/if_tunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #include <linux/netconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #include <trace/hooks/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) #define	INFINITY_LIFE_TIME	0xFFFFFFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) #define IPV6_MAX_STRLEN \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) static inline u32 cstamp_delta(unsigned long cstamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	return (cstamp - INITIAL_JIFFIES) * 100UL / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) static inline s32 rfc3315_s14_backoff_init(s32 irt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	/* multiply 'initial retransmission time' by 0.9 .. 1.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	u64 tmp = (900000 + prandom_u32() % 200001) * (u64)irt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	do_div(tmp, 1000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	return (s32)tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) static inline s32 rfc3315_s14_backoff_update(s32 rt, s32 mrt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	/* multiply 'retransmission timeout' by 1.9 .. 2.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	u64 tmp = (1900000 + prandom_u32() % 200001) * (u64)rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	do_div(tmp, 1000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	if ((s32)tmp > mrt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 		/* multiply 'maximum retransmission time' by 0.9 .. 1.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 		tmp = (900000 + prandom_u32() % 200001) * (u64)mrt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 		do_div(tmp, 1000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	return (s32)tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) static int addrconf_sysctl_register(struct inet6_dev *idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) static void addrconf_sysctl_unregister(struct inet6_dev *idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) static inline int addrconf_sysctl_register(struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) static inline void addrconf_sysctl_unregister(struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) static void ipv6_gen_rnd_iid(struct in6_addr *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) static int ipv6_generate_eui64(u8 *eui, struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) static int ipv6_count_addresses(const struct inet6_dev *idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static int ipv6_generate_stable_address(struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 					u8 dad_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 					const struct inet6_dev *idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) #define IN6_ADDR_HSIZE_SHIFT	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) #define IN6_ADDR_HSIZE		(1 << IN6_ADDR_HSIZE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151)  *	Configured unicast address hash table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) static struct hlist_head inet6_addr_lst[IN6_ADDR_HSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) static DEFINE_SPINLOCK(addrconf_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) static void addrconf_verify(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) static void addrconf_verify_rtnl(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) static void addrconf_verify_work(struct work_struct *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) static struct workqueue_struct *addrconf_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) static DECLARE_DELAYED_WORK(addr_chk_work, addrconf_verify_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) static void addrconf_join_anycast(struct inet6_ifaddr *ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) static void addrconf_leave_anycast(struct inet6_ifaddr *ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) static void addrconf_type_change(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 				 unsigned long event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) static int addrconf_ifdown(struct net_device *dev, bool unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 						  int plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 						  const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 						  u32 flags, u32 noflags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 						  bool no_gw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) static void addrconf_dad_start(struct inet6_ifaddr *ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) static void addrconf_dad_work(struct work_struct *w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) static void addrconf_dad_completed(struct inet6_ifaddr *ifp, bool bump_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 				   bool send_na);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) static void addrconf_dad_run(struct inet6_dev *idev, bool restart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) static void addrconf_rs_timer(struct timer_list *t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) static void inet6_prefix_notify(int event, struct inet6_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 				struct prefix_info *pinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) static struct ipv6_devconf ipv6_devconf __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	.forwarding		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	.hop_limit		= IPV6_DEFAULT_HOPLIMIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	.mtu6			= IPV6_MIN_MTU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	.accept_ra		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	.accept_redirects	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	.autoconf		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	.force_mld_version	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	.mldv1_unsolicited_report_interval = 10 * HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	.mldv2_unsolicited_report_interval = HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	.dad_transmits		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	.rtr_solicits		= MAX_RTR_SOLICITATIONS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	.rtr_solicit_interval	= RTR_SOLICITATION_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	.rtr_solicit_max_interval = RTR_SOLICITATION_MAX_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	.rtr_solicit_delay	= MAX_RTR_SOLICITATION_DELAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	.use_tempaddr		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	.temp_valid_lft		= TEMP_VALID_LIFETIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	.temp_prefered_lft	= TEMP_PREFERRED_LIFETIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	.regen_max_retry	= REGEN_MAX_RETRY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	.max_desync_factor	= MAX_DESYNC_FACTOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	.max_addresses		= IPV6_MAX_ADDRESSES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	.accept_ra_defrtr	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	.accept_ra_from_local	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	.accept_ra_min_hop_limit= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	.accept_ra_pinfo	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) #ifdef CONFIG_IPV6_ROUTER_PREF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	.accept_ra_rtr_pref	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	.rtr_probe_interval	= 60 * HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) #ifdef CONFIG_IPV6_ROUTE_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	.accept_ra_rt_info_min_plen = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	.accept_ra_rt_info_max_plen = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	.accept_ra_rt_table	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	.proxy_ndp		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	.accept_source_route	= 0,	/* we do not accept RH0 by default. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	.disable_ipv6		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	.accept_dad		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	.suppress_frag_ndisc	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	.accept_ra_mtu		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	.stable_secret		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		.initialized = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	.use_oif_addrs_only	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	.ignore_routes_with_linkdown = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	.keep_addr_on_down	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	.seg6_enabled		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) #ifdef CONFIG_IPV6_SEG6_HMAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	.seg6_require_hmac	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	.enhanced_dad           = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	.addr_gen_mode		= IN6_ADDR_GEN_MODE_EUI64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	.disable_policy		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	.rpl_seg_enabled	= 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) static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	.forwarding		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	.hop_limit		= IPV6_DEFAULT_HOPLIMIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	.mtu6			= IPV6_MIN_MTU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	.accept_ra		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	.accept_redirects	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	.autoconf		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	.force_mld_version	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	.mldv1_unsolicited_report_interval = 10 * HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	.mldv2_unsolicited_report_interval = HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	.dad_transmits		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	.rtr_solicits		= MAX_RTR_SOLICITATIONS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	.rtr_solicit_interval	= RTR_SOLICITATION_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	.rtr_solicit_max_interval = RTR_SOLICITATION_MAX_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	.rtr_solicit_delay	= MAX_RTR_SOLICITATION_DELAY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	.use_tempaddr		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	.temp_valid_lft		= TEMP_VALID_LIFETIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	.temp_prefered_lft	= TEMP_PREFERRED_LIFETIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	.regen_max_retry	= REGEN_MAX_RETRY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	.max_desync_factor	= MAX_DESYNC_FACTOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	.max_addresses		= IPV6_MAX_ADDRESSES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	.accept_ra_defrtr	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	.accept_ra_from_local	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	.accept_ra_min_hop_limit= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	.accept_ra_pinfo	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) #ifdef CONFIG_IPV6_ROUTER_PREF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	.accept_ra_rtr_pref	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	.rtr_probe_interval	= 60 * HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) #ifdef CONFIG_IPV6_ROUTE_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	.accept_ra_rt_info_min_plen = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	.accept_ra_rt_info_max_plen = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	.accept_ra_rt_table	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	.proxy_ndp		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	.accept_source_route	= 0,	/* we do not accept RH0 by default. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	.disable_ipv6		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	.accept_dad		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	.suppress_frag_ndisc	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	.accept_ra_mtu		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	.stable_secret		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		.initialized = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	.use_oif_addrs_only	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	.ignore_routes_with_linkdown = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	.keep_addr_on_down	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	.seg6_enabled		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) #ifdef CONFIG_IPV6_SEG6_HMAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	.seg6_require_hmac	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	.enhanced_dad           = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	.addr_gen_mode		= IN6_ADDR_GEN_MODE_EUI64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	.disable_policy		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	.rpl_seg_enabled	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) /* Check if link is ready: is it up and is a valid qdisc available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) static inline bool addrconf_link_ready(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	return netif_oper_up(dev) && !qdisc_tx_is_noop(dev);
^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) static void addrconf_del_rs_timer(struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	if (del_timer(&idev->rs_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		__in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) static void addrconf_del_dad_work(struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	if (cancel_delayed_work(&ifp->dad_work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		__in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) static void addrconf_mod_rs_timer(struct inet6_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 				  unsigned long when)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	if (!timer_pending(&idev->rs_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		in6_dev_hold(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	mod_timer(&idev->rs_timer, jiffies + when);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) static void addrconf_mod_dad_work(struct inet6_ifaddr *ifp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 				   unsigned long delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	in6_ifa_hold(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	if (mod_delayed_work(addrconf_wq, &ifp->dad_work, delay))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) static int snmp6_alloc_dev(struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	idev->stats.ipv6 = alloc_percpu(struct ipstats_mib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	if (!idev->stats.ipv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		goto err_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	for_each_possible_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		struct ipstats_mib *addrconf_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		addrconf_stats = per_cpu_ptr(idev->stats.ipv6, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		u64_stats_init(&addrconf_stats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	idev->stats.icmpv6dev = kzalloc(sizeof(struct icmpv6_mib_device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 					GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	if (!idev->stats.icmpv6dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		goto err_icmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	idev->stats.icmpv6msgdev = kzalloc(sizeof(struct icmpv6msg_mib_device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 					   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	if (!idev->stats.icmpv6msgdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		goto err_icmpmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) err_icmpmsg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	kfree(idev->stats.icmpv6dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) err_icmp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	free_percpu(idev->stats.ipv6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) err_ip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) static struct inet6_dev *ipv6_add_dev(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	struct inet6_dev *ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	if (dev->mtu < IPV6_MIN_MTU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	if (!ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	rwlock_init(&ndev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	ndev->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	INIT_LIST_HEAD(&ndev->addr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	timer_setup(&ndev->rs_timer, addrconf_rs_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	if (ndev->cnf.stable_secret.initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		ndev->cnf.addr_gen_mode = IN6_ADDR_GEN_MODE_STABLE_PRIVACY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	ndev->cnf.mtu6 = dev->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	if (!ndev->nd_parms) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		kfree(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	if (ndev->cnf.forwarding)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		dev_disable_lro(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	/* We refer to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	dev_hold(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	if (snmp6_alloc_dev(ndev) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		netdev_dbg(dev, "%s: cannot allocate memory for statistics\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		neigh_parms_release(&nd_tbl, ndev->nd_parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		kfree(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	if (snmp6_register_dev(ndev) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		netdev_dbg(dev, "%s: cannot create /proc/net/dev_snmp6/%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 			   __func__, dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		goto err_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	/* One reference from device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	refcount_set(&ndev->refcnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	if (dev->flags & (IFF_NOARP | IFF_LOOPBACK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		ndev->cnf.accept_dad = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) #if IS_ENABLED(CONFIG_IPV6_SIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	if (dev->type == ARPHRD_SIT && (dev->priv_flags & IFF_ISATAP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		pr_info("%s: Disabled Multicast RS\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		ndev->cnf.rtr_solicits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	INIT_LIST_HEAD(&ndev->tempaddr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	ndev->desync_factor = U32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	if ((dev->flags&IFF_LOOPBACK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	    dev->type == ARPHRD_TUNNEL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	    dev->type == ARPHRD_TUNNEL6 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	    dev->type == ARPHRD_SIT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	    dev->type == ARPHRD_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		ndev->cnf.use_tempaddr = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	ndev->token = in6addr_any;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	if (netif_running(dev) && addrconf_link_ready(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		ndev->if_flags |= IF_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	ipv6_mc_init_dev(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	ndev->tstamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	err = addrconf_sysctl_register(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		ipv6_mc_destroy_dev(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		snmp6_unregister_dev(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		goto err_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	/* protected by rtnl_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	rcu_assign_pointer(dev->ip6_ptr, ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	/* Join interface-local all-node multicast group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	ipv6_dev_mc_inc(dev, &in6addr_interfacelocal_allnodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	/* Join all-node multicast group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	ipv6_dev_mc_inc(dev, &in6addr_linklocal_allnodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	/* Join all-router multicast group if forwarding is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	if (ndev->cnf.forwarding && (dev->flags & IFF_MULTICAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		ipv6_dev_mc_inc(dev, &in6addr_linklocal_allrouters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	return ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) err_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	neigh_parms_release(&nd_tbl, ndev->nd_parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	ndev->dead = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	in6_dev_finish_destroy(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) static struct inet6_dev *ipv6_find_idev(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	if (!idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		idev = ipv6_add_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		if (IS_ERR(idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 			return idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	if (dev->flags&IFF_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		ipv6_mc_up(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	return idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) static int inet6_netconf_msgsize_devconf(int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	int size =  NLMSG_ALIGN(sizeof(struct netconfmsg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		    + nla_total_size(4);	/* NETCONFA_IFINDEX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	bool all = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	if (type == NETCONFA_ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		all = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	if (all || type == NETCONFA_FORWARDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		size += nla_total_size(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) #ifdef CONFIG_IPV6_MROUTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	if (all || type == NETCONFA_MC_FORWARDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		size += nla_total_size(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	if (all || type == NETCONFA_PROXY_NEIGH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		size += nla_total_size(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	if (all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		size += nla_total_size(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) static int inet6_netconf_fill_devconf(struct sk_buff *skb, int ifindex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 				      struct ipv6_devconf *devconf, u32 portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 				      u32 seq, int event, unsigned int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 				      int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	struct nlmsghdr  *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	struct netconfmsg *ncm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	bool all = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct netconfmsg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	if (!nlh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	if (type == NETCONFA_ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		all = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	ncm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	ncm->ncm_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	if (!devconf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	if ((all || type == NETCONFA_FORWARDING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	    nla_put_s32(skb, NETCONFA_FORWARDING, devconf->forwarding) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) #ifdef CONFIG_IPV6_MROUTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	if ((all || type == NETCONFA_MC_FORWARDING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	    nla_put_s32(skb, NETCONFA_MC_FORWARDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			devconf->mc_forwarding) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	if ((all || type == NETCONFA_PROXY_NEIGH) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	    nla_put_s32(skb, NETCONFA_PROXY_NEIGH, devconf->proxy_ndp) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	if ((all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	    nla_put_s32(skb, NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 			devconf->ignore_routes_with_linkdown) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	nlmsg_cancel(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) void inet6_netconf_notify_devconf(struct net *net, int event, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 				  int ifindex, struct ipv6_devconf *devconf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	int err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	skb = nlmsg_new(inet6_netconf_msgsize_devconf(type), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	err = inet6_netconf_fill_devconf(skb, ifindex, devconf, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 					 event, 0, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		/* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		WARN_ON(err == -EMSGSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	rtnl_notify(skb, net, 0, RTNLGRP_IPV6_NETCONF, NULL, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	rtnl_set_sk_err(net, RTNLGRP_IPV6_NETCONF, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) static const struct nla_policy devconf_ipv6_policy[NETCONFA_MAX+1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	[NETCONFA_IFINDEX]	= { .len = sizeof(int) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	[NETCONFA_FORWARDING]	= { .len = sizeof(int) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	[NETCONFA_PROXY_NEIGH]	= { .len = sizeof(int) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	[NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN]	= { .len = sizeof(int) },
^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 inet6_netconf_valid_get_req(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 				       const struct nlmsghdr *nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 				       struct nlattr **tb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 				       struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(struct netconfmsg))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		NL_SET_ERR_MSG_MOD(extack, "Invalid header for netconf get request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	if (!netlink_strict_get_check(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		return nlmsg_parse_deprecated(nlh, sizeof(struct netconfmsg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 					      tb, NETCONFA_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 					      devconf_ipv6_policy, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct netconfmsg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 					    tb, NETCONFA_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 					    devconf_ipv6_policy, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	for (i = 0; i <= NETCONFA_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		if (!tb[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		switch (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		case NETCONFA_IFINDEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 			NL_SET_ERR_MSG_MOD(extack, "Unsupported attribute in netconf get request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) static int inet6_netconf_get_devconf(struct sk_buff *in_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 				     struct nlmsghdr *nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 				     struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	struct net *net = sock_net(in_skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	struct nlattr *tb[NETCONFA_MAX+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	struct inet6_dev *in6_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	struct net_device *dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	struct ipv6_devconf *devconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	int ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	err = inet6_netconf_valid_get_req(in_skb, nlh, tb, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	if (!tb[NETCONFA_IFINDEX])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	ifindex = nla_get_s32(tb[NETCONFA_IFINDEX]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	switch (ifindex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	case NETCONFA_IFINDEX_ALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		devconf = net->ipv6.devconf_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	case NETCONFA_IFINDEX_DEFAULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		devconf = net->ipv6.devconf_dflt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		dev = dev_get_by_index(net, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		in6_dev = in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		if (!in6_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 			goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		devconf = &in6_dev->cnf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	skb = nlmsg_new(inet6_netconf_msgsize_devconf(NETCONFA_ALL), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	err = inet6_netconf_fill_devconf(skb, ifindex, devconf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 					 NETLINK_CB(in_skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 					 nlh->nlmsg_seq, RTM_NEWNETCONF, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 					 NETCONFA_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		/* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		WARN_ON(err == -EMSGSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	if (in6_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		in6_dev_put(in6_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) static int inet6_netconf_dump_devconf(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 				      struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	const struct nlmsghdr *nlh = cb->nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	int h, s_h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	int idx, s_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	if (cb->strict_check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		struct netlink_ext_ack *extack = cb->extack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		struct netconfmsg *ncm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ncm))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 			NL_SET_ERR_MSG_MOD(extack, "Invalid header for netconf dump request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		if (nlmsg_attrlen(nlh, sizeof(*ncm))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 			NL_SET_ERR_MSG_MOD(extack, "Invalid data after header in netconf dump request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 			return -EINVAL;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	s_h = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	s_idx = idx = cb->args[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		head = &net->dev_index_head[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 			  net->dev_base_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		hlist_for_each_entry_rcu(dev, head, index_hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			if (idx < s_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 				goto cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 			idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 			if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 				goto cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			if (inet6_netconf_fill_devconf(skb, dev->ifindex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 						       &idev->cnf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 						       NETLINK_CB(cb->skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 						       nlh->nlmsg_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 						       RTM_NEWNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 						       NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 						       NETCONFA_ALL) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 				rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 				goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 			nl_dump_check_consistent(cb, nlmsg_hdr(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) cont:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 			idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	if (h == NETDEV_HASHENTRIES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		if (inet6_netconf_fill_devconf(skb, NETCONFA_IFINDEX_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 					       net->ipv6.devconf_all,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 					       NETLINK_CB(cb->skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 					       nlh->nlmsg_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 					       RTM_NEWNETCONF, NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 					       NETCONFA_ALL) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 			h++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	if (h == NETDEV_HASHENTRIES + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		if (inet6_netconf_fill_devconf(skb, NETCONFA_IFINDEX_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 					       net->ipv6.devconf_dflt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 					       NETLINK_CB(cb->skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 					       nlh->nlmsg_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 					       RTM_NEWNETCONF, NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 					       NETCONFA_ALL) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 			h++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	cb->args[0] = h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	cb->args[1] = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) static void dev_forward_change(struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	struct inet6_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	dev = idev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	if (idev->cnf.forwarding)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 		dev_disable_lro(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	if (dev->flags & IFF_MULTICAST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		if (idev->cnf.forwarding) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			ipv6_dev_mc_inc(dev, &in6addr_linklocal_allrouters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 			ipv6_dev_mc_inc(dev, &in6addr_interfacelocal_allrouters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 			ipv6_dev_mc_inc(dev, &in6addr_sitelocal_allrouters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 			ipv6_dev_mc_dec(dev, &in6addr_linklocal_allrouters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 			ipv6_dev_mc_dec(dev, &in6addr_interfacelocal_allrouters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 			ipv6_dev_mc_dec(dev, &in6addr_sitelocal_allrouters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	list_for_each_entry(ifa, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		if (ifa->flags&IFA_F_TENTATIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		if (idev->cnf.forwarding)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			addrconf_join_anycast(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 			addrconf_leave_anycast(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	inet6_netconf_notify_devconf(dev_net(dev), RTM_NEWNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 				     NETCONFA_FORWARDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 				     dev->ifindex, &idev->cnf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) static void addrconf_forward_change(struct net *net, __s32 newf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	for_each_netdev(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		if (idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 			int changed = (!idev->cnf.forwarding) ^ (!newf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 			idev->cnf.forwarding = newf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 			if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 				dev_forward_change(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) static int addrconf_fixup_forwarding(struct ctl_table *table, int *p, int newf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	int old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 		return restart_syscall();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	net = (struct net *)table->extra2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	old = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	*p = newf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	if (p == &net->ipv6.devconf_dflt->forwarding) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		if ((!newf) ^ (!old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 						     NETCONFA_FORWARDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 						     NETCONFA_IFINDEX_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 						     net->ipv6.devconf_dflt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	if (p == &net->ipv6.devconf_all->forwarding) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		int old_dflt = net->ipv6.devconf_dflt->forwarding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		net->ipv6.devconf_dflt->forwarding = newf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		if ((!newf) ^ (!old_dflt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 			inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 						     NETCONFA_FORWARDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 						     NETCONFA_IFINDEX_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 						     net->ipv6.devconf_dflt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		addrconf_forward_change(net, newf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		if ((!newf) ^ (!old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 			inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 						     NETCONFA_FORWARDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 						     NETCONFA_IFINDEX_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 						     net->ipv6.devconf_all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	} else if ((!newf) ^ (!old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		dev_forward_change((struct inet6_dev *)table->extra1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	if (newf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		rt6_purge_dflt_routers(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) static void addrconf_linkdown_change(struct net *net, __s32 newf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	for_each_netdev(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		if (idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 			int changed = (!idev->cnf.ignore_routes_with_linkdown) ^ (!newf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 			idev->cnf.ignore_routes_with_linkdown = newf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 			if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 				inet6_netconf_notify_devconf(dev_net(dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 							     RTM_NEWNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 							     NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 							     dev->ifindex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 							     &idev->cnf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) static int addrconf_fixup_linkdown(struct ctl_table *table, int *p, int newf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	int old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		return restart_syscall();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	net = (struct net *)table->extra2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	old = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	*p = newf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	if (p == &net->ipv6.devconf_dflt->ignore_routes_with_linkdown) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		if ((!newf) ^ (!old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 			inet6_netconf_notify_devconf(net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 						     RTM_NEWNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 						     NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 						     NETCONFA_IFINDEX_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 						     net->ipv6.devconf_dflt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	if (p == &net->ipv6.devconf_all->ignore_routes_with_linkdown) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 		net->ipv6.devconf_dflt->ignore_routes_with_linkdown = newf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		addrconf_linkdown_change(net, newf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		if ((!newf) ^ (!old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 			inet6_netconf_notify_devconf(net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 						     RTM_NEWNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 						     NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 						     NETCONFA_IFINDEX_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 						     net->ipv6.devconf_all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) /* Nobody refers to this ifaddr, destroy it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	WARN_ON(!hlist_unhashed(&ifp->addr_lst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) #ifdef NET_REFCNT_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	pr_debug("%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	in6_dev_put(ifp->idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	if (cancel_delayed_work(&ifp->dad_work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		pr_notice("delayed DAD work was pending while freeing ifa=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 			  ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	if (ifp->state != INET6_IFADDR_STATE_DEAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		pr_warn("Freeing alive inet6 address %p\n", ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	kfree_rcu(ifp, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	struct list_head *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	int ifp_scope = ipv6_addr_src_scope(&ifp->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	 * Each device address list is sorted in order of scope -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	 * global before linklocal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	list_for_each(p, &idev->addr_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		struct inet6_ifaddr *ifa
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 			= list_entry(p, struct inet6_ifaddr, if_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	list_add_tail_rcu(&ifp->if_list, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) static u32 inet6_addr_hash(const struct net *net, const struct in6_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	u32 val = ipv6_addr_hash(addr) ^ net_hash_mix(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	return hash_32(val, IN6_ADDR_HSIZE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 			       struct net_device *dev, unsigned int hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	hlist_for_each_entry(ifp, &inet6_addr_lst[hash], addr_lst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		if (!net_eq(dev_net(ifp->idev->dev), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		if (ipv6_addr_equal(&ifp->addr, addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 			if (!dev || ifp->idev->dev == dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 				return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) static int ipv6_add_addr_hash(struct net_device *dev, struct inet6_ifaddr *ifa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	unsigned int hash = inet6_addr_hash(dev_net(dev), &ifa->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	spin_lock(&addrconf_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	/* Ignore adding duplicate addresses on an interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	if (ipv6_chk_same_addr(dev_net(dev), &ifa->addr, dev, hash)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		netdev_dbg(dev, "ipv6_add_addr: already assigned\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		err = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	spin_unlock(&addrconf_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) /* On success it returns ifp with increased reference count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) static struct inet6_ifaddr *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	      bool can_block, struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	gfp_t gfp_flags = can_block ? GFP_KERNEL : GFP_ATOMIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	int addr_type = ipv6_addr_type(cfg->pfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	struct net *net = dev_net(idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	struct inet6_ifaddr *ifa = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	struct fib6_info *f6i = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	if (addr_type == IPV6_ADDR_ANY ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	    (addr_type & IPV6_ADDR_MULTICAST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	     !(cfg->ifa_flags & IFA_F_MCAUTOJOIN)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	    (!(idev->dev->flags & IFF_LOOPBACK) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	     !netif_is_l3_master(idev->dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	     addr_type & IPV6_ADDR_LOOPBACK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		return ERR_PTR(-EADDRNOTAVAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	if (idev->dead) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		err = -ENODEV;			/*XXX*/
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	if (idev->cnf.disable_ipv6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		err = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	/* validator notifier needs to be blocking;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	 * do not call in atomic context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	if (can_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		struct in6_validator_info i6vi = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 			.i6vi_addr = *cfg->pfx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 			.i6vi_dev = idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 			.extack = extack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		err = inet6addr_validator_notifier_call_chain(NETDEV_UP, &i6vi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		err = notifier_to_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	ifa = kzalloc(sizeof(*ifa), gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	if (!ifa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	f6i = addrconf_f6i_alloc(net, idev, cfg->pfx, false, gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	if (IS_ERR(f6i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		err = PTR_ERR(f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		f6i = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	if (net->ipv6.devconf_all->disable_policy ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	    idev->cnf.disable_policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		f6i->dst_nopolicy = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	neigh_parms_data_state_setall(idev->nd_parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	ifa->addr = *cfg->pfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	if (cfg->peer_pfx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		ifa->peer_addr = *cfg->peer_pfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	spin_lock_init(&ifa->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	INIT_DELAYED_WORK(&ifa->dad_work, addrconf_dad_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	INIT_HLIST_NODE(&ifa->addr_lst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	ifa->scope = cfg->scope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	ifa->prefix_len = cfg->plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	ifa->rt_priority = cfg->rt_priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	ifa->flags = cfg->ifa_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	/* No need to add the TENTATIVE flag for addresses with NODAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	if (!(cfg->ifa_flags & IFA_F_NODAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		ifa->flags |= IFA_F_TENTATIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	ifa->valid_lft = cfg->valid_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	ifa->prefered_lft = cfg->preferred_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	ifa->cstamp = ifa->tstamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	ifa->tokenized = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	ifa->rt = f6i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	ifa->idev = idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	in6_dev_hold(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	/* For caller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	refcount_set(&ifa->refcnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	rcu_read_lock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	err = ipv6_add_addr_hash(idev->dev, ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 		rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	write_lock(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	/* Add to inet6_dev unicast addr list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	ipv6_link_dev_addr(idev, ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	if (ifa->flags&IFA_F_TEMPORARY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		list_add(&ifa->tmp_list, &idev->tempaddr_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		in6_ifa_hold(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	in6_ifa_hold(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	write_unlock(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	inet6addr_notifier_call_chain(NETDEV_UP, ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	if (unlikely(err < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 		fib6_info_release(f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		if (ifa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 			if (ifa->idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 				in6_dev_put(ifa->idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 			kfree(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		ifa = ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	return ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) enum cleanup_prefix_rt_t {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	CLEANUP_PREFIX_RT_NOP,    /* no cleanup action for prefix route */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	CLEANUP_PREFIX_RT_DEL,    /* delete the prefix route */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	CLEANUP_PREFIX_RT_EXPIRE, /* update the lifetime of the prefix route */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)  * Check, whether the prefix for ifp would still need a prefix route
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)  * after deleting ifp. The function returns one of the CLEANUP_PREFIX_RT_*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)  * constants.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)  * 1) we don't purge prefix if address was not permanent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)  *    prefix is managed by its own lifetime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)  * 2) we also don't purge, if the address was IFA_F_NOPREFIXROUTE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)  * 3) if there are no addresses, delete prefix.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)  * 4) if there are still other permanent address(es),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)  *    corresponding prefix is still permanent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)  * 5) if there are still other addresses with IFA_F_NOPREFIXROUTE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)  *    don't purge the prefix, assume user space is managing it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)  * 6) otherwise, update prefix lifetime to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)  *    longest valid lifetime among the corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)  *    addresses on the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)  *    Note: subsequent RA will update lifetime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) static enum cleanup_prefix_rt_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) check_cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long *expires)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	struct inet6_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	struct inet6_dev *idev = ifp->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	unsigned long lifetime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	enum cleanup_prefix_rt_t action = CLEANUP_PREFIX_RT_DEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	*expires = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	list_for_each_entry(ifa, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		if (ifa == ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 		if (ifa->prefix_len != ifp->prefix_len ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		    !ipv6_prefix_equal(&ifa->addr, &ifp->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 				       ifp->prefix_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		if (ifa->flags & (IFA_F_PERMANENT | IFA_F_NOPREFIXROUTE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 			return CLEANUP_PREFIX_RT_NOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 		action = CLEANUP_PREFIX_RT_EXPIRE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 		spin_lock(&ifa->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		lifetime = addrconf_timeout_fixup(ifa->valid_lft, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 		 * Note: Because this address is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 		 * not permanent, lifetime <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 		 * LONG_MAX / HZ here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 		if (time_before(*expires, ifa->tstamp + lifetime * HZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 			*expires = ifa->tstamp + lifetime * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		spin_unlock(&ifa->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	return action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		     bool del_rt, bool del_peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	struct fib6_info *f6i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	f6i = addrconf_get_prefix_route(del_peer ? &ifp->peer_addr : &ifp->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 					ifp->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 					ifp->idev->dev, 0, RTF_DEFAULT, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	if (f6i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		if (del_rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 			ip6_del_rt(dev_net(ifp->idev->dev), f6i, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 			if (!(f6i->fib6_flags & RTF_EXPIRES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 				fib6_set_expires(f6i, expires);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 			fib6_info_release(f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) /* This function wants to get referenced ifp and releases it before return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) static void ipv6_del_addr(struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	enum cleanup_prefix_rt_t action = CLEANUP_PREFIX_RT_NOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	unsigned long expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	state = ifp->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	ifp->state = INET6_IFADDR_STATE_DEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	if (state == INET6_IFADDR_STATE_DEAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	spin_lock_bh(&addrconf_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	hlist_del_init_rcu(&ifp->addr_lst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	spin_unlock_bh(&addrconf_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	write_lock_bh(&ifp->idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	if (ifp->flags&IFA_F_TEMPORARY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 		list_del(&ifp->tmp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		if (ifp->ifpub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 			in6_ifa_put(ifp->ifpub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 			ifp->ifpub = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 		__in6_ifa_put(ifp);
^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) 	if (ifp->flags & IFA_F_PERMANENT && !(ifp->flags & IFA_F_NOPREFIXROUTE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		action = check_cleanup_prefix_route(ifp, &expires);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	list_del_rcu(&ifp->if_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	__in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	write_unlock_bh(&ifp->idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	addrconf_del_dad_work(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	ipv6_ifa_notify(RTM_DELADDR, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	inet6addr_notifier_call_chain(NETDEV_DOWN, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	if (action != CLEANUP_PREFIX_RT_NOP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 		cleanup_prefix_route(ifp, expires,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 			action == CLEANUP_PREFIX_RT_DEL, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	/* clean up prefsrc entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	rt6_remove_prefsrc(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	struct inet6_dev *idev = ifp->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	unsigned long tmp_tstamp, age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	unsigned long regen_advance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	s32 cnf_temp_preferred_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	struct inet6_ifaddr *ift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	struct ifa6_config cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	long max_desync_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	struct in6_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	write_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	in6_dev_hold(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	if (idev->cnf.use_tempaddr <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 		pr_info("%s: use_tempaddr is disabled\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 		in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	if (ifp->regen_count++ >= idev->cnf.regen_max_retry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		idev->cnf.use_tempaddr = -1;	/*XXX*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 		pr_warn("%s: regeneration time exceeded - disabled temporary address support\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 			__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	in6_ifa_hold(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	memcpy(addr.s6_addr, ifp->addr.s6_addr, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	ipv6_gen_rnd_iid(&addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	age = (now - ifp->tstamp) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	regen_advance = idev->cnf.regen_max_retry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 			idev->cnf.dad_transmits *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 			max(NEIGH_VAR(idev->nd_parms, RETRANS_TIME), HZ/100) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	/* recalculate max_desync_factor each time and update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	 * idev->desync_factor if it's larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	cnf_temp_preferred_lft = READ_ONCE(idev->cnf.temp_prefered_lft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	max_desync_factor = min_t(__u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 				  idev->cnf.max_desync_factor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 				  cnf_temp_preferred_lft - regen_advance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	if (unlikely(idev->desync_factor > max_desync_factor)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		if (max_desync_factor > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 			get_random_bytes(&idev->desync_factor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 					 sizeof(idev->desync_factor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 			idev->desync_factor %= max_desync_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 			idev->desync_factor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	memset(&cfg, 0, sizeof(cfg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	cfg.valid_lft = min_t(__u32, ifp->valid_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 			      idev->cnf.temp_valid_lft + age);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	cfg.preferred_lft = cnf_temp_preferred_lft + age - idev->desync_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	cfg.preferred_lft = min_t(__u32, ifp->prefered_lft, cfg.preferred_lft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	cfg.plen = ifp->prefix_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	tmp_tstamp = ifp->tstamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 	spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	/* A temporary address is created only if this calculated Preferred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	 * Lifetime is greater than REGEN_ADVANCE time units.  In particular,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	 * an implementation must not create a temporary address with a zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	 * Preferred Lifetime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	 * Use age calculation as in addrconf_verify to avoid unnecessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	 * temporary addresses being generated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	if (cfg.preferred_lft <= regen_advance + age) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 		in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 		in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 		ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		goto out;
^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) 	cfg.ifa_flags = IFA_F_TEMPORARY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	/* set in addrconf_prefix_rcv() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 	if (ifp->flags & IFA_F_OPTIMISTIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		cfg.ifa_flags |= IFA_F_OPTIMISTIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	cfg.pfx = &addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	cfg.scope = ipv6_addr_scope(cfg.pfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	ift = ipv6_add_addr(idev, &cfg, block, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	if (IS_ERR(ift)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		pr_info("%s: retry temporary address regeneration\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		write_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	spin_lock_bh(&ift->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	ift->ifpub = ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	ift->cstamp = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	ift->tstamp = tmp_tstamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	spin_unlock_bh(&ift->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	addrconf_dad_start(ift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	in6_ifa_put(ift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432)  *	Choose an appropriate source address (RFC3484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	IPV6_SADDR_RULE_INIT = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	IPV6_SADDR_RULE_LOCAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	IPV6_SADDR_RULE_SCOPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	IPV6_SADDR_RULE_PREFERRED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) #ifdef CONFIG_IPV6_MIP6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	IPV6_SADDR_RULE_HOA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	IPV6_SADDR_RULE_OIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	IPV6_SADDR_RULE_LABEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	IPV6_SADDR_RULE_PRIVACY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	IPV6_SADDR_RULE_ORCHID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 	IPV6_SADDR_RULE_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	IPV6_SADDR_RULE_NOT_OPTIMISTIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	IPV6_SADDR_RULE_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) struct ipv6_saddr_score {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	int			rule;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	int			addr_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	struct inet6_ifaddr	*ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	DECLARE_BITMAP(scorebits, IPV6_SADDR_RULE_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	int			scopedist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	int			matchlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) struct ipv6_saddr_dst {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	const struct in6_addr *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	int ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	int scope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	int label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	unsigned int prefs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) static inline int ipv6_saddr_preferred(int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	if (type & (IPV6_ADDR_MAPPED|IPV6_ADDR_COMPATv4|IPV6_ADDR_LOOPBACK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) static bool ipv6_use_optimistic_addr(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 				     struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	if (!net->ipv6.devconf_all->optimistic_dad && !idev->cnf.optimistic_dad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	if (!net->ipv6.devconf_all->use_optimistic && !idev->cnf.use_optimistic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) static bool ipv6_allow_optimistic_dad(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 				      struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	if (!net->ipv6.devconf_all->optimistic_dad && !idev->cnf.optimistic_dad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) static int ipv6_get_saddr_eval(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 			       struct ipv6_saddr_score *score,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 			       struct ipv6_saddr_dst *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 			       int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	if (i <= score->rule) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 		switch (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 		case IPV6_SADDR_RULE_SCOPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 			ret = score->scopedist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 		case IPV6_SADDR_RULE_PREFIX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 			ret = score->matchlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 			ret = !!test_bit(i, score->scorebits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	switch (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	case IPV6_SADDR_RULE_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 		/* Rule 0: remember if hiscore is not ready yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 		ret = !!score->ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	case IPV6_SADDR_RULE_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 		/* Rule 1: Prefer same address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 		ret = ipv6_addr_equal(&score->ifa->addr, dst->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	case IPV6_SADDR_RULE_SCOPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 		/* Rule 2: Prefer appropriate scope
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 		 *      ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 		 *       ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 		 *    -1 |  d 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 		 *    ---+--+-+---> scope
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 		 *       |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 		 *       |             d is scope of the destination.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 		 *  B-d  |  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 		 *       |   \      <- smaller scope is better if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 		 *  B-15 |    \        if scope is enough for destination.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 		 *       |             ret = B - scope (-1 <= scope >= d <= 15).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 		 * d-C-1 | /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 		 *       |/         <- greater is better
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 		 *   -C  /             if scope is not enough for destination.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 		 *      /|             ret = scope - C (-1 <= d < scope <= 15).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 		 * d - C - 1 < B -15 (for all -1 <= d <= 15).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 		 * C > d + 14 - B >= 15 + 14 - B = 29 - B.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 		 * Assume B = 0 and we get C > 29.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 		ret = __ipv6_addr_src_scope(score->addr_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		if (ret >= dst->scope)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 			ret = -ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 			ret -= 128;	/* 30 is enough */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 		score->scopedist = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	case IPV6_SADDR_RULE_PREFERRED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		/* Rule 3: Avoid deprecated and optimistic addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		u8 avoid = IFA_F_DEPRECATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		if (!ipv6_use_optimistic_addr(net, score->ifa->idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 			avoid |= IFA_F_OPTIMISTIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		ret = ipv6_saddr_preferred(score->addr_type) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 		      !(score->ifa->flags & avoid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) #ifdef CONFIG_IPV6_MIP6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	case IPV6_SADDR_RULE_HOA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 		/* Rule 4: Prefer home address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 		int prefhome = !(dst->prefs & IPV6_PREFER_SRC_COA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 		ret = !(score->ifa->flags & IFA_F_HOMEADDRESS) ^ prefhome;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	case IPV6_SADDR_RULE_OIF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 		/* Rule 5: Prefer outgoing interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 		ret = (!dst->ifindex ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		       dst->ifindex == score->ifa->idev->dev->ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	case IPV6_SADDR_RULE_LABEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 		/* Rule 6: Prefer matching label */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 		ret = ipv6_addr_label(net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 				      &score->ifa->addr, score->addr_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 				      score->ifa->idev->dev->ifindex) == dst->label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	case IPV6_SADDR_RULE_PRIVACY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 		/* Rule 7: Prefer public address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 		 * Note: prefer temporary address if use_tempaddr >= 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 		int preftmp = dst->prefs & (IPV6_PREFER_SRC_PUBLIC|IPV6_PREFER_SRC_TMP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 				!!(dst->prefs & IPV6_PREFER_SRC_TMP) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 				score->ifa->idev->cnf.use_tempaddr >= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 		ret = (!(score->ifa->flags & IFA_F_TEMPORARY)) ^ preftmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	case IPV6_SADDR_RULE_ORCHID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 		/* Rule 8-: Prefer ORCHID vs ORCHID or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 		 *	    non-ORCHID vs non-ORCHID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		ret = !(ipv6_addr_orchid(&score->ifa->addr) ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 			ipv6_addr_orchid(dst->addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	case IPV6_SADDR_RULE_PREFIX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 		/* Rule 8: Use longest matching prefix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 		ret = ipv6_addr_diff(&score->ifa->addr, dst->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 		if (ret > score->ifa->prefix_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 			ret = score->ifa->prefix_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 		score->matchlen = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	case IPV6_SADDR_RULE_NOT_OPTIMISTIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 		/* Optimistic addresses still have lower precedence than other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 		 * preferred addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 		ret = !(score->ifa->flags & IFA_F_OPTIMISTIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 		__set_bit(i, score->scorebits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	score->rule = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) static int __ipv6_dev_get_saddr(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 				struct ipv6_saddr_dst *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 				struct inet6_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 				struct ipv6_saddr_score *scores,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 				int hiscore_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	struct ipv6_saddr_score *score = &scores[1 - hiscore_idx], *hiscore = &scores[hiscore_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	list_for_each_entry_rcu(score->ifa, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 		 * - Tentative Address (RFC2462 section 5.4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 		 *  - A tentative address is not considered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 		 *    "assigned to an interface" in the traditional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 		 *    sense, unless it is also flagged as optimistic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 		 * - Candidate Source Address (section 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 		 *  - In any case, anycast addresses, multicast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 		 *    addresses, and the unspecified address MUST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 		 *    NOT be included in a candidate set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 		if ((score->ifa->flags & IFA_F_TENTATIVE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 		    (!(score->ifa->flags & IFA_F_OPTIMISTIC)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 		score->addr_type = __ipv6_addr_type(&score->ifa->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 		if (unlikely(score->addr_type == IPV6_ADDR_ANY ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 			     score->addr_type & IPV6_ADDR_MULTICAST)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 			net_dbg_ratelimited("ADDRCONF: unspecified / multicast address assigned as unicast address on %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 					    idev->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 		score->rule = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 		bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 		for (i = 0; i < IPV6_SADDR_RULE_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 			int minihiscore, miniscore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 			minihiscore = ipv6_get_saddr_eval(net, hiscore, dst, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 			miniscore = ipv6_get_saddr_eval(net, score, dst, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 			if (minihiscore > miniscore) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 				if (i == IPV6_SADDR_RULE_SCOPE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 				    score->scopedist > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 					/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 					 * special case:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 					 * each remaining entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 					 * has too small (not enough)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 					 * scope, because ifa entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 					 * are sorted by their scope
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 					 * values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 					goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 			} else if (minihiscore < miniscore) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 				swap(hiscore, score);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 				hiscore_idx = 1 - hiscore_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 				/* restore our iterator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 				score->ifa = hiscore->ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 			}
^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) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	return hiscore_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) static int ipv6_get_saddr_master(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 				 const struct net_device *dst_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 				 const struct net_device *master,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 				 struct ipv6_saddr_dst *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 				 struct ipv6_saddr_score *scores,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 				 int hiscore_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	idev = __in6_dev_get(dst_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	if (idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 		hiscore_idx = __ipv6_dev_get_saddr(net, dst, idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 						   scores, hiscore_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	idev = __in6_dev_get(master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	if (idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 		hiscore_idx = __ipv6_dev_get_saddr(net, dst, idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 						   scores, hiscore_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	return hiscore_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 		       const struct in6_addr *daddr, unsigned int prefs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 		       struct in6_addr *saddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	struct ipv6_saddr_score scores[2], *hiscore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	struct ipv6_saddr_dst dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	int dst_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 	bool use_oif_addr = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	int hiscore_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	dst_type = __ipv6_addr_type(daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	dst.addr = daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	dst.ifindex = dst_dev ? dst_dev->ifindex : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	dst.scope = __ipv6_addr_src_scope(dst_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	dst.label = ipv6_addr_label(net, daddr, dst_type, dst.ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	dst.prefs = prefs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	scores[hiscore_idx].rule = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 	scores[hiscore_idx].ifa = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	/* Candidate Source Address (section 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	 *  - multicast and link-local destination address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	 *    the set of candidate source address MUST only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	 *    include addresses assigned to interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	 *    belonging to the same link as the outgoing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	 *    interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	 * (- For site-local destination addresses, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	 *    set of candidate source addresses MUST only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	 *    include addresses assigned to interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	 *    belonging to the same site as the outgoing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	 *    interface.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	 *  - "It is RECOMMENDED that the candidate source addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	 *    be the set of unicast addresses assigned to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	 *    interface that will be used to send to the destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 	 *    (the 'outgoing' interface)." (RFC 6724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	if (dst_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 		idev = __in6_dev_get(dst_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 		if ((dst_type & IPV6_ADDR_MULTICAST) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 		    dst.scope <= IPV6_ADDR_SCOPE_LINKLOCAL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 		    (idev && idev->cnf.use_oif_addrs_only)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 			use_oif_addr = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	if (use_oif_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 		if (idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 			hiscore_idx = __ipv6_dev_get_saddr(net, &dst, idev, scores, hiscore_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 		const struct net_device *master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 		int master_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 		/* if dst_dev exists and is enslaved to an L3 device, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 		 * prefer addresses from dst_dev and then the master over
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 		 * any other enslaved devices in the L3 domain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 		master = l3mdev_master_dev_rcu(dst_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 		if (master) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 			master_idx = master->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 			hiscore_idx = ipv6_get_saddr_master(net, dst_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 							    master, &dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 							    scores, hiscore_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 			if (scores[hiscore_idx].ifa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 		for_each_netdev_rcu(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 			/* only consider addresses on devices in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 			 * same L3 domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 			if (l3mdev_master_ifindex_rcu(dev) != master_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 			idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 			if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 			hiscore_idx = __ipv6_dev_get_saddr(net, &dst, idev, scores, hiscore_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	hiscore = &scores[hiscore_idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	if (!hiscore->ifa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 		ret = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 		*saddr = hiscore->ifa->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) EXPORT_SYMBOL(ipv6_dev_get_saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 		      u32 banned_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	int err = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	list_for_each_entry_reverse(ifp, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 		if (ifp->scope > IFA_LINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 		if (ifp->scope == IFA_LINK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 		    !(ifp->flags & banned_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 			*addr = ifp->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 			err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 		    u32 banned_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	int err = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 	idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	if (idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 		read_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 		err = __ipv6_get_lladdr(idev, addr, banned_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 		read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	return err;
^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) static int ipv6_count_addresses(const struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	const struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	int cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	list_for_each_entry_rcu(ifp, &idev->addr_list, if_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 		cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) int ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 		  const struct net_device *dev, int strict)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	return ipv6_chk_addr_and_flags(net, addr, dev, !dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 				       strict, IFA_F_TENTATIVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) EXPORT_SYMBOL(ipv6_chk_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) /* device argument is used to find the L3 domain of interest. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)  * skip_dev_check is set, then the ifp device is not checked against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893)  * the passed in dev argument. So the 2 cases for addresses checks are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)  *   1. does the address exist in the L3 domain that dev is part of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)  *      (skip_dev_check = true), or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897)  *   2. does the address exist on the specific device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898)  *      (skip_dev_check = false)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) static struct net_device *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) __ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 			  const struct net_device *dev, bool skip_dev_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 			  int strict, u32 banned_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 	unsigned int hash = inet6_addr_hash(net, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	struct net_device *l3mdev, *ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 	u32 ifp_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	l3mdev = l3mdev_master_dev_rcu(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 	if (skip_dev_check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 		dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 		ndev = ifp->idev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 		if (!net_eq(dev_net(ndev), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 		if (l3mdev_master_dev_rcu(ndev) != l3mdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 		/* Decouple optimistic from tentative for evaluation here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 		 * Ban optimistic addresses explicitly, when required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 		ifp_flags = (ifp->flags&IFA_F_OPTIMISTIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 			    ? (ifp->flags&~IFA_F_TENTATIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 			    : ifp->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 		if (ipv6_addr_equal(&ifp->addr, addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 		    !(ifp_flags&banned_flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 		    (!dev || ndev == dev ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 		     !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 			return ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) int ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 			    const struct net_device *dev, bool skip_dev_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 			    int strict, u32 banned_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	return __ipv6_chk_addr_and_flags(net, addr, dev, skip_dev_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 					 strict, banned_flags) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) EXPORT_SYMBOL(ipv6_chk_addr_and_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) /* Compares an address/prefix_len with addresses on device @dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)  * If one is found it returns true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) bool ipv6_chk_custom_prefix(const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 	const unsigned int prefix_len, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 	const struct inet6_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 	const struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	if (idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 		list_for_each_entry_rcu(ifa, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 			ret = ipv6_prefix_equal(addr, &ifa->addr, prefix_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) EXPORT_SYMBOL(ipv6_chk_custom_prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) int ipv6_chk_prefix(const struct in6_addr *addr, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 	const struct inet6_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 	const struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 	int	onlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	onlink = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 	idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	if (idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 		list_for_each_entry_rcu(ifa, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 			onlink = ipv6_prefix_equal(addr, &ifa->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 						   ifa->prefix_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 			if (onlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 	return onlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) EXPORT_SYMBOL(ipv6_chk_prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001)  * ipv6_dev_find - find the first device with a given source address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002)  * @net: the net namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003)  * @addr: the source address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005)  * The caller should be protected by RCU, or RTNL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) struct net_device *ipv6_dev_find(struct net *net, const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 				 struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 	return __ipv6_chk_addr_and_flags(net, addr, dev, !dev, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 					 IFA_F_TENTATIVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) EXPORT_SYMBOL(ipv6_dev_find);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 				     struct net_device *dev, int strict)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 	unsigned int hash = inet6_addr_hash(net, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	struct inet6_ifaddr *ifp, *result = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 		if (!net_eq(dev_net(ifp->idev->dev), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 		if (ipv6_addr_equal(&ifp->addr, addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 			if (!dev || ifp->idev->dev == dev ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 			    !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 				result = ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 				in6_ifa_hold(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) /* Gets referenced address, destroys ifaddr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) static void addrconf_dad_stop(struct inet6_ifaddr *ifp, int dad_failed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 	if (dad_failed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 		ifp->flags |= IFA_F_DADFAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	if (ifp->flags&IFA_F_TEMPORARY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 		struct inet6_ifaddr *ifpub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 		spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 		ifpub = ifp->ifpub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 		if (ifpub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 			in6_ifa_hold(ifpub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 			spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 			ipv6_create_tempaddr(ifpub, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 			in6_ifa_put(ifpub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 			spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 		ipv6_del_addr(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 	} else if (ifp->flags&IFA_F_PERMANENT || !dad_failed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 		spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 		addrconf_del_dad_work(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 		ifp->flags |= IFA_F_TENTATIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 		if (dad_failed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 			ifp->flags &= ~IFA_F_OPTIMISTIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 		spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 		if (dad_failed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 			ipv6_ifa_notify(0, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 		in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 		ipv6_del_addr(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) static int addrconf_dad_end(struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 	int err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 	if (ifp->state == INET6_IFADDR_STATE_DAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 		ifp->state = INET6_IFADDR_STATE_POSTDAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 	spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 	struct inet6_dev *idev = ifp->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 	struct net *net = dev_net(ifp->idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	if (addrconf_dad_end(ifp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 		in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	net_info_ratelimited("%s: IPv6 duplicate address %pI6c used by %pM detected!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 			     ifp->idev->dev->name, &ifp->addr, eth_hdr(skb)->h_source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 	spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 	if (ifp->flags & IFA_F_STABLE_PRIVACY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 		struct in6_addr new_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 		struct inet6_ifaddr *ifp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 		int retries = ifp->stable_privacy_retry + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 		struct ifa6_config cfg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 			.pfx = &new_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 			.plen = ifp->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 			.ifa_flags = ifp->flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 			.valid_lft = ifp->valid_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 			.preferred_lft = ifp->prefered_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 			.scope = ifp->scope,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 		if (retries > net->ipv6.sysctl.idgen_retries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 			net_info_ratelimited("%s: privacy stable address generation failed because of DAD conflicts!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 					     ifp->idev->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 			goto errdad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 		new_addr = ifp->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 		if (ipv6_generate_stable_address(&new_addr, retries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 						 idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 			goto errdad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 		spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 		if (idev->cnf.max_addresses &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 		    ipv6_count_addresses(idev) >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 		    idev->cnf.max_addresses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 			goto lock_errdad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 		net_info_ratelimited("%s: generating new stable privacy address because of DAD conflict\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 				     ifp->idev->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 		ifp2 = ipv6_add_addr(idev, &cfg, false, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 		if (IS_ERR(ifp2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 			goto lock_errdad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 		spin_lock_bh(&ifp2->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 		ifp2->stable_privacy_retry = retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 		ifp2->state = INET6_IFADDR_STATE_PREDAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 		spin_unlock_bh(&ifp2->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 		addrconf_mod_dad_work(ifp2, net->ipv6.sysctl.idgen_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 		in6_ifa_put(ifp2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) lock_errdad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 		spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) errdad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 	/* transition from _POSTDAD to _ERRDAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	ifp->state = INET6_IFADDR_STATE_ERRDAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 	spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 	addrconf_mod_dad_work(ifp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 	in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) /* Join to solicited addr multicast group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162)  * caller must hold RTNL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) void addrconf_join_solict(struct net_device *dev, const struct in6_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 	struct in6_addr maddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 	if (dev->flags&(IFF_LOOPBACK|IFF_NOARP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	addrconf_addr_solict_mult(addr, &maddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 	ipv6_dev_mc_inc(dev, &maddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) /* caller must hold RTNL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) void addrconf_leave_solict(struct inet6_dev *idev, const struct in6_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 	struct in6_addr maddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 	if (idev->dev->flags&(IFF_LOOPBACK|IFF_NOARP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 	addrconf_addr_solict_mult(addr, &maddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 	__ipv6_dev_mc_dec(idev, &maddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) /* caller must hold RTNL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) static void addrconf_join_anycast(struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 	struct in6_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 	if (ifp->prefix_len >= 127) /* RFC 6164 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 	ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 	if (ipv6_addr_any(&addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 	__ipv6_dev_ac_inc(ifp->idev, &addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) /* caller must hold RTNL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) static void addrconf_leave_anycast(struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 	struct in6_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 	if (ifp->prefix_len >= 127) /* RFC 6164 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 	ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 	if (ipv6_addr_any(&addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	__ipv6_dev_ac_dec(ifp->idev, &addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) static int addrconf_ifid_6lowpan(u8 *eui, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 	switch (dev->addr_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 	case ETH_ALEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 		memcpy(eui, dev->dev_addr, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 		eui[3] = 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 		eui[4] = 0xFE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 		memcpy(eui + 5, dev->dev_addr + 3, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 	case EUI64_ADDR_LEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 		memcpy(eui, dev->dev_addr, EUI64_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 		eui[0] ^= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) static int addrconf_ifid_ieee1394(u8 *eui, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 	union fwnet_hwaddr *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 	if (dev->addr_len != FWNET_ALEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 	ha = (union fwnet_hwaddr *)dev->dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 	memcpy(eui, &ha->uc.uniq_id, sizeof(ha->uc.uniq_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 	eui[0] ^= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) static int addrconf_ifid_arcnet(u8 *eui, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 	/* XXX: inherit EUI-64 from other interface -- yoshfuji */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 	if (dev->addr_len != ARCNET_ALEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 	memset(eui, 0, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 	eui[7] = *(u8 *)dev->dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) static int addrconf_ifid_infiniband(u8 *eui, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 	if (dev->addr_len != INFINIBAND_ALEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 	memcpy(eui, dev->dev_addr + 12, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 	eui[0] |= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) static int __ipv6_isatap_ifid(u8 *eui, __be32 addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 	if (addr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 	eui[0] = (ipv4_is_zeronet(addr) || ipv4_is_private_10(addr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 		  ipv4_is_loopback(addr) || ipv4_is_linklocal_169(addr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 		  ipv4_is_private_172(addr) || ipv4_is_test_192(addr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 		  ipv4_is_anycast_6to4(addr) || ipv4_is_private_192(addr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 		  ipv4_is_test_198(addr) || ipv4_is_multicast(addr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 		  ipv4_is_lbcast(addr)) ? 0x00 : 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 	eui[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 	eui[2] = 0x5E;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 	eui[3] = 0xFE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 	memcpy(eui + 4, &addr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) static int addrconf_ifid_sit(u8 *eui, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 	if (dev->priv_flags & IFF_ISATAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 		return __ipv6_isatap_ifid(eui, *(__be32 *)dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) static int addrconf_ifid_gre(u8 *eui, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 	return __ipv6_isatap_ifid(eui, *(__be32 *)dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) static int addrconf_ifid_ip6tnl(u8 *eui, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 	memcpy(eui, dev->perm_addr, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 	memcpy(eui + 5, dev->perm_addr + 3, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 	eui[3] = 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 	eui[4] = 0xFE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 	eui[0] ^= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) static int ipv6_generate_eui64(u8 *eui, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 	switch (dev->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 	case ARPHRD_ETHER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 	case ARPHRD_FDDI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 		return addrconf_ifid_eui48(eui, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 	case ARPHRD_ARCNET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 		return addrconf_ifid_arcnet(eui, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 	case ARPHRD_INFINIBAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 		return addrconf_ifid_infiniband(eui, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 	case ARPHRD_SIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 		return addrconf_ifid_sit(eui, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 	case ARPHRD_IPGRE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 	case ARPHRD_TUNNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 		return addrconf_ifid_gre(eui, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 	case ARPHRD_6LOWPAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 		return addrconf_ifid_6lowpan(eui, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 	case ARPHRD_IEEE1394:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 		return addrconf_ifid_ieee1394(eui, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 	case ARPHRD_TUNNEL6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 	case ARPHRD_IP6GRE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 	case ARPHRD_RAWIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 		return addrconf_ifid_ip6tnl(eui, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) static int ipv6_inherit_eui64(u8 *eui, struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 	int err = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 	read_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 	list_for_each_entry_reverse(ifp, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 		if (ifp->scope > IFA_LINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 		if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 			memcpy(eui, ifp->addr.s6_addr+8, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 			err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 	read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) /* Generation of a randomized Interface Identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)  * draft-ietf-6man-rfc4941bis, Section 3.3.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) static void ipv6_gen_rnd_iid(struct in6_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) regen:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 	get_random_bytes(&addr->s6_addr[8], 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 	/* <draft-ietf-6man-rfc4941bis-08.txt>, Section 3.3.1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 	 * check if generated address is not inappropriate:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 	 * - Reserved IPv6 Interface Identifers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 	 * - XXX: already assigned to an address on the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 	/* Subnet-router anycast: 0000:0000:0000:0000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 	if (!(addr->s6_addr32[2] | addr->s6_addr32[3]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 		goto regen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 	/* IANA Ethernet block: 0200:5EFF:FE00:0000-0200:5EFF:FE00:5212
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 	 * Proxy Mobile IPv6:   0200:5EFF:FE00:5213
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 	 * IANA Ethernet block: 0200:5EFF:FE00:5214-0200:5EFF:FEFF:FFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	if (ntohl(addr->s6_addr32[2]) == 0x02005eff &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 	    (ntohl(addr->s6_addr32[3]) & 0Xff000000) == 0xfe000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 		goto regen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 	/* Reserved subnet anycast addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 	if (ntohl(addr->s6_addr32[2]) == 0xfdffffff &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	    ntohl(addr->s6_addr32[3]) >= 0Xffffff80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 		goto regen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) u32 addrconf_rt_table(const struct net_device *dev, u32 default_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 	struct inet6_dev *idev = in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 	int sysctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	u32 table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 		return default_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 	sysctl = idev->cnf.accept_ra_rt_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 	if (sysctl == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 		table = default_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 	} else if (sysctl > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 		table = (u32) sysctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 		table = (unsigned) dev->ifindex + (-sysctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 	in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 	return table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405)  *	Add prefix route.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) addrconf_prefix_route(struct in6_addr *pfx, int plen, u32 metric,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 		      struct net_device *dev, unsigned long expires,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 		      u32 flags, gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 	struct fib6_config cfg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 		.fc_table = l3mdev_fib_table(dev) ? : addrconf_rt_table(dev, RT6_TABLE_PREFIX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 		.fc_metric = metric ? : IP6_RT_PRIO_ADDRCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 		.fc_ifindex = dev->ifindex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 		.fc_expires = expires,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 		.fc_dst_len = plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 		.fc_flags = RTF_UP | flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 		.fc_nlinfo.nl_net = dev_net(dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 		.fc_protocol = RTPROT_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 		.fc_type = RTN_UNICAST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 	cfg.fc_dst = *pfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 	/* Prevent useless cloning on PtP SIT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 	   This thing is done here expecting that the whole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 	   class of non-broadcast devices need not cloning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) #if IS_ENABLED(CONFIG_IPV6_SIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 	if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 		cfg.fc_flags |= RTF_NONEXTHOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 	ip6_route_add(&cfg, gfp_flags, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 						  int plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 						  const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 						  u32 flags, u32 noflags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 						  bool no_gw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 	struct fib6_node *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 	struct fib6_info *rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 	struct fib6_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 	u32 tb_id = l3mdev_fib_table(dev) ? : addrconf_rt_table(dev, RT6_TABLE_PREFIX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 	table = fib6_get_table(dev_net(dev), tb_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 	if (!table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 	fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 	if (!fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 	for_each_fib6_node_rt_rcu(fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 		/* prefix routes only use builtin fib6_nh */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 		if (rt->nh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 		if (rt->fib6_nh->fib_nh_dev->ifindex != dev->ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 		if (no_gw && rt->fib6_nh->fib_nh_gw_family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 		if ((rt->fib6_flags & flags) != flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 		if ((rt->fib6_flags & noflags) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 		if (!fib6_info_hold_safe(rt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 	return rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) /* Create "default" multicast route to the interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) static void addrconf_add_mroute(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 	struct fib6_config cfg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 		.fc_table = l3mdev_fib_table(dev) ? : RT6_TABLE_LOCAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 		.fc_metric = IP6_RT_PRIO_ADDRCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 		.fc_ifindex = dev->ifindex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 		.fc_dst_len = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 		.fc_flags = RTF_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 		.fc_type = RTN_MULTICAST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 		.fc_nlinfo.nl_net = dev_net(dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 		.fc_protocol = RTPROT_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 	ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 	ip6_route_add(&cfg, GFP_KERNEL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) static struct inet6_dev *addrconf_add_dev(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 	idev = ipv6_find_idev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 	if (IS_ERR(idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 		return idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 	if (idev->cnf.disable_ipv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 		return ERR_PTR(-EACCES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 	/* Add default multicast route */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 	if (!(dev->flags & IFF_LOOPBACK) && !netif_is_l3_master(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 		addrconf_add_mroute(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 	return idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) static void manage_tempaddrs(struct inet6_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 			     struct inet6_ifaddr *ifp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 			     __u32 valid_lft, __u32 prefered_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 			     bool create, unsigned long now)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 	u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 	struct inet6_ifaddr *ift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 	read_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 	/* update all temporary addresses in the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 	list_for_each_entry(ift, &idev->tempaddr_list, tmp_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 		int age, max_valid, max_prefered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 		if (ifp != ift->ifpub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 		/* RFC 4941 section 3.3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 		 * If a received option will extend the lifetime of a public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 		 * address, the lifetimes of temporary addresses should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 		 * be extended, subject to the overall constraint that no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 		 * temporary addresses should ever remain "valid" or "preferred"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 		 * for a time longer than (TEMP_VALID_LIFETIME) or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 		 * (TEMP_PREFERRED_LIFETIME - DESYNC_FACTOR), respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 		age = (now - ift->cstamp) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 		max_valid = idev->cnf.temp_valid_lft - age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 		if (max_valid < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 			max_valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 		max_prefered = idev->cnf.temp_prefered_lft -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 			       idev->desync_factor - age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 		if (max_prefered < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 			max_prefered = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 		if (valid_lft > max_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 			valid_lft = max_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 		if (prefered_lft > max_prefered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 			prefered_lft = max_prefered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 		spin_lock(&ift->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 		flags = ift->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 		ift->valid_lft = valid_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 		ift->prefered_lft = prefered_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 		ift->tstamp = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 		if (prefered_lft > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 			ift->flags &= ~IFA_F_DEPRECATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 		spin_unlock(&ift->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 		if (!(flags&IFA_F_TENTATIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 			ipv6_ifa_notify(0, ift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 	if ((create || list_empty(&idev->tempaddr_list)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 	    idev->cnf.use_tempaddr > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 		/* When a new public address is created as described
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 		 * in [ADDRCONF], also create a new temporary address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 		 * Also create a temporary address if it's enabled but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 		 * no temporary address currently exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 		read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 		ipv6_create_tempaddr(ifp, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 		read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) static bool is_addr_mode_generate_stable(struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 	return idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_STABLE_PRIVACY ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 	       idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_RANDOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) int addrconf_prefix_rcv_add_addr(struct net *net, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 				 const struct prefix_info *pinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 				 struct inet6_dev *in6_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 				 const struct in6_addr *addr, int addr_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 				 u32 addr_flags, bool sllao, bool tokenized,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 				 __u32 valid_lft, u32 prefered_lft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 	struct inet6_ifaddr *ifp = ipv6_get_ifaddr(net, addr, dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 	int create = 0, update_lft = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 	if (!ifp && valid_lft) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 		int max_addresses = in6_dev->cnf.max_addresses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 		struct ifa6_config cfg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 			.pfx = addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 			.plen = pinfo->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 			.ifa_flags = addr_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 			.valid_lft = valid_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 			.preferred_lft = prefered_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 			.scope = addr_type & IPV6_ADDR_SCOPE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 		if ((net->ipv6.devconf_all->optimistic_dad ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 		     in6_dev->cnf.optimistic_dad) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 		    !net->ipv6.devconf_all->forwarding && sllao)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 			cfg.ifa_flags |= IFA_F_OPTIMISTIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 		/* Do not allow to create too much of autoconfigured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 		 * addresses; this would be too easy way to crash kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 		if (!max_addresses ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 		    ipv6_count_addresses(in6_dev) < max_addresses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 			ifp = ipv6_add_addr(in6_dev, &cfg, false, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 		if (IS_ERR_OR_NULL(ifp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 		create = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 		spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 		ifp->flags |= IFA_F_MANAGETEMPADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 		ifp->cstamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 		ifp->tokenized = tokenized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 		spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) 		addrconf_dad_start(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 	if (ifp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 		u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 		unsigned long now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 		u32 stored_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 		/* update lifetime (RFC2462 5.5.3 e) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 		spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 		now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 		if (ifp->valid_lft > (now - ifp->tstamp) / HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 			stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 			stored_lft = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 		if (!create && stored_lft) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 			const u32 minimum_lft = min_t(u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 				stored_lft, MIN_VALID_LIFETIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 			valid_lft = max(valid_lft, minimum_lft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 			/* RFC4862 Section 5.5.3e:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 			 * "Note that the preferred lifetime of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 			 *  corresponding address is always reset to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 			 *  the Preferred Lifetime in the received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 			 *  Prefix Information option, regardless of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 			 *  whether the valid lifetime is also reset or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 			 *  ignored."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 			 * So we should always update prefered_lft here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 			update_lft = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 		if (update_lft) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 			ifp->valid_lft = valid_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 			ifp->prefered_lft = prefered_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 			ifp->tstamp = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 			flags = ifp->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 			ifp->flags &= ~IFA_F_DEPRECATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 			spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 			if (!(flags&IFA_F_TENTATIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 				ipv6_ifa_notify(0, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 			spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 		manage_tempaddrs(in6_dev, ifp, valid_lft, prefered_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 				 create, now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 		in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 		addrconf_verify();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) EXPORT_SYMBOL_GPL(addrconf_prefix_rcv_add_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 	struct prefix_info *pinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 	__u32 valid_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 	__u32 prefered_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 	int addr_type, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 	u32 addr_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 	struct inet6_dev *in6_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 	struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 	pinfo = (struct prefix_info *) opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 	if (len < sizeof(struct prefix_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 		netdev_dbg(dev, "addrconf: prefix option too short\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 	 *	Validation checks ([ADDRCONF], page 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 	addr_type = ipv6_addr_type(&pinfo->prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 	if (addr_type & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 	valid_lft = ntohl(pinfo->valid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 	prefered_lft = ntohl(pinfo->prefered);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 	if (prefered_lft > valid_lft) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 		net_warn_ratelimited("addrconf: prefix option has invalid lifetime\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 	in6_dev = in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 	if (!in6_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 		net_dbg_ratelimited("addrconf: device %s not configured\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 				    dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 	 *	Two things going on here:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 	 *	1) Add routes for on-link prefixes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 	 *	2) Configure prefixes with the auto flag set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 	if (pinfo->onlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 		struct fib6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 		unsigned long rt_expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 		/* Avoid arithmetic overflow. Really, we could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 		 * save rt_expires in seconds, likely valid_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 		 * but it would require division in fib gc, that it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 		 * not good.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 		if (HZ > USER_HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 			rt_expires = addrconf_timeout_fixup(valid_lft, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 			rt_expires = addrconf_timeout_fixup(valid_lft, USER_HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 		if (addrconf_finite_timeout(rt_expires))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 			rt_expires *= HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 		rt = addrconf_get_prefix_route(&pinfo->prefix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 					       pinfo->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 					       dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 					       RTF_ADDRCONF | RTF_PREFIX_RT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 					       RTF_DEFAULT, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 		if (rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 			/* Autoconf prefix route */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 			if (valid_lft == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 				ip6_del_rt(net, rt, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 				rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 			} else if (addrconf_finite_timeout(rt_expires)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 				/* not infinity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 				fib6_set_expires(rt, jiffies + rt_expires);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 				fib6_clean_expires(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 		} else if (valid_lft) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 			clock_t expires = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 			int flags = RTF_ADDRCONF | RTF_PREFIX_RT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 			if (addrconf_finite_timeout(rt_expires)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 				/* not infinity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 				flags |= RTF_EXPIRES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 				expires = jiffies_to_clock_t(rt_expires);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 			addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 					      0, dev, expires, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 					      GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 		fib6_info_release(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 	/* Try to figure out our local address for this prefix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 	if (pinfo->autoconf && in6_dev->cnf.autoconf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 		struct in6_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 		bool tokenized = false, dev_addr_generated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 		if (pinfo->prefix_len == 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 			memcpy(&addr, &pinfo->prefix, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 			if (!ipv6_addr_any(&in6_dev->token)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 				read_lock_bh(&in6_dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 				memcpy(addr.s6_addr + 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 				       in6_dev->token.s6_addr + 8, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 				read_unlock_bh(&in6_dev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 				tokenized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 			} else if (is_addr_mode_generate_stable(in6_dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 				   !ipv6_generate_stable_address(&addr, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 								 in6_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 				addr_flags |= IFA_F_STABLE_PRIVACY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 				goto ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 			} else if (ipv6_generate_eui64(addr.s6_addr + 8, dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 				   ipv6_inherit_eui64(addr.s6_addr + 8, in6_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 				goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 				dev_addr_generated = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 			goto ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 		net_dbg_ratelimited("IPv6 addrconf: prefix with wrong length %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 				    pinfo->prefix_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 		goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) ok:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 		err = addrconf_prefix_rcv_add_addr(net, dev, pinfo, in6_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 						   &addr, addr_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 						   addr_flags, sllao,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 						   tokenized, valid_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 						   prefered_lft);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 			goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 		/* Ignore error case here because previous prefix add addr was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 		 * successful which will be notified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 		ndisc_ops_prefix_rcv_add_addr(net, dev, pinfo, in6_dev, &addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 					      addr_type, addr_flags, sllao,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) 					      tokenized, valid_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 					      prefered_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 					      dev_addr_generated);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 	inet6_prefix_notify(RTM_NEWPREFIX, in6_dev, pinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) 	in6_dev_put(in6_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) static int addrconf_set_sit_dstaddr(struct net *net, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 		struct in6_ifreq *ireq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 	struct ip_tunnel_parm p = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 	if (!(ipv6_addr_type(&ireq->ifr6_addr) & IPV6_ADDR_COMPATv4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 		return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 	p.iph.daddr = ireq->ifr6_addr.s6_addr32[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 	p.iph.version = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) 	p.iph.ihl = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 	p.iph.protocol = IPPROTO_IPV6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 	p.iph.ttl = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 	if (!dev->netdev_ops->ndo_tunnel_ctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) 	err = dev->netdev_ops->ndo_tunnel_ctl(dev, &p, SIOCADDTUNNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) 	dev = __dev_get_by_name(net, p.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) 		return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 	return dev_open(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877)  *	Set destination address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878)  *	Special case for SIT interfaces where we create a new "virtual"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879)  *	device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) int addrconf_set_dstaddr(struct net *net, void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 	struct in6_ifreq ireq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 	int err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 	if (!IS_ENABLED(CONFIG_IPV6_SIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 	if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 	dev = __dev_get_by_index(net, ireq.ifr6_ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 	if (dev && dev->type == ARPHRD_SIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 		err = addrconf_set_sit_dstaddr(net, dev, &ireq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) static int ipv6_mc_config(struct sock *sk, bool join,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 			  const struct in6_addr *addr, int ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 	lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 	if (join)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 		ret = ipv6_sock_mc_join(sk, ifindex, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 		ret = ipv6_sock_mc_drop(sk, ifindex, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) 	release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918)  *	Manual configuration of address on an interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) static int inet6_addr_add(struct net *net, int ifindex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 			  struct ifa6_config *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 			  struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 	unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 	clock_t expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 	u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 	if (cfg->plen > 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 	/* check the lifetime */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 	if (!cfg->valid_lft || cfg->preferred_lft > cfg->valid_lft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 	if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR && cfg->plen != 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 	dev = __dev_get_by_index(net, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 	idev = addrconf_add_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 	if (IS_ERR(idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 		return PTR_ERR(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 	if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 		int ret = ipv6_mc_config(net->ipv6.mc_autojoin_sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 					 true, cfg->pfx, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) 	cfg->scope = ipv6_addr_scope(cfg->pfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 	timeout = addrconf_timeout_fixup(cfg->valid_lft, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 	if (addrconf_finite_timeout(timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 		expires = jiffies_to_clock_t(timeout * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 		cfg->valid_lft = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 		flags = RTF_EXPIRES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 		expires = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 		flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 		cfg->ifa_flags |= IFA_F_PERMANENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 	timeout = addrconf_timeout_fixup(cfg->preferred_lft, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) 	if (addrconf_finite_timeout(timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) 		if (timeout == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 			cfg->ifa_flags |= IFA_F_DEPRECATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) 		cfg->preferred_lft = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) 	ifp = ipv6_add_addr(idev, cfg, true, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 	if (!IS_ERR(ifp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) 		if (!(cfg->ifa_flags & IFA_F_NOPREFIXROUTE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 			addrconf_prefix_route(&ifp->addr, ifp->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) 					      ifp->rt_priority, dev, expires,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 					      flags, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 		/* Send a netlink notification if DAD is enabled and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) 		 * optimistic flag is not set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 		if (!(ifp->flags & (IFA_F_OPTIMISTIC | IFA_F_NODAD)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 			ipv6_ifa_notify(0, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 		 * Note that section 3.1 of RFC 4429 indicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) 		 * that the Optimistic flag should not be set for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) 		 * manually configured addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 		addrconf_dad_start(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) 		if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 			manage_tempaddrs(idev, ifp, cfg->valid_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) 					 cfg->preferred_lft, true, jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) 		in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) 		addrconf_verify_rtnl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 	} else if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 		ipv6_mc_config(net->ipv6.mc_autojoin_sk, false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 			       cfg->pfx, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 	return PTR_ERR(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) static int inet6_addr_del(struct net *net, int ifindex, u32 ifa_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 			  const struct in6_addr *pfx, unsigned int plen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 	if (plen > 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) 	dev = __dev_get_by_index(net, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 	idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 	read_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 	list_for_each_entry(ifp, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 		if (ifp->prefix_len == plen &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 		    ipv6_addr_equal(pfx, &ifp->addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 			in6_ifa_hold(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 			read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 			if (!(ifp->flags & IFA_F_TEMPORARY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 			    (ifa_flags & IFA_F_MANAGETEMPADDR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 				manage_tempaddrs(idev, ifp, 0, 0, false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) 						 jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 			ipv6_del_addr(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) 			addrconf_verify_rtnl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 			if (ipv6_addr_is_multicast(pfx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) 				ipv6_mc_config(net->ipv6.mc_autojoin_sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 					       false, pfx, dev->ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) 	read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) 	return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) int addrconf_add_ifaddr(struct net *net, void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 	struct ifa6_config cfg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 		.ifa_flags = IFA_F_PERMANENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 		.preferred_lft = INFINITY_LIFE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) 		.valid_lft = INFINITY_LIFE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 	struct in6_ifreq ireq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 	if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 	if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 	cfg.pfx = &ireq.ifr6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 	cfg.plen = ireq.ifr6_prefixlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 	err = inet6_addr_add(net, ireq.ifr6_ifindex, &cfg, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) int addrconf_del_ifaddr(struct net *net, void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 	struct in6_ifreq ireq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 	if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 	if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 	err = inet6_addr_del(net, ireq.ifr6_ifindex, 0, &ireq.ifr6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) 			     ireq.ifr6_prefixlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) static void add_addr(struct inet6_dev *idev, const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) 		     int plen, int scope)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) 	struct ifa6_config cfg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) 		.pfx = addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) 		.plen = plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) 		.ifa_flags = IFA_F_PERMANENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) 		.valid_lft = INFINITY_LIFE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) 		.preferred_lft = INFINITY_LIFE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) 		.scope = scope
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) 	ifp = ipv6_add_addr(idev, &cfg, true, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 	if (!IS_ERR(ifp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) 		spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 		ifp->flags &= ~IFA_F_TENTATIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 		spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) 		rt_genid_bump_ipv6(dev_net(idev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 		ipv6_ifa_notify(RTM_NEWADDR, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 		in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) #if IS_ENABLED(CONFIG_IPV6_SIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) static void sit_add_v4_addrs(struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 	struct in6_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 	struct net *net = dev_net(idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 	int scope, plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 	u32 pflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) 	memset(&addr, 0, sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 	memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 	if (idev->dev->flags&IFF_POINTOPOINT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 		if (idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 		addr.s6_addr32[0] = htonl(0xfe800000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) 		scope = IFA_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 		plen = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) 		scope = IPV6_ADDR_COMPATv4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 		plen = 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) 		pflags |= RTF_NONEXTHOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) 	if (addr.s6_addr32[3]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 		add_addr(idev, &addr, plen, scope);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) 		addrconf_prefix_route(&addr, plen, 0, idev->dev, 0, pflags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) 				      GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) 	for_each_netdev(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) 		struct in_device *in_dev = __in_dev_get_rtnl(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) 		if (in_dev && (dev->flags & IFF_UP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) 			struct in_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) 			int flag = scope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) 			in_dev_for_each_ifa_rtnl(ifa, in_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) 				addr.s6_addr32[3] = ifa->ifa_local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) 				if (ifa->ifa_scope == RT_SCOPE_LINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) 				if (ifa->ifa_scope >= RT_SCOPE_HOST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) 					if (idev->dev->flags&IFF_POINTOPOINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) 						continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) 					flag |= IFA_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) 				add_addr(idev, &addr, plen, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) 				addrconf_prefix_route(&addr, plen, 0, idev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) 						      0, pflags, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) static void init_loopback(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 	struct inet6_dev  *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) 	/* ::1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) 	idev = ipv6_find_idev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 	if (IS_ERR(idev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 		pr_debug("%s: add_dev failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) 	add_addr(idev, &in6addr_loopback, 128, IFA_HOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) void addrconf_add_linklocal(struct inet6_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) 			    const struct in6_addr *addr, u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) 	struct ifa6_config cfg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) 		.pfx = addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) 		.plen = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) 		.ifa_flags = flags | IFA_F_PERMANENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 		.valid_lft = INFINITY_LIFE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) 		.preferred_lft = INFINITY_LIFE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 		.scope = IFA_LINK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) 	if ((dev_net(idev->dev)->ipv6.devconf_all->optimistic_dad ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) 	     idev->cnf.optimistic_dad) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) 	    !dev_net(idev->dev)->ipv6.devconf_all->forwarding)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 		cfg.ifa_flags |= IFA_F_OPTIMISTIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) 	ifp = ipv6_add_addr(idev, &cfg, true, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) 	if (!IS_ERR(ifp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) 		addrconf_prefix_route(&ifp->addr, ifp->prefix_len, 0, idev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) 				      0, 0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) 		addrconf_dad_start(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) 		in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) EXPORT_SYMBOL_GPL(addrconf_add_linklocal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) static bool ipv6_reserved_interfaceid(struct in6_addr address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) 	if ((address.s6_addr32[2] | address.s6_addr32[3]) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) 	if (address.s6_addr32[2] == htonl(0x02005eff) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) 	    ((address.s6_addr32[3] & htonl(0xfe000000)) == htonl(0xfe000000)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) 	if (address.s6_addr32[2] == htonl(0xfdffffff) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) 	    ((address.s6_addr32[3] & htonl(0xffffff80)) == htonl(0xffffff80)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) static int ipv6_generate_stable_address(struct in6_addr *address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 					u8 dad_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 					const struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 	static DEFINE_SPINLOCK(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) 	static __u32 digest[SHA1_DIGEST_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 	static __u32 workspace[SHA1_WORKSPACE_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 	static union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 		char __data[SHA1_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 			struct in6_addr secret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) 			__be32 prefix[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 			unsigned char hwaddr[MAX_ADDR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) 			u8 dad_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) 		} __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) 	} data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 	struct in6_addr secret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) 	struct in6_addr temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) 	struct net *net = dev_net(idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 	BUILD_BUG_ON(sizeof(data.__data) != sizeof(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) 	if (idev->cnf.stable_secret.initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 		secret = idev->cnf.stable_secret.secret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) 	else if (net->ipv6.devconf_dflt->stable_secret.initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 		secret = net->ipv6.devconf_dflt->stable_secret.secret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) 	spin_lock_bh(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) 	sha1_init(digest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) 	memset(&data, 0, sizeof(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 	memset(workspace, 0, sizeof(workspace));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) 	memcpy(data.hwaddr, idev->dev->perm_addr, idev->dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 	data.prefix[0] = address->s6_addr32[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) 	data.prefix[1] = address->s6_addr32[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) 	data.secret = secret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 	data.dad_count = dad_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 	sha1_transform(digest, data.__data, workspace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) 	temp = *address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 	temp.s6_addr32[2] = (__force __be32)digest[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) 	temp.s6_addr32[3] = (__force __be32)digest[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) 	spin_unlock_bh(&lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) 	if (ipv6_reserved_interfaceid(temp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) 		dad_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) 		if (dad_count > dev_net(idev->dev)->ipv6.sysctl.idgen_retries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) 	*address = temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) static void ipv6_gen_mode_random_init(struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) 	struct ipv6_stable_secret *s = &idev->cnf.stable_secret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) 	if (s->initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) 	s = &idev->cnf.stable_secret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) 	get_random_bytes(&s->secret, sizeof(s->secret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) 	s->initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) static void addrconf_addr_gen(struct inet6_dev *idev, bool prefix_route)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 	struct in6_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) 	/* no link local addresses on L3 master devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) 	if (netif_is_l3_master(idev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) 	/* no link local addresses on devices flagged as slaves */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) 	if (idev->dev->flags & IFF_SLAVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) 	ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) 	switch (idev->cnf.addr_gen_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) 	case IN6_ADDR_GEN_MODE_RANDOM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) 		ipv6_gen_mode_random_init(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) 	case IN6_ADDR_GEN_MODE_STABLE_PRIVACY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) 		if (!ipv6_generate_stable_address(&addr, 0, idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 			addrconf_add_linklocal(idev, &addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) 					       IFA_F_STABLE_PRIVACY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) 		else if (prefix_route)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) 			addrconf_prefix_route(&addr, 64, 0, idev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) 					      0, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) 	case IN6_ADDR_GEN_MODE_EUI64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) 		/* addrconf_add_linklocal also adds a prefix_route and we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 		 * only need to care about prefix routes if ipv6_generate_eui64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) 		 * couldn't generate one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) 		if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) 			addrconf_add_linklocal(idev, &addr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) 		else if (prefix_route)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) 			addrconf_prefix_route(&addr, 64, 0, idev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) 					      0, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) 	case IN6_ADDR_GEN_MODE_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) 		/* will not add any link local address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) static void addrconf_dev_config(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) 	bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 	if ((dev->type != ARPHRD_ETHER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 	    (dev->type != ARPHRD_FDDI) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) 	    (dev->type != ARPHRD_ARCNET) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) 	    (dev->type != ARPHRD_INFINIBAND) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) 	    (dev->type != ARPHRD_IEEE1394) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) 	    (dev->type != ARPHRD_TUNNEL6) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) 	    (dev->type != ARPHRD_6LOWPAN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) 	    (dev->type != ARPHRD_IP6GRE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) 	    (dev->type != ARPHRD_IPGRE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) 	    (dev->type != ARPHRD_TUNNEL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) 	    (dev->type != ARPHRD_NONE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) 	    (dev->type != ARPHRD_RAWIP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) 		/* Alas, we support only Ethernet autoconfiguration. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) 		idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) 		if (!IS_ERR_OR_NULL(idev) && dev->flags & IFF_UP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) 		    dev->flags & IFF_MULTICAST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) 			ipv6_mc_up(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) 	idev = addrconf_add_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) 	if (IS_ERR(idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) 	trace_android_vh_ipv6_gen_linklocal_addr(dev, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) 	/* this device type has no EUI support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) 	if (dev->type == ARPHRD_NONE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) 	    idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_EUI64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) 		idev->cnf.addr_gen_mode = IN6_ADDR_GEN_MODE_RANDOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) 	addrconf_addr_gen(idev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) #if IS_ENABLED(CONFIG_IPV6_SIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) static void addrconf_sit_config(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 	 * Configure the tunnel with one of our IPv4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) 	 * addresses... we should configure all of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) 	 * our v4 addrs in the tunnel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) 	idev = ipv6_find_idev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) 	if (IS_ERR(idev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) 		pr_debug("%s: add_dev failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 	if (dev->priv_flags & IFF_ISATAP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) 		addrconf_addr_gen(idev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) 	sit_add_v4_addrs(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) 	if (dev->flags&IFF_POINTOPOINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) 		addrconf_add_mroute(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) #if IS_ENABLED(CONFIG_NET_IPGRE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) static void addrconf_gre_config(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) 	idev = ipv6_find_idev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) 	if (IS_ERR(idev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) 		pr_debug("%s: add_dev failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) 	addrconf_addr_gen(idev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) 	if (dev->flags & IFF_POINTOPOINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) 		addrconf_add_mroute(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) static int fixup_permanent_addr(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) 				struct inet6_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) 				struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 	/* !fib6_node means the host route was removed from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) 	 * FIB, for example, if 'lo' device is taken down. In that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) 	 * case regenerate the host route.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) 	if (!ifp->rt || !ifp->rt->fib6_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) 		struct fib6_info *f6i, *prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) 		f6i = addrconf_f6i_alloc(net, idev, &ifp->addr, false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) 					 GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) 		if (IS_ERR(f6i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) 			return PTR_ERR(f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) 		/* ifp->rt can be accessed outside of rtnl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) 		spin_lock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) 		prev = ifp->rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) 		ifp->rt = f6i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) 		spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) 		fib6_info_release(prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) 	if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) 		addrconf_prefix_route(&ifp->addr, ifp->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) 				      ifp->rt_priority, idev->dev, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) 				      GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) 	if (ifp->state == INET6_IFADDR_STATE_PREDAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) 		addrconf_dad_start(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) static void addrconf_permanent_addr(struct net *net, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) 	struct inet6_ifaddr *ifp, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) 	idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) 	write_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) 	list_for_each_entry_safe(ifp, tmp, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 		if ((ifp->flags & IFA_F_PERMANENT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) 		    fixup_permanent_addr(net, idev, ifp) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) 			write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) 			in6_ifa_hold(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) 			ipv6_del_addr(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) 			write_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) 			net_info_ratelimited("%s: Failed to add prefix route for address %pI6c; dropping\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) 					     idev->dev->name, &ifp->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) 	write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) static int addrconf_notify(struct notifier_block *this, unsigned long event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) 			   void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) 	struct netdev_notifier_change_info *change_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) 	struct netdev_notifier_changeupper_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) 	struct inet6_dev *idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) 	struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) 	int run_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) 	case NETDEV_REGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) 		if (!idev && dev->mtu >= IPV6_MIN_MTU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) 			idev = ipv6_add_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) 			if (IS_ERR(idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) 				return notifier_from_errno(PTR_ERR(idev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) 	case NETDEV_CHANGEMTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) 		/* if MTU under IPV6_MIN_MTU stop IPv6 on this interface. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) 		if (dev->mtu < IPV6_MIN_MTU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) 			addrconf_ifdown(dev, dev != net->loopback_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) 		if (idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) 			rt6_mtu_change(dev, dev->mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) 			idev->cnf.mtu6 = dev->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) 		/* allocate new idev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) 		idev = ipv6_add_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) 		if (IS_ERR(idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) 		/* device is still not ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) 		if (!(idev->if_flags & IF_READY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) 		run_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) 	case NETDEV_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) 	case NETDEV_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) 		if (dev->flags & IFF_SLAVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) 		if (idev && idev->cnf.disable_ipv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) 		if (event == NETDEV_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) 			/* restore routes for permanent addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) 			addrconf_permanent_addr(net, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) 			if (!addrconf_link_ready(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) 				/* device is not ready yet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) 				pr_debug("ADDRCONF(NETDEV_UP): %s: link is not ready\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) 					 dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) 			if (!idev && dev->mtu >= IPV6_MIN_MTU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 				idev = ipv6_add_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 			if (!IS_ERR_OR_NULL(idev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) 				idev->if_flags |= IF_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) 				run_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) 		} else if (event == NETDEV_CHANGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) 			if (!addrconf_link_ready(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 				/* device is still not ready. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) 				rt6_sync_down_dev(dev, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) 			if (!IS_ERR_OR_NULL(idev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) 				if (idev->if_flags & IF_READY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) 					/* device is already configured -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 					 * but resend MLD reports, we might
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) 					 * have roamed and need to update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 					 * multicast snooping switches
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) 					ipv6_mc_up(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) 					change_info = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) 					if (change_info->flags_changed & IFF_NOARP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) 						addrconf_dad_run(idev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) 					rt6_sync_up(dev, RTNH_F_LINKDOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 				idev->if_flags |= IF_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) 			pr_info("ADDRCONF(NETDEV_CHANGE): %s: link becomes ready\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) 				dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) 			run_pending = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) 		switch (dev->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) #if IS_ENABLED(CONFIG_IPV6_SIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) 		case ARPHRD_SIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 			addrconf_sit_config(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) #if IS_ENABLED(CONFIG_NET_IPGRE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) 		case ARPHRD_IPGRE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) 			addrconf_gre_config(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) 		case ARPHRD_LOOPBACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) 			init_loopback(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) 			addrconf_dev_config(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) 		if (!IS_ERR_OR_NULL(idev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) 			if (run_pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) 				addrconf_dad_run(idev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) 			/* Device has an address by now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) 			rt6_sync_up(dev, RTNH_F_DEAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) 			 * If the MTU changed during the interface down,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) 			 * when the interface up, the changed MTU must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) 			 * reflected in the idev as well as routers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) 			if (idev->cnf.mtu6 != dev->mtu &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) 			    dev->mtu >= IPV6_MIN_MTU) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) 				rt6_mtu_change(dev, dev->mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) 				idev->cnf.mtu6 = dev->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) 			idev->tstamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) 			inet6_ifinfo_notify(RTM_NEWLINK, idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) 			 * If the changed mtu during down is lower than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) 			 * IPV6_MIN_MTU stop IPv6 on this interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) 			if (dev->mtu < IPV6_MIN_MTU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) 				addrconf_ifdown(dev, dev != net->loopback_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) 	case NETDEV_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) 	case NETDEV_UNREGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) 		 *	Remove all addresses from this interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) 		addrconf_ifdown(dev, event != NETDEV_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) 	case NETDEV_CHANGENAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) 		if (idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 			snmp6_unregister_dev(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) 			addrconf_sysctl_unregister(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) 			err = addrconf_sysctl_register(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 				return notifier_from_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) 			err = snmp6_register_dev(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 			if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) 				addrconf_sysctl_unregister(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) 				return notifier_from_errno(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) 	case NETDEV_PRE_TYPE_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) 	case NETDEV_POST_TYPE_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) 		if (idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) 			addrconf_type_change(dev, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) 	case NETDEV_CHANGEUPPER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) 		info = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) 		/* flush all routes if dev is linked to or unlinked from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) 		 * an L3 master device (e.g., VRF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) 		if (info->upper_dev && netif_is_l3_master(info->upper_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) 			addrconf_ifdown(dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711)  *	addrconf module should be notified of a device going up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) static struct notifier_block ipv6_dev_notf = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) 	.notifier_call = addrconf_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) 	.priority = ADDRCONF_NOTIFY_PRIORITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) static void addrconf_type_change(struct net_device *dev, unsigned long event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) 	idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) 	if (event == NETDEV_POST_TYPE_CHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) 		ipv6_mc_remap(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) 	else if (event == NETDEV_PRE_TYPE_CHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) 		ipv6_mc_unmap(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) static bool addr_is_local(const struct in6_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 	return ipv6_addr_type(addr) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) 		(IPV6_ADDR_LINKLOCAL | IPV6_ADDR_LOOPBACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) static int addrconf_ifdown(struct net_device *dev, bool unregister)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) 	unsigned long event = unregister ? NETDEV_UNREGISTER : NETDEV_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) 	struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) 	struct inet6_ifaddr *ifa, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) 	bool keep_addr = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) 	bool was_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) 	int state, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) 	rt6_disable_ip(dev, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) 	idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) 	 * Step 1: remove reference to ipv6 device from parent device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) 	 *	   Do not dev_put!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) 	if (unregister) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) 		idev->dead = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) 		/* protected by rtnl_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) 		RCU_INIT_POINTER(dev->ip6_ptr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) 		/* Step 1.5: remove snmp6 entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) 		snmp6_unregister_dev(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) 	/* combine the user config with event to determine if permanent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) 	 * addresses are to be removed from address hash table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 	if (!unregister && !idev->cnf.disable_ipv6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) 		/* aggregate the system setting and interface setting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) 		int _keep_addr = net->ipv6.devconf_all->keep_addr_on_down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) 		if (!_keep_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) 			_keep_addr = idev->cnf.keep_addr_on_down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) 		keep_addr = (_keep_addr > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) 	/* Step 2: clear hash table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) 	for (i = 0; i < IN6_ADDR_HSIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) 		struct hlist_head *h = &inet6_addr_lst[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) 		spin_lock_bh(&addrconf_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) 		hlist_for_each_entry_rcu(ifa, h, addr_lst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) 			if (ifa->idev == idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) 				addrconf_del_dad_work(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) 				/* combined flag + permanent flag decide if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) 				 * address is retained on a down event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) 				if (!keep_addr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) 				    !(ifa->flags & IFA_F_PERMANENT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) 				    addr_is_local(&ifa->addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) 					hlist_del_init_rcu(&ifa->addr_lst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) 					goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) 		spin_unlock_bh(&addrconf_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) 	write_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) 	addrconf_del_rs_timer(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) 	/* Step 2: clear flags for stateless addrconf, repeated down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) 	 *         detection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) 	was_ready = idev->if_flags & IF_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) 	if (!unregister)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) 		idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) 	/* Step 3: clear tempaddr list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) 	while (!list_empty(&idev->tempaddr_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) 		ifa = list_first_entry(&idev->tempaddr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) 				       struct inet6_ifaddr, tmp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) 		list_del(&ifa->tmp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) 		write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) 		spin_lock_bh(&ifa->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) 		if (ifa->ifpub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) 			in6_ifa_put(ifa->ifpub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) 			ifa->ifpub = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) 		spin_unlock_bh(&ifa->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) 		in6_ifa_put(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) 		write_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 	list_for_each_entry_safe(ifa, tmp, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) 		struct fib6_info *rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) 		bool keep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) 		addrconf_del_dad_work(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) 		keep = keep_addr && (ifa->flags & IFA_F_PERMANENT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) 			!addr_is_local(&ifa->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) 		write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) 		spin_lock_bh(&ifa->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) 		if (keep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) 			/* set state to skip the notifier below */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) 			state = INET6_IFADDR_STATE_DEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) 			ifa->state = INET6_IFADDR_STATE_PREDAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) 			if (!(ifa->flags & IFA_F_NODAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) 				ifa->flags |= IFA_F_TENTATIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) 			rt = ifa->rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) 			ifa->rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) 			state = ifa->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) 			ifa->state = INET6_IFADDR_STATE_DEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) 		spin_unlock_bh(&ifa->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) 		if (rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) 			ip6_del_rt(net, rt, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) 		if (state != INET6_IFADDR_STATE_DEAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) 			__ipv6_ifa_notify(RTM_DELADDR, ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) 			inet6addr_notifier_call_chain(NETDEV_DOWN, ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) 			if (idev->cnf.forwarding)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) 				addrconf_leave_anycast(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) 			addrconf_leave_solict(ifa->idev, &ifa->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) 		write_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) 		if (!keep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) 			list_del_rcu(&ifa->if_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) 			in6_ifa_put(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) 	write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) 	/* Step 5: Discard anycast and multicast list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) 	if (unregister) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) 		ipv6_ac_destroy_dev(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) 		ipv6_mc_destroy_dev(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) 	} else if (was_ready) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) 		ipv6_mc_down(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 	idev->tstamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) 	/* Last: Shot the device (if unregistered) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) 	if (unregister) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) 		addrconf_sysctl_unregister(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) 		neigh_parms_release(&nd_tbl, idev->nd_parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) 		neigh_ifdown(&nd_tbl, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) 		in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) static void addrconf_rs_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) 	struct inet6_dev *idev = from_timer(idev, t, rs_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) 	struct net_device *dev = idev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) 	struct in6_addr lladdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) 	write_lock(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) 	if (idev->dead || !(idev->if_flags & IF_READY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) 	if (!ipv6_accept_ra(idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) 	/* Announcement received after solicitation was sent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) 	if (idev->if_flags & IF_RA_RCVD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) 	if (idev->rs_probes++ < idev->cnf.rtr_solicits || idev->cnf.rtr_solicits < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) 		write_unlock(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) 		if (!ipv6_get_lladdr(dev, &lladdr, IFA_F_TENTATIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) 			ndisc_send_rs(dev, &lladdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) 				      &in6addr_linklocal_allrouters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) 			goto put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) 		write_lock(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) 		idev->rs_interval = rfc3315_s14_backoff_update(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) 			idev->rs_interval, idev->cnf.rtr_solicit_max_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) 		/* The wait after the last probe can be shorter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) 		addrconf_mod_rs_timer(idev, (idev->rs_probes ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) 					     idev->cnf.rtr_solicits) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) 				      idev->cnf.rtr_solicit_delay :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) 				      idev->rs_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) 		 * Note: we do not support deprecated "all on-link"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) 		 * assumption any longer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) 		pr_debug("%s: no IPv6 routers present\n", idev->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) 	write_unlock(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) 	in6_dev_put(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951)  *	Duplicate Address Detection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) static void addrconf_dad_kick(struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) 	unsigned long rand_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) 	struct inet6_dev *idev = ifp->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) 	u64 nonce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) 	if (ifp->flags & IFA_F_OPTIMISTIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) 		rand_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) 		rand_num = prandom_u32() % (idev->cnf.rtr_solicit_delay ? : 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) 	nonce = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) 	if (idev->cnf.enhanced_dad ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) 	    dev_net(idev->dev)->ipv6.devconf_all->enhanced_dad) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) 		do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) 			get_random_bytes(&nonce, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) 		while (nonce == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) 	ifp->dad_nonce = nonce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) 	ifp->dad_probes = idev->cnf.dad_transmits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) 	addrconf_mod_dad_work(ifp, rand_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) static void addrconf_dad_begin(struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) 	struct inet6_dev *idev = ifp->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) 	struct net_device *dev = idev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) 	bool bump_id, notify = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) 	struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) 	addrconf_join_solict(dev, &ifp->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) 	prandom_seed((__force u32) ifp->addr.s6_addr32[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) 	read_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) 	spin_lock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) 	if (ifp->state == INET6_IFADDR_STATE_DEAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) 	net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) 	if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) 	    (net->ipv6.devconf_all->accept_dad < 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) 	     idev->cnf.accept_dad < 1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) 	    !(ifp->flags&IFA_F_TENTATIVE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) 	    ifp->flags & IFA_F_NODAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) 		bool send_na = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) 		if (ifp->flags & IFA_F_TENTATIVE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) 		    !(ifp->flags & IFA_F_OPTIMISTIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) 			send_na = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) 		bump_id = ifp->flags & IFA_F_TENTATIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) 		ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) 		spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) 		read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) 		addrconf_dad_completed(ifp, bump_id, send_na);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) 	if (!(idev->if_flags & IF_READY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) 		spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) 		read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) 		 * If the device is not ready:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) 		 * - keep it tentative if it is a permanent address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) 		 * - otherwise, kill it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) 		in6_ifa_hold(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) 		addrconf_dad_stop(ifp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) 	 * Optimistic nodes can start receiving
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) 	 * Frames right away
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) 	if (ifp->flags & IFA_F_OPTIMISTIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) 		ip6_ins_rt(net, ifp->rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) 		if (ipv6_use_optimistic_addr(net, idev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) 			/* Because optimistic nodes can use this address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) 			 * notify listeners. If DAD fails, RTM_DELADDR is sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) 			notify = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) 	addrconf_dad_kick(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) 	spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) 	read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) 	if (notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) 		ipv6_ifa_notify(RTM_NEWADDR, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) static void addrconf_dad_start(struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) 	bool begin_dad = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) 	spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) 	if (ifp->state != INET6_IFADDR_STATE_DEAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) 		ifp->state = INET6_IFADDR_STATE_PREDAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) 		begin_dad = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) 	spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) 	if (begin_dad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) 		addrconf_mod_dad_work(ifp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) static void addrconf_dad_work(struct work_struct *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) 	struct inet6_ifaddr *ifp = container_of(to_delayed_work(w),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) 						struct inet6_ifaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) 						dad_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) 	struct inet6_dev *idev = ifp->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) 	bool bump_id, disable_ipv6 = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) 	struct in6_addr mcaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) 	enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) 		DAD_PROCESS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) 		DAD_BEGIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) 		DAD_ABORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) 	} action = DAD_PROCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) 	spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) 	if (ifp->state == INET6_IFADDR_STATE_PREDAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) 		action = DAD_BEGIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) 		ifp->state = INET6_IFADDR_STATE_DAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) 	} else if (ifp->state == INET6_IFADDR_STATE_ERRDAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) 		action = DAD_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) 		ifp->state = INET6_IFADDR_STATE_POSTDAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) 		if ((dev_net(idev->dev)->ipv6.devconf_all->accept_dad > 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) 		     idev->cnf.accept_dad > 1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) 		    !idev->cnf.disable_ipv6 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) 		    !(ifp->flags & IFA_F_STABLE_PRIVACY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) 			struct in6_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) 			addr.s6_addr32[0] = htonl(0xfe800000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) 			addr.s6_addr32[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) 			if (!ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) 			    ipv6_addr_equal(&ifp->addr, &addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) 				/* DAD failed for link-local based on MAC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) 				idev->cnf.disable_ipv6 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) 				pr_info("%s: IPv6 being disabled!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) 					ifp->idev->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) 				disable_ipv6 = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) 	spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) 	if (action == DAD_BEGIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) 		addrconf_dad_begin(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) 	} else if (action == DAD_ABORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) 		in6_ifa_hold(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) 		addrconf_dad_stop(ifp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) 		if (disable_ipv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) 			addrconf_ifdown(idev->dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) 	if (!ifp->dad_probes && addrconf_dad_end(ifp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) 	write_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) 	if (idev->dead || !(idev->if_flags & IF_READY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) 		write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) 	spin_lock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) 	if (ifp->state == INET6_IFADDR_STATE_DEAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) 		spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) 		write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) 	if (ifp->dad_probes == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) 		bool send_na = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) 		 * DAD was successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) 		if (ifp->flags & IFA_F_TENTATIVE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) 		    !(ifp->flags & IFA_F_OPTIMISTIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) 			send_na = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) 		bump_id = ifp->flags & IFA_F_TENTATIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) 		ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) 		spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) 		write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) 		addrconf_dad_completed(ifp, bump_id, send_na);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) 	ifp->dad_probes--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) 	addrconf_mod_dad_work(ifp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) 			      max(NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) 				  HZ/100));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) 	spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) 	write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) 	/* send a neighbour solicitation for our addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) 	addrconf_addr_solict_mult(&ifp->addr, &mcaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) 	ndisc_send_ns(ifp->idev->dev, &ifp->addr, &mcaddr, &in6addr_any,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) 		      ifp->dad_nonce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) 	in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) /* ifp->idev must be at least read locked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) static bool ipv6_lonely_lladdr(struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) 	struct inet6_ifaddr *ifpiter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) 	struct inet6_dev *idev = ifp->idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) 	list_for_each_entry_reverse(ifpiter, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) 		if (ifpiter->scope > IFA_LINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) 		if (ifp != ifpiter && ifpiter->scope == IFA_LINK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) 		    (ifpiter->flags & (IFA_F_PERMANENT|IFA_F_TENTATIVE|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) 				       IFA_F_OPTIMISTIC|IFA_F_DADFAILED)) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) 		    IFA_F_PERMANENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) static void addrconf_dad_completed(struct inet6_ifaddr *ifp, bool bump_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) 				   bool send_na)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) 	struct net_device *dev = ifp->idev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) 	struct in6_addr lladdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) 	bool send_rs, send_mld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) 	addrconf_del_dad_work(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) 	 *	Configure the address for reception. Now it is valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) 	ipv6_ifa_notify(RTM_NEWADDR, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) 	/* If added prefix is link local and we are prepared to process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) 	   router advertisements, start sending router solicitations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) 	read_lock_bh(&ifp->idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) 	send_mld = ifp->scope == IFA_LINK && ipv6_lonely_lladdr(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) 	send_rs = send_mld &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) 		  ipv6_accept_ra(ifp->idev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) 		  ifp->idev->cnf.rtr_solicits != 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) 		  (dev->flags&IFF_LOOPBACK) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) 	read_unlock_bh(&ifp->idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) 	/* While dad is in progress mld report's source address is in6_addrany.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) 	 * Resend with proper ll now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) 	if (send_mld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) 		ipv6_mc_dad_complete(ifp->idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) 	/* send unsolicited NA if enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) 	if (send_na &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) 	    (ifp->idev->cnf.ndisc_notify ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) 	     dev_net(dev)->ipv6.devconf_all->ndisc_notify)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) 		ndisc_send_na(dev, &in6addr_linklocal_allnodes, &ifp->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) 			      /*router=*/ !!ifp->idev->cnf.forwarding,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) 			      /*solicited=*/ false, /*override=*/ true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) 			      /*inc_opt=*/ true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) 	if (send_rs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) 		 *	If a host as already performed a random delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) 		 *	[...] as part of DAD [...] there is no need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) 		 *	to delay again before sending the first RS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) 		if (ipv6_get_lladdr(dev, &lladdr, IFA_F_TENTATIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) 		ndisc_send_rs(dev, &lladdr, &in6addr_linklocal_allrouters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) 		write_lock_bh(&ifp->idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) 		spin_lock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) 		ifp->idev->rs_interval = rfc3315_s14_backoff_init(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) 			ifp->idev->cnf.rtr_solicit_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) 		ifp->idev->rs_probes = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) 		ifp->idev->if_flags |= IF_RS_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) 		addrconf_mod_rs_timer(ifp->idev, ifp->idev->rs_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) 		spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) 		write_unlock_bh(&ifp->idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) 	if (bump_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) 		rt_genid_bump_ipv6(dev_net(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) 	/* Make sure that a new temporary address will be created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) 	 * before this temporary address becomes deprecated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) 	if (ifp->flags & IFA_F_TEMPORARY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) 		addrconf_verify_rtnl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) static void addrconf_dad_run(struct inet6_dev *idev, bool restart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) 	read_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) 	list_for_each_entry(ifp, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) 		spin_lock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) 		if ((ifp->flags & IFA_F_TENTATIVE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) 		     ifp->state == INET6_IFADDR_STATE_DAD) || restart) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) 			if (restart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) 				ifp->state = INET6_IFADDR_STATE_PREDAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) 			addrconf_dad_kick(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) 		spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) 	read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) struct if6_iter_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) 	struct seq_net_private p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) 	int bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) 	int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) static struct inet6_ifaddr *if6_get_first(struct seq_file *seq, loff_t pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) 	struct if6_iter_state *state = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) 	struct net *net = seq_file_net(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) 	struct inet6_ifaddr *ifa = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) 	int p = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) 	/* initial bucket if pos is 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) 	if (pos == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) 		state->bucket = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) 		state->offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) 	for (; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) 		hlist_for_each_entry_rcu(ifa, &inet6_addr_lst[state->bucket],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) 					 addr_lst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) 			if (!net_eq(dev_net(ifa->idev->dev), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) 			/* sync with offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) 			if (p < state->offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) 				p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) 			return ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) 		/* prepare for next bucket */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) 		state->offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) 		p = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) static struct inet6_ifaddr *if6_get_next(struct seq_file *seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) 					 struct inet6_ifaddr *ifa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) 	struct if6_iter_state *state = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) 	struct net *net = seq_file_net(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) 	hlist_for_each_entry_continue_rcu(ifa, addr_lst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) 		if (!net_eq(dev_net(ifa->idev->dev), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) 		state->offset++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) 		return ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) 	state->offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) 	while (++state->bucket < IN6_ADDR_HSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) 		hlist_for_each_entry_rcu(ifa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) 				     &inet6_addr_lst[state->bucket], addr_lst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) 			if (!net_eq(dev_net(ifa->idev->dev), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) 			return ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) static void *if6_seq_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) 	__acquires(rcu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) 	return if6_get_first(seq, *pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) static void *if6_seq_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) 	struct inet6_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) 	ifa = if6_get_next(seq, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) 	return ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) static void if6_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) 	__releases(rcu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) static int if6_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) 	struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) 	seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) 		   &ifp->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) 		   ifp->idev->dev->ifindex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) 		   ifp->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) 		   ifp->scope,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) 		   (u8) ifp->flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) 		   ifp->idev->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) static const struct seq_operations if6_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) 	.start	= if6_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) 	.next	= if6_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) 	.show	= if6_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) 	.stop	= if6_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) static int __net_init if6_proc_net_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) 	if (!proc_create_net("if_inet6", 0444, net->proc_net, &if6_seq_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) 			sizeof(struct if6_iter_state)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) static void __net_exit if6_proc_net_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) 	remove_proc_entry("if_inet6", net->proc_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) static struct pernet_operations if6_proc_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) 	.init = if6_proc_net_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) 	.exit = if6_proc_net_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) int __init if6_proc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) 	return register_pernet_subsys(&if6_proc_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) void if6_proc_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) 	unregister_pernet_subsys(&if6_proc_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) #endif	/* CONFIG_PROC_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) #if IS_ENABLED(CONFIG_IPV6_MIP6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) /* Check if address is a home address configured on any interface. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) int ipv6_chk_home_addr(struct net *net, const struct in6_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) 	unsigned int hash = inet6_addr_hash(net, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) 	struct inet6_ifaddr *ifp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) 	hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) 		if (!net_eq(dev_net(ifp->idev->dev), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) 		if (ipv6_addr_equal(&ifp->addr, addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) 		    (ifp->flags & IFA_F_HOMEADDRESS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) 			ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) /* RFC6554 has some algorithm to avoid loops in segment routing by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443)  * checking if the segments contains any of a local interface address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445)  * Quote:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447)  * To detect loops in the SRH, a router MUST determine if the SRH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448)  * includes multiple addresses assigned to any interface on that router.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449)  * If such addresses appear more than once and are separated by at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450)  * one address not assigned to that router.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) int ipv6_chk_rpl_srh_loop(struct net *net, const struct in6_addr *segs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) 			  unsigned char nsegs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) 	const struct in6_addr *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) 	int i, ret = 0, found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) 	bool separated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) 	unsigned int hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) 	bool hash_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) 	for (i = 0; i < nsegs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) 		addr = &segs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) 		hash = inet6_addr_hash(net, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) 		hash_found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) 		hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) 			if (!net_eq(dev_net(ifp->idev->dev), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) 			if (ipv6_addr_equal(&ifp->addr, addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) 				hash_found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) 		if (hash_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) 			if (found > 1 && separated) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) 				ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) 			separated = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) 			found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) 			separated = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496)  *	Periodic address status verification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) static void addrconf_verify_rtnl(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) 	unsigned long now, next, next_sec, next_sched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) 	rcu_read_lock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) 	now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) 	next = round_jiffies_up(now + ADDR_CHECK_FREQUENCY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) 	cancel_delayed_work(&addr_chk_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) 	for (i = 0; i < IN6_ADDR_HSIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) 		hlist_for_each_entry_rcu_bh(ifp, &inet6_addr_lst[i], addr_lst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) 			unsigned long age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) 			/* When setting preferred_lft to a value not zero or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) 			 * infinity, while valid_lft is infinity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520) 			 * IFA_F_PERMANENT has a non-infinity life time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) 			if ((ifp->flags & IFA_F_PERMANENT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) 			    (ifp->prefered_lft == INFINITY_LIFE_TIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) 			spin_lock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) 			/* We try to batch several events at once. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) 			age = (now - ifp->tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530) 			if (ifp->valid_lft != INFINITY_LIFE_TIME &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) 			    age >= ifp->valid_lft) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) 				spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) 				in6_ifa_hold(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) 				ipv6_del_addr(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) 				goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) 			} else if (ifp->prefered_lft == INFINITY_LIFE_TIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) 				spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) 			} else if (age >= ifp->prefered_lft) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) 				/* jiffies - ifp->tstamp > age >= ifp->prefered_lft */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) 				int deprecate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) 				if (!(ifp->flags&IFA_F_DEPRECATED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) 					deprecate = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) 					ifp->flags |= IFA_F_DEPRECATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) 				if ((ifp->valid_lft != INFINITY_LIFE_TIME) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) 				    (time_before(ifp->tstamp + ifp->valid_lft * HZ, next)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) 					next = ifp->tstamp + ifp->valid_lft * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) 				spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) 				if (deprecate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) 					in6_ifa_hold(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) 					ipv6_ifa_notify(0, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) 					in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) 					goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) 			} else if ((ifp->flags&IFA_F_TEMPORARY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) 				   !(ifp->flags&IFA_F_TENTATIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) 				unsigned long regen_advance = ifp->idev->cnf.regen_max_retry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) 					ifp->idev->cnf.dad_transmits *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) 					max(NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME), HZ/100) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) 				if (age >= ifp->prefered_lft - regen_advance) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) 					struct inet6_ifaddr *ifpub = ifp->ifpub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) 					if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) 						next = ifp->tstamp + ifp->prefered_lft * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) 					if (!ifp->regen_count && ifpub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) 						ifp->regen_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) 						in6_ifa_hold(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) 						in6_ifa_hold(ifpub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) 						spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) 						spin_lock(&ifpub->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) 						ifpub->regen_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) 						spin_unlock(&ifpub->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) 						rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) 						ipv6_create_tempaddr(ifpub, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) 						in6_ifa_put(ifpub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) 						in6_ifa_put(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) 						rcu_read_lock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) 						goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) 				} else if (time_before(ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ, next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) 					next = ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) 				spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) 				/* ifp->prefered_lft <= ifp->valid_lft */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) 				if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) 					next = ifp->tstamp + ifp->prefered_lft * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) 				spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) 	next_sec = round_jiffies_up(next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) 	next_sched = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) 	/* If rounded timeout is accurate enough, accept it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) 	if (time_before(next_sec, next + ADDRCONF_TIMER_FUZZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) 		next_sched = next_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) 	/* And minimum interval is ADDRCONF_TIMER_FUZZ_MAX. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) 	if (time_before(next_sched, jiffies + ADDRCONF_TIMER_FUZZ_MAX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) 		next_sched = jiffies + ADDRCONF_TIMER_FUZZ_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) 	pr_debug("now = %lu, schedule = %lu, rounded schedule = %lu => %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) 		 now, next, next_sec, next_sched);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) 	mod_delayed_work(addrconf_wq, &addr_chk_work, next_sched - now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) 	rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) static void addrconf_verify_work(struct work_struct *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) 	addrconf_verify_rtnl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) static void addrconf_verify(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) 	mod_delayed_work(addrconf_wq, &addr_chk_work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) 				     struct in6_addr **peer_pfx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) 	struct in6_addr *pfx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) 	*peer_pfx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) 	if (addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) 		pfx = nla_data(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) 	if (local) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) 		if (pfx && nla_memcmp(local, pfx, sizeof(*pfx)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) 			*peer_pfx = pfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) 		pfx = nla_data(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) 	return pfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) static const struct nla_policy ifa_ipv6_policy[IFA_MAX+1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) 	[IFA_ADDRESS]		= { .len = sizeof(struct in6_addr) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) 	[IFA_LOCAL]		= { .len = sizeof(struct in6_addr) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) 	[IFA_CACHEINFO]		= { .len = sizeof(struct ifa_cacheinfo) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) 	[IFA_FLAGS]		= { .len = sizeof(u32) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) 	[IFA_RT_PRIORITY]	= { .len = sizeof(u32) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) 	[IFA_TARGET_NETNSID]	= { .type = NLA_S32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) 		  struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) 	struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) 	struct ifaddrmsg *ifm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) 	struct nlattr *tb[IFA_MAX+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) 	struct in6_addr *pfx, *peer_pfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) 	u32 ifa_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) 	err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) 				     ifa_ipv6_policy, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) 	ifm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) 	pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer_pfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) 	if (!pfx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) 	ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) 	/* We ignore other flags so far. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) 	ifa_flags &= IFA_F_MANAGETEMPADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) 	return inet6_addr_del(net, ifm->ifa_index, ifa_flags, pfx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) 			      ifm->ifa_prefixlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) static int modify_prefix_route(struct inet6_ifaddr *ifp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) 			       unsigned long expires, u32 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) 			       bool modify_peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690) 	struct fib6_info *f6i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) 	u32 prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693) 	f6i = addrconf_get_prefix_route(modify_peer ? &ifp->peer_addr : &ifp->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694) 					ifp->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) 					ifp->idev->dev, 0, RTF_DEFAULT, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) 	if (!f6i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) 	prio = ifp->rt_priority ? : IP6_RT_PRIO_ADDRCONF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) 	if (f6i->fib6_metric != prio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701) 		/* delete old one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) 		ip6_del_rt(dev_net(ifp->idev->dev), f6i, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) 		/* add new one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) 		addrconf_prefix_route(modify_peer ? &ifp->peer_addr : &ifp->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) 				      ifp->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) 				      ifp->rt_priority, ifp->idev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) 				      expires, flags, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) 		if (!expires)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) 			fib6_clean_expires(f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) 			fib6_set_expires(f6i, expires);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) 		fib6_info_release(f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) static int inet6_addr_modify(struct inet6_ifaddr *ifp, struct ifa6_config *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) 	u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) 	clock_t expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) 	unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) 	bool was_managetempaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) 	bool had_prefixroute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) 	bool new_peer = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) 	if (!cfg->valid_lft || cfg->preferred_lft > cfg->valid_lft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) 	if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) 	    (ifp->flags & IFA_F_TEMPORARY || ifp->prefix_len != 64))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) 	if (!(ifp->flags & IFA_F_TENTATIVE) || ifp->flags & IFA_F_DADFAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) 		cfg->ifa_flags &= ~IFA_F_OPTIMISTIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) 	timeout = addrconf_timeout_fixup(cfg->valid_lft, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) 	if (addrconf_finite_timeout(timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) 		expires = jiffies_to_clock_t(timeout * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) 		cfg->valid_lft = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) 		flags = RTF_EXPIRES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) 		expires = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) 		flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) 		cfg->ifa_flags |= IFA_F_PERMANENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) 	timeout = addrconf_timeout_fixup(cfg->preferred_lft, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) 	if (addrconf_finite_timeout(timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) 		if (timeout == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) 			cfg->ifa_flags |= IFA_F_DEPRECATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) 		cfg->preferred_lft = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) 	if (cfg->peer_pfx &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) 	    memcmp(&ifp->peer_addr, cfg->peer_pfx, sizeof(struct in6_addr))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) 		if (!ipv6_addr_any(&ifp->peer_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) 			cleanup_prefix_route(ifp, expires, true, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) 		new_peer = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) 	spin_lock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) 	was_managetempaddr = ifp->flags & IFA_F_MANAGETEMPADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) 	had_prefixroute = ifp->flags & IFA_F_PERMANENT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) 			  !(ifp->flags & IFA_F_NOPREFIXROUTE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) 	ifp->flags &= ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) 			IFA_F_HOMEADDRESS | IFA_F_MANAGETEMPADDR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) 			IFA_F_NOPREFIXROUTE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) 	ifp->flags |= cfg->ifa_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) 	ifp->tstamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) 	ifp->valid_lft = cfg->valid_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) 	ifp->prefered_lft = cfg->preferred_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) 	if (cfg->rt_priority && cfg->rt_priority != ifp->rt_priority)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) 		ifp->rt_priority = cfg->rt_priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) 	if (new_peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) 		ifp->peer_addr = *cfg->peer_pfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) 	spin_unlock_bh(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786) 	if (!(ifp->flags&IFA_F_TENTATIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) 		ipv6_ifa_notify(0, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) 	if (!(cfg->ifa_flags & IFA_F_NOPREFIXROUTE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) 		int rc = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792) 		if (had_prefixroute)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) 			rc = modify_prefix_route(ifp, expires, flags, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) 		/* prefix route could have been deleted; if so restore it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) 		if (rc == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) 			addrconf_prefix_route(&ifp->addr, ifp->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) 					      ifp->rt_priority, ifp->idev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) 					      expires, flags, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) 		if (had_prefixroute && !ipv6_addr_any(&ifp->peer_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) 			rc = modify_prefix_route(ifp, expires, flags, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) 		if (rc == -ENOENT && !ipv6_addr_any(&ifp->peer_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) 			addrconf_prefix_route(&ifp->peer_addr, ifp->prefix_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) 					      ifp->rt_priority, ifp->idev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) 					      expires, flags, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) 	} else if (had_prefixroute) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) 		enum cleanup_prefix_rt_t action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) 		unsigned long rt_expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) 		write_lock_bh(&ifp->idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) 		action = check_cleanup_prefix_route(ifp, &rt_expires);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) 		write_unlock_bh(&ifp->idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) 		if (action != CLEANUP_PREFIX_RT_NOP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) 			cleanup_prefix_route(ifp, rt_expires,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) 				action == CLEANUP_PREFIX_RT_DEL, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) 	if (was_managetempaddr || ifp->flags & IFA_F_MANAGETEMPADDR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) 		if (was_managetempaddr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) 		    !(ifp->flags & IFA_F_MANAGETEMPADDR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) 			cfg->valid_lft = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828) 			cfg->preferred_lft = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) 		manage_tempaddrs(ifp->idev, ifp, cfg->valid_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) 				 cfg->preferred_lft, !was_managetempaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) 				 jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) 	addrconf_verify_rtnl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) 		  struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844) 	struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) 	struct ifaddrmsg *ifm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) 	struct nlattr *tb[IFA_MAX+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) 	struct in6_addr *peer_pfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848) 	struct inet6_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) 	struct ifa6_config cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) 	err = nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) 				     ifa_ipv6_policy, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) 	memset(&cfg, 0, sizeof(cfg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) 	ifm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) 	cfg.pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer_pfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) 	if (!cfg.pfx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) 	cfg.peer_pfx = peer_pfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) 	cfg.plen = ifm->ifa_prefixlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) 	if (tb[IFA_RT_PRIORITY])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) 		cfg.rt_priority = nla_get_u32(tb[IFA_RT_PRIORITY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) 	cfg.valid_lft = INFINITY_LIFE_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) 	cfg.preferred_lft = INFINITY_LIFE_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) 	if (tb[IFA_CACHEINFO]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) 		struct ifa_cacheinfo *ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) 		ci = nla_data(tb[IFA_CACHEINFO]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) 		cfg.valid_lft = ci->ifa_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) 		cfg.preferred_lft = ci->ifa_prefered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) 	dev =  __dev_get_by_index(net, ifm->ifa_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) 	if (tb[IFA_FLAGS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) 		cfg.ifa_flags = nla_get_u32(tb[IFA_FLAGS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) 		cfg.ifa_flags = ifm->ifa_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) 	/* We ignore other flags so far. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) 	cfg.ifa_flags &= IFA_F_NODAD | IFA_F_HOMEADDRESS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) 			 IFA_F_MANAGETEMPADDR | IFA_F_NOPREFIXROUTE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) 			 IFA_F_MCAUTOJOIN | IFA_F_OPTIMISTIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) 	idev = ipv6_find_idev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) 	if (IS_ERR(idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) 		return PTR_ERR(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) 	if (!ipv6_allow_optimistic_dad(net, idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) 		cfg.ifa_flags &= ~IFA_F_OPTIMISTIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) 	if (cfg.ifa_flags & IFA_F_NODAD &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) 	    cfg.ifa_flags & IFA_F_OPTIMISTIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) 		NL_SET_ERR_MSG(extack, "IFA_F_NODAD and IFA_F_OPTIMISTIC are mutually exclusive");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) 	ifa = ipv6_get_ifaddr(net, cfg.pfx, dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) 	if (!ifa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) 		 * It would be best to check for !NLM_F_CREATE here but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) 		 * userspace already relies on not having to provide this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) 		return inet6_addr_add(net, ifm->ifa_index, &cfg, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) 	if (nlh->nlmsg_flags & NLM_F_EXCL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) 	    !(nlh->nlmsg_flags & NLM_F_REPLACE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) 		err = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922) 		err = inet6_addr_modify(ifa, &cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) 	in6_ifa_put(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929) static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u32 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930) 			  u8 scope, int ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) 	struct ifaddrmsg *ifm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934) 	ifm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) 	ifm->ifa_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936) 	ifm->ifa_prefixlen = prefixlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937) 	ifm->ifa_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938) 	ifm->ifa_scope = scope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939) 	ifm->ifa_index = ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) static int put_cacheinfo(struct sk_buff *skb, unsigned long cstamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943) 			 unsigned long tstamp, u32 preferred, u32 valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) 	struct ifa_cacheinfo ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) 	ci.cstamp = cstamp_delta(cstamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948) 	ci.tstamp = cstamp_delta(tstamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) 	ci.ifa_prefered = preferred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) 	ci.ifa_valid = valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) 	return nla_put(skb, IFA_CACHEINFO, sizeof(ci), &ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) static inline int rt_scope(int ifa_scope)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957) 	if (ifa_scope & IFA_HOST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958) 		return RT_SCOPE_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) 	else if (ifa_scope & IFA_LINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960) 		return RT_SCOPE_LINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961) 	else if (ifa_scope & IFA_SITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) 		return RT_SCOPE_SITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964) 		return RT_SCOPE_UNIVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967) static inline int inet6_ifaddr_msgsize(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969) 	return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) 	       + nla_total_size(16) /* IFA_LOCAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) 	       + nla_total_size(16) /* IFA_ADDRESS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) 	       + nla_total_size(sizeof(struct ifa_cacheinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973) 	       + nla_total_size(4)  /* IFA_FLAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) 	       + nla_total_size(4)  /* IFA_RT_PRIORITY */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) enum addr_type_t {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) 	UNICAST_ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) 	MULTICAST_ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) 	ANYCAST_ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983) struct inet6_fill_args {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) 	u32 portid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) 	u32 seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) 	int event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987) 	unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) 	int netnsid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989) 	int ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) 	enum addr_type_t type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) 			     struct inet6_fill_args *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) 	struct nlmsghdr  *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997) 	u32 preferred, valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) 	nlh = nlmsg_put(skb, args->portid, args->seq, args->event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000) 			sizeof(struct ifaddrmsg), args->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) 	if (!nlh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) 	put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005) 		      ifa->idev->dev->ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) 	if (args->netnsid >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008) 	    nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) 	spin_lock_bh(&ifa->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012) 	if (!((ifa->flags&IFA_F_PERMANENT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) 	      (ifa->prefered_lft == INFINITY_LIFE_TIME))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) 		preferred = ifa->prefered_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) 		valid = ifa->valid_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) 		if (preferred != INFINITY_LIFE_TIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) 			long tval = (jiffies - ifa->tstamp)/HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) 			if (preferred > tval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) 				preferred -= tval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021) 				preferred = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) 			if (valid != INFINITY_LIFE_TIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) 				if (valid > tval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) 					valid -= tval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) 					valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) 		preferred = INFINITY_LIFE_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) 		valid = INFINITY_LIFE_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) 	spin_unlock_bh(&ifa->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) 	if (!ipv6_addr_any(&ifa->peer_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036) 		if (nla_put_in6_addr(skb, IFA_LOCAL, &ifa->addr) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) 		    nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->peer_addr) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) 		if (nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->addr) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) 	if (ifa->rt_priority &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) 	    nla_put_u32(skb, IFA_RT_PRIORITY, ifa->rt_priority))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) 	if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050) 	if (nla_put_u32(skb, IFA_FLAGS, ifa->flags) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053) 	nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) 	nlmsg_cancel(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061) static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) 			       struct inet6_fill_args *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064) 	struct nlmsghdr  *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) 	u8 scope = RT_SCOPE_UNIVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066) 	int ifindex = ifmca->idev->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068) 	if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) 		scope = RT_SCOPE_SITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) 	nlh = nlmsg_put(skb, args->portid, args->seq, args->event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072) 			sizeof(struct ifaddrmsg), args->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) 	if (!nlh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) 	if (args->netnsid >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) 	    nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078) 		nlmsg_cancel(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) 	put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083) 	if (nla_put_in6_addr(skb, IFA_MULTICAST, &ifmca->mca_addr) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) 	    put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085) 			  INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) 		nlmsg_cancel(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090) 	nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) 			       struct inet6_fill_args *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) 	struct net_device *dev = fib6_info_nh_dev(ifaca->aca_rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098) 	int ifindex = dev ? dev->ifindex : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) 	struct nlmsghdr  *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100) 	u8 scope = RT_SCOPE_UNIVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) 	if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) 		scope = RT_SCOPE_SITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) 	nlh = nlmsg_put(skb, args->portid, args->seq, args->event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106) 			sizeof(struct ifaddrmsg), args->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) 	if (!nlh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110) 	if (args->netnsid >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111) 	    nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112) 		nlmsg_cancel(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) 	put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117) 	if (nla_put_in6_addr(skb, IFA_ANYCAST, &ifaca->aca_addr) < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) 	    put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119) 			  INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) 		nlmsg_cancel(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124) 	nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128) /* called with rcu_read_lock() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129) static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) 			  struct netlink_callback *cb, int s_ip_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) 			  struct inet6_fill_args *fillargs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) 	struct ifmcaddr6 *ifmca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134) 	struct ifacaddr6 *ifaca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135) 	int ip_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136) 	int err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138) 	read_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139) 	switch (fillargs->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140) 	case UNICAST_ADDR: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141) 		struct inet6_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142) 		fillargs->event = RTM_NEWADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144) 		/* unicast address incl. temp addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145) 		list_for_each_entry(ifa, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146) 			if (ip_idx < s_ip_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147) 				goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148) 			err = inet6_fill_ifaddr(skb, ifa, fillargs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) 			nl_dump_check_consistent(cb, nlmsg_hdr(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) 			ip_idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) 	case MULTICAST_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) 		fillargs->event = RTM_GETMULTICAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160) 		/* multicast address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) 		for (ifmca = idev->mc_list; ifmca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) 		     ifmca = ifmca->next, ip_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163) 			if (ip_idx < s_ip_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) 			err = inet6_fill_ifmcaddr(skb, ifmca, fillargs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170) 	case ANYCAST_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) 		fillargs->event = RTM_GETANYCAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172) 		/* anycast address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173) 		for (ifaca = idev->ac_list; ifaca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174) 		     ifaca = ifaca->aca_next, ip_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175) 			if (ip_idx < s_ip_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177) 			err = inet6_fill_ifacaddr(skb, ifaca, fillargs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) 	read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186) 	cb->args[2] = ip_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190) static int inet6_valid_dump_ifaddr_req(const struct nlmsghdr *nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) 				       struct inet6_fill_args *fillargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) 				       struct net **tgt_net, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) 				       struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) 	struct netlink_ext_ack *extack = cb->extack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) 	struct nlattr *tb[IFA_MAX+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197) 	struct ifaddrmsg *ifm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198) 	int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200) 	if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201) 		NL_SET_ERR_MSG_MOD(extack, "Invalid header for address dump request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205) 	ifm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206) 	if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207) 		NL_SET_ERR_MSG_MOD(extack, "Invalid values in header for address dump request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211) 	fillargs->ifindex = ifm->ifa_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212) 	if (fillargs->ifindex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) 		cb->answer_flags |= NLM_F_DUMP_FILTERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) 		fillargs->flags |= NLM_F_DUMP_FILTERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217) 	err = nlmsg_parse_deprecated_strict(nlh, sizeof(*ifm), tb, IFA_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) 					    ifa_ipv6_policy, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) 	for (i = 0; i <= IFA_MAX; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223) 		if (!tb[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226) 		if (i == IFA_TARGET_NETNSID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227) 			struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229) 			fillargs->netnsid = nla_get_s32(tb[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230) 			net = rtnl_get_net_ns_capable(sk, fillargs->netnsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231) 			if (IS_ERR(net)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) 				fillargs->netnsid = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) 				NL_SET_ERR_MSG_MOD(extack, "Invalid target network namespace id");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234) 				return PTR_ERR(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236) 			*tgt_net = net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238) 			NL_SET_ERR_MSG_MOD(extack, "Unsupported attribute in dump request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) 			   enum addr_type_t type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249) 	const struct nlmsghdr *nlh = cb->nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250) 	struct inet6_fill_args fillargs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251) 		.portid = NETLINK_CB(cb->skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252) 		.seq = cb->nlh->nlmsg_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253) 		.flags = NLM_F_MULTI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254) 		.netnsid = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255) 		.type = type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257) 	struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258) 	struct net *tgt_net = net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259) 	int idx, s_idx, s_ip_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260) 	int h, s_h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263) 	struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) 	s_h = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267) 	s_idx = idx = cb->args[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) 	s_ip_idx = cb->args[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270) 	if (cb->strict_check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271) 		err = inet6_valid_dump_ifaddr_req(nlh, &fillargs, &tgt_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) 						  skb->sk, cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) 			goto put_tgt_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) 		err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277) 		if (fillargs.ifindex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278) 			dev = __dev_get_by_index(tgt_net, fillargs.ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279) 			if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280) 				err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281) 				goto put_tgt_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283) 			idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284) 			if (idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285) 				err = in6_dump_addrs(idev, skb, cb, s_ip_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286) 						     &fillargs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287) 				if (err > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288) 					err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290) 			goto put_tgt_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) 	cb->seq = atomic_read(&tgt_net->ipv6.dev_addr_genid) ^ tgt_net->dev_base_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) 	for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297) 		idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) 		head = &tgt_net->dev_index_head[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299) 		hlist_for_each_entry_rcu(dev, head, index_hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300) 			if (idx < s_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301) 				goto cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302) 			if (h > s_h || idx > s_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303) 				s_ip_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304) 			idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305) 			if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306) 				goto cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308) 			if (in6_dump_addrs(idev, skb, cb, s_ip_idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309) 					   &fillargs) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310) 				goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311) cont:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312) 			idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) 	cb->args[0] = h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) 	cb->args[1] = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319) put_tgt_net:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) 	if (fillargs.netnsid >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321) 		put_net(tgt_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) 	return skb->len ? : err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) static int inet6_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) 	enum addr_type_t type = UNICAST_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330) 	return inet6_dump_addr(skb, cb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) static int inet6_dump_ifmcaddr(struct sk_buff *skb, struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335) 	enum addr_type_t type = MULTICAST_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337) 	return inet6_dump_addr(skb, cb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341) static int inet6_dump_ifacaddr(struct sk_buff *skb, struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343) 	enum addr_type_t type = ANYCAST_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345) 	return inet6_dump_addr(skb, cb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) static int inet6_rtm_valid_getaddr_req(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) 				       const struct nlmsghdr *nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350) 				       struct nlattr **tb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351) 				       struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353) 	struct ifaddrmsg *ifm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) 	if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) 		NL_SET_ERR_MSG_MOD(extack, "Invalid header for get address request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361) 	if (!netlink_strict_get_check(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362) 		return nlmsg_parse_deprecated(nlh, sizeof(*ifm), tb, IFA_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363) 					      ifa_ipv6_policy, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365) 	ifm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366) 	if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367) 		NL_SET_ERR_MSG_MOD(extack, "Invalid values in header for get address request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371) 	err = nlmsg_parse_deprecated_strict(nlh, sizeof(*ifm), tb, IFA_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372) 					    ifa_ipv6_policy, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376) 	for (i = 0; i <= IFA_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377) 		if (!tb[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380) 		switch (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381) 		case IFA_TARGET_NETNSID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) 		case IFA_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383) 		case IFA_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386) 			NL_SET_ERR_MSG_MOD(extack, "Unsupported attribute in get address request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr *nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) 			     struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397) 	struct net *net = sock_net(in_skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) 	struct inet6_fill_args fillargs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) 		.portid = NETLINK_CB(in_skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400) 		.seq = nlh->nlmsg_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401) 		.event = RTM_NEWADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402) 		.flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) 		.netnsid = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405) 	struct net *tgt_net = net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) 	struct ifaddrmsg *ifm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) 	struct nlattr *tb[IFA_MAX+1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408) 	struct in6_addr *addr = NULL, *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) 	struct net_device *dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410) 	struct inet6_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414) 	err = inet6_rtm_valid_getaddr_req(in_skb, nlh, tb, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418) 	if (tb[IFA_TARGET_NETNSID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) 		fillargs.netnsid = nla_get_s32(tb[IFA_TARGET_NETNSID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421) 		tgt_net = rtnl_get_net_ns_capable(NETLINK_CB(in_skb).sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) 						  fillargs.netnsid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) 		if (IS_ERR(tgt_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424) 			return PTR_ERR(tgt_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427) 	addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) 	if (!addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) 	ifm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) 	if (ifm->ifa_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433) 		dev = dev_get_by_index(tgt_net, ifm->ifa_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) 	ifa = ipv6_get_ifaddr(tgt_net, addr, dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436) 	if (!ifa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437) 		err = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) 	skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442) 	if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) 		err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444) 		goto errout_ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447) 	err = inet6_fill_ifaddr(skb, ifa, &fillargs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449) 		/* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450) 		WARN_ON(err == -EMSGSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) 		goto errout_ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) 	err = rtnl_unicast(skb, tgt_net, NETLINK_CB(in_skb).portid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455) errout_ifa:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) 	in6_ifa_put(ifa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) 	if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459) 		dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) 	if (fillargs.netnsid >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461) 		put_net(tgt_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466) static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469) 	struct net *net = dev_net(ifa->idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470) 	struct inet6_fill_args fillargs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471) 		.portid = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472) 		.seq = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473) 		.event = event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474) 		.flags = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475) 		.netnsid = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) 	int err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) 	skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) 	err = inet6_fill_ifaddr(skb, ifa, &fillargs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485) 		/* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) 		WARN_ON(err == -EMSGSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) 	rtnl_notify(skb, net, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494) 		rtnl_set_sk_err(net, RTNLGRP_IPV6_IFADDR, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497) static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498) 				__s32 *array, int bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500) 	BUG_ON(bytes < (DEVCONF_MAX * 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502) 	memset(array, 0, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503) 	array[DEVCONF_FORWARDING] = cnf->forwarding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504) 	array[DEVCONF_HOPLIMIT] = cnf->hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505) 	array[DEVCONF_MTU6] = cnf->mtu6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506) 	array[DEVCONF_ACCEPT_RA] = cnf->accept_ra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) 	array[DEVCONF_ACCEPT_REDIRECTS] = cnf->accept_redirects;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5508) 	array[DEVCONF_AUTOCONF] = cnf->autoconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5509) 	array[DEVCONF_DAD_TRANSMITS] = cnf->dad_transmits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5510) 	array[DEVCONF_RTR_SOLICITS] = cnf->rtr_solicits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5511) 	array[DEVCONF_RTR_SOLICIT_INTERVAL] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5512) 		jiffies_to_msecs(cnf->rtr_solicit_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5513) 	array[DEVCONF_RTR_SOLICIT_MAX_INTERVAL] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5514) 		jiffies_to_msecs(cnf->rtr_solicit_max_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5515) 	array[DEVCONF_RTR_SOLICIT_DELAY] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5516) 		jiffies_to_msecs(cnf->rtr_solicit_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5517) 	array[DEVCONF_FORCE_MLD_VERSION] = cnf->force_mld_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5518) 	array[DEVCONF_MLDV1_UNSOLICITED_REPORT_INTERVAL] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5519) 		jiffies_to_msecs(cnf->mldv1_unsolicited_report_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5520) 	array[DEVCONF_MLDV2_UNSOLICITED_REPORT_INTERVAL] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5521) 		jiffies_to_msecs(cnf->mldv2_unsolicited_report_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5522) 	array[DEVCONF_USE_TEMPADDR] = cnf->use_tempaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5523) 	array[DEVCONF_TEMP_VALID_LFT] = cnf->temp_valid_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5524) 	array[DEVCONF_TEMP_PREFERED_LFT] = cnf->temp_prefered_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5525) 	array[DEVCONF_REGEN_MAX_RETRY] = cnf->regen_max_retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5526) 	array[DEVCONF_MAX_DESYNC_FACTOR] = cnf->max_desync_factor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5527) 	array[DEVCONF_MAX_ADDRESSES] = cnf->max_addresses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5528) 	array[DEVCONF_ACCEPT_RA_DEFRTR] = cnf->accept_ra_defrtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5529) 	array[DEVCONF_ACCEPT_RA_MIN_HOP_LIMIT] = cnf->accept_ra_min_hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5530) 	array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5531) #ifdef CONFIG_IPV6_ROUTER_PREF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5532) 	array[DEVCONF_ACCEPT_RA_RTR_PREF] = cnf->accept_ra_rtr_pref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5533) 	array[DEVCONF_RTR_PROBE_INTERVAL] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5534) 		jiffies_to_msecs(cnf->rtr_probe_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5535) #ifdef CONFIG_IPV6_ROUTE_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5536) 	array[DEVCONF_ACCEPT_RA_RT_INFO_MIN_PLEN] = cnf->accept_ra_rt_info_min_plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5537) 	array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5538) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5539) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5540) 	array[DEVCONF_PROXY_NDP] = cnf->proxy_ndp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5541) 	array[DEVCONF_ACCEPT_SOURCE_ROUTE] = cnf->accept_source_route;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5542) #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5543) 	array[DEVCONF_OPTIMISTIC_DAD] = cnf->optimistic_dad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5544) 	array[DEVCONF_USE_OPTIMISTIC] = cnf->use_optimistic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5545) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5546) #ifdef CONFIG_IPV6_MROUTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5547) 	array[DEVCONF_MC_FORWARDING] = cnf->mc_forwarding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5548) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5549) 	array[DEVCONF_DISABLE_IPV6] = cnf->disable_ipv6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5550) 	array[DEVCONF_ACCEPT_DAD] = cnf->accept_dad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5551) 	array[DEVCONF_FORCE_TLLAO] = cnf->force_tllao;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5552) 	array[DEVCONF_NDISC_NOTIFY] = cnf->ndisc_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5553) 	array[DEVCONF_SUPPRESS_FRAG_NDISC] = cnf->suppress_frag_ndisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5554) 	array[DEVCONF_ACCEPT_RA_FROM_LOCAL] = cnf->accept_ra_from_local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5555) 	array[DEVCONF_ACCEPT_RA_MTU] = cnf->accept_ra_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5556) 	array[DEVCONF_IGNORE_ROUTES_WITH_LINKDOWN] = cnf->ignore_routes_with_linkdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5557) 	/* we omit DEVCONF_STABLE_SECRET for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5558) 	array[DEVCONF_USE_OIF_ADDRS_ONLY] = cnf->use_oif_addrs_only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5559) 	array[DEVCONF_DROP_UNICAST_IN_L2_MULTICAST] = cnf->drop_unicast_in_l2_multicast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5560) 	array[DEVCONF_DROP_UNSOLICITED_NA] = cnf->drop_unsolicited_na;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5561) 	array[DEVCONF_KEEP_ADDR_ON_DOWN] = cnf->keep_addr_on_down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5562) 	array[DEVCONF_SEG6_ENABLED] = cnf->seg6_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5563) #ifdef CONFIG_IPV6_SEG6_HMAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5564) 	array[DEVCONF_SEG6_REQUIRE_HMAC] = cnf->seg6_require_hmac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5565) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5566) 	array[DEVCONF_ENHANCED_DAD] = cnf->enhanced_dad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5567) 	array[DEVCONF_ADDR_GEN_MODE] = cnf->addr_gen_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5568) 	array[DEVCONF_DISABLE_POLICY] = cnf->disable_policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5569) 	array[DEVCONF_NDISC_TCLASS] = cnf->ndisc_tclass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5570) 	array[DEVCONF_RPL_SEG_ENABLED] = cnf->rpl_seg_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5573) static inline size_t inet6_ifla6_size(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5575) 	return nla_total_size(4) /* IFLA_INET6_FLAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5576) 	     + nla_total_size(sizeof(struct ifla_cacheinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5577) 	     + nla_total_size(DEVCONF_MAX * 4) /* IFLA_INET6_CONF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5578) 	     + nla_total_size(IPSTATS_MIB_MAX * 8) /* IFLA_INET6_STATS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5579) 	     + nla_total_size(ICMP6_MIB_MAX * 8) /* IFLA_INET6_ICMP6STATS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5580) 	     + nla_total_size(sizeof(struct in6_addr)) /* IFLA_INET6_TOKEN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5581) 	     + nla_total_size(1) /* IFLA_INET6_ADDR_GEN_MODE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5582) 	     + 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5585) static inline size_t inet6_if_nlmsg_size(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5587) 	return NLMSG_ALIGN(sizeof(struct ifinfomsg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5588) 	       + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5589) 	       + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5590) 	       + nla_total_size(4) /* IFLA_MTU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5591) 	       + nla_total_size(4) /* IFLA_LINK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5592) 	       + nla_total_size(1) /* IFLA_OPERSTATE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5593) 	       + nla_total_size(inet6_ifla6_size()); /* IFLA_PROTINFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5596) static inline void __snmp6_fill_statsdev(u64 *stats, atomic_long_t *mib,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5597) 					int bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5599) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5600) 	int pad = bytes - sizeof(u64) * ICMP6_MIB_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5601) 	BUG_ON(pad < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5603) 	/* Use put_unaligned() because stats may not be aligned for u64. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5604) 	put_unaligned(ICMP6_MIB_MAX, &stats[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5605) 	for (i = 1; i < ICMP6_MIB_MAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5606) 		put_unaligned(atomic_long_read(&mib[i]), &stats[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5608) 	memset(&stats[ICMP6_MIB_MAX], 0, pad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5611) static inline void __snmp6_fill_stats64(u64 *stats, void __percpu *mib,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5612) 					int bytes, size_t syncpoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5614) 	int i, c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5615) 	u64 buff[IPSTATS_MIB_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5616) 	int pad = bytes - sizeof(u64) * IPSTATS_MIB_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5618) 	BUG_ON(pad < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5620) 	memset(buff, 0, sizeof(buff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5621) 	buff[0] = IPSTATS_MIB_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5623) 	for_each_possible_cpu(c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5624) 		for (i = 1; i < IPSTATS_MIB_MAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5625) 			buff[i] += snmp_get_cpu_field64(mib, c, i, syncpoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5626) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5628) 	memcpy(stats, buff, IPSTATS_MIB_MAX * sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5629) 	memset(&stats[IPSTATS_MIB_MAX], 0, pad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5632) static void snmp6_fill_stats(u64 *stats, struct inet6_dev *idev, int attrtype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5633) 			     int bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5635) 	switch (attrtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5636) 	case IFLA_INET6_STATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5637) 		__snmp6_fill_stats64(stats, idev->stats.ipv6, bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5638) 				     offsetof(struct ipstats_mib, syncp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5639) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5640) 	case IFLA_INET6_ICMP6STATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5641) 		__snmp6_fill_statsdev(stats, idev->stats.icmpv6dev->mibs, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5642) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5643) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5646) static int inet6_fill_ifla6_attrs(struct sk_buff *skb, struct inet6_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5647) 				  u32 ext_filter_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5649) 	struct nlattr *nla;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5650) 	struct ifla_cacheinfo ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5652) 	if (nla_put_u32(skb, IFLA_INET6_FLAGS, idev->if_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5653) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5654) 	ci.max_reasm_len = IPV6_MAXPLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5655) 	ci.tstamp = cstamp_delta(idev->tstamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5656) 	ci.reachable_time = jiffies_to_msecs(idev->nd_parms->reachable_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5657) 	ci.retrans_time = jiffies_to_msecs(NEIGH_VAR(idev->nd_parms, RETRANS_TIME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5658) 	if (nla_put(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5659) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5660) 	nla = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5661) 	if (!nla)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5662) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5663) 	ipv6_store_devconf(&idev->cnf, nla_data(nla), nla_len(nla));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5665) 	/* XXX - MC not implemented */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5667) 	if (ext_filter_mask & RTEXT_FILTER_SKIP_STATS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5668) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5670) 	nla = nla_reserve(skb, IFLA_INET6_STATS, IPSTATS_MIB_MAX * sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5671) 	if (!nla)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5672) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5673) 	snmp6_fill_stats(nla_data(nla), idev, IFLA_INET6_STATS, nla_len(nla));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5675) 	nla = nla_reserve(skb, IFLA_INET6_ICMP6STATS, ICMP6_MIB_MAX * sizeof(u64));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5676) 	if (!nla)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5677) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5678) 	snmp6_fill_stats(nla_data(nla), idev, IFLA_INET6_ICMP6STATS, nla_len(nla));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5680) 	nla = nla_reserve(skb, IFLA_INET6_TOKEN, sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5681) 	if (!nla)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5682) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5683) 	read_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5684) 	memcpy(nla_data(nla), idev->token.s6_addr, nla_len(nla));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5685) 	read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5687) 	if (nla_put_u8(skb, IFLA_INET6_ADDR_GEN_MODE, idev->cnf.addr_gen_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5688) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5690) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5692) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5693) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5696) static size_t inet6_get_link_af_size(const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5697) 				     u32 ext_filter_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5699) 	if (!__in6_dev_get(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5700) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5702) 	return inet6_ifla6_size();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5705) static int inet6_fill_link_af(struct sk_buff *skb, const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5706) 			      u32 ext_filter_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5708) 	struct inet6_dev *idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5710) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5711) 		return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5713) 	if (inet6_fill_ifla6_attrs(skb, idev, ext_filter_mask) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5714) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5716) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5719) static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5721) 	struct inet6_ifaddr *ifp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5722) 	struct net_device *dev = idev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5723) 	bool clear_token, update_rs = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5724) 	struct in6_addr ll_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5726) 	ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5728) 	if (!token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5729) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5730) 	if (dev->flags & (IFF_LOOPBACK | IFF_NOARP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5731) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5732) 	if (!ipv6_accept_ra(idev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5733) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5734) 	if (idev->cnf.rtr_solicits == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5735) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5737) 	write_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5739) 	BUILD_BUG_ON(sizeof(token->s6_addr) != 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5740) 	memcpy(idev->token.s6_addr + 8, token->s6_addr + 8, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5742) 	write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5744) 	clear_token = ipv6_addr_any(token);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5745) 	if (clear_token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5746) 		goto update_lft;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5748) 	if (!idev->dead && (idev->if_flags & IF_READY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5749) 	    !ipv6_get_lladdr(dev, &ll_addr, IFA_F_TENTATIVE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5750) 			     IFA_F_OPTIMISTIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5751) 		/* If we're not ready, then normal ifup will take care
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5752) 		 * of this. Otherwise, we need to request our rs here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5753) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5754) 		ndisc_send_rs(dev, &ll_addr, &in6addr_linklocal_allrouters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5755) 		update_rs = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5756) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5758) update_lft:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5759) 	write_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5761) 	if (update_rs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5762) 		idev->if_flags |= IF_RS_SENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5763) 		idev->rs_interval = rfc3315_s14_backoff_init(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5764) 			idev->cnf.rtr_solicit_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5765) 		idev->rs_probes = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5766) 		addrconf_mod_rs_timer(idev, idev->rs_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5767) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5769) 	/* Well, that's kinda nasty ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5770) 	list_for_each_entry(ifp, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5771) 		spin_lock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5772) 		if (ifp->tokenized) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5773) 			ifp->valid_lft = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5774) 			ifp->prefered_lft = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5775) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5776) 		spin_unlock(&ifp->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5777) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5779) 	write_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5780) 	inet6_ifinfo_notify(RTM_NEWLINK, idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5781) 	addrconf_verify_rtnl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5782) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5785) static const struct nla_policy inet6_af_policy[IFLA_INET6_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5786) 	[IFLA_INET6_ADDR_GEN_MODE]	= { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5787) 	[IFLA_INET6_TOKEN]		= { .len = sizeof(struct in6_addr) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5788) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5790) static int check_addr_gen_mode(int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5792) 	if (mode != IN6_ADDR_GEN_MODE_EUI64 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5793) 	    mode != IN6_ADDR_GEN_MODE_NONE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5794) 	    mode != IN6_ADDR_GEN_MODE_STABLE_PRIVACY &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5795) 	    mode != IN6_ADDR_GEN_MODE_RANDOM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5796) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5797) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5800) static int check_stable_privacy(struct inet6_dev *idev, struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5801) 				int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5803) 	if (mode == IN6_ADDR_GEN_MODE_STABLE_PRIVACY &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5804) 	    !idev->cnf.stable_secret.initialized &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5805) 	    !net->ipv6.devconf_dflt->stable_secret.initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5806) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5807) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5810) static int inet6_validate_link_af(const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5811) 				  const struct nlattr *nla)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5813) 	struct nlattr *tb[IFLA_INET6_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5814) 	struct inet6_dev *idev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5815) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5817) 	if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5818) 		idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5819) 		if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5820) 			return -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5821) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5823) 	err = nla_parse_nested_deprecated(tb, IFLA_INET6_MAX, nla,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5824) 					  inet6_af_policy, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5825) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5826) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5828) 	if (!tb[IFLA_INET6_TOKEN] && !tb[IFLA_INET6_ADDR_GEN_MODE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5829) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5831) 	if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5832) 		u8 mode = nla_get_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5834) 		if (check_addr_gen_mode(mode) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5835) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5836) 		if (dev && check_stable_privacy(idev, dev_net(dev), mode) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5837) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5838) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5840) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5843) static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5845) 	struct inet6_dev *idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5846) 	struct nlattr *tb[IFLA_INET6_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5847) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5849) 	if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5850) 		return -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5852) 	if (nla_parse_nested_deprecated(tb, IFLA_INET6_MAX, nla, NULL, NULL) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5853) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5855) 	if (tb[IFLA_INET6_TOKEN]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5856) 		err = inet6_set_iftoken(idev, nla_data(tb[IFLA_INET6_TOKEN]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5857) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5858) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5859) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5861) 	if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5862) 		u8 mode = nla_get_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5864) 		idev->cnf.addr_gen_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5865) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5867) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5870) static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5871) 			     u32 portid, u32 seq, int event, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5873) 	struct net_device *dev = idev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5874) 	struct ifinfomsg *hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5875) 	struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5876) 	void *protoinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5878) 	nlh = nlmsg_put(skb, portid, seq, event, sizeof(*hdr), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5879) 	if (!nlh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5880) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5882) 	hdr = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5883) 	hdr->ifi_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5884) 	hdr->__ifi_pad = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5885) 	hdr->ifi_type = dev->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5886) 	hdr->ifi_index = dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5887) 	hdr->ifi_flags = dev_get_flags(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5888) 	hdr->ifi_change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5890) 	if (nla_put_string(skb, IFLA_IFNAME, dev->name) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5891) 	    (dev->addr_len &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5892) 	     nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5893) 	    nla_put_u32(skb, IFLA_MTU, dev->mtu) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5894) 	    (dev->ifindex != dev_get_iflink(dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5895) 	     nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5896) 	    nla_put_u8(skb, IFLA_OPERSTATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5897) 		       netif_running(dev) ? dev->operstate : IF_OPER_DOWN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5898) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5899) 	protoinfo = nla_nest_start_noflag(skb, IFLA_PROTINFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5900) 	if (!protoinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5901) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5903) 	if (inet6_fill_ifla6_attrs(skb, idev, 0) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5904) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5906) 	nla_nest_end(skb, protoinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5907) 	nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5908) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5910) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5911) 	nlmsg_cancel(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5912) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5915) static int inet6_valid_dump_ifinfo(const struct nlmsghdr *nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5916) 				   struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5917) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5918) 	struct ifinfomsg *ifm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5920) 	if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5921) 		NL_SET_ERR_MSG_MOD(extack, "Invalid header for link dump request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5922) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5923) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5925) 	if (nlmsg_attrlen(nlh, sizeof(*ifm))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5926) 		NL_SET_ERR_MSG_MOD(extack, "Invalid data after header");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5927) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5928) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5930) 	ifm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5931) 	if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5932) 	    ifm->ifi_change || ifm->ifi_index) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5933) 		NL_SET_ERR_MSG_MOD(extack, "Invalid values in header for dump request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5934) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5935) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5937) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5940) static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5942) 	struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5943) 	int h, s_h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5944) 	int idx = 0, s_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5945) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5946) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5947) 	struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5949) 	/* only requests using strict checking can pass data to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5950) 	 * influence the dump
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5951) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5952) 	if (cb->strict_check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5953) 		int err = inet6_valid_dump_ifinfo(cb->nlh, cb->extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5955) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5956) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5957) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5959) 	s_h = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5960) 	s_idx = cb->args[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5962) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5963) 	for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5964) 		idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5965) 		head = &net->dev_index_head[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5966) 		hlist_for_each_entry_rcu(dev, head, index_hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5967) 			if (idx < s_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5968) 				goto cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5969) 			idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5970) 			if (!idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5971) 				goto cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5972) 			if (inet6_fill_ifinfo(skb, idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5973) 					      NETLINK_CB(cb->skb).portid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5974) 					      cb->nlh->nlmsg_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5975) 					      RTM_NEWLINK, NLM_F_MULTI) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5976) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5977) cont:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5978) 			idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5979) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5980) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5981) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5982) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5983) 	cb->args[1] = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5984) 	cb->args[0] = h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5986) 	return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5989) void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5990) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5991) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5992) 	struct net *net = dev_net(idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5993) 	int err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5995) 	skb = nlmsg_new(inet6_if_nlmsg_size(), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5996) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5997) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5999) 	err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6000) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6001) 		/* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6002) 		WARN_ON(err == -EMSGSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6003) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6004) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6005) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6006) 	rtnl_notify(skb, net, 0, RTNLGRP_IPV6_IFINFO, NULL, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6007) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6008) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6009) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6010) 		rtnl_set_sk_err(net, RTNLGRP_IPV6_IFINFO, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6013) static inline size_t inet6_prefix_nlmsg_size(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6015) 	return NLMSG_ALIGN(sizeof(struct prefixmsg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6016) 	       + nla_total_size(sizeof(struct in6_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6017) 	       + nla_total_size(sizeof(struct prefix_cacheinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6020) static int inet6_fill_prefix(struct sk_buff *skb, struct inet6_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6021) 			     struct prefix_info *pinfo, u32 portid, u32 seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6022) 			     int event, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6023) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6024) 	struct prefixmsg *pmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6025) 	struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6026) 	struct prefix_cacheinfo	ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6028) 	nlh = nlmsg_put(skb, portid, seq, event, sizeof(*pmsg), flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6029) 	if (!nlh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6030) 		return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6032) 	pmsg = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6033) 	pmsg->prefix_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6034) 	pmsg->prefix_pad1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6035) 	pmsg->prefix_pad2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6036) 	pmsg->prefix_ifindex = idev->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6037) 	pmsg->prefix_len = pinfo->prefix_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6038) 	pmsg->prefix_type = pinfo->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6039) 	pmsg->prefix_pad3 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6040) 	pmsg->prefix_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6041) 	if (pinfo->onlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6042) 		pmsg->prefix_flags |= IF_PREFIX_ONLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6043) 	if (pinfo->autoconf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6044) 		pmsg->prefix_flags |= IF_PREFIX_AUTOCONF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6046) 	if (nla_put(skb, PREFIX_ADDRESS, sizeof(pinfo->prefix), &pinfo->prefix))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6047) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6048) 	ci.preferred_time = ntohl(pinfo->prefered);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6049) 	ci.valid_time = ntohl(pinfo->valid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6050) 	if (nla_put(skb, PREFIX_CACHEINFO, sizeof(ci), &ci))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6051) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6052) 	nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6053) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6055) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6056) 	nlmsg_cancel(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6057) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6060) static void inet6_prefix_notify(int event, struct inet6_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6061) 			 struct prefix_info *pinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6063) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6064) 	struct net *net = dev_net(idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6065) 	int err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6067) 	skb = nlmsg_new(inet6_prefix_nlmsg_size(), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6068) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6069) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6071) 	err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6072) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6073) 		/* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6074) 		WARN_ON(err == -EMSGSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6075) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6076) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6077) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6078) 	rtnl_notify(skb, net, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6079) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6080) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6081) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6082) 		rtnl_set_sk_err(net, RTNLGRP_IPV6_PREFIX, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6085) static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6086) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6087) 	struct net *net = dev_net(ifp->idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6089) 	if (event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6090) 		ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6092) 	inet6_ifa_notify(event ? : RTM_NEWADDR, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6094) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6095) 	case RTM_NEWADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6096) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6097) 		 * If the address was optimistic we inserted the route at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6098) 		 * start of our DAD process, so we don't need to do it again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6099) 		 * If the device was taken down in the middle of the DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6100) 		 * cycle there is a race where we could get here without a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6101) 		 * host route, so nothing to insert. That will be fixed when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6102) 		 * the device is brought up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6103) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6104) 		if (ifp->rt && !rcu_access_pointer(ifp->rt->fib6_node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6105) 			ip6_ins_rt(net, ifp->rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6106) 		} else if (!ifp->rt && (ifp->idev->dev->flags & IFF_UP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6107) 			pr_warn("BUG: Address %pI6c on device %s is missing its host route.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6108) 				&ifp->addr, ifp->idev->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6109) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6111) 		if (ifp->idev->cnf.forwarding)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6112) 			addrconf_join_anycast(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6113) 		if (!ipv6_addr_any(&ifp->peer_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6114) 			addrconf_prefix_route(&ifp->peer_addr, 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6115) 					      ifp->rt_priority, ifp->idev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6116) 					      0, 0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6117) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6118) 	case RTM_DELADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6119) 		if (ifp->idev->cnf.forwarding)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6120) 			addrconf_leave_anycast(ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6121) 		addrconf_leave_solict(ifp->idev, &ifp->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6122) 		if (!ipv6_addr_any(&ifp->peer_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6123) 			struct fib6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6125) 			rt = addrconf_get_prefix_route(&ifp->peer_addr, 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6126) 						       ifp->idev->dev, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6127) 						       false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6128) 			if (rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6129) 				ip6_del_rt(net, rt, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6130) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6131) 		if (ifp->rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6132) 			ip6_del_rt(net, ifp->rt, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6133) 			ifp->rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6135) 		rt_genid_bump_ipv6(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6136) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6138) 	atomic_inc(&net->ipv6.dev_addr_genid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6141) static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6143) 	rcu_read_lock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6144) 	if (likely(ifp->idev->dead == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6145) 		__ipv6_ifa_notify(event, ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6146) 	rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6149) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6151) static int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6152) 		void *buffer, size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6154) 	int *valp = ctl->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6155) 	int val = *valp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6156) 	loff_t pos = *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6157) 	struct ctl_table lctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6158) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6160) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6161) 	 * ctl->data points to idev->cnf.forwarding, we should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6162) 	 * not modify it until we get the rtnl lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6163) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6164) 	lctl = *ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6165) 	lctl.data = &val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6167) 	ret = proc_dointvec(&lctl, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6169) 	if (write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6170) 		ret = addrconf_fixup_forwarding(ctl, valp, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6171) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6172) 		*ppos = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6173) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6176) static int addrconf_sysctl_mtu(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6177) 		void *buffer, size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6179) 	struct inet6_dev *idev = ctl->extra1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6180) 	int min_mtu = IPV6_MIN_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6181) 	struct ctl_table lctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6183) 	lctl = *ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6184) 	lctl.extra1 = &min_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6185) 	lctl.extra2 = idev ? &idev->dev->mtu : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6187) 	return proc_dointvec_minmax(&lctl, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6190) static void dev_disable_change(struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6192) 	struct netdev_notifier_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6194) 	if (!idev || !idev->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6195) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6197) 	netdev_notifier_info_init(&info, idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6198) 	if (idev->cnf.disable_ipv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6199) 		addrconf_notify(NULL, NETDEV_DOWN, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6200) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6201) 		addrconf_notify(NULL, NETDEV_UP, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6204) static void addrconf_disable_change(struct net *net, __s32 newf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6206) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6207) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6209) 	for_each_netdev(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6210) 		idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6211) 		if (idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6212) 			int changed = (!idev->cnf.disable_ipv6) ^ (!newf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6213) 			idev->cnf.disable_ipv6 = newf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6214) 			if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6215) 				dev_disable_change(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6216) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6220) static int addrconf_disable_ipv6(struct ctl_table *table, int *p, int newf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6222) 	struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6223) 	int old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6225) 	if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6226) 		return restart_syscall();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6228) 	net = (struct net *)table->extra2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6229) 	old = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6230) 	*p = newf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6232) 	if (p == &net->ipv6.devconf_dflt->disable_ipv6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6233) 		rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6234) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6237) 	if (p == &net->ipv6.devconf_all->disable_ipv6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6238) 		net->ipv6.devconf_dflt->disable_ipv6 = newf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6239) 		addrconf_disable_change(net, newf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6240) 	} else if ((!newf) ^ (!old))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6241) 		dev_disable_change((struct inet6_dev *)table->extra1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6243) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6244) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6247) static int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6248) 		void *buffer, size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6250) 	int *valp = ctl->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6251) 	int val = *valp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6252) 	loff_t pos = *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6253) 	struct ctl_table lctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6254) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6256) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6257) 	 * ctl->data points to idev->cnf.disable_ipv6, we should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6258) 	 * not modify it until we get the rtnl lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6259) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6260) 	lctl = *ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6261) 	lctl.data = &val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6263) 	ret = proc_dointvec(&lctl, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6265) 	if (write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6266) 		ret = addrconf_disable_ipv6(ctl, valp, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6267) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6268) 		*ppos = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6269) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6272) static int addrconf_sysctl_proxy_ndp(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6273) 		void *buffer, size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6275) 	int *valp = ctl->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6276) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6277) 	int old, new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6279) 	old = *valp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6280) 	ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6281) 	new = *valp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6283) 	if (write && old != new) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6284) 		struct net *net = ctl->extra2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6286) 		if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6287) 			return restart_syscall();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6289) 		if (valp == &net->ipv6.devconf_dflt->proxy_ndp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6290) 			inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6291) 						     NETCONFA_PROXY_NEIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6292) 						     NETCONFA_IFINDEX_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6293) 						     net->ipv6.devconf_dflt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6294) 		else if (valp == &net->ipv6.devconf_all->proxy_ndp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6295) 			inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6296) 						     NETCONFA_PROXY_NEIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6297) 						     NETCONFA_IFINDEX_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6298) 						     net->ipv6.devconf_all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6299) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6300) 			struct inet6_dev *idev = ctl->extra1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6302) 			inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6303) 						     NETCONFA_PROXY_NEIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6304) 						     idev->dev->ifindex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6305) 						     &idev->cnf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6306) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6307) 		rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6310) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6313) static int addrconf_sysctl_addr_gen_mode(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6314) 					 void *buffer, size_t *lenp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6315) 					 loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6317) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6318) 	u32 new_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6319) 	struct inet6_dev *idev = (struct inet6_dev *)ctl->extra1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6320) 	struct net *net = (struct net *)ctl->extra2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6321) 	struct ctl_table tmp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6322) 		.data = &new_val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6323) 		.maxlen = sizeof(new_val),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6324) 		.mode = ctl->mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6325) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6327) 	if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6328) 		return restart_syscall();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6330) 	new_val = *((u32 *)ctl->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6332) 	ret = proc_douintvec(&tmp, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6333) 	if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6334) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6336) 	if (write) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6337) 		if (check_addr_gen_mode(new_val) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6338) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6339) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6340) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6342) 		if (idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6343) 			if (check_stable_privacy(idev, net, new_val) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6344) 				ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6345) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6346) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6348) 			if (idev->cnf.addr_gen_mode != new_val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6349) 				idev->cnf.addr_gen_mode = new_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6350) 				addrconf_dev_config(idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6351) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6352) 		} else if (&net->ipv6.devconf_all->addr_gen_mode == ctl->data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6353) 			struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6355) 			net->ipv6.devconf_dflt->addr_gen_mode = new_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6356) 			for_each_netdev(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6357) 				idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6358) 				if (idev &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6359) 				    idev->cnf.addr_gen_mode != new_val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6360) 					idev->cnf.addr_gen_mode = new_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6361) 					addrconf_dev_config(idev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6362) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6363) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6364) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6366) 		*((u32 *)ctl->data) = new_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6369) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6370) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6372) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6375) static int addrconf_sysctl_stable_secret(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6376) 					 void *buffer, size_t *lenp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6377) 					 loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6379) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6380) 	struct in6_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6381) 	char str[IPV6_MAX_STRLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6382) 	struct ctl_table lctl = *ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6383) 	struct net *net = ctl->extra2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6384) 	struct ipv6_stable_secret *secret = ctl->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6386) 	if (&net->ipv6.devconf_all->stable_secret == ctl->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6387) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6389) 	lctl.maxlen = IPV6_MAX_STRLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6390) 	lctl.data = str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6392) 	if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6393) 		return restart_syscall();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6395) 	if (!write && !secret->initialized) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6396) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6397) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6398) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6400) 	err = snprintf(str, sizeof(str), "%pI6", &secret->secret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6401) 	if (err >= sizeof(str)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6402) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6403) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6404) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6406) 	err = proc_dostring(&lctl, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6407) 	if (err || !write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6408) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6410) 	if (in6_pton(str, -1, addr.in6_u.u6_addr8, -1, NULL) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6411) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6412) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6415) 	secret->initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6416) 	secret->secret = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6418) 	if (&net->ipv6.devconf_dflt->stable_secret == ctl->data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6419) 		struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6421) 		for_each_netdev(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6422) 			struct inet6_dev *idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6424) 			if (idev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6425) 				idev->cnf.addr_gen_mode =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6426) 					IN6_ADDR_GEN_MODE_STABLE_PRIVACY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6427) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6428) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6429) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6430) 		struct inet6_dev *idev = ctl->extra1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6432) 		idev->cnf.addr_gen_mode = IN6_ADDR_GEN_MODE_STABLE_PRIVACY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6435) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6436) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6438) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6441) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6442) int addrconf_sysctl_ignore_routes_with_linkdown(struct ctl_table *ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6443) 						int write, void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6444) 						size_t *lenp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6445) 						loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6447) 	int *valp = ctl->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6448) 	int val = *valp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6449) 	loff_t pos = *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6450) 	struct ctl_table lctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6451) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6453) 	/* ctl->data points to idev->cnf.ignore_routes_when_linkdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6454) 	 * we should not modify it until we get the rtnl lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6455) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6456) 	lctl = *ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6457) 	lctl.data = &val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6459) 	ret = proc_dointvec(&lctl, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6461) 	if (write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6462) 		ret = addrconf_fixup_linkdown(ctl, valp, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6463) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6464) 		*ppos = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6465) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6468) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6469) void addrconf_set_nopolicy(struct rt6_info *rt, int action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6471) 	if (rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6472) 		if (action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6473) 			rt->dst.flags |= DST_NOPOLICY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6474) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6475) 			rt->dst.flags &= ~DST_NOPOLICY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6479) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6480) void addrconf_disable_policy_idev(struct inet6_dev *idev, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6482) 	struct inet6_ifaddr *ifa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6484) 	read_lock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6485) 	list_for_each_entry(ifa, &idev->addr_list, if_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6486) 		spin_lock(&ifa->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6487) 		if (ifa->rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6488) 			/* host routes only use builtin fib6_nh */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6489) 			struct fib6_nh *nh = ifa->rt->fib6_nh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6490) 			int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6492) 			rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6493) 			ifa->rt->dst_nopolicy = val ? true : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6494) 			if (nh->rt6i_pcpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6495) 				for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6496) 					struct rt6_info **rtp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6498) 					rtp = per_cpu_ptr(nh->rt6i_pcpu, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6499) 					addrconf_set_nopolicy(*rtp, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6500) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6501) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6502) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6503) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6504) 		spin_unlock(&ifa->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6506) 	read_unlock_bh(&idev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6509) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6510) int addrconf_disable_policy(struct ctl_table *ctl, int *valp, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6512) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6513) 	struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6515) 	if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6516) 		return restart_syscall();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6518) 	*valp = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6520) 	net = (struct net *)ctl->extra2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6521) 	if (valp == &net->ipv6.devconf_dflt->disable_policy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6522) 		rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6523) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6524) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6526) 	if (valp == &net->ipv6.devconf_all->disable_policy)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6527) 		struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6529) 		for_each_netdev(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6530) 			idev = __in6_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6531) 			if (idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6532) 				addrconf_disable_policy_idev(idev, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6533) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6534) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6535) 		idev = (struct inet6_dev *)ctl->extra1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6536) 		addrconf_disable_policy_idev(idev, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6537) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6539) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6540) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6543) static int addrconf_sysctl_disable_policy(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6544) 				   void *buffer, size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6546) 	int *valp = ctl->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6547) 	int val = *valp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6548) 	loff_t pos = *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6549) 	struct ctl_table lctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6550) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6552) 	lctl = *ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6553) 	lctl.data = &val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6554) 	ret = proc_dointvec(&lctl, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6556) 	if (write && (*valp != val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6557) 		ret = addrconf_disable_policy(ctl, valp, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6559) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6560) 		*ppos = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6562) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6565) static int minus_one = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6566) static const int two_five_five = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6568) static const struct ctl_table addrconf_sysctl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6569) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6570) 		.procname	= "forwarding",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6571) 		.data		= &ipv6_devconf.forwarding,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6572) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6573) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6574) 		.proc_handler	= addrconf_sysctl_forward,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6575) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6576) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6577) 		.procname	= "hop_limit",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6578) 		.data		= &ipv6_devconf.hop_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6579) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6580) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6581) 		.proc_handler	= proc_dointvec_minmax,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6582) 		.extra1		= (void *)SYSCTL_ONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6583) 		.extra2		= (void *)&two_five_five,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6584) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6585) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6586) 		.procname	= "mtu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6587) 		.data		= &ipv6_devconf.mtu6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6588) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6589) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6590) 		.proc_handler	= addrconf_sysctl_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6591) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6592) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6593) 		.procname	= "accept_ra",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6594) 		.data		= &ipv6_devconf.accept_ra,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6595) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6596) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6597) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6598) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6599) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6600) 		.procname	= "accept_redirects",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6601) 		.data		= &ipv6_devconf.accept_redirects,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6602) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6603) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6604) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6605) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6606) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6607) 		.procname	= "autoconf",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6608) 		.data		= &ipv6_devconf.autoconf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6609) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6610) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6611) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6612) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6613) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6614) 		.procname	= "dad_transmits",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6615) 		.data		= &ipv6_devconf.dad_transmits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6616) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6617) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6618) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6619) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6620) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6621) 		.procname	= "router_solicitations",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6622) 		.data		= &ipv6_devconf.rtr_solicits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6623) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6624) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6625) 		.proc_handler	= proc_dointvec_minmax,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6626) 		.extra1		= &minus_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6627) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6628) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6629) 		.procname	= "router_solicitation_interval",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6630) 		.data		= &ipv6_devconf.rtr_solicit_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6631) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6632) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6633) 		.proc_handler	= proc_dointvec_jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6634) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6635) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6636) 		.procname	= "router_solicitation_max_interval",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6637) 		.data		= &ipv6_devconf.rtr_solicit_max_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6638) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6639) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6640) 		.proc_handler	= proc_dointvec_jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6641) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6642) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6643) 		.procname	= "router_solicitation_delay",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6644) 		.data		= &ipv6_devconf.rtr_solicit_delay,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6645) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6646) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6647) 		.proc_handler	= proc_dointvec_jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6648) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6649) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6650) 		.procname	= "force_mld_version",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6651) 		.data		= &ipv6_devconf.force_mld_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6652) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6653) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6654) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6655) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6656) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6657) 		.procname	= "mldv1_unsolicited_report_interval",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6658) 		.data		=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6659) 			&ipv6_devconf.mldv1_unsolicited_report_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6660) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6661) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6662) 		.proc_handler	= proc_dointvec_ms_jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6663) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6664) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6665) 		.procname	= "mldv2_unsolicited_report_interval",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6666) 		.data		=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6667) 			&ipv6_devconf.mldv2_unsolicited_report_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6668) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6669) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6670) 		.proc_handler	= proc_dointvec_ms_jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6671) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6672) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6673) 		.procname	= "use_tempaddr",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6674) 		.data		= &ipv6_devconf.use_tempaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6675) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6676) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6677) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6678) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6679) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6680) 		.procname	= "temp_valid_lft",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6681) 		.data		= &ipv6_devconf.temp_valid_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6682) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6683) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6684) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6685) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6686) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6687) 		.procname	= "temp_prefered_lft",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6688) 		.data		= &ipv6_devconf.temp_prefered_lft,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6689) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6690) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6691) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6692) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6693) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6694) 		.procname	= "regen_max_retry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6695) 		.data		= &ipv6_devconf.regen_max_retry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6696) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6697) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6698) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6699) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6700) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6701) 		.procname	= "max_desync_factor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6702) 		.data		= &ipv6_devconf.max_desync_factor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6703) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6704) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6705) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6706) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6707) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6708) 		.procname	= "max_addresses",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6709) 		.data		= &ipv6_devconf.max_addresses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6710) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6711) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6712) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6713) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6714) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6715) 		.procname	= "accept_ra_defrtr",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6716) 		.data		= &ipv6_devconf.accept_ra_defrtr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6717) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6718) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6719) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6720) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6721) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6722) 		.procname	= "accept_ra_min_hop_limit",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6723) 		.data		= &ipv6_devconf.accept_ra_min_hop_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6724) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6725) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6726) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6727) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6728) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6729) 		.procname	= "accept_ra_pinfo",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6730) 		.data		= &ipv6_devconf.accept_ra_pinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6731) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6732) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6733) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6734) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6735) #ifdef CONFIG_IPV6_ROUTER_PREF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6736) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6737) 		.procname	= "accept_ra_rtr_pref",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6738) 		.data		= &ipv6_devconf.accept_ra_rtr_pref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6739) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6740) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6741) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6742) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6743) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6744) 		.procname	= "router_probe_interval",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6745) 		.data		= &ipv6_devconf.rtr_probe_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6746) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6747) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6748) 		.proc_handler	= proc_dointvec_jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6749) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6750) #ifdef CONFIG_IPV6_ROUTE_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6751) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6752) 		.procname	= "accept_ra_rt_info_min_plen",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6753) 		.data		= &ipv6_devconf.accept_ra_rt_info_min_plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6754) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6755) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6756) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6757) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6758) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6759) 		.procname	= "accept_ra_rt_info_max_plen",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6760) 		.data		= &ipv6_devconf.accept_ra_rt_info_max_plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6761) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6762) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6763) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6764) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6765) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6766) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6767) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6768) 		.procname	= "accept_ra_rt_table",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6769) 		.data		= &ipv6_devconf.accept_ra_rt_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6770) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6771) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6772) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6773) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6774) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6775) 		.procname	= "proxy_ndp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6776) 		.data		= &ipv6_devconf.proxy_ndp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6777) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6778) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6779) 		.proc_handler	= addrconf_sysctl_proxy_ndp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6780) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6781) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6782) 		.procname	= "accept_source_route",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6783) 		.data		= &ipv6_devconf.accept_source_route,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6784) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6785) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6786) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6787) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6788) #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6789) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6790) 		.procname	= "optimistic_dad",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6791) 		.data		= &ipv6_devconf.optimistic_dad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6792) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6793) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6794) 		.proc_handler   = proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6795) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6796) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6797) 		.procname	= "use_optimistic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6798) 		.data		= &ipv6_devconf.use_optimistic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6799) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6800) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6801) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6802) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6803) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6804) #ifdef CONFIG_IPV6_MROUTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6805) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6806) 		.procname	= "mc_forwarding",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6807) 		.data		= &ipv6_devconf.mc_forwarding,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6808) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6809) 		.mode		= 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6810) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6811) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6812) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6813) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6814) 		.procname	= "disable_ipv6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6815) 		.data		= &ipv6_devconf.disable_ipv6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6816) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6817) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6818) 		.proc_handler	= addrconf_sysctl_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6819) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6820) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6821) 		.procname	= "accept_dad",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6822) 		.data		= &ipv6_devconf.accept_dad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6823) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6824) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6825) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6826) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6827) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6828) 		.procname	= "force_tllao",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6829) 		.data		= &ipv6_devconf.force_tllao,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6830) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6831) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6832) 		.proc_handler	= proc_dointvec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6833) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6834) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6835) 		.procname	= "ndisc_notify",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6836) 		.data		= &ipv6_devconf.ndisc_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6837) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6838) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6839) 		.proc_handler	= proc_dointvec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6840) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6841) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6842) 		.procname	= "suppress_frag_ndisc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6843) 		.data		= &ipv6_devconf.suppress_frag_ndisc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6844) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6845) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6846) 		.proc_handler	= proc_dointvec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6847) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6848) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6849) 		.procname	= "accept_ra_from_local",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6850) 		.data		= &ipv6_devconf.accept_ra_from_local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6851) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6852) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6853) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6854) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6855) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6856) 		.procname	= "accept_ra_mtu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6857) 		.data		= &ipv6_devconf.accept_ra_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6858) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6859) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6860) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6861) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6862) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6863) 		.procname	= "stable_secret",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6864) 		.data		= &ipv6_devconf.stable_secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6865) 		.maxlen		= IPV6_MAX_STRLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6866) 		.mode		= 0600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6867) 		.proc_handler	= addrconf_sysctl_stable_secret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6868) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6869) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6870) 		.procname	= "use_oif_addrs_only",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6871) 		.data		= &ipv6_devconf.use_oif_addrs_only,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6872) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6873) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6874) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6875) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6876) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6877) 		.procname	= "ignore_routes_with_linkdown",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6878) 		.data		= &ipv6_devconf.ignore_routes_with_linkdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6879) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6880) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6881) 		.proc_handler	= addrconf_sysctl_ignore_routes_with_linkdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6882) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6883) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6884) 		.procname	= "drop_unicast_in_l2_multicast",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6885) 		.data		= &ipv6_devconf.drop_unicast_in_l2_multicast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6886) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6887) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6888) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6889) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6890) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6891) 		.procname	= "drop_unsolicited_na",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6892) 		.data		= &ipv6_devconf.drop_unsolicited_na,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6893) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6894) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6895) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6896) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6897) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6898) 		.procname	= "keep_addr_on_down",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6899) 		.data		= &ipv6_devconf.keep_addr_on_down,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6900) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6901) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6902) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6904) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6905) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6906) 		.procname	= "seg6_enabled",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6907) 		.data		= &ipv6_devconf.seg6_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6908) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6909) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6910) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6911) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6912) #ifdef CONFIG_IPV6_SEG6_HMAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6913) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6914) 		.procname	= "seg6_require_hmac",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6915) 		.data		= &ipv6_devconf.seg6_require_hmac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6916) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6917) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6918) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6919) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6920) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6921) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6922) 		.procname       = "enhanced_dad",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6923) 		.data           = &ipv6_devconf.enhanced_dad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6924) 		.maxlen         = sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6925) 		.mode           = 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6926) 		.proc_handler   = proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6927) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6928) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6929) 		.procname		= "addr_gen_mode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6930) 		.data			= &ipv6_devconf.addr_gen_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6931) 		.maxlen			= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6932) 		.mode			= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6933) 		.proc_handler	= addrconf_sysctl_addr_gen_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6934) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6935) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6936) 		.procname       = "disable_policy",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6937) 		.data           = &ipv6_devconf.disable_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6938) 		.maxlen         = sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6939) 		.mode           = 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6940) 		.proc_handler   = addrconf_sysctl_disable_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6941) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6942) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6943) 		.procname	= "ndisc_tclass",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6944) 		.data		= &ipv6_devconf.ndisc_tclass,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6945) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6946) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6947) 		.proc_handler	= proc_dointvec_minmax,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6948) 		.extra1		= (void *)SYSCTL_ZERO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6949) 		.extra2		= (void *)&two_five_five,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6950) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6951) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6952) 		.procname	= "rpl_seg_enabled",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6953) 		.data		= &ipv6_devconf.rpl_seg_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6954) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6955) 		.mode		= 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6956) 		.proc_handler	= proc_dointvec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6957) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6958) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6959) 		/* sentinel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6960) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6961) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6963) static int __addrconf_sysctl_register(struct net *net, char *dev_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6964) 		struct inet6_dev *idev, struct ipv6_devconf *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6965) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6966) 	int i, ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6967) 	struct ctl_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6968) 	char path[sizeof("net/ipv6/conf/") + IFNAMSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6970) 	table = kmemdup(addrconf_sysctl, sizeof(addrconf_sysctl), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6971) 	if (!table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6972) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6974) 	for (i = 0; table[i].data; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6975) 		table[i].data += (char *)p - (char *)&ipv6_devconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6976) 		/* If one of these is already set, then it is not safe to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6977) 		 * overwrite either of them: this makes proc_dointvec_minmax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6978) 		 * usable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6979) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6980) 		if (!table[i].extra1 && !table[i].extra2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6981) 			table[i].extra1 = idev; /* embedded; no ref */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6982) 			table[i].extra2 = net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6983) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6984) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6986) 	snprintf(path, sizeof(path), "net/ipv6/conf/%s", dev_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6988) 	p->sysctl_header = register_net_sysctl(net, path, table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6989) 	if (!p->sysctl_header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6990) 		goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6992) 	if (!strcmp(dev_name, "all"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6993) 		ifindex = NETCONFA_IFINDEX_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6994) 	else if (!strcmp(dev_name, "default"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6995) 		ifindex = NETCONFA_IFINDEX_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6996) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6997) 		ifindex = idev->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6998) 	inet6_netconf_notify_devconf(net, RTM_NEWNETCONF, NETCONFA_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6999) 				     ifindex, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7000) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7002) free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7003) 	kfree(table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7004) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7005) 	return -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7008) static void __addrconf_sysctl_unregister(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7009) 					 struct ipv6_devconf *p, int ifindex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7010) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7011) 	struct ctl_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7013) 	if (!p->sysctl_header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7014) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7016) 	table = p->sysctl_header->ctl_table_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7017) 	unregister_net_sysctl_table(p->sysctl_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7018) 	p->sysctl_header = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7019) 	kfree(table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7021) 	inet6_netconf_notify_devconf(net, RTM_DELNETCONF, 0, ifindex, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7024) static int addrconf_sysctl_register(struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7025) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7026) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7028) 	if (!sysctl_dev_name_is_allowed(idev->dev->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7029) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7031) 	err = neigh_sysctl_register(idev->dev, idev->nd_parms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7032) 				    &ndisc_ifinfo_sysctl_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7033) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7034) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7035) 	err = __addrconf_sysctl_register(dev_net(idev->dev), idev->dev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7036) 					 idev, &idev->cnf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7037) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7038) 		neigh_sysctl_unregister(idev->nd_parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7040) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7043) static void addrconf_sysctl_unregister(struct inet6_dev *idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7044) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7045) 	__addrconf_sysctl_unregister(dev_net(idev->dev), &idev->cnf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7046) 				     idev->dev->ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7047) 	neigh_sysctl_unregister(idev->nd_parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7051) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7053) static int __net_init addrconf_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7054) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7055) 	int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7056) 	struct ipv6_devconf *all, *dflt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7058) 	all = kmemdup(&ipv6_devconf, sizeof(ipv6_devconf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7059) 	if (!all)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7060) 		goto err_alloc_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7062) 	dflt = kmemdup(&ipv6_devconf_dflt, sizeof(ipv6_devconf_dflt), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7063) 	if (!dflt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7064) 		goto err_alloc_dflt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7066) 	if (IS_ENABLED(CONFIG_SYSCTL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7067) 	    !net_eq(net, &init_net)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7068) 		switch (sysctl_devconf_inherit_init_net) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7069) 		case 1:  /* copy from init_net */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7070) 			memcpy(all, init_net.ipv6.devconf_all,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7071) 			       sizeof(ipv6_devconf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7072) 			memcpy(dflt, init_net.ipv6.devconf_dflt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7073) 			       sizeof(ipv6_devconf_dflt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7074) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7075) 		case 3: /* copy from the current netns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7076) 			memcpy(all, current->nsproxy->net_ns->ipv6.devconf_all,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7077) 			       sizeof(ipv6_devconf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7078) 			memcpy(dflt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7079) 			       current->nsproxy->net_ns->ipv6.devconf_dflt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7080) 			       sizeof(ipv6_devconf_dflt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7081) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7082) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7083) 		case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7084) 			/* use compiled values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7085) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7086) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7087) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7089) 	/* these will be inherited by all namespaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7090) 	dflt->autoconf = ipv6_defaults.autoconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7091) 	dflt->disable_ipv6 = ipv6_defaults.disable_ipv6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7093) 	dflt->stable_secret.initialized = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7094) 	all->stable_secret.initialized = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7096) 	net->ipv6.devconf_all = all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7097) 	net->ipv6.devconf_dflt = dflt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7099) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7100) 	err = __addrconf_sysctl_register(net, "all", NULL, all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7101) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7102) 		goto err_reg_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7104) 	err = __addrconf_sysctl_register(net, "default", NULL, dflt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7105) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7106) 		goto err_reg_dflt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7107) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7108) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7110) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7111) err_reg_dflt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7112) 	__addrconf_sysctl_unregister(net, all, NETCONFA_IFINDEX_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7113) err_reg_all:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7114) 	kfree(dflt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7115) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7116) err_alloc_dflt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7117) 	kfree(all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7118) err_alloc_all:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7119) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7122) static void __net_exit addrconf_exit_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7124) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7125) 	__addrconf_sysctl_unregister(net, net->ipv6.devconf_dflt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7126) 				     NETCONFA_IFINDEX_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7127) 	__addrconf_sysctl_unregister(net, net->ipv6.devconf_all,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7128) 				     NETCONFA_IFINDEX_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7129) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7130) 	kfree(net->ipv6.devconf_dflt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7131) 	kfree(net->ipv6.devconf_all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7134) static struct pernet_operations addrconf_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7135) 	.init = addrconf_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7136) 	.exit = addrconf_exit_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7139) static struct rtnl_af_ops inet6_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7140) 	.family		  = AF_INET6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7141) 	.fill_link_af	  = inet6_fill_link_af,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7142) 	.get_link_af_size = inet6_get_link_af_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7143) 	.validate_link_af = inet6_validate_link_af,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7144) 	.set_link_af	  = inet6_set_link_af,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7147) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7148)  *	Init / cleanup code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7149)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7151) int __init addrconf_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7153) 	struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7154) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7156) 	err = ipv6_addr_label_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7157) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7158) 		pr_crit("%s: cannot initialize default policy table: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7159) 			__func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7160) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7161) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7163) 	err = register_pernet_subsys(&addrconf_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7164) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7165) 		goto out_addrlabel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7167) 	addrconf_wq = create_workqueue("ipv6_addrconf");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7168) 	if (!addrconf_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7169) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7170) 		goto out_nowq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7173) 	/* The addrconf netdev notifier requires that loopback_dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7174) 	 * has it's ipv6 private information allocated and setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7175) 	 * before it can bring up and give link-local addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7176) 	 * to other devices which are up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7177) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7178) 	 * Unfortunately, loopback_dev is not necessarily the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7179) 	 * entry in the global dev_base list of net devices.  In fact,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7180) 	 * it is likely to be the very last entry on that list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7181) 	 * So this causes the notifier registry below to try and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7182) 	 * give link-local addresses to all devices besides loopback_dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7183) 	 * first, then loopback_dev, which cases all the non-loopback_dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7184) 	 * devices to fail to get a link-local address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7185) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7186) 	 * So, as a temporary fix, allocate the ipv6 structure for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7187) 	 * loopback_dev first by hand.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7188) 	 * Longer term, all of the dependencies ipv6 has upon the loopback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7189) 	 * device and it being up should be removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7190) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7191) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7192) 	idev = ipv6_add_dev(init_net.loopback_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7193) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7194) 	if (IS_ERR(idev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7195) 		err = PTR_ERR(idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7196) 		goto errlo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7199) 	ip6_route_init_special_entries();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7201) 	for (i = 0; i < IN6_ADDR_HSIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7202) 		INIT_HLIST_HEAD(&inet6_addr_lst[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7204) 	register_netdevice_notifier(&ipv6_dev_notf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7206) 	addrconf_verify();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7208) 	rtnl_af_register(&inet6_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7210) 	err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETLINK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7211) 				   NULL, inet6_dump_ifinfo, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7212) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7213) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7215) 	err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_NEWADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7216) 				   inet6_rtm_newaddr, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7217) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7218) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7219) 	err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_DELADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7220) 				   inet6_rtm_deladdr, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7221) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7222) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7223) 	err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7224) 				   inet6_rtm_getaddr, inet6_dump_ifaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7225) 				   RTNL_FLAG_DOIT_UNLOCKED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7226) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7227) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7228) 	err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETMULTICAST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7229) 				   NULL, inet6_dump_ifmcaddr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7230) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7231) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7232) 	err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETANYCAST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7233) 				   NULL, inet6_dump_ifacaddr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7234) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7235) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7236) 	err = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETNETCONF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7237) 				   inet6_netconf_get_devconf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7238) 				   inet6_netconf_dump_devconf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7239) 				   RTNL_FLAG_DOIT_UNLOCKED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7240) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7241) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7242) 	err = ipv6_addr_label_rtnl_register();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7243) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7244) 		goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7246) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7247) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7248) 	rtnl_unregister_all(PF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7249) 	rtnl_af_unregister(&inet6_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7250) 	unregister_netdevice_notifier(&ipv6_dev_notf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7251) errlo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7252) 	destroy_workqueue(addrconf_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7253) out_nowq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7254) 	unregister_pernet_subsys(&addrconf_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7255) out_addrlabel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7256) 	ipv6_addr_label_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7257) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7258) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7261) void addrconf_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7263) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7264) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7266) 	unregister_netdevice_notifier(&ipv6_dev_notf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7267) 	unregister_pernet_subsys(&addrconf_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7268) 	ipv6_addr_label_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7270) 	rtnl_af_unregister(&inet6_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7272) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7274) 	/* clean dev list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7275) 	for_each_netdev(&init_net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7276) 		if (__in6_dev_get(dev) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7277) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7278) 		addrconf_ifdown(dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7280) 	addrconf_ifdown(init_net.loopback_dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7282) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7283) 	 *	Check hash table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7284) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7285) 	spin_lock_bh(&addrconf_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7286) 	for (i = 0; i < IN6_ADDR_HSIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7287) 		WARN_ON(!hlist_empty(&inet6_addr_lst[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7288) 	spin_unlock_bh(&addrconf_hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7289) 	cancel_delayed_work(&addr_chk_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7290) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7292) 	destroy_workqueue(addrconf_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7293) }