From: Roy Marples Date: Fri, 9 Nov 2007 16:08:49 +0000 (+0000) Subject: We should not use ntohl in IN_LOCAL define, instead where we use it. X-Git-Tag: v3.2.3~146 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0e24b8d2184d574f385896537485a8a6a317687;p=thirdparty%2Fdhcpcd.git We should not use ntohl in IN_LOCAL define, instead where we use it. --- diff --git a/client.c b/client.c index 44c0c0df..5323be32 100644 --- a/client.c +++ b/client.c @@ -180,7 +180,7 @@ static bool get_old_lease (const options_t *options, interface_t *iface, #ifdef ENABLE_ARP /* Check that no-one is using the address */ if ((options->dolastlease || - (IN_LINKLOCAL (dhcp->address.s_addr) && + (IN_LINKLOCAL (ntohl (dhcp->address.s_addr)) && (! options->doipv4ll || arp_claim (iface, dhcp->address))))) { @@ -271,7 +271,9 @@ int dhcp_run (const options_t *options, int *pidfd) return (-1); } - if (! options->daemonised && IN_LINKLOCAL (dhcp->address.s_addr)) { + if (! options->daemonised && + IN_LINKLOCAL (ntohl (dhcp->address.s_addr))) + { logger (LOG_ERR, "cannot request a link local address"); return (-1); } @@ -459,7 +461,7 @@ int dhcp_run (const options_t *options, int *pidfd) || state == STATE_REBINDING) { logger (LOG_INFO, "received SIGHUP, releasing lease"); - if (! IN_LINKLOCAL (dhcp->address.s_addr)) { + if (! IN_LINKLOCAL (ntohl (dhcp->address.s_addr))) { SOCKET_MODE (SOCKET_OPEN); xid = random (); if ((open_socket (iface, false)) >= 0) @@ -489,13 +491,13 @@ int dhcp_run (const options_t *options, int *pidfd) case STATE_INIT: if (xid != 0) { if (iface->previous_address.s_addr != 0 && - ! IN_LINKLOCAL (iface->previous_address.s_addr) && + ! IN_LINKLOCAL (ntohl (iface->previous_address.s_addr)) && ! options->doinform) { logger (LOG_ERR, "lost lease"); if (! options->persistent) DROP_CONFIG; - } else + } else if (! IN_LINKLOCAL (ntohl (iface->previous_address.s_addr))) logger (LOG_ERR, "timed out"); SOCKET_MODE (SOCKET_CLOSED); @@ -525,7 +527,7 @@ int dhcp_run (const options_t *options, int *pidfd) #ifdef ENABLE_IPV4LL if (! options->test && options->doipv4ll && (! dhcp->address.s_addr || - (! IN_LINKLOCAL (dhcp->address.s_addr) && + (! IN_LINKLOCAL (ntohl (dhcp->address.s_addr)) && ! options->dolastlease))) { logger (LOG_INFO, "probing for an IPV4LL address"); @@ -534,9 +536,6 @@ int dhcp_run (const options_t *options, int *pidfd) if (ipv4ll_get_address (iface, dhcp) == -1) { break; } - if (! daemonised) - logger (LOG_WARNING, "using IPV4LL address %s", - inet_ntoa (dhcp->address)); timeout = dhcp->renewaltime; } #endif @@ -544,6 +543,10 @@ int dhcp_run (const options_t *options, int *pidfd) #if defined (ENABLE_INFO) || defined (ENABLE_IPV4LL) if (dhcp->address.s_addr) { + if (! daemonised && + IN_LINKLOCAL (ntohl (dhcp->address.s_addr))) + logger (LOG_WARNING, "using IPV4LL address %s", + inet_ntoa (dhcp->address)); if (configure (options, iface, dhcp, true) == -1 && ! daemonised) { @@ -601,7 +604,7 @@ int dhcp_run (const options_t *options, int *pidfd) break; case STATE_BOUND: case STATE_RENEW_REQUESTED: - if (IN_LINKLOCAL (dhcp->address.s_addr)) { + if (IN_LINKLOCAL (ntohl (dhcp->address.s_addr))) { memset (&dhcp->address, 0, sizeof (struct in_addr)); state = STATE_INIT; xid = 0; diff --git a/configure.c b/configure.c index ae5fa555..ca832aa9 100644 --- a/configure.c +++ b/configure.c @@ -546,7 +546,7 @@ int configure (const options_t *options, interface_t *iface, * address and isn't link local itself */ if (options-> doipv4ll && ! haslinklocal && - IN_PRIVATE (dhcp->address.s_addr)) + IN_PRIVATE (ntohl (dhcp->address.s_addr))) { struct in_addr dest; struct in_addr mask; diff --git a/dhcp.c b/dhcp.c index 4f8c3ffd..532d9536 100644 --- a/dhcp.c +++ b/dhcp.c @@ -78,7 +78,7 @@ size_t send_message (const interface_t *iface, const dhcp_t *dhcp, if ((type == DHCP_INFORM || type == DHCP_RELEASE || type == DHCP_REQUEST) && - ! IN_LINKLOCAL (iface->previous_address.s_addr)) + ! IN_LINKLOCAL (ntohl (iface->previous_address.s_addr))) { message->ciaddr = iface->previous_address.s_addr; from.s_addr = iface->previous_address.s_addr; @@ -143,7 +143,7 @@ size_t send_message (const interface_t *iface, const dhcp_t *dhcp, memcpy (p, &_val.s_addr, 4); \ p += 4; \ } - if (IN_LINKLOCAL (dhcp->address.s_addr)) + if (IN_LINKLOCAL (ntohl (dhcp->address.s_addr))) logger (LOG_ERR, "cannot request a link local address"); else { if (dhcp->address.s_addr != iface->previous_address.s_addr && diff --git a/dhcpcd.c b/dhcpcd.c index d52bfd76..5db98e8b 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -458,7 +458,7 @@ int main(int argc, char **argv) options->keep_address = true; } - if (IN_LINKLOCAL (options->request_address.s_addr)) { + if (IN_LINKLOCAL (ntohl (options->request_address.s_addr))) { logger (LOG_ERR, "you are not allowed to request a link local address"); exit (EXIT_FAILURE); } diff --git a/interface.h b/interface.h index f49afd89..3115452e 100644 --- a/interface.h +++ b/interface.h @@ -45,9 +45,9 @@ * 192.168/16 */ #ifndef IN_PRIVATE -# define IN_PRIVATE(addr) (((ntohl (addr) & IN_CLASSA_NET) == 0x0a000000) || \ - ((ntohl (addr) & 0xfff00000) == 0xac100000) || \ - ((ntohl (addr) & IN_CLASSB_NET) == 0xc0a80000)) +# define IN_PRIVATE(addr) (((addr & IN_CLASSA_NET) == 0x0a000000) || \ + ((addr & 0xfff00000) == 0xac100000) || \ + ((addr & IN_CLASSB_NET) == 0xc0a80000)) #endif #define LINKLOCAL_ADDR 0xa9fe0000 @@ -55,7 +55,7 @@ #define LINKLOCAL_BRDC 0xa9feffff #ifndef IN_LINKLOCAL -# define IN_LINKLOCAL(addr) ((ntohl (addr) & IN_CLASSB_NET) == LINKLOCAL_ADDR) +# define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR) #endif typedef struct route_t