Commit graph

146 commits

Author SHA1 Message Date
Umut Tezduyar Lindskog b5db00e52e sd-ipv4ll/networkd: generate predictable addresses
Increase the chance of using the same link local address between reboots. The
pseudo random sequence of addresses we attempt is now seeded with data that is
very likely to stay the same between reboots, but at the same time be unique
to the specific machine/nic.

First we try to use the ID_NET_NAME_* data from the udev db combined with the
machin-id, which is guaranteed to be unique and persistent, if available. If
that is not possible (e.g., in containers where we don't have access to the
udev db) we fallback to using the MAC address of the interface, which is
guaranteed to be unique, and likely to be persistent.

[tomegun: three minor changes:

 - don't expose HASH_KEY in the siphash24 header
 - get rid of some compile-warnings (and some casts at the same time),
   by using uint8_t[8] rather than uint64_t in the api
 - added commit message]
2014-03-21 20:24:10 +01:00
Brandon Philips 9765ce69e1 network: dhcp: create explicit host route to gateway
Some DHCP servers gives you a netmask of 255.255.255.255 so the gateway is not
routable. Other DHCP client implementations look through the existing routes to
figure out if they should add an explicit host route. See below for a link.

However, it makes sense to just create the route explicitly whether it is
needed or not since it is explicit, makes the dhcp route entries independent of
other entries and saves us from knowing the state of the kernel tables.

After patch route table on a machine with a network (common case):

default via 10.0.2.2 dev ens3
10.0.2.0/24 dev ens3  proto kernel  scope link  src 10.0.2.15
10.0.2.2 dev ens3  scope link

After patch route table on a machine without a network (this case):

default via 10.240.0.1 dev ens4v1
10.240.0.1 dev ens4v1  scope link

The code from dhcpcd that works around this issue is on line 637.
https://android.googlesource.com/platform/external/dhcpcd/+/master/configure.c
2014-03-21 17:52:42 +01:00
Tom Gundersen eb34d4af3f networkd: link - create dhcp and ipv4ll eagerly
Make sure the client objects exist for the lifetime of the Link.
2014-03-20 20:18:15 +01:00
Tom Gundersen c49b33aca6 networkd: update mac address in clients when it changes
Pass the mac address on to ipv4ll and dhcp clients so they always have
up-to-date information, and may react appropriately to the change.

Also drop setting the mac address from uevent, and only log when the
address actually changes.
2014-03-20 20:18:15 +01:00
Lennart Poettering 03e334a1c7 util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed,
and returns -1 unconditionally. This makes it easy to write lines like
this:

        fd = safe_close(fd);

Which will close an fd if it is open, and reset the fd variable
correctly.

By making use of this new scheme we can drop a > 200 lines of code that
was required to test for non-negative fds or to reset the closed fd
variable afterwards.
2014-03-18 19:31:34 +01:00
Tom Gundersen e09826dcf1 networkd: netdev - support joining already existing netdevs 2014-03-15 20:10:36 +01:00
Michael Olbrich eed0eee85a networkd: fix typo
It's HAVE_SPLIT_USR not HAVE_SPLIT_USER
2014-03-14 18:51:41 +01:00
Zbigniew Jędrzejewski-Szmek 315db1a8ae Do not return -1 (EINVAL) on allocation error 2014-03-14 09:31:34 -04:00
Tom Gundersen 06f021a804 networkd: allow more than one static DNS server 2014-03-14 12:44:17 +01:00
Tom Gundersen 0ea51a1129 networkd: fix creation of runtime dirs at startup
This allows us to drop the repeated attempted creations of the runtime dirs during runtime.
2014-03-14 12:44:17 +01:00
Tom Gundersen 2a1763edfb networkd: lease - store (up to) one dhcp lease file per interface
This removes an accidentally left-over test fragment.
2014-03-14 12:44:17 +01:00
Tom Gundersen f0c4cd7a2c networkd: rework startup
Open all listenerns before loading configuration.
2014-03-11 12:03:46 +01:00
Tom Gundersen a748b692dd network: link - simplify code a bit and remove some debug logging 2014-03-09 18:22:18 +01:00
Zbigniew Jędrzejewski-Szmek 58b129170c networkd: fix confusion from missing braces
Fixup for 76800848f2 'networkd: link - degrade failed UP to warning'.
2014-03-08 11:58:56 -05:00
Tom Gundersen 76800848f2 networkd: link - degrade failed UP to warning
Something else may still bring the link up, so don't enter failed state prematurely.
2014-03-08 01:12:46 +01:00
Daniel Mack 2c5859afec Make tables for DEFINE_STRING_TABLE_LOOKUP consistent
Bring some arrays that are used for DEFINE_STRING_TABLE_LOOKUP() in the
same order than the enums they reference.

Also, pass the corresponding _MAX value to the array initalizer where
appropriate.
2014-03-07 21:38:48 +01:00
Tom Gundersen 9842de0d93 networkd: use new rtnl_message_read() API 2014-03-07 17:39:04 +01:00
Tom Gundersen d22f1006a1 sd-rtnl/networkd: use new rtnl_message_read() API and drop helper
With the new sd_rtnl_message_read_string(), there is no longer a need for
rtnl_message_get_ifname().
2014-03-06 19:44:37 +01:00
Tom Gundersen 69629de9c8 networkd: listen to changes to the MAC address
Bridges will change their MAC address when other devices are enslaved. We need
the correct MAC address to acquire a DHCP lease, so take note of it whenever
it changes.
2014-03-05 11:53:29 +01:00
Mark Oteiza 0ad6148e87 networkd: restore logic for enslaving to a master bonding interface
This partially reverts commit 54abf46, which unintentionally removed the
enslaving support for bonding interfaces
2014-03-05 10:41:20 +01:00
Umut Tezduyar Lindskog 5c1d3fc93d sd-network: IPv4 link-local support [v2]
Implements IPv4LL with respect to RFC 3927
(http://tools.ietf.org/rfc/rfc3927.txt) and integrates it
with networkd. Majority of the IPv4LL state machine is
taken from avahi (http://avahi.org/) project's autoip.

IPv4LL can be enabled by IPv4LL=yes under [Network]
section of .network file.

IPv4LL works independent of DHCP but if DHCP lease is
aquired, then LL address will be dropped.

[tomegun: removed a trailing newline and a compiler warning]
2014-03-03 23:24:34 +01:00
Tom Gundersen b6b8adbff4 networkd: wait-online - fix typo 2014-03-03 23:24:34 +01:00
Thomas Hindoe Paaboel Andersen e1528e085c networkd-wait-online: use automatic cleanup 2014-03-01 23:16:55 +01:00
Tom Gundersen cb6fa44cb5 sd-network: turn states 'unknown' and 'unmanaged' into errnos 2014-02-28 02:08:08 +01:00
Tom Gundersen 020d59000f networkd: add networkd-wait-online
This is mostly a proof of concept to try sd-network, so we don't
hook it up with a .service file quite yet. We probably want it to
be more clever about deciding when we are 'online'.

The binary  will wait for at least one network managed by networkd,
and until all networks managed by networkd are configured.
2014-02-28 01:17:38 +01:00
Tom Gundersen fe8db0c5ee sd-network: add new library
This is similar to sd-login, but exposes the state of networkd rather than logind.

Include it in libsystemd-dhcp and rename it to libsystemd-network.
2014-02-28 01:01:13 +01:00
Tom Gundersen fe6b2d55bc networkd: add basic support for MACVLANs 2014-02-25 21:19:08 +01:00
Tom Gundersen 0c2f9b8469 networkd: handle SIGINT and SIGTERM 2014-02-22 21:24:36 +01:00
Tom Gundersen 12e0f830f5 test: always use assert_se in tests 2014-02-22 21:24:36 +01:00
Tom Gundersen bf175aafd2 net-util: match on the driver as exposed by ethtool if DRIVER not set
Also fix a copy-paste error that broke matching on interface name.
2014-02-21 22:59:29 +01:00
Tom Gundersen edbb03e95a .network/.netdev/.link: allow to match on architecture 2014-02-21 16:05:02 +01:00
Tom Gundersen c0dda18697 networkd: netdev - allow filtering on kernel cmdline, host and virt 2014-02-20 22:12:25 +01:00
Tom Gundersen 2cc412b593 network/link: Match - filter on kernel cmdline, host and virt 2014-02-20 21:50:34 +01:00
Lennart Poettering 151b9b9662 api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes
returned as last, sometimes as first and sometimes as second parameter.
Let's clean this up a bit. Here are the new rules:

1. The object the new object is derived from is put first, if there is any

2. The object we are creating will be returned in the next arguments

3. This is followed by any additional arguments

Rationale:

For functions that operate on an object we always put that object first.
Constructors should probably not be too different in this regard. Also,
if the additional parameters might want to use varargs which suggests to
put them last.

Note that this new scheme only applies to constructor functions, not to
all other functions. We do give a lot of freedom for those.

Note that this commit only changes the order of the new functions we
added, for old ones we accept the wrong order and leave it like that.
2014-02-20 00:03:10 +01:00
Lennart Poettering 39883f622f make gcc shut up
If -flto is used then gcc will generate a lot more warnings than before,
among them a number of use-without-initialization warnings. Most of them
without are false positives, but let's make them go away, because it
doesn't really matter.
2014-02-19 17:53:50 +01:00
Tom Gundersen 14efd7617b networkd: dhcp - log when lease is lost 2014-02-19 16:46:58 +01:00
Tom Gundersen 216816c6bc networkd: link - only reset transient hostname if it was set by us 2014-02-19 16:46:58 +01:00
Tom Gundersen 9b1c2626ce net-match: fix Driver= match
It should match on the driver of the parent device.
2014-02-18 22:34:26 +01:00
Tom Gundersen 11a7f22939 networkd: refactor link_add() :(
Don't set set **ret when returning r < 0, as matching on the errno may easily
give false positives in the future leading to null pointer dereference.

Reported-by: David Herrmann <dh.herrmann@gmail.com>
2014-02-18 22:34:26 +01:00
Tom Gundersen 482e2ac193 man: minor fixes to networkd page
Also enforce that we don't allow setting the Broadcast for IPv6 addresses.
2014-02-18 15:50:45 +01:00
Tom Gundersen 4fb7242cbb sd-rtnl-message: store reference to the bus in the message
This mimics the sd-bus api, as we may need it in the future.
2014-02-18 11:21:22 +01:00
Umut Tezduyar Lindskog 17256461f5 networkd: act on lease only if there is one
Interface could go down before acquiring a dhcp lease
2014-02-17 23:30:08 +01:00
Tom Gundersen 818dc5e72a sd-rtnl: always include linux/rtnetlink.h 2014-02-15 12:14:45 +01:00
Tom Gundersen ee3a6a51e5 sd-rtnl: message_open_container - don't take a 'size' argument
We can always know the size based on the type, so let's do this inside the library.
2014-02-15 12:14:45 +01:00
Lennart Poettering 31a4e15384 rtnl: support adding VETH_INFO_PEER containers into rtnl messages 2014-02-13 18:47:53 +01:00
Lennart Poettering d595c5cc9e rtnl: rename constructors from the form sd_rtnl_xxx_yyy_new() to sd_rtnl_xxx_new_yyy()
So far we followed the rule to always indicate the "flavour" of
constructors after the "_new_" or "_open_" in the function name, so
let's keep things in sync here for rtnl and do the same.
2014-02-13 13:53:25 +01:00
Lennart Poettering cf6a891173 rtnl: drop "sd_" prefix from cleanup macros
The "sd_" prefix is supposed to be used on exported symbols only, and
not in the middle of names. Let's drop it from the cleanup macros hence,
to make things simpler.

The bus cleanup macros don't carry the "sd_" either, so this brings the
APIs a bit nearer.
2014-02-13 03:44:14 +01:00
Tom Gundersen 624b5a636f networkd: correctly handle manager_free(NULL) 2014-02-13 01:41:32 +01:00
Tom Gundersen 60ad0c85e5 networkd: work inside containers
Udev does not run in containers, so instead of relying on it to tell us when a
network device is ready to be used by networkd, we simply assume that any
device was fully initialized before being added to the container.
2014-02-12 17:04:35 +01:00
Tom Gundersen 63ffa72022 networkd: link - correctly skip state ENSLAVING when no vlans configured
This fixes a regression introduced in 672682a6b
2014-02-10 23:01:47 +01:00