summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/dhcp-option.c
Commit message (Collapse)AuthorAgeFilesLines
* libsystemd-network: constify castsZbigniew Jędrzejewski-Szmek2022-05-081-2/+2
| | | | It is better to not drop the const-ness from the argument.
* strv: make iterator in STRV_FOREACH() declaread in the loopYu Watanabe2022-03-191-1/+0
| | | | This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
* rfc3046 implementationYegor Alexeyev2021-05-081-13/+93
|
* libsystemd-network: fix dhcp option buffer confusionZbigniew Jędrzejewski-Szmek2021-04-151-1/+2
| | | | | | We were writing to the wrong buffer with a wrong offset :( Bug present since the original introduction of the code in 04b28be1a306fd2ba454d3ee333d63df71aa3873.
* network: Use ordered_hashmap_ensure_put (#18233)Susant Sahani2021-01-171-3/+3
|
* dhcp: length of each user class field must be positiveYu Watanabe2021-01-131-4/+6
| | | | | This also fixes an memory leak when sd_dhcp_client_set_user_class() is called multiple times.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* tree-wide: define iterator inside of the macroZbigniew Jędrzejewski-Szmek2020-09-081-3/+2
|
* dhcp: remove struct sd_dhcp_raw_optionYu Watanabe2019-11-181-2/+42
| | | | sd_dhcp_raw_option and sd_dhcp_option are essentially equivalent.
* tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe2019-11-041-1/+0
|
* networkd: dhcp server Support Vendor specific 43Susant Sahani2019-10-311-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implementes https://tools.ietf.org/html/rfc2132 ``` [DHCPServer] SendRawOption=26:uint32:1400 SendRawOption=23:uint8:10 ``` Frame 448: 350 bytes on wire (2800 bits), 350 bytes captured (2800 bits) on interface 0 Linux cooked capture Internet Protocol Version 4, Src: 192.168.5.1, Dst: 192.168.5.11 User Datagram Protocol, Src Port: 67, Dst Port: 68 Dynamic Host Configuration Protocol (ACK) Message type: Boot Reply (2) Hardware type: Ethernet (0x01) Hardware address length: 6 Hops: 0 Transaction ID: 0x71f8de9d Seconds elapsed: 0 Bootp flags: 0x0000 (Unicast) Client IP address: 0.0.0.0 Your (client) IP address: 192.168.5.11 Next server IP address: 0.0.0.0 Relay agent IP address: 0.0.0.0 Client MAC address: 1e:04:f8:b8:2f:d4 (1e:04:f8:b8:2f:d4) Client hardware address padding: 00000000000000000000 Server host name not given Boot file name not given Magic cookie: DHCP Option: (53) DHCP Message Type (ACK) Length: 1 DHCP: ACK (5) Option: (51) IP Address Lease Time Length: 4 IP Address Lease Time: (3600s) 1 hour Option: (1) Subnet Mask (255.255.255.0) Length: 4 Subnet Mask: 255.255.255.0 Option: (3) Router Length: 4 Router: 192.168.5.1 Option: (6) Domain Name Server Length: 4 Domain Name Server: 192.168.5.1 Option: (42) Network Time Protocol Servers Length: 4 Network Time Protocol Server: 192.168.5.1 Option: (101) TCode Length: 13 TZ TCode: Europe/Berlin Option: (43) Vendor-Specific Information Length: 9 Value: 1701311a0431343030 Option: (54) DHCP Server Identifier (192.168.5.1) Length: 4 DHCP Server Identifier: 192.168.5.1 Option: (255) End Option End: 255 ```
* network: DHCP server Add support to transmit SIP serverSusant Sahani2019-09-201-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. DHCP server trasmit 2. Client parses and saves in leases Implements http://www.rfc-editor.org/rfc/rfc3361.txt ``` Frame 134: 348 bytes on wire (2784 bits), 348 bytes captured (2784 bits) on interface 0 Ethernet II, Src: 42:65:85:d6:4e:32 (42:65:85:d6:4e:32), Dst: 1e:04:f8:b8:2f:d4 (1e:04:f8:b8:2f:d4) Internet Protocol Version 4, Src: 192.168.5.1, Dst: 192.168.5.11 User Datagram Protocol, Src Port: 67, Dst Port: 68 Dynamic Host Configuration Protocol (ACK) Message type: Boot Reply (2) Hardware type: Ethernet (0x01) Hardware address length: 6 Hops: 0 Transaction ID: 0x7cc87cb4 Seconds elapsed: 0 Bootp flags: 0x0000 (Unicast) Client IP address: 0.0.0.0 Your (client) IP address: 192.168.5.11 Next server IP address: 0.0.0.0 Relay agent IP address: 0.0.0.0 Client MAC address: 1e:04:f8:b8:2f:d4 (1e:04:f8:b8:2f:d4) Client hardware address padding: 00000000000000000000 Server host name not given Boot file name not given Magic cookie: DHCP Option: (53) DHCP Message Type (ACK) Length: 1 DHCP: ACK (5) Option: (51) IP Address Lease Time Length: 4 IP Address Lease Time: (3600s) 1 hour Option: (1) Subnet Mask (255.255.255.0) Length: 4 Subnet Mask: 255.255.255.0 Option: (3) Router Length: 4 Router: 192.168.5.1 Option: (6) Domain Name Server Length: 4 Domain Name Server: 192.168.5.1 Option: (42) Network Time Protocol Servers Length: 4 Network Time Protocol Server: 192.168.1.1 Option: (120) SIP Servers <=====here Length: 9 SIP Server Encoding: IPv4 Address (1) SIP Server Address: 192.168.1.1 SIP Server Address: 192.168.5.2 Option: (101) TCode Length: 13 TZ TCode: Europe/Berlin Option: (54) DHCP Server Identifier (192.168.5.1) Length: 4 DHCP Server Identifier: 192.168.5.1 Option: (255) End Option End: 255 ``` ``` cat /run/systemd/netif/state  ✔  ⚡  3148  16:40:51 OPER_STATE=routable CARRIER_STATE=carrier ADDRESS_STATE=routable DNS=192.168.94.2 192.168.5.1 NTP=192.168.5.1 SIP=192.168.1.1 192.168.5.2 ``` aa
* libsystemd-network: make option_append() atomic and make the code a bit clearerZbigniew Jędrzejewski-Szmek2019-08-031-27/+32
| | | | | | | | | | | | | | Comparisons are done in the normal order (if (need > available), not if (available < need)), variables have reduced scope and are renamed for clarity. The only functional change is that if we return -ENAMETOOLONG, we do that without modifying the options[] array. I also added an explanatory comment. The use of one offset to point into three buffers is not obvious. Coverity (in CID#1402354) says that sname might be accessed at bad offset, but I cannot see this happening. We check for available space before writing anything.
* dhcp: use memdup_suffix0() instead of strndup()Yu Watanabe2019-06-191-1/+1
|
* util: split out memcmp()/memset() related calls into memory-util.[ch]Lennart Poettering2019-03-131-3/+3
| | | | Just some source rearranging.
* 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.
* networkd: add support to send DHCP user class option (#7499)Susant Sahani2018-05-071-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch add support to enables to send User Class option code 77 RFC 3004. This option MAY carry multiple User Classes. The format of this option is as follows: Code Len Value +-----+-----+--------------------- . . . --+ | 77 | N | User Class Data ('Len' octets) | +-----+-----+--------------------- . . . --+ where Value consists of one or more instances of User Class Data. Each instance of User Class Data is formatted as follows: UC_Len_i User_Class_Data_i +--------+------------------------ . . . --+ | L_i | Opaque-Data ('UC_Len_i' octets) | +--------+------------------------ . . . --+ UserClass= A DHCPv4 client can use UserClass option to identify the type or category of user or applications it represents. The information contained in this option is an string that represents the user class of which the client is a member. Each class sets an identifying string of information to be used by the DHCP service to classify clients. Takes a whitespace-separated list. UserClass= hello world how are you Closes: RFC: #5134
* 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 TAKE_PTR() macroLennart Poettering2018-03-221-4/+2
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* Replace free and reassignment with free_and_replaceDaniel Lockyer2017-11-241-3/+1
|
* 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.
* tree-wide: make ++/-- usage consistent WRT spacingVito Caputo2016-02-221-1/+1
| | | | | | Throughout the tree there's spurious use of spaces separating ++ and -- operators from their respective operands. Make ++ and -- operator consistent with the majority of existing uses; discard the spaces.
* libsystemd-network: don't abbreviate "callback" as "cb" needlesslyLennart Poettering2016-02-201-2/+2
| | | | | This isn't an excercise in creating APIs that are hard to understand, hence let's call a callback a callback.
* Merge pull request #2589 from keszybz/resolve-tool-2Lennart Poettering2016-02-131-6/+1
|\ | | | | Better support of OPENPGPKEY, CAA, TLSA packets and tests
| * Add memcpy_safeZbigniew Jędrzejewski-Szmek2016-02-111-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ISO/IEC 9899:1999 §7.21.1/2 says: Where an argument declared as size_t n specifies the length of the array for a function, n can have the value zero on a call to that function. Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4. In base64_append_width memcpy was called as memcpy(x, NULL, 0). GCC 4.9 started making use of this and assumes This worked fine under -O0, but does something strange under -O3. This patch fixes a bug in base64_append_width(), fixes a possible bug in journal_file_append_entry_internal(), and makes use of the new function to simplify the code in other places.
* | tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
|/ | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* dhcp: make DHCP_OPTION_* enum publicBeniamino Galvani2016-01-201-10/+10
| | | | | | | | 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.
* sd-dhcp: parse error message in DECLINE or NAKTom Gundersen2015-11-251-46/+63
| | | | | | 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.
* tree-wide: sort includesThomas Hindoe Paaboel Andersen2015-11-161-2/+2
| | | | Sort the includes accoding to the new coding style.
* network: s/user_data/userdata/Lennart Poettering2015-08-261-6/+6
| | | | | Everywhere else we call the generic user data pointer just "userdata", rather than "user_data". Let's do this here, too.
* sd-dhcp: option_append - support falling back to 'sname' and 'file'Tom Gundersen2014-05-211-7/+81
|
* sd-dhcp: make sure we can not fill options so much that there is no space ↵Tom Gundersen2014-05-211-0/+4
| | | | for END
* sd-dhcp: refactor parse_optionsTom Gundersen2014-05-201-41/+41
| | | | | Similar to the previous patch, exchange a length and a pointer with only one offset variable. Also fix the type of the options to be uint8_t[], rather than uint8_t*.
* sd-dhcp: refactor dhcp_option_appendTom Gundersen2014-05-201-19/+14
| | | | | | | | | | | | | Store a pointer to the options in the DHCPMessage struct, and pass this together with an offset around, rather than a uint8_t**. This avoids us having to (re)compute the pointer; and changes dhcp_option_append from adjusting both the pointer to the next option and the remaining size of the options, to just adjusting the current offset. This makes the code a bit simpler to follow IMHO, but there should be no functional change.
* sd-dhcp-client: move magic cookie into DHCPMessage structTom Gundersen2014-04-061-8/+4
| | | | | | | | Also move the checking of it to the main message handler, rather than the options parser. Fix a bug, so we now drop the packet if any of the magic bytes don't match. Before we used to only drop the packet if they were all wrong.
* sd-network: add new libraryTom Gundersen2014-02-281-0/+184
This is similar to sd-login, but exposes the state of networkd rather than logind. Include it in libsystemd-dhcp and rename it to libsystemd-network.