~ubuntu-branches/ubuntu/trusty/linux-linaro-omap/trusty

« back to all changes in this revision

Viewing changes to drivers/net/tun.c

  • Committer: Package Import Robot
  • Author(s): John Rigby, John Rigby
  • Date: 2011-09-26 10:44:23 UTC
  • Revision ID: package-import@ubuntu.com-20110926104423-57i0gl3v99b3lkfg
Tags: 3.0.0-1007.9
[ John Rigby ]

Enable crypto modules and remove crypto-modules from
exclude-module files
LP: #826021

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
        gid_t                   group;
124
124
 
125
125
        struct net_device       *dev;
 
126
        u32                     set_features;
 
127
#define TUN_USER_FEATURES (NETIF_F_HW_CSUM|NETIF_F_TSO_ECN|NETIF_F_TSO| \
 
128
                          NETIF_F_TSO6|NETIF_F_UFO)
126
129
        struct fasync_struct    *fasync;
127
130
 
128
131
        struct tap_filter       txflt;
451
454
        return 0;
452
455
}
453
456
 
 
457
static u32 tun_net_fix_features(struct net_device *dev, u32 features)
 
458
{
 
459
        struct tun_struct *tun = netdev_priv(dev);
 
460
 
 
461
        return (features & tun->set_features) | (features & ~TUN_USER_FEATURES);
 
462
}
 
463
#ifdef CONFIG_NET_POLL_CONTROLLER
 
464
static void tun_poll_controller(struct net_device *dev)
 
465
{
 
466
        /*
 
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
 
476
         */
 
477
        return;
 
478
}
 
479
#endif
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,
 
489
#endif
460
490
};
461
491
 
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,
 
504
#endif
471
505
};
472
506
 
473
507
/* Initialize net device. */
494
528
                dev->netdev_ops = &tap_netdev_ops;
495
529
                /* Ethernet TAP Device */
496
530
                ether_setup(dev);
 
531
                dev->priv_flags &= ~IFF_TX_SKB_SHARING;
497
532
 
498
533
                random_ether_addr(dev->dev_addr);
499
534
 
628
663
                        kfree_skb(skb);
629
664
                        return -EINVAL;
630
665
                }
631
 
        } else if (tun->flags & TUN_NOCHECKSUM)
632
 
                skb->ip_summed = CHECKSUM_UNNECESSARY;
 
666
        }
633
667
 
634
668
        switch (tun->flags & TUN_TYPE_MASK) {
635
669
        case TUN_TUN_DEV:
1088
1122
 
1089
1123
                tun_net_init(dev);
1090
1124
 
1091
 
                if (strchr(dev->name, '%')) {
1092
 
                        err = dev_alloc_name(dev, dev->name);
1093
 
                        if (err < 0)
1094
 
                                goto err_free_sk;
1095
 
                }
 
1125
                dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST |
 
1126
                        TUN_USER_FEATURES;
 
1127
                dev->features = dev->hw_features;
1096
1128
 
1097
1129
                err = register_netdevice(tun->dev);
1098
1130
                if (err < 0)
1158
1190
 
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)
1162
1194
{
1163
 
        u32 old_features, features;
1164
 
 
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
1169
 
                                    |NETIF_F_UFO));
 
1195
        u32 features = 0;
1170
1196
 
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;
1174
1200
 
1175
1201
                if (arg & (TUN_F_TSO4|TUN_F_TSO6)) {
1195
1221
        if (arg)
1196
1222
                return -EINVAL;
1197
1223
 
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);
1201
1226
 
1202
1227
        return 0;
1203
1228
}
1262
1287
 
1263
1288
        case TUNSETNOCSUM:
1264
1289
                /* Disable/Enable checksum */
1265
 
                if (arg)
1266
 
                        tun->flags |= TUN_NOCHECKSUM;
1267
 
                else
1268
 
                        tun->flags &= ~TUN_NOCHECKSUM;
1269
1290
 
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");
1272
1294
                break;
1273
1295
 
1316
1338
                break;
1317
1339
#endif
1318
1340
        case TUNSETOFFLOAD:
1319
 
                ret = set_offload(tun->dev, arg);
 
1341
                ret = set_offload(tun, arg);
1320
1342
                break;
1321
1343
 
1322
1344
        case TUNSETTXFILTER:
1548
1570
{
1549
1571
        cmd->supported          = 0;
1550
1572
        cmd->advertising        = 0;
1551
 
        cmd->speed              = SPEED_10;
 
1573
        ethtool_cmd_speed_set(cmd, SPEED_10);
1552
1574
        cmd->duplex             = DUPLEX_FULL;
1553
1575
        cmd->port               = PORT_TP;
1554
1576
        cmd->phy_address        = 0;
1595
1617
#endif
1596
1618
}
1597
1619
 
1598
 
static u32 tun_get_rx_csum(struct net_device *dev)
1599
 
{
1600
 
        struct tun_struct *tun = netdev_priv(dev);
1601
 
        return (tun->flags & TUN_NOCHECKSUM) == 0;
1602
 
}
1603
 
 
1604
 
static int tun_set_rx_csum(struct net_device *dev, u32 data)
1605
 
{
1606
 
        struct tun_struct *tun = netdev_priv(dev);
1607
 
        if (data)
1608
 
                tun->flags &= ~TUN_NOCHECKSUM;
1609
 
        else
1610
 
                tun->flags |= TUN_NOCHECKSUM;
1611
 
        return 0;
1612
 
}
1613
 
 
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
1622
1626
};
1623
1627
 
1624
1628