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)  *	Ioctl handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *	Linux ethernet bridge
^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)  *	Lennert Buytenhek		<buytenh@gnu.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/if_bridge.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/times.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "br_private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static int get_bridge_ifindices(struct net *net, int *indices, int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	for_each_netdev_rcu(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		if (i >= num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		if (dev->priv_flags & IFF_EBRIDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 			indices[i++] = dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	return i;
^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) /* called with RTNL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static void get_port_ifindices(struct net_bridge *br, int *ifindices, int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	list_for_each_entry(p, &br->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		if (p->port_no < num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			ifindices[p->port_no] = p->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * Format up to a page worth of forwarding table entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * userbuf -- where to copy result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * maxnum  -- maximum number of entries desired
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *            (limited to a page for sanity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * offset  -- number of records to skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static int get_fdb_entries(struct net_bridge *br, void __user *userbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			   unsigned long maxnum, unsigned long offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	int num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	/* Clamp size to PAGE_SIZE, test maxnum to avoid overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (maxnum > PAGE_SIZE/sizeof(struct __fdb_entry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		maxnum = PAGE_SIZE/sizeof(struct __fdb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	size = maxnum * sizeof(struct __fdb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	buf = kmalloc(size, GFP_USER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	num = br_fdb_fillbuf(br, buf, maxnum, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (num > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		if (copy_to_user(userbuf, buf, num*sizeof(struct __fdb_entry)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			num = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /* called with RTNL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int add_del_if(struct net_bridge *br, int ifindex, int isadd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct net *net = dev_net(br->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	dev = __dev_get_by_index(net, ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (dev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (isadd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		ret = br_add_if(br, dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		ret = br_del_if(br, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^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)  * Legacy ioctl's through SIOCDEVPRIVATE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * This interface is deprecated because it was too difficult
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * to do the translation for 32/64bit ioctl compatibility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int old_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct net_bridge_port *p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	unsigned long args[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	int ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	if (copy_from_user(args, rq->ifr_data, sizeof(args)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	switch (args[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	case BRCTL_ADD_IF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	case BRCTL_DEL_IF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return add_del_if(br, args[1], args[0] == BRCTL_ADD_IF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	case BRCTL_GET_BRIDGE_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		struct __bridge_info b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		memset(&b, 0, sizeof(struct __bridge_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		memcpy(&b.designated_root, &br->designated_root, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		memcpy(&b.bridge_id, &br->bridge_id, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		b.root_path_cost = br->root_path_cost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		b.max_age = jiffies_to_clock_t(br->max_age);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		b.hello_time = jiffies_to_clock_t(br->hello_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		b.forward_delay = br->forward_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		b.bridge_max_age = br->bridge_max_age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		b.bridge_hello_time = br->bridge_hello_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		b.bridge_forward_delay = jiffies_to_clock_t(br->bridge_forward_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		b.topology_change = br->topology_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		b.topology_change_detected = br->topology_change_detected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		b.root_port = br->root_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		b.stp_enabled = (br->stp_enabled != BR_NO_STP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		b.ageing_time = jiffies_to_clock_t(br->ageing_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		b.hello_timer_value = br_timer_value(&br->hello_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		b.tcn_timer_value = br_timer_value(&br->tcn_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		b.topology_change_timer_value = br_timer_value(&br->topology_change_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		b.gc_timer_value = br_timer_value(&br->gc_work.timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		if (copy_to_user((void __user *)args[1], &b, sizeof(b)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	case BRCTL_GET_PORT_LIST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		int num, *indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		num = args[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		if (num < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		if (num == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			num = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (num > BR_MAX_PORTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			num = BR_MAX_PORTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		indices = kcalloc(num, sizeof(int), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		if (indices == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		get_port_ifindices(br, indices, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		if (copy_to_user((void __user *)args[1], indices, num*sizeof(int)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			num =  -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		kfree(indices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	case BRCTL_SET_BRIDGE_FORWARD_DELAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		if (!ns_capable(dev_net(dev)->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		ret = br_set_forward_delay(br, args[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	case BRCTL_SET_BRIDGE_HELLO_TIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		if (!ns_capable(dev_net(dev)->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		ret = br_set_hello_time(br, args[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	case BRCTL_SET_BRIDGE_MAX_AGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		if (!ns_capable(dev_net(dev)->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		ret = br_set_max_age(br, args[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	case BRCTL_SET_AGEING_TIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		if (!ns_capable(dev_net(dev)->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		ret = br_set_ageing_time(br, args[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	case BRCTL_GET_PORT_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		struct __port_info p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		struct net_bridge_port *pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		if ((pt = br_get_port(br, args[2])) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		memset(&p, 0, sizeof(struct __port_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		memcpy(&p.designated_root, &pt->designated_root, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		memcpy(&p.designated_bridge, &pt->designated_bridge, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		p.port_id = pt->port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		p.designated_port = pt->designated_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		p.path_cost = pt->path_cost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		p.designated_cost = pt->designated_cost;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		p.state = pt->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		p.top_change_ack = pt->topology_change_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		p.config_pending = pt->config_pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		p.message_age_timer_value = br_timer_value(&pt->message_age_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		p.forward_delay_timer_value = br_timer_value(&pt->forward_delay_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		p.hold_timer_value = br_timer_value(&pt->hold_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		if (copy_to_user((void __user *)args[1], &p, sizeof(p)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	case BRCTL_SET_BRIDGE_STP_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		if (!ns_capable(dev_net(dev)->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		ret = br_stp_set_enabled(br, args[1], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	case BRCTL_SET_BRIDGE_PRIORITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		if (!ns_capable(dev_net(dev)->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		br_stp_set_bridge_priority(br, args[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	case BRCTL_SET_PORT_PRIORITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		if (!ns_capable(dev_net(dev)->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		spin_lock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		if ((p = br_get_port(br, args[1])) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			ret = br_stp_set_port_priority(p, args[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		spin_unlock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	case BRCTL_SET_PATH_COST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		if (!ns_capable(dev_net(dev)->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		spin_lock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		if ((p = br_get_port(br, args[1])) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			ret = br_stp_set_path_cost(p, args[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		spin_unlock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	case BRCTL_GET_FDB_ENTRIES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return get_fdb_entries(br, (void __user *)args[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 				       args[2], args[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			br_ifinfo_notify(RTM_NEWLINK, NULL, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			netdev_state_change(br->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static int old_deviceless(struct net *net, void __user *uarg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	unsigned long args[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (copy_from_user(args, uarg, sizeof(args)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	switch (args[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	case BRCTL_GET_VERSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		return BRCTL_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	case BRCTL_GET_BRIDGES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		int *indices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		if (args[2] >= 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		indices = kcalloc(args[2], sizeof(int), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		if (indices == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		args[2] = get_bridge_ifindices(net, indices, args[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		ret = copy_to_user((void __user *)args[1], indices, args[2]*sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			? -EFAULT : args[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		kfree(indices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	case BRCTL_ADD_BRIDGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	case BRCTL_DEL_BRIDGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		char buf[IFNAMSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		if (copy_from_user(buf, (void __user *)args[1], IFNAMSIZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		buf[IFNAMSIZ-1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		if (args[0] == BRCTL_ADD_BRIDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			return br_add_bridge(net, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		return br_del_bridge(net, buf);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, void __user *uarg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	case SIOCGIFBR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	case SIOCSIFBR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		return old_deviceless(net, uarg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	case SIOCBRADDBR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	case SIOCBRDELBR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		char buf[IFNAMSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		if (copy_from_user(buf, uarg, IFNAMSIZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		buf[IFNAMSIZ-1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		if (cmd == SIOCBRADDBR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			return br_add_bridge(net, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		return br_del_bridge(net, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	case SIOCDEVPRIVATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		return old_dev_ioctl(dev, rq, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	case SIOCBRADDIF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	case SIOCBRDELIF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		return add_del_if(br, rq->ifr_ifindex, cmd == SIOCBRADDIF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	br_debug(br, "Bridge does not support ioctl 0x%x\n", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }