From a1bd4fa88c432968d9b81480bc6f469d32fd32b5 Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 01 2020 12:12:33 +0000 Subject: NetworkManager-1.30.0 base --- diff --git a/CONTRIBUTING b/CONTRIBUTING index e24095e..8335cbf 100644 --- a/CONTRIBUTING +++ b/CONTRIBUTING @@ -1,38 +1,51 @@ Guidelines for Contributing =========================== + Coding Standard --------------- -Coding standards are generally GNOME coding standards, with these exceptions: - a) 4 space tabs (_not_ 8-space tabs) - b) REAL tabs (_not_ a mix of tabs and spaces in the initial indent) - c) spaces used to align continuation lines past the indent point of the - first statement line, like so: +The formatting uses clang-format with clang 11.0. Run +`./contrib/scripts/nm-code-format.sh -i` to reformat the code +or call `clang-format` yourself. +You may also call `./contrib/scripts/nm-code-format-container.sh` +which runs a Fedora 33 container using podman. +You are welcome to not bother and open a merge request with +wrong formatting, but note that we then will automatically adjust +your contribution before merging. + +The automatic reformatting was done by commit 328fb90f3e0d4e35975aff63944ac0412d7893a5. +Use `--ignore-rev` option or `--ignore-revs-file .git-blame-ignore-revs` to ignore +the reformatting commit with git-blame: + +``` +$ git config --add 'blame.ignoreRevsFile' '.git-blame-ignore-revs' +``` - if ( some_really_really_long_variable_name - && another_really_really_long_variable_name) { - ... - } +Since our coding style is entirely automated, the following are just +some details of the style we use: -* Keep a space between the function name and the opening '('. - GOOD: g_strdup (x) - BAD: g_strdup(x) +* Indent with 4 spaces. (_no_ tabs). + +* Have no space between the function name and the opening '('. + - GOOD: `g_strdup(x)` + - BAD: `g_strdup (x)` * C-style comments - GOOD: f(x); /* comment */ - BAD: f(x); // comment + - GOOD: `f(x); /* comment */` + - BAD: `f(x); // comment` * Keep assignments in the variable declaration area pretty short. - GOOD: MyObject *object; - BAD: MyObject *object = complex_and_long_init_function(arg1, arg2, arg3); + - GOOD: `MyObject *object;` + - BAD: `MyObject *object = complex_and_long_init_function(arg1, arg2, arg3);` * 80-cols is a guideline, don't make the code uncomfortable in order to fit in less than 80 cols. * Constants are CAPS_WITH_UNDERSCORES and use the preprocessor. - GOOD: #define MY_CONSTANT 42 - BAD: static const unsigned myConstant = 42; + - GOOD: `#define MY_CONSTANT 42` + - BAD: `static const unsigned myConstant = 42;` + Legal ----- @@ -46,6 +59,8 @@ Note that all new contributions to NetworkManager MUST be made under terms of LGPL-2.1+, that is also the case for parts that are currently licensed GPL-2.0+. The reason for that is that we might eventually relicense everything as LGPL and new contributions already must agree with that future change. +For more details see [RELICENSE.md](RELICENSE.md). + Assertions in NetworkManager code --------------------------------- @@ -131,15 +146,21 @@ The notes it are called "refs/notes/bugs". So configure: - $ git config --add 'remote.origin.fetch' 'refs/notes/bugs:refs/notes/bugs' - $ git config --add 'notes.displayref' 'refs/notes/bugs' +``` +$ git config --add 'remote.origin.fetch' 'refs/notes/bugs:refs/notes/bugs' +$ git config --add 'notes.displayref' 'refs/notes/bugs' +``` For example, set notes with - $ git notes --ref refs/notes/bugs add -m "(cherry picked from $COMMIT_SHA)" HEAD +``` +$ git notes --ref refs/notes/bugs add -m "(cherry picked from $COMMIT_SHA)" HEAD +``` You should see the notes in git-log output as well. To resync our local notes use: - $ git fetch origin refs/notes/bugs:refs/notes/bugs -f +``` +$ git fetch origin refs/notes/bugs:refs/notes/bugs -f +``` diff --git a/Makefile.am b/Makefile.am index 741b1e6..0ea43de 100644 --- a/Makefile.am +++ b/Makefile.am @@ -85,6 +85,8 @@ completiondir = $(datadir)/bash-completion/completions nmlocaledir = $(datadir)/locale +INTROSPECTION_EXTRA_CFLAGS = -Wno-incompatible-pointer-types-discards-qualifiers + GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM @@ -677,7 +679,10 @@ endif noinst_LTLIBRARIES += introspection/libnmdbus.la -introspection_libnmdbus_la_CPPFLAGS = $(GLIB_CFLAGS) +introspection_libnmdbus_la_CPPFLAGS = \ + $(GLIB_CFLAGS) \ + $(INTROSPECTION_EXTRA_CFLAGS) \ + $(NULL) introspection_sources = \ introspection/org.freedesktop.NetworkManager.AccessPoint.c \ @@ -903,8 +908,6 @@ dbusinterfaces_DATA = \ CLEANFILES += $(introspection_sources) CLEANFILES += $(DBUS_INTERFACE_DOCS) -$(dispatcher_libnm_dispatcher_core_la_OBJECTS): $(introspection_sources) -$(dispatcher_nm_dispatcher_OBJECTS): $(introspection_sources) $(libnm_liblibnm_la_OBJECTS): $(introspection_sources) $(libnm_libnm_la_OBJECTS): $(introspection_sources) @@ -925,6 +928,7 @@ libnm_core_lib_h_pub_real = \ libnm-core/nm-core-types.h \ libnm-core/nm-dbus-interface.h \ libnm-core/nm-errors.h \ + libnm-core/nm-keyfile.h \ libnm-core/nm-setting-6lowpan.h \ libnm-core/nm-setting-8021x.h \ libnm-core/nm-setting-adsl.h \ @@ -939,6 +943,7 @@ libnm_core_lib_h_pub_real = \ libnm-core/nm-setting-ethtool.h \ libnm-core/nm-setting-generic.h \ libnm-core/nm-setting-gsm.h \ + libnm-core/nm-setting-hostname.h \ libnm-core/nm-setting-infiniband.h \ libnm-core/nm-setting-ip-config.h \ libnm-core/nm-setting-ip-tunnel.h \ @@ -950,6 +955,7 @@ libnm_core_lib_h_pub_real = \ libnm-core/nm-setting-olpc-mesh.h \ libnm-core/nm-setting-ovs-bridge.h \ libnm-core/nm-setting-ovs-dpdk.h \ + libnm-core/nm-setting-ovs-external-ids.h \ libnm-core/nm-setting-ovs-interface.h \ libnm-core/nm-setting-ovs-patch.h \ libnm-core/nm-setting-ovs-port.h \ @@ -963,6 +969,7 @@ libnm_core_lib_h_pub_real = \ libnm-core/nm-setting-team.h \ libnm-core/nm-setting-tun.h \ libnm-core/nm-setting-user.h \ + libnm-core/nm-setting-veth.h \ libnm-core/nm-setting-vlan.h \ libnm-core/nm-setting-vpn.h \ libnm-core/nm-setting-vrf.h \ @@ -1012,6 +1019,7 @@ libnm_core_lib_c_settings_real = \ libnm-core/nm-setting-ethtool.c \ libnm-core/nm-setting-generic.c \ libnm-core/nm-setting-gsm.c \ + libnm-core/nm-setting-hostname.c \ libnm-core/nm-setting-infiniband.c \ libnm-core/nm-setting-ip-config.c \ libnm-core/nm-setting-ip-tunnel.c \ @@ -1023,6 +1031,7 @@ libnm_core_lib_c_settings_real = \ libnm-core/nm-setting-olpc-mesh.c \ libnm-core/nm-setting-ovs-bridge.c \ libnm-core/nm-setting-ovs-dpdk.c \ + libnm-core/nm-setting-ovs-external-ids.c \ libnm-core/nm-setting-ovs-interface.c \ libnm-core/nm-setting-ovs-patch.c \ libnm-core/nm-setting-ovs-port.c \ @@ -1036,6 +1045,7 @@ libnm_core_lib_c_settings_real = \ libnm-core/nm-setting-team.c \ libnm-core/nm-setting-tun.c \ libnm-core/nm-setting-user.c \ + libnm-core/nm-setting-veth.c \ libnm-core/nm-setting-vlan.c \ libnm-core/nm-setting-vpn.c \ libnm-core/nm-setting-vrf.c \ @@ -1216,6 +1226,7 @@ GLIB_GENERATED += \ libnm-core/tests/nm-core-tests-enum-types.h \ libnm-core/tests/nm-core-tests-enum-types.c nm_core_tests_enum_types_sources = libnm-core/tests/test-general-enums.h +nm_core_tests_enum_types_MKENUMS_C_FLAGS = --fhead '\#include "nm-default.h"\n' libnm-core/tests/nm-core-tests-enum-types.h.stamp: libnm-core/tests/.dirstamp libnm-core/tests/nm-core-tests-enum-types.c.stamp: libnm-core/tests/.dirstamp @@ -1354,6 +1365,7 @@ libnm_lib_h_pub_real = \ libnm/nm-device-ppp.h \ libnm/nm-device-team.h \ libnm/nm-device-tun.h \ + libnm/nm-device-veth.h \ libnm/nm-device-vlan.h \ libnm/nm-device-vrf.h \ libnm/nm-device-vxlan.h \ @@ -1418,6 +1430,7 @@ libnm_lib_c_real = \ libnm/nm-device-ppp.c \ libnm/nm-device-team.c \ libnm/nm-device-tun.c \ + libnm/nm-device-veth.c \ libnm/nm-device-vlan.c \ libnm/nm-device-vrf.c \ libnm/nm-device-vxlan.c \ @@ -1480,6 +1493,7 @@ nodist_libnm_liblibnm_la_SOURCES = \ libnm_liblibnm_la_LIBADD = \ libnm-core/nm-libnm-core-aux/libnm-libnm-core-aux.la \ + libnm-core/nm-keyfile/libnm-keyfile.la \ libnm-core/libnm-core.la \ $(libnm_crypto_lib) \ libnm-core/nm-libnm-core-intern/libnm-libnm-core-intern.la \ @@ -1573,6 +1587,7 @@ libnm_NM_1_0_gir_FILES = \ $(libnm_core_lib_c_real) \ $(libnm_lib_h_pub_mkenums) \ $(libnm_lib_h_pub_real) \ + libnm-core/nm-keyfile/nm-keyfile.c \ $(libnm_lib_c_mkenums) \ $(libnm_lib_c_real) libnm_NM_1_0_gir_SCANNERFLAGS = --warn-all --identifier-prefix=NM --symbol-prefix=nm @@ -1595,8 +1610,20 @@ libnm_noinst_data = \ noinst_DATA += $(libnm_noinst_data) +EXTRA_DIST += clients/cli/generate-docs-nm-settings-nmcli.xml.in + +if BUILD_DOCS clients/cli/generate-docs-nm-settings-nmcli.xml: clients/cli/generate-docs-nm-settings-nmcli - $(AM_V_GEN) clients/cli/generate-docs-nm-settings-nmcli > $@ + $(AM_V_GEN) clients/cli/generate-docs-nm-settings-nmcli > "$@" +check-local-generate-docs-nm-settings-nmcli: clients/cli/generate-docs-nm-settings-nmcli.xml + $(srcdir)/tools/check-compare-generated.sh "$(srcdir)" "$(builddir)" "$<" +check_local += check-local-generate-docs-nm-settings-nmcli +DISTCLEANFILES += clients/cli/generate-docs-nm-settings-nmcli.xml +else +clients/cli/generate-docs-nm-settings-nmcli.xml: clients/cli/generate-docs-nm-settings-nmcli.xml.in + $(AM_V_GEN) cp $^ $@ +check-local-generate-docs-nm-settings-nmcli: +endif libnm_docs_sources = $(libnm_core_lib_c_settings_real) @@ -2124,6 +2151,8 @@ src_libNetworkManagerBase_la_SOURCES = \ src/nm-netns.h \ src/nm-l3-config-data.c \ src/nm-l3-config-data.h \ + src/nm-l3-ipv4ll.c \ + src/nm-l3-ipv4ll.h \ src/nm-l3cfg.c \ src/nm-l3cfg.h \ src/nm-ip-config.c \ @@ -3020,7 +3049,10 @@ nodist_src_settings_plugins_ifcfg_rh_libnmdbus_ifcfg_rh_la_SOURCES = \ src/settings/plugins/ifcfg-rh/nmdbus-ifcfg-rh.c \ src/settings/plugins/ifcfg-rh/nmdbus-ifcfg-rh.h -src_settings_plugins_ifcfg_rh_libnmdbus_ifcfg_rh_la_CPPFLAGS = $(filter-out -DGLIB_VERSION_MAX_ALLOWED%,$(src_cppflags_base)) +src_settings_plugins_ifcfg_rh_libnmdbus_ifcfg_rh_la_CPPFLAGS = \ + $(filter-out -DGLIB_VERSION_MAX_ALLOWED%,$(src_cppflags_base)) \ + $(INTROSPECTION_EXTRA_CFLAGS) \ + $(NULL) CLEANFILES += $(nodist_src_settings_plugins_ifcfg_rh_libnmdbus_ifcfg_rh_la_SOURCES) @@ -4117,12 +4149,14 @@ src_tests_ldadd = \ check_programs += \ src/tests/test-core \ src/tests/test-core-with-expect \ + src/tests/test-dcb \ src/tests/test-ip4-config \ src/tests/test-ip6-config \ - src/tests/test-dcb \ + src/tests/test-l3cfg \ src/tests/test-systemd \ + src/tests/test-utils \ src/tests/test-wired-defname \ - src/tests/test-utils + $(NULL) src_tests_test_ip4_config_CPPFLAGS = $(src_cppflags_test) src_tests_test_ip4_config_LDFLAGS = $(src_tests_ldflags) @@ -4152,13 +4186,18 @@ src_tests_test_utils_CPPFLAGS = $(src_cppflags_test) src_tests_test_utils_LDFLAGS = $(src_tests_ldflags) src_tests_test_utils_LDADD = $(src_tests_ldadd) -$(src_tests_test_ip4_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums) -$(src_tests_test_ip6_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums) -$(src_tests_test_dcb_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +src_tests_test_l3cfg_CPPFLAGS = $(src_cppflags_test) +src_tests_test_l3cfg_LDFLAGS = $(src_devices_tests_ldflags) +src_tests_test_l3cfg_LDADD = $(src_tests_ldadd) + $(src_tests_test_core_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(src_tests_test_core_with_expect_OBJECTS): $(libnm_core_lib_h_pub_mkenums) -$(src_tests_test_wired_defname_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +$(src_tests_test_dcb_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +$(src_tests_test_ip4_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +$(src_tests_test_ip6_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +$(src_tests_test_l3cfg_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(src_tests_test_utils_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +$(src_tests_test_wired_defname_OBJECTS): $(libnm_core_lib_h_pub_mkenums) src_tests_test_systemd_CPPFLAGS = \ $(src_libnm_systemd_core_la_cppflags) \ @@ -4308,6 +4347,7 @@ dispatcher_tests_test_dispatcher_envp_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_CLIENT \ $(GLIB_CFLAGS) \ $(SANITIZER_EXEC_CFLAGS) \ + $(INTROSPECTION_EXTRA_CFLAGS) \ $(NULL) dispatcher_tests_test_dispatcher_envp_SOURCES = \ @@ -4433,12 +4473,12 @@ $(clients_common_libnmc_base_la_OBJECTS): $(libnm_lib_h_pub_mkenums) $(clients_common_libnmc_base_la_OBJECTS): clients/common/.dirstamp clients_common_settings_doc_h = clients/common/settings-docs.h -if HAVE_INTROSPECTION +if BUILD_DOCS $(clients_common_settings_doc_h): clients/common/settings-docs.xsl libnm/nm-settings-docs-gir.xml clients/common/.dirstamp $(AM_V_GEN) $(XSLTPROC) --output $@ $< $(word 2,$^) DISTCLEANFILES += $(clients_common_settings_doc_h) check-local-settings-docs: $(clients_common_settings_doc_h) - $(srcdir)/tools/check-settings-docs.sh "$(srcdir)" "$(builddir)" "$(clients_common_settings_doc_h)" + $(srcdir)/tools/check-compare-generated.sh "$(srcdir)" "$(builddir)" "$(clients_common_settings_doc_h)" check_local += check-local-settings-docs else $(clients_common_settings_doc_h): $(clients_common_settings_doc_h).in clients/common/.dirstamp @@ -4977,6 +5017,11 @@ EXTRA_DIST += \ clients/tests/test-client.check-on-disk/test_004.expected \ $(NULL) +check-local-gitlab-ci: + "$(srcdir)/tools/check-gitlab-ci.sh" "$(srcdir)" + +check_local += check-local-gitlab-ci + ############################################################################### # data ############################################################################### @@ -5265,7 +5310,8 @@ EXTRA_DIST += \ tools/check-config-options.sh \ tools/check-docs.sh \ tools/check-exports.sh \ - tools/check-settings-docs.sh \ + tools/check-compare-generated.sh \ + tools/check-gitlab-ci.sh \ tools/create-exports-NetworkManager.sh \ tools/debug-helper.py \ tools/meson-post-install.sh \ @@ -5295,7 +5341,7 @@ include Makefile.examples if WITH_PYTHON_BLACK check-python-black: - test "$$NMTST_SKIP_PYTHON_BLACK" != 1 && $(BLACK) --check $(top_srcdir) $(top_srcdir)/examples/python/gi/nm-wg-set + test "$$NMTST_SKIP_PYTHON_BLACK" == 1 || $(BLACK) --check $(top_srcdir) $(top_srcdir)/examples/python/gi/nm-wg-set check_local += check-python-black endif diff --git a/Makefile.examples b/Makefile.examples index 385a835..3cb4629 100644 --- a/Makefile.examples +++ b/Makefile.examples @@ -178,8 +178,10 @@ EXTRA_DIST += \ examples/python/gi/list-connections.py \ examples/python/gi/nm-add-connection2.py \ examples/python/gi/nm-connection-update-stable-id.py \ + examples/python/gi/nm-keyfile.py \ examples/python/gi/nm-update2.py \ examples/python/gi/nm-wg-set \ + examples/python/gi/ovs-external-ids.py \ examples/python/gi/setting-user-data.py \ examples/python/gi/show-wifi-networks.py \ examples/python/gi/update-ip4-method.py \ diff --git a/Makefile.in b/Makefile.in index e793d9a..24acffc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -162,13 +162,15 @@ TESTS = $(am__EXEEXT_12) @HAVE_INTROSPECTION_TRUE@am__append_8 = libnm/NM-1.0.typelib @HAVE_INTROSPECTION_TRUE@am__append_9 = libnm/NM-1.0.gir @HAVE_INTROSPECTION_TRUE@am__append_10 = $(libnm_noinst_data) -@HAVE_INTROSPECTION_TRUE@am__append_11 = $(libnm_noinst_data) -@HAVE_INTROSPECTION_TRUE@am__append_12 = $(libnm_noinst_data) \ -@HAVE_INTROSPECTION_TRUE@ $(clients_common_settings_doc_h) -@HAVE_INTROSPECTION_TRUE@am__append_13 = $(libnm_tests_programs_req_introspection) -@HAVE_INTROSPECTION_FALSE@am__append_14 = $(libnm_tests_programs_req_introspection) -@REQUIRE_ROOT_TESTS_TRUE@am__append_15 = -DREQUIRE_ROOT_TESTS=1 -@WITH_WEXT_TRUE@am__append_16 = \ +@HAVE_INTROSPECTION_TRUE@am__append_11 = clients/cli/generate-docs-nm-settings-nmcli.xml.in \ +@HAVE_INTROSPECTION_TRUE@ $(libnm_noinst_data) +@BUILD_DOCS_TRUE@@HAVE_INTROSPECTION_TRUE@am__append_12 = check-local-generate-docs-nm-settings-nmcli +@BUILD_DOCS_TRUE@@HAVE_INTROSPECTION_TRUE@am__append_13 = clients/cli/generate-docs-nm-settings-nmcli.xml +@HAVE_INTROSPECTION_TRUE@am__append_14 = $(libnm_noinst_data) +@HAVE_INTROSPECTION_TRUE@am__append_15 = $(libnm_tests_programs_req_introspection) +@HAVE_INTROSPECTION_FALSE@am__append_16 = $(libnm_tests_programs_req_introspection) +@REQUIRE_ROOT_TESTS_TRUE@am__append_17 = -DREQUIRE_ROOT_TESTS=1 +@WITH_WEXT_TRUE@am__append_18 = \ @WITH_WEXT_TRUE@ src/platform/wifi/nm-wifi-utils-wext.c \ @WITH_WEXT_TRUE@ src/platform/wifi/nm-wifi-utils-wext.h @@ -176,185 +178,186 @@ TESTS = $(am__EXEEXT_12) ############################################################################### # src/ppp ############################################################################### -@WITH_PPP_TRUE@am__append_17 = src/ppp/libnm-ppp-plugin.la -@WITH_PPP_TRUE@am__append_18 = src/ppp/nm-pppd-plugin.la +@WITH_PPP_TRUE@am__append_19 = src/ppp/libnm-ppp-plugin.la +@WITH_PPP_TRUE@am__append_20 = src/ppp/nm-pppd-plugin.la ############################################################################### # src/settings/plugins/ifcfg-rh ############################################################################### -@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_19 = src/settings/plugins/ifcfg-rh/libnm-settings-plugin-ifcfg-rh.la -@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_20 = \ +@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_21 = src/settings/plugins/ifcfg-rh/libnm-settings-plugin-ifcfg-rh.la +@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_22 = \ @CONFIG_PLUGIN_IFCFG_RH_TRUE@ src/settings/plugins/ifcfg-rh/libnmdbus-ifcfg-rh.la \ @CONFIG_PLUGIN_IFCFG_RH_TRUE@ src/settings/plugins/ifcfg-rh/libnms-ifcfg-rh-core.la -@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_21 = $(nodist_src_settings_plugins_ifcfg_rh_libnmdbus_ifcfg_rh_la_SOURCES) -@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_22 = check-local-symbols-settings-ifcfg-rh +@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_23 = $(nodist_src_settings_plugins_ifcfg_rh_libnmdbus_ifcfg_rh_la_SOURCES) +@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_24 = check-local-symbols-settings-ifcfg-rh ############################################################################### # src/settings/plugins/ifcfg-rh/tests ############################################################################### -@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_23 = src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh -@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_24 = \ +@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_25 = src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh +@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_26 = \ @CONFIG_PLUGIN_IFCFG_RH_TRUE@ src/settings/plugins/ifcfg-rh/nm-ifup \ @CONFIG_PLUGIN_IFCFG_RH_TRUE@ src/settings/plugins/ifcfg-rh/nm-ifdown -@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_25 = install-data-hook-ifcfg-rh +@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_27 = install-data-hook-ifcfg-rh ############################################################################### -@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_26 = src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.conf +@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_28 = src/settings/plugins/ifcfg-rh/nm-ifcfg-rh.conf ############################################################################### # src/settings/plugins/ifupdown ############################################################################### -@CONFIG_PLUGIN_IFUPDOWN_TRUE@am__append_27 = src/settings/plugins/ifupdown/libnm-settings-plugin-ifupdown.la -@CONFIG_PLUGIN_IFUPDOWN_TRUE@am__append_28 = src/settings/plugins/ifupdown/libnms-ifupdown-core.la -@CONFIG_PLUGIN_IFUPDOWN_TRUE@am__append_29 = check-local-symbols-settings-ifupdown +@CONFIG_PLUGIN_IFUPDOWN_TRUE@am__append_29 = src/settings/plugins/ifupdown/libnm-settings-plugin-ifupdown.la +@CONFIG_PLUGIN_IFUPDOWN_TRUE@am__append_30 = src/settings/plugins/ifupdown/libnms-ifupdown-core.la +@CONFIG_PLUGIN_IFUPDOWN_TRUE@am__append_31 = check-local-symbols-settings-ifupdown ############################################################################### -@CONFIG_PLUGIN_IFUPDOWN_TRUE@am__append_30 = src/settings/plugins/ifupdown/tests/test-ifupdown +@CONFIG_PLUGIN_IFUPDOWN_TRUE@am__append_32 = src/settings/plugins/ifupdown/tests/test-ifupdown ############################################################################### -@WITH_MODEM_MANAGER_1_TRUE@am__append_31 = \ +@WITH_MODEM_MANAGER_1_TRUE@am__append_33 = \ @WITH_MODEM_MANAGER_1_TRUE@ src/devices/wwan/libnm-wwan.la \ @WITH_MODEM_MANAGER_1_TRUE@ src/devices/wwan/libnm-device-plugin-wwan.la \ @WITH_MODEM_MANAGER_1_TRUE@ src/devices/bluetooth/libnm-device-plugin-bluetooth.la -@WITH_MODEM_MANAGER_1_TRUE@@WITH_OFONO_TRUE@am__append_32 = \ +@WITH_MODEM_MANAGER_1_TRUE@@WITH_OFONO_TRUE@am__append_34 = \ @WITH_MODEM_MANAGER_1_TRUE@@WITH_OFONO_TRUE@ src/devices/wwan/nm-modem-ofono.c \ @WITH_MODEM_MANAGER_1_TRUE@@WITH_OFONO_TRUE@ src/devices/wwan/nm-modem-ofono.h -@WITH_MODEM_MANAGER_1_TRUE@am__append_33 = check-local-devices-wwan \ +@WITH_MODEM_MANAGER_1_TRUE@am__append_35 = check-local-devices-wwan \ @WITH_MODEM_MANAGER_1_TRUE@ check-local-devices-bluetooth -@WITH_MODEM_MANAGER_1_TRUE@am__append_34 = src/devices/wwan/tests/test-service-providers +@WITH_MODEM_MANAGER_1_TRUE@am__append_36 = src/devices/wwan/tests/test-service-providers ############################################################################### # src/devices/bluetooth ############################################################################### -@WITH_MODEM_MANAGER_1_TRUE@am__append_35 = src/devices/bluetooth/libnm-bluetooth-utils.la -@WITH_BLUEZ5_DUN_TRUE@@WITH_MODEM_MANAGER_1_TRUE@am__append_36 = \ +@WITH_MODEM_MANAGER_1_TRUE@am__append_37 = src/devices/bluetooth/libnm-bluetooth-utils.la +@WITH_BLUEZ5_DUN_TRUE@@WITH_MODEM_MANAGER_1_TRUE@am__append_38 = \ @WITH_BLUEZ5_DUN_TRUE@@WITH_MODEM_MANAGER_1_TRUE@ src/devices/bluetooth/nm-bluez5-dun.c \ @WITH_BLUEZ5_DUN_TRUE@@WITH_MODEM_MANAGER_1_TRUE@ src/devices/bluetooth/nm-bluez5-dun.h \ @WITH_BLUEZ5_DUN_TRUE@@WITH_MODEM_MANAGER_1_TRUE@ $(NULL) -@WITH_BLUEZ5_DUN_TRUE@@WITH_MODEM_MANAGER_1_TRUE@am__append_37 = $(BLUEZ5_CFLAGS) -@WITH_BLUEZ5_DUN_TRUE@@WITH_MODEM_MANAGER_1_TRUE@am__append_38 = $(BLUEZ5_LIBS) +@WITH_BLUEZ5_DUN_TRUE@@WITH_MODEM_MANAGER_1_TRUE@am__append_39 = $(BLUEZ5_CFLAGS) +@WITH_BLUEZ5_DUN_TRUE@@WITH_MODEM_MANAGER_1_TRUE@am__append_40 = $(BLUEZ5_LIBS) ############################################################################### -@WITH_MODEM_MANAGER_1_TRUE@am__append_39 = \ +@WITH_MODEM_MANAGER_1_TRUE@am__append_41 = \ @WITH_MODEM_MANAGER_1_TRUE@ src/devices/bluetooth/tests/nm-bt-test ############################################################################### # src/devices/wifi ############################################################################### -@WITH_WIFI_TRUE@am__append_40 = src/devices/wifi/libnm-wifi-base.la -@WITH_IWD_TRUE@@WITH_WIFI_TRUE@am__append_41 = \ +@WITH_WIFI_TRUE@am__append_42 = src/devices/wifi/libnm-wifi-base.la +@WITH_IWD_TRUE@@WITH_WIFI_TRUE@am__append_43 = \ @WITH_IWD_TRUE@@WITH_WIFI_TRUE@ src/devices/wifi/nm-device-iwd.c \ @WITH_IWD_TRUE@@WITH_WIFI_TRUE@ src/devices/wifi/nm-device-iwd.h \ @WITH_IWD_TRUE@@WITH_WIFI_TRUE@ src/devices/wifi/nm-iwd-manager.c \ @WITH_IWD_TRUE@@WITH_WIFI_TRUE@ src/devices/wifi/nm-iwd-manager.h \ @WITH_IWD_TRUE@@WITH_WIFI_TRUE@ $(NULL) -@WITH_WIFI_TRUE@am__append_42 = src/devices/wifi/libnm-device-plugin-wifi.la -@WITH_WIFI_TRUE@am__append_43 = check-local-devices-wifi -@WITH_WIFI_TRUE@am__append_44 = src/devices/wifi/tests/test-devices-wifi +@WITH_WIFI_TRUE@am__append_44 = src/devices/wifi/libnm-device-plugin-wifi.la +@WITH_WIFI_TRUE@am__append_45 = check-local-devices-wifi +@WITH_WIFI_TRUE@am__append_46 = src/devices/wifi/tests/test-devices-wifi ############################################################################### # src/devices/team ############################################################################### -@WITH_TEAMDCTL_TRUE@am__append_45 = src/devices/team/libnm-device-plugin-team.la -@WITH_TEAMDCTL_TRUE@am__append_46 = check-local-devices-team -@WITH_OPENVSWITCH_TRUE@am__append_47 = src/devices/ovs/libnm-device-plugin-ovs.la -@HAVE_INTROSPECTION_TRUE@am__append_48 = check-local-settings-docs -@HAVE_INTROSPECTION_TRUE@am__append_49 = clients/common/libnmc.la -@HAVE_INTROSPECTION_FALSE@am__append_50 = clients/common/libnmc.la -@HAVE_INTROSPECTION_TRUE@am__append_51 = clients/common/tests/test-clients-common -@BUILD_NMCLI_TRUE@@HAVE_INTROSPECTION_FALSE@am__append_52 = clients/common/tests/test-clients-common +@WITH_TEAMDCTL_TRUE@am__append_47 = src/devices/team/libnm-device-plugin-team.la +@WITH_TEAMDCTL_TRUE@am__append_48 = check-local-devices-team +@WITH_OPENVSWITCH_TRUE@am__append_49 = src/devices/ovs/libnm-device-plugin-ovs.la +@BUILD_DOCS_TRUE@am__append_50 = $(clients_common_settings_doc_h) +@BUILD_DOCS_TRUE@am__append_51 = check-local-settings-docs +@HAVE_INTROSPECTION_TRUE@am__append_52 = clients/common/libnmc.la +@HAVE_INTROSPECTION_FALSE@am__append_53 = clients/common/libnmc.la +@HAVE_INTROSPECTION_TRUE@am__append_54 = clients/common/tests/test-clients-common +@BUILD_NMCLI_TRUE@@HAVE_INTROSPECTION_FALSE@am__append_55 = clients/common/tests/test-clients-common ############################################################################### # clients/cli ############################################################################### -@BUILD_NMCLI_TRUE@am__append_53 = clients/cli/nmcli -@BUILD_NMCLI_TRUE@am__append_54 = install-data-hook-nmcli -@BUILD_NMCLI_TRUE@am__append_55 = uninstall-hook-nmcli +@BUILD_NMCLI_TRUE@am__append_56 = clients/cli/nmcli +@BUILD_NMCLI_TRUE@am__append_57 = install-data-hook-nmcli +@BUILD_NMCLI_TRUE@am__append_58 = uninstall-hook-nmcli ############################################################################### # clients/tui ############################################################################### -@BUILD_NMTUI_TRUE@am__append_56 = clients/tui/newt/libnmt-newt.a -@BUILD_NMTUI_TRUE@am__append_57 = clients/tui/nmtui -@BUILD_NMTUI_TRUE@am__append_58 = install-exec-hook-nmtui -@BUILD_NMTUI_TRUE@am__append_59 = uninstall-hook-nmtui +@BUILD_NMTUI_TRUE@am__append_59 = clients/tui/newt/libnmt-newt.a +@BUILD_NMTUI_TRUE@am__append_60 = clients/tui/nmtui +@BUILD_NMTUI_TRUE@am__append_61 = install-exec-hook-nmtui +@BUILD_NMTUI_TRUE@am__append_62 = uninstall-hook-nmtui ############################################################################### # clients/nm-cloud-setup ############################################################################### -@BUILD_NM_CLOUD_SETUP_TRUE@am__append_60 = clients/cloud-setup/nm-cloud-setup -@BUILD_NM_CLOUD_SETUP_TRUE@@HAVE_SYSTEMD_TRUE@am__append_61 = \ +@BUILD_NM_CLOUD_SETUP_TRUE@am__append_63 = clients/cloud-setup/nm-cloud-setup +@BUILD_NM_CLOUD_SETUP_TRUE@@HAVE_SYSTEMD_TRUE@am__append_64 = \ @BUILD_NM_CLOUD_SETUP_TRUE@@HAVE_SYSTEMD_TRUE@ clients/cloud-setup/nm-cloud-setup.service \ @BUILD_NM_CLOUD_SETUP_TRUE@@HAVE_SYSTEMD_TRUE@ clients/cloud-setup/nm-cloud-setup.timer \ @BUILD_NM_CLOUD_SETUP_TRUE@@HAVE_SYSTEMD_TRUE@ $(NULL) -@BUILD_NM_CLOUD_SETUP_TRUE@@HAVE_SYSTEMD_TRUE@am__append_62 = install-data-hook-cloud-setup -@BUILD_NM_CLOUD_SETUP_TRUE@@HAVE_SYSTEMD_TRUE@am__append_63 = uninstall-hook-cloud-setup -@BUILD_NM_CLOUD_SETUP_TRUE@am__append_64 = \ +@BUILD_NM_CLOUD_SETUP_TRUE@@HAVE_SYSTEMD_TRUE@am__append_65 = install-data-hook-cloud-setup +@BUILD_NM_CLOUD_SETUP_TRUE@@HAVE_SYSTEMD_TRUE@am__append_66 = uninstall-hook-cloud-setup +@BUILD_NM_CLOUD_SETUP_TRUE@am__append_67 = \ @BUILD_NM_CLOUD_SETUP_TRUE@ clients/cloud-setup/90-nm-cloud-setup.sh \ @BUILD_NM_CLOUD_SETUP_TRUE@ clients/cloud-setup/meson.build \ @BUILD_NM_CLOUD_SETUP_TRUE@ clients/cloud-setup/nm-cloud-setup.service.in \ @BUILD_NM_CLOUD_SETUP_TRUE@ clients/cloud-setup/nm-cloud-setup.timer \ @BUILD_NM_CLOUD_SETUP_TRUE@ $(NULL) -@BUILD_NM_CLOUD_SETUP_TRUE@am__append_65 = \ +@BUILD_NM_CLOUD_SETUP_TRUE@am__append_68 = \ @BUILD_NM_CLOUD_SETUP_TRUE@ clients/cloud-setup/nm-cloud-setup.service ############################################################################### # data ############################################################################### -@HAVE_SYSTEMD_TRUE@am__append_66 = \ +@HAVE_SYSTEMD_TRUE@am__append_69 = \ @HAVE_SYSTEMD_TRUE@ data/NetworkManager.service \ @HAVE_SYSTEMD_TRUE@ data/NetworkManager-wait-online.service \ @HAVE_SYSTEMD_TRUE@ data/NetworkManager-dispatcher.service \ @HAVE_SYSTEMD_TRUE@ $(NULL) -@HAVE_INTROSPECTION_TRUE@am__append_67 = $(man_nm_settings_xml) -@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_68 = man/nm-settings-ifcfg-rh.5 -@CONFIG_PLUGIN_IFCFG_RH_FALSE@am__append_69 = man/nm-settings-ifcfg-rh.5 -@CONFIG_PLUGIN_IFCFG_RH_FALSE@am__append_70 = man/nm-settings-ifcfg-rh.5 -@WITH_OPENVSWITCH_TRUE@am__append_71 = man/nm-openvswitch.7 -@WITH_OPENVSWITCH_FALSE@am__append_72 = man/nm-openvswitch.7 -@WITH_OPENVSWITCH_FALSE@am__append_73 = man/nm-openvswitch.7 -@HAVE_DOCS_TRUE@am__append_74 = install-data-hook-man -@HAVE_DOCS_TRUE@am__append_75 = uninstall-hook-man -@HAVE_DOCS_TRUE@am__append_76 = $(man_pages) $(man_pages_autogen) -@BUILD_DOCS_TRUE@am__append_77 = $(man_pages) $(man_pages_autogen) +@HAVE_INTROSPECTION_TRUE@am__append_70 = $(man_nm_settings_xml) +@CONFIG_PLUGIN_IFCFG_RH_TRUE@am__append_71 = man/nm-settings-ifcfg-rh.5 +@CONFIG_PLUGIN_IFCFG_RH_FALSE@am__append_72 = man/nm-settings-ifcfg-rh.5 +@CONFIG_PLUGIN_IFCFG_RH_FALSE@am__append_73 = man/nm-settings-ifcfg-rh.5 +@WITH_OPENVSWITCH_TRUE@am__append_74 = man/nm-openvswitch.7 +@WITH_OPENVSWITCH_FALSE@am__append_75 = man/nm-openvswitch.7 +@WITH_OPENVSWITCH_FALSE@am__append_76 = man/nm-openvswitch.7 +@HAVE_DOCS_TRUE@am__append_77 = install-data-hook-man +@HAVE_DOCS_TRUE@am__append_78 = uninstall-hook-man +@HAVE_DOCS_TRUE@am__append_79 = $(man_pages) $(man_pages_autogen) +@BUILD_DOCS_TRUE@am__append_80 = $(man_pages) $(man_pages_autogen) ############################################################################### # vapi ############################################################################### -@ENABLE_VAPIGEN_TRUE@am__append_78 = \ +@ENABLE_VAPIGEN_TRUE@am__append_81 = \ @ENABLE_VAPIGEN_TRUE@ vapi/libnm.vapi -@ENABLE_VAPIGEN_TRUE@am__append_79 = \ +@ENABLE_VAPIGEN_TRUE@am__append_82 = \ @ENABLE_VAPIGEN_TRUE@ $(VAPIGEN_VAPIS) \ @ENABLE_VAPIGEN_TRUE@ $(VAPIGEN_VAPIS:.vapi=.deps) -@ENABLE_VAPIGEN_TRUE@am__append_80 = $(VAPIGEN_VAPIS) +@ENABLE_VAPIGEN_TRUE@am__append_83 = $(VAPIGEN_VAPIS) ############################################################################### -@ENABLE_TESTS_TRUE@am__append_81 = $(check_programs) $(check_programs_norun) -@ENABLE_TESTS_TRUE@am__append_82 = $(check_ltlibraries) -@ENABLE_TESTS_FALSE@am__append_83 = $(check_programs) $(check_programs_norun) -@ENABLE_TESTS_FALSE@am__append_84 = $(check_ltlibraries) -@WITH_QT_TRUE@am__append_85 = \ +@ENABLE_TESTS_TRUE@am__append_84 = $(check_programs) $(check_programs_norun) +@ENABLE_TESTS_TRUE@am__append_85 = $(check_ltlibraries) +@ENABLE_TESTS_FALSE@am__append_86 = $(check_programs) $(check_programs_norun) +@ENABLE_TESTS_FALSE@am__append_87 = $(check_ltlibraries) +@WITH_QT_TRUE@am__append_88 = \ @WITH_QT_TRUE@ examples/C/qt/add-connection-wired \ @WITH_QT_TRUE@ examples/C/qt/list-connections \ @WITH_QT_TRUE@ examples/C/qt/change-ipv4-addresses \ @WITH_QT_TRUE@ examples/C/qt/monitor-nm-running -@WITH_QT_TRUE@am__append_86 = \ +@WITH_QT_TRUE@am__append_89 = \ @WITH_QT_TRUE@ examples/C/qt/monitor-nm-running.moc -@WITH_PYTHON_BLACK_TRUE@am__append_87 = check-python-black +@WITH_PYTHON_BLACK_TRUE@am__append_90 = check-python-black subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/attributes.m4 \ @@ -447,11 +450,11 @@ am__EXEEXT_12 = shared/nm-glib-aux/tests/test-shared-general$(EXEEXT) \ src/tests/config/test-config$(EXEEXT) \ src/tests/test-core$(EXEEXT) \ src/tests/test-core-with-expect$(EXEEXT) \ - src/tests/test-ip4-config$(EXEEXT) \ - src/tests/test-ip6-config$(EXEEXT) src/tests/test-dcb$(EXEEXT) \ - src/tests/test-systemd$(EXEEXT) \ - src/tests/test-wired-defname$(EXEEXT) \ + src/tests/test-dcb$(EXEEXT) src/tests/test-ip4-config$(EXEEXT) \ + src/tests/test-ip6-config$(EXEEXT) \ + src/tests/test-l3cfg$(EXEEXT) src/tests/test-systemd$(EXEEXT) \ src/tests/test-utils$(EXEEXT) \ + src/tests/test-wired-defname$(EXEEXT) \ dispatcher/tests/test-dispatcher-envp$(EXEEXT) \ $(am__EXEEXT_10) $(am__EXEEXT_11) \ clients/common/tests/test-libnm-core-aux$(EXEEXT) @@ -683,6 +686,7 @@ am__objects_3 = libnm-core/libnm_core_la-nm-setting-6lowpan.lo \ libnm-core/libnm_core_la-nm-setting-ethtool.lo \ libnm-core/libnm_core_la-nm-setting-generic.lo \ libnm-core/libnm_core_la-nm-setting-gsm.lo \ + libnm-core/libnm_core_la-nm-setting-hostname.lo \ libnm-core/libnm_core_la-nm-setting-infiniband.lo \ libnm-core/libnm_core_la-nm-setting-ip-config.lo \ libnm-core/libnm_core_la-nm-setting-ip-tunnel.lo \ @@ -694,6 +698,7 @@ am__objects_3 = libnm-core/libnm_core_la-nm-setting-6lowpan.lo \ libnm-core/libnm_core_la-nm-setting-olpc-mesh.lo \ libnm-core/libnm_core_la-nm-setting-ovs-bridge.lo \ libnm-core/libnm_core_la-nm-setting-ovs-dpdk.lo \ + libnm-core/libnm_core_la-nm-setting-ovs-external-ids.lo \ libnm-core/libnm_core_la-nm-setting-ovs-interface.lo \ libnm-core/libnm_core_la-nm-setting-ovs-patch.lo \ libnm-core/libnm_core_la-nm-setting-ovs-port.lo \ @@ -707,6 +712,7 @@ am__objects_3 = libnm-core/libnm_core_la-nm-setting-6lowpan.lo \ libnm-core/libnm_core_la-nm-setting-team.lo \ libnm-core/libnm_core_la-nm-setting-tun.lo \ libnm-core/libnm_core_la-nm-setting-user.lo \ + libnm-core/libnm_core_la-nm-setting-veth.lo \ libnm-core/libnm_core_la-nm-setting-vlan.lo \ libnm-core/libnm_core_la-nm-setting-vpn.lo \ libnm-core/libnm_core_la-nm-setting-vrf.lo \ @@ -807,6 +813,7 @@ libnm_core_nm_libnm_core_intern_libnm_libnm_core_intern_la_LINK = \ $(LDFLAGS) -o $@ libnm_liblibnm_la_DEPENDENCIES = \ libnm-core/nm-libnm-core-aux/libnm-libnm-core-aux.la \ + libnm-core/nm-keyfile/libnm-keyfile.la \ libnm-core/libnm-core.la $(libnm_crypto_lib) \ libnm-core/nm-libnm-core-intern/libnm-libnm-core-intern.la \ introspection/libnmdbus.la \ @@ -843,6 +850,7 @@ am__objects_6 = libnm/liblibnm_la-nm-client.lo \ libnm/liblibnm_la-nm-device-ppp.lo \ libnm/liblibnm_la-nm-device-team.lo \ libnm/liblibnm_la-nm-device-tun.lo \ + libnm/liblibnm_la-nm-device-veth.lo \ libnm/liblibnm_la-nm-device-vlan.lo \ libnm/liblibnm_la-nm-device-vrf.lo \ libnm/liblibnm_la-nm-device-vxlan.lo \ @@ -1357,7 +1365,8 @@ am__src_libNetworkManagerBase_la_SOURCES_DIST = src/nm-core-utils.c \ src/ndisc/nm-ndisc.h src/ndisc/nm-ndisc-private.h \ src/nm-dbus-utils.c src/nm-dbus-utils.h src/nm-dbus-object.c \ src/nm-dbus-object.h src/nm-netns.c src/nm-netns.h \ - src/nm-l3-config-data.c src/nm-l3-config-data.h src/nm-l3cfg.c \ + src/nm-l3-config-data.c src/nm-l3-config-data.h \ + src/nm-l3-ipv4ll.c src/nm-l3-ipv4ll.h src/nm-l3cfg.c \ src/nm-l3cfg.h src/nm-ip-config.c src/nm-ip-config.h \ src/nm-ip4-config.c src/nm-ip4-config.h src/nm-ip6-config.c \ src/nm-ip6-config.h src/dhcp/nm-dhcp-client.c \ @@ -1390,6 +1399,7 @@ am_src_libNetworkManagerBase_la_OBJECTS = \ src/libNetworkManagerBase_la-nm-dbus-object.lo \ src/libNetworkManagerBase_la-nm-netns.lo \ src/libNetworkManagerBase_la-nm-l3-config-data.lo \ + src/libNetworkManagerBase_la-nm-l3-ipv4ll.lo \ src/libNetworkManagerBase_la-nm-l3cfg.lo \ src/libNetworkManagerBase_la-nm-ip-config.lo \ src/libNetworkManagerBase_la-nm-ip4-config.lo \ @@ -2445,6 +2455,14 @@ src_tests_test_ip6_config_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(src_tests_test_ip6_config_LDFLAGS) \ $(LDFLAGS) -o $@ +src_tests_test_l3cfg_SOURCES = src/tests/test-l3cfg.c +src_tests_test_l3cfg_OBJECTS = \ + src/tests/test_l3cfg-test-l3cfg.$(OBJEXT) +src_tests_test_l3cfg_DEPENDENCIES = $(src_tests_ldadd) +src_tests_test_l3cfg_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) $(src_tests_test_l3cfg_LDFLAGS) \ + $(LDFLAGS) -o $@ src_tests_test_systemd_SOURCES = src/tests/test-systemd.c src_tests_test_systemd_OBJECTS = \ src/tests/test_systemd-test-systemd.$(OBJEXT) @@ -2659,6 +2677,7 @@ am__depfiles_remade = clients/$(DEPDIR)/nm_online-nm-online.Po \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ethtool.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-generic.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-gsm.Plo \ + libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-hostname.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-infiniband.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ip-config.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ip-tunnel.Plo \ @@ -2670,6 +2689,7 @@ am__depfiles_remade = clients/$(DEPDIR)/nm_online-nm-online.Po \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-olpc-mesh.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-bridge.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-dpdk.Plo \ + libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-external-ids.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-interface.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-patch.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-port.Plo \ @@ -2683,6 +2703,7 @@ am__depfiles_remade = clients/$(DEPDIR)/nm_online-nm-online.Po \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-team.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-tun.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-user.Plo \ + libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-veth.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vlan.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vpn.Plo \ libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vrf.Plo \ @@ -2741,6 +2762,7 @@ am__depfiles_remade = clients/$(DEPDIR)/nm_online-nm-online.Po \ libnm/$(DEPDIR)/liblibnm_la-nm-device-ppp.Plo \ libnm/$(DEPDIR)/liblibnm_la-nm-device-team.Plo \ libnm/$(DEPDIR)/liblibnm_la-nm-device-tun.Plo \ + libnm/$(DEPDIR)/liblibnm_la-nm-device-veth.Plo \ libnm/$(DEPDIR)/liblibnm_la-nm-device-vlan.Plo \ libnm/$(DEPDIR)/liblibnm_la-nm-device-vrf.Plo \ libnm/$(DEPDIR)/liblibnm_la-nm-device-vxlan.Plo \ @@ -2864,6 +2886,7 @@ am__depfiles_remade = clients/$(DEPDIR)/nm_online-nm-online.Po \ src/$(DEPDIR)/libNetworkManagerBase_la-nm-ip4-config.Plo \ src/$(DEPDIR)/libNetworkManagerBase_la-nm-ip6-config.Plo \ src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3-config-data.Plo \ + src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3-ipv4ll.Plo \ src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3cfg.Plo \ src/$(DEPDIR)/libNetworkManagerBase_la-nm-logging.Plo \ src/$(DEPDIR)/libNetworkManagerBase_la-nm-netns.Plo \ @@ -3074,6 +3097,7 @@ am__depfiles_remade = clients/$(DEPDIR)/nm_online-nm-online.Po \ src/tests/$(DEPDIR)/test_dcb-test-dcb.Po \ src/tests/$(DEPDIR)/test_ip4_config-test-ip4-config.Po \ src/tests/$(DEPDIR)/test_ip6_config-test-ip6-config.Po \ + src/tests/$(DEPDIR)/test_l3cfg-test-l3cfg.Po \ src/tests/$(DEPDIR)/test_systemd-test-systemd.Po \ src/tests/$(DEPDIR)/test_utils-test-utils.Po \ src/tests/$(DEPDIR)/test_wired_defname-test-wired-defname.Po \ @@ -3233,8 +3257,8 @@ SOURCES = $(clients_tui_newt_libnmt_newt_a_SOURCES) \ $(src_tests_config_test_config_SOURCES) src/tests/test-core.c \ src/tests/test-core-with-expect.c src/tests/test-dcb.c \ src/tests/test-ip4-config.c src/tests/test-ip6-config.c \ - src/tests/test-systemd.c src/tests/test-utils.c \ - src/tests/test-wired-defname.c + src/tests/test-l3cfg.c src/tests/test-systemd.c \ + src/tests/test-utils.c src/tests/test-wired-defname.c DIST_SOURCES = $(am__clients_tui_newt_libnmt_newt_a_SOURCES_DIST) \ $(clients_common_libnmc_base_la_SOURCES) \ $(clients_common_libnmc_la_SOURCES) \ @@ -3345,8 +3369,8 @@ DIST_SOURCES = $(am__clients_tui_newt_libnmt_newt_a_SOURCES_DIST) \ $(src_tests_config_test_config_SOURCES) src/tests/test-core.c \ src/tests/test-core-with-expect.c src/tests/test-dcb.c \ src/tests/test-ip4-config.c src/tests/test-ip6-config.c \ - src/tests/test-systemd.c src/tests/test-utils.c \ - src/tests/test-wired-defname.c + src/tests/test-l3cfg.c src/tests/test-systemd.c \ + src/tests/test-utils.c src/tests/test-wired-defname.c RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ @@ -3982,13 +4006,13 @@ noinst_LTLIBRARIES = shared/libcsiphash.la shared/libcrbtree.la \ src/libnm-systemd-core.la $(NULL) \ shared/systemd/libnm-systemd-logging-stub.la \ shared/systemd/libnm-systemd-shared.la \ - src/initrd/libnmi-core.la $(am__append_20) $(am__append_28) \ - $(am__append_35) $(am__append_40) \ - dispatcher/libnm-dispatcher-core.la $(am__append_82) -check_LTLIBRARIES = $(am__append_84) -noinst_LIBRARIES = $(am__append_56) + src/initrd/libnmi-core.la $(am__append_22) $(am__append_30) \ + $(am__append_37) $(am__append_42) \ + dispatcher/libnm-dispatcher-core.la $(am__append_85) +check_LTLIBRARIES = $(am__append_87) +noinst_LIBRARIES = $(am__append_59) noinst_DATA = $(am__append_10) -dist_libexec_SCRIPTS = $(am__append_24) +dist_libexec_SCRIPTS = $(am__append_26) ############################################################################### lib_LTLIBRARIES = libnm/libnm.la @@ -3997,29 +4021,29 @@ plugin_LTLIBRARIES = $(core_plugins) ############################################################################### # src/devices/adsl ############################################################################### -core_plugins = $(am__append_17) $(am__append_19) $(am__append_27) \ - src/devices/adsl/libnm-device-plugin-adsl.la $(am__append_31) \ - $(am__append_42) $(am__append_45) $(am__append_47) +core_plugins = $(am__append_19) $(am__append_21) $(am__append_29) \ + src/devices/adsl/libnm-device-plugin-adsl.la $(am__append_33) \ + $(am__append_44) $(am__append_47) $(am__append_49) service_DATA = -man_MANS = $(am__append_76) +man_MANS = $(am__append_79) examples_DATA = data/server.conf CLEANFILES = $(introspection_sources) $(DBUS_INTERFACE_DOCS) \ - src/NetworkManager.ver $(am__append_21) \ + src/NetworkManager.ver $(am__append_23) \ $(dispatcher_nmdbus_dispatcher_sources) \ dispatcher/org.freedesktop.nm_dispatcher.service \ - $(am__append_65) clients/tests/test-client.log \ + $(am__append_68) clients/tests/test-client.log \ data/NetworkManager-dispatcher.service \ data/NetworkManager-wait-online.service \ data/NetworkManager.service data/server.conf $(NULL) \ - $(am__append_67) man/common.ent $(am__append_77) \ - $(am__append_80) $(GLIB_GENERATED) $(INTROSPECTION_GIRS) \ + $(am__append_70) man/common.ent $(am__append_80) \ + $(am__append_83) $(GLIB_GENERATED) $(INTROSPECTION_GIRS) \ $(typelib_DATA) cscope.in.out cscope.out cscope.po.out $(NULL) \ - $(am__append_86) + $(am__append_89) ############################################################################### DISTCLEANFILES = config-extra.h intltool-extract intltool-merge \ intltool-update $(polkit_policy_DATA) libnm/libnm.pc \ - $(am__append_12) + $(am__append_13) $(am__append_14) $(am__append_50) ############################################################################### @@ -4615,7 +4639,7 @@ EXTRA_DIST = shared/c-stdaux/src/c-stdaux.h $(NULL) \ clients/cli/nmcli-completion clients/cli/meson.build \ clients/common/settings-docs.xsl clients/common/meson.build \ clients/common/tests/meson.build clients/tui/meson.build \ - clients/tui/newt/meson.build $(am__append_64) \ + clients/tui/newt/meson.build $(am__append_67) \ clients/tests/test-client.py \ clients/tests/test-client.check-on-disk/test_001.expected \ clients/tests/test-client.check-on-disk/test_002.expected \ @@ -4628,7 +4652,7 @@ EXTRA_DIST = shared/c-stdaux/src/c-stdaux.h $(NULL) \ data/NetworkManager-wait-online.service.in \ data/NetworkManager.service.in data/meson.build \ data/nm-shared.xml data/server.conf.in $(NULL) \ - $(am__append_69) $(am__append_72) man/common.ent.in \ + $(am__append_72) $(am__append_75) man/common.ent.in \ $(man_nm_settings_xml) $(addsuffix .xsl,$(basename \ $(man_nm_settings_xml))) $(man_pages) $(addsuffix \ .xml,$(basename $(man_pages))) $(man_pages_autogen) $(NULL) \ @@ -4650,7 +4674,8 @@ EXTRA_DIST = shared/c-stdaux/src/c-stdaux.h $(NULL) \ shared/nm-utils/nm-vpn-plugin-utils.h \ shared/nm-version-macros.h.in shared/meson.build \ tools/check-config-options.sh tools/check-docs.sh \ - tools/check-exports.sh tools/check-settings-docs.sh \ + tools/check-exports.sh tools/check-compare-generated.sh \ + tools/check-gitlab-ci.sh \ tools/create-exports-NetworkManager.sh tools/debug-helper.py \ tools/meson-post-install.sh tools/run-nm-test.sh \ tools/test-networkmanager-service.py \ @@ -4699,7 +4724,9 @@ EXTRA_DIST = shared/c-stdaux/src/c-stdaux.h $(NULL) \ examples/python/gi/list-connections.py \ examples/python/gi/nm-add-connection2.py \ examples/python/gi/nm-connection-update-stable-id.py \ + examples/python/gi/nm-keyfile.py \ examples/python/gi/nm-update2.py examples/python/gi/nm-wg-set \ + examples/python/gi/ovs-external-ids.py \ examples/python/gi/setting-user-data.py \ examples/python/gi/show-wifi-networks.py \ examples/python/gi/update-ip4-method.py \ @@ -4710,18 +4737,18 @@ EXTRA_DIST = shared/c-stdaux/src/c-stdaux.h $(NULL) \ examples/shell/get-hostname.sh examples/shell/list-devices.sh \ examples/shell/disconnect-device.sh \ examples/shell/active-wifi.sh $(NULL) -EXTRA_LTLIBRARIES = $(am__append_50) +EXTRA_LTLIBRARIES = $(am__append_53) dist_hook = dist-hook-settings-ifcfg-rh-alias-files dist_dependencies = libnm-core/nm-vpn-dbus-types.xml \ - libnm-core/nm-dbus-types.xml $(am__append_70) $(am__append_73) \ + libnm-core/nm-dbus-types.xml $(am__append_73) $(am__append_76) \ $(man_pages) $(man_pages_autogen) dist_configure_check = $(am__append_2) -install_data_hook = install-data-hook-dirs $(am__append_25) \ - install-data-hook-dispatcher $(am__append_54) $(am__append_62) \ - $(am__append_74) -install_exec_hook = $(am__append_58) -uninstall_hook = $(am__append_55) $(am__append_59) $(am__append_63) \ - $(am__append_75) +install_data_hook = install-data-hook-dirs $(am__append_27) \ + install-data-hook-dispatcher $(am__append_57) $(am__append_65) \ + $(am__append_77) +install_exec_hook = $(am__append_61) +uninstall_hook = $(am__append_58) $(am__append_62) $(am__append_66) \ + $(am__append_78) BUILT_SOURCES = libnm-core/nm-vpn-dbus-types.xml \ libnm-core/nm-dbus-types.xml $(gir_DATA) $(typelib_DATA) GLIB_GENERATED = $(libnm_core_lib_h_pub_mkenums) \ @@ -4731,9 +4758,9 @@ GLIB_GENERATED = $(libnm_core_lib_h_pub_mkenums) \ $(libnm_lib_h_pub_mkenums) $(libnm_lib_c_mkenums) man_pages = man/NetworkManager.8 man/NetworkManager.conf.5 \ man/nm-online.1 man/nm-initrd-generator.8 man/nmcli-examples.7 \ - man/nmcli.1 man/nmtui.1 $(am__append_71) + man/nmcli.1 man/nmtui.1 $(am__append_74) man_pages_autogen = man/nm-settings-dbus.5 man/nm-settings-keyfile.5 \ - man/nm-settings-nmcli.5 $(NULL) $(am__append_68) + man/nm-settings-nmcli.5 $(NULL) $(am__append_71) ############################################################################### @@ -4768,14 +4795,14 @@ check_programs = shared/nm-glib-aux/tests/test-shared-general \ libnm-core/tests/test-keyfile libnm-core/tests/test-secrets \ libnm-core/tests/test-setting \ libnm-core/tests/test-settings-defaults libnm/tests/test-libnm \ - $(am__append_13) src/initrd/tests/test-dt-reader \ + $(am__append_15) src/initrd/tests/test-dt-reader \ src/initrd/tests/test-ibft-reader \ src/initrd/tests/test-cmdline-reader \ src/dhcp/tests/test-dhcp-dhclient \ src/dhcp/tests/test-dhcp-utils \ src/settings/plugins/keyfile/tests/test-keyfile-settings \ - $(am__append_23) $(am__append_30) $(am__append_34) \ - $(am__append_44) src/dnsmasq/tests/test-dnsmasq-utils \ + $(am__append_25) $(am__append_32) $(am__append_36) \ + $(am__append_46) src/dnsmasq/tests/test-dnsmasq-utils \ src/platform/tests/test-address-fake \ src/platform/tests/test-address-linux \ src/platform/tests/test-cleanup-fake \ @@ -4792,13 +4819,13 @@ check_programs = shared/nm-glib-aux/tests/test-shared-general \ src/ndisc/tests/test-ndisc-fake \ src/supplicant/tests/test-supplicant-config \ src/tests/config/test-config src/tests/test-core \ - src/tests/test-core-with-expect src/tests/test-ip4-config \ - src/tests/test-ip6-config src/tests/test-dcb \ - src/tests/test-systemd src/tests/test-wired-defname \ - src/tests/test-utils dispatcher/tests/test-dispatcher-envp \ - $(am__append_51) $(am__append_52) \ - clients/common/tests/test-libnm-core-aux -check_programs_norun = $(am__append_14) $(am__append_39) \ + src/tests/test-core-with-expect src/tests/test-dcb \ + src/tests/test-ip4-config src/tests/test-ip6-config \ + src/tests/test-l3cfg src/tests/test-systemd \ + src/tests/test-utils src/tests/test-wired-defname $(NULL) \ + dispatcher/tests/test-dispatcher-envp $(am__append_54) \ + $(am__append_55) clients/common/tests/test-libnm-core-aux +check_programs_norun = $(am__append_16) $(am__append_41) \ src/platform/tests/monitor src/ndisc/tests/test-ndisc-linux \ examples/C/glib/add-connection-gdbus \ examples/C/glib/add-connection-libnm \ @@ -4807,7 +4834,7 @@ check_programs_norun = $(am__append_14) $(am__append_39) \ examples/C/glib/list-connections-gdbus \ examples/C/glib/list-connections-libnm \ examples/C/glib/monitor-nm-running-gdbus \ - examples/C/glib/monitor-nm-state-gdbus $(am__append_85) + examples/C/glib/monitor-nm-state-gdbus $(am__append_88) ############################################################################### @@ -4817,19 +4844,19 @@ check_programs_norun = $(am__append_14) $(am__append_39) \ check_ltlibraries = $(am__append_6) $(am__append_7) \ libnm/tests/libnm-vpn-plugin-utils-test.la \ src/libNetworkManagerTest.la clients/common/libnmc-base.la \ - $(am__append_49) -check_local = check-docs check-local-exports-libnm \ - check-config-options $(am__append_22) $(am__append_29) \ - check-local-devices-adsl $(am__append_33) $(am__append_43) \ - $(am__append_46) $(am__append_48) \ - check-local-clients-tests-test-client $(am__append_87) \ - check-po-msgfmt -VAPIGEN_VAPIS = $(am__append_78) -dbusservice_DATA = $(am__append_26) dispatcher/nm-dispatcher.conf \ + $(am__append_52) +check_local = check-docs check-local-exports-libnm $(am__append_12) \ + check-config-options $(am__append_24) $(am__append_31) \ + check-local-devices-adsl $(am__append_35) $(am__append_45) \ + $(am__append_48) $(am__append_51) \ + check-local-clients-tests-test-client check-local-gitlab-ci \ + $(am__append_90) check-po-msgfmt +VAPIGEN_VAPIS = $(am__append_81) +dbusservice_DATA = $(am__append_28) dispatcher/nm-dispatcher.conf \ src/org.freedesktop.NetworkManager.conf dbusactivation_DATA = \ dispatcher/org.freedesktop.nm_dispatcher.service -systemdsystemunit_DATA = $(am__append_61) $(am__append_66) +systemdsystemunit_DATA = $(am__append_64) $(am__append_69) INTROSPECTION_GIRS = $(am__append_9) INTROSPECTION_SCANNER_ARGS = INTROSPECTION_COMPILER_ARGS = @@ -4844,9 +4871,9 @@ nodist_libnminclude_HEADERS = $(libnm_core_lib_h_pub_mkenums) \ pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libnm/libnm.pc pppd_plugindir = $(PPPD_PLUGIN_DIR) -pppd_plugin_LTLIBRARIES = $(am__append_18) +pppd_plugin_LTLIBRARIES = $(am__append_20) vapidir = $(datadir)/vala/vapi -vapi_DATA = $(am__append_79) +vapi_DATA = $(am__append_82) examplesdir = $(docdir)/examples rundir = $(runstatedir)/NetworkManager statedir = $(localstatedir)/lib/NetworkManager @@ -4855,6 +4882,7 @@ dbusactivationdir = $(datadir)/dbus-1/system-services servicedir = $(datadir)/dbus-1/system-services completiondir = $(datadir)/bash-completion/completions nmlocaledir = $(datadir)/locale +INTROSPECTION_EXTRA_CFLAGS = -Wno-incompatible-pointer-types-discards-qualifiers GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM SUBDIRS = . po $(am__append_1) @@ -5290,7 +5318,11 @@ shared_nm_glib_aux_tests_test_shared_general_LDADD = \ @WITH_JANSSON_TRUE@ $(GLIB_LIBS) \ @WITH_JANSSON_TRUE@ $(NULL) -introspection_libnmdbus_la_CPPFLAGS = $(GLIB_CFLAGS) +introspection_libnmdbus_la_CPPFLAGS = \ + $(GLIB_CFLAGS) \ + $(INTROSPECTION_EXTRA_CFLAGS) \ + $(NULL) + introspection_sources = \ introspection/org.freedesktop.NetworkManager.AccessPoint.c \ introspection/org.freedesktop.NetworkManager.AccessPoint.h \ @@ -5503,6 +5535,7 @@ libnm_core_lib_h_pub_real = \ libnm-core/nm-core-types.h \ libnm-core/nm-dbus-interface.h \ libnm-core/nm-errors.h \ + libnm-core/nm-keyfile.h \ libnm-core/nm-setting-6lowpan.h \ libnm-core/nm-setting-8021x.h \ libnm-core/nm-setting-adsl.h \ @@ -5517,6 +5550,7 @@ libnm_core_lib_h_pub_real = \ libnm-core/nm-setting-ethtool.h \ libnm-core/nm-setting-generic.h \ libnm-core/nm-setting-gsm.h \ + libnm-core/nm-setting-hostname.h \ libnm-core/nm-setting-infiniband.h \ libnm-core/nm-setting-ip-config.h \ libnm-core/nm-setting-ip-tunnel.h \ @@ -5528,6 +5562,7 @@ libnm_core_lib_h_pub_real = \ libnm-core/nm-setting-olpc-mesh.h \ libnm-core/nm-setting-ovs-bridge.h \ libnm-core/nm-setting-ovs-dpdk.h \ + libnm-core/nm-setting-ovs-external-ids.h \ libnm-core/nm-setting-ovs-interface.h \ libnm-core/nm-setting-ovs-patch.h \ libnm-core/nm-setting-ovs-port.h \ @@ -5541,6 +5576,7 @@ libnm_core_lib_h_pub_real = \ libnm-core/nm-setting-team.h \ libnm-core/nm-setting-tun.h \ libnm-core/nm-setting-user.h \ + libnm-core/nm-setting-veth.h \ libnm-core/nm-setting-vlan.h \ libnm-core/nm-setting-vpn.h \ libnm-core/nm-setting-vrf.h \ @@ -5593,6 +5629,7 @@ libnm_core_lib_c_settings_real = \ libnm-core/nm-setting-ethtool.c \ libnm-core/nm-setting-generic.c \ libnm-core/nm-setting-gsm.c \ + libnm-core/nm-setting-hostname.c \ libnm-core/nm-setting-infiniband.c \ libnm-core/nm-setting-ip-config.c \ libnm-core/nm-setting-ip-tunnel.c \ @@ -5604,6 +5641,7 @@ libnm_core_lib_c_settings_real = \ libnm-core/nm-setting-olpc-mesh.c \ libnm-core/nm-setting-ovs-bridge.c \ libnm-core/nm-setting-ovs-dpdk.c \ + libnm-core/nm-setting-ovs-external-ids.c \ libnm-core/nm-setting-ovs-interface.c \ libnm-core/nm-setting-ovs-patch.c \ libnm-core/nm-setting-ovs-port.c \ @@ -5617,6 +5655,7 @@ libnm_core_lib_c_settings_real = \ libnm-core/nm-setting-team.c \ libnm-core/nm-setting-tun.c \ libnm-core/nm-setting-user.c \ + libnm-core/nm-setting-veth.c \ libnm-core/nm-setting-vlan.c \ libnm-core/nm-setting-vpn.c \ libnm-core/nm-setting-vrf.c \ @@ -5719,6 +5758,7 @@ libnm_core_libnm_core_la_LDFLAGS = \ @HAVE_CRYPTO_NSS_TRUE@ $(NSS_LIBS) nm_core_tests_enum_types_sources = libnm-core/tests/test-general-enums.h +nm_core_tests_enum_types_MKENUMS_C_FLAGS = --fhead '\#include "nm-default.h"\n' libnm_core_tests_cppflags = \ -I$(srcdir)/libnm-core/tests \ -I$(builddir)/libnm-core/tests \ @@ -5807,6 +5847,7 @@ libnm_lib_h_pub_real = \ libnm/nm-device-ppp.h \ libnm/nm-device-team.h \ libnm/nm-device-tun.h \ + libnm/nm-device-veth.h \ libnm/nm-device-vlan.h \ libnm/nm-device-vrf.h \ libnm/nm-device-vxlan.h \ @@ -5874,6 +5915,7 @@ libnm_lib_c_real = \ libnm/nm-device-ppp.c \ libnm/nm-device-team.c \ libnm/nm-device-tun.c \ + libnm/nm-device-veth.c \ libnm/nm-device-vlan.c \ libnm/nm-device-vrf.c \ libnm/nm-device-vxlan.c \ @@ -5927,6 +5969,7 @@ nodist_libnm_liblibnm_la_SOURCES = \ libnm_liblibnm_la_LIBADD = \ libnm-core/nm-libnm-core-aux/libnm-libnm-core-aux.la \ + libnm-core/nm-keyfile/libnm-keyfile.la \ libnm-core/libnm-core.la \ $(libnm_crypto_lib) \ libnm-core/nm-libnm-core-intern/libnm-libnm-core-intern.la \ @@ -5986,6 +6029,7 @@ libnm_NM_1_0_typelib = $(am__append_8) @HAVE_INTROSPECTION_TRUE@ $(libnm_core_lib_c_real) \ @HAVE_INTROSPECTION_TRUE@ $(libnm_lib_h_pub_mkenums) \ @HAVE_INTROSPECTION_TRUE@ $(libnm_lib_h_pub_real) \ +@HAVE_INTROSPECTION_TRUE@ libnm-core/nm-keyfile/nm-keyfile.c \ @HAVE_INTROSPECTION_TRUE@ $(libnm_lib_c_mkenums) \ @HAVE_INTROSPECTION_TRUE@ $(libnm_lib_c_real) @@ -6112,7 +6156,7 @@ src_cppflags = \ $(NULL) src_cppflags_test = $(src_cppflags) -DNETWORKMANAGER_COMPILATION_TEST \ - $(NULL) $(am__append_15) + $(NULL) $(am__append_17) src_ldflags = $(CODE_COVERAGE_LDFLAGS) ############################################################################### @@ -6403,7 +6447,8 @@ src_libNetworkManagerBase_la_SOURCES = src/nm-core-utils.c \ src/ndisc/nm-ndisc.h src/ndisc/nm-ndisc-private.h \ src/nm-dbus-utils.c src/nm-dbus-utils.h src/nm-dbus-object.c \ src/nm-dbus-object.h src/nm-netns.c src/nm-netns.h \ - src/nm-l3-config-data.c src/nm-l3-config-data.h src/nm-l3cfg.c \ + src/nm-l3-config-data.c src/nm-l3-config-data.h \ + src/nm-l3-ipv4ll.c src/nm-l3-ipv4ll.h src/nm-l3cfg.c \ src/nm-l3cfg.h src/nm-ip-config.c src/nm-ip-config.h \ src/nm-ip4-config.c src/nm-ip4-config.h src/nm-ip6-config.c \ src/nm-ip6-config.h src/dhcp/nm-dhcp-client.c \ @@ -6412,7 +6457,7 @@ src_libNetworkManagerBase_la_SOURCES = src/nm-core-utils.c \ src/dhcp/nm-dhcp-utils.h src/dhcp/nm-dhcp-options.c \ src/dhcp/nm-dhcp-options.h src/dhcp/nm-dhcp-systemd.c \ src/dhcp/nm-dhcp-manager.c src/dhcp/nm-dhcp-manager.h \ - src/main-utils.c src/main-utils.h $(NULL) $(am__append_16) + src/main-utils.c src/main-utils.h $(NULL) $(am__append_18) src_libNetworkManagerBase_la_LIBADD = \ $(GLIB_LIBS) \ $(SYSTEMD_JOURNAL_LIBS) \ @@ -6893,7 +6938,11 @@ src_settings_plugins_keyfile_tests_test_keyfile_settings_LDADD = \ @CONFIG_PLUGIN_IFCFG_RH_TRUE@ src/settings/plugins/ifcfg-rh/nmdbus-ifcfg-rh.c \ @CONFIG_PLUGIN_IFCFG_RH_TRUE@ src/settings/plugins/ifcfg-rh/nmdbus-ifcfg-rh.h -@CONFIG_PLUGIN_IFCFG_RH_TRUE@src_settings_plugins_ifcfg_rh_libnmdbus_ifcfg_rh_la_CPPFLAGS = $(filter-out -DGLIB_VERSION_MAX_ALLOWED%,$(src_cppflags_base)) +@CONFIG_PLUGIN_IFCFG_RH_TRUE@src_settings_plugins_ifcfg_rh_libnmdbus_ifcfg_rh_la_CPPFLAGS = \ +@CONFIG_PLUGIN_IFCFG_RH_TRUE@ $(filter-out -DGLIB_VERSION_MAX_ALLOWED%,$(src_cppflags_base)) \ +@CONFIG_PLUGIN_IFCFG_RH_TRUE@ $(INTROSPECTION_EXTRA_CFLAGS) \ +@CONFIG_PLUGIN_IFCFG_RH_TRUE@ $(NULL) + ############################################################################### @CONFIG_PLUGIN_IFCFG_RH_TRUE@src_settings_plugins_ifcfg_rh_libnms_ifcfg_rh_core_la_SOURCES = \ @@ -7025,7 +7074,7 @@ src_devices_adsl_libnm_device_plugin_adsl_la_LIBADD = \ @WITH_MODEM_MANAGER_1_TRUE@ src/devices/wwan/nm-modem.h \ @WITH_MODEM_MANAGER_1_TRUE@ src/devices/wwan/nm-service-providers.c \ @WITH_MODEM_MANAGER_1_TRUE@ src/devices/wwan/nm-service-providers.h \ -@WITH_MODEM_MANAGER_1_TRUE@ $(NULL) $(am__append_32) +@WITH_MODEM_MANAGER_1_TRUE@ $(NULL) $(am__append_34) @WITH_MODEM_MANAGER_1_TRUE@src_devices_wwan_libnm_wwan_la_CPPFLAGS = $(src_devices_wwan_cppflags) @WITH_MODEM_MANAGER_1_TRUE@src_devices_wwan_libnm_wwan_la_LDFLAGS = \ @WITH_MODEM_MANAGER_1_TRUE@ -avoid-version \ @@ -7076,13 +7125,13 @@ src_devices_adsl_libnm_device_plugin_adsl_la_LIBADD = \ @WITH_MODEM_MANAGER_1_TRUE@src_devices_bluetooth_libnm_bluetooth_utils_la_SOURCES = src/devices/bluetooth/nm-bluez-common.h \ @WITH_MODEM_MANAGER_1_TRUE@ src/devices/bluetooth/nm-bt-error.c \ @WITH_MODEM_MANAGER_1_TRUE@ src/devices/bluetooth/nm-bt-error.h \ -@WITH_MODEM_MANAGER_1_TRUE@ $(NULL) $(am__append_36) +@WITH_MODEM_MANAGER_1_TRUE@ $(NULL) $(am__append_38) @WITH_MODEM_MANAGER_1_TRUE@src_devices_bluetooth_libnm_bluetooth_utils_la_CPPFLAGS = \ @WITH_MODEM_MANAGER_1_TRUE@ $(src_cppflags_base) $(NULL) \ -@WITH_MODEM_MANAGER_1_TRUE@ $(am__append_37) +@WITH_MODEM_MANAGER_1_TRUE@ $(am__append_39) @WITH_MODEM_MANAGER_1_TRUE@src_devices_bluetooth_libnm_bluetooth_utils_la_LIBADD = \ @WITH_MODEM_MANAGER_1_TRUE@ $(GLIB_LIBS) $(NULL) \ -@WITH_MODEM_MANAGER_1_TRUE@ $(am__append_38) +@WITH_MODEM_MANAGER_1_TRUE@ $(am__append_40) @WITH_MODEM_MANAGER_1_TRUE@src_devices_bluetooth_libnm_device_plugin_bluetooth_la_SOURCES = \ @WITH_MODEM_MANAGER_1_TRUE@ src/devices/bluetooth/nm-bluez-manager.c \ @WITH_MODEM_MANAGER_1_TRUE@ src/devices/bluetooth/nm-bluez-manager.h \ @@ -7130,7 +7179,7 @@ src_devices_adsl_libnm_device_plugin_adsl_la_LIBADD = \ @WITH_WIFI_TRUE@ src/devices/wifi/nm-wifi-p2p-peer.h \ @WITH_WIFI_TRUE@ src/devices/wifi/nm-wifi-utils.c \ @WITH_WIFI_TRUE@ src/devices/wifi/nm-wifi-utils.h $(NULL) \ -@WITH_WIFI_TRUE@ $(am__append_41) +@WITH_WIFI_TRUE@ $(am__append_43) @WITH_WIFI_TRUE@src_devices_wifi_libnm_wifi_base_la_CPPFLAGS = $(src_cppflags_device_plugin) @WITH_WIFI_TRUE@src_devices_wifi_libnm_wifi_base_la_LIBADD = \ @WITH_WIFI_TRUE@ $(GLIB_LIBS) @@ -7374,6 +7423,9 @@ src_tests_test_wired_defname_LDADD = $(src_tests_ldadd) src_tests_test_utils_CPPFLAGS = $(src_cppflags_test) src_tests_test_utils_LDFLAGS = $(src_tests_ldflags) src_tests_test_utils_LDADD = $(src_tests_ldadd) +src_tests_test_l3cfg_CPPFLAGS = $(src_cppflags_test) +src_tests_test_l3cfg_LDFLAGS = $(src_devices_tests_ldflags) +src_tests_test_l3cfg_LDADD = $(src_tests_ldadd) src_tests_test_systemd_CPPFLAGS = \ $(src_libnm_systemd_core_la_cppflags) \ -DNETWORKMANAGER_COMPILATION_TEST \ @@ -7457,6 +7509,7 @@ dispatcher_tests_test_dispatcher_envp_CPPFLAGS = \ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_CLIENT \ $(GLIB_CFLAGS) \ $(SANITIZER_EXEC_CFLAGS) \ + $(INTROSPECTION_EXTRA_CFLAGS) \ $(NULL) dispatcher_tests_test_dispatcher_envp_SOURCES = \ @@ -8683,6 +8736,9 @@ libnm-core/libnm_core_la-nm-setting-generic.lo: \ libnm-core/libnm_core_la-nm-setting-gsm.lo: \ libnm-core/$(am__dirstamp) \ libnm-core/$(DEPDIR)/$(am__dirstamp) +libnm-core/libnm_core_la-nm-setting-hostname.lo: \ + libnm-core/$(am__dirstamp) \ + libnm-core/$(DEPDIR)/$(am__dirstamp) libnm-core/libnm_core_la-nm-setting-infiniband.lo: \ libnm-core/$(am__dirstamp) \ libnm-core/$(DEPDIR)/$(am__dirstamp) @@ -8716,6 +8772,9 @@ libnm-core/libnm_core_la-nm-setting-ovs-bridge.lo: \ libnm-core/libnm_core_la-nm-setting-ovs-dpdk.lo: \ libnm-core/$(am__dirstamp) \ libnm-core/$(DEPDIR)/$(am__dirstamp) +libnm-core/libnm_core_la-nm-setting-ovs-external-ids.lo: \ + libnm-core/$(am__dirstamp) \ + libnm-core/$(DEPDIR)/$(am__dirstamp) libnm-core/libnm_core_la-nm-setting-ovs-interface.lo: \ libnm-core/$(am__dirstamp) \ libnm-core/$(DEPDIR)/$(am__dirstamp) @@ -8755,6 +8814,9 @@ libnm-core/libnm_core_la-nm-setting-tun.lo: \ libnm-core/libnm_core_la-nm-setting-user.lo: \ libnm-core/$(am__dirstamp) \ libnm-core/$(DEPDIR)/$(am__dirstamp) +libnm-core/libnm_core_la-nm-setting-veth.lo: \ + libnm-core/$(am__dirstamp) \ + libnm-core/$(DEPDIR)/$(am__dirstamp) libnm-core/libnm_core_la-nm-setting-vlan.lo: \ libnm-core/$(am__dirstamp) \ libnm-core/$(DEPDIR)/$(am__dirstamp) @@ -8939,6 +9001,8 @@ libnm/liblibnm_la-nm-device-team.lo: libnm/$(am__dirstamp) \ libnm/$(DEPDIR)/$(am__dirstamp) libnm/liblibnm_la-nm-device-tun.lo: libnm/$(am__dirstamp) \ libnm/$(DEPDIR)/$(am__dirstamp) +libnm/liblibnm_la-nm-device-veth.lo: libnm/$(am__dirstamp) \ + libnm/$(DEPDIR)/$(am__dirstamp) libnm/liblibnm_la-nm-device-vlan.lo: libnm/$(am__dirstamp) \ libnm/$(DEPDIR)/$(am__dirstamp) libnm/liblibnm_la-nm-device-vrf.lo: libnm/$(am__dirstamp) \ @@ -9837,6 +9901,8 @@ src/libNetworkManagerBase_la-nm-netns.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libNetworkManagerBase_la-nm-l3-config-data.lo: \ src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) +src/libNetworkManagerBase_la-nm-l3-ipv4ll.lo: src/$(am__dirstamp) \ + src/$(DEPDIR)/$(am__dirstamp) src/libNetworkManagerBase_la-nm-l3cfg.lo: src/$(am__dirstamp) \ src/$(DEPDIR)/$(am__dirstamp) src/libNetworkManagerBase_la-nm-ip-config.lo: src/$(am__dirstamp) \ @@ -10881,6 +10947,12 @@ src/tests/test_ip6_config-test-ip6-config.$(OBJEXT): \ src/tests/test-ip6-config$(EXEEXT): $(src_tests_test_ip6_config_OBJECTS) $(src_tests_test_ip6_config_DEPENDENCIES) $(EXTRA_src_tests_test_ip6_config_DEPENDENCIES) src/tests/$(am__dirstamp) @rm -f src/tests/test-ip6-config$(EXEEXT) $(AM_V_CCLD)$(src_tests_test_ip6_config_LINK) $(src_tests_test_ip6_config_OBJECTS) $(src_tests_test_ip6_config_LDADD) $(LIBS) +src/tests/test_l3cfg-test-l3cfg.$(OBJEXT): src/tests/$(am__dirstamp) \ + src/tests/$(DEPDIR)/$(am__dirstamp) + +src/tests/test-l3cfg$(EXEEXT): $(src_tests_test_l3cfg_OBJECTS) $(src_tests_test_l3cfg_DEPENDENCIES) $(EXTRA_src_tests_test_l3cfg_DEPENDENCIES) src/tests/$(am__dirstamp) + @rm -f src/tests/test-l3cfg$(EXEEXT) + $(AM_V_CCLD)$(src_tests_test_l3cfg_LINK) $(src_tests_test_l3cfg_OBJECTS) $(src_tests_test_l3cfg_LDADD) $(LIBS) src/tests/test_systemd-test-systemd.$(OBJEXT): \ src/tests/$(am__dirstamp) src/tests/$(DEPDIR)/$(am__dirstamp) @@ -11241,6 +11313,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ethtool.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-generic.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-gsm.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-hostname.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-infiniband.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ip-config.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ip-tunnel.Plo@am__quote@ # am--include-marker @@ -11252,6 +11325,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-olpc-mesh.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-bridge.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-dpdk.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-external-ids.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-interface.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-patch.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-port.Plo@am__quote@ # am--include-marker @@ -11265,6 +11339,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-team.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-tun.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-user.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-veth.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vlan.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vpn.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vrf.Plo@am__quote@ # am--include-marker @@ -11323,6 +11398,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@libnm/$(DEPDIR)/liblibnm_la-nm-device-ppp.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm/$(DEPDIR)/liblibnm_la-nm-device-team.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm/$(DEPDIR)/liblibnm_la-nm-device-tun.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@libnm/$(DEPDIR)/liblibnm_la-nm-device-veth.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm/$(DEPDIR)/liblibnm_la-nm-device-vlan.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm/$(DEPDIR)/liblibnm_la-nm-device-vrf.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@libnm/$(DEPDIR)/liblibnm_la-nm-device-vxlan.Plo@am__quote@ # am--include-marker @@ -11446,6 +11522,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libNetworkManagerBase_la-nm-ip4-config.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libNetworkManagerBase_la-nm-ip6-config.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3-config-data.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3-ipv4ll.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3cfg.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libNetworkManagerBase_la-nm-logging.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/libNetworkManagerBase_la-nm-netns.Plo@am__quote@ # am--include-marker @@ -11656,6 +11733,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@src/tests/$(DEPDIR)/test_dcb-test-dcb.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/tests/$(DEPDIR)/test_ip4_config-test-ip4-config.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/tests/$(DEPDIR)/test_ip6_config-test-ip6-config.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@src/tests/$(DEPDIR)/test_l3cfg-test-l3cfg.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/tests/$(DEPDIR)/test_systemd-test-systemd.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/tests/$(DEPDIR)/test_utils-test-utils.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@src/tests/$(DEPDIR)/test_wired_defname-test-wired-defname.Po@am__quote@ # am--include-marker @@ -12464,6 +12542,13 @@ libnm-core/libnm_core_la-nm-setting-gsm.lo: libnm-core/nm-setting-gsm.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm-core/libnm_core_la-nm-setting-gsm.lo `test -f 'libnm-core/nm-setting-gsm.c' || echo '$(srcdir)/'`libnm-core/nm-setting-gsm.c +libnm-core/libnm_core_la-nm-setting-hostname.lo: libnm-core/nm-setting-hostname.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm-core/libnm_core_la-nm-setting-hostname.lo -MD -MP -MF libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-hostname.Tpo -c -o libnm-core/libnm_core_la-nm-setting-hostname.lo `test -f 'libnm-core/nm-setting-hostname.c' || echo '$(srcdir)/'`libnm-core/nm-setting-hostname.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-hostname.Tpo libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-hostname.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libnm-core/nm-setting-hostname.c' object='libnm-core/libnm_core_la-nm-setting-hostname.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm-core/libnm_core_la-nm-setting-hostname.lo `test -f 'libnm-core/nm-setting-hostname.c' || echo '$(srcdir)/'`libnm-core/nm-setting-hostname.c + libnm-core/libnm_core_la-nm-setting-infiniband.lo: libnm-core/nm-setting-infiniband.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm-core/libnm_core_la-nm-setting-infiniband.lo -MD -MP -MF libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-infiniband.Tpo -c -o libnm-core/libnm_core_la-nm-setting-infiniband.lo `test -f 'libnm-core/nm-setting-infiniband.c' || echo '$(srcdir)/'`libnm-core/nm-setting-infiniband.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-infiniband.Tpo libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-infiniband.Plo @@ -12541,6 +12626,13 @@ libnm-core/libnm_core_la-nm-setting-ovs-dpdk.lo: libnm-core/nm-setting-ovs-dpdk. @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm-core/libnm_core_la-nm-setting-ovs-dpdk.lo `test -f 'libnm-core/nm-setting-ovs-dpdk.c' || echo '$(srcdir)/'`libnm-core/nm-setting-ovs-dpdk.c +libnm-core/libnm_core_la-nm-setting-ovs-external-ids.lo: libnm-core/nm-setting-ovs-external-ids.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm-core/libnm_core_la-nm-setting-ovs-external-ids.lo -MD -MP -MF libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-external-ids.Tpo -c -o libnm-core/libnm_core_la-nm-setting-ovs-external-ids.lo `test -f 'libnm-core/nm-setting-ovs-external-ids.c' || echo '$(srcdir)/'`libnm-core/nm-setting-ovs-external-ids.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-external-ids.Tpo libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-external-ids.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libnm-core/nm-setting-ovs-external-ids.c' object='libnm-core/libnm_core_la-nm-setting-ovs-external-ids.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm-core/libnm_core_la-nm-setting-ovs-external-ids.lo `test -f 'libnm-core/nm-setting-ovs-external-ids.c' || echo '$(srcdir)/'`libnm-core/nm-setting-ovs-external-ids.c + libnm-core/libnm_core_la-nm-setting-ovs-interface.lo: libnm-core/nm-setting-ovs-interface.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm-core/libnm_core_la-nm-setting-ovs-interface.lo -MD -MP -MF libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-interface.Tpo -c -o libnm-core/libnm_core_la-nm-setting-ovs-interface.lo `test -f 'libnm-core/nm-setting-ovs-interface.c' || echo '$(srcdir)/'`libnm-core/nm-setting-ovs-interface.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-interface.Tpo libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-interface.Plo @@ -12632,6 +12724,13 @@ libnm-core/libnm_core_la-nm-setting-user.lo: libnm-core/nm-setting-user.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm-core/libnm_core_la-nm-setting-user.lo `test -f 'libnm-core/nm-setting-user.c' || echo '$(srcdir)/'`libnm-core/nm-setting-user.c +libnm-core/libnm_core_la-nm-setting-veth.lo: libnm-core/nm-setting-veth.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm-core/libnm_core_la-nm-setting-veth.lo -MD -MP -MF libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-veth.Tpo -c -o libnm-core/libnm_core_la-nm-setting-veth.lo `test -f 'libnm-core/nm-setting-veth.c' || echo '$(srcdir)/'`libnm-core/nm-setting-veth.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-veth.Tpo libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-veth.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libnm-core/nm-setting-veth.c' object='libnm-core/libnm_core_la-nm-setting-veth.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm-core/libnm_core_la-nm-setting-veth.lo `test -f 'libnm-core/nm-setting-veth.c' || echo '$(srcdir)/'`libnm-core/nm-setting-veth.c + libnm-core/libnm_core_la-nm-setting-vlan.lo: libnm-core/nm-setting-vlan.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_core_libnm_core_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm-core/libnm_core_la-nm-setting-vlan.lo -MD -MP -MF libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vlan.Tpo -c -o libnm-core/libnm_core_la-nm-setting-vlan.lo `test -f 'libnm-core/nm-setting-vlan.c' || echo '$(srcdir)/'`libnm-core/nm-setting-vlan.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vlan.Tpo libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vlan.Plo @@ -13045,6 +13144,13 @@ libnm/liblibnm_la-nm-device-tun.lo: libnm/nm-device-tun.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_liblibnm_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm/liblibnm_la-nm-device-tun.lo `test -f 'libnm/nm-device-tun.c' || echo '$(srcdir)/'`libnm/nm-device-tun.c +libnm/liblibnm_la-nm-device-veth.lo: libnm/nm-device-veth.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_liblibnm_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm/liblibnm_la-nm-device-veth.lo -MD -MP -MF libnm/$(DEPDIR)/liblibnm_la-nm-device-veth.Tpo -c -o libnm/liblibnm_la-nm-device-veth.lo `test -f 'libnm/nm-device-veth.c' || echo '$(srcdir)/'`libnm/nm-device-veth.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libnm/$(DEPDIR)/liblibnm_la-nm-device-veth.Tpo libnm/$(DEPDIR)/liblibnm_la-nm-device-veth.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libnm/nm-device-veth.c' object='libnm/liblibnm_la-nm-device-veth.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_liblibnm_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libnm/liblibnm_la-nm-device-veth.lo `test -f 'libnm/nm-device-veth.c' || echo '$(srcdir)/'`libnm/nm-device-veth.c + libnm/liblibnm_la-nm-device-vlan.lo: libnm/nm-device-vlan.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libnm_liblibnm_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libnm/liblibnm_la-nm-device-vlan.lo -MD -MP -MF libnm/$(DEPDIR)/liblibnm_la-nm-device-vlan.Tpo -c -o libnm/liblibnm_la-nm-device-vlan.lo `test -f 'libnm/nm-device-vlan.c' || echo '$(srcdir)/'`libnm/nm-device-vlan.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libnm/$(DEPDIR)/liblibnm_la-nm-device-vlan.Tpo libnm/$(DEPDIR)/liblibnm_la-nm-device-vlan.Plo @@ -14641,6 +14747,13 @@ src/libNetworkManagerBase_la-nm-l3-config-data.lo: src/nm-l3-config-data.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libNetworkManagerBase_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/libNetworkManagerBase_la-nm-l3-config-data.lo `test -f 'src/nm-l3-config-data.c' || echo '$(srcdir)/'`src/nm-l3-config-data.c +src/libNetworkManagerBase_la-nm-l3-ipv4ll.lo: src/nm-l3-ipv4ll.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libNetworkManagerBase_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/libNetworkManagerBase_la-nm-l3-ipv4ll.lo -MD -MP -MF src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3-ipv4ll.Tpo -c -o src/libNetworkManagerBase_la-nm-l3-ipv4ll.lo `test -f 'src/nm-l3-ipv4ll.c' || echo '$(srcdir)/'`src/nm-l3-ipv4ll.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3-ipv4ll.Tpo src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3-ipv4ll.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/nm-l3-ipv4ll.c' object='src/libNetworkManagerBase_la-nm-l3-ipv4ll.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libNetworkManagerBase_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/libNetworkManagerBase_la-nm-l3-ipv4ll.lo `test -f 'src/nm-l3-ipv4ll.c' || echo '$(srcdir)/'`src/nm-l3-ipv4ll.c + src/libNetworkManagerBase_la-nm-l3cfg.lo: src/nm-l3cfg.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_libNetworkManagerBase_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/libNetworkManagerBase_la-nm-l3cfg.lo -MD -MP -MF src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3cfg.Tpo -c -o src/libNetworkManagerBase_la-nm-l3cfg.lo `test -f 'src/nm-l3cfg.c' || echo '$(srcdir)/'`src/nm-l3cfg.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3cfg.Tpo src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3cfg.Plo @@ -16853,6 +16966,20 @@ src/tests/test_ip6_config-test-ip6-config.obj: src/tests/test-ip6-config.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_tests_test_ip6_config_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/tests/test_ip6_config-test-ip6-config.obj `if test -f 'src/tests/test-ip6-config.c'; then $(CYGPATH_W) 'src/tests/test-ip6-config.c'; else $(CYGPATH_W) '$(srcdir)/src/tests/test-ip6-config.c'; fi` +src/tests/test_l3cfg-test-l3cfg.o: src/tests/test-l3cfg.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_tests_test_l3cfg_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/tests/test_l3cfg-test-l3cfg.o -MD -MP -MF src/tests/$(DEPDIR)/test_l3cfg-test-l3cfg.Tpo -c -o src/tests/test_l3cfg-test-l3cfg.o `test -f 'src/tests/test-l3cfg.c' || echo '$(srcdir)/'`src/tests/test-l3cfg.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/tests/$(DEPDIR)/test_l3cfg-test-l3cfg.Tpo src/tests/$(DEPDIR)/test_l3cfg-test-l3cfg.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/tests/test-l3cfg.c' object='src/tests/test_l3cfg-test-l3cfg.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_tests_test_l3cfg_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/tests/test_l3cfg-test-l3cfg.o `test -f 'src/tests/test-l3cfg.c' || echo '$(srcdir)/'`src/tests/test-l3cfg.c + +src/tests/test_l3cfg-test-l3cfg.obj: src/tests/test-l3cfg.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_tests_test_l3cfg_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/tests/test_l3cfg-test-l3cfg.obj -MD -MP -MF src/tests/$(DEPDIR)/test_l3cfg-test-l3cfg.Tpo -c -o src/tests/test_l3cfg-test-l3cfg.obj `if test -f 'src/tests/test-l3cfg.c'; then $(CYGPATH_W) 'src/tests/test-l3cfg.c'; else $(CYGPATH_W) '$(srcdir)/src/tests/test-l3cfg.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/tests/$(DEPDIR)/test_l3cfg-test-l3cfg.Tpo src/tests/$(DEPDIR)/test_l3cfg-test-l3cfg.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='src/tests/test-l3cfg.c' object='src/tests/test_l3cfg-test-l3cfg.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_tests_test_l3cfg_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/tests/test_l3cfg-test-l3cfg.obj `if test -f 'src/tests/test-l3cfg.c'; then $(CYGPATH_W) 'src/tests/test-l3cfg.c'; else $(CYGPATH_W) '$(srcdir)/src/tests/test-l3cfg.c'; fi` + src/tests/test_systemd-test-systemd.o: src/tests/test-systemd.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(src_tests_test_systemd_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/tests/test_systemd-test-systemd.o -MD -MP -MF src/tests/$(DEPDIR)/test_systemd-test-systemd.Tpo -c -o src/tests/test_systemd-test-systemd.o `test -f 'src/tests/test-systemd.c' || echo '$(srcdir)/'`src/tests/test-systemd.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) src/tests/$(DEPDIR)/test_systemd-test-systemd.Tpo src/tests/$(DEPDIR)/test_systemd-test-systemd.Po @@ -18114,6 +18241,13 @@ src/tests/test-core-with-expect.log: src/tests/test-core-with-expect$(EXEEXT) --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) +src/tests/test-dcb.log: src/tests/test-dcb$(EXEEXT) + @p='src/tests/test-dcb$(EXEEXT)'; \ + b='src/tests/test-dcb'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) src/tests/test-ip4-config.log: src/tests/test-ip4-config$(EXEEXT) @p='src/tests/test-ip4-config$(EXEEXT)'; \ b='src/tests/test-ip4-config'; \ @@ -18128,9 +18262,9 @@ src/tests/test-ip6-config.log: src/tests/test-ip6-config$(EXEEXT) --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) -src/tests/test-dcb.log: src/tests/test-dcb$(EXEEXT) - @p='src/tests/test-dcb$(EXEEXT)'; \ - b='src/tests/test-dcb'; \ +src/tests/test-l3cfg.log: src/tests/test-l3cfg$(EXEEXT) + @p='src/tests/test-l3cfg$(EXEEXT)'; \ + b='src/tests/test-l3cfg'; \ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ @@ -18142,16 +18276,16 @@ src/tests/test-systemd.log: src/tests/test-systemd$(EXEEXT) --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) -src/tests/test-wired-defname.log: src/tests/test-wired-defname$(EXEEXT) - @p='src/tests/test-wired-defname$(EXEEXT)'; \ - b='src/tests/test-wired-defname'; \ +src/tests/test-utils.log: src/tests/test-utils$(EXEEXT) + @p='src/tests/test-utils$(EXEEXT)'; \ + b='src/tests/test-utils'; \ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) -src/tests/test-utils.log: src/tests/test-utils$(EXEEXT) - @p='src/tests/test-utils$(EXEEXT)'; \ - b='src/tests/test-utils'; \ +src/tests/test-wired-defname.log: src/tests/test-wired-defname$(EXEEXT) + @p='src/tests/test-wired-defname$(EXEEXT)'; \ + b='src/tests/test-wired-defname'; \ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ @@ -18772,6 +18906,7 @@ distclean: distclean-recursive -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ethtool.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-generic.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-gsm.Plo + -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-hostname.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-infiniband.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ip-config.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ip-tunnel.Plo @@ -18783,6 +18918,7 @@ distclean: distclean-recursive -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-olpc-mesh.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-bridge.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-dpdk.Plo + -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-external-ids.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-interface.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-patch.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-port.Plo @@ -18796,6 +18932,7 @@ distclean: distclean-recursive -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-team.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-tun.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-user.Plo + -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-veth.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vlan.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vpn.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vrf.Plo @@ -18854,6 +18991,7 @@ distclean: distclean-recursive -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-ppp.Plo -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-team.Plo -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-tun.Plo + -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-veth.Plo -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-vlan.Plo -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-vrf.Plo -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-vxlan.Plo @@ -18977,6 +19115,7 @@ distclean: distclean-recursive -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-ip4-config.Plo -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-ip6-config.Plo -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3-config-data.Plo + -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3-ipv4ll.Plo -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3cfg.Plo -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-logging.Plo -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-netns.Plo @@ -19187,6 +19326,7 @@ distclean: distclean-recursive -rm -f src/tests/$(DEPDIR)/test_dcb-test-dcb.Po -rm -f src/tests/$(DEPDIR)/test_ip4_config-test-ip4-config.Po -rm -f src/tests/$(DEPDIR)/test_ip6_config-test-ip6-config.Po + -rm -f src/tests/$(DEPDIR)/test_l3cfg-test-l3cfg.Po -rm -f src/tests/$(DEPDIR)/test_systemd-test-systemd.Po -rm -f src/tests/$(DEPDIR)/test_utils-test-utils.Po -rm -f src/tests/$(DEPDIR)/test_wired_defname-test-wired-defname.Po @@ -19423,6 +19563,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ethtool.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-generic.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-gsm.Plo + -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-hostname.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-infiniband.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ip-config.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ip-tunnel.Plo @@ -19434,6 +19575,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-olpc-mesh.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-bridge.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-dpdk.Plo + -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-external-ids.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-interface.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-patch.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-ovs-port.Plo @@ -19447,6 +19589,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-team.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-tun.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-user.Plo + -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-veth.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vlan.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vpn.Plo -rm -f libnm-core/$(DEPDIR)/libnm_core_la-nm-setting-vrf.Plo @@ -19505,6 +19648,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-ppp.Plo -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-team.Plo -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-tun.Plo + -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-veth.Plo -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-vlan.Plo -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-vrf.Plo -rm -f libnm/$(DEPDIR)/liblibnm_la-nm-device-vxlan.Plo @@ -19628,6 +19772,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-ip4-config.Plo -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-ip6-config.Plo -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3-config-data.Plo + -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3-ipv4ll.Plo -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-l3cfg.Plo -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-logging.Plo -rm -f src/$(DEPDIR)/libNetworkManagerBase_la-nm-netns.Plo @@ -19838,6 +19983,7 @@ maintainer-clean: maintainer-clean-recursive -rm -f src/tests/$(DEPDIR)/test_dcb-test-dcb.Po -rm -f src/tests/$(DEPDIR)/test_ip4_config-test-ip4-config.Po -rm -f src/tests/$(DEPDIR)/test_ip6_config-test-ip6-config.Po + -rm -f src/tests/$(DEPDIR)/test_l3cfg-test-l3cfg.Po -rm -f src/tests/$(DEPDIR)/test_systemd-test-systemd.Po -rm -f src/tests/$(DEPDIR)/test_utils-test-utils.Po -rm -f src/tests/$(DEPDIR)/test_wired_defname-test-wired-defname.Po @@ -20039,8 +20185,6 @@ introspection/%.h: introspection/%.c docs/api/dbus-%.xml: introspection/%.c $() -$(dispatcher_libnm_dispatcher_core_la_OBJECTS): $(introspection_sources) -$(dispatcher_nm_dispatcher_OBJECTS): $(introspection_sources) $(libnm_liblibnm_la_OBJECTS): $(introspection_sources) $(libnm_libnm_la_OBJECTS): $(introspection_sources) @@ -20100,8 +20244,13 @@ check-local-exports-libnm: libnm/libnm.la @HAVE_INTROSPECTION_TRUE@libnm/libnm.typelib: libnm/libnm.gir @HAVE_INTROSPECTION_TRUE@ $(INTROSPECTION_COMPILER) --includedir=$(srcdir)/libnm-core --includedir=$(builddir)/libnm-core --includedir=$(srcdir)/libnm --includedir=$(builddir)/libnm $< -o $@ -@HAVE_INTROSPECTION_TRUE@clients/cli/generate-docs-nm-settings-nmcli.xml: clients/cli/generate-docs-nm-settings-nmcli -@HAVE_INTROSPECTION_TRUE@ $(AM_V_GEN) clients/cli/generate-docs-nm-settings-nmcli > $@ +@BUILD_DOCS_TRUE@@HAVE_INTROSPECTION_TRUE@clients/cli/generate-docs-nm-settings-nmcli.xml: clients/cli/generate-docs-nm-settings-nmcli +@BUILD_DOCS_TRUE@@HAVE_INTROSPECTION_TRUE@ $(AM_V_GEN) clients/cli/generate-docs-nm-settings-nmcli > "$@" +@BUILD_DOCS_TRUE@@HAVE_INTROSPECTION_TRUE@check-local-generate-docs-nm-settings-nmcli: clients/cli/generate-docs-nm-settings-nmcli.xml +@BUILD_DOCS_TRUE@@HAVE_INTROSPECTION_TRUE@ $(srcdir)/tools/check-compare-generated.sh "$(srcdir)" "$(builddir)" "$<" +@BUILD_DOCS_FALSE@@HAVE_INTROSPECTION_TRUE@clients/cli/generate-docs-nm-settings-nmcli.xml: clients/cli/generate-docs-nm-settings-nmcli.xml.in +@BUILD_DOCS_FALSE@@HAVE_INTROSPECTION_TRUE@ $(AM_V_GEN) cp $^ $@ +@BUILD_DOCS_FALSE@@HAVE_INTROSPECTION_TRUE@check-local-generate-docs-nm-settings-nmcli: @HAVE_INTROSPECTION_TRUE@libnm/nm-property-infos-%.xml: tools/generate-docs-nm-property-infos.pl $(libnm_docs_sources) @HAVE_INTROSPECTION_TRUE@ $(AM_V_GEN) $(srcdir)/tools/generate-docs-nm-property-infos.pl $(patsubst nm-property-infos-%.xml,%,$(notdir $@)) $@ $(filter-out $<,$^) @@ -20270,13 +20419,14 @@ $(src_supplicant_tests_test_supplicant_config_OBJECTS): $(libnm_core_lib_h_pub_m $(src_tests_config_test_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums) -$(src_tests_test_ip4_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums) -$(src_tests_test_ip6_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums) -$(src_tests_test_dcb_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(src_tests_test_core_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(src_tests_test_core_with_expect_OBJECTS): $(libnm_core_lib_h_pub_mkenums) -$(src_tests_test_wired_defname_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +$(src_tests_test_dcb_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +$(src_tests_test_ip4_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +$(src_tests_test_ip6_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +$(src_tests_test_l3cfg_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(src_tests_test_utils_OBJECTS): $(libnm_core_lib_h_pub_mkenums) +$(src_tests_test_wired_defname_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(src_tests_test_systemd_OBJECTS): $(libnm_core_lib_h_pub_mkenums) @@ -20318,13 +20468,13 @@ $(clients_nm_online_OBJECTS): $(libnm_lib_h_pub_mkenums) $(clients_common_libnmc_base_la_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(clients_common_libnmc_base_la_OBJECTS): $(libnm_lib_h_pub_mkenums) $(clients_common_libnmc_base_la_OBJECTS): clients/common/.dirstamp -@HAVE_INTROSPECTION_TRUE@$(clients_common_settings_doc_h): clients/common/settings-docs.xsl libnm/nm-settings-docs-gir.xml clients/common/.dirstamp -@HAVE_INTROSPECTION_TRUE@ $(AM_V_GEN) $(XSLTPROC) --output $@ $< $(word 2,$^) -@HAVE_INTROSPECTION_TRUE@check-local-settings-docs: $(clients_common_settings_doc_h) -@HAVE_INTROSPECTION_TRUE@ $(srcdir)/tools/check-settings-docs.sh "$(srcdir)" "$(builddir)" "$(clients_common_settings_doc_h)" -@HAVE_INTROSPECTION_FALSE@$(clients_common_settings_doc_h): $(clients_common_settings_doc_h).in clients/common/.dirstamp -@HAVE_INTROSPECTION_FALSE@ $(AM_V_GEN) cp "$(srcdir)/$(clients_common_settings_doc_h).in" "$(builddir)/$(clients_common_settings_doc_h)" -@HAVE_INTROSPECTION_FALSE@check-local-settings-docs: +@BUILD_DOCS_TRUE@$(clients_common_settings_doc_h): clients/common/settings-docs.xsl libnm/nm-settings-docs-gir.xml clients/common/.dirstamp +@BUILD_DOCS_TRUE@ $(AM_V_GEN) $(XSLTPROC) --output $@ $< $(word 2,$^) +@BUILD_DOCS_TRUE@check-local-settings-docs: $(clients_common_settings_doc_h) +@BUILD_DOCS_TRUE@ $(srcdir)/tools/check-compare-generated.sh "$(srcdir)" "$(builddir)" "$(clients_common_settings_doc_h)" +@BUILD_DOCS_FALSE@$(clients_common_settings_doc_h): $(clients_common_settings_doc_h).in clients/common/.dirstamp +@BUILD_DOCS_FALSE@ $(AM_V_GEN) cp "$(srcdir)/$(clients_common_settings_doc_h).in" "$(builddir)/$(clients_common_settings_doc_h)" +@BUILD_DOCS_FALSE@check-local-settings-docs: $(clients_common_libnmc_la_OBJECTS): $(libnm_core_lib_h_pub_mkenums) $(clients_common_libnmc_la_OBJECTS): $(clients_common_settings_doc_h) @@ -20392,6 +20542,9 @@ check-local-clients-tests-test-client: clients/cli/nmcli clients/tests/test-clie cat "$(builddir)/clients/tests/test-client.log"; \ test "$$r" = ok +check-local-gitlab-ci: + "$(srcdir)/tools/check-gitlab-ci.sh" "$(srcdir)" + @HAVE_SYSTEMD_TRUE@data/NetworkManager.service: $(srcdir)/data/NetworkManager.service.in @HAVE_SYSTEMD_TRUE@ $(AM_V_GEN) $(data_edit) $< >$@ @@ -20455,7 +20608,7 @@ $(examples_C_glib_list_connections_libnm_OBJECTS): $(libnm_core_lib_h_pub_mkenum ############################################################################### @WITH_PYTHON_BLACK_TRUE@check-python-black: -@WITH_PYTHON_BLACK_TRUE@ test "$$NMTST_SKIP_PYTHON_BLACK" != 1 && $(BLACK) --check $(top_srcdir) $(top_srcdir)/examples/python/gi/nm-wg-set +@WITH_PYTHON_BLACK_TRUE@ test "$$NMTST_SKIP_PYTHON_BLACK" == 1 || $(BLACK) --check $(top_srcdir) $(top_srcdir)/examples/python/gi/nm-wg-set ############################################################################### diff --git a/NEWS b/NEWS index a9a0ea1..292c140 100644 --- a/NEWS +++ b/NEWS @@ -1,20 +1,60 @@ ============================================= -NetworkManager-1.28 -Overview of changes since NetworkManager-1.26 +NetworkManager-1.30 +Overview of changes since NetworkManager-1.28 ============================================= -This is a snapshot of NetworkManager 1.28 development series. +This is a snapshot of NetworkManager 1.30 development series. The API is subject to change and not guaranteed to be compatible with the later release. USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE! -* Introduce new "rc-manager=auto" setting and make it the default, - unless a different default is chosen at compile time. - This mode tries to detect "systemd-resolved", "resolvconf", and "netconfig" +* libnm: nm_setting_bond_add_option() no longer validates the + option that is set. Instead, use nm_connection_verify() to validate + the profile. +* Increase timeout of NetworkManager-wait-online.service to 60 seconds. + +============================================= +NetworkManager-1.28 +Overview of changes since NetworkManager-1.26 +============================================= + +* Introduce a new "rc-manager=auto" setting and make it the default, + unless a different default is chosen at compile time. This mode + tries to detect "systemd-resolved", "resolvconf", and "netconfig" and chooses the mode that seems most suitable depending on build - setting and runtime detection. - "resolvconf" and "netconfig" are only considered iff NetworkManager - was built with the respective options enabled. + setting and runtime detection. "resolvconf" and "netconfig" are + only considered iff NetworkManager was built with the respective + options enabled. +* The long deprecated D-Bus property "Ip4Address" on + "org.freedesktop.NetworkManager.Device" interface is now defunct and + always returns zero. +* Introduce a ipv4.dhcp-reject-servers connection property that + specifies a list of DHCP server-ids from which offers should be + rejected. +* Add a ipv4.dhcp-vendor-class-identifier connection property to send + a custom value for the Vendor Class Identifier DHCP option. +* Support obtaining the system hostname through the FQDN DHCPv6 + option. +* dbus: don't require policykit permission for GetAppliedConnection of + a device. +* When supported by kernel, use netlink to configure bridge settings + instead of writing to sysfs. +* Deprecate the "active_slave" bond option which now has the same effect + as setting the "primary" option. +* The initrd generator now also accepts MAC addresses to indicate + interfaces. +* Add a new provider for nm-cloud-setup to support automatic network + configuration on Azure. +* The initrd generator now supports creating Infiniband connections. +* Fix running DHCPv6-PD over PPPoE. +* Fix building NetworkManager with LTO (Link Time Optimization). +* Fix failure activating Wi-Fi P2P connections. +* Reformat code using spaces instead of tabs. Also, the entire C + source code is now formatted with "clang-format" (version 11.0). +* Change the behavior of nm-initrd-generator so that the 'ip=off|none' kernel + cmdline argument actually generates a connection which disables both + ipv4 and ipv6. Previously the generated connection would disable ipv4 + but ipv6 would be set to the 'auto' method. ============================================= NetworkManager-1.26 diff --git a/autogen.sh b/autogen.sh index 9bb0294..ca9253f 100755 --- a/autogen.sh +++ b/autogen.sh @@ -28,5 +28,5 @@ AUTOPOINT='intltoolize --automake --copy' autoreconf --force --install --verbose cd $olddir if test -z "$NOCONFIGURE"; then - exec $srcdir/configure --enable-maintainer-mode --enable-more-warnings=error --enable-gtk-doc --enable-introspection "$@" + exec $srcdir/configure --enable-maintainer-mode --enable-more-warnings=error --enable-gtk-doc --enable-introspection "$@" fi diff --git a/clients/cli/agent.c b/clients/cli/agent.c index f3707db..293ff65 100644 --- a/clients/cli/agent.c +++ b/clients/cli/agent.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2014 Red Hat, Inc. */ @@ -17,220 +17,214 @@ #include "nm-polkit-listener.h" static void -usage (void) +usage(void) { - g_printerr (_("Usage: nmcli agent { COMMAND | help }\n\n" - "COMMAND := { secret | polkit | all }\n\n" - )); + g_printerr(_("Usage: nmcli agent { COMMAND | help }\n\n" + "COMMAND := { secret | polkit | all }\n\n")); } static void -usage_agent_secret (void) +usage_agent_secret(void) { - g_printerr (_("Usage: nmcli agent secret { help }\n" - "\n" - "Runs nmcli as NetworkManager secret agent. When NetworkManager requires\n" - "a password it asks registered agents for it. This command keeps nmcli running\n" - "and if a password is required asks the user for it.\n\n")); + g_printerr(_("Usage: nmcli agent secret { help }\n" + "\n" + "Runs nmcli as NetworkManager secret agent. When NetworkManager requires\n" + "a password it asks registered agents for it. This command keeps nmcli running\n" + "and if a password is required asks the user for it.\n\n")); } static void -usage_agent_polkit (void) +usage_agent_polkit(void) { - g_printerr (_("Usage: nmcli agent polkit { help }\n" - "\n" - "Registers nmcli as a polkit action for the user session.\n" - "When a polkit daemon requires an authorization, nmcli asks the user and gives\n" - "the response back to polkit.\n\n")); + g_printerr(_("Usage: nmcli agent polkit { help }\n" + "\n" + "Registers nmcli as a polkit action for the user session.\n" + "When a polkit daemon requires an authorization, nmcli asks the user and gives\n" + "the response back to polkit.\n\n")); } static void -usage_agent_all (void) +usage_agent_all(void) { - g_printerr (_("Usage: nmcli agent all { help }\n" - "\n" - "Runs nmcli as both NetworkManager secret and a polkit agent.\n\n")); + g_printerr(_("Usage: nmcli agent all { help }\n" + "\n" + "Runs nmcli as both NetworkManager secret and a polkit agent.\n\n")); } /* for pre-filling a string to readline prompt */ static char *pre_input_deftext; static int -set_deftext (void) +set_deftext(void) { - if (pre_input_deftext && rl_startup_hook) { - rl_insert_text (pre_input_deftext); - g_free (pre_input_deftext); - pre_input_deftext = NULL; - rl_startup_hook = NULL; - } - return 0; + if (pre_input_deftext && rl_startup_hook) { + rl_insert_text(pre_input_deftext); + g_free(pre_input_deftext); + pre_input_deftext = NULL; + rl_startup_hook = NULL; + } + return 0; } static gboolean -get_secrets_from_user (const NmcConfig *nmc_config, - const char *request_id, - const char *title, - const char *msg, - GPtrArray *secrets) +get_secrets_from_user(const NmcConfig *nmc_config, + const char * request_id, + const char * title, + const char * msg, + GPtrArray * secrets) { - int i; - - for (i = 0; i < secrets->len; i++) { - NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; - char *pwd = NULL; - - /* Ask user for the password */ - if (msg) - g_print ("%s\n", msg); - if (secret->value) { - /* Prefill the password if we have it. */ - rl_startup_hook = set_deftext; - pre_input_deftext = g_strdup (secret->value); - } - if (secret->no_prompt_entry_id) - pwd = nmc_readline (nmc_config, "%s: ", secret->pretty_name); - else - pwd = nmc_readline (nmc_config, "%s (%s): ", secret->pretty_name, secret->entry_id); - - /* No password provided, cancel the secrets. */ - if (!pwd) - return FALSE; - g_free (secret->value); - secret->value = pwd; - } - return TRUE; + int i; + + for (i = 0; i < secrets->len; i++) { + NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; + char * pwd = NULL; + + /* Ask user for the password */ + if (msg) + g_print("%s\n", msg); + if (secret->value) { + /* Prefill the password if we have it. */ + rl_startup_hook = set_deftext; + pre_input_deftext = g_strdup(secret->value); + } + if (secret->no_prompt_entry_id) + pwd = nmc_readline(nmc_config, "%s: ", secret->pretty_name); + else + pwd = nmc_readline(nmc_config, "%s (%s): ", secret->pretty_name, secret->entry_id); + + /* No password provided, cancel the secrets. */ + if (!pwd) + return FALSE; + g_free(secret->value); + secret->value = pwd; + } + return TRUE; } static void -secrets_requested (NMSecretAgentSimple *agent, - const char *request_id, - const char *title, - const char *msg, - GPtrArray *secrets, - gpointer user_data) +secrets_requested(NMSecretAgentSimple *agent, + const char * request_id, + const char * title, + const char * msg, + GPtrArray * secrets, + gpointer user_data) { - NmCli *nmc = user_data; - gboolean success; + NmCli * nmc = user_data; + gboolean success; - if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) - nmc_terminal_erase_line (); + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) + nmc_terminal_erase_line(); - success = get_secrets_from_user (&nmc->nmc_config, request_id, title, msg, secrets); - nm_secret_agent_simple_response (agent, - request_id, - success ? secrets : NULL); + success = get_secrets_from_user(&nmc->nmc_config, request_id, title, msg, secrets); + nm_secret_agent_simple_response(agent, request_id, success ? secrets : NULL); } static void -do_agent_secret (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv) +do_agent_secret(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - next_arg (nmc, &argc, &argv, NULL); - if (nmc->complete) - return; - - /* Create secret agent */ - nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-agent"); - if (nmc->secret_agent) { - /* We keep running */ - nmc->should_wait++; - - nm_secret_agent_simple_enable (nmc->secret_agent, NULL); - g_signal_connect (nmc->secret_agent, - NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS, - G_CALLBACK (secrets_requested), - nmc); - g_print (_("nmcli successfully registered as a NetworkManager's secret agent.\n")); - } else { - g_string_printf (nmc->return_text, _("Error: secret agent initialization failed")); - nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; - } + next_arg(nmc, &argc, &argv, NULL); + if (nmc->complete) + return; + + /* Create secret agent */ + nmc->secret_agent = nm_secret_agent_simple_new("nmcli-agent"); + if (nmc->secret_agent) { + /* We keep running */ + nmc->should_wait++; + + nm_secret_agent_simple_enable(nmc->secret_agent, NULL); + g_signal_connect(nmc->secret_agent, + NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS, + G_CALLBACK(secrets_requested), + nmc); + g_print(_("nmcli successfully registered as a NetworkManager's secret agent.\n")); + } else { + g_string_printf(nmc->return_text, _("Error: secret agent initialization failed")); + nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; + } } static void -polkit_registered (gpointer instance, - gpointer user_data) +polkit_registered(gpointer instance, gpointer user_data) { - g_print (_("nmcli successfully registered as a polkit agent.\n")); + g_print(_("nmcli successfully registered as a polkit agent.\n")); } static void -polkit_error (gpointer instance, - const char *error, - gpointer user_data) +polkit_error(gpointer instance, const char *error, gpointer user_data) { - g_main_loop_quit (loop); + g_main_loop_quit(loop); } static void -do_agent_polkit (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv) +do_agent_polkit(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - gs_free_error GError *error = NULL; - - next_arg (nmc, &argc, &argv, NULL); - if (nmc->complete) - return; - - if (!nmc_polkit_agent_init (nmc, TRUE, &error)) { - g_dbus_error_strip_remote_error (error); - g_string_printf (nmc->return_text, - _("Error: polkit agent initialization failed: %s"), - error->message); - nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; - } else { - /* We keep running */ - nmc->should_wait++; - g_signal_connect (nmc->pk_listener, - NM_POLKIT_LISTENER_SIGNAL_ERROR, - G_CALLBACK (polkit_error), - NULL); - g_signal_connect (nmc->pk_listener, - NM_POLKIT_LISTENER_SIGNAL_REGISTERED, - G_CALLBACK (polkit_registered), - NULL); - - /* keep running */ - nmc->should_wait++; - } + gs_free_error GError *error = NULL; + + next_arg(nmc, &argc, &argv, NULL); + if (nmc->complete) + return; + + if (!nmc_polkit_agent_init(nmc, TRUE, &error)) { + g_dbus_error_strip_remote_error(error); + g_string_printf(nmc->return_text, + _("Error: polkit agent initialization failed: %s"), + error->message); + nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; + } else { + /* We keep running */ + nmc->should_wait++; + g_signal_connect(nmc->pk_listener, + NM_POLKIT_LISTENER_SIGNAL_ERROR, + G_CALLBACK(polkit_error), + NULL); + g_signal_connect(nmc->pk_listener, + NM_POLKIT_LISTENER_SIGNAL_REGISTERED, + G_CALLBACK(polkit_registered), + NULL); + + /* keep running */ + nmc->should_wait++; + } } static void -do_agent_all (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv) +do_agent_all(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - NMCResultCode r; - - next_arg (nmc, &argc, &argv, NULL); - if (nmc->complete) - return; - - /* Run both secret and polkit agent */ - do_agent_secret (cmd, nmc, argc, argv); - r = nmc->return_value; - if (r != NMC_RESULT_SUCCESS) { - g_printerr ("%s\n", nmc->return_text->str); - g_string_truncate (nmc->return_text, 0); - nmc->return_value = NMC_RESULT_SUCCESS; - } - - do_agent_polkit (cmd, nmc, argc, argv); - if (nmc->return_value != NMC_RESULT_SUCCESS) { - g_printerr ("%s\n", nmc->return_text->str); - g_string_truncate (nmc->return_text, 0); - } - - if (r != NMC_RESULT_SUCCESS) - nmc->return_value = r; + NMCResultCode r; + + next_arg(nmc, &argc, &argv, NULL); + if (nmc->complete) + return; + + /* Run both secret and polkit agent */ + do_agent_secret(cmd, nmc, argc, argv); + r = nmc->return_value; + if (r != NMC_RESULT_SUCCESS) { + g_printerr("%s\n", nmc->return_text->str); + g_string_truncate(nmc->return_text, 0); + nmc->return_value = NMC_RESULT_SUCCESS; + } + + do_agent_polkit(cmd, nmc, argc, argv); + if (nmc->return_value != NMC_RESULT_SUCCESS) { + g_printerr("%s\n", nmc->return_text->str); + g_string_truncate(nmc->return_text, 0); + } + + if (r != NMC_RESULT_SUCCESS) + nmc->return_value = r; } void -nmc_command_func_agent (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv) +nmc_command_func_agent(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - static const NMCCommand cmds[] = { - { "secret", do_agent_secret, usage_agent_secret, TRUE, TRUE }, - { "polkit", do_agent_polkit, usage_agent_polkit, TRUE, TRUE }, - { "all", do_agent_all, usage_agent_all, TRUE, TRUE }, - { NULL, do_agent_all, usage, TRUE, TRUE }, - }; - - next_arg (nmc, &argc, &argv, NULL); - nmc_do_cmd (nmc, cmds, *argv, argc, argv); + static const NMCCommand cmds[] = { + {"secret", do_agent_secret, usage_agent_secret, TRUE, TRUE}, + {"polkit", do_agent_polkit, usage_agent_polkit, TRUE, TRUE}, + {"all", do_agent_all, usage_agent_all, TRUE, TRUE}, + {NULL, do_agent_all, usage, TRUE, TRUE}, + }; + + next_arg(nmc, &argc, &argv, NULL); + nmc_do_cmd(nmc, cmds, *argv, argc, argv); } diff --git a/clients/cli/common.c b/clients/cli/common.c index 15cc430..e530656 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2012 - 2018 Red Hat, Inc. */ @@ -24,365 +24,359 @@ /*****************************************************************************/ static char ** -_ip_config_get_routes (NMIPConfig *cfg) +_ip_config_get_routes(NMIPConfig *cfg) { - gs_unref_hashtable GHashTable *hash = NULL; - GPtrArray *ptr_array; - char **arr; - guint i; - - ptr_array = nm_ip_config_get_routes (cfg); - if (!ptr_array) - return NULL; - - if (ptr_array->len == 0) - return NULL; - - arr = g_new (char *, ptr_array->len + 1); - for (i = 0; i < ptr_array->len; i++) { - NMIPRoute *route = g_ptr_array_index (ptr_array, i); - gs_strfreev char **names = NULL; - gsize j; - GString *str; - guint64 metric; - gs_free char *attributes = NULL; - - str = g_string_new (NULL); - g_string_append_printf (str, - "dst = %s/%u, nh = %s", - nm_ip_route_get_dest (route), - nm_ip_route_get_prefix (route), - nm_ip_route_get_next_hop (route) - ?: (nm_ip_route_get_family (route) == AF_INET ? "0.0.0.0" : "::")); - - metric = nm_ip_route_get_metric (route); - if (metric != -1) { - g_string_append_printf (str, - ", mt = %u", - (guint) metric); - } - - names = nm_ip_route_get_attribute_names (route); - if (names[0]) { - if (!hash) - hash = g_hash_table_new (nm_str_hash, g_str_equal); - else - g_hash_table_remove_all (hash); - - for (j = 0; names[j]; j++) - g_hash_table_insert (hash, names[j], nm_ip_route_get_attribute (route, names[j])); - - attributes = nm_utils_format_variant_attributes (hash, ',', '='); - if (attributes) { - g_string_append (str, ", "); - g_string_append (str, attributes); - } - } - - arr[i] = g_string_free (str, FALSE); - } - - nm_assert (i == ptr_array->len); - arr[i] = NULL; - - return arr; + gs_unref_hashtable GHashTable *hash = NULL; + GPtrArray * ptr_array; + char ** arr; + guint i; + + ptr_array = nm_ip_config_get_routes(cfg); + if (!ptr_array) + return NULL; + + if (ptr_array->len == 0) + return NULL; + + arr = g_new(char *, ptr_array->len + 1); + for (i = 0; i < ptr_array->len; i++) { + NMIPRoute * route = g_ptr_array_index(ptr_array, i); + gs_strfreev char **names = NULL; + gsize j; + GString * str; + guint64 metric; + gs_free char * attributes = NULL; + + str = g_string_new(NULL); + g_string_append_printf( + str, + "dst = %s/%u, nh = %s", + nm_ip_route_get_dest(route), + nm_ip_route_get_prefix(route), + nm_ip_route_get_next_hop(route) + ?: (nm_ip_route_get_family(route) == AF_INET ? "0.0.0.0" : "::")); + + metric = nm_ip_route_get_metric(route); + if (metric != -1) { + g_string_append_printf(str, ", mt = %u", (guint) metric); + } + + names = nm_ip_route_get_attribute_names(route); + if (names[0]) { + if (!hash) + hash = g_hash_table_new(nm_str_hash, g_str_equal); + else + g_hash_table_remove_all(hash); + + for (j = 0; names[j]; j++) + g_hash_table_insert(hash, names[j], nm_ip_route_get_attribute(route, names[j])); + + attributes = nm_utils_format_variant_attributes(hash, ',', '='); + if (attributes) { + g_string_append(str, ", "); + g_string_append(str, attributes); + } + } + + arr[i] = g_string_free(str, FALSE); + } + + nm_assert(i == ptr_array->len); + arr[i] = NULL; + + return arr; } /*****************************************************************************/ -static gconstpointer -_metagen_ip4_config_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer _metagen_ip4_config_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMIPConfig *cfg4 = target; - GPtrArray *ptr_array; - char **arr; - const char *const*arrc; - guint i = 0; - const char *str; - - nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM); - - NMC_HANDLE_COLOR (NM_META_COLOR_NONE); - NM_SET_OUT (out_is_default, TRUE); - - switch (info->info_type) { - case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS: - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) - return NULL; - ptr_array = nm_ip_config_get_addresses (cfg4); - if (ptr_array) { - arr = g_new (char *, ptr_array->len + 1); - for (i = 0; i < ptr_array->len; i++) { - NMIPAddress *addr = g_ptr_array_index (ptr_array, i); - - arr[i] = g_strdup_printf ("%s/%u", - nm_ip_address_get_address (addr), - nm_ip_address_get_prefix (addr)); - } - arr[i] = NULL; - } else - arr = NULL; - goto arr_out; - case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY: - str = nm_ip_config_get_gateway (cfg4); - NM_SET_OUT (out_is_default, !str); - return str; - case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE: - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) - return NULL; - arr = _ip_config_get_routes (cfg4); - goto arr_out; - case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS: - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) - return NULL; - arrc = nm_ip_config_get_nameservers (cfg4); - goto arrc_out; - case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN: - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) - return NULL; - arrc = nm_ip_config_get_domains (cfg4); - goto arrc_out; - case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS: - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) - return NULL; - arrc = nm_ip_config_get_wins_servers (cfg4); - goto arrc_out; - default: - break; - } - - g_return_val_if_reached (NULL); + NMIPConfig * cfg4 = target; + GPtrArray * ptr_array; + char ** arr; + const char *const *arrc; + guint i = 0; + const char * str; + + nm_assert(info->info_type < _NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM); + + NMC_HANDLE_COLOR(NM_META_COLOR_NONE); + NM_SET_OUT(out_is_default, TRUE); + + switch (info->info_type) { + case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS: + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) + return NULL; + ptr_array = nm_ip_config_get_addresses(cfg4); + if (ptr_array) { + arr = g_new(char *, ptr_array->len + 1); + for (i = 0; i < ptr_array->len; i++) { + NMIPAddress *addr = g_ptr_array_index(ptr_array, i); + + arr[i] = g_strdup_printf("%s/%u", + nm_ip_address_get_address(addr), + nm_ip_address_get_prefix(addr)); + } + arr[i] = NULL; + } else + arr = NULL; + goto arr_out; + case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY: + str = nm_ip_config_get_gateway(cfg4); + NM_SET_OUT(out_is_default, !str); + return str; + case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE: + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) + return NULL; + arr = _ip_config_get_routes(cfg4); + goto arr_out; + case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS: + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) + return NULL; + arrc = nm_ip_config_get_nameservers(cfg4); + goto arrc_out; + case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN: + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) + return NULL; + arrc = nm_ip_config_get_domains(cfg4); + goto arrc_out; + case NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS: + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) + return NULL; + arrc = nm_ip_config_get_wins_servers(cfg4); + goto arrc_out; + default: + break; + } + + g_return_val_if_reached(NULL); arrc_out: - NM_SET_OUT (out_is_default, !arrc || !arrc[0]); - *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; - return arrc; + NM_SET_OUT(out_is_default, !arrc || !arrc[0]); + *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; + return arrc; arr_out: - NM_SET_OUT (out_is_default, !arr || !arr[0]); - *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; - *out_to_free = arr; - return arr; + NM_SET_OUT(out_is_default, !arr || !arr[0]); + *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; + *out_to_free = arr; + return arr; } const NmcMetaGenericInfo *const metagen_ip4_config[_NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM + 1] = { #define _METAGEN_IP4_CONFIG(type, name) \ - [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_ip4_config_get_fcn) - _METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS, "ADDRESS"), - _METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY, "GATEWAY"), - _METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE, "ROUTE"), - _METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS, "DNS"), - _METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN, "DOMAIN"), - _METAGEN_IP4_CONFIG (NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS, "WINS"), + [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_ip4_config_get_fcn) + _METAGEN_IP4_CONFIG(NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS, "ADDRESS"), + _METAGEN_IP4_CONFIG(NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY, "GATEWAY"), + _METAGEN_IP4_CONFIG(NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE, "ROUTE"), + _METAGEN_IP4_CONFIG(NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS, "DNS"), + _METAGEN_IP4_CONFIG(NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN, "DOMAIN"), + _METAGEN_IP4_CONFIG(NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS, "WINS"), }; /*****************************************************************************/ -static gconstpointer -_metagen_ip6_config_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer _metagen_ip6_config_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMIPConfig *cfg6 = target; - GPtrArray *ptr_array; - char **arr; - const char *const*arrc; - guint i = 0; - const char *str; - - nm_assert (info->info_type < _NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM); - - NMC_HANDLE_COLOR (NM_META_COLOR_NONE); - NM_SET_OUT (out_is_default, TRUE); - - switch (info->info_type) { - case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ADDRESS: - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) - return NULL; - ptr_array = nm_ip_config_get_addresses (cfg6); - if (ptr_array) { - arr = g_new (char *, ptr_array->len + 1); - for (i = 0; i < ptr_array->len; i++) { - NMIPAddress *addr = g_ptr_array_index (ptr_array, i); - - arr[i] = g_strdup_printf ("%s/%u", - nm_ip_address_get_address (addr), - nm_ip_address_get_prefix (addr)); - } - arr[i] = NULL; - } else - arr = NULL; - goto arr_out; - case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_GATEWAY: - str = nm_ip_config_get_gateway (cfg6); - NM_SET_OUT (out_is_default, !str); - return str; - case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ROUTE: - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) - return NULL; - arr = _ip_config_get_routes (cfg6); - goto arr_out; - case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DNS: - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) - return NULL; - arrc = nm_ip_config_get_nameservers (cfg6); - goto arrc_out; - case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN: - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) - return NULL; - arrc = nm_ip_config_get_domains (cfg6); - goto arrc_out; - default: - break; - } - - g_return_val_if_reached (NULL); + NMIPConfig * cfg6 = target; + GPtrArray * ptr_array; + char ** arr; + const char *const *arrc; + guint i = 0; + const char * str; + + nm_assert(info->info_type < _NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM); + + NMC_HANDLE_COLOR(NM_META_COLOR_NONE); + NM_SET_OUT(out_is_default, TRUE); + + switch (info->info_type) { + case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ADDRESS: + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) + return NULL; + ptr_array = nm_ip_config_get_addresses(cfg6); + if (ptr_array) { + arr = g_new(char *, ptr_array->len + 1); + for (i = 0; i < ptr_array->len; i++) { + NMIPAddress *addr = g_ptr_array_index(ptr_array, i); + + arr[i] = g_strdup_printf("%s/%u", + nm_ip_address_get_address(addr), + nm_ip_address_get_prefix(addr)); + } + arr[i] = NULL; + } else + arr = NULL; + goto arr_out; + case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_GATEWAY: + str = nm_ip_config_get_gateway(cfg6); + NM_SET_OUT(out_is_default, !str); + return str; + case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ROUTE: + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) + return NULL; + arr = _ip_config_get_routes(cfg6); + goto arr_out; + case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DNS: + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) + return NULL; + arrc = nm_ip_config_get_nameservers(cfg6); + goto arrc_out; + case NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN: + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) + return NULL; + arrc = nm_ip_config_get_domains(cfg6); + goto arrc_out; + default: + break; + } + + g_return_val_if_reached(NULL); arrc_out: - NM_SET_OUT (out_is_default, !arrc || !arrc[0]); - *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; - return arrc; + NM_SET_OUT(out_is_default, !arrc || !arrc[0]); + *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; + return arrc; arr_out: - NM_SET_OUT (out_is_default, !arr || !arr[0]); - *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; - *out_to_free = arr; - return arr; + NM_SET_OUT(out_is_default, !arr || !arr[0]); + *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; + *out_to_free = arr; + return arr; } const NmcMetaGenericInfo *const metagen_ip6_config[_NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM + 1] = { #define _METAGEN_IP6_CONFIG(type, name) \ - [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_ip6_config_get_fcn) - _METAGEN_IP6_CONFIG (NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ADDRESS, "ADDRESS"), - _METAGEN_IP6_CONFIG (NMC_GENERIC_INFO_TYPE_IP6_CONFIG_GATEWAY, "GATEWAY"), - _METAGEN_IP6_CONFIG (NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ROUTE, "ROUTE"), - _METAGEN_IP6_CONFIG (NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DNS, "DNS"), - _METAGEN_IP6_CONFIG (NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN, "DOMAIN"), + [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_ip6_config_get_fcn) + _METAGEN_IP6_CONFIG(NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ADDRESS, "ADDRESS"), + _METAGEN_IP6_CONFIG(NMC_GENERIC_INFO_TYPE_IP6_CONFIG_GATEWAY, "GATEWAY"), + _METAGEN_IP6_CONFIG(NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ROUTE, "ROUTE"), + _METAGEN_IP6_CONFIG(NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DNS, "DNS"), + _METAGEN_IP6_CONFIG(NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN, "DOMAIN"), }; /*****************************************************************************/ -static gconstpointer -_metagen_dhcp_config_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) +static gconstpointer _metagen_dhcp_config_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) { - NMDhcpConfig *dhcp = target; - guint i; - char **arr = NULL; + NMDhcpConfig *dhcp = target; + guint i; + char ** arr = NULL; - NMC_HANDLE_COLOR (NM_META_COLOR_NONE); + NMC_HANDLE_COLOR(NM_META_COLOR_NONE); - switch (info->info_type) { - case NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION: - { - GHashTable *table; - gs_free char **arr2 = NULL; - guint n; + switch (info->info_type) { + case NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION: + { + GHashTable * table; + gs_free char **arr2 = NULL; + guint n; - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) - return NULL; + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) + return NULL; - table = nm_dhcp_config_get_options (dhcp); - if (!table) - goto arr_out; + table = nm_dhcp_config_get_options(dhcp); + if (!table) + goto arr_out; - arr2 = (char **) nm_utils_strdict_get_keys (table, TRUE, &n); - if (!n) - goto arr_out; + arr2 = (char **) nm_utils_strdict_get_keys(table, TRUE, &n); + if (!n) + goto arr_out; - nm_assert (arr2 && !arr2[n] && n == NM_PTRARRAY_LEN (arr2)); - for (i = 0; i < n; i++) { - const char *k = arr2[i]; - const char *v; + nm_assert(arr2 && !arr2[n] && n == NM_PTRARRAY_LEN(arr2)); + for (i = 0; i < n; i++) { + const char *k = arr2[i]; + const char *v; - nm_assert (k); - v = g_hash_table_lookup (table, k); - arr2[i] = g_strdup_printf ("%s = %s", k, v); - } + nm_assert(k); + v = g_hash_table_lookup(table, k); + arr2[i] = g_strdup_printf("%s = %s", k, v); + } - arr = g_steal_pointer (&arr2); - goto arr_out; - } - default: - break; - } + arr = g_steal_pointer(&arr2); + goto arr_out; + } + default: + break; + } - g_return_val_if_reached (NULL); + g_return_val_if_reached(NULL); arr_out: - NM_SET_OUT (out_is_default, !arr || !arr[0]); - *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; - *out_to_free = arr; - return arr; + NM_SET_OUT(out_is_default, !arr || !arr[0]); + *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; + *out_to_free = arr; + return arr; } const NmcMetaGenericInfo *const metagen_dhcp_config[_NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_NUM + 1] = { #define _METAGEN_DHCP_CONFIG(type, name) \ - [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_dhcp_config_get_fcn) - _METAGEN_DHCP_CONFIG (NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION, "OPTION"), + [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_dhcp_config_get_fcn) + _METAGEN_DHCP_CONFIG(NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION, "OPTION"), }; /*****************************************************************************/ gboolean -print_ip_config (NMIPConfig *cfg, - int addr_family, - const NmcConfig *nmc_config, - const char *one_field) +print_ip_config(NMIPConfig * cfg, + int addr_family, + const NmcConfig *nmc_config, + const char * one_field) { - gs_free_error GError *error = NULL; - gs_free char *field_str = NULL; - - if (!cfg) - return FALSE; - - if (one_field) { - field_str = g_strdup_printf ("IP%c.%s", - nm_utils_addr_family_to_char (addr_family), - one_field); - } - - if (!nmc_print (nmc_config, - (gpointer[]) { cfg, NULL }, - NULL, - NULL, - addr_family == AF_INET - ? NMC_META_GENERIC_GROUP ("IP4", metagen_ip4_config, N_("GROUP")) - : NMC_META_GENERIC_GROUP ("IP6", metagen_ip6_config, N_("GROUP")), - field_str, - &error)) { - return FALSE; - } - return TRUE; + gs_free_error GError *error = NULL; + gs_free char * field_str = NULL; + + if (!cfg) + return FALSE; + + if (one_field) { + field_str = + g_strdup_printf("IP%c.%s", nm_utils_addr_family_to_char(addr_family), one_field); + } + + if (!nmc_print(nmc_config, + (gpointer[]){cfg, NULL}, + NULL, + NULL, + addr_family == AF_INET + ? NMC_META_GENERIC_GROUP("IP4", metagen_ip4_config, N_("GROUP")) + : NMC_META_GENERIC_GROUP("IP6", metagen_ip6_config, N_("GROUP")), + field_str, + &error)) { + return FALSE; + } + return TRUE; } gboolean -print_dhcp_config (NMDhcpConfig *dhcp, - int addr_family, - const NmcConfig *nmc_config, - const char *one_field) +print_dhcp_config(NMDhcpConfig * dhcp, + int addr_family, + const NmcConfig *nmc_config, + const char * one_field) { - gs_free_error GError *error = NULL; - gs_free char *field_str = NULL; - - if (!dhcp) - return FALSE; - - if (one_field) { - field_str = g_strdup_printf ("DHCP%c.%s", - nm_utils_addr_family_to_char (addr_family), - one_field); - } - - if (!nmc_print (nmc_config, - (gpointer[]) { dhcp, NULL }, - NULL, - NULL, - addr_family == AF_INET - ? NMC_META_GENERIC_GROUP ("DHCP4", metagen_dhcp_config, N_("GROUP")) - : NMC_META_GENERIC_GROUP ("DHCP6", metagen_dhcp_config, N_("GROUP")), - field_str, - &error)) { - return FALSE; - } - return TRUE; + gs_free_error GError *error = NULL; + gs_free char * field_str = NULL; + + if (!dhcp) + return FALSE; + + if (one_field) { + field_str = + g_strdup_printf("DHCP%c.%s", nm_utils_addr_family_to_char(addr_family), one_field); + } + + if (!nmc_print(nmc_config, + (gpointer[]){dhcp, NULL}, + NULL, + NULL, + addr_family == AF_INET + ? NMC_META_GENERIC_GROUP("DHCP4", metagen_dhcp_config, N_("GROUP")) + : NMC_META_GENERIC_GROUP("DHCP6", metagen_dhcp_config, N_("GROUP")), + field_str, + &error)) { + return FALSE; + } + return TRUE; } /* @@ -406,337 +400,337 @@ print_dhcp_config (NMDhcpConfig *dhcp, * Returns: found connection, or %NULL */ NMConnection * -nmc_find_connection (const GPtrArray *connections, - const char *filter_type, - const char *filter_val, - GPtrArray **out_result, - gboolean complete) +nmc_find_connection(const GPtrArray *connections, + const char * filter_type, + const char * filter_val, + GPtrArray ** out_result, + gboolean complete) { - NMConnection *best_candidate_uuid = NULL; - NMConnection *best_candidate = NULL; - gs_unref_ptrarray GPtrArray *result_allocated = NULL; - GPtrArray *result = out_result ? *out_result : NULL; - const guint result_inital_len = result ? result->len : 0u; - guint i, j; - - nm_assert (connections); - nm_assert (filter_val); - - for (i = 0; i < connections->len; i++) { - gboolean match_by_uuid = FALSE; - NMConnection *connection; - const char *v; - const char *v_num; - - connection = NM_CONNECTION (connections->pdata[i]); - - if (NM_IN_STRSET (filter_type, NULL, "uuid")) { - v = nm_connection_get_uuid (connection); - if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, v); - if (nm_streq0 (filter_val, v)) { - match_by_uuid = TRUE; - goto found; - } - } - - if (NM_IN_STRSET (filter_type, NULL, "id")) { - v = nm_connection_get_id (connection); - if (complete) - nmc_complete_strings (filter_val, v); - if (nm_streq0 (filter_val, v)) - goto found; - } - - if (NM_IN_STRSET (filter_type, NULL, "path")) { - v = nm_connection_get_path (connection); - v_num = nm_utils_dbus_path_get_last_component (v); - if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, v, (*filter_val ? v_num : NULL)); - if ( nm_streq0 (filter_val, v) - || (filter_type && nm_streq0 (filter_val, v_num))) - goto found; - } - - if (NM_IN_STRSET (filter_type, NULL, "filename")) { - v = nm_remote_connection_get_filename (NM_REMOTE_CONNECTION (connections->pdata[i])); - if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, v); - if (nm_streq0 (filter_val, v)) - goto found; - } - - continue; + NMConnection * best_candidate_uuid = NULL; + NMConnection * best_candidate = NULL; + gs_unref_ptrarray GPtrArray *result_allocated = NULL; + GPtrArray * result = out_result ? *out_result : NULL; + const guint result_inital_len = result ? result->len : 0u; + guint i, j; + + nm_assert(connections); + nm_assert(filter_val); + + for (i = 0; i < connections->len; i++) { + gboolean match_by_uuid = FALSE; + NMConnection *connection; + const char * v; + const char * v_num; + + connection = NM_CONNECTION(connections->pdata[i]); + + if (NM_IN_STRSET(filter_type, NULL, "uuid")) { + v = nm_connection_get_uuid(connection); + if (complete && (filter_type || *filter_val)) + nmc_complete_strings(filter_val, v); + if (nm_streq0(filter_val, v)) { + match_by_uuid = TRUE; + goto found; + } + } + + if (NM_IN_STRSET(filter_type, NULL, "id")) { + v = nm_connection_get_id(connection); + if (complete) + nmc_complete_strings(filter_val, v); + if (nm_streq0(filter_val, v)) + goto found; + } + + if (NM_IN_STRSET(filter_type, NULL, "path")) { + v = nm_connection_get_path(connection); + v_num = nm_utils_dbus_path_get_last_component(v); + if (complete && (filter_type || *filter_val)) + nmc_complete_strings(filter_val, v, (*filter_val ? v_num : NULL)); + if (nm_streq0(filter_val, v) || (filter_type && nm_streq0(filter_val, v_num))) + goto found; + } + + if (NM_IN_STRSET(filter_type, NULL, "filename")) { + v = nm_remote_connection_get_filename(NM_REMOTE_CONNECTION(connections->pdata[i])); + if (complete && (filter_type || *filter_val)) + nmc_complete_strings(filter_val, v); + if (nm_streq0(filter_val, v)) + goto found; + } + + continue; found: - if (match_by_uuid) { - if ( !complete - && !out_result) - return connection; - best_candidate_uuid = connection; - } else { - if (!best_candidate) - best_candidate = connection; - } - if (out_result) { - gboolean already_tracked = FALSE; - - if (!result) { - result_allocated = g_ptr_array_new_with_free_func (g_object_unref); - result = result_allocated; - } else { - for (j = 0; j < result->len; j++) { - if (connection == result->pdata[j]) { - already_tracked = TRUE; - break; - } - } - } - if (!already_tracked) { - if (match_by_uuid) { - /* the profile is matched exactly (by UUID). We prepend it - * to the list of all found profiles. */ - g_ptr_array_insert (result, result_inital_len, g_object_ref (connection)); - } else - g_ptr_array_add (result, g_object_ref (connection)); - } - } - } - - if (result_allocated) - *out_result = g_steal_pointer (&result_allocated); - return best_candidate_uuid ?: best_candidate; + if (match_by_uuid) { + if (!complete && !out_result) + return connection; + best_candidate_uuid = connection; + } else { + if (!best_candidate) + best_candidate = connection; + } + if (out_result) { + gboolean already_tracked = FALSE; + + if (!result) { + result_allocated = g_ptr_array_new_with_free_func(g_object_unref); + result = result_allocated; + } else { + for (j = 0; j < result->len; j++) { + if (connection == result->pdata[j]) { + already_tracked = TRUE; + break; + } + } + } + if (!already_tracked) { + if (match_by_uuid) { + /* the profile is matched exactly (by UUID). We prepend it + * to the list of all found profiles. */ + g_ptr_array_insert(result, result_inital_len, g_object_ref(connection)); + } else + g_ptr_array_add(result, g_object_ref(connection)); + } + } + } + + if (result_allocated) + *out_result = g_steal_pointer(&result_allocated); + return best_candidate_uuid ?: best_candidate; } NMActiveConnection * -nmc_find_active_connection (const GPtrArray *active_cons, - const char *filter_type, - const char *filter_val, - GPtrArray **out_result, - gboolean complete) +nmc_find_active_connection(const GPtrArray *active_cons, + const char * filter_type, + const char * filter_val, + GPtrArray ** out_result, + gboolean complete) { - guint i, j; - NMActiveConnection *best_candidate = NULL; - GPtrArray *result = out_result ? *out_result : NULL; - - nm_assert (filter_val); - - for (i = 0; i < active_cons->len; i++) { - NMRemoteConnection *con; - NMActiveConnection *candidate = g_ptr_array_index (active_cons, i); - const char *v, *v_num; - - con = nm_active_connection_get_connection (candidate); - - /* When filter_type is NULL, compare connection ID (filter_val) - * against all types. Otherwise, only compare against the specific - * type. If 'path' or 'apath' filter types are specified, comparison - * against numeric index (in addition to the whole path) is allowed. - */ - if (NM_IN_STRSET (filter_type, NULL, "id")) { - v = nm_active_connection_get_id (candidate); - if (complete) - nmc_complete_strings (filter_val, v); - if (nm_streq0 (filter_val, v)) - goto found; - } - - if (NM_IN_STRSET (filter_type, NULL, "uuid")) { - v = nm_active_connection_get_uuid (candidate); - if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, v); - if (nm_streq0 (filter_val, v)) - goto found; - } - - if (NM_IN_STRSET (filter_type, NULL, "path")) { - v = con ? nm_connection_get_path (NM_CONNECTION (con)) : NULL; - v_num = nm_utils_dbus_path_get_last_component (v); - if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, v, filter_type ? v_num : NULL); - if ( nm_streq0 (filter_val, v) - || (filter_type && nm_streq0 (filter_val, v_num))) - goto found; - } - - if (NM_IN_STRSET (filter_type, NULL, "filename")) { - v = nm_remote_connection_get_filename (con); - if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, v); - if (nm_streq0 (filter_val, v)) - goto found; - } - - if (NM_IN_STRSET (filter_type, NULL, "apath")) { - v = nm_object_get_path (NM_OBJECT (candidate)); - v_num = nm_utils_dbus_path_get_last_component (v); - if (complete && (filter_type || *filter_val)) - nmc_complete_strings (filter_val, v, filter_type ? v_num : NULL); - if ( nm_streq0 (filter_val, v) - || (filter_type && nm_streq0 (filter_val, v_num))) - goto found; - } - - continue; + guint i, j; + NMActiveConnection *best_candidate = NULL; + GPtrArray * result = out_result ? *out_result : NULL; + + nm_assert(filter_val); + + for (i = 0; i < active_cons->len; i++) { + NMRemoteConnection *con; + NMActiveConnection *candidate = g_ptr_array_index(active_cons, i); + const char * v, *v_num; + + con = nm_active_connection_get_connection(candidate); + + /* When filter_type is NULL, compare connection ID (filter_val) + * against all types. Otherwise, only compare against the specific + * type. If 'path' or 'apath' filter types are specified, comparison + * against numeric index (in addition to the whole path) is allowed. + */ + if (NM_IN_STRSET(filter_type, NULL, "id")) { + v = nm_active_connection_get_id(candidate); + if (complete) + nmc_complete_strings(filter_val, v); + if (nm_streq0(filter_val, v)) + goto found; + } + + if (NM_IN_STRSET(filter_type, NULL, "uuid")) { + v = nm_active_connection_get_uuid(candidate); + if (complete && (filter_type || *filter_val)) + nmc_complete_strings(filter_val, v); + if (nm_streq0(filter_val, v)) + goto found; + } + + if (NM_IN_STRSET(filter_type, NULL, "path")) { + v = con ? nm_connection_get_path(NM_CONNECTION(con)) : NULL; + v_num = nm_utils_dbus_path_get_last_component(v); + if (complete && (filter_type || *filter_val)) + nmc_complete_strings(filter_val, v, filter_type ? v_num : NULL); + if (nm_streq0(filter_val, v) || (filter_type && nm_streq0(filter_val, v_num))) + goto found; + } + + if (NM_IN_STRSET(filter_type, NULL, "filename")) { + v = nm_remote_connection_get_filename(con); + if (complete && (filter_type || *filter_val)) + nmc_complete_strings(filter_val, v); + if (nm_streq0(filter_val, v)) + goto found; + } + + if (NM_IN_STRSET(filter_type, NULL, "apath")) { + v = nm_object_get_path(NM_OBJECT(candidate)); + v_num = nm_utils_dbus_path_get_last_component(v); + if (complete && (filter_type || *filter_val)) + nmc_complete_strings(filter_val, v, filter_type ? v_num : NULL); + if (nm_streq0(filter_val, v) || (filter_type && nm_streq0(filter_val, v_num))) + goto found; + } + + continue; found: - if (!out_result) - return candidate; - if (!best_candidate) - best_candidate = candidate; - if (!result) - result = g_ptr_array_new_with_free_func (g_object_unref); - for (j = 0; j < result->len; j++) { - if (candidate == result->pdata[j]) - break; - } - if (j == result->len) - g_ptr_array_add (result, g_object_ref (candidate)); - } - - NM_SET_OUT (out_result, result); - return best_candidate; + if (!out_result) + return candidate; + if (!best_candidate) + best_candidate = candidate; + if (!result) + result = g_ptr_array_new_with_free_func(g_object_unref); + for (j = 0; j < result->len; j++) { + if (candidate == result->pdata[j]) + break; + } + if (j == result->len) + g_ptr_array_add(result, g_object_ref(candidate)); + } + + NM_SET_OUT(out_result, result); + return best_candidate; } static gboolean -vpn_openconnect_get_secrets (NMConnection *connection, GPtrArray *secrets) +vpn_openconnect_get_secrets(NMConnection *connection, GPtrArray *secrets) { - GError *error = NULL; - NMSettingVpn *s_vpn; - const char *gw, *port; - gs_free char *cookie = NULL; - gs_free char *gateway = NULL; - gs_free char *gwcert = NULL; - int status = 0; - int i; - gboolean ret; - - if (!connection) - return FALSE; - - if (!nm_connection_is_type (connection, NM_SETTING_VPN_SETTING_NAME)) - return FALSE; - - s_vpn = nm_connection_get_setting_vpn (connection); - if (!nm_streq0 (nm_setting_vpn_get_service_type (s_vpn), NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) - return FALSE; - - /* Get gateway and port */ - gw = nm_setting_vpn_get_data_item (s_vpn, "gateway"); - port = gw ? strrchr (gw, ':') : NULL; - - /* Interactively authenticate to OpenConnect server and get secrets */ - ret = nm_vpn_openconnect_authenticate_helper (gw, &cookie, &gateway, &gwcert, &status, &error); - if (!ret) { - g_printerr (_("Error: openconnect failed: %s\n"), error->message); - g_clear_error (&error); - return FALSE; - } - - if (WIFEXITED (status)) { - if (WEXITSTATUS (status) != 0) - g_printerr (_("Error: openconnect failed with status %d\n"), WEXITSTATUS (status)); - } else if (WIFSIGNALED (status)) - g_printerr (_("Error: openconnect failed with signal %d\n"), WTERMSIG (status)); - - /* Append port to the host value */ - if (gateway && port) { - gs_free char *tmp = gateway; - - gateway = g_strdup_printf ("%s%s", tmp, port); - } - - /* Fill secrets to the array */ - for (i = 0; i < secrets->len; i++) { - NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; - - if (secret->secret_type != NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET) - continue; - if (!nm_streq0 (secret->vpn_type, NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) - continue; - - if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "cookie")) { - g_free (secret->value); - secret->value = g_steal_pointer (&cookie); - } else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gateway")) { - g_free (secret->value); - secret->value = g_steal_pointer (&gateway); - } else if (nm_streq0 (secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gwcert")) { - g_free (secret->value); - secret->value = g_steal_pointer (&gwcert); - } - } - - return TRUE; + GError * error = NULL; + NMSettingVpn *s_vpn; + const char * gw, *port; + gs_free char *cookie = NULL; + gs_free char *gateway = NULL; + gs_free char *gwcert = NULL; + int status = 0; + int i; + gboolean ret; + + if (!connection) + return FALSE; + + if (!nm_connection_is_type(connection, NM_SETTING_VPN_SETTING_NAME)) + return FALSE; + + s_vpn = nm_connection_get_setting_vpn(connection); + if (!nm_streq0(nm_setting_vpn_get_service_type(s_vpn), NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) + return FALSE; + + /* Get gateway and port */ + gw = nm_setting_vpn_get_data_item(s_vpn, "gateway"); + port = gw ? strrchr(gw, ':') : NULL; + + /* Interactively authenticate to OpenConnect server and get secrets */ + ret = nm_vpn_openconnect_authenticate_helper(gw, &cookie, &gateway, &gwcert, &status, &error); + if (!ret) { + g_printerr(_("Error: openconnect failed: %s\n"), error->message); + g_clear_error(&error); + return FALSE; + } + + if (WIFEXITED(status)) { + if (WEXITSTATUS(status) != 0) + g_printerr(_("Error: openconnect failed with status %d\n"), WEXITSTATUS(status)); + } else if (WIFSIGNALED(status)) + g_printerr(_("Error: openconnect failed with signal %d\n"), WTERMSIG(status)); + + /* Append port to the host value */ + if (gateway && port) { + gs_free char *tmp = gateway; + + gateway = g_strdup_printf("%s%s", tmp, port); + } + + /* Fill secrets to the array */ + for (i = 0; i < secrets->len; i++) { + NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; + + if (secret->secret_type != NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET) + continue; + if (!nm_streq0(secret->vpn_type, NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT)) + continue; + + if (nm_streq0(secret->entry_id, NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "cookie")) { + g_free(secret->value); + secret->value = g_steal_pointer(&cookie); + } else if (nm_streq0(secret->entry_id, + NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gateway")) { + g_free(secret->value); + secret->value = g_steal_pointer(&gateway); + } else if (nm_streq0(secret->entry_id, + NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "gwcert")) { + g_free(secret->value); + secret->value = g_steal_pointer(&gwcert); + } + } + + return TRUE; } static gboolean -get_secrets_from_user (const NmcConfig *nmc_config, - const char *request_id, - const char *title, - const char *msg, - NMConnection *connection, - gboolean ask, - GHashTable *pwds_hash, - GPtrArray *secrets) +get_secrets_from_user(const NmcConfig *nmc_config, + const char * request_id, + const char * title, + const char * msg, + NMConnection * connection, + gboolean ask, + GHashTable * pwds_hash, + GPtrArray * secrets) { - int i; - - /* Check if there is a VPN OpenConnect secret to ask for */ - if (ask) - vpn_openconnect_get_secrets (connection, secrets); - - for (i = 0; i < secrets->len; i++) { - NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; - char *pwd = NULL; - - /* First try to find the password in provided passwords file, - * then ask user. */ - if (pwds_hash && (pwd = g_hash_table_lookup (pwds_hash, secret->entry_id))) { - pwd = g_strdup (pwd); - } else { - if (ask) { - gboolean echo_on; - - if (secret->value) { - if (!g_strcmp0 (secret->vpn_type, NM_DBUS_INTERFACE ".openconnect")) { - /* Do not present and ask user for openconnect secrets, we already have them */ - continue; - } else { - /* Prefill the password if we have it. */ - rl_startup_hook = nmc_rl_set_deftext; - nmc_rl_pre_input_deftext = g_strdup (secret->value); - } - } - if (msg) - g_print ("%s\n", msg); - - echo_on = secret->is_secret - ? nmc_config->show_secrets - : TRUE; - - if (secret->no_prompt_entry_id) - pwd = nmc_readline_echo (nmc_config, echo_on, "%s: ", secret->pretty_name); - else - pwd = nmc_readline_echo (nmc_config, echo_on, "%s (%s): ", secret->pretty_name, secret->entry_id); - - if (!pwd) - pwd = g_strdup (""); - } else { - if (msg) - g_print ("%s\n", msg); - g_printerr (_("Warning: password for '%s' not given in 'passwd-file' " - "and nmcli cannot ask without '--ask' option.\n"), - secret->entry_id); - } - } - /* No password provided, cancel the secrets. */ - if (!pwd) - return FALSE; - nm_free_secret (secret->value); - secret->value = pwd; - } - return TRUE; + int i; + + /* Check if there is a VPN OpenConnect secret to ask for */ + if (ask) + vpn_openconnect_get_secrets(connection, secrets); + + for (i = 0; i < secrets->len; i++) { + NMSecretAgentSimpleSecret *secret = secrets->pdata[i]; + char * pwd = NULL; + + /* First try to find the password in provided passwords file, + * then ask user. */ + if (pwds_hash && (pwd = g_hash_table_lookup(pwds_hash, secret->entry_id))) { + pwd = g_strdup(pwd); + } else { + if (ask) { + gboolean echo_on; + + if (secret->value) { + if (!g_strcmp0(secret->vpn_type, NM_DBUS_INTERFACE ".openconnect")) { + /* Do not present and ask user for openconnect secrets, we already have them */ + continue; + } else { + /* Prefill the password if we have it. */ + rl_startup_hook = nmc_rl_set_deftext; + nmc_rl_pre_input_deftext = g_strdup(secret->value); + } + } + if (msg) + g_print("%s\n", msg); + + echo_on = secret->is_secret ? nmc_config->show_secrets : TRUE; + + if (secret->no_prompt_entry_id) + pwd = nmc_readline_echo(nmc_config, echo_on, "%s: ", secret->pretty_name); + else + pwd = nmc_readline_echo(nmc_config, + echo_on, + "%s (%s): ", + secret->pretty_name, + secret->entry_id); + + if (!pwd) + pwd = g_strdup(""); + } else { + if (msg) + g_print("%s\n", msg); + g_printerr(_("Warning: password for '%s' not given in 'passwd-file' " + "and nmcli cannot ask without '--ask' option.\n"), + secret->entry_id); + } + } + /* No password provided, cancel the secrets. */ + if (!pwd) + return FALSE; + nm_free_secret(secret->value); + secret->value = pwd; + } + return TRUE; } /** @@ -754,81 +748,81 @@ get_secrets_from_user (const NmcConfig *nmc_config, * NMSecretAgentSimpleSecret. */ void -nmc_secrets_requested (NMSecretAgentSimple *agent, - const char *request_id, - const char *title, - const char *msg, - GPtrArray *secrets, - gpointer user_data) +nmc_secrets_requested(NMSecretAgentSimple *agent, + const char * request_id, + const char * title, + const char * msg, + GPtrArray * secrets, + gpointer user_data) { - NmCli *nmc = (NmCli *) user_data; - NMConnection *connection = NULL; - char *path, *p; - gboolean success = FALSE; - const GPtrArray *connections; - - if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) - nmc_terminal_erase_line (); - - /* Find the connection for the request */ - path = g_strdup (request_id); - if (path) { - p = strrchr (path, '/'); - if (p) - *p = '\0'; - connections = nm_client_get_connections (nmc->client); - connection = nmc_find_connection (connections, "path", path, NULL, FALSE); - g_free (path); - } - - success = get_secrets_from_user (&nmc->nmc_config, - request_id, - title, - msg, - connection, - nmc->nmc_config.in_editor || nmc->ask, - nmc->pwds_hash, - secrets); - if (success) - nm_secret_agent_simple_response (agent, request_id, secrets); - else { - /* Unregister our secret agent on failure, so that another agent - * may be tried */ - if (nmc->secret_agent) { - nm_secret_agent_old_unregister (NM_SECRET_AGENT_OLD (nmc->secret_agent), NULL, NULL); - g_clear_object (&nmc->secret_agent); - } - } + NmCli * nmc = (NmCli *) user_data; + NMConnection * connection = NULL; + char * path, *p; + gboolean success = FALSE; + const GPtrArray *connections; + + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) + nmc_terminal_erase_line(); + + /* Find the connection for the request */ + path = g_strdup(request_id); + if (path) { + p = strrchr(path, '/'); + if (p) + *p = '\0'; + connections = nm_client_get_connections(nmc->client); + connection = nmc_find_connection(connections, "path", path, NULL, FALSE); + g_free(path); + } + + success = get_secrets_from_user(&nmc->nmc_config, + request_id, + title, + msg, + connection, + nmc->nmc_config.in_editor || nmc->ask, + nmc->pwds_hash, + secrets); + if (success) + nm_secret_agent_simple_response(agent, request_id, secrets); + else { + /* Unregister our secret agent on failure, so that another agent + * may be tried */ + if (nmc->secret_agent) { + nm_secret_agent_old_unregister(NM_SECRET_AGENT_OLD(nmc->secret_agent), NULL, NULL); + g_clear_object(&nmc->secret_agent); + } + } } char * -nmc_unique_connection_name (const GPtrArray *connections, const char *try_name) +nmc_unique_connection_name(const GPtrArray *connections, const char *try_name) { - NMConnection *connection; - const char *name; - char *new_name; - unsigned num = 1; - int i = 0; - - new_name = g_strdup (try_name); - while (i < connections->len) { - connection = NM_CONNECTION (connections->pdata[i]); - - name = nm_connection_get_id (connection); - if (g_strcmp0 (new_name, name) == 0) { - g_free (new_name); - new_name = g_strdup_printf ("%s-%d", try_name, num++); - i = 0; - } else - i++; - } - return new_name; + NMConnection *connection; + const char * name; + char * new_name; + unsigned num = 1; + int i = 0; + + new_name = g_strdup(try_name); + while (i < connections->len) { + connection = NM_CONNECTION(connections->pdata[i]); + + name = nm_connection_get_id(connection); + if (g_strcmp0(new_name, name) == 0) { + g_free(new_name); + new_name = g_strdup_printf("%s-%d", try_name, num++); + i = 0; + } else + i++; + } + return new_name; } /* readline state variables */ static gboolean nmcli_in_readline = FALSE; static gboolean rl_got_line; -static char *rl_string; +static char * rl_string; /** * nmc_cleanup_readline: @@ -837,109 +831,103 @@ static char *rl_string; * It makes sure the terminal is not garbled. */ void -nmc_cleanup_readline (void) +nmc_cleanup_readline(void) { - rl_free_line_state (); - rl_cleanup_after_signal (); + rl_free_line_state(); + rl_cleanup_after_signal(); } gboolean -nmc_get_in_readline (void) +nmc_get_in_readline(void) { - return nmcli_in_readline; + return nmcli_in_readline; } void -nmc_set_in_readline (gboolean in_readline) +nmc_set_in_readline(gboolean in_readline) { - nmcli_in_readline = in_readline; + nmcli_in_readline = in_readline; } static void -readline_cb (char *line) +readline_cb(char *line) { - rl_got_line = TRUE; - rl_string = line; - rl_callback_handler_remove (); + rl_got_line = TRUE; + rl_string = line; + rl_callback_handler_remove(); } static gboolean -stdin_ready_cb (int fd, - GIOCondition condition, - gpointer data) +stdin_ready_cb(int fd, GIOCondition condition, gpointer data) { - rl_callback_read_char (); - return TRUE; + rl_callback_read_char(); + return TRUE; } static char * -nmc_readline_helper (const NmcConfig *nmc_config, - const char *prompt) +nmc_readline_helper(const NmcConfig *nmc_config, const char *prompt) { - GSource *io_source; + GSource *io_source; - nmc_set_in_readline (TRUE); + nmc_set_in_readline(TRUE); - io_source = nm_g_unix_fd_source_new (STDIN_FILENO, - G_IO_IN, - G_PRIORITY_DEFAULT, - stdin_ready_cb, - NULL, - NULL); - g_source_attach (io_source, NULL); + io_source = nm_g_unix_fd_source_new(STDIN_FILENO, + G_IO_IN, + G_PRIORITY_DEFAULT, + stdin_ready_cb, + NULL, + NULL); + g_source_attach(io_source, NULL); read_again: - rl_string = NULL; - rl_got_line = FALSE; - rl_callback_handler_install (prompt, readline_cb); - - while ( !rl_got_line - && g_main_loop_is_running (loop) - && !nmc_seen_sigint ()) - g_main_context_iteration (NULL, TRUE); - - /* If Ctrl-C was detected, complete the line */ - if (nmc_seen_sigint ()) { - rl_echo_signal_char (SIGINT); - if (!rl_got_line) { - rl_stuff_char ('\n'); - rl_callback_read_char (); - } - } - - /* Add string to the history */ - if (rl_string && *rl_string) - add_history (rl_string); - - if (nmc_seen_sigint ()) { - /* Ctrl-C */ - nmc_clear_sigint (); - if ( nmc_config->in_editor - || (rl_string && *rl_string)) { - /* In editor, or the line is not empty */ - /* Call readline again to get new prompt (repeat) */ - g_free (rl_string); - goto read_again; - } else { - /* Not in editor and line is empty, exit */ - nmc_exit (); - } - } else if (!rl_string) { - /* Ctrl-D, exit */ - nmc_exit (); - } - - /* Return NULL, not empty string */ - if (rl_string && *rl_string == '\0') { - g_free (rl_string); - rl_string = NULL; - } - - nm_clear_g_source_inst (&io_source); - - nmc_set_in_readline (FALSE); - - return rl_string; + rl_string = NULL; + rl_got_line = FALSE; + rl_callback_handler_install(prompt, readline_cb); + + while (!rl_got_line && g_main_loop_is_running(loop) && !nmc_seen_sigint()) + g_main_context_iteration(NULL, TRUE); + + /* If Ctrl-C was detected, complete the line */ + if (nmc_seen_sigint()) { + rl_echo_signal_char(SIGINT); + if (!rl_got_line) { + rl_stuff_char('\n'); + rl_callback_read_char(); + } + } + + /* Add string to the history */ + if (rl_string && *rl_string) + add_history(rl_string); + + if (nmc_seen_sigint()) { + /* Ctrl-C */ + nmc_clear_sigint(); + if (nmc_config->in_editor || (rl_string && *rl_string)) { + /* In editor, or the line is not empty */ + /* Call readline again to get new prompt (repeat) */ + g_free(rl_string); + goto read_again; + } else { + /* Not in editor and line is empty, exit */ + nmc_exit(); + } + } else if (!rl_string) { + /* Ctrl-D, exit */ + nmc_exit(); + } + + /* Return NULL, not empty string */ + if (rl_string && *rl_string == '\0') { + g_free(rl_string); + rl_string = NULL; + } + + nm_clear_g_source_inst(&io_source); + + nmc_set_in_readline(FALSE); + + return rl_string; } /** @@ -957,44 +945,42 @@ read_again: * this function returns NULL. */ char * -nmc_readline (const NmcConfig *nmc_config, - const char *prompt_fmt, - ...) +nmc_readline(const NmcConfig *nmc_config, const char *prompt_fmt, ...) { - va_list args; - gs_free char *prompt = NULL; + va_list args; + gs_free char *prompt = NULL; - rl_initialize (); + rl_initialize(); - va_start (args, prompt_fmt); - prompt = g_strdup_vprintf (prompt_fmt, args); - va_end (args); - return nmc_readline_helper (nmc_config, prompt); + va_start(args, prompt_fmt); + prompt = g_strdup_vprintf(prompt_fmt, args); + va_end(args); + return nmc_readline_helper(nmc_config, prompt); } static void -nmc_secret_redisplay (void) +nmc_secret_redisplay(void) { - int save_point = rl_point; - int save_end = rl_end; - char *save_line_buffer = rl_line_buffer; - const char *subst = nmc_password_subst_char (); - int subst_len = strlen (subst); - int i; - - rl_point = g_utf8_strlen (save_line_buffer, save_point) * subst_len; - rl_end = g_utf8_strlen (rl_line_buffer, -1) * subst_len; - rl_line_buffer = g_slice_alloc (rl_end + 1); - - for (i = 0; i + subst_len <= rl_end; i += subst_len) - memcpy (&rl_line_buffer[i], subst, subst_len); - rl_line_buffer[i] = '\0'; - - rl_redisplay (); - g_slice_free1 (rl_end + 1, rl_line_buffer); - rl_line_buffer = save_line_buffer; - rl_end = save_end; - rl_point = save_point; + int save_point = rl_point; + int save_end = rl_end; + char * save_line_buffer = rl_line_buffer; + const char *subst = nmc_password_subst_char(); + int subst_len = strlen(subst); + int i; + + rl_point = g_utf8_strlen(save_line_buffer, save_point) * subst_len; + rl_end = g_utf8_strlen(rl_line_buffer, -1) * subst_len; + rl_line_buffer = g_slice_alloc(rl_end + 1); + + for (i = 0; i + subst_len <= rl_end; i += subst_len) + memcpy(&rl_line_buffer[i], subst, subst_len); + rl_line_buffer[i] = '\0'; + + rl_redisplay(); + g_slice_free1(rl_end + 1, rl_line_buffer); + rl_line_buffer = save_line_buffer; + rl_end = save_end; + rl_point = save_point; } /** @@ -1004,43 +990,42 @@ nmc_secret_redisplay (void) * nmc_readline(TRUE, ...) == nmc_readline(...) */ char * -nmc_readline_echo (const NmcConfig *nmc_config, - gboolean echo_on, - const char *prompt_fmt, - ...) +nmc_readline_echo(const NmcConfig *nmc_config, gboolean echo_on, const char *prompt_fmt, ...) { - va_list args; - gs_free char *prompt = NULL; - char *str; - nm_auto_free HISTORY_STATE *saved_history = NULL; - HISTORY_STATE passwd_history = { 0, }; - - va_start (args, prompt_fmt); - prompt = g_strdup_vprintf (prompt_fmt, args); - va_end (args); - - rl_initialize (); - - /* Hide the actual password */ - if (!echo_on) { - saved_history = history_get_history_state (); - history_set_history_state (&passwd_history); - /* stifling history is important as it tells readline to - * not store anything, otherwise sensitive data could be - * leaked */ - stifle_history (0); - rl_redisplay_function = nmc_secret_redisplay; - } - - str = nmc_readline_helper (nmc_config, prompt); - - /* Restore the non-hiding behavior */ - if (!echo_on) { - rl_redisplay_function = rl_redisplay; - history_set_history_state (saved_history); - } - - return str; + va_list args; + gs_free char *prompt = NULL; + char * str; + nm_auto_free HISTORY_STATE *saved_history = NULL; + HISTORY_STATE passwd_history = { + 0, + }; + + va_start(args, prompt_fmt); + prompt = g_strdup_vprintf(prompt_fmt, args); + va_end(args); + + rl_initialize(); + + /* Hide the actual password */ + if (!echo_on) { + saved_history = history_get_history_state(); + history_set_history_state(&passwd_history); + /* stifling history is important as it tells readline to + * not store anything, otherwise sensitive data could be + * leaked */ + stifle_history(0); + rl_redisplay_function = nmc_secret_redisplay; + } + + str = nmc_readline_helper(nmc_config, prompt); + + /* Restore the non-hiding behavior */ + if (!echo_on) { + rl_redisplay_function = rl_redisplay; + history_set_history_state(saved_history); + } + + return str; } /** @@ -1053,102 +1038,102 @@ nmc_readline_echo (const NmcConfig *nmc_config, * See e.g. http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC49 */ char * -nmc_rl_gen_func_basic (const char *text, int state, const char *const*words) +nmc_rl_gen_func_basic(const char *text, int state, const char *const *words) { - static int list_idx, len; - const char *name; - - if (!state) { - list_idx = 0; - len = strlen (text); - } - - /* Return the next name which partially matches one from the 'words' list. */ - while ((name = words[list_idx])) { - list_idx++; - - if (strncmp (name, text, len) == 0) - return g_strdup (name); - } - return NULL; + static int list_idx, len; + const char *name; + + if (!state) { + list_idx = 0; + len = strlen(text); + } + + /* Return the next name which partially matches one from the 'words' list. */ + while ((name = words[list_idx])) { + list_idx++; + + if (strncmp(name, text, len) == 0) + return g_strdup(name); + } + return NULL; } static struct { - bool initialized; - guint idx; - char **values; -} _rl_compentry_func_wrap = { 0 }; + bool initialized; + guint idx; + char **values; +} _rl_compentry_func_wrap = {0}; static char * -_rl_compentry_func_wrap_fcn (const char *text, int state) +_rl_compentry_func_wrap_fcn(const char *text, int state) { - g_return_val_if_fail (_rl_compentry_func_wrap.initialized, NULL); - - while ( _rl_compentry_func_wrap.values - && _rl_compentry_func_wrap.values[_rl_compentry_func_wrap.idx] - && !g_str_has_prefix (_rl_compentry_func_wrap.values[_rl_compentry_func_wrap.idx], text)) - _rl_compentry_func_wrap.idx++; - - if ( !_rl_compentry_func_wrap.values - || !_rl_compentry_func_wrap.values[_rl_compentry_func_wrap.idx]) { - g_strfreev (_rl_compentry_func_wrap.values); - _rl_compentry_func_wrap.values = NULL; - _rl_compentry_func_wrap.initialized = FALSE; - return NULL; - } - - return g_strdup (_rl_compentry_func_wrap.values[_rl_compentry_func_wrap.idx++]); + g_return_val_if_fail(_rl_compentry_func_wrap.initialized, NULL); + + while (_rl_compentry_func_wrap.values + && _rl_compentry_func_wrap.values[_rl_compentry_func_wrap.idx] + && !g_str_has_prefix(_rl_compentry_func_wrap.values[_rl_compentry_func_wrap.idx], text)) + _rl_compentry_func_wrap.idx++; + + if (!_rl_compentry_func_wrap.values + || !_rl_compentry_func_wrap.values[_rl_compentry_func_wrap.idx]) { + g_strfreev(_rl_compentry_func_wrap.values); + _rl_compentry_func_wrap.values = NULL; + _rl_compentry_func_wrap.initialized = FALSE; + return NULL; + } + + return g_strdup(_rl_compentry_func_wrap.values[_rl_compentry_func_wrap.idx++]); } NmcCompEntryFunc -nmc_rl_compentry_func_wrap (const char *const*values) +nmc_rl_compentry_func_wrap(const char *const *values) { - g_strfreev (_rl_compentry_func_wrap.values); - _rl_compentry_func_wrap.values = g_strdupv ((char **) values); - _rl_compentry_func_wrap.idx = 0; - _rl_compentry_func_wrap.initialized = TRUE; - return _rl_compentry_func_wrap_fcn; + g_strfreev(_rl_compentry_func_wrap.values); + _rl_compentry_func_wrap.values = g_strdupv((char **) values); + _rl_compentry_func_wrap.idx = 0; + _rl_compentry_func_wrap.initialized = TRUE; + return _rl_compentry_func_wrap_fcn; } char * -nmc_rl_gen_func_ifnames (const char *text, int state) +nmc_rl_gen_func_ifnames(const char *text, int state) { - int i; - const GPtrArray *devices; - const char **ifnames; - char *ret; - - devices = nm_client_get_devices (nm_cli_global_readline->client); - if (devices->len == 0) - return NULL; - - ifnames = g_new (const char *, devices->len + 1); - for (i = 0; i < devices->len; i++) { - NMDevice *dev = g_ptr_array_index (devices, i); - const char *ifname = nm_device_get_iface (dev); - ifnames[i] = ifname; - } - ifnames[i] = NULL; - - ret = nmc_rl_gen_func_basic (text, state, ifnames); - - g_free (ifnames); - return ret; + int i; + const GPtrArray *devices; + const char ** ifnames; + char * ret; + + devices = nm_client_get_devices(nm_cli_global_readline->client); + if (devices->len == 0) + return NULL; + + ifnames = g_new(const char *, devices->len + 1); + for (i = 0; i < devices->len; i++) { + NMDevice * dev = g_ptr_array_index(devices, i); + const char *ifname = nm_device_get_iface(dev); + ifnames[i] = ifname; + } + ifnames[i] = NULL; + + ret = nmc_rl_gen_func_basic(text, state, ifnames); + + g_free(ifnames); + return ret; } /* for pre-filling a string to readline prompt */ char *nmc_rl_pre_input_deftext; int -nmc_rl_set_deftext (void) +nmc_rl_set_deftext(void) { - if (nmc_rl_pre_input_deftext && rl_startup_hook) { - rl_insert_text (nmc_rl_pre_input_deftext); - g_free (nmc_rl_pre_input_deftext); - nmc_rl_pre_input_deftext = NULL; - rl_startup_hook = NULL; - } - return 0; + if (nmc_rl_pre_input_deftext && rl_startup_hook) { + rl_insert_text(nmc_rl_pre_input_deftext); + g_free(nmc_rl_pre_input_deftext); + nmc_rl_pre_input_deftext = NULL; + rl_startup_hook = NULL; + } + return 0; } /** @@ -1160,140 +1145,154 @@ nmc_rl_set_deftext (void) * Returns: a newly allocated string containing capabilities names separated by commas. */ char * -nmc_parse_lldp_capabilities (guint value) +nmc_parse_lldp_capabilities(guint value) { - /* IEEE Std 802.1AB-2009 - Table 8.4 */ - const char *names[] = { "other", "repeater", "mac-bridge", "wlan-access-point", - "router", "telephone", "docsis-cable-device", "station-only", - "c-vlan-component", "s-vlan-component", "tpmr" }; - gboolean first = TRUE; - GString *str; - int i; - - if (!value) - return g_strdup ("none"); - - str = g_string_new (""); - - for (i = 0; i < G_N_ELEMENTS (names); i++) { - if (value & (1 << i)) { - if (!first) - g_string_append_c (str, ','); - - first = FALSE; - value &= ~(1 << i); - g_string_append (str, names[i]); - } - } - - if (value) { - if (!first) - g_string_append_c (str, ','); - g_string_append (str, "reserved"); - } - - return g_string_free (str, FALSE); + /* IEEE Std 802.1AB-2009 - Table 8.4 */ + const char *names[] = {"other", + "repeater", + "mac-bridge", + "wlan-access-point", + "router", + "telephone", + "docsis-cable-device", + "station-only", + "c-vlan-component", + "s-vlan-component", + "tpmr"}; + gboolean first = TRUE; + GString * str; + int i; + + if (!value) + return g_strdup("none"); + + str = g_string_new(""); + + for (i = 0; i < G_N_ELEMENTS(names); i++) { + if (value & (1 << i)) { + if (!first) + g_string_append_c(str, ','); + + first = FALSE; + value &= ~(1 << i); + g_string_append(str, names[i]); + } + } + + if (value) { + if (!first) + g_string_append_c(str, ','); + g_string_append(str, "reserved"); + } + + return g_string_free(str, FALSE); } static void -command_done (GObject *object, GAsyncResult *res, gpointer user_data) +command_done(GObject *object, GAsyncResult *res, gpointer user_data) { - GTask *task = G_TASK (res); - NmCli *nmc = user_data; - gs_free_error GError *error = NULL; + GTask * task = G_TASK(res); + NmCli * nmc = user_data; + gs_free_error GError *error = NULL; - if (!g_task_propagate_boolean (task, &error)) { - nmc->return_value = error->code; - g_string_assign (nmc->return_text, error->message); - } + if (!g_task_propagate_boolean(task, &error)) { + nmc->return_value = error->code; + g_string_assign(nmc->return_text, error->message); + } - if (!nmc->should_wait) - g_main_loop_quit (loop); + if (!nmc->should_wait) + g_main_loop_quit(loop); } typedef struct { - const NMCCommand *cmd; - int argc; - char **argv; - GTask *task; + const NMCCommand *cmd; + int argc; + char ** argv; + GTask * task; } CmdCall; static void -call_cmd (NmCli *nmc, GTask *task, const NMCCommand *cmd, int argc, const char *const*argv); +call_cmd(NmCli *nmc, GTask *task, const NMCCommand *cmd, int argc, const char *const *argv); static void -got_client (GObject *source_object, GAsyncResult *res, gpointer user_data) +got_client(GObject *source_object, GAsyncResult *res, gpointer user_data) { - gs_unref_object GTask *task = NULL; - gs_free_error GError *error = NULL; - CmdCall *call = user_data; - NmCli *nmc; - - nm_assert (NM_IS_CLIENT (source_object)); - - task = g_steal_pointer (&call->task); - nmc = g_task_get_task_data (task); - - nmc->should_wait--; - - if (!g_async_initable_init_finish (G_ASYNC_INITABLE (source_object), - res, - &error)) { - g_object_unref (source_object); - g_task_return_new_error (task, NMCLI_ERROR, NMC_RESULT_ERROR_UNKNOWN, - _("Error: Could not create NMClient object: %s."), - error->message); - } else { - nmc->client = NM_CLIENT (source_object); - call_cmd (nmc, g_steal_pointer (&task), call->cmd, call->argc, (const char *const*) call->argv); - } - - g_strfreev (call->argv); - nm_g_slice_free (call); + gs_unref_object GTask *task = NULL; + gs_free_error GError *error = NULL; + CmdCall * call = user_data; + NmCli * nmc; + + nm_assert(NM_IS_CLIENT(source_object)); + + task = g_steal_pointer(&call->task); + nmc = g_task_get_task_data(task); + + nmc->should_wait--; + + if (!g_async_initable_init_finish(G_ASYNC_INITABLE(source_object), res, &error)) { + g_object_unref(source_object); + g_task_return_new_error(task, + NMCLI_ERROR, + NMC_RESULT_ERROR_UNKNOWN, + _("Error: Could not create NMClient object: %s."), + error->message); + } else { + nmc->client = NM_CLIENT(source_object); + call_cmd(nmc, + g_steal_pointer(&task), + call->cmd, + call->argc, + (const char *const *) call->argv); + } + + g_strfreev(call->argv); + nm_g_slice_free(call); } static void -call_cmd (NmCli *nmc, GTask *task, const NMCCommand *cmd, int argc, const char *const*argv) +call_cmd(NmCli *nmc, GTask *task, const NMCCommand *cmd, int argc, const char *const *argv) { - CmdCall *call; - - if (nmc->client || !cmd->needs_client) { - - /* Check whether NetworkManager is running */ - if (cmd->needs_nm_running && !nm_client_get_nm_running (nmc->client)) { - g_task_return_new_error (task, NMCLI_ERROR, NMC_RESULT_ERROR_NM_NOT_RUNNING, - _("Error: NetworkManager is not running.")); - } else { - cmd->func (cmd, nmc, argc, argv); - g_task_return_boolean (task, TRUE); - } - - g_object_unref (task); - } else { - nm_assert (nmc->client == NULL); - - nmc->should_wait++; - call = g_slice_new (CmdCall); - *call = (CmdCall) { - .cmd = cmd, - .argc = argc, - .argv = nm_utils_strv_dup (argv, argc, TRUE), - .task = task, - }; - nmc_client_new_async (NULL, - got_client, - call, - NM_CLIENT_INSTANCE_FLAGS, (guint) NM_CLIENT_INSTANCE_FLAGS_NO_AUTO_FETCH_PERMISSIONS, - NULL); - } + CmdCall *call; + + if (nmc->client || !cmd->needs_client) { + /* Check whether NetworkManager is running */ + if (cmd->needs_nm_running && !nm_client_get_nm_running(nmc->client)) { + g_task_return_new_error(task, + NMCLI_ERROR, + NMC_RESULT_ERROR_NM_NOT_RUNNING, + _("Error: NetworkManager is not running.")); + } else { + cmd->func(cmd, nmc, argc, argv); + g_task_return_boolean(task, TRUE); + } + + g_object_unref(task); + } else { + nm_assert(nmc->client == NULL); + + nmc->should_wait++; + call = g_slice_new(CmdCall); + *call = (CmdCall){ + .cmd = cmd, + .argc = argc, + .argv = nm_utils_strv_dup(argv, argc, TRUE), + .task = task, + }; + nmc_client_new_async(NULL, + got_client, + call, + NM_CLIENT_INSTANCE_FLAGS, + (guint) NM_CLIENT_INSTANCE_FLAGS_NO_AUTO_FETCH_PERMISSIONS, + NULL); + } } static void -nmc_complete_help (const char *prefix) +nmc_complete_help(const char *prefix) { - nmc_complete_strings (prefix, "help"); - if (*prefix == '-') - nmc_complete_strings (prefix, "-help", "--help"); + nmc_complete_strings(prefix, "help"); + if (*prefix == '-') + nmc_complete_strings(prefix, "-help", "--help"); } /** @@ -1316,61 +1315,67 @@ nmc_complete_help (const char *prefix) * no callback to free the memory in (for simplicity). */ void -nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, const char *const*argv) +nmc_do_cmd(NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, const char *const *argv) { - const NMCCommand *c; - gs_unref_object GTask *task = NULL; - - task = nm_g_task_new (NULL, NULL, nmc_do_cmd, command_done, nmc); - g_task_set_task_data (task, nmc, NULL); - - if (argc == 0 && nmc->complete) { - g_task_return_boolean (task, TRUE); - return; - } - - if (argc == 1 && nmc->complete) { - for (c = cmds; c->cmd; ++c) { - if (!*cmd || matches (cmd, c->cmd)) - g_print ("%s\n", c->cmd); - } - nmc_complete_help (cmd); - g_task_return_boolean (task, TRUE); - return; - } - - for (c = cmds; c->cmd; ++c) { - if (cmd && matches (cmd, c->cmd)) - break; - } - - if (c->cmd) { - /* A valid command was specified. */ - if (c->usage && argc == 2 && nmc->complete) - nmc_complete_help (*(argv+1)); - if (!nmc->complete && c->usage && nmc_arg_is_help (*(argv+1))) { - c->usage (); - g_task_return_boolean (task, TRUE); - } else { - call_cmd (nmc, g_steal_pointer (&task), c, argc, (const char *const*) argv); - } - } else if (cmd) { - /* Not a known command. */ - if (nmc_arg_is_help (cmd) && c->usage) { - c->usage (); - g_task_return_boolean (task, TRUE); - } else { - g_task_return_new_error (task, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: argument '%s' not understood. Try passing --help instead."), cmd); - } - } else if (c->func) { - /* No command, run the default handler. */ - call_cmd (nmc, g_steal_pointer (&task), c, argc, (const char *const*) argv); - } else { - /* No command and no default handler. */ - g_task_return_new_error (task, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: missing argument. Try passing --help.")); - } + const NMCCommand *c; + gs_unref_object GTask *task = NULL; + + task = nm_g_task_new(NULL, NULL, nmc_do_cmd, command_done, nmc); + g_task_set_task_data(task, nmc, NULL); + + if (argc == 0 && nmc->complete) { + g_task_return_boolean(task, TRUE); + return; + } + + if (argc == 1 && nmc->complete) { + for (c = cmds; c->cmd; ++c) { + if (!*cmd || matches(cmd, c->cmd)) + g_print("%s\n", c->cmd); + } + nmc_complete_help(cmd); + g_task_return_boolean(task, TRUE); + return; + } + + for (c = cmds; c->cmd; ++c) { + if (cmd && matches(cmd, c->cmd)) + break; + } + + if (c->cmd) { + /* A valid command was specified. */ + if (c->usage && argc == 2 && nmc->complete) + nmc_complete_help(*(argv + 1)); + if (!nmc->complete && c->usage && nmc_arg_is_help(*(argv + 1))) { + c->usage(); + g_task_return_boolean(task, TRUE); + } else { + call_cmd(nmc, g_steal_pointer(&task), c, argc, (const char *const *) argv); + } + } else if (cmd) { + /* Not a known command. */ + if (nmc_arg_is_help(cmd) && c->usage) { + c->usage(); + g_task_return_boolean(task, TRUE); + } else { + g_task_return_new_error( + task, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: argument '%s' not understood. Try passing --help instead."), + cmd); + } + } else if (c->func) { + /* No command, run the default handler. */ + call_cmd(nmc, g_steal_pointer(&task), c, argc, (const char *const *) argv); + } else { + /* No command and no default handler. */ + g_task_return_new_error(task, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: missing argument. Try passing --help.")); + } } /** @@ -1385,30 +1390,29 @@ nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, cons * no better way to suggest completion other than a hardcoded string list. */ void -nmc_complete_strv (const char *prefix, gssize nargs, const char *const*args) +nmc_complete_strv(const char *prefix, gssize nargs, const char *const *args) { - gsize i, n; + gsize i, n; - if (prefix && !prefix[0]) - prefix = NULL; + if (prefix && !prefix[0]) + prefix = NULL; - if (nargs < 0) { - nm_assert (nargs == -1); - n = NM_PTRARRAY_LEN (args); - } else - n = (gsize) nargs; + if (nargs < 0) { + nm_assert(nargs == -1); + n = NM_PTRARRAY_LEN(args); + } else + n = (gsize) nargs; - for (i = 0; i < n; i++) { - const char *candidate = args[i]; + for (i = 0; i < n; i++) { + const char *candidate = args[i]; - if (!candidate) - continue; - if ( prefix - && !matches (prefix, candidate)) - continue; + if (!candidate) + continue; + if (prefix && !matches(prefix, candidate)) + continue; - g_print ("%s\n", candidate); - } + g_print("%s\n", candidate); + } } /** @@ -1419,10 +1423,9 @@ nmc_complete_strv (const char *prefix, gssize nargs, const char *const*args) * Prints all the matching possible boolean values for completion. */ void -nmc_complete_bool (const char *prefix) +nmc_complete_bool(const char *prefix) { - nmc_complete_strings (prefix, "true", "yes", "on", - "false", "no", "off"); + nmc_complete_strings(prefix, "true", "yes", "on", "false", "no", "off"); } /** @@ -1432,68 +1435,68 @@ nmc_complete_bool (const char *prefix) * Returns a simplified message for some errors hard to understand. */ const char * -nmc_error_get_simple_message (GError *error) +nmc_error_get_simple_message(GError *error) { - /* Return a clear message instead of the obscure D-Bus policy error */ - if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED)) - return _("access denied"); - if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) - return _("NetworkManager is not running"); - else - return error->message; + /* Return a clear message instead of the obscure D-Bus policy error */ + if (g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED)) + return _("access denied"); + if (g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) + return _("NetworkManager is not running"); + else + return error->message; } GVariant * -nmc_dbus_call_sync (NmCli *nmc, - const char *object_path, - const char *interface_name, - const char *method_name, - GVariant *parameters, - const GVariantType *reply_type, - GError **error) +nmc_dbus_call_sync(NmCli * nmc, + const char * object_path, + const char * interface_name, + const char * method_name, + GVariant * parameters, + const GVariantType *reply_type, + GError ** error) { - gs_unref_object GDBusConnection *connection = NULL; - gs_free_error GError *local = NULL; - GVariant *result; - - if (nmc->timeout == -1) - nmc->timeout = 90; - - connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &local); - if (!connection) { - g_set_error (error, - NMCLI_ERROR, - NMC_RESULT_ERROR_UNKNOWN, - _("Error: error connecting to system bus: %s"), - local->message); - return NULL; - } - - result = g_dbus_connection_call_sync (connection, - "org.freedesktop.NetworkManager", - object_path, - interface_name, - method_name, - parameters, - reply_type, - G_DBUS_CALL_FLAGS_NONE, - nmc->timeout * 1000, - NULL, - error); - - if (error && *error) - g_dbus_error_strip_remote_error (*error); - - return result; + gs_unref_object GDBusConnection *connection = NULL; + gs_free_error GError *local = NULL; + GVariant * result; + + if (nmc->timeout == -1) + nmc->timeout = 90; + + connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &local); + if (!connection) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_UNKNOWN, + _("Error: error connecting to system bus: %s"), + local->message); + return NULL; + } + + result = g_dbus_connection_call_sync(connection, + "org.freedesktop.NetworkManager", + object_path, + interface_name, + method_name, + parameters, + reply_type, + G_DBUS_CALL_FLAGS_NONE, + nmc->timeout * 1000, + NULL, + error); + + if (error && *error) + g_dbus_error_strip_remote_error(*error); + + return result; } /*****************************************************************************/ -NM_UTILS_LOOKUP_STR_DEFINE (nm_connectivity_to_string, NMConnectivityState, - NM_UTILS_LOOKUP_DEFAULT (N_("unknown")), - NM_UTILS_LOOKUP_ITEM (NM_CONNECTIVITY_NONE, N_("none")), - NM_UTILS_LOOKUP_ITEM (NM_CONNECTIVITY_PORTAL, N_("portal")), - NM_UTILS_LOOKUP_ITEM (NM_CONNECTIVITY_LIMITED, N_("limited")), - NM_UTILS_LOOKUP_ITEM (NM_CONNECTIVITY_FULL, N_("full")), - NM_UTILS_LOOKUP_ITEM_IGNORE (NM_CONNECTIVITY_UNKNOWN), -); +NM_UTILS_LOOKUP_STR_DEFINE(nm_connectivity_to_string, + NMConnectivityState, + NM_UTILS_LOOKUP_DEFAULT(N_("unknown")), + NM_UTILS_LOOKUP_ITEM(NM_CONNECTIVITY_NONE, N_("none")), + NM_UTILS_LOOKUP_ITEM(NM_CONNECTIVITY_PORTAL, N_("portal")), + NM_UTILS_LOOKUP_ITEM(NM_CONNECTIVITY_LIMITED, N_("limited")), + NM_UTILS_LOOKUP_ITEM(NM_CONNECTIVITY_FULL, N_("full")), + NM_UTILS_LOOKUP_ITEM_IGNORE(NM_CONNECTIVITY_UNKNOWN), ); diff --git a/clients/cli/common.h b/clients/cli/common.h index 243a209..2c7339f 100644 --- a/clients/cli/common.h +++ b/clients/cli/common.h @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2012 - 2014 Red Hat, Inc. */ @@ -9,81 +9,77 @@ #include "nmcli.h" #include "nm-secret-agent-simple.h" - -gboolean print_ip_config (NMIPConfig *cfg, - int addr_family, - const NmcConfig *nmc_config, - const char *one_field); - -gboolean print_dhcp_config (NMDhcpConfig *dhcp, - int addr_family, - const NmcConfig *nmc_config, - const char *one_field); - -NMConnection *nmc_find_connection (const GPtrArray *connections, - const char *filter_type, - const char *filter_val, - GPtrArray **out_result, - gboolean complete); - -NMActiveConnection *nmc_find_active_connection (const GPtrArray *active_cons, - const char *filter_type, - const char *filter_val, - GPtrArray **out_result, - gboolean complete); - -void nmc_secrets_requested (NMSecretAgentSimple *agent, - const char *request_id, - const char *title, - const char *msg, - GPtrArray *secrets, - gpointer user_data); - -char *nmc_unique_connection_name (const GPtrArray *connections, - const char *try_name); - -void nmc_cleanup_readline (void); -char *nmc_readline (const NmcConfig *nmc_config, - const char *prompt_fmt, - ...) G_GNUC_PRINTF (2, 3); -char *nmc_readline_echo (const NmcConfig *nmc_config, - gboolean echo_on, - const char *prompt_fmt, - ...) G_GNUC_PRINTF (3, 4); -NmcCompEntryFunc nmc_rl_compentry_func_wrap (const char *const*values); -char *nmc_rl_gen_func_basic (const char *text, int state, const char *const*words); -char *nmc_rl_gen_func_ifnames (const char *text, int state); -gboolean nmc_get_in_readline (void); -void nmc_set_in_readline (gboolean in_readline); +gboolean print_ip_config(NMIPConfig * cfg, + int addr_family, + const NmcConfig *nmc_config, + const char * one_field); + +gboolean print_dhcp_config(NMDhcpConfig * dhcp, + int addr_family, + const NmcConfig *nmc_config, + const char * one_field); + +NMConnection *nmc_find_connection(const GPtrArray *connections, + const char * filter_type, + const char * filter_val, + GPtrArray ** out_result, + gboolean complete); + +NMActiveConnection *nmc_find_active_connection(const GPtrArray *active_cons, + const char * filter_type, + const char * filter_val, + GPtrArray ** out_result, + gboolean complete); + +void nmc_secrets_requested(NMSecretAgentSimple *agent, + const char * request_id, + const char * title, + const char * msg, + GPtrArray * secrets, + gpointer user_data); + +char *nmc_unique_connection_name(const GPtrArray *connections, const char *try_name); + +void nmc_cleanup_readline(void); +char *nmc_readline(const NmcConfig *nmc_config, const char *prompt_fmt, ...) G_GNUC_PRINTF(2, 3); +char *nmc_readline_echo(const NmcConfig *nmc_config, gboolean echo_on, const char *prompt_fmt, ...) + G_GNUC_PRINTF(3, 4); +NmcCompEntryFunc nmc_rl_compentry_func_wrap(const char *const *values); +char * nmc_rl_gen_func_basic(const char *text, int state, const char *const *words); +char * nmc_rl_gen_func_ifnames(const char *text, int state); +gboolean nmc_get_in_readline(void); +void nmc_set_in_readline(gboolean in_readline); /* for pre-filling a string to readline prompt */ extern char *nmc_rl_pre_input_deftext; -int nmc_rl_set_deftext (void); +int nmc_rl_set_deftext(void); -char *nmc_parse_lldp_capabilities (guint value); +char *nmc_parse_lldp_capabilities(guint value); -void nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, const char *const*argv); +void +nmc_do_cmd(NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, const char *const *argv); -void nmc_complete_strv (const char *prefix, gssize nargs, const char *const*args); +void nmc_complete_strv(const char *prefix, gssize nargs, const char *const *args); -#define nmc_complete_strings(prefix, ...) nmc_complete_strv ((prefix), NM_NARG (__VA_ARGS__), (const char *const[]) { __VA_ARGS__ }) +#define nmc_complete_strings(prefix, ...) \ + nmc_complete_strv((prefix), NM_NARG(__VA_ARGS__), (const char *const[]){__VA_ARGS__}) -void nmc_complete_bool (const char *prefix); +void nmc_complete_bool(const char *prefix); -const char *nmc_error_get_simple_message (GError *error); +const char *nmc_error_get_simple_message(GError *error); extern const NmcMetaGenericInfo *const metagen_ip4_config[]; extern const NmcMetaGenericInfo *const metagen_ip6_config[]; extern const NmcMetaGenericInfo *const metagen_dhcp_config[]; -const char *nm_connectivity_to_string (NMConnectivityState connectivity); +const char *nm_connectivity_to_string(NMConnectivityState connectivity); -GVariant *nmc_dbus_call_sync (NmCli *nmc, - const char *object_path, - const char *interface_name, - const char *method_name, - GVariant *parameters, - const GVariantType *reply_type, - GError **error); +GVariant *nmc_dbus_call_sync(NmCli * nmc, + const char * object_path, + const char * interface_name, + const char * method_name, + GVariant * parameters, + const GVariantType *reply_type, + GError ** error); #endif /* NMC_COMMON_H */ diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 3878264..5b8929b 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2010 - 2018 Red Hat, Inc. */ @@ -30,20 +30,25 @@ /*****************************************************************************/ typedef enum { - PROPERTY_INF_FLAG_NONE = 0x0, - PROPERTY_INF_FLAG_DISABLED = 0x1, /* Don't ask due to runtime decision. */ - PROPERTY_INF_FLAG_ENABLED = 0x2, /* Override NM_META_PROPERTY_INF_FLAG_DONT_ASK due to runtime decision. */ - PROPERTY_INF_FLAG_ALL = 0x3, + PROPERTY_INF_FLAG_NONE = 0x0, + PROPERTY_INF_FLAG_DISABLED = 0x1, /* Don't ask due to runtime decision. */ + PROPERTY_INF_FLAG_ENABLED = + 0x2, /* Override NM_META_PROPERTY_INF_FLAG_DONT_ASK due to runtime decision. */ + PROPERTY_INF_FLAG_ALL = 0x3, } PropertyInfFlags; -typedef char *(*CompEntryFunc) (const char *, int); +typedef char *(*CompEntryFunc)(const char *, int); typedef struct _OptionInfo { - const NMMetaSettingInfoEditor *setting_info; - const char *property; - const char *option; - gboolean (*check_and_set)(NmCli *nmc, NMConnection *connection, const struct _OptionInfo *option, const char *value, GError **error); - CompEntryFunc generator_func; + const NMMetaSettingInfoEditor *setting_info; + const char * property; + const char * option; + gboolean (*check_and_set)(NmCli * nmc, + NMConnection * connection, + const struct _OptionInfo *option, + const char * value, + GError ** error); + CompEntryFunc generator_func; } OptionInfo; /* define some prompts for connection editor */ @@ -53,76 +58,78 @@ typedef struct _OptionInfo { /* define some other prompts */ -#define PROMPT_CONNECTION _("Connection (name, UUID, or path): ") -#define PROMPT_VPN_CONNECTION _("VPN connection (name, UUID, or path): ") -#define PROMPT_CONNECTIONS _("Connection(s) (name, UUID, or path): ") +#define PROMPT_CONNECTION _("Connection (name, UUID, or path): ") +#define PROMPT_VPN_CONNECTION _("VPN connection (name, UUID, or path): ") +#define PROMPT_CONNECTIONS _("Connection(s) (name, UUID, or path): ") #define PROMPT_ACTIVE_CONNECTIONS _("Connection(s) (name, UUID, path or apath): ") #define BASE_PROMPT "nmcli> " /*****************************************************************************/ -static -NM_UTILS_LOOKUP_STR_DEFINE (active_connection_state_to_string, NMActiveConnectionState, - NM_UTILS_LOOKUP_DEFAULT (N_("unknown")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_ACTIVATING, N_("activating")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_ACTIVATED, N_("activated")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_DEACTIVATING, N_("deactivating")), - NM_UTILS_LOOKUP_ITEM (NM_ACTIVE_CONNECTION_STATE_DEACTIVATED, N_("deactivated")), - NM_UTILS_LOOKUP_ITEM_IGNORE (NM_ACTIVE_CONNECTION_STATE_UNKNOWN), -); - -static -NM_UTILS_LOOKUP_STR_DEFINE (vpn_connection_state_to_string, NMVpnConnectionState, - NM_UTILS_LOOKUP_DEFAULT (N_("unknown")), - NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_PREPARE, N_("VPN connecting (prepare)")), - NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_NEED_AUTH, N_("VPN connecting (need authentication)")), - NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_CONNECT, N_("VPN connecting")), - NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_IP_CONFIG_GET, N_("VPN connecting (getting IP configuration)")), - NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_ACTIVATED, N_("VPN connected")), - NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_FAILED, N_("VPN connection failed")), - NM_UTILS_LOOKUP_ITEM (NM_VPN_CONNECTION_STATE_DISCONNECTED, N_("VPN disconnected")), - NM_UTILS_LOOKUP_ITEM_IGNORE (NM_VPN_CONNECTION_STATE_UNKNOWN), -); +static NM_UTILS_LOOKUP_STR_DEFINE( + active_connection_state_to_string, + NMActiveConnectionState, + NM_UTILS_LOOKUP_DEFAULT(N_("unknown")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_ACTIVATING, N_("activating")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_ACTIVATED, N_("activated")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_DEACTIVATING, N_("deactivating")), + NM_UTILS_LOOKUP_ITEM(NM_ACTIVE_CONNECTION_STATE_DEACTIVATED, N_("deactivated")), + NM_UTILS_LOOKUP_ITEM_IGNORE(NM_ACTIVE_CONNECTION_STATE_UNKNOWN), ); + +static NM_UTILS_LOOKUP_STR_DEFINE( + vpn_connection_state_to_string, + NMVpnConnectionState, + NM_UTILS_LOOKUP_DEFAULT(N_("unknown")), + NM_UTILS_LOOKUP_ITEM(NM_VPN_CONNECTION_STATE_PREPARE, N_("VPN connecting (prepare)")), + NM_UTILS_LOOKUP_ITEM(NM_VPN_CONNECTION_STATE_NEED_AUTH, + N_("VPN connecting (need authentication)")), + NM_UTILS_LOOKUP_ITEM(NM_VPN_CONNECTION_STATE_CONNECT, N_("VPN connecting")), + NM_UTILS_LOOKUP_ITEM(NM_VPN_CONNECTION_STATE_IP_CONFIG_GET, + N_("VPN connecting (getting IP configuration)")), + NM_UTILS_LOOKUP_ITEM(NM_VPN_CONNECTION_STATE_ACTIVATED, N_("VPN connected")), + NM_UTILS_LOOKUP_ITEM(NM_VPN_CONNECTION_STATE_FAILED, N_("VPN connection failed")), + NM_UTILS_LOOKUP_ITEM(NM_VPN_CONNECTION_STATE_DISCONNECTED, N_("VPN disconnected")), + NM_UTILS_LOOKUP_ITEM_IGNORE(NM_VPN_CONNECTION_STATE_UNKNOWN), ); /*****************************************************************************/ typedef struct { - NmCli *nmc; - char *orig_id; - char *orig_uuid; - char *new_id; + NmCli *nmc; + char * orig_id; + char * orig_uuid; + char * new_id; } AddConnectionInfo; static AddConnectionInfo * -_add_connection_info_new (NmCli *nmc, - NMConnection *orig_connection, - NMConnection *new_connection) +_add_connection_info_new(NmCli *nmc, NMConnection *orig_connection, NMConnection *new_connection) { - AddConnectionInfo *info; + AddConnectionInfo *info; - info = g_slice_new (AddConnectionInfo); - *info = (AddConnectionInfo) { - .nmc = nmc, - .orig_id = orig_connection ? g_strdup (nm_connection_get_id (orig_connection)) : NULL, - .orig_uuid = orig_connection ? g_strdup (nm_connection_get_uuid (orig_connection)) : NULL, - .new_id = g_strdup (nm_connection_get_id (new_connection)), - }; - return info; + info = g_slice_new(AddConnectionInfo); + *info = (AddConnectionInfo){ + .nmc = nmc, + .orig_id = orig_connection ? g_strdup(nm_connection_get_id(orig_connection)) : NULL, + .orig_uuid = orig_connection ? g_strdup(nm_connection_get_uuid(orig_connection)) : NULL, + .new_id = g_strdup(nm_connection_get_id(new_connection)), + }; + return info; } static void -_add_connection_info_free (AddConnectionInfo *info) +_add_connection_info_free(AddConnectionInfo *info) { - g_free (info->orig_id); - g_free (info->orig_uuid); - g_free (info->new_id); - nm_g_slice_free (info); + g_free(info->orig_id); + g_free(info->orig_uuid); + g_free(info->new_id); + nm_g_slice_free(info); } -NM_AUTO_DEFINE_FCN (AddConnectionInfo *, _nm_auto_free_add_connection_info, _add_connection_info_free); +NM_AUTO_DEFINE_FCN(AddConnectionInfo *, + _nm_auto_free_add_connection_info, + _add_connection_info_free); -#define nm_auto_free_add_connection_info nm_auto (_nm_auto_free_add_connection_info) +#define nm_auto_free_add_connection_info nm_auto(_nm_auto_free_add_connection_info) /*****************************************************************************/ @@ -130,136 +137,142 @@ NM_AUTO_DEFINE_FCN (AddConnectionInfo *, _nm_auto_free_add_connection_info, _add * prefers an alias instead of the settings name when in pretty print mode. * That is so that we print "wifi" instead of "802-11-wireless" in "nmcli c". */ static const char * -connection_type_to_display (const char *type, NMMetaAccessorGetType get_type) +connection_type_to_display(const char *type, NMMetaAccessorGetType get_type) { - const NMMetaSettingInfoEditor *editor; - int i; + const NMMetaSettingInfoEditor *editor; + int i; - nm_assert (NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE)); + nm_assert( + NM_IN_SET(get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE)); - if (!type) - return NULL; + if (!type) + return NULL; - if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) - return type; + if (get_type != NM_META_ACCESSOR_GET_TYPE_PRETTY) + return type; - for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { - editor = &nm_meta_setting_infos_editor[i]; - if (nm_streq (type, editor->general->setting_name)) - return editor->alias ?: type; - } - return type; + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + editor = &nm_meta_setting_infos_editor[i]; + if (nm_streq(type, editor->general->setting_name)) + return editor->alias ?: type; + } + return type; } static int -active_connection_get_state_ord (NMActiveConnection *active) -{ - /* returns an integer related to @active's state, that can be used for sorting - * active connections based on their activation state. */ - if (!active) - return -2; - - switch (nm_active_connection_get_state (active)) { - case NM_ACTIVE_CONNECTION_STATE_UNKNOWN: return 0; - case NM_ACTIVE_CONNECTION_STATE_DEACTIVATED: return 1; - case NM_ACTIVE_CONNECTION_STATE_DEACTIVATING: return 2; - case NM_ACTIVE_CONNECTION_STATE_ACTIVATING: return 3; - case NM_ACTIVE_CONNECTION_STATE_ACTIVATED: return 4; - } - return -1; +active_connection_get_state_ord(NMActiveConnection *active) +{ + /* returns an integer related to @active's state, that can be used for sorting + * active connections based on their activation state. */ + if (!active) + return -2; + + switch (nm_active_connection_get_state(active)) { + case NM_ACTIVE_CONNECTION_STATE_UNKNOWN: + return 0; + case NM_ACTIVE_CONNECTION_STATE_DEACTIVATED: + return 1; + case NM_ACTIVE_CONNECTION_STATE_DEACTIVATING: + return 2; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATING: + return 3; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATED: + return 4; + } + return -1; } int -nmc_active_connection_cmp (NMActiveConnection *ac_a, NMActiveConnection *ac_b) -{ - NMSettingIPConfig *s_ip; - NMRemoteConnection *conn; - NMIPConfig *da_ip; - NMIPConfig *db_ip; - int da_num_addrs; - int db_num_addrs; - int cmp = 0; - - /* Non-active sort last. */ - NM_CMP_SELF (ac_a, ac_b); - NM_CMP_DIRECT (active_connection_get_state_ord (ac_b), - active_connection_get_state_ord (ac_a)); - - /* Shared connections (likely hotspots) go on the top if possible */ - conn = nm_active_connection_get_connection (ac_a); - s_ip = conn ? nm_connection_get_setting_ip6_config (NM_CONNECTION (conn)) : NULL; - if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) - cmp++; - conn = nm_active_connection_get_connection (ac_b); - s_ip = conn ? nm_connection_get_setting_ip6_config (NM_CONNECTION (conn)) : NULL; - if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) - cmp--; - NM_CMP_RETURN (cmp); - - conn = nm_active_connection_get_connection (ac_a); - s_ip = conn ? nm_connection_get_setting_ip4_config (NM_CONNECTION (conn)) : NULL; - if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) - cmp++; - conn = nm_active_connection_get_connection (ac_b); - s_ip = conn ? nm_connection_get_setting_ip4_config (NM_CONNECTION (conn)) : NULL; - if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) - cmp--; - NM_CMP_RETURN (cmp); - - /* VPNs go next */ - NM_CMP_DIRECT (!!nm_active_connection_get_vpn (ac_a), - !!nm_active_connection_get_vpn (ac_b)); - - /* Default devices are prioritized */ - NM_CMP_DIRECT (nm_active_connection_get_default (ac_a), - nm_active_connection_get_default (ac_b)); - - /* Default IPv6 devices are prioritized */ - NM_CMP_DIRECT (nm_active_connection_get_default6 (ac_a), - nm_active_connection_get_default6 (ac_b)); - - /* Sort by number of addresses. */ - da_ip = nm_active_connection_get_ip4_config (ac_a); - da_num_addrs = da_ip ? nm_ip_config_get_addresses (da_ip)->len : 0; - db_ip = nm_active_connection_get_ip4_config (ac_b); - db_num_addrs = db_ip ? nm_ip_config_get_addresses (db_ip)->len : 0; - - da_ip = nm_active_connection_get_ip6_config (ac_a); - da_num_addrs += da_ip ? nm_ip_config_get_addresses (da_ip)->len : 0; - db_ip = nm_active_connection_get_ip6_config (ac_b); - db_num_addrs += db_ip ? nm_ip_config_get_addresses (db_ip)->len : 0; - - NM_CMP_DIRECT (da_num_addrs, db_num_addrs); - - return 0; +nmc_active_connection_cmp(NMActiveConnection *ac_a, NMActiveConnection *ac_b) +{ + NMSettingIPConfig * s_ip; + NMRemoteConnection *conn; + NMIPConfig * da_ip; + NMIPConfig * db_ip; + int da_num_addrs; + int db_num_addrs; + int cmp = 0; + + /* Non-active sort last. */ + NM_CMP_SELF(ac_a, ac_b); + NM_CMP_DIRECT(active_connection_get_state_ord(ac_b), active_connection_get_state_ord(ac_a)); + + /* Shared connections (likely hotspots) go on the top if possible */ + conn = nm_active_connection_get_connection(ac_a); + s_ip = conn ? nm_connection_get_setting_ip6_config(NM_CONNECTION(conn)) : NULL; + if (s_ip + && strcmp(nm_setting_ip_config_get_method(s_ip), NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) + cmp++; + conn = nm_active_connection_get_connection(ac_b); + s_ip = conn ? nm_connection_get_setting_ip6_config(NM_CONNECTION(conn)) : NULL; + if (s_ip + && strcmp(nm_setting_ip_config_get_method(s_ip), NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0) + cmp--; + NM_CMP_RETURN(cmp); + + conn = nm_active_connection_get_connection(ac_a); + s_ip = conn ? nm_connection_get_setting_ip4_config(NM_CONNECTION(conn)) : NULL; + if (s_ip + && strcmp(nm_setting_ip_config_get_method(s_ip), NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) + cmp++; + conn = nm_active_connection_get_connection(ac_b); + s_ip = conn ? nm_connection_get_setting_ip4_config(NM_CONNECTION(conn)) : NULL; + if (s_ip + && strcmp(nm_setting_ip_config_get_method(s_ip), NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) + cmp--; + NM_CMP_RETURN(cmp); + + /* VPNs go next */ + NM_CMP_DIRECT(!!nm_active_connection_get_vpn(ac_a), !!nm_active_connection_get_vpn(ac_b)); + + /* Default devices are prioritized */ + NM_CMP_DIRECT(nm_active_connection_get_default(ac_a), nm_active_connection_get_default(ac_b)); + + /* Default IPv6 devices are prioritized */ + NM_CMP_DIRECT(nm_active_connection_get_default6(ac_a), nm_active_connection_get_default6(ac_b)); + + /* Sort by number of addresses. */ + da_ip = nm_active_connection_get_ip4_config(ac_a); + da_num_addrs = da_ip ? nm_ip_config_get_addresses(da_ip)->len : 0; + db_ip = nm_active_connection_get_ip4_config(ac_b); + db_num_addrs = db_ip ? nm_ip_config_get_addresses(db_ip)->len : 0; + + da_ip = nm_active_connection_get_ip6_config(ac_a); + da_num_addrs += da_ip ? nm_ip_config_get_addresses(da_ip)->len : 0; + db_ip = nm_active_connection_get_ip6_config(ac_b); + db_num_addrs += db_ip ? nm_ip_config_get_addresses(db_ip)->len : 0; + + NM_CMP_DIRECT(da_num_addrs, db_num_addrs); + + return 0; } static char * -get_ac_device_string (NMActiveConnection *active) +get_ac_device_string(NMActiveConnection *active) { - GString *dev_str; - const GPtrArray *devices; - guint i; + GString * dev_str; + const GPtrArray *devices; + guint i; - if (!active) - return NULL; + if (!active) + return NULL; - /* Get devices of the active connection */ - dev_str = g_string_new (NULL); - devices = nm_active_connection_get_devices (active); - for (i = 0; i < devices->len; i++) { - NMDevice *device = g_ptr_array_index (devices, i); - const char *dev_iface = nm_device_get_iface (device); + /* Get devices of the active connection */ + dev_str = g_string_new(NULL); + devices = nm_active_connection_get_devices(active); + for (i = 0; i < devices->len; i++) { + NMDevice * device = g_ptr_array_index(devices, i); + const char *dev_iface = nm_device_get_iface(device); - if (dev_iface) { - g_string_append (dev_str, dev_iface); - g_string_append_c (dev_str, ','); - } - } - if (dev_str->len > 0) - g_string_truncate (dev_str, dev_str->len - 1); /* Cut off last ',' */ + if (dev_iface) { + g_string_append(dev_str, dev_iface); + g_string_append_c(dev_str, ','); + } + } + if (dev_str->len > 0) + g_string_truncate(dev_str, dev_str->len - 1); /* Cut off last ',' */ - return g_string_free (dev_str, FALSE); + return g_string_free(dev_str, FALSE); } /*****************************************************************************/ @@ -268,23 +281,23 @@ get_ac_device_string (NMActiveConnection *active) * and in gnome-control-center as well. It could probably be shared somehow. */ static const char * -get_vpn_connection_type (NMConnection *connection) +get_vpn_connection_type(NMConnection *connection) { - NMSettingVpn *s_vpn; - const char *type, *p; + NMSettingVpn *s_vpn; + const char * type, *p; - s_vpn = nm_connection_get_setting_vpn (connection); - if (!s_vpn) - return NULL; + s_vpn = nm_connection_get_setting_vpn(connection); + if (!s_vpn) + return NULL; - /* The service type is in form of "org.freedesktop.NetworkManager.vpnc". - * Extract end part after last dot, e.g. "vpnc" - */ - type = nm_setting_vpn_get_service_type (nm_connection_get_setting_vpn (connection)); - if (!type) - return NULL; - p = strrchr (type, '.'); - return p ? p + 1 : type; + /* The service type is in form of "org.freedesktop.NetworkManager.vpnc". + * Extract end part after last dot, e.g. "vpnc" + */ + type = nm_setting_vpn_get_service_type(nm_connection_get_setting_vpn(connection)); + if (!type) + return NULL; + p = strrchr(type, '.'); + return p ? p + 1 : type; } /* VPN parameters can be found at: @@ -296,587 +309,589 @@ get_vpn_connection_type (NMConnection *connection) * See also 'properties' directory in these plugins. */ static const char * -find_vpn_gateway_key (const char *vpn_type) -{ - if (vpn_type) { - if (nm_streq (vpn_type, "openvpn")) return "remote"; - if (nm_streq (vpn_type, "vpnc")) return "IPSec gateway"; - if (nm_streq (vpn_type, "pptp")) return "gateway"; - if (nm_streq (vpn_type, "openconnect")) return "gateway"; - if (nm_streq (vpn_type, "openswan")) return "right"; - if (nm_streq (vpn_type, "libreswan")) return "right"; - if (nm_streq (vpn_type, "ssh")) return "remote"; - if (nm_streq (vpn_type, "l2tp")) return "gateway"; - } - return NULL; +find_vpn_gateway_key(const char *vpn_type) +{ + if (vpn_type) { + if (nm_streq(vpn_type, "openvpn")) + return "remote"; + if (nm_streq(vpn_type, "vpnc")) + return "IPSec gateway"; + if (nm_streq(vpn_type, "pptp")) + return "gateway"; + if (nm_streq(vpn_type, "openconnect")) + return "gateway"; + if (nm_streq(vpn_type, "openswan")) + return "right"; + if (nm_streq(vpn_type, "libreswan")) + return "right"; + if (nm_streq(vpn_type, "ssh")) + return "remote"; + if (nm_streq(vpn_type, "l2tp")) + return "gateway"; + } + return NULL; } static const char * -find_vpn_username_key (const char *vpn_type) -{ - if (vpn_type) { - if (nm_streq (vpn_type, "openvpn")) return "username"; - if (nm_streq (vpn_type, "vpnc")) return "Xauth username"; - if (nm_streq (vpn_type, "pptp")) return "user"; - if (nm_streq (vpn_type, "openconnect")) return "username"; - if (nm_streq (vpn_type, "openswan")) return "leftxauthusername"; - if (nm_streq (vpn_type, "libreswan")) return "leftxauthusername"; - if (nm_streq (vpn_type, "l2tp")) return "user"; - } - return NULL; -} - -enum VpnDataItem { - VPN_DATA_ITEM_GATEWAY, - VPN_DATA_ITEM_USERNAME -}; +find_vpn_username_key(const char *vpn_type) +{ + if (vpn_type) { + if (nm_streq(vpn_type, "openvpn")) + return "username"; + if (nm_streq(vpn_type, "vpnc")) + return "Xauth username"; + if (nm_streq(vpn_type, "pptp")) + return "user"; + if (nm_streq(vpn_type, "openconnect")) + return "username"; + if (nm_streq(vpn_type, "openswan")) + return "leftxauthusername"; + if (nm_streq(vpn_type, "libreswan")) + return "leftxauthusername"; + if (nm_streq(vpn_type, "l2tp")) + return "user"; + } + return NULL; +} + +enum VpnDataItem { VPN_DATA_ITEM_GATEWAY, VPN_DATA_ITEM_USERNAME }; static const char * -get_vpn_data_item (NMConnection *connection, enum VpnDataItem vpn_data_item) +get_vpn_data_item(NMConnection *connection, enum VpnDataItem vpn_data_item) { - const char *type; - const char *key = NULL; + const char *type; + const char *key = NULL; - type = get_vpn_connection_type (connection); + type = get_vpn_connection_type(connection); - switch (vpn_data_item) { - case VPN_DATA_ITEM_GATEWAY: - key = find_vpn_gateway_key (type); - break; - case VPN_DATA_ITEM_USERNAME: - key = find_vpn_username_key (type); - break; - default: - break; - } + switch (vpn_data_item) { + case VPN_DATA_ITEM_GATEWAY: + key = find_vpn_gateway_key(type); + break; + case VPN_DATA_ITEM_USERNAME: + key = find_vpn_username_key(type); + break; + default: + break; + } - if (!key) - return NULL; - return nm_setting_vpn_get_data_item (nm_connection_get_setting_vpn (connection), key); + if (!key) + return NULL; + return nm_setting_vpn_get_data_item(nm_connection_get_setting_vpn(connection), key); } /*****************************************************************************/ typedef struct { - NMConnection *connection; - NMActiveConnection *primary_active; - GPtrArray *all_active; - bool show_active_fields; + NMConnection * connection; + NMActiveConnection *primary_active; + GPtrArray * all_active; + bool show_active_fields; } MetagenConShowRowData; static MetagenConShowRowData * -_metagen_con_show_row_data_new_for_connection (NMRemoteConnection *connection, gboolean show_active_fields) +_metagen_con_show_row_data_new_for_connection(NMRemoteConnection *connection, + gboolean show_active_fields) { - MetagenConShowRowData *row_data; + MetagenConShowRowData *row_data; - row_data = g_slice_new0 (MetagenConShowRowData); - row_data->connection = g_object_ref (NM_CONNECTION (connection)); - row_data->show_active_fields = show_active_fields; - return row_data; + row_data = g_slice_new0(MetagenConShowRowData); + row_data->connection = g_object_ref(NM_CONNECTION(connection)); + row_data->show_active_fields = show_active_fields; + return row_data; } static MetagenConShowRowData * -_metagen_con_show_row_data_new_for_active_connection (NMRemoteConnection *connection, NMActiveConnection *active, gboolean show_active_fields) +_metagen_con_show_row_data_new_for_active_connection(NMRemoteConnection *connection, + NMActiveConnection *active, + gboolean show_active_fields) { - MetagenConShowRowData *row_data; + MetagenConShowRowData *row_data; - row_data = g_slice_new0 (MetagenConShowRowData); - if (connection) - row_data->connection = g_object_ref (NM_CONNECTION (connection)); - row_data->primary_active = g_object_ref (active); - row_data->show_active_fields = show_active_fields; - return row_data; + row_data = g_slice_new0(MetagenConShowRowData); + if (connection) + row_data->connection = g_object_ref(NM_CONNECTION(connection)); + row_data->primary_active = g_object_ref(active); + row_data->show_active_fields = show_active_fields; + return row_data; } static void -_metagen_con_show_row_data_add_active_connection (MetagenConShowRowData *row_data, NMActiveConnection *active) +_metagen_con_show_row_data_add_active_connection(MetagenConShowRowData *row_data, + NMActiveConnection * active) { - if (!row_data->primary_active) { - row_data->primary_active = g_object_ref (active); - return; - } - if (!row_data->all_active) { - row_data->all_active = g_ptr_array_new_with_free_func (g_object_unref); - g_ptr_array_add (row_data->all_active, g_object_ref (row_data->primary_active)); - } - g_ptr_array_add (row_data->all_active, g_object_ref (active)); + if (!row_data->primary_active) { + row_data->primary_active = g_object_ref(active); + return; + } + if (!row_data->all_active) { + row_data->all_active = g_ptr_array_new_with_free_func(g_object_unref); + g_ptr_array_add(row_data->all_active, g_object_ref(row_data->primary_active)); + } + g_ptr_array_add(row_data->all_active, g_object_ref(active)); } static void -_metagen_con_show_row_data_init_primary_active (MetagenConShowRowData *row_data) +_metagen_con_show_row_data_init_primary_active(MetagenConShowRowData *row_data) { - NMActiveConnection *ac, *best_ac; - guint i; + NMActiveConnection *ac, *best_ac; + guint i; - if (!row_data->all_active) - return; + if (!row_data->all_active) + return; - best_ac = row_data->all_active->pdata[0]; - for (i = 1; i < row_data->all_active->len; i++) { - ac = row_data->all_active->pdata[i]; + best_ac = row_data->all_active->pdata[0]; + for (i = 1; i < row_data->all_active->len; i++) { + ac = row_data->all_active->pdata[i]; - if (active_connection_get_state_ord (ac) > active_connection_get_state_ord (best_ac)) - best_ac = ac; - } + if (active_connection_get_state_ord(ac) > active_connection_get_state_ord(best_ac)) + best_ac = ac; + } - if (row_data->primary_active != best_ac) { - g_object_unref (row_data->primary_active); - row_data->primary_active = g_object_ref (best_ac); - } - nm_clear_pointer (&row_data->all_active, g_ptr_array_unref); + if (row_data->primary_active != best_ac) { + g_object_unref(row_data->primary_active); + row_data->primary_active = g_object_ref(best_ac); + } + nm_clear_pointer(&row_data->all_active, g_ptr_array_unref); } static void -_metagen_con_show_row_data_destroy (gpointer data) +_metagen_con_show_row_data_destroy(gpointer data) { - MetagenConShowRowData *row_data = data; + MetagenConShowRowData *row_data = data; - if (!row_data) - return; + if (!row_data) + return; - g_clear_object (&row_data->connection); - g_clear_object (&row_data->primary_active); - nm_clear_pointer (&row_data->all_active, g_ptr_array_unref); - g_slice_free (MetagenConShowRowData, row_data); + g_clear_object(&row_data->connection); + g_clear_object(&row_data->primary_active); + nm_clear_pointer(&row_data->all_active, g_ptr_array_unref); + g_slice_free(MetagenConShowRowData, row_data); } static const char * -_con_show_fcn_get_id (NMConnection *c, NMActiveConnection *ac) +_con_show_fcn_get_id(NMConnection *c, NMActiveConnection *ac) { - NMSettingConnection *s_con = NULL; - const char *s; + NMSettingConnection *s_con = NULL; + const char * s; - if (c) - s_con = nm_connection_get_setting_connection (c); + if (c) + s_con = nm_connection_get_setting_connection(c); - s = s_con ? nm_setting_connection_get_id (s_con) : NULL; - if (!s && ac) { - /* note that if we have no s_con, that usually means that the user has no permissions - * to see the connection. We still fall to get the ID from the active-connection, - * which exposes it despite the user having no permissions. - * - * That might be unexpected, because the user is shown an ID, which he later - * is unable to resolve in other operations. */ - s = nm_active_connection_get_id (ac); - } - return s; + s = s_con ? nm_setting_connection_get_id(s_con) : NULL; + if (!s && ac) { + /* note that if we have no s_con, that usually means that the user has no permissions + * to see the connection. We still fall to get the ID from the active-connection, + * which exposes it despite the user having no permissions. + * + * That might be unexpected, because the user is shown an ID, which he later + * is unable to resolve in other operations. */ + s = nm_active_connection_get_id(ac); + } + return s; } static const char * -_con_show_fcn_get_type (NMConnection *c, NMActiveConnection *ac, NMMetaAccessorGetType get_type) -{ - NMSettingConnection *s_con = NULL; - const char *s; - - if (c) - s_con = nm_connection_get_setting_connection (c); - - s = s_con ? nm_setting_connection_get_connection_type (s_con) : NULL; - if (!s && ac) { - /* see _con_show_fcn_get_id() for why we fallback to get the value - * from @ac. */ - s = nm_active_connection_get_connection_type (ac); - } - return connection_type_to_display (s, get_type); -} - -static gconstpointer -_metagen_con_show_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) -{ - const MetagenConShowRowData *row_data = target; - NMConnection *c = row_data->connection; - NMActiveConnection *ac = row_data->primary_active; - NMSettingConnection *s_con = NULL; - const char *s; - char *s_mut; - - NMC_HANDLE_COLOR (nmc_active_connection_state_to_color (ac)); - - if (c) - s_con = nm_connection_get_setting_connection (c); - - if (!row_data->show_active_fields) { - /* we are not supposed to show any fields of the active connection. - * We only tracked the primary_active to get the coloring right. - * From now on, there is no active connection. */ - ac = NULL; - - /* in this mode, we expect that we are called only with connections that - * have a [connection] setting and a UUID. Otherwise, the connection is - * effectively invisible to the user, and should be hidden. - * - * But in that case, we expect that the caller pre-filtered this row out. - * So assert(). */ - nm_assert (s_con); - nm_assert (nm_setting_connection_get_uuid (s_con)); - } - - nm_assert (NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE)); - - switch (info->info_type) { - case NMC_GENERIC_INFO_TYPE_CON_SHOW_NAME: - return _con_show_fcn_get_id (c, ac); - case NMC_GENERIC_INFO_TYPE_CON_SHOW_UUID: - s = s_con ? nm_setting_connection_get_uuid (s_con) : NULL; - if (!s && ac) { - /* see _con_show_fcn_get_id() for why we fallback to get the value - * from @ac. */ - s = nm_active_connection_get_uuid (ac); - } - return s; - case NMC_GENERIC_INFO_TYPE_CON_SHOW_TYPE: - return _con_show_fcn_get_type (c, ac, get_type); - case NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP: - case NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP_REAL: - if (!s_con) - return NULL; - { - guint64 timestamp; - time_t timestamp_real; - - timestamp = nm_setting_connection_get_timestamp (s_con); - - if (info->info_type == NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP) - return (*out_to_free = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp)); - else { - struct tm localtime_result; - - if (!timestamp) { - if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) - return _("never"); - return "never"; - } - timestamp_real = timestamp; - s_mut = g_malloc0 (128); - strftime (s_mut, 127, "%c", localtime_r (×tamp_real, &localtime_result)); - return (*out_to_free = s_mut); - } - } - case NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT: - if (!s_con) - return NULL; - return nmc_meta_generic_get_bool (nm_setting_connection_get_autoconnect (s_con), get_type); - case NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT_PRIORITY: - if (!s_con) - return NULL; - return (*out_to_free = g_strdup_printf ("%d", nm_setting_connection_get_autoconnect_priority (s_con))); - case NMC_GENERIC_INFO_TYPE_CON_SHOW_READONLY: - if (!s_con) - return NULL; - return nmc_meta_generic_get_bool (nm_setting_connection_get_read_only (s_con), get_type); - case NMC_GENERIC_INFO_TYPE_CON_SHOW_DBUS_PATH: - if (!c) - return NULL; - return nm_connection_get_path (c); - case NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE: - return nmc_meta_generic_get_bool (!!ac, get_type); - case NMC_GENERIC_INFO_TYPE_CON_SHOW_DEVICE: - if (ac) - return (*out_to_free = get_ac_device_string (ac)); - return NULL; - case NMC_GENERIC_INFO_TYPE_CON_SHOW_STATE: - return nmc_meta_generic_get_str_i18n (ac - ? active_connection_state_to_string (nm_active_connection_get_state (ac)) - : NULL, - get_type); - case NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE_PATH: - if (ac) - return nm_object_get_path (NM_OBJECT (ac)); - return NULL; - case NMC_GENERIC_INFO_TYPE_CON_SHOW_SLAVE: - if (!s_con) - return NULL; - return nm_setting_connection_get_slave_type (s_con); - case NMC_GENERIC_INFO_TYPE_CON_SHOW_FILENAME: - if (!NM_IS_REMOTE_CONNECTION (c)) - return NULL; - return nm_remote_connection_get_filename (NM_REMOTE_CONNECTION (c)); - default: - break; - } - - g_return_val_if_reached (NULL); +_con_show_fcn_get_type(NMConnection *c, NMActiveConnection *ac, NMMetaAccessorGetType get_type) +{ + NMSettingConnection *s_con = NULL; + const char * s; + + if (c) + s_con = nm_connection_get_setting_connection(c); + + s = s_con ? nm_setting_connection_get_connection_type(s_con) : NULL; + if (!s && ac) { + /* see _con_show_fcn_get_id() for why we fallback to get the value + * from @ac. */ + s = nm_active_connection_get_connection_type(ac); + } + return connection_type_to_display(s, get_type); +} + +static gconstpointer _metagen_con_show_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +{ + const MetagenConShowRowData *row_data = target; + NMConnection * c = row_data->connection; + NMActiveConnection * ac = row_data->primary_active; + NMSettingConnection * s_con = NULL; + const char * s; + char * s_mut; + + NMC_HANDLE_COLOR(nmc_active_connection_state_to_color(ac)); + + if (c) + s_con = nm_connection_get_setting_connection(c); + + if (!row_data->show_active_fields) { + /* we are not supposed to show any fields of the active connection. + * We only tracked the primary_active to get the coloring right. + * From now on, there is no active connection. */ + ac = NULL; + + /* in this mode, we expect that we are called only with connections that + * have a [connection] setting and a UUID. Otherwise, the connection is + * effectively invisible to the user, and should be hidden. + * + * But in that case, we expect that the caller pre-filtered this row out. + * So assert(). */ + nm_assert(s_con); + nm_assert(nm_setting_connection_get_uuid(s_con)); + } + + nm_assert( + NM_IN_SET(get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE)); + + switch (info->info_type) { + case NMC_GENERIC_INFO_TYPE_CON_SHOW_NAME: + return _con_show_fcn_get_id(c, ac); + case NMC_GENERIC_INFO_TYPE_CON_SHOW_UUID: + s = s_con ? nm_setting_connection_get_uuid(s_con) : NULL; + if (!s && ac) { + /* see _con_show_fcn_get_id() for why we fallback to get the value + * from @ac. */ + s = nm_active_connection_get_uuid(ac); + } + return s; + case NMC_GENERIC_INFO_TYPE_CON_SHOW_TYPE: + return _con_show_fcn_get_type(c, ac, get_type); + case NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP: + case NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP_REAL: + if (!s_con) + return NULL; + { + guint64 timestamp; + time_t timestamp_real; + + timestamp = nm_setting_connection_get_timestamp(s_con); + + if (info->info_type == NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP) + return (*out_to_free = g_strdup_printf("%" G_GUINT64_FORMAT, timestamp)); + else { + struct tm localtime_result; + + if (!timestamp) { + if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY) + return _("never"); + return "never"; + } + timestamp_real = timestamp; + s_mut = g_malloc0(128); + strftime(s_mut, 127, "%c", localtime_r(×tamp_real, &localtime_result)); + return (*out_to_free = s_mut); + } + } + case NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT: + if (!s_con) + return NULL; + return nmc_meta_generic_get_bool(nm_setting_connection_get_autoconnect(s_con), get_type); + case NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT_PRIORITY: + if (!s_con) + return NULL; + return (*out_to_free = + g_strdup_printf("%d", nm_setting_connection_get_autoconnect_priority(s_con))); + case NMC_GENERIC_INFO_TYPE_CON_SHOW_READONLY: + if (!s_con) + return NULL; + return nmc_meta_generic_get_bool(nm_setting_connection_get_read_only(s_con), get_type); + case NMC_GENERIC_INFO_TYPE_CON_SHOW_DBUS_PATH: + if (!c) + return NULL; + return nm_connection_get_path(c); + case NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE: + return nmc_meta_generic_get_bool(!!ac, get_type); + case NMC_GENERIC_INFO_TYPE_CON_SHOW_DEVICE: + if (ac) + return (*out_to_free = get_ac_device_string(ac)); + return NULL; + case NMC_GENERIC_INFO_TYPE_CON_SHOW_STATE: + return nmc_meta_generic_get_str_i18n( + ac ? active_connection_state_to_string(nm_active_connection_get_state(ac)) : NULL, + get_type); + case NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE_PATH: + if (ac) + return nm_object_get_path(NM_OBJECT(ac)); + return NULL; + case NMC_GENERIC_INFO_TYPE_CON_SHOW_SLAVE: + if (!s_con) + return NULL; + return nm_setting_connection_get_slave_type(s_con); + case NMC_GENERIC_INFO_TYPE_CON_SHOW_FILENAME: + if (!NM_IS_REMOTE_CONNECTION(c)) + return NULL; + return nm_remote_connection_get_filename(NM_REMOTE_CONNECTION(c)); + default: + break; + } + + g_return_val_if_reached(NULL); } const NmcMetaGenericInfo *const metagen_con_show[_NMC_GENERIC_INFO_TYPE_CON_SHOW_NUM + 1] = { #define _METAGEN_CON_SHOW(type, name) \ - [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_con_show_get_fcn) - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_NAME, "NAME"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_UUID, "UUID"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_TYPE, "TYPE"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP, "TIMESTAMP"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP_REAL, "TIMESTAMP-REAL"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT, "AUTOCONNECT"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT_PRIORITY, "AUTOCONNECT-PRIORITY"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_READONLY, "READONLY"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_DBUS_PATH, "DBUS-PATH"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE, "ACTIVE"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_DEVICE, "DEVICE"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_STATE, "STATE"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE_PATH, "ACTIVE-PATH"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_SLAVE, "SLAVE"), - _METAGEN_CON_SHOW (NMC_GENERIC_INFO_TYPE_CON_SHOW_FILENAME, "FILENAME"), + [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_con_show_get_fcn) + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_NAME, "NAME"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_UUID, "UUID"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_TYPE, "TYPE"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP, "TIMESTAMP"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP_REAL, "TIMESTAMP-REAL"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT, "AUTOCONNECT"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT_PRIORITY, "AUTOCONNECT-PRIORITY"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_READONLY, "READONLY"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_DBUS_PATH, "DBUS-PATH"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE, "ACTIVE"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_DEVICE, "DEVICE"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_STATE, "STATE"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE_PATH, "ACTIVE-PATH"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_SLAVE, "SLAVE"), + _METAGEN_CON_SHOW(NMC_GENERIC_INFO_TYPE_CON_SHOW_FILENAME, "FILENAME"), }; -#define NMC_FIELDS_CON_SHOW_COMMON "NAME,UUID,TYPE,DEVICE" +#define NMC_FIELDS_CON_SHOW_COMMON "NAME,UUID,TYPE,DEVICE" /*****************************************************************************/ -static gconstpointer -_metagen_con_active_general_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) -{ - NMActiveConnection *ac = target; - NMConnection *c; - NMSettingConnection *s_con = NULL; - NMDevice *dev; - guint i; - const char *s; - - NMC_HANDLE_COLOR (NM_META_COLOR_NONE); - - nm_assert (NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE)); - - c = NM_CONNECTION (nm_active_connection_get_connection (ac)); - if (c) - s_con = nm_connection_get_setting_connection (c); - - switch (info->info_type) { - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NAME: - return nm_active_connection_get_id (ac); - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_UUID: - return nm_active_connection_get_uuid (ac); - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES: - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_IP_IFACE: - { - GString *str = NULL; - const GPtrArray *devices; - - s = NULL; - devices = nm_active_connection_get_devices (ac); - if (devices) { - for (i = 0; i < devices->len; i++) { - NMDevice *device = g_ptr_array_index (devices, i); - const char *iface; - - if (info->info_type == NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES) { - iface = nm_device_get_iface (device); - } else { - iface = nm_device_get_ip_iface (device); - } - - if (!iface) - continue; - if (!s) { - s = iface; - continue; - } - if (!str) - str = g_string_new (s); - g_string_append_c (str, ','); - g_string_append (str, iface); - } - } - if (str) - return (*out_to_free = g_string_free (str, FALSE)); - return s; - } - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_STATE: - return nmc_meta_generic_get_str_i18n (active_connection_state_to_string (nm_active_connection_get_state (ac)), - get_type); - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT: - return nmc_meta_generic_get_bool (nm_active_connection_get_default (ac), get_type); - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT6: - return nmc_meta_generic_get_bool (nm_active_connection_get_default6 (ac), get_type); - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_SPEC_OBJECT: - return nm_active_connection_get_specific_object_path (ac); - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_VPN: - return nmc_meta_generic_get_bool (NM_IS_VPN_CONNECTION (ac), get_type); - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DBUS_PATH: - return nm_object_get_path (NM_OBJECT (ac)); - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_CON_PATH: - return c ? nm_connection_get_path (c) : NULL; - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_ZONE: - /* this is really ugly, because the zone is not a property of the active-connection, - * but the settings-connection profile. There is no guarantee, that they agree. */ - return s_con ? nm_setting_connection_get_zone (s_con) : NULL; - case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_MASTER_PATH: - dev = nm_active_connection_get_master (ac); - return dev ? nm_object_get_path (NM_OBJECT (dev)) : NULL; - default: - break; - } - - g_return_val_if_reached (NULL); -} - -const NmcMetaGenericInfo *const metagen_con_active_general[_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NUM + 1] = { +static gconstpointer _metagen_con_active_general_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +{ + NMActiveConnection * ac = target; + NMConnection * c; + NMSettingConnection *s_con = NULL; + NMDevice * dev; + guint i; + const char * s; + + NMC_HANDLE_COLOR(NM_META_COLOR_NONE); + + nm_assert( + NM_IN_SET(get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE)); + + c = NM_CONNECTION(nm_active_connection_get_connection(ac)); + if (c) + s_con = nm_connection_get_setting_connection(c); + + switch (info->info_type) { + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NAME: + return nm_active_connection_get_id(ac); + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_UUID: + return nm_active_connection_get_uuid(ac); + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES: + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_IP_IFACE: + { + GString * str = NULL; + const GPtrArray *devices; + + s = NULL; + devices = nm_active_connection_get_devices(ac); + if (devices) { + for (i = 0; i < devices->len; i++) { + NMDevice * device = g_ptr_array_index(devices, i); + const char *iface; + + if (info->info_type == NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES) { + iface = nm_device_get_iface(device); + } else { + iface = nm_device_get_ip_iface(device); + } + + if (!iface) + continue; + if (!s) { + s = iface; + continue; + } + if (!str) + str = g_string_new(s); + g_string_append_c(str, ','); + g_string_append(str, iface); + } + } + if (str) + return (*out_to_free = g_string_free(str, FALSE)); + return s; + } + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_STATE: + return nmc_meta_generic_get_str_i18n( + active_connection_state_to_string(nm_active_connection_get_state(ac)), + get_type); + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT: + return nmc_meta_generic_get_bool(nm_active_connection_get_default(ac), get_type); + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT6: + return nmc_meta_generic_get_bool(nm_active_connection_get_default6(ac), get_type); + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_SPEC_OBJECT: + return nm_active_connection_get_specific_object_path(ac); + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_VPN: + return nmc_meta_generic_get_bool(NM_IS_VPN_CONNECTION(ac), get_type); + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DBUS_PATH: + return nm_object_get_path(NM_OBJECT(ac)); + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_CON_PATH: + return c ? nm_connection_get_path(c) : NULL; + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_ZONE: + /* this is really ugly, because the zone is not a property of the active-connection, + * but the settings-connection profile. There is no guarantee, that they agree. */ + return s_con ? nm_setting_connection_get_zone(s_con) : NULL; + case NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_MASTER_PATH: + dev = nm_active_connection_get_master(ac); + return dev ? nm_object_get_path(NM_OBJECT(dev)) : NULL; + default: + break; + } + + g_return_val_if_reached(NULL); +} + +const NmcMetaGenericInfo + *const metagen_con_active_general[_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NUM + 1] = { #define _METAGEN_CON_ACTIVE_GENERAL(type, name) \ - [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_con_active_general_get_fcn) - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NAME, "NAME"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_UUID, "UUID"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES, "DEVICES"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_IP_IFACE, "IP-IFACE"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_STATE, "STATE"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT, "DEFAULT"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT6, "DEFAULT6"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_SPEC_OBJECT, "SPEC-OBJECT"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_VPN, "VPN"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DBUS_PATH, "DBUS-PATH"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_CON_PATH, "CON-PATH"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_ZONE, "ZONE"), - _METAGEN_CON_ACTIVE_GENERAL (NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_MASTER_PATH, "MASTER-PATH"), + [type] = \ + NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_con_active_general_get_fcn) + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NAME, "NAME"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_UUID, "UUID"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES, "DEVICES"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_IP_IFACE, "IP-IFACE"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_STATE, "STATE"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT, "DEFAULT"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT6, "DEFAULT6"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_SPEC_OBJECT, + "SPEC-OBJECT"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_VPN, "VPN"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DBUS_PATH, + "DBUS-PATH"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_CON_PATH, "CON-PATH"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_ZONE, "ZONE"), + _METAGEN_CON_ACTIVE_GENERAL(NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_MASTER_PATH, + "MASTER-PATH"), }; /*****************************************************************************/ -static gconstpointer -_metagen_con_active_vpn_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS) -{ - NMActiveConnection *ac = target; - NMConnection *c; - NMSettingVpn *s_vpn = NULL; - NMVpnConnectionState vpn_state; - guint i; - const char *s; - char **arr = NULL; - - nm_assert (NM_IS_VPN_CONNECTION (ac)); - - NMC_HANDLE_COLOR (NM_META_COLOR_NONE); - - nm_assert (NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE)); - - c = NM_CONNECTION (nm_active_connection_get_connection (ac)); - if (c) - s_vpn = nm_connection_get_setting_vpn (c); - - switch (info->info_type) { - case NMC_GENERIC_INFO_TYPE_CON_VPN_TYPE: - return c ? get_vpn_connection_type (c) : NULL; - case NMC_GENERIC_INFO_TYPE_CON_VPN_USERNAME: - if ( s_vpn - && (s = nm_setting_vpn_get_user_name (s_vpn))) - return s; - return c ? get_vpn_data_item (c, VPN_DATA_ITEM_USERNAME) : NULL; - case NMC_GENERIC_INFO_TYPE_CON_VPN_GATEWAY: - return c ? get_vpn_data_item (c, VPN_DATA_ITEM_GATEWAY) : NULL; - case NMC_GENERIC_INFO_TYPE_CON_VPN_BANNER: - s = nm_vpn_connection_get_banner (NM_VPN_CONNECTION (ac)); - if (s) - return (*out_to_free = g_strescape (s, "")); - return NULL; - case NMC_GENERIC_INFO_TYPE_CON_VPN_VPN_STATE: - vpn_state = nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (ac)); - return (*out_to_free = nmc_meta_generic_get_enum_with_detail (NMC_META_GENERIC_GET_ENUM_TYPE_DASH, - vpn_state, - vpn_connection_state_to_string (vpn_state), - get_type)); - case NMC_GENERIC_INFO_TYPE_CON_VPN_CFG: - if (!NM_FLAGS_HAS (get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) - return NULL; - if (s_vpn) { - gs_free char **arr2 = NULL; - guint n; - - arr2 = (char **) nm_setting_vpn_get_data_keys (s_vpn, &n); - if (!n) - goto arr_out; - - nm_assert (arr2 && !arr2[n]); - for (i = 0; i < n; i++) { - const char *k = arr2[i]; - const char *v; - - nm_assert (k); - v = nm_setting_vpn_get_data_item (s_vpn, k); - /* update the arr array in-place. Previously it contained - * the constant keys, now it contains the strdup'ed output text. */ - arr2[i] = g_strdup_printf ("%s = %s", k, v); - } - - arr = g_steal_pointer (&arr2); - } - goto arr_out; - default: - break; - } - - g_return_val_if_reached (NULL); +static gconstpointer _metagen_con_active_vpn_get_fcn(NMC_META_GENERIC_INFO_GET_FCN_ARGS) +{ + NMActiveConnection * ac = target; + NMConnection * c; + NMSettingVpn * s_vpn = NULL; + NMVpnConnectionState vpn_state; + guint i; + const char * s; + char ** arr = NULL; + + nm_assert(NM_IS_VPN_CONNECTION(ac)); + + NMC_HANDLE_COLOR(NM_META_COLOR_NONE); + + nm_assert( + NM_IN_SET(get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE)); + + c = NM_CONNECTION(nm_active_connection_get_connection(ac)); + if (c) + s_vpn = nm_connection_get_setting_vpn(c); + + switch (info->info_type) { + case NMC_GENERIC_INFO_TYPE_CON_VPN_TYPE: + return c ? get_vpn_connection_type(c) : NULL; + case NMC_GENERIC_INFO_TYPE_CON_VPN_USERNAME: + if (s_vpn && (s = nm_setting_vpn_get_user_name(s_vpn))) + return s; + return c ? get_vpn_data_item(c, VPN_DATA_ITEM_USERNAME) : NULL; + case NMC_GENERIC_INFO_TYPE_CON_VPN_GATEWAY: + return c ? get_vpn_data_item(c, VPN_DATA_ITEM_GATEWAY) : NULL; + case NMC_GENERIC_INFO_TYPE_CON_VPN_BANNER: + s = nm_vpn_connection_get_banner(NM_VPN_CONNECTION(ac)); + if (s) + return (*out_to_free = g_strescape(s, "")); + return NULL; + case NMC_GENERIC_INFO_TYPE_CON_VPN_VPN_STATE: + vpn_state = nm_vpn_connection_get_vpn_state(NM_VPN_CONNECTION(ac)); + return (*out_to_free = + nmc_meta_generic_get_enum_with_detail(NMC_META_GENERIC_GET_ENUM_TYPE_DASH, + vpn_state, + vpn_connection_state_to_string(vpn_state), + get_type)); + case NMC_GENERIC_INFO_TYPE_CON_VPN_CFG: + if (!NM_FLAGS_HAS(get_flags, NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV)) + return NULL; + if (s_vpn) { + gs_free char **arr2 = NULL; + guint n; + + arr2 = (char **) nm_setting_vpn_get_data_keys(s_vpn, &n); + if (!n) + goto arr_out; + + nm_assert(arr2 && !arr2[n]); + for (i = 0; i < n; i++) { + const char *k = arr2[i]; + const char *v; + + nm_assert(k); + v = nm_setting_vpn_get_data_item(s_vpn, k); + /* update the arr array in-place. Previously it contained + * the constant keys, now it contains the strdup'ed output text. */ + arr2[i] = g_strdup_printf("%s = %s", k, v); + } + + arr = g_steal_pointer(&arr2); + } + goto arr_out; + default: + break; + } + + g_return_val_if_reached(NULL); arr_out: - NM_SET_OUT (out_is_default, !arr || !arr[0]); - *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; - *out_to_free = arr; - return arr; + NM_SET_OUT(out_is_default, !arr || !arr[0]); + *out_flags |= NM_META_ACCESSOR_GET_OUT_FLAGS_STRV; + *out_to_free = arr; + return arr; } -const NmcMetaGenericInfo *const metagen_con_active_vpn[_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_VPN_NUM + 1] = { +const NmcMetaGenericInfo + *const metagen_con_active_vpn[_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_VPN_NUM + 1] = { #define _METAGEN_CON_ACTIVE_VPN(type, name) \ - [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_con_active_vpn_get_fcn) - _METAGEN_CON_ACTIVE_VPN (NMC_GENERIC_INFO_TYPE_CON_VPN_TYPE, "TYPE"), - _METAGEN_CON_ACTIVE_VPN (NMC_GENERIC_INFO_TYPE_CON_VPN_USERNAME, "USERNAME"), - _METAGEN_CON_ACTIVE_VPN (NMC_GENERIC_INFO_TYPE_CON_VPN_GATEWAY, "GATEWAY"), - _METAGEN_CON_ACTIVE_VPN (NMC_GENERIC_INFO_TYPE_CON_VPN_BANNER, "BANNER"), - _METAGEN_CON_ACTIVE_VPN (NMC_GENERIC_INFO_TYPE_CON_VPN_VPN_STATE, "VPN-STATE"), - _METAGEN_CON_ACTIVE_VPN (NMC_GENERIC_INFO_TYPE_CON_VPN_CFG, "CFG"), + [type] = NMC_META_GENERIC(name, .info_type = type, .get_fcn = _metagen_con_active_vpn_get_fcn) + _METAGEN_CON_ACTIVE_VPN(NMC_GENERIC_INFO_TYPE_CON_VPN_TYPE, "TYPE"), + _METAGEN_CON_ACTIVE_VPN(NMC_GENERIC_INFO_TYPE_CON_VPN_USERNAME, "USERNAME"), + _METAGEN_CON_ACTIVE_VPN(NMC_GENERIC_INFO_TYPE_CON_VPN_GATEWAY, "GATEWAY"), + _METAGEN_CON_ACTIVE_VPN(NMC_GENERIC_INFO_TYPE_CON_VPN_BANNER, "BANNER"), + _METAGEN_CON_ACTIVE_VPN(NMC_GENERIC_INFO_TYPE_CON_VPN_VPN_STATE, "VPN-STATE"), + _METAGEN_CON_ACTIVE_VPN(NMC_GENERIC_INFO_TYPE_CON_VPN_CFG, "CFG"), }; /*****************************************************************************/ -#define NMC_FIELDS_SETTINGS_NAMES_ALL NM_SETTING_CONNECTION_SETTING_NAME","\ - NM_SETTING_MATCH_SETTING_NAME","\ - NM_SETTING_WIRED_SETTING_NAME","\ - NM_SETTING_802_1X_SETTING_NAME","\ - NM_SETTING_WIRELESS_SETTING_NAME","\ - NM_SETTING_WIRELESS_SECURITY_SETTING_NAME","\ - NM_SETTING_IP4_CONFIG_SETTING_NAME","\ - NM_SETTING_IP6_CONFIG_SETTING_NAME","\ - NM_SETTING_SERIAL_SETTING_NAME","\ - NM_SETTING_WIFI_P2P_SETTING_NAME","\ - NM_SETTING_PPP_SETTING_NAME","\ - NM_SETTING_PPPOE_SETTING_NAME","\ - NM_SETTING_ADSL_SETTING_NAME","\ - NM_SETTING_GSM_SETTING_NAME","\ - NM_SETTING_CDMA_SETTING_NAME","\ - NM_SETTING_BLUETOOTH_SETTING_NAME","\ - NM_SETTING_OLPC_MESH_SETTING_NAME","\ - NM_SETTING_VPN_SETTING_NAME","\ - NM_SETTING_INFINIBAND_SETTING_NAME","\ - NM_SETTING_BOND_SETTING_NAME","\ - NM_SETTING_VLAN_SETTING_NAME","\ - NM_SETTING_BRIDGE_SETTING_NAME","\ - NM_SETTING_BRIDGE_PORT_SETTING_NAME","\ - NM_SETTING_TEAM_SETTING_NAME","\ - NM_SETTING_TEAM_PORT_SETTING_NAME"," \ - NM_SETTING_OVS_BRIDGE_SETTING_NAME","\ - NM_SETTING_OVS_INTERFACE_SETTING_NAME","\ - NM_SETTING_OVS_PATCH_SETTING_NAME","\ - NM_SETTING_OVS_PORT_SETTING_NAME","\ - NM_SETTING_DCB_SETTING_NAME"," \ - NM_SETTING_TUN_SETTING_NAME"," \ - NM_SETTING_IP_TUNNEL_SETTING_NAME"," \ - NM_SETTING_MACSEC_SETTING_NAME"," \ - NM_SETTING_MACVLAN_SETTING_NAME"," \ - NM_SETTING_VXLAN_SETTING_NAME"," \ - NM_SETTING_VRF_SETTING_NAME"," \ - NM_SETTING_WPAN_SETTING_NAME","\ - NM_SETTING_6LOWPAN_SETTING_NAME","\ - NM_SETTING_WIREGUARD_SETTING_NAME","\ - NM_SETTING_PROXY_SETTING_NAME"," \ - NM_SETTING_TC_CONFIG_SETTING_NAME"," \ - NM_SETTING_SRIOV_SETTING_NAME"," \ - NM_SETTING_ETHTOOL_SETTING_NAME"," \ - NM_SETTING_OVS_DPDK_SETTING_NAME \ - // NM_SETTING_DUMMY_SETTING_NAME - // NM_SETTING_WIMAX_SETTING_NAME +#define NMC_FIELDS_SETTINGS_NAMES_ALL \ + NM_SETTING_CONNECTION_SETTING_NAME \ + "," NM_SETTING_MATCH_SETTING_NAME "," NM_SETTING_WIRED_SETTING_NAME \ + "," NM_SETTING_VETH_SETTING_NAME "," NM_SETTING_802_1X_SETTING_NAME \ + "," NM_SETTING_WIRELESS_SETTING_NAME "," NM_SETTING_WIRELESS_SECURITY_SETTING_NAME \ + "," NM_SETTING_IP4_CONFIG_SETTING_NAME "," NM_SETTING_IP6_CONFIG_SETTING_NAME \ + "," NM_SETTING_SERIAL_SETTING_NAME "," NM_SETTING_WIFI_P2P_SETTING_NAME \ + "," NM_SETTING_PPP_SETTING_NAME "," NM_SETTING_PPPOE_SETTING_NAME \ + "," NM_SETTING_ADSL_SETTING_NAME "," NM_SETTING_GSM_SETTING_NAME \ + "," NM_SETTING_CDMA_SETTING_NAME "," NM_SETTING_BLUETOOTH_SETTING_NAME \ + "," NM_SETTING_OLPC_MESH_SETTING_NAME "," NM_SETTING_VPN_SETTING_NAME \ + "," NM_SETTING_INFINIBAND_SETTING_NAME "," NM_SETTING_BOND_SETTING_NAME \ + "," NM_SETTING_VLAN_SETTING_NAME "," NM_SETTING_BRIDGE_SETTING_NAME \ + "," NM_SETTING_BRIDGE_PORT_SETTING_NAME "," NM_SETTING_TEAM_SETTING_NAME \ + "," NM_SETTING_TEAM_PORT_SETTING_NAME "," NM_SETTING_OVS_BRIDGE_SETTING_NAME \ + "," NM_SETTING_OVS_INTERFACE_SETTING_NAME "," NM_SETTING_OVS_PATCH_SETTING_NAME \ + "," NM_SETTING_OVS_PORT_SETTING_NAME "," NM_SETTING_DCB_SETTING_NAME \ + "," NM_SETTING_TUN_SETTING_NAME "," NM_SETTING_IP_TUNNEL_SETTING_NAME \ + "," NM_SETTING_MACSEC_SETTING_NAME "," NM_SETTING_MACVLAN_SETTING_NAME \ + "," NM_SETTING_VXLAN_SETTING_NAME "," NM_SETTING_VRF_SETTING_NAME \ + "," NM_SETTING_WPAN_SETTING_NAME "," NM_SETTING_6LOWPAN_SETTING_NAME \ + "," NM_SETTING_WIREGUARD_SETTING_NAME "," NM_SETTING_PROXY_SETTING_NAME \ + "," NM_SETTING_TC_CONFIG_SETTING_NAME "," NM_SETTING_SRIOV_SETTING_NAME \ + "," NM_SETTING_ETHTOOL_SETTING_NAME "," NM_SETTING_OVS_DPDK_SETTING_NAME \ + "," NM_SETTING_HOSTNAME_SETTING_NAME /* NM_SETTING_DUMMY_SETTING_NAME NM_SETTING_WIMAX_SETTING_NAME */ const NmcMetaGenericInfo *const nmc_fields_con_active_details_groups[] = { - NMC_META_GENERIC_WITH_NESTED ("GENERAL", metagen_con_active_general), /* 0 */ - NMC_META_GENERIC_WITH_NESTED ("IP4", metagen_ip4_config), /* 1 */ - NMC_META_GENERIC_WITH_NESTED ("DHCP4", metagen_dhcp_config), /* 2 */ - NMC_META_GENERIC_WITH_NESTED ("IP6", metagen_ip6_config), /* 3 */ - NMC_META_GENERIC_WITH_NESTED ("DHCP6", metagen_dhcp_config), /* 4 */ - NMC_META_GENERIC_WITH_NESTED ("VPN", metagen_con_active_vpn), /* 5 */ - NULL, + NMC_META_GENERIC_WITH_NESTED("GENERAL", metagen_con_active_general), /* 0 */ + NMC_META_GENERIC_WITH_NESTED("IP4", metagen_ip4_config), /* 1 */ + NMC_META_GENERIC_WITH_NESTED("DHCP4", metagen_dhcp_config), /* 2 */ + NMC_META_GENERIC_WITH_NESTED("IP6", metagen_ip6_config), /* 3 */ + NMC_META_GENERIC_WITH_NESTED("DHCP6", metagen_dhcp_config), /* 4 */ + NMC_META_GENERIC_WITH_NESTED("VPN", metagen_con_active_vpn), /* 5 */ + NULL, }; /* Pseudo group names for 'connection show ' */ @@ -885,16 +900,16 @@ const NmcMetaGenericInfo *const nmc_fields_con_active_details_groups[] = { #define CON_SHOW_DETAIL_GROUP_PROFILE "profile" #define CON_SHOW_DETAIL_GROUP_ACTIVE "active" -static guint progress_id = 0; /* ID of event source for displaying progress */ +static guint progress_id = 0; /* ID of event source for displaying progress */ /* for readline TAB completion in editor */ typedef struct { - NmCli *nmc; - char *con_type; - NMConnection *connection; - NMSetting *setting; - const char *property; - char **words; + NmCli * nmc; + char * con_type; + NMConnection *connection; + NMSetting * setting; + const char * property; + char ** words; } TabCompletionInfo; static TabCompletionInfo nmc_tab_completion; @@ -902,1446 +917,1517 @@ static TabCompletionInfo nmc_tab_completion; /*****************************************************************************/ static void -usage (void) -{ - g_printerr (_("Usage: nmcli connection { COMMAND | help }\n\n" - "COMMAND := { show | up | down | add | modify | clone | edit | delete | monitor | reload | load | import | export }\n\n" - " show [--active] [--order ]\n" - " show [--active] [id | uuid | path | apath] ...\n\n" - " up [[id | uuid | path] ] [ifname ] [ap ] [passwd-file ]\n\n" - " down [id | uuid | path | apath] ...\n\n" - " add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- ([+|-]. )+]\n\n" - " modify [--temporary] [id | uuid | path] ([+|-]. )+\n\n" - " clone [--temporary] [id | uuid | path ] \n\n" - " edit [id | uuid | path] \n" - " edit [type ] [con-name ]\n\n" - " delete [id | uuid | path] \n\n" - " monitor [id | uuid | path] ...\n\n" - " reload\n\n" - " load [ ... ]\n\n" - " import [--temporary] type file \n\n" - " export [id | uuid | path] []\n\n")); +usage(void) +{ + g_printerr( + _("Usage: nmcli connection { COMMAND | help }\n\n" + "COMMAND := { show | up | down | add | modify | clone | edit | delete | monitor | reload " + "| load | import | export }\n\n" + " show [--active] [--order ]\n" + " show [--active] [id | uuid | path | apath] ...\n\n" + " up [[id | uuid | path] ] [ifname ] [ap ] [passwd-file ]\n\n" + " down [id | uuid | path | apath] ...\n\n" + " add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- " + "([+|-]. )+]\n\n" + " modify [--temporary] [id | uuid | path] ([+|-]. )+\n\n" + " clone [--temporary] [id | uuid | path ] \n\n" + " edit [id | uuid | path] \n" + " edit [type ] [con-name ]\n\n" + " delete [id | uuid | path] \n\n" + " monitor [id | uuid | path] ...\n\n" + " reload\n\n" + " load [ ... ]\n\n" + " import [--temporary] type file \n\n" + " export [id | uuid | path] []\n\n")); } static void -usage_connection_show (void) -{ - g_printerr (_("Usage: nmcli connection show { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [--active] [--order ]\n" - "\n" - "List in-memory and on-disk connection profiles, some of which may also be\n" - "active if a device is using that connection profile. Without a parameter, all\n" - "profiles are listed. When --active option is specified, only the active\n" - "profiles are shown. --order allows custom connection ordering (see manual page).\n" - "\n" - "ARGUMENTS := [--active] [id | uuid | path | apath] ...\n" - "\n" - "Show details for specified connections. By default, both static configuration\n" - "and active connection data are displayed. It is possible to filter the output\n" - "using global '--fields' option. Refer to the manual page for more information.\n" - "When --active option is specified, only the active profiles are taken into\n" - "account. Use global --show-secrets option to reveal associated secrets as well.\n")); +usage_connection_show(void) +{ + g_printerr( + _("Usage: nmcli connection show { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [--active] [--order ]\n" + "\n" + "List in-memory and on-disk connection profiles, some of which may also be\n" + "active if a device is using that connection profile. Without a parameter, all\n" + "profiles are listed. When --active option is specified, only the active\n" + "profiles are shown. --order allows custom connection ordering (see manual page).\n" + "\n" + "ARGUMENTS := [--active] [id | uuid | path | apath] ...\n" + "\n" + "Show details for specified connections. By default, both static configuration\n" + "and active connection data are displayed. It is possible to filter the output\n" + "using global '--fields' option. Refer to the manual page for more information.\n" + "When --active option is specified, only the active profiles are taken into\n" + "account. Use global --show-secrets option to reveal associated secrets as well.\n")); } static void -usage_connection_up (void) -{ - g_printerr (_("Usage: nmcli connection up { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path] [ifname ] [ap ] [nsp ] [passwd-file ]\n" - "\n" - "Activate a connection on a device. The profile to activate is identified by its\n" - "name, UUID or D-Bus path.\n" - "\n" - "ARGUMENTS := ifname [ap ] [nsp ] [passwd-file ]\n" - "\n" - "Activate a device with a connection. The connection profile is selected\n" - "automatically by NetworkManager.\n" - "\n" - "ifname - specifies the device to active the connection on\n" - "ap - specifies AP to connect to (only valid for Wi-Fi)\n" - "nsp - specifies NSP to connect to (only valid for WiMAX)\n" - "passwd-file - file with password(s) required to activate the connection\n\n")); +usage_connection_up(void) +{ + g_printerr(_("Usage: nmcli connection up { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path] [ifname ] [ap ] [nsp ] " + "[passwd-file ]\n" + "\n" + "Activate a connection on a device. The profile to activate is identified by its\n" + "name, UUID or D-Bus path.\n" + "\n" + "ARGUMENTS := ifname [ap ] [nsp ] [passwd-file ]\n" + "\n" + "Activate a device with a connection. The connection profile is selected\n" + "automatically by NetworkManager.\n" + "\n" + "ifname - specifies the device to active the connection on\n" + "ap - specifies AP to connect to (only valid for Wi-Fi)\n" + "nsp - specifies NSP to connect to (only valid for WiMAX)\n" + "passwd-file - file with password(s) required to activate the connection\n\n")); } static void -usage_connection_down (void) +usage_connection_down(void) { - g_printerr (_("Usage: nmcli connection down { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path | apath] ...\n" - "\n" - "Deactivate a connection from a device (without preventing the device from\n" - "further auto-activation). The profile to deactivate is identified by its name,\n" - "UUID or D-Bus path.\n\n")); + g_printerr(_("Usage: nmcli connection down { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path | apath] ...\n" + "\n" + "Deactivate a connection from a device (without preventing the device from\n" + "further auto-activation). The profile to deactivate is identified by its name,\n" + "UUID or D-Bus path.\n\n")); } static void -usage_connection_add (void) -{ - g_printerr (_("Usage: nmcli connection add { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- ([+|-]. )+]\n\n" - " COMMON_OPTIONS:\n" - " type \n" - " ifname | \"*\"\n" - " [con-name ]\n" - " [autoconnect yes|no]\n" - " [save yes|no]\n" - " [master ]\n" - " [slave-type ]\n\n" - " TYPE_SPECIFIC_OPTIONS:\n" - " ethernet: [mac ]\n" - " [cloned-mac ]\n" - " [mtu ]\n\n" - " wifi: ssid \n" - " [mac ]\n" - " [cloned-mac ]\n" - " [mtu ]\n" - " [mode infrastructure|ap|adhoc]\n\n" - " wimax: [mac ]\n" - " [nsp ]\n\n" - " pppoe: username \n" - " [password ]\n" - " [service ]\n" - " [mtu ]\n" - " [mac ]\n\n" - " gsm: apn \n" - " [user ]\n" - " [password ]\n\n" - " cdma: [user ]\n" - " [password ]\n\n" - " infiniband: [mac ]\n" - " [mtu ]\n" - " [transport-mode datagram | connected]\n" - " [parent ]\n" - " [p-key ]\n\n" - " bluetooth: [addr ]\n" - " [bt-type panu|nap|dun-gsm|dun-cdma]\n\n" - " vlan: dev \n" - " id \n" - " [flags ]\n" - " [ingress ]\n" - " [egress ]\n" - " [mtu ]\n\n" - " bond: [mode balance-rr (0) | active-backup (1) | balance-xor (2) | broadcast (3) |\n" - " 802.3ad (4) | balance-tlb (5) | balance-alb (6)]\n" - " [primary ]\n" - " [miimon ]\n" - " [downdelay ]\n" - " [updelay ]\n" - " [arp-interval ]\n" - " [arp-ip-target ]\n" - " [lacp-rate slow (0) | fast (1)]\n\n" - " bond-slave: master \n\n" - " team: [config |]\n\n" - " team-slave: master \n" - " [config |]\n\n" - " bridge: [stp yes|no]\n" - " [priority ]\n" - " [forward-delay <2-30>]\n" - " [hello-time <1-10>]\n" - " [max-age <6-40>]\n" - " [ageing-time <0-1000000>]\n" - " [multicast-snooping yes|no]\n" - " [mac ]\n\n" - " bridge-slave: master \n" - " [priority <0-63>]\n" - " [path-cost <1-65535>]\n" - " [hairpin yes|no]\n\n" - " vpn: vpn-type vpnc|openvpn|pptp|openconnect|openswan|libreswan|ssh|l2tp|iodine|...\n" - " [user ]\n\n" - " olpc-mesh: ssid \n" - " [channel <1-13>]\n" - " [dhcp-anycast ]\n\n" - " adsl: username \n" - " protocol pppoa|pppoe|ipoatm\n" - " [password ]\n" - " [encapsulation vcmux|llc]\n\n" - " tun: mode tun|tap\n" - " [owner ]\n" - " [group ]\n" - " [pi yes|no]\n" - " [vnet-hdr yes|no]\n" - " [multi-queue yes|no]\n\n" - " ip-tunnel: mode ipip|gre|sit|isatap|vti|ip6ip6|ipip6|ip6gre|vti6\n" - " remote \n" - " [local ]\n" - " [dev ]\n\n" - " macsec: dev \n" - " mode \n" - " [cak ckn ]\n" - " [encrypt yes|no]\n" - " [port 1-65534]\n\n\n" - " macvlan: dev \n" - " mode vepa|bridge|private|passthru|source\n" - " [tap yes|no]\n\n" - " vxlan: id \n" - " remote \n" - " [local ]\n" - " [dev ]\n" - " [source-port-min <0-65535>]\n" - " [source-port-max <0-65535>]\n" - " [destination-port <0-65535>]\n\n" - " wpan: [short-addr <0x0000-0xffff>]\n" - " [pan-id <0x0000-0xffff>]\n" - " [page ]\n" - " [channel ]\n" - " [mac ]\n\n" - " 6lowpan: dev \n" - " dummy:\n\n" - " SLAVE_OPTIONS:\n" - " bridge: [priority <0-63>]\n" - " [path-cost <1-65535>]\n" - " [hairpin yes|no]\n\n" - " team: [config |]\n\n" - " IP_OPTIONS:\n" - " [ip4 ] [gw4 ]\n" - " [ip6 ] [gw6 ]\n\n")); +usage_connection_add(void) +{ + g_printerr(_("Usage: nmcli connection add { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- " + "([+|-]. )+]\n\n" + " COMMON_OPTIONS:\n" + " type \n" + " ifname | \"*\"\n" + " [con-name ]\n" + " [autoconnect yes|no]\n" + " [save yes|no]\n" + " [master ]\n" + " [slave-type ]\n\n" + " TYPE_SPECIFIC_OPTIONS:\n" + " ethernet: [mac ]\n" + " [cloned-mac ]\n" + " [mtu ]\n\n" + " wifi: ssid \n" + " [mac ]\n" + " [cloned-mac ]\n" + " [mtu ]\n" + " [mode infrastructure|ap|adhoc]\n\n" + " wimax: [mac ]\n" + " [nsp ]\n\n" + " pppoe: username \n" + " [password ]\n" + " [service ]\n" + " [mtu ]\n" + " [mac ]\n\n" + " gsm: apn \n" + " [user ]\n" + " [password ]\n\n" + " cdma: [user ]\n" + " [password ]\n\n" + " infiniband: [mac ]\n" + " [mtu ]\n" + " [transport-mode datagram | connected]\n" + " [parent ]\n" + " [p-key ]\n\n" + " bluetooth: [addr ]\n" + " [bt-type panu|nap|dun-gsm|dun-cdma]\n\n" + " vlan: dev \n" + " id \n" + " [flags ]\n" + " [ingress ]\n" + " [egress ]\n" + " [mtu ]\n\n" + " bond: [mode balance-rr (0) | active-backup (1) | balance-xor (2) | " + "broadcast (3) |\n" + " 802.3ad (4) | balance-tlb (5) | balance-alb (6)]\n" + " [primary ]\n" + " [miimon ]\n" + " [downdelay ]\n" + " [updelay ]\n" + " [arp-interval ]\n" + " [arp-ip-target ]\n" + " [lacp-rate slow (0) | fast (1)]\n\n" + " bond-slave: master \n\n" + " team: [config |]\n\n" + " team-slave: master \n" + " [config |]\n\n" + " bridge: [stp yes|no]\n" + " [priority ]\n" + " [forward-delay <2-30>]\n" + " [hello-time <1-10>]\n" + " [max-age <6-40>]\n" + " [ageing-time <0-1000000>]\n" + " [multicast-snooping yes|no]\n" + " [mac ]\n\n" + " bridge-slave: master \n" + " [priority <0-63>]\n" + " [path-cost <1-65535>]\n" + " [hairpin yes|no]\n\n" + " vpn: vpn-type " + "vpnc|openvpn|pptp|openconnect|openswan|libreswan|ssh|l2tp|iodine|...\n" + " [user ]\n\n" + " olpc-mesh: ssid \n" + " [channel <1-13>]\n" + " [dhcp-anycast ]\n\n" + " adsl: username \n" + " protocol pppoa|pppoe|ipoatm\n" + " [password ]\n" + " [encapsulation vcmux|llc]\n\n" + " tun: mode tun|tap\n" + " [owner ]\n" + " [group ]\n" + " [pi yes|no]\n" + " [vnet-hdr yes|no]\n" + " [multi-queue yes|no]\n\n" + " ip-tunnel: mode ipip|gre|sit|isatap|vti|ip6ip6|ipip6|ip6gre|vti6\n" + " remote \n" + " [local ]\n" + " [dev ]\n\n" + " macsec: dev \n" + " mode \n" + " [cak ckn ]\n" + " [encrypt yes|no]\n" + " [port 1-65534]\n\n\n" + " macvlan: dev \n" + " mode vepa|bridge|private|passthru|source\n" + " [tap yes|no]\n\n" + " vxlan: id \n" + " [remote ]\n" + " [local ]\n" + " [dev ]\n" + " [source-port-min <0-65535>]\n" + " [source-port-max <0-65535>]\n" + " [destination-port <0-65535>]\n\n" + " wpan: [short-addr <0x0000-0xffff>]\n" + " [pan-id <0x0000-0xffff>]\n" + " [page ]\n" + " [channel ]\n" + " [mac ]\n\n" + " 6lowpan: dev \n" + " dummy:\n\n" + " SLAVE_OPTIONS:\n" + " bridge: [priority <0-63>]\n" + " [path-cost <1-65535>]\n" + " [hairpin yes|no]\n\n" + " team: [config |]\n\n" + " IP_OPTIONS:\n" + " [ip4 ] [gw4 ]\n" + " [ip6 ] [gw6 ]\n\n")); } static void -usage_connection_modify (void) -{ - g_printerr (_("Usage: nmcli connection modify { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path] ([+|-]. )+\n" - "\n" - "Modify one or more properties of the connection profile.\n" - "The profile is identified by its name, UUID or D-Bus path. For multi-valued\n" - "properties you can use optional '+' or '-' prefix to the property name.\n" - "The '+' sign allows appending items instead of overwriting the whole value.\n" - "The '-' sign allows removing selected items instead of the whole value.\n" - "\n" - "ARGUMENTS := remove \n" - "\n" - "Remove a setting from the connection profile.\n" - "\n" - "Examples:\n" - "nmcli con mod home-wifi wifi.ssid rakosnicek\n" - "nmcli con mod em1-1 ipv4.method manual ipv4.addr \"192.168.1.2/24, 10.10.1.5/8\"\n" - "nmcli con mod em1-1 +ipv4.dns 8.8.4.4\n" - "nmcli con mod em1-1 -ipv4.dns 1\n" - "nmcli con mod em1-1 -ipv6.addr \"abbe::cafe/56\"\n" - "nmcli con mod bond0 +bond.options mii=500\n" - "nmcli con mod bond0 -bond.options downdelay\n" - "nmcli con mod em1-1 remove sriov\n\n")); +usage_connection_modify(void) +{ + g_printerr( + _("Usage: nmcli connection modify { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path] ([+|-]. )+\n" + "\n" + "Modify one or more properties of the connection profile.\n" + "The profile is identified by its name, UUID or D-Bus path. For multi-valued\n" + "properties you can use optional '+' or '-' prefix to the property name.\n" + "The '+' sign allows appending items instead of overwriting the whole value.\n" + "The '-' sign allows removing selected items instead of the whole value.\n" + "\n" + "ARGUMENTS := remove \n" + "\n" + "Remove a setting from the connection profile.\n" + "\n" + "Examples:\n" + "nmcli con mod home-wifi wifi.ssid rakosnicek\n" + "nmcli con mod em1-1 ipv4.method manual ipv4.addr \"192.168.1.2/24, 10.10.1.5/8\"\n" + "nmcli con mod em1-1 +ipv4.dns 8.8.4.4\n" + "nmcli con mod em1-1 -ipv4.dns 1\n" + "nmcli con mod em1-1 -ipv6.addr \"abbe::cafe/56\"\n" + "nmcli con mod bond0 +bond.options mii=500\n" + "nmcli con mod bond0 -bond.options downdelay\n" + "nmcli con mod em1-1 remove sriov\n\n")); } static void -usage_connection_clone (void) +usage_connection_clone(void) { - g_printerr (_("Usage: nmcli connection clone { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [--temporary] [id | uuid | path] \n" - "\n" - "Clone an existing connection profile. The newly created connection will be\n" - "the exact copy of the , except the uuid property (will be generated) and\n" - "id (provided as argument).\n\n")); + g_printerr(_("Usage: nmcli connection clone { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [--temporary] [id | uuid | path] \n" + "\n" + "Clone an existing connection profile. The newly created connection will be\n" + "the exact copy of the , except the uuid property (will be generated) and\n" + "id (provided as argument).\n\n")); } static void -usage_connection_edit (void) +usage_connection_edit(void) { - g_printerr (_("Usage: nmcli connection edit { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path] \n" - "\n" - "Edit an existing connection profile in an interactive editor.\n" - "The profile is identified by its name, UUID or D-Bus path\n" - "\n" - "ARGUMENTS := [type ] [con-name ]\n" - "\n" - "Add a new connection profile in an interactive editor.\n\n")); + g_printerr(_("Usage: nmcli connection edit { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path] \n" + "\n" + "Edit an existing connection profile in an interactive editor.\n" + "The profile is identified by its name, UUID or D-Bus path\n" + "\n" + "ARGUMENTS := [type ] [con-name ]\n" + "\n" + "Add a new connection profile in an interactive editor.\n\n")); } static void -usage_connection_delete (void) +usage_connection_delete(void) { - g_printerr (_("Usage: nmcli connection delete { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path] \n" - "\n" - "Delete a connection profile.\n" - "The profile is identified by its name, UUID or D-Bus path.\n\n")); + g_printerr(_("Usage: nmcli connection delete { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path] \n" + "\n" + "Delete a connection profile.\n" + "The profile is identified by its name, UUID or D-Bus path.\n\n")); } static void -usage_connection_monitor (void) +usage_connection_monitor(void) { - g_printerr (_("Usage: nmcli connection monitor { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path] ...\n" - "\n" - "Monitor connection profile activity.\n" - "This command prints a line whenever the specified connection changes.\n" - "Monitors all connection profiles in case none is specified.\n\n")); + g_printerr(_("Usage: nmcli connection monitor { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path] ...\n" + "\n" + "Monitor connection profile activity.\n" + "This command prints a line whenever the specified connection changes.\n" + "Monitors all connection profiles in case none is specified.\n\n")); } static void -usage_connection_reload (void) +usage_connection_reload(void) { - g_printerr (_("Usage: nmcli connection reload { help }\n" - "\n" - "Reload all connection files from disk.\n\n")); + g_printerr(_("Usage: nmcli connection reload { help }\n" + "\n" + "Reload all connection files from disk.\n\n")); } static void -usage_connection_load (void) +usage_connection_load(void) { - g_printerr (_("Usage: nmcli connection load { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [...]\n" - "\n" - "Load/reload one or more connection files from disk. Use this after manually\n" - "editing a connection file to ensure that NetworkManager is aware of its latest\n" - "state.\n\n")); + g_printerr(_("Usage: nmcli connection load { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [...]\n" + "\n" + "Load/reload one or more connection files from disk. Use this after manually\n" + "editing a connection file to ensure that NetworkManager is aware of its latest\n" + "state.\n\n")); } static void -usage_connection_import (void) +usage_connection_import(void) { - g_printerr (_("Usage: nmcli connection import { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [--temporary] type file \n" - "\n" - "Import an external/foreign configuration as a NetworkManager connection profile.\n" - "The type of the input file is specified by type option.\n" - "Only VPN configurations are supported at the moment. The configuration\n" - "is imported by NetworkManager VPN plugins.\n\n")); + g_printerr( + _("Usage: nmcli connection import { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [--temporary] type file \n" + "\n" + "Import an external/foreign configuration as a NetworkManager connection profile.\n" + "The type of the input file is specified by type option.\n" + "Only VPN configurations are supported at the moment. The configuration\n" + "is imported by NetworkManager VPN plugins.\n\n")); } static void -usage_connection_export (void) +usage_connection_export(void) { - g_printerr (_("Usage: nmcli connection export { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path] []\n" - "\n" - "Export a connection. Only VPN connections are supported at the moment.\n" - "The data are directed to standard output or to a file if a name is given.\n\n")); + g_printerr(_("Usage: nmcli connection export { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path] []\n" + "\n" + "Export a connection. Only VPN connections are supported at the moment.\n" + "The data are directed to standard output or to a file if a name is given.\n\n")); } static void -quit (void) +quit(void) { - if (nm_clear_g_source (&progress_id)) - nmc_terminal_erase_line (); - g_main_loop_quit (loop); + if (nm_clear_g_source(&progress_id)) + nmc_terminal_erase_line(); + g_main_loop_quit(loop); } static char * -construct_header_name (const char *base, const char *spec) +construct_header_name(const char *base, const char *spec) { - if (spec == NULL) - return g_strdup (base); + if (spec == NULL) + return g_strdup(base); - return g_strdup_printf ("%s (%s)", base, spec); + return g_strdup_printf("%s (%s)", base, spec); } static int -get_ac_for_connection_cmp (gconstpointer pa, gconstpointer pb) +get_ac_for_connection_cmp(gconstpointer pa, gconstpointer pb) { - NMActiveConnection *ac_a = *((NMActiveConnection *const*) pa); - NMActiveConnection *ac_b = *((NMActiveConnection *const*) pb); + NMActiveConnection *ac_a = *((NMActiveConnection *const *) pa); + NMActiveConnection *ac_b = *((NMActiveConnection *const *) pb); - NM_CMP_RETURN (nmc_active_connection_cmp (ac_a, ac_b)); - NM_CMP_DIRECT_STRCMP0 (nm_active_connection_get_id (ac_a), - nm_active_connection_get_id (ac_b)); - NM_CMP_DIRECT_STRCMP0 (nm_active_connection_get_connection_type (ac_a), - nm_active_connection_get_connection_type (ac_b)); - NM_CMP_DIRECT_STRCMP0 (nm_object_get_path (NM_OBJECT (ac_a)), - nm_object_get_path (NM_OBJECT (ac_b))); + NM_CMP_RETURN(nmc_active_connection_cmp(ac_a, ac_b)); + NM_CMP_DIRECT_STRCMP0(nm_active_connection_get_id(ac_a), nm_active_connection_get_id(ac_b)); + NM_CMP_DIRECT_STRCMP0(nm_active_connection_get_connection_type(ac_a), + nm_active_connection_get_connection_type(ac_b)); + NM_CMP_DIRECT_STRCMP0(nm_object_get_path(NM_OBJECT(ac_a)), nm_object_get_path(NM_OBJECT(ac_b))); - g_return_val_if_reached (0); + g_return_val_if_reached(0); } static NMActiveConnection * -get_ac_for_connection (const GPtrArray *active_cons, NMConnection *connection, GPtrArray **out_result) +get_ac_for_connection(const GPtrArray *active_cons, + NMConnection * connection, + GPtrArray ** out_result) { - guint i; - NMActiveConnection *best_candidate = NULL; - GPtrArray *result = out_result ? *out_result : NULL; + guint i; + NMActiveConnection *best_candidate = NULL; + GPtrArray * result = out_result ? *out_result : NULL; - for (i = 0; i < active_cons->len; i++) { - NMActiveConnection *candidate = g_ptr_array_index (active_cons, i); - NMRemoteConnection *con; + for (i = 0; i < active_cons->len; i++) { + NMActiveConnection *candidate = g_ptr_array_index(active_cons, i); + NMRemoteConnection *con; - con = nm_active_connection_get_connection (candidate); - if (NM_CONNECTION (con) != connection) - continue; + con = nm_active_connection_get_connection(candidate); + if (NM_CONNECTION(con) != connection) + continue; - if (!out_result) - return candidate; - if (!result) - result = g_ptr_array_new_with_free_func (g_object_unref); - g_ptr_array_add (result, g_object_ref (candidate)); - } + if (!out_result) + return candidate; + if (!result) + result = g_ptr_array_new_with_free_func(g_object_unref); + g_ptr_array_add(result, g_object_ref(candidate)); + } - if (result) { - g_ptr_array_sort (result, get_ac_for_connection_cmp); - best_candidate = result->pdata[0]; - } + if (result) { + g_ptr_array_sort(result, get_ac_for_connection_cmp); + best_candidate = result->pdata[0]; + } - NM_SET_OUT (out_result, result); - return best_candidate; + NM_SET_OUT(out_result, result); + return best_candidate; } typedef struct { - GMainLoop *loop; - NMConnection *local; - const char *setting_name; + GMainLoop * loop; + NMConnection *local; + const char * setting_name; } GetSecretsData; static void -got_secrets (GObject *source_object, GAsyncResult *res, gpointer user_data) +got_secrets(GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMRemoteConnection *remote = NM_REMOTE_CONNECTION (source_object); - GetSecretsData *data = user_data; - gs_unref_variant GVariant *secrets = NULL; + NMRemoteConnection *remote = NM_REMOTE_CONNECTION(source_object); + GetSecretsData * data = user_data; + gs_unref_variant GVariant *secrets = NULL; - secrets = nm_remote_connection_get_secrets_finish (remote, res, NULL); - if (secrets) { - gs_free_error GError *error = NULL; + secrets = nm_remote_connection_get_secrets_finish(remote, res, NULL); + if (secrets) { + gs_free_error GError *error = NULL; - if (!nm_connection_update_secrets (data->local, NULL, secrets, &error) && error) { - g_printerr (_("Error updating secrets for %s: %s\n"), - data->setting_name, error->message); - } - } + if (!nm_connection_update_secrets(data->local, NULL, secrets, &error) && error) { + g_printerr(_("Error updating secrets for %s: %s\n"), + data->setting_name, + error->message); + } + } - g_main_loop_quit (data->loop); + g_main_loop_quit(data->loop); } /* Put secrets into local connection. */ static void -update_secrets_in_connection (NMRemoteConnection *remote, NMConnection *local) -{ - GetSecretsData data = { 0, }; - GType setting_type; - int i; - - data.local = local; - data.loop = g_main_loop_new (NULL, FALSE); - - for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { - setting_type = nm_meta_setting_infos[i].get_setting_gtype(); - if (!nm_connection_get_setting (NM_CONNECTION (remote), setting_type)) - continue; - if (!nm_meta_setting_info_editor_has_secrets (nm_meta_setting_info_editor_find_by_gtype (setting_type))) - continue; - data.setting_name = nm_meta_setting_infos[i].setting_name; - nm_remote_connection_get_secrets_async (remote, - nm_meta_setting_infos[i].setting_name, - NULL, - got_secrets, - &data); - g_main_loop_run (data.loop); - } - - g_main_loop_unref (data.loop); +update_secrets_in_connection(NMRemoteConnection *remote, NMConnection *local) +{ + GetSecretsData data = { + 0, + }; + GType setting_type; + int i; + + data.local = local; + data.loop = g_main_loop_new(NULL, FALSE); + + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + setting_type = nm_meta_setting_infos[i].get_setting_gtype(); + if (!nm_connection_get_setting(NM_CONNECTION(remote), setting_type)) + continue; + if (!nm_meta_setting_info_editor_has_secrets( + nm_meta_setting_info_editor_find_by_gtype(setting_type))) + continue; + data.setting_name = nm_meta_setting_infos[i].setting_name; + nm_remote_connection_get_secrets_async(remote, + nm_meta_setting_infos[i].setting_name, + NULL, + got_secrets, + &data); + g_main_loop_run(data.loop); + } + + g_main_loop_unref(data.loop); } static gboolean -nmc_connection_profile_details (NMConnection *connection, NmCli *nmc) -{ - GError *error = NULL; - GArray *print_settings_array; - GPtrArray *prop_array = NULL; - guint i; - char *fields_str; - char *fields_all = NMC_FIELDS_SETTINGS_NAMES_ALL; - char *fields_common = NMC_FIELDS_SETTINGS_NAMES_ALL; - const char *base_hdr = _("Connection profile details"); - gboolean was_output = FALSE; - - if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) - fields_str = fields_common; - else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) - fields_str = fields_all; - else - fields_str = nmc->required_fields; - - print_settings_array = parse_output_fields (fields_str, (const NMMetaAbstractInfo *const*) nm_meta_setting_infos_editor_p (), - TRUE, &prop_array, &error); - if (error) { - g_string_printf (nmc->return_text, _("Error: 'connection show': %s"), error->message); - g_error_free (error); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - return FALSE; - } - g_assert (print_settings_array); - - /* Main header */ - { - gs_free char *header_name = NULL; - gs_free NmcOutputField *row = NULL; - gs_unref_array GArray *out_indices = NULL; - - header_name = construct_header_name (base_hdr, nm_connection_get_id (connection)); - out_indices = parse_output_fields (NMC_FIELDS_SETTINGS_NAMES_ALL, - (const NMMetaAbstractInfo *const*) nm_meta_setting_infos_editor_p (), - FALSE, NULL, NULL); - - row = g_new0 (NmcOutputField, _NM_META_SETTING_TYPE_NUM + 1); - for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) - row[i].info = (const NMMetaAbstractInfo *) &nm_meta_setting_infos_editor[i]; - - print_required_fields (&nmc->nmc_config, - &nmc->pager_data, - NMC_OF_FLAG_MAIN_HEADER_ONLY, - out_indices, - header_name, - 0, - row); - } - - /* Loop through the required settings and print them. */ - for (i = 0; i < print_settings_array->len; i++) { - NMSetting *setting; - int section_idx = g_array_index (print_settings_array, int, i); - const char *prop_name = (const char *) g_ptr_array_index (prop_array, i); - - if ( NM_IN_SET (nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY) - && !nmc->nmc_config.multiline_output - && was_output) - g_print ("\n"); /* Empty line */ - - was_output = FALSE; - - setting = nm_connection_get_setting_by_name (connection, nm_meta_setting_infos_editor[section_idx].general->setting_name); - if (setting) { - setting_details (&nmc->nmc_config, setting, prop_name); - was_output = TRUE; - } - } - - g_array_free (print_settings_array, TRUE); - if (prop_array) - g_ptr_array_free (prop_array, TRUE); - - return TRUE; +nmc_connection_profile_details(NMConnection *connection, NmCli *nmc) +{ + GError * error = NULL; + GArray * print_settings_array; + GPtrArray * prop_array = NULL; + guint i; + char * fields_str; + char * fields_all = NMC_FIELDS_SETTINGS_NAMES_ALL; + char * fields_common = NMC_FIELDS_SETTINGS_NAMES_ALL; + const char *base_hdr = _("Connection profile details"); + gboolean was_output = FALSE; + + if (!nmc->required_fields || g_ascii_strcasecmp(nmc->required_fields, "common") == 0) + fields_str = fields_common; + else if (!nmc->required_fields || g_ascii_strcasecmp(nmc->required_fields, "all") == 0) + fields_str = fields_all; + else + fields_str = nmc->required_fields; + + print_settings_array = + parse_output_fields(fields_str, + (const NMMetaAbstractInfo *const *) nm_meta_setting_infos_editor_p(), + TRUE, + &prop_array, + &error); + if (error) { + g_string_printf(nmc->return_text, _("Error: 'connection show': %s"), error->message); + g_error_free(error); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + return FALSE; + } + g_assert(print_settings_array); + + /* Main header */ + { + gs_free char *header_name = NULL; + gs_free NmcOutputField *row = NULL; + gs_unref_array GArray *out_indices = NULL; + + header_name = construct_header_name(base_hdr, nm_connection_get_id(connection)); + out_indices = parse_output_fields( + NMC_FIELDS_SETTINGS_NAMES_ALL, + (const NMMetaAbstractInfo *const *) nm_meta_setting_infos_editor_p(), + FALSE, + NULL, + NULL); + + row = g_new0(NmcOutputField, _NM_META_SETTING_TYPE_NUM + 1); + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) + row[i].info = (const NMMetaAbstractInfo *) &nm_meta_setting_infos_editor[i]; + + print_required_fields(&nmc->nmc_config, + &nmc->pager_data, + NMC_OF_FLAG_MAIN_HEADER_ONLY, + out_indices, + header_name, + 0, + row); + } + + /* Loop through the required settings and print them. */ + for (i = 0; i < print_settings_array->len; i++) { + NMSetting * setting; + int section_idx = g_array_index(print_settings_array, int, i); + const char *prop_name = (const char *) g_ptr_array_index(prop_array, i); + + if (NM_IN_SET(nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY) + && !nmc->nmc_config.multiline_output && was_output) + g_print("\n"); /* Empty line */ + + was_output = FALSE; + + setting = nm_connection_get_setting_by_name( + connection, + nm_meta_setting_infos_editor[section_idx].general->setting_name); + if (setting) { + setting_details(&nmc->nmc_config, setting, prop_name); + was_output = TRUE; + } + } + + g_array_free(print_settings_array, TRUE); + if (prop_array) + g_ptr_array_free(prop_array, TRUE); + + return TRUE; } NMMetaColor -nmc_active_connection_state_to_color (NMActiveConnection *ac) +nmc_active_connection_state_to_color(NMActiveConnection *ac) { - NMActiveConnectionState state; + NMActiveConnectionState state; - if (!ac) - return NM_META_COLOR_CONNECTION_UNKNOWN; + if (!ac) + return NM_META_COLOR_CONNECTION_UNKNOWN; - if (NM_FLAGS_HAS (nm_active_connection_get_state_flags (ac), NM_ACTIVATION_STATE_FLAG_EXTERNAL)) - return NM_META_COLOR_CONNECTION_EXTERNAL; + if (NM_FLAGS_HAS(nm_active_connection_get_state_flags(ac), NM_ACTIVATION_STATE_FLAG_EXTERNAL)) + return NM_META_COLOR_CONNECTION_EXTERNAL; - state = nm_active_connection_get_state (ac); + state = nm_active_connection_get_state(ac); - if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) - return NM_META_COLOR_CONNECTION_ACTIVATING; - else if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) - return NM_META_COLOR_CONNECTION_ACTIVATED; - else if (state > NM_ACTIVE_CONNECTION_STATE_ACTIVATED) - return NM_META_COLOR_CONNECTION_DISCONNECTING; - else - return NM_META_COLOR_CONNECTION_UNKNOWN; + if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) + return NM_META_COLOR_CONNECTION_ACTIVATING; + else if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) + return NM_META_COLOR_CONNECTION_ACTIVATED; + else if (state > NM_ACTIVE_CONNECTION_STATE_ACTIVATED) + return NM_META_COLOR_CONNECTION_DISCONNECTING; + else + return NM_META_COLOR_CONNECTION_UNKNOWN; } static gboolean -nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc) -{ - GError *error = NULL; - GArray *print_groups; - GPtrArray *group_fields = NULL; - int i; - const char *fields_str = NULL; - const char *base_hdr = _("Activate connection details"); - gboolean was_output = FALSE; - - if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) { - /* pass */ - } else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) { - /* pass */ - } else - fields_str = nmc->required_fields; - - print_groups = parse_output_fields (fields_str, (const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_groups, TRUE, &group_fields, &error); - if (error) { - g_string_printf (nmc->return_text, _("Error: 'connection show': %s"), error->message); - g_error_free (error); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - return FALSE; - } - g_assert (print_groups); - - /* Main header */ - { - gs_free char *header_name = NULL; - gs_free NmcOutputField *row = NULL; - gs_unref_array GArray *out_indices = NULL; - - header_name = construct_header_name (base_hdr, nm_active_connection_get_uuid (acon)); - out_indices = parse_output_fields (NULL, - (const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_groups, - FALSE, NULL, NULL); - - row = g_new0 (NmcOutputField, G_N_ELEMENTS (nmc_fields_con_active_details_groups) + 1); - for (i = 0; nmc_fields_con_active_details_groups[i]; i++) - row[i].info = (const NMMetaAbstractInfo *) nmc_fields_con_active_details_groups[i]; - - print_required_fields (&nmc->nmc_config, - &nmc->pager_data, - NMC_OF_FLAG_MAIN_HEADER_ONLY, - out_indices, - header_name, - 0, - row); - } - - /* Loop through the groups and print them. */ - for (i = 0; i < print_groups->len; i++) { - int group_idx = g_array_index (print_groups, int, i); - char *group_fld = (char *) g_ptr_array_index (group_fields, i); - - if ( NM_IN_SET (nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY) - && !nmc->nmc_config.multiline_output - && was_output) - g_print ("\n"); - - was_output = FALSE; - - if (nmc_fields_con_active_details_groups[group_idx]->nested == metagen_con_active_general) { - gs_free char *f = NULL; - - if (group_fld) - f = g_strdup_printf ("GENERAL.%s", group_fld); - - nmc_print (&nmc->nmc_config, - (gpointer[]) { acon, NULL }, - NULL, - NULL, - NMC_META_GENERIC_GROUP ("GENERAL", metagen_con_active_general, N_("GROUP")), - f, - NULL); - was_output = TRUE; - continue; - } - - /* IP4 */ - if (g_ascii_strcasecmp (nmc_fields_con_active_details_groups[group_idx]->name, nmc_fields_con_active_details_groups[1]->name) == 0) { - gboolean b1 = FALSE; - NMIPConfig *cfg4 = nm_active_connection_get_ip4_config (acon); - - b1 = print_ip_config (cfg4, AF_INET, &nmc->nmc_config, group_fld); - was_output = was_output || b1; - } - - /* DHCP4 */ - if (g_ascii_strcasecmp (nmc_fields_con_active_details_groups[group_idx]->name, nmc_fields_con_active_details_groups[2]->name) == 0) { - gboolean b1 = FALSE; - NMDhcpConfig *dhcp4 = nm_active_connection_get_dhcp4_config (acon); - - b1 = print_dhcp_config (dhcp4, AF_INET, &nmc->nmc_config, group_fld); - was_output = was_output || b1; - } - - /* IP6 */ - if (g_ascii_strcasecmp (nmc_fields_con_active_details_groups[group_idx]->name, nmc_fields_con_active_details_groups[3]->name) == 0) { - gboolean b1 = FALSE; - NMIPConfig *cfg6 = nm_active_connection_get_ip6_config (acon); - - b1 = print_ip_config (cfg6, AF_INET6, &nmc->nmc_config, group_fld); - was_output = was_output || b1; - } - - /* DHCP6 */ - if (g_ascii_strcasecmp (nmc_fields_con_active_details_groups[group_idx]->name, nmc_fields_con_active_details_groups[4]->name) == 0) { - gboolean b1 = FALSE; - NMDhcpConfig *dhcp6 = nm_active_connection_get_dhcp6_config (acon); - - b1 = print_dhcp_config (dhcp6, AF_INET6, &nmc->nmc_config, group_fld); - was_output = was_output || b1; - } - - if (nmc_fields_con_active_details_groups[group_idx]->nested == metagen_con_active_vpn) { - if (NM_IS_VPN_CONNECTION (acon)) { - nmc_print (&nmc->nmc_config, - (gpointer[]) { acon, NULL }, - NULL, - NULL, - NMC_META_GENERIC_GROUP ("VPN", metagen_con_active_vpn, N_("NAME")), - group_fld, - NULL); - was_output = TRUE; - } - continue; - } - } - - g_array_free (print_groups, TRUE); - if (group_fields) - g_ptr_array_free (group_fields, TRUE); - - return TRUE; +nmc_active_connection_details(NMActiveConnection *acon, NmCli *nmc) +{ + GError * error = NULL; + GArray * print_groups; + GPtrArray * group_fields = NULL; + int i; + const char *fields_str = NULL; + const char *base_hdr = _("Activate connection details"); + gboolean was_output = FALSE; + + if (!nmc->required_fields || g_ascii_strcasecmp(nmc->required_fields, "common") == 0) { + /* pass */ + } else if (!nmc->required_fields || g_ascii_strcasecmp(nmc->required_fields, "all") == 0) { + /* pass */ + } else + fields_str = nmc->required_fields; + + print_groups = parse_output_fields( + fields_str, + (const NMMetaAbstractInfo *const *) nmc_fields_con_active_details_groups, + TRUE, + &group_fields, + &error); + if (error) { + g_string_printf(nmc->return_text, _("Error: 'connection show': %s"), error->message); + g_error_free(error); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + return FALSE; + } + g_assert(print_groups); + + /* Main header */ + { + gs_free char *header_name = NULL; + gs_free NmcOutputField *row = NULL; + gs_unref_array GArray *out_indices = NULL; + + header_name = construct_header_name(base_hdr, nm_active_connection_get_uuid(acon)); + out_indices = parse_output_fields( + NULL, + (const NMMetaAbstractInfo *const *) nmc_fields_con_active_details_groups, + FALSE, + NULL, + NULL); + + row = g_new0(NmcOutputField, G_N_ELEMENTS(nmc_fields_con_active_details_groups) + 1); + for (i = 0; nmc_fields_con_active_details_groups[i]; i++) + row[i].info = (const NMMetaAbstractInfo *) nmc_fields_con_active_details_groups[i]; + + print_required_fields(&nmc->nmc_config, + &nmc->pager_data, + NMC_OF_FLAG_MAIN_HEADER_ONLY, + out_indices, + header_name, + 0, + row); + } + + /* Loop through the groups and print them. */ + for (i = 0; i < print_groups->len; i++) { + int group_idx = g_array_index(print_groups, int, i); + char *group_fld = (char *) g_ptr_array_index(group_fields, i); + + if (NM_IN_SET(nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY) + && !nmc->nmc_config.multiline_output && was_output) + g_print("\n"); + + was_output = FALSE; + + if (nmc_fields_con_active_details_groups[group_idx]->nested == metagen_con_active_general) { + gs_free char *f = NULL; + + if (group_fld) + f = g_strdup_printf("GENERAL.%s", group_fld); + + nmc_print(&nmc->nmc_config, + (gpointer[]){acon, NULL}, + NULL, + NULL, + NMC_META_GENERIC_GROUP("GENERAL", metagen_con_active_general, N_("GROUP")), + f, + NULL); + was_output = TRUE; + continue; + } + + /* IP4 */ + if (g_ascii_strcasecmp(nmc_fields_con_active_details_groups[group_idx]->name, + nmc_fields_con_active_details_groups[1]->name) + == 0) { + gboolean b1 = FALSE; + NMIPConfig *cfg4 = nm_active_connection_get_ip4_config(acon); + + b1 = print_ip_config(cfg4, AF_INET, &nmc->nmc_config, group_fld); + was_output = was_output || b1; + } + + /* DHCP4 */ + if (g_ascii_strcasecmp(nmc_fields_con_active_details_groups[group_idx]->name, + nmc_fields_con_active_details_groups[2]->name) + == 0) { + gboolean b1 = FALSE; + NMDhcpConfig *dhcp4 = nm_active_connection_get_dhcp4_config(acon); + + b1 = print_dhcp_config(dhcp4, AF_INET, &nmc->nmc_config, group_fld); + was_output = was_output || b1; + } + + /* IP6 */ + if (g_ascii_strcasecmp(nmc_fields_con_active_details_groups[group_idx]->name, + nmc_fields_con_active_details_groups[3]->name) + == 0) { + gboolean b1 = FALSE; + NMIPConfig *cfg6 = nm_active_connection_get_ip6_config(acon); + + b1 = print_ip_config(cfg6, AF_INET6, &nmc->nmc_config, group_fld); + was_output = was_output || b1; + } + + /* DHCP6 */ + if (g_ascii_strcasecmp(nmc_fields_con_active_details_groups[group_idx]->name, + nmc_fields_con_active_details_groups[4]->name) + == 0) { + gboolean b1 = FALSE; + NMDhcpConfig *dhcp6 = nm_active_connection_get_dhcp6_config(acon); + + b1 = print_dhcp_config(dhcp6, AF_INET6, &nmc->nmc_config, group_fld); + was_output = was_output || b1; + } + + if (nmc_fields_con_active_details_groups[group_idx]->nested == metagen_con_active_vpn) { + if (NM_IS_VPN_CONNECTION(acon)) { + nmc_print(&nmc->nmc_config, + (gpointer[]){acon, NULL}, + NULL, + NULL, + NMC_META_GENERIC_GROUP("VPN", metagen_con_active_vpn, N_("NAME")), + group_fld, + NULL); + was_output = TRUE; + } + continue; + } + } + + g_array_free(print_groups, TRUE); + if (group_fields) + g_ptr_array_free(group_fields, TRUE); + + return TRUE; } static gboolean -split_required_fields_for_con_show (const char *input, - char **profile_flds, - char **active_flds, - GError **error) -{ - gs_free const char **fields = NULL; - const char *const*iter; - nm_auto_free_gstring GString *str1 = NULL; - nm_auto_free_gstring GString *str2 = NULL; - gboolean group_profile = FALSE; - gboolean group_active = FALSE; - gboolean do_free; - - if (!input) { - *profile_flds = NULL; - *active_flds = NULL; - return TRUE; - } - - str1 = g_string_new (NULL); - str2 = g_string_new (NULL); - - fields = nm_utils_strsplit_set_with_empty (input, ","); - for (iter = fields; iter && *iter; iter++) { - char *s_mutable = (char *) (*iter); - char *dot; - gboolean is_all; - gboolean is_common; - gboolean found; - int i; - - g_strstrip (s_mutable); - dot = strchr (s_mutable, '.'); - if (dot) - *dot = '\0'; - - is_all = !dot && g_ascii_strcasecmp (s_mutable, "all") == 0; - is_common = !dot && g_ascii_strcasecmp (s_mutable, "common") == 0; - - found = FALSE; - for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { - if ( is_all || is_common - || !g_ascii_strcasecmp (s_mutable, nm_meta_setting_infos[i].setting_name)) { - if (dot) - *dot = '.'; - g_string_append (str1, s_mutable); - g_string_append_c (str1, ','); - found = TRUE; - break; - } - } - if (found) - continue; - - for (i = 0; nmc_fields_con_active_details_groups[i]; i++) { - if ( is_all || is_common - || !g_ascii_strcasecmp (s_mutable, nmc_fields_con_active_details_groups[i]->name)) { - if (dot) - *dot = '.'; - g_string_append (str2, s_mutable); - g_string_append_c (str2, ','); - found = TRUE; - break; - } - } - if (!found) { - if (dot) - *dot = '.'; - if (!g_ascii_strcasecmp (s_mutable, CON_SHOW_DETAIL_GROUP_PROFILE)) - group_profile = TRUE; - else if (!g_ascii_strcasecmp (s_mutable, CON_SHOW_DETAIL_GROUP_ACTIVE)) - group_active = TRUE; - else { - gs_free char *allowed1 = nm_meta_abstract_infos_get_names_str ((const NMMetaAbstractInfo *const*) nm_meta_setting_infos_editor_p (), NULL); - gs_free char *allowed2 = nm_meta_abstract_infos_get_names_str ((const NMMetaAbstractInfo *const*) nmc_fields_con_active_details_groups, NULL); - - g_set_error (error, NMCLI_ERROR, 0, _("invalid field '%s'; allowed fields: %s and %s, or %s,%s"), - s_mutable, allowed1, allowed2, CON_SHOW_DETAIL_GROUP_PROFILE, CON_SHOW_DETAIL_GROUP_ACTIVE); - return FALSE; - } - } - } - - /* Handle pseudo groups: profile, active */ - if (group_profile) { - if (str1->len > 0) { - g_set_error (error, NMCLI_ERROR, 0, _("'%s' has to be alone"), - CON_SHOW_DETAIL_GROUP_PROFILE); - return FALSE; - } - g_string_assign (str1, "all,"); - } - if (group_active) { - if (str2->len > 0) { - g_set_error (error, NMCLI_ERROR, 0, _("'%s' has to be alone"), - CON_SHOW_DETAIL_GROUP_ACTIVE); - return FALSE; - } - g_string_assign (str2, "all,"); - } - - if (str1->len > 0) - g_string_truncate (str1, str1->len - 1); - if (str2->len > 0) - g_string_truncate (str2, str2->len - 1); - - do_free = (str1->len == 0); - *profile_flds = g_string_free (g_steal_pointer (&str1), do_free); - do_free = (str2->len == 0); - *active_flds = g_string_free (g_steal_pointer (&str2), do_free); - return TRUE; +split_required_fields_for_con_show(const char *input, + char ** profile_flds, + char ** active_flds, + GError ** error) +{ + gs_free const char **fields = NULL; + const char *const * iter; + nm_auto_free_gstring GString *str1 = NULL; + nm_auto_free_gstring GString *str2 = NULL; + gboolean group_profile = FALSE; + gboolean group_active = FALSE; + gboolean do_free; + + if (!input) { + *profile_flds = NULL; + *active_flds = NULL; + return TRUE; + } + + str1 = g_string_new(NULL); + str2 = g_string_new(NULL); + + fields = nm_utils_strsplit_set_with_empty(input, ","); + for (iter = fields; iter && *iter; iter++) { + char * s_mutable = (char *) (*iter); + char * dot; + gboolean is_all; + gboolean is_common; + gboolean found; + int i; + + g_strstrip(s_mutable); + dot = strchr(s_mutable, '.'); + if (dot) + *dot = '\0'; + + is_all = !dot && g_ascii_strcasecmp(s_mutable, "all") == 0; + is_common = !dot && g_ascii_strcasecmp(s_mutable, "common") == 0; + + found = FALSE; + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + if (is_all || is_common + || !g_ascii_strcasecmp(s_mutable, nm_meta_setting_infos[i].setting_name)) { + if (dot) + *dot = '.'; + g_string_append(str1, s_mutable); + g_string_append_c(str1, ','); + found = TRUE; + break; + } + } + if (found) + continue; + + for (i = 0; nmc_fields_con_active_details_groups[i]; i++) { + if (is_all || is_common + || !g_ascii_strcasecmp(s_mutable, nmc_fields_con_active_details_groups[i]->name)) { + if (dot) + *dot = '.'; + g_string_append(str2, s_mutable); + g_string_append_c(str2, ','); + found = TRUE; + break; + } + } + if (!found) { + if (dot) + *dot = '.'; + if (!g_ascii_strcasecmp(s_mutable, CON_SHOW_DETAIL_GROUP_PROFILE)) + group_profile = TRUE; + else if (!g_ascii_strcasecmp(s_mutable, CON_SHOW_DETAIL_GROUP_ACTIVE)) + group_active = TRUE; + else { + gs_free char *allowed1 = nm_meta_abstract_infos_get_names_str( + (const NMMetaAbstractInfo *const *) nm_meta_setting_infos_editor_p(), + NULL); + gs_free char *allowed2 = nm_meta_abstract_infos_get_names_str( + (const NMMetaAbstractInfo *const *) nmc_fields_con_active_details_groups, + NULL); + + g_set_error(error, + NMCLI_ERROR, + 0, + _("invalid field '%s'; allowed fields: %s and %s, or %s,%s"), + s_mutable, + allowed1, + allowed2, + CON_SHOW_DETAIL_GROUP_PROFILE, + CON_SHOW_DETAIL_GROUP_ACTIVE); + return FALSE; + } + } + } + + /* Handle pseudo groups: profile, active */ + if (group_profile) { + if (str1->len > 0) { + g_set_error(error, + NMCLI_ERROR, + 0, + _("'%s' has to be alone"), + CON_SHOW_DETAIL_GROUP_PROFILE); + return FALSE; + } + g_string_assign(str1, "all,"); + } + if (group_active) { + if (str2->len > 0) { + g_set_error(error, + NMCLI_ERROR, + 0, + _("'%s' has to be alone"), + CON_SHOW_DETAIL_GROUP_ACTIVE); + return FALSE; + } + g_string_assign(str2, "all,"); + } + + if (str1->len > 0) + g_string_truncate(str1, str1->len - 1); + if (str2->len > 0) + g_string_truncate(str2, str2->len - 1); + + do_free = (str1->len == 0); + *profile_flds = g_string_free(g_steal_pointer(&str1), do_free); + do_free = (str2->len == 0); + *active_flds = g_string_free(g_steal_pointer(&str2), do_free); + return TRUE; } typedef enum { - NMC_SORT_ACTIVE = 1, - NMC_SORT_ACTIVE_INV = -1, - NMC_SORT_NAME = 2, - NMC_SORT_NAME_INV = -2, - NMC_SORT_TYPE = 3, - NMC_SORT_TYPE_INV = -3, - NMC_SORT_PATH = 4, - NMC_SORT_PATH_INV = -4, + NMC_SORT_ACTIVE = 1, + NMC_SORT_ACTIVE_INV = -1, + NMC_SORT_NAME = 2, + NMC_SORT_NAME_INV = -2, + NMC_SORT_TYPE = 3, + NMC_SORT_TYPE_INV = -3, + NMC_SORT_PATH = 4, + NMC_SORT_PATH_INV = -4, } NmcSortOrder; typedef struct { - NmCli *nmc; - const GArray *order; - gboolean show_active_fields; + NmCli * nmc; + const GArray *order; + gboolean show_active_fields; } ConShowSortInfo; static int -con_show_get_items_cmp (gconstpointer pa, gconstpointer pb, gpointer user_data) -{ - const ConShowSortInfo *sort_info = user_data; - const MetagenConShowRowData *row_data_a = *((const MetagenConShowRowData *const*) pa); - const MetagenConShowRowData *row_data_b = *((const MetagenConShowRowData *const*) pb); - NMConnection *c_a = row_data_a->connection; - NMConnection *c_b = row_data_b->connection; - NMActiveConnection *ac_a = row_data_a->primary_active; - NMActiveConnection *ac_b = row_data_b->primary_active; - NMActiveConnection *ac_a_effective = sort_info->show_active_fields ? ac_a : NULL; - NMActiveConnection *ac_b_effective = sort_info->show_active_fields ? ac_b : NULL; - - /* first sort active-connections which are invisible, i.e. that have no connection */ - if (!c_a && c_b) - return -1; - if (!c_b && c_a) - return 1; - - /* we have two connections... */ - if (c_a && c_b && c_a != c_b) { - const NmcSortOrder *order_arr; - guint i, order_len; - NMMetaAccessorGetType get_type = nmc_print_output_to_accessor_get_type (sort_info->nmc->nmc_config.print_output); - - if (sort_info->order) { - order_arr = &g_array_index (sort_info->order, NmcSortOrder, 0); - order_len = sort_info->order->len; - } else { - static const NmcSortOrder def[] = { NMC_SORT_ACTIVE, NMC_SORT_NAME, NMC_SORT_PATH }; - - /* Note: the default order does not consider whether a column is shown. - * That means, the selection of the output fields, does not affect the - * order (although there could be an argument that it should). */ - order_arr = def; - order_len = G_N_ELEMENTS (def); - } - - for (i = 0; i < order_len; i++) { - NmcSortOrder item = order_arr[i]; - - switch (item) { - - case NMC_SORT_ACTIVE: - NM_CMP_RETURN (nmc_active_connection_cmp (ac_b, ac_a)); - break; - case NMC_SORT_ACTIVE_INV: - NM_CMP_RETURN (nmc_active_connection_cmp (ac_a, ac_b)); - break; - - case NMC_SORT_TYPE: - NM_CMP_DIRECT_STRCMP0 (_con_show_fcn_get_type (c_a, ac_a_effective, get_type), - _con_show_fcn_get_type (c_b, ac_b_effective, get_type)); - break; - case NMC_SORT_TYPE_INV: - NM_CMP_DIRECT_STRCMP0 (_con_show_fcn_get_type (c_b, ac_b_effective, get_type), - _con_show_fcn_get_type (c_a, ac_a_effective, get_type)); - break; - - case NMC_SORT_NAME: - NM_CMP_RETURN (nm_utf8_collate0 (_con_show_fcn_get_id (c_a, ac_a_effective), - _con_show_fcn_get_id (c_b, ac_b_effective))); - break; - case NMC_SORT_NAME_INV: - NM_CMP_RETURN (nm_utf8_collate0 (_con_show_fcn_get_id (c_b, ac_b_effective), - _con_show_fcn_get_id (c_a, ac_a_effective))); - break; - - case NMC_SORT_PATH: - NM_CMP_RETURN (nm_utils_dbus_path_cmp (nm_connection_get_path (c_a), nm_connection_get_path (c_b))); - break; - - case NMC_SORT_PATH_INV: - NM_CMP_RETURN (nm_utils_dbus_path_cmp (nm_connection_get_path (c_b), nm_connection_get_path (c_a))); - break; - - default: - nm_assert_not_reached (); - break; - } - } - - NM_CMP_DIRECT_STRCMP0 (nm_connection_get_uuid (c_a), - nm_connection_get_uuid (c_b)); - NM_CMP_DIRECT_STRCMP0 (nm_connection_get_path (c_a), - nm_connection_get_path (c_b)); - } - - NM_CMP_DIRECT_STRCMP0 (nm_object_get_path (NM_OBJECT (ac_a)), - nm_object_get_path (NM_OBJECT (ac_b))); - - g_return_val_if_reached (0); +con_show_get_items_cmp(gconstpointer pa, gconstpointer pb, gpointer user_data) +{ + const ConShowSortInfo * sort_info = user_data; + const MetagenConShowRowData *row_data_a = *((const MetagenConShowRowData *const *) pa); + const MetagenConShowRowData *row_data_b = *((const MetagenConShowRowData *const *) pb); + NMConnection * c_a = row_data_a->connection; + NMConnection * c_b = row_data_b->connection; + NMActiveConnection * ac_a = row_data_a->primary_active; + NMActiveConnection * ac_b = row_data_b->primary_active; + NMActiveConnection * ac_a_effective = sort_info->show_active_fields ? ac_a : NULL; + NMActiveConnection * ac_b_effective = sort_info->show_active_fields ? ac_b : NULL; + + /* first sort active-connections which are invisible, i.e. that have no connection */ + if (!c_a && c_b) + return -1; + if (!c_b && c_a) + return 1; + + /* we have two connections... */ + if (c_a && c_b && c_a != c_b) { + const NmcSortOrder * order_arr; + guint i, order_len; + NMMetaAccessorGetType get_type = + nmc_print_output_to_accessor_get_type(sort_info->nmc->nmc_config.print_output); + + if (sort_info->order) { + order_arr = &g_array_index(sort_info->order, NmcSortOrder, 0); + order_len = sort_info->order->len; + } else { + static const NmcSortOrder def[] = {NMC_SORT_ACTIVE, NMC_SORT_NAME, NMC_SORT_PATH}; + + /* Note: the default order does not consider whether a column is shown. + * That means, the selection of the output fields, does not affect the + * order (although there could be an argument that it should). */ + order_arr = def; + order_len = G_N_ELEMENTS(def); + } + + for (i = 0; i < order_len; i++) { + NmcSortOrder item = order_arr[i]; + + switch (item) { + case NMC_SORT_ACTIVE: + NM_CMP_RETURN(nmc_active_connection_cmp(ac_b, ac_a)); + break; + case NMC_SORT_ACTIVE_INV: + NM_CMP_RETURN(nmc_active_connection_cmp(ac_a, ac_b)); + break; + + case NMC_SORT_TYPE: + NM_CMP_DIRECT_STRCMP0(_con_show_fcn_get_type(c_a, ac_a_effective, get_type), + _con_show_fcn_get_type(c_b, ac_b_effective, get_type)); + break; + case NMC_SORT_TYPE_INV: + NM_CMP_DIRECT_STRCMP0(_con_show_fcn_get_type(c_b, ac_b_effective, get_type), + _con_show_fcn_get_type(c_a, ac_a_effective, get_type)); + break; + + case NMC_SORT_NAME: + NM_CMP_RETURN(nm_utf8_collate0(_con_show_fcn_get_id(c_a, ac_a_effective), + _con_show_fcn_get_id(c_b, ac_b_effective))); + break; + case NMC_SORT_NAME_INV: + NM_CMP_RETURN(nm_utf8_collate0(_con_show_fcn_get_id(c_b, ac_b_effective), + _con_show_fcn_get_id(c_a, ac_a_effective))); + break; + + case NMC_SORT_PATH: + NM_CMP_RETURN(nm_utils_dbus_path_cmp(nm_connection_get_path(c_a), + nm_connection_get_path(c_b))); + break; + + case NMC_SORT_PATH_INV: + NM_CMP_RETURN(nm_utils_dbus_path_cmp(nm_connection_get_path(c_b), + nm_connection_get_path(c_a))); + break; + + default: + nm_assert_not_reached(); + break; + } + } + + NM_CMP_DIRECT_STRCMP0(nm_connection_get_uuid(c_a), nm_connection_get_uuid(c_b)); + NM_CMP_DIRECT_STRCMP0(nm_connection_get_path(c_a), nm_connection_get_path(c_b)); + } + + NM_CMP_DIRECT_STRCMP0(nm_object_get_path(NM_OBJECT(ac_a)), nm_object_get_path(NM_OBJECT(ac_b))); + + g_return_val_if_reached(0); } static GPtrArray * -con_show_get_items (NmCli *nmc, gboolean active_only, gboolean show_active_fields, GArray *order) -{ - gs_unref_hashtable GHashTable *row_hash = NULL; - GHashTableIter hiter; - GPtrArray *result; - const GPtrArray *arr; - NMRemoteConnection *c; - MetagenConShowRowData *row_data; - guint i; - const ConShowSortInfo sort_info = { - .nmc = nmc, - .order = order, - .show_active_fields = show_active_fields, - }; - - row_hash = g_hash_table_new (nm_direct_hash, NULL); - - arr = nm_client_get_connections (nmc->client); - for (i = 0; i < arr->len; i++) { - /* Note: libnm will not expose connection that are invisible - * to the user but currently inactive. - * - * That differs from get-active-connection(). If an invisible connection - * is active, we can get its NMActiveConnection. We can even obtain - * the corresponding NMRemoteConnection (although, of course it has - * no visible settings). - * - * I think this inconsistency is a bug in libnm. Anyway, the result is, - * that we print invisible connections if they are active, but otherwise - * we exclude them. */ - c = arr->pdata[i]; - g_hash_table_insert (row_hash, - c, - _metagen_con_show_row_data_new_for_connection (c, - show_active_fields)); - } - - arr = nm_client_get_active_connections (nmc->client); - for (i = 0; i < arr->len; i++) { - NMActiveConnection *ac = arr->pdata[i]; - - c = nm_active_connection_get_connection (ac); - if (!show_active_fields && !c) { - /* the active connection has no connection, and we don't show - * any active fields. Skip this row. */ - continue; - } - - row_data = c - ? g_hash_table_lookup (row_hash, c) - : NULL; - - if (show_active_fields || !c) { - /* the active connection either has no connection (in which we create a - * connection-less row), or we are interested in showing each active - * connection in its own row. Add a row. */ - if (row_data) { - /* we create a rowdata for this connection earlier. We drop it, because this - * connection is tracked via the rowdata of the active connection. */ - g_hash_table_remove (row_hash, c); - _metagen_con_show_row_data_destroy (row_data); - } - row_data = _metagen_con_show_row_data_new_for_active_connection (c, ac, show_active_fields); - g_hash_table_insert (row_hash, ac, row_data); - continue; - } - - /* we add the active connection to the row for the referenced - * connection. We need to group them this way, to print the proper - * color (activated or not) based on primary_active. */ - if (!row_data) { - /* this is unexpected. The active connection references a connection that - * seemingly no longer exists. It's a bug in libnm. Add a row nonetheless. */ - row_data = _metagen_con_show_row_data_new_for_connection (c, show_active_fields); - g_hash_table_insert (row_hash, c, row_data); - } - _metagen_con_show_row_data_add_active_connection (row_data, ac); - } - - result = g_ptr_array_new_with_free_func (_metagen_con_show_row_data_destroy); - - g_hash_table_iter_init (&hiter, row_hash); - while (g_hash_table_iter_next (&hiter, NULL, (gpointer *) &row_data)) { - if ( active_only - && !row_data->primary_active) { - /* We only print connections that are active. Skip this row. */ - _metagen_con_show_row_data_destroy (row_data); - continue; - } - if (!show_active_fields) { - NMSettingConnection *s_con; - - nm_assert (NM_IS_REMOTE_CONNECTION (row_data->connection)); - s_con = nm_connection_get_setting_connection (row_data->connection); - if ( !s_con - || !nm_setting_connection_get_uuid (s_con)) { - /* we are in a mode, where we only print rows for connection. - * For that we require that all rows are visible to the user, - * meaning: the have a [connection] setting and a UUID. - * - * Otherwise, this connection is likely invisible to the user. - * Skip it. */ - _metagen_con_show_row_data_destroy (row_data); - continue; - } - _metagen_con_show_row_data_init_primary_active (row_data); - } else - nm_assert (!row_data->all_active); - g_ptr_array_add (result, row_data); - } - - g_ptr_array_sort_with_data (result, con_show_get_items_cmp, (gpointer) &sort_info); - return result; +con_show_get_items(NmCli *nmc, gboolean active_only, gboolean show_active_fields, GArray *order) +{ + gs_unref_hashtable GHashTable *row_hash = NULL; + GHashTableIter hiter; + GPtrArray * result; + const GPtrArray * arr; + NMRemoteConnection * c; + MetagenConShowRowData * row_data; + guint i; + const ConShowSortInfo sort_info = { + .nmc = nmc, + .order = order, + .show_active_fields = show_active_fields, + }; + + row_hash = g_hash_table_new(nm_direct_hash, NULL); + + arr = nm_client_get_connections(nmc->client); + for (i = 0; i < arr->len; i++) { + /* Note: libnm will not expose connection that are invisible + * to the user but currently inactive. + * + * That differs from get-active-connection(). If an invisible connection + * is active, we can get its NMActiveConnection. We can even obtain + * the corresponding NMRemoteConnection (although, of course it has + * no visible settings). + * + * I think this inconsistency is a bug in libnm. Anyway, the result is, + * that we print invisible connections if they are active, but otherwise + * we exclude them. */ + c = arr->pdata[i]; + g_hash_table_insert(row_hash, + c, + _metagen_con_show_row_data_new_for_connection(c, show_active_fields)); + } + + arr = nm_client_get_active_connections(nmc->client); + for (i = 0; i < arr->len; i++) { + NMActiveConnection *ac = arr->pdata[i]; + + c = nm_active_connection_get_connection(ac); + if (!show_active_fields && !c) { + /* the active connection has no connection, and we don't show + * any active fields. Skip this row. */ + continue; + } + + row_data = c ? g_hash_table_lookup(row_hash, c) : NULL; + + if (show_active_fields || !c) { + /* the active connection either has no connection (in which we create a + * connection-less row), or we are interested in showing each active + * connection in its own row. Add a row. */ + if (row_data) { + /* we create a rowdata for this connection earlier. We drop it, because this + * connection is tracked via the rowdata of the active connection. */ + g_hash_table_remove(row_hash, c); + _metagen_con_show_row_data_destroy(row_data); + } + row_data = + _metagen_con_show_row_data_new_for_active_connection(c, ac, show_active_fields); + g_hash_table_insert(row_hash, ac, row_data); + continue; + } + + /* we add the active connection to the row for the referenced + * connection. We need to group them this way, to print the proper + * color (activated or not) based on primary_active. */ + if (!row_data) { + /* this is unexpected. The active connection references a connection that + * seemingly no longer exists. It's a bug in libnm. Add a row nonetheless. */ + row_data = _metagen_con_show_row_data_new_for_connection(c, show_active_fields); + g_hash_table_insert(row_hash, c, row_data); + } + _metagen_con_show_row_data_add_active_connection(row_data, ac); + } + + result = g_ptr_array_new_with_free_func(_metagen_con_show_row_data_destroy); + + g_hash_table_iter_init(&hiter, row_hash); + while (g_hash_table_iter_next(&hiter, NULL, (gpointer *) &row_data)) { + if (active_only && !row_data->primary_active) { + /* We only print connections that are active. Skip this row. */ + _metagen_con_show_row_data_destroy(row_data); + continue; + } + if (!show_active_fields) { + NMSettingConnection *s_con; + + nm_assert(NM_IS_REMOTE_CONNECTION(row_data->connection)); + s_con = nm_connection_get_setting_connection(row_data->connection); + if (!s_con || !nm_setting_connection_get_uuid(s_con)) { + /* we are in a mode, where we only print rows for connection. + * For that we require that all rows are visible to the user, + * meaning: the have a [connection] setting and a UUID. + * + * Otherwise, this connection is likely invisible to the user. + * Skip it. */ + _metagen_con_show_row_data_destroy(row_data); + continue; + } + _metagen_con_show_row_data_init_primary_active(row_data); + } else + nm_assert(!row_data->all_active); + g_ptr_array_add(result, row_data); + } + + g_ptr_array_sort_with_data(result, con_show_get_items_cmp, (gpointer) &sort_info); + return result; } static GArray * -parse_preferred_connection_order (const char *order, GError **error) -{ - gs_free const char **strv = NULL; - const char *const*iter; - const char *str; - GArray *order_arr; - NmcSortOrder val; - gboolean inverse, unique; - guint i; - - strv = nm_utils_strsplit_set (order, ":"); - if (!strv) { - g_set_error (error, NMCLI_ERROR, 0, - _("incorrect string '%s' of '--order' option"), order); - return NULL; - } - - order_arr = g_array_sized_new (FALSE, FALSE, sizeof (NmcSortOrder), 4); - for (iter = strv; iter && *iter; iter++) { - str = *iter; - inverse = FALSE; - if (str[0] == '-') - inverse = TRUE; - if (str[0] == '+' || str[0] == '-') - str++; - - if (matches (str, "active")) - val = inverse ? NMC_SORT_ACTIVE_INV : NMC_SORT_ACTIVE; - else if (matches (str, "name")) - val = inverse ? NMC_SORT_NAME_INV : NMC_SORT_NAME; - else if (matches (str, "type")) - val = inverse ? NMC_SORT_TYPE_INV : NMC_SORT_TYPE; - else if (matches (str, "path")) - val = inverse ? NMC_SORT_PATH_INV : NMC_SORT_PATH; - else { - g_array_unref (order_arr); - order_arr = NULL; - g_set_error (error, NMCLI_ERROR, 0, - _("incorrect item '%s' in '--order' option"), *iter); - break; - } - /* Check for duplicates and ignore them. */ - unique = TRUE; - for (i = 0; i < order_arr->len; i++) { - if (abs (g_array_index (order_arr, NmcSortOrder, i)) - abs (val) == 0) { - unique = FALSE; - break; - } - } - - /* Value is ok and unique, add it to the array */ - if (unique) - g_array_append_val (order_arr, val); - } - - return order_arr; +parse_preferred_connection_order(const char *order, GError **error) +{ + gs_free const char **strv = NULL; + const char *const * iter; + const char * str; + GArray * order_arr; + NmcSortOrder val; + gboolean inverse, unique; + guint i; + + strv = nm_utils_strsplit_set(order, ":"); + if (!strv) { + g_set_error(error, NMCLI_ERROR, 0, _("incorrect string '%s' of '--order' option"), order); + return NULL; + } + + order_arr = g_array_sized_new(FALSE, FALSE, sizeof(NmcSortOrder), 4); + for (iter = strv; iter && *iter; iter++) { + str = *iter; + inverse = FALSE; + if (str[0] == '-') + inverse = TRUE; + if (str[0] == '+' || str[0] == '-') + str++; + + if (matches(str, "active")) + val = inverse ? NMC_SORT_ACTIVE_INV : NMC_SORT_ACTIVE; + else if (matches(str, "name")) + val = inverse ? NMC_SORT_NAME_INV : NMC_SORT_NAME; + else if (matches(str, "type")) + val = inverse ? NMC_SORT_TYPE_INV : NMC_SORT_TYPE; + else if (matches(str, "path")) + val = inverse ? NMC_SORT_PATH_INV : NMC_SORT_PATH; + else { + g_array_unref(order_arr); + order_arr = NULL; + g_set_error(error, NMCLI_ERROR, 0, _("incorrect item '%s' in '--order' option"), *iter); + break; + } + /* Check for duplicates and ignore them. */ + unique = TRUE; + for (i = 0; i < order_arr->len; i++) { + if (abs(g_array_index(order_arr, NmcSortOrder, i)) - abs(val) == 0) { + unique = FALSE; + break; + } + } + + /* Value is ok and unique, add it to the array */ + if (unique) + g_array_append_val(order_arr, val); + } + + return order_arr; } static NMConnection * -get_connection (NmCli *nmc, - int *argc, - const char *const**argv, - const char **out_selector, - const char **out_value, - GPtrArray **out_result, - GError **error) -{ - const GPtrArray *connections; - NMConnection *connection = NULL; - const char *selector = NULL; - - NM_SET_OUT (out_selector, NULL); - NM_SET_OUT (out_value, NULL); - - if (*argc == 0) { - g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("No connection specified")); - return NULL; - } - - if (*argc == 1 && nmc->complete) - nmc_complete_strings (**argv, "id", "uuid", "path", "filename"); - - if (NM_IN_STRSET (**argv, "id", "uuid", "path", "filename")) { - if (*argc == 1) { - if (!nmc->complete) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("%s argument is missing"), selector); - return NULL; - } - } else { - selector = **argv; - (*argv)++; - (*argc)--; - } - } - - NM_SET_OUT (out_selector, selector); - NM_SET_OUT (out_value, **argv); - - connections = nm_client_get_connections (nmc->client); - connection = nmc_find_connection (connections, selector, **argv, out_result, - *argc == 1 && nmc->complete); - if (!connection) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_NOT_FOUND, - _("unknown connection '%s'"), **argv); - } - - next_arg (nmc, argc, argv, NULL); - return connection; +get_connection(NmCli * nmc, + int * argc, + const char *const **argv, + const char ** out_selector, + const char ** out_value, + GPtrArray ** out_result, + GError ** error) +{ + const GPtrArray *connections; + NMConnection * connection = NULL; + const char * selector = NULL; + + NM_SET_OUT(out_selector, NULL); + NM_SET_OUT(out_value, NULL); + + if (*argc == 0) { + g_set_error_literal(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("No connection specified")); + return NULL; + } + + if (*argc == 1 && nmc->complete) + nmc_complete_strings(**argv, "id", "uuid", "path", "filename"); + + if (NM_IN_STRSET(**argv, "id", "uuid", "path", "filename")) { + if (*argc == 1) { + if (!nmc->complete) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("%s argument is missing"), + selector); + return NULL; + } + } else { + selector = **argv; + (*argv)++; + (*argc)--; + } + } + + NM_SET_OUT(out_selector, selector); + NM_SET_OUT(out_value, **argv); + + connections = nm_client_get_connections(nmc->client); + connection = + nmc_find_connection(connections, selector, **argv, out_result, *argc == 1 && nmc->complete); + if (!connection) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_NOT_FOUND, + _("unknown connection '%s'"), + **argv); + } + + next_arg(nmc, argc, argv, NULL); + return connection; } static void -do_connections_show (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv) -{ - gs_free_error GError *err = NULL; - gs_free char *profile_flds = NULL; - gs_free char *active_flds = NULL; - gboolean active_only = FALSE; - gs_unref_array GArray *order = NULL; - guint i; - int option; - - /* check connection show options [--active] [--order ] */ - while ((option = next_arg (nmc, &argc, &argv, "--active", "--order", NULL)) > 0) { - switch (option) { - case 1: /* --active */ - active_only = TRUE; - break; - case 2: /* --order */ - argc--; - argv++; - if (!argc) { - g_set_error_literal (&err, NMCLI_ERROR, 0, - _("'--order' argument is missing")); - goto finish; - } - order = parse_preferred_connection_order (*argv, &err); - if (err) - goto finish; - break; - default: - g_assert_not_reached(); - break; - } - } - - if (argc == 0) { - const char *fields_str = NULL; - gs_unref_ptrarray GPtrArray *items = NULL; - gs_free NMMetaSelectionResultList *selection = NULL; - gboolean show_active_fields = TRUE; - - if (nmc->complete) - goto finish; - - if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) - fields_str = NMC_FIELDS_CON_SHOW_COMMON; - else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) { - /* pass */ - } else - fields_str = nmc->required_fields; - - /* determine whether the user wants to see any fields that are related to active-connections - * (e.g. the apath, the current state, or the device where the profile is active). - * - * If that's the case, then we will show one line for each active connection. In case - * a profile has multiple active connections, it will be listed multiple times. - * If that's not the case, we filter out these duplicate lines. */ - selection = nm_meta_selection_create_parse_list ((const NMMetaAbstractInfo *const*) metagen_con_show, - fields_str, - FALSE, - NULL); - if (selection && selection->num > 0) { - show_active_fields = FALSE; - for (i = 0; i < selection->num; i++) { - const NmcMetaGenericInfo *info = (const NmcMetaGenericInfo *) selection->items[i].info; - - if (NM_IN_SET (info->info_type, NMC_GENERIC_INFO_TYPE_CON_SHOW_DEVICE, - NMC_GENERIC_INFO_TYPE_CON_SHOW_STATE, - NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE_PATH)) { - show_active_fields = TRUE; - break; - } - } - } - - nm_cli_spawn_pager (&nmc->nmc_config, &nmc->pager_data); - - items = con_show_get_items (nmc, active_only, show_active_fields, order); - g_ptr_array_add (items, NULL); - if (!nmc_print (&nmc->nmc_config, - items->pdata, - NULL, - active_only - ? _("NetworkManager active profiles") - : _("NetworkManager connection profiles"), - (const NMMetaAbstractInfo *const*) metagen_con_show, - fields_str, - &err)) - goto finish; - } else { - gboolean new_line = FALSE; - gboolean without_fields = (nmc->required_fields == NULL); - const GPtrArray *active_cons = nm_client_get_active_connections (nmc->client); - - /* multiline mode is default for 'connection show ' */ - if (!nmc->mode_specified) - nmc->nmc_config_mutable.multiline_output = TRUE; - - /* Split required fields into the settings and active ones. */ - if (!split_required_fields_for_con_show (nmc->required_fields, &profile_flds, &active_flds, &err)) - goto finish; - - nm_clear_g_free (&nmc->required_fields); - - /* Before printing the connections check if we have a "--show-secret" - * option after the connection ids */ - if (!nmc->nmc_config.show_secrets && !nmc->complete) { - int argc_cp = argc; - const char *const*argv_cp = argv; - - do { - if (NM_IN_STRSET (*argv_cp, "id", "uuid", "path", "filename", "apath")) { - argc_cp--; - argv_cp++; - } - } while (next_arg (nmc, &argc_cp, &argv_cp, NULL) != -1); - } - - while (argc > 0) { - const GPtrArray *connections; - gboolean res; - NMConnection *con; - gs_unref_object NMActiveConnection *explicit_acon = NULL; - const char *selector = NULL; - gs_unref_ptrarray GPtrArray *found_cons = NULL; - gboolean explicit_acon_handled = FALSE; - guint i_found_cons; - - if (argc == 1 && nmc->complete) - nmc_complete_strings (*argv, "id", "uuid", "path", "filename", "apath"); - - if (NM_IN_STRSET (*argv, "id", "uuid", "path", "filename", "apath")) { - selector = *argv; - argc--; - argv++; - if (!argc) { - g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1)); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; - } - } - - /* Try to find connection by id, uuid or path first */ - connections = nm_client_get_connections (nmc->client); - con = nmc_find_connection (connections, selector, *argv, &found_cons, - argc == 1 && nmc->complete); - if ( !con - && NM_IN_STRSET (selector, NULL, "apath")) { - /* Try apath too */ - explicit_acon = nmc_find_active_connection (active_cons, "apath", *argv, NULL, - argc == 1 && nmc->complete); - if (explicit_acon) { - if ( !selector - && !nm_streq0 (*argv, nm_object_get_path (NM_OBJECT (explicit_acon)))) { - /* we matched the apath based on the last component alone (note the full D-Bus path). - * That is how nmc_find_active_connection() works, if you pass in a selector. - * Reject it. */ - explicit_acon = NULL; - } - nm_g_object_ref (explicit_acon); - } - } - - if (!con && !explicit_acon) { - g_string_printf (nmc->return_text, _("Error: %s - no such connection profile."), *argv); - nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; - goto finish; - } - - /* Print connection details: - * Usually we have both static and active connection. - * But when a connection is private to a user, another user - * may see only the active connection. - */ - - if (nmc->complete) { - next_arg (nmc, &argc, &argv, NULL); - continue; - } - - explicit_acon_handled = FALSE; - i_found_cons = 0; - for (;;) { - gs_unref_ptrarray GPtrArray *found_acons = NULL; - - if (explicit_acon) { - if (explicit_acon_handled) - break; - explicit_acon_handled = TRUE; - /* the user referenced an "apath". In this case, we can only have at most one connection - * and one apath. */ - con = NM_CONNECTION (nm_active_connection_get_connection (explicit_acon)); - } else { - if (i_found_cons >= found_cons->len) - break; - con = found_cons->pdata[i_found_cons++]; - get_ac_for_connection (active_cons, con, &found_acons); - } - - if (active_only && !explicit_acon && !found_acons) { - /* this connection is not interesting, we only print active ones. */ - continue; - } - - nm_assert (explicit_acon || con); - - if (new_line) - g_print ("\n"); - new_line = TRUE; - - if (without_fields || profile_flds) { - if (con) { - nmc->required_fields = profile_flds; - if (nmc->nmc_config.show_secrets) - update_secrets_in_connection (NM_REMOTE_CONNECTION (con), con); - res = nmc_connection_profile_details (con, nmc); - nmc->required_fields = NULL; - if (!res) - goto finish; - } - } - - if (without_fields || active_flds) { - guint l = explicit_acon ? 1 : (found_acons ? found_acons->len : 0); - - for (i = 0; i < l; i++) { - NMActiveConnection *acon; - - if (i > 0) { - /* if there are multiple active connections, separate them with newline. - * that is a bit odd, because we already separate connections with newlines, - * and commonly don't separate the connection from the first active connection. */ - g_print ("\n"); - } - - if (explicit_acon) - acon = explicit_acon; - else - acon = found_acons->pdata[i]; - - nmc->required_fields = active_flds; - res = nmc_active_connection_details (acon, nmc); - nmc->required_fields = NULL; - if (!res) - goto finish; - } - } - } - - next_arg (nmc, &argc, &argv, NULL); - } - } +do_connections_show(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) +{ + gs_free_error GError *err = NULL; + gs_free char * profile_flds = NULL; + gs_free char * active_flds = NULL; + gboolean active_only = FALSE; + gs_unref_array GArray *order = NULL; + guint i; + int option; + + /* check connection show options [--active] [--order ] */ + while ((option = next_arg(nmc, &argc, &argv, "--active", "--order", NULL)) > 0) { + switch (option) { + case 1: /* --active */ + active_only = TRUE; + break; + case 2: /* --order */ + argc--; + argv++; + if (!argc) { + g_set_error_literal(&err, NMCLI_ERROR, 0, _("'--order' argument is missing")); + goto finish; + } + order = parse_preferred_connection_order(*argv, &err); + if (err) + goto finish; + break; + default: + g_assert_not_reached(); + break; + } + } + + if (argc == 0) { + const char * fields_str = NULL; + gs_unref_ptrarray GPtrArray *items = NULL; + gs_free NMMetaSelectionResultList *selection = NULL; + gboolean show_active_fields = TRUE; + + if (nmc->complete) + goto finish; + + if (!nmc->required_fields || g_ascii_strcasecmp(nmc->required_fields, "common") == 0) + fields_str = NMC_FIELDS_CON_SHOW_COMMON; + else if (!nmc->required_fields || g_ascii_strcasecmp(nmc->required_fields, "all") == 0) { + /* pass */ + } else + fields_str = nmc->required_fields; + + /* determine whether the user wants to see any fields that are related to active-connections + * (e.g. the apath, the current state, or the device where the profile is active). + * + * If that's the case, then we will show one line for each active connection. In case + * a profile has multiple active connections, it will be listed multiple times. + * If that's not the case, we filter out these duplicate lines. */ + selection = nm_meta_selection_create_parse_list( + (const NMMetaAbstractInfo *const *) metagen_con_show, + fields_str, + FALSE, + NULL); + if (selection && selection->num > 0) { + show_active_fields = FALSE; + for (i = 0; i < selection->num; i++) { + const NmcMetaGenericInfo *info = + (const NmcMetaGenericInfo *) selection->items[i].info; + + if (NM_IN_SET(info->info_type, + NMC_GENERIC_INFO_TYPE_CON_SHOW_DEVICE, + NMC_GENERIC_INFO_TYPE_CON_SHOW_STATE, + NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE, + NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE_PATH)) { + show_active_fields = TRUE; + break; + } + } + } + + nm_cli_spawn_pager(&nmc->nmc_config, &nmc->pager_data); + + items = con_show_get_items(nmc, active_only, show_active_fields, order); + g_ptr_array_add(items, NULL); + if (!nmc_print(&nmc->nmc_config, + items->pdata, + NULL, + active_only ? _("NetworkManager active profiles") + : _("NetworkManager connection profiles"), + (const NMMetaAbstractInfo *const *) metagen_con_show, + fields_str, + &err)) + goto finish; + } else { + gboolean new_line = FALSE; + gboolean without_fields = (nmc->required_fields == NULL); + const GPtrArray *active_cons = nm_client_get_active_connections(nmc->client); + + /* multiline mode is default for 'connection show ' */ + if (!nmc->mode_specified) + nmc->nmc_config_mutable.multiline_output = TRUE; + + /* Split required fields into the settings and active ones. */ + if (!split_required_fields_for_con_show(nmc->required_fields, + &profile_flds, + &active_flds, + &err)) + goto finish; + + nm_clear_g_free(&nmc->required_fields); + + /* Before printing the connections check if we have a "--show-secret" + * option after the connection ids */ + if (!nmc->nmc_config.show_secrets && !nmc->complete) { + int argc_cp = argc; + const char *const *argv_cp = argv; + + do { + if (NM_IN_STRSET(*argv_cp, "id", "uuid", "path", "filename", "apath")) { + argc_cp--; + argv_cp++; + } + } while (next_arg(nmc, &argc_cp, &argv_cp, NULL) != -1); + } + + while (argc > 0) { + const GPtrArray *connections; + gboolean res; + NMConnection * con; + gs_unref_object NMActiveConnection *explicit_acon = NULL; + const char * selector = NULL; + gs_unref_ptrarray GPtrArray *found_cons = NULL; + gboolean explicit_acon_handled = FALSE; + guint i_found_cons; + + if (argc == 1 && nmc->complete) + nmc_complete_strings(*argv, "id", "uuid", "path", "filename", "apath"); + + if (NM_IN_STRSET(*argv, "id", "uuid", "path", "filename", "apath")) { + selector = *argv; + argc--; + argv++; + if (!argc) { + g_string_printf(nmc->return_text, + _("Error: %s argument is missing."), + *(argv - 1)); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + goto finish; + } + } + + /* Try to find connection by id, uuid or path first */ + connections = nm_client_get_connections(nmc->client); + con = nmc_find_connection(connections, + selector, + *argv, + &found_cons, + argc == 1 && nmc->complete); + if (!con && NM_IN_STRSET(selector, NULL, "apath")) { + /* Try apath too */ + explicit_acon = nmc_find_active_connection(active_cons, + "apath", + *argv, + NULL, + argc == 1 && nmc->complete); + if (explicit_acon) { + if (!selector + && !nm_streq0(*argv, nm_object_get_path(NM_OBJECT(explicit_acon)))) { + /* we matched the apath based on the last component alone (note the full D-Bus path). + * That is how nmc_find_active_connection() works, if you pass in a selector. + * Reject it. */ + explicit_acon = NULL; + } + nm_g_object_ref(explicit_acon); + } + } + + if (!con && !explicit_acon) { + g_string_printf(nmc->return_text, + _("Error: %s - no such connection profile."), + *argv); + nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; + goto finish; + } + + /* Print connection details: + * Usually we have both static and active connection. + * But when a connection is private to a user, another user + * may see only the active connection. + */ + + if (nmc->complete) { + next_arg(nmc, &argc, &argv, NULL); + continue; + } + + explicit_acon_handled = FALSE; + i_found_cons = 0; + for (;;) { + gs_unref_ptrarray GPtrArray *found_acons = NULL; + + if (explicit_acon) { + if (explicit_acon_handled) + break; + explicit_acon_handled = TRUE; + /* the user referenced an "apath". In this case, we can only have at most one connection + * and one apath. */ + con = NM_CONNECTION(nm_active_connection_get_connection(explicit_acon)); + } else { + if (i_found_cons >= found_cons->len) + break; + con = found_cons->pdata[i_found_cons++]; + get_ac_for_connection(active_cons, con, &found_acons); + } + + if (active_only && !explicit_acon && !found_acons) { + /* this connection is not interesting, we only print active ones. */ + continue; + } + + nm_assert(explicit_acon || con); + + if (new_line) + g_print("\n"); + new_line = TRUE; + + if (without_fields || profile_flds) { + if (con) { + nmc->required_fields = profile_flds; + if (nmc->nmc_config.show_secrets) + update_secrets_in_connection(NM_REMOTE_CONNECTION(con), con); + res = nmc_connection_profile_details(con, nmc); + nmc->required_fields = NULL; + if (!res) + goto finish; + } + } + + if (without_fields || active_flds) { + guint l = explicit_acon ? 1 : (found_acons ? found_acons->len : 0); + + for (i = 0; i < l; i++) { + NMActiveConnection *acon; + + if (i > 0) { + /* if there are multiple active connections, separate them with newline. + * that is a bit odd, because we already separate connections with newlines, + * and commonly don't separate the connection from the first active connection. */ + g_print("\n"); + } + + if (explicit_acon) + acon = explicit_acon; + else + acon = found_acons->pdata[i]; + + nmc->required_fields = active_flds; + res = nmc_active_connection_details(acon, nmc); + nmc->required_fields = NULL; + if (!res) + goto finish; + } + } + } + + next_arg(nmc, &argc, &argv, NULL); + } + } finish: - if (err) { - g_string_printf (nmc->return_text, _("Error: %s."), err->message); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - } + if (err) { + g_string_printf(nmc->return_text, _("Error: %s."), err->message); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + } } static NMActiveConnection * -get_default_active_connection (NmCli *nmc, NMDevice **device) -{ - NMActiveConnection *default_ac = NULL; - NMDevice *non_default_device = NULL; - NMActiveConnection *non_default_ac = NULL; - const GPtrArray *connections; - guint i; - - g_return_val_if_fail (nmc, NULL); - g_return_val_if_fail (device, NULL); - g_return_val_if_fail (*device == NULL, NULL); - - connections = nm_client_get_active_connections (nmc->client); - for (i = 0; i < connections->len; i++) { - NMActiveConnection *candidate = g_ptr_array_index (connections, i); - const GPtrArray *devices; - - devices = nm_active_connection_get_devices (candidate); - if (!devices->len) - continue; - - if (nm_active_connection_get_default (candidate)) { - if (!default_ac) { - *device = g_ptr_array_index (devices, 0); - default_ac = candidate; - } - } else { - if (!non_default_ac) { - non_default_device = g_ptr_array_index (devices, 0); - non_default_ac = candidate; - } - } - } - - /* Prefer the default connection if one exists, otherwise return the first - * non-default connection. - */ - if (!default_ac && non_default_ac) { - default_ac = non_default_ac; - *device = non_default_device; - } - return default_ac; +get_default_active_connection(NmCli *nmc, NMDevice **device) +{ + NMActiveConnection *default_ac = NULL; + NMDevice * non_default_device = NULL; + NMActiveConnection *non_default_ac = NULL; + const GPtrArray * connections; + guint i; + + g_return_val_if_fail(nmc, NULL); + g_return_val_if_fail(device, NULL); + g_return_val_if_fail(*device == NULL, NULL); + + connections = nm_client_get_active_connections(nmc->client); + for (i = 0; i < connections->len; i++) { + NMActiveConnection *candidate = g_ptr_array_index(connections, i); + const GPtrArray * devices; + + devices = nm_active_connection_get_devices(candidate); + if (!devices->len) + continue; + + if (nm_active_connection_get_default(candidate)) { + if (!default_ac) { + *device = g_ptr_array_index(devices, 0); + default_ac = candidate; + } + } else { + if (!non_default_ac) { + non_default_device = g_ptr_array_index(devices, 0); + non_default_ac = candidate; + } + } + } + + /* Prefer the default connection if one exists, otherwise return the first + * non-default connection. + */ + if (!default_ac && non_default_ac) { + default_ac = non_default_ac; + *device = non_default_device; + } + return default_ac; } /* Find a device to activate the connection on. @@ -2354,830 +2440,855 @@ get_default_active_connection (NmCli *nmc, NMDevice **device) * RETURNS: TRUE when a device is found, FALSE otherwise. */ static gboolean -find_device_for_connection (NmCli *nmc, - NMConnection *connection, - const char *iface, - const char *ap, - const char *nsp, - NMDevice **device, - const char **spec_object, - GError **error) -{ - NMSettingConnection *s_con; - const char *con_type; - guint i, j; - - g_return_val_if_fail (nmc, FALSE); - g_return_val_if_fail (iface || ap || nsp, FALSE); - g_return_val_if_fail (device && *device == NULL, FALSE); - g_return_val_if_fail (spec_object && *spec_object == NULL, FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); - con_type = nm_setting_connection_get_connection_type (s_con); - - if (strcmp (con_type, NM_SETTING_VPN_SETTING_NAME) == 0) { - /* VPN connections */ - NMActiveConnection *active = NULL; - if (iface) { - *device = nm_client_get_device_by_iface (nmc->client, iface); - if (*device) - active = nm_device_get_active_connection (*device); - - if (!active) { - g_set_error (error, NMCLI_ERROR, 0, _("no active connection on device '%s'"), iface); - return FALSE; - } - *spec_object = nm_object_get_path (NM_OBJECT (active)); - return TRUE; - } else { - active = get_default_active_connection (nmc, device); - if (!active) { - g_set_error_literal (error, NMCLI_ERROR, 0, _("no active connection or device")); - return FALSE; - } - *spec_object = nm_object_get_path (NM_OBJECT (active)); - return TRUE; - } - } else { - /* Other connections */ - NMDevice *found_device = NULL; - const GPtrArray *devices = nm_client_get_devices (nmc->client); - - for (i = 0; i < devices->len && !found_device; i++) { - NMDevice *dev = g_ptr_array_index (devices, i); - - if (iface) { - const char *dev_iface = nm_device_get_iface (dev); - if (!nm_streq0 (dev_iface, iface)) - continue; - - if (!nm_device_connection_compatible (dev, connection, error)) { - g_prefix_error (error, _("device '%s' not compatible with connection '%s': "), - iface, nm_setting_connection_get_id (s_con)); - return FALSE; - } - - } else { - if (!nm_device_connection_compatible (dev, connection, NULL)) - continue; - } - - found_device = dev; - if ( ap - && nm_streq (con_type, NM_SETTING_WIRELESS_SETTING_NAME) - && NM_IS_DEVICE_WIFI (dev)) { - gs_free char *bssid_up = g_ascii_strup (ap, -1); - const GPtrArray *aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (dev)); - found_device = NULL; /* Mark as not found; set to the device again later, only if AP matches */ - - for (j = 0; j < aps->len; j++) { - NMAccessPoint *candidate_ap = g_ptr_array_index (aps, j); - const char *candidate_bssid = nm_access_point_get_bssid (candidate_ap); - - if (nm_streq0 (bssid_up, candidate_bssid)) { - found_device = dev; - *spec_object = nm_object_get_path (NM_OBJECT (candidate_ap)); - break; - } - } - } - } - - if (!found_device) { - if (iface) { - g_set_error (error, NMCLI_ERROR, 0, _("device '%s' not compatible with connection '%s'"), - iface, nm_setting_connection_get_id (s_con)); - } else { - g_set_error (error, NMCLI_ERROR, 0, _("no device found for connection '%s'"), - nm_setting_connection_get_id (s_con)); - } - return FALSE; - } - - *device = found_device; - return TRUE; - } +find_device_for_connection(NmCli * nmc, + NMConnection *connection, + const char * iface, + const char * ap, + const char * nsp, + NMDevice ** device, + const char ** spec_object, + GError ** error) +{ + NMSettingConnection *s_con; + const char * con_type; + guint i, j; + + g_return_val_if_fail(nmc, FALSE); + g_return_val_if_fail(iface || ap || nsp, FALSE); + g_return_val_if_fail(device && *device == NULL, FALSE); + g_return_val_if_fail(spec_object && *spec_object == NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + con_type = nm_setting_connection_get_connection_type(s_con); + + if (strcmp(con_type, NM_SETTING_VPN_SETTING_NAME) == 0) { + /* VPN connections */ + NMActiveConnection *active = NULL; + if (iface) { + *device = nm_client_get_device_by_iface(nmc->client, iface); + if (*device) + active = nm_device_get_active_connection(*device); + + if (!active) { + g_set_error(error, NMCLI_ERROR, 0, _("no active connection on device '%s'"), iface); + return FALSE; + } + *spec_object = nm_object_get_path(NM_OBJECT(active)); + return TRUE; + } else { + active = get_default_active_connection(nmc, device); + if (!active) { + g_set_error_literal(error, NMCLI_ERROR, 0, _("no active connection or device")); + return FALSE; + } + *spec_object = nm_object_get_path(NM_OBJECT(active)); + return TRUE; + } + } else { + /* Other connections */ + NMDevice * found_device = NULL; + const GPtrArray *devices = nm_client_get_devices(nmc->client); + + for (i = 0; i < devices->len && !found_device; i++) { + NMDevice *dev = g_ptr_array_index(devices, i); + + if (iface) { + const char *dev_iface = nm_device_get_iface(dev); + if (!nm_streq0(dev_iface, iface)) + continue; + + if (!nm_device_connection_compatible(dev, connection, error)) { + g_prefix_error(error, + _("device '%s' not compatible with connection '%s': "), + iface, + nm_setting_connection_get_id(s_con)); + return FALSE; + } + + } else { + if (!nm_device_connection_compatible(dev, connection, NULL)) + continue; + } + + found_device = dev; + if (ap && nm_streq(con_type, NM_SETTING_WIRELESS_SETTING_NAME) + && NM_IS_DEVICE_WIFI(dev)) { + gs_free char * bssid_up = g_ascii_strup(ap, -1); + const GPtrArray *aps = nm_device_wifi_get_access_points(NM_DEVICE_WIFI(dev)); + found_device = + NULL; /* Mark as not found; set to the device again later, only if AP matches */ + + for (j = 0; j < aps->len; j++) { + NMAccessPoint *candidate_ap = g_ptr_array_index(aps, j); + const char * candidate_bssid = nm_access_point_get_bssid(candidate_ap); + + if (nm_streq0(bssid_up, candidate_bssid)) { + found_device = dev; + *spec_object = nm_object_get_path(NM_OBJECT(candidate_ap)); + break; + } + } + } + } + + if (!found_device) { + if (iface) { + g_set_error(error, + NMCLI_ERROR, + 0, + _("device '%s' not compatible with connection '%s'"), + iface, + nm_setting_connection_get_id(s_con)); + } else { + g_set_error(error, + NMCLI_ERROR, + 0, + _("no device found for connection '%s'"), + nm_setting_connection_get_id(s_con)); + } + return FALSE; + } + + *device = found_device; + return TRUE; + } } typedef struct { - NmCli *nmc; - NMDevice *device; - NMActiveConnection *active; + NmCli * nmc; + NMDevice * device; + NMActiveConnection *active; } ActivateConnectionInfo; static void -active_connection_hint (GString *return_text, - NMActiveConnection *active, - NMDevice *device) +active_connection_hint(GString *return_text, NMActiveConnection *active, NMDevice *device) { - NMRemoteConnection *connection; - nm_auto_free_gstring GString *hint = NULL; - const GPtrArray *devices; - guint i; + NMRemoteConnection * connection; + nm_auto_free_gstring GString *hint = NULL; + const GPtrArray * devices; + guint i; - if (!active) - return; + if (!active) + return; - if (!nm_streq (NM_CONFIG_DEFAULT_LOGGING_BACKEND, "journal")) - return; + if (!nm_streq(NM_CONFIG_DEFAULT_LOGGING_BACKEND, "journal")) + return; - connection = nm_active_connection_get_connection (active); - g_return_if_fail (connection); + connection = nm_active_connection_get_connection(active); + g_return_if_fail(connection); - hint = g_string_new ("journalctl -xe "); - g_string_append_printf (hint, "NM_CONNECTION=%s", - nm_connection_get_uuid (NM_CONNECTION (connection))); + hint = g_string_new("journalctl -xe "); + g_string_append_printf(hint, + "NM_CONNECTION=%s", + nm_connection_get_uuid(NM_CONNECTION(connection))); - if (device) - g_string_append_printf (hint, " + NM_DEVICE=%s", nm_device_get_iface (device)); - else { - devices = nm_active_connection_get_devices (active); - for (i = 0; i < devices->len; i++) { - g_string_append_printf (hint, " + NM_DEVICE=%s", - nm_device_get_iface (NM_DEVICE (g_ptr_array_index (devices, i)))); - } - } + if (device) + g_string_append_printf(hint, " + NM_DEVICE=%s", nm_device_get_iface(device)); + else { + devices = nm_active_connection_get_devices(active); + for (i = 0; i < devices->len; i++) { + g_string_append_printf(hint, + " + NM_DEVICE=%s", + nm_device_get_iface(NM_DEVICE(g_ptr_array_index(devices, i)))); + } + } - g_string_append (return_text, "\n"); - g_string_append_printf (return_text, _("Hint: use '%s' to get more details."), hint->str); + g_string_append(return_text, "\n"); + g_string_append_printf(return_text, _("Hint: use '%s' to get more details."), hint->str); } -static void activate_connection_info_finish (ActivateConnectionInfo *info); +static void activate_connection_info_finish(ActivateConnectionInfo *info); static void -check_activated (ActivateConnectionInfo *info) -{ - NMActiveConnectionState ac_state; - NmCli *nmc = info->nmc; - const char *reason = NULL; - - ac_state = nmc_activation_get_effective_state (info->active, info->device, &reason); - switch (ac_state) { - case NM_ACTIVE_CONNECTION_STATE_ACTIVATED: - if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) - nmc_terminal_erase_line (); - if (reason) { - g_print (_("Connection successfully activated (%s) (D-Bus active path: %s)\n"), - reason, - nm_object_get_path (NM_OBJECT (info->active))); - } else { - g_print (_("Connection successfully activated (D-Bus active path: %s)\n"), - nm_object_get_path (NM_OBJECT (info->active))); - } - activate_connection_info_finish (info); - break; - case NM_ACTIVE_CONNECTION_STATE_DEACTIVATED: - nm_assert (reason); - g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s"), - reason); - active_connection_hint (nmc->return_text, info->active, info->device); - nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; - activate_connection_info_finish (info); - break; - case NM_ACTIVE_CONNECTION_STATE_ACTIVATING: - if (nmc->secret_agent) { - NMRemoteConnection *connection = nm_active_connection_get_connection (info->active); - - nm_secret_agent_simple_enable (nmc->secret_agent, - nm_connection_get_path (NM_CONNECTION (connection))); - } - break; - default: - break; - } +check_activated(ActivateConnectionInfo *info) +{ + NMActiveConnectionState ac_state; + NmCli * nmc = info->nmc; + const char * reason = NULL; + + ac_state = nmc_activation_get_effective_state(info->active, info->device, &reason); + switch (ac_state) { + case NM_ACTIVE_CONNECTION_STATE_ACTIVATED: + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) + nmc_terminal_erase_line(); + if (reason) { + g_print(_("Connection successfully activated (%s) (D-Bus active path: %s)\n"), + reason, + nm_object_get_path(NM_OBJECT(info->active))); + } else { + g_print(_("Connection successfully activated (D-Bus active path: %s)\n"), + nm_object_get_path(NM_OBJECT(info->active))); + } + activate_connection_info_finish(info); + break; + case NM_ACTIVE_CONNECTION_STATE_DEACTIVATED: + nm_assert(reason); + g_string_printf(nmc->return_text, _("Error: Connection activation failed: %s"), reason); + active_connection_hint(nmc->return_text, info->active, info->device); + nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; + activate_connection_info_finish(info); + break; + case NM_ACTIVE_CONNECTION_STATE_ACTIVATING: + if (nmc->secret_agent) { + NMRemoteConnection *connection = nm_active_connection_get_connection(info->active); + + nm_secret_agent_simple_enable(nmc->secret_agent, + nm_connection_get_path(NM_CONNECTION(connection))); + } + break; + default: + break; + } } static void -device_state_cb (NMDevice *device, GParamSpec *pspec, ActivateConnectionInfo *info) +device_state_cb(NMDevice *device, GParamSpec *pspec, ActivateConnectionInfo *info) { - check_activated (info); + check_activated(info); } static void -active_connection_state_cb (NMActiveConnection *active, - NMActiveConnectionState state, - NMActiveConnectionStateReason reason, - ActivateConnectionInfo *info) +active_connection_state_cb(NMActiveConnection * active, + NMActiveConnectionState state, + NMActiveConnectionStateReason reason, + ActivateConnectionInfo * info) { - check_activated (info); + check_activated(info); } static void -set_nmc_error_timeout (NmCli *nmc) +set_nmc_error_timeout(NmCli *nmc) { - g_string_printf (nmc->return_text, _("Error: Timeout expired (%d seconds)"), nmc->timeout); - nmc->return_value = NMC_RESULT_ERROR_TIMEOUT_EXPIRED; + g_string_printf(nmc->return_text, _("Error: Timeout expired (%d seconds)"), nmc->timeout); + nmc->return_value = NMC_RESULT_ERROR_TIMEOUT_EXPIRED; } static gboolean -activate_connection_timeout_cb (gpointer user_data) +activate_connection_timeout_cb(gpointer user_data) { - ActivateConnectionInfo *info = user_data; + ActivateConnectionInfo *info = user_data; - /* Time expired -> exit nmcli */ - set_nmc_error_timeout (info->nmc); - activate_connection_info_finish (info); - return FALSE; + /* Time expired -> exit nmcli */ + set_nmc_error_timeout(info->nmc); + activate_connection_info_finish(info); + return FALSE; } static gboolean -progress_cb (gpointer user_data) +progress_cb(gpointer user_data) { - const char *str = (const char *) user_data; + const char *str = (const char *) user_data; - nmc_terminal_show_progress (str); + nmc_terminal_show_progress(str); - return TRUE; + return TRUE; } static gboolean -progress_active_connection_cb (gpointer user_data) +progress_active_connection_cb(gpointer user_data) { - NMActiveConnection *active = user_data; - const char *str; - NMDevice *device; - NMActiveConnectionState ac_state; - const GPtrArray *ac_devs; + NMActiveConnection * active = user_data; + const char * str; + NMDevice * device; + NMActiveConnectionState ac_state; + const GPtrArray * ac_devs; - ac_state = nm_active_connection_get_state (active); + ac_state = nm_active_connection_get_state(active); - if (ac_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) { - /* If the connection is activating, the device state - * is more interesting. */ - ac_devs = nm_active_connection_get_devices (active); - device = ac_devs->len > 0 ? g_ptr_array_index (ac_devs, 0) : NULL; - } else { - device = NULL; - } + if (ac_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) { + /* If the connection is activating, the device state + * is more interesting. */ + ac_devs = nm_active_connection_get_devices(active); + device = ac_devs->len > 0 ? g_ptr_array_index(ac_devs, 0) : NULL; + } else { + device = NULL; + } - str = device - ? gettext (nmc_device_state_to_string_with_external (device)) - : active_connection_state_to_string (ac_state); + str = device ? gettext(nmc_device_state_to_string_with_external(device)) + : active_connection_state_to_string(ac_state); - nmc_terminal_show_progress (str); + nmc_terminal_show_progress(str); - return TRUE; + return TRUE; } static void -activate_connection_info_finish (ActivateConnectionInfo *info) +activate_connection_info_finish(ActivateConnectionInfo *info) { - if (info->device) { - g_signal_handlers_disconnect_by_func (info->device, G_CALLBACK (device_state_cb), info); - g_object_unref (info->device); - } + if (info->device) { + g_signal_handlers_disconnect_by_func(info->device, G_CALLBACK(device_state_cb), info); + g_object_unref(info->device); + } - if (info->active) { - g_signal_handlers_disconnect_by_func (info->active, G_CALLBACK (active_connection_state_cb), info); - g_object_unref (info->active); - } + if (info->active) { + g_signal_handlers_disconnect_by_func(info->active, + G_CALLBACK(active_connection_state_cb), + info); + g_object_unref(info->active); + } - g_free (info); - quit (); + g_free(info); + quit(); } static void -activate_connection_cb (GObject *client, GAsyncResult *result, gpointer user_data) -{ - ActivateConnectionInfo *info = (ActivateConnectionInfo *) user_data; - NmCli *nmc = info->nmc; - NMDevice *device = info->device; - NMActiveConnection *active; - NMActiveConnectionState state; - const GPtrArray *ac_devs; - GError *error = NULL; - - info->active = active = nm_client_activate_connection_finish (NM_CLIENT (client), result, &error); - - if (error) { - g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s"), - error->message); - g_error_free (error); - active_connection_hint (nmc->return_text, info->active, info->device); - nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; - activate_connection_info_finish (info); - } else { - state = nm_active_connection_get_state (active); - if (!device && !nm_active_connection_get_vpn (active)) { - /* device could be NULL for virtual devices. Fill it here. */ - ac_devs = nm_active_connection_get_devices (active); - device = ac_devs->len > 0 ? g_ptr_array_index (ac_devs, 0) : NULL; - if (device) - info->device = g_object_ref (device); - } - - if (nmc->nowait_flag || state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { - /* User doesn't want to wait or already activated */ - if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { - if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) - nmc_terminal_erase_line (); - g_print (_("Connection successfully activated (D-Bus active path: %s)\n"), - nm_object_get_path (NM_OBJECT (active))); - } - activate_connection_info_finish (info); - } else { - /* Monitor the active connection and device (if available) states */ - g_signal_connect (active, "state-changed", G_CALLBACK (active_connection_state_cb), info); - if (device) - g_signal_connect (device, "notify::" NM_DEVICE_STATE, G_CALLBACK (device_state_cb), info); - /* Both active_connection_state_cb () and device_state_cb () will just - * call check_activated (info). So, just call it once directly after - * connecting on both the signals of the objects and skip the call to - * the callbacks. - */ - check_activated (info); - - /* Start progress indication showing VPN states */ - if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) { - if (progress_id) - g_source_remove (progress_id); - progress_id = g_timeout_add (120, progress_active_connection_cb, active); - } - - /* Start timer not to loop forever when signals are not emitted */ - g_timeout_add_seconds (nmc->timeout, activate_connection_timeout_cb, info); - } - } +activate_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data) +{ + ActivateConnectionInfo *info = (ActivateConnectionInfo *) user_data; + NmCli * nmc = info->nmc; + NMDevice * device = info->device; + NMActiveConnection * active; + NMActiveConnectionState state; + const GPtrArray * ac_devs; + GError * error = NULL; + + info->active = active = nm_client_activate_connection_finish(NM_CLIENT(client), result, &error); + + if (error) { + g_string_printf(nmc->return_text, + _("Error: Connection activation failed: %s"), + error->message); + g_error_free(error); + active_connection_hint(nmc->return_text, info->active, info->device); + nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; + activate_connection_info_finish(info); + } else { + state = nm_active_connection_get_state(active); + if (!device && !nm_active_connection_get_vpn(active)) { + /* device could be NULL for virtual devices. Fill it here. */ + ac_devs = nm_active_connection_get_devices(active); + device = ac_devs->len > 0 ? g_ptr_array_index(ac_devs, 0) : NULL; + if (device) + info->device = g_object_ref(device); + } + + if (nmc->nowait_flag || state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { + /* User doesn't want to wait or already activated */ + if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) + nmc_terminal_erase_line(); + g_print(_("Connection successfully activated (D-Bus active path: %s)\n"), + nm_object_get_path(NM_OBJECT(active))); + } + activate_connection_info_finish(info); + } else { + /* Monitor the active connection and device (if available) states */ + g_signal_connect(active, "state-changed", G_CALLBACK(active_connection_state_cb), info); + if (device) + g_signal_connect(device, + "notify::" NM_DEVICE_STATE, + G_CALLBACK(device_state_cb), + info); + /* Both active_connection_state_cb () and device_state_cb () will just + * call check_activated (info). So, just call it once directly after + * connecting on both the signals of the objects and skip the call to + * the callbacks. + */ + check_activated(info); + + /* Start progress indication showing VPN states */ + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) { + if (progress_id) + g_source_remove(progress_id); + progress_id = g_timeout_add(120, progress_active_connection_cb, active); + } + + /* Start timer not to loop forever when signals are not emitted */ + g_timeout_add_seconds(nmc->timeout, activate_connection_timeout_cb, info); + } + } } static gboolean -nmc_activate_connection (NmCli *nmc, - NMConnection *connection, - const char *ifname, - const char *ap, - const char *nsp, - const char *pwds, - GAsyncReadyCallback callback, - GError **error) -{ - ActivateConnectionInfo *info; - - GHashTable *pwds_hash; - NMDevice *device = NULL; - const char *spec_object = NULL; - gboolean device_found; - - g_return_val_if_fail (nmc, FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if ( connection - && ( ifname - || ap - || nsp)) { - gs_free_error GError *local = NULL; - - device_found = find_device_for_connection (nmc, connection, ifname, ap, nsp, &device, &spec_object, &local); - - /* Virtual connection may not have their interfaces created yet */ - if (!device_found && !nm_connection_is_virtual (connection)) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_CON_ACTIVATION, - "%s", local->message); - return FALSE; - } - } else if (ifname) { - device = nm_client_get_device_by_iface (nmc->client, ifname); - if (!device) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_NOT_FOUND, - _("unknown device '%s'."), ifname); - return FALSE; - } - } else if (!connection) { - g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_NOT_FOUND, - _("neither a valid connection nor device given")); - return FALSE; - } - - /* Parse passwords given in passwords file */ - { - gs_free_error GError *local = NULL; - gssize error_line; - - pwds_hash = nmc_utils_read_passwd_file (pwds, &error_line, &local); - if (!pwds_hash) { - if (error_line >= 0) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("invalid passwd-file '%s' at line %zd: %s"), - pwds, - error_line, - local->message); - } else { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("invalid passwd-file '%s': %s"), - pwds, - local->message); - } - return FALSE; - } - } - - if (nmc->pwds_hash) - g_hash_table_destroy (nmc->pwds_hash); - nmc->pwds_hash = pwds_hash; - - nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-connect"); - if (nmc->secret_agent) { - g_signal_connect (nmc->secret_agent, - NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS, - G_CALLBACK (nmc_secrets_requested), - nmc); - } - - info = g_malloc0 (sizeof (ActivateConnectionInfo)); - info->nmc = nmc; - if (device) - info->device = g_object_ref (device); - - nm_client_activate_connection_async (nmc->client, - connection, - device, - spec_object, - NULL, - callback, - info); - return TRUE; +nmc_activate_connection(NmCli * nmc, + NMConnection * connection, + const char * ifname, + const char * ap, + const char * nsp, + const char * pwds, + GAsyncReadyCallback callback, + GError ** error) +{ + ActivateConnectionInfo *info; + + GHashTable *pwds_hash; + NMDevice * device = NULL; + const char *spec_object = NULL; + gboolean device_found; + + g_return_val_if_fail(nmc, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + if (connection && (ifname || ap || nsp)) { + gs_free_error GError *local = NULL; + + device_found = find_device_for_connection(nmc, + connection, + ifname, + ap, + nsp, + &device, + &spec_object, + &local); + + /* Virtual connection may not have their interfaces created yet */ + if (!device_found && !nm_connection_is_virtual(connection)) { + g_set_error(error, NMCLI_ERROR, NMC_RESULT_ERROR_CON_ACTIVATION, "%s", local->message); + return FALSE; + } + } else if (ifname) { + device = nm_client_get_device_by_iface(nmc->client, ifname); + if (!device) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_NOT_FOUND, + _("unknown device '%s'."), + ifname); + return FALSE; + } + } else if (!connection) { + g_set_error_literal(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_NOT_FOUND, + _("neither a valid connection nor device given")); + return FALSE; + } + + /* Parse passwords given in passwords file */ + { + gs_free_error GError *local = NULL; + gssize error_line; + + pwds_hash = nmc_utils_read_passwd_file(pwds, &error_line, &local); + if (!pwds_hash) { + if (error_line >= 0) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("invalid passwd-file '%s' at line %zd: %s"), + pwds, + error_line, + local->message); + } else { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("invalid passwd-file '%s': %s"), + pwds, + local->message); + } + return FALSE; + } + } + + if (nmc->pwds_hash) + g_hash_table_destroy(nmc->pwds_hash); + nmc->pwds_hash = pwds_hash; + + nmc->secret_agent = nm_secret_agent_simple_new("nmcli-connect"); + if (nmc->secret_agent) { + g_signal_connect(nmc->secret_agent, + NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS, + G_CALLBACK(nmc_secrets_requested), + nmc); + } + + info = g_malloc0(sizeof(ActivateConnectionInfo)); + info->nmc = nmc; + if (device) + info->device = g_object_ref(device); + + nm_client_activate_connection_async(nmc->client, + connection, + device, + spec_object, + NULL, + callback, + info); + return TRUE; } static void -do_connection_up (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv) -{ - NMConnection *connection = NULL; - const char *ifname = NULL; - const char *ap = NULL; - const char *nsp = NULL; - const char *pwds = NULL; - gs_free_error GError *error = NULL; - gs_strfreev char **arg_arr = NULL; - int arg_num; - const char *const**argv_ptr; - int *argc_ptr; - - /* - * Set default timeout for connection activation. - * Activation can take quite a long time, use 90 seconds. - */ - if (nmc->timeout == -1) - nmc->timeout = 90; - - next_arg (nmc, &argc, &argv, NULL); - argv_ptr = &argv; - argc_ptr = &argc; - - if (argc == 0 && nmc->ask) { - gs_free char *line = NULL; - - /* nmc_do_cmd() should not call this with argc=0. */ - g_assert (!nmc->complete); - - line = nmc_readline (&nmc->nmc_config, - PROMPT_CONNECTION); - nmc_string_to_arg_array (line, NULL, TRUE, &arg_arr, &arg_num); - argv_ptr = (const char *const**) &arg_arr; - argc_ptr = &arg_num; - } - - if (argc > 0 && strcmp (*argv, "ifname") != 0) { - connection = get_connection (nmc, argc_ptr, argv_ptr, NULL, NULL, NULL, &error); - if (!connection) { - g_string_printf (nmc->return_text, _("Error: %s."), error->message); - nmc->return_value = error->code; - return; - } - } - - while (argc > 0) { - if (argc == 1 && nmc->complete) - nmc_complete_strings (*argv, "ifname", "ap", "passwd-file"); - - if (strcmp (*argv, "ifname") == 0) { - argc--; - argv++; - if (!argc) { - g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1)); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - return; - } - - ifname = *argv; - if (argc == 1 && nmc->complete) - nmc_complete_device (nmc->client, ifname, ap != NULL); - } - else if (strcmp (*argv, "ap") == 0) { - argc--; - argv++; - if (!argc) { - g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1)); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - return; - } - - ap = *argv; - if (argc == 1 && nmc->complete) - nmc_complete_bssid (nmc->client, ifname, ap); - } - else if (strcmp (*argv, "passwd-file") == 0) { - argc--; - argv++; - if (!argc) { - g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1)); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - return; - } - - if (argc == 1 && nmc->complete) - nmc->return_value = NMC_RESULT_COMPLETE_FILE; - - pwds = *argv; - } - else if (!nmc->complete) { - g_string_printf (nmc->return_text, _("Error: invalid extra argument '%s'."), *argv); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - return; - } - - next_arg (nmc, &argc, &argv, NULL); - } - - if (nmc->complete) - return; - - /* Use nowait_flag instead of should_wait because exiting has to be postponed till - * active_connection_state_cb() is called. That gives NM time to check our permissions - * and we can follow activation progress. - */ - nmc->nowait_flag = (nmc->timeout == 0); - nmc->should_wait++; - - if (!nmc_activate_connection (nmc, connection, ifname, ap, nsp, pwds, activate_connection_cb, &error)) { - g_string_printf (nmc->return_text, _("Error: %s."), - error->message); - nmc->should_wait--; - nmc->return_value = error->code; - return; - } - - /* Start progress indication */ - if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) - progress_id = g_timeout_add (120, progress_cb, _("preparing")); +do_connection_up(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) +{ + NMConnection *connection = NULL; + const char * ifname = NULL; + const char * ap = NULL; + const char * nsp = NULL; + const char * pwds = NULL; + gs_free_error GError *error = NULL; + gs_strfreev char ** arg_arr = NULL; + int arg_num; + const char *const ** argv_ptr; + int * argc_ptr; + + /* + * Set default timeout for connection activation. + * Activation can take quite a long time, use 90 seconds. + */ + if (nmc->timeout == -1) + nmc->timeout = 90; + + next_arg(nmc, &argc, &argv, NULL); + argv_ptr = &argv; + argc_ptr = &argc; + + if (argc == 0 && nmc->ask) { + gs_free char *line = NULL; + + /* nmc_do_cmd() should not call this with argc=0. */ + g_assert(!nmc->complete); + + line = nmc_readline(&nmc->nmc_config, PROMPT_CONNECTION); + nmc_string_to_arg_array(line, NULL, TRUE, &arg_arr, &arg_num); + argv_ptr = (const char *const **) &arg_arr; + argc_ptr = &arg_num; + } + + if (argc > 0 && strcmp(*argv, "ifname") != 0) { + connection = get_connection(nmc, argc_ptr, argv_ptr, NULL, NULL, NULL, &error); + if (!connection) { + g_string_printf(nmc->return_text, _("Error: %s."), error->message); + nmc->return_value = error->code; + return; + } + } + + while (argc > 0) { + if (argc == 1 && nmc->complete) + nmc_complete_strings(*argv, "ifname", "ap", "passwd-file"); + + if (strcmp(*argv, "ifname") == 0) { + argc--; + argv++; + if (!argc) { + g_string_printf(nmc->return_text, _("Error: %s argument is missing."), *(argv - 1)); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + return; + } + + ifname = *argv; + if (argc == 1 && nmc->complete) + nmc_complete_device(nmc->client, ifname, ap != NULL); + } else if (strcmp(*argv, "ap") == 0) { + argc--; + argv++; + if (!argc) { + g_string_printf(nmc->return_text, _("Error: %s argument is missing."), *(argv - 1)); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + return; + } + + ap = *argv; + if (argc == 1 && nmc->complete) + nmc_complete_bssid(nmc->client, ifname, ap); + } else if (strcmp(*argv, "passwd-file") == 0) { + argc--; + argv++; + if (!argc) { + g_string_printf(nmc->return_text, _("Error: %s argument is missing."), *(argv - 1)); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + return; + } + + if (argc == 1 && nmc->complete) + nmc->return_value = NMC_RESULT_COMPLETE_FILE; + + pwds = *argv; + } else if (!nmc->complete) { + g_string_printf(nmc->return_text, _("Error: invalid extra argument '%s'."), *argv); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + return; + } + + next_arg(nmc, &argc, &argv, NULL); + } + + if (nmc->complete) + return; + + /* Use nowait_flag instead of should_wait because exiting has to be postponed till + * active_connection_state_cb() is called. That gives NM time to check our permissions + * and we can follow activation progress. + */ + nmc->nowait_flag = (nmc->timeout == 0); + nmc->should_wait++; + + if (!nmc_activate_connection(nmc, + connection, + ifname, + ap, + nsp, + pwds, + activate_connection_cb, + &error)) { + g_string_printf(nmc->return_text, _("Error: %s."), error->message); + nmc->should_wait--; + nmc->return_value = error->code; + return; + } + + /* Start progress indication */ + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) + progress_id = g_timeout_add(120, progress_cb, _("preparing")); } /*****************************************************************************/ typedef struct { - NmCli *nmc; - /* a list of object that is relevant for the callback. The object - * type differs, and depends on the type of callback. */ - GPtrArray *obj_list; - guint timeout_id; - GCancellable *cancellable; + NmCli *nmc; + /* a list of object that is relevant for the callback. The object + * type differs, and depends on the type of callback. */ + GPtrArray * obj_list; + guint timeout_id; + GCancellable *cancellable; } ConnectionCbInfo; -static void connection_removed_cb (NMClient *client, NMConnection *connection, ConnectionCbInfo *info); +static void +connection_removed_cb(NMClient *client, NMConnection *connection, ConnectionCbInfo *info); -static void down_active_connection_state_cb (NMActiveConnection *active, - GParamSpec *pspec, - ConnectionCbInfo *info); +static void down_active_connection_state_cb(NMActiveConnection *active, + GParamSpec * pspec, + ConnectionCbInfo * info); static void -connection_cb_info_obj_list_destroy (ConnectionCbInfo *info, gpointer obj) +connection_cb_info_obj_list_destroy(ConnectionCbInfo *info, gpointer obj) { - nm_assert (info); - nm_assert (info->obj_list); - nm_assert (G_IS_OBJECT (obj)); + nm_assert(info); + nm_assert(info->obj_list); + nm_assert(G_IS_OBJECT(obj)); - g_signal_handlers_disconnect_by_func (obj, down_active_connection_state_cb, info); - g_object_unref (obj); + g_signal_handlers_disconnect_by_func(obj, down_active_connection_state_cb, info); + g_object_unref(obj); } static gssize -connection_cb_info_obj_list_idx (ConnectionCbInfo *info, gpointer obj) +connection_cb_info_obj_list_idx(ConnectionCbInfo *info, gpointer obj) { - guint i; + guint i; - nm_assert (info); - nm_assert (info->obj_list); - nm_assert (G_IS_OBJECT (obj)); + nm_assert(info); + nm_assert(info->obj_list); + nm_assert(G_IS_OBJECT(obj)); - for (i = 0; i < info->obj_list->len; i++) { - if (info->obj_list->pdata[i] == obj) - return i; - } - return -1; + for (i = 0; i < info->obj_list->len; i++) { + if (info->obj_list->pdata[i] == obj) + return i; + } + return -1; } static gpointer -connection_cb_info_obj_list_has (ConnectionCbInfo *info, gpointer obj) +connection_cb_info_obj_list_has(ConnectionCbInfo *info, gpointer obj) { - gssize idx; + gssize idx; - idx = connection_cb_info_obj_list_idx (info, obj); - if (idx >= 0) - return info->obj_list->pdata[idx]; - return NULL; + idx = connection_cb_info_obj_list_idx(info, obj); + if (idx >= 0) + return info->obj_list->pdata[idx]; + return NULL; } static gpointer -connection_cb_info_obj_list_steal (ConnectionCbInfo *info, gpointer obj) +connection_cb_info_obj_list_steal(ConnectionCbInfo *info, gpointer obj) { - gssize idx; + gssize idx; - idx = connection_cb_info_obj_list_idx (info, obj); - if (idx >= 0) { - g_ptr_array_remove_index (info->obj_list, idx); - return obj; - } - return NULL; + idx = connection_cb_info_obj_list_idx(info, obj); + if (idx >= 0) { + g_ptr_array_remove_index(info->obj_list, idx); + return obj; + } + return NULL; } static void -connection_cb_info_finish (ConnectionCbInfo *info, gpointer obj) +connection_cb_info_finish(ConnectionCbInfo *info, gpointer obj) { - if (obj) { - obj = connection_cb_info_obj_list_steal (info, obj); - if (obj) - connection_cb_info_obj_list_destroy (info, obj); - } else { - while (info->obj_list->len > 0) { - obj = info->obj_list->pdata[info->obj_list->len - 1]; - g_ptr_array_remove_index (info->obj_list, info->obj_list->len - 1); - connection_cb_info_obj_list_destroy (info, obj); - } - } + if (obj) { + obj = connection_cb_info_obj_list_steal(info, obj); + if (obj) + connection_cb_info_obj_list_destroy(info, obj); + } else { + while (info->obj_list->len > 0) { + obj = info->obj_list->pdata[info->obj_list->len - 1]; + g_ptr_array_remove_index(info->obj_list, info->obj_list->len - 1); + connection_cb_info_obj_list_destroy(info, obj); + } + } - if (info->obj_list->len > 0) - return; + if (info->obj_list->len > 0) + return; - nm_clear_g_source (&info->timeout_id); - nm_clear_g_cancellable (&info->cancellable); - g_ptr_array_free (info->obj_list, TRUE); + nm_clear_g_source(&info->timeout_id); + nm_clear_g_cancellable(&info->cancellable); + g_ptr_array_free(info->obj_list, TRUE); - g_signal_handlers_disconnect_by_func (info->nmc->client, connection_removed_cb, info); + g_signal_handlers_disconnect_by_func(info->nmc->client, connection_removed_cb, info); - g_slice_free (ConnectionCbInfo, info); + g_slice_free(ConnectionCbInfo, info); - quit (); + quit(); } /*****************************************************************************/ static void -connection_removed_cb (NMClient *client, NMConnection *connection, ConnectionCbInfo *info) +connection_removed_cb(NMClient *client, NMConnection *connection, ConnectionCbInfo *info) { - if (!connection_cb_info_obj_list_has (info, connection)) - return; - g_print (_("Connection '%s' (%s) successfully deleted.\n"), - nm_connection_get_id (connection), - nm_connection_get_uuid (connection)); - connection_cb_info_finish (info, connection); + if (!connection_cb_info_obj_list_has(info, connection)) + return; + g_print(_("Connection '%s' (%s) successfully deleted.\n"), + nm_connection_get_id(connection), + nm_connection_get_uuid(connection)); + connection_cb_info_finish(info, connection); } static void -down_active_connection_state_cb (NMActiveConnection *active, - GParamSpec *pspec, - ConnectionCbInfo *info) +down_active_connection_state_cb(NMActiveConnection *active, + GParamSpec * pspec, + ConnectionCbInfo * info) { - if (nm_active_connection_get_state (active) < NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) - return; + if (nm_active_connection_get_state(active) < NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) + return; - if (info->nmc->nmc_config.print_output == NMC_PRINT_PRETTY) - nmc_terminal_erase_line (); - g_print (_("Connection '%s' successfully deactivated (D-Bus active path: %s)\n"), - nm_active_connection_get_id (active), nm_object_get_path (NM_OBJECT (active))); + if (info->nmc->nmc_config.print_output == NMC_PRINT_PRETTY) + nmc_terminal_erase_line(); + g_print(_("Connection '%s' successfully deactivated (D-Bus active path: %s)\n"), + nm_active_connection_get_id(active), + nm_object_get_path(NM_OBJECT(active))); - g_signal_handlers_disconnect_by_func (G_OBJECT (active), - down_active_connection_state_cb, - info); - connection_cb_info_finish (info, active); + g_signal_handlers_disconnect_by_func(G_OBJECT(active), down_active_connection_state_cb, info); + connection_cb_info_finish(info, active); } static gboolean -connection_op_timeout_cb (gpointer user_data) +connection_op_timeout_cb(gpointer user_data) { - ConnectionCbInfo *info = user_data; + ConnectionCbInfo *info = user_data; - set_nmc_error_timeout (info->nmc); - connection_cb_info_finish (info, NULL); - return G_SOURCE_REMOVE; + set_nmc_error_timeout(info->nmc); + connection_cb_info_finish(info, NULL); + return G_SOURCE_REMOVE; } static void -do_connection_down (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv) -{ - NMActiveConnection *active; - ConnectionCbInfo *info = NULL; - const GPtrArray *active_cons; - gs_strfreev char **arg_arr = NULL; - const char *const*arg_ptr; - int arg_num; - guint i; - gs_unref_ptrarray GPtrArray *found_active_cons = NULL; - - if (nmc->timeout == -1) - nmc->timeout = 10; - - next_arg (nmc, &argc, &argv, NULL); - arg_ptr = argv; - arg_num = argc; - - if (argc == 0) { - /* nmc_do_cmd() should not call this with argc=0. */ - g_assert (!nmc->complete); - - if (nmc->ask) { - gs_free char *line = NULL; - - line = nmc_readline (&nmc->nmc_config, - PROMPT_ACTIVE_CONNECTIONS); - nmc_string_to_arg_array (line, NULL, TRUE, &arg_arr, &arg_num); - arg_ptr = (const char *const*) arg_arr; - } - if (arg_num == 0) { - g_string_printf (nmc->return_text, _("Error: No connection specified.")); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - return; - } - } - - /* Get active connections */ - active_cons = nm_client_get_active_connections (nmc->client); - while (arg_num > 0) { - const char *selector = NULL; - - if (arg_num == 1 && nmc->complete) - nmc_complete_strings (*arg_ptr, "id", "uuid", "path", "filename", "apath"); - - if (NM_IN_STRSET (*arg_ptr, "id", "uuid", "path", "filename", "apath")) { - selector = *arg_ptr; - arg_num--; - arg_ptr++; - if (!arg_num) { - g_string_printf (nmc->return_text, _("Error: %s argument is missing."), selector); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - return; - } - } - - active = nmc_find_active_connection (active_cons, - selector, - *arg_ptr, - &found_active_cons, - arg_num == 1 && nmc->complete); - if (!active) { - if (!nmc->complete) - g_printerr (_("Error: '%s' is not an active connection.\n"), *arg_ptr); - g_string_printf (nmc->return_text, _("Error: not all active connections found.")); - nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; - } - - next_arg (nmc->ask ? NULL : nmc, &arg_num, &arg_ptr, NULL); - } - - if (!found_active_cons) { - g_string_printf (nmc->return_text, _("Error: no active connection provided.")); - nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; - return; - } - nm_assert (found_active_cons->len > 0); - - if (nmc->complete) - return; - - if (nmc->timeout > 0) { - nmc->should_wait++; - - info = g_slice_new0 (ConnectionCbInfo); - info->nmc = nmc; - info->obj_list = g_ptr_array_sized_new (found_active_cons->len); - for (i = 0; i < found_active_cons->len; i++) { - active = found_active_cons->pdata[i]; - g_ptr_array_add (info->obj_list, g_object_ref (active)); - g_signal_connect (active, - "notify::" NM_ACTIVE_CONNECTION_STATE, - G_CALLBACK (down_active_connection_state_cb), - info); - } - info->timeout_id = g_timeout_add_seconds (nmc->timeout, connection_op_timeout_cb, info); - } - - for (i = 0; i < found_active_cons->len; i++) { - GError *error = NULL; - - active = found_active_cons->pdata[i]; - - if (!nm_client_deactivate_connection (nmc->client, active, NULL, &error)) { - g_print (_("Connection '%s' deactivation failed: %s\n"), - nm_active_connection_get_id (active), error->message); - g_clear_error (&error); - - if (info) { - g_signal_handlers_disconnect_by_func (active, - down_active_connection_state_cb, - info); - connection_cb_info_finish (info, active); - } - } - } +do_connection_down(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) +{ + NMActiveConnection *active; + ConnectionCbInfo * info = NULL; + const GPtrArray * active_cons; + gs_strfreev char ** arg_arr = NULL; + const char *const * arg_ptr; + int arg_num; + guint i; + gs_unref_ptrarray GPtrArray *found_active_cons = NULL; + + if (nmc->timeout == -1) + nmc->timeout = 10; + + next_arg(nmc, &argc, &argv, NULL); + arg_ptr = argv; + arg_num = argc; + + if (argc == 0) { + /* nmc_do_cmd() should not call this with argc=0. */ + g_assert(!nmc->complete); + + if (nmc->ask) { + gs_free char *line = NULL; + + line = nmc_readline(&nmc->nmc_config, PROMPT_ACTIVE_CONNECTIONS); + nmc_string_to_arg_array(line, NULL, TRUE, &arg_arr, &arg_num); + arg_ptr = (const char *const *) arg_arr; + } + if (arg_num == 0) { + g_string_printf(nmc->return_text, _("Error: No connection specified.")); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + return; + } + } + + /* Get active connections */ + active_cons = nm_client_get_active_connections(nmc->client); + while (arg_num > 0) { + const char *selector = NULL; + + if (arg_num == 1 && nmc->complete) + nmc_complete_strings(*arg_ptr, "id", "uuid", "path", "filename", "apath"); + + if (NM_IN_STRSET(*arg_ptr, "id", "uuid", "path", "filename", "apath")) { + selector = *arg_ptr; + arg_num--; + arg_ptr++; + if (!arg_num) { + g_string_printf(nmc->return_text, _("Error: %s argument is missing."), selector); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + return; + } + } + + active = nmc_find_active_connection(active_cons, + selector, + *arg_ptr, + &found_active_cons, + arg_num == 1 && nmc->complete); + if (!active) { + if (!nmc->complete) + g_printerr(_("Error: '%s' is not an active connection.\n"), *arg_ptr); + g_string_printf(nmc->return_text, _("Error: not all active connections found.")); + nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; + } + + next_arg(nmc->ask ? NULL : nmc, &arg_num, &arg_ptr, NULL); + } + + if (!found_active_cons) { + g_string_printf(nmc->return_text, _("Error: no active connection provided.")); + nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; + return; + } + nm_assert(found_active_cons->len > 0); + + if (nmc->complete) + return; + + if (nmc->timeout > 0) { + nmc->should_wait++; + + info = g_slice_new0(ConnectionCbInfo); + info->nmc = nmc; + info->obj_list = g_ptr_array_sized_new(found_active_cons->len); + for (i = 0; i < found_active_cons->len; i++) { + active = found_active_cons->pdata[i]; + g_ptr_array_add(info->obj_list, g_object_ref(active)); + g_signal_connect(active, + "notify::" NM_ACTIVE_CONNECTION_STATE, + G_CALLBACK(down_active_connection_state_cb), + info); + } + info->timeout_id = g_timeout_add_seconds(nmc->timeout, connection_op_timeout_cb, info); + } + + for (i = 0; i < found_active_cons->len; i++) { + GError *error = NULL; + + active = found_active_cons->pdata[i]; + + if (!nm_client_deactivate_connection(nmc->client, active, NULL, &error)) { + g_print(_("Connection '%s' deactivation failed: %s\n"), + nm_active_connection_get_id(active), + error->message); + g_clear_error(&error); + + if (info) { + g_signal_handlers_disconnect_by_func(active, down_active_connection_state_cb, info); + connection_cb_info_finish(info, active); + } + } + } } /*****************************************************************************/ @@ -3187,23 +3298,23 @@ do_connection_down (const NMCCommand *cmd, NmCli *nmc, int argc, const char *con * if exists, else return the 'name'. The returned string must not be freed. */ static const char * -get_name_alias_toplevel (const char *name, const char *slave_type) +get_name_alias_toplevel(const char *name, const char *slave_type) { - const NMMetaSettingInfoEditor *setting_info; + const NMMetaSettingInfoEditor *setting_info; - if (slave_type) { - const char *slave_name; + if (slave_type) { + const char *slave_name; - if (nm_meta_setting_info_valid_parts_for_slave_type (slave_type, &slave_name)) - return slave_name ?: name; - return name; - } + if (nm_meta_setting_info_valid_parts_for_slave_type(slave_type, &slave_name)) + return slave_name ?: name; + return name; + } - setting_info = nm_meta_setting_info_editor_find_by_name (name, FALSE); - if (setting_info) - return setting_info->alias ?: setting_info->general->setting_name; + setting_info = nm_meta_setting_info_editor_find_by_name(name, FALSE); + if (setting_info) + return setting_info->alias ?: setting_info->general->setting_name; - return name; + return name; } /* @@ -3213,86 +3324,91 @@ get_name_alias_toplevel (const char *name, const char *slave_type) * Returns: string; the caller is responsible for freeing it. */ static char * -get_valid_options_string (const NMMetaSettingValidPartItem *const*array, const NMMetaSettingValidPartItem *const*array_slv) +get_valid_options_string(const NMMetaSettingValidPartItem *const *array, + const NMMetaSettingValidPartItem *const *array_slv) { - const NMMetaSettingValidPartItem *const*iter = array; - GString *str; - int i; + const NMMetaSettingValidPartItem *const *iter = array; + GString * str; + int i; - str = g_string_sized_new (150); + str = g_string_sized_new(150); - for (i = 0; i < 2; i++, iter = array_slv) { - for (; iter && *iter; iter++) { - const NMMetaSettingInfoEditor *setting_info = (*iter)->setting_info; + for (i = 0; i < 2; i++, iter = array_slv) { + for (; iter && *iter; iter++) { + const NMMetaSettingInfoEditor *setting_info = (*iter)->setting_info; - if (str->len) - g_string_append (str, ", "); - if (setting_info->alias) - g_string_append_printf (str, "%s (%s)", setting_info->general->setting_name, setting_info->alias); - else - g_string_append (str, setting_info->general->setting_name); - } - } - return g_string_free (str, FALSE); + if (str->len) + g_string_append(str, ", "); + if (setting_info->alias) + g_string_append_printf(str, + "%s (%s)", + setting_info->general->setting_name, + setting_info->alias); + else + g_string_append(str, setting_info->general->setting_name); + } + } + return g_string_free(str, FALSE); } static char * -get_valid_options_string_toplevel (void) +get_valid_options_string_toplevel(void) { - GString *str; - int i; + GString *str; + int i; - str = g_string_sized_new (150); - for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { - const NMMetaSettingInfoEditor *setting_info = &nm_meta_setting_infos_editor[i]; + str = g_string_sized_new(150); + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + const NMMetaSettingInfoEditor *setting_info = &nm_meta_setting_infos_editor[i]; - if (!setting_info->valid_parts) - continue; + if (!setting_info->valid_parts) + continue; - if (str->len) - g_string_append (str, ", "); - if (setting_info->alias) - g_string_append_printf (str, "%s (%s)", setting_info->general->setting_name, setting_info->alias); - else - g_string_append (str, setting_info->general->setting_name); - } + if (str->len) + g_string_append(str, ", "); + if (setting_info->alias) + g_string_append_printf(str, + "%s (%s)", + setting_info->general->setting_name, + setting_info->alias); + else + g_string_append(str, setting_info->general->setting_name); + } - if (str->len) - g_string_append (str, ", "); - g_string_append (str, "bond-slave, bridge-slave, team-slave"); + if (str->len) + g_string_append(str, ", "); + g_string_append(str, "bond-slave, bridge-slave, team-slave"); - return g_string_free (str, FALSE); + return g_string_free(str, FALSE); } -static const NMMetaSettingValidPartItem *const* -get_valid_settings_array (const char *con_type) +static const NMMetaSettingValidPartItem *const * +get_valid_settings_array(const char *con_type) { - const NMMetaSettingInfoEditor *setting_info; + const NMMetaSettingInfoEditor *setting_info; - /* No connection type yet? Return settings for a generic connection - * (just the "connection" setting), which always makes sense. */ - if (!con_type) - return nm_meta_setting_info_valid_parts_default; + /* No connection type yet? Return settings for a generic connection + * (just the "connection" setting), which always makes sense. */ + if (!con_type) + return nm_meta_setting_info_valid_parts_default; - setting_info = nm_meta_setting_info_editor_find_by_name (con_type, FALSE); - if (setting_info) - return setting_info->valid_parts ?: NM_PTRARRAY_EMPTY (const NMMetaSettingValidPartItem *); - return NULL; + setting_info = nm_meta_setting_info_editor_find_by_name(con_type, FALSE); + if (setting_info) + return setting_info->valid_parts ?: NM_PTRARRAY_EMPTY(const NMMetaSettingValidPartItem *); + return NULL; } static char * -_construct_property_name (const char *setting_name, - const char *property_name, - NMMetaAccessorModifier modifier) +_construct_property_name(const char * setting_name, + const char * property_name, + NMMetaAccessorModifier modifier) { - return g_strdup_printf ("%s%s.%s\n", - ( modifier == NM_META_ACCESSOR_MODIFIER_ADD - ? "+" - : ( modifier == NM_META_ACCESSOR_MODIFIER_DEL - ? "-" - : "")), - setting_name, - property_name); + return g_strdup_printf("%s%s.%s\n", + (modifier == NM_META_ACCESSOR_MODIFIER_ADD + ? "+" + : (modifier == NM_META_ACCESSOR_MODIFIER_DEL ? "-" : "")), + setting_name, + property_name); } /* get_valid_properties_string: @@ -3310,74 +3426,71 @@ _construct_property_name (const char *setting_name, * Returns: list of property.arg elements */ static char * -get_valid_properties_string (const NMMetaSettingValidPartItem *const*array, - const NMMetaSettingValidPartItem *const*array_slv, - NMMetaAccessorModifier modifier, - const char *prefix, - const char *postfix) -{ - const NMMetaSettingValidPartItem *const*iter = array; - const char *prop_name = NULL; - GString *str; - guint i, j; - gboolean full_match = FALSE; - - g_return_val_if_fail (prefix, NULL); - - str = g_string_sized_new (1024); - - for (i = 0; i < 2; i++, iter = array_slv) { - for (; !full_match && iter && *iter; iter++) { - const NMMetaSettingInfoEditor *setting_info = (*iter)->setting_info; - - if ( !(g_str_has_prefix (setting_info->general->setting_name, prefix)) - && ( !setting_info->alias - || !g_str_has_prefix (setting_info->alias, prefix))) { - continue; - } - - /* If postix (so prefix is terminated by a dot), check - * that prefix is not ambiguous */ - if (postfix) { - /* If we have a perfect match, no need to look for others - * prefix and no check on ambiguity should be performed. - * Moreover, erase previous matches from output string */ - if ( nm_streq (prefix, setting_info->general->setting_name) - || nm_streq0 (prefix, setting_info->alias)) { - g_string_erase (str, 0, -1); - full_match = TRUE; - } else if (prop_name) - return g_string_free (str, TRUE); - prop_name = prefix; - } else - prop_name = setting_info->general->setting_name; - - /* Search the array with the arguments of the current property */ - for (j = 0; j < setting_info->properties_num; j++) { - gs_free char *ss1 = NULL; - const char *arg_name; - - arg_name = setting_info->properties[j]->property_name; - - /* If required, expand the alias too */ - if ( !postfix - && setting_info->alias) { - gs_free char *ss2 = NULL; - - ss2 = _construct_property_name (setting_info->alias, arg_name, modifier); - g_string_append (str, ss2); - } - - if ( postfix - && !g_str_has_prefix (arg_name, postfix)) - continue; - - ss1 = _construct_property_name (prop_name, arg_name, modifier); - g_string_append (str, ss1); - } - } - } - return g_string_free (str, FALSE); +get_valid_properties_string(const NMMetaSettingValidPartItem *const *array, + const NMMetaSettingValidPartItem *const *array_slv, + NMMetaAccessorModifier modifier, + const char * prefix, + const char * postfix) +{ + const NMMetaSettingValidPartItem *const *iter = array; + const char * prop_name = NULL; + GString * str; + guint i, j; + gboolean full_match = FALSE; + + g_return_val_if_fail(prefix, NULL); + + str = g_string_sized_new(1024); + + for (i = 0; i < 2; i++, iter = array_slv) { + for (; !full_match && iter && *iter; iter++) { + const NMMetaSettingInfoEditor *setting_info = (*iter)->setting_info; + + if (!(g_str_has_prefix(setting_info->general->setting_name, prefix)) + && (!setting_info->alias || !g_str_has_prefix(setting_info->alias, prefix))) { + continue; + } + + /* If postix (so prefix is terminated by a dot), check + * that prefix is not ambiguous */ + if (postfix) { + /* If we have a perfect match, no need to look for others + * prefix and no check on ambiguity should be performed. + * Moreover, erase previous matches from output string */ + if (nm_streq(prefix, setting_info->general->setting_name) + || nm_streq0(prefix, setting_info->alias)) { + g_string_erase(str, 0, -1); + full_match = TRUE; + } else if (prop_name) + return g_string_free(str, TRUE); + prop_name = prefix; + } else + prop_name = setting_info->general->setting_name; + + /* Search the array with the arguments of the current property */ + for (j = 0; j < setting_info->properties_num; j++) { + gs_free char *ss1 = NULL; + const char * arg_name; + + arg_name = setting_info->properties[j]->property_name; + + /* If required, expand the alias too */ + if (!postfix && setting_info->alias) { + gs_free char *ss2 = NULL; + + ss2 = _construct_property_name(setting_info->alias, arg_name, modifier); + g_string_append(str, ss2); + } + + if (postfix && !g_str_has_prefix(arg_name, postfix)) + continue; + + ss1 = _construct_property_name(prop_name, arg_name, modifier); + g_string_append(str, ss1); + } + } + } + return g_string_free(str, FALSE); } /* @@ -3390,176 +3503,179 @@ get_valid_properties_string (const NMMetaSettingValidPartItem *const*array, * The returned string must not be freed. */ static const char * -check_valid_name (const char *val, const NMMetaSettingValidPartItem *const*array, const NMMetaSettingValidPartItem *const*array_slv, GError **error) -{ - const NMMetaSettingValidPartItem *const*iter; - gs_unref_ptrarray GPtrArray *tmp_arr = NULL; - const char *str; - GError *tmp_err = NULL; - int i; - - g_return_val_if_fail (array, NULL); - - /* Create a temporary array that can be used in nmc_string_is_valid() */ - tmp_arr = g_ptr_array_sized_new (32); - iter = array; - for (i = 0; i < 2; i++, iter = array_slv) { - for (; iter && *iter; iter++) { - const NMMetaSettingInfoEditor *setting_info = (*iter)->setting_info; - - g_ptr_array_add (tmp_arr, (gpointer) setting_info->general->setting_name); - if (setting_info->alias) - g_ptr_array_add (tmp_arr, (gpointer) setting_info->alias); - } - } - g_ptr_array_add (tmp_arr, (gpointer) NULL); - - /* Check string validity */ - str = nmc_string_is_valid (val, (const char **) tmp_arr->pdata, &tmp_err); - if (!str) { - if (tmp_err->code == 1) - g_propagate_error (error, tmp_err); - else { - /* We want to handle aliases, so construct own error message */ - gs_free char *err_str = NULL; - - err_str = get_valid_options_string (array, array_slv); - g_set_error (error, 1, 0, _("'%s' not among [%s]"), val, err_str); - g_clear_error (&tmp_err); - } - return NULL; - } - - /* Return a pointer to the found string in passed 'array' */ - iter = array; - for (i = 0; i < 2; i++, iter = array_slv) { - for (; iter && *iter; iter++) { - const NMMetaSettingInfoEditor *setting_info = (*iter)->setting_info; - - if ( nm_streq (setting_info->general->setting_name, str) - || nm_streq0 (setting_info->alias, str)) { - return setting_info->general->setting_name; - } - } - } - - /* We should not really come here */ - g_set_error (error, 1, 0, _("Unknown error")); - return NULL; +check_valid_name(const char * val, + const NMMetaSettingValidPartItem *const *array, + const NMMetaSettingValidPartItem *const *array_slv, + GError ** error) +{ + const NMMetaSettingValidPartItem *const *iter; + gs_unref_ptrarray GPtrArray *tmp_arr = NULL; + const char * str; + GError * tmp_err = NULL; + int i; + + g_return_val_if_fail(array, NULL); + + /* Create a temporary array that can be used in nmc_string_is_valid() */ + tmp_arr = g_ptr_array_sized_new(32); + iter = array; + for (i = 0; i < 2; i++, iter = array_slv) { + for (; iter && *iter; iter++) { + const NMMetaSettingInfoEditor *setting_info = (*iter)->setting_info; + + g_ptr_array_add(tmp_arr, (gpointer) setting_info->general->setting_name); + if (setting_info->alias) + g_ptr_array_add(tmp_arr, (gpointer) setting_info->alias); + } + } + g_ptr_array_add(tmp_arr, (gpointer) NULL); + + /* Check string validity */ + str = nmc_string_is_valid(val, (const char **) tmp_arr->pdata, &tmp_err); + if (!str) { + if (tmp_err->code == 1) + g_propagate_error(error, tmp_err); + else { + /* We want to handle aliases, so construct own error message */ + gs_free char *err_str = NULL; + + err_str = get_valid_options_string(array, array_slv); + g_set_error(error, 1, 0, _("'%s' not among [%s]"), val, err_str); + g_clear_error(&tmp_err); + } + return NULL; + } + + /* Return a pointer to the found string in passed 'array' */ + iter = array; + for (i = 0; i < 2; i++, iter = array_slv) { + for (; iter && *iter; iter++) { + const NMMetaSettingInfoEditor *setting_info = (*iter)->setting_info; + + if (nm_streq(setting_info->general->setting_name, str) + || nm_streq0(setting_info->alias, str)) { + return setting_info->general->setting_name; + } + } + } + + /* We should not really come here */ + g_set_error(error, 1, 0, _("Unknown error")); + return NULL; } static const char * -check_valid_name_toplevel (const char *val, const char **slave_type, GError **error) -{ - gs_unref_ptrarray GPtrArray *tmp_arr = NULL; - const NMMetaSettingInfoEditor *setting_info; - gs_free_error GError *tmp_err = NULL; - const char *str; - int i; - - NM_SET_OUT (slave_type, NULL); - - /* Create a temporary array that can be used in nmc_string_is_valid() */ - tmp_arr = g_ptr_array_sized_new (32); - for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { - setting_info = &nm_meta_setting_infos_editor[i]; - g_ptr_array_add (tmp_arr, (gpointer) setting_info->general->setting_name); - if (setting_info->alias) - g_ptr_array_add (tmp_arr, (gpointer) setting_info->alias); - } - g_ptr_array_add (tmp_arr, "bond-slave"); - g_ptr_array_add (tmp_arr, "bridge-slave"); - g_ptr_array_add (tmp_arr, "team-slave"); - g_ptr_array_add (tmp_arr, (gpointer) NULL); - - /* Check string validity */ - str = nmc_string_is_valid (val, (const char **) tmp_arr->pdata, &tmp_err); - if (!str) { - if (tmp_err->code == 1) - g_propagate_error (error, g_steal_pointer (&tmp_err)); - else { - /* We want to handle aliases, so construct own error message */ - gs_free char *err_str = NULL; - - err_str = get_valid_options_string_toplevel (); - g_set_error (error, 1, 0, _("'%s' not among [%s]"), val, err_str); - } - return NULL; - } - - if (nm_streq (str, "bond-slave")) { - NM_SET_OUT (slave_type, NM_SETTING_BOND_SETTING_NAME); - return NM_SETTING_WIRED_SETTING_NAME; - } else if (nm_streq (str, "bridge-slave")) { - NM_SET_OUT (slave_type, NM_SETTING_BRIDGE_SETTING_NAME); - return NM_SETTING_WIRED_SETTING_NAME; - } else if (nm_streq (str, "team-slave")) { - NM_SET_OUT (slave_type, NM_SETTING_TEAM_SETTING_NAME); - return NM_SETTING_WIRED_SETTING_NAME; - } - - setting_info = nm_meta_setting_info_editor_find_by_name (str, TRUE); - if (setting_info) - return setting_info->general->setting_name; - - /* We should not really come here */ - g_set_error (error, 1, 0, _("Unknown error")); - return NULL; +check_valid_name_toplevel(const char *val, const char **slave_type, GError **error) +{ + gs_unref_ptrarray GPtrArray * tmp_arr = NULL; + const NMMetaSettingInfoEditor *setting_info; + gs_free_error GError *tmp_err = NULL; + const char * str; + int i; + + NM_SET_OUT(slave_type, NULL); + + /* Create a temporary array that can be used in nmc_string_is_valid() */ + tmp_arr = g_ptr_array_sized_new(32); + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + setting_info = &nm_meta_setting_infos_editor[i]; + g_ptr_array_add(tmp_arr, (gpointer) setting_info->general->setting_name); + if (setting_info->alias) + g_ptr_array_add(tmp_arr, (gpointer) setting_info->alias); + } + g_ptr_array_add(tmp_arr, "bond-slave"); + g_ptr_array_add(tmp_arr, "bridge-slave"); + g_ptr_array_add(tmp_arr, "team-slave"); + g_ptr_array_add(tmp_arr, (gpointer) NULL); + + /* Check string validity */ + str = nmc_string_is_valid(val, (const char **) tmp_arr->pdata, &tmp_err); + if (!str) { + if (tmp_err->code == 1) + g_propagate_error(error, g_steal_pointer(&tmp_err)); + else { + /* We want to handle aliases, so construct own error message */ + gs_free char *err_str = NULL; + + err_str = get_valid_options_string_toplevel(); + g_set_error(error, 1, 0, _("'%s' not among [%s]"), val, err_str); + } + return NULL; + } + + if (nm_streq(str, "bond-slave")) { + NM_SET_OUT(slave_type, NM_SETTING_BOND_SETTING_NAME); + return NM_SETTING_WIRED_SETTING_NAME; + } else if (nm_streq(str, "bridge-slave")) { + NM_SET_OUT(slave_type, NM_SETTING_BRIDGE_SETTING_NAME); + return NM_SETTING_WIRED_SETTING_NAME; + } else if (nm_streq(str, "team-slave")) { + NM_SET_OUT(slave_type, NM_SETTING_TEAM_SETTING_NAME); + return NM_SETTING_WIRED_SETTING_NAME; + } + + setting_info = nm_meta_setting_info_editor_find_by_name(str, TRUE); + if (setting_info) + return setting_info->general->setting_name; + + /* We should not really come here */ + g_set_error(error, 1, 0, _("Unknown error")); + return NULL; } static gboolean -is_setting_mandatory (NMConnection *connection, NMSetting *setting) +is_setting_mandatory(NMConnection *connection, NMSetting *setting) { - NMSettingConnection *s_con; - const char *c_type; - const NMMetaSettingValidPartItem *const*item; - const char *name; - const char *s_type; - guint i; + NMSettingConnection * s_con; + const char * c_type; + const NMMetaSettingValidPartItem *const *item; + const char * name; + const char * s_type; + guint i; - s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); - c_type = nm_setting_connection_get_connection_type (s_con); - s_type = nm_setting_connection_get_slave_type (s_con); + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + c_type = nm_setting_connection_get_connection_type(s_con); + s_type = nm_setting_connection_get_slave_type(s_con); - name = nm_setting_get_name (setting); + name = nm_setting_get_name(setting); - for (i = 0; i < 2; i++) { - if (i == 0) - item = get_valid_settings_array (c_type); - else - item = nm_meta_setting_info_valid_parts_for_slave_type (s_type, NULL); - for (; item && *item; item++) { - if (!strcmp (name, (*item)->setting_info->general->setting_name)) - return (*item)->mandatory; - } - } + for (i = 0; i < 2; i++) { + if (i == 0) + item = get_valid_settings_array(c_type); + else + item = nm_meta_setting_info_valid_parts_for_slave_type(s_type, NULL); + for (; item && *item; item++) { + if (!strcmp(name, (*item)->setting_info->general->setting_name)) + return (*item)->mandatory; + } + } - return FALSE; + return FALSE; } /*****************************************************************************/ static const char * -_strip_master_prefix (const char *master, const char *(**func)(NMConnection *)) -{ - if (!master) - return NULL; - - if (g_str_has_prefix (master, "ifname/")) { - master = master + strlen ("ifname/"); - if (func) - *func = nm_connection_get_interface_name; - } else if (g_str_has_prefix (master, "uuid/")) { - master = master + strlen ("uuid/"); - if (func) - *func = nm_connection_get_uuid; - } else if (g_str_has_prefix (master, "id/")) { - master = master + strlen ("id/"); - if (func) - *func = nm_connection_get_id; - } - return master; +_strip_master_prefix(const char *master, const char *(**func)(NMConnection *) ) +{ + if (!master) + return NULL; + + if (g_str_has_prefix(master, "ifname/")) { + master = master + strlen("ifname/"); + if (func) + *func = nm_connection_get_interface_name; + } else if (g_str_has_prefix(master, "uuid/")) { + master = master + strlen("uuid/"); + if (func) + *func = nm_connection_get_uuid; + } else if (g_str_has_prefix(master, "id/")) { + master = master + strlen("id/"); + if (func) + *func = nm_connection_get_id; + } + return master; } /* normalized_master_for_slave: @@ -3576,307 +3692,312 @@ _strip_master_prefix (const char *master, const char *(**func)(NMConnection *)) * Returns: identifier of master connection if found, %NULL otherwise */ static const char * -normalized_master_for_slave (const GPtrArray *connections, - const char *master, - const char *type, - const char **out_type) -{ - NMConnection *connection; - NMSettingConnection *s_con; - const char *con_type = NULL, *id, *uuid, *ifname; - guint i; - const char *found_by_id = NULL; - const char *out_type_by_id = NULL; - const char *out_master = NULL; - const char *(*func) (NMConnection *) = NULL; - - if (!master) - return NULL; - - master = _strip_master_prefix (master, &func); - for (i = 0; i < connections->len; i++) { - connection = NM_CONNECTION (connections->pdata[i]); - s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); - con_type = nm_setting_connection_get_connection_type (s_con); - if (type && g_strcmp0 (con_type, type) != 0) - continue; - if (func) { - /* There was a prefix; only compare to that type. */ - if (g_strcmp0 (master, func (connection)) == 0) { - if (out_type) - *out_type = con_type; - if (func == nm_connection_get_id) - out_master = nm_connection_get_uuid (connection); - else - out_master = master; - break; - } - } else { - id = nm_connection_get_id (connection); - uuid = nm_connection_get_uuid (connection); - ifname = nm_connection_get_interface_name (connection); - if ( g_strcmp0 (master, uuid) == 0 - || g_strcmp0 (master, ifname) == 0) { - out_master = master; - if (out_type) - *out_type = con_type; - break; - } - if (!found_by_id && g_strcmp0 (master, id) == 0) { - out_type_by_id = con_type; - found_by_id = uuid; - } - } - } - - if (!out_master) { - out_master = found_by_id; - if (out_type) - *out_type = out_type_by_id; - } - - if (!out_master) { - g_print (_("Warning: master='%s' doesn't refer to any existing profile.\n"), master); - out_master = master; - if (out_type) - *out_type = type; - } - - return out_master; +normalized_master_for_slave(const GPtrArray *connections, + const char * master, + const char * type, + const char ** out_type) +{ + NMConnection * connection; + NMSettingConnection *s_con; + const char * con_type = NULL, *id, *uuid, *ifname; + guint i; + const char * found_by_id = NULL; + const char * out_type_by_id = NULL; + const char * out_master = NULL; + const char *(*func)(NMConnection *) = NULL; + + if (!master) + return NULL; + + master = _strip_master_prefix(master, &func); + for (i = 0; i < connections->len; i++) { + connection = NM_CONNECTION(connections->pdata[i]); + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + con_type = nm_setting_connection_get_connection_type(s_con); + if (type && g_strcmp0(con_type, type) != 0) + continue; + if (func) { + /* There was a prefix; only compare to that type. */ + if (g_strcmp0(master, func(connection)) == 0) { + if (out_type) + *out_type = con_type; + if (func == nm_connection_get_id) + out_master = nm_connection_get_uuid(connection); + else + out_master = master; + break; + } + } else { + id = nm_connection_get_id(connection); + uuid = nm_connection_get_uuid(connection); + ifname = nm_connection_get_interface_name(connection); + if (g_strcmp0(master, uuid) == 0 || g_strcmp0(master, ifname) == 0) { + out_master = master; + if (out_type) + *out_type = con_type; + break; + } + if (!found_by_id && g_strcmp0(master, id) == 0) { + out_type_by_id = con_type; + found_by_id = uuid; + } + } + } + + if (!out_master) { + out_master = found_by_id; + if (out_type) + *out_type = out_type_by_id; + } + + if (!out_master) { + g_print(_("Warning: master='%s' doesn't refer to any existing profile.\n"), master); + out_master = master; + if (out_type) + *out_type = type; + } + + return out_master; } #define WORD_YES "yes" #define WORD_NO "no" static const char * -prompt_yes_no (gboolean default_yes, char *delim) +prompt_yes_no(gboolean default_yes, char *delim) { - static char prompt[128] = { 0 }; + static char prompt[128] = {0}; - if (!delim) - delim = ""; + if (!delim) + delim = ""; - snprintf (prompt, sizeof (prompt), "(%s/%s) [%s]%s ", - WORD_YES, WORD_NO, - default_yes ? WORD_YES : WORD_NO, delim); + snprintf(prompt, + sizeof(prompt), + "(%s/%s) [%s]%s ", + WORD_YES, + WORD_NO, + default_yes ? WORD_YES : WORD_NO, + delim); - return prompt; + return prompt; } static NMSetting * -is_setting_valid (NMConnection *connection, const NMMetaSettingValidPartItem *const*valid_settings_main, const NMMetaSettingValidPartItem *const*valid_settings_slave, const char *setting) +is_setting_valid(NMConnection * connection, + const NMMetaSettingValidPartItem *const *valid_settings_main, + const NMMetaSettingValidPartItem *const *valid_settings_slave, + const char * setting) { - const char *setting_name; + const char *setting_name; - if (!(setting_name = check_valid_name (setting, valid_settings_main, valid_settings_slave, NULL))) - return NULL; - return nm_connection_get_setting_by_name (connection, setting_name); + if (!(setting_name = + check_valid_name(setting, valid_settings_main, valid_settings_slave, NULL))) + return NULL; + return nm_connection_get_setting_by_name(connection, setting_name); } static char * -is_property_valid (NMSetting *setting, const char *property, GError **error) +is_property_valid(NMSetting *setting, const char *property, GError **error) { - gs_strfreev char **valid_props = NULL; - const char *prop_name; + gs_strfreev char **valid_props = NULL; + const char * prop_name; - valid_props = nmc_setting_get_valid_properties (setting); - prop_name = nmc_string_is_valid (property, (const char **) valid_props, error); - return g_strdup (prop_name); + valid_props = nmc_setting_get_valid_properties(setting); + prop_name = nmc_string_is_valid(property, (const char **) valid_props, error); + return g_strdup(prop_name); } static char * -unique_master_iface_ifname (const GPtrArray *connections, - const char *try_name) +unique_master_iface_ifname(const GPtrArray *connections, const char *try_name) { - char *new_name; - guint num = 0; - guint i; + char *new_name; + guint num = 0; + guint i; - new_name = g_strdup (try_name); + new_name = g_strdup(try_name); again: - for (i = 0; i < connections->len; i++) { - NMConnection *connection = connections->pdata[i]; + for (i = 0; i < connections->len; i++) { + NMConnection *connection = connections->pdata[i]; - if (nm_streq0 (new_name, nm_connection_get_interface_name (connection))) { - num++; - g_free (new_name); - new_name = g_strdup_printf ("%s%u", try_name, num); - goto again; - } - } - return new_name; + if (nm_streq0(new_name, nm_connection_get_interface_name(connection))) { + num++; + g_free(new_name); + new_name = g_strdup_printf("%s%u", try_name, num); + goto again; + } + } + return new_name; } static void -set_default_interface_name (NmCli *nmc, - NMSettingConnection *s_con) +set_default_interface_name(NmCli *nmc, NMSettingConnection *s_con) { - const char *default_name; - const char *con_type; + const char *default_name; + const char *con_type; - if (nm_setting_connection_get_interface_name (s_con)) - return; + if (nm_setting_connection_get_interface_name(s_con)) + return; - con_type = nm_setting_connection_get_connection_type (s_con); + con_type = nm_setting_connection_get_connection_type(s_con); - /* Set a sensible bond/team/bridge interface name by default */ - if (nm_streq0 (con_type, NM_SETTING_BOND_SETTING_NAME)) - default_name = "nm-bond"; - else if (nm_streq0 (con_type, NM_SETTING_TEAM_SETTING_NAME)) - default_name = "nm-team"; - else if (nm_streq0 (con_type, NM_SETTING_BRIDGE_SETTING_NAME)) - default_name = "nm-bridge"; - else - default_name = NULL; + /* Set a sensible bond/team/bridge interface name by default */ + if (nm_streq0(con_type, NM_SETTING_BOND_SETTING_NAME)) + default_name = "nm-bond"; + else if (nm_streq0(con_type, NM_SETTING_TEAM_SETTING_NAME)) + default_name = "nm-team"; + else if (nm_streq0(con_type, NM_SETTING_BRIDGE_SETTING_NAME)) + default_name = "nm-bridge"; + else + default_name = NULL; - if (default_name) { - const GPtrArray *connections; - gs_free char *ifname = NULL; + if (default_name) { + const GPtrArray *connections; + gs_free char * ifname = NULL; - connections = nm_client_get_connections (nmc->client); - ifname = unique_master_iface_ifname (connections, default_name); - g_object_set (s_con, NM_SETTING_CONNECTION_INTERFACE_NAME, ifname, NULL); - } + connections = nm_client_get_connections(nmc->client); + ifname = unique_master_iface_ifname(connections, default_name); + g_object_set(s_con, NM_SETTING_CONNECTION_INTERFACE_NAME, ifname, NULL); + } } /*****************************************************************************/ static PropertyInfFlags -_dynamic_options_set (const NMMetaAbstractInfo *abstract_info, - PropertyInfFlags mask, PropertyInfFlags set) +_dynamic_options_set(const NMMetaAbstractInfo *abstract_info, + PropertyInfFlags mask, + PropertyInfFlags set) { - static GHashTable *cache = NULL; - gpointer p; - PropertyInfFlags v, v2; + static GHashTable *cache = NULL; + gpointer p; + PropertyInfFlags v, v2; - if (G_UNLIKELY (!cache)) - cache = g_hash_table_new (nm_direct_hash, NULL); + if (G_UNLIKELY(!cache)) + cache = g_hash_table_new(nm_direct_hash, NULL); - if (g_hash_table_lookup_extended (cache, (gpointer) abstract_info, NULL, &p)) - v = GPOINTER_TO_UINT (p); - else - v = 0; + if (g_hash_table_lookup_extended(cache, (gpointer) abstract_info, NULL, &p)) + v = GPOINTER_TO_UINT(p); + else + v = 0; - v2 = (v & ~mask) | (mask & set); - if (v != v2) - g_hash_table_insert (cache, (gpointer) abstract_info, GUINT_TO_POINTER (v2)); + v2 = (v & ~mask) | (mask & set); + if (v != v2) + g_hash_table_insert(cache, (gpointer) abstract_info, GUINT_TO_POINTER(v2)); - return v2; + return v2; } static PropertyInfFlags -_dynamic_options_get (const NMMetaAbstractInfo *abstract_info) +_dynamic_options_get(const NMMetaAbstractInfo *abstract_info) { - return _dynamic_options_set (abstract_info, 0, 0); + return _dynamic_options_set(abstract_info, 0, 0); } /*****************************************************************************/ static gboolean -_meta_property_needs_bond_hack (const NMMetaPropertyInfo *property_info) +_meta_property_needs_bond_hack(const NMMetaPropertyInfo *property_info) { - /* hack: the bond property data is handled special and not generically. - * Eventually, get rid of explicitly checking whether we handle a bond. */ - if (!property_info) - g_return_val_if_reached (FALSE); - return property_info->property_typ_data - && property_info->property_typ_data->nested == &nm_meta_property_typ_data_bond; - + /* hack: the bond property data is handled special and not generically. + * Eventually, get rid of explicitly checking whether we handle a bond. */ + if (!property_info) + g_return_val_if_reached(FALSE); + return property_info->property_typ_data + && property_info->property_typ_data->nested == &nm_meta_property_typ_data_bond; } static char ** -_meta_abstract_complete (const NMMetaAbstractInfo *abstract_info, const char *text) -{ - const char *const*values; - char **values_to_free = NULL; - const NMMetaOperationContext ctx = { - .connection = nmc_tab_completion.connection, - }; - - values = nm_meta_abstract_info_complete (abstract_info, - nmc_meta_environment, - (gpointer) nmc_meta_environment_arg, - &ctx, - text, - NULL, - &values_to_free); - if (values) - return values_to_free ?: g_strdupv ((char **) values); - return NULL; +_meta_abstract_complete(const NMMetaAbstractInfo *abstract_info, const char *text) +{ + const char *const * values; + char ** values_to_free = NULL; + const NMMetaOperationContext ctx = { + .connection = nmc_tab_completion.connection, + }; + + values = nm_meta_abstract_info_complete(abstract_info, + nmc_meta_environment, + (gpointer) nmc_meta_environment_arg, + &ctx, + text, + NULL, + &values_to_free); + if (values) + return values_to_free ?: g_strdupv((char **) values); + return NULL; } static char * -_meta_abstract_generator (const char *text, int state) +_meta_abstract_generator(const char *text, int state) { - if (nmc_tab_completion.words) { - return nmc_rl_gen_func_basic (text, - state, - (const char *const *) nmc_tab_completion.words); - } + if (nmc_tab_completion.words) { + return nmc_rl_gen_func_basic(text, state, (const char *const *) nmc_tab_completion.words); + } - return NULL; + return NULL; } static void -_meta_abstract_get (const NMMetaAbstractInfo *abstract_info, - const NMMetaSettingInfoEditor **out_setting_info, - const char **out_setting_name, - const char **out_property_name, - const char **out_option, - NMMetaPropertyInfFlags *out_inf_flags, - const char **out_prompt, - const char **out_def_hint) +_meta_abstract_get(const NMMetaAbstractInfo * abstract_info, + const NMMetaSettingInfoEditor **out_setting_info, + const char ** out_setting_name, + const char ** out_property_name, + const char ** out_option, + NMMetaPropertyInfFlags * out_inf_flags, + const char ** out_prompt, + const char ** out_def_hint) { - const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; + const NMMetaPropertyInfo *info = (const NMMetaPropertyInfo *) abstract_info; - NM_SET_OUT (out_option, info->property_alias); - NM_SET_OUT (out_setting_info, info->setting_info); - NM_SET_OUT (out_setting_name, info->setting_info->general->setting_name); - NM_SET_OUT (out_property_name, info->property_name); - NM_SET_OUT (out_option, info->property_alias); - NM_SET_OUT (out_inf_flags, info->inf_flags); - NM_SET_OUT (out_prompt, info->prompt); - NM_SET_OUT (out_def_hint, info->def_hint); + NM_SET_OUT(out_option, info->property_alias); + NM_SET_OUT(out_setting_info, info->setting_info); + NM_SET_OUT(out_setting_name, info->setting_info->general->setting_name); + NM_SET_OUT(out_property_name, info->property_name); + NM_SET_OUT(out_option, info->property_alias); + NM_SET_OUT(out_inf_flags, info->inf_flags); + NM_SET_OUT(out_prompt, info->prompt); + NM_SET_OUT(out_def_hint, info->def_hint); } -static const OptionInfo *_meta_abstract_get_option_info (const NMMetaAbstractInfo *abstract_info); +static const OptionInfo *_meta_abstract_get_option_info(const NMMetaAbstractInfo *abstract_info); /* * Mark options in option_info as relevant. * The questionnaire (for --ask) will ask for them. */ static void -enable_options (const char *setting_name, const char *property, const char * const *opts) +enable_options(const char *setting_name, const char *property, const char *const *opts) { - const NMMetaPropertyInfo *property_info; + const NMMetaPropertyInfo *property_info; - property_info = nm_meta_property_info_find_by_name (setting_name, property); + property_info = nm_meta_property_info_find_by_name(setting_name, property); - if (!property_info) - g_return_if_reached (); + if (!property_info) + g_return_if_reached(); - if (_meta_property_needs_bond_hack (property_info)) { - guint i; + if (_meta_property_needs_bond_hack(property_info)) { + guint i; - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; - if ( bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_DONT_ASK - && bi->base.property_alias - && g_strv_contains (opts, bi->base.property_alias)) - _dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_ENABLED, PROPERTY_INF_FLAG_ENABLED); - } - return; - } + if (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_DONT_ASK && bi->base.property_alias + && g_strv_contains(opts, bi->base.property_alias)) + _dynamic_options_set((const NMMetaAbstractInfo *) bi, + PROPERTY_INF_FLAG_ENABLED, + PROPERTY_INF_FLAG_ENABLED); + } + return; + } - if (!property_info->is_cli_option) - g_return_if_reached (); + if (!property_info->is_cli_option) + g_return_if_reached(); - if ( property_info->inf_flags & NM_META_PROPERTY_INF_FLAG_DONT_ASK - && property_info->property_alias - && g_strv_contains (opts, property_info->property_alias)) - _dynamic_options_set ((const NMMetaAbstractInfo *) property_info, PROPERTY_INF_FLAG_ENABLED, PROPERTY_INF_FLAG_ENABLED); + if (property_info->inf_flags & NM_META_PROPERTY_INF_FLAG_DONT_ASK + && property_info->property_alias && g_strv_contains(opts, property_info->property_alias)) + _dynamic_options_set((const NMMetaAbstractInfo *) property_info, + PROPERTY_INF_FLAG_ENABLED, + PROPERTY_INF_FLAG_ENABLED); } /* @@ -3885,52 +4006,55 @@ enable_options (const char *setting_name, const char *property, const char * con * The questionnaire (for --ask) will not ask for them. */ static void -disable_options (const char *setting_name, const char *property) -{ - const NMMetaPropertyInfo *property_infos_local[2]; - const NMMetaPropertyInfo *const*property_infos; - guint p; - - if (property) { - const NMMetaPropertyInfo *pi; - - pi = nm_meta_property_info_find_by_name (setting_name, property); - if (!pi) - g_return_if_reached (); - if ( !_meta_property_needs_bond_hack (pi) - && !pi->is_cli_option) - return; - property_infos_local[0] = pi; - property_infos_local[1] = NULL; - property_infos = property_infos_local; - } else { - const NMMetaSettingInfoEditor *setting_info; - - setting_info = nm_meta_setting_info_editor_find_by_name (setting_name, FALSE); - if (!setting_info) - g_return_if_reached (); - property_infos = setting_info->properties; - if (!property_infos) - return; - } - - for (p = 0; property_infos[p]; p++) { - const NMMetaPropertyInfo *property_info = property_infos[p]; - - if (_meta_property_needs_bond_hack (property_info)) { - guint i; - - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; - - _dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_DISABLED, PROPERTY_INF_FLAG_DISABLED); - } - nm_assert (p == 0 && !property_infos[1]); - } else { - if (property_info->is_cli_option) - _dynamic_options_set ((const NMMetaAbstractInfo *) property_info, PROPERTY_INF_FLAG_DISABLED, PROPERTY_INF_FLAG_DISABLED); - } - } +disable_options(const char *setting_name, const char *property) +{ + const NMMetaPropertyInfo * property_infos_local[2]; + const NMMetaPropertyInfo *const *property_infos; + guint p; + + if (property) { + const NMMetaPropertyInfo *pi; + + pi = nm_meta_property_info_find_by_name(setting_name, property); + if (!pi) + g_return_if_reached(); + if (!_meta_property_needs_bond_hack(pi) && !pi->is_cli_option) + return; + property_infos_local[0] = pi; + property_infos_local[1] = NULL; + property_infos = property_infos_local; + } else { + const NMMetaSettingInfoEditor *setting_info; + + setting_info = nm_meta_setting_info_editor_find_by_name(setting_name, FALSE); + if (!setting_info) + g_return_if_reached(); + property_infos = setting_info->properties; + if (!property_infos) + return; + } + + for (p = 0; property_infos[p]; p++) { + const NMMetaPropertyInfo *property_info = property_infos[p]; + + if (_meta_property_needs_bond_hack(property_info)) { + guint i; + + for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + + _dynamic_options_set((const NMMetaAbstractInfo *) bi, + PROPERTY_INF_FLAG_DISABLED, + PROPERTY_INF_FLAG_DISABLED); + } + nm_assert(p == 0 && !property_infos[1]); + } else { + if (property_info->is_cli_option) + _dynamic_options_set((const NMMetaAbstractInfo *) property_info, + PROPERTY_INF_FLAG_DISABLED, + PROPERTY_INF_FLAG_DISABLED); + } + } } /* @@ -3939,126 +4063,146 @@ disable_options (const char *setting_name, const char *property) * nmcli session. */ static void -reset_options (void) +reset_options(void) { - NMMetaSettingType s; + NMMetaSettingType s; - for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { - const NMMetaPropertyInfo *const*property_infos; - guint p; + for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { + const NMMetaPropertyInfo *const *property_infos; + guint p; - property_infos = nm_meta_setting_infos_editor[s].properties; - if (!property_infos) - continue; - for (p = 0; property_infos[p]; p++) { - const NMMetaPropertyInfo *property_info = property_infos[p]; + property_infos = nm_meta_setting_infos_editor[s].properties; + if (!property_infos) + continue; + for (p = 0; property_infos[p]; p++) { + const NMMetaPropertyInfo *property_info = property_infos[p]; - if (_meta_property_needs_bond_hack (property_info)) { - guint i; + if (_meta_property_needs_bond_hack(property_info)) { + guint i; - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; - _dynamic_options_set ((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_ALL, 0); - } - } else { - if (property_info->is_cli_option) - _dynamic_options_set ((const NMMetaAbstractInfo *) property_info, PROPERTY_INF_FLAG_ALL, 0); - } - } - } + _dynamic_options_set((const NMMetaAbstractInfo *) bi, PROPERTY_INF_FLAG_ALL, 0); + } + } else { + if (property_info->is_cli_option) + _dynamic_options_set((const NMMetaAbstractInfo *) property_info, + PROPERTY_INF_FLAG_ALL, + 0); + } + } + } } static gboolean -set_property (NMClient *client, - NMConnection *connection, - const char *setting_name, - const char *property, - const char *value, - NMMetaAccessorModifier modifier, - GError **error) -{ - gs_free char *property_name = NULL; - gs_free_error GError *local = NULL; - NMSetting *setting; - - nm_assert (setting_name && setting_name[0]); - nm_assert (NM_IN_SET (modifier, NM_META_ACCESSOR_MODIFIER_SET, - NM_META_ACCESSOR_MODIFIER_ADD, - NM_META_ACCESSOR_MODIFIER_DEL)); - - setting = nm_connection_get_setting_by_name (connection, setting_name); - if (!setting) { - setting = nm_meta_setting_info_editor_new_setting (nm_meta_setting_info_editor_find_by_name (setting_name, FALSE), - NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI); - nm_connection_add_setting (connection, setting); - } - - property_name = is_property_valid (setting, property, &local); - if (!property_name) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: invalid property '%s': %s."), - property, local->message); - return FALSE; - } - - if (!nmc_setting_set_property (client, - setting, - property_name, - ( ( modifier == NM_META_ACCESSOR_MODIFIER_DEL - && !value) - ? NM_META_ACCESSOR_MODIFIER_SET - : modifier), - value, - &local)) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: failed to %s %s.%s: %s."), - ( modifier != NM_META_ACCESSOR_MODIFIER_DEL - ? "modify" - : "remove a value from"), - setting_name, - property, - local->message); - return FALSE; - } - - /* Don't ask for this property in interactive mode. */ - disable_options (setting_name, property_name); - - return TRUE; +set_property(NMClient * client, + NMConnection * connection, + const char * setting_name, + const char * property, + const char * value, + NMMetaAccessorModifier modifier, + GError ** error) +{ + gs_free char *property_name = NULL; + gs_free_error GError *local = NULL; + NMSetting * setting; + + nm_assert(setting_name && setting_name[0]); + nm_assert(NM_IN_SET(modifier, + NM_META_ACCESSOR_MODIFIER_SET, + NM_META_ACCESSOR_MODIFIER_ADD, + NM_META_ACCESSOR_MODIFIER_DEL)); + + setting = nm_connection_get_setting_by_name(connection, setting_name); + if (!setting) { + setting = nm_meta_setting_info_editor_new_setting( + nm_meta_setting_info_editor_find_by_name(setting_name, FALSE), + NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI); + nm_connection_add_setting(connection, setting); + } + + property_name = is_property_valid(setting, property, &local); + if (!property_name) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: invalid property '%s': %s."), + property, + local->message); + return FALSE; + } + + if (!nmc_setting_set_property(client, + setting, + property_name, + ((modifier == NM_META_ACCESSOR_MODIFIER_DEL && !value) + ? NM_META_ACCESSOR_MODIFIER_SET + : modifier), + value, + &local)) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: failed to %s %s.%s: %s."), + (modifier != NM_META_ACCESSOR_MODIFIER_DEL ? "modify" : "remove a value from"), + setting_name, + property, + local->message); + return FALSE; + } + + /* Don't ask for this property in interactive mode. */ + disable_options(setting_name, property_name); + + return TRUE; } static gboolean -set_option (NmCli *nmc, NMConnection *connection, const NMMetaAbstractInfo *abstract_info, const char *value, GError **error) -{ - const char *setting_name, *property_name, *option_name; - NMMetaPropertyInfFlags inf_flags; - const OptionInfo *option; - - option = _meta_abstract_get_option_info (abstract_info); - - _dynamic_options_set (abstract_info, PROPERTY_INF_FLAG_DISABLED, PROPERTY_INF_FLAG_DISABLED); - - _meta_abstract_get (abstract_info, NULL, &setting_name, &property_name, &option_name, &inf_flags, NULL, NULL); - if (option && option->check_and_set) { - return option->check_and_set (nmc, connection, option, value, error); - } else if (value) { - return set_property (nmc->client, - connection, - setting_name, - property_name, - value, - inf_flags & NM_META_PROPERTY_INF_FLAG_MULTI - ? NM_META_ACCESSOR_MODIFIER_ADD - : NM_META_ACCESSOR_MODIFIER_SET, - error); - } else if (inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: '%s' is mandatory."), option_name); - return FALSE; - } - - return TRUE; +set_option(NmCli * nmc, + NMConnection * connection, + const NMMetaAbstractInfo *abstract_info, + const char * value, + GError ** error) +{ + const char * setting_name, *property_name, *option_name; + NMMetaPropertyInfFlags inf_flags; + const OptionInfo * option; + + option = _meta_abstract_get_option_info(abstract_info); + + _dynamic_options_set(abstract_info, PROPERTY_INF_FLAG_DISABLED, PROPERTY_INF_FLAG_DISABLED); + + _meta_abstract_get(abstract_info, + NULL, + &setting_name, + &property_name, + &option_name, + &inf_flags, + NULL, + NULL); + if (option && option->check_and_set) { + return option->check_and_set(nmc, connection, option, value, error); + } else if (value) { + return set_property(nmc->client, + connection, + setting_name, + property_name, + value, + inf_flags & NM_META_PROPERTY_INF_FLAG_MULTI + ? NM_META_ACCESSOR_MODIFIER_ADD + : NM_META_ACCESSOR_MODIFIER_SET, + error); + } else if (inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: '%s' is mandatory."), + option_name); + return FALSE; + } + + return TRUE; } /* @@ -4066,34 +4210,43 @@ set_option (NmCli *nmc, NMConnection *connection, const NMMetaAbstractInfo *abst * and slave type. */ static gboolean -con_settings (NMConnection *connection, const NMMetaSettingValidPartItem *const**type_settings, const NMMetaSettingValidPartItem *const**slv_settings, GError **error) -{ - const char *con_type; - NMSettingConnection *s_con; - - g_return_val_if_fail (type_settings, FALSE); - g_return_val_if_fail (slv_settings, FALSE); - - s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); - - con_type = nm_setting_connection_get_slave_type (s_con); - *slv_settings = nm_meta_setting_info_valid_parts_for_slave_type (con_type, NULL); - if (!*slv_settings) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: invalid slave type; %s."), con_type); - return FALSE; - } - - con_type = nm_setting_connection_get_connection_type (s_con); - *type_settings = get_valid_settings_array (con_type); - if (!*type_settings) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: invalid connection type; %s."), con_type); - return FALSE; - } - - return TRUE; +con_settings(NMConnection * connection, + const NMMetaSettingValidPartItem *const **type_settings, + const NMMetaSettingValidPartItem *const **slv_settings, + GError ** error) +{ + const char * con_type; + NMSettingConnection *s_con; + + g_return_val_if_fail(type_settings, FALSE); + g_return_val_if_fail(slv_settings, FALSE); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + + con_type = nm_setting_connection_get_slave_type(s_con); + *slv_settings = nm_meta_setting_info_valid_parts_for_slave_type(con_type, NULL); + if (!*slv_settings) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: invalid slave type; %s."), + con_type); + return FALSE; + } + + con_type = nm_setting_connection_get_connection_type(s_con); + *type_settings = get_valid_settings_array(con_type); + if (!*type_settings) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: invalid connection type; %s."), + con_type); + return FALSE; + } + + return TRUE; } /* @@ -4101,1720 +4254,1868 @@ con_settings (NMConnection *connection, const NMMetaSettingValidPartItem *const* * it's possible that a type is already set). */ static void -ensure_settings (NMConnection *connection, const NMMetaSettingValidPartItem *const*item) +ensure_settings(NMConnection *connection, const NMMetaSettingValidPartItem *const *item) { - NMSetting *setting; + NMSetting *setting; - for (; item && *item; item++) { - if (!(*item)->mandatory) - continue; - if (nm_connection_get_setting_by_name (connection, (*item)->setting_info->general->setting_name)) - continue; - setting = nm_meta_setting_info_editor_new_setting ((*item)->setting_info, - NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI); - nm_connection_add_setting (connection, setting); - } + for (; item && *item; item++) { + if (!(*item)->mandatory) + continue; + if (nm_connection_get_setting_by_name(connection, + (*item)->setting_info->general->setting_name)) + continue; + setting = nm_meta_setting_info_editor_new_setting((*item)->setting_info, + NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI); + nm_connection_add_setting(connection, setting); + } } /*****************************************************************************/ static char * -gen_func_bool_values_l10n (const char *text, int state) +gen_func_bool_values_l10n(const char *text, int state) { - const char *words[] = { WORD_YES, WORD_NO, NULL }; - return nmc_rl_gen_func_basic (text, state, words); + const char *words[] = {WORD_YES, WORD_NO, NULL}; + return nmc_rl_gen_func_basic(text, state, words); } static char * -gen_func_bt_type (const char *text, int state) +gen_func_bt_type(const char *text, int state) { - const char *words[] = { "panu", "nap", "dun-gsm", "dun-cdma", NULL }; - return nmc_rl_gen_func_basic (text, state, words); + const char *words[] = {"panu", "nap", "dun-gsm", "dun-cdma", NULL}; + return nmc_rl_gen_func_basic(text, state, words); } static char * -gen_func_bond_mode (const char *text, int state) -{ - const char *words[] = { "balance-rr", "active-backup", "balance-xor", "broadcast", - "802.3ad", "balance-tlb", "balance-alb", NULL }; - return nmc_rl_gen_func_basic (text, state, words); +gen_func_bond_mode(const char *text, int state) +{ + const char *words[] = {"balance-rr", + "active-backup", + "balance-xor", + "broadcast", + "802.3ad", + "balance-tlb", + "balance-alb", + NULL}; + return nmc_rl_gen_func_basic(text, state, words); } static char * -gen_func_bond_mon_mode (const char *text, int state) +gen_func_bond_mon_mode(const char *text, int state) { - const char *words[] = { "miimon", "arp", NULL }; - return nmc_rl_gen_func_basic (text, state, words); + const char *words[] = {"miimon", "arp", NULL}; + return nmc_rl_gen_func_basic(text, state, words); } static char * -gen_func_bond_lacp_rate (const char *text, int state) +gen_func_bond_lacp_rate(const char *text, int state) { - const char *words[] = { "slow", "fast", NULL }; - return nmc_rl_gen_func_basic (text, state, words); + const char *words[] = {"slow", "fast", NULL}; + return nmc_rl_gen_func_basic(text, state, words); } /*****************************************************************************/ static gboolean -set_connection_type (NmCli *nmc, NMConnection *con, const OptionInfo *option, const char *value, GError **error) -{ - const NMMetaSettingValidPartItem *const*type_settings; - const NMMetaSettingValidPartItem *const*slv_settings; - GError *local = NULL; - const char *master[] = { "master", NULL }; - const char *slave_type = NULL; - - value = check_valid_name_toplevel (value, &slave_type, &local); - if (!value) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: bad connection type: %s"), local->message); - g_clear_error (&local); - return FALSE; - } - - if (slave_type) { - if (!set_property (nmc->client, - con, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_SLAVE_TYPE, - slave_type, - NM_META_ACCESSOR_MODIFIER_SET, - error)) { - return FALSE; - } - enable_options (NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, master); - } - - /* ifname is mandatory for all connection types except virtual ones (bond, team, bridge, vlan) */ - if ( (strcmp (value, NM_SETTING_BOND_SETTING_NAME) == 0) - || (strcmp (value, NM_SETTING_TEAM_SETTING_NAME) == 0) - || (strcmp (value, NM_SETTING_BRIDGE_SETTING_NAME) == 0) - || (strcmp (value, NM_SETTING_VLAN_SETTING_NAME) == 0)) { - disable_options (NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_INTERFACE_NAME); - } - - if (!set_property (nmc->client, - con, - option->setting_info->general->setting_name, - option->property, - value, - NM_META_ACCESSOR_MODIFIER_SET, - error)) - return FALSE; - - if (!con_settings (con, &type_settings, &slv_settings, error)) - return FALSE; - - ensure_settings (con, slv_settings); - ensure_settings (con, type_settings); - - return TRUE; +set_connection_type(NmCli * nmc, + NMConnection * con, + const OptionInfo *option, + const char * value, + GError ** error) +{ + const NMMetaSettingValidPartItem *const *type_settings; + const NMMetaSettingValidPartItem *const *slv_settings; + GError * local = NULL; + const char * master[] = {"master", NULL}; + const char * slave_type = NULL; + + value = check_valid_name_toplevel(value, &slave_type, &local); + if (!value) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: bad connection type: %s"), + local->message); + g_clear_error(&local); + return FALSE; + } + + if (slave_type) { + if (!set_property(nmc->client, + con, + NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_SLAVE_TYPE, + slave_type, + NM_META_ACCESSOR_MODIFIER_SET, + error)) { + return FALSE; + } + enable_options(NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_MASTER, master); + } + + /* ifname is mandatory for all connection types except virtual ones (bond, team, bridge, vlan) */ + if ((strcmp(value, NM_SETTING_BOND_SETTING_NAME) == 0) + || (strcmp(value, NM_SETTING_TEAM_SETTING_NAME) == 0) + || (strcmp(value, NM_SETTING_BRIDGE_SETTING_NAME) == 0) + || (strcmp(value, NM_SETTING_VLAN_SETTING_NAME) == 0)) { + disable_options(NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME); + } + + if (!set_property(nmc->client, + con, + option->setting_info->general->setting_name, + option->property, + value, + NM_META_ACCESSOR_MODIFIER_SET, + error)) + return FALSE; + + if (!con_settings(con, &type_settings, &slv_settings, error)) + return FALSE; + + ensure_settings(con, slv_settings); + ensure_settings(con, type_settings); + + return TRUE; } static gboolean -set_connection_iface (NmCli *nmc, NMConnection *con, const OptionInfo *option, const char *value, GError **error) -{ - if (value) { - /* Special value of '*' means no specific interface name */ - if (strcmp (value, "*") == 0) - value = NULL; - } - - return set_property (nmc->client, - con, - option->setting_info->general->setting_name, - option->property, - value, - NM_META_ACCESSOR_MODIFIER_SET, - error); +set_connection_iface(NmCli * nmc, + NMConnection * con, + const OptionInfo *option, + const char * value, + GError ** error) +{ + if (value) { + /* Special value of '*' means no specific interface name */ + if (strcmp(value, "*") == 0) + value = NULL; + } + + return set_property(nmc->client, + con, + option->setting_info->general->setting_name, + option->property, + value, + NM_META_ACCESSOR_MODIFIER_SET, + error); } static gboolean -set_connection_master (NmCli *nmc, NMConnection *con, const OptionInfo *option, const char *value, GError **error) -{ - const GPtrArray *connections; - NMSettingConnection *s_con; - const char *slave_type; - - s_con = nm_connection_get_setting_connection (con); - g_return_val_if_fail (s_con, FALSE); - - if (!value) { - g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: master is required")); - return FALSE; - } - - slave_type = nm_setting_connection_get_slave_type (s_con); - connections = nm_client_get_connections (nmc->client); - value = normalized_master_for_slave (connections, value, slave_type, &slave_type); - - if (!set_property (nmc->client, - con, - NM_SETTING_CONNECTION_SETTING_NAME, - NM_SETTING_CONNECTION_SLAVE_TYPE, - slave_type, - NM_META_ACCESSOR_MODIFIER_SET, - error)) { - return FALSE; - } - - return set_property (nmc->client, - con, - option->setting_info->general->setting_name, - option->property, - value, - NM_META_ACCESSOR_MODIFIER_SET, - error); +set_connection_master(NmCli * nmc, + NMConnection * con, + const OptionInfo *option, + const char * value, + GError ** error) +{ + const GPtrArray * connections; + NMSettingConnection *s_con; + const char * slave_type; + + s_con = nm_connection_get_setting_connection(con); + g_return_val_if_fail(s_con, FALSE); + + if (!value) { + g_set_error_literal(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: master is required")); + return FALSE; + } + + slave_type = nm_setting_connection_get_slave_type(s_con); + connections = nm_client_get_connections(nmc->client); + value = normalized_master_for_slave(connections, value, slave_type, &slave_type); + + if (!set_property(nmc->client, + con, + NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_SLAVE_TYPE, + slave_type, + NM_META_ACCESSOR_MODIFIER_SET, + error)) { + return FALSE; + } + + return set_property(nmc->client, + con, + option->setting_info->general->setting_name, + option->property, + value, + NM_META_ACCESSOR_MODIFIER_SET, + error); } static gboolean -set_bond_option (NmCli *nmc, NMConnection *con, const OptionInfo *option, const char *value, GError **error) -{ - NMSettingBond *s_bond; - gboolean success; - gs_free char *name = NULL; - char *p; - - s_bond = nm_connection_get_setting_bond (con); - g_return_val_if_fail (s_bond, FALSE); - - name = g_strdup (option->option); - for (p = name; p[0]; p++) { - if (p[0] == '-') - p[0] = '_'; - } - - if (nm_str_is_empty (value)) { - nm_setting_bond_remove_option (s_bond, name); - success = TRUE; - } else - success = _nm_meta_setting_bond_add_option (NM_SETTING (s_bond), name, value, error); - - if (!success) - return FALSE; - - if (success) { - if (nm_streq (name, NM_SETTING_BOND_OPTION_MODE)) { - value = nmc_bond_validate_mode (value, error); - if (nm_streq (value, "active-backup")) { - enable_options (NM_SETTING_BOND_SETTING_NAME, - NM_SETTING_BOND_OPTIONS, - NM_MAKE_STRV ("primary")); - } - } - } - - return success; +set_bond_option(NmCli * nmc, + NMConnection * con, + const OptionInfo *option, + const char * value, + GError ** error) +{ + NMSettingBond *s_bond; + gboolean success; + gs_free char * name = NULL; + char * p; + + s_bond = nm_connection_get_setting_bond(con); + g_return_val_if_fail(s_bond, FALSE); + + name = g_strdup(option->option); + for (p = name; p[0]; p++) { + if (p[0] == '-') + p[0] = '_'; + } + + if (nm_str_is_empty(value)) { + nm_setting_bond_remove_option(s_bond, name); + success = TRUE; + } else + success = _nm_meta_setting_bond_add_option(NM_SETTING(s_bond), name, value, error); + + if (!success) + return FALSE; + + if (success) { + if (nm_streq(name, NM_SETTING_BOND_OPTION_MODE)) { + value = nmc_bond_validate_mode(value, error); + if (nm_streq(value, "active-backup")) { + enable_options(NM_SETTING_BOND_SETTING_NAME, + NM_SETTING_BOND_OPTIONS, + NM_MAKE_STRV("primary")); + } + } + } + + return success; } static gboolean -set_bond_monitoring_mode (NmCli *nmc, NMConnection *con, const OptionInfo *option, const char *value, GError **error) -{ - NMSettingBond *s_bond; - gs_free char *monitor_mode = NULL; - const char *miimon_opts[] = { "miimon", "downdelay", "updelay", NULL }; - const char *arp_opts[] = { "arp-interval", "arp-ip-target", NULL }; - - s_bond = nm_connection_get_setting_bond (con); - g_return_val_if_fail (s_bond, FALSE); - - if (value) { - monitor_mode = g_strdup (value); - g_strstrip (monitor_mode); - } else { - monitor_mode = g_strdup (NM_META_TEXT_WORD_MIIMON); - } - - if (matches (monitor_mode, NM_META_TEXT_WORD_MIIMON)) - enable_options (NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS, miimon_opts); - else if (matches (monitor_mode, NM_META_TEXT_WORD_ARP)) - enable_options (NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS, arp_opts); - else { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: '%s' is not a valid monitoring mode; use '%s' or '%s'.\n"), - monitor_mode, NM_META_TEXT_WORD_MIIMON, NM_META_TEXT_WORD_ARP); - return FALSE; - } - - return TRUE; +set_bond_monitoring_mode(NmCli * nmc, + NMConnection * con, + const OptionInfo *option, + const char * value, + GError ** error) +{ + NMSettingBond *s_bond; + gs_free char * monitor_mode = NULL; + const char * miimon_opts[] = {"miimon", "downdelay", "updelay", NULL}; + const char * arp_opts[] = {"arp-interval", "arp-ip-target", NULL}; + + s_bond = nm_connection_get_setting_bond(con); + g_return_val_if_fail(s_bond, FALSE); + + if (value) { + monitor_mode = g_strdup(value); + g_strstrip(monitor_mode); + } else { + monitor_mode = g_strdup(NM_META_TEXT_WORD_MIIMON); + } + + if (matches(monitor_mode, NM_META_TEXT_WORD_MIIMON)) + enable_options(NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS, miimon_opts); + else if (matches(monitor_mode, NM_META_TEXT_WORD_ARP)) + enable_options(NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS, arp_opts); + else { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: '%s' is not a valid monitoring mode; use '%s' or '%s'.\n"), + monitor_mode, + NM_META_TEXT_WORD_MIIMON, + NM_META_TEXT_WORD_ARP); + return FALSE; + } + + return TRUE; } static gboolean -set_bluetooth_type (NmCli *nmc, NMConnection *con, const OptionInfo *option, const char *value, GError **error) -{ - NMSetting *setting; - - if (!value) - return TRUE; - - /* 'dun' type requires adding 'gsm' or 'cdma' setting */ - if ( !strcmp (value, NM_SETTING_BLUETOOTH_TYPE_DUN) - || !strcmp (value, NM_SETTING_BLUETOOTH_TYPE_DUN"-gsm")) { - value = NM_SETTING_BLUETOOTH_TYPE_DUN; - setting = nm_meta_setting_info_editor_new_setting (&nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_GSM], - NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI); - nm_connection_add_setting (con, setting); - } else if (!strcmp (value, NM_SETTING_BLUETOOTH_TYPE_DUN"-cdma")) { - value = NM_SETTING_BLUETOOTH_TYPE_DUN; - setting = nm_setting_cdma_new (); - nm_connection_add_setting (con, setting); - } else if (!strcmp (value, NM_SETTING_BLUETOOTH_TYPE_PANU) || !strcmp (value, NM_SETTING_BLUETOOTH_TYPE_NAP)) { - /* no op */ - } else { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: 'bt-type': '%s' not valid; use [%s, %s, %s (%s), %s]."), - value, NM_SETTING_BLUETOOTH_TYPE_PANU, NM_SETTING_BLUETOOTH_TYPE_NAP, - NM_SETTING_BLUETOOTH_TYPE_DUN, NM_SETTING_BLUETOOTH_TYPE_DUN"-gsm", - NM_SETTING_BLUETOOTH_TYPE_DUN"-cdma"); - return FALSE; - } - - return set_property (nmc->client, - con, - option->setting_info->general->setting_name, - option->property, - value, - NM_META_ACCESSOR_MODIFIER_SET, - error); +set_bluetooth_type(NmCli * nmc, + NMConnection * con, + const OptionInfo *option, + const char * value, + GError ** error) +{ + NMSetting *setting; + + if (!value) + return TRUE; + + /* 'dun' type requires adding 'gsm' or 'cdma' setting */ + if (!strcmp(value, NM_SETTING_BLUETOOTH_TYPE_DUN) + || !strcmp(value, NM_SETTING_BLUETOOTH_TYPE_DUN "-gsm")) { + value = NM_SETTING_BLUETOOTH_TYPE_DUN; + setting = nm_meta_setting_info_editor_new_setting( + &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_GSM], + NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI); + nm_connection_add_setting(con, setting); + } else if (!strcmp(value, NM_SETTING_BLUETOOTH_TYPE_DUN "-cdma")) { + value = NM_SETTING_BLUETOOTH_TYPE_DUN; + setting = nm_setting_cdma_new(); + nm_connection_add_setting(con, setting); + } else if (!strcmp(value, NM_SETTING_BLUETOOTH_TYPE_PANU) + || !strcmp(value, NM_SETTING_BLUETOOTH_TYPE_NAP)) { + /* no op */ + } else { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: 'bt-type': '%s' not valid; use [%s, %s, %s (%s), %s]."), + value, + NM_SETTING_BLUETOOTH_TYPE_PANU, + NM_SETTING_BLUETOOTH_TYPE_NAP, + NM_SETTING_BLUETOOTH_TYPE_DUN, + NM_SETTING_BLUETOOTH_TYPE_DUN "-gsm", + NM_SETTING_BLUETOOTH_TYPE_DUN "-cdma"); + return FALSE; + } + + return set_property(nmc->client, + con, + option->setting_info->general->setting_name, + option->property, + value, + NM_META_ACCESSOR_MODIFIER_SET, + error); } static gboolean -set_ip4_address (NmCli *nmc, NMConnection *con, const OptionInfo *option, const char *value, GError **error) -{ - NMSettingIPConfig *s_ip4; - - if (!value) - return TRUE; - - s_ip4 = nm_connection_get_setting_ip4_config (con); - if (!s_ip4) { - s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new (); - nm_connection_add_setting (con, NM_SETTING (s_ip4)); - g_object_set (s_ip4, - NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NULL); - } - return set_property (nmc->client, - con, - option->setting_info->general->setting_name, - option->property, - value, - NM_META_ACCESSOR_MODIFIER_ADD, - error); +set_ip4_address(NmCli * nmc, + NMConnection * con, + const OptionInfo *option, + const char * value, + GError ** error) +{ + NMSettingIPConfig *s_ip4; + + if (!value) + return TRUE; + + s_ip4 = nm_connection_get_setting_ip4_config(con); + if (!s_ip4) { + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(con, NM_SETTING(s_ip4)); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, NULL); + } + return set_property(nmc->client, + con, + option->setting_info->general->setting_name, + option->property, + value, + NM_META_ACCESSOR_MODIFIER_ADD, + error); } static gboolean -set_ip6_address (NmCli *nmc, NMConnection *con, const OptionInfo *option, const char *value, GError **error) -{ - NMSettingIPConfig *s_ip6; - - if (!value) - return TRUE; - - s_ip6 = nm_connection_get_setting_ip6_config (con); - if (!s_ip6) { - s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); - nm_connection_add_setting (con, NM_SETTING (s_ip6)); - g_object_set (s_ip6, - NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, - NULL); - } - return set_property (nmc->client, - con, - option->setting_info->general->setting_name, - option->property, - value, - NM_META_ACCESSOR_MODIFIER_ADD, - error); +set_ip6_address(NmCli * nmc, + NMConnection * con, + const OptionInfo *option, + const char * value, + GError ** error) +{ + NMSettingIPConfig *s_ip6; + + if (!value) + return TRUE; + + s_ip6 = nm_connection_get_setting_ip6_config(con); + if (!s_ip6) { + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(con, NM_SETTING(s_ip6)); + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, NULL); + } + return set_property(nmc->client, + con, + option->setting_info->general->setting_name, + option->property, + value, + NM_META_ACCESSOR_MODIFIER_ADD, + error); } /*****************************************************************************/ static const OptionInfo * -_meta_abstract_get_option_info (const NMMetaAbstractInfo *abstract_info) +_meta_abstract_get_option_info(const NMMetaAbstractInfo *abstract_info) { - static const OptionInfo option_info[] = { + static const OptionInfo option_info[] = { #define OPTION_INFO(name, property_name_, property_alias_, check_and_set_, generator_func_) \ - { \ - .setting_info = &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_##name], \ - .property = property_name_, \ - .option = property_alias_, \ - .check_and_set = check_and_set_, \ - .generator_func = generator_func_, \ - } - OPTION_INFO (CONNECTION, NM_SETTING_CONNECTION_TYPE, "type", set_connection_type, NULL), - OPTION_INFO (CONNECTION, NM_SETTING_CONNECTION_INTERFACE_NAME, "ifname", set_connection_iface, NULL), - OPTION_INFO (CONNECTION, NM_SETTING_CONNECTION_MASTER, "master", set_connection_master, NULL), - OPTION_INFO (BLUETOOTH, NM_SETTING_BLUETOOTH_TYPE, "bt-type", set_bluetooth_type, gen_func_bt_type), - OPTION_INFO (BOND, NM_SETTING_BOND_OPTIONS, "mode", set_bond_option, gen_func_bond_mode), - OPTION_INFO (BOND, NM_SETTING_BOND_OPTIONS, "primary", set_bond_option, nmc_rl_gen_func_ifnames), - OPTION_INFO (BOND, NM_SETTING_BOND_OPTIONS, NULL, set_bond_monitoring_mode, gen_func_bond_mon_mode), - OPTION_INFO (BOND, NM_SETTING_BOND_OPTIONS, "miimon", set_bond_option, NULL), - OPTION_INFO (BOND, NM_SETTING_BOND_OPTIONS, "downdelay", set_bond_option, NULL), - OPTION_INFO (BOND, NM_SETTING_BOND_OPTIONS, "updelay", set_bond_option, NULL), - OPTION_INFO (BOND, NM_SETTING_BOND_OPTIONS, "arp-interval", set_bond_option, NULL), - OPTION_INFO (BOND, NM_SETTING_BOND_OPTIONS, "arp-ip-target", set_bond_option, NULL), - OPTION_INFO (BOND, NM_SETTING_BOND_OPTIONS, "lacp-rate", set_bond_option, gen_func_bond_lacp_rate), - OPTION_INFO (IP4_CONFIG, NM_SETTING_IP_CONFIG_ADDRESSES, "ip4", set_ip4_address, NULL), - OPTION_INFO (IP6_CONFIG, NM_SETTING_IP_CONFIG_ADDRESSES, "ip6", set_ip6_address, NULL), - { 0 }, - }; - const char *property_name, *option; - const NMMetaSettingInfoEditor *setting_info; - const OptionInfo *candidate; - - _meta_abstract_get (abstract_info, &setting_info, NULL, &property_name, &option, NULL, NULL, NULL); - - for (candidate = option_info; candidate->setting_info; candidate++) { - if ( candidate->setting_info == setting_info - && nm_streq0 (candidate->property, property_name) - && nm_streq0 (candidate->option, option)) { - return candidate; - } - } - return NULL; + { \ + .setting_info = &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_##name], \ + .property = property_name_, \ + .option = property_alias_, \ + .check_and_set = check_and_set_, \ + .generator_func = generator_func_, \ + } + OPTION_INFO(CONNECTION, NM_SETTING_CONNECTION_TYPE, "type", set_connection_type, NULL), + OPTION_INFO(CONNECTION, + NM_SETTING_CONNECTION_INTERFACE_NAME, + "ifname", + set_connection_iface, + NULL), + OPTION_INFO(CONNECTION, + NM_SETTING_CONNECTION_MASTER, + "master", + set_connection_master, + NULL), + OPTION_INFO(BLUETOOTH, + NM_SETTING_BLUETOOTH_TYPE, + "bt-type", + set_bluetooth_type, + gen_func_bt_type), + OPTION_INFO(BOND, NM_SETTING_BOND_OPTIONS, "mode", set_bond_option, gen_func_bond_mode), + OPTION_INFO(BOND, + NM_SETTING_BOND_OPTIONS, + "primary", + set_bond_option, + nmc_rl_gen_func_ifnames), + OPTION_INFO(BOND, + NM_SETTING_BOND_OPTIONS, + NULL, + set_bond_monitoring_mode, + gen_func_bond_mon_mode), + OPTION_INFO(BOND, NM_SETTING_BOND_OPTIONS, "miimon", set_bond_option, NULL), + OPTION_INFO(BOND, NM_SETTING_BOND_OPTIONS, "downdelay", set_bond_option, NULL), + OPTION_INFO(BOND, NM_SETTING_BOND_OPTIONS, "updelay", set_bond_option, NULL), + OPTION_INFO(BOND, NM_SETTING_BOND_OPTIONS, "arp-interval", set_bond_option, NULL), + OPTION_INFO(BOND, NM_SETTING_BOND_OPTIONS, "arp-ip-target", set_bond_option, NULL), + OPTION_INFO(BOND, + NM_SETTING_BOND_OPTIONS, + "lacp-rate", + set_bond_option, + gen_func_bond_lacp_rate), + OPTION_INFO(IP4_CONFIG, NM_SETTING_IP_CONFIG_ADDRESSES, "ip4", set_ip4_address, NULL), + OPTION_INFO(IP6_CONFIG, NM_SETTING_IP_CONFIG_ADDRESSES, "ip6", set_ip6_address, NULL), + {0}, + }; + const char * property_name, *option; + const NMMetaSettingInfoEditor *setting_info; + const OptionInfo * candidate; + + _meta_abstract_get(abstract_info, + &setting_info, + NULL, + &property_name, + &option, + NULL, + NULL, + NULL); + + for (candidate = option_info; candidate->setting_info; candidate++) { + if (candidate->setting_info == setting_info && nm_streq0(candidate->property, property_name) + && nm_streq0(candidate->option, option)) { + return candidate; + } + } + return NULL; } static gboolean -option_relevant (NMConnection *connection, const NMMetaAbstractInfo *abstract_info) +option_relevant(NMConnection *connection, const NMMetaAbstractInfo *abstract_info) { - const char *setting_name; - NMMetaPropertyInfFlags inf_flags; + const char * setting_name; + NMMetaPropertyInfFlags inf_flags; - _meta_abstract_get (abstract_info, NULL, &setting_name, NULL, NULL, &inf_flags, NULL, NULL); + _meta_abstract_get(abstract_info, NULL, &setting_name, NULL, NULL, &inf_flags, NULL, NULL); - if ( (inf_flags & NM_META_PROPERTY_INF_FLAG_DONT_ASK) - && !(_dynamic_options_get (abstract_info) & PROPERTY_INF_FLAG_ENABLED)) - return FALSE; - if (_dynamic_options_get (abstract_info) & PROPERTY_INF_FLAG_DISABLED) - return FALSE; - if (!nm_connection_get_setting_by_name (connection, setting_name)) - return FALSE; - return TRUE; + if ((inf_flags & NM_META_PROPERTY_INF_FLAG_DONT_ASK) + && !(_dynamic_options_get(abstract_info) & PROPERTY_INF_FLAG_ENABLED)) + return FALSE; + if (_dynamic_options_get(abstract_info) & PROPERTY_INF_FLAG_DISABLED) + return FALSE; + if (!nm_connection_get_setting_by_name(connection, setting_name)) + return FALSE; + return TRUE; } /*****************************************************************************/ static void -complete_property_name (NmCli *nmc, NMConnection *connection, - NMMetaAccessorModifier modifier, - const char *prefix, - const char *postfix) -{ - NMSettingConnection *s_con; - const NMMetaSettingValidPartItem *const*valid_settings_main; - const NMMetaSettingValidPartItem *const*valid_settings_slave; - const char *connection_type = NULL; - const char *slave_type = NULL; - gs_free char *word_list = NULL; - NMMetaSettingType s; - - connection_type = nm_connection_get_connection_type (connection); - s_con = nm_connection_get_setting_connection (connection); - if (s_con) - slave_type = nm_setting_connection_get_slave_type (s_con); - valid_settings_main = get_valid_settings_array (connection_type); - valid_settings_slave = nm_meta_setting_info_valid_parts_for_slave_type (slave_type, NULL); - - word_list = get_valid_properties_string (valid_settings_main, valid_settings_slave, modifier, prefix, postfix); - if (word_list) - g_print ("%s", word_list); - - if (modifier != NM_META_ACCESSOR_MODIFIER_SET) - return; - - for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { - const NMMetaPropertyInfo *const*property_infos; - guint p; - - if (!nm_connection_get_setting_by_name (connection, nm_meta_setting_infos_editor[s].general->setting_name)) - continue; - - property_infos = nm_meta_setting_infos_editor[s].properties; - if (!property_infos) - continue; - for (p = 0; property_infos[p]; p++) { - const NMMetaPropertyInfo *property_info = property_infos[p]; - - if (_meta_property_needs_bond_hack (property_info)) { - guint i; - - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; - - if ( !bi->base.property_alias - || !g_str_has_prefix (bi->base.property_alias, prefix)) - continue; - g_print ("%s\n", bi->base.property_alias); - } - } else { - if (!property_info->is_cli_option) - continue; - if ( !property_info->property_alias - || !g_str_has_prefix (property_info->property_alias, prefix)) - continue; - g_print ("%s\n", property_info->property_alias); - } - } - } +complete_property_name(NmCli * nmc, + NMConnection * connection, + NMMetaAccessorModifier modifier, + const char * prefix, + const char * postfix) +{ + NMSettingConnection * s_con; + const NMMetaSettingValidPartItem *const *valid_settings_main; + const NMMetaSettingValidPartItem *const *valid_settings_slave; + const char * connection_type = NULL; + const char * slave_type = NULL; + gs_free char * word_list = NULL; + NMMetaSettingType s; + + connection_type = nm_connection_get_connection_type(connection); + s_con = nm_connection_get_setting_connection(connection); + if (s_con) + slave_type = nm_setting_connection_get_slave_type(s_con); + valid_settings_main = get_valid_settings_array(connection_type); + valid_settings_slave = nm_meta_setting_info_valid_parts_for_slave_type(slave_type, NULL); + + word_list = get_valid_properties_string(valid_settings_main, + valid_settings_slave, + modifier, + prefix, + postfix); + if (word_list) + g_print("%s", word_list); + + if (modifier != NM_META_ACCESSOR_MODIFIER_SET) + return; + + for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { + const NMMetaPropertyInfo *const *property_infos; + guint p; + + if (!nm_connection_get_setting_by_name( + connection, + nm_meta_setting_infos_editor[s].general->setting_name)) + continue; + + property_infos = nm_meta_setting_infos_editor[s].properties; + if (!property_infos) + continue; + for (p = 0; property_infos[p]; p++) { + const NMMetaPropertyInfo *property_info = property_infos[p]; + + if (_meta_property_needs_bond_hack(property_info)) { + guint i; + + for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + + if (!bi->base.property_alias + || !g_str_has_prefix(bi->base.property_alias, prefix)) + continue; + g_print("%s\n", bi->base.property_alias); + } + } else { + if (!property_info->is_cli_option) + continue; + if (!property_info->property_alias + || !g_str_has_prefix(property_info->property_alias, prefix)) + continue; + g_print("%s\n", property_info->property_alias); + } + } + } } static void -run_rl_generator (rl_compentry_func_t *generator_func, const char *prefix) +run_rl_generator(rl_compentry_func_t *generator_func, const char *prefix) { - int state = 0; - char *str; + int state = 0; + char *str; - while ((str = generator_func (prefix, state))) { - g_print ("%s\n", str); - g_free (str); - if (state == 0) - state = 1; - } + while ((str = generator_func(prefix, state))) { + g_print("%s\n", str); + g_free(str); + if (state == 0) + state = 1; + } } static gboolean -complete_option (NmCli *nmc, const NMMetaAbstractInfo *abstract_info, const char *prefix, NMConnection *context_connection) -{ - const OptionInfo *candidate; - const char *const*values; - gs_strfreev char **values_to_free = NULL; - gboolean complete_filename = FALSE; - const NMMetaOperationContext ctx = { - .connection = context_connection, - }; - - values = nm_meta_abstract_info_complete (abstract_info, - nmc_meta_environment, - (gpointer) nmc_meta_environment_arg, - &ctx, - prefix, - &complete_filename, - &values_to_free); - if (complete_filename) { - nmc->return_value = NMC_RESULT_COMPLETE_FILE; - return TRUE; - } - if (values) { - for (; values[0]; values++) - g_print ("%s\n", values[0]); - return TRUE; - } - - candidate = _meta_abstract_get_option_info (abstract_info); - if (candidate && candidate->generator_func) { - run_rl_generator (candidate->generator_func, prefix); - return TRUE; - } - - return FALSE; +complete_option(NmCli * nmc, + const NMMetaAbstractInfo *abstract_info, + const char * prefix, + NMConnection * context_connection) +{ + const OptionInfo * candidate; + const char *const * values; + gs_strfreev char ** values_to_free = NULL; + gboolean complete_filename = FALSE; + const NMMetaOperationContext ctx = { + .connection = context_connection, + }; + + values = nm_meta_abstract_info_complete(abstract_info, + nmc_meta_environment, + (gpointer) nmc_meta_environment_arg, + &ctx, + prefix, + &complete_filename, + &values_to_free); + if (complete_filename) { + nmc->return_value = NMC_RESULT_COMPLETE_FILE; + return TRUE; + } + if (values) { + for (; values[0]; values++) + g_print("%s\n", values[0]); + return TRUE; + } + + candidate = _meta_abstract_get_option_info(abstract_info); + if (candidate && candidate->generator_func) { + run_rl_generator(candidate->generator_func, prefix); + return TRUE; + } + + return FALSE; } static void -complete_existing_setting (NmCli *nmc, NMConnection *connection, const char *prefix) +complete_existing_setting(NmCli *nmc, NMConnection *connection, const char *prefix) { - gs_free NMSetting **settings = NULL; - const NMMetaSettingInfoEditor *editor; - guint i; + gs_free NMSetting ** settings = NULL; + const NMMetaSettingInfoEditor *editor; + guint i; - settings = nm_connection_get_settings (connection, NULL); - for (i = 0; settings && settings[i]; i++) { - editor = nm_meta_setting_info_editor_find_by_setting (settings[i]); + settings = nm_connection_get_settings(connection, NULL); + for (i = 0; settings && settings[i]; i++) { + editor = nm_meta_setting_info_editor_find_by_setting(settings[i]); - if (!prefix || g_str_has_prefix (editor->general->setting_name, prefix)) - g_print ("%s\n", editor->general->setting_name); + if (!prefix || g_str_has_prefix(editor->general->setting_name, prefix)) + g_print("%s\n", editor->general->setting_name); - if (editor->alias) { - if (!prefix || g_str_has_prefix (editor->alias, prefix)) - g_print ("%s\n", editor->alias); - } - } + if (editor->alias) { + if (!prefix || g_str_has_prefix(editor->alias, prefix)) + g_print("%s\n", editor->alias); + } + } } static void -complete_property (NmCli *nmc, const char *setting_name, const char *property, const char *prefix, NMConnection *connection) +complete_property(NmCli * nmc, + const char * setting_name, + const char * property, + const char * prefix, + NMConnection *connection) { - const NMMetaPropertyInfo *property_info; + const NMMetaPropertyInfo *property_info; - property_info = nm_meta_property_info_find_by_name (setting_name, property); - if (property_info) - complete_option (nmc, (const NMMetaAbstractInfo *) property_info, prefix, connection); + property_info = nm_meta_property_info_find_by_name(setting_name, property); + if (property_info) + complete_option(nmc, (const NMMetaAbstractInfo *) property_info, prefix, connection); } /*****************************************************************************/ static gboolean -connection_remove_setting (NMConnection *connection, NMSetting *setting, GError **error) +connection_remove_setting(NMConnection *connection, NMSetting *setting, GError **error) { - gboolean mandatory; + gboolean mandatory; - g_return_val_if_fail (setting, FALSE); + g_return_val_if_fail(setting, FALSE); - mandatory = is_setting_mandatory (connection, setting); - if (!mandatory) { - nm_connection_remove_setting (connection, G_OBJECT_TYPE (setting)); - return TRUE; - } - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: setting '%s' is mandatory and cannot be removed."), - nm_setting_get_name (setting)); - return FALSE; + mandatory = is_setting_mandatory(connection, setting); + if (!mandatory) { + nm_connection_remove_setting(connection, G_OBJECT_TYPE(setting)); + return TRUE; + } + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: setting '%s' is mandatory and cannot be removed."), + nm_setting_get_name(setting)); + return FALSE; } static gboolean -get_value (const char **value, int *argc, const char *const**argv, const char *option, GError **error) -{ - if (!**argv) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: value for '%s' is missing."), option); - return FALSE; - } - - /* Empty string will reset the value to default */ - if (**argv[0] == '\0') - *value = NULL; - else - *value = *argv[0]; - - (*argc)--; - (*argv)++; - return TRUE; +get_value(const char ** value, + int * argc, + const char *const **argv, + const char * option, + GError ** error) +{ + if (!**argv) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: value for '%s' is missing."), + option); + return FALSE; + } + + /* Empty string will reset the value to default */ + if (**argv[0] == '\0') + *value = NULL; + else + *value = *argv[0]; + + (*argc)--; + (*argv)++; + return TRUE; } gboolean -nmc_process_connection_properties (NmCli *nmc, - NMConnection *connection, - int *argc, - const char *const**argv, - gboolean allow_setting_removal, - GError **error) -{ - /* First check if we have a slave-type, as this would mean we will not - * have ip properties but possibly others, slave-type specific. - */ - /* Go through arguments and set properties */ - do { - const NMMetaSettingValidPartItem *const*type_settings; - const NMMetaSettingValidPartItem *const*slv_settings; - NMMetaAccessorModifier modifier; - const char *option_orig; - const char *option; - const char *value = NULL; - const char *tmp; - - if (!con_settings (connection, &type_settings, &slv_settings, error)) - return FALSE; - - ensure_settings (connection, slv_settings); - ensure_settings (connection, type_settings); - - if (*argc <= 0) { - g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: . argument is missing.")); - return FALSE; - } - - nm_assert (argv); - nm_assert (*argv); - nm_assert (**argv); - - option_orig = **argv; - - switch (option_orig[0]) { - case '+': modifier = NM_META_ACCESSOR_MODIFIER_ADD; option = &option_orig[1]; break; - case '-': modifier = NM_META_ACCESSOR_MODIFIER_DEL; option = &option_orig[1]; break; - default: modifier = NM_META_ACCESSOR_MODIFIER_SET; option = option_orig; break; - } - - if ( allow_setting_removal - && modifier == NM_META_ACCESSOR_MODIFIER_SET - && nm_streq (option, "remove")) { - NMSetting *ss; - const char *setting_name; - - (*argc)--; - (*argv)++; - - if (*argc == 1 && nmc->complete) { - complete_existing_setting (nmc, connection, value); - return TRUE; - } - - if (!*argc) { - g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: missing setting.")); - return FALSE; - } - - setting_name = **argv; - (*argc)--; - (*argv)++; - - ss = is_setting_valid (connection, - type_settings, - slv_settings, - setting_name); - if (!ss) { - if (check_valid_name (setting_name, - type_settings, - slv_settings, - NULL)) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Setting '%s' is not present in the connection."), - setting_name); - } else { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: invalid setting argument '%s'."), - setting_name); - } - return FALSE; - } - - if (!connection_remove_setting (connection, ss, error)) - return FALSE; - } else if ((tmp = strchr (option, '.'))) { - gs_free char *option_sett = g_strndup (option, tmp - option); - const char *option_prop = &tmp[1]; - const char *option_sett_expanded; - GError *local = NULL; - - /* This seems like a . (such as "connection.id" or "bond.mode"), - * optionally prefixed with "+| or "-". */ - - if ( *argc == 1 - && nmc->complete) - complete_property_name (nmc, connection, modifier, option_sett, option_prop); - - option_sett_expanded = check_valid_name (option_sett, type_settings, slv_settings, &local); - if (!option_sett_expanded) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: invalid or not allowed setting '%s': %s."), - option_sett, local->message); - g_clear_error (&local); - return FALSE; - } - - (*argc)--; - (*argv)++; - if (!get_value (&value, argc, argv, option_orig, error)) - return FALSE; - - if (!*argc && nmc->complete) { - complete_property (nmc, option_sett, option_prop, value ?: "", connection); - return TRUE; - } - - if (!set_property (nmc->client, connection, option_sett_expanded, option_prop, value, modifier, error)) - return FALSE; - } else { - const NMMetaAbstractInfo *chosen = NULL; - const char *chosen_setting_name = NULL; - const char *chosen_option = NULL; - NMMetaSettingType s; - - /* Let's see if this is an property alias (such as "id", "mode", "type" or "con-name")*/ - for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { - const NMMetaPropertyInfo *const*property_infos; - guint p; - - if (!check_valid_name (nm_meta_setting_infos[s].setting_name, - type_settings, slv_settings, NULL)) - continue; - - property_infos = nm_meta_setting_infos_editor[s].properties; - if (!property_infos) - continue; - for (p = 0; property_infos[p]; p++) { - const NMMetaPropertyInfo *property_info = property_infos[p]; - - if (_meta_property_needs_bond_hack (property_info)) { - guint i; - - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; - - if (!nm_streq0 (bi->base.property_alias, option)) - continue; - if (chosen) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: '%s' is ambiguous (%s.%s or %s.%s)."), option, - chosen_setting_name, chosen_option, - nm_meta_setting_infos[s].setting_name, option); - return FALSE; - } - chosen_setting_name = nm_meta_setting_infos[s].setting_name; - chosen_option = option; - chosen = (const NMMetaAbstractInfo *) bi; - } - } else { - if (!property_info->is_cli_option) - continue; - if (!nm_streq0 (property_info->property_alias, option)) - continue; - if (chosen) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: '%s' is ambiguous (%s.%s or %s.%s)."), option, - chosen_setting_name, chosen_option, - nm_meta_setting_infos[s].setting_name, option); - return FALSE; - } - chosen_setting_name = nm_meta_setting_infos[s].setting_name; - chosen_option = option; - chosen = (const NMMetaAbstractInfo *) property_info; - } - } - } - - if (!chosen) { - if (*argc == 1 && nmc->complete) { - if ( allow_setting_removal - && g_str_has_prefix ("remove", option)) - g_print ("remove\n"); - complete_property_name (nmc, connection, modifier, option, NULL); - } - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("Error: invalid . '%s'."), option); - return FALSE; - } - - if (*argc == 1 && nmc->complete) - complete_property_name (nmc, connection, modifier, option, NULL); - - (*argc)--; - (*argv)++; - if (!get_value (&value, argc, argv, option_orig, error)) - return FALSE; - - if (!*argc && nmc->complete) - complete_option (nmc, chosen, value ?: "", connection); - - if (!set_option (nmc, connection, chosen, value, error)) - return FALSE; - } - } while (*argc); - - return TRUE; +nmc_process_connection_properties(NmCli * nmc, + NMConnection * connection, + int * argc, + const char *const **argv, + gboolean allow_setting_removal, + GError ** error) +{ + /* First check if we have a slave-type, as this would mean we will not + * have ip properties but possibly others, slave-type specific. + */ + /* Go through arguments and set properties */ + do { + const NMMetaSettingValidPartItem *const *type_settings; + const NMMetaSettingValidPartItem *const *slv_settings; + NMMetaAccessorModifier modifier; + const char * option_orig; + const char * option; + const char * value = NULL; + const char * tmp; + const NMMetaAbstractInfo * chosen = NULL; + const char * chosen_setting_name = NULL; + const char * chosen_option = NULL; + NMMetaSettingType s; + + if (!con_settings(connection, &type_settings, &slv_settings, error)) + return FALSE; + + ensure_settings(connection, slv_settings); + ensure_settings(connection, type_settings); + + if (*argc <= 0) { + g_set_error_literal(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: . argument is missing.")); + return FALSE; + } + + nm_assert(argv); + nm_assert(*argv); + nm_assert(**argv); + + option_orig = **argv; + + switch (option_orig[0]) { + case '+': + modifier = NM_META_ACCESSOR_MODIFIER_ADD; + option = &option_orig[1]; + break; + case '-': + modifier = NM_META_ACCESSOR_MODIFIER_DEL; + option = &option_orig[1]; + break; + default: + modifier = NM_META_ACCESSOR_MODIFIER_SET; + option = option_orig; + break; + } + + if (allow_setting_removal && modifier == NM_META_ACCESSOR_MODIFIER_SET + && nm_streq(option, "remove")) { + NMSetting * ss; + const char *setting_name; + + (*argc)--; + (*argv)++; + + if (*argc == 1 && nmc->complete) { + complete_existing_setting(nmc, connection, value); + return TRUE; + } + + if (!*argc) { + g_set_error_literal(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: missing setting.")); + return FALSE; + } + + setting_name = **argv; + (*argc)--; + (*argv)++; + + ss = is_setting_valid(connection, type_settings, slv_settings, setting_name); + if (!ss) { + if (!check_valid_name(setting_name, type_settings, slv_settings, NULL)) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: invalid setting argument '%s'."), + setting_name); + return FALSE; + } + continue; + } + + if (!connection_remove_setting(connection, ss, error)) + return FALSE; + + continue; + } + + if ((tmp = strchr(option, '.'))) { + gs_free char *option_sett = g_strndup(option, tmp - option); + const char * option_prop = &tmp[1]; + const char * option_sett_expanded; + GError * local = NULL; + + /* This seems like a . (such as "connection.id" or "bond.mode"), + * optionally prefixed with "+| or "-". */ + + if (*argc == 1 && nmc->complete) + complete_property_name(nmc, connection, modifier, option_sett, option_prop); + + option_sett_expanded = + check_valid_name(option_sett, type_settings, slv_settings, &local); + if (!option_sett_expanded) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: invalid or not allowed setting '%s': %s."), + option_sett, + local->message); + g_clear_error(&local); + return FALSE; + } + + (*argc)--; + (*argv)++; + if (!get_value(&value, argc, argv, option_orig, error)) + return FALSE; + + if (!*argc && nmc->complete) { + complete_property(nmc, option_sett, option_prop, value ?: "", connection); + return TRUE; + } + + if (!set_property(nmc->client, + connection, + option_sett_expanded, + option_prop, + value, + modifier, + error)) + return FALSE; + + continue; + } + + /* Let's see if this is an property alias (such as "id", "mode", "type" or "con-name")*/ + for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { + const NMMetaPropertyInfo *const *property_infos; + guint p; + + if (!check_valid_name(nm_meta_setting_infos[s].setting_name, + type_settings, + slv_settings, + NULL)) + continue; + + property_infos = nm_meta_setting_infos_editor[s].properties; + if (!property_infos) + continue; + for (p = 0; property_infos[p]; p++) { + const NMMetaPropertyInfo *property_info = property_infos[p]; + + if (_meta_property_needs_bond_hack(property_info)) { + guint i; + + for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { + const NMMetaNestedPropertyInfo *bi = + &nm_meta_property_typ_data_bond.nested[i]; + + if (!nm_streq0(bi->base.property_alias, option)) + continue; + if (chosen) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: '%s' is ambiguous (%s.%s or %s.%s)."), + option, + chosen_setting_name, + chosen_option, + nm_meta_setting_infos[s].setting_name, + option); + return FALSE; + } + chosen_setting_name = nm_meta_setting_infos[s].setting_name; + chosen_option = option; + chosen = (const NMMetaAbstractInfo *) bi; + } + } else { + if (!property_info->is_cli_option) + continue; + if (!nm_streq0(property_info->property_alias, option)) + continue; + if (chosen) { + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: '%s' is ambiguous (%s.%s or %s.%s)."), + option, + chosen_setting_name, + chosen_option, + nm_meta_setting_infos[s].setting_name, + option); + return FALSE; + } + chosen_setting_name = nm_meta_setting_infos[s].setting_name; + chosen_option = option; + chosen = (const NMMetaAbstractInfo *) property_info; + } + } + } + + if (!chosen) { + if (*argc == 1 && nmc->complete) { + if (allow_setting_removal && g_str_has_prefix("remove", option)) + g_print("remove\n"); + complete_property_name(nmc, connection, modifier, option, NULL); + } + g_set_error(error, + NMCLI_ERROR, + NMC_RESULT_ERROR_USER_INPUT, + _("Error: invalid . '%s'."), + option); + return FALSE; + } + + if (*argc == 1 && nmc->complete) + complete_property_name(nmc, connection, modifier, option, NULL); + + (*argc)--; + (*argv)++; + if (!get_value(&value, argc, argv, option_orig, error)) + return FALSE; + + if (!*argc && nmc->complete) + complete_option(nmc, chosen, value ?: "", connection); + + if (!set_option(nmc, connection, chosen, value, error)) + return FALSE; + + } while (*argc); + + return TRUE; } static void -add_connection_cb (GObject *client, - GAsyncResult *result, - gpointer user_data) -{ - nm_auto_free_add_connection_info AddConnectionInfo *info = user_data; - NmCli *nmc = info->nmc; - NMRemoteConnection *connection; - GError *error = NULL; - const GPtrArray *connections; - guint i, found; - - connection = nm_client_add_connection2_finish (NM_CLIENT (client), result, NULL, &error); - if (error) { - g_string_printf (nmc->return_text, - _("Error: Failed to add '%s' connection: %s"), - info->new_id, error->message); - g_error_free (error); - nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; - } else { - connections = nm_client_get_connections (nmc->client); - if (connections) { - found = 0; - for (i = 0; i < connections->len; i++) { - NMConnection *candidate = NM_CONNECTION (connections->pdata[i]); - - if ((NMConnection *) connection == candidate) - continue; - if (nm_streq0 (nm_connection_get_id (candidate), info->new_id)) - found++; - } - if (found > 0) { - g_printerr (g_dngettext (GETTEXT_PACKAGE, - "Warning: There is another connection with the name '%1$s'. Reference the connection by its uuid '%2$s'\n", - "Warning: There are %3$u other connections with the name '%1$s'. Reference the connection by its uuid '%2$s'\n", - found), - info->new_id, - nm_connection_get_uuid (NM_CONNECTION (connection)), - found); - } - } - - g_print (_("Connection '%s' (%s) successfully added.\n"), - nm_connection_get_id (NM_CONNECTION (connection)), - nm_connection_get_uuid (NM_CONNECTION (connection))); - g_object_unref (connection); - } - - quit (); +add_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data) +{ + nm_auto_free_add_connection_info AddConnectionInfo *info = user_data; + NmCli * nmc = info->nmc; + NMRemoteConnection * connection; + GError * error = NULL; + const GPtrArray * connections; + guint i, found; + + connection = nm_client_add_connection2_finish(NM_CLIENT(client), result, NULL, &error); + if (error) { + g_string_printf(nmc->return_text, + _("Error: Failed to add '%s' connection: %s"), + info->new_id, + error->message); + g_error_free(error); + nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; + } else { + connections = nm_client_get_connections(nmc->client); + if (connections) { + found = 0; + for (i = 0; i < connections->len; i++) { + NMConnection *candidate = NM_CONNECTION(connections->pdata[i]); + + if ((NMConnection *) connection == candidate) + continue; + if (nm_streq0(nm_connection_get_id(candidate), info->new_id)) + found++; + } + if (found > 0) { + g_printerr(g_dngettext(GETTEXT_PACKAGE, + "Warning: There is another connection with the name '%1$s'. " + "Reference the connection by its uuid '%2$s'\n", + "Warning: There are %3$u other connections with the name " + "'%1$s'. Reference the connection by its uuid '%2$s'\n", + found), + info->new_id, + nm_connection_get_uuid(NM_CONNECTION(connection)), + found); + } + } + + g_print(_("Connection '%s' (%s) successfully added.\n"), + nm_connection_get_id(NM_CONNECTION(connection)), + nm_connection_get_uuid(NM_CONNECTION(connection))); + g_object_unref(connection); + } + + quit(); } static void -add_connection (NMClient *client, - NMConnection *connection, - gboolean temporary, - GAsyncReadyCallback callback, - gpointer user_data) -{ - nm_client_add_connection2 (client, - nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL), - temporary - ? NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY - : NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK, - NULL, - TRUE, - NULL, - callback, - user_data); +add_connection(NMClient * client, + NMConnection * connection, + gboolean temporary, + GAsyncReadyCallback callback, + gpointer user_data) +{ + nm_client_add_connection2(client, + nm_connection_to_dbus(connection, NM_CONNECTION_SERIALIZE_ALL), + temporary ? NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY + : NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK, + NULL, + TRUE, + NULL, + callback, + user_data); } static void -update_connection (NMRemoteConnection *connection, - gboolean temporary, - GAsyncReadyCallback callback, - gpointer user_data) +update_connection(NMRemoteConnection *connection, + gboolean temporary, + GAsyncReadyCallback callback, + gpointer user_data) { - nm_remote_connection_commit_changes_async (connection, - !temporary, - NULL, - callback, - user_data); + nm_remote_connection_commit_changes_async(connection, !temporary, NULL, callback, user_data); } static gboolean -is_single_word (const char* line) +is_single_word(const char *line) { - size_t n1, n2, n3; + size_t n1, n2, n3; - n1 = strspn (line, " \t"); - n2 = strcspn (line+n1, " \t\0") + n1; - n3 = strspn (line+n2, " \t"); + n1 = strspn(line, " \t"); + n2 = strcspn(line + n1, " \t\0") + n1; + n3 = strspn(line + n2, " \t"); - if (n3 == 0) - return TRUE; - else - return FALSE; + if (n3 == 0) + return TRUE; + else + return FALSE; } static char ** -nmcli_con_add_tab_completion (const char *text, int start, int end) -{ - NMMetaSettingType s; - char **match_array = NULL; - rl_compentry_func_t *generator_func = NULL; - gs_free char *no = g_strdup_printf ("[%s]: ", _("no")); - gs_free char *yes = g_strdup_printf ("[%s]: ", _("yes")); - const NMMetaAbstractInfo *info; - - /* Disable readline's default filename completion */ - rl_attempted_completion_over = 1; - - /* Restore standard append character to space */ - rl_completion_append_character = '\x00'; - - if (!is_single_word (rl_line_buffer)) - return NULL; - - for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { - const NMMetaPropertyInfo *const*property_infos; - guint p; - - property_infos = nm_meta_setting_infos_editor[s].properties; - if (!property_infos) - continue; - for (p = 0; property_infos[p]; p++) { - const NMMetaPropertyInfo *property_info = property_infos[p]; - - if (_meta_property_needs_bond_hack (property_info)) { - guint i; - - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; - - if ( bi->base.prompt - && g_str_has_prefix (rl_prompt, bi->base.prompt)) { - goto next; - } - } - } else { - if ( property_info->prompt - && g_str_has_prefix (rl_prompt, property_info->prompt)) { - info = (const NMMetaAbstractInfo *) property_info; - nmc_tab_completion.words = _meta_abstract_complete (info, text); - if (nmc_tab_completion.words) { - match_array = rl_completion_matches (text, _meta_abstract_generator); - nm_clear_pointer (&nmc_tab_completion.words, g_strfreev); - } - return match_array; - } - } - } - } +nmcli_con_add_tab_completion(const char *text, int start, int end) +{ + NMMetaSettingType s; + char ** match_array = NULL; + rl_compentry_func_t * generator_func = NULL; + gs_free char * no = g_strdup_printf("[%s]: ", _("no")); + gs_free char * yes = g_strdup_printf("[%s]: ", _("yes")); + const NMMetaAbstractInfo *info; + + /* Disable readline's default filename completion */ + rl_attempted_completion_over = 1; + + /* Restore standard append character to space */ + rl_completion_append_character = '\x00'; + + if (!is_single_word(rl_line_buffer)) + return NULL; + + for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { + const NMMetaPropertyInfo *const *property_infos; + guint p; + + property_infos = nm_meta_setting_infos_editor[s].properties; + if (!property_infos) + continue; + for (p = 0; property_infos[p]; p++) { + const NMMetaPropertyInfo *property_info = property_infos[p]; + + if (_meta_property_needs_bond_hack(property_info)) { + guint i; + + for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + + if (bi->base.prompt && g_str_has_prefix(rl_prompt, bi->base.prompt)) { + goto next; + } + } + } else { + if (property_info->prompt && g_str_has_prefix(rl_prompt, property_info->prompt)) { + info = (const NMMetaAbstractInfo *) property_info; + nmc_tab_completion.words = _meta_abstract_complete(info, text); + if (nmc_tab_completion.words) { + match_array = rl_completion_matches(text, _meta_abstract_generator); + nm_clear_pointer(&nmc_tab_completion.words, g_strfreev); + } + return match_array; + } + } + } + } next: - if (g_str_has_prefix (rl_prompt, NM_META_TEXT_PROMPT_BT_TYPE)) - generator_func = gen_func_bt_type; - else if (g_str_has_prefix (rl_prompt, NM_META_TEXT_PROMPT_BOND_MODE)) - generator_func = gen_func_bond_mode; - else if (g_str_has_prefix (rl_prompt, NM_META_TEXT_PROMPT_BOND_MON_MODE)) - generator_func = gen_func_bond_mon_mode; - else if ( g_str_has_suffix (rl_prompt, yes) - || g_str_has_suffix (rl_prompt, no)) - generator_func = gen_func_bool_values_l10n; + if (g_str_has_prefix(rl_prompt, NM_META_TEXT_PROMPT_BT_TYPE)) + generator_func = gen_func_bt_type; + else if (g_str_has_prefix(rl_prompt, NM_META_TEXT_PROMPT_BOND_MODE)) + generator_func = gen_func_bond_mode; + else if (g_str_has_prefix(rl_prompt, NM_META_TEXT_PROMPT_BOND_MON_MODE)) + generator_func = gen_func_bond_mon_mode; + else if (g_str_has_suffix(rl_prompt, yes) || g_str_has_suffix(rl_prompt, no)) + generator_func = gen_func_bool_values_l10n; - if (generator_func) - match_array = rl_completion_matches (text, generator_func); + if (generator_func) + match_array = rl_completion_matches(text, generator_func); - return match_array; + return match_array; } static void -ask_option (NmCli *nmc, NMConnection *connection, const NMMetaAbstractInfo *abstract_info) -{ - char *value; - GError *error = NULL; - gs_free char *prompt = NULL; - gboolean multi; - const char *opt_prompt, *opt_def_hint; - NMMetaPropertyInfFlags inf_flags; - - _meta_abstract_get (abstract_info, NULL, NULL, NULL, NULL, &inf_flags, &opt_prompt, &opt_def_hint); - prompt = g_strjoin ("", - gettext (opt_prompt), - opt_def_hint ? " " : "", - opt_def_hint ?: "", - ": ", - NULL); - - multi = NM_FLAGS_HAS (inf_flags, NM_META_PROPERTY_INF_FLAG_MULTI); - - if (multi) - g_print (_("You can specify this option more than once. Press when you're done.\n")); +ask_option(NmCli *nmc, NMConnection *connection, const NMMetaAbstractInfo *abstract_info) +{ + char * value; + GError * error = NULL; + gs_free char * prompt = NULL; + gboolean multi; + const char * opt_prompt, *opt_def_hint; + NMMetaPropertyInfFlags inf_flags; + + _meta_abstract_get(abstract_info, + NULL, + NULL, + NULL, + NULL, + &inf_flags, + &opt_prompt, + &opt_def_hint); + prompt = + g_strjoin("", gettext(opt_prompt), opt_def_hint ? " " : "", opt_def_hint ?: "", ": ", NULL); + + multi = NM_FLAGS_HAS(inf_flags, NM_META_PROPERTY_INF_FLAG_MULTI); + + if (multi) + g_print(_("You can specify this option more than once. Press when you're done.\n")); again: - value = nmc_readline (&nmc->nmc_config, - "%s", - prompt); - if (multi && !value) - return; + value = nmc_readline(&nmc->nmc_config, "%s", prompt); + if (multi && !value) + return; - if (!set_option (nmc, connection, abstract_info, value, &error)) { - g_printerr ("%s\n", error->message); - g_clear_error (&error); - goto again; - } + if (!set_option(nmc, connection, abstract_info, value, &error)) { + g_printerr("%s\n", error->message); + g_clear_error(&error); + goto again; + } - if (multi && value) - goto again; + if (multi && value) + goto again; } static NMMetaSettingType -connection_get_base_meta_setting_type (NMConnection *connection) +connection_get_base_meta_setting_type(NMConnection *connection) { - const char *connection_type; - NMSetting *base_setting; - const NMMetaSettingInfoEditor *editor; + const char * connection_type; + NMSetting * base_setting; + const NMMetaSettingInfoEditor *editor; - connection_type = nm_connection_get_connection_type (connection); - nm_assert (connection_type); - base_setting = nm_connection_get_setting_by_name (connection, connection_type); - nm_assert (base_setting); - editor = nm_meta_setting_info_editor_find_by_setting (base_setting); - nm_assert (editor); + connection_type = nm_connection_get_connection_type(connection); + nm_assert(connection_type); + base_setting = nm_connection_get_setting_by_name(connection, connection_type); + nm_assert(base_setting); + editor = nm_meta_setting_info_editor_find_by_setting(base_setting); + nm_assert(editor); - return editor - nm_meta_setting_infos_editor; + return editor - nm_meta_setting_infos_editor; } static void -questionnaire_mandatory_ask_setting (NmCli *nmc, NMConnection *connection, NMMetaSettingType type) -{ - const NMMetaSettingInfoEditor *editor; - const NMMetaPropertyInfo *property_info; - guint p; - - editor = &nm_meta_setting_infos_editor[type]; - if (!editor->properties) - return; - - for (p = 0; editor->properties[p]; p++) { - property_info = editor->properties[p]; - - if (_meta_property_needs_bond_hack (property_info)) { - guint i; - - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; - - if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) - continue; - if ( (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) - || (_dynamic_options_get ((const NMMetaAbstractInfo *) bi) & PROPERTY_INF_FLAG_ENABLED)) - ask_option (nmc, connection, (const NMMetaAbstractInfo *) bi); - } - } else { - if (!property_info->is_cli_option) - continue; - - if (!option_relevant (connection, (const NMMetaAbstractInfo *) property_info)) - continue; - if ( (property_info->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) - || (_dynamic_options_get ((const NMMetaAbstractInfo *) property_info) & PROPERTY_INF_FLAG_ENABLED)) - ask_option (nmc, connection, (const NMMetaAbstractInfo *) property_info); - } - } +questionnaire_mandatory_ask_setting(NmCli *nmc, NMConnection *connection, NMMetaSettingType type) +{ + const NMMetaSettingInfoEditor *editor; + const NMMetaPropertyInfo * property_info; + guint p; + + editor = &nm_meta_setting_infos_editor[type]; + if (!editor->properties) + return; + + for (p = 0; editor->properties[p]; p++) { + property_info = editor->properties[p]; + + if (_meta_property_needs_bond_hack(property_info)) { + guint i; + + for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + + if (!option_relevant(connection, (const NMMetaAbstractInfo *) bi)) + continue; + if ((bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) + || (_dynamic_options_get((const NMMetaAbstractInfo *) bi) + & PROPERTY_INF_FLAG_ENABLED)) + ask_option(nmc, connection, (const NMMetaAbstractInfo *) bi); + } + } else { + if (!property_info->is_cli_option) + continue; + + if (!option_relevant(connection, (const NMMetaAbstractInfo *) property_info)) + continue; + if ((property_info->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) + || (_dynamic_options_get((const NMMetaAbstractInfo *) property_info) + & PROPERTY_INF_FLAG_ENABLED)) + ask_option(nmc, connection, (const NMMetaAbstractInfo *) property_info); + } + } } static void -questionnaire_mandatory (NmCli *nmc, NMConnection *connection) +questionnaire_mandatory(NmCli *nmc, NMConnection *connection) { - NMMetaSettingType s, base; + NMMetaSettingType s, base; - /* First ask connection properties */ - questionnaire_mandatory_ask_setting (nmc, connection, NM_META_SETTING_TYPE_CONNECTION); + /* First ask connection properties */ + questionnaire_mandatory_ask_setting(nmc, connection, NM_META_SETTING_TYPE_CONNECTION); - /* Ask properties of the base setting */ - base = connection_get_base_meta_setting_type (connection); - questionnaire_mandatory_ask_setting (nmc, connection, base); + /* Ask properties of the base setting */ + base = connection_get_base_meta_setting_type(connection); + questionnaire_mandatory_ask_setting(nmc, connection, base); - /* Remaining settings */ - for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { - if (!NM_IN_SET (s, NM_META_SETTING_TYPE_CONNECTION, base)) - questionnaire_mandatory_ask_setting (nmc, connection, s); - } + /* Remaining settings */ + for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { + if (!NM_IN_SET(s, NM_META_SETTING_TYPE_CONNECTION, base)) + questionnaire_mandatory_ask_setting(nmc, connection, s); + } } static gboolean -want_provide_opt_args (const NmcConfig *nmc_config, - const char *type, - guint num) -{ - gs_free char *answer = NULL; - - /* Ask for optional arguments. */ - g_print (ngettext ("There is %d optional setting for %s.\n", - "There are %d optional settings for %s.\n", - num), - (int) num, - type); - answer = nmc_readline (nmc_config, - ngettext ("Do you want to provide it? %s", - "Do you want to provide them? %s", - num), - prompt_yes_no (TRUE, NULL)); - nm_strstrip (answer); - return !answer || matches (answer, WORD_YES); +want_provide_opt_args(const NmcConfig *nmc_config, const char *type, guint num) +{ + gs_free char *answer = NULL; + + /* Ask for optional arguments. */ + g_print(ngettext("There is %d optional setting for %s.\n", + "There are %d optional settings for %s.\n", + num), + (int) num, + type); + answer = nmc_readline( + nmc_config, + ngettext("Do you want to provide it? %s", "Do you want to provide them? %s", num), + prompt_yes_no(TRUE, NULL)); + nm_strstrip(answer); + return !answer || matches(answer, WORD_YES); } static gboolean -questionnaire_one_optional (NmCli *nmc, NMConnection *connection) +questionnaire_one_optional(NmCli *nmc, NMConnection *connection) { - NMMetaSettingType base; - gs_unref_ptrarray GPtrArray *infos = NULL; - guint i, j; - gboolean already_confirmed = FALSE; - NMMetaSettingType s_asking = NM_META_SETTING_TYPE_UNKNOWN; - NMMetaSettingType settings[_NM_META_SETTING_TYPE_NUM]; + NMMetaSettingType base; + gs_unref_ptrarray GPtrArray *infos = NULL; + guint i, j; + gboolean already_confirmed = FALSE; + NMMetaSettingType s_asking = NM_META_SETTING_TYPE_UNKNOWN; + NMMetaSettingType settings[_NM_META_SETTING_TYPE_NUM]; - base = connection_get_base_meta_setting_type (connection); + base = connection_get_base_meta_setting_type(connection); - i = 0; - settings[i++] = NM_META_SETTING_TYPE_CONNECTION; - settings[i++] = base; - for (j = 0; j < _NM_META_SETTING_TYPE_NUM; j++) { - if (!NM_IN_SET (j, NM_META_SETTING_TYPE_CONNECTION, base)) - settings[i++] = j; - } + i = 0; + settings[i++] = NM_META_SETTING_TYPE_CONNECTION; + settings[i++] = base; + for (j = 0; j < _NM_META_SETTING_TYPE_NUM; j++) { + if (!NM_IN_SET(j, NM_META_SETTING_TYPE_CONNECTION, base)) + settings[i++] = j; + } - infos = g_ptr_array_new (); + infos = g_ptr_array_new(); - /* Find first setting with relevant options and count them. */ + /* Find first setting with relevant options and count them. */ again: - for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { - const NMMetaPropertyInfo *const*property_infos; - guint p; - - if ( s_asking != NM_META_SETTING_TYPE_UNKNOWN - && settings[i] != s_asking) - continue; - - property_infos = nm_meta_setting_infos_editor[settings[i]].properties; - if (!property_infos) - continue; - for (p = 0; property_infos[p]; p++) { - const NMMetaPropertyInfo *property_info = property_infos[p]; - - if (_meta_property_needs_bond_hack (property_info)) { - for (j = 0; j < nm_meta_property_typ_data_bond.nested_len; j++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[j]; - - if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) - continue; - g_ptr_array_add (infos, (gpointer) bi); - } - } else { - if (!property_info->is_cli_option) - continue; - if (!option_relevant (connection, (const NMMetaAbstractInfo *) property_info)) - continue; - g_ptr_array_add (infos, (gpointer) property_info); - } - } - if (infos->len) { - s_asking = settings[i]; - break; - } - } - - if (infos->len) { - const NMMetaSettingInfoEditor *setting_info = NULL; - - _meta_abstract_get (infos->pdata[0], &setting_info, NULL, NULL, NULL, NULL, NULL, NULL); - - /* Now ask for the settings. */ - if ( already_confirmed - || want_provide_opt_args (&nmc->nmc_config, - _(setting_info->pretty_name), - infos->len)) { - ask_option (nmc, connection, infos->pdata[0]); - already_confirmed = TRUE; - /* asking for an option may enable other options. Create the list again. */ - g_ptr_array_set_size (infos, 0); - goto again; - } - } - - if (s_asking == NM_META_SETTING_TYPE_UNKNOWN) - return FALSE; - - /* Make sure we won't ask again. */ - disable_options (nm_meta_setting_infos[s_asking].setting_name, NULL); - return TRUE; + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + const NMMetaPropertyInfo *const *property_infos; + guint p; + + if (s_asking != NM_META_SETTING_TYPE_UNKNOWN && settings[i] != s_asking) + continue; + + property_infos = nm_meta_setting_infos_editor[settings[i]].properties; + if (!property_infos) + continue; + for (p = 0; property_infos[p]; p++) { + const NMMetaPropertyInfo *property_info = property_infos[p]; + + if (_meta_property_needs_bond_hack(property_info)) { + for (j = 0; j < nm_meta_property_typ_data_bond.nested_len; j++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[j]; + + if (!option_relevant(connection, (const NMMetaAbstractInfo *) bi)) + continue; + g_ptr_array_add(infos, (gpointer) bi); + } + } else { + if (!property_info->is_cli_option) + continue; + if (!option_relevant(connection, (const NMMetaAbstractInfo *) property_info)) + continue; + g_ptr_array_add(infos, (gpointer) property_info); + } + } + if (infos->len) { + s_asking = settings[i]; + break; + } + } + + if (infos->len) { + const NMMetaSettingInfoEditor *setting_info = NULL; + + _meta_abstract_get(infos->pdata[0], &setting_info, NULL, NULL, NULL, NULL, NULL, NULL); + + /* Now ask for the settings. */ + if (already_confirmed + || want_provide_opt_args(&nmc->nmc_config, _(setting_info->pretty_name), infos->len)) { + ask_option(nmc, connection, infos->pdata[0]); + already_confirmed = TRUE; + /* asking for an option may enable other options. Create the list again. */ + g_ptr_array_set_size(infos, 0); + goto again; + } + } + + if (s_asking == NM_META_SETTING_TYPE_UNKNOWN) + return FALSE; + + /* Make sure we won't ask again. */ + disable_options(nm_meta_setting_infos[s_asking].setting_name, NULL); + return TRUE; } static void -do_connection_add (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv) +do_connection_add(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv) { - gs_unref_object NMConnection *connection = NULL; - NMSettingConnection *s_con; - gs_free_error GError *error = NULL; - gboolean save_bool = TRUE; - gboolean seen_dash_dash = FALSE; - NMMetaSettingType s; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + gs_free_error GError *error = NULL; + gboolean save_bool = TRUE; + gboolean seen_dash_dash = FALSE; + NMMetaSettingType s; - next_arg (nmc, &argc, &argv, NULL); + next_arg(nmc, &argc, &argv, NULL); - rl_attempted_completion_function = nmcli_con_add_tab_completion; + rl_attempted_completion_function = nmcli_con_add_tab_completion; - nmc->return_value = NMC_RESULT_SUCCESS; + nmc->return_value = NMC_RESULT_SUCCESS; - connection = nm_simple_connection_new (); + connection = nm_simple_connection_new(); - s_con = (NMSettingConnection *) nm_setting_connection_new (); - nm_connection_add_setting (connection, NM_SETTING (s_con)); + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); read_properties: - g_clear_error (&error); - /* Get the arguments from the command line if any */ - if (argc && !nmc_process_connection_properties (nmc, connection, &argc, &argv, FALSE, &error)) { - if (g_strcmp0 (*argv, "--") == 0 && !seen_dash_dash) { - /* This is for compatibility with older nmcli that required - * options and properties to be separated with "--" */ - seen_dash_dash = TRUE; - next_arg (nmc, &argc, &argv, NULL); - goto read_properties; - } else if (g_strcmp0 (*argv, "save") == 0) { - /* It would be better if "save" was a separate argument and not - * mixed with properties, but there's not much we can do about it now. */ - argc--; - argv++; - if (!argc) { - g_string_printf (nmc->return_text, - _("Error: value for '%s' argument is required."), - "save"); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; - } - g_clear_error (&error); - if (!nmc_string_to_bool (*argv, &save_bool, &error)) { - g_string_printf (nmc->return_text, _("Error: 'save': %s."), - error->message); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; - } - next_arg (nmc, &argc, &argv, NULL); - goto read_properties; - } - - g_string_assign (nmc->return_text, error->message); - nmc->return_value = error->code; - goto finish; - } - - if (nmc->complete) - goto finish; - - /* Now ask user for the rest of the mandatory options. */ - if (nmc->ask) - questionnaire_mandatory (nmc, connection); - - /* Traditionally, we didn't ask for these options for ethernet slaves. They don't - * make much sense, since these are likely to be set by the master anyway. */ - if (nm_setting_connection_get_slave_type (s_con)) { - disable_options (NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MTU); - disable_options (NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS); - disable_options (NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_CLONED_MAC_ADDRESS); - } - - /* Connection id is special in that it's required but we don't insist - * on getting it from the user -- we just make up something sensible. */ - if (!nm_setting_connection_get_id (s_con)) { - const char *ifname = nm_setting_connection_get_interface_name (s_con); - const char *type = nm_setting_connection_get_connection_type (s_con); - const char *slave_type = nm_setting_connection_get_slave_type (s_con); - - /* If only bother when there's a type, which is not guaranteed at this point. - * Otherwise, the validation will fail anyway. */ - if (type) { - gs_free char *try_name = NULL; - gs_free char *default_name = NULL; - const GPtrArray *connections; - - connections = nm_client_get_connections (nmc->client); - try_name = ifname - ? g_strdup_printf ("%s-%s", get_name_alias_toplevel (type, slave_type), ifname) - : g_strdup (get_name_alias_toplevel (type, slave_type)); - default_name = nmc_unique_connection_name (connections, try_name); - g_object_set (s_con, NM_SETTING_CONNECTION_ID, default_name, NULL); - } - } - - /* For some software connection types we generate the interface name for the user. */ - set_default_interface_name (nmc, s_con); - - /* Now see if there's something optional that needs to be asked for. - * Keep asking until there's no more things to ask for. */ - do { - /* This ensures all settings that make sense are present. */ - nm_connection_normalize (connection, NULL, NULL, NULL); - } while (nmc->ask && questionnaire_one_optional (nmc, connection)); - - /* Mandatory settings. No good reason to check this other than guarding the user - * from doing something that's not likely to make sense (such as missing ifname - * on a bond/bridge/team, etc.). Added just to preserve traditional behavior, it - * perhaps is a good idea to just remove this. */ - for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { - const NMMetaPropertyInfo *const*property_infos; - guint p; - - property_infos = nm_meta_setting_infos_editor[s].properties; - if (!property_infos) - continue; - for (p = 0; property_infos[p]; p++) { - const NMMetaPropertyInfo *property_info = property_infos[p]; - - if (_meta_property_needs_bond_hack (property_info)) { - guint i; - - for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { - const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; - - if (!option_relevant (connection, (const NMMetaAbstractInfo *) bi)) - continue; - if (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) { - g_string_printf (nmc->return_text, _("Error: '%s' argument is required."), bi->base.property_alias); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; - } - } - } else { - if (!property_info->is_cli_option) - continue; - if (!option_relevant (connection, (const NMMetaAbstractInfo *) property_info)) - continue; - if (property_info->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) { - g_string_printf (nmc->return_text, _("Error: '%s' argument is required."), property_info->property_alias); - nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; - goto finish; - } - } - } - } - - add_connection (nmc->client, - connection, - !save_bool, - add_connection_cb, - _add_connection_info_new (nmc, NULL, connection)); - nmc->should_wait++; + g_clear_error(&error); + /* Get the arguments from the command line if any */ + if (argc && !nmc_process_connection_properties(nmc, connection, &argc, &argv, FALSE, &error)) { + if (g_strcmp0(*argv, "--") == 0 && !seen_dash_dash) { + /* This is for compatibility with older nmcli that required + * options and properties to be separated with "--" */ + seen_dash_dash = TRUE; + next_arg(nmc, &argc, &argv, NULL); + goto read_properties; + } else if (g_strcmp0(*argv, "save") == 0) { + /* It would be better if "save" was a separate argument and not + * mixed with properties, but there's not much we can do about it now. */ + argc--; + argv++; + if (!argc) { + g_string_printf(nmc->return_text, + _("Error: value for '%s' argument is required."), + "save"); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + goto finish; + } + g_clear_error(&error); + if (!nmc_string_to_bool(*argv, &save_bool, &error)) { + g_string_printf(nmc->return_text, _("Error: 'save': %s."), error->message); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + goto finish; + } + next_arg(nmc, &argc, &argv, NULL); + goto read_properties; + } + + g_string_assign(nmc->return_text, error->message); + nmc->return_value = error->code; + goto finish; + } + + if (nmc->complete) + goto finish; + + /* Now ask user for the rest of the mandatory options. */ + if (nmc->ask) + questionnaire_mandatory(nmc, connection); + + /* Traditionally, we didn't ask for these options for ethernet slaves. They don't + * make much sense, since these are likely to be set by the master anyway. */ + if (nm_setting_connection_get_slave_type(s_con)) { + disable_options(NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MTU); + disable_options(NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS); + disable_options(NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_CLONED_MAC_ADDRESS); + } + + /* Connection id is special in that it's required but we don't insist + * on getting it from the user -- we just make up something sensible. */ + if (!nm_setting_connection_get_id(s_con)) { + const char *ifname = nm_setting_connection_get_interface_name(s_con); + const char *type = nm_setting_connection_get_connection_type(s_con); + const char *slave_type = nm_setting_connection_get_slave_type(s_con); + + /* If only bother when there's a type, which is not guaranteed at this point. + * Otherwise, the validation will fail anyway. */ + if (type) { + gs_free char * try_name = NULL; + gs_free char * default_name = NULL; + const GPtrArray *connections; + + connections = nm_client_get_connections(nmc->client); + try_name = + ifname ? g_strdup_printf("%s-%s", get_name_alias_toplevel(type, slave_type), ifname) + : g_strdup(get_name_alias_toplevel(type, slave_type)); + default_name = nmc_unique_connection_name(connections, try_name); + g_object_set(s_con, NM_SETTING_CONNECTION_ID, default_name, NULL); + } + } + + /* For some software connection types we generate the interface name for the user. */ + set_default_interface_name(nmc, s_con); + + /* Now see if there's something optional that needs to be asked for. + * Keep asking until there's no more things to ask for. */ + do { + /* This ensures all settings that make sense are present. */ + nm_connection_normalize(connection, NULL, NULL, NULL); + } while (nmc->ask && questionnaire_one_optional(nmc, connection)); + + /* Mandatory settings. No good reason to check this other than guarding the user + * from doing something that's not likely to make sense (such as missing ifname + * on a bond/bridge/team, etc.). Added just to preserve traditional behavior, it + * perhaps is a good idea to just remove this. */ + for (s = 0; s < _NM_META_SETTING_TYPE_NUM; s++) { + const NMMetaPropertyInfo *const *property_infos; + guint p; + + property_infos = nm_meta_setting_infos_editor[s].properties; + if (!property_infos) + continue; + for (p = 0; property_infos[p]; p++) { + const NMMetaPropertyInfo *property_info = property_infos[p]; + + if (_meta_property_needs_bond_hack(property_info)) { + guint i; + + for (i = 0; i < nm_meta_property_typ_data_bond.nested_len; i++) { + const NMMetaNestedPropertyInfo *bi = &nm_meta_property_typ_data_bond.nested[i]; + + if (!option_relevant(connection, (const NMMetaAbstractInfo *) bi)) + continue; + if (bi->base.inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) { + g_string_printf(nmc->return_text, + _("Error: '%s' argument is required."), + bi->base.property_alias); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + goto finish; + } + } + } else { + if (!property_info->is_cli_option) + continue; + if (!option_relevant(connection, (const NMMetaAbstractInfo *) property_info)) + continue; + if (property_info->inf_flags & NM_META_PROPERTY_INF_FLAG_REQD) { + g_string_printf(nmc->return_text, + _("Error: '%s' argument is required."), + property_info->property_alias); + nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; + goto finish; + } + } + } + } + + add_connection(nmc->client, + connection, + !save_bool, + add_connection_cb, + _add_connection_info_new(nmc, NULL, connection)); + nmc->should_wait++; finish: - reset_options (); + reset_options(); } /*****************************************************************************/ /* Functions for readline TAB completion in editor */ static void -uuid_display_hook (char **array, int len, int max_len) -{ - const GPtrArray *connections; - NMConnection *con; - int i, max = 0; - char *tmp; - const char *id; - for (i = 1; i <= len; i++) { - connections = nm_client_get_connections (nmc_tab_completion.nmc->client); - con = nmc_find_connection (connections, "uuid", array[i], NULL, FALSE); - id = con ? nm_connection_get_id (con) : NULL; - if (id) { - tmp = g_strdup_printf ("%s (%s)", array[i], id); - g_free (array[i]); - array[i] = tmp; - if (max < strlen (id)) - max = strlen (id); - } - } - rl_display_match_list (array, len, max_len + max + 3); - rl_forced_update_display (); +uuid_display_hook(char **array, int len, int max_len) +{ + const GPtrArray *connections; + NMConnection * con; + int i, max = 0; + char * tmp; + const char * id; + for (i = 1; i <= len; i++) { + connections = nm_client_get_connections(nmc_tab_completion.nmc->client); + con = nmc_find_connection(connections, "uuid", array[i], NULL, FALSE); + id = con ? nm_connection_get_id(con) : NULL; + if (id) { + tmp = g_strdup_printf("%s (%s)", array[i], id); + g_free(array[i]); + array[i] = tmp; + if (max < strlen(id)) + max = strlen(id); + } + } + rl_display_match_list(array, len, max_len + max + 3); + rl_forced_update_display(); } static char * -gen_nmcli_cmds_menu (const char *text, int state) -{ - const char *words[] = { "goto", "set", "remove", "describe", "print", "verify", - "save", "activate", "back", "help", "quit", "nmcli", - NULL }; - return nmc_rl_gen_func_basic (text, state, words); +gen_nmcli_cmds_menu(const char *text, int state) +{ + const char *words[] = {"goto", + "set", + "remove", + "describe", + "print", + "verify", + "save", + "activate", + "back", + "help", + "quit", + "nmcli", + NULL}; + return nmc_rl_gen_func_basic(text, state, words); } static char * -gen_nmcli_cmds_submenu (const char *text, int state) +gen_nmcli_cmds_submenu(const char *text, int state) { - const char *words[] = { "set", "add", "change", "remove", "describe", - "print", "back", "help", "quit", - NULL }; - return nmc_rl_gen_func_basic (text, state, words); + const char *words[] = + {"set", "add", "change", "remove", "describe", "print", "back", "help", "quit", NULL}; + return nmc_rl_gen_func_basic(text, state, words); } static char * -gen_cmd_nmcli (const char *text, int state) +gen_cmd_nmcli(const char *text, int state) { - const char *words[] = { "status-line", "save-confirmation", "show-secrets", NULL }; - return nmc_rl_gen_func_basic (text, state, words); + const char *words[] = {"status-line", "save-confirmation", "show-secrets", NULL}; + return nmc_rl_gen_func_basic(text, state, words); } static char * -gen_func_bool_values (const char *text, int state) +gen_func_bool_values(const char *text, int state) { - const char *words[] = { "yes", "no", NULL }; - return nmc_rl_gen_func_basic (text, state, words); + const char *words[] = {"yes", "no", NULL}; + return nmc_rl_gen_func_basic(text, state, words); } static char * -gen_cmd_verify0 (const char *text, int state) +gen_cmd_verify0(const char *text, int state) { - const char *words[] = { "all", "fix", NULL }; - return nmc_rl_gen_func_basic (text, state, words); + const char *words[] = {"all", "fix", NULL}; + return nmc_rl_gen_func_basic(text, state, words); } static char * -gen_cmd_print0 (const char *text, int state) -{ - static char **words = NULL; - char *ret = NULL; - - if (!state) { - GVariant *settings; - GVariantIter iter; - const char *setting_name; - int i = 0; - - settings = nm_connection_to_dbus (nmc_tab_completion.connection, NM_CONNECTION_SERIALIZE_NO_SECRETS); - words = g_new (char *, g_variant_n_children (settings) + 2); - g_variant_iter_init (&iter, settings); - while (g_variant_iter_next (&iter, "{&s@a{sv}}", &setting_name, NULL)) - words [i++] = g_strdup (setting_name); - words[i++] = g_strdup ("all"); - words[i] = NULL; - g_variant_unref (settings); - } - - if (words) { - ret = nmc_rl_gen_func_basic (text, state, (const char **) words); - if (ret == NULL) { - g_strfreev (words); - words = NULL; - } - } - return ret; +gen_cmd_print0(const char *text, int state) +{ + static char **words = NULL; + char * ret = NULL; + + if (!state) { + GVariant * settings; + GVariantIter iter; + const char * setting_name; + int i = 0; + + settings = nm_connection_to_dbus(nmc_tab_completion.connection, + NM_CONNECTION_SERIALIZE_NO_SECRETS); + words = g_new(char *, g_variant_n_children(settings) + 2); + g_variant_iter_init(&iter, settings); + while (g_variant_iter_next(&iter, "{&s@a{sv}}", &setting_name, NULL)) + words[i++] = g_strdup(setting_name); + words[i++] = g_strdup("all"); + words[i] = NULL; + g_variant_unref(settings); + } + + if (words) { + ret = nmc_rl_gen_func_basic(text, state, (const char **) words); + if (ret == NULL) { + g_strfreev(words); + words = NULL; + } + } + return ret; } static char * -gen_cmd_print2 (const char *text, int state) +gen_cmd_print2(const char *text, int state) { - const char *words[] = { "setting", "connection", "all", NULL }; - return nmc_rl_gen_func_basic (text, state, words); + const char *words[] = {"setting", "connection", "all", NULL}; + return nmc_rl_gen_func_basic(text, state, words); } static char * -gen_cmd_save (const char *text, int state) +gen_cmd_save(const char *text, int state) { - const char *words[] = { "persistent", "temporary", NULL }; - return nmc_rl_gen_func_basic (text, state, words); + const char *words[] = {"persistent", "temporary", NULL}; + return nmc_rl_gen_func_basic(text, state, words); } static rl_compentry_func_t * -gen_connection_types (const char *text) +gen_connection_types(const char *text) { - gs_free char **values = NULL; - const NMMetaSettingInfoEditor *editor; - GPtrArray *array; - int i; + gs_free char ** values = NULL; + const NMMetaSettingInfoEditor *editor; + GPtrArray * array; + int i; - array = g_ptr_array_new (); + array = g_ptr_array_new(); - for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { - editor = &nm_meta_setting_infos_editor[i]; - if (!editor->valid_parts) - continue; - g_ptr_array_add (array, (gpointer) nm_meta_setting_infos[i].setting_name); - if (editor->alias) - g_ptr_array_add (array, (gpointer) editor->alias); - } + for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { + editor = &nm_meta_setting_infos_editor[i]; + if (!editor->valid_parts) + continue; + g_ptr_array_add(array, (gpointer) nm_meta_setting_infos[i].setting_name); + if (editor->alias) + g_ptr_array_add(array, (gpointer) editor->alias); + } - g_ptr_array_add (array, "bond-slave"); - g_ptr_array_add (array, "bridge-slave"); - g_ptr_array_add (array, "team-slave"); - g_ptr_array_add (array, NULL); + g_ptr_array_add(array, "bond-slave"); + g_ptr_array_add(array, "bridge-slave"); + g_ptr_array_add(array, "team-slave"); + g_ptr_array_add(array, NULL); - values = (char **) g_ptr_array_free (array, FALSE); + values = (char **) g_ptr_array_free(array, FALSE); - return nmc_rl_compentry_func_wrap ((const char *const*) values); + return nmc_rl_compentry_func_wrap((const char *const *) values); } static char * -gen_setting_names (const char *text, int state) -{ - static int list_idx, len, is_slv; - const char *s_name, *a_name; - const NMMetaSettingValidPartItem *const*valid_settings_arr; - NMSettingConnection *s_con; - const char *s_type = NULL; - - if (!state) { - list_idx = 0; - len = strlen (text); - is_slv = 0; - } - - if (!is_slv) { - valid_settings_arr = get_valid_settings_array (nmc_tab_completion.con_type); - if (list_idx >= NM_PTRARRAY_LEN (valid_settings_arr)) - return NULL; - for (; valid_settings_arr[list_idx];) { - const NMMetaSettingInfoEditor *setting_info = valid_settings_arr[list_idx]->setting_info; - - a_name = setting_info->alias; - s_name = setting_info->general->setting_name; - list_idx++; - if (len == 0 && a_name) - return g_strdup_printf ("%s (%s)", s_name, a_name); - if (a_name && !strncmp (text, a_name, len)) - return g_strdup (a_name); - if (s_name && !strncmp (text, s_name, len)) - return g_strdup (s_name); - } - - /* Let's give a try to parameters related to slave type */ - list_idx = 0; - is_slv = 1; - } - - /* is_slv */ - s_con = nm_connection_get_setting_connection (nmc_tab_completion.connection); - if (s_con) - s_type = nm_setting_connection_get_slave_type (s_con); - valid_settings_arr = nm_meta_setting_info_valid_parts_for_slave_type (s_type, NULL); - - if (list_idx < NM_PTRARRAY_LEN (valid_settings_arr)) { - while (valid_settings_arr[list_idx]) { - const NMMetaSettingInfoEditor *setting_info = valid_settings_arr[list_idx]->setting_info; - - a_name = setting_info->alias; - s_name = setting_info->general->setting_name; - list_idx++; - if (len == 0 && a_name) - return g_strdup_printf ("%s (%s)", s_name, a_name); - if (a_name && !strncmp (text, a_name, len)) - return g_strdup (a_name); - if (s_name && !strncmp (text, s_name, len)) - return g_strdup (s_name); - } - } - - return NULL; +gen_setting_names(const char *text, int state) +{ + static int list_idx, len, is_slv; + const char * s_name, *a_name; + const NMMetaSettingValidPartItem *const *valid_settings_arr; + NMSettingConnection * s_con; + const char * s_type = NULL; + + if (!state) { + list_idx = 0; + len = strlen(text); + is_slv = 0; + } + + if (!is_slv) { + valid_settings_arr = get_valid_settings_array(nmc_tab_completion.con_type); + if (list_idx >= NM_PTRARRAY_LEN(valid_settings_arr)) + return NULL; + for (; valid_settings_arr[list_idx];) { + const NMMetaSettingInfoEditor *setting_info = + valid_settings_arr[list_idx]->setting_info; + + a_name = setting_info->alias; + s_name = setting_info->general->setting_name; + list_idx++; + if (len == 0 && a_name) + return g_strdup_printf("%s (%s)", s_name, a_name); + if (a_name && !strncmp(text, a_name, len)) + return g_strdup(a_name); + if (s_name && !strncmp(text, s_name, len)) + return g_strdup(s_name); + } + + /* Let's give a try to parameters related to slave type */ + list_idx = 0; + is_slv = 1; + } + + /* is_slv */ + s_con = nm_connection_get_setting_connection(nmc_tab_completion.connection); + if (s_con) + s_type = nm_setting_connection_get_slave_type(s_con); + valid_settings_arr = nm_meta_setting_info_valid_parts_for_slave_type(s_type, NULL); + + if (list_idx < NM_PTRARRAY_LEN(valid_settings_arr)) { + while (valid_settings_arr[list_idx]) { + const NMMetaSettingInfoEditor *setting_info = + valid_settings_arr[list_idx]->setting_info; + + a_name = setting_info->alias; + s_name = setting_info->general->setting_name; + list_idx++; + if (len == 0 && a_name) + return g_strdup_printf("%s (%s)", s_name, a_name); + if (a_name && !strncmp(text, a_name, len)) + return g_strdup(a_name); + if (s_name && !strncmp(text, s_name, len)) + return g_strdup(s_name); + } + } + + return NULL; } static char * -gen_property_names (const char *text, int state) -{ - NMSetting *setting = NULL; - char **valid_props = NULL; - char *ret = NULL; - const char *line = rl_line_buffer; - const char *setting_name; - char **strv = NULL; - const NMMetaSettingValidPartItem *const*valid_settings_main; - const NMMetaSettingValidPartItem *const*valid_settings_slave; - const char *p1; - const char *slv_type; - - /* Try to get the setting from 'line' - setting_name.property */ - p1 = strchr (line, '.'); - if (p1) { - while (p1 > line && !g_ascii_isspace (*p1)) - p1--; - - strv = g_strsplit (p1 + 1, ".", 2); - - valid_settings_main = get_valid_settings_array (nmc_tab_completion.con_type); - - /* Support autocompletion of slave-connection parameters - * guessing the slave type from the setting name already - * typed (or autocompleted) */ - if (nm_streq0 (strv[0], NM_SETTING_TEAM_PORT_SETTING_NAME)) - slv_type = NM_SETTING_TEAM_SETTING_NAME; - else if (nm_streq0 (strv[0], NM_SETTING_BRIDGE_PORT_SETTING_NAME)) - slv_type = NM_SETTING_BRIDGE_SETTING_NAME; - else - slv_type = NULL; - valid_settings_slave = nm_meta_setting_info_valid_parts_for_slave_type (slv_type, NULL); - - setting_name = check_valid_name (strv[0], - valid_settings_main, - valid_settings_slave, - NULL); - if (setting_name) { - setting = nm_meta_setting_info_editor_new_setting (nm_meta_setting_info_editor_find_by_name (setting_name, FALSE), - NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT); - } - } - - if (!setting) { - /* Else take the current setting, if any */ - setting = nmc_tab_completion.setting ? g_object_ref (nmc_tab_completion.setting) : NULL; - } - - if (setting) { - valid_props = nmc_setting_get_valid_properties (setting); - ret = nmc_rl_gen_func_basic (text, state, (const char **) valid_props); - } - - g_strfreev (strv); - g_strfreev (valid_props); - if (setting) - g_object_unref (setting); - return ret; +gen_property_names(const char *text, int state) +{ + NMSetting * setting = NULL; + char ** valid_props = NULL; + char * ret = NULL; + const char * line = rl_line_buffer; + const char * setting_name; + char ** strv = NULL; + const NMMetaSettingValidPartItem *const *valid_settings_main; + const NMMetaSettingValidPartItem *const *valid_settings_slave; + const char * p1; + const char * slv_type; + + /* Try to get the setting from 'line' - setting_name.property */ + p1 = strchr(line, '.'); + if (p1) { + while (p1 > line && !g_ascii_isspace(*p1)) + p1--; + + strv = g_strsplit(p1 + 1, ".", 2); + + valid_settings_main = get_valid_settings_array(nmc_tab_completion.con_type); + + /* Support autocompletion of slave-connection parameters + * guessing the slave type from the setting name already + * typed (or autocompleted) */ + if (nm_streq0(strv[0], NM_SETTING_TEAM_PORT_SETTING_NAME)) + slv_type = NM_SETTING_TEAM_SETTING_NAME; + else if (nm_streq0(strv[0], NM_SETTING_BRIDGE_PORT_SETTING_NAME)) + slv_type = NM_SETTING_BRIDGE_SETTING_NAME; + else + slv_type = NULL; + valid_settings_slave = nm_meta_setting_info_valid_parts_for_slave_type(slv_type, NULL); + + setting_name = check_valid_name(strv[0], valid_settings_main, valid_settings_slave, NULL); + if (setting_name) { + setting = nm_meta_setting_info_editor_new_setting( + nm_meta_setting_info_editor_find_by_name(setting_name, FALSE), + NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT); + } + } + + if (!setting) { + /* Else take the current setting, if any */ + setting = nmc_tab_completion.setting ? g_object_ref(nmc_tab_completion.setting) : NULL; + } + + if (setting) { + valid_props = nmc_setting_get_valid_properties(setting); + ret = nmc_rl_gen_func_basic(text, state, (const char **) valid_props); + } + + g_strfreev(strv); + g_strfreev(valid_props); + if (setting) + g_object_unref(setting); + return ret; } static char * -gen_compat_devices (const char *text, int state) -{ - guint i, j = 0; - const GPtrArray *devices; - const char **compatible_devices; - char *ret; - - devices = nm_client_get_devices (nmc_tab_completion.nmc->client); - if (devices->len == 0) - return NULL; - - compatible_devices = g_new (const char *, devices->len + 1); - for (i = 0; i < devices->len; i++) { - NMDevice *dev = g_ptr_array_index (devices, i); - const char *ifname = nm_device_get_iface (dev); - NMDevice *device = NULL; - const char *spec_object = NULL; - - if (find_device_for_connection (nmc_tab_completion.nmc, nmc_tab_completion.connection, - ifname, NULL, NULL, &device, &spec_object, NULL)) { - compatible_devices[j++] = ifname; - } - } - compatible_devices[j] = NULL; - - ret = nmc_rl_gen_func_basic (text, state, compatible_devices); - - g_free (compatible_devices); - return ret; +gen_compat_devices(const char *text, int state) +{ + guint i, j = 0; + const GPtrArray *devices; + const char ** compatible_devices; + char * ret; + + devices = nm_client_get_devices(nmc_tab_completion.nmc->client); + if (devices->len == 0) + return NULL; + + compatible_devices = g_new(const char *, devices->len + 1); + for (i = 0; i < devices->len; i++) { + NMDevice * dev = g_ptr_array_index(devices, i); + const char *ifname = nm_device_get_iface(dev); + NMDevice * device = NULL; + const char *spec_object = NULL; + + if (find_device_for_connection(nmc_tab_completion.nmc, + nmc_tab_completion.connection, + ifname, + NULL, + NULL, + &device, + &spec_object, + NULL)) { + compatible_devices[j++] = ifname; + } + } + compatible_devices[j] = NULL; + + ret = nmc_rl_gen_func_basic(text, state, compatible_devices); + + g_free(compatible_devices); + return ret; } static const char ** -_create_vpn_array (const GPtrArray *connections, gboolean uuid) +_create_vpn_array(const GPtrArray *connections, gboolean uuid) { - int c, idx = 0; - const char **array; + int c, idx = 0; + const char **array; - if (connections->len < 1) - return NULL; + if (connections->len < 1) + return NULL; - array = g_new (const char *, connections->len + 1); - for (c = 0; c < connections->len; c++) { - NMConnection *connection = NM_CONNECTION (connections->pdata[c]); - const char *type = nm_connection_get_connection_type (connection); + array = g_new(const char *, connections->len + 1); + for (c = 0; c < connections->len; c++) { + NMConnection *connection = NM_CONNECTION(connections->pdata[c]); + const char * type = nm_connection_get_connection_type(connection); - if (g_strcmp0 (type, NM_SETTING_VPN_SETTING_NAME) == 0) - array[idx++] = uuid ? nm_connection_get_uuid (connection) : nm_connection_get_id (connection); - } - array[idx] = NULL; - return array; + if (g_strcmp0(type, NM_SETTING_VPN_SETTING_NAME) == 0) + array[idx++] = + uuid ? nm_connection_get_uuid(connection) : nm_connection_get_id(connection); + } + array[idx] = NULL; + return array; } static char * -gen_vpn_uuids (const char *text, int state) +gen_vpn_uuids(const char *text, int state) { - const GPtrArray *connections; - const char **uuids; - char *ret; + const GPtrArray *connections; + const char ** uuids; + char * ret; - connections = nm_client_get_connections (nm_cli_global_readline->client); - if (connections->len < 1) - return NULL; + connections = nm_client_get_connections(nm_cli_global_readline->client); + if (connections->len < 1) + return NULL; - uuids = _create_vpn_array (connections, TRUE); - ret = nmc_rl_gen_func_basic (text, state, uuids); - g_free (uuids); - return ret; + uuids = _create_vpn_array(connections, TRUE); + ret = nmc_rl_gen_func_basic(text, state, uuids); + g_free(uuids); + return ret; } static char * -gen_vpn_ids (const char *text, int state) +gen_vpn_ids(const char *text, int state) { - const GPtrArray *connections; - const char **ids; - char *ret; + const GPtrArray *connections; + const char ** ids; + char * ret; - connections = nm_client_get_connections (nm_cli_global_readline->client); - if (connections->len < 1) - return NULL; + connections = nm_client_get_connections(nm_cli_global_readline->client); + if (connections->len < 1) + return NULL; - ids = _create_vpn_array (connections, FALSE); - ret = nmc_rl_gen_func_basic (text, state, ids); - g_free (ids); - return ret; + ids = _create_vpn_array(connections, FALSE); + ret = nmc_rl_gen_func_basic(text, state, ids); + g_free(ids); + return ret; } static rl_compentry_func_t * -get_gen_func_cmd_nmcli (const char *str) +get_gen_func_cmd_nmcli(const char *str) { - if (!str) - return NULL; - if (matches (str, "status-line")) - return gen_func_bool_values; - if (matches (str, "save-confirmation")) - return gen_func_bool_values; - if (matches (str, "show-secrets")) - return gen_func_bool_values; - return NULL; + if (!str) + return NULL; + if (matches(str, "status-line")) + return gen_func_bool_values; + if (matches(str, "save-confirmation")) + return gen_func_bool_values; + if (matches(str, "show-secrets")) + return gen_func_bool_values; + return NULL; } /* @@ -5837,63 +6138,62 @@ get_gen_func_cmd_nmcli (const char *str) * line=" bla ipv4.method" cmd="goto" -> FALSE */ static gboolean -should_complete_cmd (const char *line, int end, const char *cmd, - int *cw_num, char **prev_word) -{ - char *tmp; - const char *word1, *word2, *word3; - size_t n1, n2, n3, n4, n5, n6; - gboolean word1_done, word2_done, word3_done; - gboolean ret = FALSE; - - if (!line) - return FALSE; - - tmp = g_strdup (line); - - n1 = strspn (tmp, " \t"); - n2 = strcspn (tmp+n1, " \t\0") + n1; - n3 = strspn (tmp+n2, " \t") + n2; - n4 = strcspn (tmp+n3, " \t\0") + n3; - n5 = strspn (tmp+n4, " \t") + n4; - n6 = strcspn (tmp+n5, " \t\0") + n5; - - word1_done = end > n2; - word2_done = end > n4; - word3_done = end > n6; - tmp[n2] = tmp[n4] = tmp[n6] = '\0'; - - word1 = tmp[n1] ? tmp + n1 : NULL; - word2 = tmp[n3] ? tmp + n3 : NULL; - word3 = tmp[n5] ? tmp + n5 : NULL; - - if (!word1_done) { - if (cw_num) - *cw_num = 1; - if (prev_word) - *prev_word = NULL; - } else if (!word2_done) { - if (cw_num) - *cw_num = 2; - if (prev_word) - *prev_word = g_strdup (word1); - } else if (!word3_done) { - if (cw_num) - *cw_num = 3; - if (prev_word) - *prev_word = g_strdup (word2); - } else { - if (cw_num) - *cw_num = 4; - if (prev_word) - *prev_word = g_strdup (word3); - } - - if (word1 && matches (word1, cmd)) - ret = TRUE; - - g_free (tmp); - return ret; +should_complete_cmd(const char *line, int end, const char *cmd, int *cw_num, char **prev_word) +{ + char * tmp; + const char *word1, *word2, *word3; + size_t n1, n2, n3, n4, n5, n6; + gboolean word1_done, word2_done, word3_done; + gboolean ret = FALSE; + + if (!line) + return FALSE; + + tmp = g_strdup(line); + + n1 = strspn(tmp, " \t"); + n2 = strcspn(tmp + n1, " \t\0") + n1; + n3 = strspn(tmp + n2, " \t") + n2; + n4 = strcspn(tmp + n3, " \t\0") + n3; + n5 = strspn(tmp + n4, " \t") + n4; + n6 = strcspn(tmp + n5, " \t\0") + n5; + + word1_done = end > n2; + word2_done = end > n4; + word3_done = end > n6; + tmp[n2] = tmp[n4] = tmp[n6] = '\0'; + + word1 = tmp[n1] ? tmp + n1 : NULL; + word2 = tmp[n3] ? tmp + n3 : NULL; + word3 = tmp[n5] ? tmp + n5 : NULL; + + if (!word1_done) { + if (cw_num) + *cw_num = 1; + if (prev_word) + *prev_word = NULL; + } else if (!word2_done) { + if (cw_num) + *cw_num = 2; + if (prev_word) + *prev_word = g_strdup(word1); + } else if (!word3_done) { + if (cw_num) + *cw_num = 3; + if (prev_word) + *prev_word = g_strdup(word2); + } else { + if (cw_num) + *cw_num = 4; + if (prev_word) + *prev_word = g_strdup(word3); + } + + if (word1 && matches(word1, cmd)) + ret = TRUE; + + g_free(tmp); + return ret; } /* @@ -5908,239 +6208,227 @@ should_complete_cmd (const char *line, int end, const char *cmd, * Extract setting and property names from prompt and/or line. */ static void -extract_setting_and_property (const char *prompt, const char *line, - char **setting, char **property) -{ - char *prop = NULL; - char *sett = NULL; - - if (prompt) { - /* prompt looks like this: - "nmcli 802-1x>" or "nmcli 802-1x.pac-file>" */ - const char *p1, *p2, *dot; - size_t num1, num2; - p1 = strchr (prompt, ' '); - if (p1) { - dot = strchr (++p1, '.'); - if (dot) { - p2 = dot + 1; - num1 = strcspn (p1, "."); - num2 = strcspn (p2, ">"); - sett = num1 > 0 ? g_strndup (p1, num1) : NULL; - prop = num2 > 0 ? g_strndup (p2, num2) : NULL; - } else { - num1 = strcspn (p1, ">"); - sett = num1 > 0 ? g_strndup (p1, num1) : NULL; - } - } - } - - if (line) { - /* line looks like this: - " set 802-1x.pac-file ..." or " set pac-file ..." */ - const char *p1, *p2, *dot; - size_t n1, n2, n3, n4; - size_t num1, num2, len; - n1 = strspn (line, " \t"); /* white-space */ - n2 = strcspn (line+n1, " \t\0") + n1; /* command */ - n3 = strspn (line+n2, " \t") + n2; /* white-space */ - n4 = strcspn (line+n3, " \t\0") + n3; /* setting/property */ - p1 = line + n3; - len = n4 - n3; - - dot = strchr (p1, '.'); - if (dot && dot < p1 + len) { - p2 = dot + 1; - num1 = strcspn (p1, "."); - num2 = len > num1 + 1 ? len - num1 - 1 : 0; - sett = num1 > 0 ? g_strndup (p1, num1) : sett; - prop = num2 > 0 ? g_strndup (p2, num2) : prop; - } else { - if (!prop) - prop = len > 0 ? g_strndup (p1, len) : NULL; - } - } - - if (setting) - *setting = sett; - else - g_free (sett); - if (property) - *property = prop; - else - g_free (prop); +extract_setting_and_property(const char *prompt, const char *line, char **setting, char **property) +{ + char *prop = NULL; + char *sett = NULL; + + if (prompt) { + /* prompt looks like this: + * "nmcli 802-1x>" or "nmcli 802-1x.pac-file>" */ + const char *p1, *p2, *dot; + size_t num1, num2; + p1 = strchr(prompt, ' '); + if (p1) { + dot = strchr(++p1, '.'); + if (dot) { + p2 = dot + 1; + num1 = strcspn(p1, "."); + num2 = strcspn(p2, ">"); + sett = num1 > 0 ? g_strndup(p1, num1) : NULL; + prop = num2 > 0 ? g_strndup(p2, num2) : NULL; + } else { + num1 = strcspn(p1, ">"); + sett = num1 > 0 ? g_strndup(p1, num1) : NULL; + } + } + } + + if (line) { + /* line looks like this: + * " set 802-1x.pac-file ..." or " set pac-file ..." */ + const char *p1, *p2, *dot; + size_t n1, n2, n3, n4; + size_t num1, num2, len; + n1 = strspn(line, " \t"); /* white-space */ + n2 = strcspn(line + n1, " \t\0") + n1; /* command */ + n3 = strspn(line + n2, " \t") + n2; /* white-space */ + n4 = strcspn(line + n3, " \t\0") + n3; /* setting/property */ + p1 = line + n3; + len = n4 - n3; + + dot = strchr(p1, '.'); + if (dot && dot < p1 + len) { + p2 = dot + 1; + num1 = strcspn(p1, "."); + num2 = len > num1 + 1 ? len - num1 - 1 : 0; + sett = num1 > 0 ? g_strndup(p1, num1) : sett; + prop = num2 > 0 ? g_strndup(p2, num2) : prop; + } else { + if (!prop) + prop = len > 0 ? g_strndup(p1, len) : NULL; + } + } + + if (setting) + *setting = sett; + else + g_free(sett); + if (property) + *property = prop; + else + g_free(prop); } static void -get_setting_and_property (const char *prompt, - const char *line, - NMSetting **setting_out, - char **property_out) -{ - const NMMetaSettingValidPartItem *const*valid_settings_main; - const NMMetaSettingValidPartItem *const*valid_settings_slave; - gs_unref_object NMSetting *setting = NULL; - gs_free char *property = NULL; - NMSettingConnection *s_con; - gs_free char *sett = NULL; - gs_free char *prop = NULL; - const char *s_type = NULL; - const char *setting_name; - - extract_setting_and_property (prompt, line, &sett, &prop); - - if (sett) { - /* Is this too much (and useless?) effort for an unlikely case? */ - s_con = nm_connection_get_setting_connection (nmc_tab_completion.connection); - if (s_con) - s_type = nm_setting_connection_get_slave_type (s_con); - - valid_settings_main = get_valid_settings_array (nmc_tab_completion.con_type); - valid_settings_slave = nm_meta_setting_info_valid_parts_for_slave_type (s_type, NULL); - - setting_name = check_valid_name (sett, - valid_settings_main, - valid_settings_slave, - NULL); - setting = nm_meta_setting_info_editor_new_setting (nm_meta_setting_info_editor_find_by_name (setting_name, FALSE), - NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT); - } else - setting = nm_g_object_ref (nmc_tab_completion.setting); - - if (setting && prop) - property = is_property_valid (setting, prop, NULL); - else - property = g_strdup (nmc_tab_completion.property); - - *setting_out = g_steal_pointer (&setting); - *property_out = g_steal_pointer (&property); +get_setting_and_property(const char *prompt, + const char *line, + NMSetting **setting_out, + char ** property_out) +{ + const NMMetaSettingValidPartItem *const *valid_settings_main; + const NMMetaSettingValidPartItem *const *valid_settings_slave; + gs_unref_object NMSetting *setting = NULL; + gs_free char * property = NULL; + NMSettingConnection * s_con; + gs_free char * sett = NULL; + gs_free char * prop = NULL; + const char * s_type = NULL; + const char * setting_name; + + extract_setting_and_property(prompt, line, &sett, &prop); + + if (sett) { + /* Is this too much (and useless?) effort for an unlikely case? */ + s_con = nm_connection_get_setting_connection(nmc_tab_completion.connection); + if (s_con) + s_type = nm_setting_connection_get_slave_type(s_con); + + valid_settings_main = get_valid_settings_array(nmc_tab_completion.con_type); + valid_settings_slave = nm_meta_setting_info_valid_parts_for_slave_type(s_type, NULL); + + setting_name = check_valid_name(sett, valid_settings_main, valid_settings_slave, NULL); + setting = nm_meta_setting_info_editor_new_setting( + nm_meta_setting_info_editor_find_by_name(setting_name, FALSE), + NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT); + } else + setting = nm_g_object_ref(nmc_tab_completion.setting); + + if (setting && prop) + property = is_property_valid(setting, prop, NULL); + else + property = g_strdup(nmc_tab_completion.property); + + *setting_out = g_steal_pointer(&setting); + *property_out = g_steal_pointer(&property); } static gboolean -_get_and_check_property (const char *prompt, - const char *line, - const char **array, - const char **array_multi, - gboolean *multi) +_get_and_check_property(const char * prompt, + const char * line, + const char **array, + const char **array_multi, + gboolean * multi) { - gs_free char *prop = NULL; - gboolean found = FALSE; + gs_free char *prop = NULL; + gboolean found = FALSE; - extract_setting_and_property (prompt, line, NULL, &prop); - if (prop) { - if (array) - found = !!nmc_string_is_valid (prop, array, NULL); - if (array_multi && multi) - *multi = !!nmc_string_is_valid (prop, array_multi, NULL); - } - return found; + extract_setting_and_property(prompt, line, NULL, &prop); + if (prop) { + if (array) + found = !!nmc_string_is_valid(prop, array, NULL); + if (array_multi && multi) + *multi = !!nmc_string_is_valid(prop, array_multi, NULL); + } + return found; } static gboolean -should_complete_files (const char *prompt, const char *line) -{ - const char *file_properties[] = { - /* '802-1x' properties */ - "ca-cert", - "ca-path", - "client-cert", - "pac-file", - "phase2-ca-cert", - "phase2-ca-path", - "phase2-client-cert", - "private-key", - "phase2-private-key", - /* 'team' and 'team-port' properties */ - "config", - /* 'proxy' properties */ - "pac-script", - NULL - }; - return _get_and_check_property (prompt, line, file_properties, NULL, NULL); +should_complete_files(const char *prompt, const char *line) +{ + const char *file_properties[] = {/* '802-1x' properties */ + "ca-cert", + "ca-path", + "client-cert", + "pac-file", + "phase2-ca-cert", + "phase2-ca-path", + "phase2-client-cert", + "private-key", + "phase2-private-key", + /* 'team' and 'team-port' properties */ + "config", + /* 'proxy' properties */ + "pac-script", + NULL}; + return _get_and_check_property(prompt, line, file_properties, NULL, NULL); } static gboolean -should_complete_vpn_uuids (const char *prompt, const char *line) +should_complete_vpn_uuids(const char *prompt, const char *line) { - const char *uuid_properties[] = { - /* 'connection' properties */ - "secondaries", - NULL - }; - return _get_and_check_property (prompt, line, uuid_properties, NULL, NULL); + const char *uuid_properties[] = {/* 'connection' properties */ + "secondaries", + NULL}; + return _get_and_check_property(prompt, line, uuid_properties, NULL, NULL); } -static const char *const* -get_allowed_property_values (char ***out_to_free) +static const char *const * +get_allowed_property_values(char ***out_to_free) { - gs_unref_object NMSetting *setting = NULL; - gs_free char *property = NULL; - const char *const*avals = NULL; + gs_unref_object NMSetting *setting = NULL; + gs_free char * property = NULL; + const char *const * avals = NULL; - get_setting_and_property (rl_prompt, rl_line_buffer, &setting, &property); - if (setting && property) - avals = nmc_setting_get_property_allowed_values (setting, property, out_to_free); - return avals; + get_setting_and_property(rl_prompt, rl_line_buffer, &setting, &property); + if (setting && property) + avals = nmc_setting_get_property_allowed_values(setting, property, out_to_free); + return avals; } static gboolean -should_complete_property_values (const char *prompt, const char *line, gboolean *multi) -{ - gs_strfreev char **to_free = NULL; - - /* properties allowing multiple values */ - const char *multi_props[] = { - /* '802-1x' properties */ - NM_SETTING_802_1X_EAP, - /* '802-11-wireless-security' properties */ - NM_SETTING_WIRELESS_SECURITY_PROTO, - NM_SETTING_WIRELESS_SECURITY_PAIRWISE, - NM_SETTING_WIRELESS_SECURITY_GROUP, - /* 'bond' properties */ - NM_SETTING_BOND_OPTIONS, - /* 'ethernet' properties */ - NM_SETTING_WIRED_S390_OPTIONS, - NULL - }; - _get_and_check_property (prompt, line, NULL, multi_props, multi); - return !!get_allowed_property_values (&to_free); +should_complete_property_values(const char *prompt, const char *line, gboolean *multi) +{ + gs_strfreev char **to_free = NULL; + + /* properties allowing multiple values */ + const char *multi_props[] = {/* '802-1x' properties */ + NM_SETTING_802_1X_EAP, + /* '802-11-wireless-security' properties */ + NM_SETTING_WIRELESS_SECURITY_PROTO, + NM_SETTING_WIRELESS_SECURITY_PAIRWISE, + NM_SETTING_WIRELESS_SECURITY_GROUP, + /* 'bond' properties */ + NM_SETTING_BOND_OPTIONS, + /* 'ethernet' properties */ + NM_SETTING_WIRED_S390_OPTIONS, + NULL}; + _get_and_check_property(prompt, line, NULL, multi_props, multi); + return !!get_allowed_property_values(&to_free); } static gboolean -_setting_property_is_boolean (NMSetting *setting, const char *property_name) +_setting_property_is_boolean(NMSetting *setting, const char *property_name) { - const GParamSpec *pspec; + const GParamSpec *pspec; - nm_assert (NM_IS_SETTING (setting)); - nm_assert (property_name); + nm_assert(NM_IS_SETTING(setting)); + nm_assert(property_name); - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), property_name); - return pspec - && pspec->value_type == G_TYPE_BOOLEAN; + pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(setting), property_name); + return pspec && pspec->value_type == G_TYPE_BOOLEAN; } static gboolean -should_complete_boolean (const char *prompt, const char *line) +should_complete_boolean(const char *prompt, const char *line) { - gs_unref_object NMSetting *setting = NULL; - gs_free char *property = NULL; + gs_unref_object NMSetting *setting = NULL; + gs_free char * property = NULL; - get_setting_and_property (prompt, line, &setting, &property); - return setting - && property - && _setting_property_is_boolean (setting, property); + get_setting_and_property(prompt, line, &setting, &property); + return setting && property && _setting_property_is_boolean(setting, property); } static char * -gen_property_values (const char *text, int state) +gen_property_values(const char *text, int state) { - gs_strfreev char **to_free = NULL; - const char *const*avals; + gs_strfreev char **to_free = NULL; + const char *const *avals; - avals = get_allowed_property_values (&to_free); - if (!avals) - return NULL; - return nmc_rl_gen_func_basic (text, state, avals); + avals = get_allowed_property_values(&to_free); + if (!avals) + return NULL; + return nmc_rl_gen_func_basic(text, state, avals); } /* from readline */ @@ -6153,614 +6441,618 @@ extern int rl_complete_with_tilde_expansion; * array of matches, or NULL if there aren't any. */ static char ** -nmcli_editor_tab_completion (const char *text, int start, int end) -{ - rl_compentry_func_t *generator_func = NULL; - const char *line = rl_line_buffer; - gs_free char *prompt_tmp = NULL; - gs_free char *word = NULL; - char **match_array = NULL; - size_t n1; - int num; - - /* Restore standard append character to space */ - rl_completion_append_character = ' '; - - /* Restore standard function for displaying matches */ - rl_completion_display_matches_hook = NULL; - - /* Disable default filename completion */ - rl_attempted_completion_over = 1; - - /* Enable tilde expansion when filenames are completed */ - rl_complete_with_tilde_expansion = 1; - - /* Filter out possible ANSI color escape sequences */ - prompt_tmp = nmc_filter_out_colors ((const char *) rl_prompt); - - /* Find the first non-space character */ - n1 = strspn (line, " \t"); - - /* Choose the right generator function */ - if (strcmp (prompt_tmp, EDITOR_PROMPT_CON_TYPE) == 0) - generator_func = gen_connection_types (text); - else if (strcmp (prompt_tmp, EDITOR_PROMPT_SETTING) == 0) - generator_func = gen_setting_names; - else if (strcmp (prompt_tmp, EDITOR_PROMPT_PROPERTY) == 0) - generator_func = gen_property_names; - else if ( g_str_has_suffix (rl_prompt, prompt_yes_no (TRUE, NULL)) - || g_str_has_suffix (rl_prompt, prompt_yes_no (FALSE, NULL))) - generator_func = gen_func_bool_values_l10n; - else if (g_str_has_prefix (prompt_tmp, "nmcli")) { - if (!strchr (prompt_tmp, '.')) { - int level = g_str_has_prefix (prompt_tmp, "nmcli>") ? 0 : 1; - const char *dot = strchr (line, '.'); - gboolean multi; - - /* Main menu - level 0,1 */ - if (start == n1) - generator_func = gen_nmcli_cmds_menu; - else { - if (should_complete_cmd (line, end, "goto", &num, NULL) && num <= 2) { - if (level == 0 && (!dot || dot >= line + end)) - generator_func = gen_setting_names; - else - generator_func = gen_property_names; - } else if (should_complete_cmd (line, end, "set", &num, NULL)) { - if (num < 3) { - if (level == 0 && (!dot || dot >= line + end)) { - generator_func = gen_setting_names; - rl_completion_append_character = '.'; - } else - generator_func = gen_property_names; - } else { - if (num == 3 && should_complete_files (NULL, line)) - rl_attempted_completion_over = 0; - else if (should_complete_vpn_uuids (NULL, line)) { - rl_completion_display_matches_hook = uuid_display_hook; - generator_func = gen_vpn_uuids; - } else if ( should_complete_property_values (NULL, line, &multi) - && (num == 3 || multi)) { - generator_func = gen_property_values; - } else if (should_complete_boolean (NULL, line) && num == 3) - generator_func = gen_func_bool_values; - } - } else if ( ( should_complete_cmd (line, end, "remove", &num, NULL) - || should_complete_cmd (line, end, "describe", &num, NULL)) - && num <= 2) { - if (level == 0 && (!dot || dot >= line + end)) { - generator_func = gen_setting_names; - rl_completion_append_character = '.'; - } else - generator_func = gen_property_names; - } else if (should_complete_cmd (line, end, "nmcli", &num, &word)) { - if (num < 3) - generator_func = gen_cmd_nmcli; - else if (num == 3) - generator_func = get_gen_func_cmd_nmcli (word); - } else if (should_complete_cmd (line, end, "print", &num, NULL) && num <= 2) { - if (level == 0 && (!dot || dot >= line + end)) - generator_func = gen_cmd_print0; - else - generator_func = gen_property_names; - } else if (should_complete_cmd (line, end, "verify", &num, NULL) && num <= 2) { - generator_func = gen_cmd_verify0; - } else if (should_complete_cmd (line, end, "activate", &num, NULL) && num <= 2) { - generator_func = gen_compat_devices; - } else if (should_complete_cmd (line, end, "save", &num, NULL) && num <= 2) { - generator_func = gen_cmd_save; - } else if (should_complete_cmd (line, end, "help", &num, NULL) && num <= 2) - generator_func = gen_nmcli_cmds_menu; - } - } else { - /* Submenu - level 2 */ - if (start == n1) - generator_func = gen_nmcli_cmds_submenu; - else { - gboolean multi; - - if ( should_complete_cmd (line, end, "add", &num, NULL) - || should_complete_cmd (line, end, "set", &num, NULL)) { - if (num <= 2 && should_complete_files (prompt_tmp, line)) - rl_attempted_completion_over = 0; - else if (should_complete_vpn_uuids (prompt_tmp, line)) { - rl_completion_display_matches_hook = uuid_display_hook; - generator_func = gen_vpn_uuids; - } else if ( should_complete_property_values (prompt_tmp, NULL, &multi) - && (num <= 2 || multi)) { - generator_func = gen_property_values; - } else if (should_complete_boolean (prompt_tmp, NULL) && num <= 2) - generator_func = gen_func_bool_values; - } - if (should_complete_cmd (line, end, "print", &num, NULL) && num <= 2) - generator_func = gen_cmd_print2; - else if (should_complete_cmd (line, end, "help", &num, NULL) && num <= 2) - generator_func = gen_nmcli_cmds_submenu; - } - } - } - - if (generator_func) - match_array = rl_completion_matches (text, generator_func); - - return match_array; +nmcli_editor_tab_completion(const char *text, int start, int end) +{ + rl_compentry_func_t *generator_func = NULL; + const char * line = rl_line_buffer; + gs_free char * prompt_tmp = NULL; + gs_free char * word = NULL; + char ** match_array = NULL; + size_t n1; + int num; + + /* Restore standard append character to space */ + rl_completion_append_character = ' '; + + /* Restore standard function for displaying matches */ + rl_completion_display_matches_hook = NULL; + + /* Disable default filename completion */ + rl_attempted_completion_over = 1; + + /* Enable tilde expansion when filenames are completed */ + rl_complete_with_tilde_expansion = 1; + + /* Filter out possible ANSI color escape sequences */ + prompt_tmp = nmc_filter_out_colors((const char *) rl_prompt); + + /* Find the first non-space character */ + n1 = strspn(line, " \t"); + + /* Choose the right generator function */ + if (strcmp(prompt_tmp, EDITOR_PROMPT_CON_TYPE) == 0) + generator_func = gen_connection_types(text); + else if (strcmp(prompt_tmp, EDITOR_PROMPT_SETTING) == 0) + generator_func = gen_setting_names; + else if (strcmp(prompt_tmp, EDITOR_PROMPT_PROPERTY) == 0) + generator_func = gen_property_names; + else if (g_str_has_suffix(rl_prompt, prompt_yes_no(TRUE, NULL)) + || g_str_has_suffix(rl_prompt, prompt_yes_no(FALSE, NULL))) + generator_func = gen_func_bool_values_l10n; + else if (g_str_has_prefix(prompt_tmp, "nmcli")) { + if (!strchr(prompt_tmp, '.')) { + int level = g_str_has_prefix(prompt_tmp, "nmcli>") ? 0 : 1; + const char *dot = strchr(line, '.'); + gboolean multi; + + /* Main menu - level 0,1 */ + if (start == n1) + generator_func = gen_nmcli_cmds_menu; + else { + if (should_complete_cmd(line, end, "goto", &num, NULL) && num <= 2) { + if (level == 0 && (!dot || dot >= line + end)) + generator_func = gen_setting_names; + else + generator_func = gen_property_names; + } else if (should_complete_cmd(line, end, "set", &num, NULL)) { + if (num < 3) { + if (level == 0 && (!dot || dot >= line + end)) { + generator_func = gen_setting_names; + rl_completion_append_character = '.'; + } else + generator_func = gen_property_names; + } else { + if (num == 3 && should_complete_files(NULL, line)) + rl_attempted_completion_over = 0; + else if (should_complete_vpn_uuids(NULL, line)) { + rl_completion_display_matches_hook = uuid_display_hook; + generator_func = gen_vpn_uuids; + } else if (should_complete_property_values(NULL, line, &multi) + && (num == 3 || multi)) { + generator_func = gen_property_values; + } else if (should_complete_boolean(NULL, line) && num == 3) + generator_func = gen_func_bool_values; + } + } else if ((should_complete_cmd(line, end, "remove", &num, NULL) + || should_complete_cmd(line, end, "describe", &num, NULL)) + && num <= 2) { + if (level == 0 && (!dot || dot >= line + end)) { + generator_func = gen_setting_names; + rl_completion_append_character = '.'; + } else + generator_func = gen_property_names; + } else if (should_complete_cmd(line, end, "nmcli", &num, &word)) { + if (num < 3) + generator_func = gen_cmd_nmcli; + else if (num == 3) + generator_func = get_gen_func_cmd_nmcli(word); + } else if (should_complete_cmd(line, end, "print", &num, NULL) && num <= 2) { + if (level == 0 && (!dot || dot >= line + end)) + generator_func = gen_cmd_print0; + else + generator_func = gen_property_names; + } else if (should_complete_cmd(line, end, "verify", &num, NULL) && num <= 2) { + generator_func = gen_cmd_verify0; + } else if (should_complete_cmd(line, end, "activate", &num, NULL) && num <= 2) { + generator_func = gen_compat_devices; + } else if (should_complete_cmd(line, end, "save", &num, NULL) && num <= 2) { + generator_func = gen_cmd_save; + } else if (should_complete_cmd(line, end, "help", &num, NULL) && num <= 2) + generator_func = gen_nmcli_cmds_menu; + } + } else { + /* Submenu - level 2 */ + if (start == n1) + generator_func = gen_nmcli_cmds_submenu; + else { + gboolean multi; + + if (should_complete_cmd(line, end, "add", &num, NULL) + || should_complete_cmd(line, end, "set", &num, NULL)) { + if (num <= 2 && should_complete_files(prompt_tmp, line)) + rl_attempted_completion_over = 0; + else if (should_complete_vpn_uuids(prompt_tmp, line)) { + rl_completion_display_matches_hook = uuid_display_hook; + generator_func = gen_vpn_uuids; + } else if (should_complete_property_values(prompt_tmp, NULL, &multi) + && (num <= 2 || multi)) { + generator_func = gen_property_values; + } else if (should_complete_boolean(prompt_tmp, NULL) && num <= 2) + generator_func = gen_func_bool_values; + } + if (should_complete_cmd(line, end, "print", &num, NULL) && num <= 2) + generator_func = gen_cmd_print2; + else if (should_complete_cmd(line, end, "help", &num, NULL) && num <= 2) + generator_func = gen_nmcli_cmds_submenu; + } + } + } + + if (generator_func) + match_array = rl_completion_matches(text, generator_func); + + return match_array; } #define NMCLI_EDITOR_HISTORY ".nmcli-history" static void -load_history_cmds (const char *uuid) -{ - GKeyFile *kf; - char *filename; - char **keys; - char *line; - size_t i; - GError *err = NULL; - - filename = g_build_filename (g_get_home_dir (), NMCLI_EDITOR_HISTORY, NULL); - kf = g_key_file_new (); - if (!g_key_file_load_from_file (kf, filename, G_KEY_FILE_KEEP_COMMENTS, &err)) { - if (g_error_matches (err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE)) - g_print ("Warning: %s parse error: %s\n", filename, err->message); - g_key_file_free (kf); - g_free (filename); - return; - } - keys = g_key_file_get_keys (kf, uuid, NULL, NULL); - for (i = 0; keys && keys[i]; i++) { - line = g_key_file_get_string (kf, uuid, keys[i], NULL); - if (line && *line) - add_history (line); - g_free (line); - } - g_strfreev (keys); - g_key_file_free (kf); - g_free (filename); +load_history_cmds(const char *uuid) +{ + GKeyFile *kf; + char * filename; + char ** keys; + char * line; + size_t i; + GError * err = NULL; + + filename = g_build_filename(g_get_home_dir(), NMCLI_EDITOR_HISTORY, NULL); + kf = g_key_file_new(); + if (!g_key_file_load_from_file(kf, filename, G_KEY_FILE_KEEP_COMMENTS, &err)) { + if (g_error_matches(err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE)) + g_print("Warning: %s parse error: %s\n", filename, err->message); + g_key_file_free(kf); + g_free(filename); + return; + } + keys = g_key_file_get_keys(kf, uuid, NULL, NULL); + for (i = 0; keys && keys[i]; i++) { + line = g_key_file_get_string(kf, uuid, keys[i], NULL); + if (line && *line) + add_history(line); + g_free(line); + } + g_strfreev(keys); + g_key_file_free(kf); + g_free(filename); } static void -save_history_cmds (const char *uuid) +save_history_cmds(const char *uuid) { - nm_auto_unref_keyfile GKeyFile *kf = NULL; - gs_free_error GError *error = NULL; - gs_free char *filename = NULL; - gs_free char *data = NULL; - HIST_ENTRY **hist; - gsize len; - gsize i; + nm_auto_unref_keyfile GKeyFile *kf = NULL; + gs_free_error GError *error = NULL; + gs_free char * filename = NULL; + gs_free char * data = NULL; + HIST_ENTRY ** hist; + gsize len; + gsize i; - hist = history_list (); - if (!hist) - return; + hist = history_list(); + if (!hist) + return; - filename = g_build_filename (g_get_home_dir (), NMCLI_EDITOR_HISTORY, NULL); + filename = g_build_filename(g_get_home_dir(), NMCLI_EDITOR_HISTORY, NULL); - kf = g_key_file_new (); + kf = g_key_file_new(); - if (!g_key_file_load_from_file (kf, filename, G_KEY_FILE_KEEP_COMMENTS, &error)) { - if ( !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT) - && !g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND)) { - g_print ("Warning: %s parse error: %s\n", filename, error->message); - return; - } - g_clear_error (&error); - } + if (!g_key_file_load_from_file(kf, filename, G_KEY_FILE_KEEP_COMMENTS, &error)) { + if (!g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOENT) + && !g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND)) { + g_print("Warning: %s parse error: %s\n", filename, error->message); + return; + } + g_clear_error(&error); + } - /* Remove previous history group and save new history entries */ - g_key_file_remove_group (kf, uuid, NULL); - for (i = 0; hist[i]; i++) { - char key[100]; + /* Remove previous history group and save new history entries */ + g_key_file_remove_group(kf, uuid, NULL); + for (i = 0; hist[i]; i++) { + char key[100]; - nm_sprintf_buf (key, "%zd", i); - g_key_file_set_string (kf, uuid, key, hist[i]->line); - } + nm_sprintf_buf(key, "%zd", i); + g_key_file_set_string(kf, uuid, key, hist[i]->line); + } - /* Write history to file */ - data = g_key_file_to_data (kf, &len, NULL); - if (data) - g_file_set_contents (filename, data, len, NULL); + /* Write history to file */ + data = g_key_file_to_data(kf, &len, NULL); + if (data) + g_file_set_contents(filename, data, len, NULL); } /*****************************************************************************/ static void -editor_show_connection (NMConnection *connection, NmCli *nmc) +editor_show_connection(NMConnection *connection, NmCli *nmc) { - nmc->nmc_config_mutable.print_output = NMC_PRINT_PRETTY; - nmc->nmc_config_mutable.multiline_output = TRUE; - nmc->nmc_config_mutable.escape_values = 0; + nmc->nmc_config_mutable.print_output = NMC_PRINT_PRETTY; + nmc->nmc_config_mutable.multiline_output = TRUE; + nmc->nmc_config_mutable.escape_values = 0; - nmc_connection_profile_details (connection, nmc); + nmc_connection_profile_details(connection, nmc); } static void -editor_show_setting (NMSetting *setting, NmCli *nmc) +editor_show_setting(NMSetting *setting, NmCli *nmc) { - g_print (_("['%s' setting values]\n"), - nm_setting_get_name (setting)); + g_print(_("['%s' setting values]\n"), nm_setting_get_name(setting)); - nmc->nmc_config_mutable.print_output = NMC_PRINT_NORMAL; - nmc->nmc_config_mutable.multiline_output = TRUE; - nmc->nmc_config_mutable.escape_values = 0; + nmc->nmc_config_mutable.print_output = NMC_PRINT_NORMAL; + nmc->nmc_config_mutable.multiline_output = TRUE; + nmc->nmc_config_mutable.escape_values = 0; - setting_details (&nmc->nmc_config, setting, NULL); + setting_details(&nmc->nmc_config, setting, NULL); } typedef enum { - NMC_EDITOR_MAIN_CMD_UNKNOWN = 0, - NMC_EDITOR_MAIN_CMD_GOTO, - NMC_EDITOR_MAIN_CMD_REMOVE, - NMC_EDITOR_MAIN_CMD_SET, - NMC_EDITOR_MAIN_CMD_DESCRIBE, - NMC_EDITOR_MAIN_CMD_PRINT, - NMC_EDITOR_MAIN_CMD_VERIFY, - NMC_EDITOR_MAIN_CMD_SAVE, - NMC_EDITOR_MAIN_CMD_ACTIVATE, - NMC_EDITOR_MAIN_CMD_BACK, - NMC_EDITOR_MAIN_CMD_HELP, - NMC_EDITOR_MAIN_CMD_NMCLI, - NMC_EDITOR_MAIN_CMD_QUIT, + NMC_EDITOR_MAIN_CMD_UNKNOWN = 0, + NMC_EDITOR_MAIN_CMD_GOTO, + NMC_EDITOR_MAIN_CMD_REMOVE, + NMC_EDITOR_MAIN_CMD_SET, + NMC_EDITOR_MAIN_CMD_DESCRIBE, + NMC_EDITOR_MAIN_CMD_PRINT, + NMC_EDITOR_MAIN_CMD_VERIFY, + NMC_EDITOR_MAIN_CMD_SAVE, + NMC_EDITOR_MAIN_CMD_ACTIVATE, + NMC_EDITOR_MAIN_CMD_BACK, + NMC_EDITOR_MAIN_CMD_HELP, + NMC_EDITOR_MAIN_CMD_NMCLI, + NMC_EDITOR_MAIN_CMD_QUIT, } NmcEditorMainCmd; static void -_split_cmd (const char *cmd, char **out_arg0, const char **out_argr) +_split_cmd(const char *cmd, char **out_arg0, const char **out_argr) { - gs_free char *arg0 = NULL; - const char *argr = NULL; - gsize l; + gs_free char *arg0 = NULL; + const char * argr = NULL; + gsize l; - NM_SET_OUT (out_arg0, NULL); - NM_SET_OUT (out_argr, NULL); + NM_SET_OUT(out_arg0, NULL); + NM_SET_OUT(out_argr, NULL); - if (!cmd) - return; - while (nm_utils_is_separator (cmd[0])) - cmd++; - if (!cmd[0]) - return; + if (!cmd) + return; + while (nm_utils_is_separator(cmd[0])) + cmd++; + if (!cmd[0]) + return; - l = strcspn (cmd, " \t"); - arg0 = g_strndup (cmd, l); - cmd += l; - if (cmd[0]) { - while (nm_utils_is_separator (cmd[0])) - cmd++; - if (cmd[0]) - argr = cmd; - } + l = strcspn(cmd, " \t"); + arg0 = g_strndup(cmd, l); + cmd += l; + if (cmd[0]) { + while (nm_utils_is_separator(cmd[0])) + cmd++; + if (cmd[0]) + argr = cmd; + } - NM_SET_OUT (out_arg0, g_steal_pointer (&arg0)); - NM_SET_OUT (out_argr, argr); + NM_SET_OUT(out_arg0, g_steal_pointer(&arg0)); + NM_SET_OUT(out_argr, argr); } static NmcEditorMainCmd -parse_editor_main_cmd (const char *cmd, char **cmd_arg) -{ - NmcEditorMainCmd editor_cmd = NMC_EDITOR_MAIN_CMD_UNKNOWN; - gs_free char *cmd_arg0 = NULL; - const char *cmd_argr; - - _split_cmd (cmd, &cmd_arg0, &cmd_argr); - if (!cmd_arg0) - goto fail; - - if (matches (cmd_arg0, "goto")) - editor_cmd = NMC_EDITOR_MAIN_CMD_GOTO; - else if (matches (cmd_arg0, "remove")) - editor_cmd = NMC_EDITOR_MAIN_CMD_REMOVE; - else if (matches (cmd_arg0, "set")) - editor_cmd = NMC_EDITOR_MAIN_CMD_SET; - else if (matches (cmd_arg0, "describe")) - editor_cmd = NMC_EDITOR_MAIN_CMD_DESCRIBE; - else if (matches (cmd_arg0, "print")) - editor_cmd = NMC_EDITOR_MAIN_CMD_PRINT; - else if (matches (cmd_arg0, "verify")) - editor_cmd = NMC_EDITOR_MAIN_CMD_VERIFY; - else if (matches (cmd_arg0, "save")) - editor_cmd = NMC_EDITOR_MAIN_CMD_SAVE; - else if (matches (cmd_arg0, "activate")) - editor_cmd = NMC_EDITOR_MAIN_CMD_ACTIVATE; - else if (matches (cmd_arg0, "back")) - editor_cmd = NMC_EDITOR_MAIN_CMD_BACK; - else if (matches (cmd_arg0, "help") || strcmp (cmd_arg0, "?") == 0) - editor_cmd = NMC_EDITOR_MAIN_CMD_HELP; - else if (matches (cmd_arg0, "quit")) - editor_cmd = NMC_EDITOR_MAIN_CMD_QUIT; - else if (matches (cmd_arg0, "nmcli")) - editor_cmd = NMC_EDITOR_MAIN_CMD_NMCLI; - else - goto fail; - - NM_SET_OUT (cmd_arg, g_strdup (cmd_argr)); - return editor_cmd; +parse_editor_main_cmd(const char *cmd, char **cmd_arg) +{ + NmcEditorMainCmd editor_cmd = NMC_EDITOR_MAIN_CMD_UNKNOWN; + gs_free char * cmd_arg0 = NULL; + const char * cmd_argr; + + _split_cmd(cmd, &cmd_arg0, &cmd_argr); + if (!cmd_arg0) + goto fail; + + if (matches(cmd_arg0, "goto")) + editor_cmd = NMC_EDITOR_MAIN_CMD_GOTO; + else if (matches(cmd_arg0, "remove")) + editor_cmd = NMC_EDITOR_MAIN_CMD_REMOVE; + else if (matches(cmd_arg0, "set")) + editor_cmd = NMC_EDITOR_MAIN_CMD_SET; + else if (matches(cmd_arg0, "describe")) + editor_cmd = NMC_EDITOR_MAIN_CMD_DESCRIBE; + else if (matches(cmd_arg0, "print")) + editor_cmd = NMC_EDITOR_MAIN_CMD_PRINT; + else if (matches(cmd_arg0, "verify")) + editor_cmd = NMC_EDITOR_MAIN_CMD_VERIFY; + else if (matches(cmd_arg0, "save")) + editor_cmd = NMC_EDITOR_MAIN_CMD_SAVE; + else if (matches(cmd_arg0, "activate")) + editor_cmd = NMC_EDITOR_MAIN_CMD_ACTIVATE; + else if (matches(cmd_arg0, "back")) + editor_cmd = NMC_EDITOR_MAIN_CMD_BACK; + else if (matches(cmd_arg0, "help") || strcmp(cmd_arg0, "?") == 0) + editor_cmd = NMC_EDITOR_MAIN_CMD_HELP; + else if (matches(cmd_arg0, "quit")) + editor_cmd = NMC_EDITOR_MAIN_CMD_QUIT; + else if (matches(cmd_arg0, "nmcli")) + editor_cmd = NMC_EDITOR_MAIN_CMD_NMCLI; + else + goto fail; + + NM_SET_OUT(cmd_arg, g_strdup(cmd_argr)); + return editor_cmd; fail: - NM_SET_OUT (cmd_arg, NULL); - return NMC_EDITOR_MAIN_CMD_UNKNOWN; + NM_SET_OUT(cmd_arg, NULL); + return NMC_EDITOR_MAIN_CMD_UNKNOWN; } static void -editor_main_usage (void) -{ - g_print ("------------------------------------------------------------------------------\n"); - /* TRANSLATORS: do not translate command names and keywords before :: - * However, you should translate terms enclosed in <>. - */ - g_print (_("---[ Main menu ]---\n" - "goto [ | ] :: go to a setting or property\n" - "remove [.] | :: remove setting or reset property value\n" - "set [. ] :: set property value\n" - "describe [.] :: describe property\n" - "print [all | [.]] :: print the connection\n" - "verify [all | fix] :: verify the connection\n" - "save [persistent|temporary] :: save the connection\n" - "activate [] [/|] :: activate the connection\n" - "back :: go one level up (back)\n" - "help/? [] :: print this help\n" - "nmcli :: nmcli configuration\n" - "quit :: exit nmcli\n")); - g_print ("------------------------------------------------------------------------------\n"); +editor_main_usage(void) +{ + g_print("------------------------------------------------------------------------------\n"); + /* TRANSLATORS: do not translate command names and keywords before :: + * However, you should translate terms enclosed in <>. + */ + g_print(_("---[ Main menu ]---\n" + "goto [ | ] :: go to a setting or property\n" + "remove [.] | :: remove setting or reset property value\n" + "set [. ] :: set property value\n" + "describe [.] :: describe property\n" + "print [all | [.]] :: print the connection\n" + "verify [all | fix] :: verify the connection\n" + "save [persistent|temporary] :: save the connection\n" + "activate [] [/|] :: activate the connection\n" + "back :: go one level up (back)\n" + "help/? [] :: print this help\n" + "nmcli :: nmcli configuration\n" + "quit :: exit nmcli\n")); + g_print("------------------------------------------------------------------------------\n"); } static void -editor_main_help (const char *command) -{ - if (!command) - editor_main_usage (); - else { - /* detailed command descriptions */ - NmcEditorMainCmd cmd = parse_editor_main_cmd (command, NULL); - - switch (cmd) { - case NMC_EDITOR_MAIN_CMD_GOTO: - g_print (_("goto [.] | :: enter setting/property for editing\n\n" - "This command enters into a setting or property for editing it.\n\n" - "Examples: nmcli> goto connection\n" - " nmcli connection> goto secondaries\n" - " nmcli> goto ipv4.addresses\n")); - break; - case NMC_EDITOR_MAIN_CMD_REMOVE: - g_print (_("remove [.] :: remove setting or reset property value\n\n" - "This command removes an entire setting from the connection, or if a property\n" - "is given, resets that property to the default value.\n\n" - "Examples: nmcli> remove wifi-sec\n" - " nmcli> remove eth.mtu\n")); - break; - case NMC_EDITOR_MAIN_CMD_SET: - g_print (_("set [. ] :: set property value\n\n" - "This command sets property value.\n\n" - "Example: nmcli> set con.id My connection\n")); - break; - case NMC_EDITOR_MAIN_CMD_DESCRIBE: - g_print (_("describe [.] :: describe property\n\n" - "Shows property description. You can consult nm-settings(5) " - "manual page to see all NM settings and properties.\n")); - break; - case NMC_EDITOR_MAIN_CMD_PRINT: - g_print (_("print [all] :: print setting or connection values\n\n" - "Shows current property or the whole connection.\n\n" - "Example: nmcli ipv4> print all\n")); - break; - case NMC_EDITOR_MAIN_CMD_VERIFY: - g_print (_("verify [all | fix] :: verify setting or connection validity\n\n" - "Verifies whether the setting or connection is valid and can be saved later.\n" - "It indicates invalid values on error. Some errors may be fixed automatically\n" - "by 'fix' option.\n\n" - "Examples: nmcli> verify\n" - " nmcli> verify fix\n" - " nmcli bond> verify\n")); - break; - case NMC_EDITOR_MAIN_CMD_SAVE: - g_print (_("save [persistent|temporary] :: save the connection\n\n" - "Sends the connection profile to NetworkManager that either will save it\n" - "persistently, or will only keep it in memory. 'save' without an argument\n" - "means 'save persistent'.\n" - "Note that once you save the profile persistently those settings are saved\n" - "across reboot or restart. Subsequent changes can also be temporary or\n" - "persistent, but any temporary changes will not persist across reboot or\n" - "restart. If you want to fully remove the persistent connection, the connection\n" - "profile must be deleted.\n")); - break; - case NMC_EDITOR_MAIN_CMD_ACTIVATE: - g_print (_("activate [] [/|] :: activate the connection\n\n" - "Activates the connection.\n\n" - "Available options:\n" - " - device the connection will be activated on\n" - "/| - AP (Wi-Fi) or NSP (WiMAX) (prepend with / when is not specified)\n")); - break; - case NMC_EDITOR_MAIN_CMD_BACK: - g_print (_("back :: go to upper menu level\n\n")); - break; - case NMC_EDITOR_MAIN_CMD_HELP: - g_print (_("help/? [] :: help for the nmcli commands\n\n")); - break; - case NMC_EDITOR_MAIN_CMD_NMCLI: - g_print (_("nmcli [ ] :: nmcli configuration\n\n" - "Configures nmcli. The following options are available:\n" - "status-line yes | no [default: no]\n" - "save-confirmation yes | no [default: yes]\n" - "show-secrets yes | no [default: no]\n" - "prompt-color | <0-8> [default: 0]\n" - "%s" /* color table description */ - "\n" - "Examples: nmcli> nmcli status-line yes\n" - " nmcli> nmcli save-confirmation no\n" - " nmcli> nmcli prompt-color 3\n"), - " 0 = normal\n" - " 1 = \33[30mblack\33[0m\n" - " 2 = \33[31mred\33[0m\n" - " 3 = \33[32mgreen\33[0m\n" - " 4 = \33[33myellow\33[0m\n" - " 5 = \33[34mblue\33[0m\n" - " 6 = \33[35mmagenta\33[0m\n" - " 7 = \33[36mcyan\33[0m\n" - " 8 = \33[37mwhite\33[0m\n"); - break; - case NMC_EDITOR_MAIN_CMD_QUIT: - g_print (_("quit :: exit nmcli\n\n" - "This command exits nmcli. When the connection being edited " - "is not saved, the user is asked to confirm the action.\n")); - break; - default: - g_print (_("Unknown command: '%s'\n"), command); - break; - } - } +editor_main_help(const char *command) +{ + if (!command) + editor_main_usage(); + else { + /* detailed command descriptions */ + NmcEditorMainCmd cmd = parse_editor_main_cmd(command, NULL); + + switch (cmd) { + case NMC_EDITOR_MAIN_CMD_GOTO: + g_print(_("goto [.] | :: enter setting/property for editing\n\n" + "This command enters into a setting or property for editing it.\n\n" + "Examples: nmcli> goto connection\n" + " nmcli connection> goto secondaries\n" + " nmcli> goto ipv4.addresses\n")); + break; + case NMC_EDITOR_MAIN_CMD_REMOVE: + g_print( + _("remove [.] :: remove setting or reset property value\n\n" + "This command removes an entire setting from the connection, or if a property\n" + "is given, resets that property to the default value.\n\n" + "Examples: nmcli> remove wifi-sec\n" + " nmcli> remove eth.mtu\n")); + break; + case NMC_EDITOR_MAIN_CMD_SET: + g_print(_("set [. ] :: set property value\n\n" + "This command sets property value.\n\n" + "Example: nmcli> set con.id My connection\n")); + break; + case NMC_EDITOR_MAIN_CMD_DESCRIBE: + g_print(_("describe [.] :: describe property\n\n" + "Shows property description. You can consult nm-settings(5) " + "manual page to see all NM settings and properties.\n")); + break; + case NMC_EDITOR_MAIN_CMD_PRINT: + g_print(_("print [all] :: print setting or connection values\n\n" + "Shows current property or the whole connection.\n\n" + "Example: nmcli ipv4> print all\n")); + break; + case NMC_EDITOR_MAIN_CMD_VERIFY: + g_print( + _("verify [all | fix] :: verify setting or connection validity\n\n" + "Verifies whether the setting or connection is valid and can be saved later.\n" + "It indicates invalid values on error. Some errors may be fixed automatically\n" + "by 'fix' option.\n\n" + "Examples: nmcli> verify\n" + " nmcli> verify fix\n" + " nmcli bond> verify\n")); + break; + case NMC_EDITOR_MAIN_CMD_SAVE: + g_print( + _("save [persistent|temporary] :: save the connection\n\n" + "Sends the connection profile to NetworkManager that either will save it\n" + "persistently, or will only keep it in memory. 'save' without an argument\n" + "means 'save persistent'.\n" + "Note that once you save the profile persistently those settings are saved\n" + "across reboot or restart. Subsequent changes can also be temporary or\n" + "persistent, but any temporary changes will not persist across reboot or\n" + "restart. If you want to fully remove the persistent connection, the connection\n" + "profile must be deleted.\n")); + break; + case NMC_EDITOR_MAIN_CMD_ACTIVATE: + g_print(_("activate [] [/|] :: activate the connection\n\n" + "Activates the connection.\n\n" + "Available options:\n" + " - device the connection will be activated on\n" + "/| - AP (Wi-Fi) or NSP (WiMAX) (prepend with / when is " + "not specified)\n")); + break; + case NMC_EDITOR_MAIN_CMD_BACK: + g_print(_("back :: go to upper menu level\n\n")); + break; + case NMC_EDITOR_MAIN_CMD_HELP: + g_print(_("help/? [] :: help for the nmcli commands\n\n")); + break; + case NMC_EDITOR_MAIN_CMD_NMCLI: + g_print(_("nmcli [ ] :: nmcli configuration\n\n" + "Configures nmcli. The following options are available:\n" + "status-line yes | no [default: no]\n" + "save-confirmation yes | no [default: yes]\n" + "show-secrets yes | no [default: no]\n" + "prompt-color | <0-8> [default: 0]\n" + "%s" /* color table description */ + "\n" + "Examples: nmcli> nmcli status-line yes\n" + " nmcli> nmcli save-confirmation no\n" + " nmcli> nmcli prompt-color 3\n"), + " 0 = normal\n" + " 1 = \33[30mblack\33[0m\n" + " 2 = \33[31mred\33[0m\n" + " 3 = \33[32mgreen\33[0m\n" + " 4 = \33[33myellow\33[0m\n" + " 5 = \33[34mblue\33[0m\n" + " 6 = \33[35mmagenta\33[0m\n" + " 7 = \33[36mcyan\33[0m\n" + " 8 = \33[37mwhite\33[0m\n"); + break; + case NMC_EDITOR_MAIN_CMD_QUIT: + g_print(_("quit :: exit nmcli\n\n" + "This command exits nmcli. When the connection being edited " + "is not saved, the user is asked to confirm the action.\n")); + break; + default: + g_print(_("Unknown command: '%s'\n"), command); + break; + } + } } typedef enum { - NMC_EDITOR_SUB_CMD_UNKNOWN = 0, - NMC_EDITOR_SUB_CMD_SET, - NMC_EDITOR_SUB_CMD_ADD, - NMC_EDITOR_SUB_CMD_CHANGE, - NMC_EDITOR_SUB_CMD_REMOVE, - NMC_EDITOR_SUB_CMD_DESCRIBE, - NMC_EDITOR_SUB_CMD_PRINT, - NMC_EDITOR_SUB_CMD_BACK, - NMC_EDITOR_SUB_CMD_HELP, - NMC_EDITOR_SUB_CMD_QUIT + NMC_EDITOR_SUB_CMD_UNKNOWN = 0, + NMC_EDITOR_SUB_CMD_SET, + NMC_EDITOR_SUB_CMD_ADD, + NMC_EDITOR_SUB_CMD_CHANGE, + NMC_EDITOR_SUB_CMD_REMOVE, + NMC_EDITOR_SUB_CMD_DESCRIBE, + NMC_EDITOR_SUB_CMD_PRINT, + NMC_EDITOR_SUB_CMD_BACK, + NMC_EDITOR_SUB_CMD_HELP, + NMC_EDITOR_SUB_CMD_QUIT } NmcEditorSubCmd; static NmcEditorSubCmd -parse_editor_sub_cmd (const char *cmd, char **cmd_arg) -{ - NmcEditorSubCmd editor_cmd = NMC_EDITOR_SUB_CMD_UNKNOWN; - gs_free char *cmd_arg0 = NULL; - const char *cmd_argr; - - _split_cmd (cmd, &cmd_arg0, &cmd_argr); - if (!cmd_arg0) - goto fail; - - if (matches (cmd_arg0, "set")) - editor_cmd = NMC_EDITOR_SUB_CMD_SET; - else if (matches (cmd_arg0, "add")) - editor_cmd = NMC_EDITOR_SUB_CMD_ADD; - else if (matches (cmd_arg0, "change")) - editor_cmd = NMC_EDITOR_SUB_CMD_CHANGE; - else if (matches (cmd_arg0, "remove")) - editor_cmd = NMC_EDITOR_SUB_CMD_REMOVE; - else if (matches (cmd_arg0, "describe")) - editor_cmd = NMC_EDITOR_SUB_CMD_DESCRIBE; - else if (matches (cmd_arg0, "print")) - editor_cmd = NMC_EDITOR_SUB_CMD_PRINT; - else if (matches (cmd_arg0, "back")) - editor_cmd = NMC_EDITOR_SUB_CMD_BACK; - else if (matches (cmd_arg0, "help") || strcmp (cmd_arg0, "?") == 0) - editor_cmd = NMC_EDITOR_SUB_CMD_HELP; - else if (matches (cmd_arg0, "quit")) - editor_cmd = NMC_EDITOR_SUB_CMD_QUIT; - else - goto fail; - - NM_SET_OUT (cmd_arg, g_strdup (cmd_argr)); - return editor_cmd; +parse_editor_sub_cmd(const char *cmd, char **cmd_arg) +{ + NmcEditorSubCmd editor_cmd = NMC_EDITOR_SUB_CMD_UNKNOWN; + gs_free char * cmd_arg0 = NULL; + const char * cmd_argr; + + _split_cmd(cmd, &cmd_arg0, &cmd_argr); + if (!cmd_arg0) + goto fail; + + if (matches(cmd_arg0, "set")) + editor_cmd = NMC_EDITOR_SUB_CMD_SET; + else if (matches(cmd_arg0, "add")) + editor_cmd = NMC_EDITOR_SUB_CMD_ADD; + else if (matches(cmd_arg0, "change")) + editor_cmd = NMC_EDITOR_SUB_CMD_CHANGE; + else if (matches(cmd_arg0, "remove")) + editor_cmd = NMC_EDITOR_SUB_CMD_REMOVE; + else if (matches(cmd_arg0, "describe")) + editor_cmd = NMC_EDITOR_SUB_CMD_DESCRIBE; + else if (matches(cmd_arg0, "print")) + editor_cmd = NMC_EDITOR_SUB_CMD_PRINT; + else if (matches(cmd_arg0, "back")) + editor_cmd = NMC_EDITOR_SUB_CMD_BACK; + else if (matches(cmd_arg0, "help") || strcmp(cmd_arg0, "?") == 0) + editor_cmd = NMC_EDITOR_SUB_CMD_HELP; + else if (matches(cmd_arg0, "quit")) + editor_cmd = NMC_EDITOR_SUB_CMD_QUIT; + else + goto fail; + + NM_SET_OUT(cmd_arg, g_strdup(cmd_argr)); + return editor_cmd; fail: - NM_SET_OUT (cmd_arg, NULL); - return NMC_EDITOR_SUB_CMD_UNKNOWN; + NM_SET_OUT(cmd_arg, NULL); + return NMC_EDITOR_SUB_CMD_UNKNOWN; } static void -editor_sub_help (void) -{ - g_print ("------------------------------------------------------------------------------\n"); - /* TRANSLATORS: do not translate command names and keywords before :: - * However, you should translate terms enclosed in <>. - */ - g_print (_("---[ Property menu ]---\n" - "set [] :: set new value\n" - "add [] :: add new option to the property\n" - "change :: change current value\n" - "remove [ |