diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-19 12:11:20 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-19 12:11:20 +0000 |
| commit | 08a61180ceeafaa09e33ef5afc8af45a219ccdf1 (patch) | |
| tree | fae0cd596fffa42de37bab5d70318cd576278bc3 | |
| parent | 2d25491ed0836a50c6c1c107090d8f72b87ef71d (diff) | |
| download | busybox-w32-08a61180ceeafaa09e33ef5afc8af45a219ccdf1.tar.gz busybox-w32-08a61180ceeafaa09e33ef5afc8af45a219ccdf1.tar.bz2 busybox-w32-08a61180ceeafaa09e33ef5afc8af45a219ccdf1.zip | |
ll_map: disable interface name caching code
function old new delta
find_by_index - 26 +26
static.icache 4 - -4
ll_idx_n2a 71 59 -12
static.ncache 16 - -16
ll_index_to_flags 40 24 -16
xll_name_to_index 206 104 -102
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 0/3 up/down: 26/-150) Total: -124 bytes
text data bss dec hex filename
734703 3040 14440 752183 b7a37 busybox_old
734599 3040 14416 752055 b79b7 busybox_unstripped
| -rw-r--r-- | networking/libiproute/ll_map.c | 77 | ||||
| -rw-r--r-- | networking/libiproute/ll_map.h | 14 |
2 files changed, 51 insertions, 40 deletions
diff --git a/networking/libiproute/ll_map.c b/networking/libiproute/ll_map.c index eb9b0a4ff..e8a8279b0 100644 --- a/networking/libiproute/ll_map.c +++ b/networking/libiproute/ll_map.c | |||
| @@ -11,26 +11,34 @@ | |||
| 11 | * | 11 | * |
| 12 | */ | 12 | */ |
| 13 | 13 | ||
| 14 | //#include <sys/socket.h> /* socket() */ | ||
| 15 | #include <net/if.h> /* struct ifreq and co. */ | 14 | #include <net/if.h> /* struct ifreq and co. */ |
| 16 | //#include <sys/ioctl.h> /* ioctl() & SIOCGIFINDEX */ | ||
| 17 | 15 | ||
| 18 | #include "libbb.h" | 16 | #include "libbb.h" |
| 19 | #include "libnetlink.h" | 17 | #include "libnetlink.h" |
| 20 | #include "ll_map.h" | 18 | #include "ll_map.h" |
| 21 | 19 | ||
| 22 | struct idxmap { | 20 | struct idxmap { |
| 23 | struct idxmap * next; | 21 | struct idxmap *next; |
| 24 | int index; | 22 | int index; |
| 25 | int type; | 23 | int type; |
| 26 | int alen; | 24 | int alen; |
| 27 | unsigned flags; | 25 | unsigned flags; |
| 28 | unsigned char addr[8]; | 26 | unsigned char addr[8]; |
| 29 | char name[16]; | 27 | char name[16]; |
| 30 | }; | 28 | }; |
| 31 | 29 | ||
| 32 | static struct idxmap *idxmap[16]; | 30 | static struct idxmap *idxmap[16]; |
| 33 | 31 | ||
| 32 | static struct idxmap *find_by_index(int idx) | ||
| 33 | { | ||
| 34 | struct idxmap *im; | ||
| 35 | |||
| 36 | for (im = idxmap[idx & 0xF]; im; im = im->next) | ||
| 37 | if (im->index == idx) | ||
| 38 | return im; | ||
| 39 | return NULL; | ||
| 40 | } | ||
| 41 | |||
| 34 | int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) | 42 | int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) |
| 35 | { | 43 | { |
| 36 | int h; | 44 | int h; |
| @@ -44,25 +52,22 @@ int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) | |||
| 44 | if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifi))) | 52 | if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifi))) |
| 45 | return -1; | 53 | return -1; |
| 46 | 54 | ||
| 47 | |||
| 48 | memset(tb, 0, sizeof(tb)); | 55 | memset(tb, 0, sizeof(tb)); |
| 49 | parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(n)); | 56 | parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(n)); |
| 50 | if (tb[IFLA_IFNAME] == NULL) | 57 | if (tb[IFLA_IFNAME] == NULL) |
| 51 | return 0; | 58 | return 0; |
| 52 | 59 | ||
| 53 | h = ifi->ifi_index&0xF; | 60 | h = ifi->ifi_index & 0xF; |
| 54 | 61 | ||
| 55 | for (imp = &idxmap[h]; (im = *imp) != NULL; imp = &im->next) | 62 | for (imp = &idxmap[h]; (im = *imp) != NULL; imp = &im->next) |
| 56 | if (im->index == ifi->ifi_index) | 63 | if (im->index == ifi->ifi_index) |
| 57 | break; | 64 | goto found; |
| 58 | |||
| 59 | if (im == NULL) { | ||
| 60 | im = xmalloc(sizeof(*im)); | ||
| 61 | im->next = *imp; | ||
| 62 | im->index = ifi->ifi_index; | ||
| 63 | *imp = im; | ||
| 64 | } | ||
| 65 | 65 | ||
| 66 | im = xmalloc(sizeof(*im)); | ||
| 67 | im->next = *imp; | ||
| 68 | im->index = ifi->ifi_index; | ||
| 69 | *imp = im; | ||
| 70 | found: | ||
| 66 | im->type = ifi->ifi_type; | 71 | im->type = ifi->ifi_type; |
| 67 | im->flags = ifi->ifi_flags; | 72 | im->flags = ifi->ifi_flags; |
| 68 | if (tb[IFLA_ADDRESS]) { | 73 | if (tb[IFLA_ADDRESS]) { |
| @@ -85,9 +90,9 @@ const char *ll_idx_n2a(int idx, char *buf) | |||
| 85 | 90 | ||
| 86 | if (idx == 0) | 91 | if (idx == 0) |
| 87 | return "*"; | 92 | return "*"; |
| 88 | for (im = idxmap[idx & 0xF]; im; im = im->next) | 93 | im = find_by_index(idx); |
| 89 | if (im->index == idx) | 94 | if (im) |
| 90 | return im->name; | 95 | return im->name; |
| 91 | snprintf(buf, 16, "if%d", idx); | 96 | snprintf(buf, 16, "if%d", idx); |
| 92 | return buf; | 97 | return buf; |
| 93 | } | 98 | } |
| @@ -100,17 +105,19 @@ const char *ll_index_to_name(int idx) | |||
| 100 | return ll_idx_n2a(idx, nbuf); | 105 | return ll_idx_n2a(idx, nbuf); |
| 101 | } | 106 | } |
| 102 | 107 | ||
| 108 | #ifdef UNUSED | ||
| 103 | int ll_index_to_type(int idx) | 109 | int ll_index_to_type(int idx) |
| 104 | { | 110 | { |
| 105 | struct idxmap *im; | 111 | struct idxmap *im; |
| 106 | 112 | ||
| 107 | if (idx == 0) | 113 | if (idx == 0) |
| 108 | return -1; | 114 | return -1; |
| 109 | for (im = idxmap[idx & 0xF]; im; im = im->next) | 115 | im = find_by_index(idx); |
| 110 | if (im->index == idx) | 116 | if (im) |
| 111 | return im->type; | 117 | return im->type; |
| 112 | return -1; | 118 | return -1; |
| 113 | } | 119 | } |
| 120 | #endif | ||
| 114 | 121 | ||
| 115 | unsigned ll_index_to_flags(int idx) | 122 | unsigned ll_index_to_flags(int idx) |
| 116 | { | 123 | { |
| @@ -118,23 +125,24 @@ unsigned ll_index_to_flags(int idx) | |||
| 118 | 125 | ||
| 119 | if (idx == 0) | 126 | if (idx == 0) |
| 120 | return 0; | 127 | return 0; |
| 121 | 128 | im = find_by_index(idx); | |
| 122 | for (im = idxmap[idx & 0xF]; im; im = im->next) | 129 | if (im) |
| 123 | if (im->index == idx) | 130 | return im->flags; |
| 124 | return im->flags; | ||
| 125 | return 0; | 131 | return 0; |
| 126 | } | 132 | } |
| 127 | 133 | ||
| 128 | // TODO: caching is not warranted - no users which repeatedly call it | ||
| 129 | int xll_name_to_index(const char * const name) | 134 | int xll_name_to_index(const char * const name) |
| 130 | { | 135 | { |
| 136 | int ret = 0; | ||
| 137 | int sock_fd; | ||
| 138 | |||
| 139 | /* caching is not warranted - no users which repeatedly call it */ | ||
| 140 | #ifdef UNUSED | ||
| 131 | static char ncache[16]; | 141 | static char ncache[16]; |
| 132 | static int icache; | 142 | static int icache; |
| 133 | 143 | ||
| 134 | struct idxmap *im; | 144 | struct idxmap *im; |
| 135 | int sock_fd; | ||
| 136 | int i; | 145 | int i; |
| 137 | int ret = 0; | ||
| 138 | 146 | ||
| 139 | if (name == NULL) | 147 | if (name == NULL) |
| 140 | goto out; | 148 | goto out; |
| @@ -159,10 +167,13 @@ int xll_name_to_index(const char * const name) | |||
| 159 | * we explicitely request it (check for dev_load() in net/core/dev.c). | 167 | * we explicitely request it (check for dev_load() in net/core/dev.c). |
| 160 | * I can think of other similar scenario, but they are less common... | 168 | * I can think of other similar scenario, but they are less common... |
| 161 | * Jean II */ | 169 | * Jean II */ |
| 170 | #endif | ||
| 171 | |||
| 162 | sock_fd = socket(AF_INET, SOCK_DGRAM, 0); | 172 | sock_fd = socket(AF_INET, SOCK_DGRAM, 0); |
| 163 | if (sock_fd) { | 173 | if (sock_fd) { |
| 164 | struct ifreq ifr; | 174 | struct ifreq ifr; |
| 165 | int tmp; | 175 | int tmp; |
| 176 | |||
| 166 | strncpy(ifr.ifr_name, name, IFNAMSIZ); | 177 | strncpy(ifr.ifr_name, name, IFNAMSIZ); |
| 167 | ifr.ifr_ifindex = -1; | 178 | ifr.ifr_ifindex = -1; |
| 168 | tmp = ioctl(sock_fd, SIOCGIFINDEX, &ifr); | 179 | tmp = ioctl(sock_fd, SIOCGIFINDEX, &ifr); |
| @@ -173,7 +184,7 @@ int xll_name_to_index(const char * const name) | |||
| 173 | * to the reader... Jean II */ | 184 | * to the reader... Jean II */ |
| 174 | ret = ifr.ifr_ifindex; | 185 | ret = ifr.ifr_ifindex; |
| 175 | } | 186 | } |
| 176 | out: | 187 | /* out:*/ |
| 177 | if (ret <= 0) | 188 | if (ret <= 0) |
| 178 | bb_error_msg_and_die("cannot find device \"%s\"", name); | 189 | bb_error_msg_and_die("cannot find device \"%s\"", name); |
| 179 | return ret; | 190 | return ret; |
diff --git a/networking/libiproute/ll_map.h b/networking/libiproute/ll_map.h index abb640444..2dfc84422 100644 --- a/networking/libiproute/ll_map.h +++ b/networking/libiproute/ll_map.h | |||
| @@ -2,12 +2,12 @@ | |||
| 2 | #ifndef __LL_MAP_H__ | 2 | #ifndef __LL_MAP_H__ |
| 3 | #define __LL_MAP_H__ 1 | 3 | #define __LL_MAP_H__ 1 |
| 4 | 4 | ||
| 5 | extern int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); | 5 | int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); |
| 6 | extern int ll_init_map(struct rtnl_handle *rth); | 6 | int ll_init_map(struct rtnl_handle *rth); |
| 7 | extern int xll_name_to_index(const char * const name); | 7 | int xll_name_to_index(const char * const name); |
| 8 | extern const char *ll_index_to_name(int idx); | 8 | const char *ll_index_to_name(int idx); |
| 9 | extern const char *ll_idx_n2a(int idx, char *buf); | 9 | const char *ll_idx_n2a(int idx, char *buf); |
| 10 | extern int ll_index_to_type(int idx); | 10 | /* int ll_index_to_type(int idx); */ |
| 11 | extern unsigned ll_index_to_flags(int idx); | 11 | unsigned ll_index_to_flags(int idx); |
| 12 | 12 | ||
| 13 | #endif /* __LL_MAP_H__ */ | 13 | #endif /* __LL_MAP_H__ */ |
