Commit graph

31361 commits

Author SHA1 Message Date
Lubomir Rintel
aaa9a9cd25 libnm/client: don't reset properties when interface goes away
In case the D-Bus interfaces start dropping off (typically all off them go
one by one when the object is being deleted), don't reset all the properties.

In particular, keep most properties around, only tear down "o" and "ao",
so that the object dependencies get torn down, but we still get enough
properties around to identify what the dead object was its heyday.

One example of where this is not good is when the device-removed signal
is emmitted, the device no longer has the ifname:

  $ nmcli monitor
  <quit NetworkManager>
  (null): device removed
  (null): device removed
  ...
2022-11-13 15:25:19 +01:00
Lubomir Rintel
8b3cb0dabf libnm/client/test: test cleanup on service shutdown
Currently we assert that properties are reset on client teardown. That
is not the right thing to do and we're not going to do that in future.

However, what is important to test is that the properties are reset when
the daemon goes away. Test that.
2022-11-13 15:25:16 +01:00
Lubomir Rintel
d3490a92db libnm/client/test: always run the cleanup test
The part where a device was created and its cleanup on client
description was only run randomly.

This is silly and gave me hard time. No reason not to be always running
it.
2022-11-13 15:25:11 +01:00
Lubomir Rintel
253bb3579f tests/client: test nmcli monitor
Some basic tests for nmcli monitor. Note that they now assert against
behavior that I find incorrect. Will be fixed separately.
2022-11-13 15:25:01 +01:00
Lubomir Rintel
fe2eddd67c nmcli/monitor: always print running status on monitor startup
Previously we'd note if NM is stopped, but not if it's running.
I suppose it's nice for the user to know that the monitor started
running, but, it's also important for the monitor to be testable (so
that we know that we are ready to start adding mock objects, etc.)

This also gets rids of some duplication at expense of a little less
nuanced message.
2022-11-13 15:24:19 +01:00
Lubomir Rintel
777f31436c merge: branch 'lr/unbreak-gir'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1451
2022-11-11 16:08:17 +01:00
Thomas Haller
9ecb72ae4b
libnm/trivial: fix style
Fixes: 412a5d2d08 ('libnm: show ethtool options in "gen-metadata-nm-settings-libnm-core.xml"')
2022-11-10 14:41:38 +01:00
Thomas Haller
954ca6b411
ifcfg-rh: merge branch 'th/ethtool-ifcfg-fixes'
https://bugzilla.redhat.com/show_bug.cgi?id=2134569

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1452
2022-11-10 13:48:25 +01:00
Thomas Haller
c593834842
core: filter out invalid Wake-On-Lan flags
NMSettingWired does not reject invalid flags. Filter them out in wake_on_lan_enable().
In practice, it makes no difference, the unknown flags were ignored anyway.
2022-11-10 13:46:35 +01:00
Thomas Haller
4303d33727
ifcfg-rh: fix persisting all-default NMSettingEthtool with autoneg/wol flags
Fixes: 26ed9e6714 ('ifcfg-rh: fix persisting all-default NMSettingEthtool settings')
2022-11-10 13:46:34 +01:00
Thomas Haller
21661c6f71
ifcfg-rh: fix persisting ethtool options
If there were any pause options and any non-pause options,
the created setting was invalid.

I don't think it's reasonably possible to parse the broken settings.
So there is no workaround trying to read the existing broken settings
from disk. Luckily, the broken setting was just silently ignored by
the parser, so you simply could not persist certain settings.

https://bugzilla.redhat.com/show_bug.cgi?id=2134569

Fixes: 652ddca04c ('ethtool: Introducing PAUSE support')
2022-11-10 13:45:43 +01:00
Thomas Haller
3755e6b175
ifcfg-rh/tests: add test checking persisting ethtool settings to ifcfg-rh
There are still various failures. That will be fixed next.
2022-11-10 13:44:58 +01:00
Thomas Haller
8e4296a487
libnm: merge branch 'th/libnm-metadata-xml-ethtool'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1453
2022-11-10 13:33:42 +01:00
Thomas Haller
412a5d2d08
libnm: show ethtool options in "gen-metadata-nm-settings-libnm-core.xml" 2022-11-10 13:00:50 +01:00
Thomas Haller
171f2c4ce3
libnm: skip "name" property for "gen-metadata-nm-settings-libnm-core.xml" 2022-11-10 09:36:53 +01:00
Thomas Haller
a0370e0efa
ethtool: add and use nm_ethtool_id_get_variant_type() helper 2022-11-10 09:36:53 +01:00
Thomas Haller
7f22835328
wwan/ofono: merge branch 'peat-psuwit:for-upstream/mr773-plus'
https://bugs.launchpad.net/bugs/1565717
https://bugs.launchpad.net/bugs/1579098
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/771
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/773

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1392
2022-11-10 07:56:28 +01:00
Ratchanan Srirattanamet
e34e38e744
wwan/ofono: cleanup comments and warnings in existing code 2022-11-10 07:54:24 +01:00
Ratchanan Srirattanamet
61e99ed715
wwan/ofono: fix memory leak in handle_settings()
[thaller@redhat.com: modified original patch.]

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-11-10 07:54:10 +01:00
Ratchanan Srirattanamet
f0ef4a440f
wwan/device-modem: re-check device availability after enable
It's possible that the modem is enabled outside of NM. If not
re-check, device could stay disabled throughout until something else
about the modem changes again.
2022-11-10 07:44:59 +01:00
Ratchanan Srirattanamet
2f3a0eaa0b
wwan/modem: return early if set_mm_enable is not implemented
We don't want to e.g. pre-empt the state change signal, because it's not
gonna happen.
2022-11-10 07:44:59 +01:00
Ratchanan Srirattanamet
580453d376
wwan/device-modem: disabled but not enable-able modem is unavailable
If a modem is disabled, and it has no method to enable it, then by no
mean it's "available" to NM.
2022-11-10 07:44:58 +01:00
Ratchanan Srirattanamet
f914df4f79
wwan/ofono: avoid bogus IP failure when not connecting
If modem is not at least "registered", a connection is not happening, which
means IP settings change is probably not interesting. Avoid trying to
parse it, so that we don't trigger connection failure when there isn't
one.
2022-11-10 07:44:58 +01:00
Ratchanan Srirattanamet
e7809a2bd7
wwan/ofono: clear current_octx on disconnect
This way, we won't signal failure when "PropertyChanged" signal for an
empty "Settings" eventually arrive.
2022-11-10 07:44:57 +01:00
Ratchanan Srirattanamet
5abc6f5911
wwan/ofono: also recognize connman's "Powered" property
This property "controls [oFono] whether packet radio use is allowed". It
makes sense to consider the value of FALSE to mean DISABLED.
2022-11-10 07:44:57 +01:00
Ratchanan Srirattanamet
ffbb8d2f51
wwan/ofono: when connect while searching, wait a bit
We don't have to outright refuse to connect if we're not registered.
Instead, wait up to 60 seconds for modem to register.
2022-11-10 07:44:56 +01:00
Bhushan Shah
9fc72bf75d
wwan/ofono: create connections based on available contexts
Downstream patches for this does it through NMSettings plugin, however
settings plugin are hard to maintain and complicated architecture wise
as well.

So directly create a connection profiles in-memory from the
nm-modem-ofono side. Those profiles are created in /run, and are not
added as a persistent connection, because connection state quite depends
on the state of ofono

This also allows us to drop the hack where we are keeping track of
active context/APN through the connection name, i.e if connection name
was in /imsi/context1 format, it was used. Instead now, Connection name
is actual context name which is user friendly ("Vodafone Connect" e.g.
in my case), and details like IMSI and context are stored internally.

[ratchanan@ubports.com:
- forward-ported to main branch.
- fold "wwan/ofono: handle context removal" into this commit.
- track the "preferred"-ness of the context and react accordingly.
  Creates proxies for all retrived contexts to listen to changes.
  While at it, also track name and type.
- use, instead of ignore, internet APN. Also support internet+mms APN.
- correct priv->contexts' value destroy function.
- factor out UUID generation as a helper function.
- handle the case where context dictionary is missing required keys.
- simplify nm_ofono_connection_new's arguments and rename to
  add_or_update_connection. Makes it handle the case where the
  connection already exists.
- also simplify other functions' arguments.
- clean up code and comments. Fix memory problems. Get rid of warnings.
]

Co-authored-by: Ratchanan Srirattanamet <ratchanan@ubports.com>
2022-11-10 07:44:56 +01:00
Thomas Haller
9e2ff9dabd
libnm: merge branch 'th/more-libnm-metadata-xml'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1449
2022-11-09 11:19:13 +01:00
Lubomir Rintel
133540763c libnm: test that Gir data matches actual exports
This verifies that what's in our public headers has version nodes, and
that they match Since: tags.

Not pretty (because python) but discovered a *lot* of issues.
2022-11-08 13:14:56 +01:00
Thomas Haller
112a399a17
libnm: add nm_utils_ensure_gtypes() helper to API
"gen-metadata-nm-settings-libnm-core.xml" now contains also the names of
the NMSetting types, like "NMSettingConnection". That can be useful
to create NMSetting instances generically (that is, without knowing
the C API that gets called).

So you might be tempted to run

    #!/bin/python

    import gi

    gi.require_version("NM", "1.0")
    from gi.repository import GObject, NM

    connection = NM.SimpleConnection()

    # NM.utils_ensure_gtypes()

    gtype_name = "NMSetting6Lowpan"
    gtype = GObject.type_from_name(gtype_name)
    setting = GObject.new(gtype)

    connection.add_setting(setting)

However, without NM.utils_ensure_gtypes() that would not work, because
the GType is not yet created. For a user who doesn't know a priory all
setting types, it's not entirely clear how to make this work. Well, a
GObject introspection user could iterate over al NM.Setting* names and
try to instantiate the classes. However, that is still cumbersome, and not
accessible to a C user (without GI) and the currently loaded libnm
library may be newer and have unknown setting types.

In particular plain C user would need to know to call all the right
nm_setting_*_get_type(), functions, so it needs to know all the existing
52 type getters (and cannot support those from a newer libnm version).

With nm_utils_ensure_gtypes(), the user can get the typename and create
instances generically only using g_type_from_name().

Possible alternatives:

 - libnm also has _nm_utils_init() which runs as __attribute__((constructor)).
   We could also always instantiate all GType there. However, I don't like running
   non-trivial, absolutely necessary code before main().
 - hook nm_setting_get_type() to create all GType for the NMSetting
   subclasses too. The problem is, that it's not entirely trivial to
   avoid deadlock.
 - hook nm_connection_get_type() to create all NMSetting types. That
   would not deadlock, but it still is questionable whether we should
   automatically, at non-obvious times instantiate all GTypes.
2022-11-08 13:13:59 +01:00
Thomas Haller
fd2d66953c
libnm: show NMSetting gtype in "gen-metadata-nm-settings-libnm-core.xml" 2022-11-08 13:13:58 +01:00
Thomas Haller
0f7117b4d2
libnm: show gprop-data,is-secret,is-secret-flags in "gen-metadata-nm-settings-libnm-core.xml" 2022-11-08 13:13:58 +01:00
Thomas Haller
7d9f65ebc4
libnm: add code comment in "gen-metadata-nm-settings-libnm-core.xml" 2022-11-08 13:13:58 +01:00
Thomas Haller
4f4f9807a4
libnm: use NMStrBuf in "gen-metadata-nm-settings-libnm-core.c"
It's more convenient to use, because we don't need to keep track
(and free) the allocated string.
2022-11-08 13:13:58 +01:00
Thomas Haller
82384b8fd8
platform: merge branch 'th/nmp-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1448
2022-11-08 12:58:27 +01:00
Thomas Haller
57b23c12cc
platform: only initialize actual data for stackinit NMPObject
The NMPObject is a tagged union. There is no need to initialize anything
after the size of the actually used union field. Change this, so maybe we
get a valgrind warning about uninitialized memory if we wrongly try to
access it.

On the other hand, the object really is supposed to be a full
NMPObject. Previously, we would get a valgrind warning, if we tried to
pass fewer data there.

It really doesn't matter much, but all other functions don't assume
that there is any important data after the size indicated by the class.
2022-11-08 12:57:24 +01:00
Thomas Haller
dd2c5044f6
platform: add internal helper function to get full NMPObject size 2022-11-08 12:54:44 +01:00
Thomas Haller
c9123c2ece
platform: extend cmd_obj_{hash_update,cmp}() hooks to check for identity
We will extend IPv4 routes with the list of next hops. This field will
be heap allocated and be part of the NMPObjectIP4Route object, while
also being part of the identity. To support the ID operator that checks
fields of the NMPObject, add a "for_id" argument to the hash/cmp hooks.

Also, a function that sets cmd_obj_{hash_update,cmp}() MUST not set
cmd_plobj_id_{hashupdate,cmp}(), as it would have overlapping
functionality. Therefore, the objects that define
cmd_obj_{hash_update,cmp}() need to fully implement the ID comparison.
2022-11-08 12:54:44 +01:00
Thomas Haller
ff63b2eb6e
platform: unify full/id hash/cmp implementations for NMPObject 2022-11-08 12:54:44 +01:00
Thomas Haller
5da0d18fbe
platform/tests: add unit test checking consistency of NMPClass 2022-11-08 12:54:35 +01:00
Thomas Haller
8feeb199ad
platform: drop redundant hook implementations from NMPObject classes
A NMPClass that has data outside the plobj part, needs
to implement the cmd_obj_*() hooks, instead of cmd_plobj_*().

For those objects, reasoning only about the plobj part is not
sufficient. Implementing both hooks is also unnecessary and
confusing.

Ensure that if we have cmd_obj_*() hooks set, that the corresponding
cmd_plobj_*() hooks are unset.
2022-11-08 12:53:46 +01:00
Thomas Haller
ee34eeafb9
platform: fix nmp_object_copy(id_only) for object that don't implement cmd_plobj_id_copy()
The if-else-if was wrong. It meant that if an object did not implement
cmd_plobj_id_copy(), nothign was copied (for id-only).

I think this code path was not actually hit, because we never clone
an object only by ID.

Fixes: c91a4617a1 ('nmp-object: allow missing implementations for certain virtual functions')
2022-11-08 12:53:41 +01:00
Lubomir Rintel
e13eb9010c Makefile.am: tidy up the introspection conditional part
Use of conditionals in makefiles needs to be kept to a necessary minimum
otherwise they get out of hand quickly. There's no indentation to aid
reading and conditional chunks longer than a screen and nested ones are
almost impossible to comprehend.

The "if HAVE_INTROSPECTION" part does both.

Let's make it a little less horrible. There's generally no point in
making unused targets or variable assignment unless they collide with
pre-built stuff or have multiple variants.
2022-11-08 11:43:06 +01:00
Lubomir Rintel
4c49d67cc8 docs/api: fix ugly things in Makefile
Turns out automake doesn't like either that we add dependencies to a
target conditionally. Not sure why, but it's a tasteless thing to do
nevertheless:

  gtk-doc.make:174: warning: $(DOC_MAIN_SGML_FILE) was already defined in condition BUILD_DOCS, which is included in condition TRUE ...
  docs/api/Makefile.am:112:   'gtk-doc.make' included from here
  docs/api/Makefile.am:14: ... '$(DOC_MAIN_SGML_FILE)' previously defined here

In any case, the dependency is wrong in the first place -- the source
document doesn't depend on other source. The target (which is a stamp
file, since the xslt processor produces multiple files) does! Moreover,
there's a dependency of the stamp file on $(content_files) already, so
including GENERATED_FILES (like we already do) in content_files should
be sufficient.

While at that, deal with other not-so-nice things; don't extend "all"
target needlessly and don't define a target conditionally.
2022-11-08 11:43:06 +01:00
Lubomir Rintel
45d9f1c01c libnm: actually export a lot of routines that were supposed to be public
Add them to @libnm_1_40_4 as opposed to @libnm_1_42_0 because we now know
this is going to be backported to 1.40.4 first.
2022-11-08 11:43:00 +01:00
Lubomir Rintel
d78000d921 libnm: export nm_utils_ip_{address,rout}es_{from,to}_variant
These are present in a public header yet are not properly commented,
versioned or exported.

Export them now. Another option would be to move them to a private
header; but I suspect someone has intended them to be exported at some
point.

Add them to @libnm_1_40_4 as opposed to @libnm_1_42_0 because we now know
this is going to be backported to 1.40.4 first.
2022-11-08 11:41:47 +01:00
Lubomir Rintel
c0b2b5e3a8 libnm/connection: fix a handful of versioning tags
These are marked as being available sooner than they actually appear in
libnm.ver.
2022-11-08 11:40:18 +01:00
Lubomir Rintel
117a440cd9 libnm: fix a large amount of Since tags
Some comments are malformed, some are missing altogether.
2022-11-08 11:40:18 +01:00
Lubomir Rintel
1c6b0edb30 libnm: drop nm_vpn_plugin_old_set_{,ip6_}config()
Remove the functions from a public header. They were missing from
libnm.ver and thus never actually exported.

There's no point in salvaging them now as the whole NMVpnPluginOld has
been replaced NMVpnServicePlugin and new uses are discouraged.
2022-11-08 11:40:18 +01:00
Lubomir Rintel
ecb9a48040 libnm: remove nm_device_wpan_get_hw_address()
Remove the function from a public header. It was missing from libnm.ver
and thus never actually exported.

There's no point in salvaging it now as it nm_device_get_hw_address()
exists as a better option.
2022-11-08 11:40:18 +01:00