Commit Graph

790 Commits

Author SHA1 Message Date
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
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
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 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 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
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 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
Tom Gundersen 672682a6b9 networkd: VLAN - allow multiple vlans to be created on a link
Also limit the range of vlan ids. Other implementations and
documentation use the ranges {0,1}-{4094,4095}, but we use
the one accepted by the kernel: 0-4094.

Reported-by: Oleksii Shevchuk <alxchk@gmail.com>
2014-02-10 19:00:17 +01:00
Tom Gundersen d50cf59b94 networkd: fix setting dns from dhcp 2014-02-10 11:53:20 +01:00
Thomas Hindoe Paaboel Andersen ecd2f2c594 remove unused variables 2014-02-07 23:09:40 +01:00
Tom Gundersen a6cc569e33 sd-dhcp-client: split sd_dhcp_lease from sd_dhcp_client
This allows us users of the library to keep copies of old leases. This is
used by networkd to know what addresses to drop (if any) when the lease
expires.

In the future this may be used by DNAv4 and sd-dhcp-server.
2014-02-07 15:48:35 +01:00
Tom Gundersen 71acb5e7dc networkd: don't fail on DHCP errors 2014-02-01 16:51:35 +01:00
Tom Gundersen c07aeadfea networkd: dhcp - refactor handler 2014-01-31 12:20:34 +01:00
Tom Gundersen 50add2909c networkd: netdev - reduce chance of race when receiving netdev's ifindex
When creating a new link, the kernel will not inform us about the new ifindex
in its ack. We have to listen for newly created devices and deduce the new
ifindex by matching on the ifname.

We used to do this by waiting for a new device from libudev, but that is asking
for trouble, as udev will happily rename the device before handing it to us.
Listen on rtnl instead, the chance of the name being changed before reaching us
is much smaller (if not nil).

Kernel patch in the works to make this unneccessary.
2014-01-30 14:30:39 +01:00
Tom Gundersen 377a218f87 sd-dhcp-client/net-util: make netmask_to_prefixlen generic
This was originally included in the dhcp-client at my request, but it is not
really dhcp-specific and useful outside of it, so let's pull it out.
2014-01-30 14:30:39 +01:00
Tom Gundersen eb0ea358b6 networkd: address - add support for broadcast 2014-01-30 14:30:39 +01:00
Tom Gundersen eb27aeca24 networkd: dhcpv4 - add notion of 'CriticalConnection'
These connections are never torn down, even when the DHCP specifications say that
they should be. This is useful/necessary when the rootfs (or another critical fs)
is mounted over this network connection, and dataloss would result if the connection
is lost.

This option defaults to off, but our initrd generator (TBD) will enable it when
applicable.
2014-01-30 14:30:39 +01:00
Tom Gundersen c9ccc19f9e networkd: improve logging a bit
Fix/add some structured logging messages, and be uniform about when we WARN and ERR.
2014-01-25 11:39:22 +01:00
Tom Gundersen 54abf461d6 networkd: add basic VLAN support 2014-01-25 11:25:17 +01:00
Tom Gundersen 52433f6b65 networkd: add basic bonding support
Refactor bridging support to be generic netdev support and extend it to
cover bonding as well.
2014-01-22 17:56:49 +01:00
Tom Gundersen 5d4795f372 sd-rtnl: link - allow setting the change mask 2014-01-22 17:56:49 +01:00
Tom Gundersen e6674986de networkd: use 'up'/'down' rather than 'on'/'off' 2014-01-19 15:43:33 +01:00
Tom Gundersen b25ef18b33 sd-dhcp-client: refactor client_{free,new}
Make them more simiar to sd_bus and friends. Also factor out the event attachment. In the future,
we will likely want to support external main-loops, so this is a first step. For the time being,
we are still requiring an sd_event to be attached though.
2014-01-18 19:32:45 +01:00
Tom Gundersen bcbca8291f networkd: don't hard depend on system bus
We may not have a dbus daemon in the initrd (until we can rely on kdbus). In
this case, simply ignore any attempts at using the bus. There is only one user
for now, but surely more to come.

In order to work reliably in the real root without kdbus, but at the same time
don't delay boot when kdbus is in use, order ourselves after dbus.service.
2014-01-18 01:56:41 +01:00
Tom Gundersen 7ae4ef6d23 sd-dhcp-client: refactor DNS support
Rather than keeping an array of pointers to addresses, just keep an array of addresses.
2014-01-16 20:32:08 +01:00
Tom Gundersen 1346b1f038 sd-dhcp-client/networkd: add transient hostname support 2014-01-16 20:32:08 +01:00
Tom Gundersen 6fc7349894 networkd: dhcp - only set the MTU option once
Only set MTU request when creating the dhcp client, not every time it is restarted.
2014-01-16 20:32:08 +01:00
Tom Gundersen 396945dc1f networkd: link - only save original MTU when necessary 2014-01-16 20:32:08 +01:00
Tom Gundersen 1f6d9bc9ee networkd: improve logging 2014-01-16 20:32:08 +01:00
Tom Gundersen 4f882b2a50 sd-dhcp-client/networkd: add interface MTU support 2014-01-16 01:44:19 +01:00
Tom Gundersen 5be4d38e31 networkd: DHCPv4 - allow opting out of using DNS servers
Setting UseDNS=no will ignore any received DNS servers.
2014-01-13 21:54:57 +01:00
Tom Gundersen 3bef724f7e networkd: generate resolv.conf
This adds support to generate a basic resolv.conf in /run/systemd/network.
This file will not take any effect unless a symlink is created from
/etc/resolv.conf.

Nameservers received over DHCP takes precedence over statically configured ones.

Note: /etc/resolv.conf is severely limited, so in the future we will likely
rather provide a much more powerfull nss plugin (or something to that effect),
but this should allow current users to function without any loss of
functionality.
2014-01-12 15:37:21 +01:00
Tom Gundersen ab47d620b4 networkd: improve logging a bit 2014-01-12 15:37:21 +01:00
Zbigniew Jędrzejewski-Szmek 39032b8777 network: use GNU-ism to simplify macros
Thanks David!
2014-01-11 10:07:22 -05:00
Zbigniew Jędrzejewski-Szmek 628706137e networkd: print the received DHCPv4 address and gateway
It seems that networkd stores in_addr.s_addr contents in reverse
order (little-endian, not network order). This is a bit confusing,
but sd_rtnl evidently likes this order.
2014-01-08 22:15:27 -05:00
Zbigniew Jędrzejewski-Szmek 3333d748fa networkd: use structured logging for links and bridges 2014-01-08 22:15:27 -05:00
Tom Gundersen aa3437a573 networkd: print the ifindex of added links
This debug information may be useful when comapring to dropped rtnetlink messages.
2014-01-03 18:20:11 +01:00
Tom Gundersen 2672953bde networkd: improve logging
This gives a bit better messages when a link is added twice.
2014-01-03 16:56:09 +01:00
Tom Gundersen efbc88b8ed networkd: improve link state change logging 2014-01-03 16:20:10 +01:00
Tom Gundersen ff25413852 networkd: link - explicitly set the link to be up if the call to IFF_UP succeeds
No need to wait for the NEWLINK message to arrive.
2014-01-03 02:18:55 +01:00
Tom Gundersen b1b532f58c networkd: dhcp - avoid null pointer dereference 2014-01-03 01:42:26 +01:00
Tom Gundersen 1746cf2ad7 networkd: add more asserts and ignore all events when link has failed 2014-01-03 01:42:26 +01:00
Tom Gundersen 06a6e59301 networkd: only track state of links we are managing
If a network is not (yet) set for a link, we do not care about its state (as we
anyway don't know what to do with it).
2014-01-02 15:56:10 +01:00
Tom Gundersen 449f755492 networkd: improve logging
Remove redundant messages, add some debugging ones and make wording more uniform.
2014-01-02 15:49:23 +01:00
Kay Sievers be9326ca1d networkd: fix NULL pointer deref 2014-01-02 05:16:14 +01:00
Tom Gundersen 5eb036ca53 networkd: fix getting initial state
We were requesting the state and then ignoring it...
2014-01-02 01:43:05 +01:00
Tom Gundersen f5be560181 networkd: add DHCPv4 support
This adds basic DHCPv4 support. Link-sense is enabled unconditionally,
but the plan is to make that configurable.

I tested this in a VM with lots of NICs and over wifi in the various
coffee shops I found this Christmas, but more testing would definitely
be appreciated.
2014-01-01 16:26:27 +01:00
Tom Gundersen f048a16b46 networkd: distinguish between static and dynamic addresses/routes
Static addresses/routes are associated with a network. Dynamic
addresses/routes are associtade with links (as the corresponding network
may be shared by several links).
2014-01-01 16:23:00 +01:00
Tom Gundersen ef1ba6065c networkd: link - remove useless states
Rework the state-machine a bit.
2013-12-17 22:08:12 +01:00
Tom Gundersen 22936833e1 networkd: rename link_update_flags to link_update
We are likely to track more than the flags in the future.
2013-12-17 22:08:12 +01:00
Tom Gundersen b0d27a2508 networkd: correct logging message 2013-12-17 09:24:57 +01:00
Tom Gundersen 0f49a5f751 network: use SETLINK to bring up interfaces 2013-12-16 17:28:19 +01:00
Tom Gundersen fc25d7f805 rtnl: simplify link_new()
Drop most of the arguments and instead introduce link_set_{flags,type}.
2013-12-16 17:28:18 +01:00
Tom Gundersen dd3efc0993 networkd: add link-sense and simplify state-machine a bit
This listens to rtnetlink for changes to IFF_UP and IFF_LOWER_UP (link sense). The latter
is simply logged at the moment, but will be useful once we add dhcp support.
2013-12-04 14:15:13 +01:00
Tom Gundersen 02b59d57e0 networkd: add bridge support
A bridge is specified in a .netdev file with a section [Bridge]
and at least the entry Name=.

A link may be joined to a bridge if the .network applied to it has
a Bridge= entry giving the name of the bridge in its [Network] section.

We eagerly create all bridges on startup, and links are added to
bridges as soon as they both appear.
2013-11-26 01:32:25 +01:00
Tom Gundersen c166a07055 networkd: minor fixes
In particular, store the ifname, though we should only use it carefully, as
it is not guaranteed to be stable. Using it for logging is fine though.
2013-11-26 01:32:25 +01:00
Dave Reisner a9bc6d2df1 networkd: use correct printf formatter
uint64_t can be formatted correctly with %ju, rather than casting to
unsigned and potentially losing accuracy.
2013-11-25 18:19:49 -05:00
Tom Gundersen 5a3eb5a77d networkd: make sure Network and Link can always be freed
Also, don't fail a link just because we can't find its MAC address.
2013-11-21 21:04:04 +01:00
Tom Gundersen 602cc437e8 networkd: avoid segfault 2013-11-21 20:48:06 +01:00
Tom Gundersen 0617ffabe8 networkd: make sure Links and Networks are freed 2013-11-19 14:39:19 +01:00
Tom Gundersen f882c247ad networkd: make all calls async 2013-11-17 23:12:27 +01:00
Tom Gundersen 8cd11a0f0f networkd: store netmask and mac address explicitly 2013-11-17 23:11:11 +01:00
Tom Gundersen fe4824e065 rtnl: rename rtnl_bus_send_with_reply_and_block() to rtnl_bus_call()
Follow the equivalent rename in sd-bus to stay as similar as possible.
2013-11-13 19:48:44 +01:00
Tom Gundersen f579559b3a networkd: add a basic network daemon
This daemon listens for and configures network devices tagged with
'systemd-networkd'. By default, no devices are tagged so this daemon
can safely run in parallel with existing network daemons/scripts.

Networks are configured in /etc/systemd/network/*.network. The first .network
file that matches a given link is applied. The matching logic is similar to
the one for .link files, but additionally supports matching on interface name.

The mid-term aim is to provide an alternative to ad-hoc scripts currently used
in initrd's and for wired setups that don't change much (e.g., as seen on
servers/and some embedded systems).

Currently, static addresses and a gateway can be configured.

Example .network file:

[Match]
Name=wlp2s0

[Network]
Description=My Network
Gateway=192.168.1.1
Address=192.168.1.23/24
Address=fe80::9aee:94ff:fe3f:c618/64
2013-11-09 23:41:17 +01:00