summaryrefslogtreecommitdiff
path: root/libnm-core
AgeCommit message (Collapse)AuthorFilesLines
2018-12-03keyfile: add helper functions to record loaded UUID filesThomas Haller1-0/+4
This code will be used later. We want to remember which keyfiles are currently loaded (or hidden). With the addition or multiple keyfile directories (soon), there are two cases where this matters: - if there are multiple keyfiles which reference the same UUID, we can only load one of them. That is already a problem today with only one keyfile directory, where multiple files can reference the same UUID. The implementation will pick the file based on priorities (like the file modification date). However, the user may call explicitly call `nmcli connection load`. In that case, we cannot reload all files to find out whether the to be loaded file is hidden according to the defined priorities. We cannot do that, because we must not make decisions based on files on disk, which we are not told to reload. So, during a `nmcli connection load` we must look at unrelated files, to determine how to load the file. Instead, we do allow the user to load any file, even if it would be shadowed by other files. When we do that, we may want to persist which file is currently loaded, so that a service restart and a `nmcli connection reload` does not undo the load again. This can be later later be solved by writing a symlink "/var/run/NetworkManager/system-connections/.loaded-$UUID.nmkeyfile" which targets the currently active file. - if a profile was loaded from read-only persistant storage, the user may still delete the profile. We also need to remember the deletion of the file. That will be achieved by symlinking "/dev/null" as "/etc/NetworkManager/system-connections/.loaded-$UUID.nmkeyfile". Add helper functions to read and write these symlinks.
2018-12-03keyfile: cleanup nm_keyfile_utils_ignore_filename()Thomas Haller1-33/+54
2018-12-01all: make use of NM_MAKE_STRV() macroThomas Haller2-8/+5
2018-11-29all: say Wi-Fi instead of "wifi" or "WiFi"Lubomir Rintel1-3/+3
Correct the spelling across the *entire* tree, including translations, comments, etc. It's easier that way. Even the places where it's not exposed to the user, such as tests, so that we learn how is it spelled correctly.
2018-11-20libnm-core: macsec: don't require a cak in verify()Beniamino Galvani1-0/+6
CAK is a connection secret and can be NULL for various reasons (agent-owned, no permissions to get secrets, etc.). verify() must not require it. Fixes: 474a0dbfbeeda7504d6599abe4adf0ddf18bab1e
2018-11-13dhcp: add "ipv4.dhcp-client-id=duid" settingThomas Haller1-0/+3
Add a new mode for the DHCPv4 client identifier. "duid" is what the internal (systemd) DHCP client already does by default. It is also the same as used by systemd-networkd's "ClientIdentifier=duid" setting. What we still lack (compared to networkd) are a way to overwrite IAID and the DUID. Previously, this mode was used by the internal DHCP plugin by default. However, it could not be explicitly configured. In general, our default values should also be explicitly selectable. Now the "duid" client identifier can also be used with the "dhclient" plugin.
2018-11-13doc: add hint about ipv4.dhcp-client-id=stableThomas Haller2-2/+5
2018-11-13all: add "${MAC}" substituion for "connection.stable-id"Thomas Haller1-2/+2
We already had "${DEVICE}" which uses the interface name. In times of predictable interface naming, that works well. It allows the user to generate IDs per device which don't change when the hardware is replaced. "${MAC}" is similar, except that is uses the permanent MAC address of the device. The substitution results in the empty word, if the device has no permanent MAC address (like software devices). The per-device substitutions "${DEVICE}" and "${MAC}" are especially interesting with "connection.multi-connect=multiple".
2018-11-13dhcp: don't load IPv4 client-id from lease fileThomas Haller1-2/+2
The client-id is something that we want to determine top-down. Meaning, if the user specifies it via ipv4.dhcp-client-id, then it should be used. If the user leaves it unspecified, we choose a default stable client-id. For the internal DHCP plugin, this is a node specific client-id based on - the predictable interface name - and /etc/machine-id It's not clear, why we should allow specifying the client-id in the lease file as a third source of configuration. It really pushes the configuration first down (when we do DHCP without lease file), to store an additional bit of configuration for future DHCP attempts. If the machine-id or the interface-name changes, then so does the default client-id. In this case, also "ipv4.dhcp-client-id=stable" changes. It's fair to require that the user keeps the machine-id stable, if the machine identity doesn't change. Also, the lease files are stored in /var/lib/NetworkManager, which is more volatile than /etc/machine-id. So, if we think that machine-id and interface-name is not stable, why would we assume that we have a suitable lease file? Also, if you do: nmcli connection add con-name "$PROFILE" ... ipv4.dhcp-client-id '' nmcli connection up $PROFILE nmcli connection modify "$PROFILE" ipv4.dhcp-client-id mac nmcli connection up $PROFILE nmcli connection modify "$PROFILE" ipv4.dhcp-client-id '' nmcli connection up $PROFILE wouldn't you expect that the original (default) client-id is used again? Also, this works badly with global connection defaults in NetworkManager.conf. If you configure a connection default, previously already this would always force the client-id and overrule the lease. That is reasonable, but in which case would you ever want to use the client-id from the lease?
2018-11-13all: cleanup GChecksum handlingThomas Haller2-18/+11
- prefer nm_auto_free_checksum over explicit free. - use nm_utils_checksum_get_digest*(). - prefer defines for digest length. - assume g_checksum_new() cannot fail.
2018-11-13man: document global connection default for "ipv4.dns-priority"Thomas Haller1-2/+3
... and "ipv6.dns-priority". Fixes: 77ded12da46457848e86561b0e9460f03302e6e8
2018-11-07libnm-core: don't serialize synthetic properties in nm_setting_to_string()Lubomir Rintel3-4/+19
Fixes: f957ea2b343828ad1fa2014bc7a4dedaf854f3bc https://github.com/NetworkManager/NetworkManager/pull/245
2018-10-31libnm: add nm_utils_uuid_is_null() helperThomas Haller3-0/+36
2018-10-31libnm: add nm_utils_uuid_generate_from_string_bin() functionThomas Haller2-15/+40
2018-10-31libnm: add support for SHA1 based version 5 UUIDsThomas Haller3-114/+146
The entire point of using version 3/5 UUIDs is to generate stable UUIDs based on a string. It's usually important that we don't change the UUID generation algorithm later on. Since we didn't have a version 5 implementation, we would always resort to the MD5 based version 3. Version 5 is recommended by RFC 4122: o Choose either MD5 [4] or SHA-1 [8] as the hash algorithm; If backward compatibility is not an issue, SHA-1 is preferred. Add a version 5 implementation so we can use it in the future. All test values are generated with python's uuid module or OSSP uuid.
2018-10-31libnm/tests: add more tests for generating UUIDsThomas Haller1-7/+146
The expected values are checked with python's uuid module and OSSP uuid.
2018-10-31libnm/trivial: rename uuid type VARIANT3 to VERSION3Thomas Haller3-17/+17
In RFC 4122, this is called "version 3", not "variant 3". While for UUIDs there is also a concept of "variants", that is something else. Fix naming.
2018-10-31libnm: expose UUID utils as internal APIThomas Haller2-17/+62
We link against libuuid.so, but it was entirely internal to libnm-core. We only exposed UUIDs in string form. Add API to also handle UUIDs in binary form. Note that libuuid already defines a type "uuid_t". However, don't use it and instead use our own typedef NMUuid. Reasons: - uuid.h should be internal to libnm-core (nm-utils.c specifically), and not be used by or exposed it other parts of the code. - uuid_t is a typedef for a guchar[16] array. Typedefs for arrays are confusing, because depending on whether it's an automatic variable or a pointer in a function argument, they behave differently regarding whether to take their address or not and usage of "sizeof()".
2018-10-23libnm: hash settings in NMConnection by gtypeThomas Haller1-14/+30
NMConnection keeps a list (hash table) of all settings. There are two lookup methods to find a setting in a connection: - nm_connection_get_setting() by GType - nm_connection_get_setting_by_name() by name Note, that nm_connection_get_setting_by_name() first converts the name to a GType, and then looks up the setting by GType. But then, nm_connection_get_setting() would again convert the GType to the type name, and hash the name. That is pointless, just index by GType directly. Maybe, using a hash table is anyway overkill because commonly there are only a handful of settings in a connection. Regardless of that, change the hashing.
2018-10-23device: return void pointer from nm_device_get_applied_setting()Thomas Haller1-2/+6
Literally ever use of nm_device_get_applied_setting() requires a cast. Just don't.
2018-10-23keyfile: move and rename NM_CONFIG_KEYFILE_PATH_DEFAULT defineThomas Haller1-0/+1
2018-10-23keyfile/trivial: rename keyfile related functionsThomas Haller2-13/+13
NM_CONFIG_KEYFILE_PATH_IN_MEMORY is now called NMS_KEYFILE_PATH_NAME_RUN. This name seems odd in the current context, it will be more suitable when we also have NMS_KEYFILE_PATH_NAME_LIB (for /usr/lib).
2018-10-23keyfile: move keyfile utilities from src/ to libnm-core/Thomas Haller2-0/+134
These utilities are concerned with valid file names (as NetworkManager daemon requires it). This is relevant for everybody who wants to write keyfile files directly. Hence, move it to libnm-core. Still as internal API.
2018-10-17libnm-core: expose internal _nm_dbus_typecheck_response() helperThomas Haller2-26/+72
2018-10-08libnm-core: fix other int comparisons in team settingBeniamino Galvani1-7/+7
I forgot to update them when applying commit 72b454177121. Fixes: 72b45417712186b0247ba5a69e42d54a27763fb0
2018-10-07core/setting-wpan: add page and channel propertiesLubomir Rintel2-2/+134
2018-10-07core/setting-wpan: fix some whitespace errorsLubomir Rintel1-15/+15
2018-10-07libnm-core: fix int comparisons in team settingThomas Haller1-2/+2
2018-10-06libnm-core: remove unneeded comparisonsBeniamino Galvani1-2/+2
a_gendata and b_gendata cannot be NULL. This makes coverity happy.
2018-10-06libnm-core: use g_variant_type_equal() to compare variant typesBeniamino Galvani2-2/+2
Even if a direct pointer comparison should be fine, use the proper function. GVariantType documentation says: "Two types may not be compared by value; use g_variant_type_equal() or g_variant_type_is_subtype_of()." This also fixes coverity warnings.
2018-10-06libnm-core: fix coverity warningBeniamino Galvani1-11/+11
3. NetworkManager-1.14.0/libnm-core/nm-utils.c:4944: var_compare_op: Comparing "str" to null implies that "str" might be null. 4. NetworkManager-1.14.0/libnm-core/nm-utils.c:4958: var_deref_op: Dereferencing null pointer "str". # 4956| # 4957| /* do some very basic validation to see if this might be a JSON object. */ # 4958|-> if (str[0] == '{') { # 4959| gsize l; # 4960|
2018-10-04keyfile: split automatically setting ID/UUID for keyfileThomas Haller4-56/+35
keyfile already supports omitting the "connection.id" and "connection.uuid". In that case, the ID would be taken from the keyfile's name, and the UUID was generated by md5 hashing the full filename. No longer do this during nm_keyfile_read(), instead let all callers call nm_keyfile_read_ensure_*() to their liking. This is done for two reasons: - a minor reason is, that one day we want to expose keyfile API as public API. That means, we also want to read keyfiles from stdin, where there is no filename available. The implementation which parses stdio needs to define their own way of auto-generating ID and UUID. Note how nm_keyfile_read()'s API no longer takes a filename as argument, which would be awkward for the stdin case. - Currently, we only support one keyfile directory, which (configurably) is "/etc/NetworkManager/system-connections". In the future, we want to support multiple keyfile dirctories, like "/var/run/NetworkManager/profiles" or "/usr/lib/NetworkManager/profiles". Here we want that a file "foo" (which does not specify a UUID) gets the same UUID regardless of the directory it is in. That seems better, because then the UUID won't change as you move the file between directories. Yes, that means, that the same UUID will be provided by multiple files, but NetworkManager must already cope with that situation anyway. Unfortunately, the UUID generation scheme hashes the full path. That means, we must hash the path name of the file "foo" inside the original "system-connections" directory. Refactor the code so that it accounds for a difference between the filename of the keyfile, and the profile_dir used for generating the UUID.
2018-10-04keyfile: refactor setting default ID/UUID in nm_keyfile_read()Thomas Haller2-14/+51
Split out the functionality for auto-detecting the ID and UUID of a connection. First of all, nm_keyfile_read() is already overcomplicated. The next commit will require the caller to explicitly call these functions.
2018-09-30Fix typosRafael Fontenelle3-3/+3
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/21 [thaller@redhat.com: fix generated clients/common/settings-docs.h.in file and fix wrong change in src/systemd/src/libsystemd/sd-event/sd-event.c]
2018-09-30libnm: cleanup _nm_utils_hexstr2bin*() helperThomas Haller2-35/+104
Add 3 variants of _nm_utils_hexstr2bin*(): - _nm_utils_hexstr2bin_full(), which takes a preallocated buffer and fills it. - _nm_utils_hexstr2bin_alloc() which returns a malloc'ed buffer - _nm_utils_hexstr2bin_buf(), which fills a preallocated buffer of a specific size.
2018-09-30all: drop _nm_utils_bin2hexstr()Thomas Haller2-20/+0
We already have nm_utils_bin2hexstr() and _nm_utils_bin2hexstr_full(). This is confusing. - nm_utils_bin2hexstr() is public API of libnm. Also, it has a last argument @final_len to truncate the string at that length. It uses no delimiter and lower-case characters. - _nm_utils_bin2hexstr_full() does not do any truncation, but it has options to specify a delimiter, the character case, and to update a given buffer in-place. Also, like nm_utils_bin2hexstr() and _nm_utils_bin2hexstr() it can allocate a new buffer on demand. - _nm_utils_bin2hexstr() would use ':' as delimiter and make the case configurable. Also, it would always allocate the returned buffer. It's too much and confusing. Drop _nm_utils_bin2hexstr() which is internal API and just a wrapper around _nm_utils_bin2hexstr_full().
2018-09-30libnm: return output buffer from _nm_utils_bin2hexstr_full()Thomas Haller2-16/+39
It's just more convenient, as it allows better chaining. Also, allow passing %NULL as @out buffer. It's clear how large the output buffer must be, so for convenience let the function (optionally) allocate a new buffer. This behavior of whether to - take @out, fill it, and return @out - take no @out, allocate new buffer, fill and and return it is slightly error prone. But it was already error prone before, when it would accept an input buffer without explicit buffer length. I think this makes it more safe, because in the common case the caller can avoid pre-allocating a buffer of the right size and the function gets it right.
2018-09-30all/trivial: rename hexstr<>bin conversion functionsThomas Haller2-25/+25
"bin2str" and "str2bin" are not very clear. These strings are hex-strings. Rename.
2018-09-30libnm/macsec: tighten up verification and normalize mka_cak/mka_ckn propertiesThomas Haller2-1/+47
2018-09-29libnm: use nm_free_secret() in nm-setting-macsec.cThomas Haller1-5/+4
2018-09-27wifi: support hidden ssid in AP modeBeniamino Galvani1-5/+11
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/48
2018-09-19core/tests: remove an unused variableLubomir Rintel1-1/+0
test-general.c:6612:19: error: unused variable 'buf_free_1' [-Werror,-Wunused-variable] gs_free gpointer buf_free_1 = NULL;
2018-09-19crypto: remove some unused variablesLubomir Rintel1-3/+0
libnm-core/nm-crypto.c:191:39: error: unused variable 'data_content' [-Werror,-Wunused-variable] nm_auto_clear_secret_ptr NMSecretPtr data_content = { 0 }; libnm-core/nm-crypto.c:341:18: error: unused variable 'der' [-Werror,-Wunused-variable] gs_free guchar *der = NULL; libnm-core/nm-crypto.c:518:16: error: unused variable 'output' [-Werror,-Wunused-variable] gs_free char *output = NULL;
2018-09-18core/setting: don't assume we have a connection when synthesizing a propertyLubomir Rintel1-1/+5
nm_setting_to_string() operates on the setting alone, without a connection. Tolerate that. This fixed nm_connection_dump(vlan_connection).
2018-09-17docs: misc. typos pt2luz.paz19-37/+37
Remainder of typos found using `codespell -q 3 --skip="./shared,./src/systemd,*.po" -I ../NetworkManager-word-whitelist.txt` whereby whitelist consists of: ``` ans busses cace cna conexant crasher iff liftime creat nd sav technik uint ``` https://github.com/NetworkManager/NetworkManager/pull/205
2018-09-14libnm/trivial: whitespaceThomas Haller1-8/+8
2018-09-14libnm: document nm_utils_parse_variant_attributes() returning floating ↵Thomas Haller1-1/+3
references See-also: https://bugzilla.redhat.com/show_bug.cgi?id=1594887
2018-09-14libnm: add missing NM_AVAILABLE_IN_1_2 macro for nm_connection_get_setting_tun()Thomas Haller1-0/+1
2018-09-14libnm: add missing NM_AVAILABLE_IN_1_14 macro to new APIThomas Haller1-0/+1
Fixes: df30651b8906cfe6a5cb7aef01a220d1f21b80f3
2018-09-14libnm: drop API nm_connection_get_setting_{6lowpan,sriov,wpan}()Thomas Haller2-55/+1
Note that NMSettingEthtool and NMSettingMatch don't have such functions either. We have API nm_connection_get_setting (NMConnection *, GType) nm_connection_get_setting_by_name (NMConnection *, const char *) which can be used generically, meaning: the requested setting type is an argument to the function. That is generally more useful and flexible. Don't add API which duplicates existing functionality and is (arguably) inferiour. Drop it now. This is an ABI/API break for the current development cycle where the 1.14.0 API is still unstable. Indeed it's already after 1.14-rc1, which is ugly. But it's also unlikely that somebody already uses this API/ABI and is badly impacted by this change. Note that nm_connection_get_setting() and nm_connection_get_setting_by_name() are slightly inconvenient in C still, because they usually require a cast. We should fix that by changing the return type to "void *". Such a change may be possibly any time without breaking API/ABI (almost, it'd be an API change when taking a function pointer without casting).