Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 103217
b: refs/heads/master
c: 5228ddc
h: refs/heads/master
i:
  103215: 07dc556
v: v3
  • Loading branch information
Rusty Russell authored and David S. Miller committed Jul 3, 2008
1 parent fb659e6 commit 0fa9943
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 07240fd0902c872f044f523893364a1a24c9f278
refs/heads/master: 5228ddc98fa49b3cedab4024e269d62410a0d806
49 changes: 49 additions & 0 deletions trunk/drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,46 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
return err;
}

/* This is like a cut-down ethtool ops, except done via tun fd so no
* privs required. */
static int set_offload(struct net_device *dev, unsigned long arg)
{
unsigned int old_features, features;

old_features = dev->features;
/* Unset features, set them as we chew on the arg. */
features = (old_features & ~(NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST
|NETIF_F_TSO_ECN|NETIF_F_TSO|NETIF_F_TSO6));

if (arg & TUN_F_CSUM) {
features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST;
arg &= ~TUN_F_CSUM;

if (arg & (TUN_F_TSO4|TUN_F_TSO6)) {
if (arg & TUN_F_TSO_ECN) {
features |= NETIF_F_TSO_ECN;
arg &= ~TUN_F_TSO_ECN;
}
if (arg & TUN_F_TSO4)
features |= NETIF_F_TSO;
if (arg & TUN_F_TSO6)
features |= NETIF_F_TSO6;
arg &= ~(TUN_F_TSO4|TUN_F_TSO6);
}
}

/* This gives the user a way to test for new features in future by
* trying to set them. */
if (arg)
return -EINVAL;

dev->features = features;
if (old_features != dev->features)
netdev_features_change(dev);

return 0;
}

static int tun_chr_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
Expand Down Expand Up @@ -715,6 +755,15 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
break;
#endif

case TUNSETOFFLOAD:
{
int ret;
rtnl_lock();
ret = set_offload(tun->dev, arg);
rtnl_unlock();
return ret;
}

case SIOCGIFFLAGS:
ifr.ifr_flags = tun->if_flags;
if (copy_to_user( argp, &ifr, sizeof ifr))
Expand Down
7 changes: 7 additions & 0 deletions trunk/include/linux/if_tun.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@
#define TUNSETLINK _IOW('T', 205, int)
#define TUNSETGROUP _IOW('T', 206, int)
#define TUNGETFEATURES _IOR('T', 207, unsigned int)
#define TUNSETOFFLOAD _IOW('T', 208, unsigned int)

/* TUNSETIFF ifr flags */
#define IFF_TUN 0x0001
#define IFF_TAP 0x0002
#define IFF_NO_PI 0x1000
#define IFF_ONE_QUEUE 0x2000

/* Features for GSO (TUNSETOFFLOAD). */
#define TUN_F_CSUM 0x01 /* You can hand me unchecksummed packets. */
#define TUN_F_TSO4 0x02 /* I can handle TSO for IPv4 packets */
#define TUN_F_TSO6 0x04 /* I can handle TSO for IPv6 packets */
#define TUN_F_TSO_ECN 0x08 /* I can handle TSO with ECN bits. */

struct tun_pi {
unsigned short flags;
__be16 proto;
Expand Down

0 comments on commit 0fa9943

Please sign in to comment.