提交 8fa592e3 编写于 作者: A Aron Griffis 提交者: Daniel Veillard

Remove MAX_TAP_ID and let kernel do numbering

* src/bridge.c: no need to format the device string in brAddTap()
  this can be delegated to the kernel and removes an arbitrary limit.
上级 e195b439
...@@ -49,8 +49,6 @@ ...@@ -49,8 +49,6 @@
#include "util.h" #include "util.h"
#include "logging.h" #include "logging.h"
#define MAX_TAP_ID 256
#define JIFFIES_TO_MS(j) (((j)*1000)/HZ) #define JIFFIES_TO_MS(j) (((j)*1000)/HZ)
#define MS_TO_JIFFIES(ms) (((ms)*HZ)/1000) #define MS_TO_JIFFIES(ms) (((ms)*HZ)/1000)
...@@ -466,76 +464,52 @@ brAddTap(brControl *ctl, ...@@ -466,76 +464,52 @@ brAddTap(brControl *ctl,
int vnet_hdr, int vnet_hdr,
int *tapfd) int *tapfd)
{ {
int id, subst, fd; int fd, len;
struct ifreq ifr = {0};
if (!ctl || !ctl->fd || !bridge || !ifname) if (!ctl || !ctl->fd || !bridge || !ifname)
return EINVAL; return EINVAL;
subst = id = 0;
if (strstr(*ifname, "%d"))
subst = 1;
if ((fd = open("/dev/net/tun", O_RDWR)) < 0) if ((fd = open("/dev/net/tun", O_RDWR)) < 0)
return errno; return errno;
if (vnet_hdr) ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
vnet_hdr = brProbeVnetHdr(fd);
do { #ifdef IFF_VNET_HDR
struct ifreq try; if (vnet_hdr && brProbeVnetHdr(fd))
int len; ifr.ifr_flags |= IFF_VNET_HDR;
#endif
memset(&try, 0, sizeof(struct ifreq)); strncpy(ifr.ifr_name, *ifname, IFNAMSIZ-1);
try.ifr_flags = IFF_TAP|IFF_NO_PI; if (ioctl(fd, TUNSETIFF, &ifr) < 0)
goto error;
#ifdef IFF_VNET_HDR len = strlen(ifr.ifr_name);
if (vnet_hdr) if (len >= BR_IFNAME_MAXLEN - 1) {
try.ifr_flags |= IFF_VNET_HDR; errno = EINVAL;
#endif goto error;
}
if (subst) { /* We need to set the interface MTU before adding it
len = snprintf(try.ifr_name, BR_IFNAME_MAXLEN, *ifname, id); * to the bridge, because the bridge will have its
if (len >= BR_IFNAME_MAXLEN) { * MTU adjusted automatically when we add the new interface.
errno = EADDRINUSE; */
goto error; if ((errno = brSetInterfaceMtu(ctl, bridge, ifr.ifr_name)))
} goto error;
} else { if ((errno = brAddInterface(ctl, bridge, ifr.ifr_name)))
len = strlen(*ifname); goto error;
if (len >= BR_IFNAME_MAXLEN - 1) { if ((errno = brSetInterfaceUp(ctl, ifr.ifr_name, 1)))
errno = EINVAL; goto error;
goto error; if (!tapfd &&
} (errno = ioctl(fd, TUNSETPERSIST, 1)))
goto error;
strncpy(try.ifr_name, *ifname, len); VIR_FREE(*ifname);
try.ifr_name[len] = '\0'; if (!(*ifname = strdup(ifr.ifr_name)))
} goto error;
if (tapfd)
if (ioctl(fd, TUNSETIFF, &try) == 0) { *tapfd = fd;
/* We need to set the interface MTU before adding it return 0;
* to the bridge, because the bridge will have its
* MTU adjusted automatically when we add the new interface.
*/
if ((errno = brSetInterfaceMtu(ctl, bridge, try.ifr_name)))
goto error;
if ((errno = brAddInterface(ctl, bridge, try.ifr_name)))
goto error;
if ((errno = brSetInterfaceUp(ctl, try.ifr_name, 1)))
goto error;
if (!tapfd &&
(errno = ioctl(fd, TUNSETPERSIST, 1)))
goto error;
VIR_FREE(*ifname);
if (!(*ifname = strdup(try.ifr_name)))
goto error;
if (tapfd)
*tapfd = fd;
return 0;
}
id++;
} while (subst && id <= MAX_TAP_ID);
error: error:
close(fd); close(fd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册