Commit Graph

56 Commits

Author SHA1 Message Date
Lennart Poettering 4b58153dd2 core: add "invocation ID" concept to service manager
This adds a new invocation ID concept to the service manager. The invocation ID
identifies each runtime cycle of a unit uniquely. A new randomized 128bit ID is
generated each time a unit moves from and inactive to an activating or active
state.

The primary usecase for this concept is to connect the runtime data PID 1
maintains about a service with the offline data the journal stores about it.
Previously we'd use the unit name plus start/stop times, which however is
highly racy since the journal will generally process log data after the service
already ended.

The "invocation ID" kinda matches the "boot ID" concept of the Linux kernel,
except that it applies to an individual unit instead of the whole system.

The invocation ID is passed to the activated processes as environment variable.
It is additionally stored as extended attribute on the cgroup of the unit. The
latter is used by journald to automatically retrieve it for each log logged
message and attach it to the log entry. The environment variable is very easily
accessible, even for unprivileged services. OTOH the extended attribute is only
accessible to privileged processes (this is because cgroupfs only supports the
"trusted." xattr namespace, not "user."). The environment variable may be
altered by services, the extended attribute may not be, hence is the better
choice for the journal.

Note that reading the invocation ID off the extended attribute from journald is
racy, similar to the way reading the unit name for a logging process is.

This patch adds APIs to read the invocation ID to sd-id128:
sd_id128_get_invocation() may be used in a similar fashion to
sd_id128_get_boot().

PID1's own logging is updated to always include the invocation ID when it logs
information about a unit.

A new bus call GetUnitByInvocationID() is added that allows retrieving a bus
path to a unit by its invocation ID. The bus path is built using the invocation
ID, thus providing a path for referring to a unit that is valid only for the
current runtime cycleof it.

Outlook for the future: should the kernel eventually allow passing of cgroup
information along AF_UNIX/SOCK_DGRAM messages via a unique cgroup id, then we
can alter the invocation ID to be generated as hash from that rather than
entirely randomly. This way we can derive the invocation race-freely from the
messages.
2016-10-07 20:14:38 +02:00
Felipe Sateler 8dec4a9d2d core,network: Use const qualifiers for block-local variables in macro functions (#4019)
Prevents discard-qualifiers warnings when the passed variable was const
2016-08-23 12:29:30 +03:00
Tobias Jungel 6cad256dbe networkd-link: parse linkinfo to get kind 2016-06-09 21:42:05 +02:00
Lennart Poettering 1e7a0e21c9 network: beef up ipv6 RA support considerably
This reworks sd-ndisc and networkd substantially to support IPv6 RA much more
comprehensively. Since the API is extended quite a bit networkd has been ported
over too, and the patch is not as straight-forward as one could wish. The
rework includes:

- Support for DNSSL, RDNSS and RA routing options in sd-ndisc and networkd. Two
  new configuration options have been added to networkd to make this
  configurable.

- sd-ndisc now exposes an sd_ndisc_router object that encapsulates a full RA
  message, and has direct, friendly acessor functions for the singleton RA
  properties, as well as an iterative interface to iterate through known and
  unsupported options. The router object may either be retrieved from the wire,
  or generated from raw data. In many ways the sd-ndisc API now matches the
  sd-lldp API, except that no implicit database of seen data is kept. (Note
  that sd-ndisc actually had a half-written, but unused implementaiton of such
  a store, which is removed now.)

- sd-ndisc will now collect the reception timestamps of RA, which is useful to
  make sd_ndisc_router fully descriptive of what it covers.

Fixes: #1079
2016-06-06 20:11:38 +02:00
Tom Yan 720bec40e9 networkd-dhcp6: generalize DHCPv6 client (re)starting
dhcp6_request_address() was merely a function to switch the DHCPv6 client from "stateless" mode to "stateful" mode. It was also a one-way switch. Also, to (re)start the client, we would need to repeat separate function calls.

In this patch, dhcp6_request_address() is made a general starter/manager of the DHCPv6 client. It now takes an extra parameter so we will be specifying which mode the DHCPv6 client should be started in. Also it will keep track of the current mode and compare with the newly requested mode, and only restart the client in case there is a difference between them.

This also makes sure that the DHCPv6 client will be (re)started accordingly as per the Router Advertisement flags.
2016-06-01 14:54:46 +08:00
Lennart Poettering 7272b25e16 networkd: reworkd LLDP emission to allow control of propagation level
This allows selecting the propagation level of emitted LLDP packets
(specifically: the destination MAC address of the packets). This is useful
because it allows generating LLDP packets that optionally cross certain types
of bridges.

See 802.11ab-2009, Table 7-1 for details.
2016-05-09 15:45:31 +02:00
Zbigniew Jędrzejewski-Szmek 634f0f983c networkd: rework headers to avoid circular includes
Header files were organized in a way where the includer would add various
typedefs used by the includee before including it, resulting in a tangled
web of dependencies between files.

Replace this with the following logic:

          networkd.h
         /          \
networkd-link.h      \
networkd-ipv4ll.h--\__\
networkd-fdb.h         \
networkd-network.h    netword-netdev-*.h
networkd-route.h           \
                      networkd-netdev.h

If a pointer to a structure defined in a different header file is needed,
use a typedef line instead of including the whole header.
2016-04-29 19:01:28 -04:00
Lennart Poettering 8e1ad1eaf7 networkd: add basic LLDP transmission support
Let's add some minimalistic LLDP sender support. The idea is that this is
either on or off, and all fields determined automatically rather than
configured explicitly.
2016-02-21 20:58:59 +01:00
Lennart Poettering b9d74c40c6 networkd: make a couple of functions static
These functions are nowadays used only within networkd-link.c, hence ther's no
point in littering our public namespace with them.
2016-02-21 20:40:57 +01:00
Lennart Poettering b710e6b68d networkd: enable LLDP only on ethernet 2016-02-20 22:42:29 +01:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Thomas Hindoe Paaboel Andersen 71d35b6b55 tree-wide: sort includes in *.h
This is a continuation of the previous include sort patch, which
only sorted for .c files.
2015-11-18 23:09:02 +01:00
Tom Gundersen c601ebf79f sd-dhcp6-client: bind to link-local address
This ensures that several DHCPv6 clients can run on separate interfaces
simultaneously.
2015-11-17 14:17:41 +01:00
Tom Gundersen e7ab854c6c networkd: link - track state of IPv6LL address
This is managed by the kernel, but we should track whether or not we have
a configured IPv6LL address. This fixes two issues:
 - we now wait for IPv6LL before considering the link ready
 - we now wait for IPv6LL before attempting to do NDisc or DHCPv6
   these protocols relies on an LL address being available.
2015-11-11 15:42:38 +01:00
Tom Gundersen 3b015d40c1 networkd: ndisc - handle router advertisement in userspace
Router Discovery is a core part of IPv6, which by default is handled by the kernel.
However, the kernel implementation is meant as a fall-back, and to fully support
the protocol a userspace implementation is desired.

The protocol essentially listens for Router Advertisement packets from routers
on the local link and use these to configure the client automatically. The four
main pieces of information are: what kind (if any) of DHCPv6 configuration should
be performed; a default gateway; the prefixes that should be considered to be on
the local link; and the prefixes with which we can preform SLAAC in order to pick
a global IPv6 address.

A lot of additional information is also available, which we do not yet fully
support, but which will eventually allow us to avoid the need for DHCPv6 in the
common case.

Short-term, the reason for wanting this is in userspace was the desire to fully
track all the addresses on links we manage, and that is not possible for addresses
managed by the kernel (as the kernel does not expose to us the fact that it
manages these addresses). Moreover, we would like to support stable privacy
addresses, which will soon be mandated and the legacy MAC-based global addresses
deprecated, to do this well we need to handle the generation in userspace. Lastly,
more long-term we wish to support more RA options than what the kernel exposes.
2015-11-11 15:42:38 +01:00
Tom Gundersen f5a8c43f39 networkd: IPv6 router discovery - follow IPv6AcceptRouterAdvertisemnt=
The previous behavior:
When DHCPv6 was enabled, router discover was performed first, and then DHCPv6 was
enabled only if the relevant flags were passed in the Router Advertisement message.
Moreover, router discovery was performed even if AcceptRouterAdvertisements=false,
moreover, even if router advertisements were accepted (by the kernel) the flags
indicating that DHCPv6 should be performed were ignored.

New behavior:
If RouterAdvertisements are accepted, and either no routers are found, or an
advertisement is received indicating DHCPv6 should be performed, the DHCPv6
client is started. Moreover, the DHCP option now truly enables the DHCPv6
client regardless of router discovery (though it will probably not be
very useful to get a lease withotu any routes, this seems the more consistent
approach).

The recommended default setting should be to set DHCP=ipv4 and to leave
IPv6AcceptRouterAdvertisements unset.
2015-11-11 15:42:38 +01:00
Tom Gundersen 7a695d8e1f networkd: dhcp6 - split up configure() method
Enabling address acquisition, configuring the client and starting the client are now
split out. This to better handle the client being repeatedly enabled due to router
advertisements.
2015-11-11 15:42:38 +01:00
Tom Gundersen 1c8e710c2b networkd: route - track routes 2015-10-30 12:32:48 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Tom Gundersen 9b4d33193a networkd: dhcp6 - do not handle prefix expiration
This ressurects 47d45d3cde. We now always use /128 prefixes,
so there is no need for the DHCPv6 code to know about prefixes expiring.
2015-10-22 17:19:54 +02:00
Tom Gundersen a13c50e7a3 networkd: ndisc - split out from dhcp6 code 2015-10-22 17:19:54 +02:00
Tom Gundersen de1e9928f1 networkd: rename icmp6 to ndisc 2015-10-22 17:19:54 +02:00
Tom Gundersen 4d7b83da7b sd-ndisc: rename API from sd-icmp6-nd 2015-10-22 17:19:54 +02:00
Tom Gundersen 3ad0c5d8a4 sd-icmp6-nd: rename files to sd-ndisc
The actual code rename will follow. The reason for the change of name is to make it
simpler and more uniform with how we name other libraries (we don't include the
underlying protocol). The new name also matches the naming in the kernel (which
is particularly relevent here as we expect to let the kernel do some parts of
the protocol and we do others).
2015-10-22 17:19:54 +02:00
Tom Gundersen 84de38c569 networkd: manager/link - only serialize once per event-loop iteration
Every time the state is written out we may trigger third-party apps, so
let's be a bit more careful about writing this out unnecessarily.
2015-10-21 03:24:23 +02:00
Tom Gundersen adda1ed94a networkd: address - distinguish between addresses added by us and by others
We only keep the addresses that we added ourselves in link->addresses, and
introduce a new set link->addresses_foreign to keep addresses of unknown
origin.

Only functional change is that "foreign" addresses no longer prevent a link
from entering "configured" state.
2015-10-21 02:35:31 +02:00
Tom Gundersen 8012cd3919 networkd: link - only consider configured when all addresses are ready
We were considering a link configured whilst its IPv6 addresses were still
tentative.

Fixes issue #650.
2015-10-21 02:35:31 +02:00
Tom Gundersen 91b5f99731 networkd: make address_{establish,release}() static
No need to expose these functions, but rather call them from address_{add,drop}.
2015-10-11 15:04:16 +02:00
Tom Gundersen cf1d700da3 networkd: address - store active addresses in a Set rather than a List
We need to be able to look these things up quickly as we will be updating them
continuously and there can in principle be many of them.
2015-10-11 15:04:16 +02:00
Tom Gundersen 200a0868fc networkd: address - process in manager.c rather than link.c 2015-10-11 15:04:16 +02:00
Patrik Flykt 18d29550b5 networkd: Wait for DHCPv6 before announcing link configured
Wait until DHCPv6 has acquired an address before announcing the link
to be configured. Log the DHCPv6 lease lost event.
2015-09-23 15:24:04 +03:00
Lennart Poettering fc2f9534d0 networkd: split up networkd.h into per-object header files
No functional changes, just moving definitions into separate header
files.
2015-08-27 14:01:23 +02:00
Lennart Poettering 21b80ad126 networkd: optionally push dhcp timezone into timedated 2015-08-27 02:13:59 +02:00
Tom Gundersen 1c4baffc18 sd-netlink: rename from sd-rtnl 2015-06-13 19:52:54 +02:00
Lennart Poettering f2341e0a87 core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.

Also contains a couple of other logging improvements:

- Drops a couple of strerror() invocations in favour of using %m.

- Not only .mount units now warn if a symlinks exist for the mount
  point already, .automount units do that too, now.

- A few invocations of log_struct() that didn't actually pass any
  additional structured data have been replaced by simpler invocations
  of log_unit_info() and friends.

- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
  that works like LOG_MESSAGE() but prefixes the message with the unit
  name. Similar, there's now LOG_LINK_MESSAGE() and
  LOG_NETDEV_MESSAGE().

- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
  LOG_NETDEV_INTERFACE() macros have been added that generate the
  necessary per object fields. The old log_unit_struct() call has been
  removed in favour of these new macros used in raw log_struct()
  invocations. In addition to removing one more function call this
  allows generated structured log messages that contain two object
  fields, as necessary for example for network interfaces that are
  joined into another network interface, and whose messages shall be
  indexed by both.

- The LOG_ERRNO() macro has been removed, in favour of
  log_struct_errno(). The latter has the benefit of ensuring that %m in
  format strings is properly resolved to the specified error number.

- A number of logging messages have been converted to use
  log_unit_info() instead of log_info()

- The client code in sysv-generator no longer #includes core code from
  src/core/.

- log_unit_full_errno() has been removed, log_unit_full() instead takes
  an errno now, too.

- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
  avoid double evaluation of their parameters
2015-05-11 22:24:45 +02:00
Patrik Flykt be3a09b7ff network: Implement fallback DHCPv6 prefix handling for older kernels
When setting IPv6 addresses acquired by DHCPv6, systemd-networkd sets
the IFA_F_NOPREFIXROUTE flag in the IFA_FLAGS netlink attribute. As
the flag and the attribute are present starting with Linux 3.14, older
kernels will need systemd-network to manage prefix route expiry.

By default, DHCPv6 addresses are first assigned setting the
IFA_F_NOPREFIXROUTE flag in the IFA_FLAGS netlink attribute. Should
the address assignment fail, the same assignment is tried without
the IFA_FLAGS attribute. Should also the second attempt fail, an error
is printed and address assignment ends with failure. As successful use
of the IFA_FLAGS netlink attribute is recorded in the Link structure,
the DHCPv6 code will know if the kernel or systemd-network fallback
code handles expiring prefixes.

The prefix expiration and IPv6 address updating fallback code is
resurrected from the parts deleted with commit
47d45d3cde.

This patch can be removed once the minimum kernel requirements are
greater than or equal to 3.14.
2015-05-04 09:42:37 +03:00
Alin Rauta 0d4ad91dd4 networkd: add support for Uplink Failure Detection
Introduce BindCarrier= to indicate the set of links that determine if
the current link should be brought UP or DOWN.

[tomegun: add a bit to commit message]
2015-02-27 13:58:30 -05:00
Paul Martin 804319344b networkd DHCPv4 logging endian fix
On Tue, Feb 10, 2015 at 08:10:43PM +0100, Lennart Poettering wrote:

> Hmm, I think it would be nicer to use be32toh() here instead, since it
> ensures the macro is (to a limited degree) typesafe.
>
> Any chance you could rework that?

From: Paul Martin <paul.martin@codethink.co.uk>
Date: Wed, 11 Feb 2015 11:47:16 +0000
Subject: [PATCH] networkd dhcpv4 logging endian fix

On a big-endian host, systemd-networkd prints out IPv4 network
addresses byte reversed:

Feb 10 16:43:32 hostname systemd-networkd[151]: eth0 : DHCPv4 address 158.1.24.10/16 via 1.1.24.10

The address obtained is 10.24.1.158/16 and the route is

  10.24.0.0/16 dev eth0  src 10.24.1.187

The macro ADDRESS_FMT_VAL() unpacks a "struct in_addr" in a
little-endian specific manner.

This patch forces the passed address into host order, then unpacks it.

On an x86 later than i486, compiled with -O2, the only extra overhead
is a single bswap instruction.
2015-02-11 12:57:17 +01:00
Tom Gundersen d0d6a4cd70 networkd: generalize IPv4LL to LinkLocal
This allows both IPv4 and IPv6 link-local addresses to be enabled or disabled. By default
we still enable IPv6LL and disable IPv4LL. The old config option is kept for backwards
compatibility, but removed from the documentation.
2015-02-09 12:20:10 +01:00
Tom Gundersen a97dcc12e4 networkd: exit on idle
We will be woken up on rtnl or dbus activity, so let's just quit if some time has passed and that is the only thing that can happen.

Note that we will always stay around if we expect network activity (e.g. DHCP is enabled), as we are not restarted on that.
2015-02-05 12:04:19 +01:00
Tom Gundersen e331e24649 networkd: add basic dbus API
Only the very basics, more to come.

For now:

$ busctl tree org.freedesktop.network1
└─/org/freedesktop/network1
  └─/org/freedesktop/network1/link
    ├─/org/freedesktop/network1/link/1
    ├─/org/freedesktop/network1/link/2
    ├─/org/freedesktop/network1/link/3
    ├─/org/freedesktop/network1/link/4
    ├─/org/freedesktop/network1/link/5
    ├─/org/freedesktop/network1/link/6
    ├─/org/freedesktop/network1/link/7
    ├─/org/freedesktop/network1/link/8
    └─/org/freedesktop/network1/link/9

$ busctl introspect org.freedesktop.network1 /org/freedesktop/network1
NAME                                TYPE      SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.network1.Manager    interface -         -            -
.OperationalState                   property  s         "carrier" emits-change

$ busctl introspect org.freedesktop.network1 /org/freedesktop/network1/link/1
NAME                                TYPE      SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.network1.Link       interface -         -            -
.AdministrativeState                property  s         "unmanaged" emits-change
.OperationalState                   property  s         "carrier" emits-change
2015-02-05 11:50:34 +01:00
Tom Gundersen 9c0a72f961 networkd: handle suspend events 2015-02-03 22:20:38 +01:00
Susant Sahani 49699bac94 LLDP: Add support for networkctl 2014-12-19 08:15:05 +05:30
Susant Sahani ce43e48446 networkd: integrate LLDP
This patch integrates LLDP with networkd.

Example conf:
file : lldp.network

[Match]
Name=em1

[Network]
LLDP=yes
2014-12-19 08:02:45 +05:30
Patrik Flykt 5c79bd7983 networkd-dhcp6: Move ICMPv6 and DHCPv6 configuration to new file
Handle all aspects of ICMPv6 and DHCPv6 in a file of its own as is done
with DHCPv4 and IPv4LL.
2014-12-10 18:31:21 +01:00
Tom Gundersen 45af44d47d networkd: manager - enumerate addresses globally, rather than per-link
The kernel always returns all addresses, rather than only for the given link, so let's only enumerate once.
2014-12-08 22:13:40 +01:00
Lennart Poettering 6c861f0aef networkd: update logging macros for parameter order, and errno, to match rest of the code 2014-11-28 02:18:46 +01:00
Lennart Poettering 79008bddf6 log: rearrange log function naming
- Rename log_meta() → log_internal(), to follow naming scheme of most
  other log functions that are usually invoked through macros, but never
  directly.

- Rename log_info_object() to log_object_info(), simply because the
  object should be before any other parameters, to follow OO-style
  programming style.
2014-11-27 22:05:24 +01:00
Lennart Poettering 086891e5c1 log: add an "error" parameter to all low-level logging calls and intrdouce log_error_errno() as log calls that take error numbers
This change has two benefits:

- The format string %m will now resolve to the specified error (or to
  errno if the specified error is 0. This allows getting rid of a ton of
  strerror() invocations, a function that is not thread-safe.

- The specified error can be passed to the journal in the ERRNO= field.

Now of course, we just need somebody to convert all cases of this:

        log_error("Something happened: %s", strerror(-r));

into thus:

        log_error_errno(-r, "Something happened: %m");
2014-11-27 22:05:23 +01:00
Tom Gundersen a61bb41c29 networkd: move carrier gained/lost handling from link_update_flags() to link_update()
This allows us also to simplify link_has_carrier() a bit.
2014-09-04 14:10:57 +02:00