mirror of
https://github.com/rsmarples/dhcpcd.git
synced 2024-12-18 06:13:30 +08:00
Suck it hard and use gettimeofday for Linux. Lets just hope that the clock works under Linux during ARP floods.
This commit is contained in:
parent
6a3e853169
commit
f830c2aa70
@ -1,6 +1,6 @@
|
||||
dhcpcd-3.1.5
|
||||
Fix the flushing of addresses on BSD systems.
|
||||
Rework the arp code again so that we don't link to librt on Linux.
|
||||
Rework get_time so that we don't link to librt on Linux.
|
||||
Thanks to regenrecht for reporting the below three overflows:-
|
||||
Fix a potential buffer overflow in hwaddr_ntoa if length > 42.
|
||||
Fix a potential heap overflow in decode_CSR when CIDR > 32.
|
||||
|
20
arp.c
20
arp.c
@ -104,11 +104,6 @@ int arp_claim (interface_t *iface, struct in_addr address)
|
||||
int nclaims = 0;
|
||||
struct in_addr null_address;
|
||||
|
||||
#ifdef HAVE_GET_TIME
|
||||
struct timeval stopat;
|
||||
struct timeval now;
|
||||
#endif
|
||||
|
||||
if (! iface)
|
||||
return (-1);
|
||||
|
||||
@ -135,6 +130,8 @@ int arp_claim (interface_t *iface, struct in_addr address)
|
||||
fd_set rset;
|
||||
int bytes;
|
||||
int s = 0;
|
||||
struct timeval stopat;
|
||||
struct timeval now;
|
||||
|
||||
/* Only select if we have a timeout */
|
||||
if (timeout > 0) {
|
||||
@ -170,32 +167,21 @@ int arp_claim (interface_t *iface, struct in_addr address)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GET_TIME
|
||||
/* Setup our stop time */
|
||||
if (get_time (&stopat) != 0)
|
||||
break;
|
||||
stopat.tv_usec += timeout;
|
||||
#endif
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check for ARP floods */
|
||||
#ifdef __linux__
|
||||
/* Linux does modify the tv struct, otherwise we would have to link
|
||||
* into librt to use get get_time function */
|
||||
timeout = tv.tv_usec;
|
||||
if (timeout <= 0)
|
||||
continue;
|
||||
#else
|
||||
/* We maybe ARP flooded, so check our time */
|
||||
if (get_time (&now) != 0)
|
||||
break;
|
||||
if (timercmp (&now, &stopat, >)) {
|
||||
timeout = 0;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (! FD_ISSET (iface->fd, &rset))
|
||||
continue;
|
||||
|
38
common.c
38
common.c
@ -79,6 +79,8 @@ size_t strlcpy (char *dst, const char *src, size_t size)
|
||||
/* This requires us to link to rt on glibc, so we use sysinfo instead */
|
||||
#ifdef __linux__
|
||||
#include <sys/sysinfo.h>
|
||||
/* Avoid clock_gettime as it requires librt on Linux */
|
||||
#undef CLOCK_MONOTONIC
|
||||
long uptime (void)
|
||||
{
|
||||
struct sysinfo info;
|
||||
@ -86,7 +88,19 @@ long uptime (void)
|
||||
sysinfo (&info);
|
||||
return info.uptime;
|
||||
}
|
||||
#elif __APPLE__
|
||||
#elif CLOCK_MONOTONIC
|
||||
long uptime (void)
|
||||
{
|
||||
struct timespec tp;
|
||||
|
||||
if (clock_gettime (CLOCK_MONOTONIC, &tp) == -1) {
|
||||
logger (LOG_ERR, "clock_gettime: %s", strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return tp.tv_sec;
|
||||
}
|
||||
#else
|
||||
/* Darwin doesn't appear to have an uptime, so try and make one ourselves */
|
||||
long uptime (void)
|
||||
{
|
||||
@ -103,27 +117,14 @@ long uptime (void)
|
||||
|
||||
return tv.tv_sec - start;
|
||||
}
|
||||
#else
|
||||
long uptime (void)
|
||||
{
|
||||
struct timespec tp;
|
||||
|
||||
if (clock_gettime (CLOCK_MONOTONIC, &tp) == -1) {
|
||||
logger (LOG_ERR, "clock_gettime: %s", strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return tp.tv_sec;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Handy function to get the time.
|
||||
* We only care about time advancements, not the actual time itself
|
||||
* Which is why we use CLOCK_MONOTONIC, but it is not available on all
|
||||
* platforms
|
||||
* platforms.
|
||||
*/
|
||||
#ifdef HAVE_GET_TIME
|
||||
# ifdef CLOCK_MONOTONIC
|
||||
#ifdef CLOCK_MONOTONIC
|
||||
int get_time (struct timeval *tp)
|
||||
{
|
||||
struct timespec ts;
|
||||
@ -137,16 +138,15 @@ int get_time (struct timeval *tp)
|
||||
tp->tv_usec = ts.tv_nsec / 1000;
|
||||
return (0);
|
||||
}
|
||||
# else
|
||||
#else
|
||||
int get_time (struct timeval *tp)
|
||||
{
|
||||
if (gettimeofday (&tp, NULL) == -1) {
|
||||
if (gettimeofday (tp, NULL) == -1) {
|
||||
logger (LOG_ERR, "gettimeofday: %s", strerror (errno));
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void *xmalloc (size_t s)
|
||||
|
4
common.h
4
common.h
@ -35,11 +35,9 @@ size_t strlcpy (char *dst, const char *src, size_t size);
|
||||
|
||||
#ifdef __linux__
|
||||
void srandomdev (void);
|
||||
#else
|
||||
#define HAVE_GET_TIME
|
||||
int get_time (struct timeval *tp);
|
||||
#endif
|
||||
|
||||
int get_time (struct timeval *tp);
|
||||
long uptime (void);
|
||||
void *xmalloc (size_t size);
|
||||
char *xstrdup (const char *str);
|
||||
|
Loading…
Reference in New Issue
Block a user