summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Ross <andy.ross@windriver.com>2012-08-06 12:41:04 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-08-07 12:58:02 +0100
commit99e6ed0b468d0269c432e250e90e3d0d96b709f1 (patch)
tree09a11025d2f90d3732790daba2704d267edde39a
parent89886d93591372fdf28ffbf5b16c28ea399c6f0c (diff)
downloadpoky-99e6ed0b468d0269c432e250e90e3d0d96b709f1.tar.gz
iputils: Break libsysfs dependency
iputils drops a /bin/arping with a runtime linkage against libsysfs in /usr. Port Fedora 17 iputils-20071127-infiniband.patch, which inlines access previously done by libsysfs. (From OE-Core rev: 99c482124e9f476923f6d5cf0a9e5551507f9d14) Signed-off-by: Andy Ross <andy.ross@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-extended/iputils/files/arping-break-libsysfs-dependency.patch296
-rw-r--r--meta/recipes-extended/iputils/iputils_s20101006.bb5
2 files changed, 299 insertions, 2 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
diff --git a/meta/recipes-extended/iputils/iputils_s20101006.bb b/meta/recipes-extended/iputils/iputils_s20101006.bb
index 394ab5803c..62e2b5e364 100644
--- a/meta/recipes-extended/iputils/iputils_s20101006.bb
+++ b/meta/recipes-extended/iputils/iputils_s20101006.bb
@@ -11,9 +11,9 @@ LIC_FILES_CHKSUM = "file://ping.c;beginline=1;endline=35;md5=f9ceb201733e9a6cf8f
11 file://arping.c;beginline=1;endline=10;md5=ada2a6d06acc90f943bddf40d15e0541 \ 11 file://arping.c;beginline=1;endline=10;md5=ada2a6d06acc90f943bddf40d15e0541 \
12 file://tftpd.c;beginline=1;endline=32;md5=28834bf8a91a5b8a92755dbee709ef96 " 12 file://tftpd.c;beginline=1;endline=32;md5=28834bf8a91a5b8a92755dbee709ef96 "
13 13
14DEPENDS = "sysfsutils openssl docbook-utils-native sgmlspl-native" 14DEPENDS = "openssl docbook-utils-native sgmlspl-native"
15 15
16PR = "r4" 16PR = "r5"
17 17
18SRC_URI = "http://www.skbuff.net/iputils/${BPN}-${PV}.tar.bz2 \ 18SRC_URI = "http://www.skbuff.net/iputils/${BPN}-${PV}.tar.bz2 \
19 file://debian/fix-dead-host-ping-stats.diff \ 19 file://debian/fix-dead-host-ping-stats.diff \
@@ -22,6 +22,7 @@ SRC_URI = "http://www.skbuff.net/iputils/${BPN}-${PV}.tar.bz2 \
22 file://debian/targets.diff \ 22 file://debian/targets.diff \
23 file://debian/fix-arping-timeouts.diff \ 23 file://debian/fix-arping-timeouts.diff \
24 file://nsgmls-path-fix.patch \ 24 file://nsgmls-path-fix.patch \
25 file://arping-break-libsysfs-dependency.patch \
25 " 26 "
26 27
27SRC_URI[md5sum] = "a36c25e9ec17e48be514dc0485e7376c" 28SRC_URI[md5sum] = "a36c25e9ec17e48be514dc0485e7376c"