Commit Graph

419 Commits

Author SHA1 Message Date
Francesco Giudici
c6448f724b cli: get team defaults from setting header files
this allows centralizing default values definition and allows quicker
and safer update of default values.
2018-01-15 18:27:10 +01:00
Lubomir Rintel
cd476e4dc9 core: load jansson on demand
Avoid using it if the symbols clash is detected.
2018-01-08 10:15:29 +01:00
Lubomir Rintel
9e4de97967 libnm-core: move detection of UTF-8 capable terminals to clients/
Having it in libnm doesn't make any sense and prevents using it for more
internal functionality.

Too bad nm_utils_wifi_strength_bars() is already a public API.
No problem -- replace it with a compatible yet dumber equivalent.
2017-12-18 14:47:37 +01:00
Lubomir Rintel
6672c5e92e all: get rid of a handful of unused-but-set variables 2017-12-18 13:29:32 +01:00
Thomas Haller
cb06a36a18 libnm: avoid deep cloning list of address attribute names for nm_utils_ip_addresses_to_variant()
It's only a temporary list. No need for cloning the names
as well.
2017-12-18 12:14:50 +01:00
Thomas Haller
f299a79d5b libnm: sort attribute names in nm_tc_action_get_attribute_names()
The order in which the attribute names are returns should
be defined and stable. Sort them and re-use the helper functions.
2017-12-18 12:14:49 +01:00
Thomas Haller
d83eee5d57 utils: extend binary-search to return the first/last index
binary-search can find an index of a matching entry in a sorted
list. However, if the list contains multiple entries that compare
equal, it can be interesting to find the first/last entry. For example,
if you want to append new items after the last.

Extend binary search to optionally continue the binary search
to determine the range that compares equal.
2017-12-15 11:36:07 +01:00
Thomas Haller
f44f21c87e core: avoid leaks parsing team link-watcher
Found by coverity.
2017-12-12 11:15:38 +01:00
Lubomir Rintel
de41c45e61 libnm-core: add functionality for dealing with tc-style traffic filter specifiers
Tailored to fit both nmcli and keyfile needs.
2017-12-11 11:02:04 +01:00
Lubomir Rintel
733464ada3 libnm-core: add functionality for dealing with tc-style action specifiers
Tailored to fit both nmcli and keyfile needs.
2017-12-11 11:02:04 +01:00
Lubomir Rintel
92f8f30d47 clients: add tc qdisc support
What works:

  nmcli c add con-name dum0 ifname dum0 type dummy \
      tc.qdiscs 'ingress, root pfifo_fast'
  nmcli c modify dum0 -tc.qdiscs 'root pfifo_fast'
  nmcli c modify dum0 +tc.qdiscs 'root handle 666: fq_codel'
2017-12-11 10:52:23 +01:00
Lubomir Rintel
7c1de05f41 libnm-core: add functionality for dealing with tc-style qdisc specifiers
Tailored to fit both nmcli and keyfile needs.
2017-12-11 10:52:22 +01:00
Lubomir Rintel
18dd937b81 libnm-core/utils: allow use of bytestring with attributes 2017-12-11 10:30:26 +01:00
Lubomir Rintel
47b1dc3828 libnm-core/utils: add some special properties for the attributes
"no_value" indicates that the the attribute is a single word, not a
key=value pair. If the type is BOOLEAN then the attribute is considered
true, if it's a STRING then the key is used instead of a value.

"consumes_rest" indicates that the particular key takes the unparseable
tail of the string for a value.

This allows parsing tc-style strings. Consider this filter:

              ,------ regular key/value pair
       ,-----'----.
  root handle 1234: matchall action simple foo bar baz
    |                  |     `-----------.-----------'
    |                  |                 `- "", STRING, consumes_rest
    |                  `------------------- "kind", STRING, no_value
    `-------------------------------------- "root', BOOLEAN, no_value
2017-12-11 10:30:26 +01:00
Lubomir Rintel
48a619e62b libnm-core/utils: allow using the same character for key/value and attribute separators
Allows doing a nm_utils_parse_variant_attributes(..., ' ', ' ').
2017-12-11 10:30:26 +01:00
Lubomir Rintel
9a00750c06 libnm-core/utils: (trivial) use g_set_error_literal() where appropriate 2017-12-11 10:30:25 +01:00
Thomas Haller
b11eac1a0d libnm: use nm_utils_named_values_from_str_dict()
Make use of NMUtilsNamedValue in nm_utils_format_variant_attributes().
This avoids creating a GList and sorting it.

Also, reuse nm_utils_named_values_from_str_dict() in
nm_setting_bond_get_option().
2017-12-08 18:48:36 +01:00
Thomas Haller
b1c65d32fe Revert "Makefile: rework team compilation flags"
I don't think we should do this.

- renamining/dropping configure options is still an annoyance,
  because it requires to different ./configure options depending
  on the version. The rename from --enable-teamctl to --enable-team
  might be theoretically nice, but more annoying then helpful.

- There is no strict dependency between --enable-team and
  --enable-json-validation. At most, one could argue that
  when enabling the team plugin (--enable-teamctl), then
  libnm must also be build with --enable-json-validation.
  But in fact, the team plugin will happily work with a
  libnm that doesn't link against libjansson.
  That is --enable-teamctl --disable-json-validation will work
  in practice just fine.
  On the other hand, libnm is a client library to create connection
  profiles, fully supporting team profiles also makes sense if the
  actual plugin is not installed (or build). Thus, --disable-teamctl
  --enable-json-validation certainly makes sense.

At this point, one might ask whether libnm is even still complete without
libjansson. Maybe libnm should *require* --enable-json-validation.
But that is not what the patch was doing, and it would also need
some careful consideration before doing so.

This reverts commit 9d5cd7eae8.
2017-12-08 09:07:30 +01:00
Francesco Giudici
9d5cd7eae8 Makefile: rework team compilation flags
Rename the team functionality enablement from 'teamdctl' to 'team'.
Force jansson lib requirement for team functionality: NetworkManager
requires the teamd daemon to manage team. As teamd depends upon jansson
lib, adding jansson requirement for teaming support in NetworkManager
seems reasonable.
Remove the jansson_validation flag, as the only generic json function in
nmcli (not related to team) was the one to check if a string was in json
format. Anyway, that function is used for team checks only. So, move
also json validation functions under the WITH_TEAM flag.
2017-12-08 00:46:27 +01:00
Francesco Giudici
a5642fd93a libnm-core: team: rework defaults management on runner properties
till now when no explicit value was set on a property, the default value
for that property was returned, also if the property was not applicable
to the selected runner.
Fix this, showing default values for properties only when relevant and
showing instead -1 or null when the property is not relevant for the
selected runner.
Moreover, reset all the properties but the link-watchers when the team.runner
is changed: this is required to clean up the properties unrelated to the
new runner and start with the runner-specific defaults.
2017-12-08 00:46:27 +01:00
Francesco Giudici
fdd41852ee libnm-core: json: share code to load defaults in team(-port).config
Move code from _nm_utils_team_config_get to the brand new
_json_team_add_defaults function without any change.
Then remove the duplicated code from _nm_utils_team_config_equal and
leverage the new function. Here the only functional change is that
the defaults for "notify_peers" and "mcast_rejoin" for the
"activebackup" runner are added (the only case in which their default
values are different than 0).
2017-12-08 00:46:27 +01:00
Francesco Giudici
f0ae71e7d6 libnm-core: trivial: just move static json functions 2017-12-08 00:46:27 +01:00
Francesco Giudici
8648aa576e libnm-core: trivial: move json key deletion code to a separate function 2017-12-08 00:46:27 +01:00
Francesco Giudici
363a2cfe95 libnm-core: synchronize team.link_watchers when team.config is set. 2017-12-08 00:46:26 +01:00
Francesco Giudici
e59878ce19 libnm-core: synchronize team.config when team.link_watchers is set. 2017-12-08 00:46:26 +01:00
Francesco Giudici
ba4ce843fa libnm-core: add backend for GVariant de/serialization of link_watchers. 2017-12-08 00:46:26 +01:00
Francesco Giudici
5e6f7de4be libnm-core: preserve keys order in team.config with old jansson libs
When jansson lib version is < 2.8 the order of the keys of json objects
is not preserved automatically. In particular, when loading the json
string, parsing it and dumping it back to a string the key order will be
lost if the now deprecated JSON_PRESERVE_ORDER flag is not set.
Add the flag: will do nothing on recent jansson versions but will fix
behavior for legacy ones.
2017-12-08 00:46:26 +01:00
Thomas Haller
15608713c4 libnm: drop now unused helper function _nm_utils_strsplit_set() 2017-11-29 16:26:28 +01:00
Thomas Haller
26e7abc65e libnm: be more accepting parsing boolean values in nm_utils_parse_variant_attributes()
We should use the same str2bool parser everywhere: _nm_utils_ascii_str_to_bool().
Incidentally, this function allows more forms of expressing a boolean
value.

  $ nmcli connection modify "$CON" ipv4.routes '1.2.3.4/32 1.2.3.1 onlink=1'
  Error: failed to modify ipv4.routes: invalid option 'onlink=1': invalid boolean value '1' for attribute 'onlink'.
2017-11-24 12:28:56 +01:00
Thomas Haller
3c8c63dcca libnm: stable order in _nm_utils_strdict_to_dbus() 2017-11-21 13:48:49 +01:00
Thomas Haller
a6be2f4aa9 all: use nm_str_hash() instead of g_str_hash()
We also do this for libnm and libnm-core, where it causes visible changes
in behavior. But if somebody would rely on the hashing implementation
for hash tables, it would be seriously flawed.
2017-11-16 11:49:52 +01:00
Thomas Haller
3ee8de20c4 all: include "nm-utils/nm-hash-utils.h" by default
Next we will use siphash24() instead of the glib version g_direct_hash() or
g_str_hash(). Hence, the "nm-utils/nm-hash-utils.h" header becomes very
fundamental and will be needed basically everywhere.

Instead of requiring the users to include them, let it be included via
"nm-default.h" header.
2017-11-16 11:49:51 +01:00
Beniamino Galvani
07d5c86e78 build: fix wrong jansson prerequisites
Currently there are multiple features that require Jansson support,
but WITH_JANSSON=1 is set only when configuring with
--enable-json-validation.  Therefore a build with
"--disable-json-validation --enable-ovs" fails.

The availability of Jansson (WITH_JANSSON) should only be used:

 - to check if dependent features can be enabled
 - to determine compiler and linker flags in the Makefile
 - in nm-jansson.h to define compatibility functions if needed

Everything else must be controlled by a configure switch.

https://bugzilla.gnome.org/show_bug.cgi?id=790233
2017-11-14 15:56:59 +01:00
Francesco Giudici
3e34e404b4 libnm-core: enforce team and team-port defaults
Rework a bit the way default values are check, set and aligned.
2017-11-09 17:56:15 +01:00
Francesco Giudici
dadf710ee3 libnm-core: add functions to align team json config to exposed properties 2017-11-09 17:56:15 +01:00
Thomas Haller
650a47e16c all: use nm-jansson.h 2017-11-09 17:32:22 +01:00
Thomas Haller
ffcab3f653 libnm: add internal helper function nm_utils_inet_ntop() 2017-11-09 09:27:31 +01:00
Thomas Haller
f3146de41b libnm: avoid unnecessary copies accessing NMIPRoute's attributes
We want to support large number of routes. Reduce the number
of copies, by adding internal accessor functions.

Also, work around a complaint from coverity:

  46. NetworkManager-1.9.2/libnm-core/nm-utils.c:1987:
  dereference: Dereferencing a null pointer "names".
2017-10-30 14:12:41 +01:00
Thomas Haller
5f882e8e8f libnm: reject colon in nm_utils_is_valid_iface_name()
Since kernel commit a4176a9391868bfa87705bcd2e3b49e9b9dd2996 (net:
reject creation of netdev names with colons), kernel rejects any
colons in the interface name.

Since kernel could get away with tightening up the check, we can
too.

The user anyway can not choose arbitrary interface names, like
"all", "default", "bonding_masters" are all going to fail one
way or another.
2017-10-23 14:59:52 +02:00
Beniamino Galvani
0a7b08968d libnm-core: normalize "tx_hash" when comparing team config
teamd adds the "tx_hash" property for "lacp" and "loadbalance" runners
when not present. Do the same so that our original configuration
matches with the one reported by teamd.

https://bugzilla.redhat.com/show_bug.cgi?id=1497333
2017-10-19 14:31:07 +02:00
Thomas Haller
2f56de7492 all: add helper functions for nm_hash_update*()
By using a macro, we don't cast all the types to guint. Instead,
we use their native types directly. Hence, we don't need
nm_hash_update_uint64() nor nm_hash_update_ptr().
Also, for types smaller then guint like char, we save hashing
the all zero bytes.
2017-10-18 13:29:22 +02:00
Thomas Haller
0e9e35e309 all: refactor hashing by introducing NMHashState
The privious NM_HASH_* macros directly operated on a guint value
and were thus close to the actual implementation.

Replace them by adding a NMHashState struct and accessors to
update the hash state. This hides the implementation better
and would allow us to carry more state. For example, we could
switch to siphash24() transparently.

For now, we still do a form basically djb2 hashing, albeit with
differing start seed.

Also add nm_hash_str() and nm_str_hash():

- nm_hash_str() is our own string hashing implementation

- nm_str_hash() is our own string implementation, but with a
  GHashFunc signature, suitable to pass it to g_hash_table_new().
  Also, it has this name in order to remind you of g_str_hash(),
  which it is replacing.
2017-10-18 13:05:00 +02:00
Thomas Haller
281d2d9fad shared: split random and hash utils
"nm-utils/nm-shared-utils.h" shall contain utility function without other
dependencies. It is intended to be used by other projects as-is.

nm_utils_random_bytes() requires getrandom() and a HAVE_GETRANDOM configure
check. That makes it more cumbersome to re-use "nm-shared-utils.h", in
cases where you don't care about nm_utils_random_bytes().

Split nm_utils_random_bytes() out to a separate file.

Same for hash utils, which depend on nm_utils_random_bytes(). Also, hash
utils will eventually be extended to use siphash24.
2017-10-17 20:02:59 +02:00
Thomas Haller
4a2798434e core: introduce NM_HASH_INIT() to initialize hash seed
Introduce a NM_HASH_INIT() function. It makes the places
where we initialize a hash with a certain seed visually clear.

Also, move them from "shared/nm-utils/nm-shared-utils.h" to
"shared/nm-utils/nm-macros-internal.h". We might want to
have NM_HASH_INIT() non-inline (hence, define it in the
source file).
2017-10-13 12:47:55 +02:00
Thomas Haller
d06c46b80f libnm: make index variable i unsigned for iterating array
GArray's and GPtrArray's plen argument is unsigned. The index variable
to iterate the list, should not have a smaller range (or different data type).

Also, assert against negative idx argument.
2017-09-27 18:58:53 +02:00
Thomas Haller
121321542e libnm: fix uninitialized variable in get_system_encodings()
CC       libnm-core/libnm_core_libnm_core_la-nm-utils.lo
  libnm-core/nm-utils.c:210:6: error: variable 'encodings' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
          if (lang) {
              ^~~~
  libnm-core/nm-utils.c:220:7: note: uninitialized use occurs here
          if (!encodings) {
               ^~~~~~~~~
  libnm-core/nm-utils.c:210:2: note: remove the 'if' if its condition is always true
          if (lang) {
          ^~~~~~~~~~
  libnm-core/nm-utils.c:198:30: note: initialize the variable 'encodings' to silence this warning
          const char *const *encodings;
                                      ^
                                       = NULL

Fixes: 28a0627481
2017-09-13 08:17:30 +02:00
Beniamino Galvani
789f8a6b51 libnm-core: also consider LC_ALL and LC_CTYPE to guess SSID charset
Also consider LC_ALL and LC_CTYPE environment variables, in addition
to LANG, to determine the charset used for converting SSIDs to UTF-8.

https://bugzilla.gnome.org/show_bug.cgi?id=784415
2017-09-12 23:46:51 +02:00
Beniamino Galvani
28a0627481 libnm-core: cache the current character encoding
Instead of performing the parsing of environment variables and the
lookup for every string, cache the selected encoding.
2017-09-12 23:46:49 +02:00
Thomas Haller
5c42cdb287 all: use _nm_utils_ip4_*() utils functions 2017-09-05 18:44:04 +02:00
Thomas Haller
f0adca00f3 core: fix creating lower-case MAC address with nm_utils_hwaddr_ntoa_buf()
There is only one caller at the moment, and he passes TRUE anyway.
2017-07-25 15:17:50 +02:00