[libvirt] [PATCH] Fix build when default python is python3

As the python generator scripts are written in python2, the ./configure script must check for python2 before checking for python otherwise, on platforms where both python2 and python3 are available and on which the default python points to python3, ./configure will try to use the wrong one. Signed-off-by: Lénaïc Huard <lenaic@lhuard.fr.eu.org> --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 10ce184..5446634 100644 --- a/configure.ac +++ b/configure.ac @@ -2032,7 +2032,7 @@ AM_CONDITIONAL([WITH_HYPERV], [test "$with_hyperv" = "yes"]) dnl Allow perl/python overrides -AC_PATH_PROG([PYTHON], [python]) +AC_PATH_PROGS([PYTHON], [python2 python]) AC_PATH_PROG([PERL], [perl]) AC_ARG_ENABLE([with-test-suite], -- 1.8.5.1

On Tue, Dec 17, 2013 at 06:53:28PM +0100, Lénaïc Huard wrote:
As the python generator scripts are written in python2, the ./configure script must check for python2 before checking for python otherwise, on platforms where both python2 and python3 are available and on which the default python points to python3, ./configure will try to use the wrong one.
Signed-off-by: Lénaïc Huard <lenaic@lhuard.fr.eu.org> --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac index 10ce184..5446634 100644 --- a/configure.ac +++ b/configure.ac @@ -2032,7 +2032,7 @@ AM_CONDITIONAL([WITH_HYPERV], [test "$with_hyperv" = "yes"])
dnl Allow perl/python overrides -AC_PATH_PROG([PYTHON], [python]) +AC_PATH_PROGS([PYTHON], [python2 python]) AC_PATH_PROG([PERL], [perl])
AC_ARG_ENABLE([with-test-suite],
ACK, at some point we should make apibuild.py able to work with py3 too, but that's lower priority now the main python library is split off in GIT. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 12/17/2013 10:56 AM, Daniel P. Berrange wrote:
On Tue, Dec 17, 2013 at 06:53:28PM +0100, Lénaïc Huard wrote:
As the python generator scripts are written in python2, the ./configure script must check for python2 before checking for python otherwise, on platforms where both python2 and python3 are available and on which the default python points to python3, ./configure will try to use the wrong one.
Signed-off-by: Lénaïc Huard <lenaic@lhuard.fr.eu.org> --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ACK, at some point we should make apibuild.py able to work with py3 too, but that's lower priority now the main python library is split off in GIT.
Pushed. Congrats on your first libvirt patch. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

When the host is configured with very restrictive firewall (default policy is DROP for all chains, including OUTPUT), the bridge driver for Linux adds netfilter entries to allow DHCP and DNS requests to go from the VM to the dnsmasq of the host. The issue that this commit fixes is the fact that a DROP policy on the OUTPUT chain blocks the DHCP replies from the host’s dnsmasq to the VM. As DHCP replies are sent in UDP, they are not caught by any --ctstate ESTABLISHED rule and so, need to be explicitly allowed. Signed-off-by: Lénaïc Huard <lenaic@lhuard.fr.eu.org> --- src/libvirt_private.syms | 2 ++ src/network/bridge_driver_linux.c | 36 ++++++++++++++--------- src/util/viriptables.c | 61 +++++++++++++++++++++++++++++++++++++++ src/util/viriptables.h | 7 +++++ 4 files changed, 93 insertions(+), 13 deletions(-) Sorry, I just noticed that I forgot to update networkRemoveGeneralFirewallRules. diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2dbb8f8..c26ce29 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1290,6 +1290,7 @@ iptablesAddForwardRejectOut; iptablesAddOutputFixUdpChecksum; iptablesAddTcpInput; iptablesAddUdpInput; +iptablesAddUdpOutput; iptablesRemoveDontMasquerade; iptablesRemoveForwardAllowCross; iptablesRemoveForwardAllowIn; @@ -1301,6 +1302,7 @@ iptablesRemoveForwardRejectOut; iptablesRemoveOutputFixUdpChecksum; iptablesRemoveTcpInput; iptablesRemoveUdpInput; +iptablesRemoveUdpOutput; # util/virjson.h diff --git a/src/network/bridge_driver_linux.c b/src/network/bridge_driver_linux.c index 066779a..a2f0248 100644 --- a/src/network/bridge_driver_linux.c +++ b/src/network/bridge_driver_linux.c @@ -564,6 +564,13 @@ int networkAddGeneralFirewallRules(virNetworkObjPtr network) goto err2; } + if (iptablesAddUdpOutput(AF_INET, network->def->bridge, 68) < 0) { + virReportError(VIR_ERR_SYSTEM_ERROR, + _("failed to add iptables rule to allow DHCP replies to '%s'"), + network->def->bridge); + goto err3; + } + /* If we are doing local DHCP service on this network, attempt to * add a rule that will fixup the checksum of DHCP response * packets back to the guests (but report failure without @@ -582,14 +589,14 @@ int networkAddGeneralFirewallRules(virNetworkObjPtr network) virReportError(VIR_ERR_SYSTEM_ERROR, _("failed to add iptables rule to allow DNS requests from '%s'"), network->def->bridge); - goto err3; + goto err4; } if (iptablesAddUdpInput(AF_INET, network->def->bridge, 53) < 0) { virReportError(VIR_ERR_SYSTEM_ERROR, _("failed to add iptables rule to allow DNS requests from '%s'"), network->def->bridge); - goto err4; + goto err5; } /* allow TFTP requests through to dnsmasq if necessary */ @@ -598,7 +605,7 @@ int networkAddGeneralFirewallRules(virNetworkObjPtr network) virReportError(VIR_ERR_SYSTEM_ERROR, _("failed to add iptables rule to allow TFTP requests from '%s'"), network->def->bridge); - goto err5; + goto err6; } /* Catch all rules to block forwarding to/from bridges */ @@ -607,14 +614,14 @@ int networkAddGeneralFirewallRules(virNetworkObjPtr network) virReportError(VIR_ERR_SYSTEM_ERROR, _("failed to add iptables rule to block outbound traffic from '%s'"), network->def->bridge); - goto err6; + goto err7; } if (iptablesAddForwardRejectIn(AF_INET, network->def->bridge) < 0) { virReportError(VIR_ERR_SYSTEM_ERROR, _("failed to add iptables rule to block inbound traffic to '%s'"), network->def->bridge); - goto err7; + goto err8; } /* Allow traffic between guests on the same bridge */ @@ -622,31 +629,33 @@ int networkAddGeneralFirewallRules(virNetworkObjPtr network) virReportError(VIR_ERR_SYSTEM_ERROR, _("failed to add iptables rule to allow cross bridge traffic on '%s'"), network->def->bridge); - goto err8; + goto err9; } /* add IPv6 general rules, if needed */ if (networkAddGeneralIp6tablesRules(network) < 0) { - goto err9; + goto err10; } return 0; /* unwind in reverse order from the point of failure */ -err9: +err10: iptablesRemoveForwardAllowCross(AF_INET, network->def->bridge); -err8: +err9: iptablesRemoveForwardRejectIn(AF_INET, network->def->bridge); -err7: +err8: iptablesRemoveForwardRejectOut(AF_INET, network->def->bridge); -err6: +err7: if (ipv4def && ipv4def->tftproot) { iptablesRemoveUdpInput(AF_INET, network->def->bridge, 69); } -err5: +err6: iptablesRemoveUdpInput(AF_INET, network->def->bridge, 53); -err4: +err5: iptablesRemoveTcpInput(AF_INET, network->def->bridge, 53); +err4: + iptablesRemoveUdpOutput(AF_INET, network->def->bridge, 68); err3: iptablesRemoveUdpInput(AF_INET, network->def->bridge, 67); err2: @@ -680,6 +689,7 @@ void networkRemoveGeneralFirewallRules(virNetworkObjPtr network) if (ipv4def && (ipv4def->nranges || ipv4def->nhosts)) { iptablesRemoveOutputFixUdpChecksum(network->def->bridge, 68); } + iptablesRemoveUdpOutput(AF_INET, network->def->bridge, 68); iptablesRemoveUdpInput(AF_INET, network->def->bridge, 67); iptablesRemoveTcpInput(AF_INET, network->def->bridge, 67); } diff --git a/src/util/viriptables.c b/src/util/viriptables.c index a1711bb..9b78d86 100644 --- a/src/util/viriptables.c +++ b/src/util/viriptables.c @@ -184,6 +184,28 @@ iptablesInput(int family, NULL); } +static int +iptablesOutput(int family, + const char *iface, + int port, + int action, + int tcp) +{ + char portstr[32]; + + snprintf(portstr, sizeof(portstr), "%d", port); + portstr[sizeof(portstr) - 1] = '\0'; + + return iptablesAddRemoveRule("filter", "OUTPUT", + family, + action, + "--out-interface", iface, + "--protocol", tcp ? "tcp" : "udp", + "--destination-port", portstr, + "--jump", "ACCEPT", + NULL); +} + /** * iptablesAddTcpInput: * @ctx: pointer to the IP table context @@ -262,6 +284,45 @@ iptablesRemoveUdpInput(int family, return iptablesInput(family, iface, port, REMOVE, 0); } +/** + * iptablesAddUdpOutput: + * @ctx: pointer to the IP table context + * @iface: the interface name + * @port: the UDP port to add + * + * Add an output to the IP table allowing access to the given @port from + * the given @iface interface for UDP packets + * + * Returns 0 in case of success or an error code in case of error + */ + +int +iptablesAddUdpOutput(int family, + const char *iface, + int port) +{ + return iptablesOutput(family, iface, port, ADD, 0); +} + +/** + * iptablesRemoveUdpOutput: + * @ctx: pointer to the IP table context + * @iface: the interface name + * @port: the UDP port to remove + * + * Removes an output from the IP table, hence forbidding access to the given + * @port from the given @iface interface for UDP packets + * + * Returns 0 in case of success or an error code in case of error + */ +int +iptablesRemoveUdpOutput(int family, + const char *iface, + int port) +{ + return iptablesOutput(family, iface, port, REMOVE, 0); +} + static char *iptablesFormatNetwork(virSocketAddr *netaddr, unsigned int prefix) diff --git a/src/util/viriptables.h b/src/util/viriptables.h index 6dfb992..2f9a212 100644 --- a/src/util/viriptables.h +++ b/src/util/viriptables.h @@ -40,6 +40,13 @@ int iptablesRemoveUdpInput (int family, const char *iface, int port); +int iptablesAddUdpOutput (int family, + const char *iface, + int port); +int iptablesRemoveUdpOutput (int family, + const char *iface, + int port); + int iptablesAddForwardAllowOut (virSocketAddr *netaddr, unsigned int prefix, const char *iface, -- 1.8.5.1
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Lénaïc Huard