Commit graph

92 commits

Author SHA1 Message Date
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
Lennart Poettering 2a1288ff89 util: introduce CMSG_FOREACH() macro and make use of it everywhere
It's only marginally shorter then the usual for() loop, but certainly
more readable.
2015-06-10 19:29:47 +02:00
Lennart Poettering dd168445f8 dhcp: yes, infiniband has the larger MAC address length, but let the compuler figure that out... 2015-04-12 20:15:08 +02:00
Ronny Chevalier 3df3e884ae shared: add random-util.[ch] 2015-04-11 00:11:13 +02:00
Lennart Poettering 3dc055541c Revert "sd-dhcp-client: fix strict aliasing issue"
This reverts commit 6ec8e7c763.

This doesn't fix any issues, just makes the code harder to read.
2015-04-10 19:04:43 +02:00
Shawn Landden 6ec8e7c763 sd-dhcp-client: fix strict aliasing issue 2015-03-14 14:50:45 +01: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
Lennart Poettering a38d99451f Revert "tree-wide: Always use recvmsg with MSG_CMSG_CLOEXEC"
This reverts commit d6d810fbf8.

It's apparently not OK to pass MSG_CMSG_CLOEXEC to recvmsg() of raw
sockets.
2015-02-12 11:45:39 +01:00
Cristian Rodríguez d6d810fbf8 tree-wide: Always use recvmsg with MSG_CMSG_CLOEXEC 2015-02-10 21:20:16 +01: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
Zbigniew Jędrzejewski-Szmek 1fa2f38f0f Assorted format fixes
Types used for pids and uids in various interfaces are unpredictable.
Too bad.
2015-01-22 01:14:52 -05: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
Veres Lajos f131770b14 tree-wide: spelling fixes
https://github.com/vlajos/misspell_fixer

b6fdeb618c
Thanks to Torstein Husebo <torstein@huseboe.net>.
2014-12-30 20:07:04 -05:00
Tom Gundersen 0411760af1 sd-dhcp-client: log if we fail to set up lease timers 2014-12-11 14:43:09 +01:00
Dan Williams e37f74a6d5 sd-dhcp-lease: load/save client ID
The lease is usually tied to the client ID, so users of the
lease may want to know what client ID it was acquired with.
2014-11-19 00:58:51 +01:00
Dan Williams ba6c0fd630 sd-dhcp-client: allow getting/setting the client ID
The client identifier can be in many different formats, not just
the one that systemd creates from the Ethernet MAC address.  Non-
ethernet interfaces may have different client IDs formats.  Users
may also have custom client IDs that the wish to use to preserve
lease options delivered by servers configured with the existing
client ID.
2014-11-19 00:53:24 +01:00
Dan Williams d8d74ef06f sd-dhcp-client: fix REBOOT state handling
client->secs wasn't getting set in the REBOOT state, causing
an assertion.  REBOOT should work the same way as INIT, per
RFC 2131:

 secs   2  Filled in by client, seconds elapsed since client
           began address acquisition or renewal process.

REBOOT is necessary because some DHCP servers (eg on
home routers) do not hand back the same IP address unless the
'ciaddr' field is filled with that address, which DISCOVER
cannot do per the RFCs.  This leads to multiple leases
on machine reboot or DHCP client restart.
2014-11-18 18:25:43 +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 affaa94fc3 sd-dhcp-client: clean up raw socket sd_event_source when creating new UDP socket
The raw socket sd_event_source used for DHCP server solicitations
was simply dropped on the floor when creating the new UDP socket
after a lease has been acquired.  Clean it up properly so we're
not still listening and responding to events on it.
2014-10-31 09:26:27 +01: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
Ruben Kerkhof 6ff8806e1d Fix a few typos in log messages 2014-08-29 09:28:19 -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 db73295acc util: never use ether_ntoa(), since it formats with %x, not %02x, which makes ethernet addresses look funny 2014-08-15 13:19:03 +02:00
Tom Gundersen 324f818781 sd-dhcp-client: allow the max dhcp message size to be set to the MTU of the link 2014-08-01 16:34:50 +02:00
Tom Gundersen 615c1467c8 sd-dhcp-client: add support for FORCERENEW
This partially implements RFC3203. Note that we are not fully compliant as we do not
support authentication.
2014-07-28 10:44:51 +02:00
Tom Gundersen 0af03ba57f sd-dhcp-client: listen on UDP socket as soon as a lease is acquired
This is necessary in order to listen for FORCERENEW events.
2014-07-28 10:44:51 +02:00
Tom Gundersen 2d2349cc3e sd-dhcp-client: drop event DHCP_EVENT_NO_LEASE
Keep this internal to the client and simply restart it when NAK is receieved, as
per the RFC.
2014-07-28 10:44:51 +02:00
Tom Gundersen 9fbc25232c sd-dhcp-client: only verify UDP messages
RAW messages are verified by the BPF in the kernel.
2014-07-28 10:44:51 +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
Tom Gundersen f5de5b0020 sd-dhcp-client: make request broadcasts opt-in
It appears there is no good way to decide whether or not broadcasts should be enabled,
there is hardware that must have broadcast, and there are networks that only allow
unicast. So we give up and make this configurable.

By default, unicast is used, but if the kernel were to inform us abotu certain
interfaces requiring broadcast, we could change this to opt-in by default in
those cases.
2014-07-15 18:55:31 +02:00
Susant Sahani edb85f0d8d networkd: dhcp add vendor class indentifier option 60
Vendor Class Identifier be used by DHCP clients to identify
their vendor type and configuration. When using this option,
vendors can define their own specific identifier values, such
as to convey a particular hardware or operating system
configuration or other identifying information.

Vendor-specified DHCP options—features that let administrators assign
separate options to clients with similar configuration requirements.
For example, if DHCP-aware clients for example we want to separate
different gateway and option for different set of people
(dev/test/hr/finance) in a org or devices for example web/database
servers or let's say in a embedded device etc and require a different
default gateway or DNS server than the rest of clients.
2014-07-14 11:39:20 +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
Eugene Yakubovich 4cc7a82c94 networkd: send hostname to dhcp server
Send hostname (option 12) in DISCOVER and REQUEST messages so the
DHCP server could use it to register with dynamic DNS and such.

To opt-out of this behaviour set SendHostname to false in [DHCP]
section of .network file

[tomegun: rebased, made sure a failing set_hostname is a noop and moved
          config from DHCPv4 to DHCP]
2014-07-01 22:02:25 +02:00
Tom Gundersen fb41e6d7c6 sd-dhcp-client: don't fail hard if UDP socket can not be bound
Even if we cannot renew the lease at T1, we will likely succeed at T2, so warn and ignore the failure.

This could happen if for whatever reason the received address is not yet configured, or it has
been lost.
2014-06-29 16:42:43 +02:00
Patrik Flykt 68ceb9df6a sd-dhcp-client/networkd: set lifetimes for IPv4 addresses
Note that /proc/sys/net/ipv4/ip_dynaddr needs to be non-zero.

[tomegun: hook up DHCP renew events to increase the lifetime when necessary]
2014-06-29 15:18:21 +02:00
Tom Gundersen 574cc92888 sd-dhcp-client: return NULL from _unref() like the other sd-* libraries
Let's keep this behavior consistent across our libraries.

In order to keep the refcounting working, a DONT_DESTROY macro similar
to the one in sd-bus was introduced.
2014-06-24 17:05:39 +02:00
Thomas Hindoe Paaboel Andersen f7926298e9 sd-dhcp-client: check return from dhcp_option_append 2014-06-18 23:21:00 +02:00
Andreas Henriksson 8186d9dda0 sd-dhcp-client: fix invalid free() in client_send_request()
static int client_send_request(...) in
./src/libsystemd-network/sd-dhcp-client.c tries to initialize
"request" by calling client_message_init(...), which has atleast
5 error cases where it can return without that happening.
This leads to the function finishing without "request" being initialized.
2014-06-13 18:57:33 +02:00
Camilo Aguilar 63a070415d sd-dhcp-client: allways request broadcast
On systems which cannot receive unicast packets until its IP stack has been configured
we need to request broadcast packets. We are currently not able to reliably detect when
this is necessary, so set it unconditionally for now.

This is set on all packets, but the DHCP server will only broadcast the packets that are
necessary, and unicast the rest.

For more information please refer to this thread in CoreOS: https://github.com/coreos/bugs/issues/12

[tomegun: rephrased commit message]
2014-06-03 10:55:46 +02:00
Cristian Rodríguez 590b6b9188 Use %m instead of strerror(errno) where appropiate 2014-05-25 11:18:28 +08:00