Commit Graph

501 Commits

Author SHA1 Message Date
Lubomir Rintel
e96f0e6349 all: trivial: use g_value_dup_string () 2016-05-30 16:13:48 +02:00
Thomas Haller
04852d2877 dhcp: log setting and clearing systemd dhcp client instance
internal systemd code produces logging messages by itself, like
  libsystemd: DHCP CLIENT (0x9204b5ce): ACK

Let's log the pointer value initially, to associate the logged "xid"
with the pointer value of the client.

Now we get:

  <trace> [1464520695.7655] dhcp4 (enp0s25): dhcp-client4: set 0x556cdd9d6800
  <debug> [1464520695.7658] libsystemd: DHCP CLIENT (0x9d87b7c5): STARTED on ifindex 2
2016-05-29 13:33:07 +02:00
Thomas Haller
a2c843499c all/tests: split core part out of "nm-test-utils.h"
A large part of "nm-test-utils.h" is only relevant for tests inside "src/"
directory, as they are helpers related to NetworkManager core part.

Split this part out of "nm-test-utils.h" header.
2016-05-17 16:48:52 +02:00
Thomas Haller
2e710c2e10 sd/dhcp: workaround multiple "Domain Name" (option 15) entries
https://mail.gnome.org/archives/networkmanager-list/2005-April/msg00022.html
https://tools.ietf.org/html/rfc2132#section-3.17
https://bugzilla.gnome.org/show_bug.cgi?id=766191
2016-05-11 11:14:28 +02:00
Thomas Haller
f027b71f65 build: cleanup include of <config.h>
It is recomended to include <config.h> with angle brackets [1].

Note, that usually we don't include <config.h> directly, except in
two places we have to (because there we include conflicting libraries
that must be included before "nm-default.h").
In that case, define __CONFIG_H__ which is used as include guard around
<config.h> by "nm-default.h".

[1] https://www.gnu.org/software/autoconf/manual/autoconf-2.66/html_node/Configuration-Headers.html
2016-04-28 19:02:58 +02:00
Thomas Haller
6bf022359f core/trivial: rename "source" field of addresses and routes
The "source" field of NMPlatformIPRoute (now "rt_source") maps to the
protocol field of the route. The source of NMPlatformIPAddress (now
"addr_source") has no direct equivalent in the kernel.

As their use is different, they should have different names. Also,
the name "source" is used all over the place. Hence give the fields
a more distinct name.
2016-04-28 12:53:21 +02:00
Thomas Haller
54233b6f3b core: use nm_utils_machine_id_read() in "nm-dhcp-client.c" 2016-04-26 12:48:28 +02:00
Dan Williams
8c8a577a30 dhcp/systemd: actually hook up information-only mode
Fixes: 89d1e46615
Tested-by: Celti on IRC
2016-04-25 17:00:54 -05:00
Thomas Haller
cf0c300058 dhcp: refactor nm_dhcp_client_stop_existing() 2016-04-22 12:58:20 +02:00
Thomas Haller
44768f0311 platform: change @plen field of NMPlatformIPxAddress to type guint8
On netlink layer, this field is uint8_t/uchar.

A larger (signed) plen makes no sense. Adjust the signatures
to have only guint8.
2016-04-11 11:26:36 +02:00
Thomas Haller
14ee5dd2f8 platform: change @plen field of NMPlatformIPxRoute to type guint8
On netlink layer, this field is uint8_t/uchar.

A larger (signed) plen makes no sense. Adjust the signatures
to have only guint8.
2016-04-11 11:26:36 +02:00
Thomas Haller
9152dec99f build: disable deprecation checks for internal compilation
For internal compilation we want to be able to use deprecated
API without warnings.

Define the version min/max macros to effectively disable deprecation
warnings.

However, don't do it via CFLAGS option in the makefiles, instead hack it
to "nm-default.h". After all, *every* source file that is for internal
compilation needs to include this header as first.
2016-04-05 22:22:58 +02:00
Beniamino Galvani
76b79df155 dhcp: don't fail assertions when a DHCP client is not available
If no configured client is available, gracefully fail the activation
without throwing runtime errors.
2016-03-24 15:03:04 +01:00
Beniamino Galvani
fd971567b9 dhcp: fall back to other clients when an invalid one is specified
If the user specifies an invalid 'dhcp' option in configuration,
currently we disable DHCP. Instead, fall back to other available
clients, as we do for other options.
2016-03-24 15:03:04 +01:00
Francesco Giudici
99ad9df342 dhcp: fix GBytes leak in nm_dhcp_client_start_ip4() 2016-03-18 10:46:16 +01:00
Thomas Haller
e3d2fc861b dhcp: support _LOGx_ENABLED() macro in dhcp-client
The macro _LOGx_ENABLED() is defined with a default implementation
that depends on _NMLOG_DOMAIN. Although that default does not
check for LOGD_DHCP4 vs. LOGD_DHCP6, still provide it.
Determining the correct domain might involve a larger performance
impact that what we would safe.
2016-03-17 18:00:53 +01:00
Thomas Haller
aed3c810b3 systemd: split "nm-sd.h" out of "nm-sd-adapt.h"
Now we have:

"nm-sd.h" is a header file of NetworkManager with utilities
related to systemd. It can be used anywhere freely.

Also, systemd headers that are considered public API (like
"sd-event.h") can be used without restrictions.

When compiling the systemd sources, we always must include
"nm-sd-adapt.h" as first. Similarly, systemd headers must
not include "nm-sd-adapt.h", because they are either public
(in which case the adapter is not needed) or they are internal
(in which case they are themself included via a systemd source).

Sometimes, we must internal API (like "dhcp-lease-internal.h").
In this case, we also must include "nm-sd-adapt.h".
2016-03-11 11:02:12 +01:00
Thomas Haller
fd8c56425e all/tests: fix tests after adjusting glib logging level
Fixes: b49322b568
2016-03-10 14:04:32 +01:00
Beniamino Galvani
d6d9f47a32 dhcp: client: use logging helpers 2016-03-04 11:59:37 +01:00
Thomas Haller
cd4f84b738 all: don't include error->code in log messages
GError codes are only unique per domain, so logging the code without
also indicating the domain is not helpful. And anyway, if the error
messages are not distinctive enough to tell the whole story then we
should fix the error messages.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Thomas Haller
01b9b4104c all: clean-up usage of GError
Functions that take a GError** MUST fill it in on error. There is no
need to check whether error is NULL if the function it was passed to
had a failing return value.

Likewise, a proper GError must have a non-NULL message, so there's no
need to double-check that either.

Based-on-patch-by: Dan Winship <danw@gnome.org>
2016-03-03 18:54:20 +01:00
Beniamino Galvani
89d1e46615 dhcp/systemd: enable DHCPv6 support
Until now the internal DHCP client could start a DHCPv6 transaction
but was not able to parse the lease and pass the information back to
the core. Add the missing glue code to make this work.

https://bugzilla.gnome.org/show_bug.cgi?id=762432
2016-03-03 11:29:27 +01:00
Thomas Haller
bf29d02ac1 systemd: don't include "nm-sd-adapt.h" in systemd header files
The header files are not compiled directly, but always included while compiling
other source files. We already require every source file to include "nm-sd-adapt.h"
as first, thus we don't need the include in the headers too.
2016-02-29 14:08:00 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Beniamino Galvani
0f5c5ad446 dhcp/systemd: accept default gateway in classless static routes option
RFC 3442 allows a default gateway to be specified in option 121
(Classless Static Routes) and override the Router option.  Implement
this in the internal DHCP client.

https://bugzilla.gnome.org/show_bug.cgi?id=761268
2016-02-16 00:08:15 +01:00
Thomas Haller
e663b88c59 all/trivial: rename STRLEN() macro to NM_STRLEN()
We should not have defines/macros in header files without a nm/NM
prefix. STRLEN() was one of the few offenders.

https://mail.gnome.org/archives/networkmanager-list/2016-February/msg00048.html
2016-02-14 11:34:42 +01:00
Thomas Haller
2c2d9d2e4c build: cleanup default includes
- "gsystem-local-alloc.h" and <gio/gio.h> are already included via
  "nm-default.h". No need to include them separately.

- include "nm-macros-internal.h" via "nm-default.h" and drop all
  explict includes.

- in the modified files, ensure that we always include "config.h"
  and "nm-default.h" first. As second, include the header file
  for the current source file (if applicable). Then follow external
  includes and finally internal nm includes.

- include nm headers inside source code files with quotes

- internal header files don't need to include default headers.
  They can savely assume that "nm-default.h" is already included
  and with it glib, nm-glib.h, nm-macros-internal.h, etc.
2016-02-12 15:36:01 +01:00
Thomas Haller
acc0d79224 systemd: merge branch 'systemd' into master 2016-01-26 17:45:23 +01:00
Beniamino Galvani
3eb5037e1f dhcp/systemd: disable callback before stopping the client
Otherwise the call to stop() would generate a new unwanted state
transition.
2016-01-25 17:46:01 +01:00
Beniamino Galvani
37d0833a15 dhcp/systemd: honor timeout 2016-01-25 17:46:01 +01:00
Beniamino Galvani
2ef70653fb dhcp/systemd: gracefully fail when the interface has unknown ARP type 2016-01-25 17:46:01 +01:00
Thomas Haller
a99a0d194d dhcp: clear watch_id in child-watch callback 2016-01-20 10:27:36 +01:00
Beniamino Galvani
ea1eb94d9b core: use nm_clear_g_signal_handler() where possible
Replacement was done with command:

spatch --sp-file nm_clear_g_signal_handler.cocci --in-place --smpl-spacing --dir src

where nm_clear_g_signal_handler.cocci contains:

@@
expression obj, id;
@@
- if (id) {
-    g_signal_handler_disconnect (obj, id);
-    id = 0;
- }
+ nm_clear_g_signal_handler (obj, &id);
2016-01-06 21:25:56 +01:00
Beniamino Galvani
f96abc8be5 core: always use gulong to store signal handler ids
We inconsistently use gulong,guint,int types to store signal handler
id, but the type returned by g_signal_connect() is a gulong.

This has no practical consequences because a int/guint is enough to
store the value, however it is better to use a consistent type, also
because nm_clear_g_signal_handler() accepts a pointer to the signal id
and thus it must be always called with the same pointer type.
2016-01-06 21:25:55 +01:00
Beniamino Galvani
fbd3286955 core,libnm: use nm_clear_g_source() where possible
Replacement was done with commands:

spatch --sp-file nm_clear_g_source.cocci --in-place --smpl-spacing --dir src
spatch --sp-file nm_clear_g_source.cocci --in-place --smpl-spacing --dir libnm

where nm_clear_g_source.cocci contains:

@@
expression e;
@@
- if (e) {
-    g_source_remove (e);
-    e = 0;
- }
+ nm_clear_g_source (&e);
2016-01-06 21:25:55 +01:00
Thomas Haller
db80ec05ab build: rename directory "include" to "shared"
Up to now, the "include" directory contained (only) header files that were
used project-wide by libs, core, clients, et al.

Since the directory now also contains a non-header file, the "include"
name is misleading. Instead of adding yet another directory that is
project-wide, with non-header-only content, rename the "include"
directory to "shared".
2015-12-24 11:42:37 +01:00
Jiří Klimeš
d944a0f134 dhcp: lifetimes are unsigned integers, use %u printf specifier (rh #1268911)
https://bugzilla.redhat.com/show_bug.cgi?id=1268911
2015-12-03 15:25:54 +01:00
Glenn Washburn
7a97d16944 dhcp-helper: call g_type_init() to support pre 2.36.0 glib
https://bugzilla.gnome.org/show_bug.cgi?id=758614

[thaller@redhat.com: original patch modified to use nm_g_type_init()]
2015-11-25 10:15:32 +01:00
Beniamino Galvani
c3573ebf2b dhcp4: send FQDN option when ipv4.dhcp-fqdn is set
Modify the 3 DHCP client backends to support the new property.
2015-11-23 22:09:12 +01:00
Beniamino Galvani
dbbb08eb01 dhcp-manager: strip hostname sent by dhcpcd
The dhclient DHCP backend strips the domain part from the hostname
option sent to server; for consistency among different backends
uniform the dhcpcd client to do the same.
2015-11-23 16:31:08 +01:00
Beniamino Galvani
c09b12240e dhcp-manager: strip hostname sent by internal DHCP client
The dhclient DHCP backend strips the domain part from the hostname
option sent to server; for consistency among different backends
uniform the internal client to do the same.
2015-11-23 16:31:08 +01:00
Beniamino Galvani
aa22b2d87f systemd: merge branch 'systemd' into master 2015-11-23 16:18:10 +01:00
Beniamino Galvani
b8c2fc26c1 dhcp: pass IPv6 link-local address to DHCP client
The DHCP client from new libsystemd-network requires a link-local IPv6
address to be passed to the library; add a new argument to
nm_dhcp_manager_start_ip6() and related functions.
2015-11-23 15:58:17 +01:00
Dan Williams
b023d0754b exported-object: add support for DBus ObjectManager interface
NMExportedObject now derives from GDBusObjectSkeleton, which is what
GDBusObjectManagerServer wants.  The main GDBusConnection and each
private server connection now gets a new GDBusObjectManagerServer,
and exported objects are registered with that instead of individually
exporting each GDBusInterfaceSkeleton.

Previously exported objects were not referenced by the BusManager,
but instead removed from the exports hash via weak references.  The
GDBusObjectManagerServer instead references exported objects, which
can make them live much longer than they did before.

Co-Authored-By: Thomas Haller <thaller@redhat.com>
2015-11-18 15:15:05 +01:00
Thomas Haller
6c8aa669a4 platform: properly handle IPv4 peer-addresses
The peer-address (IFA_ADDRESS) can also be all-zero (0.0.0.0).
That is distinct from an usual address without explicit peer-address,
which implicitly has the same peer and local address.

Previously, we treated an all-zero peer_address as having peer and
local address equal. This is especially grave, because the peer is part
of the primary key for an IPv4 address. So we not only get a property of
the address wrong, but we wrongly consider two different addresses as
one and the same.

To properly handle these addresses, we always must explicitly set the peer.
2015-11-02 13:57:01 +01:00
Thomas Haller
a2d59f5f10 platform: add buffer argument to platform to-string functions
Arguably, it is more convenient to use the static buffer as
it saves typing.

But having such a low-level function use a static buffer also
limits the way how to use it. As it was, you could not avoid
using the static buffer.

E.g. you cannot do:

  char buf[100];

  _LOGD ("nmp-object: %s; platform-link: %s",
         nmp_object_to_string (nmpobj, buf, sizeof(buf)),
         nm_platform_link_to_string (link));

This will fail for non-obvious reasons because both
to-string functions end up using the same static buffer.

Also change the to-string implementations to accept NULL
as valid and return it as "(null)".

https://bugzilla.gnome.org/show_bug.cgi?id=756427
2015-11-01 17:28:08 +01:00
Beniamino Galvani
90fb64024c merge: merge branch 'systemd' into master 2015-10-08 14:14:19 +02:00
Lubomir Rintel
a8af3fae57 dhcp-systemd: sd_dhcp_lease_load() returns no lease or error on ENOENT
If the lease file doesn't exist sd_dhcp_lease_load() still indicates
success while not returning any lease, resulting in an assertion fail
when we try to generate an IP4Config:

  #0  g_logv (log_domain=0x7f309b45dba0 "NetworkManager", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7ffc815c38e0) at gmessages.c:1046
  #1  0x00007f3097d4fa3f in g_log (log_domain=log_domain@entry=0x7f309b45dba0 "NetworkManager", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7f3097dbd73d "%s: assertion '%s' failed")
      at gmessages.c:1079
  #2  0x00007f3097d4fa79 in g_return_if_fail_warning (log_domain=log_domain@entry=0x7f309b45dba0 "NetworkManager", pretty_function=pretty_function@entry=0x7f309b456b30 <__FUNCTION__.31435> "lease_to_ip4_config",
      expression=expression@entry=0x7f309b456417 "lease != NULL") at gmessages.c:1088
  #3  0x00007f309b35454a in lease_to_ip4_config (lease=0x0, options=options@entry=0x0, default_priority=default_priority@entry=100, log_lease=log_lease@entry=0, error=0x0) at dhcp-manager/nm-dhcp-systemd.c:230
  #4  0x00007f309b3546a0 in nm_dhcp_systemd_get_lease_ip_configs (iface=<optimized out>, uuid=<optimized out>, ipv6=<optimized out>, default_route_metric=100) at dhcp-manager/nm-dhcp-systemd.c:397
  #5  0x00007f309b35ed4a in find_ip4_lease_config (ext_ip4_config=0x7f309cbe8640, connection=0x7f309cb98250, self=0x7f309cbfb7b0) at devices/nm-device.c:7215
  #6  capture_lease_config (ext_ip6_config=0x0, out_ip6_config=0x0, out_ip4_config=0x7f309cbfb5d0, ext_ip4_config=0x7f309cbe8640, self=0x7f309cbfb7b0) at devices/nm-device.c:7289
  #7  update_ip4_config (self=self@entry=0x7f309cbfb7b0, initial=initial@entry=1) at devices/nm-device.c:7323
  #8  0x00007f309b3608be in nm_device_capture_initial_config (self=self@entry=0x7f309cbfb7b0) at devices/nm-device.c:7428
  #9  0x00007f309b3dbaad in get_existing_connection (out_generated=<synthetic pointer>, device=0x7f309cbfb7b0, manager=0x7f309cb7f150) at nm-manager.c:1550
  #10 recheck_assume_connection (device=device@entry=0x7f309cbfb7b0, user_data=user_data@entry=0x7f309cb7f150) at nm-manager.c:1689
  #11 0x00007f309b3dc62d in add_device (self=0x7f309cb7f150, device=0x7f309cbfb7b0, try_assume=1) at nm-manager.c:1875
  #12 0x00007f309b3dcd10 in platform_link_added (self=self@entry=0x7f309cb7f150, ifindex=<optimized out>, plink=plink@entry=0x7f309cbcff40) at nm-manager.c:1984
  #13 0x00007f309b3df7d4 in platform_query_devices (self=0x7f309cb7f150) at nm-manager.c:2056
  #14 nm_manager_start (self=0x7f309cb7f150) at nm-manager.c:4220
  #15 0x00007f309b341f2c in main (argc=1, argv=0x7ffc815c3f68) at main.c:494
2015-10-08 12:20:29 +02:00
Beniamino Galvani
76726b9922 dhcp-manager: fix memory leak in DHCP listener
Fixes: 7f6e39ec6e
2015-10-07 14:21:37 +02:00
Thomas Haller
7bf10a75db build: extract version macros from "nm-version.h" to new header file "nm-version-macros.h"
For libnm library, "nm-dbus-interface.h" contains defines like the D-Bus
paths of NetworkManager. It is desirable to have this header usable without
having a dependency on "glib.h", for example for a QT application. For that,
commit c0852964a8 removed that dependancy.

For libnm-glib library, the analog to "nm-dbus-interface.h" is
"NetworkManager.h", and the same applies there. Commit
159e827a72 removed that include.
However, that broke build on PackageKit [1] which expected to get the
version macros by including "NetworkManager.h". So at least for libnm-glib,
we need to preserve old behavior so that a user including
"NetworkManager.h" gets the version macros, but not "glib.h".

Extract the version macros to a new header file "nm-version-macros.h".
This header doesn't include "glib.h" and can be included from
"NetworkManager.h". This gives as previous behavior and a glib-free
include.

For libnm we still don't include "nm-version-macros.h" to "nm-dbus-interface.h".
Very few users will actually need the version macros, but not using
libnm.
Users that use libnm, should just include (libnm's) "NetworkManager.h" to
get all headers.
As a special case, a user who doesn't want to use glib/libnm, but still
needs both "nm-dbus-interface.h" and "nm-version-macros.h", can include
them both separately.

[1] https://github.com/hughsie/PackageKit/issues/85

Fixes: 4545a7fe96
2015-09-30 23:10:29 +02:00