*/
const struct token *
dhcp_auth_validate(struct authstate *state, const struct auth *auth,
- const uint8_t *m, size_t mlen, int mp, int mt,
- const uint8_t *data, size_t dlen)
+ const void *vm, size_t mlen, int mp, int mt,
+ const void *vdata, size_t dlen)
{
+ const uint8_t *m, *data;
uint8_t protocol, algorithm, rdm, *mm, type;
uint64_t replay;
uint32_t secretid;
return NULL;
}
+ m = vm;
+ data = vdata;
/* Ensure that d is inside m which *may* not be the case for DHPCPv4 */
if (data < m || data > m + mlen || data + dlen > m + mlen) {
errno = ERANGE;
*/
ssize_t
dhcp_auth_encode(struct auth *auth, const struct token *t,
- uint8_t *m, size_t mlen, int mp, int mt,
- uint8_t *data, size_t dlen)
+ void *vm, size_t mlen, int mp, int mt,
+ void *vdata, size_t dlen)
{
uint64_t rdm;
uint8_t hmac[HMAC_LENGTH];
time_t now;
- uint8_t hops, *p, info;
+ uint8_t hops, *p, info, *m, *data;
uint32_t giaddr, secretid;
if (auth->protocol == 0 && t == NULL) {
/* Work out the auth area size.
* We only need to do this for DISCOVER messages */
- if (data == NULL) {
+ if (vdata == NULL) {
dlen = 1 + 1 + 1 + 8;
switch(auth->protocol) {
case AUTH_PROTO_TOKEN:
}
/* Ensure that d is inside m which *may* not be the case for DHPCPv4 */
+ m = vm;
+ data = vdata;
if (data < m || data > m + mlen || data + dlen > m + mlen) {
errno = ERANGE;
return -1;
const struct token * dhcp_auth_validate(struct authstate *,
const struct auth *,
- const uint8_t *, size_t, int, int,
- const uint8_t *, size_t);
+ const void *, size_t, int, int,
+ const void *, size_t);
ssize_t dhcp_auth_encode(struct auth *, const struct token *,
- uint8_t *, size_t, int, int,
- uint8_t *, size_t);
+ void *, size_t, int, int,
+ void *, size_t);
#endif
}
size_t
-dhcp_read_lease_fd(int fd, uint8_t **lease)
+dhcp_read_lease_fd(int fd, void **lease)
{
uint8_t *buf, *nbuf;
size_t len, new_len;
const uint8_t *, size_t, struct dhcp_opt **),
const uint8_t *od, size_t ol);
void dhcp_zero_index(struct dhcp_opt *);
-size_t dhcp_read_lease_fd(int, uint8_t **);
+size_t dhcp_read_lease_fd(int, void **);
#endif
int fd;
bool fd_opened;
struct dhcp_state *state = D_STATE(ifp);
- uint8_t *lease;
+ struct bootp *lease;
size_t bytes;
uint8_t type;
#ifdef AUTH
logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
ifp->name, state->leasefile);
- bytes = dhcp_read_lease_fd(fd, &lease);
+ bytes = dhcp_read_lease_fd(fd, (void **)&lease);
if (fd_opened)
close(fd);
if (bytes == 0) {
dhcp_arp_bind(ifp);
}
-static size_t
-get_udp_data(uint8_t **data, uint8_t *udp)
+static void *
+get_udp_data(uint8_t *udp, size_t *len)
{
struct udp_bootp_packet *p;
p = (struct udp_bootp_packet *)udp;
- *data = udp + offsetof(struct udp_bootp_packet, bootp);
- return ntohs(p->ip.ip_len) - sizeof(p->ip) - sizeof(p->udp);
+ *len = ntohs(p->ip.ip_len) - sizeof(p->ip) - sizeof(p->udp);
+ return udp + offsetof(struct udp_bootp_packet, bootp);
}
static int
static void
dhcp_handlepacket(struct interface *ifp, uint8_t *data, size_t len, int flags)
{
- uint8_t *bootp;
+ struct bootp *bootp;
struct in_addr from;
int i;
size_t udp_len;
* However some servers send a truncated vendor area.
* dhcpcd can work fine without the vendor area being sent.
*/
- udp_len = get_udp_data(&bootp, data);
+ bootp = get_udp_data(data, &udp_len);
/* udp_len must be correct because the values are checked in
* valid_udp_packet(). */
if (udp_len < offsetof(struct bootp, vend)) {
}
/* To make our IS_DHCP macro easy, ensure the vendor
* area has at least 4 octets. */
- while (udp_len < offsetof(struct bootp, vend) + 4)
- bootp[udp_len++] = '\0';
+ len = udp_len - offsetof(struct bootp, vend);
+ while (len < 4) {
+ bootp->vend[len++] = '\0';
+ udp_len++;
+ }
- dhcp_handledhcp(ifp, (struct bootp *)bootp, udp_len, &from);
+ dhcp_handledhcp(ifp, bootp, udp_len, &from);
}
static void
state = D6_STATE(ifp);
return dhcp_auth_encode(&ifp->options->auth, state->auth.token,
- (uint8_t *)state->send, state->send_len,
+ state->send, state->send_len,
6, state->send->type,
D6_OPTION_DATA(o), ntohs(o->len));
}
struct dhcp6_state *state;
struct stat st;
int fd;
- uint8_t *lease;
struct timespec acquired;
time_t now;
int retval;
if (fd == -1)
return -1;
retval = -1;
- lease = NULL;
- state->new_len = dhcp_read_lease_fd(fd, &lease);
- state->new = (struct dhcp6_message *)lease;
+ state->new_len = dhcp_read_lease_fd(fd, (void **)&state->new);
if (fd_opened)
close(fd);
if (state->new_len == 0)
o = dhcp6_getmoption(D6_OPTION_AUTH, state->new, state->new_len);
if (o) {
if (dhcp_auth_validate(&state->auth, &ifp->options->auth,
- (uint8_t *)state->new, state->new_len, 6, state->new->type,
+ state->new, state->new_len, 6, state->new->type,
D6_COPTION_DATA(o), ntohs(o->len)) == NULL)
{
logger(ifp->ctx, LOG_DEBUG,
auth = dhcp6_getmoption(D6_OPTION_AUTH, r, len);
if (auth) {
if (dhcp_auth_validate(&state->auth, &ifo->auth,
- (uint8_t *)r, len, 6, r->type,
+ r, len, 6, r->type,
D6_COPTION_DATA(auth), ntohs(auth->len)) == NULL)
{
logger(ifp->ctx, LOG_DEBUG, "dhcp_auth_validate: %m");