summaryrefslogtreecommitdiff
path: root/src/dhcp/nm-dhcp-dhclient-utils.c
Commit message (Collapse)AuthorAgeFilesLines
* all: move "src/" directory to "src/core/"Thomas Haller2021-02-041-714/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently "src/" mostly contains the source code of the daemon. I say mostly, because that is not true, there are also the device, settings, wwan, ppp plugins, the initrd generator, the pppd and dhcp helper, and probably more. Also we have source code under libnm-core/, libnm/, clients/, and shared/ directories. That is all confusing. We should have one "src" directory, that contains subdirectories. Those subdirectories should contain individual parts (libraries or applications), that possibly have dependencies on other subdirectories. There should be a flat hierarchy of directories under src/, which contains individual modules. As the name "src/" is already taken, that prevents any sensible restructuring of the code. As a first step, move "src/" to "src/core/". This gives space to reorganize the code better by moving individual components into "src/". For inspiration, look at systemd's "src/" directory. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/743
* all: update deprecated SPDX license identifiersThomas Haller2021-01-051-1/+1
| | | | | | | | | | | | | | | | These SPDX license identifiers are deprecated ([1]). Update them. [1] https://spdx.org/licenses/ sed \ -e '1 s%^/\* SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+ \*/$%/* SPDX-License-Identifier: \1-or-later */%' \ -e '1,2 s%^\(--\|#\|//\) SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+$%\1 SPDX-License-Identifier: \2-or-later%' \ -i \ $(git grep -l SPDX-License-Identifier -- \ ':(exclude)shared/c-*/' \ ':(exclude)shared/n-*/' \ ':(exclude)shared/systemd/src' \ ':(exclude)src/systemd/src')
* all: explicit include <linux/if_{ether,infiniband,vlan}.h> as neededThomas Haller2020-12-221-0/+1
| | | | | | | | | | | | | | Currently libnm headers include <linux/if_{ether,infiniband,vlan}.h>. These are public headers, that means we drag in the linux header to all users of <NetworkManager.h>. Often the linux headers work badly together with certain headers from libc. Depending on the libc version, you have to order linux headers in the right order with respect to libc headers. We should do better about libnm headers. As a first step, assume that the linux headers don't get included by libnm, and explicitly include them where they are needed.
* all: unify comment style for SPDX-License-Identifier tagThomas Haller2020-09-291-1/+1
| | | | | | | | | | Our coding style recommends C style comments (/* */) instead of C++ (//). Also, systemd (which we partly fork) uses C style comments for the SPDX-License-Identifier. Unify the style. $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
* format: replace tabs for indentation in code commentsac/clang-formatThomas Haller2020-09-281-19/+19
| | | | | | | | | | | | sed -i \ -e 's/^'$'\t'' \*/ */g' \ -e 's/^'$'\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t\t\t'' \*/ */g' \ $(git ls-files -- '*.[hc]')
* all: reformat all with new clang-format styleAntonio Cardace2020-09-281-612/+591
| | | | | | | | | | | | Run: ./contrib/scripts/nm-code-format.sh -i ./contrib/scripts/nm-code-format.sh -i Yes, it needs to run twice because the first run doesn't yet produce the final result. Signed-off-by: Antonio Cardace <acardace@redhat.com>
* core: honor the ipv4.dhcp-reject-servers propertyBeniamino Galvani2020-08-261-0/+14
|
* all: fix typo in man pagesSayed Shah2020-07-031-1/+1
| | | | | | | | There should be a comma after 'Otherwise' and 'Currently'. https://bugzilla.redhat.com/show_bug.cgi?id=1852452 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/560
* dhcp: rename mudurl to mud_urlThomas Haller2020-04-241-12/+12
|
* dhcp: add support for MUD URL (RFC 8520)Eliot Lear2020-04-241-2/+24
| | | | | | | | | | | [thaller@redhat.com: rewritten commit message] https://tools.ietf.org/html/rfc8520 https://blog.apnic.net/2019/05/14/protecting-the-internet-of-things-with-mud/ https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/402 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/463
* all: use nm_clear_pointer() instead of g_clear_pointer()Thomas Haller2020-03-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | g_clear_pointer() would always cast the destroy notify function pointer to GDestroyNotify. That means, it lost some type safety, like GPtrArray *ptr_arr = ... g_clear_pointer (&ptr_arr, g_array_unref); Since glib 2.58 ([1]), g_clear_pointer() is also more type safe. But this is not used by NetworkManager, because we don't set GLIB_VERSION_MIN_REQUIRED to 2.58. [1] https://gitlab.gnome.org/GNOME/glib/-/commit/f9a9902aac826ab4aecc25f6eb533a418a4fa559 We have nm_clear_pointer() to avoid this issue for a long time (pre 1.12.0). Possibly we should redefine in our source tree g_clear_pointer() as nm_clear_pointer(). However, I don't like to patch glib functions with our own variant. Arguably, we do patch g_clear_error() in such a manner. But there the point is to make the function inlinable. Also, nm_clear_pointer() returns a boolean that indicates whether anything was cleared. That is sometimes useful. I think we should just consistently use nm_clear_pointer() instead, which does always the preferable thing. Replace: sed 's/\<g_clear_pointer *(\([^;]*\), *\([a-z_A-Z0-9]\+\) *)/nm_clear_pointer (\1, \2)/g' $(git grep -l g_clear_pointer) -i
* dhcp: support FQDN flags in the dhclient backendBeniamino Galvani2019-11-281-21/+36
| | | | Make the dhclient backend honor the ipv4.dhcp-fqdn-flags setting.
* dhcp: include conditionals from existing dhclient configurationBeniamino Galvani2019-10-101-11/+32
| | | | | | | | | | Since commit 159ff23268b1 ('dhcp/dhclient-utils: skip over dhclient.conf blocks') we skip blocks enclosed in lines containing '{' and '}' because NM should ignore 'lease', 'alias' and other declarations. However, conditional statements seem useful and should not be skipped. https://bugzilla.redhat.com/show_bug.cgi?id=1758550
* all: SPDX header conversionLubomir Rintel2019-09-101-14/+1
| | | | | $ find * -type f |xargs perl contrib/scripts/spdx.pl $ git rm contrib/scripts/spdx.pl
* dhcp: prefer nm_assert() to g_assert*()Francesco Giudici2019-09-051-1/+1
|
* all: drop emacs file variables from source filesThomas Haller2019-06-111-1/+0
| | | | | | | | | | | | | | | | | | | | | | We no longer add these. If you use Emacs, configure it yourself. Also, due to our "smart-tab" usage the editor anyway does a subpar job handling our tabs. However, on the upside every user can choose whatever tab-width he/she prefers. If "smart-tabs" are used properly (like we do), every tab-width will work. No manual changes, just ran commands: F=($(git grep -l -e '-\*-')) sed '1 { /\/\* *-\*- *[mM]ode.*\*\/$/d }' -i "${F[@]}" sed '1,4 { /^\(#\|--\|dnl\) *-\*- [mM]ode/d }' -i "${F[@]}" Check remaining lines with: git grep -e '-\*-' The ultimate purpose of this is to cleanup our files and eventually use SPDX license identifiers. For that, first get rid of the boilerplate lines.
* shared: move most of "shared/nm-utils" to "shared/nm-glib-aux"Thomas Haller2019-04-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From the files under "shared/nm-utils" we build an internal library that provides glib-based helper utilities. Move the files of that basic library to a new subdirectory "shared/nm-glib-aux" and rename the helper library "libnm-core-base.la" to "libnm-glib-aux.la". Reasons: - the name "utils" is overused in our code-base. Everything's an "utils". Give this thing a more distinct name. - there were additional files under "shared/nm-utils", which are not part of this internal library "libnm-utils-base.la". All the files that are part of this library should be together in the same directory, but files that are not, should not be there. - the new name should better convey what this library is and what is isn't: it's a set of utilities and helper functions that extend glib with funcitonality that we commonly need. There are still some files left under "shared/nm-utils". They have less a unifying propose to be in their own directory, so I leave them there for now. But at least they are separate from "shared/nm-glib-aux", which has a very clear purpose. (cherry picked from commit 80db06f768e47541eae7d66ef48fbe47bf1a69ce)
* dhcp: cleanup nm_dhcp_dhclient_create_config()Thomas Haller2019-04-101-24/+27
|
* dhcp: cleanup nm_dhcp_dhclient_read_duid()Thomas Haller2019-04-101-18/+22
|
* dhcp: cleanup grab_request_options()Thomas Haller2019-04-101-17/+28
|
* dhcp: cleanup nm_dhcp_dhclient_save_duid()Thomas Haller2019-04-101-23/+20
|
* all: drop unnecessary includes of <errno.h> and <string.h>Thomas Haller2019-02-121-1/+0
| | | | | "nm-macros-interal.h" already includes <errno.h> and <string.h>. No need to include it everywhere else too.
* all: don't use "static inline" in source filesThomas Haller2019-02-061-1/+1
| | | | | | | | For static functions inside a module, the compiler determines on its own whether to inline the function. Also, "inline" was used at some places that don't immediatly look like candidates for inlining. It was most likely a copy&paste error.
* dhcp: don't request DHCP6 client-id option with internal clientThomas Haller2018-12-191-0/+2
| | | | | | | | | | | | | | | | | sd_dhcp6_client_set_request_option() only accepts a white-listed set of options. Unexpected options are rejected with -EINVAL. Currently supported are only: - SD_DHCP6_OPTION_DNS_SERVERS - SD_DHCP6_OPTION_DOMAIN_LIST - SD_DHCP6_OPTION_SNTP_SERVERS - SD_DHCP6_OPTION_NTP_SERVER - SD_DHCP6_OPTION_RAPID_COMMIT As such, SD_DHCP6_OPTION_CLIENTID is not accepted and requesting it was silently ignored. Fixes: d2dd3b2c90221fdfa40ca81a9fcffe6a777d95de
* dhcp: minor refactoring return paths in NMDhcpDhclient.get_duid()Thomas Haller2018-11-131-0/+1
|
* dhcp: refactor nm_dhcp_dhclient_save_duid() to accept original DUIDThomas Haller2018-11-131-1/+10
| | | | | | | | | There should be lower layers that are concerned with writing and reading dhclient configuration files. It's wrong to have a nm_dhcp_dhclient_save_duid() function which requires the caller to pre-escape the string to write. The caller shouldn't be concerned with the file format, that's why the function is used in the first place.
* dhcp: drop unused nm_dhcp_dhclient_get_client_id_from_config_file()Thomas Haller2018-11-131-23/+0
| | | | | | | | Drop unused function. Aside from that, dhclient configuration files support a very complex syntax. The parser was very naive and insufficient in parsing such files. It's good we can just drop it.
* build: avoid header conflict for <linux/if.h> and <net/if.h> with ↵Thomas Haller2018-11-121-0/+1
| | | | | | | | | | | | | | | | | | | | | "nm-platform.h" In the past, the headers "linux/if.h" and "net/if.h" were incompatible. That means, we can either include one or the other, but not both. This is fixed in the meantime, however the issue still exists when building against older kernel/glibc. That means, including one of these headers from a header file is problematic. In particular if it's a header like "nm-platform.h", which itself is dragged in by many other headers. Avoid that by not including these headers from "platform.h", but instead from the source files where needed (or possibly from less popular header files). Currently there is no problem. However, this allows an unknowing user to include <net/if.h> at the same time with "nm-platform.h", which is easy to get wrong.
* dhcp: save root-path in the state fileLubomir Rintel2018-09-181-0/+1
| | | | | | | | | On networked boot we need to somehow communicate this to the early boot machinery. Sadly, no DBus there and we're running in configure-and-quit mode. Abusing the state file for this sounds almost reasonable and is reasonably straightforward thing to do.
* dhcp/trivial: add fixme comments to nm_dhcp_dhclient_unescape_duid()Thomas Haller2018-08-221-0/+7
|
* dhcp/dhclient-utils: skip over dhclient.conf blocksLubomir Rintel2018-07-231-8/+15
| | | | | | | | | | | | | | Extend the lame-ass dhclient.conf parser to ignore the blocks we can't do anything useful about: alias{}, pseudo{} and even lease{}. Note that there's still a lot of cases we can't handle without a full-fledged dhclient.conf parser -- notably the files that don't use line breaks to separate the statements. That is probably okay -- the whole thing is probably mostly useless and we shall ever bother only about cases that actually cause trouble. https://github.com/NetworkManager/NetworkManager/pull/153
* dhclient: always update the DUID in the lease fileFrancesco Giudici2018-06-071-12/+20
| | | | | | | We will soon introduce a property to set a custom DUID and we want to enforce that the provided value is used. Note that this commit does not cause any change in behavior in current code.
* dhclient: fix updating the DUID in multiline lease filesFrancesco Giudici2018-06-071-2/+7
| | | | | | | | | | | | | | | | | | The nm_dhcp_dhclient_save_duid() function will save a newly generated DUID to a previously existing lease file. The function will only save the DUID if not present in the lease file: in this case, should preserve the other contents of the lease file. A dhclient lease file for IPv6 generated by NetworkManager will always add the DUID as a first item: so in practice finding a lease file without DUID will never happen. This has hidden a bug in the function: the loop that is meant to append the non-duid lines in the lease file would strip all the newlines, mangling the lease file. Fix the function allowing to keep the original lines and add a test to check this functionality is kept well functioning. FIXME: the new test and the other duid ones already there store the file in the current working-directory. Tests should not do that.
* all: remove consecutive empty linesBeniamino Galvani2018-04-301-1/+0
| | | | | | | Normalize coding style by removing consecutive empty lines from C sources and headers. https://github.com/NetworkManager/NetworkManager/pull/108
* dhcp: remove unused nm_dhcp_dhclient_read_lease_ip_configs() functionThomas Haller2018-03-201-256/+0
|
* dhclient: write client-id with backslash and quotes as hexBeniamino Galvani2018-03-151-1/+1
|
* dhcp: dhclient: set type 0 for printable client IDsBeniamino Galvani2018-03-151-8/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | The documentation for the ipv4.dhcp-client-id property says: If the property is not a hex string it is considered as a non-hardware-address client ID and the 'type' field is set to 0. However, currently we set the client-id without the leading zero byte in the dhclient configuration and thus dhclient sends the first string character as type and the remainder as client-id content. Looking through git history, the dhclient plugin has always behaved this way even if the intent was clearly that string client-id had to be zero padded (this is evident by looking at nm_dhcp_utils_client_id_string_to_bytes()). The internal plugin instead sends the correct client-id with zero type. Change the dhclient plugin to honor the documented behavior and add the leading zero byte when the client-id is a string. This commit introduces a change in behavior for users that have dhcp=dhclient and have a plain string (not hexadecimal) set in ipv4.dhcp-client-id, as NM will send a different client-id possibly changing the IP address returned by the server. https://bugzilla.gnome.org/show_bug.cgi?id=793957
* dhcp: refactor type of NMDhcpClient duid to be GBytesThomas Haller2018-02-151-8/+15
| | | | | GBytes is immutable. It's better suited to contain the duid parameter then a GByteArray.
* dhcp: fix memleak parsing dhclient file with multiple dhcp-client-identifier ↵Thomas Haller2018-02-151-0/+3
| | | | lines
* dhcp: cleanup handling of ipv4.dhcp-client-id and avoid assertion failureThomas Haller2018-01-041-3/+5
| | | | | | | | | | | | | The internal client asserts that the length of the client ID is not more than MAX_CLIENT_ID_LEN. Avoid that assert by truncating the string. Also add new nm_dhcp_client_set_client_id_*() setters, that either set the ID based on a string (in our common dhclient specific format), or based on the binary data (as obtained from systemd client). Also, add checks and assertions that the client ID which is set via nm_dhcp_client_set_client_id() is always of length of at least 2 (as required by rfc2132, section-9.14).
* core,clients: use our own string hashing function nm_str_hash()Thomas Haller2017-10-181-1/+1
| | | | | | | | | | | | | | | | | | | | Replace the usage of g_str_hash() with our own nm_str_hash(). GLib's g_str_hash() uses djb2 hashing function, just like we do at the moment. The only difference is, that we use a diffrent seed value. Note, that we initialize the hash seed with random data (by calling getrandom() or reading /dev/urandom). That is a change compared to before. This change of the hashing function and accessing the random pool might be undesired for libnm/libnm-core. Hence, the change is not done there as it possibly changes behavior for public API. Maybe we should do that later though. At this point, there isn't much of a change. This patch becomes interesting, if we decide to use a different hashing algorithm.
* core: rework tracking of gateway/default-route in ip-configThomas Haller2017-10-101-1/+15
| | | | | | | | | | | | | | | | | | | | | | Instead of having 3 properties @gateway, @never_default and @has_gateway on NMIP4Config/NMIP6Config that determine the default-route, track the default-route as a regular route. The gateway setting is the configuration knob for the default-route. Since an NMIP4Config/NMIP6Config instance only has one gateway property, it cannot track more then one default-routes (see related bug rh#1445417). Especially with policy routing, it might be interesting to configure a default-route in multiple tables. Also, later it might be interesting to allow adding default-routes as regular static routes in a connection, so that the user can configure additional route parameters for the default-route or add default-routes in multiple tables. With this patch, default-routes now have a rt_source property according to their origin. Also, the previous commits of this branch broke handling of the default-route :) . That should be working now again.
* dhcp: dhclient: remove the --timeout argument from the command lineFrancesco Giudici2017-09-151-1/+23
| | | | | | | | | | | | | | | | | | the --timeout command line option is a custom feature added in some linux distributions (fedora). Passing that command line argument will make dhclient fail if the binary does not support it, preventing activation of dhcp based connections. Worse, the option has just been recently changed from "-timeout", so that we are currently incompatibile with Centos, RedHat and older versions of Fedora too. Leverage the "timeout" option in dhclient config file: it will produce the expected behavior and will be universally supported. Fixes test: dhcp-timeout Fixes: fa46736013fa1e3df1508b1f67b495ce45daf94a https://bugzilla.redhat.com/show_bug.cgi?id=1491243
* core/dhcp: use addr-family parameter for instead of booleanThomas Haller2017-09-111-12/+14
| | | | | | | | | | | | | In many cases we want to treat IPv4 and IPv6 generically. That looks nicer if we distingish by an @addr_family integer, instead of a boolean. Replace the @is_ipv6 boolean with an @addr_family paramter. The @is_ipv6 boolean is inconsistent with other places where we use @is_ipv4 to indicate the opposite. Eventually, we should use @addr_family everywhere. Also, at the call site it's not immediately clear what TRUE/FALSE means, here AF_INET/AF_INET6 is better.
* all: use _nm_utils_ip4_*() utils functionsThomas Haller2017-09-051-1/+1
|
* dhcp/dhclient: improve "interface" statement parsingJonathan Kang2017-07-101-1/+2
| | | | | | | | | | | | | | | | | | | | | In commit d405cfd9089f9552969e6a3e1a1c4550fc3c1695, parsing "interface" statement is introduced. But it leads to uncommplete parsing of the "request" entry, if one of the lines in "request" entry is prefixed with word "interface". For example, the default configuration of openSUSE distribution: request subnet-mask, broadcast-address, routers, rfc3442-classless-static-routes, interface-mtu, host-name, domain-name, domain-search, domain-name-servers, nis-domain, nis-servers, nds-context, nds-servers, nds-tree-name, netbios-name-servers, netbios-dd-server, netbios-node-type, netbios-scope, ntp-servers; Fixes: d405cfd9089f9552969e6a3e1a1c4550fc3c1695 https://bugzilla.opensuse.org/show_bug.cgi?id=1047004 https://mail.gnome.org/archives/networkmanager-list/2017-July/msg00015.html
* core: pass NMDedupMultiIndex instance to NMIP4Config and otherThomas Haller2017-07-051-2/+6
| | | | | | | | | | | | | | NMIP4Config, NMIP6Config, and NMPlatform shall share one NMDedupMultiIndex instance. For that, pass an NMDedupMultiIndex instance to NMPlatform and NMNetns. NMNetns than passes it on to NMDevice, NMDhcpClient, NMIP4Config and NMIP6Config. So currently NMNetns is the access point to the shared NMDedupMultiIndex instance, and it gets it from it's NMPlatform instance. The NMDedupMultiIndex instance is really a singleton, we don't want multiple instances of it. However, for testing, instead of adding a singleton instance, pass the instance explicitly around.
* dhcp: allow FQDNs in ipv4.dhcp-hostnameBeniamino Galvani2017-05-041-12/+2
| | | | | | | | | | | | | | | If users wrote a FQDN in ipv4.dhcp-hostname presumably it's because they really want to send the full value, not only the host part, so let's send it as-is. This obviously is a change in behavior, but only for users that have a FQDN in ipv4.dhcp-hostname, where it's not clear if they really want the domain to be stripped. When the property is unset, we keep sending only the host part of the system hostname to maintain backwards compatibility. This commit aligns NM behavior to initscripts.
* dhcp: simplify how hostname and FQDN are passed down to backendsBeniamino Galvani2017-05-041-20/+22
| | | | | Since they are mutually exclusive, pass a string and a boolean to indicate whether we want to use the hostname or the FQDN option.
* dhcp: dhclient: Allow unqualified fqdn.fqdn for DHCPv6Jonas Jonsson2017-05-031-4/+1
| | | | | | | | | | | | | | ISC dhclient will always append the zero label to the fqdn.fqdn option. The dhcp-options(5) suggest that it's perfectly fine to have an unqualified name. "... This can be a fully-qualified domain name, or a single label. ..." The ISC dhcpd will ignore this trailing zero label and do DDNS regardless. https://bugzilla.gnome.org/show_bug.cgi?id=761467