Commit graph

120 commits

Author SHA1 Message Date
Tom Gundersen 68a8723c85 networkd: link - clean up state files
Also keep the path to the lease file around rather than regenarating it all the time.
2014-05-09 14:41:27 +02:00
Tom Gundersen bbf7c04821 sd-network: expose global operational state 2014-05-08 17:21:37 +02:00
Tom Gundersen 75adc2189b networkd: link - operstate is an enum, not a bitmask 2014-05-08 15:27:55 +02:00
Tom Gundersen 99b4cc3e75 networkd: link - always maintain link operstate regardless of admin state 2014-05-07 16:54:02 +02:00
Tom Gundersen deb2e5230b sd-network: expose both admin and operational state directly
Also add a call to check if a link is loopback, as this should commonly be ignored.
2014-05-07 16:54:02 +02:00
Umut Tezduyar Lindskog 8ddbeaa23c networkd: dont configure route if lease doesn't have one 2014-04-30 00:05:28 +02:00
Tom Gundersen 9b86b3930a networkd: link - don't fail a link if RF kill is active 2014-04-28 00:16:46 +02:00
Umut Tezduyar Lindskog d96e629fd7 networkd: do not complain about IFF_RUNNING
Otherwise:
eth0: unknown link flags gained: 0x00040 (ignoring)

[tomegun: hiding these messages is ok, as IFF_RUNNING is redundant
          and can be deduced from operstate and IFF_LOWER_UP]
2014-04-27 23:36:30 +02:00
Tom Gundersen 3a67e927e3 networkd-wait-online: improve interoptability and enable by default
To make sure we don't delay boot on systems where (some) network links are managed by someone else
we don't block if something else has successfully brought up a link.

We will still block until all links we are aware of that are  managed by networkd have been
configured, but if no such links exist, and someone else have configured a link sufficiently
that it has a carrier, it may be that the link is ready so we should no longer block.

Note that in all likelyhood the link is not ready (no addresses/routes configured),
so whatever network managment daemon configured it should provide a similar wait-online
service to block network-online.target until it is ready.

The aim is to block as long as we know networking is not fully configured, but no longer. This
will allow systemd-networkd-wait-online.service to be enabled on any system, even if we don't
know whether networkd is the main/only network manager.

Even in the case networking is fully configured by networkd, the default behavior may not be
sufficient: if two links need to be configured, but the first is fully configured before the
second one appears we will assume the network is up. To work around that, we allow specifying
specific devices to wait for before considering the network up.

This unit is enabled by default, just like systemd-networkd, but will only be pulled in if
anyone pulls in network-online.target.
2014-04-24 00:23:07 +02:00
Thomas Hindoe Paaboel Andersen cc544d5fb4 networkd: link - add missing curly brackets
introduced in 1e9be60bba
2014-04-22 21:45:17 +02:00
Tom Gundersen df9aa406e8 networkd: link - reduce default verbosity a bit 2014-04-22 21:06:00 +02:00
Tom Gundersen 1e9be60bba networkd: link - support IFLA_OPERSTATE
This properly detects the state of the link based on both the link flags and the
operstate.

Moreover, always log state-changes even if we are not yet managing the link.
2014-04-22 21:06:00 +02:00
Tom Gundersen 45ad2c1328 networkd: link - don't react to successfull link up
Avoid having two code-paths racing with eacother to do the same thing. The change
of flags will be detected in the normal way, so only use the link_up_handler
to detect if the 'up' failed and in that case fail the link.
2014-04-22 21:06:00 +02:00
Tom Gundersen 124fa2c601 networkd: link - log when starting clients fail 2014-04-22 21:06:00 +02:00
Tom Gundersen 2139694e82 networkd: link - avoid cycle when failing 2014-04-22 21:06:00 +02:00
Tom Gundersen 111bb8f93a networkd: link - stop clients when failing 2014-04-22 21:06:00 +02:00
Tom Gundersen 57bd6899b3 networkd: link - add explicit unmanaged state 2014-04-20 19:54:35 +02:00
Tom Gundersen 4bb40e8125 networkd: link - set mac addresses when starting clients
MAC addreses are also set when NEWLINK messages are receieved, but only if the clients have
already been initialized.
2014-04-20 19:34:53 +02:00
Tom Gundersen c6a1eb79a5 networkd: link - log changes in some common link flags 2014-04-20 19:20:26 +02:00
Tom Gundersen 75ee87c8c6 networkd: link - use IFF_DORMANT instead of IFF_RUNNING
Should be no functional change, but avoids spurious log
messages when in operstate UNKNOWN and !IFF_LOWER_UP.
2014-04-20 18:02:15 +02:00
Tom Gundersen 069e10a0e0 networkd: link - make debug logging a bit more readable
Drop leading zeros which will never be used when printing the link flags.
2014-04-20 14:42:57 +02:00
Tom Gundersen b8941f74c8 networkd: link - track interface renames 2014-04-19 20:39:29 +02:00
Tom Gundersen 505f8da732 networkd: tie links to rtnl rather than udev
This essentially swaps the roles of rtnl and udev in networkd. After this
change libudev is only used for waiting for udev to initialize devices and
to get udev-specific information needed for some [Match] attributes.

This in particular simplifies the code in containers where udev is not really
useful, but also simplifies things and reduces round-trips in the non-container
case.
2014-04-19 18:41:58 +02:00
Tom Gundersen 3379e257ee networkd: link - make state changing logging a bit less verbose 2014-04-14 17:55:47 +02:00
Tom Gundersen e9189a1f56 networkd: link - ignore missing MAC address from NEWLINK message
The kernel may broadcast such messages, simply discard them.
2014-04-14 17:53:01 +02:00
Tom Gundersen 7cc832b91e networkd: link - require both RUNNING and LOWER_UP before using link
Usually RUNNING implies LOWER_UP, but for drivers that don't support oper state, RUNNING can
also mean that the state is unknown. In that case we should just trust LOWER_UP directly.
2014-04-12 12:48:12 +02:00
Tom Gundersen ffba61663a networkd: wait for IFF_RUNNING rather than IFF_LOWER_UP
The interface is not fully ready until it enterns RUNNING. This was causing
problems with sending out DHCP messages before the interface was ready, so they
would get lost. In particular this affected DHCP INIT-REBOOT, as it relies on
the first package sent being successful (or it will fall back to a full reboot).

Also improve the logging a lot, to make future debugging of link state a lot
easier.
2014-04-12 12:06:28 +02:00
Tom Gundersen 702807365e networkd: add an assert
This error should never happen, so replace the check with an assert. The check
was anyway broken due to an uninitialized return value.

Reported by Thomas Hindoe Paaboel Andersen <phomes@gmail.com>.
2014-04-11 23:57:18 +02:00
Patrik Flykt 56cd007ab8 sd-ipv4ll: Add reference counting for IPv4LL
Similar to DHCP, the IPv4LL library user can decide to free the LL
client any time the callback is called. Guard against freeing the
LL client in the callback by introducing proper reference counting.

Also update code using the IPv4LL library to properly handle a
returned NULL from the notify and stop functions if the IPv4LL
client was freed.
2014-04-11 10:53:52 +03:00
Patrik Flykt e5b04c8de8 sd-dhcp-client: Add reference counting for DHCP
The DHCP library user can decide to free the DHCP client any time
the callback is called. After the callback has been called, other
computations may still be needed - the best example being a full
restart of the DHCP procedure in case of lease expiry.

Fix this by introducing proper reference counting. Properly handle
a returned NULL from the notify and stop functions if the DHCP
client was freed.
2014-04-11 10:53:10 +03:00
Tom Gundersen 7ff8f4b53c networkd: guard against NULL pointers
This should never be a problem, but better be safe than sorry.
2014-04-08 21:26:19 +02:00
Umut Tezduyar Lindskog aba496a58a networkd: smooth transition from ipv4ll to dhcp address
Currently when both ipv4ll and dhcp are enabled, ipv4ll
address (if one has been claimed) is removed when dhcp
address is aquired. This is not the best thing to do
since there might be clients unaware of the removal
trying to communicate.

This patch provides a smooth transition between ipv4ll
and dhcp. If ipv4ll address was claimed [1] before dhcp,
address is marked as deprecated. Deprecated address is still
a valid address and packets can be received on it but address
cannot be selected as a source address. If dhcp lease cannot
be extended, then ipv4ll address is marked as valid again.

[1] If there is no collision, claiming IPv4LL takes between 4 to
7 seconds.
2014-04-03 16:00:25 +02:00
Umut Tezduyar Lindskog 3e790eae01 networkd: drop routes when lease expires 2014-04-03 16:00:19 +02:00
Tom Gundersen 208612034e networkd: rewind rtnl message between passing it to functions
This makes updating link status on netdev links work again.
2014-03-31 17:17:56 +02:00
Tom Gundersen fd88eb8ab0 networkd: link - fix memory leak 2014-03-31 10:04:32 +02:00
Tom Gundersen c6f7c917a1 libsystemd-network: move network-utils from src/shared
This does not belong in shared as it is mostly a detail of our networking subsystem.

Moreover, now we can use libudev here, which will simplify things.
2014-03-21 21:54:37 +01:00
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
Zbigniew Jędrzejewski-Szmek 315db1a8ae Do not return -1 (EINVAL) on allocation error 2014-03-14 09:31:34 -04: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 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
Tom Gundersen 9842de0d93 networkd: use new rtnl_message_read() API 2014-03-07 17:39:04 +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