summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/dhcp-network.c
Commit message (Collapse)AuthorAgeFilesLines
* optionally set socket priority on DHCPv4 raw socketchris2023-01-121-4/+14
|
* tree-wide: use -EBADF moreYu Watanabe2022-12-211-2/+2
|
* dhcp: make dhcp_network_bind_raw_socket() take struct hw_addr_dataYu Watanabe2022-08-061-57/+71
|
* dhcp: shorten BPF code a bitYu Watanabe2021-10-211-10/+6
| | | | | | - replace `A = k` and `X = A` with `X = k`, - replace `A ^= X` and `A == 0` with `A == X`. - use UINT32_MAX when accept a packet
* dhcp: rebreak function argumentsYu Watanabe2021-10-211-8/+23
|
* dhcp: fix assertionsYu Watanabe2021-10-211-2/+5
|
* dhcp: shorten code a bitYu Watanabe2021-10-211-9/+3
|
* dhcp: Implemented BindToInterface= configuration optionYegor Alexeyev2021-04-141-6/+9
|
* libsystemd-network: add comment explaining unusual memory accessZbigniew Jędrzejewski-Szmek2020-11-101-1/+1
| | | | | Inspired by coverity CID#1435984. I'm confused by the union definion every time I look at it... Let's at least add a comment to help future readers.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* dhcp4: fix DHCP on InfiniBand interfacesTimo Rothenpieler2020-10-281-15/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | With these patches applied, networkd is successfully able to get an address from a DHCP server on an IPoIB interface. 1) Makes networkd pass the actual interface type to the dhcp client, instead of hardcoding it to Ethernet. 2) Fixes some issues in handling the larger (20 Byte) IB MAC addresses in the dhcp code. 3) Add a new field to networkds Link struct, which holds the interface broadcast address. 3.1) Modify the DHCP code to also expect the broadcast address as parameter. On an Ethernet-Interface the Broadcast address never changes and is always all 6 bytes set to 0xFF. On an IB one however it is not neccesarily always the same, thus fetching the actual address from the interface is neccesary. 4) Only the last 8 bytes of an IB MAC are stable, so when using an IB MAC to generate a client ID, only pass those 8 bytes.
* tree-wide: drop socket.h when socket-util.h is includedYu Watanabe2019-11-041-1/+0
|
* dhcp4: make IPServiceType configurableSiddharth Chandrasekara2019-09-261-2/+6
| | | | | | | | | | 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>
* tree-wide: port various users over to socket_bind_to_ifindex()Lennart Poettering2019-03-181-6/+2
|
* dhcp: ignore padding of 'chaddr' in DHCP server responseThomas Haller2019-02-151-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* tree-wide: use setsockopt_int() moreYu Watanabe2018-10-191-3/+3
|
* tree-wide: introduce setsockopt_int() helper and make use of it everywhereLennart Poettering2018-10-181-10/+10
| | | | | | As suggested by @heftig: https://github.com/systemd/systemd/commit/6d5e65f6454212cd400d0ebda34978a9f20cc26a#commitcomment-30938667
* tree-wide: add a single version of "static const int one = 1"Lennart Poettering2018-10-151-7/+7
| | | | | | | | | | All over the place we define local variables for the various sockopts that take a bool-like "int" value. Sometimes they are const, sometimes static, sometimes both, sometimes neither. Let's clean this up, introduce a common const variable "const_int_one" (as well as one matching "const_int_zero") and use it everywhere, all acorss the codebase.
* dhcp: fix assertion starting DHCP client without MAC address (#10054)Thomas Haller2018-09-111-2/+0
| | | | | | | | | | | | | | | | | | | An assertion in dhcp_network_bind_raw_socket() is triggered when starting an sd_dhcp_client without setting a MAC address first. - sd_dhcp_client_start() - client_start() - client_start_delayed() - dhcp_network_bind_raw_socket() In that case, the arp-type and MAC address is still unset. Note that dhcp_network_bind_raw_socket() already checks for a valid arp-type and MAC address below, so we should just gracefully return -EINVAL. Maybe sd_dhcp_client_start() should fail earlier when starting without MAC address. But the failure here will be correctly propagated and the start aborted. Fixes: 76253e73f9c9c24fec755e485516f3b55d0707b4
* tree-wide: use proper unicode © instead of (C) where we canLennart Poettering2018-06-141-1/+1
| | | | | | Let's use a proper unicode copyright symbol where we can, it's prettier. This important patch is very important.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | 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.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | 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.
* macro: introduce new TAKE_FD() macroLennart Poettering2018-03-221-8/+2
| | | | | | | This is similar to TAKE_PTR() but operates on file descriptors, and thus assigns -1 to the fd parameter after returning it. Removes 60 lines from our codebase. Pretty good too I think.
* libsystemd-network: fix unaligned loads (issue #7654)Shawn Landden2017-12-181-2/+3
| | | | | | should fix https://github.com/systemd/systemd/issues/7654 Also fix up mistaken endianness swap. BPF is native endianness.
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* dhcp-network: adjust sockaddr length for addresses longer than 8 bytes (#6527)bengal2017-08-081-7/+9
| | | | | | An infiniband hardware address is 20 bytes, but sockaddr_ll.sll_addr is only 8 bytes. Explicitly ensure that sockaddr_union has enough space for infiniband addresses, even if they run over sockaddr_ll and add a macro to compute the proper size to pass to kernel.
* dhcp: bind udp sockets to interfaces (#4822)27o2016-12-071-1/+13
|
* networkd: support setting dhcp client listen port (#4631)Susant Sahani2016-11-101-4/+6
| | | | | | Allow setting custom port for the DHCP client to listen on in networkd. [DHCP] ListenPort=6677
* tree-wide: htonl() is weird, let's use htobe32() instead (#3538)Lennart Poettering2016-06-151-2/+2
| | | Super-important change, yeah!
* util-lib: split out fd-related operations into fd-util.[ch]Lennart Poettering2015-10-251-6/+6
| | | | | There are more than enough to deserve their own .c file, hence move them over.
* remove unused includesThomas Hindoe Paaboel Andersen2015-02-231-2/+0
| | | | | | 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.
* treewide: correct typos and use consistent "MAC" spellingTorstein Husebø2015-02-091-1/+1
|
* sd-dhcp-client: support non-Ethernet hardware addressesDan Williams2014-10-111-9/+45
| | | | | | | 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.
* sd-network: make socket filter programs static const where possibleLennart Poettering2014-07-291-51/+52
| | | | | (also, fix some whitespace/indentation issues, and avoid "index" as identifier in order to not clash against libc's "index()" call)
* dhcp-network: enable IP_FREEBIND for UDP socketsTom Gundersen2014-07-281-7/+9
| | | | | This allows the sockets to be bound to a specific address before it is configured, also enable SO_REUSEADDR to allow multiple DHCP clients to run at the same time.
* dhcp-network: make clear that we are ANDing Fragment offset field with maskMichal Sekletar2014-07-071-1/+1
| | | | | | Reading BPF assembly written as C macros is inherently difficult. Don't make it harder than necessary and provide clearer explanation in the comment.
* dhcp-network: ignore IP packets with More Fragments (MF) flag setMichal Sekletar2014-07-071-0/+4
| | | | | | | | | We already ignore IP fragments, because we expect that Fragment offset (FO) field is not set. However first fragment in a fragmented IP flow will have all zeroes in FO field. We should ignore such packet as well, thus we need to look at MF flag in the IP header. Checking MF flag will filter out all except last packet in fragmented flows. Last one will be ruled out by next check for value of FO.
* dhcp-network: add check for DHCP.chaddrMichal Sekletar2014-07-071-2/+13
| | | | | | 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.
* dhcp-network: don't bother with IP fragmentsMichal Sekletar2014-06-221-0/+4
|
* sd-dhcp-server: fix broadcast of DHCP packetsTom Gundersen2014-06-211-0/+4
| | | | | The destination IP address should be INADDR_BROADCAST, but was accidentally left as INADDR_ANY.
* dhcp-network: remove TODOMichal Sekletar2014-06-181-1/+0
| | | | | | There is no need to explicitly check version of L3 protocol in the ethernet header because we bind socket with .sll_protocol set to ETH_P_IP, thus we only receive IPv4 packets on the socket.
* sd-dhcp-server: add basic functionality for creating/destroying server instanceTom Gundersen2014-06-131-0/+1
|
* dhcp-network: allow UDP socket to listen on any addressTom Gundersen2014-06-131-2/+13
| | | | | | For this to work nicely we need to use REUSEADDR so that more than one socket can be open at the same time. Also, we request the ifindex to be appended to incoming messages, so we know whence it came.
* sd-dhcp: network - don't leak sockets on failureTom Gundersen2014-05-061-26/+41
| | | | Also some general cleanups
* sd-dhcp: network - set TOS on outgoing packetsTom Gundersen2014-05-061-1/+4
| | | | | This should improve performance on busy wireless networks and the like. Inspired by a similar change in dnsmasq.
* dhcp-network: don't pass ifindex to bind_udp_socketTom Gundersen2014-05-061-1/+1
| | | | | UDP sockets can anyway not be bound to specific netdev's. The packages would have to be filtered when received instead.
* sd-dhcp-client: improve BPFTom Gundersen2014-04-061-2/+19
| | | | | | Try a bit harder to make the kernel drop packets not for us. This should reduce the number of wakeups from n^2 to n in the number of dhcp clients, which admittedly only makes a differenc in very extreme cases.
* sd-dhcp-client: eagerly drop too small packetsTom Gundersen2014-04-061-2/+5
| | | | | | If they are too small to fit the IP+UDP+DHCP headers they can be of no use, so don't waste resources parsing them. This is at the cost of losing some verbosity in the logging.
* sd-dhcp-client: use BPF on raw socketTom Gundersen2014-04-021-0/+18
| | | | | | | | | | | | Filter out everything except UDP packets destined for the DHCP client port, this should avoid the vast majority of spurious wakeups. Filter based on [0], with permission. Possible improvemnts: also check for the DHCP magic cookie to drop invalid packets. Check for our xid to filter out packets destined for other clients. [0]: <https://github.com/ambrop72/badvpn/blob/master/dhcpclient/BDHCPClient.c#L57>
* sd-dhcp-client: --omg-optimizedTom Gundersen2014-04-011-2/+1
| | | | | | | | | | | | | | Passing the protocol to socket() is redundant as it will be specified again in bind(). Dropping the redundancy reduces the cost of bind() from ~30ms to ~0ms. For details see [0]. networkd in a container (i.e., with next to no network latency) can now negotiate a DHCP lease in 0.7 - 5 ms. Thanks to Kay for help with debugging and to Daniel Borkmann for the pointer to fix the problem. [0]: <https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=902fefb82ef72a50c78cb4a20cc954b037a98d1c>