|
61 | 61 | #include <linux/crc32.h>
|
62 | 62 | #include <linux/nsproxy.h>
|
63 | 63 | #include <linux/virtio_net.h>
|
| 64 | +#include <linux/rcupdate.h> |
64 | 65 | #include <net/net_namespace.h>
|
65 | 66 | #include <net/netns/generic.h>
|
66 | 67 | #include <net/rtnetlink.h>
|
@@ -366,6 +367,10 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev)
|
366 | 367 | if (!check_filter(&tun->txflt, skb))
|
367 | 368 | goto drop;
|
368 | 369 |
|
| 370 | + if (tun->socket.sk->sk_filter && |
| 371 | + sk_filter(tun->socket.sk, skb)) |
| 372 | + goto drop; |
| 373 | + |
369 | 374 | if (skb_queue_len(&tun->socket.sk->sk_receive_queue) >= dev->tx_queue_len) {
|
370 | 375 | if (!(tun->flags & TUN_ONE_QUEUE)) {
|
371 | 376 | /* Normal queueing mode. */
|
@@ -1162,6 +1167,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
|
1162 | 1167 | struct tun_file *tfile = file->private_data;
|
1163 | 1168 | struct tun_struct *tun;
|
1164 | 1169 | void __user* argp = (void __user*)arg;
|
| 1170 | + struct sock_fprog fprog; |
1165 | 1171 | struct ifreq ifr;
|
1166 | 1172 | int sndbuf;
|
1167 | 1173 | int ret;
|
@@ -1309,6 +1315,26 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
|
1309 | 1315 | tun->socket.sk->sk_sndbuf = sndbuf;
|
1310 | 1316 | break;
|
1311 | 1317 |
|
| 1318 | + case TUNATTACHFILTER: |
| 1319 | + /* Can be set only for TAPs */ |
| 1320 | + ret = -EINVAL; |
| 1321 | + if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) |
| 1322 | + break; |
| 1323 | + ret = -EFAULT; |
| 1324 | + if (copy_from_user(&fprog, argp, sizeof(fprog))) |
| 1325 | + break; |
| 1326 | + |
| 1327 | + ret = sk_attach_filter(&fprog, tun->socket.sk); |
| 1328 | + break; |
| 1329 | + |
| 1330 | + case TUNDETACHFILTER: |
| 1331 | + /* Can be set only for TAPs */ |
| 1332 | + ret = -EINVAL; |
| 1333 | + if ((tun->flags & TUN_TYPE_MASK) != TUN_TAP_DEV) |
| 1334 | + break; |
| 1335 | + ret = sk_detach_filter(tun->socket.sk); |
| 1336 | + break; |
| 1337 | + |
1312 | 1338 | default:
|
1313 | 1339 | ret = -EINVAL;
|
1314 | 1340 | break;
|
|
0 commit comments