Commit Graph

238 Commits

Author SHA1 Message Date
Jiří Klimeš
49eda63e75 dhcp: add a testcase for distinguishing client identifier type
MAC-like string, but with an invalid char => plain ASCII string => quoted.
2013-09-09 09:14:38 +02:00
Dan Williams
b415b8a468 dhcp: add testcase for quoting problematic client identifiers 2013-09-06 11:20:08 -05:00
Jiří Klimeš
1ef19f377b dhcp: string vs. byte-array of dhcp-client-identifier (rh #999503)
Distinguish properly between ASCII strings and byte arrays for
dhcp-client-identifier. Else dhclient refuses to parse the configuration
file.
2013-09-06 11:20:00 -05:00
Thomas Haller
f4118492b6 fix: avoid call to g_file_test with NULL path in nm-dhcp-dhclient.c
Calling g_file_test with a NULL path causes valgrind to complain.

 NetworkManager[24512]: <debug> [1377884547.687536] [dhcp-manager/nm-dhcp-dhclient.c:482] create_dhclient_config(): (em1): no existing dhclient configuration to merge
 ==24512== Syscall param access(pathname) points to unaddressable byte(s)
 ==24512==    at 0x3F976E7627: access (in /usr/lib64/libc-2.17.so)
 ==24512==    by 0x4EDA556: g_file_test (in /usr/lib64/libglib-2.0.so.0.3600.3)
 ==24512==    by 0x49BB69: create_dhclient_config (nm-dhcp-dhclient.c:364)
 ==24512==    by 0x49CC39: ip4_start (nm-dhcp-dhclient.c:671)

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-08-30 19:53:25 +02:00
Dan Winship
bfce3f7dc8 build: switch from $(INCLUDES) to $(AM_CPPFLAGS) to make automake happy
Unfortunately, $(AM_CPPFLAGS) gets overridden by per-target _CPPFLAGS
variables, which $(INCLUDES) did not, so this requires some additional
changes.

In most places, I have just gotten rid of the per-target _CPPFLAGS
variables; in directories with a single target, the per-target
variable is unnecessary, and in directories with multiple targets, the
per-target variable is often undesirable, since it forces some files
to be compiled twice, even though there ends up being no difference
between the two files.
2013-08-22 11:49:16 -04:00
Pavel Šimerda
80c48a62be dhcp: kill dhclient on fatal errors
This helps to avoid dhclient DOSing the network.

https://bugzilla.gnome.org/show_bug.cgi?id=705137
2013-08-13 22:35:00 +02:00
Pavel Šimerda
320a9d16a3 all: replace struct in_addr with guint32 2013-08-03 00:15:07 -05:00
Pavel Šimerda
6762b2f792 core: use NMIP[46]Route in nm-ip[46]-config 2013-08-03 00:15:07 -05:00
Pavel Šimerda
e0f37dce45 dhcp: fix IPv6 address timestamp setting 2013-07-30 16:36:47 +02:00
Pavel Šimerda
53e55aab36 dhcp: push address lifetime to nm-ip[46]-config 2013-07-30 11:40:19 +02:00
Dan Williams
86a197f177 dhcp: add debug logging to config file merging 2013-07-22 14:28:48 -05:00
Dan Williams
1364ccb2c2 dhcp: also check for config files by UUID 2013-07-22 14:28:48 -05:00
Pavel Šimerda
d8e6065f63 core: switch nm-ip4-config's NMIP[46]Address to NMPlatformIP[46]Address 2013-07-20 15:30:08 +02:00
Pavel Šimerda
7c0657a119 core: cleanup nm-ip[46]-config 2013-07-12 11:38:35 +02:00
Martin Pitt
fd4709fa27 core: add option for running from the build tree
Add hidden command line option --run-from-build-dir; with that, helpers
like nm-avahi-autoipd.action and nm-dhcp-helper will be called from the
build tree instead of libexecdir, which allows testing without having to
install first.

Helper paths are now stored in global variables instead of macros, and
get modified with that new option.

https://bugzilla.gnome.org/show_bug.cgi?id=698752
2013-05-22 16:17:23 +02:00
Dan Williams
04cb58eacd core: convert the DBus manager to a single-ref object
It's created very, very early and never needs to be unrefed
by anything except the main() function.
2013-05-20 16:38:33 -03:00
Dan Williams
b9ea3ed1b1 build: don't install nm-dhcp-helper dbus permissions if we don't need to
The DHCP helper uses a private socket when building with dbus-glib >= 0.100,
which means we don't need to install a D-Bus permissions file.
2013-05-14 15:37:41 -05:00
Dan Winship
c4417c71b6 core: use non-recursive build
Although having different parts of NM in different subdirectories
keeps the source tree neat, it has made the build messy, particularly
because of cross-dependencies between the subdirs.

Reorganize to build all of the pieces of the NetworkManager binary
from src/Makefile, and only use recursive make for test programs,
helper binaries, and plugins.

As part of this, get rid of all the per-directory convenience
libraries, and switch to building a single top-level
libNetworkManager.la, containing everything except main.c, which all
of the test programs can then link against.
2013-05-08 15:07:18 -04:00
Dan Winship
d529580cbb libnm-glib, core: use g_cclosure_marshal_generic
Since we depend on new glib now, we can just use the generic
marshaller rather than generating our own.
2013-05-08 14:59:29 -04:00
Martin Pitt
57a9fb3c89 Use %NULL macro in doc strings
Mass-converted "NULL" to "%NULL" in docstrings with

  find -name '*.c'| xargs sed -i '/^ \*.*[^%]NULL/ s/NULL\b/%NULL/g'
2013-04-19 10:08:17 -04:00
Dan Williams
b69171061c dhcp: use private socket to return status if available
Allows DHCP to work when a bus daemon isn't running.  This also
fixes a race condition where when multiple interfaces are attempting
to get a DHCP lease at the same time, if one DHCP client instance
triggers the callout, that instance gets the bus name, and any
other client triggering the callout at that time will fail because
the bus name is already taken.  Since this commit allows using
a private socket, where no process has a bus name, this race is
avoided.

Also move the DHCP helper from callouts/ to src/dhcp-manager/ to
consolidate all the DHCP stuff and clean up some of the helper's
code.
2013-04-08 11:30:31 -05:00
Dan Winship
213a3a4d2e core: don't pass config data to NMDHCPManager and NMDnsManager
Rather than passing specific bits of data to NMDHCPManager and
NMDnsManager, just let them call nm_config_get() and then get the data
themselves.

Also, remove the GError argument from nm_dhcp_manager_new(), since the
function never returned NULL. This in turn means there is no longer
any need for a distinction between nm_dhcp_manager_new() and
nm_dhcp_manager_get(), so remove the former.
2013-04-03 10:23:48 -04:00
Pavel Šimerda
eb2b990ddc trivial: rename rand to avoid -Wshadow 2013-04-02 11:03:47 +02:00
Dan Williams
5d6d5cd136 dhclient: copy leasefiles from old location if needed (rh #916233) (bgo #696210)
When the default leasefile location got moved from distro-specific
dhclient locations to a single NM-specific location, that apparently
broke scripts and external tools that depended on the old location,
like dract netbooting.

During a netboot, DHCP is started from the initramfs and gets a
lease, and the leasefile lives in the initramfs.  When the real
system is started, and the rootfs switches from the initramfs to
the actual rootfs, something needs to copy the leasefiles over to
where NetworkManager can find them.  For dracut at least, various
dracut scripts were doing this, and copying to the old location
in /var/lib/dhclient or /var/lib/dhcp.  Which means NM can no
longer find them, and proceeds to acquire a new DHCP lease when
taking over the existing connection, rather than renewing the
existing lease.  This can lead to loss of network connectivity
and thus the netboot process fails.

If no leasefile for the connection in the new location exists,
look in the old locations and copy that leasefile over to the new
location.
2013-03-26 15:26:18 -05:00
Dan Williams
c934038b59 dhcp: fix up testcase for "also request static-routes;" 2013-03-21 13:20:13 -05:00
Dan Williams
0bf0ee7136 dhcp: look harder for machine-id, and generate random DUID if it doesn't exist (bgo #696109)
Not all systems have machine-id in /etc, some still have it in /var/lib/dbus/
especially if they aren't using systemd.  Furthermore, if we don't have
any machine-id file (like in the future, if we don't have a messaebus
daemon running) fall back to a random DUID as a last resort.
2013-03-20 11:28:53 -05:00
Dan Williams
3e293e1101 dhcp: we don't always have an NMSettingIP6Config for the DHCP hostname
Prevents:

NetworkManager[19405]: nm_setting_ip6_config_get_dhcp_hostname: assertion `NM_IS_SETTING_IP6_CONFIG (setting)' failed
2013-03-20 11:28:22 -05:00
Jiří Klimeš
a96053fe13 dhclient: also request 'static-routes' option from DHCP server (rh #922558)
DHCP server won't send 'Static Route' option to the client if it is not
explicitly requested.
2013-03-20 10:00:42 +01:00
Dan Winship
6f44b7f3c6 all: remove redundant return-if-fail checks
NM_IS_FOO(x) returns FALSE if x is NULL, so we don't need a separate
(x != NULL) check before it.
2013-03-07 07:32:27 -05:00
Dan Williams
97990135f1 dhcp: ensure any dhclient script from dhclient.conf is ignored
The config file can specify a dhclient script, which gets used instead
of what NM passes on the command-line.  Make sure that script gets
ignored in the final dhclient config, because the script NM passes
is the script that needs to be used to pass data back to NM.  People
may have old dhclient.conf files lying around that get picked up and
we don't want any script specified there to interfere.
2013-02-27 17:17:11 +01:00
Dan Winship
f936400c38 tests: clean up gtester usage
Use g_test_add_func() and g_test_add_data_func() to simplify the test
cases, getting rid of the GLIB_CHECK_VERSION calls in the process.
2013-02-26 13:07:33 +01:00
Dan Williams
cc7e5cc591 dhcp: debug log generated DUID 2013-02-14 16:19:10 -06:00
Dan Williams
1b1b4bd91c dhcp: write DUID out to lease file if not already present
Ensure that dhclient uses the administrator-specified or machine-id
generated DUID.
2013-02-14 16:19:05 -06:00
Gene Czarcinski
c0efef8c92 dhcp: add special machine-id parse function
The original used uuid_parse() but that function did not
work properly since the format of the machine-id is
not compatable with a real uuid.  This patch adds a new
machine_id_parse() routine to correctly convert the
character string of hex digits to a 16 byte binary string.
2013-02-14 16:18:59 -06:00
Dan Winship
d04f286327 all: remove pointless NULL checks
g_malloc(), etc, never return NULL, by API contract. Likewise, by
extension, no other glib function ever returns NULL due to lack of
memory. So remove lots of unnecessary checks (the vast majority of
which would have immediately crashed had they ever run anyway, since
g_set_error(), g_warning(), and nm_log_*() all need to allocate
memory).

https://bugzilla.gnome.org/show_bug.cgi?id=693678
2013-02-13 13:38:13 -05:00
Dan Williams
140ebbbf89 dhcp: generate DUID-UUID from /etc/machine-id (bgo #691885)
DHCPv6 RFCs require the DUID to be constant over time and to
be used as a permanent identifiers of the machine.  This precludes
using a network interface MAC address since the MAC address may
change, and there may be more than one network interface installed.

Storing the DUID causes problems when an OS image is cloned between
virtual or physical machines because then the saved DUID is no longer
unique.

To fix all these issues, generate the DUID from the machine's hashed
machine-id, which is already a unique identifier of the machine and
will always be present because dbus requires it, and NM requires
dbus.  It is assumed administrators will change the machine-id when
cloning an OS image; thus they only have to update one file, not
two (machine-id and the stored DUID).

Administrators may still override the machine-id-derived DUID by
setting a DUID in the default dhclient config file or the
interface-specific dhclient config files.

dhclient no longer saves a generated DUID to the config files,
because the default DUID will always be regenerated from
the machine-id on startup and thus always stable.
2013-02-07 12:38:58 -06:00
Dan Williams
9ee46b45f1 dhcp: fix infinite loop when escaping DUID
Oops; only enabled when debugging was turned on, but still sucks.
2013-02-05 09:23:08 -06:00
Dan Williams
e15d161289 dhclient: add testcases for reading DUIDs from leasefiles 2013-01-29 10:18:42 -06:00
Dan Williams
62a940ab7b dhclient: save DUID to dhclient leasefiles when required
The DUID is supposed to be machine-wide, so if we're writing a new
leasefile, save the default DUID to it.  If we haven't saved a
persistent DUID yet, do that to.
2013-01-29 10:18:42 -06:00
Mathieu Trudel-Lapierre
ab4bc03de2 dhclient: read DUID from leasefiles 2013-01-29 10:18:42 -06:00
Dan Williams
dc518cf86b dhcp: add generic DUID infrastructure
Add infrastructure for generating DUID-LLT from a given device MAC and
passing it around to the DHCP client implementations.

Thanks to Mathieu Trudel-Lapierre for bug fixes in the
unescaping code, which were merged into this commit.
2013-01-29 10:16:45 -06:00
Dan Williams
c4e519bd78 dhcp: pass device hardware address to DHCP
Gets used for stuff like the interface DUID for DHCPv6.
2013-01-29 10:07:54 -06:00
Mathieu Trudel-Lapierre
f41f41506c dhcp: ensure hostname is sent to the DHCP server for default wired connections
For the default wired connection (or any connection that doesn't have an IPv4
setting, which means "auto"), the hostname should always be sent to the DHCP
server to register in DNS.
2012-12-04 12:21:24 -06:00
Gene Czarcinski
90b99522d7 dhcp: fix DHCPv6 to support server-side dynamic DNS (bgo #684242)
This patch makes DHCPv6 support more or less equivalent to that
one of IPv4 DHCP.

(dcbw: fix some formatting, rearrange code so it's less convoluted,
fix up writing hostname to ifcfg files)
2012-11-16 17:26:19 -06:00
Pavel Šimerda
1a7e7c9031 dhcp: check for distribution dhclient.conf at runtime
For NetworkManager, dhclient is a runtime dependency. Distribution dhclient
configuration is either put directly into /etc or in /etc/dhcp. It is much
safer to check this at runtime than to guess the location from distribution
name.

Additionally, the distribution dhclient configuration files can be overriden
by a configuration file in /etc/NetworkManager.

TODO: Functions get_dhclient_config() and merge_dhclient_config() should
be also used for IPv6.
2012-11-16 15:27:22 -06:00
Pavel Šimerda
20d4125cfc dhcp: store NetworkManager-specific dhclient leases in /var/lib/NetworkManager/
DHCP lease file names are built by NetworkManager and contain connection UUID
which makes them NM-specific. Their new location belongs to NetworkManager and
doesn't have to be guessed. With no guessing, we don't need distribution-specific
conditionals.

Note: This change may require modifications to the selinux policy. But after all
these files actually belong to NetworkManager as well as the instance of dhclient
that uses them.
2012-11-16 15:27:22 -06:00
Pavel Šimerda
077fafa870 dhcp: drop support for dhclient 3.x
ISC DHCP client 3.x doesn't support DHCP for IPv6 and is not used
in current distributions.
2012-11-16 15:27:22 -06:00
Pavel Šimerda
a52fba46fe dhcp: do not require dhclient to support '-4' option (bgo #679428)
dhclient only supports '-4' option when built with IPv6 support. In all
cases it defaults to IPv4 when it is not specified.

Inspired by Gentoo.
2012-11-16 15:27:22 -06:00
Pavel Šimerda
faa1bcb540 build: improve documentation and test configure options
Use --enable-doc and --enable-tests instead of --with-docs and
--with-tests. This is consistent with other features and with
--enable-gtk-doc option. Support current variants as fallback.

Don't build tests unless --enable-tests is specified.
2012-11-13 20:23:06 +01:00
Pavel Šimerda
d82669d3fd build: unify NetworkManager path handling (some paths are changed)
Use autoconf/automake variables for NetworkManager paths. Use
NetworkManager subdirectory where appropriate.

Files in /var/run (or /run on some distros) are moved into a separate
directory as is usual with other daemons. It makes the filesystem
more readable and file prefixing unnecessary.

/var/run/NetworkManager.pid -> /var/run/NetworkManager/NetworkManager.pid
/var/run/nm-dns-dnsmasq.pid -> /var/run/NetworkManager/dnsmasq.pid
/var/run/nm-dns-dnsmasq.conf -> /var/run/NetworkManager/dnsmasq.conf

The /var/run/NetworkManager directory is created at runtime, if it doesn't
exist.

Note: Path-based security policies like SELinux and AppArmor may need to
be adapted.
2012-11-05 14:01:47 +01:00