X-Git-Url: https://repo.jachan.dev/qemu.git/blobdiff_plain/f57fb88436464cf72a2a0c7372e2dc0af1870b5f..c8e829b7bf6e1c84af8b4b13ee7fce2959c63e0e:/qemu-bridge-helper.c diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index 652eec99fd..36eb3bcfd6 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -39,7 +39,7 @@ #include #endif -#include "qemu-queue.h" +#include "qemu/queue.h" #include "net/tap-linux.h" @@ -229,7 +229,7 @@ int main(int argc, char **argv) unsigned long ifargs[4]; #endif int ifindex; - int fd, ctlfd, unixfd = -1; + int fd = -1, ctlfd = -1, unixfd = -1; int use_vnet = 0; int mtu; const char *bridge = NULL; @@ -367,6 +367,24 @@ int main(int argc, char **argv) goto cleanup; } + /* Linux uses the lowest enslaved MAC address as the MAC address of + * the bridge. Set MAC address to a high value so that it doesn't + * affect the MAC address of the bridge. + */ + if (ioctl(ctlfd, SIOCGIFHWADDR, &ifr) < 0) { + fprintf(stderr, "failed to get MAC address of device `%s': %s\n", + iface, strerror(errno)); + ret = EXIT_FAILURE; + goto cleanup; + } + ifr.ifr_hwaddr.sa_data[0] = 0xFE; + if (ioctl(ctlfd, SIOCSIFHWADDR, &ifr) < 0) { + fprintf(stderr, "failed to set MAC address of device `%s': %s\n", + iface, strerror(errno)); + ret = EXIT_FAILURE; + goto cleanup; + } + /* add the interface to the bridge */ prep_ifreq(&ifr, bridge); ifindex = if_nametoindex(iface); @@ -418,7 +436,12 @@ int main(int argc, char **argv) /* profit! */ cleanup: - + if (fd >= 0) { + close(fd); + } + if (ctlfd >= 0) { + close(ctlfd); + } while ((acl_rule = QSIMPLEQ_FIRST(&acl_list)) != NULL) { QSIMPLEQ_REMOVE_HEAD(&acl_list, entry); g_free(acl_rule);