Skip to content

Commit 195624d

Browse files
Patrick Rohrdavem330
authored andcommitted
tun: support not enabling carrier in TUNSETIFF
This change adds support for not enabling carrier during TUNSETIFF interface creation by specifying the IFF_NO_CARRIER flag. Our tests make heavy use of tun interfaces. In some scenarios, the test process creates the interface but another process brings it up after the interface is discovered via netlink notification. In that case, it is not possible to create a tun/tap interface with carrier off without it racing against the bring up. Immediately setting carrier off via TUNSETCARRIER is still too late. Signed-off-by: Patrick Rohr <prohr@google.com> Cc: Maciej Żenczykowski <maze@google.com> Cc: Lorenzo Colitti <lorenzo@google.com> Cc: Jason Wang <jasowang@redhat.com> Cc: Stephen Hemminger <stephen@networkplumber.org> Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com> Reviewed-by: Maciej Żenczykowski <maze@google.com> Acked-by: Jason Wang <jasowang@redhat.com> Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 504c25c commit 195624d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

drivers/net/tun.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2828,7 +2828,10 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
28282828
rcu_assign_pointer(tfile->tun, tun);
28292829
}
28302830

2831-
netif_carrier_on(tun->dev);
2831+
if (ifr->ifr_flags & IFF_NO_CARRIER)
2832+
netif_carrier_off(tun->dev);
2833+
else
2834+
netif_carrier_on(tun->dev);
28322835

28332836
/* Make sure persistent devices do not get stuck in
28342837
* xoff state.
@@ -3056,8 +3059,8 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
30563059
* This is needed because we never checked for invalid flags on
30573060
* TUNSETIFF.
30583061
*/
3059-
return put_user(IFF_TUN | IFF_TAP | TUN_FEATURES,
3060-
(unsigned int __user*)argp);
3062+
return put_user(IFF_TUN | IFF_TAP | IFF_NO_CARRIER |
3063+
TUN_FEATURES, (unsigned int __user*)argp);
30613064
} else if (cmd == TUNSETQUEUE) {
30623065
return tun_set_queue(file, &ifr);
30633066
} else if (cmd == SIOCGSKNS) {

include/uapi/linux/if_tun.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
#define IFF_TAP 0x0002
6868
#define IFF_NAPI 0x0010
6969
#define IFF_NAPI_FRAGS 0x0020
70+
/* Used in TUNSETIFF to bring up tun/tap without carrier */
71+
#define IFF_NO_CARRIER 0x0040
7072
#define IFF_NO_PI 0x1000
7173
/* This flag has no real effect */
7274
#define IFF_ONE_QUEUE 0x2000

0 commit comments

Comments
 (0)