]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blobdiff - iputils/patches/iputils-s20071127-arping-infiniband.patch
Move all packages to root.
[people/ms/ipfire-3.x.git] / iputils / patches / iputils-s20071127-arping-infiniband.patch
diff --git a/iputils/patches/iputils-s20071127-arping-infiniband.patch b/iputils/patches/iputils-s20071127-arping-infiniband.patch
new file mode 100644 (file)
index 0000000..9884b70
--- /dev/null
@@ -0,0 +1,244 @@
+diff -up iputils-s20071127/arping.c.infiniband iputils-s20071127/arping.c
+--- iputils-s20071127/arping.c.infiniband      2007-11-27 01:57:27.000000000 +0100
++++ iputils-s20071127/arping.c 2008-08-08 10:05:04.000000000 +0200
+@@ -50,14 +50,26 @@ int unicasting;
+ int s;
+ int broadcast_only;
+-struct sockaddr_ll me;
+-struct sockaddr_ll he;
++/*
++ * Make these two structs have padding at the end so the overly long Infiniband
++ * hardware addresses can have the remainder of their address tacked onto
++ * the end of the struct without overlapping anything.
++ */
++struct sockaddr_ll me[2];
++struct sockaddr_ll he[2];
+ struct timeval start, last;
+ int sent, brd_sent;
+ int received, brd_recv, req_recv;
++#define SYSFS_MNT_PATH          "/sys"
++#define SYSFS_CLASS             "class"
++#define SYSFS_NET               "net"
++#define SYSFS_BROADCAST         "broadcast"
++#define SYSFS_PATH_ENV          "SYSFS_PATH"
++#define SYSFS_PATH_LEN          256
++
+ #define MS_TDIFF(tv1,tv2) ( ((tv1).tv_sec-(tv2).tv_sec)*1000 + \
+                          ((tv1).tv_usec-(tv2).tv_usec)/1000 )
+@@ -124,7 +136,8 @@ int send_pack(int s, struct in_addr src,
+       p+=4;
+       gettimeofday(&now, NULL);
+-      err = sendto(s, buf, p-buf, 0, (struct sockaddr*)HE, sizeof(*HE));
++      err = sendto(s, buf, p-buf, 0, (struct sockaddr*)HE, (ah->ar_hln > 8) ?
++                   sizeof(*HE) + ah->ar_hln - 8 : sizeof(*HE));
+       if (err == p-buf) {
+               last = now;
+               sent++;
+@@ -172,7 +185,7 @@ void catcher(void)
+               finish();
+       if (last.tv_sec==0 || MS_TDIFF(tv,last) > 500) {
+-              send_pack(s, src, dst, &me, &he);
++              send_pack(s, src, dst, &me[0], &he[0]);
+               if (count == 0 && unsolicited)
+                       finish();
+       }
+@@ -219,7 +232,7 @@ int recv_pack(unsigned char *buf, int le
+               return 0;
+       if (ah->ar_pln != 4)
+               return 0;
+-      if (ah->ar_hln != me.sll_halen)
++      if (ah->ar_hln != me[0].sll_halen)
+               return 0;
+       if (len < sizeof(*ah) + 2*(4 + ah->ar_hln))
+               return 0;
+@@ -230,7 +243,7 @@ int recv_pack(unsigned char *buf, int le
+                       return 0;
+               if (src.s_addr != dst_ip.s_addr)
+                       return 0;
+-              if (memcmp(p+ah->ar_hln+4, &me.sll_addr, ah->ar_hln))
++              if (memcmp(p+ah->ar_hln+4, &me[0].sll_addr, ah->ar_hln))
+                       return 0;
+       } else {
+               /* DAD packet was:
+@@ -248,7 +261,7 @@ int recv_pack(unsigned char *buf, int le
+                */
+               if (src_ip.s_addr != dst.s_addr)
+                       return 0;
+-              if (memcmp(p, &me.sll_addr, me.sll_halen) == 0)
++              if (memcmp(p, &me[0].sll_addr, me[0].sll_halen) == 0)
+                       return 0;
+               if (src.s_addr && src.s_addr != dst_ip.s_addr)
+                       return 0;
+@@ -264,7 +277,7 @@ int recv_pack(unsigned char *buf, int le
+                       printf("for %s ", inet_ntoa(dst_ip));
+                       s_printed = 1;
+               }
+-              if (memcmp(p+ah->ar_hln+4, me.sll_addr, ah->ar_hln)) {
++              if (memcmp(p+ah->ar_hln+4, me[0].sll_addr, ah->ar_hln)) {
+                       if (!s_printed)
+                               printf("for ");
+                       printf("[");
+@@ -290,12 +303,69 @@ int recv_pack(unsigned char *buf, int le
+       if (quit_on_reply)
+               finish();
+       if(!broadcast_only) {
+-              memcpy(he.sll_addr, p, me.sll_halen);
++              memcpy(he[0].sll_addr, p, me[0].sll_halen);
+               unicasting=1;
+       }
+       return 1;
+ }
++int get_sysfs_mnt_path(char *mnt_path, size_t len)
++{
++        const char *sysfs_path_env;
++        int pth_len=0;
++
++        if (len == 0 || mnt_path == NULL)
++                return -1;
++
++        /* possible overrride of real mount path */
++        sysfs_path_env = getenv(SYSFS_PATH_ENV);
++        memset(mnt_path, 0, len);
++        strncpy(mnt_path,
++                sysfs_path_env != NULL ? sysfs_path_env : SYSFS_MNT_PATH,
++                len-1);
++
++        if ((pth_len = strlen(mnt_path)) > 0 && mnt_path[pth_len-1] == '/')
++                mnt_path[pth_len-1] = '\0';
++
++        return 0;
++}
++
++int make_sysfs_broadcast_path(char *broadcast_path, size_t len)
++{
++        char mnt_path[SYSFS_PATH_LEN];
++
++        if (get_sysfs_mnt_path(mnt_path, len) != 0)
++                return -1;
++
++        snprintf(broadcast_path, len,
++                "%s/" SYSFS_CLASS "/" SYSFS_NET "/%s/" SYSFS_BROADCAST,
++                mnt_path, device);
++
++        return 0;
++}
++
++char * read_sysfs_broadcast(char *brdcast_path)
++{
++        int fd;
++        int len_to_read;
++        char *brdcast = NULL;
++
++        if ((fd = open(brdcast_path, O_RDONLY)) > -1) {
++                len_to_read = lseek(fd, 0L, SEEK_END);
++                if ((brdcast = malloc(len_to_read+1)) != NULL) {
++                        lseek(fd, 0L, SEEK_SET);
++                        memset(brdcast, 0, len_to_read+1);
++                        if (read(fd, brdcast, len_to_read) == -1) {
++                                free(brdcast);
++                                brdcast = NULL;
++                        }
++                }
++                close(fd);
++        }
++
++        return brdcast;
++}
++
+ int
+ main(int argc, char **argv)
+ {
+@@ -459,9 +529,9 @@ main(int argc, char **argv)
+               close(probe_fd);
+       };
+-      me.sll_family = AF_PACKET;
+-      me.sll_ifindex = ifindex;
+-      me.sll_protocol = htons(ETH_P_ARP);
++      me[0].sll_family = AF_PACKET;
++      me[0].sll_ifindex = ifindex;
++      me[0].sll_protocol = htons(ETH_P_ARP);
+       if (bind(s, (struct sockaddr*)&me, sizeof(me)) == -1) {
+               perror("bind");
+               exit(2);
+@@ -474,14 +544,33 @@ main(int argc, char **argv)
+                       exit(2);
+               }
+       }
+-      if (me.sll_halen == 0) {
++      if (me[0].sll_halen == 0) {
+               if (!quiet)
+                       printf("Interface \"%s\" is not ARPable (no ll address)\n", device);
+               exit(dad?0:2);
+       }
++      he[0] = me[0];
++      he[1] = me[1];
++      {
++                char brdcast_path[SYSFS_PATH_LEN];
++                char *brdcast_val;
++                char *next_ch;
++
++                if (make_sysfs_broadcast_path(brdcast_path, sizeof brdcast_path) != 0) {
++                        perror("sysfs attribute broadcast");
++                        exit(2);
++                }
++
++                if ((brdcast_val = read_sysfs_broadcast(brdcast_path)) == NULL) {
++                        perror("sysfs read broadcast value");
++                        exit(2);
++                }
++                for (ch=0; ch<he[0].sll_halen; ch++) {
++                        he[0].sll_addr[ch] = strtol(brdcast_val + (ch*3), &next_ch, 16);
++                }
+-      he = me;
+-      memset(he.sll_addr, -1, he.sll_halen);
++                free(brdcast_val);
++      }
+       if (!quiet) {
+               printf("ARPING %s ", inet_ntoa(dst));
+@@ -501,12 +590,12 @@ main(int argc, char **argv)
+       while(1) {
+               sigset_t sset, osset;
+               unsigned char packet[4096];
+-              struct sockaddr_ll from;
++              struct sockaddr_ll from[2];
+               socklen_t alen = sizeof(from);
+               int cc;
+               if ((cc = recvfrom(s, packet, sizeof(packet), 0,
+-                                 (struct sockaddr *)&from, &alen)) < 0) {
++                                 (struct sockaddr *)&from[0], &alen)) < 0) {
+                       perror("arping: recvfrom");
+                       continue;
+               }
+@@ -514,7 +603,7 @@ main(int argc, char **argv)
+               sigaddset(&sset, SIGALRM);
+               sigaddset(&sset, SIGINT);
+               sigprocmask(SIG_BLOCK, &sset, &osset);
+-              recv_pack(packet, cc, &from);
++              recv_pack(packet, cc, &from[0]);
+               sigprocmask(SIG_SETMASK, &osset, NULL);
+       }
+ }
+diff -up iputils-s20071127/Makefile.infiniband iputils-s20071127/Makefile
+--- iputils-s20071127/Makefile.infiniband      2008-08-08 09:17:35.000000000 +0200
++++ iputils-s20071127/Makefile 2008-08-08 10:02:10.000000000 +0200
+@@ -37,6 +37,8 @@ rdisc_srv: rdisc_srv.o
+ rdisc_srv.o: rdisc.c
+       $(CC) $(CFLAGS) -DRDISC_SERVER -o rdisc_srv.o rdisc.c
++arping: arping.o
++      $(CC) $(LDFLAGS) arping.o $(LOADLIBES) $(LDLIBS) -o arping
+ check-kernel:
+ ifeq ($(KERNEL_INCLUDE),)