aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/tun.c
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2011-03-02 02:18:10 -0500
committerDavid S. Miller <davem@davemloft.net>2011-03-03 15:21:14 -0500
commit6b8a66ee919e40111e3d257b2c22b5773e34ead1 (patch)
treed8cb1d278ae51402c2f509f1049239c8e05dcb3d /drivers/net/tun.c
parent8d77c036b57cf813d838f859e11b6a188acdb1fb (diff)
tun: Convert logging messages to pr_<level> and tun_debug
Use the current logging forms with pr_fmt. Convert DBG macro to tun_debug, use netdev_printk as well. Add printf verification when TUN_DEBUG not defined. Miscellaneous comment typo fix. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r--drivers/net/tun.c83
1 files changed, 51 insertions, 32 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 55786a0efc41..f5e9ac00a07b 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -34,6 +34,8 @@
34 * Modifications for 2.3.99-pre5 kernel. 34 * Modifications for 2.3.99-pre5 kernel.
35 */ 35 */
36 36
37#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38
37#define DRV_NAME "tun" 39#define DRV_NAME "tun"
38#define DRV_VERSION "1.6" 40#define DRV_VERSION "1.6"
39#define DRV_DESCRIPTION "Universal TUN/TAP device driver" 41#define DRV_DESCRIPTION "Universal TUN/TAP device driver"
@@ -76,11 +78,27 @@
76#ifdef TUN_DEBUG 78#ifdef TUN_DEBUG
77static int debug; 79static int debug;
78 80
79#define DBG if(tun->debug)printk 81#define tun_debug(level, tun, fmt, args...) \
80#define DBG1 if(debug==2)printk 82do { \
83 if (tun->debug) \
84 netdev_printk(level, tun->dev, fmt, ##args); \
85} while (0)
86#define DBG1(level, fmt, args...) \
87do { \
88 if (debug == 2) \
89 printk(level fmt, ##args); \
90} while (0)
81#else 91#else
82#define DBG( a... ) 92#define tun_debug(level, tun, fmt, args...) \
83#define DBG1( a... ) 93do { \
94 if (0) \
95 netdev_printk(level, tun->dev, fmt, ##args); \
96} while (0)
97#define DBG1(level, fmt, args...) \
98do { \
99 if (0) \
100 printk(level fmt, ##args); \
101} while (0)
84#endif 102#endif
85 103
86#define FLT_EXACT_COUNT 8 104#define FLT_EXACT_COUNT 8
@@ -205,7 +223,7 @@ static void tun_put(struct tun_struct *tun)
205 tun_detach(tfile->tun); 223 tun_detach(tfile->tun);
206} 224}
207 225
208/* TAP filterting */ 226/* TAP filtering */
209static void addr_hash_set(u32 *mask, const u8 *addr) 227static void addr_hash_set(u32 *mask, const u8 *addr)
210{ 228{
211 int n = ether_crc(ETH_ALEN, addr) >> 26; 229 int n = ether_crc(ETH_ALEN, addr) >> 26;
@@ -360,7 +378,7 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev)
360{ 378{
361 struct tun_struct *tun = netdev_priv(dev); 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 /* Drop packet if interface is not attached */ 383 /* Drop packet if interface is not attached */
366 if (!tun->tfile) 384 if (!tun->tfile)
@@ -499,7 +517,7 @@ static unsigned int tun_chr_poll(struct file *file, poll_table * wait)
499 517
500 sk = tun->socket.sk; 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 poll_wait(file, &tun->wq.wait, wait); 522 poll_wait(file, &tun->wq.wait, wait);
505 523
@@ -690,7 +708,7 @@ static ssize_t tun_chr_aio_write(struct kiocb *iocb, const struct iovec *iv,
690 if (!tun) 708 if (!tun)
691 return -EBADFD; 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 result = tun_get_user(tun, iv, iov_length(iv, count), 713 result = tun_get_user(tun, iv, iov_length(iv, count),
696 file->f_flags & O_NONBLOCK); 714 file->f_flags & O_NONBLOCK);
@@ -739,7 +757,7 @@ static __inline__ ssize_t tun_put_user(struct tun_struct *tun,
739 else if (sinfo->gso_type & SKB_GSO_UDP) 757 else if (sinfo->gso_type & SKB_GSO_UDP)
740 gso.gso_type = VIRTIO_NET_HDR_GSO_UDP; 758 gso.gso_type = VIRTIO_NET_HDR_GSO_UDP;
741 else { 759 else {
742 printk(KERN_ERR "tun: unexpected GSO type: " 760 pr_err("unexpected GSO type: "
743 "0x%x, gso_size %d, hdr_len %d\n", 761 "0x%x, gso_size %d, hdr_len %d\n",
744 sinfo->gso_type, gso.gso_size, 762 sinfo->gso_type, gso.gso_size,
745 gso.hdr_len); 763 gso.hdr_len);
@@ -786,7 +804,7 @@ static ssize_t tun_do_read(struct tun_struct *tun,
786 struct sk_buff *skb; 804 struct sk_buff *skb;
787 ssize_t ret = 0; 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 add_wait_queue(&tun->wq.wait, &wait); 809 add_wait_queue(&tun->wq.wait, &wait);
792 while (len) { 810 while (len) {
@@ -1083,7 +1101,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1083 if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) || 1101 if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
1084 device_create_file(&tun->dev->dev, &dev_attr_owner) || 1102 device_create_file(&tun->dev->dev, &dev_attr_owner) ||
1085 device_create_file(&tun->dev->dev, &dev_attr_group)) 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 sk->sk_destruct = tun_sock_destruct; 1106 sk->sk_destruct = tun_sock_destruct;
1089 1107
@@ -1092,7 +1110,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1092 goto failed; 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 if (ifr->ifr_flags & IFF_NO_PI) 1115 if (ifr->ifr_flags & IFF_NO_PI)
1098 tun->flags |= TUN_NO_PI; 1116 tun->flags |= TUN_NO_PI;
@@ -1129,7 +1147,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
1129static int tun_get_iff(struct net *net, struct tun_struct *tun, 1147static int tun_get_iff(struct net *net, struct tun_struct *tun,
1130 struct ifreq *ifr) 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 strcpy(ifr->ifr_name, tun->dev->name); 1152 strcpy(ifr->ifr_name, tun->dev->name);
1135 1153
@@ -1229,7 +1247,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
1229 if (!tun) 1247 if (!tun)
1230 goto unlock; 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 ret = 0; 1252 ret = 0;
1235 switch (cmd) { 1253 switch (cmd) {
@@ -1249,8 +1267,8 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
1249 else 1267 else
1250 tun->flags &= ~TUN_NOCHECKSUM; 1268 tun->flags &= ~TUN_NOCHECKSUM;
1251 1269
1252 DBG(KERN_INFO "%s: checksum %s\n", 1270 tun_debug(KERN_INFO, tun, "checksum %s\n",
1253 tun->dev->name, arg ? "disabled" : "enabled"); 1271 arg ? "disabled" : "enabled");
1254 break; 1272 break;
1255 1273
1256 case TUNSETPERSIST: 1274 case TUNSETPERSIST:
@@ -1260,33 +1278,34 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
1260 else 1278 else
1261 tun->flags &= ~TUN_PERSIST; 1279 tun->flags &= ~TUN_PERSIST;
1262 1280
1263 DBG(KERN_INFO "%s: persist %s\n", 1281 tun_debug(KERN_INFO, tun, "persist %s\n",
1264 tun->dev->name, arg ? "enabled" : "disabled"); 1282 arg ? "enabled" : "disabled");
1265 break; 1283 break;
1266 1284
1267 case TUNSETOWNER: 1285 case TUNSETOWNER:
1268 /* Set owner of the device */ 1286 /* Set owner of the device */
1269 tun->owner = (uid_t) arg; 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 break; 1290 break;
1273 1291
1274 case TUNSETGROUP: 1292 case TUNSETGROUP:
1275 /* Set group of the device */ 1293 /* Set group of the device */
1276 tun->group= (gid_t) arg; 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 break; 1297 break;
1280 1298
1281 case TUNSETLINK: 1299 case TUNSETLINK:
1282 /* Only allow setting the type when the interface is down */ 1300 /* Only allow setting the type when the interface is down */
1283 if (tun->dev->flags & IFF_UP) { 1301 if (tun->dev->flags & IFF_UP) {
1284 DBG(KERN_INFO "%s: Linktype set failed because interface is up\n", 1302 tun_debug(KERN_INFO, tun,
1285 tun->dev->name); 1303 "Linktype set failed because interface is up\n");
1286 ret = -EBUSY; 1304 ret = -EBUSY;
1287 } else { 1305 } else {
1288 tun->dev->type = (int) arg; 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 ret = 0; 1309 ret = 0;
1291 } 1310 }
1292 break; 1311 break;
@@ -1318,8 +1337,8 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
1318 1337
1319 case SIOCSIFHWADDR: 1338 case SIOCSIFHWADDR:
1320 /* Set hw address */ 1339 /* Set hw address */
1321 DBG(KERN_DEBUG "%s: set hw address: %pM\n", 1340 tun_debug(KERN_DEBUG, tun, "set hw address: %pM\n",
1322 tun->dev->name, ifr.ifr_hwaddr.sa_data); 1341 ifr.ifr_hwaddr.sa_data);
1323 1342
1324 ret = dev_set_mac_address(tun->dev, &ifr.ifr_hwaddr); 1343 ret = dev_set_mac_address(tun->dev, &ifr.ifr_hwaddr);
1325 break; 1344 break;
@@ -1433,7 +1452,7 @@ static int tun_chr_fasync(int fd, struct file *file, int on)
1433 if (!tun) 1452 if (!tun)
1434 return -EBADFD; 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 if ((ret = fasync_helper(fd, file, on, &tun->fasync)) < 0) 1457 if ((ret = fasync_helper(fd, file, on, &tun->fasync)) < 0)
1439 goto out; 1458 goto out;
@@ -1455,7 +1474,7 @@ static int tun_chr_open(struct inode *inode, struct file * file)
1455{ 1474{
1456 struct tun_file *tfile; 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 tfile = kmalloc(sizeof(*tfile), GFP_KERNEL); 1479 tfile = kmalloc(sizeof(*tfile), GFP_KERNEL);
1461 if (!tfile) 1480 if (!tfile)
@@ -1476,7 +1495,7 @@ static int tun_chr_close(struct inode *inode, struct file *file)
1476 if (tun) { 1495 if (tun) {
1477 struct net_device *dev = tun->dev; 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 __tun_detach(tun); 1500 __tun_detach(tun);
1482 1501
@@ -1607,18 +1626,18 @@ static int __init tun_init(void)
1607{ 1626{
1608 int ret = 0; 1627 int ret = 0;
1609 1628
1610 printk(KERN_INFO "tun: %s, %s\n", DRV_DESCRIPTION, DRV_VERSION); 1629 pr_info("%s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
1611 printk(KERN_INFO "tun: %s\n", DRV_COPYRIGHT); 1630 pr_info("%s\n", DRV_COPYRIGHT);
1612 1631
1613 ret = rtnl_link_register(&tun_link_ops); 1632 ret = rtnl_link_register(&tun_link_ops);
1614 if (ret) { 1633 if (ret) {
1615 printk(KERN_ERR "tun: Can't register link_ops\n"); 1634 pr_err("Can't register link_ops\n");
1616 goto err_linkops; 1635 goto err_linkops;
1617 } 1636 }
1618 1637
1619 ret = misc_register(&tun_miscdev); 1638 ret = misc_register(&tun_miscdev);
1620 if (ret) { 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 goto err_misc; 1641 goto err_misc;
1623 } 1642 }
1624 return 0; 1643 return 0;