summaryrefslogtreecommitdiff
path: root/src/dhcp/nm-dhcp-dhclient.c
Commit message (Collapse)AuthorAgeFilesLines
* 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: dhclient: use the shared function to retrieve the lease file pathFrancesco Giudici2019-09-051-24/+2
| | | | ... but leave in place the custom checks dependant on the dhclient plugin
* dhcp: prefer nm_assert() to g_assert*()Francesco Giudici2019-09-051-1/+1
|
* dhcp: make "systemd" DHCP plugin configurableThomas Haller2019-08-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | We have the "internal" DHCP plugin. That's our preferred plugin, and eventually we may drop all other plugins. Currently, the "internal" plugin is based on code from systemd-networkd and implemented in "src/dhcp/nm-dhcp-systemd.c". As this code is forked we eventually want to switch to nettools' n-dhcp4 library (for IPv4). For that reason we already have "src/dhcp/nm-dhcp-nettools.c". Note that "nettools" can be configured as a DHCP plugin, but this configuration is only experimental and for testing. There is never supposed to be a "nettools" plugin, but eventually the "internal" plugin will switch implementation. We don't want to replace systemd-based implementation right away. Not until we are sure that nettools works well. For that reason we keep them both in parallel for a while. This commit makes "systemd" DHCP plugin explicitly configurable in NetworkManager.conf. Like "nettools" this is an undocumented option, only for testing. If you choose "internal" (the default), you get one of the implementations (currently the "systemd" one). But by selecting "systemd" or "nettools" explicitly, you can select the exact plugin.
* 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.
* dhcp: store dhclient's pid file in "/var/run/NetworkManager" instead of ↵Thomas Haller2019-05-201-1/+1
| | | | | | | | | | | | "/var/run" The pid-file is private to NetworkManager. It should reside in NetworkManager's run directory instead of "/var/run". I don't think that changing this location can break existing uses. Why would somebody outside of NetworkManager care about this file? https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/157
* 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)
* all: replace g_strerror() calls with nm_strerror_native()Thomas Haller2019-02-121-2/+2
|
* all: cache errno in local variable before using itThomas Haller2019-02-121-4/+6
|
* all: drop unnecessary includes of <errno.h> and <string.h>Thomas Haller2019-02-121-2/+0
| | | | | "nm-macros-interal.h" already includes <errno.h> and <string.h>. No need to include it everywhere else too.
* dhcp/trivial: wrap lines in calling client_start()Thomas Haller2018-11-131-2/+12
| | | | | | | | | | | A possible issue is that client_start() has about 136 arguments. It doesn't get simpler by saving lines of code and writing them all in the same line. Wrap the lines. While at it, use "FALSE" for "enforce_duid" argument, instead of "0". It's a boolean.
* dhcp: minor refactoring return paths in NMDhcpDhclient.get_duid()Thomas Haller2018-11-131-13/+11
|
* dhcp: use cleanup attribute for get_dhclient_leasefile()Thomas Haller2018-11-131-15/+10
|
* dhcp: don't pass duid to client ip6_start() and stop()Thomas Haller2018-11-131-8/+5
| | | | | | | | | | | | | | | | | We don't do that for ip4_start() either. The duid/client-id is stored inside the NMDhcpClient instance, and the function can access it from there. Maybe, it is often preferable to have stateless objects and not relying on ip4_start() to obtain the client ID from the client's state. However, the purpose of the NMDhcpClient object is to hold state about DHCP. To simplify the complexity of objects that inherrently have state, we should be careful about mutating the state. It adds little additional complexity of only reading the state when needed anyway. In fact, it adds complexity, because previously it wasn't enough to check all callers of nm_dhcp_client_get_client_id() to see where the client-id is used. Instead, one would also need to follow the @duid argument several layers of the call stack.
* dhcp: refactor nm_dhcp_dhclient_save_duid() to accept original DUIDThomas Haller2018-11-131-4/+1
| | | | | | | | | 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: don't re-read DHCP client ID from configuration file for dhclientThomas Haller2018-11-131-19/+0
| | | | | | | | | | | | | | | | | | | | Why would we do this? The configuration file we are reading back was written by NetworkManager in the first place. Maybe when assuming a connection after restart, this information could be interesting. It however is not actually relevant. Note how nm_dhcp_client_get_client_id() has only very few callers. - nm_device_spawn_iface_helper() in 'nm-device.c'. In this case, we either should use the client-id which we used when starting DHCP, or none at all. - ip4_start() in 'nm-dhcp-dhclient.c', but this is before starting DHCP client and before it was re-read from configuration file. - in "src/dhcp/nm-dhcp-systemd.c", but this has no effect for the dhclient plugin.
* dhcp: dhclient: fix memory leakBeniamino Galvani2018-09-271-0/+1
| | | | Fixes: c263f5355cbd86da75aaa161987fee8b59cb8c8b
* config: add --configure-and-quit=initrd modeLubomir Rintel2018-09-181-0/+19
| | | | | | | | | | | | We need a mode that: * doesn't leave processes behind * doesn't force an internal dhclient * doesn't auto-generate default connections * doesn't write out files into libdir, only /run The original configure-and-quit mode doesn't really fit the initrd use. But it's proobably not a good idea to just change its behavior.
* dhcp: return error reason from DHCP client startThomas Haller2018-09-121-69/+106
| | | | (cherry picked from commit 1a4fe308e85f0980bc9acf75047659a0e4571d2c)
* dhcp: fix leak in dhclient's dhclient_start()Thomas Haller2018-09-101-2/+6
| | | | | Fixes: 5d6d5cd136e36ed2815b7c719ada32bc6d22b481 (cherry picked from commit c87faf07a10900804b914057a2673e0e070b0af4)
* all: don't use gchar/gshort/gint/glong but C typesThomas Haller2018-07-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We commonly don't use the glib typedefs for char/short/int/long, but their C types directly. $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l 587 $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l 21114 One could argue that using the glib typedefs is preferable in public API (of our glib based libnm library) or where it clearly is related to glib, like during g_object_set (obj, PROPERTY, (gint) value, NULL); However, that argument does not seem strong, because in practice we don't follow that argument today, and seldomly use the glib typedefs. Also, the style guide for this would be hard to formalize, because "using them where clearly related to a glib" is a very loose suggestion. Also note that glib typedefs will always just be typedefs of the underlying C types. There is no danger of glib changing the meaning of these typedefs (because that would be a major API break of glib). A simple style guide is instead: don't use these typedefs. No manual actions, I only ran the bash script: FILES=($(git ls-files '*.[hc]')) sed -i \ -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \ -e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \ -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \ "${FILES[@]}"
* dhcp: look for DUID in both private and global DHCP client lease filesFrancesco Giudici2018-06-201-2/+2
| | | | | | | | | | Option to check just in NM private dhcp client specific lease files has been dropped: either get DUID from specific DHCP plugin or just use the provided one. This reverts commit f054c3fcaadb39c6597d9d9e4ed94b5d4fc29508. (cherry picked from commit 08116409f3f9bbb44115aa53fe27d9624731fa73)
* dhcp: allow to skip DUID search from DHCP client global configurationFrancesco Giudici2018-06-091-2/+2
| | | | | | | | When the used client is dhclient we were used to search for DUID not only in the specific lease files generated by NetworkManager, but also in the global lease file generated outside NetworkManager. Keep this capability but allow to just search in the NM lease files if a value different from the default one is specified in dhcp-duid.
* dhcp: remove fallback DUID-UUID generation from dhcp codeFrancesco Giudici2018-06-091-2/+1
| | | | | | | This commit centralizes the DUID generation in nm-device.c. As a consequence, a DUID is always provided when starting a DHCPv6 client. The DHCP client can override the passed DUID with the value contained in the client-specific lease file.
* dhcp: refactor dhclient_start() to use cleanup attributeThomas Haller2018-05-261-45/+45
|
* dhcp: cache errno in nm_dhcp_client_stop_existing() before using itThomas Haller2018-05-261-4/+6
|
* dhcp: minor cleanup initializing name of leasefile for NMDhcpDhclintThomas Haller2018-05-261-17/+11
|
* dhcp: fix leaking error in dhclient_start()Thomas Haller2018-05-261-0/+1
| | | | Fixes: 1b1b4bd91c29425c25e8e979cd77b7a67deb9bf5
* all: remove consecutive empty linesBeniamino Galvani2018-04-301-3/+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_manager_get_lease_ip_configs() functionThomas Haller2018-03-201-27/+0
|
* dhcp: refactor type of NMDhcpClient duid to be GBytesThomas Haller2018-02-151-6/+6
| | | | | GBytes is immutable. It's better suited to contain the duid parameter then a GByteArray.
* dhcp: cache info-only parameter in NMDhcpClientThomas Haller2018-02-151-2/+5
| | | | | | | | | | | | | | Optimally, NMDhcpClient would be stateless and all paramters would be passed on as argument. Clearly that is not feasable, because there are so many paramters, and in many cases they need to be cached for the lifetime of the client instance. Instead of passing info_only paramter to ip6_start() and cache it both in NMDhcpClient and NMDhcpSystemd, keep it in NMDhcpClient at one place. In the next commit, we will initialize info-only only once during the constructor, so it is immutable and somewhat stateless.
* dhcp: chain up parent stop() for NMDhcpSystem clientThomas Haller2018-02-151-1/+0
| | | | | | | | | | | The parent's stop() implementation does nothing interesting for NMDhcpSystem. Still, call it, it's just unexpected to not chain up the parent implementation, if all other subclasses do it. In general, if the parent's implementation is not suitable to be called by the derived class, that should be handled differently then just not chaining up. Otherwise it's inconsistent and confusing.
* dhcp: fix memleak parsing dhclient file with multiple dhcp-client-identifier ↵Thomas Haller2018-02-151-1/+3
| | | | lines
* all: replace non-leading tabs with spacesThomas Haller2018-02-071-4/+4
| | | | | | We commonly only allow tabs at the beginning of a line, not afterwards. The reason for this style is so that the code looks formated right with tabstop=4 and tabstop=8.
* core: rework tracking of gateway/default-route in ip-configThomas Haller2017-10-101-10/+7
| | | | | | | | | | | | | | | | | | | | | | 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.
* core: use ipv4.route-table setting for other IPv4 routesThomas Haller2017-10-091-0/+1
| | | | Including device-routes, default-route, DHCPv4, IPv4LL.
* dhcp/trivial: rename "priority" variables to "route_metric" in DHCP codeThomas Haller2017-10-061-1/+1
| | | | | | | | The name "priority" is well established for routes (e.g. kernel's RTA_PRIORITY netlink attribute). However, we call it at most places "metric" or "route_metric". Rename it, not to use two different names for the same thing.
* dhcp: dhclient: remove the --timeout argument from the command lineFrancesco Giudici2017-09-151-17/+12
| | | | | | | | | | | | | | | | | | 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-35/+45
| | | | | | | | | | | | | 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.
* dhcp: dhclient: fix daemon start when dhcp-timeout is specifiedFrancesco Giudici2017-09-111-1/+1
| | | | | | | | A typo in the new dhcp-timeout option caused the dhclient daemon to exit with error when the dhcp-timeout option was specified. This prevents dhcp connection to be upped. Fixes: 82ef497cc9e2728e73cb0426efbae85c83bec3fe
* core: pass NMDedupMultiIndex instance to NMIP4Config and otherThomas Haller2017-07-051-2/+5
| | | | | | | | | | | | | | 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: simplify how hostname and FQDN are passed down to backendsBeniamino Galvani2017-05-041-8/+9
| | | | | 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-3/+0
| | | | | | | | | | | | | | 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
* dhcp: dhclient: fix timeout greater than 60 secondsBeniamino Galvani2017-05-021-0/+13
| | | | | | | | | | The default timeout in dhclient is 60 seconds; if a lease can't be obtained during such interval, dhclient sends to NM a FAIL event and then the IP method fails. Thus, even if user specified a greater dhcp-timeout, NM terminated DHCP after 60 seconds. Fix this by passing an explicit timeout to dhclient.
* build: rename "src/dhcp-manager" to "src/dhcp"Thomas Haller2016-11-211-0/+706
The dhcp directory does not only contain the manager instance, but various files related to DHCP. Rename.