eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit 96c61bb6b4dd47562a79a1bdbb3d97a9de5e2fb7
parent 608bfa8d3a02139216ec3bf71c1320273e984ee9
Author: illiliti <illiliti@protonmail.com>
Date:   Sun, 25 Jun 2023 20:19:13 +0300

Merge tag '2.6'

Release 2.6

Diffstat:
M.gitignore | 4++++
MChangeLog | 4++++
MMakefile.am | 15++++++++++++++-
Macinclude.m4 | 24++++++++++++++++++++++--
Mautotests/testFILS/fils_256_test.py | 4++++
Mautotests/testFILS/fils_384_test.py | 4++++
Mautotests/testNetconfig/connection_test.py | 2+-
Mconfigure.ac | 32++++++++++++++++++++++++++++++--
Adoc/code-coverage-testing.txt | 28++++++++++++++++++++++++++++
Mdoc/main.conf | 10+++++-----
Msrc/ft.c | 13++++++++++---
Msrc/iwd.config.rst | 30++++++++++++++++++++++++++++++
Msrc/netdev.c | 92++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
Msrc/wiphy.c | 75++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Msrc/wiphy.h | 1+
15 files changed, 298 insertions(+), 40 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,6 +1,8 @@ *.o *.lo *.la +*.gcno +*.gcda .libs .deps .dirstamp @@ -73,3 +75,5 @@ unit/*.trs test-suite.log src/builtin.h autotests/*/__pycache__ +iwd-coverage.info +gcov diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,7 @@ +ver 2.6: + Add support for setting driver specific quirks. + Add support for disabling power saving mode. + ver 2.5: Fix issue with HT40+/- checks when creating chandef. Fix issue with handling support for FT-8021X-SHA384. diff --git a/Makefile.am b/Makefile.am @@ -756,12 +756,25 @@ if WIRED endif endif -clean-local: +gcov-clean: +if GCOV + -$(LCOV) --quiet --directory $(builddir) -z + -rm -rf "$(builddir)/iwd-coverage.info" "$(builddir)/gcov" + -find . -name "*.gcda" -o -name "*.gcov" -o -name "*.gcno" -delete +endif + +clean-local: gcov-clean -rm -f unit/cert-*.pem unit/cert-*.csr unit/cert-*.srl unit/*-settings.8021x maintainer-clean-local: -rm -rf build-aux ell +gcov-report: +if GCOV + $(LCOV) --quiet --directory $(builddir) --capture --output-file "iwd-coverage.info" + LANG=C $(GENHTML) --quiet --prefix $(builddir) --output-directory "$(builddir)/gcov" --title "iwd Code Coverage" --legend "$(builddir)/iwd-coverage.info" +endif + src/builtin.h: src/genbuiltin config.status $(AM_V_at)$(MKDIR_P) $(@D) $(AM_V_GEN)$(srcdir)/src/genbuiltin $(builtin_modules) > $@ diff --git a/acinclude.m4 b/acinclude.m4 @@ -46,10 +46,30 @@ AC_DEFUN([AC_PROG_CC_UBSAN], [ ]) ]) +AC_DEFUN([AC_PROG_CC_GCOV], [ + AC_CACHE_CHECK([whether ${CC-cc} accepts -fprofile-arcs], ac_cv_prog_cc_profile_arcs, [ + echo 'void f(){}' > conftest.c + if test -z "`${CC-cc} -fprofile-arcs -c conftest.c 2>&1`"; then + ac_cv_prog_cc_profile_arcs=yes + else + ac_cv_prog_cc_profile_arcs=no + fi + rm -rf conftest* + ]) + AC_CACHE_CHECK([whether ${CC-cc} accepts -ftest_coverage], ac_cv_prog_cc_test_coverage, [ + echo 'void f(){}' > conftest.c + if test -z "`${CC-cc} -ftest-coverage -c conftest.c 2>&1`"; then + ac_cv_prog_cc_test_coverage=yes + else + ac_cv_prog_cc_test_coverage=no + fi + rm -rf conftest* + ]) +]) + AC_DEFUN([COMPILER_FLAGS], [ if (test "${CFLAGS}" = ""); then - CFLAGS="-Wall -O2 -fsigned-char -fno-exceptions" - CFLAGS+=" -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" + CFLAGS="-Wall -fsigned-char -fno-exceptions" fi if (test "$USE_MAINTAINER_MODE" = "yes"); then CFLAGS+=" -Werror -Wextra" diff --git a/autotests/testFILS/fils_256_test.py b/autotests/testFILS/fils_256_test.py @@ -55,6 +55,10 @@ class Test(unittest.TestCase): testutil.test_iface_operstate() testutil.test_ifaces_connected(device.name, hapd.ifname) + # + # TODO: If this is failing its likely due to an older hostapd version + # not containing commit 7ee814201b72 + # hapd.rekey(device.address) device.disconnect() diff --git a/autotests/testFILS/fils_384_test.py b/autotests/testFILS/fils_384_test.py @@ -55,6 +55,10 @@ class Test(unittest.TestCase): testutil.test_iface_operstate() testutil.test_ifaces_connected(device.name, hapd.ifname) + # + # TODO: If this is failing its likely due to an older hostapd version + # not containing commit 7ee814201b72 + # hapd.rekey(device.address) device.disconnect() diff --git a/autotests/testNetconfig/connection_test.py b/autotests/testNetconfig/connection_test.py @@ -276,7 +276,7 @@ class Test(unittest.TestCase): elif quote or ch not in ' \t\r\n;{}#': token += ch if ch == '#': - break + continue elif ch == '{': stack.append([]) elif ch == '}': diff --git a/configure.ac b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.69]) -AC_INIT([iwd],[2.5]) +AC_INIT([iwd],[2.6]) AC_CONFIG_HEADERS(config.h) AC_CONFIG_AUX_DIR(build-aux) @@ -25,6 +25,7 @@ AC_PROG_CC_PIE AC_PROG_CC_ASAN AC_PROG_CC_LSAN AC_PROG_CC_UBSAN +AC_PROG_CC_GCOV AC_PROG_INSTALL AC_PROG_MKDIR_P AC_PROG_LN_S @@ -37,10 +38,15 @@ LT_INIT([disable-static]) AC_ARG_ENABLE(optimization, AS_HELP_STRING([--disable-optimization], [disable code optimization through compiler]), [ if (test "${enableval}" = "no"); then - CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -O0" + CFLAGS="$CFLAGS -O0" fi ]) +if (test "${enable_optimization}" != "no"); then + CFLAGS="$CFLAGS -O2" + CFLAGS+=" -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" +fi + AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], [enable compiling with debugging information]), [ if (test "${enableval}" = "yes" && @@ -49,6 +55,28 @@ AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], fi ]) +AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov], + [enable compiling with code coverage information]), [ + if (test "${enableval}" = "yes" && + test "${ac_cv_prog_cc_profile_arcs}" = "yes" && + test "${ac_cv_prog_cc_test_coverage}" = "yes"); then + CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage" + fi +]) + +if (test "${enable_gcov}" = "yes"); then + AC_CHECK_PROGS(LCOV, [lcov], "no") + AC_CHECK_PROGS(GENHTML, [genhtml], "no") + if (test "${LCOV}" == "no"); then + AC_MSG_ERROR([lcov is required]) + fi + if (test "${GENHTML}" == "no"); then + AC_MSG_ERROR([genhtml is required]) + fi +fi + +AM_CONDITIONAL(GCOV, test "${enable_gcov}" != "no") + AC_ARG_ENABLE(pie, AS_HELP_STRING([--enable-pie], [enable position independent executables flag]), [ if (test "${enableval}" = "yes" && diff --git a/doc/code-coverage-testing.txt b/doc/code-coverage-testing.txt @@ -0,0 +1,28 @@ +Code Coverage Testing +===================== + +To enable code coverage testing, the following steps should be performed. + +1. Configure iwd with --enable-gcov --disable-optimization --enable-debug: + cd iwd + ./bootstrap-configure --enable-gcov --disable-optimization + make + +2. To check unit test coverage, run unit tests: + make check + +3. If you want to perform manual testing and see code coverage of the manual + tests, simply run iwd: + src/iwd -d + +3. Optionally run test runner. If you only care about a certain test and how + it affects code coveage, you can pass the autotest to run to test runner + using the '--autotests' command line argument, like so: + tools/test-runner --autotests=testWPA2 --kernel=tools/linux + +4. Obtain the results: + make gcov-report + Open 'gcov/index.html' + +5. Remove gcov output: + make gcov-clean diff --git a/doc/main.conf b/doc/main.conf @@ -31,14 +31,14 @@ # the system resolving service. The currently supported services are: # - systemd-resolved ["systemd"] # - openresolv / resolvconf ["resolvconf"] +# - none # # If not set, the value "systemd" is used by default. Uncomment the value # below if you are using openresolv: # #NameResolvingService=resolvconf # -# iwd's support for IPv6 is still experimental and is disabled by default. -# If you want to try it anyway, uncomment the setting below. Note that -# configuration via SLAAC is currently not supported (DHCPv6 only). -# -#EnableIPv6=true +# iwd's support for IPv6 should be stable enough and is now enabled by default. +# If you experience any problems and want to force IPv6 to be disabled, +# uncomment the setting below: +#EnableIPv6=false diff --git a/src/ft.c b/src/ft.c @@ -1000,14 +1000,21 @@ void __ft_rx_authenticate(uint32_t ifindex, const uint8_t *frame, if (!ft_parse_authentication_resp_frame(frame, frame_len, info->spa, info->aa, info->aa, 2, - &status, &ies, &ies_len)) + &status, &ies, &ies_len)) { + l_debug("Could not parse auth response"); return; + } - if (status != 0) + if (status != 0) { + l_debug("BSS "MAC" rejected FT auth with status=%u", + MAC_STR(info->aa), status); goto cancel; + } - if (!ft_parse_ies(info, hs, ies, ies_len)) + if (!ft_parse_ies(info, hs, ies, ies_len)) { + l_debug("Could not parse auth response IEs"); goto cancel; + } info->parsed = true; diff --git a/src/iwd.config.rst b/src/iwd.config.rst @@ -378,6 +378,36 @@ The group ``[IPv4]`` contains settings related to IPv4 network configuration. will limit the number of access points that can be running simultaneously on different interfaces. +DriverQuirks +------------ + +The group ``[DriverQuirks]`` contains special flags associated with drivers that +are buggy or just don't behave similar enough to the majority of other drivers. + +.. list-table:: + :header-rows: 0 + :stub-columns: 0 + :widths: 20 80 + :align: left + + * - DefaultInterface + - Values: comma-separated list of drivers or glob matches + + If a driver in use matches one in this list IWD will not attempt to + remove and re-create the default interface. + + * - ForcePae + - Values: comma-separated list of drivers or glob matches + + If a driver in use matches one in this list ControlPortOverNL80211 will + not be used, and PAE will be used instead. Some drivers do not properly + support ControlPortOverNL80211 even though they advertise support for it. + + * - PowerSaveDisable + - Values: comma-separated list of drivers or glob matches + + If a driver in user matches one in this list power save will be disabled. + SEE ALSO ======== diff --git a/src/netdev.c b/src/netdev.c @@ -131,6 +131,8 @@ struct netdev { uint32_t qos_map_cmd_id; uint32_t mac_change_cmd_id; uint32_t get_oci_cmd_id; + uint32_t get_link_cmd_id; + uint32_t power_save_cmd_id; enum netdev_result result; uint16_t last_code; /* reason or status, depending on result */ struct l_timeout *neighbor_report_timeout; @@ -940,6 +942,11 @@ static void netdev_free(void *data) if (netdev->fw_roam_bss) scan_bss_free(netdev->fw_roam_bss); + if (netdev->get_link_cmd_id) { + l_netlink_cancel(rtnl, netdev->get_link_cmd_id); + netdev->get_link_cmd_id = 0; + } + scan_wdev_remove(netdev->wdev_id); watchlist_destroy(&netdev->station_watches); @@ -6116,12 +6123,14 @@ static void netdev_initial_down_cb(int error, uint16_t type, const void *data, static void netdev_getlink_cb(int error, uint16_t type, const void *data, uint32_t len, void *user_data) { + struct netdev *netdev = user_data; const struct ifinfomsg *ifi = data; unsigned int bytes; - struct netdev *netdev; l_netlink_command_func_t cb; bool powered; + netdev->get_link_cmd_id = 0; + if (error != 0) { l_error("RTM_GETLINK error %i: %s", error, strerror(-error)); return; @@ -6133,8 +6142,7 @@ static void netdev_getlink_cb(int error, uint16_t type, const void *data, return; } - netdev = netdev_find(ifi->ifi_index); - if (!netdev) + if (L_WARN_ON((uint32_t)ifi->ifi_index != netdev->index)) return; bytes = len - NLMSG_ALIGN(sizeof(struct ifinfomsg)); @@ -6212,6 +6220,63 @@ error: return NULL; } +static void netdev_get_link(struct netdev *netdev) +{ + struct ifinfomsg *rtmmsg; + size_t bufsize; + + /* Query interface flags */ + bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg)); + rtmmsg = l_malloc(bufsize); + memset(rtmmsg, 0, bufsize); + + rtmmsg->ifi_family = AF_UNSPEC; + rtmmsg->ifi_index = netdev->index; + + netdev->get_link_cmd_id = l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg, + bufsize, netdev_getlink_cb, + netdev, NULL); + L_WARN_ON(netdev->get_link_cmd_id == 0); + + l_free(rtmmsg); +} + +static void netdev_disable_ps_cb(struct l_genl_msg *msg, void *user_data) +{ + struct netdev *netdev = user_data; + int err = l_genl_msg_get_error(msg); + + netdev->power_save_cmd_id = 0; + + /* Can't do anything about it but inform the user */ + if (err < 0) + l_error("Failed to disable power save for ifindex %u (%s: %d)", + netdev->index, strerror(-err), err); + else + l_debug("Disabled power save for ifindex %u", netdev->index); + + netdev_get_link(netdev); +} + +static bool netdev_disable_power_save(struct netdev *netdev) +{ + struct l_genl_msg *msg = l_genl_msg_new(NL80211_CMD_SET_POWER_SAVE); + uint32_t disabled = NL80211_PS_DISABLED; + + l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index); + l_genl_msg_append_attr(msg, NL80211_ATTR_PS_STATE, 4, &disabled); + + netdev->power_save_cmd_id = l_genl_family_send(nl80211, msg, + netdev_disable_ps_cb, + netdev, NULL); + if (!netdev->power_save_cmd_id) { + l_error("Failed to send SET_POWER_SAVE (-EIO)"); + return false; + } + + return true; +} + struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, const uint8_t *set_mac) { @@ -6223,8 +6288,6 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, uint32_t wiphy_id; struct netdev *netdev; struct wiphy *wiphy = NULL; - struct ifinfomsg *rtmmsg; - size_t bufsize; struct l_io *pae_io = NULL; if (nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex, @@ -6283,20 +6346,15 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, l_debug("Created interface %s[%d %" PRIx64 "]", netdev->name, netdev->index, netdev->wdev_id); - /* Query interface flags */ - bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg)); - rtmmsg = l_malloc(bufsize); - memset(rtmmsg, 0, bufsize); - - rtmmsg->ifi_family = AF_UNSPEC; - rtmmsg->ifi_index = ifindex; - - l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg, bufsize, - netdev_getlink_cb, NULL, NULL); + netdev_setup_interface(netdev); - l_free(rtmmsg); + if (wiphy_power_save_disabled(wiphy)) { + /* Wait to issue GET_LINK until PS is disabled */ + if (netdev_disable_power_save(netdev)) + return netdev; + } - netdev_setup_interface(netdev); + netdev_get_link(netdev); return netdev; } diff --git a/src/wiphy.c b/src/wiphy.c @@ -71,6 +71,12 @@ static unsigned int wiphy_dump_id; enum driver_flag { DEFAULT_IF = 0x1, FORCE_PAE = 0x2, + POWER_SAVE_DISABLE = 0x4, +}; + +struct driver_flag_name { + const char *name; + enum driver_flag flag; }; struct driver_info { @@ -93,6 +99,12 @@ static const struct driver_info driver_infos[] = { { "bcmsdh_sdmmc", DEFAULT_IF }, }; +static const struct driver_flag_name driver_flag_names[] = { + { "DefaultInterface", DEFAULT_IF }, + { "ForcePae", FORCE_PAE }, + { "PowerSaveDisable", POWER_SAVE_DISABLE }, +}; + struct wiphy { uint32_t id; char name[20]; @@ -111,7 +123,7 @@ struct wiphy { char *model_str; char *vendor_str; char *driver_str; - const struct driver_info *driver_info; + uint32_t driver_flags; struct watchlist state_watches; uint8_t extended_capabilities[EXT_CAP_LEN + 2]; /* max bitmap size + IE header */ uint8_t *iftype_extended_capabilities[NUM_NL80211_IFTYPES]; @@ -685,8 +697,7 @@ bool wiphy_uses_default_if(struct wiphy *wiphy) if (!wiphy_get_driver(wiphy)) return true; - if (wiphy->driver_info && - wiphy->driver_info->flags & DEFAULT_IF) + if (wiphy->driver_flags & DEFAULT_IF) return true; return false; @@ -697,12 +708,8 @@ bool wiphy_control_port_enabled(struct wiphy *wiphy) const struct l_settings *settings = iwd_get_config(); bool enabled; - if (wiphy->driver_info && - wiphy->driver_info->flags & FORCE_PAE) { - l_info("Not using Control Port due to driver quirks: %s", - wiphy_get_driver(wiphy)); + if (wiphy->driver_flags & FORCE_PAE) return false; - } if (!wiphy_has_ext_feature(wiphy, NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) @@ -715,6 +722,14 @@ bool wiphy_control_port_enabled(struct wiphy *wiphy) return enabled; } +bool wiphy_power_save_disabled(struct wiphy *wiphy) +{ + if (wiphy->driver_flags & POWER_SAVE_DISABLE) + return true; + + return false; +} + const uint8_t *wiphy_get_permanent_address(struct wiphy *wiphy) { return wiphy->permanent_addr; @@ -1312,6 +1327,27 @@ static void wiphy_print_basic_info(struct wiphy *wiphy) l_free(joined); l_strfreev(iftypes); } + + if (wiphy->driver_flags) { + char **flags = l_strv_new(); + char *joined; + + if (wiphy->driver_flags & DEFAULT_IF) + flags = l_strv_append(flags, "DefaultInterface"); + + if (wiphy->driver_flags & FORCE_PAE) + flags = l_strv_append(flags, "ForcePae"); + + if (wiphy->driver_flags & POWER_SAVE_DISABLE) + flags = l_strv_append(flags, "PowerSaveDisable"); + + joined = l_strjoinv(flags, ' '); + + l_info("\tDriver Flags: %s", joined); + + l_free(joined); + l_strfreev(flags); + } } static void parse_supported_commands(struct wiphy *wiphy, @@ -1870,6 +1906,9 @@ static bool wiphy_get_driver_name(struct wiphy *wiphy) char driver_path[256]; ssize_t len; unsigned int i; + unsigned int j; + const struct l_settings *config = iwd_get_config(); + char **flag_list; driver_link = l_strdup_printf("/sys/class/ieee80211/%s/device/driver", wiphy->name); @@ -1885,7 +1924,25 @@ static bool wiphy_get_driver_name(struct wiphy *wiphy) for (i = 0; i < L_ARRAY_SIZE(driver_infos); i++) if (!fnmatch(driver_infos[i].prefix, wiphy->driver_str, 0)) - wiphy->driver_info = &driver_infos[i]; + wiphy->driver_flags |= driver_infos[i].flags; + + /* Check for any user-defined driver flags */ + if (!l_settings_has_group(config, "DriverQuirks")) + return true; + + for (i = 0; i < L_ARRAY_SIZE(driver_flag_names); i++) { + flag_list = l_settings_get_string_list(config, "DriverQuirks", + driver_flag_names[i].name, ','); + if (!flag_list) + continue; + + for (j = 0; flag_list[j]; j++) + if (!fnmatch(flag_list[j], wiphy->driver_str, 0)) + wiphy->driver_flags |= + driver_flag_names[i].flag; + + l_strv_free(flag_list); + } return true; } diff --git a/src/wiphy.h b/src/wiphy.h @@ -135,6 +135,7 @@ const char *wiphy_get_driver(struct wiphy *wiphy); const char *wiphy_get_name(struct wiphy *wiphy); bool wiphy_uses_default_if(struct wiphy *wiphy); bool wiphy_control_port_enabled(struct wiphy *wiphy); +bool wiphy_power_save_disabled(struct wiphy *wiphy); const uint8_t *wiphy_get_permanent_address(struct wiphy *wiphy); const uint8_t *wiphy_get_extended_capabilities(struct wiphy *wiphy, uint32_t iftype);