diff options
author | Natanael Copa <natanael.copa@gmail.com> | 2010-07-23 01:31:24 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-07-23 01:31:24 +0200 |
commit | b78ac5a20ea2f3038f9738cb05bc3bc3725fabba (patch) | |
tree | 3e1ce1d2ca050afcb8293553cac506d708e2d667 | |
parent | 4f0279bd930d02db2d5df51ce878b9b9b940f069 (diff) | |
download | busybox-w32-b78ac5a20ea2f3038f9738cb05bc3bc3725fabba.tar.gz busybox-w32-b78ac5a20ea2f3038f9738cb05bc3bc3725fabba.tar.bz2 busybox-w32-b78ac5a20ea2f3038f9738cb05bc3bc3725fabba.zip |
libnetlink: code shrink
function old new delta
xrtnl_open 95 93 -2
parse_rtattr 87 85 -2
rtnl_close 9 - -9
xrtnl_wilddump_request 101 64 -37
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/3 up/down: 0/-50) Total: -50 bytes
Signed-off-by: Natanael Copa <natanael.copa@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/libiproute/libnetlink.c | 38 | ||||
-rw-r--r-- | networking/libiproute/libnetlink.h | 6 |
2 files changed, 17 insertions, 27 deletions
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index ba24832d6..8da80b2fc 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c | |||
@@ -1,14 +1,13 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * libnetlink.c RTnetlink service routines. | 3 | * RTnetlink service routines. |
4 | * | 4 | * |
5 | * This program is free software; you can redistribute it and/or | 5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License | 6 | * modify it under the terms of the GNU General Public License |
7 | * as published by the Free Software Foundation; either version | 7 | * as published by the Free Software Foundation; either version |
8 | * 2 of the License, or (at your option) any later version. | 8 | * 2 of the License, or (at your option) any later version. |
9 | * | ||
10 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> | ||
11 | * | 9 | * |
10 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> | ||
12 | */ | 11 | */ |
13 | 12 | ||
14 | #include <sys/socket.h> | 13 | #include <sys/socket.h> |
@@ -17,12 +16,7 @@ | |||
17 | #include "libbb.h" | 16 | #include "libbb.h" |
18 | #include "libnetlink.h" | 17 | #include "libnetlink.h" |
19 | 18 | ||
20 | void FAST_FUNC rtnl_close(struct rtnl_handle *rth) | 19 | void FAST_FUNC xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/) |
21 | { | ||
22 | close(rth->fd); | ||
23 | } | ||
24 | |||
25 | int FAST_FUNC xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/) | ||
26 | { | 20 | { |
27 | socklen_t addr_len; | 21 | socklen_t addr_len; |
28 | 22 | ||
@@ -44,7 +38,6 @@ int FAST_FUNC xrtnl_open(struct rtnl_handle *rth/*, unsigned subscriptions*/) | |||
44 | bb_error_msg_and_die("wrong address family %d", rth->local.nl_family); | 38 | bb_error_msg_and_die("wrong address family %d", rth->local.nl_family); |
45 | */ | 39 | */ |
46 | rth->seq = time(NULL); | 40 | rth->seq = time(NULL); |
47 | return 0; | ||
48 | } | 41 | } |
49 | 42 | ||
50 | int FAST_FUNC xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) | 43 | int FAST_FUNC xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) |
@@ -53,10 +46,6 @@ int FAST_FUNC xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int ty | |||
53 | struct nlmsghdr nlh; | 46 | struct nlmsghdr nlh; |
54 | struct rtgenmsg g; | 47 | struct rtgenmsg g; |
55 | } req; | 48 | } req; |
56 | struct sockaddr_nl nladdr; | ||
57 | |||
58 | memset(&nladdr, 0, sizeof(nladdr)); | ||
59 | nladdr.nl_family = AF_NETLINK; | ||
60 | 49 | ||
61 | req.nlh.nlmsg_len = sizeof(req); | 50 | req.nlh.nlmsg_len = sizeof(req); |
62 | req.nlh.nlmsg_type = type; | 51 | req.nlh.nlmsg_type = type; |
@@ -65,8 +54,7 @@ int FAST_FUNC xrtnl_wilddump_request(struct rtnl_handle *rth, int family, int ty | |||
65 | req.nlh.nlmsg_seq = rth->dump = ++rth->seq; | 54 | req.nlh.nlmsg_seq = rth->dump = ++rth->seq; |
66 | req.g.rtgen_family = family; | 55 | req.g.rtgen_family = family; |
67 | 56 | ||
68 | return xsendto(rth->fd, (void*)&req, sizeof(req), | 57 | return rtnl_send(rth, (void*)&req, sizeof(req)); |
69 | (struct sockaddr*)&nladdr, sizeof(nladdr)); | ||
70 | } | 58 | } |
71 | 59 | ||
72 | int FAST_FUNC rtnl_send(struct rtnl_handle *rth, char *buf, int len) | 60 | int FAST_FUNC rtnl_send(struct rtnl_handle *rth, char *buf, int len) |
@@ -339,8 +327,10 @@ int FAST_FUNC addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data) | |||
339 | { | 327 | { |
340 | int len = RTA_LENGTH(4); | 328 | int len = RTA_LENGTH(4); |
341 | struct rtattr *rta; | 329 | struct rtattr *rta; |
342 | if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) | 330 | |
331 | if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) { | ||
343 | return -1; | 332 | return -1; |
333 | } | ||
344 | rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); | 334 | rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); |
345 | rta->rta_type = type; | 335 | rta->rta_type = type; |
346 | rta->rta_len = len; | 336 | rta->rta_len = len; |
@@ -354,8 +344,9 @@ int FAST_FUNC addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, in | |||
354 | int len = RTA_LENGTH(alen); | 344 | int len = RTA_LENGTH(alen); |
355 | struct rtattr *rta; | 345 | struct rtattr *rta; |
356 | 346 | ||
357 | if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) | 347 | if ((int)(NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) { |
358 | return -1; | 348 | return -1; |
349 | } | ||
359 | rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); | 350 | rta = (struct rtattr*)(((char*)n) + NLMSG_ALIGN(n->nlmsg_len)); |
360 | rta->rta_type = type; | 351 | rta->rta_type = type; |
361 | rta->rta_len = len; | 352 | rta->rta_len = len; |
@@ -397,7 +388,7 @@ int FAST_FUNC rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data | |||
397 | } | 388 | } |
398 | 389 | ||
399 | 390 | ||
400 | int FAST_FUNC parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) | 391 | void FAST_FUNC parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) |
401 | { | 392 | { |
402 | while (RTA_OK(rta, len)) { | 393 | while (RTA_OK(rta, len)) { |
403 | if (rta->rta_type <= max) { | 394 | if (rta->rta_type <= max) { |
@@ -408,5 +399,4 @@ int FAST_FUNC parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int | |||
408 | if (len) { | 399 | if (len) { |
409 | bb_error_msg("deficit %d, rta_len=%d!", len, rta->rta_len); | 400 | bb_error_msg("deficit %d, rta_len=%d!", len, rta->rta_len); |
410 | } | 401 | } |
411 | return 0; | ||
412 | } | 402 | } |
diff --git a/networking/libiproute/libnetlink.h b/networking/libiproute/libnetlink.h index 41ecfa6d0..4e4d5b7b9 100644 --- a/networking/libiproute/libnetlink.h +++ b/networking/libiproute/libnetlink.h | |||
@@ -18,8 +18,8 @@ struct rtnl_handle { | |||
18 | uint32_t dump; | 18 | uint32_t dump; |
19 | }; | 19 | }; |
20 | 20 | ||
21 | extern int xrtnl_open(struct rtnl_handle *rth) FAST_FUNC; | 21 | extern void xrtnl_open(struct rtnl_handle *rth) FAST_FUNC; |
22 | extern void rtnl_close(struct rtnl_handle *rth) FAST_FUNC; | 22 | #define rtnl_close(rth) (close((rth)->fd)) |
23 | extern int xrtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type) FAST_FUNC; | 23 | extern int xrtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type) FAST_FUNC; |
24 | extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) FAST_FUNC; | 24 | extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) FAST_FUNC; |
25 | extern int xrtnl_dump_filter(struct rtnl_handle *rth, | 25 | extern int xrtnl_dump_filter(struct rtnl_handle *rth, |
@@ -42,7 +42,7 @@ extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int a | |||
42 | extern int rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data) FAST_FUNC; | 42 | extern int rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data) FAST_FUNC; |
43 | extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen) FAST_FUNC; | 43 | extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen) FAST_FUNC; |
44 | 44 | ||
45 | extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) FAST_FUNC; | 45 | extern void parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) FAST_FUNC; |
46 | 46 | ||
47 | POP_SAVED_FUNCTION_VISIBILITY | 47 | POP_SAVED_FUNCTION_VISIBILITY |
48 | 48 | ||