Commit graph

29063 commits

Author SHA1 Message Date
Thomas Haller 9c99c948fd
platform: add nmp_cache_iter_for_each_reverse() helper 2021-08-17 19:56:38 +02:00
Thomas Haller 53070705b0
glib-aux: clear iterator in nm_dedup_multi_iter_{next,prev}() at the end
It seems slightly nicer not to leave a dangling pointer at the
end of the iteration. Then you could do something like

    nm_dedup_multi_iter_init(&iter, head_entry);
    while (nm_dedup_multi_iter_next(&iter)) {

        if (some_condition())
            break;
    }
    if (!iter.current)
        printf("iterated to the end\n");

As nm_dedup_multi_iter_next() and nm_dedup_multi_iter_init() are inline
functions, the compiler should even be able to see that the initial
setting becomes unnecessary (the field will be initialized by the
first nm_dedup_multi_iter_next()). Likewise, the final clearing
of the field might also be optimized away at the end of the iteration
(if, as in the common case, the iterator is not accessed afterwards).
2021-08-17 19:56:38 +02:00
Thomas Haller 57a519cc03
glib-aux: add nm_dedup_multi_iter_init_reverse() to iterate in reverse order 2021-08-17 19:56:38 +02:00
Ana Cabral bdaf82ed19 nm-initrd-generator: Merge branch 'al/initrdgenerator-ethtool-docs'
- remove duplex option 

- include man entry for rd.ethtool options

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

!960
2021-08-17 17:51:58 +00:00
Ana Cabral 44a5bdabe9 nm-initrd-generator: include man entry for rd.ethtool options 2021-08-17 12:32:54 -03:00
Ana Cabral 750d35a6e3 nm-initrd-generator: remove duplex option 2021-08-17 12:00:37 -03:00
Javier Sánchez Parra b0f5b1d97a
tui: add WireGuard support to nmtui
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/736
2021-08-17 14:10:12 +02:00
Thomas Haller 5d0d8f9e3a
platform/netlink: merge branch 'th/netlink-policy-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/959
2021-08-17 13:22:12 +02:00
Thomas Haller 76bcd78710
platform/netlink: use appropriate integer types in nla_policy 2021-08-17 13:18:08 +02:00
Thomas Haller 57d626c182
platform/netlink: rework static check in _nl_static_assert_tb() to use _Generic()
Depending on sizeof(policy) to be sizeof(NULL) is not a good check
whether the macro argument may be NULL. That is, because the size
of the policy array might accidentally be the same as the size of
a pointer. Use _Generic() instead.
2021-08-17 13:18:07 +02:00
Thomas Haller fa745181dc
platform/netlink: drop unused NLA_NUL_STRING type
Kernel implemente NLA_NUL_STRING type, but we don't implement
exactly the same type checks. Drop NLA_NUL_STRING and use a plain
NLA_STRING instead.
2021-08-17 13:18:07 +02:00
Thomas Haller f7635c9ffe
platform/netlink: use switch for type check in validate_nla() 2021-08-17 13:18:07 +02:00
Thomas Haller 68a5d1cfe5
platform/netlink: refactor handling length in validate_nla() 2021-08-17 13:18:07 +02:00
Thomas Haller 6f1274caea
platform/netlink: return uint16_t type from nla_len()
nla_len() cannot return anything larger or smaller than range uint16_t.
Change the return type of nla_len().
2021-08-17 13:18:07 +02:00
Thomas Haller 386b367bfa
platform/netlink: cleanup handling of nla_attr_minlen
- make nla_attr_minlen[] and array of uint8_t. That is large enough for
  all values we have.

- don't handle NLA_UNSPEC specially. nla_attr_minlen[NLA_UNSPEC] returns
  zero just fine.
2021-08-17 13:18:06 +02:00
Thomas Haller 0adc4fc4f6
platform/netlink: drop unused NLA type enums 2021-08-17 13:18:06 +02:00
Thomas Haller b57c1af814
udev: also react to "move" (and "change") udev actions in our rules
NetworkManager handles "add" and "move" actions the same way, by
tracking the "struct udev_device" instance.

Still, this means that also for move events, we need the right
attributes set.

See-also: https://github.com/openshift/sriov-network-operator/issues/414
2021-08-16 19:22:32 +02:00
Ana Cabral f06c89f596 nm-initrd-generator: add kernel command line options ethtool autoneg, speed and duplex to configure NICs
Merge Request !941
2021-08-11 13:55:43 -03:00
echengqi 97041efee1
core: free config_cli before exit() from main
[thaller@redhat.com: changed commit message]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/954
2021-08-11 16:23:09 +02:00
Thomas Haller e11b8b94e3
dhcp: merge branch 'th/dhcp-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/956
2021-08-11 14:23:24 +02:00
Thomas Haller f5dbf476e3
core: rename to_str() methods to to_string()
It's more common to name the to-string method *_to_string(). Rename.
2021-08-11 14:17:25 +02:00
Thomas Haller ae117c588d
dhcp: ensure NMDhcpClient was stopped in destructor
The user of NMDhcpClient is supposed to call "nm_dhcp_client_stop()"
on the instance, also because it is a ref-counted GObject type. So we
wouldn't want to rely on the last unref to stop DHCP.

Still, in case that was not done, the code somehow made the assumption
it made any sense to possibly not stop the DHCP client. For the internal
client, there is of course nothing left after destroying the
NMDhcpClient instance, but what about dhclient? I don't think we should
ever leave dhclient running unsupervised. Even during restart of the
service, we need to stop it first, and restart it afterwards.

When we quit NetworkManager, we may want to leave the interface up and
configured. For that, we may need to take care that "nm_dhcp_client_stop()"
does not destory the IP configuration of the intrerface. But I don't
think that is a problem. What we still want to do, is kill the dhclient
instance.

NMDhcpClient is not supposed to be ever restarted. It starts when an
instance gets created, and it stops with "nm_dhcp_client_stop()". Hence,
the simple "is_stopped" flag is fine to prevent that multiple stop calls
are harmful.
2021-08-11 14:17:25 +02:00
Thomas Haller 359d207d95
dhcp: stop tracking NMDhcpClient instances from NMDhcpManager
NMDhcpManager was tracking DHCP clients. During start, it would check
whether an instance for the same ifindex is running, and stop it.

That seems unnecessary and wrong. Clearly, we cannot have multiple users
(like two `NMDevice`s) run DHCP on the same interface. But its up to
them to coordinate that. They also cannot configure IP addresses at the
same interface, and if they do, then there is a big problem already.

This comes from commit 1806235049 ('dhcp: convert dhcp backends to
classes'). Maybe back then there was also the idea that NetworkManager
could quit and leave dhclient running. That idea is also flawed. When
NetworkManager stops, it leaves the interface (possibly) up, so that
restart works without disruption. That does not mean that the DHCP
client needs to keep running. What works is to restart NetworkManager in
a timely manner, then NetworkManager will start a new DHCP client after
restart. What does not work is stop NetworkManager, do nothing (like
taking over the interface by running your own manager) and expect that
DHCP keeps working indefinitely. And of course, with the internal client
this cannot possibly work either. Don't stop NetworkManager for good, if
you expect NetworkManager to run DHCP on an interface.

A different things is that when NetworkManager crashes, that after
restart it kills the left over dhclient instances. That may require a
solution, for example systemd killing all processes or checking for
left-over PID files and kill the processes. But what was implemented in
NMDhcpManager was not a solution for that.

As such, it's not clear what conflicting instance we want to kill, or
why NMDhcpManager should even track NMDhcpClient instances.
2021-08-11 14:17:25 +02:00
Thomas Haller dbdd8303fc
dhcp: replace NMDhcpClient's signals with "notify" and one notify data argument
NMDhcpClient communicates events via GObject signals. GObject signals in
principle could have several subscribers. In practice, a NMDhcpClient
instance has only one subscriber, because it was constructed with
certain parameters, so it's unlikely to be shared.

That one subscriber, always needs to subscribe to all signals
("state-changed" and "prefix-delegated"), Unless the subscriber only
creates a IPv4 client. In which case they won't subscribe to
"prefix-delegated", but that signal is also not invoked for IPv4
clients.

Combine the signals in one, and pass all parameters via a new
NMDhcpClientNotfiyData payload. I feel this is nicer, to pack all
parameters together. I find this more type-aware, where we can
switch (in the callback) based on a notify-type enum, instead
of subscribing multiple signal handlers.

With l3cfg work, DHCP handling will be refactored, where this model of
having one "generic" notify signal makes more sense than here. For the
moment, it is arguably pretty much the same. Also, because NMDhcpClient
subscribes two different handlers for IPv4 and IPv6. In the future,
there will be only one notify handler, and that can cover IPv4 and IPv6
and both "state-changed" and "prefix-delegated" (and other notification
types).
2021-08-11 14:17:24 +02:00
Thomas Haller 4d0e295317
ndisc: add nm_ndisc_dhcp_level_to_string() helper 2021-08-11 14:17:24 +02:00
Thomas Haller 1d789ca44b
std-aux: add XXX() macro 2021-08-11 14:17:24 +02:00
Wen Liang 8b133746e0 Merge branch 'wl/fix_ali_gateway' into 'main'
aliyun: reuse ipv4 gateway address returned by metadata server

See merge request NetworkManager/NetworkManager!958
2021-08-09 14:50:32 +00:00
Wen Liang 778e1f8493 aliyun: reuse ipv4 gateway address returned by metadata server
The default ipv4 gateway address of the VPC in Aliyun cloud is not the
first IP address in the CIDR subnet block, we should instead use the
ipv4 gateway address retrieved from the metadata server in
`_nmc_mangle_connection()`.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/958

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-08-09 09:35:52 -04:00
Thomas Haller f43bee77d6
glib-aux: drop unnecessary g_strlcpy() from nm_uuid_is_valid_nm() 2021-08-09 07:59:45 +02:00
Thomas Haller 30e7400528
ifup: extend ifup/ifdown to be smarter about NetworkManager profiles
Now that NetworkManager on Fedora 33 and RHEL 9 no longer writes
ifcfg-rh files by default ([1]), ifup/ifdown became less useful.

Possibly users shouldn't use it and it would be fine that new-style profiles
(keyfile) no longer work with these commands. But this is deemed as too
disruptive for users.

Note that our previous ifup/ifdown compat scripts only honored the argument
to be part of the ifcfg filename. That was not what initscripts were doing,
which called `need_config()` function that searched also the contents of
the files. With this extension, ifup/ifdown gets smarter too, to better
guess what the user might have wanted.

Extend the script by making it smarter, and to work with connection profile
names.

With this extension we further solidify ifup/ifdown as part of NetworkManager
command line API. That is problematic, because these tools pollute the
$PATH, by not having a clear NM-specific name. Also, these scripts
should only exist on Fedora/RHEL, which makes their usage non-portable
to other distros.
Also, other distros already ship different tools with name ifup/ifdown.
Extending the use of these scripts is thus undesirable, as it furthers
distro-specific commands.

Still, these arguments seem to not hold and users need to be "helped".
As Fedora users cannot be expected to unlearn "ifup" today, there is no
reason to assume they could in a few years. This likely means we will
never get rid of these scripts.

Also, if we truly would make ifup/ifdown part of NetworkManager, then a better
implementation would be that nmcli honors being called with these names.
That is not done, because nmcli's implementation currently is not as
nice to make that extension trivial (as it should be). It also would
mean to embrace ifup/ifdown officially. A shell script works well enough
as a hack.

[1] https://fedoraproject.org/wiki/Changes/NetworkManager_keyfile_instead_of_ifcfg_rh

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/936
2021-08-07 15:31:04 +02:00
Ana Cabral e6583941b1
.gitignore: include files used by eclipse-cdt IDE
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/957
2021-08-06 20:18:56 +02:00
Beniamino Galvani 3f42e2005a device: store the original MTU before force-setting it
In case the MTU is force-set (e.g. for bridges), priv->mtu_initial and
priv->ip6_mtu_initial must be initialized before changing the MTU,
otherwise the wrong value will be restored on deactivation.

Fixes: e23798a5e5 ('bridge: force (hack)-set of the MTU when explicitly set in the profile')

https://bugzilla.redhat.com/show_bug.cgi?id=1973536
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/955
2021-08-06 15:31:02 +02:00
Thomas Haller a9279d1e89
firewalld: merge branch 'th/firewalld-reloaded'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/949
2021-08-06 14:37:43 +02:00
Thomas Haller 0f100abd85
firewalld: listen to Reloaded signal and reconfigure firewall zones
During reload, firewalld drops the current runtime configuration.
NetworkManager should listen to that, and reconfigure the zones
that it cares about.
2021-08-06 14:35:35 +02:00
Thomas Haller b2ed02dda9
firewalld: fix initialized_now argument for NMFirewalldManager's "state-changed" signal 2021-08-06 14:35:34 +02:00
Thomas Haller 3d949f98e4
firewalld: make D-Bus calls against unique name for firewalld service
As we keep track of the current name owner, use its unique name
for the D-Bus requests.

We also track when the name owner changes, so at the point when we make
the D-Bus call, the current name owner was still running. We should talk
to it directly. If at the same time, firewalld restarts, we go through
our usual tracking of the name owner and will retry -- but always
talking to the unique name.
2021-08-06 14:35:34 +02:00
Thomas Haller 9debc3d028
firewalld: track current name_owner in NMFirewalldManager
Not only track whether we have a name-owner, but also which.
2021-08-06 14:35:33 +02:00
Thomas Haller b55f95abfa
firewalld: prefix firewalld logging messages with "firewalld"
It seems more apt than "firewall: ...".
2021-08-06 14:35:33 +02:00
Thomas Haller ec126740ce
nm-sudo,dispatcher: merge branch 'th/nm-sudo-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/951
2021-08-06 14:34:24 +02:00
Thomas Haller 2665fe23c2
nm-sudo,dispatcher: rename and refactor code to make them more similar
nm-sudo and nm-dispatcher are very similar from a high level. Both are D-Bus activated
services that exit on idle and all they do, is to provide a simple D-Bus API with no
objects or properties.

Hence it's not surprising that they follow the same structure.

Rename the code to make them look more similar.
2021-08-06 14:33:39 +02:00
Thomas Haller 412b5b4fa7
dispatcher: reject new requests after releasing name
After we released the well-known name (or if we failed to ever request
it), we must exit as fast as possible, so that a new instance can
be started to serve new requests.

At that point, reject new requests because they are targeted against the
unique name, which they should not do (when talking to a D-Bus activated
service that exits on idle, it's important to talk to the well-known
name).

Also, if we receive SIGTERM, start releasing the name. We are told to
shut down, and must do so in a timely manner. Again, new requests shall
not be served by this instance.
2021-08-06 14:32:55 +02:00
Thomas Haller 9f0984c63b
nm-sudo: don't register pending job for current operations
Currently we only implmement two operations (Ping() and GetFD()). Both
complete right away. There is no need to register a pending job, if
the job does not get processed asynchronously.

In the future, we may have methods that need asynchronous processing
and where we need to register them as pending job.
2021-08-06 14:32:55 +02:00
Thomas Haller 31c48ec616
nm-sudo: reject new request once we have no well-known-name
If we fail to acquire the well-known name or if we already released it,
we must not accept anymore new requests.

Otherwise, requests directly targeted to the unique name will keep the
process alive, and prevent it from restarting (and serving the
well-known name). Clients really should not talk to the unique name of a
service that exits on idle. If they do, and the service is about to shut
down, then the request will be rejected. After we released the name,
there is now turning back and we should quit fast (only processing the
requests we already have).

Also, if we receive a SIGTERM, then we are requested to quit and should
do so in a timely manner. That means, we will start with releasing the
name. As the service is D-Bus activated, new requests can be served by
the next instance (or if the service is about to be disabled altogether,
they will start failing).
2021-08-06 14:32:55 +02:00
Thomas Haller 0aaaab07d1
nm-sudo: fix clearing timeout source in _idle_timeout_cb()
Fixes: f137b32d31 ('sudo: introduce nm-sudo D-Bus service')
2021-08-06 14:32:51 +02:00
Thomas Haller 06713e7645
glib-aux: add nm_g_main_context_iterate_for_msec() helper 2021-08-06 14:31:05 +02:00
Thomas Haller 17dcef41bd
all: merge branch 'th/l3cfg-21'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/953
2021-08-05 18:34:25 +02:00
Thomas Haller 8c7ab70915
dhcp: don't log plain pointer values for debugging
We avoid logging plain pointers. The logfile should not contain pointers
as that theoretically can defeat ASLR.
2021-08-05 15:52:01 +02:00
Thomas Haller 2cbaaed820
dhcp: add nm_dhcp_client_can_accept() function 2021-08-05 15:52:00 +02:00
Thomas Haller 320a1b5a79
l3cfg: add nm_l3cfg_remove_config_all_dirty() for removing dirty configs
The "only_dirty" parameter to a remove-all() function is odd.

For one, the function is called remove-all, but depending on a parameter
it does not remove all.

Also, setting remove-all(only_dirty=TRUE) means it will remove not
everything, so passing TRUE will remove only parts. That logic seems
confusing.

Avoid that, by removing the parameter from nm_l3cfg_remove_config_all()
and add nm_l3cfg_remove_config_all_dirty().
2021-08-05 14:59:19 +02:00
Thomas Haller a3b7030d74
dispatcher: rename NM_DISPATCHER_ACTION_DHCP_CHANGE_X enums
add a NM_DISPATCHER_ACTION_DHCP_CHANGE_X() macro that can select the
right action based on a parameter.

Also rename the IPv4/IPv6 enum values, so that their naming scheme works
better with the NM_DISPATCHER_ACTION_DHCP_CHANGE_X() macro.
2021-08-05 14:59:17 +02:00