~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to drivers/net/tun.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno
  • Date: 2011-06-07 12:14:05 UTC
  • mfrom: (43.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110607121405-i3h1rd7nrnd2b73h
Tags: 2.6.39-2
[ Ben Hutchings ]
* [x86] Enable BACKLIGHT_APPLE, replacing BACKLIGHT_MBP_NVIDIA
  (Closes: #627492)
* cgroups: Disable memory resource controller by default. Allow it
  to be enabled using kernel parameter 'cgroup_enable=memory'.
* rt2800usb: Enable support for more USB devices including
  Linksys WUSB600N (Closes: #596626) (this change was accidentally
  omitted from 2.6.39-1)
* [x86] Remove Celeron from list of processors supporting PAE. Most
  'Celeron M' models do not.
* Update debconf template translations:
  - Swedish (Martin Bagge) (Closes: #628932)
  - French (David Prévot) (Closes: #628191)
* aufs: Update for 2.6.39 (Closes: #627837)
* Add stable 2.6.39.1, including:
  - ext4: dont set PageUptodate in ext4_end_bio()
  - pata_cmd64x: fix boot crash on parisc (Closes: #622997, #622745)
  - ext3: Fix fs corruption when make_indexed_dir() fails
  - netfilter: nf_ct_sip: validate Content-Length in TCP SIP messages
  - sctp: fix race between sctp_bind_addr_free() and
    sctp_bind_addr_conflict()
  - sctp: fix memory leak of the ASCONF queue when free asoc
  - md/bitmap: fix saving of events_cleared and other state
  - cdc_acm: Fix oops when Droids MuIn LCD is connected
  - cx88: Fix conversion from BKL to fine-grained locks (Closes: #619827)
  - keys: Set cred->user_ns in key_replace_session_keyring (CVE-2011-2184)
  - tmpfs: fix race between truncate and writepage
  - nfs41: Correct offset for LAYOUTCOMMIT
  - xen/mmu: fix a race window causing leave_mm BUG()
  - ext4: fix possible use-after-free in ext4_remove_li_request()
  For the complete list of changes, see:
   http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.39.1
* Bump ABI to 2
* netfilter: Enable IP_SET, IP_SET_BITMAP_IP, IP_SET_BITMAP_IPMAC,
  IP_SET_BITMAP_PORT, IP_SET_HASH_IP, IP_SET_HASH_IPPORT,
  IP_SET_HASH_IPPORTIP, IP_SET_HASH_IPPORTNET, IP_SET_HASH_NET,
  IP_SET_HASH_NETPORT, IP_SET_LIST_SET, NETFILTER_XT_SET as modules
  (Closes: #629401)

[ Aurelien Jarno ]
* [mipsel/loongson-2f] Disable_SCSI_LPFC to workaround GCC ICE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 *    Modifications for 2.3.99-pre5 kernel.
35
35
 */
36
36
 
 
37
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
38
 
37
39
#define DRV_NAME        "tun"
38
40
#define DRV_VERSION     "1.6"
39
41
#define DRV_DESCRIPTION "Universal TUN/TAP device driver"
76
78
#ifdef TUN_DEBUG
77
79
static int debug;
78
80
 
79
 
#define DBG  if(tun->debug)printk
80
 
#define DBG1 if(debug==2)printk
 
81
#define tun_debug(level, tun, fmt, args...)                     \
 
82
do {                                                            \
 
83
        if (tun->debug)                                         \
 
84
                netdev_printk(level, tun->dev, fmt, ##args);    \
 
85
} while (0)
 
86
#define DBG1(level, fmt, args...)                               \
 
87
do {                                                            \
 
88
        if (debug == 2)                                         \
 
89
                printk(level fmt, ##args);                      \
 
90
} while (0)
81
91
#else
82
 
#define DBG( a... )
83
 
#define DBG1( a... )
 
92
#define tun_debug(level, tun, fmt, args...)                     \
 
93
do {                                                            \
 
94
        if (0)                                                  \
 
95
                netdev_printk(level, tun->dev, fmt, ##args);    \
 
96
} while (0)
 
97
#define DBG1(level, fmt, args...)                               \
 
98
do {                                                            \
 
99
        if (0)                                                  \
 
100
                printk(level fmt, ##args);                      \
 
101
} while (0)
84
102
#endif
85
103
 
86
104
#define FLT_EXACT_COUNT 8
205
223
                tun_detach(tfile->tun);
206
224
}
207
225
 
208
 
/* TAP filterting */
 
226
/* TAP filtering */
209
227
static void addr_hash_set(u32 *mask, const u8 *addr)
210
228
{
211
229
        int n = ether_crc(ETH_ALEN, addr) >> 26;
360
378
{
361
379
        struct tun_struct *tun = netdev_priv(dev);
362
380
 
363
 
        DBG(KERN_INFO "%s: tun_net_xmit %d\n", tun->dev->name, skb->len);
 
381
        tun_debug(KERN_INFO, tun, "tun_net_xmit %d\n", skb->len);
364
382
 
365
383
        /* Drop packet if interface is not attached */
366
384
        if (!tun->tfile)
499
517
 
500
518
        sk = tun->socket.sk;
501
519
 
502
 
        DBG(KERN_INFO "%s: tun_chr_poll\n", tun->dev->name);
 
520
        tun_debug(KERN_INFO, tun, "tun_chr_poll\n");
503
521
 
504
522
        poll_wait(file, &tun->wq.wait, wait);
505
523
 
690
708
        if (!tun)
691
709
                return -EBADFD;
692
710
 
693
 
        DBG(KERN_INFO "%s: tun_chr_write %ld\n", tun->dev->name, count);
 
711
        tun_debug(KERN_INFO, tun, "tun_chr_write %ld\n", count);
694
712
 
695
713
        result = tun_get_user(tun, iv, iov_length(iv, count),
696
714
                              file->f_flags & O_NONBLOCK);
739
757
                        else if (sinfo->gso_type & SKB_GSO_UDP)
740
758
                                gso.gso_type = VIRTIO_NET_HDR_GSO_UDP;
741
759
                        else {
742
 
                                printk(KERN_ERR "tun: unexpected GSO type: "
 
760
                                pr_err("unexpected GSO type: "
743
761
                                       "0x%x, gso_size %d, hdr_len %d\n",
744
762
                                       sinfo->gso_type, gso.gso_size,
745
763
                                       gso.hdr_len);
786
804
        struct sk_buff *skb;
787
805
        ssize_t ret = 0;
788
806
 
789
 
        DBG(KERN_INFO "%s: tun_chr_read\n", tun->dev->name);
 
807
        tun_debug(KERN_INFO, tun, "tun_chr_read\n");
790
808
 
791
809
        add_wait_queue(&tun->wq.wait, &wait);
792
810
        while (len) {
1083
1101
                if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
1084
1102
                    device_create_file(&tun->dev->dev, &dev_attr_owner) ||
1085
1103
                    device_create_file(&tun->dev->dev, &dev_attr_group))
1086
 
                        printk(KERN_ERR "Failed to create tun sysfs files\n");
 
1104
                        pr_err("Failed to create tun sysfs files\n");
1087
1105
 
1088
1106
                sk->sk_destruct = tun_sock_destruct;
1089
1107
 
1092
1110
                        goto failed;
1093
1111
        }
1094
1112
 
1095
 
        DBG(KERN_INFO "%s: tun_set_iff\n", tun->dev->name);
 
1113
        tun_debug(KERN_INFO, tun, "tun_set_iff\n");
1096
1114
 
1097
1115
        if (ifr->ifr_flags & IFF_NO_PI)
1098
1116
                tun->flags |= TUN_NO_PI;
1129
1147
static int tun_get_iff(struct net *net, struct tun_struct *tun,
1130
1148
                       struct ifreq *ifr)
1131
1149
{
1132
 
        DBG(KERN_INFO "%s: tun_get_iff\n", tun->dev->name);
 
1150
        tun_debug(KERN_INFO, tun, "tun_get_iff\n");
1133
1151
 
1134
1152
        strcpy(ifr->ifr_name, tun->dev->name);
1135
1153
 
1142
1160
 * privs required. */
1143
1161
static int set_offload(struct net_device *dev, unsigned long arg)
1144
1162
{
1145
 
        unsigned int old_features, features;
 
1163
        u32 old_features, features;
1146
1164
 
1147
1165
        old_features = dev->features;
1148
1166
        /* Unset features, set them as we chew on the arg. */
1229
1247
        if (!tun)
1230
1248
                goto unlock;
1231
1249
 
1232
 
        DBG(KERN_INFO "%s: tun_chr_ioctl cmd %d\n", tun->dev->name, cmd);
 
1250
        tun_debug(KERN_INFO, tun, "tun_chr_ioctl cmd %d\n", cmd);
1233
1251
 
1234
1252
        ret = 0;
1235
1253
        switch (cmd) {
1249
1267
                else
1250
1268
                        tun->flags &= ~TUN_NOCHECKSUM;
1251
1269
 
1252
 
                DBG(KERN_INFO "%s: checksum %s\n",
1253
 
                    tun->dev->name, arg ? "disabled" : "enabled");
 
1270
                tun_debug(KERN_INFO, tun, "checksum %s\n",
 
1271
                          arg ? "disabled" : "enabled");
1254
1272
                break;
1255
1273
 
1256
1274
        case TUNSETPERSIST:
1260
1278
                else
1261
1279
                        tun->flags &= ~TUN_PERSIST;
1262
1280
 
1263
 
                DBG(KERN_INFO "%s: persist %s\n",
1264
 
                    tun->dev->name, arg ? "enabled" : "disabled");
 
1281
                tun_debug(KERN_INFO, tun, "persist %s\n",
 
1282
                          arg ? "enabled" : "disabled");
1265
1283
                break;
1266
1284
 
1267
1285
        case TUNSETOWNER:
1268
1286
                /* Set owner of the device */
1269
1287
                tun->owner = (uid_t) arg;
1270
1288
 
1271
 
                DBG(KERN_INFO "%s: owner set to %d\n", tun->dev->name, tun->owner);
 
1289
                tun_debug(KERN_INFO, tun, "owner set to %d\n", tun->owner);
1272
1290
                break;
1273
1291
 
1274
1292
        case TUNSETGROUP:
1275
1293
                /* Set group of the device */
1276
1294
                tun->group= (gid_t) arg;
1277
1295
 
1278
 
                DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
 
1296
                tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
1279
1297
                break;
1280
1298
 
1281
1299
        case TUNSETLINK:
1282
1300
                /* Only allow setting the type when the interface is down */
1283
1301
                if (tun->dev->flags & IFF_UP) {
1284
 
                        DBG(KERN_INFO "%s: Linktype set failed because interface is up\n",
1285
 
                                tun->dev->name);
 
1302
                        tun_debug(KERN_INFO, tun,
 
1303
                                  "Linktype set failed because interface is up\n");
1286
1304
                        ret = -EBUSY;
1287
1305
                } else {
1288
1306
                        tun->dev->type = (int) arg;
1289
 
                        DBG(KERN_INFO "%s: linktype set to %d\n", tun->dev->name, tun->dev->type);
 
1307
                        tun_debug(KERN_INFO, tun, "linktype set to %d\n",
 
1308
                                  tun->dev->type);
1290
1309
                        ret = 0;
1291
1310
                }
1292
1311
                break;
1318
1337
 
1319
1338
        case SIOCSIFHWADDR:
1320
1339
                /* Set hw address */
1321
 
                DBG(KERN_DEBUG "%s: set hw address: %pM\n",
1322
 
                        tun->dev->name, ifr.ifr_hwaddr.sa_data);
 
1340
                tun_debug(KERN_DEBUG, tun, "set hw address: %pM\n",
 
1341
                          ifr.ifr_hwaddr.sa_data);
1323
1342
 
1324
1343
                ret = dev_set_mac_address(tun->dev, &ifr.ifr_hwaddr);
1325
1344
                break;
1433
1452
        if (!tun)
1434
1453
                return -EBADFD;
1435
1454
 
1436
 
        DBG(KERN_INFO "%s: tun_chr_fasync %d\n", tun->dev->name, on);
 
1455
        tun_debug(KERN_INFO, tun, "tun_chr_fasync %d\n", on);
1437
1456
 
1438
1457
        if ((ret = fasync_helper(fd, file, on, &tun->fasync)) < 0)
1439
1458
                goto out;
1455
1474
{
1456
1475
        struct tun_file *tfile;
1457
1476
 
1458
 
        DBG1(KERN_INFO "tunX: tun_chr_open\n");
 
1477
        DBG1(KERN_INFO, "tunX: tun_chr_open\n");
1459
1478
 
1460
1479
        tfile = kmalloc(sizeof(*tfile), GFP_KERNEL);
1461
1480
        if (!tfile)
1476
1495
        if (tun) {
1477
1496
                struct net_device *dev = tun->dev;
1478
1497
 
1479
 
                DBG(KERN_INFO "%s: tun_chr_close\n", dev->name);
 
1498
                tun_debug(KERN_INFO, tun, "tun_chr_close\n");
1480
1499
 
1481
1500
                __tun_detach(tun);
1482
1501
 
1607
1626
{
1608
1627
        int ret = 0;
1609
1628
 
1610
 
        printk(KERN_INFO "tun: %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
1611
 
        printk(KERN_INFO "tun: %s\n", DRV_COPYRIGHT);
 
1629
        pr_info("%s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
 
1630
        pr_info("%s\n", DRV_COPYRIGHT);
1612
1631
 
1613
1632
        ret = rtnl_link_register(&tun_link_ops);
1614
1633
        if (ret) {
1615
 
                printk(KERN_ERR "tun: Can't register link_ops\n");
 
1634
                pr_err("Can't register link_ops\n");
1616
1635
                goto err_linkops;
1617
1636
        }
1618
1637
 
1619
1638
        ret = misc_register(&tun_miscdev);
1620
1639
        if (ret) {
1621
 
                printk(KERN_ERR "tun: Can't register misc device %d\n", TUN_MINOR);
 
1640
                pr_err("Can't register misc device %d\n", TUN_MINOR);
1622
1641
                goto err_misc;
1623
1642
        }
1624
1643
        return  0;