Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 187561 | Differences between
and this patch

Collapse All | Expand All

(-)arp.c (-19 / +49 lines)
Lines 24-30 Link Here
24
#include <sys/select.h>
24
#include <sys/select.h>
25
#include <sys/socket.h>
25
#include <sys/socket.h>
26
#include <netinet/in_systm.h>
26
#include <netinet/in_systm.h>
27
#ifdef __linux
27
#ifdef __linux__
28
#include <netinet/ether.h>
28
#include <netinet/ether.h>
29
#include <netpacket/packet.h>
29
#include <netpacket/packet.h>
30
#endif
30
#endif
Lines 69-76 Link Here
69
69
70
#ifdef ENABLE_ARP
70
#ifdef ENABLE_ARP
71
71
72
static int send_arp (interface_t *iface, int op, struct in_addr sip,
72
static int send_arp (const interface_t *iface, int op, struct in_addr sip,
73
					 unsigned char *taddr, struct in_addr tip)
73
					 const unsigned char *taddr, struct in_addr tip)
74
{
74
{
75
	struct arphdr *arp;
75
	struct arphdr *arp;
76
	int arpsize = arphdr_len2 (iface->hwlen, sizeof (struct in_addr));
76
	int arpsize = arphdr_len2 (iface->hwlen, sizeof (struct in_addr));
Lines 84-97 Link Here
84
	arp->ar_hln = iface->hwlen;
84
	arp->ar_hln = iface->hwlen;
85
	arp->ar_pln = sizeof (struct in_addr);
85
	arp->ar_pln = sizeof (struct in_addr);
86
	arp->ar_op = htons (op);
86
	arp->ar_op = htons (op);
87
	memcpy (ar_sha (arp), &iface->hwaddr, arp->ar_hln);
87
	memcpy (ar_sha (arp), iface->hwaddr, arp->ar_hln);
88
	memcpy (ar_spa (arp), &sip, arp->ar_pln);
88
	memcpy (ar_spa (arp), &sip, arp->ar_pln);
89
	if (taddr)
89
	if (taddr)
90
		memcpy (ar_tha (arp), taddr, arp->ar_hln); 
90
		memcpy (ar_tha (arp), taddr, arp->ar_hln); 
91
	memcpy (ar_tpa (arp), &tip, arp->ar_pln);
91
	memcpy (ar_tpa (arp), &tip, arp->ar_pln);
92
92
93
	logger (LOG_DEBUG, "about to send packet");
93
	retval = send_packet (iface, ETHERTYPE_ARP,
94
	retval = send_packet (iface, ETHERTYPE_ARP,
94
						  (unsigned char *) arp, arphdr_len (arp));
95
						  (unsigned char *) arp, arphdr_len (arp));
96
	logger (LOG_DEBUG, "sent packet");
95
	free (arp);
97
	free (arp);
96
	return (retval);
98
	return (retval);
97
}
99
}
Lines 105-110 Link Here
105
	int nprobes = 0;
107
	int nprobes = 0;
106
	int nclaims = 0;
108
	int nclaims = 0;
107
	struct in_addr null_address;
109
	struct in_addr null_address;
110
	struct timeval stopat;
111
	struct timeval now;
108
112
109
	if (! iface->arpable) {
113
	if (! iface->arpable) {
110
		logger (LOG_DEBUG, "interface `%s' is not ARPable", iface->name);
114
		logger (LOG_DEBUG, "interface `%s' is not ARPable", iface->name);
Lines 117-123 Link Here
117
	if (! open_socket (iface, true))
121
	if (! open_socket (iface, true))
118
		return (0);
122
		return (0);
119
123
120
	memset (&null_address, 0, sizeof (null_address));
124
	memset (&null_address, 0, sizeof (struct in_addr));
121
125
122
	buffer = xmalloc (sizeof (char *) * iface->buffer_length);
126
	buffer = xmalloc (sizeof (char *) * iface->buffer_length);
123
127
Lines 130-149 Link Here
130
		int buflen = sizeof (char *) * iface->buffer_length;
134
		int buflen = sizeof (char *) * iface->buffer_length;
131
		fd_set rset;
135
		fd_set rset;
132
		int bytes;
136
		int bytes;
133
		int s;
137
		int s = 0;
134
138
135
		tv.tv_sec = 0; 
139
		/* Only select if we have a timeout */
136
		tv.tv_usec = timeout;
140
		if (timeout > 0) {
141
			tv.tv_sec = 0; 
142
			tv.tv_usec = timeout;
137
143
138
		FD_ZERO (&rset);
144
			FD_ZERO (&rset);
139
		FD_SET (iface->fd, &rset);
145
			FD_SET (iface->fd, &rset);
140
		errno = 0;
146
141
		if ((s = select (FD_SETSIZE, &rset, NULL, NULL, &tv)) == -1) {
147
			errno = 0;
142
			if (errno != EINTR)
148
			if ((s = select (FD_SETSIZE, &rset, NULL, NULL, &tv)) == -1) {
143
				logger (LOG_ERR, "select: `%s'", strerror (errno));
149
				if (errno != EINTR)
144
			break;
150
					logger (LOG_ERR, "select: `%s'", strerror (errno));
145
		} else if (s == 0) {
151
				break;
146
			/* Timed out */
152
			}
153
		}
154
155
		/* Timed out */
156
		if (s == 0) {
147
			if (nprobes < NPROBES) {
157
			if (nprobes < NPROBES) {
148
				nprobes ++;
158
				nprobes ++;
149
				timeout = PROBE_INTERVAL;
159
				timeout = PROBE_INTERVAL;
Lines 159-166 Link Here
159
				retval = 0;
169
				retval = 0;
160
				break;
170
				break;
161
			}
171
			}
172
173
			/* Setup our stop time */
174
			if (get_time (&stopat) != 0)
175
				break;
176
			stopat.tv_usec += timeout;
177
178
			continue;
162
		}
179
		}
163
		
180
181
		logger (LOG_DEBUG, "checking time");
182
		/* We maybe ARP flooded, so check our time */
183
		if (get_time (&now) != 0)
184
			break;
185
		if (timercmp (&now, &stopat, >)) {
186
			timeout = 0;
187
			continue;
188
		}
189
190
		logger (LOG_DEBUG, "checking fd");
164
		if (! FD_ISSET (iface->fd, &rset))
191
		if (! FD_ISSET (iface->fd, &rset))
165
			continue;
192
			continue;
166
193
Lines 175-186 Link Here
175
				struct ether_addr *a;
202
				struct ether_addr *a;
176
			} rh;
203
			} rh;
177
204
205
			logger (LOG_DEBUG, "getting packet");
178
			memset (reply, 0, IP_MIN_FRAME_LENGTH);
206
			memset (reply, 0, IP_MIN_FRAME_LENGTH);
179
			if ((bytes = get_packet (iface, (unsigned char *) reply,
207
			if ((bytes = get_packet (iface, (unsigned char *) reply,
180
									 buffer,
208
									 buffer,
181
									 &buflen, &bufpos)) == -1)
209
									 &buflen, &bufpos)) == -1)
182
				break;
210
				break;
183
211
212
			logger (LOG_DEBUG, "got packet %d bytes", bytes);
184
			/* Only these types are recognised */
213
			/* Only these types are recognised */
185
			if (reply->ar_op != htons (ARPOP_REPLY))
214
			if (reply->ar_op != htons (ARPOP_REPLY))
186
				continue;
215
				continue;
Lines 194-202 Link Here
194
				2 * (4 + reply->ar_hln))
223
				2 * (4 + reply->ar_hln))
195
				continue;
224
				continue;
196
225
226
			logger (LOG_DEBUG, "assigning addresses to struc");
197
			rp.c = (unsigned char *) ar_spa (reply);
227
			rp.c = (unsigned char *) ar_spa (reply);
198
			rh.c = (unsigned char *) ar_sha (reply);
228
			rh.c = (unsigned char *) ar_sha (reply);
199
			
229
200
			/* Ensure the ARP reply is for the address we asked for */
230
			/* Ensure the ARP reply is for the address we asked for */
201
			if (rp.a->s_addr != address.s_addr)
231
			if (rp.a->s_addr != address.s_addr)
202
				continue;
232
				continue;
(-)Makefile (-5 / +9 lines)
Lines 1-4 Link Here
1
VERSION = 3.1.3
1
VERSION = 3.1.4_pre2
2
CFLAGS ?= -O2 -pipe
2
CFLAGS ?= -O2 -pipe
3
3
4
# Should work for both GNU make and BSD make
4
# Should work for both GNU make and BSD make
Lines 49-60 Link Here
49
dhcpcd_OBJS = arp.o client.o common.o configure.o dhcp.o dhcpcd.o duid.o \
49
dhcpcd_OBJS = arp.o client.o common.o configure.o dhcp.o dhcpcd.o duid.o \
50
		info.o interface.o ipv4ll.o logger.o signals.o socket.o
50
		info.o interface.o ipv4ll.o logger.o signals.o socket.o
51
51
52
# By default we don't need to link to anything
52
# These are nasty hacks to work out what libs we need to link to
53
# Except on Darwin where we need -lresolv, so they need to uncomment this
53
# We require librt for glibc bases systems
54
#dhcpcd_LIBS = -lresolv
54
LIBRT != ldd /bin/date 2>/dev/null | grep -q /librt.so && echo "-lrt" || exit 0
55
LIBRT ?= $(shell ldd /bin/date 2>/dev/null | grep -q /librt.so && echo "-lrt")
55
56
57
# Darwin needs this, but we have no way of detecting this atm
58
#LIBRESOLV = -lresolv
59
56
dhcpcd: $(dhcpcd_H) $(dhcpcd_OBJS)
60
dhcpcd: $(dhcpcd_H) $(dhcpcd_OBJS)
57
	$(CC) $(LDFLAGS) $(dhcpcd_OBJS) $(dhcpcd_LIBS) -o dhcpcd
61
	$(CC) $(LDFLAGS) $(dhcpcd_OBJS) $(LIBRT) $(LIBRESOLV) -o dhcpcd
58
62
59
version.h:
63
version.h:
60
	echo '#define VERSION "$(VERSION)"' > version.h
64
	echo '#define VERSION "$(VERSION)"' > version.h
(-)common.c (-8 / +13 lines)
Lines 76-92 Link Here
76
#  endif
76
#  endif
77
#endif
77
#endif
78
78
79
/* This requires us to link to rt on glibc, so we use sysinfo instead */
79
/* Handy function to get the time. */
80
#ifdef __linux__
80
int get_time(struct timeval *tp)
81
#include <sys/sysinfo.h>
82
long uptime (void)
83
{
81
{
84
	struct sysinfo info;
82
	struct timespec ts;
85
83
86
	sysinfo (&info);
84
	if (clock_gettime (CLOCK_MONOTONIC, &ts) == -1) {
87
	return info.uptime;
85
		logger (LOG_ERR, "clock_gettime: %s", strerror (errno));
86
		return (-1);
87
	}
88
89
	tp->tv_sec = ts.tv_sec;
90
	tp->tv_usec = ts.tv_nsec / 1000;
91
	return (0);
88
}
92
}
89
#elif __APPLE__
93
94
#ifdef __APPLE__
90
/* Darwin doesn't appear to have an uptime, so try and make one ourselves */
95
/* Darwin doesn't appear to have an uptime, so try and make one ourselves */
91
long uptime (void)
96
long uptime (void)
92
{
97
{
(-)common.h (+2 lines)
Lines 23-28 Link Here
23
#define COMMON_H
23
#define COMMON_H
24
24
25
/* string.h pulls in features.h so the below define checks work */
25
/* string.h pulls in features.h so the below define checks work */
26
#include <sys/time.h>
26
#include <string.h>
27
#include <string.h>
27
28
28
/* Only GLIBC doesn't support strlcpy */
29
/* Only GLIBC doesn't support strlcpy */
Lines 36-41 Link Here
36
void srandomdev (void);
37
void srandomdev (void);
37
#endif
38
#endif
38
39
40
int get_time(struct timeval *tp);
39
long uptime (void);
41
long uptime (void);
40
void *xmalloc (size_t size);
42
void *xmalloc (size_t size);
41
char *xstrdup (const char *str);
43
char *xstrdup (const char *str);

Return to bug 187561