Commit graph

17362 commits

Author SHA1 Message Date
Thomas Haller d9462879ac build: build intermediate library libnmc.la for nmcli
Used for unit testing in the next commit.

Also add libnmc-base.la, which contains common files for nmcli and
nmtui.
2017-04-05 16:53:06 +02:00
Thomas Haller 137273669d cli: add nmc_output_selection_create() to parse field selection
nmc_output_selection_create() returns a less opaque result then
a GArray and a GPtrArray for the groups.
2017-04-05 16:53:06 +02:00
Thomas Haller bfb9fd0d2f cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.

However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.

Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.

Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-04-05 16:53:06 +02:00
Thomas Haller 6a489199b9 cli: make setting meta data more generic
Embed a @meta_type structure in NMMetaSettingInfoEditor and
NMMetaPropertyInfo. This allows to make the NMMeta*Info instances
themself to become generic and they can be passed around as generic
NMMetaAbstractInfo types.
For one, the embedded NMMetaType pointer can be used to determine
of which type a NMMetaAbstractInfo instance is. On the other hand,
the NMMetaType struct can be extended to be a VTable to provide
generic access to the type.
In the end, both NMMetaSettingInfoEditor and NMMetaPropertyInfo are
conceptionally very similar: the describe a certain type and provide
accessors.

In nmcli we have yet another NMMetaAbstractInfo type: NmcOutputField
will be modified to become another implementation of meta data (it
already is, it just cannot be used interchangable with the other
types).

Also, embed the NMMetaSettingInfoEditor in the NMMetaPropertyInfo
instance. This allows from a given NMMetaPropertyInfo to retrieve it's
parent NMMetaSettingInfoEditor.
2017-04-05 16:53:06 +02:00
Thomas Haller db300afba1 cli: split out new file "nm-meta-setting-access.h"
"nm-meta-setting-desc.h" contains static type description, vtable and (internal)
accessor functions. Add accessor functions that operate on top of the type description
to "nm-meta-setting-access.h".
2017-04-05 16:53:06 +02:00
Thomas Haller aae721d0df cli: pass arguments for print_data separately of NmcOutputData
Don't pass on large structs of input arguments. It only convolutes
which arguments are passed, and where they come from.
2017-04-05 16:53:06 +02:00
Thomas Haller f973f0841a cli: merge NmcPrintFields into NmcOutputData and pass it directly to print_required_fields() 2017-04-05 16:53:06 +02:00
Thomas Haller ea700eec84 cli: tighter scope NmcOutputData in do_device_wifi_list()
The scope of "out" can be reduced.
2017-04-05 16:53:06 +02:00
Thomas Haller f12106d83a cli: use enum NmcOfFlags instead of plain integer flags and pass to print_required_fields() 2017-04-05 16:53:06 +02:00
Thomas Haller cecee19b2b cli: move pre-check for setting connection:secondaries out of nm-meta-setting-desc.c
This check requires additional information about the environment, that
is about the present connections in NMClient.

"nm-meta-setting-desc.c" should be independent from the libnm D-Bus
cache, hence move this code to "settings.c".
2017-04-05 16:53:06 +02:00
Thomas Haller 2379af7e36 cli: notify warning via NMMetaEnvironment instead of printing directly from "nm-meta-setting-desc.h"
The lower layers are concerned with handling settings. They should not
be aware of how to notify about warnings. Instead, signal them via
the warn_fcn() hook.
2017-04-05 16:53:06 +02:00
Thomas Haller d1c6d64e6a shared: move _nm_utils_strv_cleanup() to shared utils 2017-04-05 16:53:06 +02:00
Thomas Haller 17f9191656 cli: don't register tranform-functions for GValues when setting GObject property
For G_TYPE_BOOLEAN, let it get handled by the getter hook instead
of modifying system-wide behavior of glib.

Also, there are no properties of G_TYPE_CHAR. Just drop that.
2017-04-05 16:53:05 +02:00
Jonas Jonsson fdf967592b dhcp: dhclient: remove fqdn.encoded for dhclient -6 conf
The option fqdn.encoded doesn't exist in DHCPv6, it's a DHCPv4 flag
only.
2017-04-05 16:21:51 +02:00
Francesco Giudici d68f84073b nmcli: merge branch 'fg/nmcli_options' 2017-04-05 15:55:55 +02:00
Francesco Giudici 512ed904c6 nmcli: fix 'nmcli con export' parameters check
get_connection() will already move forward arguments (argc/argv):
remove extra argv++/argc--

Example:
"nmcli con export <vpn_con> <output_file> <extra_arg>"
now, extra_arg is detected, printing error:
"Error: unknown extra argument: 'extra_arg'."
2017-04-05 15:55:04 +02:00
Francesco Giudici 6a3d77fbe6 nmcli: allow cmd specific option parsing in next_arg() func
Options dependant on specific commands (e.g., nmcli connection show
--active) are now allowed to be processed by the next_arg() function.
This would allow autocompletion to expand options belonging to specific
command first, and then global ones.

Note that global options ("--ask" and "--show-secrets") will be auto-completed
everywhere but only if at least a '-' is passed. Command specific ones
(--temporary, --active, --order) will be auto-completed only after the command
they belongs to but without requiring the user to pass a heading '-'.

Example:
'nmcli connection show -a'
will expand '-a' into '--active', but
'nmcli connection add -a`
will expand '-a' into '--ask' (as it is a global option)

This commit fixes also autocompletion for:
nmcli connection modify --temporary
2017-04-05 15:43:40 +02:00
Thomas Haller c6c8ea2fdf cli: make static arrays in nm_vpn_get_secret_names() const 2017-04-05 14:18:55 +02:00
Thomas Haller 29dbc21c30 cli: fix leak in add_vpn_secrets()
No need to copy @tmp variable, it was leaked.
2017-04-05 14:18:55 +02:00
Francesco Giudici 3d4d1bedda nmcli: avoid calling twice "check_activated()" on "nmcli connection up"
This happens when the connection is in "activating" state and
the connection is a master one waiting for slaves: "check_activated()"
is called by the active_connection_state_cb() and device_state_cb() callbacks.

If the device has already moved to a state >= NM_DEVICE_STATE_IP_CONFIG, the
call to active_connection_state_cb() will end calling
activate_connection_info_finish(), freeing the "info" object. The subsequent
call to device_state_cb() will result in accessing the freed "info".

Just call check_activated() once after registering the
active_connection_state() and device_state_cb() callbacks.
2017-04-05 11:30:52 +02:00
Thomas Haller 95e7914e67 systemd: merge branch systemd into master 2017-04-04 12:20:51 +02:00
Thomas Haller ae172c89a6 systemd: update code from upstream (2017-04-04)
This is a direct dump from systemd git on 2017-04-04, git commit
91dacd4451309e1f4b06fb2628447ddc8425d972.

======

SYSTEMD_DIR=../systemd
COMMIT=91dacd4451309e1f4b06fb2628447ddc8425d972

(
  cd "$SYSTEMD_DIR"
  git checkout "$COMMIT"
  git reset --hard
  git clean -fdx
)

git ls-files :/src/systemd/src/ | xargs -d '\n' rm -f

nm_copy_sd() {
    mkdir -p "./src/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./src/systemd/$1"
}

nm_copy_sd "src/basic/alloc-util.c"
nm_copy_sd "src/basic/alloc-util.h"
nm_copy_sd "src/basic/async.h"
nm_copy_sd "src/basic/escape.c"
nm_copy_sd "src/basic/escape.h"
nm_copy_sd "src/basic/ether-addr-util.c"
nm_copy_sd "src/basic/ether-addr-util.h"
nm_copy_sd "src/basic/extract-word.c"
nm_copy_sd "src/basic/extract-word.h"
nm_copy_sd "src/basic/fileio.c"
nm_copy_sd "src/basic/fileio.h"
nm_copy_sd "src/basic/fd-util.c"
nm_copy_sd "src/basic/fd-util.h"
nm_copy_sd "src/basic/fs-util.c"
nm_copy_sd "src/basic/fs-util.h"
nm_copy_sd "src/basic/hash-funcs.c"
nm_copy_sd "src/basic/hash-funcs.h"
nm_copy_sd "src/basic/hashmap.c"
nm_copy_sd "src/basic/hashmap.h"
nm_copy_sd "src/basic/hexdecoct.c"
nm_copy_sd "src/basic/hexdecoct.h"
nm_copy_sd "src/basic/hostname-util.c"
nm_copy_sd "src/basic/hostname-util.h"
nm_copy_sd "src/basic/in-addr-util.c"
nm_copy_sd "src/basic/in-addr-util.h"
nm_copy_sd "src/basic/io-util.c"
nm_copy_sd "src/basic/io-util.h"
nm_copy_sd "src/basic/list.h"
nm_copy_sd "src/basic/log.h"
nm_copy_sd "src/basic/macro.h"
nm_copy_sd "src/basic/mempool.h"
nm_copy_sd "src/basic/mempool.c"
nm_copy_sd "src/basic/parse-util.c"
nm_copy_sd "src/basic/parse-util.h"
nm_copy_sd "src/basic/path-util.c"
nm_copy_sd "src/basic/path-util.h"
nm_copy_sd "src/basic/prioq.h"
nm_copy_sd "src/basic/prioq.c"
nm_copy_sd "src/basic/random-util.c"
nm_copy_sd "src/basic/random-util.h"
nm_copy_sd "src/basic/refcnt.h"
nm_copy_sd "src/basic/set.h"
nm_copy_sd "src/basic/signal-util.h"
nm_copy_sd "src/basic/siphash24.c"
nm_copy_sd "src/basic/siphash24.h"
nm_copy_sd "src/basic/socket-util.c"
nm_copy_sd "src/basic/socket-util.h"
nm_copy_sd "src/basic/sparse-endian.h"
nm_copy_sd "src/basic/stdio-util.h"
nm_copy_sd "src/basic/string-table.c"
nm_copy_sd "src/basic/string-table.h"
nm_copy_sd "src/basic/string-util.c"
nm_copy_sd "src/basic/string-util.h"
nm_copy_sd "src/basic/strv.c"
nm_copy_sd "src/basic/strv.h"
nm_copy_sd "src/basic/time-util.c"
nm_copy_sd "src/basic/time-util.h"
nm_copy_sd "src/basic/umask-util.h"
nm_copy_sd "src/basic/unaligned.h"
nm_copy_sd "src/basic/utf8.c"
nm_copy_sd "src/basic/utf8.h"
nm_copy_sd "src/basic/util.c"
nm_copy_sd "src/basic/util.h"
nm_copy_sd "src/libsystemd-network/arp-util.c"
nm_copy_sd "src/libsystemd-network/arp-util.h"
nm_copy_sd "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd "src/libsystemd-network/dhcp-network.c"
nm_copy_sd "src/libsystemd-network/dhcp-option.c"
nm_copy_sd "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd "src/libsystemd-network/lldp-internal.h"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd "src/libsystemd-network/lldp-network.c"
nm_copy_sd "src/libsystemd-network/lldp-network.h"
nm_copy_sd "src/libsystemd-network/network-internal.c"
nm_copy_sd "src/libsystemd-network/network-internal.h"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd "src/libsystemd-network/sd-lldp.c"
nm_copy_sd "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd "src/shared/dns-domain.c"
nm_copy_sd "src/shared/dns-domain.h"
nm_copy_sd "src/systemd/_sd-common.h"
nm_copy_sd "src/systemd/sd-dhcp6-client.h"
nm_copy_sd "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd "src/systemd/sd-dhcp-client.h"
nm_copy_sd "src/systemd/sd-dhcp-lease.h"
nm_copy_sd "src/systemd/sd-event.h"
nm_copy_sd "src/systemd/sd-ndisc.h"
nm_copy_sd "src/systemd/sd-id128.h"
nm_copy_sd "src/systemd/sd-ipv4acd.h"
nm_copy_sd "src/systemd/sd-ipv4ll.h"
nm_copy_sd "src/systemd/sd-lldp.h"
2017-04-04 12:19:34 +02:00
Lubomir Rintel 2839da06db settings/secret-agent: add initializers
To make coverity a bit happier.
2017-04-03 13:28:26 +02:00
Beniamino Galvani db07b867a6 cli: restore previous name of IN-USE AP property
Before commit a63c4d0824 ("cli: use designated initializers for
setting NmcOutputField fields") each field had a @name and a
@name_l10n , which were equal for all properties except for wifi
IN-USE:

 {"IN-USE",     N_("*")},          /* 15 */

The commit removed @name_l10n so now the displayed name is equal to
the field name. But now:

 $ nmcli device wifi list
 Error: 'device wifi': invalid field 'IN-USE'; allowed fields:
 NAME,SSID,SSID-HEX,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY,
 WPA-FLAGS,RSN-FLAGS,DEVICE,ACTIVE,*,DBUS-PATH

The new field name should be 'IN-USE' and not '*', otherwise scripts
doing "-f IN-USE" will break. As a side effect we now show 'IN-USE'
instead of '*' in the column header, which seems easier to understand:

IN-USE  SSID     MODE   CHAN  RATE       SIGNAL  BARS  SECURITY
*       default  Infra  5     54 Mbit/s  71      ▂▄▆_  WPA2
        guest    Infra  1     54 Mbit/s  62      ▂▄▆_  WPA2

Fixes: a63c4d0824
2017-04-01 21:33:11 +02:00
Beniamino Galvani 3fe144f934 device: emit IP_CONFIG_CHANGED signal when default route changes
We now update the default route metric based on the result of the
connectivity check. When we update the metric and there is no other
changes to the IP configuration, NMPolicy is not notified about it and
can't update the best device until an actual change in IP config
happens. This results in a wrong best device set in NMPolicy.

NMDevice has NM_DEVICE_IP[4,6]_CONFIG_CHANGED signals that are used
exclusively by NMPolicy to detect when there is a change in
configuration that requires an update of global DNS and routing
information. Emit those signals also when the default route changes.
2017-04-01 15:49:16 +02:00
Beniamino Galvani 74f7eff11b default-route-manager: return whether the default route changed 2017-04-01 15:49:16 +02:00
Beniamino Galvani 6eb6b23b28 cli: fix setting of 802-1x.eap property
Fixes: 6bf1d6fc16
2017-03-30 18:34:14 +02:00
Thomas Haller b044b306d2 gitignore: fix ignoring "clients/common/settings-docs.c" (2)
Fixes: d720f0955f
2017-03-30 18:07:35 +02:00
Thomas Haller d2af54f9bb build: fix out-of-tree build after moving generated settings-docs.c
Fixes: d720f0955f
2017-03-30 17:52:05 +02:00
Thomas Haller 1b2da4b5f3 gitignore: fix ignoring "clients/common/settings-docs.c"
Fixes: d720f0955f
2017-03-30 17:29:21 +02:00
Thomas Haller d720f0955f cli: embed gtk-doc directly in property-info structure
Also mark them for translation.
2017-03-30 16:35:52 +02:00
Thomas Haller 9033d084ab cli: merge branch 'th/cli-setting-metadata-bgo732292'
A larger refactoring of nmcli.

Splits out (a bit) the tracking of settings meta data. As such,
it goes towards what is proposed by bgo#732292.

Then, get rid (a bit) of the global data that is passed around.
2017-03-30 14:57:54 +02:00
Thomas Haller 29bcfc2522 cli: don't track output data in global NmCli structure
We should not violate the global data to track the output data
while it is constructed and printed.

Most of the time, we actually clear the output data anyway --
either before constructing it, or after printing it.
In some cases we didn't, but I think that is a bug. It's really
hard to keep track of this.

The output data should belong to a certain scope and get destroyed
afterwards. Passing it around is very confusing. Don't do that.
2017-03-30 14:56:21 +02:00
Thomas Haller 85acdd70e7 cli: split print_data() in a part with and without side-effects
To better understand which part of the code have side effects,
split print_data() in a part that mutilates the input array
and a part that only prints.
2017-03-30 13:46:09 +02:00
Thomas Haller 2ea670ab96 cli: split output data from NmCli to a separate field 2017-03-30 13:34:35 +02:00
Thomas Haller d0ce5fc550 cli: cleanup get_value_to_print() util
Don't cast const strings to non-const. And don't track
whether to free a variable in a boolean. Instead, assign
ownership to variables that get destroyed when the function
returns.
2017-03-30 13:24:55 +02:00
Thomas Haller 98ce4a8d5d cli: separate input and in-out arguments in print_data()
Don't pass down the entire NmCli instance. The output_data
array is modified by print_data(), the rest is read-only input.
2017-03-30 13:09:59 +02:00
Thomas Haller e847d0f121 cli: pass configuration options separately from NmCli structure
The NmCli structure is passed around everywhere and contains all
the state of the program. It is very hard to follow which parts
are used where.

Split out more configuration options to a NmcConfig field. This field
is mostly immutable, and modified at particular places that now can be
easily found.
2017-03-30 13:09:59 +02:00
Thomas Haller 9359d5622e cli: pass use_colors as separate option instead of global nmc
nmc contains all options and collects output data. It is very hard to
understand what it does. Start splitting it up, and pass arguments along
-- as needed.
2017-03-30 13:09:59 +02:00
Thomas Haller a63c4d0824 cli: use designated initializers for setting NmcOutputField fields
Otherwise, changing the structure is difficult because it all depends
on the order (and you don't immdiately see which field is used where).

Also, drop the name_l10n field.
2017-03-30 13:09:58 +02:00
Thomas Haller f5a0b62765 cli: use enum property type for connection.lldp
Change in behavior:

  - the setter would previoulsy allow "enable" case-insensitive.
    Now, it's case sensitive.
2017-03-30 13:09:58 +02:00
Thomas Haller b9fa0e0a19 utils: add _nm_utils_enum_from_str_full() to support aliases 2017-03-30 13:09:58 +02:00
Thomas Haller a8730c51c8 libnm: move enum utils to new shared file shared/nm-utils/nm-enum-utils.h
libnm contains the public function nm_utils_enum_from_str() et al.
The function is not flexible enough for nmcli's usecase. So, I would
need another public function like nm_utils_enum_from_str_full() that
has an extended API.

That was already required previously for ifcfg-rh writer, but in that
case I could just add it as internal API as libnm-core is linked statically
with NetworkManager.

I don't want to commit to a public API for an utility function. So move
the code instead to the shared directory, so that nmcli may link
statically against it and use the internal API.
2017-03-30 13:09:58 +02:00
Thomas Haller 63c4760cd5 cli: use enum property type for 802-1x.phase1-auth-flags 2017-03-30 13:09:58 +02:00
Thomas Haller 2e89b08343 cli: use enum property type for wifi.power-save
This changes behavior for the pretty-output.
Now, we output "%d (%s)" instead of "%s (%d)".
2017-03-30 13:09:58 +02:00
Thomas Haller f53218ed7c cli: add property type for enum and showcase for ipv6.addr-gen-mode 2017-03-30 13:09:58 +02:00
Thomas Haller 6ca30a6159 cli: belatedly add for connection user data
User data will be printed in a new multiline mode.
Need more work first.
2017-03-30 13:09:58 +02:00
Thomas Haller baf0a7c2f9 cli: don't hard-code list of settings for completion 2017-03-30 13:09:58 +02:00
Thomas Haller 23298bfc88 cli: move utils function from common.h to nm-meta-setting-desc.c
These functions are only used by nm-meta-setting-desc.c. Make them internal.
Unfortunately, they are part of "common.h" which cannot be used without
the rest of nmcli. Still todo.
2017-03-30 13:09:58 +02:00
Thomas Haller b5c8622ad3 cli: split nm-meta-setting-desc out of settings
This part contains static functions and variables to describe
settings. It is distinct from the mechanism to use them, or
access them.

Split it out.

It still uses clients/cli/common.h and clients/cli/utils.h
which shall be fixed next.
2017-03-30 13:09:58 +02:00