summaryrefslogtreecommitdiffstats
path: root/meta/recipes-extended/iputils/files
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-extended/iputils/files')
-rw-r--r--meta/recipes-extended/iputils/files/arping-break-libsysfs-dependency.patch296
1 files changed, 296 insertions, 0 deletions
diff --git a/meta/recipes-extended/iputils/files/arping-break-libsysfs-dependency.patch b/meta/recipes-extended/iputils/files/arping-break-libsysfs-dependency.patch
new file mode 100644
index 0000000000..37325ee0ae
--- /dev/null
+++ b/meta/recipes-extended/iputils/files/arping-break-libsysfs-dependency.patch
@@ -0,0 +1,296 @@
1arping: Break libsysfs dependency
2
3Port Fedora 17's iputils-20071127-infiniband.patch, which inlines sysfs
4access previously done by libsysfs (which is in /usr, and thus not
5usable by /bin/arping).
6
7Upstream-Status: Inappropriate [not author]
8Signed-off-by: Andy Ross <andy.ross@windriver.com>
9---
10 Makefile | 2 +-
11 arping.c | 152 ++++++++++++++++++++++++++++++++++++++++++++------------------
12 2 files changed, 109 insertions(+), 45 deletions(-)
13
14diff --git a/Makefile b/Makefile
15index d9a5ca5..943f048 100644
16--- a/Makefile
17+++ b/Makefile
18@@ -27,7 +27,7 @@ all: $(TARGETS)
19
20
21 tftpd: tftpd.o tftpsubs.o
22-arping: arping.o -lsysfs
23+arping: arping.o
24 ping: ping.o ping_common.o
25 ping6: ping6.o ping_common.o -lresolv -lcrypto
26 ping.o ping6.o ping_common.o: ping_common.h
27diff --git a/arping.c b/arping.c
28index 13484de..6379354 100644
29--- a/arping.c
30+++ b/arping.c
31@@ -32,8 +32,6 @@
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34
35-#include <sysfs/libsysfs.h>
36-
37 #include "SNAPSHOT.h"
38
39 static void usage(void) __attribute__((noreturn));
40@@ -52,14 +50,22 @@ int unicasting;
41 int s;
42 int broadcast_only;
43
44-struct sockaddr_storage me;
45-struct sockaddr_storage he;
46+struct sockaddr_ll *me=NULL;
47+struct sockaddr_ll *he=NULL;
48
49 struct timeval start, last;
50
51 int sent, brd_sent;
52 int received, brd_recv, req_recv;
53
54+#define SYSFS_MNT_PATH "/sys"
55+#define SYSFS_CLASS "class"
56+#define SYSFS_NET "net"
57+#define SYSFS_BROADCAST "broadcast"
58+#define SYSFS_PATH_ENV "SYSFS_PATH"
59+#define SYSFS_PATH_LEN 256
60+#define SOCKADDR_LEN (2 * sizeof(struct sockaddr_ll))
61+
62 #define MS_TDIFF(tv1,tv2) ( ((tv1).tv_sec-(tv2).tv_sec)*1000 + \
63 ((tv1).tv_usec-(tv2).tv_usec)/1000 )
64
65@@ -166,6 +172,10 @@ void finish(void)
66 printf("\n");
67 fflush(stdout);
68 }
69+
70+ free(me);
71+ free(he);
72+
73 if (dad)
74 exit(!!received);
75 if (unsolicited)
76@@ -189,8 +199,7 @@ void catcher(void)
77 finish();
78
79 if ( count!=0 && (last.tv_sec==0 || MS_TDIFF(tv,last) > 500 ) ) {
80- send_pack(s, src, dst,
81- (struct sockaddr_ll *)&me, (struct sockaddr_ll *)&he);
82+ send_pack(s, src, dst, me, he);
83 if (count >= 0)
84 count--;
85 if (count == 0 && unsolicited)
86@@ -239,7 +248,7 @@ int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
87 return 0;
88 if (ah->ar_pln != 4)
89 return 0;
90- if (ah->ar_hln != ((struct sockaddr_ll *)&me)->sll_halen)
91+ if (ah->ar_hln != me->sll_halen)
92 return 0;
93 if (len < sizeof(*ah) + 2*(4 + ah->ar_hln))
94 return 0;
95@@ -250,7 +259,7 @@ int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
96 return 0;
97 if (src.s_addr != dst_ip.s_addr)
98 return 0;
99- if (memcmp(p+ah->ar_hln+4, ((struct sockaddr_ll *)&me)->sll_addr, ah->ar_hln))
100+ if (memcmp(p+ah->ar_hln+4, me->sll_addr, ah->ar_hln))
101 return 0;
102 } else {
103 /* DAD packet was:
104@@ -268,7 +277,7 @@ int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
105 */
106 if (src_ip.s_addr != dst.s_addr)
107 return 0;
108- if (memcmp(p, ((struct sockaddr_ll *)&me)->sll_addr, ((struct sockaddr_ll *)&me)->sll_halen) == 0)
109+ if (memcmp(p, me->sll_addr, me->sll_halen) == 0)
110 return 0;
111 if (src.s_addr && src.s_addr != dst_ip.s_addr)
112 return 0;
113@@ -284,7 +293,7 @@ int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
114 printf("for %s ", inet_ntoa(dst_ip));
115 s_printed = 1;
116 }
117- if (memcmp(p+ah->ar_hln+4, ((struct sockaddr_ll *)&me)->sll_addr, ah->ar_hln)) {
118+ if (memcmp(p+ah->ar_hln+4, me->sll_addr, ah->ar_hln)) {
119 if (!s_printed)
120 printf("for ");
121 printf("[");
122@@ -310,40 +319,67 @@ int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM)
123 if (quit_on_reply)
124 finish();
125 if(!broadcast_only) {
126- memcpy(((struct sockaddr_ll *)&he)->sll_addr, p, ((struct sockaddr_ll *)&me)->sll_halen);
127+ memcpy(he->sll_addr, p, me->sll_halen);
128 unicasting=1;
129 }
130 return 1;
131 }
132
133-void set_device_broadcast(char *device, unsigned char *ba, size_t balen)
134+int get_sysfs_mnt_path(char *mnt_path, size_t len)
135 {
136- struct sysfs_class_device *dev;
137- struct sysfs_attribute *brdcast;
138- unsigned char *p;
139- int ch;
140+ const char *sysfs_path_env;
141+ int pth_len=0;
142
143- dev = sysfs_open_class_device("net", device);
144- if (!dev) {
145- perror("sysfs_open_class_device(net)");
146- exit(2);
147- }
148+ if (len == 0 || mnt_path == NULL)
149+ return -1;
150
151- brdcast = sysfs_get_classdev_attr(dev, "broadcast");
152- if (!brdcast) {
153- perror("sysfs_get_classdev_attr(broadcast)");
154- exit(2);
155- }
156+ /* possible overrride of real mount path */
157+ sysfs_path_env = getenv(SYSFS_PATH_ENV);
158+ memset(mnt_path, 0, len);
159+ strncpy(mnt_path,
160+ sysfs_path_env != NULL ? sysfs_path_env : SYSFS_MNT_PATH,
161+ len-1);
162
163- if (sysfs_read_attribute(brdcast)) {
164- perror("sysfs_read_attribute");
165- exit(2);
166- }
167+ if ((pth_len = strlen(mnt_path)) > 0 && mnt_path[pth_len-1] == '/')
168+ mnt_path[pth_len-1] = '\0';
169+
170+ return 0;
171+}
172+
173+int make_sysfs_broadcast_path(char *broadcast_path, size_t len)
174+{
175+ char mnt_path[SYSFS_PATH_LEN];
176+
177+ if (get_sysfs_mnt_path(mnt_path, len) != 0)
178+ return -1;
179
180- for (p = ba, ch = 0; p < ba + balen; p++, ch += 3)
181- *p = strtoul(brdcast->value + ch, NULL, 16);
182+ snprintf(broadcast_path, len,
183+ "%s/" SYSFS_CLASS "/" SYSFS_NET "/%s/" SYSFS_BROADCAST,
184+ mnt_path, device);
185
186- return;
187+ return 0;
188+}
189+
190+char * read_sysfs_broadcast(char *brdcast_path)
191+{
192+ int fd;
193+ int len_to_read;
194+ char *brdcast = NULL;
195+
196+ if ((fd = open(brdcast_path, O_RDONLY)) > -1) {
197+ len_to_read = lseek(fd, 0L, SEEK_END);
198+ if ((brdcast = malloc(len_to_read+1)) != NULL) {
199+ lseek(fd, 0L, SEEK_SET);
200+ memset(brdcast, 0, len_to_read+1);
201+ if (read(fd, brdcast, len_to_read) == -1) {
202+ free(brdcast);
203+ brdcast = NULL;
204+ }
205+ }
206+ close(fd);
207+ }
208+
209+ return brdcast;
210 }
211
212 int
213@@ -361,6 +397,17 @@ main(int argc, char **argv)
214 exit(-1);
215 }
216
217+ me = malloc(SOCKADDR_LEN);
218+ if (!me) {
219+ fprintf(stderr, "arping: could not allocate memory\n");
220+ exit(1);
221+ }
222+ he = malloc(SOCKADDR_LEN);
223+ if (!he) {
224+ fprintf(stderr, "arping: could not allocate memory\n");
225+ exit(1);
226+ }
227+
228 while ((ch = getopt(argc, argv, "h?bfDUAqc:w:s:I:V")) != EOF) {
229 switch(ch) {
230 case 'b':
231@@ -509,34 +556,51 @@ main(int argc, char **argv)
232 close(probe_fd);
233 };
234
235- ((struct sockaddr_ll *)&me)->sll_family = AF_PACKET;
236- ((struct sockaddr_ll *)&me)->sll_ifindex = ifindex;
237- ((struct sockaddr_ll *)&me)->sll_protocol = htons(ETH_P_ARP);
238- if (bind(s, (struct sockaddr*)&me, sizeof(me)) == -1) {
239+ me->sll_family = AF_PACKET;
240+ me->sll_ifindex = ifindex;
241+ me->sll_protocol = htons(ETH_P_ARP);
242+ if (bind(s, (struct sockaddr*)me, SOCKADDR_LEN) == -1) {
243 perror("bind");
244 exit(2);
245 }
246
247 if (1) {
248- socklen_t alen = sizeof(me);
249- if (getsockname(s, (struct sockaddr*)&me, &alen) == -1) {
250+ socklen_t alen = SOCKADDR_LEN;
251+ if (getsockname(s, (struct sockaddr*)me, &alen) == -1) {
252 perror("getsockname");
253 exit(2);
254 }
255 }
256- if (((struct sockaddr_ll *)&me)->sll_halen == 0) {
257+ if (me->sll_halen == 0) {
258 if (!quiet)
259 printf("Interface \"%s\" is not ARPable (no ll address)\n", device);
260 exit(dad?0:2);
261 }
262
263- he = me;
264+ memcpy(he, me, SOCKADDR_LEN);
265
266 #if 1
267- set_device_broadcast(device, ((struct sockaddr_ll *)&he)->sll_addr,
268- ((struct sockaddr_ll *)&he)->sll_halen);
269+ char brdcast_path[SYSFS_PATH_LEN];
270+ char *brdcast_val=NULL;
271+ char *next_ch;
272+
273+ if (make_sysfs_broadcast_path(brdcast_path, sizeof brdcast_path) != 0) {
274+ perror("sysfs attribute broadcast");
275+ exit(2);
276+ }
277+
278+ if ((brdcast_val = read_sysfs_broadcast(brdcast_path)) == NULL) {
279+ perror("sysfs read broadcast value");
280+ exit(2);
281+ }
282+
283+ for (ch=0; ch<he->sll_halen; ch++) {
284+ he->sll_addr[ch] = strtol(brdcast_val + (ch*3), &next_ch, 16);
285+ }
286+
287+ free(brdcast_val);
288 #else
289- memset(((struct sockaddr_ll *)&he)->sll_addr, -1, ((struct sockaddr_ll *)&he)->sll_halen);
290+ memset(he->sll_addr, -1, he->sll_halen);
291 #endif
292
293 if (!quiet) {
294--
2951.7.10.4
296