Skip to content

Commit ad2f99a

Browse files
arndbdavem330
authored andcommitted
net: bridge: move bridge ioctls out of .ndo_do_ioctl
Working towards obsoleting the .ndo_do_ioctl operation entirely, stop passing the SIOCBRADDIF/SIOCBRDELIF device ioctl commands into this callback. My first attempt was to add another ndo_siocbr() callback, but as there is only a single driver that takes these commands and there is already a hook mechanism to call directly into this driver, extend this hook instead, and use it for both the deviceless and the device specific ioctl commands. Cc: Roopa Prabhu <[email protected]> Cc: Nikolay Aleksandrov <[email protected]> Cc: [email protected] Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 88fc023 commit ad2f99a

File tree

7 files changed

+43
-31
lines changed

7 files changed

+43
-31
lines changed

include/linux/if_bridge.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ struct br_ip_list {
6161

6262
#define BR_DEFAULT_AGEING_TIME (300 * HZ)
6363

64-
extern void brioctl_set(int (*ioctl_hook)(struct net *, unsigned int, void __user *));
64+
struct net_bridge;
65+
void brioctl_set(int (*hook)(struct net *net, struct net_bridge *br,
66+
unsigned int cmd, struct ifreq *ifr,
67+
void __user *uarg));
68+
int br_ioctl_call(struct net *net, struct net_bridge *br, unsigned int cmd,
69+
struct ifreq *ifr, void __user *uarg);
6570

6671
#if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_IGMP_SNOOPING)
6772
int br_multicast_list_adjacent(struct net_device *dev,

net/bridge/br.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ static int __init br_init(void)
359359
if (err)
360360
goto err_out5;
361361

362-
brioctl_set(br_ioctl_deviceless_stub);
362+
brioctl_set(br_ioctl_stub);
363363

364364
#if IS_ENABLED(CONFIG_ATM_LANE)
365365
br_fdb_test_addr_hook = br_fdb_test_addr;

net/bridge/br_device.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ static const struct net_device_ops br_netdev_ops = {
454454
.ndo_set_rx_mode = br_dev_set_multicast_list,
455455
.ndo_change_rx_flags = br_dev_change_rx_flags,
456456
.ndo_change_mtu = br_change_mtu,
457-
.ndo_do_ioctl = br_dev_ioctl,
458457
.ndo_siocdevprivate = br_dev_siocdevprivate,
459458
#ifdef CONFIG_NET_POLL_CONTROLLER
460459
.ndo_netpoll_setup = br_netpoll_setup,

net/bridge/br_ioctl.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ static int old_deviceless(struct net *net, void __user *uarg)
366366
return -EOPNOTSUPP;
367367
}
368368

369-
int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, void __user *uarg)
369+
int br_ioctl_stub(struct net *net, struct net_bridge *br, unsigned int cmd,
370+
struct ifreq *ifr, void __user *uarg)
370371
{
371372
switch (cmd) {
372373
case SIOCGIFBR:
@@ -390,21 +391,11 @@ int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, void __user *uar
390391

391392
return br_del_bridge(net, buf);
392393
}
393-
}
394-
return -EOPNOTSUPP;
395-
}
396-
397-
int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
398-
{
399-
struct net_bridge *br = netdev_priv(dev);
400394

401-
switch (cmd) {
402395
case SIOCBRADDIF:
403396
case SIOCBRDELIF:
404-
return add_del_if(br, rq->ifr_ifindex, cmd == SIOCBRADDIF);
397+
return add_del_if(br, ifr->ifr_ifindex, cmd == SIOCBRADDIF);
405398

406399
}
407-
408-
br_debug(br, "Bridge does not support ioctl 0x%x\n", cmd);
409400
return -EOPNOTSUPP;
410401
}

net/bridge/br_private.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,10 @@ br_port_get_check_rtnl(const struct net_device *dev)
851851
}
852852

853853
/* br_ioctl.c */
854-
int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
855854
int br_dev_siocdevprivate(struct net_device *dev, struct ifreq *rq,
856855
void __user *data, int cmd);
857-
int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd,
858-
void __user *arg);
856+
int br_ioctl_stub(struct net *net, struct net_bridge *br, unsigned int cmd,
857+
struct ifreq *ifr, void __user *uarg);
859858

860859
/* br_multicast.c */
861860
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING

net/core/dev_ioctl.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/rtnetlink.h>
77
#include <linux/net_tstamp.h>
88
#include <linux/wireless.h>
9+
#include <linux/if_bridge.h>
910
#include <net/dsa.h>
1011
#include <net/wext.h>
1112

@@ -374,6 +375,12 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data,
374375
case SIOCWANDEV:
375376
return dev_siocwandev(dev, &ifr->ifr_settings);
376377

378+
case SIOCBRADDIF:
379+
case SIOCBRDELIF:
380+
if (!netif_device_present(dev))
381+
return -ENODEV;
382+
return br_ioctl_call(net, netdev_priv(dev), cmd, ifr, NULL);
383+
377384
case SIOCSHWTSTAMP:
378385
err = net_hwtstamp_validate(ifr);
379386
if (err)
@@ -399,9 +406,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data,
399406
cmd == SIOCBONDSETHWADDR ||
400407
cmd == SIOCBONDSLAVEINFOQUERY ||
401408
cmd == SIOCBONDINFOQUERY ||
402-
cmd == SIOCBONDCHANGEACTIVE ||
403-
cmd == SIOCBRADDIF ||
404-
cmd == SIOCBRDELIF) {
409+
cmd == SIOCBONDCHANGEACTIVE) {
405410
err = dev_do_ioctl(dev, ifr, cmd);
406411
} else
407412
err = -EINVAL;

net/socket.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,16 +1064,36 @@ static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from)
10641064
*/
10651065

10661066
static DEFINE_MUTEX(br_ioctl_mutex);
1067-
static int (*br_ioctl_hook) (struct net *, unsigned int cmd, void __user *arg);
1067+
static int (*br_ioctl_hook)(struct net *net, struct net_bridge *br,
1068+
unsigned int cmd, struct ifreq *ifr,
1069+
void __user *uarg);
10681070

1069-
void brioctl_set(int (*hook) (struct net *, unsigned int, void __user *))
1071+
void brioctl_set(int (*hook)(struct net *net, struct net_bridge *br,
1072+
unsigned int cmd, struct ifreq *ifr,
1073+
void __user *uarg))
10701074
{
10711075
mutex_lock(&br_ioctl_mutex);
10721076
br_ioctl_hook = hook;
10731077
mutex_unlock(&br_ioctl_mutex);
10741078
}
10751079
EXPORT_SYMBOL(brioctl_set);
10761080

1081+
int br_ioctl_call(struct net *net, struct net_bridge *br, unsigned int cmd,
1082+
struct ifreq *ifr, void __user *uarg)
1083+
{
1084+
int err = -ENOPKG;
1085+
1086+
if (!br_ioctl_hook)
1087+
request_module("bridge");
1088+
1089+
mutex_lock(&br_ioctl_mutex);
1090+
if (br_ioctl_hook)
1091+
err = br_ioctl_hook(net, br, cmd, ifr, uarg);
1092+
mutex_unlock(&br_ioctl_mutex);
1093+
1094+
return err;
1095+
}
1096+
10771097
static DEFINE_MUTEX(vlan_ioctl_mutex);
10781098
static int (*vlan_ioctl_hook) (struct net *, void __user *arg);
10791099

@@ -1162,14 +1182,7 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
11621182
case SIOCSIFBR:
11631183
case SIOCBRADDBR:
11641184
case SIOCBRDELBR:
1165-
err = -ENOPKG;
1166-
if (!br_ioctl_hook)
1167-
request_module("bridge");
1168-
1169-
mutex_lock(&br_ioctl_mutex);
1170-
if (br_ioctl_hook)
1171-
err = br_ioctl_hook(net, cmd, argp);
1172-
mutex_unlock(&br_ioctl_mutex);
1185+
err = br_ioctl_call(net, NULL, cmd, NULL, argp);
11731186
break;
11741187
case SIOCGIFVLAN:
11751188
case SIOCSIFVLAN:

0 commit comments

Comments
 (0)