Commit Graph

69 Commits

Author SHA1 Message Date
Yu Watanabe 0afa4d569d sd-ndisc: fix indentation 2020-12-24 17:15:44 +09:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Yu Watanabe c8bae36372 libsystemd-network: do not request each daemon exist in sd_xxx_stop() 2020-10-15 07:24:17 +09:00
Yu Watanabe 9973e6c43a ndisc: make first solicit delayed randomly
Closes #13460.
2019-09-16 05:37:04 +09:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Topi Miettinen 7ae3561a5a Delete duplicate lines
Found by inspecting results of running this small program:

int main(int argc, const char **argv) {
	for (int i = 1; i < argc; i++) {
		FILE *f;
		char line[1024], prev[1024], *r;
		int lineno;

		prev[0] = '\0';
		lineno = 1;
		f = fopen(argv[i], "r");
		if (!f)
			exit(1);
		do {
			r = fgets(line, sizeof(line), f);
			if (!r)
				break;
			if (strcmp(line, prev) == 0)
				printf("%s:%d: error: dup %s", argv[i], lineno, line);
			lineno++;
			strcpy(prev, line);
		} while (!feof(f));
		fclose(f);
	}
}
2019-01-12 16:02:26 +01:00
Yu Watanabe ff4b032106 sd-ndisc: do not unref() event sources when update or disable them 2018-11-16 22:57:42 +09:00
Yu Watanabe 144faa8ea5 sd-ndisc: use structured initializer at one more place 2018-11-16 22:57:42 +09:00
Yu Watanabe a2dcda328a ndisc: improve debug log message 2018-11-06 20:15:09 +09:00
Lennart Poettering 165ad41b7f sd-ndisc: change return value of ndisc_reset() to void
We never generate anything other than 0 anyway, and we never check it,
hence let's just simplify things.
2018-10-13 12:37:13 +02:00
Lennart Poettering 76f713dfa4 sd-ndisc: voidify sd_ndisc_stop() call
CID 1395839
2018-10-13 12:37:13 +02:00
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