diff options
author | David Heidelberger <david.heidelberger@ixit.cz> | 2014-05-09 02:47:34 +0200 |
---|---|---|
committer | David Heidelberger <david.heidelberger@ixit.cz> | 2014-05-09 02:47:54 +0200 |
commit | 58a13965a25de97f09e1327862180b0cb38723e4 (patch) | |
tree | 5e6bf3219881c03aa7c30168c89dcb59725198bd | |
parent | a5e9551311957bffac138fd1995a7870ae9119e6 (diff) | |
download | iputils-cleanup.tar.gz |
arping: remove libsysfs support, long time unsupportedcleanup
Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | arping.c | 265 |
2 files changed, 7 insertions, 273 deletions
@@ -14,7 +14,6 @@ LDFLAG_GNUTLS=-lgnutls-openssl LDFLAG_CRYPTO=-lcrypto LDFLAG_IDN=-lidn LDFLAG_RESOLV=-lresolv -LDFLAG_SYSFS=-lsysfs LDFLAG_RT=-lrt # @@ -23,8 +22,6 @@ LDFLAG_RT=-lrt # Capability support (with libcap) [yes|static|no] USE_CAP=yes -# sysfs support (with libsysfs - deprecated) [no|yes|static] -USE_SYSFS=no # IDN support (experimental) [no|yes|static] USE_IDN=no @@ -46,8 +43,6 @@ ENABLE_PING6_RTHDR=no ENABLE_RDISC_SERVER=no # ------------------------------------- -# What a pity, all new gccs are buggy and -Werror does not work. Sigh. -# CFLAGS+=-fno-strict-aliasing -Wstrict-prototypes -Wall -Werror -g CFLAGS?=-O3 -g CFLAGS+=-fno-strict-aliasing -Wstrict-prototypes -Wall CPPFLAGS+=-D_GNU_SOURCE @@ -76,12 +71,6 @@ ifneq ($(USE_CAP),no) LIB_CAP = $(call FUNC_LIB,$(USE_CAP),$(LDFLAG_CAP)) endif -# USE_SYSFS: DEF_SYSFS, LIB_SYSFS -ifneq ($(USE_SYSFS),no) - DEF_SYSFS = -DUSE_SYSFS - LIB_SYSFS = $(call FUNC_LIB,$(USE_SYSFS),$(LDFLAG_SYSFS)) -endif - # USE_IDN: DEF_IDN, LIB_IDN ifneq ($(USE_IDN),no) DEF_IDN = -DUSE_IDN @@ -135,8 +124,8 @@ $(TARGETS): %: %.o # ------------------------------------- # arping -DEF_arping = $(DEF_SYSFS) $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS) -LIB_arping = $(LIB_SYSFS) $(LIB_CAP) $(LIB_IDN) $(LDFLAG_RT) +DEF_arping = $(DEF_CAP) $(DEF_IDN) $(DEF_WITHOUT_IFADDRS) +LIB_arping = $(LIB_CAP) $(LIB_IDN) $(LDFLAG_RT) ifneq ($(ARPING_DEFAULT_DEVICE),) DEF_arping += -DDEFAULT_DEVICE=\"$(ARPING_DEFAULT_DEVICE)\" @@ -33,11 +33,6 @@ #include <netinet/in.h> #include <arpa/inet.h> -#ifdef USE_SYSFS -#include <sysfs/libsysfs.h> -struct sysfs_devattr_values; -#endif - #ifndef WITHOUT_IFADDRS #include <ifaddrs.h> #endif @@ -63,9 +58,6 @@ struct device { #ifndef WITHOUT_IFADDRS struct ifaddrs *ifa; #endif -#ifdef USE_SYSFS - struct sysfs_devattr_values *sysfs; -#endif }; int quit_on_reply=0; @@ -501,54 +493,6 @@ int recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) return 1; } -#ifdef USE_SYSFS -union sysfs_devattr_value { - unsigned long ulong; - void *ptr; -}; - -enum { - SYSFS_DEVATTR_IFINDEX, - SYSFS_DEVATTR_FLAGS, - SYSFS_DEVATTR_ADDR_LEN, - SYSFS_DEVATTR_BROADCAST, - SYSFS_DEVATTR_NUM -}; - -struct sysfs_devattr_values -{ - char *ifname; - union sysfs_devattr_value value[SYSFS_DEVATTR_NUM]; -}; - -static int sysfs_devattr_ulong_dec(char *ptr, struct sysfs_devattr_values *v, unsigned idx); -static int sysfs_devattr_ulong_hex(char *ptr, struct sysfs_devattr_values *v, unsigned idx); -static int sysfs_devattr_macaddr(char *ptr, struct sysfs_devattr_values *v, unsigned idx); - -struct sysfs_devattrs { - const char *name; - int (*handler)(char *ptr, struct sysfs_devattr_values *v, unsigned int idx); - int free; -} sysfs_devattrs[SYSFS_DEVATTR_NUM] = { - [SYSFS_DEVATTR_IFINDEX] = { - .name = "ifindex", - .handler = sysfs_devattr_ulong_dec, - }, - [SYSFS_DEVATTR_ADDR_LEN] = { - .name = "addr_len", - .handler = sysfs_devattr_ulong_dec, - }, - [SYSFS_DEVATTR_FLAGS] = { - .name = "flags", - .handler = sysfs_devattr_ulong_hex, - }, - [SYSFS_DEVATTR_BROADCAST] = { - .name = "broadcast", - .handler = sysfs_devattr_macaddr, - .free = 1, - }, -}; -#endif /* * find_device() @@ -570,7 +514,6 @@ struct sysfs_devattrs { * We have several implementations for this. * by_ifaddrs(): requires getifaddr() in glibc, and rtnetlink in * kernel. default and recommended for recent systems. - * by_sysfs(): requires libsysfs , and sysfs in kernel. * by_ioctl(): unable to list devices without ipv4 address; this * means, you need to supply the device name for * DAD purpose. @@ -648,181 +591,6 @@ static int find_device_by_ifaddrs(void) #endif } -#ifdef USE_SYSFS -static void sysfs_devattr_values_init(struct sysfs_devattr_values *v, int do_free) -{ - int i; - if (do_free) { - free(v->ifname); - for (i = 0; i < SYSFS_DEVATTR_NUM; i++) { - if (sysfs_devattrs[i].free) - free(v->value[i].ptr); - } - } - memset(v, 0, sizeof(*v)); -} - -static int sysfs_devattr_ulong(char *ptr, struct sysfs_devattr_values *v, unsigned int idx, - unsigned int base) -{ - unsigned long *p; - char *ep; - - if (!ptr || !v) - return -1; - - p = &v->value[idx].ulong; - errno = 0; - *p = strtoul(ptr, &ep, base); - if ((*ptr && isspace(*ptr & 0xff)) || errno || (*ep != '\0' && *ep != '\n')) - goto out; - - return 0; -out: - return -1; -} - -static int sysfs_devattr_ulong_dec(char *ptr, struct sysfs_devattr_values *v, unsigned int idx) -{ - int rc = sysfs_devattr_ulong(ptr, v, idx, 10); - return rc; -} - -static int sysfs_devattr_ulong_hex(char *ptr, struct sysfs_devattr_values *v, unsigned int idx) -{ - int rc = sysfs_devattr_ulong(ptr, v, idx, 16); - return rc; -} - -static int sysfs_devattr_macaddr(char *ptr, struct sysfs_devattr_values *v, unsigned int idx) -{ - unsigned char *m; - int i; - unsigned int addrlen; - - if (!ptr || !v) - return -1; - - addrlen = v->value[SYSFS_DEVATTR_ADDR_LEN].ulong; - m = malloc(addrlen); - - for (i = 0; i < addrlen; i++) { - if (i && *(ptr + i * 3 - 1) != ':') - goto out; - if (sscanf(ptr + i * 3, "%02hhx", &m[i]) != 1) - goto out; - } - - v->value[idx].ptr = m; - return 0; -out: - free(m); - return -1; -} -#endif - -int find_device_by_sysfs(void) -{ - int rc = -1; -#ifdef USE_SYSFS - struct sysfs_class *cls_net; - struct dlist *dev_list; - struct sysfs_class_device *dev; - struct sysfs_attribute *dev_attr; - struct sysfs_devattr_values sysfs_devattr_values; - int n = 0; - - if (!device.sysfs) { - device.sysfs = malloc(sizeof(*device.sysfs)); - sysfs_devattr_values_init(device.sysfs, 0); - } - - cls_net = sysfs_open_class("net"); - if (!cls_net) { - perror("sysfs_open_class"); - return -1; - } - - dev_list = sysfs_get_class_devices(cls_net); - if (!dev_list) { - perror("sysfs_get_class_devices"); - goto out; - } - - sysfs_devattr_values_init(&sysfs_devattr_values, 0); - - dlist_for_each_data(dev_list, dev, struct sysfs_class_device) { - int i; - int rc = -1; - - if (device.name && strcmp(dev->name, device.name)) - goto do_next; - - sysfs_devattr_values_init(&sysfs_devattr_values, 1); - - for (i = 0; i < SYSFS_DEVATTR_NUM; i++) { - - dev_attr = sysfs_get_classdev_attr(dev, sysfs_devattrs[i].name); - if (!dev_attr) { - perror("sysfs_get_classdev_attr"); - rc = -1; - break; - } - if (sysfs_read_attribute(dev_attr)) { - perror("sysfs_read_attribute"); - rc = -1; - break; - } - rc = sysfs_devattrs[i].handler(dev_attr->value, &sysfs_devattr_values, i); - - if (rc < 0) - break; - } - - if (rc < 0) - goto do_next; - - if (check_ifflags(sysfs_devattr_values.value[SYSFS_DEVATTR_FLAGS].ulong, - device.name != NULL) < 0) - goto do_next; - - if (!sysfs_devattr_values.value[SYSFS_DEVATTR_ADDR_LEN].ulong) - goto do_next; - - if (device.sysfs->value[SYSFS_DEVATTR_IFINDEX].ulong) { - if (device.sysfs->value[SYSFS_DEVATTR_FLAGS].ulong & IFF_RUNNING) - goto do_next; - } - - sysfs_devattr_values.ifname = strdup(dev->name); - if (!sysfs_devattr_values.ifname) { - perror("malloc"); - goto out; - } - - sysfs_devattr_values_init(device.sysfs, 1); - memcpy(device.sysfs, &sysfs_devattr_values, sizeof(*device.sysfs)); - sysfs_devattr_values_init(&sysfs_devattr_values, 0); - - if (n++) - break; - - continue; -do_next: - sysfs_devattr_values_init(&sysfs_devattr_values, 1); - } - - if (n == 1) { - device.ifindex = device.sysfs->value[SYSFS_DEVATTR_IFINDEX].ulong; - device.name = device.sysfs->ifname; - } - rc = !device.ifindex; -out: - sysfs_close_class(cls_net); -#endif - return rc; -} - static int check_device_by_ioctl(int s, struct ifreq *ifr) { if (ioctl(s, SIOCGIFFLAGS, ifr) < 0) { @@ -921,9 +689,6 @@ static int find_device(void) rc = find_device_by_ifaddrs(); if (rc >= 0) goto out; - rc = find_device_by_sysfs(); - if (rc >= 0) - goto out; rc = find_device_by_ioctl(); out: return rc; @@ -964,23 +729,6 @@ static int set_device_broadcast_ifaddrs_one(struct device *device, unsigned char return -1; #endif } -int set_device_broadcast_sysfs(struct device *device, unsigned char *ba, size_t balen) -{ -#ifdef USE_SYSFS - struct sysfs_devattr_values *v; - if (!device) - return -1; - v = device->sysfs; - if (!v) - return -1; - if (v->value[SYSFS_DEVATTR_ADDR_LEN].ulong != balen) - return -1; - memcpy(ba, v->value[SYSFS_DEVATTR_BROADCAST].ptr, balen); - return 0; -#else - return -1; -#endif -} static int set_device_broadcast_fallback(struct device *device, unsigned char *ba, size_t balen) { @@ -994,8 +742,6 @@ static void set_device_broadcast(struct device *dev, unsigned char *ba, size_t b { if (!set_device_broadcast_ifaddrs_one(dev, ba, balen, 0)) return; - if (!set_device_broadcast_sysfs(dev, ba, balen)) - return; set_device_broadcast_fallback(dev, ba, balen); } @@ -1179,13 +925,12 @@ main(int argc, char **argv) exit(2); } - if (1) { - socklen_t alen = sizeof(me); - if (getsockname(s, (struct sockaddr*)&me, &alen) == -1) { - perror("getsockname"); - exit(2); - } + socklen_t alen = sizeof(me); + if (getsockname(s, (struct sockaddr*)&me, &alen) == -1) { + perror("getsockname"); + exit(2); } + if (((struct sockaddr_ll *)&me)->sll_halen == 0) { if (!quiet) printf("Interface \"%s\" is not ARPable (no ll address)\n", device.name); |