Commit graph

99 commits

Author SHA1 Message Date
Jan Vaclav
ec91aa3c70 libnm: add property_type argument to _nm_setting_property_define_direct_strv
The purpose of this is to allow overriding to_dbus_fcn and from_dbus_fcn when
necessary (such as for special behavior regarding a deprecated/aliased properties).
2024-03-11 11:42:19 +01:00
Jan Vaclav
8f9ed29e2c libnm: allow _nm_setting_property_define_direct_strv() to be used as expression
This is so that the resulting index can be used for aliasing properties.
2024-03-11 11:42:19 +01:00
Fernando Fernandez Mancera
ac4e63ddda ip: support dhcp-send-release in NMSettingIpConfig
Introduce a new option to NMSettingIpConfig. The new option is ternary
type being the default value set to disabled. When enabled,
NetworkManager will instruct the DHCP client to send RELEASE message
when IP addresses are being removed.
2024-03-06 11:14:16 +01:00
Íñigo Huguet
c31f31acbf nm-setting: implement direct_enum as GObject property of type int
(cherry picked from commit 260865b1ac)
2024-02-21 11:20:52 +01:00
Beniamino Galvani
e12e5a2ad4 libnm,nmcli: add ipvx.dhcp-dscp property
Currently the internal DHCP client sets traffic class "CS6" in the DS
field of the IP header for outgoing packets.

dhclient sets the field according to the definition of TOS (RFC 1349),
which was was deprecated in 1998 by RFC 2474 in favor of DSCP.

Introduce a new property IPvX.dhcp-dscp (currently valid only for
IPv4) to specify a custom DSCP value for DHCP backends that support it
(currently, only the internal one).

Define the default value to CS0, because:

 - section 4.9 of RFC 4594 specifies that DHCP should use the standard
   (CS0 = 0) service class;

 - section 3.2 says that class CS6 is for "transmitting packets
   between network devices (routers) that require control (routing)
   information to be exchanged between nodes", listing "OSPF, BGP,
   ISIS, RIP" as examples of such traffic. Furthermore, it says that:

     User traffic is not allowed to use this service class.  By user
     traffic, we mean packet flows that originate from user-controlled
     end points that are connected to the network.

- we got reports of some Cisco switches dropping DHCP packets because
  of the CS6 marking.

(cherry picked from commit fcd907e062)
2024-02-06 17:02:30 +01:00
Fernando Fernandez Mancera
513eda352e connection: deprecate NMSettingConnection autoconnect-slaves property
To embrace inclusive language, deprecate the NMSettingConnection
autoconnect-slaves property and introduce autoconnect-ports property.

(cherry picked from commit 194455660d)
2024-02-02 12:52:20 +01:00
Fernando Fernandez Mancera
37972c9fe2 setting: add property_type field to _nm_setting_property_define_direct_enum
In order to make _nm_setting_property_define_direct_enum more flexible,
this patch is introducing property_type argument to it. When set to NULL
it will set property_type to nm_sett_info_propert_type_direct_enum.

(cherry picked from commit b90dd247be)
2024-02-02 12:52:20 +01:00
Fernando Fernandez Mancera
411e7573a4 connection: deprecate the NMSettingConnection slave-type property
To embrace inclusive language, deprecate the NMSettingConnection
slave-type property and introduce port-type property.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2024-01-23 08:21:07 +01:00
Fernando Fernandez Mancera
00bc10b8c0 connection: deprecate the NMSettingConnection Master property
To embrace inclusive language, deprecate the NMSettingConnection Master
property and introduce Controller property.
2024-01-11 00:19:14 +01:00
Thomas Haller
76a84e11df
libnm: rework normalization of "wifi.mac-address-randomization"
The previous code is not entirely obvious, because as always,
verify() and normalize() must agree in what they are about to
do.

Make that clearer by adding _nm_setting_wireless_normalize_mac_address_randomization(),
which evaluates the desired settings. This is the used both by verify()
and normalize().
2023-12-18 18:54:08 +01:00
Thomas Haller
026c92c30d
libnm: use G_PARAM_EXPLICIT_NOTIFY for direct flags properties
For doing this, it's important to review that no set_property()
implementation exists, which now would miss to emit the notification.
2023-12-11 21:21:28 +01:00
Thomas Haller
dee0530087
libnm: use G_PARAM_EXPLICIT_NOTIFY for direct enum properties
For doing this, it's important to review that no set_property()
implementation exists, which now would miss to emit the notification.
2023-12-11 18:09:35 +01:00
Thomas Haller
37cb6885f7
libnm: use G_PARAM_EXPLICIT_NOTIFY for direct strv properties
For doing this, it's important to review that no set_property()
implementation exists, which now would miss to emit the notification.
2023-12-11 18:06:14 +01:00
Thomas Haller
ebb8602729
libnm: use G_PARAM_EXPLICIT_NOTIFY for direct bytes properties
For doing this, it's important to review that no set_property()
implementation exists, which now would miss to emit the notification.
2023-12-11 17:59:13 +01:00
Thomas Haller
ecff549ba9
libnm: use G_PARAM_EXPLICIT_NOTIFY for direct string properties
For doing this, it's important to review that no set_property()
implementation exists, which now would miss to emit the notification.
2023-12-11 17:56:20 +01:00
Thomas Haller
96c1c49998
libnm: use G_PARAM_EXPLICIT_NOTIFY for direct int64,uint64 properties
For doing this, it's important to review that no set_property()
implementation exists, which now would miss to emit the notification.
2023-12-11 17:44:00 +01:00
Thomas Haller
cd070d6546
libnm: use G_PARAM_EXPLICIT_NOTIFY for direct int32 properties
For doing this, it's important to review that no set_property()
implementation exists, which now would miss to emit the notification.
2023-12-11 13:10:54 +01:00
Thomas Haller
325a29ad43
libnm: use G_PARAM_EXPLICIT_NOTIFY for direct uint32 properties
For doing this, it's important to review that no set_property()
implementation exists, which now would miss to emit the notification.
2023-12-11 13:09:16 +01:00
Thomas Haller
4c31c73bf6
libnm: use G_PARAM_EXPLICIT_NOTIFY for direct boolean properties
Now that we require glib 2.42, we can use G_PARAM_EXPLICIT_NOTIFY flag.
The benefit is that this flag saves a notification, when the property
value does not change.

The downside is, that implementations of set_property() must remember to
emit _notify() when required. This is somewhat alleviated by using
_nm_setting_property_set_property_direct(), which does this
automatically.

Se the flag for G_PARAM_EXPLICIT_NOTIFY for direct boolean properties.
For now, only do it for boolean properties, because of the danger of
getting this wrong. We must review all callers to make sure that they
don't implement set_properties() and don't forget to notify.
2023-12-11 13:09:15 +01:00
Thomas Haller
13179a62d3
libnm: return property index from _nm_setting_property_define_direct_string()
We will need this, when we incrementally construct the list of properties.
2023-12-11 12:57:17 +01:00
Fernando Fernandez Mancera
e68bedd28d all: reformat code to clang shipped with Fedora 39 2023-12-06 10:37:24 +01:00
Thomas Haller
cf0b482f93
libnm: implement "{ipv4,ipv6}.dns-options" as direct STRV property
"nm_sett_info_propert_type_direct_strv" is the way, now STRV properties
should be implemented. Adjust the "dns-options" property..
2023-11-23 17:19:10 +01:00
Thomas Haller
8079e8969d
libnm: implement "ipv4.dhcp-reject-servers" as direct-strv property 2023-11-15 17:59:28 +01:00
Thomas Haller
4cd58207c1
libnm: implement "ipv4.dns-search" as direct-strv property 2023-11-15 17:59:27 +01:00
Thomas Haller
3435bc3011
libnm: move NMValueStrv definition in header 2023-11-15 17:59:26 +01:00
Thomas Haller
eb3b2d9ef6
libnm: initialize "name" in _nm_properties_override_gobj()
Previously, _nm_setting_class_commit() required that the "name" of a
NMSettInfoProperty is unset, when the property also has a "param_spec".
_nm_setting_class_commit() would then as first iterate over all
properties, and set the name.

In practice, all callers only initialize NMSettInfoProperty via
_nm_properties_override_gobj(). Now, let _nm_properties_override_gobj()
set the "name" right away.

Now _nm_setting_class_commit() will instead assert that the name is always
set, and that the caller takes care of that. That means, we have less to
do in _nm_setting_class_commit() (assertions aside).
2023-11-08 09:17:16 +01:00
Thomas Haller
907970d08b
libnm: add _nm_setting_property_define_gprop_strv_oldstyle() define
This will be used for adding G_TYPE_STRV properties. This is a legacy
approach, new properties should use _nm_setting_property_define_direct_strv(),
which is more efficient and where the meta-data knows more about the
strv property.

Will be used next.
2023-11-08 09:17:14 +01:00
Thomas Haller
aa63748379
libnm: reuse static property type for strv properties 2023-11-08 09:17:14 +01:00
Thomas Haller
53b532ffba
libnm: rework creating property info for "name"
The goal is to have the properties_overrides already pre-populated with
all properties. Then we will be able to drop special cases from
_nm_setting_class_commit().
2023-11-08 09:17:04 +01:00
Thomas Haller
bd8d49495b
libnm: embed private structure in NMSetting and avoid g_type_class_add_private()
Historically, the NMSetting types were in public headers. Theoretically,
that allowed users to subtype our classes. However in practice that was
impossible because they lacked required access to internal functions to
fully create an NMSetting class outside of libnm. And it also was not
useful, because you simply cannot extend libnm by subtyping a libnm
class. And supporting such a use case would be hard and limit what we can
do in libnm.

Having GObject structs in public headers also require that we don't
change it's layout. The ABI of those structs must not change, if anybody
out there was actually subclassing our GObjects.

In libnm 1.34 (commit e46d484fae ('libnm: hide NMSetting types from
public headers')) we moved the structs from headers to internal.
This would have caused a compiler error if anybody was using those
struct definitions. However, we still didn't change the ABI/layout so
that we didn't break users who relied on it (for whatever reason).

It doesn't seem there were any affected user. We waited long enough.
Change internal ABI.

No longer use g_type_class_add_private(). Instead, embed the private
structs directly (_NM_GET_PRIVATE()) or indirectly
(_NM_GET_PRIVATE_PTR()) in the object.

The main benefit is for debugging in the debugger, where we can now
easily find the private data. Previously that was so cumbersome to be
effectively impossible.

It's also the fastest possible way, since NM_SETTING_*_GET_PRIVATE()
literally resolves to "&self->_priv" (plus static asserts and
nm_assert() for type checking).

_NM_GET_PRIVATE() also propagates constness and requires that the
argument is a compatible pointer type (at compile time).

Note that g_type_class_add_private() is also deprecated in glib 2.58 and
replaced by G_ADD_PRIVATE(). For one, we still don't rely on 2.58. Also,
G_ADD_PRIVATE() is a worse solution as it supports a usecase that we
don't care for (public structs in headers). _NM_GET_PRIVATE() is still
faster, works with older glib and most importantly: is better for
debugging as you can find the private data from an object pointer.

For NMSettingIPConfig this is rather awkward, because all direct
properties require a common "klass->private_offset". This was however
the case before this change. Nothing new here. And if you ever touch
this and do something wrong, many unit tests will fail. It's almost
impossible to get wrong, albeit it can be confusing to understand.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1773
2023-10-31 11:29:37 +01:00
Fernando Fernandez Mancera
d2ca44ffc6 all: add new "ipv[46].replace-local-rule" setting
This setting allows the user to remove the local route rule that is
autogenerated for both IPv4 and IPv6. By default, NetworkManager won't
touch the local route rule.
2023-02-21 15:36:38 +01:00
Frederic Martinsons
4509c303fa
all: add new "ipv[46].auto-route-ext-gw" setting
For external gateway route management. This setting allows an user
to deactivate the automatic route addition to the external gateway.
It can be especially useful when a VPN inside another VPN is used.

Signed-off-by: Frederic Martinsons <frederic.martinsons@unabiz.com>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/204

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1491
2023-01-09 09:35:52 +01:00
Thomas Haller
71454ae4cd
libnm: make ref counting of immutable types thread safe
The types NMBridgeVlan, NMIPRoutingRule, NMRange, NMWireGuardPeer
are immutable (or immutable, after the seal() function is called).

Immutable types are great, as it means a reference to them can be shared
without doing a full clone. Hence the G_DEFINE_BOXED_TYPE() for these
types prefers to take a reference instead of cloning the objects. Except
for sealable types, where it will prefer to clone unsealed values.
Likewise, nm_simple_connection_new_clone() probably will just take
another reference to the value, instead of doing a deep clone.

libnm is not a thread-safe library in the sense that you could pass a
NMConnection or NMClient instance to multiple threads and access them
without your own synchronization. However, it should be possible that
multiple threads access (seemingly) distinct objects.

As the copy function of these boxed types (and nm_simple_connection_new_clone()
and similar) prefers to share the references to immutable types, it is important
that the ref function is thread-safe too. Otherwise you cannot just clone a
NMConnection on thread1, hand the clone to thread2 and operate on the
clone and the original independently. If you do before this patch, you would
hit a subtle race condition.

Avoid that. While atomic operations have a runtime overhead, being safe
is more important. Also, we already save a full malloc()/free() by
having immutable, ref-counted types. We just need to make it safe to use
in order to fully benefit from it.
2022-12-20 10:35:02 +01:00
Beniamino Galvani
b64e690db8 libnm: add ovs-port.trunks property
Add a new "ovs-port.trunks" property that indicates which VLANs are
trunked by the port.

At ovsdb level the property is just an array of integers; on the
command line, ovs-vsctl accepts ranges and expands them.

In NetworkManager the ovs-port setting stores the trunks directly as a
list of ranges.
2022-11-25 14:15:41 +01:00
Beniamino Galvani
041e38b151 libnm: add NMRange
The next commit is going to introduce a new object in libnm to
represent a range of ovs-port VLANs. A "range of integers" object
seems something that can be used for other purposes in the future, so
instead of adding an object specific for this case
(e.g. NMOvsPortVlanRange), introduce a generic NMRange object that
generically represents a range of non-negative integers.
2022-11-25 14:15:39 +01:00
Thomas Haller
991a20b4b2
libnm: fix comparing "ipv[46].dns" properties
nm_setting_diff() ends up calling the compare_fcn() hook. Previously,
the hook for "dns" was _nm_setting_property_compare_fcn_default()
and the hook for "dns-data" was _nm_setting_property_compare_fcn_ignore().

That's wrong. _nm_setting_property_compare_fcn_default() converts
the property to D-Bus and compares the GVariant. However, "dns" has
to_dbus_only_in_manager_process set, so it wouldn't

Fixes: 63eaf168d1 ('libnm: add "dns-data" replacement for "ipv[46].dns" properties on D-Bus')
2022-10-28 17:54:15 +02:00
Thomas Haller
c8392018ca
libnm: refactor to-dbus on the client skipping to serialize legacy properties
We have 4 legacy properties ("ipv[46].addresses", "ipv[46].routes") that
got replaced by newer variants ("ipv[46].address-data", "ipv[46].route-data").

When the client side of libnm (_nm_utils_is_manager_process) serializes
those properties, it must only serialize the newer version. That is so
that the forward/backward compatibility works as intended.

Previously, there was the NM_SETTING_PARAM_LEGACY GObject property flag.
That was fine, but not very clear.

For one, the legacy part of those properties is only about D-Bus. In
particular, they are not deprecated in libnm, keyfile, or nmcli. Thus
the name wasn't very clear.

Also, in the meantime we have more elaborate property meta data, that
goes beyond the meta data of the GObject property.

Move NM_SETTING_PARAM_LEGACY to NMSettInfoProperty.to_dbus_only_in_manager_process.
I think, this is a better name. It's also right at

```
     _nm_properties_override_gobj(
         properties_override,
         g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ROUTES),
         NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("a(ayuayu)"),
                                        .to_dbus_fcn   = ip6_routes_to_dbus,
                                        .compare_fcn   = _nm_setting_ip_config_compare_fcn_routes,
                                        .from_dbus_fcn = ip6_routes_from_dbus, ),
         .to_dbus_only_in_manager_process = TRUE,
         .dbus_deprecated                 = TRUE, );
```

that is, directly at the place where we describe how the D-Bus property behaves.
2022-10-27 09:11:24 +02:00
Thomas Haller
bb9a9b8ee1
libnm: add extra arguments to _nm_properties_override_dbus() 2022-10-27 09:11:22 +02:00
Thomas Haller
e94abbc465
libnm: rename internal to/from dbus functions 2022-10-27 09:11:21 +02:00
Alexander Elbs
2eccb21b8e
core: move rerequest decision of secrets to NMSetting
When an authentication attempt fails, NetworkManager re-requests new secrets
from agents before retrying. This is currently decided outside of the NMSetting
objects. With this change the decision if a re-request of new secrets is really
needed is moved down to the NMSetting implementations.

For the case "802.1x authentication with TLS" a certificate with password is
configured and the assumption is, that this can never be wrong and no re-request
is needed.
2022-10-25 08:40:09 +02:00
Thomas Haller
844d03bb12
libnm: embed address family in NMSettingIPConfigClass for NM_SETTING_IP_CONFIG_GET_ADDR_FAMILY()
The G_TYPE_INSTANCE_GET_CLASS() macro is just one pointer dereference
(self)->g_class, plus additional assertions with debug builds.

As such, it is as fast as it gets. Embed the address family there, and
implement NM_SETTING_IP_CONFIG_GET_ADDR_FAMILY() that way.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1395
2022-10-06 13:46:18 +02:00
Thomas Haller
a1ab9d9e1c
libnm: use NMRefString for nm_connection_get_path()
NMConnection is an interface, implemented by NMSimpleConnection and
NMRemoteConnection.

For the most part, an NMConnection is only the content of the profile
(the settings). The "path" of the connection refers to the D-Bus path,
and wouldn't really make sense of the NMConnection interface or the
NMSimpleConnection type.

As such, the daemon (which only uses NMConnection and
NMSimpleConnection) never sets the path. Only libnm does.

NMClient uses NMRefString extensively for the D-Bus interface and the
path is already internalized. Take advantage of that. It is very likely,
that we are able to share the path instance in libnm at which point it
makes sense to use NMRefString.

Also, during nm_simple_connection_new_clone(), we can just take another
reference instead of cloning the string.
2022-10-06 13:43:33 +02:00
Thomas Haller
d75bfd3a3d
libnm: move optimized NM_IS_{SIMPLE,}CONNECTION() to internal header
We already redefine those checks to optimize for NMSimpleConnection.
Which, in particular when libnm-core is used by the daemon, is the only
implementation of the NMConnection interface.

Move those to the private header file. No need to keep it private to
"nm-connection.c".
2022-10-03 17:54:57 +02:00
Thomas Haller
28cb407056
libnm: rework lookup of private data for NMConnection of NMSimpleConnection
NMConnection is an interface, and as such has no data itself.

In practice, there are only two implementations of this interface,
NMSimpleConnection and NMRemoteConnection. The latter only exists
in libnm, not the daemon.

Thus, lookup of the private data is already optimized for
NMSimpleConnection instances via _nm_simple_connection_private_offset.

Use the same mechanism also for NMSimpleConnection itself.
2022-10-03 17:54:56 +02:00
Thomas Haller
61ff2b03df
libnm: add direct strv type for NMSetting and use it for "match.interface-name"
G_TYPE_STRV is the last property type in NMSetting that is implemented
by directly accessing the GObect property. Note that we have lots of
override, non-default implementations that still use GObject properties,
but I am talking here about properties that don't have a special
implementation and use a G_TYPE_STRV GObject property.

Add a "direct" implementation also for strv arrays.

The advantage is that we no longer call g_value_get() for various
operations, which requires a deep-copy of the strv array. The other
advantage is that we will get a unified approach for implementing strv
properties. In particular strv arrays need a lot of code to implement,
and most settings do it differently. By adding a general mechanism,
this code (and behavior) can be unified.

Showcase it on "match.interface-name".
2022-02-10 22:30:27 +01:00
Thomas Haller
72e523830c
libnm: refactor some NMSetting to use direct properties for string 2022-01-18 16:22:28 +01:00
Thomas Haller
20d6793065
libnm: refactor some NMSetting to use direct properties for uint32 2022-01-18 16:22:25 +01:00
Thomas Haller
208df83491
libnm: refactor some NMSetting to use direct properties for int32 2022-01-18 16:22:24 +01:00
Thomas Haller
710c54760c
libnm: add direct property type "int64" 2022-01-18 16:22:18 +01:00
Ana Cabral
f0cb75f669 trivial: fix typos 2022-01-10 22:48:30 +00:00