Commit graph

67 commits

Author SHA1 Message Date
Tom Gundersen f667c150a9 sd-dhcp6-client: add is_running() method 2015-11-11 15:42:38 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 8b43440b7e util-lib: move string table stuff into its own string-table.[ch] 2015-10-27 13:25:56 +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 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
Tom Gundersen 56c5815983 Merge pull request #1332 from thom311/master
sd-dhcp6: ensure canceling lease timers and refactor setting lease
2015-09-24 00:59:15 +02:00
Patrik Flykt d7c9c21f18 sd-dhcp6-client: Prevent setting and restarting of DHCPv6 client
Prevent modifications to index, MAC address, DUID and Information
Request while the DHCPv6 client is running.

Require the DHCPv6 client to be stopped first instead of always
unconditionally restarting it if the caller calls
sd_dhcp6_client_start() more than once. With this change, handling
of for example incoming Router Advertisments becomes much easier.
2015-09-23 15:11:09 +03:00
David Herrmann 10c9ce615d sd-dhcp6: fix namespacing
Prefix all exported constants with SD_DHCP6_CLIENT_* to avoid any
namespacing conflicts.
2015-09-22 14:52:23 +02:00
Thomas Haller f89087272b sd-dhcp6: ensure canceling lease timers and refactor setting lease
Factor our common code to set/clear the client lease.
Resetting the lease involves canceling old timers.

Also, most importantly, when resetting the lease
in client_receive_advertise(), ensure to cancel
the timers too. It is not immediately clear, why
at that point no timers would be pending.

The lease-unref from sd_dhcp6_client_unref() can
be omited, because of the preceeding client_reset()
call.
2015-09-22 14:41:47 +02:00
Lennart Poettering 0ae0e5cd96 dhcp: coding style fixes
We place the opening bracket of a function on the same line as the
function name. Let's do so in the DHCP sources too.
2015-08-26 21:09:00 +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
David Herrmann e6b18ffaea sd-dhcp: don't randomly ref objects
In our API design, getter-functions don't ref objects. Calls like
foo_get_bar() will not ref 'bar'. We never do that and there is no real
reason to do it in single threaded APIs. If you need a ref-count, you
better take it yourself *BEFORE* doing anything else on the parent object
(as this might invalidate your pointer).

Right now, sd_dhcp?_get_lease() refs the lease it returns. A lot of
code-paths in systemd do not expect this and thus leak the lease
reference. Fix this by changing the API to not ref returned objects.
2015-08-26 12:30:56 +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 9d89d1ae71 sd-dhcp6-client: Save a DHCPv6 lease also with Information Reply
As the lease structure contains interesting information, save it also
for the Information Reply.
2015-08-21 11:23:21 +03:00
Patrik Flykt 4e3e6679e8 sd-dhcp6-client: Fix unreferencing DHCPv6 lease on client reset
When the DHCPv6 client is started by the library user or stopped for
any reason, unref the DHCPv6 lease when resetting the DHCPv6 client
data structure. This makes the DHCPv6 client always start from a clean
state and not keep unnecessary an lease structure around when stopped.

If this is not done, a previously existing lease information can be
interpreted to be from another server when restarting DHCPv6.
2015-08-21 11:23:21 +03:00
Lennart Poettering 38a03f06a7 sd-event: make sure sd_event_now() cannot fail
Previously, if the event loop never ran before sd_event_now() would
fail. With this change it will instead fall back to invoking now(). This
way, the function cannot fail anymore, except for programming error when
invoking it with wrong parameters.

This takes into account the fact that many callers did not handle the
error condition correctly, and if the callers did, then they kept simply
invoking now() as fall back on their own. Hence let's shorten the code
using this call, and make things more robust, and let's just fall back
to now() internally.

Whether now() is used or the cache timestamp may still be detected via
the return value of sd_event_now(). If > 0 is returned, then the fall
back to now() was used, if == 0 is returned, then the cached value was
returned.

This patch also simplifies many of the invocations of sd_event_now():
the manual fall back to now() can be removed. Also, in cases where the
call is invoked withing void functions we can now protect the invocation
via assert_se(), acknowledging the fact that the call cannot fail
anymore except for programming errors with the parameters.

This change is inspired by #841.
2015-08-03 17:34:49 +02:00
Lennart Poettering 62e3d1aed5 dhcp6: remove unnecessary if check 2015-04-21 00:58:56 +02:00
Thomas Hindoe Paaboel Andersen 8283c71b71 sd-dhcp6-client: unref lease when freeing the client 2015-04-14 18:32:58 +02:00
Ronny Chevalier 3df3e884ae shared: add random-util.[ch] 2015-04-11 00:11:13 +02:00
Thomas Haller cc22955cfe sd-dhcp6-client: delay setting the DUID and don't fail constructor
sd_dhcp6_client_new() tried to set the DUID based on the machine id.
If the host has no /etc/machine-id, the constructor would fail
making it impossible to create an sd_dhcp6_client instance.

Relax this and create a DUID only later as needed. This way a caller
caller can workaround a missing machine-id file and set a DUID of his
choosing via sd_dhcp6_client_set_duid().
2015-03-04 11:01:39 +01:00
Tom Gundersen cfb5b38057 network: dhcp - split out dhcp_identifier_set_{iaid,duid_en} from dhcp6-client
This will also be used in dhcp4-client.
2015-01-21 22:57:55 +01:00
Tom Gundersen 764aad6258 network: dhcp - split out the duid structure into a new header file
We will use the same in both dhcp4 and dhcp6.
2015-01-21 22:57:55 +01:00
Patrik Flykt 950a1705dc sd-dhcp6-client: Remove unnecessary debug printout 2015-01-20 19:39:28 +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 c4e8ceddcc test-dhcp6-client: Add a simple Information Request test case
Start the DHCPv6 test case by sending an Information Request, verifying
the reply and continuing at once with the normal address acquisition
procedure. Reuse the DHCPv6 Solicit Reply so that the client code is
verified to ignore any erroneously added IPv6 address information.
2014-12-10 18:31:21 +01:00
Patrik Flykt bbfa43ca37 sd-dhcp6-client: Implement Information Request message
Implement Information Request message according to RFC 3315, section
18.1.5. with the excepion that the first message is not delayed by a
random amount. Instead systemd-networkd is supposed to take care of
desynchronizing between other clients.

Initialize the DHCPv6 client structure in sd_dhcp6_client_start()
as this allows toggling between information request and normal
DHCPv6 address aquisition modes.
2014-12-10 18:31:21 +01:00
Patrik Flykt c47e8936a4 sd-dhcp6-client: Make end of successfull option parsing explicit
When all DHCPv6 options have been parsed, dhcp6_option_parse() returns
-ENOMSG. Explicitely set the return value to indicate success so that
later code does not need to take this special value into account.
2014-12-10 18:31:21 +01:00
Lennart Poettering 356779df90 sd-event: rename sd_event_source_set_name() to sd_event_source_get_name()
To mirror the recent name change of the concept for sd_bus objects,
follow the same logic for sd_event_source objects, too.
2014-11-04 18:09:19 +01:00
Dan Williams 393b6f28ec sd-dhcp6-client: fix off-by-two error in DUID length
The duid data passed by the caller does not include the DUID type,
but sd_dhcp6_client_set_duid() was treating it like it did.
2014-11-01 14:39:47 -04:00
Dan Williams 76253e73f9 sd-dhcp-client: support non-Ethernet hardware addresses
Like Infiniband.  See RFC 4390 section 2.1 for details on DHCP
and Infiniband; chaddr is zeroed, hlen is set to 0, and htype
is set to ARPHRD_INFINIBAND because IB hardware addresses
are 20 bytes in length.
2014-10-11 12:15:54 +02:00
Tom Gundersen fe4b215625 sd-dhcp6: do basic sanity-checking of supplied DUID 2014-10-02 19:07:30 +02:00
Tom Gundersen ebe207d4ac sd-dhcp6: specify the type explicitly when setting custom DUID
This would make it simple to verify that the data is on the right format when
the type is known.
2014-10-02 19:07:30 +02:00
Tom Gundersen 9547267dc5 sd-dhcp6: support custom DUID's up to the size specified in the RFC 2014-10-02 19:07:30 +02:00
Dan Williams 66eac1201a sd-dhcp6-client: support custom DUIDs
The caller may have an existing DUID that it wants to use, and may
want to use some other DUID generation scheme than systemd's
default DUID-EN.

[tomegun: whitespace - we never use tabs]
2014-10-02 19:07:30 +02:00
Patrik Flykt 346e13a25d sd-dhcp6-client: Implement Elapsed Time option
Implement Elapsed Time option as it is defined as MUST in RFC 3315,
section 22.9. The elapsed time value is a 1/100th of a second with
a max value of 0xffff, i.e. 655.35 seconds.

As the main loop might not be running yet when sd_dhcp6_client_start() is
called, fetch the monotonic time directly and not from the event loop
while in state DHCP6_STATE_STOPPED.
2014-09-10 12:56:24 +03:00
Zbigniew Jędrzejewski-Szmek 44481a8b53 sd-dhcp6-client: properly calculate buffer size when parsing options
Also make pointer calculations more explicit so they are
easier to understand.
2014-08-30 18:42:20 -04:00
Tom Gundersen 9021bb9f93 sd-event: name event sources used in libraries
This should help in debugging failing event sources.
2014-08-28 21:19:17 +02:00
Lennart Poettering 5364f729ba indentation/spurious whitespace fixes 2014-08-20 00:18:14 +02:00
Tom Gundersen fa94c34b08 libsystemd-network: use CLOCK_BOOTTIME instead of CLOCK_MONOTONIC where possible
The timeouts in the networking library (DHCP lease timeouts and similar) should not be affected
by suspend. In the cases where CLOCK_BOOTTIME is not implemented, it is still safe to fallback to
CLOCK_MONOTONIC, as the consumers of the library (i.e., networkd) _should_ renew the leases when
coming out of suspend.
2014-07-24 19:02:58 +02:00
Dan Williams 6946f79d98 dhcp-network: remove unused DHCP6_STATE_RS
Probably a left-over from when router solicitations were
requested in the DHCP6 code.  But since they are now separate,
this state is no longer needed.
2014-07-23 09:19:47 +02:00
Tom Gundersen 4b4923e654 sd-dhcp6-client: make gcc happy
It complains about {max,init}_retransmit_time possibly being
uninitialized. It is wrong, but let's just initialize it.
2014-07-14 16:49:41 +02:00
Steven Noonan b1e1238fb3 networkd: don't clear dhcpv6 lease timers if there's no previous lease
If client->lease is NULL, dhcp6_lease_clear_timers will cause a segmentation
fault.
2014-07-04 11:34:43 +02:00
Tom Gundersen 5e91345094 sd-dhcp6-client: initialize variable 2014-07-02 15:54:27 +02:00
Thomas Hindoe Paaboel Andersen 926695f1b5 sd-dhcp6-client: check return value
Checking the return values seems to have been forgotten in
ed6ee21953
2014-07-01 23:46:51 +02:00
Tom Gundersen 54d61deb7b sd-dhcp6-client: fix free before use 2014-07-01 10:21:18 +02:00