Commit Graph

62 Commits

Author SHA1 Message Date
Lennart Poettering 39cf0351c5 tree-wide: make use of new relative time events in sd-event.h 2020-07-28 11:24:55 +02:00
Yu Watanabe 1a6c913676 libsystemd-network: rename index -> ifindex 2020-07-02 16:58:06 +09:00
Lennart Poettering ddb82ec2a2 sd-dhcp: clean-up of DHCP lease server code
This is an attempt to clean-up the DHCP lease server type code a bit. We
now strictly use the same enum everywhere, and store server info in an
array. Moreover, we use the same nomenclature everywhere.

This only makes the changes in the sd-dhcp code. The networkd code is
untouched so far (but should be fixed up like this too. But it's more
complicated since this would then touch actual settings in .network
files).

Note that this also changes some field names in serialized lease files.
But given that these field names have not been part of a released
version of systemd yet, such a change should be ok.

This is pure renaming/refactoring, shouldn't actually change any
behaviour.
2020-05-30 14:18:43 +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
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
Thomas Haller f8862395e8 dhcp: handle multiple addresses for "Router" (option 3) in DHCP library
The Router DHCP option may contain a list of one or more
routers ([1]). Extend the API of sd_dhcp_lease to return a
list instead of only the first.

Note that networkd still only uses the first router (if present).
Aside from extending the internal API of the DHCP client, there
is almost no change in behavior. The only visible difference in
behavior is that the "ROUTER" variable in the lease file is now a
list of addresses.

Note how RFC 2132 does not define certain IP addresses as invalid for the
router option. Still, previously sd_dhcp_lease_get_router() would never
return a "0.0.0.0" address. In fact, the previous API could not
differenciate whether no router option was present, whether it
was invalid, or whether its first router was "0.0.0.0". No longer let
the DHCP client library impose additional restrictions that are not
part of RFC. Instead, the caller should handle this. The patch does
that, and networkd only consideres the first router entry if it is not
"0.0.0.0".

[1] https://tools.ietf.org/html/rfc2132#section-3.5
2019-02-18 13:34:22 +01:00
Thomas Haller 6d13616b9e dhcp: support endianness independent dhcp_identifier_set_iaid()
The previous code did htole64() followed by unaligned_write_be32() (the
XOR and shift in between is endianness agnostic). That means, on every
architeture there is always exactly one byte swap and the iaid is
dependent on endianness.

Since dhcp_identifier_set_iaid() is part of the DUID generation
algorithm, this cannot be fixed without changing the client-id.
In particular, as the client-id already depends on the machine-id (and
is thus inherrently host-specific), it is better to stick to the current
behavior.

However, add a parameter to switch between old and new behaviour.
Since the new behavior is unused, the only real purpose of this
change is to self-document the oddity of the function.

Fixes: 933f9caeeb
2018-11-12 19:08:35 +01:00
Thomas Haller 43fc095532 dhcp: add test for dhcp_identifier_set_iaid() 2018-11-12 19:08:35 +01:00
Yu Watanabe 3e29b8895a libsystemd-network: set SOCK_CLOEXEC and SOCK_NONBLOCK 2018-11-12 02:03:22 +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
Lennart Poettering 810adae9e9 tree-wide: use proper unicode © instead of (C) where we can
Let's use a proper unicode copyright symbol where we can, it's prettier.

This important patch is very important.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Zbigniew Jędrzejewski-Szmek d18cb3937b Turn VALGRIND variable into a meson configuration switch
Configuration through environment variable is inconvenient with meson, because
they cannot be convieniently changed and/or are not preserved during
reconfiguration (https://github.com/mesonbuild/meson/issues/1503).
This adds -Dvalgrind=true/false, which has the advantage that it can be set
at any time with meson configure -Dvalgrind=... and ninja will rebuild targets
as necessary. Additional minor advantages are better consistency with the
options for hashmap debugging, and typo avoidance with '#if' instead of '#ifdef'.
2018-05-17 09:54:36 -07:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +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
Stefan Agner 9740eae694 sd-dhcp-client: validate hostnames stricter (#7308)
Technically DNS allows any ASCII character to be used in the
domain name. Also the DHCP specification for the FQDN option
(RFC 4702) does not put restriction on labels.

However, hostnames do have stricter requirements and typically
should only use characters from a-z (case insensitve), 0-9 and
minus.

Currently we require hostname/FQDN to be either a hostname or
a valid DNS name. Since dns_name_is_valid() allows any ASCII
characters this allows to specify hostnames which are typically
not valid.

Check hostname/FQDN more strictly and require them to pass both
tests. Specifically this requires the entire FQDN to be below 63.
2017-11-16 10:05:44 +01:00
Florian Klink da172fa9ea test-dhcp-client: fix typos in comment (#7052) 2017-10-11 14:45:48 +02:00
Yu Watanabe 4c70109600 tree-wide: use IN_SET macro (#6977) 2017-10-04 16:01:32 +02:00
juga0 dbb35f1f13 networkd: test DHCP client when Anonymize is true. 2017-09-06 19:25:41 +02:00
juga0 db3d235820 networkd: set PRL default options depending on Anonymize.
Add also Client variable to know when Anonymize is true.
2017-09-06 19:03:25 +02:00
27o 3e7b9f76f5 dhcp: bind udp sockets to interfaces (#4822) 2016-12-07 02:00:05 +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
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
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 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
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
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
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
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +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 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
David Herrmann 0374814250 sd-dhcp: fix namespacing
Prefix all constants with SD_DHCP_CLIENT_* to avoid namespacing
conflicts.
2015-09-22 14:46:21 +02: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 4b7b5abb78 dhcp: NTP servers should be requested by networkd but not implicitly by sd-dhcp
The library so far always requested the NTP servers. This might be
unnecessary in some uses, hence let's move the request into networkd
instead.
2015-08-27 01:17:30 +02:00
Lennart Poettering e473522841 dhcp: generic data should be void*, not uint8_t*
If we handly arbitrary data we should use "void*" pointers, not
"uint8_t*", how go intended C to be used.
2015-08-26 23:05:34 +02:00
Lennart Poettering 89ca10c6a6 network: s/user_data/userdata/
Everywhere else we call the generic user data pointer just "userdata",
rather than "user_data". Let's do this here, too.
2015-08-26 22:47: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
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Zbigniew Jędrzejewski-Szmek 374c22b351 test-dhcp-client: add a kludge to make valgrind happy 2015-02-02 20:31:18 -05:00
Zbigniew Jędrzejewski-Szmek fe0885f8ce test-dhcp-client: open a real udp socket for test execution
./test-dhcp-client would attempt to operate fd 0, i.e. stdin.
For example, './test-dhcp-client </dev/null' would fail with EPERM
because /dev/null cannot be used with epoll.

https://bugzilla.redhat.com/show_bug.cgi?id=1076119
2015-02-02 20:31:18 -05:00
Zbigniew Jędrzejewski-Szmek afa3509a4f test-dhcp-client: remove linebreak 2015-01-31 12:25:12 -05:00
Tom Gundersen 5bac523593 sd-dhcp-client: use RFC4361-complient ClientID by default
In addition to the benefits listed in the RFC, this allows DHCP to work also in
case several interfaces share the same MAC address on the same link (IPVLAN).

Note that this will make the ClientID (so probably the assigned IP address)
change on upgrades. If it is desired to avoid that we would have to remember and
write back the ID (which the library supports, but networkd currently does not).
2015-01-22 21:29:42 +01:00
Tom Gundersen fc292b5f58 test-dhcp-client: add more asserts 2014-10-13 10:07:29 +02: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 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
Michal Sekletar 58587a7a0c dhcp-network: add check for DHCP.chaddr
Check that received DHCP packets actually include our MAC address in
chaddr field. BPF interpreter has 32 bit wide registers but MAC address
is 48 bits long so we have to do check in two steps.
2014-07-07 12:17:55 +02:00
Tom Gundersen 0bbc2c1f3b sd-dhcp: checksum - make endianess-neutral
For efficiency, we group bytes together before adding them up. This
is guaranteed to always work (regardless of the byte order) as long
as the i-th byte in each group lign up with the i-th byte in each
other group.

On big-endian machines this broke when handling the trailing few bytes
which did not make up a full group of 4 bytes. This patch fixes the
problem by explicitly creating a 4 byte zero-padded group out of the
trailing bytes.

Reported and tested by Thomas Ritter <th.ritter@gmx.at>.
2014-06-17 09:17:07 +02:00
Tom Gundersen 085cabf266 dhcp-network: don't pass ifindex to bind_udp_socket
UDP sockets can anyway not be bound to specific netdev's. The packages would have to be filtered
when received instead.
2014-05-06 21:58:08 +02:00
Umut Tezduyar Lindskog d9bf4f8c6c libnetworkd: add link local tests
- Also only allow positive ifindex on both dhcp and ipv4ll

[tomegun: the kernel always sets a positive ifindex, but some APIs accept
          ifindex=0 with various meanings, so we should protect against
          accidentally passing ifindex=0 along.]
2014-04-27 23:39:13 +02:00
Zbigniew Jędrzejewski-Szmek 6e00a80641 test-dhcp-client: unref lease objects to make valgrind happy
Also unref client objects in test code, and initalize logging,
to DEBUG by default.
2014-04-12 10:20:55 -04:00