457
static u32 tun_net_fix_features(struct net_device *dev, u32 features)
459
struct tun_struct *tun = netdev_priv(dev);
461
return (features & tun->set_features) | (features & ~TUN_USER_FEATURES);
463
#ifdef CONFIG_NET_POLL_CONTROLLER
464
static void tun_poll_controller(struct net_device *dev)
467
* Tun only receives frames when:
468
* 1) the char device endpoint gets data from user space
469
* 2) the tun socket gets a sendmsg call from user space
470
* Since both of those are syncronous operations, we are guaranteed
471
* never to have pending data when we poll for it
472
* so theres nothing to do here but return.
473
* We need this though so netpoll recognizes us as an interface that
474
* supports polling, which enables bridge devices in virt setups to
475
* still use netconsole
454
480
static const struct net_device_ops tun_netdev_ops = {
455
481
.ndo_uninit = tun_net_uninit,
456
482
.ndo_open = tun_net_open,
457
483
.ndo_stop = tun_net_close,
458
484
.ndo_start_xmit = tun_net_xmit,
459
485
.ndo_change_mtu = tun_net_change_mtu,
486
.ndo_fix_features = tun_net_fix_features,
487
#ifdef CONFIG_NET_POLL_CONTROLLER
488
.ndo_poll_controller = tun_poll_controller,
462
492
static const struct net_device_ops tap_netdev_ops = {
465
495
.ndo_stop = tun_net_close,
466
496
.ndo_start_xmit = tun_net_xmit,
467
497
.ndo_change_mtu = tun_net_change_mtu,
498
.ndo_fix_features = tun_net_fix_features,
468
499
.ndo_set_multicast_list = tun_net_mclist,
469
500
.ndo_set_mac_address = eth_mac_addr,
470
501
.ndo_validate_addr = eth_validate_addr,
502
#ifdef CONFIG_NET_POLL_CONTROLLER
503
.ndo_poll_controller = tun_poll_controller,
473
507
/* Initialize net device. */
1089
1123
tun_net_init(dev);
1091
if (strchr(dev->name, '%')) {
1092
err = dev_alloc_name(dev, dev->name);
1125
dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST |
1127
dev->features = dev->hw_features;
1097
1129
err = register_netdevice(tun->dev);
1159
1191
/* This is like a cut-down ethtool ops, except done via tun fd so no
1160
1192
* privs required. */
1161
static int set_offload(struct net_device *dev, unsigned long arg)
1193
static int set_offload(struct tun_struct *tun, unsigned long arg)
1163
u32 old_features, features;
1165
old_features = dev->features;
1166
/* Unset features, set them as we chew on the arg. */
1167
features = (old_features & ~(NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST
1168
|NETIF_F_TSO_ECN|NETIF_F_TSO|NETIF_F_TSO6
1171
1197
if (arg & TUN_F_CSUM) {
1172
features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST;
1198
features |= NETIF_F_HW_CSUM;
1173
1199
arg &= ~TUN_F_CSUM;
1175
1201
if (arg & (TUN_F_TSO4|TUN_F_TSO6)) {
1196
1222
return -EINVAL;
1198
dev->features = features;
1199
if (old_features != dev->features)
1200
netdev_features_change(dev);
1224
tun->set_features = features;
1225
netdev_update_features(tun->dev);
1263
1288
case TUNSETNOCSUM:
1264
1289
/* Disable/Enable checksum */
1266
tun->flags |= TUN_NOCHECKSUM;
1268
tun->flags &= ~TUN_NOCHECKSUM;
1270
tun_debug(KERN_INFO, tun, "checksum %s\n",
1291
/* [unimplemented] */
1292
tun_debug(KERN_INFO, tun, "ignored: set checksum %s\n",
1271
1293
arg ? "disabled" : "enabled");
1598
static u32 tun_get_rx_csum(struct net_device *dev)
1600
struct tun_struct *tun = netdev_priv(dev);
1601
return (tun->flags & TUN_NOCHECKSUM) == 0;
1604
static int tun_set_rx_csum(struct net_device *dev, u32 data)
1606
struct tun_struct *tun = netdev_priv(dev);
1608
tun->flags &= ~TUN_NOCHECKSUM;
1610
tun->flags |= TUN_NOCHECKSUM;
1614
1620
static const struct ethtool_ops tun_ethtool_ops = {
1615
1621
.get_settings = tun_get_settings,
1616
1622
.get_drvinfo = tun_get_drvinfo,
1617
1623
.get_msglevel = tun_get_msglevel,
1618
1624
.set_msglevel = tun_set_msglevel,
1619
1625
.get_link = ethtool_op_get_link,
1620
.get_rx_csum = tun_get_rx_csum,
1621
.set_rx_csum = tun_set_rx_csum