Commit graph

827 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
Tom Gundersen 4644fee04f sd-dhcp-client/sd-ipv4ll: allow mac address to be updated at any time
If necessary, restart the clients to deal with a changing mac address
at runtime. This will solve the problem of starting clients on bridges
before they have received their final MAC address.
2014-03-21 18:36:32 +01:00
Tom Gundersen 9e64dd7276 sd-dhcp-client: add fallback subnet masks
The DHCP RFC does not require the DHCP server to send a subnet mask, so if it
is missing, let's try to use the default subnet masks based on address class.
In case the class the address belongs to does not have a default subnet mask,
we fail as before.

Also improve logging when handling invalid dhcp messages, and simply ignore them
rather than stop the whole dhcp client.
2014-03-21 17:52:42 +01:00
Tom Gundersen 022446adf9 sd-dhcp-client: make timeout handling a bit more robust
Accept any lease lifetime greater than one second. Server should not
hand out extremely short leases, but let's not be the ones to fail.

Do not fail when arming a timer in the past, but also only arm one such
timer.

Avoid rounding errors when computing the default timeouts, this may be
an issue if we are handed a very short lease.

Also, don't pass 'time_now' around, as that can be found in the event
object when needed.
2014-03-21 17:52:42 +01:00
Tom Gundersen 58ec2d3e6e sd-dhcp-client: do not reset 'secs' when entering INIT-REBOOT
Also keep start_time in sync, but that shouldn't matter.
2014-03-20 17:07:43 +01:00
Tom Gundersen 6236f49b23 sd-dhcp-client: don't pass around 'secs'
The value is stored in the client object, so get it there when needed.
2014-03-20 17:07:43 +01:00
Patrik Flykt d790d3f173 libsystemd-dhcp: Update client test case for client id and end option
Check that the client identifier is formatted as suggested in the
RFC and that the messages sent ends with an end option.
2014-03-20 10:56:29 +02:00
Patrik Flykt 9d7bf1d58c libsystemd-network: Don't unnecessarily send too long packets
Since the length used by options is known, send packets with no
extra padding.
2014-03-20 10:55:27 +02:00
Patrik Flykt 715c6a9acd libsystemd-network: Prepend hardware type byte to client identifier
Even though client identifiers SHOULD be treated as opaque objects by
DHCP servers, follow the recommendation of a hardware type field with
value 0x01 (ethernet) followed by the hardware address as described in
RFC 2132.
2014-03-20 10:54:31 +02:00
Tom Gundersen 7bf2f43972 sd-dhcp-client: accept infinite lease lifetime
Otherwise we would fail with -EINVAL. Thanks to Brandon Philips
<brandon.philips@coreos.com>, for reporting the bug.
2014-03-19 10:41:29 +01:00
Patrik Flykt 8b1243f72e libsystemd-network: Add Init-Reboot support
Init-Reboot is tried if a client IP address has been given when
the DHCP client is started. In Init-Reboot, start by sending a
broadcast DHCP Request including the supplied client IP address
but without the server identifier. After sending the request,
enter Reboot state.

If a DHCP Ack is received, proceed to Bound state as usual. If a
DHCP Nak is received or the first timeout triggers, start the
address acquisition over from DHCP Init state.

See RFC 2131, sections 4.3.2, 4.4, 4.4.1 and 4.4.2 for details.
2014-03-19 10:52:40 +02:00
Patrik Flykt 0f941add36 libsystemd-network: Restart DHCP acquisition if the lease expires
This causes the DHCP client struct initialization and DHCP client
starting to be factored out into functions of their own.
2014-03-19 10:52:40 +02:00
Patrik Flykt 8fc8e3ab98 libsystemd-network: Add hangcheck timer for DHCP client test 2014-03-19 10:52:40 +02:00
Patrik Flykt a838c939a3 libsystemd-network: Export checksum function to test case
Remove identical checksum function implementation from the test
case code.
2014-03-19 10:52:40 +02: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 d23c45bfcc sd-dhcp-client: make sure timers fire immediately
The default slack caused there to be a delay before timers fired. Solve it
by setting timers that should trigger immediately to trigger far in the past.

This brings down the ideal-case dhcp lease acquisition time from about 500ms to
about 50ms (over a veth pair, so no network latency involved).

All the rest of the time (except for ~0.5ms) is spent in the bind() call in,
dhcp_network_bind_raw_socket(). I don't know if there is anything to be done
about that though...
2014-03-18 15:53:32 +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
Kay Sievers f937d3d662 test-dhcp-client: remove pointless initializer, wrongly committed earlier 2014-03-12 01:26:34 +01:00
Kay Sievers 4ef0809c22 build-sys: add libsystemd-label to network/dhcp users 2014-03-11 22:11:39 +01:00
Tom Gundersen 93570bd7ed sd-dhcp-client: use close_nointr_nofail()
We are already assuming the close() will not fail, so make it explicit.
2014-03-11 12:03:46 +01:00
Tom Gundersen 63edaa623b sd-dhcp: generalise ip header generation
This will be needed for sd-dhcp-server.
2014-03-11 12:03:46 +01:00
Tom Gundersen 02ec5cd78a sd-dhcp-client: log the MAC address we are using 2014-03-05 11:07:15 +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 8e34a618e2 sd-dhcp-lease: add sd_dhcp_lease_get_next_server() 2014-03-03 17:18:22 +01:00
Tom Gundersen 0ad853bc06 sd-dhcp-lease: add sd_dhcp_lease_get_server_identifier() 2014-03-03 16:48:02 +01:00
Tom Gundersen ce78df79b8 sd-dhcp-lease: add Root Path support
This is necessary when mounting /dev/nfs based on a DHCP lease.
2014-03-03 16:48:02 +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