Revision c28b1c10 net/tap.c
b/net/tap.c | ||
---|---|---|
38 | 38 |
#include "qemu-char.h" |
39 | 39 |
#include "qemu-common.h" |
40 | 40 |
|
41 |
#ifdef __linux__ |
|
42 | 41 |
#include "net/tap-linux.h" |
43 |
#endif |
|
44 | 42 |
|
45 | 43 |
/* Maximum GSO packet size (64k) plus plenty of room for |
46 | 44 |
* the ethernet and virtio_net headers |
... | ... | |
347 | 345 |
return s; |
348 | 346 |
} |
349 | 347 |
|
350 |
int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required) |
|
351 |
{ |
|
352 |
struct ifreq ifr; |
|
353 |
int fd, ret; |
|
354 |
|
|
355 |
TFR(fd = open("/dev/net/tun", O_RDWR)); |
|
356 |
if (fd < 0) { |
|
357 |
fprintf(stderr, "warning: could not open /dev/net/tun: no virtual network emulation\n"); |
|
358 |
return -1; |
|
359 |
} |
|
360 |
memset(&ifr, 0, sizeof(ifr)); |
|
361 |
ifr.ifr_flags = IFF_TAP | IFF_NO_PI; |
|
362 |
|
|
363 |
if (*vnet_hdr) { |
|
364 |
unsigned int features; |
|
365 |
|
|
366 |
if (ioctl(fd, TUNGETFEATURES, &features) == 0 && |
|
367 |
features & IFF_VNET_HDR) { |
|
368 |
*vnet_hdr = 1; |
|
369 |
ifr.ifr_flags |= IFF_VNET_HDR; |
|
370 |
} |
|
371 |
|
|
372 |
if (vnet_hdr_required && !*vnet_hdr) { |
|
373 |
qemu_error("vnet_hdr=1 requested, but no kernel " |
|
374 |
"support for IFF_VNET_HDR available"); |
|
375 |
close(fd); |
|
376 |
return -1; |
|
377 |
} |
|
378 |
} |
|
379 |
|
|
380 |
if (ifname[0] != '\0') |
|
381 |
pstrcpy(ifr.ifr_name, IFNAMSIZ, ifname); |
|
382 |
else |
|
383 |
pstrcpy(ifr.ifr_name, IFNAMSIZ, "tap%d"); |
|
384 |
ret = ioctl(fd, TUNSETIFF, (void *) &ifr); |
|
385 |
if (ret != 0) { |
|
386 |
fprintf(stderr, "warning: could not configure /dev/net/tun: no virtual network emulation\n"); |
|
387 |
close(fd); |
|
388 |
return -1; |
|
389 |
} |
|
390 |
pstrcpy(ifname, ifname_size, ifr.ifr_name); |
|
391 |
fcntl(fd, F_SETFL, O_NONBLOCK); |
|
392 |
return fd; |
|
393 |
} |
|
394 |
|
|
395 | 348 |
static int launch_script(const char *setup_script, const char *ifname, int fd) |
396 | 349 |
{ |
397 | 350 |
sigset_t oldmask, mask; |
Also available in: Unified diff