Commit Graph

827 Commits

Author SHA1 Message Date
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
Thomas Haller b62f900866 dhcp6: don't include internal header "sparse-endian.h" in "sd-dhcp6-client.h"
Arguably, libsystemd-network is (still) entirely internal API.
However there is the aim of maybe exposing it as public API.
For that reason, it cannot include internal headers from
"src/basic/".

Note how files "src/systemd/sd-*.h" don't include any systemd
headers which don't themself have an "sd-" prefix.

Fixes: d89a400ed6
2018-10-04 21:29:35 +02:00
Yu Watanabe 84452783b8 dhcp6: check option length before reading values
Fixes oss-fuzz#10746
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10746.
2018-10-03 08:49:55 +09:00
Lennart Poettering 8eb41f4c08 sd-radv: EAGAIN is not really unexpected, distinguishit from other errors when logging 2018-10-02 16:26:50 +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
Lennart Poettering fdc2afc102 sd-radv: remove log_radv_warning_errno()
According to our CODING_STYLE our library code should generally not log
beyond LOG_DEBUG. Let's hence get rid of log_radv_warning_errno() and
just use log_radv_errno() instead.
2018-10-02 16:22:54 +02:00
Evgeny Vereshchagin 14f37112c8 icmp6-util: stop ignoring EAGAIN and EINTR in icmp6_receive
The code handling the errors was originally part of ndisc_recv, which,
being an event handler, would be simply turned off if it returned a negative
error code. It's no longer necessary. Plus, it helps avoid passing
an uninitialized value to radv_send.

Closes https://github.com/systemd/systemd/issues/10223.
2018-10-02 12:58:07 +02:00
Thomas Haller f21f31b24b trivial: fix spelling in code comments
Based-on-patch-by: Rafael Fontenelle <rafaelff@gnome.org>
2018-09-30 21:32:33 +02:00
Yu Watanabe 213e759ad5 dhcp6: fix memleak about sd_event 2018-09-30 14:17:33 +02:00
Evgeny Vereshchagin b387d3c132 dhcp6: fix an off-by-one error in dhcp6_option_parse_domainname
==14==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200055fa9c at pc 0x0000005458f1 bp 0x7ffc78940d90 sp 0x7ffc78940d88
READ of size 1 at 0x60200055fa9c thread T0
    #0 0x5458f0 in dhcp6_option_parse_domainname /work/build/../../src/systemd/src/libsystemd-network/dhcp6-option.c:555:29
    #1 0x54706e in dhcp6_lease_set_domains /work/build/../../src/systemd/src/libsystemd-network/sd-dhcp6-lease.c:242:13
    #2 0x53fce0 in client_parse_message /work/build/../../src/systemd/src/libsystemd-network/sd-dhcp6-client.c:984:29
    #3 0x53f3bc in client_receive_advertise /work/build/../../src/systemd/src/libsystemd-network/sd-dhcp6-client.c:1083:13
    #4 0x53d57f in client_receive_message /work/build/../../src/systemd/src/libsystemd-network/sd-dhcp6-client.c:1182:21
    #5 0x7f0f7159deee in source_dispatch /work/build/../../src/systemd/src/libsystemd/sd-event/sd-event.c:3042:21
    #6 0x7f0f7159d431 in sd_event_dispatch /work/build/../../src/systemd/src/libsystemd/sd-event/sd-event.c:3455:21
    #7 0x7f0f7159ea8d in sd_event_run /work/build/../../src/systemd/src/libsystemd/sd-event/sd-event.c:3512:21
    #8 0x531f2b in fuzz_client /work/build/../../src/systemd/src/fuzz/fuzz-dhcp6-client.c:44:9
    #9 0x531bc1 in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-dhcp6-client.c:53:9
    #10 0x57bec8 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/libfuzzer/FuzzerLoop.cpp:570:15
    #11 0x579d67 in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*) /src/libfuzzer/FuzzerLoop.cpp:479:3
    #12 0x57dc92 in fuzzer::Fuzzer::MutateAndTestOne() /src/libfuzzer/FuzzerLoop.cpp:707:19
    #13 0x580ca6 in fuzzer::Fuzzer::Loop(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, fuzzer::fuzzer_allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) /src/libfuzzer/FuzzerLoop.cpp:838:5
    #14 0x55e968 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/libfuzzer/FuzzerDriver.cpp:764:6
    #15 0x551a1c in main /src/libfuzzer/FuzzerMain.cpp:20:10
    #16 0x7f0f701a082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #17 0x41e928 in _start (/out/fuzz-dhcp6-client+0x41e928)
2018-09-29 03:07:29 +00:00
Evgeny Vereshchagin 45a7becfea tests: make fuzz-dhcp6-client work in containers provided by the OSS-Fuzz project
The containers come with an empty machine-id, which causes the fuzzer
to fail as soon as it starts.

See https://github.com/systemd/systemd/pull/9014#discussion_r189594104
2018-09-29 02:57:04 +00:00
Evgeny Vereshchagin d89a400ed6 fuzz: add a fuzzer for dhcp6_client 2018-09-29 02:27:07 +00:00
Zbigniew Jędrzejewski-Szmek 83043e8dc8
Merge pull request #10190 from evverx/fuzz-ndisc-rs
Add a fuzzer for sd-ndisc and a reproducer for an infinite loop in ndisc_handle_datagram
2018-09-28 15:54:04 +02:00
Yu Watanabe 431a4bc8c0 dhcp6: fix memleak
Let's drop client_set_lease() because just writing what it does in both
places is simpler.

Fixes #10157.
2018-09-27 18:14:19 +02:00
Yu Watanabe cb1bdeaf56 dhcp6: fix buffer size checking 2018-09-27 23:48:51 +09:00
Yu Watanabe 23976cb928 dhcp6: use offsetof instead of sizeof 2018-09-27 23:41:23 +09:00
Yu Watanabe e2975f8548 sd-dhcp-lease: fix memleaks 2018-09-27 18:04:59 +09:00
Yu Watanabe 09348d4081 sd-dhecp-lease: use free_and_replace() at one more 2018-09-27 18:04:08 +09:00
Yu Watanabe f3241c61f1 ndisc: fix two infinite loops 2018-09-26 18:54:21 +00:00
Zbigniew Jędrzejewski-Szmek 1346489f8c DHCPv6: use unsigned for flags 2018-09-25 09:29:36 +02:00
Patrik Flykt 7c881490c1 sd-dhcp6-client: Reference and unreference a stored lease
In order to be able to properly free a DHCPv6 lease, unreference the
previous lease and reference the new one.
2018-09-19 13:45:18 -06:00
Patrik Flykt 9a7225de67 dhcp6-client: Store lease timeouts T1 and T1 in client struct
Since we now have the possibility to request prefixes to be delegated
without corresponding IPv6 addresses, it does not make sense to store
lease T1 and T2 timeouts in the otherwise unused IA_NA structure.
Therefore lease timeouts T1 and T2 are moved to the DHCPv6 client
structure, as there will be only one set of stateful timeouts required
by RFC 7550, Section 4.3.
2018-09-19 13:45:18 -06:00
Patrik Flykt 134ebaa45e dhcp6-client: Select T1 and T2 timeouts from IA_NA and IA_PD
Select T1 and T2 timeouts based on whether addresses or prefixes were
requested and what the server offered. The address and prefix timeouts
values have been computed earlier when the relevant DHCPv6 options were
parsed.
2018-09-19 13:45:18 -06:00
Patrik Flykt 49228c7520 dhcp6-lease: Add function to fetch the IAID for the prefix
Add function to fetch the IAID for the delegated IA_PD prefix. In
order to keep things simple in the implemntation, the same IAID
is used with IA_NA addresses and IA_PD prefixes. But the DHCPv6
server can choose to return only IA_PD prefixes, and the client
can nowadays omit requesting of IA_NA addresses. Since the function
fetching said IAID from the lease looks only for IA_NA ones, it
will return an empty IAID, which of course does not match the one
set for prefixes.

Fix this by adding a function returning the IAID for the prefix.
2018-09-19 13:45:18 -06:00
Patrik Flykt 7776f2aeff dhcp6-client: Add tests for address, information and prefix requests
Add simple test cases to ensure the request for addresses, prefixes
and information request are handled as expected.
2018-09-19 13:45:17 -06:00
Patrik Flykt f311a62bef dhcp6-client: Function for enabling/disabling IA_NA request
Add function to enable/disable IA_NA address requests. Internally
handle the request as a bit mask and add IA_PD prefix delegation
to the same bit mask instead of having a separate boolean. Thus
the calling code can set requests for prefix and address delegation
separately. This is handy when supporting RFC 7084.

Add a check in the code that at least something is requested from
the server in Managed mode. By default request IA_NA addresses from
the DHCPv6 server. Although a value has been defined for IA_TA,
temporay IA_TA addresses are not yet requested.
2018-09-19 13:45:17 -06:00
Patrik Flykt d8c51121bb dhcp6_client: Add helper for fetching Prefix Delegation information
Add helper function for fetching enabled/disabled state of Prefix
Delegation for a DHCPv6 client. Update function setting prefix
delegation to use an int instead of a boolean.
2018-09-19 13:45:17 -06:00
Yu Watanabe dc5f9c6f39 busctl,sd-lldp: explicitly specify type of argument in compare function
Several functions are shared by qsort and hash_ops or Prioq.
This makes these functions explicitly specify argument type,
and cast to __compar_fn_t where necessary.
2018-09-19 08:28:54 +09:00
Yu Watanabe 93bab28895 tree-wide: use typesafe_qsort() 2018-09-19 08:02:52 +09:00
Zbigniew Jędrzejewski-Szmek 6d7c403324 tests: use a helper function to parse environment and open logging
The advantages are that we save a few lines, and that we can override
logging using environment variables in more test executables.
2018-09-14 09:29:57 +02:00
Zbigniew Jędrzejewski-Szmek 317bb217d3 tests: add helper to unify skipping a test and exiting 2018-09-14 09:29:57 +02:00
Zbigniew Jędrzejewski-Szmek 08d541ca06 test: when skipping tests, always print something
It is quite confusing if the test "fails" without printing anything at all.

A typo in an 'if' statement is also fixed.
2018-09-13 12:07:34 +02:00
Thomas Haller a507737e5c dhcp: fix assertion starting DHCP client without MAC address (#10054)
An assertion in dhcp_network_bind_raw_socket() is triggered when
starting an sd_dhcp_client without setting a MAC address first.

  - sd_dhcp_client_start()
    - client_start()
      - client_start_delayed()
        - dhcp_network_bind_raw_socket()

In that case, the arp-type and MAC address is still unset. Note that
dhcp_network_bind_raw_socket() already checks for a valid arp-type
and MAC address below, so we should just gracefully return -EINVAL.

Maybe sd_dhcp_client_start() should fail earlier when starting without
MAC address. But the failure here will be correctly propagated and
the start aborted.

Fixes: 76253e73f9
2018-09-11 09:45:47 +09:00
Yu Watanabe 53253d9c54 sd-dhcp6: set requested time for DUID-LLT
Follow-up for 7e90a499ab.
2018-09-04 13:07:37 -07:00
Yu Watanabe 339697f081 sd-dhcp: drop meaningless checking
mac_addr is not dynamically allocated.

Fixes CID 1395162 and 1395164.
2018-09-04 13:07:37 -07: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
Zbigniew Jędrzejewski-Szmek c07fe6d0df Merge pull request #9406 from yuwata/rfe-9228
Trivial conflict solved in merge and include net/if_arp.h added.
2018-08-23 11:11:13 +02:00
Yu Watanabe 51517f9e09 network: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe 7e90a499ab sd-dhcp: make time value for DUID-LLT configurable 2018-08-08 10:15:00 +09:00
Yu Watanabe 335f80a612 sd-dhcp: use MAC address when DUIDType=link-layer-time or link-layer but DUIDRawData= is not set 2018-08-08 10:15:00 +09:00
Yu Watanabe f7708f3ffd sd-dhcp: adjust log message 2018-08-08 10:15:00 +09:00
Yu Watanabe 9d7b8c66f5 sd-dhcp: adjust type of elements in duid
These values should be stored in network byte order.
2018-08-08 10:15:00 +09:00
Yu Watanabe 27eba50e76 sd-dhcp: use application specific machine ID when DUIDType=uuid but DUIDRawData= is not set 2018-08-08 10:15:00 +09:00
Filipe Brandenburger a0edd02e43 tree-wide: Convert compare_func's to use CMP() macro wherever possible.
Looked for definitions of functions using the *_compare_func() suffix.

Tested:
- Unit tests passed (ninja -C build/ test)
- Installed this build and booted with it.
2018-08-06 19:26:35 -07:00
Dave Reisner 25ea58d373 network/link: Fix logic error in matching devices by MAC
Prior to this commit, a .link file with a [Match] section containing
MACAddress= would match any device without a MAC. This restores the
matching logic prior to e90d037.
2018-07-07 13:48:59 +02:00
Yu Watanabe afb76fdbff tree-wide: drop double newline 2018-06-29 11:02:17 +09:00
Yu Watanabe 712fdfd609 sd-dhcp: drop unnecessary condition 2018-06-25 13:51:34 +09:00
Zbigniew Jędrzejewski-Szmek d9b02e1697 tree-wide: drop copyright headers from frequent contributors
Fixes #9320.

for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do
  git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms'
done
2018-06-20 11:58:53 +02:00
Chris Lamb 3fe910794b Correct a number of trivial typos. 2018-06-18 22:44:44 +02:00