Skip to contentSkip to conversation

ip tap: Simplify add 'tap' device w/o mode

PATCH In review Vadim Kochan 3 participants 5 messages Feb 28, 2015 – Mar 3, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip tap: Simplify add 'tap' device w/o mode

From: Vadim Kochan <[email protected]>

It allows add 'tap' device w/o specify mode:

    # ip tap add tap0

instead of return error message.

---
 ip/iptuntap.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
ip/iptuntap.c +7 -2
index b9b28a1..61b6c19 100644
@@ -107,6 +107,7 @@ static int tap_del_ioctl(struct ifreq *ifr)
 static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_t *gid)
 {
 	int count = 0;
+	char *cmd = *(argv - 2);
 
 	memset(ifr, 0, sizeof(*ifr));
 
@@ -187,8 +188,12 @@ static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_
 	}
 
 	if (!(ifr->ifr_flags & TUN_TYPE_MASK)) {
-		fprintf(stderr, "You failed to specify a tunnel mode\n");
-		return -1;
+		if(strncmp("tap", cmd, 3) == 0) {
+			ifr->ifr_flags |= IFF_TAP;
+		} else {
+			fprintf(stderr, "You failed to specify a tunnel mode\n");
+			return -1;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.2.2
#1 lore raw
Quoted 9 lines · On Sat, 28 Feb 2015 11:59:46 +0200 Vadim Kochan <[email protected]> wrote:

From: Vadim Kochan <[email protected]>

It allows add 'tap' device w/o specify mode:

    # ip tap add tap0

instead of return error message.

No. mode should not depend on device name.

Also, I noticed that reading kernel code it is possible to create a broken tun device if type is not set.

#2 lore raw
Quoted 1 line · Stephen Hemminger

No. mode should not depend on device name.

Isn't this looking at the "tap" part of "ip tap", not the device name?

#3 lore raw
Quoted 5 lines · Jonathon Reinhart
Quoted 1 line · Stephen Hemminger

No. mode should not depend on device name.

Isn't this looking at the "tap" part of "ip tap", not the device name?

Right it checks 'ip tap' not the device name.

#4 lore raw
In reply to Stephen Hemminger
Quoted 9 lines · Stephen Hemminger
Quoted 6 lines · On Sat, 28 Feb 2015 11:59:46 +0200 Vadim Kochan <[email protected]> wrote:

From: Vadim Kochan <[email protected]>

It allows add 'tap' device w/o specify mode:

    # ip tap add tap0
Quoted 9 lines
Quoted 3 lines

instead of return error message.

No. mode should not depend on device name.

Also, I noticed that reading kernel code it is possible to create a broken tun device if type is not set.

Is it still bad if it checks for 'tap' in 'ip tap' ?