History log of /freebsd-10.0-release/sbin/dhclient/bpf.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 259065 07-Dec-2013 gjb

- Copy stable/10 (r259064) to releng/10.0 as part of the
10.0-RELEASE cycle.
- Update __FreeBSD_version [1]
- Set branch name to -RC1

[1] 10.0-CURRENT __FreeBSD_version value ended at '55', so
start releng/10.0 at '100' so the branch is started with
a value ending in zero.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


# 255219 04-Sep-2013 pjd

Change the cap_rights_t type from uint64_t to a structure that we can extend
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


# 252628 03-Jul-2013 pjd

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


# 252626 03-Jul-2013 pjd

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


# 252620 03-Jul-2013 pjd

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


# 252619 03-Jul-2013 pjd

MFp4 @229474:

iov_base field is 'void *' in FreeBSD, no need to cast.

Reviewed by: brooks
Sponsored by: The FreeBSD Foundation


# 252618 03-Jul-2013 pjd

MFp4 @229473:

No caller checks send_packet() return value, so make it void.

Reviewed by: brooks
Sponsored by: The FreeBSD Foundation


# 252616 03-Jul-2013 pjd

MFp4 @229472:

Use the same type for 'from' and 'to' argument in send_packet().

Reviewed by: brooks
Sponsored by: The FreeBSD Foundation


# 252615 03-Jul-2013 pjd

MFp4 @229471:

Remove unused argument from assemble_hw_header().

Reviewed by: brooks
Sponsored by: The FreeBSD Foundation


# 252614 03-Jul-2013 pjd

MFp4 @229470:

Remove unused argument from send_packet().

Reviewed by: brooks
Sponsored by: The FreeBSD Foundation


# 198352 21-Oct-2009 philip

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)


# 178232 15-Apr-2008 brooks

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


# 162641 25-Sep-2006 brooks

It is possible for bpf to return a length such that:

length != BPF_WORDALIGN(length)

This meeans that it is possible for this to be true:

interface->rbuf_offset > interface->rbuf_len

Handle this case in the test for running out of packets. While
OpenBSD's solution of setting interface->rbuf_len to
BPF_WORDALIGN(length) is safe due to the size of the buffer, I think
this solution results in less hidden assumptions.

This should fix the problem of dhclient running away and consuming 100%
CPU.

PR: bin/102226
Submitted by: Joost Bekkers <joost at jodocus.org>
MFC after: 3 days


# 149399 23-Aug-2005 brooks

Add __FBSDID to all .c files in dhclient to aid in determining file
versions when dealing with user problems.


# 149383 22-Aug-2005 csjp

FreeBSD unconditionally supports write filters now.


# 148484 28-Jul-2005 brooks

Further fix receive_packet() by using BPF_WORDALIGN to insure the offset
is properly aligned when we move to the next packet.

Obtained from: ISC dhclient via krw at OpenBSD


# 148451 27-Jul-2005 brooks

Fix a bug in the handling of cases where we got a short (or zero)
capture. Zero length captures caused an infinte loop and short captures
probably caused memory corruption and a crash.

Reported by: many
MFC After: 3 days


# 147076 07-Jun-2005 brooks

We don't support BPF write filters at this time.

Submitted by: sam


# 147073 07-Jun-2005 brooks

This commit was generated by cvs2svn to compensate for changes in r147072,
which included commits to RCS files with non-trunk default branches.


# 147072 07-Jun-2005 brooks

Import the OpenBSD dhclient as shipped with OpenBSD-3.7 (the tag
OPENBSD_3_7).