Commit graph

131 commits

Author SHA1 Message Date
Andreas Rammhold 3742095b27
tree-wide: use IN_SET where possible
In addition to the changes from #6933 this handles cases that could be
matched with the included cocci file.
2017-10-02 13:09:54 +02:00
juga0 66173db75b networkd: RFC7844, disable INIT-REBOOT state when
Anonymize is true.
2017-09-06 19:25:41 +02:00
juga0 1b41b81599 networkd: RFC7844, do not set any other option
when Anonymize is enabled.

Use the Client variable to know whether it is enabled.
2017-09-06 19:25:41 +02:00
juga0 5e77a1468e networkd: do not send more PRL options when Anonymize is true.
* check that Client has reserved memory for PRL
* do not send duplicated ROUTES option when Anonymize is true
2017-09-06 19:25:10 +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
Zbigniew Jędrzejewski-Szmek 25f027c5ef tree-wide: when %m is used in log_*, always specify errno explicitly
All those uses were correct, but I think it's better to be explicit.
Using implicit errno is too error prone, and with this change we can require
(in the sense of a style guideline) that the code is always specified.

Helpful query: git grep -n -P 'log_[^s][a-z]+\(.*%m'
2017-05-19 14:24:03 -04:00
Alexander Galanin 5153494f1d Include 'vendor class identifier option' into DHCPREQUEST message (#5380) 2017-02-20 10:15:58 +01:00
27o 3e7b9f76f5 dhcp: bind udp sockets to interfaces (#4822) 2016-12-07 02:00:05 +01:00
Zbigniew Jędrzejewski-Szmek ef8b008455 sd-dhcp-client: use free_and_strdup
This changes the return value a bit: 1 will be returned if the value is
changed. But the return value was not documented, and the change should
be for the good anyway. Current callers don't care.
2016-11-21 23:01:02 +01:00
Lennart Poettering 17f6ed4d59 sd-dhcp: permit unsetting the hostname again
Let's handle NULL hostnames (for unsetting it) before we validate the name.
2016-11-21 22:47:47 +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
Zbigniew Jędrzejewski-Szmek 6b430fdb7c tree-wide: use mfree more 2016-10-16 23:35:39 -04:00
Lennart Poettering 45aa74c72e sd-network: don't needlessly abbreviate "callback" as "cb" in struct members
It's OK to abbreviate this in the local scope, but otherwise, let's not be
needlessly terse.
2016-05-26 15:34:42 +02:00
Lennart Poettering a114066685 sd-network: fix up assertion chaos
assert_return() should only be used to validate user-facing parameters and
state, assert() should be used for checking our own internal state and
parameters.
2016-05-26 15:34:42 +02: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
Lennart Poettering 16f0b479ca sd-dhcp: shorten NUL initialization a bit 2016-05-26 15:34:42 +02:00
Lennart Poettering 004845d18e sd-network: unify packet processing logic a bit
Let's always check for errno being EAGAIN/EINTR the same way, and always log if
we receive weirdly short packets.
2016-05-26 15:34:41 +02:00
Tom Gundersen cf447cb62d libsystemd-network: use recv(..., 0) instead of read(...) (#3317)
According to recv(2) these should be the same, but that is not true.
Passing a buffer of length 0 to read is defined to be a noop according
to read(2), but passing a buffer of length 0 to recv will discard the
pending pacet.

We can easily hit this as we allocate our buffer size depending on
the size of the incoming packet (using FIONREAD). As pointed out in
issue #3299 simply sending an empty UDP packet to the DHCP client
port will trigger a busy loop in networkd as we are polling on the
socket but never discarding the empty packet.

This reverts ad5ae47a0d but fixes the
same issue.
2016-05-22 00:00:32 +03:00
sadag ad5ae47a0d sd-dhcp-client: fix busy loop reading zero sized DHCP UDP packets. (#3299) 2016-05-20 14:26:27 +03:00
Zbigniew Jędrzejewski-Szmek d7df2fd317 dh-dhcp{,6}-client: change the semantics of DUID setting
Both versions of the code are changed to allow the caller to override
DUID using simple rules: duid type and value may be specified, in
which case the caller is responsible to providing the contents,
or just duid type may be specified as DUID_TYPE_EN, in which case we
we fill in the values. In the future more support for other types may
be added, e.g. DUID_TYPE_LLT.

There still remains and ugly discrepancy between dhcp4 and dhcp6 code:
dhcp6 has sd_dhcp6_client_set_duid and sd_dhcp6_client_set_iaid and
requires client->state to be DHCP6_STATE_STOPPED, while dhcp4 has
sd_dhcp_client_set_iaid_duid and will reconfigure the client if it
is not stopped. This commit doesn't touch that part.

This addresses #3127 § 2.
2016-05-03 12:12:04 -04:00
Zbigniew Jędrzejewski-Szmek f7a92d1a7e sd-dhcp: change uint8_t *duid to const void* 2016-05-03 12:08:56 -04:00
Zbigniew Jędrzejewski-Szmek 4b558378a7 sd-dhcp{,6}-client: use standard indentation for functions args 2016-05-03 11:52:44 -04:00
Vinay Kulkarni 413708d106 DHCP DUID, IAID configuration options 2016-03-30 16:33:55 -07:00
Zbigniew Jędrzejewski-Szmek afec45395f Revert "DHCP DUID and IAID configurability" 2016-03-21 18:24:24 -04:00
Vinay Kulkarni c83321e6d4 DHCP DUID and IAID configurability 2016-03-09 21:58:44 -08:00
Thomas Haller 3587161ade core: avoid compiler warning when compiling with -fexceptions
Initialize auto variables with cleanup attribute, otherwise we
get a compiler warning with -fexceptions.

    ./configure CFLAGS='-Wmaybe-uninitialized -fexceptions -O2'
2016-02-27 13:40:50 +01:00
Lennart Poettering 32d2064523 libsystemd-network: sd-event uses 64bit priorities, expose them in the APIs as such 2016-02-20 22:42:29 +01:00
Lennart Poettering ccf8635435 libsystemd-network: don't abbreviate "callback" as "cb" needlessly
This isn't an excercise in creating APIs that are hard to understand, hence
let's call a callback a callback.
2016-02-20 22:42:29 +01:00
Lennart Poettering 4edc2c9b6b networkd: FIONREAD is not reliable on some sockets
Fixes: #2457
2016-02-16 13:06:55 +01:00
Beniamino Galvani 8ecdcb5525 dhcp: assert the success of sd_event_now()
The function must never fail.
2016-02-15 16:20:55 +01:00
Beniamino Galvani 1d1a3e0afb dhcp: delay restarts after NAKs
The server might answer to a DHCPREQUEST with a NAK and currently the
client restarts the configuration process immediately.  It was
observed that this can easily generate loops in which the network is
flooded with DISCOVER,OFFER,REQUEST,NAK sequences.

RFC 2131 only states that "if the client receives a DHCPNAK message,
the client restarts the configuration process" without further
details.

Add a delay with exponential backoff between retries after NAKs to
limit the number of requests and cap the delay to 30 minutes.
2016-02-02 15:23:34 +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 3cd03457bd util-lib: update dns_name_to_wire_format() to optionally generate DNSSEC canonical names
We'll need this later when putting together RR serializations to
checksum.
2015-12-02 22:50:11 +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
Martin Pitt 827661914a Merge pull request #2029 from teg/network-fixes
Network fixes
2015-11-27 10:20:18 +01:00
Lennart Poettering dc477e7385 dns-domain: simplify dns_name_is_root() and dns_name_is_single_label()
Let's change the return value to bool. If we encounter an error while
parsing, return "false" instead of the actual parsing error, after all
the specified hostname does not qualify for what the function is
supposed to test.

Dealing with the additional error codes was always cumbersome, and
easily misused, like for example in the DHCP code.

Let's also rename the functions from dns_name_root() to
dns_name_is_root(), to indicate that this function checks something and
returns a bool. Similar for dns_name_is_signal_label().
2015-11-25 22:00:07 +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
Tom Gundersen 0d43d2fcb7 libsystemd-network: clean up recv functions 2015-11-25 18:30:31 +01:00
Beniamino Galvani 23873e25aa libsystemd-network: add support for "Client FQDN" DHCP option
This adds support for the Client Fully Qualified Domain Name (FQDN)
option [RFC 4702] to libsystemd-network. The option can be used to
exchange information about a DHCPv4 client's fully qualified domain
name and about responsibility for updating the DNS RR related to the
client's address assignment.

Other popular DHCP clients (dhclient, dhcpcd) support this option and
it would be useful to have it in networkd too.
2015-11-17 15:06:01 +01:00
Jan Engelhardt a8eaaee72a doc: correct orthography, word forms and missing/extraneous words 2015-11-06 13:45:21 +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 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
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 fbcd420aa4 dhcp: don't underflow in lease time calculations
Don't underflow when calculating lease time.
2015-08-27 01:59:43 +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 0339cd7707 dhcp: clean up dhcp4 lease object
a) drop handling of obsolete or unused DHCP options time_offset,
   mtu_aging_timeout, policy filter, mdr, ttl, ip forwarding settings.
   Should this become useful one day we can readd support for this.

b) For subnet mask and broadcast it is not always clear whether 0 or
   255.255.255.255 might be valid, hence maintain a boolean indicating
   validity next to it.

c) serialize/deserialize broadcast address, lifetime, T1 and T2 together
   with the rest of the fields in dhcp_lease_save() and
   dhcp_lease_load().

d) consistently return ENODATA from getter functions for data that is
   missing in the lease.

e) add missing getter calls for broadcast, lifetime, T1, T2.

f) when decoding DHCP options, generate debug messages on parse
   failures, but try to proceed if possible.

g) Similar, when deserializing a lease in dhcp_lease_load(), make sure
   we deal nicely with unparsable fields, to provide upgrade compat.

h) fix some memory allocations
2015-08-27 01:05:13 +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
Thomas Hindoe Paaboel Andersen 144c348883 sd-dhcp-client: readd deleted error check
Seems to have been removed by mistake in:
9021bb9f93
2015-06-17 19:11:18 +02:00