Commit graph

204 commits

Author SHA1 Message Date
Yuri Chornoivan d7b34e3841 all: fix minor typos
[thaller@redhat.com: original patch by Yuri, extracted from [1]]

[1] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/565
2020-07-07 18:52:49 +09:00
Yu Watanabe 921693a0f3 dhcp4: do not try to renew address when client has no lease 2020-07-07 10:18:58 +09:00
Yu Watanabe ceaec54a3c dhcp4: do not renew address if client is not running yet 2020-07-07 10:18:22 +09:00
Marc-André Lureau 7be3261222 sd-dhcp-client: add sd_dhcp_client_id_to_string()
Add a human-friendly pretty-printer for client ID.
2020-06-04 11:16:15 +02:00
Marc-André Lureau 00ebe01156 sd-dhcp-client: make struct sd_dhcp_client_id reusable 2020-06-04 11:16:15 +02:00
Zbigniew Jędrzejewski-Szmek 929d07ddcb
Merge pull request #15274 from ssahani/network-issue-9610
DHCP4: Allow lease time to be set when missing from offer
2020-05-20 16:39:41 +02:00
Susant Sahani 579ca0a2b2 sd-network: DHCPv4 - Add user class, extra option and send generic options in request state 2020-05-20 15:43:20 +02:00
Susant Sahani 4c0b8d563d sd-dhcpv4: Allow to configure lease lifetime 2020-05-20 06:30:05 +02:00
Lennart Poettering fb29cdbef2 tree-wide: make sure our control buffers are properly aligned
We always need to make them unions with a "struct cmsghdr" in them, so
that things properly aligned. Otherwise we might end up at an unaligned
address and the counting goes all wrong, possibly making the kernel
refuse our buffers.

Also, let's make sure we initialize the control buffers to zero when
sending, but leave them uninitialized when reading.

Both the alignment and the initialization thing is mentioned in the
cmsg(3) man page.
2020-05-07 14:39:44 +02:00
Lennart Poettering a258f4915a tree-wide: use CMSG_SPACE() (and not CMSG_LEN()) to allocate control buffers
We need to use the CMSG_SPACE() macro to size the control buffers, not
CMSG_LEN(). The former is rounded up to next alignment boundary, the
latter is not. The former should be used for allocations, the latter for
encoding how much of it is actually initialized. See cmsg(3) man page
for details about this.

Given how confusing this is, I guess we don't have to be too ashamed
here, in most cases we actually did get this right.
2020-05-07 14:39:44 +02:00
Zbigniew Jędrzejewski-Szmek 11f9379866
Merge pull request #15570 from poettering/cmsg-find
CMSG_FIND_DATA() and cmsg_find() work
2020-04-24 07:45:07 +02:00
Lennart Poettering 84b5d3e532 dhcp-client: port to recvmsg_safe()
Split out of #15457, let's see if this is the culprit of the CI failure.

(also setting green label here, since @keszybz already greenlit it in that other PR)
2020-04-24 07:40:32 +02:00
Lennart Poettering dac556fa7b tree-wide: use cmsg_find() helper at various places where appropriate 2020-04-23 19:41:15 +02:00
Susant Sahani d11d4a6459 sd-dhcpv4: introduce The Manufacturer Usage Description (MUD) 2020-03-30 19:16:01 +02:00
David Wood 7354900ddd network: Fix split in SendOption= on client and server
When specifying `DHCPv4.SendOption=`, it is used by systemd-networkd to
set the value of that option within the DHCP request that is sent out.
This differs to setting `DHCPServer.SendOption=`, which will place all
the options together as suboptions into the vendor-specific information
(code 43) option.

This commit adds two new config options, `DHCPv4.SendVendorOption=` and
`DHCPServer.SendVendorOption=`. These both have the behaviour of the old
`DHCPServer.SendOption=` flag, and set the value of the suboption in the
vendor-specific information option.

The behaviour of `DHCPServer.SendOption=` is then changed to reflect
that of `DHCPv4.SendOption=`. It will set the value of the corresponding
option in the DHCP request.
2020-03-19 09:08:40 +01:00
Susant Sahani 0f3ff4eae2 network: DHCP4 introduce send decline 2019-12-21 00:26:44 +09:00
Zbigniew Jędrzejewski-Szmek b014a6161a
Merge pull request #14064 from yuwata/network-unify-send-option-and-send-raw-option
network: unify SendOption= and SendRawOption=
2019-11-18 22:21:37 +01:00
Yu Watanabe 461dbb2fa9 dhcp: remove struct sd_dhcp_raw_option
sd_dhcp_raw_option and sd_dhcp_option are essentially equivalent.
2019-11-18 23:37:22 +09:00
Yu Watanabe ce0d4c4f91
Merge pull request #14056 from yuwata/dhcp-debug-logs
dhcp: add debug logs and propagate error in restarting client
2019-11-18 18:49:45 +09:00
Serge bf9012bbf6 sd-dhcp-client: anonymize DHCPDISCOVER (fixes #13992)
According to RFC7844 section 3 the DHCPDISCOVER message should not contain option 50 («Requested IP Address») when Anonymize is true
2019-11-18 00:06:01 +09:00
Yu Watanabe 944e23b8a0 dhcp4: propagate error in restarting DHCPv4 client 2019-11-17 23:52:46 +09:00
Yu Watanabe f515c345d2 dhcp4: add debug logs 2019-11-17 23:48:46 +09:00
Yu Watanabe 455fa9610c tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
Zbigniew Jędrzejewski-Szmek f7af63fd86 sd-dhcp-client: do not call assert in public functions 2019-10-24 12:04:48 +02:00
Zbigniew Jędrzejewski-Szmek 9b08c804ef sd-dhcp-client: remove unnecessary cleanup function
https://github.com/systemd/systemd/pull/13663#discussion_r335327099
2019-10-24 12:00:07 +02:00
Susant Sahani cb29c15605 network: DHCPv4 client: add support to send arbitary option and data 2019-10-15 00:14:02 +09:00
Zbigniew Jędrzejewski-Szmek 8bea7e700f sd-dhcp-client: do not crash if sd_dhcp_client_send_release() is called with no lease
Again, a public function should not crash if called at an inopportune moment.

Also, make sure we don't call the function if we have no lease.
2019-10-02 14:01:42 +02:00
Zbigniew Jędrzejewski-Szmek 8ff4585ffa sd-dhcp-client: merge client_send_release() into sd_dhcp_client_send_release()
The public function and the implementation were split into two for
no particular reason.

We would assert() on the internal state of the client. This should not be done
in a function that is directly called from a public function. (I.e., we should
not crash if the public function is called at the wrong time.)
assert() is changed to assert_return().

And before anyone asks: I put the assert_returns() *above* the internal
variables on purpose. This makes it easier to see that the assert_returns()
are about the state that is passed in, and if they are not satisfied, the
function returns immediately. The compiler doesn't care either way, so
the ordering that is clearest to the reader should be chosen.
2019-10-02 14:01:42 +02:00
Siddharth Chandrasekara afe42aef39 dhcp4: make IPServiceType configurable
IPServiceType set to CS6 (network control) causes problems on some old
network setups that continue to interpret the field as IP TOS.

Make DHCP work on such networks by allowing this field to be set to
CS4 (Realtime) instead, as this maps to IPTOS_LOWDELAY.

Signed-off-by: Siddharth Chandrasekaran <csiddharth@vmware.com>
2019-09-26 11:39:46 +09:00
Yu Watanabe 1c9a2e266f dhcp: introduce sd_dhcp_client_send_renew() 2019-07-18 22:41:48 +09:00
Yu Watanabe bdbb98d9ae dhcp: fix minor coding style issue 2019-07-18 22:41:09 +09:00
Yu Watanabe 7fa6223f67 dhcp: replace strerror() with %m 2019-07-05 02:43:56 +09:00
Yu Watanabe 3d9f670783 dhcp: fix comparison with previous lease
Follow-up for f8862395e8.

Fixes #12816.
2019-06-18 10:27:59 +02:00
Susant Sahani 1501b429a9 networkd: DHCP client add support to send RELEASE packet
closes #10820
2019-05-14 09:03:01 +02:00
Susant Sahani 727b573418 networkd: Add support for blacklisting servers
closes #6260

fuzzer: Add DHCP support for blacklisting servers
2019-05-10 15:29:55 +02:00
Susant Sahani 715cedfbf0 networkd: Allow DHCP4 client to set the number to attempt to reconfigure.
Otherwise current value is 6 and after 6 it will give up.
2019-05-07 17:12:04 +02:00
Yu Watanabe 11793fcd63 sd-dhcp: store number of trial in sd_dhcp_client::attempt
Calling 2^n as attempt is misleading.
2019-05-07 04:08:33 +02:00
Susant Sahani 8bc17bb3f7 networkd: Option to use LinkLocalAddressing only when DHCP fails
When LinkLocalAddressing=fallback or LinkLocalAddressing=ipv4-fallback
then IPv4LL will be started only when DHCP fails.

Closes #9648.
2019-05-04 16:45:57 +02:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Beniamino Galvani 22a3fd2da9 dhcp: don't stop receiving packets when the link goes down
When the link goes down, DHCP client_receive_message*() functions return an
error and the related I/O source is removed from the main loop. With the
current implementation of systemd-networkd this doesn't matter because the DHCP
client is always stopped on carrier down and restarted on carrier up. However
it seems wrong to have the DHCP client crippled (because no packet can be
received anymore) once the link goes temporarily down.

Change the receive functions to ignore a ENETDOWN event so that the client will
be able to receive packets again after the link comes back.
2019-02-19 20:19:36 +09:00
Thomas Haller 13f1fd0376 dhcp: ignore padding of 'chaddr' in DHCP server response
The "chaddr" field is 16 bytes long, with "hlen" being the
length of the address.

https://tools.ietf.org/html/rfc2131#section-4.3.1 says:

    The server MUST return to the client:

    ...

    o Any parameters specific to this client (as identified by
      the contents of 'chaddr' or 'client identifier' in the DHCPDISCOVER
      or DHCPREQUEST message), e.g., as configured by the network
      administrator,

It's not clear, whether only the first 'hlen' bytes of 'chaddr'
must correspond or all 16 bytes.

Note that https://tools.ietf.org/html/rfc4390#section-2.1 says for IPoIB

    "chaddr" (client hardware address) field MUST be zeroed.

with having "hlen" zero. This indicates that at least in this case, the
bytes after "hlen" would matter.

As the DHCP client always sets the trailing bytes to zero, we would expect
that the server also replies as such and we could just compare all 16 bytes.
However, let's be liberal and accept any padding here.

This in practice only changes behavior for infiniband, where we
previously would enforce that the first ETH_ALEN bytes are zero.
That seems arbitrary for IPoIB. We should either check all bytes or
none of them. Let's do the latter and don't enforce RFC 4390 in this
regard.
2019-02-15 11:41:06 +01:00
Yu Watanabe e4a0fe6343 dhcp: drop unnecessary brackets 2018-12-23 08:00:59 +09:00
Yu Watanabe da3c49e9a8 dhcp: use cast-to-bool for pointers 2018-12-23 08:00:59 +09:00
Yu Watanabe 759248856c dhcp: fix indentation 2018-12-23 08:00:59 +09:00
Thomas Haller ab4a88bc29 dhcp6: don't enforce DUID content for sd_dhcp6_client_set_duid()
There are various functions to set the DUID of a DHCPv6 client.
However, none of them allows to set arbitrary data. The closest is
sd_dhcp6_client_set_duid(), which would still do validation of the
DUID's content via dhcp_validate_duid_len().

Relax the validation and only log a debug message if the DUID
does not validate.

Note that dhcp_validate_duid_len() already is not very strict. For example
with DUID_TYPE_LLT it only ensures that the length is suitable to contain
hwtype and time. It does not further check that the length of hwaddr is non-zero
or suitable for hwtype. Also, non-well-known DUID types are accepted for
extensibility. Why reject certain DUIDs but allowing clearly wrong formats
otherwise?

The validation and failure should happen earlier, when accepting the
unsuitable DUID. At that point, there is more context of what is wrong,
and a better failure reason (or warning) can be reported to the user. Rejecting
the DUID when setting up the DHCPv6 client seems not optimal, in particular
because the DHCPv6 client does not care about actual content of the
DUID and treats it as opaque blob.

Also, NetworkManager (which uses this code) allows to configure the entire
binary DUID in binary. It intentionally does not validate the binary
content any further. Hence, it needs to be able to set _invalid_ DUIDs,
provided that some basic constraints are satisfied (like the maximum length).

sd_dhcp6_client_set_duid() has two callers: both set the DUID obtained
from link_get_duid(), which comes from configuration.
`man networkd.conf` says: "The configured DHCP DUID should conform to
the specification in RFC 3315, RFC 6355.". It does not not state that
it MUST conform.

Note that dhcp_validate_duid_len() has another caller: DHCPv4's
dhcp_client_set_iaid_duid_internal(). In this case, continue with
strict validation, as the callers are more controlled. Also, there is
already sd_dhcp_client_set_client_id() which can be used to bypass
this check and set arbitrary client identifiers.
2018-12-20 13:40:39 +01:00
Thomas Haller bfda0d0f09 dhcp: don't enforce hardware address length for sd_dhcp_client_set_client_id()
sd_dhcp_client_set_client_id() is the only API for setting a raw client-id.
All other setters are more restricted and only allow to set a type 255 DUID.

Also, dhcp4_set_client_identifier() is the only caller, which already
does:

                r = sd_dhcp_client_set_client_id(link->dhcp_client,
                                                 ARPHRD_ETHER,
                                                 (const uint8_t *) &link->mac,
                                                 sizeof(link->mac));

and hence ensures that the data length is indeed ETH_ALEN.

Drop additional input validation from sd_dhcp_client_set_client_id(). The client-id
is an opaque blob, and if a caller wishes to set type 1 (ethernet) or type 32
(infiniband) with unexpected address length, it should be allowed. The actual
client-id is not relevant to the DHCP client, and it's the responsibility of the
caller to generate a suitable client-id.

For example, in NetworkManager you can configure all the bytes of the
client-id, including such _invalid_ settings. I think it makes sense,
to allow the user to fully configure the identifier. Even if such configuration
would be rejected, it would be the responsibility of the higher layers (including
a sensible error message to the user) and not fail later during
sd_dhcp_client_set_client_id().

Still log a debug message if the length is unexpected.
2018-12-20 13:31:48 +01:00
Thomas Haller b9d8071458 dhcp: fix sd_dhcp_client_set_client_id() for infiniband addresses
Infiniband addresses are 20 bytes (INFINIBAND_ALEN), but only the last
8 bytes are suitable for putting into the client-id.

This bug had no effect for networkd, because sd_dhcp_client_set_client_id()
has only one caller which always uses ARPHRD_ETHER type.

I was unable to find good references for why this is correct ([1]). Fedora/RHEL
has patches for ISC dhclient that also only use the last 8 bytes ([2], [3]).
RFC 4390 (Dynamic Host Configuration Protocol (DHCP) over InfiniBand) [4] does
not discuss the content of the client-id either.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1658057#c29
[2] https://bugzilla.redhat.com/show_bug.cgi?id=660681
[3] 3ccf3c8d81/f/dhcp-lpf-ib.patch
[4] https://tools.ietf.org/html/rfc4390
2018-12-20 13:15:49 +01:00
Thomas Haller 8217ed5ec3 network: fix handling of uninitialized and zero IAID setting
An earlier commit 0e408b82b (dhcp6-client: handle IAID with value zero)
introduced a flag to sd_dhcp6_client to distinguish between an unset
IAID and a value set to zero.

However, that was not sufficient and broke leaving the setting
uninitialized in networkd configuration. The configuration parsing
also must distinguish between the default, unset value and an
explict zero configuration.

Fixes: 0e408b82b8
2018-12-10 14:25:28 +01:00
Lennart Poettering cb3108669d tree-wide: more IOVEC_MAKE() conversions 2018-11-28 13:08:19 +09:00
Yu Watanabe a3fa4287f5 dhcp-client: do not unref() event sources when update or disable them 2018-11-16 22:57:42 +09:00