Commit Graph

268 Commits

Author SHA1 Message Date
Thomas Haller
c0bc296a51 platform: use NMOptionBool instead of NMTernary
NMTernary is a dependency for libnm-core. Avoid it.
2021-01-15 11:32:49 +01:00
Thomas Haller
0dc5ea2412 shared: add NMOptionBool as alternative to NMTernary
NMTernary is part of libnm's public API. It thus cannot be used by code
without libnm/libnm-core dependency.

Add another enum with the same purpose.

The name "NMTernary" is already taken, and we should not use some macro
trickery to use (effectively) different types under the same name.
Another possible name would be "NMTern", but for no strong reasons
we choose NMOptionBool. The naming reminds of rust's std::option::Option.
2021-01-15 11:32:46 +01:00
Thomas Haller
2bb5c8b13b platform: add duplicate of NMSettingWiredWakeOnLan to nm-base for platform
Currently src/platform depends on libnm-core. libnm-core is large
optimally we have a better separation between our code. That means
libnm-core does not depend on platform and vice versa.

However, nm-platform re-uses some enums from libnm-core for internal code.
To avoid that dependency, add _NMSettingWiredWakeOnLan as a duplicate to
nm-base/nm-base.h. nm-base can both be used by libnm-core, nm-platform
and src/platform.

The only problem is that NMSettingWiredWakeOnLan is also part of public
API of libnm. It means, we must duplicate the enum. But with several
static assertions in unit tests I think that is not a problem to do.
2021-01-15 11:32:33 +01:00
Thomas Haller
977ea352a0 all: update deprecated SPDX license identifiers
These SPDX license identifiers are deprecated ([1]). Update them.

[1] https://spdx.org/licenses/

  sed \
     -e '1 s%^/\* SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+ \*/$%/* SPDX-License-Identifier: \1-or-later */%' \
     -e '1,2 s%^\(--\|#\|//\) SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+$%\1 SPDX-License-Identifier: \2-or-later%' \
     -i \
     $(git grep -l SPDX-License-Identifier -- \
         ':(exclude)shared/c-*/' \
         ':(exclude)shared/n-*/' \
         ':(exclude)shared/systemd/src' \
         ':(exclude)src/systemd/src')
2021-01-05 09:46:21 +01:00
Fernando Fernandez Mancera
cd0cf9229d veth: add support to configure veth interfaces
NetworkManager is now able to configure veth interfaces throught the
NMSettingVeth. Veth interfaces only have "peer" property.

In order to support Veth interfaces in NetworkManager the design need
to pass the following requirements:

 * Veth setting only has "peer" attribute.
 * Ethernet profiles must be applicable to Veth interfaces.
 * When creating a veth interface, the peer will be managed by
   NetworkManager but will not have a profile.
 * Veth connection can reapply only if the peer has not been modified.
 * In order to modify the veth peer, NetworkManager must deactivate the
   connection and create a new one with peer modified.

In general, it should support the basis of veth interfaces but without
breaking any existing feature or use case. The users that are using veth
interfaces as ethernet should not notice anything changed unless they
specified the veth peer setting.

Creating a Veth interface in NetworkManager is useful even without the
support for namespaces for some use cases, e.g "connecting one side of
the veth to an OVS bridge and the other side to a Linux bridge" this is
done when using OVN kubernetes [1][2]. In addition, it would provide
persistent configuration and rollback support for Veth interfaces.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1885605
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1894139

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-11-27 10:12:36 +01:00
Beniamino Galvani
abd002642f all: add hostname setting
Add a new setting that contains properties related to how NM should
get the hostname from the connection.
2020-11-16 16:43:39 +01:00
Thomas Haller
6100b52e5c libnm: add NMSettingOvsExternalIDs 2020-11-09 17:53:15 +01:00
Thomas Haller
88071abb43 all: unify comment style for SPDX-License-Identifier tag
Our coding style recommends C style comments (/* */) instead of C++
(//). Also, systemd (which we partly fork) uses C style comments for
the SPDX-License-Identifier.

Unify the style.

  $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
2020-09-29 16:50:53 +02:00
Thomas Haller
740b092fda format: replace tabs for indentation in code comments
sed -i \
     -e 's/^'$'\t'' \*/     */g' \
     -e 's/^'$'\t\t'' \*/         */g' \
     -e 's/^'$'\t\t\t'' \*/             */g' \
     -e 's/^'$'\t\t\t\t'' \*/                 */g' \
     -e 's/^'$'\t\t\t\t\t'' \*/                     */g' \
     -e 's/^'$'\t\t\t\t\t\t'' \*/                         */g' \
     -e 's/^'$'\t\t\t\t\t\t\t'' \*/                             */g' \
     $(git ls-files -- '*.[hc]')
2020-09-28 16:07:52 +02:00
Antonio Cardace
328fb90f3e all: reformat all with new clang-format style
Run:

    ./contrib/scripts/nm-code-format.sh -i
    ./contrib/scripts/nm-code-format.sh -i

Yes, it needs to run twice because the first run doesn't yet produce the
final result.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-28 16:07:51 +02:00
Thomas Haller
dea59122e7 shared: move nm_utils_hwaddr_ntoa_buf() to shared/ as _nm_utils_hwaddr_ntoa()
The name is better as it mirrors nm_utils_hwaddr_aton(). Also, move
it to shared/ so it can be reused (and inlined).
2020-09-23 13:57:37 +02:00
Thomas Haller
74c03da086 shared: move _nm_utils_hwaddr_aton() to shared/
_nm_utils_hwaddr_aton() is only a wrapper around nm_utils_hexstr2bin_full().
But it abstracts the "right" parameters for what we consider a valid MAC
address and what not. As such, this function is useful.

Move it to "shared/" and replace the dupicate macro hwaddr_aton() with
it.
2020-09-23 13:57:04 +02:00
Thomas Haller
e8e5c12480 libnm: hide nm_setting_ip_config_next_valid_dns_option() function from headers
nm_setting_ip_config_next_valid_dns_option() API was added in libnm 1.2, but
it was never exported in the ABI of libnm. It thus was unusable, and any user
trying to link against it would have been unable to do so.

Hide the API now entirely. It doesn't seem a very nice API. If we want to
allow the user to validate option names, we should expose such a function
to validate an option (not to fetch the next valid option from a
profile).

Fixes: 019943bb5d ('libnm-core: add dns-options property to NMSettingIPConfig')
2020-09-22 18:04:11 +02:00
Sayed Shah
58847f85a4 platform: use netlink for configuring bridge settings
NMDeviceBridge is currently using sysfs. The plan is to use netlink in
in the future
2020-08-20 14:03:10 -04:00
Sayed Shah
80c93b0e5e platform: add support for configuring bridge settings via netlink (2)
NMDeviceBridge is currently using sysfs. The plan is to use netlink in
in the future.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/601
2020-08-14 21:26:10 +02:00
Sayed Shah
adf0420258 platform: add support for configuring bridge settings via netlink
NMDeviceBridge is currently using sysfs. The plan is to use netlink in
in the future
2020-08-07 13:20:54 +02:00
Thomas Haller
b17e3cf707 all: add trailing semicolon to NM_AUTO_DEFINE_FCN_*() uses 2020-07-19 12:01:56 +02:00
Thomas Haller
a0b22b5b40 libnm: add _nm_setting_bond_mode_from_string() to nm-libnm-core-intern 2020-07-11 11:18:55 +02:00
Thomas Haller
f7715c6680 libnm: use NMStrBuf in "nm-setting-bridge.c" 2020-06-26 09:29:53 +02:00
Antonio Cardace
5d0d13f570 platform: add support for local routes
Also update unit tests.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/407
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-06-16 10:01:22 +02:00
Thomas Haller
49db9d8d78 libnm: add nm_setting_option_clear_by_name()
More general purpose API for generic options of settings.

The predicate function is also nicely usable via bindings.

One question is about the form of the predicate. In this case,
it is convenient to pass nm_ethtool_optname_is_coalesce(). On the
other hand, it's not very flexible as it does not accept a user
data argument. Use NMUtilsPredicateStr here, which is not flexible
but convenient for where it's used.
2020-05-22 15:58:09 +02:00
Thomas Haller
1a56a2105c libnm: add nm_setting_option_get_names()
More general purpose API for generic options of settings.
2020-05-22 15:58:09 +02:00
Thomas Haller
150af44e10 libnm: add nm_setting_option_get_uint32(), nm_setting_option_set_uint32()
More general purpose API for generic options of settings.
2020-05-22 15:58:09 +02:00
Thomas Haller
9655dff5cb libnm: add API for setting gendata options to NMSetting (nm_setting_option_get())
NMSettingEthtool is implemented using "gendata", meaning a hash
of GVariant. This is different from most other settings that have
properties implemented as GObject properties. There are two reasons
for this approach:

  - The setting is transferred via D-Bus as "a{sv}" dictionary.
    By unpacking the dictionary into GObject properties, the setting
    cannot handle unknown properties. To be forward compatible (and
    due to sloppy programming), unknown dictionary keys are silently
    ignored when parsing a NMSetting. That is error prone and also
    prevents settings to be treated loss-less.
    Instead, we should at first accept all values from the dictionary.
    Only in a second step, nm_connection_verify() rejects invalid settings
    with an error reason. This way, the user can create a NMSetting,
    but in a separate step handle if the setting doesn't verify.
    "gendata" solves this by tracking the full GVariant dictionary.
    This is still not entirely lossless, because multiple keys are
    combined.
    This is for example interesting if an libnm client fetches a connection
    from a newer NetworkManager version. Now the user can modify the
    properties that she knows about, while leaving all unknown
    properties (from newer versions) in place.

  - the approach aims to reduce the necessary boiler plate to create
    GObject properties. Adding a new property should require less new code.

This approach was always be intended to be suitable for all settings, not only
NMSettingEthtool. We should not once again try to add API like
nm_setting_ethtool_set_feature(), nm_setting_ethtool_set_coalesce(), etc.
Note that the option name already fully encodes whether it is a feature,
a coalesce option, or whatever. We should not have
"nm_setting_set_$SUB_GROUP (setting, $ONE_NAME_FROM_GROUP)" API, but
simply "nm_setting_option_set (setting, $OPTION)" accessors.

Also, when parsing a NMSettingEthtool from a GVariant, then a feature
option can be any kind of variant. Only nm_setting_verify() rejects
variants of the wrong type. As such, nm_setting_option_set*() also
doesn't validate whether the variant type matches the option. Of course,
if you set a value of wrong type, verify() will reject the setting.

Add new general purpose API for this and expose it for NMSetting.
2020-05-22 15:58:08 +02:00
Thomas Haller
618ae93b94 libnm: rename nm_setting_gendata_*() API to nm_setting_option_*()
We are going to expose some of this API in libnm.

The name "gendata" (for "generic data") is not very suited. Instead,
call the public API nm_setting_option_*(). This also brings no naming
conflict, because currently no API exists with such naming.

Rename the internal API, so that it matches the API that we are going
to expose next.
2020-05-22 15:58:08 +02:00
Thomas Haller
bfe05b48f2 libnm: drop unused internal API _nm_setting_gendata_reset_from_hash() and _nm_setting_gendata_to_gvalue()
This was intended for when the gendata hash should be converted
to/from a GValue/GHashTable. This would have been used, if
we also would have added a GObject property that exposes
the hash. But that was never done (at least not for NMSettingEthtool
and not yet).

This code is not used. If you ever need it, revert the patch
or implement it anew.
2020-05-22 15:58:08 +02:00
Thomas Haller
34fc68f20a libnm: drop unused internal function nm_setting_gendata_get_all_values()
This function is not used nor does it seem useful.

Either you only need the names (nm_setting_gendata_get_all_names())
or you need the names and values together (_nm_setting_gendata_get_all()).
Getting the values without knowing the corresponding name makes
little sense. If you need it, call _nm_setting_gendata_get_all()
instead.
2020-05-22 15:58:08 +02:00
Antonio Cardace
e08c3a6e18 nm-setting: add internal gendata API to clear value(s)
The filter function in nm_setting_gendata_clear_all() is useful
for when you want to only clear values according to a predicate,
if no such function is supplied all values will be cleared.

https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-20 10:55:01 +02:00
Antonio Cardace
572f82a77b nm-setting: add internal gendata API to get/set uint32
https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-20 10:55:01 +02:00
Beniamino Galvani
48c93b3bba libnm-core: add _nm_ip_tunnel_mode_is_layer2() 2020-05-15 09:48:25 +02:00
Thomas Haller
42288df043 libnm: adjust bridge defines NM_BRIDGE_VLAN_DEFAULT_PVID_DEF 2020-05-08 08:02:51 +02:00
Thomas Haller
bfcfdc2955 libnm: adjust bridge defines NM_BRIDGE_VLAN_STATS_ENABLED_DEF 2020-05-08 08:02:51 +02:00
Thomas Haller
f34144f70b libnm: adjust bridge defines NM_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL_* 2020-05-08 08:02:51 +02:00
Thomas Haller
55311c6a6a libnm: adjust bridge defines NM_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT_* 2020-05-08 08:02:51 +02:00
Thomas Haller
433bb1fbe4 libnm: adjust bridge defines NM_BRIDGE_MULTICAST_SNOOPING_DEF 2020-05-08 08:02:50 +02:00
Thomas Haller
96bb90a1ef libnm: adjust bridge defines NM_BRIDGE_MULTICAST_QUERY_USE_IFADDR_DEF 2020-05-08 08:02:50 +02:00
Thomas Haller
0db1d28e6d libnm: adjust bridge defines NM_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL_* 2020-05-08 08:02:50 +02:00
Thomas Haller
58001f70e8 libnm: adjust bridge defines NM_BRIDGE_MULTICAST_QUERY_INTERVAL_* 2020-05-08 08:02:50 +02:00
Thomas Haller
08cfe812ec libnm: adjust bridge defines NM_BRIDGE_MULTICAST_QUERIER_DEF 2020-05-08 08:02:50 +02:00
Thomas Haller
da6bbd73aa libnm: adjust bridge defines NM_BRIDGE_MULTICAST_QUERIER_INTERVAL_* 2020-05-08 08:02:50 +02:00
Thomas Haller
a75ec12d8b libnm: adjust bridge defines NM_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL_* 2020-05-08 08:02:50 +02:00
Thomas Haller
ec9e58ee01 libnm: adjust bridge defines NM_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL_* 2020-05-08 08:02:50 +02:00
Thomas Haller
769b176263 libnm: adjust bridge defines NM_BRIDGE_MULTICAST_LAST_MEMBER_COUNT_* 2020-05-08 08:02:50 +02:00
Thomas Haller
4c3691e52e libnm: adjust bridge defines NM_BRIDGE_PORT_PATH_COST_* 2020-05-08 08:02:49 +02:00
Thomas Haller
a7421f8bf2 libnm: adjust bridge defines NM_BRIDGE_PORT_PRIORITY_* 2020-05-08 08:02:49 +02:00
Thomas Haller
a690cedcba libnm: adjust bridge defines NM_BRIDGE_PRIORITY_* 2020-05-08 08:02:49 +02:00
Thomas Haller
e2cb0837cc libnm: adjust bridge defines NM_BRIDGE_MAX_AGE_* 2020-05-08 08:02:49 +02:00
Thomas Haller
d7dd4c70d0 libnm: adjust bridge defines NM_BRIDGE_HELLO_TIME_* 2020-05-08 08:02:49 +02:00
Thomas Haller
696fae40b7 libnm: adjust bridge defines NM_BRIDGE_STP_DEF 2020-05-08 08:02:49 +02:00
Thomas Haller
8ee4dbf709 libnm: adjust bridge defines NM_BRIDGE_FORWARD_DELAY_* 2020-05-08 08:02:49 +02:00