summaryrefslogtreecommitdiffstats
path: root/sbin/dhclient
Commit message (Collapse)AuthorAgeFilesLines
* Change the cap_rights_t type from uint64_t to a structure that we can extendpjd2013-09-052-16/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | in the future in a backward compatible (API and ABI) way. The cap_rights_t represents capability rights. We used to use one bit to represent one right, but we are running out of spare bits. Currently the new structure provides place for 114 rights (so 50 more than the previous cap_rights_t), but it is possible to grow the structure to hold at least 285 rights, although we can make it even larger if 285 rights won't be enough. The structure definition looks like this: struct cap_rights { uint64_t cr_rights[CAP_RIGHTS_VERSION + 2]; }; The initial CAP_RIGHTS_VERSION is 0. The top two bits in the first element of the cr_rights[] array contain total number of elements in the array - 2. This means if those two bits are equal to 0, we have 2 array elements. The top two bits in all remaining array elements should be 0. The next five bits in all array elements contain array index. Only one bit is used and bit position in this five-bits range defines array index. This means there can be at most five array elements in the future. To define new right the CAPRIGHT() macro must be used. The macro takes two arguments - an array index and a bit to set, eg. #define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL) We still support aliases that combine few rights, but the rights have to belong to the same array element, eg: #define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL) #define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL) #define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP) There is new API to manage the new cap_rights_t structure: cap_rights_t *cap_rights_init(cap_rights_t *rights, ...); void cap_rights_set(cap_rights_t *rights, ...); void cap_rights_clear(cap_rights_t *rights, ...); bool cap_rights_is_set(const cap_rights_t *rights, ...); bool cap_rights_is_valid(const cap_rights_t *rights); void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src); void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src); bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little); Capability rights to the cap_rights_init(), cap_rights_set(), cap_rights_clear() and cap_rights_is_set() functions are provided by separating them with commas, eg: cap_rights_t rights; cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT); There is no need to terminate the list of rights, as those functions are actually macros that take care of the termination, eg: #define cap_rights_set(rights, ...) \ __cap_rights_set((rights), __VA_ARGS__, 0ULL) void __cap_rights_set(cap_rights_t *rights, ...); Thanks to using one bit as an array index we can assert in those functions that there are no two rights belonging to different array elements provided together. For example this is illegal and will be detected, because CAP_LOOKUP belongs to element 0 and CAP_PDKILL to element 1: cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL); Providing several rights that belongs to the same array's element this way is correct, but is not advised. It should only be used for aliases definition. This commit also breaks compatibility with some existing Capsicum system calls, but I see no other way to do that. This should be fine as Capsicum is still experimental and this change is not going to 9.x. Sponsored by: The FreeBSD Foundation
* Fix dhclient for interfaces that are down. The discover_interfaces() functionpjd2013-07-041-5/+5
| | | | | | | | that looks for interface skips interfaces that are not UP. We need to call dhclient-script PREINIT before we call discover_interfaces(), so the script has a chance to bring the interface UP. Reported by: alfred
* MFp4 @229488:pjd2013-07-031-0/+3
| | | | | | | Sandbox unprivileged process using capability mode. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229487:pjd2013-07-031-0/+7
| | | | | | | | Revoke all capability rights from STDIN and allow only for write to STDOUT and STDERR. All those descriptors are redirected to /dev/null. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229486:pjd2013-07-031-1/+6
| | | | | | | | Once PID is written to the pidfile, revoke all capability rights. We just want to keep the pidfile open. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229485:pjd2013-07-031-0/+5
| | | | | | | Only allow to overwrite lease file. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229484:pjd2013-07-031-0/+4
| | | | | | | | | Limit routing socket so only poll(2) and read(2) are allowed (CAP_POLL_EVENT and CAP_READ). This prevents unprivileged process from adding, removing or modifying system routes. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229483:pjd2013-07-031-0/+6
| | | | | | | Limit communication pipe with privileged process to CAP_READ and CAP_WRITE. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229482:pjd2013-07-031-0/+12
| | | | | | | | | - Limit bpf descriptor in unprivileged process to CAP_POLL_EVENT, CAP_READ and allow for SIOCGIFFLAGS, SIOCGIFMEDIA ioctls. - While here limit bpf descriptor in privileged process to only CAP_WRITE. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229481:pjd2013-07-034-18/+75
| | | | | | | | | | | | Currently it was allowed to send any UDP packets from unprivileged process and possibly any packets because /dev/bpf was open for writing. Move sending packets to privileged process. Unprivileged process has no longer access to not connected UDP socket and has only access to /dev/bpf in read-only mode. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229480:pjd2013-07-031-0/+2
| | | | | | | Shutdown write direction of the routing socket. We only need to read from it. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229479:pjd2013-07-031-1/+4
| | | | | | | | - Add new request (IMSG_SEND_PACKET) that will be handled by privileged process. - Add $FreeBSD$. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229477:pjd2013-07-031-4/+11
| | | | | | | | | The gethostname(3) function won't work in capability mode, because reading kern.hostname sysctl is not permitted there. Cache hostname early and use cached value later. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* Remove redundant white-spaces.pjd2013-07-031-9/+9
|
* MFp4 @229476,229478:pjd2013-07-032-60/+70
| | | | | | | | | Make use of two fields: rfdesc and wfdesc to keep bpf descriptor open for reading only in rfdesc and bpf descriptor open for writing only in wfdesc. In the end they will be used by two different processes. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229474:pjd2013-07-031-2/+2
| | | | | | | iov_base field is 'void *' in FreeBSD, no need to cast. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229473:pjd2013-07-033-6/+5
| | | | | | | No caller checks send_packet() return value, so make it void. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229472:pjd2013-07-033-34/+28
| | | | | | | Use the same type for 'from' and 'to' argument in send_packet(). Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229471:pjd2013-07-033-8/+4
| | | | | | | Remove unused argument from assemble_hw_header(). Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229470:pjd2013-07-033-7/+6
| | | | | | | Remove unused argument from send_packet(). Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4: @229469:pjd2013-07-032-11/+0
| | | | | | | Garbage-collect dead prototypes. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* When acquiring a lease, record the value of the BOOTP siaddr fieldbms2013-07-023-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | contained in the DHCP offer, and write it out to the lease file as an unquoted value of the "next-server" keyword. The value is ignored when the lease is read back by dhclient, however other applications are free to parse it. The intent behind this change is to allow easier interoperability with automated installation systems e.g. Cobbler, Foreman, Razor; FreeBSD installation kernels can automatically probe the network to discover deployment servers. There are no plans to MFC this change unless a backport is specifically requested. The syntax of the "next-server <ip>" lease keyword is intended to be identical to that used by the ISC DHCPD server in its configuration files. The required defines are already present in dhclient but were unused before this change. (Note: This is NOT the same as Option 66, tftp-server-name). It has been exercised in a university protocol testbed environment, with Cobbler and an mfsBSD image containing pc-sysinstall (driven by Cobbler Cheetah templates). The SYSLINUX memdisk driver is used to boot mfsBSD. Currently this approach requires that a dedicated system profile has been created for the node where FreeBSD is to be deployed. If this is not present, the pc-sysinstall wrapper will be unable to obtain a node configuration. There is code in progress to allow mfsBSD images to obtain the required hints from the memdisk environment by parsing the MBFT ACPI chunk. This is non-standard as it is not linked into the platform's ACPI RSDT. Reviewed by: des
* Use a higher TTL (128) for DHCP packets. This matches the ISC DHCP client.jhb2013-04-221-1/+1
| | | | | PR: bin/170279 MFC after: 1 week
* Revert r239356 and use an alternate algorithm.jhb2012-08-222-6/+11
| | | | | | | | | | | | | | | | | First, don't exit when the link goes down on an interface. Instead, teach dhclient to track changes in link state and to enter the reboot state when the link on an interface goes up causing dhclient to attempt to renew its existing lease. Second, remove the change I added to clear the old lease when dhclient exits due to an error (such as ifconfig down). If an interface is using autoconfiguration it should keep its autoconfiguration as much as possible. If the next time it needs a configuration it is able to reuse the previous autoconfiguration, then leaving the settings intact allows existing connections to survive temporary outages, etc. PR: bin/166656 MFC after: 1 month
* Fix dhclient to properly exit and teardown the configured lease whenjhb2012-08-171-0/+7
| | | | | | | | | | link is lost. devd will start a new dhclient instance when link is restored. PR: bin/166656 Submitted by: Peter Jeremy (mostly) Reviewed by: brooks (earlier version from Peter) MFC after: 1 month
* Spelling fixes for sbin/uqs2012-01-072-3/+3
|
* Set svn:executable on dhclient-scriptdumbbell2011-12-301-0/+0
| | | | Sponsored by: Yakaz (http://www.yakaz.com)
* Invalid Domain Search option isn't considered as a fatal errordumbbell2011-12-301-9/+17
| | | | | | | | | | | | In the original Domain Search option patch, an invalid option value would cause the whole lease to be rejected. However, DHCP servers who emit such an invalid value are more common than I thought. With this new patch, just the option is rejected, not the entire lease. PR: bin/163431 Submitted by: Fabian Keil <fk@fabiankeil.de> (earlier version) Reviewed by: Fabian Keil <fk@fabiankeil.de> Sponsored by: Yakaz (http://www.yakaz.com)
* In sbin/dhclient, since we know the size of the source strings anyway,dim2011-12-172-3/+3
| | | | | | we might as well use memcpy; strlcpy is really unnecessary here. MFC after: 1 week
* In sbin/dhclient, work around warnings about the size argument todim2011-12-172-6/+12
| | | | | | | strlcpy appearing to be the size of the source buffer, instead of the destination. MFC after: 1 week
* dhclient-script relied on incorrect behavior of SIOCAIFADDR ioctl,glebius2011-12-131-1/+1
| | | | | | | | | | | | that changed 0.0.0.0/0.0.0.0 prefix to 0.0.0.0/255.0.0.0. In the r228313 this behavior was fixed, and since dhclient-script got broken. I'm not sure this fix is a perfect one, it just changes dhclient-script to set 0.0.0.0/255.0.0.0 explicitly. PR: kern/163206
* Support domain-search in dhclient(8)dumbbell2011-12-047-3/+180
| | | | | | | | | | | | | | | | | | | | | The "domain-search" option (option 119) allows a DHCP server to publish a list of implicit domain suffixes used during name lookup. This option is described in RFC 3397. For instance, if the domain-search option says: ".example.org .example.com" and one wants to resolve "foobar", the resolver will try: 1. "foobar.example.org" 2. "foobar.example.com" The file /etc/resolv.conf is updated with a "search" directive if the DHCP server provides "domain-search". A regression test suite is included in this patch under tools/regression/sbin/dhclient. PR: bin/151940 Sponsored by Yakaz (http://www.yakaz.com)
* Make dhclient use a pid file. Modify the rc script accordingly; whiledes2011-10-135-3/+48
| | | | | | | there, clean it up and add some error checks. Glanced at by: brooks@ MFC after: 3 weeks
* Use resolvconf(8) to update /etc/resolv.conf.ume2011-03-181-25/+46
| | | | | If you don't want to use resolvconf(8) to update /etc/resolv.conf, you can put resolvconf_enable="NO" into /etc/dhclient-enter-hooks.
* Document dhclient-enter-hooks and dhclient-exit-hooks and mentionbrian2010-09-061-1/+25
| | | | | | | | how to configure dhclient to clear the interface of IP numbers prior to configuring it. PR: 149351 MFC after: 2 weeks
* When dhclient obtains a lease, it runs dhclient-script and expectsbrian2010-07-071-16/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | it to configure the interface. When the script is complete, dhclient monitors the routing socket and will terminate if its address is deleted or if its interface is removed or brought down. Because the routing socket is already open when dhclient-script is run, dhclient ignores address deletions for 10 seconds after the script was run. If the address that will be obtained is already configured on the interface before dhclient starts, and if dhclient-script takes more than 10 seconds (perhaps due to dhclient-*-hooks latencies), on script completion, dhclient will immediately and silently exit when it sees the RTM_DELADDR routing message resulting from the script reassigning the address to the interface. This change logs dhclient's reason for exiting and also changes the 10 second timeout to be effective from completion of dhclient-script rather than from when it was started. We now ignore RTM_DELADDR and RTM_NEWADDR messages when the message contains no interface address (which should not happen) rather than exiting. Not reviewed by: brooks (timeout) MFC after: 3 weeks
* Make dhclient use bootpc (68) as the source port for unicast DHCPREQUESTphilip2009-10-213-18/+41
| | | | | | | | | | | | packets instead of allowing the protocol stack to pick a random source port. This fixes the behaviour where dhclient would never transition from RENEWING to BOUND without going through REBINDING in networks which are paranoid about DHCP spoofing, such as most mainstream cable-broadband ISP networks. Reviewed by: brooks Obtained from: OpenBSD (partly - I'm not convinced their solution can work) MFC after: 1 week (pending re approval)
* Switch the default WARNS level for sbin/ to 6.ru2009-10-191-0/+2
| | | | Submitted by: Ulrich Spörlein
* Fix the logic to count the number of "live interfaces". With this changesam2009-07-211-9/+11
| | | | | | | | dhclient now terminates when the underlying ifnet is destroyed (e.g. on card eject). Reviewed by: brooks Approved by: re (kib)
* Fix an off by one error when we limit append/prepend text sizes based on ourbrian2009-06-081-5/+15
| | | | | | | | | | | internal buffer sizes. When we 'append', assume we're appending to text. Some MS dhcp servers will give us a string with the length including the trailing NUL. when we 'append domain-name', we get something like "search x.y\000 z" in resolv.conf :( MFC after: 1 week Security: A buffer overflow (by one NUL byte) was possible.
* Support the remaining options listed in dhcp-options(5) and RFC 2132.brooks2008-10-173-5/+31
| | | | | | PR: bin/127076 Submitted by: jkim MFC after: 1 week
* Run the privileged dhclient process in its own session.ed2008-06-301-0/+1
| | | | | | | | In the MPSAFE TTY branch, I noticed PTY's to be leaked, because dhclient's privileged process was run inside the session of, say, the login shell. Make sure we call setsid() here. Approved by: philip (mentor), brooks
* Use the -n flag to route(8) when calling "route get". Otherwise we hangbrooks2008-06-091-1/+1
| | | | | | for a long time if we get a lease, but DNS isn't working. MFC after: 1 week
* When sending packets directly to the DHCP server, use a socket and sendbrooks2008-04-151-0/+15
| | | | | | | | directly rather than bogusly sending it out as a link layer broadcast (which fails to be received on some networks). PR: bin/96018 MFC after: 2 weeks
* Add a new function is_default_interface() which determines if thisbrooks2008-03-301-20/+48
| | | | | | | | | | | interface is one with the default route (or there isn't one). Use it to decide if we should adjust the default route and /etc/resolv.conf. Fix the delete of the default route. The if statement was totally bogus and the delete only worked due to a typo. [1] Reported by: Jordan Coleman <jordan at JordanColeman dot com> [1] MFC after: 1 week
* Defer state change on disassociate to avoid unnecessarily dropping thesam2008-03-221-15/+31
| | | | | | | | | | lease: track the current bssid and if it changes (as reported in an assoc/reassoc) event only then kick the state machine. This gives us immediate response when roaming but otherwise causes us to fallback on the normal state machine. Reviewed by: brooks, jhb MFC after: 3 weeks
* correct syslog mask so LOG_DEBUG msgs are not lostsam2008-03-221-1/+1
| | | | MFC after: 2 weeks
* During PREINIT, when giving the interface the address 0.0.0.0, do it as anbrooks2008-01-211-1/+1
| | | | | | | alias to avoid distrubing other addresses. PR: bin/119255 Submitted by: Jaakko Heinonen <jh at saunalahti dot fi>
* Teach dhclient(8) about net80211 link (association) status.jkim2007-12-051-1/+4
| | | | | Reviewed by: brooks MFC after: 3 days
* - Remove references to unexisting man pagesgabor2007-09-201-5/+2
| | | | | | | PR: docs/116099 Submitted by: Ben Kaduk <minimarmot@gmail.com> Approved by: re (bmah) MFC after: 3 days
OpenPOWER on IntegriCloud