Commit graph

19348 commits

Author SHA1 Message Date
Beniamino Galvani
58bb588fbe libnm-core: fix validation of connection.mdns setting
Commit 9d92848ada ("libnm: rename MDns flag UNKNOWN to DEFAULT")
changed the enum order without updating verify().

Fixes: 9d92848ada
(cherry picked from commit 0498c5487f)
2018-10-19 18:39:35 +02:00
Beniamino Galvani
be483778e7 dns: dnsmasq: avoid crash when no reverse domains exist
ip_data->domains.reverse can be NULL when the device is being removed
and has no IP configuration for a short moment.

Fixes: 6409e7719c

https://bugzilla.gnome.org/show_bug.cgi?id=797022
(cherry picked from commit f0c075f050)
(cherry picked from commit 8309a7a696)
2018-10-19 18:39:35 +02:00
Beniamino Galvani
6b8c6e891b dns: merge branch 'bg/dns-bgo746422'
https://bugzilla.gnome.org/show_bug.cgi?id=746422
(cherry picked from commit d978258924)
2018-10-19 18:39:34 +02:00
Beniamino Galvani
7d4c7e73df dns: merge branch 'bg/dns-domains-pt1-bgo746422'
https://bugzilla.gnome.org/show_bug.cgi?id=746422
(cherry picked from commit b2f306ac3d)
2018-10-19 18:39:34 +02:00
Beniamino Galvani
107c7f27af libnm-core: document dns priority
(cherry picked from commit 1fbadecdbc)
2018-10-19 18:39:34 +02:00
Beniamino Galvani
4e9555699d dns: sd-resolved: honor dns-priority
Honor dns-priority by using the preprocessed list of domains provided
by the manager.

(cherry picked from commit 5df69330b5)
2018-10-19 18:39:34 +02:00
Beniamino Galvani
bd1021a0a0 dns: dnsmasq: honor dns-priority
Honor dns-priority by using the preprocessed list of domains provided
by the manager.

(cherry picked from commit 6409e7719c)
2018-10-19 18:39:34 +02:00
Beniamino Galvani
ad98a41399 dns: fix compilation error
Fixes the following error when building with gcc 4.8.5 and address
sanitizer:

src/dns/nm-dns-dnsmasq.c: In function 'update':
src/dns/nm-dns-dnsmasq.c:506:44: error: 'first_prio' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    } else if (first_prio < 0 && first_prio != prio)
                                            ^

(cherry picked from commit 10ef61408e)
2018-10-19 18:39:34 +02:00
Beniamino Galvani
ad0400408e dns: use dns-priority to provide a preprocessed domain list to plugins
Do some preprocessing on the DNS configuration sent to plugins:

 - add the '~' default routing (lookup) domain to IP configurations
   with the default route or, when there is none, to all non-VPN
   IP configurations

 - use the dns-priority to decide which connection to use in case
   multiple connections have the same domain

 - consider a negative dns-priority value as a way to 'shadow' all
   subdomains from other connections

 - compute reverse DNS domains

and add the resulting domain list to NMDnsIPConfigData so that
split-DNS plugins can use that directly instead of reimplementing the
same logic themselves.

(cherry picked from commit dd1e671fe5)
2018-10-19 18:39:34 +02:00
Beniamino Galvani
f853788290 core: reject invalid domains from ip configurations
Reject domains containing ".." or starting with "."

(cherry picked from commit 82ebfa7351)
2018-10-19 18:39:34 +02:00
Beniamino Galvani
6a0e5fdd47 dns: dnsmasq: fix adding multiple domains
Fixes: e91f1a7d2a
(cherry picked from commit 14b6e330e2)
2018-10-19 18:39:34 +02:00
Beniamino Galvani
fb81b0bccc all: merge branch 'th/policy-and-mdns'
https://github.com/NetworkManager/NetworkManager/pull/44
(cherry picked from commit 5eea9be983)
2018-10-19 18:39:33 +02:00
Beniamino Galvani
3422988c2a dns: introduce routing domains
Similarly to what systemd-resolved does, introduce the concept of
"routing" domain, which is a domain in the search list that is used
only to decide the interface over which a query must be forwarded, but
is not used to complete unqualified host names. Routing domains are
those starting with a tilde ('~') before the actual domain name.

Domains without the initial tilde are used both for completing
unqualified names and for the routing decision.

(cherry picked from commit e91f1a7d2a)
2018-10-19 18:39:33 +02:00
Thomas Haller
427c978e30 policy: merge IPv4 and IPv6 versions of device_ip_config_changed()
(cherry picked from commit d1de905ed3)
2018-10-19 18:39:33 +02:00
Beniamino Galvani
f144eac12c dns: systemd-resolved: use generic ip-config functions
(cherry picked from commit 42ea86fb7a)
2018-10-19 18:39:33 +02:00
Thomas Haller
d7ebbd69a0 core: implement setting MDNS setting for systemd
The connection.mdns setting is a per-connection setting,
so one might expect that one activated device can only have
one MDNS setting at a time.

However, with certain VPN plugins (those that don't have their
own IP interface, like libreswan), the VPN configuration is merged
into the configuration of the device. So, in this case, there
might be multiple settings for one device that must be merged.

We already have a mechanism for that. It's NMIP4Config. Let NMIP4Config
track this piece of information. Although, stricitly speaking this
is not tied to IPv4, the alternative would be to introduce a new
object to track such data, which would be a tremendous effort
and more complicated then this.

Luckily, NMDnsManager and NMDnsPlugin are already equipped to
handle multiple NMIPConfig instances per device (IPv4 vs. IPv6,
and Device vs. VPN).

Also make "connection.mdns" configurable via global defaults in
NetworkManager.conf.

(cherry picked from commit c03a534963)
2018-10-19 18:39:33 +02:00
Beniamino Galvani
d4ca953620 dns: export search list in the D-Bus "domain" attribute
The "domain" key of the D-Bus configuration dictionary specifies the
domains a configuration applies to. In DNS code we consider domains
and searches as equivalent, so they should be exported via D-Bus using
the same logic used to populate resolv.conf and for plugins.

(cherry picked from commit 70550e2740)
2018-10-19 18:39:33 +02:00
Thomas Haller
fd5550e97c core: rework tracking config in dns-manager to use ifindex
Don't track the per-device configuration in NMDnsManager by
the ifname, but by the ifindex. We should consistently treat
the ifindex as the ID of a link, like kernel does.

At the few places where we actually need the ifname, resolve
it by looking into the platform cache. That is not necessarily
the same as the ifname that is currently tracked by NMDevice,
because netdev interfaces can be renamed, and NMDevice updates
it's link properties delayed. However, the platform cache has
the most recent notion of the correct interface name for an
ifindex, so if we ever hit a race here, we do it now more
correctly.

This also temporarily drops support for mdns. Will be re-added next,
but differently.

(cherry picked from commit b40729ca5f)
2018-10-19 18:39:33 +02:00
Beniamino Galvani
f43febc2ab dns: add @dup argument to add_dns_domains() and add_string_item()
Add a @dup argument that tells whether the new item should be
duplicated.

(cherry picked from commit b4db0e8362)
2018-10-19 18:39:33 +02:00
Beniamino Galvani
0daa4db81b dns: split out domains retrieval
(cherry picked from commit e78bfb63cd)
2018-10-19 18:39:33 +02:00
Thomas Haller
e4270341ca core/trivial: rename local variable in merge_one_ip_config()
Next commit will unify naming of variables, do a trivial rename
first to make the diff smaller.

(cherry picked from commit fc40d91b97)
2018-10-19 18:39:32 +02:00
Thomas Haller
9d5be62ffa dns: rework pending request-queue in NMDnsSystemdResolved
We had two separate queues, one for "SetLinkDNS" and one for
"SetLinkDomains". Merge them into one, and track the operation
as part of the new RequestItem structure.

A visible change to before is that we now would make all requests
per-interface first. Prevously, we would first make all SetLinkDNS
requests (for all interfaces) and then all SetLinkDomains requests.
It feels more correct to order the requests this way, not by
type.

The reason to merge is, that we will next get another operation
and in the current scheme we would need 3 GQueue instances.

While at it, refactor the code to use CList. We now anyway would
need a new struct to track the operation, requiring to allocate
and free it. Previously, we would only track the GVariant argument
as data of the GQueue.

(cherry picked from commit b0f1a54c9b)
2018-10-19 18:39:32 +02:00
Thomas Haller
2642407dc2 dns: refactor update() in NMDnsSystemdResolved to use a hash table
Use a GHashTable instead of a GArray to construct the list of
@interfaces. Also, use NMCListElem instead of GList. With this,
the runtime is O(n*log(n)) instead of O(n^2).

I belive, we should take care that all our code has a reasonable
runtime complexity, even in common use-cases the number of elements
is small. This is not about performace, because likely we expect few
entries anyway, and the direct GArray implementation is likely faster
in those cases. It's about using the data structure that best suits the
access pattern.

The log(n) part comes from sorting the keys. I also believe we should
always aim for a stable behavior. When sending the D-Bus request to
resolved, the order of elements should be in ~some~ defined order.

(cherry picked from commit 4be4a3c21f)
2018-10-19 18:39:32 +02:00
Thomas Haller
f2590e86b3 shared: add nm_cmp_int2ptr_p_with_data() helper
A cmp() implementation, for sorting an array with pointers, where each
pointer is an inteter according to GPOINTER_TO_INT().

That cames for example handy, if you have a GHashTable with keys
GINT_TO_POINTER(). Then you get the list of keys via
g_hash_table_get_keys_as_array() and want to sort them.

(cherry picked from commit 901aa0315b)
2018-10-19 18:39:32 +02:00
Thomas Haller
fb64e268bb shared: add NMCListElem
Sometimes, we want to use CList to track a simple data item. But contrary
to GList/GSList, we need to define a structure to hold the data pointer
and the CList member.

Add a generic NMCListElem type that can be used for such simple uses.

Before you ask: why not use GList/GSList? Because even simple operations
like g_list_append() is O(n), which kinda defeats the purpose of having
a doubly linked list.

This code is added to a new header file nm-c-list.h, the reason is that
there is no other good place:
  - "nm-utils/c-list.h" is a clone of upstream, it should not deviate.
  - "nm-utils/c-list-util.h" contains our utils functions for c-list.h
    but should be plain C, independent of glib.
  - "nm-utils/nm-shared-utils.h" contains our glib related utilities,
    but it should not drag in "c-list.h".
So, "nm-c-list.h" is a utility libray that extends "c-list.h" and
requires glib.

(cherry picked from commit 2aad517b0b)
2018-10-19 18:39:32 +02:00
Thomas Haller
0d3f19774f core: add nm_ip_config_get_ifindex() helper
(cherry picked from commit 4ccfa7a79a)
2018-10-19 18:39:32 +02:00
Thomas Haller
8aea6745c4 dns: merge IPv4 and IPv6 versions of add_ip_config() (part 2)
(cherry picked from commit 7d4def2764)
2018-10-19 18:39:32 +02:00
Thomas Haller
0e41dd6b4f dns: merge IPv4 and IPv6 versions of add_ip_config() (part 1)
(cherry picked from commit 49fd1e4126)
2018-10-19 18:39:32 +02:00
Thomas Haller
678327e18f dns/trivial: move code
(cherry picked from commit 03cba93873)
2018-10-19 18:39:32 +02:00
Thomas Haller
97db8306d9 libnm: rename MDns flag UNKNOWN to DEFAULT
"UNKNOWN" is not a good name. If you don't set the property
in the connection explicitly, it should be "DEFAULT".

Also, make "DEFAULT" -1. For one, that ensures that the enum's
underlying integer type is signed. Otherwise, it's cumbersome
to test "if (mdns >= DEFAULT)" because in case of unsigned types,
the compiler will warn about the check always being true.
Also, it allows for "NO" to be zero. These are no strong reasons,
but I tend to think this is better.

Also, don't make the property of NMSettingConnection a CONSTRUCT property.
Initialize the default manually in the init function.

Also, order the numeric values so that DEFAULT < NO < RESOLVE < YES with
YES being largest because it enables *the most*.

(cherry picked from commit 9d92848ada)
2018-10-19 18:39:32 +02:00
Thomas Haller
230eb62821 libnm: verify value for connection.mdns
Also, keep the internal variable of type int. The only way to set the
field is via the GObject property setter. At that point, don't yet
cast the integer type to enum.

(cherry picked from commit eec907b35a)
2018-10-19 18:39:32 +02:00
Ismo Puustinen
1e89b9f18e dns: add mechanism for propagating mDNS setting.
Update nm-policy.c and nm-dns-manager.c so that the connection-specific
settings get propagated to DNS manger. Currently the only such value is
the mDNS status.

Add update_mdns() function to DNS plugin interface. If a DNS plugin
supports mDNS, it can set an interface with a given index to support
mDNS resolving or also register the current hostname.

The mDNS support is currently added only to systemd-resolved DNS plugin.

(cherry picked from commit 25906eda9e)
2018-10-19 18:39:31 +02:00
Ismo Puustinen
19d7e66099 mdns: add new connection property.
Add support for mDNS as a connection-level property. Update ifcfg-rh and
keyfile plugins to support it.

(cherry picked from commit 2e2ff6f27a)
2018-10-19 18:39:31 +02:00
Thomas Haller
2306f8650a build: first build dns-manager and dns-plugin before the plugins
When doing changes that affect multiple source files, it's more
convenient to build the parts that have less dependencies first.
So, to fix the build failures from the core outward.

(cherry picked from commit 6dd69990c0)
2018-10-19 18:39:31 +02:00
Thomas Haller
a0e4dd7ade core: reorder code in "src/dns/nm-dns-manager.c"
Just moving code around, no other changes.

Follow a certain prefered order of declarations
in source files.

(cherry picked from commit 3d86429c9d)
2018-10-19 18:39:31 +02:00
Beniamino Galvani
2da1366905 core: drop unused macro argument
(cherry picked from commit 057744b722)
2018-10-19 18:39:31 +02:00
Thomas Haller
cca492af14 ifcfg: fix crash parsing more than 10 DNS settings in make_ip6_setting()
On master, commit [1] added a double-free error. This was
unintentionally fixed later in commit [2].

Commit [1] was backported to nm-1-10 branch in 1.10.10.

Fix it.

[1] a9b5079324, 1.11.2-dev
[2] e9321713a9, 1.12-rc1

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

Fixes: b2a9e2f326
2018-10-19 18:07:04 +02:00
Thomas Haller
5afec82a5c ndisc: merge branch 'th/ndisc-addr-lifetime'
https://github.com/NetworkManager/NetworkManager/pull/228

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/57
https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1796622

(cherry picked from commit 3baa016f89)
(cherry picked from commit 8c24119859)
(cherry picked from commit c7d8f17094)
2018-10-13 20:50:44 +02:00
Thomas Haller
2c47cf51b1 ndisc: don't update dad_counter for addresses in router config
I am not sure, we ever call complete_address() for router-configurations.
Maybe not, so the dad-counter is never incremented and does not matter either.

If we however do, then we certainly want to preserve the DAD counter
when the address is already tracked.

(cherry picked from commit 8c6629b356)
(cherry picked from commit 036d1f56ea)
(cherry picked from commit 148c9d9b0c)
2018-10-13 20:50:18 +02:00
Thomas Haller
cc16d89395 ndisc: fix updating address lifetime on Router Announcement according to RFC4862
This is a denial-of-service protection, where a malicious router
advertisement can expire the addresses.

See-also: 6554550f35
See-also: https://tools.ietf.org/search/rfc4862#section-5.5.3

https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/1796622
(cherry picked from commit 27be3e0338)
(cherry picked from commit 8e2ccd3921)
(cherry picked from commit 451bf6e275)
2018-10-13 20:50:18 +02:00
Thomas Haller
2e365f638b ndisc: handle integer overflows better for lifetime handling
we use get_expiry() to compare two lifetimes. Note, that previously,
it would correctly truncate the calculated expiry at G_MAXINT32-1.

However, that means, that two different lifetimes that both lie
more than 68 years in the future would compare equal.

Fix that, but extending the range to int64, so that no overflow
can happen.

(cherry picked from commit b086535cb7)
(cherry picked from commit fe60843232)
(cherry picked from commit 42e61a8cc8)
2018-10-13 20:50:18 +02:00
Thomas Haller
3d99992593 ndisc: minor refactoring loop in nm_ndisc_add_address()
No change in behavior. Just don't do so much work inside
the deeper nesting of the loop.

(cherry picked from commit 9d0a138ef0)
(cherry picked from commit 3cecb4d018)
(cherry picked from commit 669e004299)
2018-10-13 20:50:18 +02:00
Thomas Haller
d4b67b9441 ndisc: only generate address interface identifer after checking existing prefix
RFC4862 5.5.3, points d) and e) make it clear, that the list of
addresses should be compared based on the prefix.

  d)  If the prefix advertised is not equal to the prefix of an
    address configured by stateless autoconfiguration already in the
    list of addresses associated with the interface (where "equal"
    means the two prefix lengths are the same and the first prefix-
    length bits of the prefixes are identical), and if the Valid
    Lifetime is not 0, form an address (and add it to the list) by
    combining the advertised prefix with an interface identifier of
    the link as follows:

That means, we should not initialize the interface identifier first
(via complete_address()) and then search for the full address.

See-also: https://tools.ietf.org/search/rfc4862#section-5.5.3
(cherry picked from commit 23c417854a)
(cherry picked from commit ac5669633c)
(cherry picked from commit b2f084a8ae)
2018-10-13 20:50:18 +02:00
Thomas Haller
aeca2fb4b1 ndisc: ensure we skip unspecified IPv6 address in ndisc_set_router_config()
Later, nm_ndisc_add_address() asserts that the address is not an
unspecified address. Skip it, just to be sure.

(cherry picked from commit 700b04d0de)
(cherry picked from commit e0e698e463)
(cherry picked from commit 547dcacbfb)
2018-10-13 20:50:18 +02:00
Thomas Haller
8177b0c397 ndisc: ignore addresses with preferred lifetime larger than lifetime
Previously, we would coerce the value so that preferred is the same
as lifetime. However, RFC4862 5.5.3.c) says:

  c)  If the preferred lifetime is greater than the valid lifetime,
    silently ignore the Prefix Information option.  A node MAY wish to
    log a system management error in this case.

See-also: https://tools.ietf.org/search/rfc4862#section-5.5.3
(cherry picked from commit 43c3c259c8)
(cherry picked from commit eff9e161cb)
(cherry picked from commit dbfa7950cf)
2018-10-13 20:50:18 +02:00
Thomas Haller
f231b2b9b7 ndisc: merge branch 'th/ndisc-fixes'
https://github.com/NetworkManager/NetworkManager/pull/219

(cherry picked from commit 6e41d79067)
(cherry picked from commit 8ee0ca8cce)
(cherry picked from commit 685573e049)
2018-10-13 20:49:37 +02:00
Thomas Haller
fc9ad78f3a ndisc: always emit changed signal if an ndisc parameter changes
Note how the nm_ndisc_add_*() return a boolean to indicate whether
anything changes. That is taken to decide whether to emit a changed
signal.

Previously, we would not consider all fields which are exposed
as public API.

Note that nm-ip6-config.c would care about the lifetime of NMNDiscAddress.
For that, nm_ndisc_add_address() would correctly consider a change of
the lifetime as relevant. So, this was for the most part not broken.
However, for example nm_ndisc_add_route() would ignore changes to the
gateway.

Always signal changes if anything changes at all. It's more correct
and robust.

(cherry picked from commit 98ec56c670)
(cherry picked from commit 2e12660dd4)
(cherry picked from commit 9f6a654999)
2018-10-13 20:48:53 +02:00
Thomas Haller
3a2e6c5172 ndisc/trivial: move code
(cherry picked from commit 4f78d82fcd)
(cherry picked from commit bd41719f95)
(cherry picked from commit cdc5848be7)
2018-10-13 20:48:53 +02:00
Thomas Haller
ba6490e00e ndisc: abort handling IO in event_ready() if we are unable to switch namespace
It should never happen that we are unable to switch the namespace.
However, in case it does, we cannot just return G_SOURCE_CONTINUE,
because we will just endlessly trying to process IO without actually
reading from the socket.

This shouldn't happen, but the instance is hosed and something is
very wrong. No longer handle the socket to avoid an endless loop.

(cherry picked from commit d444fcde34)
(cherry picked from commit 6631debaa3)
(cherry picked from commit 5c56404dfc)
2018-10-13 20:48:53 +02:00
Thomas Haller
9a06bb2b7b ndisc: keep NMNDisc instance alive while processing IO in event_ready()
event_ready() calls ndp_callall_eventfd_handler(), which invokes
our own callback, which may invoke change notification.

At that point, it's not guaranteed that the signal handler won't
destroy the ndisc instance, which means, the "struct ndp" gets destroyed
while invoking callbacks. That's bad, because libndp is not robust
against that.

Ensure the object stays alive long enough.

(cherry picked from commit 9aa628cedb)
(cherry picked from commit efb9e2bc6b)
(cherry picked from commit 2ba6d74bca)
2018-10-13 20:48:53 +02:00