summaryrefslogtreecommitdiffstats
path: root/sbin/dhclient/bpf.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC: r261566brueffer2014-02-131-1/+1
| | | | | | | | Use CAP_EVENT instead of the deprecated CAP_POLL_EVENT. PR: 185382 (based on) Submitted by: Loganaden Velvindron Reviewed by: pjd
* Change the cap_rights_t type from uint64_t to a structure that we can extendpjd2013-09-051-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* 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-031-4/+49
| | | | | | | | | | | | 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 @229476,229478:pjd2013-07-031-59/+69
| | | | | | | | | 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-031-2/+1
| | | | | | | No caller checks send_packet() return value, so make it void. Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229472:pjd2013-07-031-7/+14
| | | | | | | Use the same type for 'from' and 'to' argument in send_packet(). Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229471:pjd2013-07-031-1/+1
| | | | | | | Remove unused argument from assemble_hw_header(). Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* MFp4 @229470:pjd2013-07-031-3/+2
| | | | | | | Remove unused argument from send_packet(). Reviewed by: brooks Sponsored by: The FreeBSD Foundation
* Make dhclient use bootpc (68) as the source port for unicast DHCPREQUESTphilip2009-10-211-18/+27
| | | | | | | | | | | | 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)
* 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
* It is possible for bpf to return a length such that:brooks2006-09-261-1/+1
| | | | | | | | | | | | | | | | | | | | 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
* Add __FBSDID to all .c files in dhclient to aid in determining filebrooks2005-08-231-1/+3
| | | | versions when dealing with user problems.
* FreeBSD unconditionally supports write filters now.csjp2005-08-231-2/+0
|
* Further fix receive_packet() by using BPF_WORDALIGN to insure the offsetbrooks2005-07-281-5/+15
| | | | | | is properly aligned when we move to the next packet. Obtained from: ISC dhclient via krw at OpenBSD
* Fix a bug in the handling of cases where we got a short (or zero)brooks2005-07-271-4/+4
| | | | | | | | 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
* We don't support BPF write filters at this time.brooks2005-06-071-0/+3
| | | | Submitted by: sam
* Import the OpenBSD dhclient as shipped with OpenBSD-3.7 (the tagbrooks2005-06-071-0/+374
OPENBSD_3_7).
OpenPOWER on IntegriCloud