Commit Graph

58 Commits

Author SHA1 Message Date
Lennart Poettering 437524f178 sd-ndisc: generate debug log messages on unexpected errors
We really should make it possible to debug unexpected errors, hence log
something at LOG_DEBUG.
2018-10-02 16:25:54 +02:00
Yu Watanabe 8301aa0bf1 tree-wide: use DEFINE_TRIVIAL_REF_UNREF_FUNC() macro or friends where applicable 2018-08-27 14:01:46 +09:00
Lennart Poettering 810adae9e9 tree-wide: use proper unicode © instead of (C) where we can
Let's use a proper unicode copyright symbol where we can, it's prettier.

This important patch is very important.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Patrik Flykt e82a19cb18 sd-ndisc.c: Move Router Solicitation sending after timer computaion
Move ICMPv6 Router Solicitation sending after timer computation so
that timers are already set up when the packet is being sent. This
makes it possible to create a test that inspects Router
Solicitation timer values when the Router Solicitation is sent out
on the network.
2017-05-30 10:34:15 +03:00
Patrik Flykt 1bd6f8953d sd-ndisc: Implement Router Solicitation backoff method
Instead of sending a fixed amount of Router Solicitiations, implement
the backoff algorithm proposed in RFC 7559. The backoff algorithm is
the same as used by DHCPv6.

Time out after 12s as specified in RFC 4861 in order not to delay
setting up a link for too long while sending Router Solicitations
in the background. Notice that after this change the callback will
receive a SD_NDISC_EVENT_TIMEOUT timeout event, and at a later point
when a router appears, a received Router Advertisment will cause the
callback to be called again with the SD_NDISC_EVENT_ROUTER event.
2017-05-30 10:34:15 +03:00
Patrik Flykt 88d5a3db55 sd-radv: Receive Router Solicitations
Receive Router Solicitations and send a unicast Router Advertisment
in response. Refactor ICMPv6 packet handling code so that the common
ICMPv6 validation parts are reused between the existing router
discovery and the new functionality adding reception of Router
Solicitation messages.
2017-05-15 14:49:50 +03:00
Patrik Flykt 7feeb89980 sd-ndisc: Reset counter for sent Router Solicitations (#5874)
Reset also the counter for number of Router Solicitations sent when
the associated file descriptor is closed and the event source
unreferenced. With this change the router discovery can now be
stopped and restarted arbitrary many times.
2017-05-02 15:36:24 -04:00
Zbigniew Jędrzejewski-Szmek 6b430fdb7c tree-wide: use mfree more 2016-10-16 23:35:39 -04:00
Lennart Poettering a48072b703 sd-ndisc: add missing cast
Apparently newer gcc versions are a bit more forgiving when assigning an
"unsigned char*" pointer to something of a different type. Let's add the
missing cast so that old gcc versions are fine, too.
2016-06-14 20:01:45 +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
Lennart Poettering 9c4f6ccb70 sd-ndisc: small coding style fixes
Let's use usec_t internally always, when dealing with time values.

Let's use uint8_t* pointers if we are dealing with generic byte pointers.
2016-05-26 15:34:43 +02:00
Lennart Poettering 79b490b796 sd-ndisc: add more whitespace
Whitespace doesn't hurt and helps structuring things.
2016-05-26 15:34:43 +02:00
Lennart Poettering b9e7b1cf06 sd-ndisc: stop discovery properly when something fails 2016-05-26 15:34:43 +02:00
Lennart Poettering 901c983b6d sd-ndisc: rework size checking in ndisc_ra_parse()
Let's better check the size before we subtract. Also, let's change the size
argument to size_t, as it cannot be signed anyway.

Finally, use EBADMSG for indicating invalid packets, like we do everywhere
else.
2016-05-26 15:34:43 +02:00
Lennart Poettering 745c5152c2 sd-ndisc: simplify clamping of router "pref" parameter 2016-05-26 15:34:43 +02:00
Lennart Poettering 3e261cfd3c sd-ndisc: append "event_source" to event source objects stored in structures
Otherwise it gets too confusing whether "timeout" refers to an event source or
just a timeout time specification.
2016-05-26 15:34:43 +02:00
Lennart Poettering ad2998abd5 sd-ndisc: add log_ndisc_errno() macro, to complement log_ndisc() like elsewhere
Also make use of it where appropriate.
2016-05-26 15:34:43 +02:00
Lennart Poettering b3dfcf6a76 sd-ndisc: use the right object to pass to log_ndisc()
There's no "client" object, in both cases. There's only "nd".

This wasn't noticed before, as the context object is currently not actually
used by the log macros.
2016-05-26 15:34:43 +02:00
Lennart Poettering d54b734adc sd-ndisc: Typo fix: s/advertisment/advertisement/ 2016-05-26 15:34:43 +02:00
Lennart Poettering c1c9b211e3 sd-ndisc: make the _stop() call idempotent
It's a good idea to make stopcalls idempotent, so that they become nops if the
object is already stopped.
2016-05-26 15:34:42 +02:00
Lennart Poettering a114066685 sd-network: fix up assertion chaos
assert_return() should only be used to validate user-facing parameters and
state, assert() should be used for checking our own internal state and
parameters.
2016-05-26 15:34:42 +02:00
Lennart Poettering 5c4c338adc sd-ndisc: rename sd_ndisc_init() to sd_ndisc_reset()
After all, it's actually used for resetting the state, not only for the initial
initialization.

While we are at it, also simplify the error path for
sd_ndisc_discovery_start().
2016-05-26 15:34:42 +02:00
Lennart Poettering 2f8e763376 sd-network: rename "index" field of the various clients to "ifindex"
A field "index" is not particularly precise and also might conflict with libc's
index() function definition. Also, pretty much everywhere else we call this
concept "ifindex", including in networkd, the primary user of these libraries.
Hence, let's fix this up and call this "ifindex" everywhere here too.
2016-05-26 15:34:42 +02:00
Lennart Poettering 9c2438b84e sd-ndisc: properly make various parameters unsigned 2016-05-26 15:34:42 +02:00
Lennart Poettering 004845d18e sd-network: unify packet processing logic a bit
Let's always check for errno being EAGAIN/EINTR the same way, and always log if
we receive weirdly short packets.
2016-05-26 15:34:41 +02:00
Lennart Poettering 32d2064523 libsystemd-network: sd-event uses 64bit priorities, expose them in the APIs as such 2016-02-20 22:42:29 +01:00
Lennart Poettering 4edc2c9b6b networkd: FIONREAD is not reliable on some sockets
Fixes: #2457
2016-02-16 13:06:55 +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
Zbigniew Jędrzejewski-Szmek c952944ef8 sd-ndisc: simplify if stmt and reindent log messages
Merge separate two error handling statements into two nested ifs.
This looks cleaner, and avoids a gcc warning about *prefix being
uninitialized.

While at it, fix identation of logging statements elsewhere in the
file.
2016-01-18 15:21:28 -05:00
Zbigniew Jędrzejewski-Szmek b0e6520c42 sd-ndisc: simplify ndisc_prefix_new
If the initial allocation succeeded, there is no way to
fail, so cleanup function is not necessary.
2016-01-18 15:21:27 -05:00
Lennart Poettering 4afd3348c7 tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.

With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.

The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).

This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.

Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:

       #define _cleanup_(function) __attribute__((cleanup(function)))

Or similar, to make the gcc feature easier to use.

Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.

See #2008.
2015-11-27 19:19:36 +01:00
Tom Gundersen cddf4d81ea sd-ndisc: better validate RA packets
Verify the hoplimit and that the received packet is large enough for the RA
header.

See <http://tools.ietf.org/html/rfc4861#section-6.1.2>.
2015-11-25 18:30:31 +01:00
Tom Gundersen 6d06ac1faa sd-ndisc: always send the link-layer address
We never send packets without first knowing the link-local L3 address,
so we should always include the L2 address in RS packets.
2015-11-25 18:30:31 +01:00
Tom Gundersen 0d43d2fcb7 libsystemd-network: clean up recv functions 2015-11-25 18:30:31 +01:00
Tom Gundersen d7fa4380c8 nd-ndisc: don't fail if src address is unset
This happens when running our test-suite over a socketpair,
so don't fall over in that case.

Fixes issue #1952.
2015-11-19 13:55:15 +01:00
Tom Gundersen 3ccd316353 sd-ndisc: drop RA packets from non-link-local addresses
See https://tools.ietf.org/html/rfc4861#section-4.2. Some routers (dnsmasq) will send packets
from global addresses, which would break the default route setup, so ignore those.

This is also what the kernel does.
2015-11-19 01:25:40 +01:00
Tom Gundersen 63348d13fa networkd: ndisc/dhcpv6 - handle starting running clients
The clients may be triggered to be started repeatedly without being stopped first,
simply swallow the error rather than failing the link.
2015-11-16 19:14:22 +01:00
Tom Gundersen 133dd71fdd sd-ndisc: add missing parens
Reported by Thomas Andersen.
2015-11-12 16:37:18 +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 9d96e6c3ef sd-ndisc: introduce separate callbacks
As the data passed is very different, we introduce four different callbacks:
 - Generic - router discovery timed out or state machine stopped
 - Router - router and link configuration received
 - Prefix onlink - configuration for an onlink prefix received
 - Prefix autonomous - configuration for to configure a SLAAC address for a prefix received
2015-11-11 15:42:38 +01:00
Tom Gundersen cb53894d3b sd-ndisc: notify user on STOP
Also, stop the state machine when we get into a broken state, rather than just notify the user.
2015-11-11 15:42:38 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +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 cbe91b3cba sd-ndisc: reduce callbacks
Only callback on error when the statemachine is in a truly broken state. This
is now only the case when we fail to rearm a timer.
2015-10-22 17:34:58 +02:00
Tom Gundersen 4e5ca364f4 sd-ndisc: drop sd_ndisc_get_prefixlen()
This is unused, and in the future we will pass prefixes and prefixlengths directly
to the callbacks when needed rather than having to search for them.
2015-10-22 17:19:54 +02:00
Tom Gundersen f46fc04fac sd-ndisc: drop sd_ndisc_prefix_match()
This is no longer used.
2015-10-22 17:19:54 +02:00