3 * Linux ethernet bridge
6 * Lennert Buytenhek <buytenh@gnu.org>
8 * $Id: br_ioctl.c,v 1.1.1.1 2005/04/11 02:51:12 jack 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/inetdevice.h>
19 #include <asm/uaccess.h>
20 #include "br_private.h"
22 static int br_ioctl_device(struct net_bridge *br,
36 struct net_device *dev;
39 dev = dev_get_by_index(arg0);
43 if (cmd == BRCTL_ADD_IF)
44 ret = br_add_if(br, dev);
46 ret = br_del_if(br, dev);
52 case BRCTL_GET_BRIDGE_INFO:
54 struct __bridge_info b;
56 memset(&b, 0, sizeof(struct __bridge_info));
57 memcpy(&b.designated_root, &br->designated_root, 8);
58 memcpy(&b.bridge_id, &br->bridge_id, 8);
59 b.root_path_cost = br->root_path_cost;
60 b.max_age = br->max_age;
61 b.hello_time = br->hello_time;
62 b.forward_delay = br->forward_delay;
63 b.bridge_max_age = br->bridge_max_age;
64 b.bridge_hello_time = br->bridge_hello_time;
65 b.bridge_forward_delay = br->bridge_forward_delay;
66 b.topology_change = br->topology_change;
67 b.topology_change_detected = br->topology_change_detected;
68 b.root_port = br->root_port;
69 b.stp_enabled = br->stp_enabled;
70 b.ageing_time = br->ageing_time;
71 b.gc_interval = br->gc_interval;
72 b.hello_timer_value = br_timer_get_residue(&br->hello_timer);
73 b.tcn_timer_value = br_timer_get_residue(&br->tcn_timer);
74 b.topology_change_timer_value = br_timer_get_residue(&br->topology_change_timer);
75 b.gc_timer_value = br_timer_get_residue(&br->gc_timer);
77 if (copy_to_user((void *)arg0, &b, sizeof(b)))
83 case BRCTL_GET_PORT_LIST:
91 br_get_port_ifindices(br, indices);
92 if (copy_to_user((void *)arg0, indices, 256*sizeof(int)))
98 case BRCTL_SET_BRIDGE_FORWARD_DELAY:
99 br->bridge_forward_delay = arg0;
100 if (br_is_root_bridge(br))
101 br->forward_delay = arg0;
104 case BRCTL_SET_BRIDGE_HELLO_TIME:
105 br->bridge_hello_time = arg0;
106 if (br_is_root_bridge(br))
107 br->hello_time = arg0;
110 case BRCTL_SET_BRIDGE_MAX_AGE:
111 br->bridge_max_age = arg0;
112 if (br_is_root_bridge(br))
116 case BRCTL_SET_AGEING_TIME:
117 br->ageing_time = arg0;
120 case BRCTL_SET_GC_INTERVAL:
121 br->gc_interval = arg0;
124 case BRCTL_GET_PORT_INFO:
126 struct __port_info p;
127 struct net_bridge_port *pt;
129 if ((pt = br_get_port(br, arg1)) == NULL)
132 memset(&p, 0, sizeof(struct __port_info));
133 memcpy(&p.designated_root, &pt->designated_root, 8);
134 memcpy(&p.designated_bridge, &pt->designated_bridge, 8);
135 //REX: added by kunimi
136 p.priority = pt->priority;
137 p.port_id = pt->port_id;
138 p.designated_port = pt->designated_port;
139 p.path_cost = pt->path_cost;
140 p.designated_cost = pt->designated_cost;
142 p.top_change_ack = pt->topology_change_ack;
143 p.config_pending = pt->config_pending;
144 p.message_age_timer_value = br_timer_get_residue(&pt->message_age_timer);
145 p.forward_delay_timer_value = br_timer_get_residue(&pt->forward_delay_timer);
146 p.hold_timer_value = br_timer_get_residue(&pt->hold_timer);
148 if (copy_to_user((void *)arg0, &p, sizeof(p)))
154 case BRCTL_SET_BRIDGE_STP_STATE:
155 br->stp_enabled = arg0?1:0;
158 case BRCTL_SET_BRIDGE_PRIORITY:
159 br_stp_set_bridge_priority(br, arg0);
162 case BRCTL_SET_PORT_PRIORITY:
164 struct net_bridge_port *p;
166 if ((p = br_get_port(br, arg0)) == NULL)
168 br_stp_set_port_priority(p, arg1);
172 case BRCTL_SET_PATH_COST:
174 struct net_bridge_port *p;
176 if ((p = br_get_port(br, arg0)) == NULL)
178 br_stp_set_path_cost(p, arg1);
182 case BRCTL_GET_FDB_ENTRIES:
183 return br_fdb_get_entries(br, (void *)arg0, arg1, arg2);
189 static int br_ioctl_deviceless(unsigned int cmd,
195 case BRCTL_GET_VERSION:
196 return BRCTL_VERSION;
198 case BRCTL_GET_BRIDGES:
208 arg1 = br_get_bridge_ifindices(indices, arg1);
209 if (copy_to_user((void *)arg0, indices, arg1*sizeof(int)))
215 case BRCTL_ADD_BRIDGE:
216 case BRCTL_DEL_BRIDGE:
220 if (copy_from_user(buf, (void *)arg0, IFNAMSIZ))
225 if (cmd == BRCTL_ADD_BRIDGE)
226 return br_add_bridge(buf);
228 return br_del_bridge(buf);
235 DECLARE_MUTEX(ioctl_mutex);
237 int br_ioctl_deviceless_stub(unsigned long arg)
242 if (!capable(CAP_NET_ADMIN))
245 if (copy_from_user(i, (void *)arg, 3*sizeof(unsigned long)))
249 err = br_ioctl_deviceless(i[0], i[1], i[2]);
255 int br_ioctl(struct net_bridge *br, unsigned int cmd, unsigned long arg0, unsigned long arg1, unsigned long arg2)
259 if (!capable(CAP_NET_ADMIN))
263 err = br_ioctl_deviceless(cmd, arg0, arg1);
264 if (err == -EOPNOTSUPP)
265 err = br_ioctl_device(br, cmd, arg0, arg1, arg2);
271 void br_call_ioctl_atomic(void (*fn)(void))