Commit graph

783 commits

Author SHA1 Message Date
Lennart Poettering 357e1b17b9 dhcp-server: add two missing OOM checks 2017-02-09 16:12:03 +01:00
27o 6f844e3a3f networkd: add multicast membership to lldp socket (#5282) 2017-02-09 10:36:13 +01:00
27o 28c78e07aa dhcp-server: always save the ACKed lease address (#5281) 2017-02-09 10:15:21 +01:00
Zbigniew Jędrzejewski-Szmek ec251fe7d5 tree-wide: adjust fall through comments so that gcc is happy
gcc 7 adds -Wimplicit-fallthrough=3 to -Wextra. There are a few ways
we could deal with that. After we take into account the need to stay compatible
with older versions of the compiler (and other compilers), I don't think adding
__attribute__((fallthrough)), even as a macro, is worth the trouble. It sticks
out too much, a comment is just as good. But gcc has some very specific
requiremnts how the comment should look. Adjust it the specific form that it
likes. I don't think the extra stuff we had in those comments was adding much
value.

(Note: the documentation seems to be wrong, and seems to describe a different
pattern from the one that is actually used. I guess either the docs or the code
will have to change before gcc 7 is finalized.)
2017-01-31 14:04:55 -05:00
Evgeny Vereshchagin 0b75a95ace sd-network: fix memleak in dhcp6_lease_set_domains (#5113)
The simplest way to reproduce:
```diff
diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c
index bd289fa..4e14d8f 100644
--- a/src/libsystemd-network/test-dhcp6-client.c
+++ b/src/libsystemd-network/test-dhcp6-client.c
@@ -286,6 +286,8 @@ static int test_advertise_option(sd_event *e) {
                         assert_se(optlen == 11);
                         assert_se(dhcp6_lease_set_domains(lease, optval,
                                                           optlen) >= 0);
+                        assert_se(dhcp6_lease_set_domains(lease, optval,
+                                                          optlen) >= 0);
                         break;

                 case SD_DHCP6_OPTION_SNTP_SERVERS:
```

Fixes:
```
==27369==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 10 byte(s) in 1 object(s) allocated from:
    #0 0x7f90e7d21160 in strdup (/lib64/libasan.so.3+0x5a160)
    #1 0x7f90e7467f69 in strv_extend src/basic/strv.c:552
    #2 0x5612fcc19379 in dhcp6_option_parse_domainname src/libsystemd-network/dhcp6-option.c:399
    #3 0x5612fcc1acdf in dhcp6_lease_set_domains src/libsystemd-network/sd-dhcp6-lease.c:225
    #4 0x5612fcc06b95 in test_advertise_option src/libsystemd-network/test-dhcp6-client.c:287
    #5 0x5612fcc0a987 in main src/libsystemd-network/test-dhcp6-client.c:761
    #6 0x7f90e6d46400 in __libc_start_main (/lib64/libc.so.6+0x20400)

SUMMARY: AddressSanitizer: 10 byte(s) leaked in 1 allocation(s).
```
2017-01-23 21:12:58 -05:00
Evgeny Vereshchagin 419eaa8f8d sd-network: fix memleak in dhcp6_option_parse_domainname (#5114)
The simplest way to reproduce:
```diff
diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c
index bd289fa..7b0a5ef 100644
--- a/src/libsystemd-network/test-dhcp6-client.c
+++ b/src/libsystemd-network/test-dhcp6-client.c
@@ -168,7 +168,7 @@ static uint8_t msg_advertise[198] = {
         0x00, 0x17, 0x00, 0x10, 0x20, 0x01, 0x0d, 0xb8,
         0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x0b,
-        0x03, 0x6c, 0x61, 0x62, 0x05, 0x69, 0x6e, 0x74,
+        0x01, 0x6c, 0x01, 0x62, 0x00, 0x0a, 0x6e, 0x74,
         0x72, 0x61, 0x00, 0x00, 0x1f, 0x00, 0x10, 0x20,
         0x01, 0x0d, 0xb8, 0xde, 0xad, 0xbe, 0xef, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
@@ -338,9 +338,7 @@ static int test_advertise_option(sd_event *e) {
         assert_se(!memcmp(addrs, &msg_advertise[124], r * 16));

         r = sd_dhcp6_lease_get_domains(lease, &domains);
-        assert_se(r == 1);
-        assert_se(!strcmp("lab.intra", domains[0]));
-        assert_se(domains[1] == NULL);
+        assert_se(r == -ENOENT);

         r = sd_dhcp6_lease_get_ntp_addrs(lease, &addrs);
         assert_se(r == 1);
```

Fixes:
```
=================================================================
==15043==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x7f13c8564160 in strdup (/lib64/libasan.so.3+0x5a160)
    #1 0x7f13c7caaf69 in strv_extend src/basic/strv.c:552
    #2 0x55f775787230 in dhcp6_option_parse_domainname src/libsystemd-network/dhcp6-option.c:399
    #3 0x55f775788b96 in dhcp6_lease_set_domains src/libsystemd-network/sd-dhcp6-lease.c:225
    #4 0x55f775774b95 in test_advertise_option src/libsystemd-network/test-dhcp6-client.c:287
    #5 0x55f77577883e in main src/libsystemd-network/test-dhcp6-client.c:759
    #6 0x7f13c7589400 in __libc_start_main (/lib64/libc.so.6+0x20400)

Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x7f13c8564160 in strdup (/lib64/libasan.so.3+0x5a160)
    #1 0x7f13c7caaf69 in strv_extend src/basic/strv.c:552
    #2 0x55f775787230 in dhcp6_option_parse_domainname src/libsystemd-network/dhcp6-option.c:399
    #3 0x55f775788b96 in dhcp6_lease_set_domains src/libsystemd-network/sd-dhcp6-lease.c:225
    #4 0x55f775781348 in client_parse_message src/libsystemd-network/sd-dhcp6-client.c:807
    #5 0x55f775781ba2 in client_receive_advertise src/libsystemd-network/sd-dhcp6-client.c:895
    #6 0x55f775782453 in client_receive_message src/libsystemd-network/sd-dhcp6-client.c:994
    #7 0x7f13c7e447f4 in source_dispatch src/libsystemd/sd-event/sd-event.c:2268
    #8 0x7f13c7e471b0 in sd_event_dispatch src/libsystemd/sd-event/sd-event.c:2627
    #9 0x7f13c7e47ab3 in sd_event_run src/libsystemd/sd-event/sd-event.c:2686
    #10 0x7f13c7e47c21 in sd_event_loop src/libsystemd/sd-event/sd-event.c:2706
    #11 0x55f77577863c in test_client_solicit src/libsystemd-network/test-dhcp6-client.c:737
    #12 0x55f77577884b in main src/libsystemd-network/test-dhcp6-client.c:760
    #13 0x7f13c7589400 in __libc_start_main (/lib64/libc.so.6+0x20400)

SUMMARY: AddressSanitizer: 8 byte(s) leaked in 2 allocation(s).
```
2017-01-23 21:11:59 -05:00
Jörg Thalheim 9f702d00d6 ndisc: ignore invalid SLAAC prefix lengths (#4923)
- linux does not accept prefixes for SLAAC unequal to 64 bits: http://lxr.free-electrons.com/source/net/ipv6/addrconf.c#L2741
- when networkd tries export such a route to the kernel it will get -EINVAL and
  set the whole device into a failed state.
- this patch will make networkd ignore such prefixes for SLAAC,
  but process other informations which may contain other prefixes.
- Note that rfc4862 does not forbid prefix length != 64 bit
2016-12-20 20:27:06 +01:00
David Michael 1aa68db1ae network: fix const qualifier (#4849)
Follow up for #4809.
2016-12-07 16:42:17 -05:00
David Michael 618b196e9d network: support negation in matching patterns (#4809) 2016-12-07 19:12:10 +01:00
27o 3e7b9f76f5 dhcp: bind udp sockets to interfaces (#4822) 2016-12-07 02:00:05 +01:00
Zbigniew Jędrzejewski-Szmek ef8b008455 sd-dhcp-client: use free_and_strdup
This changes the return value a bit: 1 will be returned if the value is
changed. But the return value was not documented, and the change should
be for the good anyway. Current callers don't care.
2016-11-21 23:01:02 +01:00
Lennart Poettering d9ec2e632d dhcp4: filter bogus DNS/NTP server addresses silently
if we receive a bogus lease with a DNS/NTP server within local scope let's
politely ignore.

Fixes: #4524
2016-11-21 22:58:26 +01:00
Lennart Poettering fdedbe2676 basic: add explicit ipv4-specific in_addr classification calls
This adds in4_addr_is_localhost() and in4_addr_is_link_local() that only take
an IPv4 "struct in_addr", to match in_addr_is_localhost() and
in_addr_is_link_local() that that a "union in_addr_union".

This matches the existing in4_addr_is_null() call that already exists.

For IPv6 glibc already exports a set of macros, hence we don't add similar
functions in6_addr_is_localhost(). We also drop in6_addr_is_null() as
IN6_IS_ADDR_UNSPECIFIED() already provides that.
2016-11-21 22:47:47 +01:00
Lennart Poettering 17f6ed4d59 sd-dhcp: permit unsetting the hostname again
Let's handle NULL hostnames (for unsetting it) before we validate the name.
2016-11-21 22:47:47 +01:00
Susant Sahani 9faed222fc networkd: support setting dhcp client listen port (#4631)
Allow setting custom port for the DHCP client to listen on in networkd.

[DHCP]
ListenPort=6677
2016-11-10 18:34:19 -05:00
Zbigniew Jędrzejewski-Szmek 6b430fdb7c tree-wide: use mfree more 2016-10-16 23:35:39 -04:00
Michael Biebl 595bfe7df2 Various fixes for typos found by lintian (#3705) 2016-07-12 12:52:11 +02:00
Lennart Poettering 2cb623954f Fix #3236 (#3633)
* networkd: condition_test() can return a negative error, handle that

If a condition check fails with an error we should not consider the check
successful. Fix that.

We should probably also improve logging in this case, but for now, let's just
unbreak this breakage.

Fixes: #3236

* condition: handle unrecognized architectures nicer

When we encounter a check for an architecture we don't know we should not
let the condition check fail with an error code, but instead simply return
false. After all the architecture might just be newer than the ones we know, in
which case it's certainly not our local one.

Fixes: #3236
2016-06-30 15:56:23 -07:00
Lennart Poettering 616aab6085 Merge pull request #3481 from poettering/relative-memcg
various changes, most importantly regarding memory metrics
2016-06-16 13:56:23 +02:00
Lennart Poettering 8e38570ebe tree-wide: htonl() is weird, let's use htobe32() instead (#3538)
Super-important change, yeah!
2016-06-15 01:26:01 +02: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 1f152e4b41 network: use inet_ntop() rather than SD_NDISC_ADDRESS_FORMAT_VAL() when serializing
Let's use the usual libc API for serializing IPv6 addresses, instead of the
NDISC-specific macro we should get rid of anyway.
2016-06-06 19:59:09 +02:00
Lennart Poettering a1fb61b0e8 lldp: minor coding style improvement 2016-06-06 19:59:08 +02:00
Lennart Poettering 3db2ec568c lldp: add sd_lldp_get_event() call
sd-ndisc has something like this, let's add this for sd-lldp, too.
2016-06-06 19:59:08 +02:00
Lennart Poettering f3315c5860 lldp: deal properly with recv() returning EAGAIN/EINTR
It might very well return EAGAIN in case of packet checksum problems and
suchlike, hence let's better handle this nicely, the same way as we do it in
the other sd-network libraries for incoming datagrams.
2016-06-06 19:59:08 +02:00
Lennart Poettering 35ad2cd7ce lldp: pass correct neighbor object to REMOVED callback 2016-06-06 19:59:08 +02:00
Lennart Poettering f137029bb8 lldp: rename TLV accessor pseudo-macros
Let's make sure the inline functions for retrieving TLV data actually carry TLV
in the name, so that we don#t assume they retrieve the whole, raw packet data.
2016-06-06 19:59:08 +02:00
Lennart Poettering a85b46c33f lldp: make sd_lldp_neighbor_tlv_rewind() return whether there's a first entry
This way it's nicer to use as it matches how sd_lldp_neighbor_tlv_next()
indicates an EOF too via its return value.
2016-06-06 19:59:08 +02:00
Lennart Poettering a2966471d8 lldp: use NULL instead 0, when we deal with a pointer 2016-06-06 19:59:08 +02:00
Lennart Poettering 09155f682a lldp: add _public_ to a two exported functions missing it 2016-06-06 19:59:08 +02:00
Lennart Poettering 8a19206d1b lldp: clarify that sd_lldp_neighbor_get_ttl() returns seconds
Let's simply encode this in the parameter name.
2016-06-06 19:59:08 +02:00
Lennart Poettering fc6a313b5b lldp: add proper ref counting to sd_lldp object and a separate call for setting the ifindex
Let's make sd-lldp a bit more like sd-ndisc ant the other APIs, and add proper
ref counting and a separate call for setting the ifindex.

This also adds a new lldp_reset() call we can use at various places to close
all fds. This is also similar to how sd-ndisc already does it.
2016-06-06 19:59:07 +02:00
Lennart Poettering 16fed825d6 sd-lldp: take triple timestamp when reading LLDP packets
It's a good idea to store away the recption time of LLDP packets in the
neighbor object, simply because the LLDP data only has a validity of a certain
amount of time.

Hence, let's record the timestamp when we receive the datagram and expose an
API for it. Also, automatically expire LLDP neighbors based on this new
timestamp.
2016-06-06 19:59:07 +02:00
Zbigniew Jędrzejewski-Szmek 20f8477be5 Merge pull request #3392 from poettering/assorted-stuff
Assorted stuff
2016-06-04 18:47:56 -04:00
Thomas Haller aa31ce1812 network: fix wrong include of source file "ether-addr-util.c" (#3402)
Fixes: 9ed8b06c9b
2016-05-31 13:00:54 +02:00
Lennart Poettering 76a9d0f171 dhcp-server: fix integer underflow
Let's better ignore an invalid message size parameter, than assume ridiculously
larger sizes.
2016-05-30 18:28:51 +02:00
Zbigniew Jędrzejewski-Szmek ccf1c70800 Merge pull request #3360 from glaubitz/master
Fix multiple unaligned accesses in test-dns-packet and sd-dhcp-server.
2016-05-28 15:02:05 -04:00
John Paul Adrian Glaubitz 9ae8424410 networkd/sd-dhcp-server: Fix unaligned access in parse_request(). 2016-05-27 22:40:16 +02:00
Lennart Poettering ae06d1be4e ipv4ll: shorten some checks by using IN_SET a bit
As suggested:

https://github.com/systemd/systemd/pull/3328#discussion-diff-64285764
2016-05-26 15:34:43 +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 b24ef0493a ipv4acd: rename "ll" parameter to "acd" everywhere
Appears to be a (confusing) left-over from copy/paste when this still was
ipv4ll code.
2016-05-26 15:34:43 +02:00
Lennart Poettering 703945c1dc sd-ipv4ll: add a bit of logging to IPv4LL too 2016-05-26 15:34:43 +02:00
Lennart Poettering 3aacc173e9 sd-ipv4acd: drop IPV4ACD_NETWORK definition
Appears to be a copy/paste mistake from sd-ipv4ll. Let's get rid of this.
2016-05-26 15:34:43 +02:00
Lennart Poettering 96a7979f3d ipv4acd: rework how we pick ipv4ll addresses
Let's make the seed actually work as stable seed, and use siphash24 to generate
the series of addresses, instead of the opaque libc random_r().

This not only makes the seed truly work as stable, portable seed, but also
makes the code quite a bit shorter, and removes a couple of memory allocations.
2016-05-26 15:34:43 +02:00
Lennart Poettering 38958cd66e ipv4ll: change "seed" parameter to be uint64_t
Let's make clear this always has the same size, since otherwise it's not useful
for reproducible runs, which this is really about however.
2016-05-26 15:34:43 +02:00
Lennart Poettering ff0c5ebd4a ipv4acd: make sure our event handler callbacks never check uninitialized "r" for errors 2016-05-26 15:34:42 +02:00
Lennart Poettering e3f4eedba1 ipv4acd: normalize time types to usec_t
We try to stick to usec_t for encoding time information, do that here too. In
particular, get rid of "int" second specifications, since signed timespans are
a weird thing.
2016-05-26 15:34:42 +02:00
Lennart Poettering d63458452d ipv4acd: in case the state engine is reused, reset n_conflict timer to 0 2016-05-26 15:34:42 +02:00
Lennart Poettering d914f7a563 ipv4acd: no need to memcpy() where assignment suffices 2016-05-26 15:34:42 +02:00
Lennart Poettering c9e458a419 ipv4acd: introduce new "started" state
This state is active immediately after the state engine was started, but before
the first timer hits.

This way multiple _start() invocations on the same object are always detected
correctly.
2016-05-26 15:34:42 +02:00
Lennart Poettering d246e77a43 ipv4acd: rename ipv4acd_stop() → ipv4acd_reset()
This is much less confusing, since there's also sd_ipv4acd_stop(), which was
idfferent from ipv4acd_stop().

After renaming it, let's also use the funciton when destroying ipv4acd objects,
as the code is pretty much the same for that.
2016-05-26 15:34:42 +02:00
Lennart Poettering 4dbf7b3a93 ipv4acd: add "_event_source" suffix to event source objects
Otherwise the field "receive_message" is a bit too confusing, as it suggests it
actually stores a message object of some kind.
2016-05-26 15:34:42 +02:00
Lennart Poettering 784cdc2d0b ipv4acd: make the iteration and conflict fields unsigned
They are counters after all, and can never go below zero, hence don't pretend
with the chose type that they could.

Also, prefix their name with "n_", to indicate that they are counters.
2016-05-26 15:34:42 +02:00
Lennart Poettering 73e94c0dcb ipv4l-{acd,ll}: make sure ipv4 addresses are unsigned
And some other minor fixes.
2016-05-26 15:34:42 +02:00
Lennart Poettering a48fc60a33 ipv4acd: library code should never log
Or actually, not at any level higher than debug.
2016-05-26 15:34:42 +02:00
Lennart Poettering c116f52635 sd-ipv4{acl,ll}: don't make use of RefCnt objects
These objects are only useful when multiple threads are involved, as they
operate with atomic operations. Given that our libraries are explicitly not
thread-safe don't make use of RefCnt here, and make things a bit simpler.
2016-05-26 15:34:42 +02:00
Lennart Poettering 45aa74c72e sd-network: don't needlessly abbreviate "callback" as "cb" in struct members
It's OK to abbreviate this in the local scope, but otherwise, let's not be
needlessly terse.
2016-05-26 15:34:42 +02:00
Lennart Poettering 671eaa7405 dhcp: fix operator precedence issue with macro 2016-05-26 15:34:42 +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 16f0b479ca sd-dhcp: shorten NUL initialization a bit 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
Susant Sahani 15fec93be3 networkd: networkd: ndisc set SO_BINDTODEVICE on socket (#3294)
From the issue #2004 we are receiving packet even if this
packet is not intended for this interface.

This can be reproduced.

lp3s0: Updating address: 2001:db8:1:0:7e7a:91ff:fe6d:ffe2/64 (valid for 1d)
wlp3s0: Updating address: fe80::7e7a:91ff:fe6d:ffe2/64 (valid forever)
NDisc CLIENT: Received RA from non-link-local address ::. Ignoring.
NDisc CLIENT: Received RA on wrong interface: 2 != 6. Ignoring.
NDisc CLIENT: Received RA on wrong interface: 2 != 3. Ignoring.
enp0s25: Updating address: 2001:db8:1:0:2ad2:44ff:fe6a:ae07/64 (valid for 1d)
enp0s25: Updating address: fe80::2ad2:44ff:fe6a:ae07/64 (valid forever)
NDisc CLIENT: Sent Router Solicitation
NDisc CLIENT: Sent Router Solicitation
NDisc CLIENT: Sent Router Solicitation
NDisc CLIENT: Received RA on wrong interface: 3 != 2. Ignoring.
NDisc CLIENT: Received RA on wrong interface: 3 != 6. Ignoring.
NDisc CLIENT: Received RA from non-link-local address ::. Ignoring.
NDisc CLIENT: Received RA on wrong interface: 2 != 6. Ignoring.
NDisc CLIENT: Received RA on wrong interface: 2 != 3. Ignoring.
enp0s25: Updating address: 2001:db8:1:0:2ad2:44ff:fe6a:ae07/64 (valid for 1d)
enp0s25: Updating address: fe80::2ad2:44ff:fe6a:ae07/64 (valid forever)

Add SO_BINDTODEVICE to socket
fixes #2004
2016-05-23 11:13:57 +02:00
Lennart Poettering e095f51dd1 ipv4acd/ipv4ll: stop using read() on SOCK_DGRAM sockets
This is a follow-up to cf447cb62d.

Let's generally follow the rule to not use read() on SOCK_DGRAM sockets, let's
always use recv() on that.

Also, don't abort IPV4ACD logic in case we read a short packet. Simply log and
ignore.
2016-05-22 14:26:36 +02:00
Lennart Poettering e78f9587ab sd-ipv4acd: do not define ether_addr_is_nul() redundantly
we already have ether_addr_is_null() in ether-addr-util.h, let's use it here,
too.
2016-05-22 14:26:06 +02:00
Lennart Poettering 2d3e723657 sd-ipv4acd: drop HASH_KEY definition, as it is unused 2016-05-22 14:25:02 +02:00
Tom Gundersen cf447cb62d libsystemd-network: use recv(..., 0) instead of read(...) (#3317)
According to recv(2) these should be the same, but that is not true.
Passing a buffer of length 0 to read is defined to be a noop according
to read(2), but passing a buffer of length 0 to recv will discard the
pending pacet.

We can easily hit this as we allocate our buffer size depending on
the size of the incoming packet (using FIONREAD). As pointed out in
issue #3299 simply sending an empty UDP packet to the DHCP client
port will trigger a busy loop in networkd as we are polling on the
socket but never discarding the empty packet.

This reverts ad5ae47a0d but fixes the
same issue.
2016-05-22 00:00:32 +03:00
Tom Gundersen 51e0b25077 Merge pull request #3235 from dkg/hwaddr-cleanup
minor improvements for dealing with MAC Addresses
2016-05-20 17:27:58 +02:00
sadag ad5ae47a0d sd-dhcp-client: fix busy loop reading zero sized DHCP UDP packets. (#3299) 2016-05-20 14:26:27 +03:00
Clemens Gruber 77ff6022fa networkd: Add EmitRouter= option for DHCP Server (#3251)
Add an option to disable appending DHCP option 3 (Router) to the DHCP
OFFER and ACK packets.
This commit adds the boolean option EmitRouter= for the [DHCPServer]
section in .network files.

Rationale: On embedded devices, it is very useful to have a DHCP server
running on an USB OTG ethernet gadget interface to avoid manual setup on
the client PCs, but it should only serve IP addresses, no route(r)s.
Otherwise, Windows clients experience network connectivity issues, due
to them using the address set in DHCP option 3 as default gateway.

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
2016-05-17 19:34:25 -04:00
Daniel Kahn Gillmor 9ed8b06c9b network: rely on ether_addr_from_string instead of sscanf 2016-05-17 16:55:20 -04:00
Zbigniew Jędrzejewski-Szmek bd9a722196 sd-dhcp6-client: add log_errno macro and improve debug messages a bit 2016-05-15 19:57:00 -04:00
Zbigniew Jędrzejewski-Szmek 483d099e16 tree-wide: drop spurious "&"s when passing functions around
Also adjust indentation in various places.
2016-05-15 19:56:59 -04:00
Lennart Poettering a9dd908d09 network: Make sure we log about parse errors for ifname lists
Fix-up for 93e2822684
2016-05-09 15:45:31 +02:00
Lennart Poettering d31645adef tree-wide: port more code to use ifname_valid() 2016-05-09 15:45:31 +02:00
Susant Sahani 93e2822684 networkd: cleanup FOREACH_WORD 2016-05-06 09:37:31 +05:30
Zbigniew Jędrzejewski-Szmek 7c285c7419 network: get rid of DUID_TYPE_RAW
It wasn't used for anything after the recent changes.
2016-05-03 12:26:43 -04:00
Zbigniew Jędrzejewski-Szmek d7df2fd317 dh-dhcp{,6}-client: change the semantics of DUID setting
Both versions of the code are changed to allow the caller to override
DUID using simple rules: duid type and value may be specified, in
which case the caller is responsible to providing the contents,
or just duid type may be specified as DUID_TYPE_EN, in which case we
we fill in the values. In the future more support for other types may
be added, e.g. DUID_TYPE_LLT.

There still remains and ugly discrepancy between dhcp4 and dhcp6 code:
dhcp6 has sd_dhcp6_client_set_duid and sd_dhcp6_client_set_iaid and
requires client->state to be DHCP6_STATE_STOPPED, while dhcp4 has
sd_dhcp_client_set_iaid_duid and will reconfigure the client if it
is not stopped. This commit doesn't touch that part.

This addresses #3127 § 2.
2016-05-03 12:12:04 -04:00
Zbigniew Jędrzejewski-Szmek 3b6a4e97ea dhcp-identifier: un-inline dhcp_validate_duid_len
After all it is used in more than one place and is not that short.
Also tweak the test a bit:
- do not check that duid_len > 0, because we want to allow unknown
  duid types, and there might be some which are fine with 0 length data,
  (also assert should not be called from library code),
- always check that duid_len <= MAX_DUID_LEN, because we could overwrite
  available buffer space otherwise.
2016-05-03 12:09:38 -04:00
Zbigniew Jędrzejewski-Szmek f7a92d1a7e sd-dhcp: change uint8_t *duid to const void* 2016-05-03 12:08:56 -04:00
Zbigniew Jędrzejewski-Szmek 4b558378a7 sd-dhcp{,6}-client: use standard indentation for functions args 2016-05-03 11:52:44 -04:00
Vinay Kulkarni b7f71444c0 Address code-review items for pull-request #2890
1. Replace strtol with unhexchar, verified with valid and invalid DUID strings.
2. Fix logging to use log_syntax instead of log_error.
3. On error reading DUID, ignore read and preserve previous state.
4. Fix man-pages to use markup, remove options not yet implemented.
5. Remove spurious header line in new files.
2016-04-04 21:06:11 -07:00
Thomas Haller 7908dd6730 dhcp-identifier: handle too long duid_len in dhcp_validate_duid_len()
Callers of dhcp_validate_duid_len() know that they must not pass
a zero duid_len. Thus asserting against that is appropriate.
On the other hand, they are not aware of the maximum allowed length
of a duid, as that is the reason why they call dhcp_validate_duid_len()
in the first place. So dhcp_validate_duid_len() should just signal a
regular error.

Thereby, change assert_return() to an assert() as this is an internal
function.
2016-04-01 15:03:27 +02:00
Zbigniew Jędrzejewski-Szmek 1db30aeab1 Merge pull request #2915 from vinaykul/master 2016-03-31 00:52:23 -04:00
Vinay Kulkarni 413708d106 DHCP DUID, IAID configuration options 2016-03-30 16:33:55 -07:00
Beniamino Galvani 6afa676780 lldp: move public macros to sd-lldp.h and namespace them
lldp.h contains definitions of LLDP types, subtypes and capabilities which
should be exposed in public headers. Get rid of the file and move those
definitions to sd-lldp.h with the SD_ prefix.
2016-03-24 16:41:48 +01:00
Zbigniew Jędrzejewski-Szmek afec45395f Revert "DHCP DUID and IAID configurability" 2016-03-21 18:24:24 -04:00
Thomas Haller 0513ea4e3f lldp: fix starting ttl timer for lldp neighbor
lldp_start_timer() was only called during sd_lldp_get_neighbors().
Ensure that the timer is (re-)started when a new neighbor appears.
Otherwise, the timer is not started when relying on the events alone.

Fixes: 34437b4f9c
2016-03-14 17:02:19 +01:00
Vinay Kulkarni c83321e6d4 DHCP DUID and IAID configurability 2016-03-09 21:58:44 -08:00
Zbigniew Jędrzejewski-Szmek b3ad5fa944 lldp: fix memleak
in_addr_to_string returned 0, which was treated as error by the calling
code, which expects 1 on success.

CID #1351757, #1351758.
2016-03-04 21:45:45 -05:00
Thomas Haller 3587161ade core: avoid compiler warning when compiling with -fexceptions
Initialize auto variables with cleanup attribute, otherwise we
get a compiler warning with -fexceptions.

    ./configure CFLAGS='-Wmaybe-uninitialized -fexceptions -O2'
2016-02-27 13:40:50 +01:00
Patrik Flykt 8eb7b6a595 sd-dhcp-server: Send replies to BOOTP relay server port
RFC 2131 Section 4.1 says that

 "If the ’giaddr’ field in a DHCP message from a client is non-zero,
  the server sends any return messages to the ’DHCP server’ port on the
  BOOTP relay agent whose address appears in ’giaddr’."

Fix this by adding a destination port when sending unicast UDP packets
and provide the server port when a BOOTP relay agent is being used.
2016-02-25 15:46:55 +02:00
Vito Caputo 9ed794a32d tree-wide: minor formatting inconsistency cleanups 2016-02-23 14:20:34 -08:00
Vito Caputo 313cefa1d9 tree-wide: make ++/-- usage consistent WRT spacing
Throughout the tree there's spurious use of spaces separating ++ and --
operators from their respective operands.  Make ++ and -- operator
consistent with the majority of existing uses; discard the spaces.
2016-02-22 20:32:04 -08:00
Lennart Poettering 90dffb2241 sd-lldp: beef up callback logic
Instead of just notifying about the fact that something changed in the
database, actually inform the callback what precisely changed. This is useful,
so that the LLDP tx logic can be put into "fast" mode as soon as a previously
unknown peer appears, as suggested by the LLDP spec.
2016-02-21 20:58:59 +01:00
Lennart Poettering b553a6b13c sd-lldp: filter out LLDP messages coming from our own MAC address
Let's not get confused should we be connected to some bridge that mirrors back
our packets.
2016-02-21 20:40:58 +01:00
Lennart Poettering 34437b4f9c sd-lldp: rework sd-lldp API
This reworks the sd-lldp substantially, simplifying things on one hand, and
extending the logic a bit on the other.

Specifically:

- Besides the sd_lldp object only one other object is maintained now,
  sd_lldp_neighbor. It's used both as storage for literal LLDP packets, and for
  maintainging info about peers in the database. Separation between packet, TLV
  and chassis data is not maintained anymore. This should be a major
  simplification.

- The sd-lldp API has been extended so that a couple of per-neighbor fields may
  be queried directly, without iterating through the object. Other fields that
  may appear multiple times, OTOH have to be iterated through.

- The maximum number of entries in the neighbor database is now configurable
  during runtime.

- The generation of callbacks from sd_lldp objects is more restricted:
  callbacks are only invoked when actual data changed.

- The TTL information is now hooked with a timer event, so that removals from
  the neighbor database due to TTLs now result in a callback event.

- Querying LLDP neighbor database will now return a strictly ordered array, to
  guarantee stability.

- A "capabilities" mask may now be configured, that selects what type of LLDP
  neighbor data is collected. This may be used to restrict collection of LLDP
  info about routers instead of all neighbors. This is now exposed via
  networkd's LLDP= setting.

- sd-lldp's API to serialize the collected data to text files has been removed.
  Instead, there's now an API to extract the raw binary data from LLDP neighbor
  objects, as well as one to convert this raw binary data back to an LLDP
  neighbor object. networkd will save this raw binary data to /run now, and the
  client side can simply parse the information.

- support for parsing the more exotic TLVs has been removed, since we are not
  using that. Instead there are now APIs to extract the raw data from TLVs.
  Given how easy it is to parse the TLVs clients should do so now directly
  instead of relying on our APIs for that.

- A lot of the APIs that parse out LLDP strings have been simplified so that
  they actually return strings, instead of char arrays with a length. To deal
  with possibly dangerous characters the strings are escaped if needed.

- APIs to extract and format the chassis and port IDs as strings has been
  added.

- lldp.h has been simplified a lot. The enums are anonymous now, since they
  were never used as enums, but simply as constants. Most definitions we don't
  actually use ourselves have eben removed.
2016-02-21 20:40:56 +01:00
Lennart Poettering 7cde237777 sd-lldp: fix how we create the LLDP listening socket
Specifiy the ethernet family, and make sure we se the O_CLOEXEC and O_NONBLOCK
bits how we should for all fds.
2016-02-20 22:42:29 +01:00
Lennart Poettering 0ef6f45425 tree-wide: place #pragma once at the same place everywhere
Usually, we place the #pragma once before the copyright blurb in header files,
but in a few cases we didn't. Move those around, so that we do the same thing
everywhere.
2016-02-20 22:42:29 +01:00
Lennart Poettering 358977458b sd-lldp: simplify lldp_network_bind_raw_socket() a bit
Let's constify the filter program, drop a few includes and structure
definitions.
2016-02-20 22:42:29 +01:00
Lennart Poettering 43a6a52efe sd-lldp: move ETHERTYPE_LLDP to missing.h
After all, most ETHERTYPE variables are defined in the system headers, hence
define these where we defined all other fill-ins for system headers.
2016-02-20 22:42:29 +01:00
Lennart Poettering bd8650e9b8 test-lldp: fix error checking expressions 2016-02-20 22:42:29 +01: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 032b27f534 sd-lldp: drop "port" object
Let's just keep the few parts we actually need of it in the main sd_lldp
object, so that we can simplify things quite a bit.

While we are at it, remove ifname and mac fields which we make no use of
whatsoever.
2016-02-20 22:42:29 +01:00
Lennart Poettering 2139d247bd sd-lldp: drop keeping of statistics
We don't expose them, and they are only of questionnable use.
2016-02-20 22:42:29 +01:00
Lennart Poettering ccf8635435 libsystemd-network: don't abbreviate "callback" as "cb" needlessly
This isn't an excercise in creating APIs that are hard to understand, hence
let's call a callback a callback.
2016-02-20 22:42:29 +01:00
Lennart Poettering c7d264ff98 sd-lldp: drop state field
There's really no point in maintaining a state, the state machine is trivial,
and we actually never look at the state anyway, we just keep updating it.
2016-02-20 22:42:29 +01:00
Nathan McSween e306723ec4 Remove/add (un)needed includes 2016-02-18 23:34:30 +00:00
Lennart Poettering 4edc2c9b6b networkd: FIONREAD is not reliable on some sockets
Fixes: #2457
2016-02-16 13:06:55 +01:00
Beniamino Galvani 8ecdcb5525 dhcp: assert the success of sd_event_now()
The function must never fail.
2016-02-15 16:20:55 +01:00
Lennart Poettering 91ba5ac7d0 Merge pull request #2589 from keszybz/resolve-tool-2
Better support of OPENPGPKEY, CAA, TLSA packets and tests
2016-02-13 11:15:41 +01:00
Zbigniew Jędrzejewski-Szmek 75f32f047c Add memcpy_safe
ISO/IEC 9899:1999 §7.21.1/2 says:
Where an argument declared as size_t n specifies the length of the array
for a function, n can have the value zero on a call to that
function. Unless explicitly stated otherwise in the description of a
particular function in this subclause, pointer arguments on such a call
shall still have valid values, as described in 7.1.4.

In base64_append_width memcpy was called as memcpy(x, NULL, 0).  GCC 4.9
started making use of this and assumes This worked fine under -O0, but
does something strange under -O3.

This patch fixes a bug in base64_append_width(), fixes a possible bug in
journal_file_append_entry_internal(), and makes use of the new function
to simplify the code in other places.
2016-02-11 13:07:02 -05: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
Beniamino Galvani 1d1a3e0afb dhcp: delay restarts after NAKs
The server might answer to a DHCPREQUEST with a NAK and currently the
client restarts the configuration process immediately.  It was
observed that this can easily generate loops in which the network is
flooded with DISCOVER,OFFER,REQUEST,NAK sequences.

RFC 2131 only states that "if the client receives a DHCPNAK message,
the client restarts the configuration process" without further
details.

Add a delay with exponential backoff between retries after NAKs to
limit the number of requests and cap the delay to 30 minutes.
2016-02-02 15:23:34 +01:00
Lennart Poettering 978c64777a dhcp: make host/domain name validity checks stricter
Also don't permit host/domain names that reference the root domain, and unify the codepaths for this.
2016-01-26 14:42:04 +01:00
Daniel Mack 9ecbcdffdf Merge pull request #2391 from keszybz/coverity
Coverity inspired fixes
2016-01-21 11:50:08 +01:00
Zbigniew Jędrzejewski-Szmek 63a54aa15e libsystemd-network: avoid double free on error
This could happen if the remote sent us a badly formatted
option.

CID #1317206.
2016-01-20 18:55:55 -05:00
Zbigniew Jędrzejewski-Szmek b14fff6e44 libsystemd-network: use assert_se
It cannot fail.

CID #1320623.
2016-01-20 18:55:55 -05:00
Beniamino Galvani 2c1ab8ca9b dhcp: make DHCP6_OPTION_* enum public
libsystemd-network provides the public function
sd_dhcp6_client_set_request_option() to enable the request of a given
DHCP option. However the enum defining such options is defined in the
internal header dhcp6-protocol.h. Move the enum definition to the
public header sd-dhcp6-client.h and properly namespace values.
2016-01-20 17:25:16 +01:00
Beniamino Galvani 22805d9207 dhcp: make DHCP_OPTION_* enum public
libsystemd-network provides the public function
sd_dhcp_client_set_request_option() to enable the request of a given
DHCP option. However the enum defining such options is defined in the
internal header dhcp-protocol.h. Move the enum definition to the
public header sd-dhcp-client.h and properly namespace values.
2016-01-20 17:25:16 +01:00
Beniamino Galvani f8693fc797 dhcp: export routes as opaque objects
At the moment sd_dhcp_lease_get_routes() returns an array of structs
which are not defined in public headers. Instead, change the function
to return an array of pointers to opaque sd_dhcp_route objects.
2016-01-20 17:25:16 +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
Daniel Mack d054f0a4d4 tree-wide: use xsprintf() where applicable
Also add a coccinelle receipt to help with such transitions.
2016-01-12 15:36:32 +01:00
Zbigniew Jędrzejewski-Szmek d790d8c1b2 Merge pull request #2223 from ssahani/lldp
Closes #2223.
2015-12-25 00:40:07 -05:00
Susant Sahani 859c37b152 V3 LLDP: Add packet validation (system name and description)
LLDP type system name and system description should
be with in 255 characters and unique.

Let's add the validation to discard corrupt packets.
2015-12-25 10:48:23 +05:30
Susant Sahani e5c42b7ff1 lldp: improve logging 2015-12-25 10:42:43 +05:30
Lennart Poettering 3cd03457bd util-lib: update dns_name_to_wire_format() to optionally generate DNSSEC canonical names
We'll need this later when putting together RR serializations to
checksum.
2015-12-02 22:50:11 +01: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
Martin Pitt 827661914a Merge pull request #2029 from teg/network-fixes
Network fixes
2015-11-27 10:20:18 +01:00
Lennart Poettering 422baca0f2 dns-domain: rework dns_label_escape() to not imply memory allocation
The new dns_label_escape() call now operates on a buffer passed in,
similar to dns_label_unescape(). This should make decoding a bit faster,
and nicer.
2015-11-25 22:00:07 +01:00
Lennart Poettering dc477e7385 dns-domain: simplify dns_name_is_root() and dns_name_is_single_label()
Let's change the return value to bool. If we encounter an error while
parsing, return "false" instead of the actual parsing error, after all
the specified hostname does not qualify for what the function is
supposed to test.

Dealing with the additional error codes was always cumbersome, and
easily misused, like for example in the DHCP code.

Let's also rename the functions from dns_name_root() to
dns_name_is_root(), to indicate that this function checks something and
returns a bool. Similar for dns_name_is_signal_label().
2015-11-25 22:00:07 +01:00
Tom Gundersen f693e9b38f sd-dhcp: parse error message in DECLINE or NAK
If a client sends a DECLINE or a server sends a NAK, they can include
a string with a message to explain the error. Parse this and print it
at debug level.
2015-11-25 18:30:31 +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
Lennart Poettering bb54817f3b Merge pull request #1947 from phomes/sort-includes2
tree-wide: sort includes in *.h
2015-11-19 23:32:30 +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 dc9715d419 Merge pull request #1931 from bengal/dhcp-fqdn-v2
libsystemd-network: add support for "Client FQDN" DHCP option (v2)
2015-11-19 02:27:10 +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
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
Martin Pitt 92939fc4c0 Merge pull request #1920 from teg/networkd-fixes
networkd fixes
2015-11-17 17:01:32 +01:00
Beniamino Galvani 23873e25aa libsystemd-network: add support for "Client FQDN" DHCP option
This adds support for the Client Fully Qualified Domain Name (FQDN)
option [RFC 4702] to libsystemd-network. The option can be used to
exchange information about a DHCPv4 client's fully qualified domain
name and about responsibility for updating the DNS RR related to the
client's address assignment.

Other popular DHCP clients (dhclient, dhcpcd) support this option and
it would be useful to have it in networkd too.
2015-11-17 15:06:01 +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 6506063f8f sd-dhcp6-client: allow multiple clients on host
We need to enable SO_REUSEADDR in order for several sockets to be allowed
to bind to the same port (even on different links).
2015-11-17 13:26:51 +01:00
Daniel Mack a57246551a Merge pull request #1926 from phomes/include-order-libudev
tree-wide: group include of libudev.h with sd-*
2015-11-17 09:36:25 +01:00
Thomas Hindoe Paaboel Andersen b4bbcaa9c4 tree-wide: group include of libudev.h with sd-* 2015-11-17 07:06:08 +01:00
Lennart Poettering 0c28d28834 sd-ipv4ll: fix error path if sd-ipv4acd allocation fails
Let's make sure the destructor cannot hit the n_ref == 0 case.
2015-11-17 00:52:10 +01:00
Lennart Poettering 357bc17975 Merge pull request #1923 from zonque/siphash
siphash24: let siphash24_finalize() and siphash24() return the result…
2015-11-17 00:32:06 +01:00
Daniel Mack 933f9caeeb siphash24: let siphash24_finalize() and siphash24() return the result directly
Rather than passing a pointer to return the result, return it directly
from the function calls.

Also, return the result in native endianess, and let the callers care
about the conversion. For hash tables and bloom filters, we don't care,
but in order to keep MAC addresses and DHCP client IDs stable, we
explicitly convert to LE.
2015-11-16 23:17:52 +01:00
Thomas Hindoe Paaboel Andersen cf0fbc49e6 tree-wide: sort includes
Sort the includes accoding to the new coding style.
2015-11-16 22:09:36 +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
Martin Pitt dbe81cbd2a siphash24: change result argument to uint64_t
Change the "out" parameter from uint8_t[8] to uint64_t. On architectures which
enforce pointer alignment this fixes crashes when we previously cast an
unaligned array to uint64_t*, and on others this should at least improve
performance as the compiler now aligns these properly.

This also simplifies the code in most cases by getting rid of typecasts. The
only place which we can't change is struct duid's en.id, as that is _packed_
and public API, so we can't enforce alignment of the "id" field and have to
use memcpy instead.
2015-11-16 15:20:29 +01:00
Tom Gundersen 3098562c92 networkd: dhcp6 - don't log about losing a lease we never had 2015-11-13 14:51:06 +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
Tom Gundersen f667c150a9 sd-dhcp6-client: add is_running() method 2015-11-11 15:42:38 +01:00
Tom Gundersen 76fba3ca60 Merge pull request #1735 from thom311/master
lldp: avoid compiler warnings in lldp_tfl_package_read* functions
2015-11-10 14:41:35 +01:00
Daniel Mack b0bc8dbd73 Merge pull request #1820 from michich/errno-v2
[v2] treewide: treatment of errno and other cleanups
2015-11-09 21:56:49 +01:00
Jan Engelhardt a8eaaee72a doc: correct orthography, word forms and missing/extraneous words 2015-11-06 13:45:21 +01:00
Michal Schmidt e26ea7fc2d libsystemd-network: inet_pton does not set errno on parsing error
it would set errno only for an invalid address family.

Also fix a copy&paste error in one error string.
2015-11-05 13:44:10 +01:00
Lennart Poettering b11d6a7bed util-lib: move character class definitions to string-util.h 2015-11-03 17:45:11 +01:00
Tom Gundersen 0f8980e48b sd-pppoe: drop
It is really unclear if we want to / have the resources to support this fully, so drop it
for now. It can easily be brought back if a killer usecase emerges.

Note that this code was never hooked up, so this does not remove any features.
2015-11-03 16:14:12 +01:00
Thomas Haller 9ac8e91324 lldp: avoid compiler warnings in lldp_tfl_package_read* functions
gcc 5.1.1 wrongly warns about uninitialized variable @r2 when compiling
with "-Og". Refactor the code to avoid the warnings.

Fixes: 564cabd46c
2015-10-31 22:30:14 +01:00
Tom Gundersen 93f660da98 sd-dhcp6-client: fix assert in options parsing 2015-10-30 12:32:49 +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 8b43440b7e util-lib: move string table stuff into its own string-table.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 0d39fa9c69 util-lib: move more file I/O related calls into fileio.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering e4e73a6325 util-lib: split out hex/dec/oct encoding/decoding into its own file 2015-10-27 13:25:55 +01:00
Lennart Poettering 6bedfcbb29 util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 04c0136989 sd-*.h: clean up exported (or to-be-exported) header files
Exported header files should not include internal headers. Fix that.

Exported header files should not use the bool type. So far we opted to
stick to C89 for exported headers, and hence use "int" for bools in
them. Continue to do so.

Exported header files should have #include lines for everything they use
including inttypes.h and sys/types.h, so that they may be included in
any order.

Exported header files should have C++ guards, hence add them.

Exported header files should not use gcc extensions like #pragma once,
get rid of it.
2015-10-24 23:42:56 +02: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
Tom Gundersen f6e0ce6660 sd-ndisc: don't trigger timeout on prefix expiry
The caller of the library is no longer notified, so triggering a timer
just to clean up is not necessary. Instead check for and clean up
invalid prefixes lazily.
2015-10-22 17:19:54 +02:00
Tom Gundersen 272f5cd9b7 sd-ndisc: remove a prefix from the ndisc object when freeing it
This follows the coding style, and allows some simplification to the rest of the code.
2015-10-22 17:19:54 +02:00
Tom Gundersen 77b05fa9a7 sd-ndisc: don't inform the caller of expired prefixes
The caller should push any lifetime information into the kernel and let the kernel handle
prefix expiration.
2015-10-22 17:19:54 +02:00
Tom Gundersen c93578f54b sd-ndisc: clean up state enum
There is no need to assign valuse to the states. Also add _INVALID and _MAX,
even though these are not used, it keeps it consistent.
2015-10-22 17:19:54 +02:00
Tom Gundersen 46ec668714 sd-ndisc: rename icmp6 to ndisc throughout the code 2015-10-22 17:19:54 +02:00
Tom Gundersen 940367a0ab libsystemd-network: split icm6-util.[ch] out of dhcp6 code 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 129dc1b489 sd-ipv4ll: allow initial address to be set explicitly
This is useful in case the daemon is restarted and the state of the IPv4LL client should
be serialized/deserialized.
2015-10-11 15:04:16 +02:00
Tom Gundersen ed19c567e5 libsystemd-network: limit accuracy of timestamps in logging
We don't care about timestamps down to the last usec, round to the closest sec
as that will be plenty for debugging purposes.
2015-10-11 15:04:15 +02:00