Commit Graph

26105 Commits

Author SHA1 Message Date
Thomas Haller
ef66b99eed libnm/tests: assert for valid test input for _test_verify_options_bridge() 2020-06-11 18:35:42 +02:00
Thomas Haller
f9721385ce libnm: don't require birdge multicast_snooping with multicast_router auto,enabled
This does not match kernel behavior. You seem to be able to configure
multicast_snooping=auto,enabled with multicast_snooping off just fine.

Possibly this constrained was inspired by `ip link`, which says:

  mcast_router MULTICAST_ROUTER - set bridge's multicast router if IGMP
  snooping is enabled.

But kernel doesn't enforce this:

  ip link delete br0 2>/dev/null; \
  ip link add br0 type bridge mcast_router 1 mcast_snooping 0; \
  grep ^ /sys/devices/virtual/net/br0/bridge/{multicast_router,multicast_snooping}

gives:

    /sys/devices/virtual/net/br0/bridge/multicast_router:1
    /sys/devices/virtual/net/br0/bridge/multicast_snooping:0

We probably should not implement additional constrains on top of what
kernel does, if the conditions are that obscure.

Fixes: e01d3b4c2b ('nm-setting-bridge: add 'multicast-router' bridge option')
2020-06-11 18:35:36 +02:00
Thomas Haller
e8aaa95354 lldp: merge branch 'th/lldp-raw'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/529
2020-06-11 18:23:46 +02:00
Thomas Haller
0bc6f6a197 lldp: accept all chassis-id/port-id types and support network-address
Do what systemd does with sd_lldp_neighbor_get_chassis_id_as_string()
and sd_lldp_neighbor_get_port_id_as_string(). Maybe we should use the
systemd functions directly, however that is not done because the way
how we convert the values to string is part of our stable API. Let's not
rely on systemd for that.

Also, support SD_LLDP_CHASSIS_SUBTYPE_NETWORK_ADDRESS and SD_LLDP_PORT_SUBTYPE_NETWORK_ADDRESS
types. Use the same formatting scheme as systemd ([1]) and lldpd ([2]).

[1] a07e962549/src/libsystemd-network/lldp-neighbor.c (L422)
[2] d21599d2e6/src/lib/atoms/chassis.c (L125)

Also, in case we don't support the type or the type contains unexpected
data, fallback to still expose the LLDP neighbor, and convert the value
to a hex string (like systemd does). This means, lldp_neighbor_new()
in practice can no longer fail and the error handling for that can be
dropped.

There is one tiny problem: now as fallback we expose the
chassis-id/port-id as hex string. That means, if we in the future
recognize a new type, we will have to change API for those types.
The alternative would be to either hide the neighbor completely from the
D-Bus API (as previously done), or not expose the hex strings on D-Bus.
Neither seems very attractive, so expose the value (and reserve the
right to change API in the future).
2020-06-11 16:51:50 +02:00
Thomas Haller
58f738fa3b lldp: use full chassis-id/port-id as ID for LLDP neighbor
For the ID of LLDP neighbors follow what systemd does (w.r.t. what it
consideres equality of two neighbors).

Note that previously we did almost the same thing. Except, we compared
priv->chassis_id and priv->port_id, but these values are string
representations of the original (binary value). Don't use the pretty
strings as ID but the original binary value.
2020-06-11 16:51:50 +02:00
Thomas Haller
bf3bd1cff1 lldp: parse destination-address on demand
An invalid destination address doesn't need to break the LLDL neighbor entirely.
In fact, systemd will already filter out such addresses. So in practice,
the neighbor always has a valid destination address.

There is thus no need to parse it already during lldp_neighbor_new().
2020-06-11 16:51:50 +02:00
Thomas Haller
e7955f577e lldp: use nm_utils_ether_addr_equal() instead of re-implementation 2020-06-11 16:51:50 +02:00
Thomas Haller
0d41abea2e lldp: only have GHashTable instance for LLDP neighbors when running
When the instance is not running (after creation or after stop), there
is no need to keep the GHashTable around.

Create it when needed (during start) and clear it during stop. This
makes it slightly cheaper to keep a NMLldpListener instance around,
if it's currently not running.

NMDevice already keeps the NMLldpListener around, even after stopping
it. It's not clear whether the instance will be started again, so also
clear the GHashTable. Also, one effect is that if you initially were in
a network with many LLDP neibors, after stop and start, the GHashTable
now gets recreated and may not need to allocate a large internal array
as before.
2020-06-11 16:51:50 +02:00
Thomas Haller
a7aa2a5e01 lldp: delay change notification for LLDP neighbor events
We already rate limit change events by two seconds. When we notice
that something changed, we call data_changed_schedule().

Previously, that would immediately issue the change notification,
if ratelimiting currently was not in effect. That means, if we happen
go receive two LLDP neighbor events in short succession, then the
first one will trigger the change notification right away, while
the second will be rate limited.

Avoid that by always issue scheduling the change notification in
the background. And if we currently are not rate limited, with
an idle handler with low priority.
2020-06-11 16:51:50 +02:00
Thomas Haller
d2313bef5e lldp: change order of dictionary fields for LLDP neighbor variant
This changes the order to what the code did previously, before switching
from GVariantDict to GVariantBuilder. But it changes the actually
serialized order in the variant.
2020-06-11 16:51:50 +02:00
Thomas Haller
ae0da6dd60 lldp: use GVariantBuilder instead of GVariantDict
GVariantDict is basically a GHashTable, and during g_variant_dict_end()
it uses a GVariantBuilder to create the variant.

This is totally unnecessary in this case. It's probably unnecessary in
most use cases, because commonly we construct variants in a determined series
of steps and don't need to add/remove keys.

Aside the overhead, GHashTable also does not give a stable sort order,
which seems a pretty bad property in this case.

Note that the code changes the order in which we call
g_variant_builder_add() for the fields in code, to preserve the previous
order that GVariantDict actually created (at least, with my version of
glib).
2020-06-11 16:51:50 +02:00
Thomas Haller
cf4763207f lldp: add LLDP attributes to GVariant builder without intermediate parsing (2) 2020-06-11 16:51:49 +02:00
Thomas Haller
4aa0b9180a lldp: add LLDP attributes to GVariant builder without intermediate parsing (1)
The intermediate parsing step serves very little purpose.

The only use is to ensure that we always add the keys in a stable
order, but we can easily ensure that otherwise.
2020-06-11 16:51:49 +02:00
Thomas Haller
94ee6f4fe1 lldp: use nm_g_variant_builder_add_sv*() helpers in "nm-lldp-listener.c" 2020-06-11 16:51:49 +02:00
Thomas Haller
5e6e361c21 lldp: no longer keep parsed attributes in LldpNeighbor
We only need to parse them to construct the GVariant. There is
no need to keep them around otherwise.

We still keep LldpAttrs array and don't construct the GVariant right
away. The benefit is that this way while parsing we set the array
fields, and afterwards, when we generate the string dictionary, the
keys are sorted.
2020-06-11 16:51:49 +02:00
Thomas Haller
22f161d722 lldp: split parsing of LLDP attributes from lldp_neighbor_new()
Move the parsing of the LLDP attributes to a separate function.
In the next step, we will no longer keep all attribute around
and no longer parse them during lldp_neighbor_new().

One effect is that we can no longer (easily) declare the LLDP message as
invalid, if parsing the attributes fails. That makes IMO more sense,
because we should try to expose what little we could parse, and not
be forgiving to unexpected data. If we wanted, we still could hide such
neighbors entirely from being exposed, but that is not done, because
it seems better to expose the parts that were valid.
2020-06-11 16:51:49 +02:00
Thomas Haller
28a0093d67 lldp: separate LLDP attribute list from LldpNeighbor
We actually only need to parse the attributes while constructing
the GVariant. In a first step decouple the tracking of the parsed
attributes from LldpNeighbor struct. More will follow.
2020-06-11 16:51:49 +02:00
Thomas Haller
e189d65ab6 lldp: expose raw LLDP message on D-Bus
Also, track sd_lldp_neighbor instance directly.

sd_lldp_neighbor is a perfectly reasonable container for keeping
track of the LLDP neighbor information. Just keep a reference to
it, and don't clone the data. Especially since the LLDP library
keeps a reference to this instance as well.

Also, to compare whether two neighbors are the same, it is sufficient
to only consider the raw data. Everything else depends on these fields
anyway.

This is only possible and useful becuase sd_lldp_neighbor is of course
immutable. It wouldn't make sense otherwise, but it also would be bad
design to mutate the sd_lldp_neighbor instances.

This couples our code slightly more to the systemd code, which we usually
try to avoid. But when we move away in the future from systemd LLDP library,
we anyway need to rework this heavily (and then too, we wouldn't want
to clone the data, when we could just share the reference).
2020-06-11 16:51:46 +02:00
Thomas Haller
597e717659 lldp: track LLDP_ATTR_TYPE_ARRAY_OF_VARIANTS as array instead of CList
Allocating and growing the buffer with realloc isn't really
complicated. Do that instead of using a CList.

Also, if there is only one element, then we can track it in-place.
2020-06-11 16:49:27 +02:00
Thomas Haller
89795fbe3d lldp: rework _lldp_attr_id_to_name() to lookup by ID
NM_UTILS_LOOKUP_STR_DEFINE() is implemented via a switch statement.
You'd expect that the compiler could optimize that to plain lookup,
since all indexes are consecutive numbers. Anyway, my compiler doesn't,
so use the array ourself.

Note that NM_UTILS_LOOKUP_STR_DEFINE() is exactly intended to lookup
by enum/integer, if the enum values are not consecutive numbers. It may
not be best, when you can directly use the numbers as lookup index.
2020-06-11 16:49:27 +02:00
Thomas Haller
2aab266dac lldp: rename LLDP_ATTR_TYPE_VARDICT to LLDP_ATTR_TYPE_VARIANT
VARDICT sounds like it would be a variant of "a{sv}" type. But it
can be really any GVariant. Rename to make the type more generic.

This will be used to also hold a binary variant of type "ay".
2020-06-11 16:49:27 +02:00
Thomas Haller
9b7c5ca12d lldp: fix lldp_neighbor_equal() to compare variants
Fixes: 8200078ec5 ('lldp: support IEEE 802.3 TLVs')
2020-06-11 16:49:27 +02:00
Thomas Haller
7c0d73d94a lldp: fix lldp_neighbor_equal() to compare lists of variants
Fixes: 6c52d946fc ('lldp: add support for management address TLV')
2020-06-11 16:49:27 +02:00
Thomas Haller
8cd9b87c91 lldp: backslash escape untrusted chassis-id,port-id strings
This is a serious issue, because this is not guaranteed to be UTF-8
data.

Fixes: 07a9364d9c ('device: export list of LLDP neighbors through D-Bus')
2020-06-11 16:49:27 +02:00
Thomas Haller
2b52b003f8 lldp/tests: assert for expected GVariant when parsing LLDP neighbor
Currently the LLDP parsing code uses GVariantBuild, which possibly does not
ensure a stable order of elements. Thus the test may not be stable.

However, that will be fixed very soon.
2020-06-11 16:49:27 +02:00
Thomas Haller
2d50370e07 lldp/tests: add test for parsing LLDP frame 2020-06-11 16:49:27 +02:00
Thomas Haller
4aa657086e lldp/tests: assert for variant lookup in tests 2020-06-11 16:49:27 +02:00
Thomas Haller
393bc8c8f6 shared: add nm_utils_buf_utf8safe_escape_cp() helper 2020-06-11 16:49:26 +02:00
Thomas Haller
39127758bd shared: add nm_utils_ether_addr_equal(), nm_utils_ether_addr_cmp() 2020-06-11 12:00:52 +02:00
Thomas Haller
fce73b1c82 shared: add nm_g_variant_builder_add_sv_*() helpers 2020-06-11 12:00:52 +02:00
Thomas Haller
3f19c1fa52 shared/tests: add nmtst_assert_variant_bytestring() helper 2020-06-11 12:00:49 +02:00
Thomas Haller
82faec5875 supplicant: merge branch 'th/supplicant-config-verify'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/468

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/535
2020-06-11 11:06:41 +02:00
Thomas Haller
505aee6598 supplicant: use macros to initialize config options 2020-06-11 11:06:30 +02:00
Thomas Haller
4afd62246b supplicant: use binary search to lookup option in "nm-supplicant-settings-verify" 2020-06-11 11:06:30 +02:00
Thomas Haller
1fc1a40dd5 supplicant: remove unused str_allowed_multiple field from options 2020-06-11 11:06:30 +02:00
Thomas Haller
941277a9d6 supplicant: remove unused, duplicate "pac_file" entry from opt_table 2020-06-11 11:06:29 +02:00
Thomas Haller
97f5c684dc supplicant: rename OptType enum to have "NM" prefix
Names in header files should have a "NM" prefix. Rename.
2020-06-11 11:06:29 +02:00
Thomas Haller
f2f82c13b5 supplicant: move strv lists into option meta data
Have the string list definition closer to the option where it is used.
2020-06-11 11:06:29 +02:00
Thomas Haller
03b3e0bfd6 supplicant: nicer align code in "nm-supplicant-settings-verify.c"
Yes, fewer lines of code is often better, if that means the code itself is
simpler. Code doesn't get simpler by cramping more in the same line.
Have every value on a separate line.

Also, vertically align the table.
2020-06-11 11:06:29 +02:00
Thomas Haller
e7a74721be supplicant: fix verification of key_mgmt config for FT-FILS-SHA{256,384}
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/468

Fixes: d17a0a0905 ('supplicant: allow fast transition for WPA-PSK and WPA-EAP')
2020-06-11 11:06:19 +02:00
Thomas Haller
8a78b15c9b docs: merge branch 'th/nm-settings-manual'
This is a first step to improve our manual pages ([1]).

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1614726

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/528
2020-06-11 10:54:04 +02:00
Thomas Haller
10020a9466 docs: generate nm-settings-docs-nmcli.xml based on nmcli meta data
We have the correct meta-data of supported properties for nmcli. It is
in clients/common. Use that for generating the manual page instead of
the properties that are part of libnm (some properties may be in libnm
but not supported by nmcli, or some properties may not be GObject
properties, and not detected as by GObject introspection).
2020-06-11 10:53:50 +02:00
Thomas Haller
87edf2f298 docs: move generate-docs scripts from "libnm/" to "tools/"
They are not only used in "libnm/" directory. Move to "tools/".
2020-06-11 10:53:50 +02:00
Thomas Haller
d2f8d5a4fa docs: move "nm-settings-docs-{dbus,nmcli}.xml" from "libnm/" to "man/"
"nm-settings-docs-nmcli.xml" will be generated by a tool that depends on
"clients/common/". The file should thus not be in libnm directory, otherwise
there is a circular dependency.

Move the file to "man/" directory.

For consistency, also move "nm-settings-docs-dbus.xml". Note that we
cannot move "nm-settings-docs-gir.xml" to "man/", because that one is
needed for building clients.
2020-06-11 10:53:50 +02:00
Thomas Haller
caa70a50d7 all: move "shared/nm-libnm-aux" to "libnm/nm-libnm-aux"
Like the previous commit. Move code that depends on libnm out
of shared to avoid circular dependency.

Also add a readme file explaining the reason for existence of
the helper library.
2020-06-11 10:53:50 +02:00
Thomas Haller
a9408e3497 all: move "shared/nm-libnm-core-aux" to "libnm-core/nm-libnm-core-aux"
Like the previous commit. Move code that depends on libnm-core out
of shared to avoid circular dependency.

Also add a readme file explaining the reason for existence of
the helper libraries nm-libnm-core-intern and nm-libnm-core-aux.
2020-06-11 10:53:50 +02:00
Thomas Haller
e17a067e68 all: move "shared/nm-libnm-core-intern" to "libnm-core/nm-libnm-core-intern"
The "shared" directory is used by libnm-core, it should thus only depend on
code that is in the "shared" directory. Otherwise there is a circular
dependency, and meson's subdir() does not work nicely.

Also, libnm-core is really part of (and also an extension of) libnm-core,
so it belongs there.

I guess, the original idea was that this is also an extension for libnm,
so another project could take these utility functions (by copying them
into their source tree) and use them. That is still possible, it's
just that the sources are no longer under the shared directory.

Also add a readme to explain the non-obvious meaning of these files.
2020-06-11 10:53:50 +02:00
Thomas Haller
b760dee8c8 all: move "shared/nm-keyfile" to "libnm-core/nm-keyfile"
Originally, these files were part of libnm-core and linked together.
However, that is a licensing violation, because the code is GPL-2.0+
licensed, while libnm-core also gets linked with libnm (it must thus
be LGPL-2.1+). The original intent behind moving the code to "shared/"
was to avoid the licensing issue, but also to prepare when we would add
a separate, GPL licensed libnm-keyfile. However, currently we hope to
be able to relicense the code, so that it actually could be exposed as
part of libnm. This is work in progress at ([1]).

[1] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/ ## 517

Anyway, the current directory layout is problematic. libnm-keyfile
depends on libnm-core, while libnm-core depends on code under shared.
That means, there is a circular dependency and meson's subdir() does
not work well.

Move the code.
2020-06-11 10:53:50 +02:00
Thomas Haller
98f3d68cbe docs: unify "nm-property-infos-*.xml" and "nm-settings-docs-*.xml" (root element)
There is no need that two XML files that essentially hold similar
information are fundamentally different. Make them more alike.
This way, we can use the same tools that operate on either of
these input files.
2020-06-11 10:53:50 +02:00
Thomas Haller
09f484ae9f docs: update documentation for nm-settings-nmcli manual 2020-06-11 10:53:49 +02:00