Commit Graph

140 Commits

Author SHA1 Message Date
Pawel Jakub Dawidek
374a8a322b Fix dhclient for interfaces that are down. The discover_interfaces() function
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
2013-07-04 12:27:10 +00:00
Pawel Jakub Dawidek
8da93e6861 MFp4 @229488:
Sandbox unprivileged process using capability mode.

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
2013-07-03 22:23:25 +00:00
Pawel Jakub Dawidek
a6f38228d4 MFp4 @229487:
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
2013-07-03 22:22:29 +00:00
Pawel Jakub Dawidek
4c7a48b7a9 MFp4 @229486:
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
2013-07-03 22:21:11 +00:00
Pawel Jakub Dawidek
fe5c716394 MFp4 @229485:
Only allow to overwrite lease file.

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
2013-07-03 22:19:43 +00:00
Pawel Jakub Dawidek
f73ac8b9de MFp4 @229484:
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
2013-07-03 22:18:40 +00:00
Pawel Jakub Dawidek
de2c882f5c MFp4 @229483:
Limit communication pipe with privileged process to CAP_READ and CAP_WRITE.

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
2013-07-03 22:17:29 +00:00
Pawel Jakub Dawidek
3b2ed0659c MFp4 @229482:
- 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
2013-07-03 22:16:02 +00:00
Pawel Jakub Dawidek
235eb53002 MFp4 @229481:
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
2013-07-03 22:12:54 +00:00
Pawel Jakub Dawidek
e374cef518 MFp4 @229480:
Shutdown write direction of the routing socket. We only need to read from it.

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
2013-07-03 22:09:02 +00:00
Pawel Jakub Dawidek
7fdc27bc51 MFp4 @229479:
- Add new request (IMSG_SEND_PACKET) that will be handled by privileged process.
- Add $FreeBSD$.

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
2013-07-03 22:07:55 +00:00
Pawel Jakub Dawidek
0bbe83068e MFp4 @229477:
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
2013-07-03 22:05:36 +00:00
Pawel Jakub Dawidek
c786bc9089 Remove redundant white-spaces. 2013-07-03 22:03:19 +00:00
Pawel Jakub Dawidek
b0f1b32afb MFp4 @229476,229478:
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
2013-07-03 22:01:52 +00:00
Pawel Jakub Dawidek
3a0fc7d8a9 MFp4 @229474:
iov_base field is 'void *' in FreeBSD, no need to cast.

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
2013-07-03 21:58:26 +00:00
Pawel Jakub Dawidek
e8da500388 MFp4 @229473:
No caller checks send_packet() return value, so make it void.

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
2013-07-03 21:57:24 +00:00
Pawel Jakub Dawidek
ba019ae51f MFp4 @229472:
Use the same type for 'from' and 'to' argument in send_packet().

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
2013-07-03 21:53:54 +00:00
Pawel Jakub Dawidek
d1f4d85494 MFp4 @229471:
Remove unused argument from assemble_hw_header().

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
2013-07-03 21:49:10 +00:00
Pawel Jakub Dawidek
592291c1e7 MFp4 @229470:
Remove unused argument from send_packet().

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
2013-07-03 21:45:29 +00:00
Pawel Jakub Dawidek
181ab08d9e MFp4: @229469:
Garbage-collect dead prototypes.

Reviewed by:	brooks
Sponsored by:	The FreeBSD Foundation
2013-07-03 21:41:35 +00:00
Bruce M Simpson
d32438c3f1 When acquiring a lease, record the value of the BOOTP siaddr field
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
2013-07-02 13:24:37 +00:00
John Baldwin
9291a1cd14 Use a higher TTL (128) for DHCP packets. This matches the ISC DHCP client.
PR:		bin/170279
MFC after:	1 week
2013-04-22 15:02:32 +00:00
John Baldwin
0a26f85822 Revert r239356 and use an alternate algorithm.
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
2012-08-22 13:53:37 +00:00
John Baldwin
83f745b8b9 Fix dhclient to properly exit and teardown the configured lease when
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
2012-08-17 15:53:43 +00:00
Ulrich Spörlein
4b85a12f71 Spelling fixes for sbin/ 2012-01-07 16:09:33 +00:00
Jean-Sébastien Pédron
999f397284 Set svn:executable on dhclient-script
Sponsored by:	Yakaz (http://www.yakaz.com)
2011-12-30 14:46:53 +00:00
Jean-Sébastien Pédron
33d5b03267 Invalid Domain Search option isn't considered as a fatal error
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)
2011-12-30 14:33:08 +00:00
Dimitry Andric
7824741286 In sbin/dhclient, since we know the size of the source strings anyway,
we might as well use memcpy; strlcpy is really unnecessary here.

MFC after:	1 week
2011-12-17 01:29:46 +00:00
Dimitry Andric
e2f95dd941 In sbin/dhclient, work around warnings about the size argument to
strlcpy appearing to be the size of the source buffer, instead of the
destination.

MFC after:	1 week
2011-12-17 01:19:07 +00:00
Gleb Smirnoff
1c6eeddad9 dhclient-script relied on incorrect behavior of SIOCAIFADDR ioctl,
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
2011-12-13 11:54:51 +00:00
Jean-Sébastien Pédron
409139f051 Support domain-search in dhclient(8)
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)
2011-12-04 14:44:31 +00:00
Dag-Erling Smørgrav
23f39c906b Make dhclient use a pid file. Modify the rc script accordingly; while
there, clean it up and add some error checks.

Glanced at by:	brooks@
MFC after:	3 weeks
2011-10-13 17:20:45 +00:00
Hajimu UMEMOTO
9201145d02 Use resolvconf(8) to update /etc/resolv.conf.
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.
2011-03-18 12:23:20 +00:00
Brian Somers
5172455266 Document dhclient-enter-hooks and dhclient-exit-hooks and mention
how to configure dhclient to clear the interface of IP numbers prior
to configuring it.

PR:		149351
MFC after:	2 weeks
2010-09-06 09:59:10 +00:00
Brian Somers
6964abef83 When dhclient obtains a lease, it runs dhclient-script and expects
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
2010-07-07 06:06:54 +00:00
Philip Paeps
9b683f8da6 Make dhclient use bootpc (68) as the source port for unicast DHCPREQUEST
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)
2009-10-21 23:50:35 +00:00
Ruslan Ermilov
106d839190 Switch the default WARNS level for sbin/ to 6.
Submitted by:	Ulrich Spörlein
2009-10-19 16:00:24 +00:00
Sam Leffler
f8c44ada2e Fix the logic to count the number of "live interfaces". With this change
dhclient now terminates when the underlying ifnet is destroyed (e.g.
on card eject).

Reviewed by:	brooks
Approved by:	re (kib)
2009-07-21 15:06:10 +00:00
Brian Somers
043bcc8d44 Fix an off by one error when we limit append/prepend text sizes based on our
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.
2009-06-08 21:42:30 +00:00
Brooks Davis
38e755fd40 Support the remaining options listed in dhcp-options(5) and RFC 2132.
PR:		bin/127076
Submitted by:	jkim
MFC after:	1 week
2008-10-17 13:28:53 +00:00
Ed Schouten
708925463e Run the privileged dhclient process in its own session.
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
2008-06-30 20:23:49 +00:00
Brooks Davis
9761cdd839 Use the -n flag to route(8) when calling "route get". Otherwise we hang
for a long time if we get a lease, but DNS isn't working.

MFC after:	1 week
2008-06-09 20:03:35 +00:00
Brooks Davis
8ca3089abc When sending packets directly to the DHCP server, use a socket and send
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
2008-04-15 22:48:56 +00:00
Brooks Davis
d5354256b6 Add a new function is_default_interface() which determines if this
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
2008-03-30 02:42:39 +00:00
Sam Leffler
61063e478a Defer state change on disassociate to avoid unnecessarily dropping the
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
2008-03-22 16:24:02 +00:00
Sam Leffler
043f1935e0 correct syslog mask so LOG_DEBUG msgs are not lost
MFC after:	2 weeks
2008-03-22 16:18:07 +00:00
Brooks Davis
1547317e88 During PREINIT, when giving the interface the address 0.0.0.0, do it as an
alias to avoid distrubing other addresses.

PR:		bin/119255
Submitted by:	Jaakko Heinonen <jh at saunalahti dot fi>
2008-01-21 23:54:57 +00:00
Jung-uk Kim
cd765a6594 Teach dhclient(8) about net80211 link (association) status.
Reviewed by:	brooks
MFC after:	3 days
2007-12-05 17:13:45 +00:00
Gabor Kovesdan
6b7267a277 - Remove references to unexisting man pages
PR:		docs/116099
Submitted by:	Ben Kaduk <minimarmot@gmail.com>
Approved by:	re (bmah)
MFC after:	3 days
2007-09-20 10:46:25 +00:00
Andrew Thompson
60932bc9ae Use the -n flag on ifconfig so that dhclient does not cause the kernel module
to be reloaded when the interface is torn down.

Reviewed by:	brooks
Approved by:	re (kensmith)
2007-07-03 17:49:32 +00:00