Commit graph

24 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 99f1d3fc50 sd-dhcp6: fix check if serverid is set
Ever since the initial implementation in 631bbe7129,
client_parse_message() was supposed to check that the message contains exactly
one serverid. The check that no more than one is given was implemented
correctly, but the check that at least one is given was not. Simplify the whole
thing by making dhcp6_lease_get_serverid() return an error if the id is not
set, and do not require the arguments to be present if the contents of the id
are not needed.
2018-02-15 10:04:02 +01:00
Patrik Flykt 652bf04254 dhcp6: Add function to iterate and fetch delegated prefixes
Add a function for fetching the next delegated prefix and another
one to reset the iteration to the first prefix.
2018-01-04 15:22:44 +02:00
Patrik Flykt dce6563fc6 dhcp6: Handle a received IA PD option
Parse the received IA PD option and verify its IAID.
2018-01-04 15:22:44 +02:00
Patrik Flykt e0026dcbd2 dhcp6: Name structs in DHCP6IA
Name structs containing IA NA with ID and T1 and T2 lifetimes and
IA TA containing only the ID so that the structs can be expressed
properly.
2018-01-04 15:22:43 +02: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
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
Zbigniew Jędrzejewski-Szmek 6b430fdb7c tree-wide: use mfree more 2016-10-16 23:35:39 -04: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 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
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 52efd56a63 tree-wide: we place the opening bracket on the same line as the function name
Let's do this everywhere the same way.
2015-08-27 17:48:24 +02:00
Lennart Poettering 3733eec3e2 dhcp: stop using refcnt.h
No need to invole atomic ops in single-threaded APIs, let's simplify
this.
2015-08-26 21:05:53 +02:00
Patrik Flykt 41e4615d4f sd-dhcp6: Support deprecated SNTP Configuration Option
Although the SNTP option specified in RFC 4075 has been deprecated, some
servers are still sending NTP information with this option. Use the SNTP
information provided only if the NTP option is not present.

Update the test case as SNTP information is also requested.
2015-08-21 11:23:22 +03:00
Patrik Flykt 6599680e2d sd-dhcp6: Add support for DHCPv6 NTP Server Option
Support NTP server and multicast addresses and NTP server domain names
as specified in RFC 5908.
2015-08-21 11:23:22 +03:00
Patrik Flykt 5da1b97f3c sd-dhcp6: Add support for DHCPv6 DNS Domain Search List option
Support DHCPv6 DNS search list option as specified in RFC 3646. This
option contains a list of DNS search domains encoded without compression
as specified in Section 8. of RFC 3315.
2015-08-21 11:23:22 +03:00
Patrik Flykt 7bd8e95d44 sd-dhcp6: Add support for DHCPv6 DNS Recursive Name Server option
Support DHCPv6 DNS server option as specified in RFC 3646. This option
contains a list of IPv6 DNS server addresses.
2015-08-21 11:23:21 +03:00
Patrik Flykt e7504d9547 sd-dhcp6-lease: Revise address iteration functions
Revise the address iteration functions so that one helper function
resets the iterator to the start of the address list while the
second one fetches addresses one by one.

The test case is also updated.
2015-01-27 09:35:24 +02:00
Tom Gundersen f0c4b1c3fd refcnt: refcnt is unsigned, fix comparisons
This does not make a difference, but the code was confusing.
2015-01-13 23:03:11 +01:00
Patrik Flykt fab15fec24 sd-dhcp6-lease: Return only -EINVAL when a NULL lease is supplied
Suppyling a NULL lease is not a condition that needs to be asserted,
returning -EINVAL is informative enough to the caller. This simplifies
calling code and doesn't falsely indicate that something erroneous was
attempted.
2014-12-10 18:31:21 +01:00
Patrik Flykt ee3a5027f7 sd-dhcp6-lease: Name the structure containing IAADDR data
With this change the DHCP6_OPTION_IAADDR_LEN define can be removed in
favor of using sizeof(). Using the name of the struct and sizeof()
makes it clearer how much and what data is being copied from the
DHCPv6 message.
2014-10-09 14:57:53 +03:00
Patrik Flykt ed6ee21953 sd-dhcp6-client: Implement Rapid Commit
Add a Rapid Commit option to Solicit messages and expect a Reply to
be received instead of an Advertise. When receiving a DHCPv6 message
from the server in state Solicit, continue testing whether the
message is a Reply. Ease up the message type checking, it's not fatal
if the message is of a wrong type.

Add helper functions to set/get the rapid commit of a lease. See
RFC 3315, sections 17., 17.1.2., 17.1.4. and 18.1.8.
2014-06-26 16:10:47 +03:00
Patrik Flykt 709d6710d0 sd-dhcp6-lease: Add helper function to compute remaining expiry time
Create a helper function to compute the remaining time in seconds from
time T2 to the IPv6 address with the longest lifetime. The computed
time is used as the Maximum Retransmission Duration in Rebinding state.
See RFC 3315, section 18.1.4. for details.
2014-06-26 16:10:21 +03:00
Patrik Flykt ea3b3a75ab sd-dhcp6-lease: Add functions for accessing lease and addresses
Add support functions for accessing the current client lease as well
as iterating over the addresses and get their preferred and valid
lifetimes.
2014-06-19 15:44:44 +03:00
Patrik Flykt 3fb2c57038 sd-dhcp6-lease: Add DHCPv6 lease handling
Create a structure describing a DHCPv6 lease. Add internal functions
for creating a new lease and accessing the server ID, preference and
IAID. Provide functions for clearing addresses and associated timers.

External users are initially given only the capabilities of
referencing and unreferencing the lease structure.
2014-06-19 15:44:44 +03:00