tap-linux.c (264986e2c8f14a0f4a32ac6f1e083905833a5fc7) | tap-linux.c (d26e445c80fddcc7483b83f3115e5067fef28fe6) |
---|---|
1/* 2 * QEMU System Emulator 3 * 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 * Copyright (c) 2009 Red Hat, Inc. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to deal --- 28 unchanged lines hidden (view full) --- 37#define PATH_NET_TUN "/dev/net/tun" 38 39int tap_open(char *ifname, int ifname_size, int *vnet_hdr, 40 int vnet_hdr_required, int mq_required) 41{ 42 struct ifreq ifr; 43 int fd, ret; 44 int len = sizeof(struct virtio_net_hdr); | 1/* 2 * QEMU System Emulator 3 * 4 * Copyright (c) 2003-2008 Fabrice Bellard 5 * Copyright (c) 2009 Red Hat, Inc. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to deal --- 28 unchanged lines hidden (view full) --- 37#define PATH_NET_TUN "/dev/net/tun" 38 39int tap_open(char *ifname, int ifname_size, int *vnet_hdr, 40 int vnet_hdr_required, int mq_required) 41{ 42 struct ifreq ifr; 43 int fd, ret; 44 int len = sizeof(struct virtio_net_hdr); |
45 unsigned int features; |
|
45 46 TFR(fd = open(PATH_NET_TUN, O_RDWR)); 47 if (fd < 0) { 48 error_report("could not open %s: %m", PATH_NET_TUN); 49 return -1; 50 } 51 memset(&ifr, 0, sizeof(ifr)); 52 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; 53 | 46 47 TFR(fd = open(PATH_NET_TUN, O_RDWR)); 48 if (fd < 0) { 49 error_report("could not open %s: %m", PATH_NET_TUN); 50 return -1; 51 } 52 memset(&ifr, 0, sizeof(ifr)); 53 ifr.ifr_flags = IFF_TAP | IFF_NO_PI; 54 |
54 if (*vnet_hdr) { 55 unsigned int features; | 55 if (ioctl(fd, TUNGETFEATURES, &features) == 0 && 56 features & IFF_ONE_QUEUE) { 57 ifr.ifr_flags |= IFF_ONE_QUEUE; 58 } |
56 | 59 |
60 if (*vnet_hdr) { |
|
57 if (ioctl(fd, TUNGETFEATURES, &features) == 0 && 58 features & IFF_VNET_HDR) { 59 *vnet_hdr = 1; 60 ifr.ifr_flags |= IFF_VNET_HDR; 61 } else { 62 *vnet_hdr = 0; 63 } 64 --- 8 unchanged lines hidden (view full) --- 73 * tap it might have been modified e.g. by another instance of qemu. 74 * Ignore errors since old kernels do not support this ioctl: in this 75 * case the header size implicitly has the correct value. 76 */ 77 ioctl(fd, TUNSETVNETHDRSZ, &len); 78 } 79 80 if (mq_required) { | 61 if (ioctl(fd, TUNGETFEATURES, &features) == 0 && 62 features & IFF_VNET_HDR) { 63 *vnet_hdr = 1; 64 ifr.ifr_flags |= IFF_VNET_HDR; 65 } else { 66 *vnet_hdr = 0; 67 } 68 --- 8 unchanged lines hidden (view full) --- 77 * tap it might have been modified e.g. by another instance of qemu. 78 * Ignore errors since old kernels do not support this ioctl: in this 79 * case the header size implicitly has the correct value. 80 */ 81 ioctl(fd, TUNSETVNETHDRSZ, &len); 82 } 83 84 if (mq_required) { |
81 unsigned int features; 82 | |
83 if ((ioctl(fd, TUNGETFEATURES, &features) != 0) || 84 !(features & IFF_MULTI_QUEUE)) { 85 error_report("multiqueue required, but no kernel " 86 "support for IFF_MULTI_QUEUE available"); 87 close(fd); 88 return -1; 89 } else { 90 ifr.ifr_flags |= IFF_MULTI_QUEUE; --- 186 unchanged lines hidden --- | 85 if ((ioctl(fd, TUNGETFEATURES, &features) != 0) || 86 !(features & IFF_MULTI_QUEUE)) { 87 error_report("multiqueue required, but no kernel " 88 "support for IFF_MULTI_QUEUE available"); 89 close(fd); 90 return -1; 91 } else { 92 ifr.ifr_flags |= IFF_MULTI_QUEUE; --- 186 unchanged lines hidden --- |