Skip to content

Commit

Permalink
python: Add async DNS support.
Browse files Browse the repository at this point in the history
This adds a Python version of the async DNS support added in:

771680d DNS: Add basic support for asynchronous DNS resolving

The above version uses the unbound C library, and this
implimentation uses the SWIG-wrapped Python version of that.

In the event that the Python unbound library is not available,
a warning will be logged and the resolve() method will just
return None. For the case where inet_parse_active() is passed
an IP address, it will not try to resolve it, so existing
behavior should be preserved in the case that the unbound
library is unavailable.

Intentional differences from the C version are as follows:

  OVS_HOSTS_FILE environment variable can bet set to override
  the system 'hosts' file. This is primarily to allow testing to
  be done without requiring network connectivity.

  Since resolution can still be done via hosts file lookup, DNS
  lookups are not disabled when resolv.conf cannot be loaded.

  The Python socket_util module has fallen behind its C equivalent.
  The bare minimum change was done to inet_parse_active() to support
  sync/async dns, as there is no equivalent to
  parse_sockaddr_components(), inet_parse_passive(), etc. A TODO
  was added to bring socket_util.py up to equivalency to the C
  version.

Signed-off-by: Terry Wilson <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
  • Loading branch information
otherwiseguy authored and igsilya committed Jul 14, 2023
1 parent 501f665 commit 4d55a36
Show file tree
Hide file tree
Showing 16 changed files with 615 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ jobs:
run: sudo apt update || true
- name: install common dependencies
run: sudo apt install -y ${{ env.dependencies }}
- name: install libunbound libunwind
- name: install libunbound libunwind python3-unbound
# GitHub Actions doesn't have 32-bit versions of these libraries.
if: matrix.m32 == ''
run: sudo apt install -y libunbound-dev libunwind-dev
run: sudo apt install -y libunbound-dev libunwind-dev python3-unbound
- name: install 32-bit libraries
if: matrix.m32 != ''
run: sudo apt install -y gcc-multilib
Expand Down
4 changes: 2 additions & 2 deletions Documentation/intro/install/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ need the following software:
If libcap-ng is installed, then Open vSwitch will automatically build with
support for it.

- Python 3.4 or later.
- Python 3.6 or later.

- Unbound library, from http://www.unbound.net, is optional but recommended if
you want to enable ovs-vswitchd and other utilities to use DNS names when
Expand Down Expand Up @@ -208,7 +208,7 @@ simply install and run Open vSwitch you require the following software:
from iproute2 (part of all major distributions and available at
https://wiki.linuxfoundation.org/networking/iproute2).

- Python 3.4 or later.
- Python 3.6 or later.

On Linux you should ensure that ``/dev/urandom`` exists. To support TAP
devices, you must also ensure that ``/dev/net/tun`` exists.
Expand Down
2 changes: 1 addition & 1 deletion Documentation/intro/install/rhel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Once that is completed, remove the file ``/tmp/ovs.spec``.
If python3-sphinx package is not available in your version of RHEL, you can
install it via pip with 'pip install sphinx'.

Open vSwitch requires python 3.4 or newer which is not available in older
Open vSwitch requires python 3.6 or newer which is not available in older
distributions. In the case of RHEL 6.x and its derivatives, one option is
to install python34 from `EPEL`_.

Expand Down
2 changes: 1 addition & 1 deletion Documentation/intro/install/windows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The following explains the steps in some detail.

'C:/MinGW /mingw'.

- Python 3.4 or later.
- Python 3.6 or later.

Install the latest Python 3.x from python.org and verify that its path is
part of Windows' PATH environment variable.
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Post-v3.1.0
table to check the status.
- Linux TC offload:
* Add support for offloading VXLAN tunnels with the GBP extensions.
- Python
* Added async DNS support.
* Dropped support for Python < 3.6.


v3.1.0 - 16 Feb 2023
Expand Down
1 change: 1 addition & 0 deletions debian/control.in
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ Depends:
Suggests:
python3-netaddr,
python3-pyparsing,
python3-unbound,
Description: Python 3 bindings for Open vSwitch
Open vSwitch is a production quality, multilayer, software-based,
Ethernet virtual switch. It is designed to enable massive network
Expand Down
8 changes: 4 additions & 4 deletions m4/openvswitch.m4
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,16 @@ dnl Checks for valgrind/valgrind.h.
AC_DEFUN([OVS_CHECK_VALGRIND],
[AC_CHECK_HEADERS([valgrind/valgrind.h])])

dnl Checks for Python 3.4 or later.
dnl Checks for Python 3.6 or later.
AC_DEFUN([OVS_CHECK_PYTHON3],
[AC_CACHE_CHECK(
[for Python 3 (version 3.4 or later)],
[for Python 3 (version 3.6 or later)],
[ovs_cv_python3],
[if test -n "$PYTHON3"; then
ovs_cv_python3=$PYTHON3
else
ovs_cv_python3=no
for binary in python3 python3.4 python3.5 python3.6 python3.7; do
for binary in python3 python3.6 python3.7 python3.8 python3.9 python3.10 python3.11 python3.12; do
ovs_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for dir in $PATH; do
IFS=$ovs_save_IFS
Expand All @@ -401,7 +401,7 @@ else:
done
fi])
if test "$ovs_cv_python3" = no; then
AC_MSG_ERROR([Python 3.4 or later is required but not found in $PATH, please install it or set $PYTHON3 to point to it])
AC_MSG_ERROR([Python 3.6 or later is required but not found in $PATH, please install it or set $PYTHON3 to point to it])
fi
AC_ARG_VAR([PYTHON3])
PYTHON3=$ovs_cv_python3])
Expand Down
7 changes: 7 additions & 0 deletions python/TODO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ Python Bindings To-do List

* Support write-only-changed monitor mode (equivalent of
OVSDB_IDL_WRITE_CHANGED_ONLY).

* socket_util:

* Add equivalent fuctions to inet_parse_passive, parse_sockaddr_components,
et al. to better support using async dns. The reconnect code will
currently log a warning when inet_parse_active() returns w/o yet having
resolved an address, but will continue to connect and eventually succeed.
2 changes: 2 additions & 0 deletions python/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ovs_pyfiles = \
python/ovs/compat/sortedcontainers/sorteddict.py \
python/ovs/compat/sortedcontainers/sortedset.py \
python/ovs/daemon.py \
python/ovs/dns_resolve.py \
python/ovs/db/__init__.py \
python/ovs/db/custom_index.py \
python/ovs/db/data.py \
Expand Down Expand Up @@ -55,6 +56,7 @@ ovs_pyfiles = \

ovs_pytests = \
python/ovs/tests/test_decoders.py \
python/ovs/tests/test_dns_resolve.py \
python/ovs/tests/test_filter.py \
python/ovs/tests/test_kv.py \
python/ovs/tests/test_list.py \
Expand Down
Loading

0 comments on commit 4d55a36

Please sign in to comment.