tun: drop most type defines

It's just as easy to use IFF_ flags directly,
there's no point in adding our own defines.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Michael S. Tsirkin 2014-11-19 15:17:31 +02:00
parent 031f5e0338
commit 40630b82c2

View file

@ -109,12 +109,6 @@ do { \
* overload it to mean fasync when stored there. * overload it to mean fasync when stored there.
*/ */
#define TUN_FASYNC IFF_ATTACH_QUEUE #define TUN_FASYNC IFF_ATTACH_QUEUE
#define TUN_NO_PI IFF_NO_PI
/* This flag has no real effect */
#define TUN_ONE_QUEUE IFF_ONE_QUEUE
#define TUN_PERSIST IFF_PERSIST
#define TUN_VNET_HDR IFF_VNET_HDR
#define TUN_TAP_MQ IFF_MULTI_QUEUE
#define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | \ #define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | \
IFF_MULTI_QUEUE) IFF_MULTI_QUEUE)
@ -487,7 +481,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
if (tun && tun->numqueues == 0 && tun->numdisabled == 0) { if (tun && tun->numqueues == 0 && tun->numdisabled == 0) {
netif_carrier_off(tun->dev); netif_carrier_off(tun->dev);
if (!(tun->flags & TUN_PERSIST) && if (!(tun->flags & IFF_PERSIST) &&
tun->dev->reg_state == NETREG_REGISTERED) tun->dev->reg_state == NETREG_REGISTERED)
unregister_netdevice(tun->dev); unregister_netdevice(tun->dev);
} }
@ -538,7 +532,7 @@ static void tun_detach_all(struct net_device *dev)
} }
BUG_ON(tun->numdisabled != 0); BUG_ON(tun->numdisabled != 0);
if (tun->flags & TUN_PERSIST) if (tun->flags & IFF_PERSIST)
module_put(THIS_MODULE); module_put(THIS_MODULE);
} }
@ -556,7 +550,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file, bool skip_filte
goto out; goto out;
err = -EBUSY; err = -EBUSY;
if (!(tun->flags & TUN_TAP_MQ) && tun->numqueues == 1) if (!(tun->flags & IFF_MULTI_QUEUE) && tun->numqueues == 1)
goto out; goto out;
err = -E2BIG; err = -E2BIG;
@ -935,7 +929,7 @@ static void tun_net_init(struct net_device *dev)
struct tun_struct *tun = netdev_priv(dev); struct tun_struct *tun = netdev_priv(dev);
switch (tun->flags & TUN_TYPE_MASK) { switch (tun->flags & TUN_TYPE_MASK) {
case TUN_TUN_DEV: case IFF_TUN:
dev->netdev_ops = &tun_netdev_ops; dev->netdev_ops = &tun_netdev_ops;
/* Point-to-Point TUN Device */ /* Point-to-Point TUN Device */
@ -949,7 +943,7 @@ static void tun_net_init(struct net_device *dev)
dev->tx_queue_len = TUN_READQ_SIZE; /* We prefer our own queue length */ dev->tx_queue_len = TUN_READQ_SIZE; /* We prefer our own queue length */
break; break;
case TUN_TAP_DEV: case IFF_TAP:
dev->netdev_ops = &tap_netdev_ops; dev->netdev_ops = &tap_netdev_ops;
/* Ethernet TAP Device */ /* Ethernet TAP Device */
ether_setup(dev); ether_setup(dev);
@ -1040,7 +1034,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
int err; int err;
u32 rxhash; u32 rxhash;
if (!(tun->flags & TUN_NO_PI)) { if (!(tun->flags & IFF_NO_PI)) {
if (len < sizeof(pi)) if (len < sizeof(pi))
return -EINVAL; return -EINVAL;
len -= sizeof(pi); len -= sizeof(pi);
@ -1050,7 +1044,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
offset += sizeof(pi); offset += sizeof(pi);
} }
if (tun->flags & TUN_VNET_HDR) { if (tun->flags & IFF_VNET_HDR) {
if (len < tun->vnet_hdr_sz) if (len < tun->vnet_hdr_sz)
return -EINVAL; return -EINVAL;
len -= tun->vnet_hdr_sz; len -= tun->vnet_hdr_sz;
@ -1067,7 +1061,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
offset += tun->vnet_hdr_sz; offset += tun->vnet_hdr_sz;
} }
if ((tun->flags & TUN_TYPE_MASK) == TUN_TAP_DEV) { if ((tun->flags & TUN_TYPE_MASK) == IFF_TAP) {
align += NET_IP_ALIGN; align += NET_IP_ALIGN;
if (unlikely(len < ETH_HLEN || if (unlikely(len < ETH_HLEN ||
(gso.hdr_len && gso.hdr_len < ETH_HLEN))) (gso.hdr_len && gso.hdr_len < ETH_HLEN)))
@ -1130,8 +1124,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
} }
switch (tun->flags & TUN_TYPE_MASK) { switch (tun->flags & TUN_TYPE_MASK) {
case TUN_TUN_DEV: case IFF_TUN:
if (tun->flags & TUN_NO_PI) { if (tun->flags & IFF_NO_PI) {
switch (skb->data[0] & 0xf0) { switch (skb->data[0] & 0xf0) {
case 0x40: case 0x40:
pi.proto = htons(ETH_P_IP); pi.proto = htons(ETH_P_IP);
@ -1150,7 +1144,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
skb->protocol = pi.proto; skb->protocol = pi.proto;
skb->dev = tun->dev; skb->dev = tun->dev;
break; break;
case TUN_TAP_DEV: case IFF_TAP:
skb->protocol = eth_type_trans(skb, tun->dev); skb->protocol = eth_type_trans(skb, tun->dev);
break; break;
} }
@ -1256,10 +1250,10 @@ static ssize_t tun_put_user(struct tun_struct *tun,
if (vlan_tx_tag_present(skb)) if (vlan_tx_tag_present(skb))
vlan_hlen = VLAN_HLEN; vlan_hlen = VLAN_HLEN;
if (tun->flags & TUN_VNET_HDR) if (tun->flags & IFF_VNET_HDR)
vnet_hdr_sz = tun->vnet_hdr_sz; vnet_hdr_sz = tun->vnet_hdr_sz;
if (!(tun->flags & TUN_NO_PI)) { if (!(tun->flags & IFF_NO_PI)) {
if ((len -= sizeof(pi)) < 0) if ((len -= sizeof(pi)) < 0)
return -EINVAL; return -EINVAL;
@ -1592,7 +1586,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
return -EINVAL; return -EINVAL;
if (!!(ifr->ifr_flags & IFF_MULTI_QUEUE) != if (!!(ifr->ifr_flags & IFF_MULTI_QUEUE) !=
!!(tun->flags & TUN_TAP_MQ)) !!(tun->flags & IFF_MULTI_QUEUE))
return -EINVAL; return -EINVAL;
if (tun_not_capable(tun)) if (tun_not_capable(tun))
@ -1605,7 +1599,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
if (err < 0) if (err < 0)
return err; return err;
if (tun->flags & TUN_TAP_MQ && if (tun->flags & IFF_MULTI_QUEUE &&
(tun->numqueues + tun->numdisabled > 1)) { (tun->numqueues + tun->numdisabled > 1)) {
/* One or more queue has already been attached, no need /* One or more queue has already been attached, no need
* to initialize the device again. * to initialize the device again.
@ -1628,11 +1622,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
/* Set dev type */ /* Set dev type */
if (ifr->ifr_flags & IFF_TUN) { if (ifr->ifr_flags & IFF_TUN) {
/* TUN device */ /* TUN device */
flags |= TUN_TUN_DEV; flags |= IFF_TUN;
name = "tun%d"; name = "tun%d";
} else if (ifr->ifr_flags & IFF_TAP) { } else if (ifr->ifr_flags & IFF_TAP) {
/* TAP device */ /* TAP device */
flags |= TUN_TAP_DEV; flags |= IFF_TAP;
name = "tap%d"; name = "tap%d";
} else } else
return -EINVAL; return -EINVAL;
@ -1825,7 +1819,7 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr)
ret = tun_attach(tun, file, false); ret = tun_attach(tun, file, false);
} else if (ifr->ifr_flags & IFF_DETACH_QUEUE) { } else if (ifr->ifr_flags & IFF_DETACH_QUEUE) {
tun = rtnl_dereference(tfile->tun); tun = rtnl_dereference(tfile->tun);
if (!tun || !(tun->flags & TUN_TAP_MQ) || tfile->detached) if (!tun || !(tun->flags & IFF_MULTI_QUEUE) || tfile->detached)
ret = -EINVAL; ret = -EINVAL;
else else
__tun_detach(tfile, false); __tun_detach(tfile, false);
@ -1929,12 +1923,12 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
/* Disable/Enable persist mode. Keep an extra reference to the /* Disable/Enable persist mode. Keep an extra reference to the
* module to prevent the module being unprobed. * module to prevent the module being unprobed.
*/ */
if (arg && !(tun->flags & TUN_PERSIST)) { if (arg && !(tun->flags & IFF_PERSIST)) {
tun->flags |= TUN_PERSIST; tun->flags |= IFF_PERSIST;
__module_get(THIS_MODULE); __module_get(THIS_MODULE);
} }
if (!arg && (tun->flags & TUN_PERSIST)) { if (!arg && (tun->flags & IFF_PERSIST)) {
tun->flags &= ~TUN_PERSIST; tun->flags &= ~IFF_PERSIST;
module_put(THIS_MODULE); module_put(THIS_MODULE);
} }
@ -1992,7 +1986,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
case TUNSETTXFILTER: case TUNSETTXFILTER:
/* Can be set only for TAPs */ /* Can be set only for TAPs */
ret = -EINVAL; ret = -EINVAL;
if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
break; break;
ret = update_filter(&tun->txflt, (void __user *)arg); ret = update_filter(&tun->txflt, (void __user *)arg);
break; break;
@ -2051,7 +2045,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
case TUNATTACHFILTER: case TUNATTACHFILTER:
/* Can be set only for TAPs */ /* Can be set only for TAPs */
ret = -EINVAL; ret = -EINVAL;
if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
break; break;
ret = -EFAULT; ret = -EFAULT;
if (copy_from_user(&tun->fprog, argp, sizeof(tun->fprog))) if (copy_from_user(&tun->fprog, argp, sizeof(tun->fprog)))
@ -2063,7 +2057,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
case TUNDETACHFILTER: case TUNDETACHFILTER:
/* Can be set only for TAPs */ /* Can be set only for TAPs */
ret = -EINVAL; ret = -EINVAL;
if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
break; break;
ret = 0; ret = 0;
tun_detach_filter(tun, tun->numqueues); tun_detach_filter(tun, tun->numqueues);
@ -2071,7 +2065,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
case TUNGETFILTER: case TUNGETFILTER:
ret = -EINVAL; ret = -EINVAL;
if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) if ((tun->flags & TUN_TYPE_MASK) != IFF_TAP)
break; break;
ret = -EFAULT; ret = -EFAULT;
if (copy_to_user(argp, &tun->fprog, sizeof(tun->fprog))) if (copy_to_user(argp, &tun->fprog, sizeof(tun->fprog)))
@ -2264,10 +2258,10 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info
strlcpy(info->version, DRV_VERSION, sizeof(info->version)); strlcpy(info->version, DRV_VERSION, sizeof(info->version));
switch (tun->flags & TUN_TYPE_MASK) { switch (tun->flags & TUN_TYPE_MASK) {
case TUN_TUN_DEV: case IFF_TUN:
strlcpy(info->bus_info, "tun", sizeof(info->bus_info)); strlcpy(info->bus_info, "tun", sizeof(info->bus_info));
break; break;
case TUN_TAP_DEV: case IFF_TAP:
strlcpy(info->bus_info, "tap", sizeof(info->bus_info)); strlcpy(info->bus_info, "tap", sizeof(info->bus_info));
break; break;
} }