3 * Linux ethernet bridge
6 * Lennert Buytenhek <buytenh@gnu.org>
8 * $Id: br_ioctl.c,v 1.4 2000/11/08 05:16:40 davem Exp $
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
16 #include <linux/kernel.h>
17 #include <linux/if_bridge.h>
18 #include <linux/netdevice.h>
19 #include <linux/times.h>
20 #include <asm/uaccess.h>
21 #include "br_private.h"
23 /* Report time remaining in user HZ */
24 static unsigned long timer_residue(const struct timer_list *timer)
26 return timer_pending(timer)
27 ? jiffies_to_clock_t(timer->expires - jiffies) : 0;
30 int br_ioctl_device(struct net_bridge *br, unsigned int cmd,
31 unsigned long arg0, unsigned long arg1, unsigned long arg2)
41 struct net_device *dev;
44 if (!capable(CAP_NET_ADMIN))
47 dev = dev_get_by_index(arg0);
51 if (cmd == BRCTL_ADD_IF)
52 ret = br_add_if(br, dev);
54 ret = br_del_if(br, dev);
60 case BRCTL_GET_BRIDGE_INFO:
62 struct __bridge_info b;
64 memset(&b, 0, sizeof(struct __bridge_info));
66 memcpy(&b.designated_root, &br->designated_root, 8);
67 memcpy(&b.bridge_id, &br->bridge_id, 8);
68 b.root_path_cost = br->root_path_cost;
69 b.max_age = jiffies_to_clock_t(br->max_age);
70 b.hello_time = jiffies_to_clock_t(br->hello_time);
71 b.forward_delay = br->forward_delay;
72 b.bridge_max_age = br->bridge_max_age;
73 b.bridge_hello_time = br->bridge_hello_time;
74 b.bridge_forward_delay = jiffies_to_clock_t(br->bridge_forward_delay);
75 b.topology_change = br->topology_change;
76 b.topology_change_detected = br->topology_change_detected;
77 b.root_port = br->root_port;
78 b.stp_enabled = br->stp_enabled;
79 b.ageing_time = jiffies_to_clock_t(br->ageing_time);
80 b.hello_timer_value = timer_residue(&br->hello_timer);
81 b.tcn_timer_value = timer_residue(&br->tcn_timer);
82 b.topology_change_timer_value = timer_residue(&br->topology_change_timer);
83 b.gc_timer_value = timer_residue(&br->gc_timer);
86 if (copy_to_user((void *)arg0, &b, sizeof(b)))
92 case BRCTL_GET_PORT_LIST:
101 if (num > BR_MAX_PORTS)
104 indices = kmalloc(num*sizeof(int), GFP_KERNEL);
108 memset(indices, 0, num*sizeof(int));
110 br_get_port_ifindices(br, indices, num);
111 if (copy_to_user((void *)arg0, indices, num*sizeof(int)))
117 case BRCTL_SET_BRIDGE_FORWARD_DELAY:
118 if (!capable(CAP_NET_ADMIN))
121 spin_lock_bh(&br->lock);
122 br->bridge_forward_delay = clock_t_to_jiffies(arg0);
123 if (br_is_root_bridge(br))
124 br->forward_delay = br->bridge_forward_delay;
125 spin_unlock_bh(&br->lock);
128 case BRCTL_SET_BRIDGE_HELLO_TIME:
129 if (!capable(CAP_NET_ADMIN))
132 spin_lock_bh(&br->lock);
133 br->bridge_hello_time = clock_t_to_jiffies(arg0);
134 if (br_is_root_bridge(br))
135 br->hello_time = br->bridge_hello_time;
136 spin_unlock_bh(&br->lock);
139 case BRCTL_SET_BRIDGE_MAX_AGE:
140 if (!capable(CAP_NET_ADMIN))
143 spin_lock_bh(&br->lock);
144 br->bridge_max_age = clock_t_to_jiffies(arg0);
145 if (br_is_root_bridge(br))
146 br->max_age = br->bridge_max_age;
147 spin_unlock_bh(&br->lock);
150 case BRCTL_SET_AGEING_TIME:
151 if (!capable(CAP_NET_ADMIN))
154 br->ageing_time = clock_t_to_jiffies(arg0);
157 case BRCTL_GET_PORT_INFO:
159 struct __port_info p;
160 struct net_bridge_port *pt;
163 if ((pt = br_get_port(br, arg1)) == NULL) {
168 memset(&p, 0, sizeof(struct __port_info));
169 memcpy(&p.designated_root, &pt->designated_root, 8);
170 memcpy(&p.designated_bridge, &pt->designated_bridge, 8);
171 p.port_id = pt->port_id;
172 p.designated_port = pt->designated_port;
173 p.path_cost = pt->path_cost;
174 p.designated_cost = pt->designated_cost;
176 p.top_change_ack = pt->topology_change_ack;
177 p.config_pending = pt->config_pending;
178 p.message_age_timer_value = timer_residue(&pt->message_age_timer);
179 p.forward_delay_timer_value = timer_residue(&pt->forward_delay_timer);
180 p.hold_timer_value = timer_residue(&pt->hold_timer);
184 if (copy_to_user((void *)arg0, &p, sizeof(p)))
190 case BRCTL_SET_BRIDGE_STP_STATE:
191 if (!capable(CAP_NET_ADMIN))
194 br->stp_enabled = arg0?1:0;
197 case BRCTL_SET_BRIDGE_PRIORITY:
198 if (!capable(CAP_NET_ADMIN))
201 spin_lock_bh(&br->lock);
202 br_stp_set_bridge_priority(br, arg0);
203 spin_unlock_bh(&br->lock);
206 case BRCTL_SET_PORT_PRIORITY:
208 struct net_bridge_port *p;
211 if (!capable(CAP_NET_ADMIN))
214 if (arg1 >= (1<<(16-BR_PORT_BITS)))
217 spin_lock_bh(&br->lock);
218 if ((p = br_get_port(br, arg0)) == NULL)
221 br_stp_set_port_priority(p, arg1);
222 spin_unlock_bh(&br->lock);
226 case BRCTL_SET_PATH_COST:
228 struct net_bridge_port *p;
231 if (!capable(CAP_NET_ADMIN))
234 spin_lock_bh(&br->lock);
235 if ((p = br_get_port(br, arg0)) == NULL)
238 br_stp_set_path_cost(p, arg1);
239 spin_unlock_bh(&br->lock);
243 case BRCTL_GET_FDB_ENTRIES:
244 return br_fdb_get_entries(br, (void *)arg0, arg1, arg2);
250 static int br_ioctl_deviceless(unsigned int cmd,
256 case BRCTL_GET_VERSION:
257 return BRCTL_VERSION;
259 case BRCTL_GET_BRIDGES:
264 indices = kmalloc(arg1*sizeof(int), GFP_KERNEL);
268 memset(indices, 0, arg1*sizeof(int));
269 arg1 = br_get_bridge_ifindices(indices, arg1);
271 ret = copy_to_user((void *)arg0, indices, arg1*sizeof(int))
278 case BRCTL_ADD_BRIDGE:
279 case BRCTL_DEL_BRIDGE:
283 if (!capable(CAP_NET_ADMIN))
286 if (copy_from_user(buf, (void *)arg0, IFNAMSIZ))
291 if (cmd == BRCTL_ADD_BRIDGE)
292 return br_add_bridge(buf);
294 return br_del_bridge(buf);
302 int br_ioctl_deviceless_stub(unsigned long arg)
306 if (copy_from_user(i, (void *)arg, 3*sizeof(unsigned long)))
309 return br_ioctl_deviceless(i[0], i[1], i[2]);