aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-12-02 06:30:57 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-12-02 06:30:57 +0000
commit8723a94c2570cdf3a6baddfff7a43523470ed368 (patch)
treeef77e4759909ebde2d7b5d3f49eea65700a79ef7
parent5cb40bbbd33b361d46cf4a0e75e97e9d119c1270 (diff)
downloadbusybox-w32-8723a94c2570cdf3a6baddfff7a43523470ed368.tar.gz
busybox-w32-8723a94c2570cdf3a6baddfff7a43523470ed368.tar.bz2
busybox-w32-8723a94c2570cdf3a6baddfff7a43523470ed368.zip
libnetlink: comment out unused code; don't use 8k stack buffers
function old new delta ipaddr_modify 1305 1297 -8 do_iprule 963 955 -8 do_iproute 2193 2169 -24 xrtnl_dump_filter 418 391 -27 rtnl_talk 671 536 -135 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/5 up/down: 0/-202) Total: -202 bytes
-rw-r--r--networking/libiproute/libnetlink.c97
-rw-r--r--networking/libiproute/libnetlink.h5
2 files changed, 65 insertions, 37 deletions
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c
index 0f6040977..d29d035d0 100644
--- a/networking/libiproute/libnetlink.c
+++ b/networking/libiproute/libnetlink.c
@@ -108,9 +108,10 @@ static int rtnl_dump_filter(struct rtnl_handle *rth,
108 int (*junk)(struct sockaddr_nl *, struct nlmsghdr *n, void *), 108 int (*junk)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
109 void *arg2*/) 109 void *arg2*/)
110{ 110{
111 char buf[8192]; 111 int retval = -1;
112 char *buf = xmalloc(8*1024); /* avoid big stack buffer */
112 struct sockaddr_nl nladdr; 113 struct sockaddr_nl nladdr;
113 struct iovec iov = { buf, sizeof(buf) }; 114 struct iovec iov = { buf, 8*1024 };
114 115
115 while (1) { 116 while (1) {
116 int status; 117 int status;
@@ -133,7 +134,7 @@ static int rtnl_dump_filter(struct rtnl_handle *rth,
133 } 134 }
134 if (status == 0) { 135 if (status == 0) {
135 bb_error_msg("EOF on netlink"); 136 bb_error_msg("EOF on netlink");
136 return -1; 137 goto ret;
137 } 138 }
138 if (msg.msg_namelen != sizeof(nladdr)) { 139 if (msg.msg_namelen != sizeof(nladdr)) {
139 bb_error_msg_and_die("sender address length == %d", msg.msg_namelen); 140 bb_error_msg_and_die("sender address length == %d", msg.msg_namelen);
@@ -146,16 +147,18 @@ static int rtnl_dump_filter(struct rtnl_handle *rth,
146 if (nladdr.nl_pid != 0 || 147 if (nladdr.nl_pid != 0 ||
147 h->nlmsg_pid != rth->local.nl_pid || 148 h->nlmsg_pid != rth->local.nl_pid ||
148 h->nlmsg_seq != rth->dump) { 149 h->nlmsg_seq != rth->dump) {
149/* if (junk) { 150// if (junk) {
150 err = junk(&nladdr, h, arg2); 151// err = junk(&nladdr, h, arg2);
151 if (err < 0) 152// if (err < 0) {
152 return err; 153// retval = err;
153 } */ 154// goto ret;
155// }
156// }
154 goto skip_it; 157 goto skip_it;
155 } 158 }
156 159
157 if (h->nlmsg_type == NLMSG_DONE) { 160 if (h->nlmsg_type == NLMSG_DONE) {
158 return 0; 161 goto ret_0;
159 } 162 }
160 if (h->nlmsg_type == NLMSG_ERROR) { 163 if (h->nlmsg_type == NLMSG_ERROR) {
161 struct nlmsgerr *l_err = (struct nlmsgerr*)NLMSG_DATA(h); 164 struct nlmsgerr *l_err = (struct nlmsgerr*)NLMSG_DATA(h);
@@ -165,13 +168,15 @@ static int rtnl_dump_filter(struct rtnl_handle *rth,
165 errno = -l_err->error; 168 errno = -l_err->error;
166 bb_perror_msg("RTNETLINK answers"); 169 bb_perror_msg("RTNETLINK answers");
167 } 170 }
168 return -1; 171 goto ret;
169 } 172 }
170 err = filter(&nladdr, h, arg1); 173 err = filter(&nladdr, h, arg1);
171 if (err < 0) 174 if (err < 0) {
172 return err; 175 retval = err;
176 goto ret;
177 }
173 178
174skip_it: 179 skip_it:
175 h = NLMSG_NEXT(h, status); 180 h = NLMSG_NEXT(h, status);
176 } 181 }
177 if (msg.msg_flags & MSG_TRUNC) { 182 if (msg.msg_flags & MSG_TRUNC) {
@@ -181,7 +186,12 @@ skip_it:
181 if (status) { 186 if (status) {
182 bb_error_msg_and_die("remnant of size %d!", status); 187 bb_error_msg_and_die("remnant of size %d!", status);
183 } 188 }
184 } 189 } /* while (1) */
190 ret_0:
191 retval++; /* = 0 */
192 ret:
193 free(buf);
194 return retval;
185} 195}
186 196
187int xrtnl_dump_filter(struct rtnl_handle *rth, 197int xrtnl_dump_filter(struct rtnl_handle *rth,
@@ -194,17 +204,24 @@ int xrtnl_dump_filter(struct rtnl_handle *rth,
194 return ret; 204 return ret;
195} 205}
196 206
197int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, 207int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
198 unsigned groups, struct nlmsghdr *answer, 208 pid_t peer, unsigned groups,
199 int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), 209 struct nlmsghdr *answer,
210 int (*junk)(struct sockaddr_nl *, struct nlmsghdr *n, void *),
200 void *jarg) 211 void *jarg)
201{ 212{
213/* bbox doesn't use parameters no. 3, 4, 6, 7, they are stubbed out */
214#define peer 0
215#define groups 0
216#define junk NULL
217#define jarg NULL
218 int retval = -1;
202 int status; 219 int status;
203 unsigned seq; 220 unsigned seq;
204 struct nlmsghdr *h; 221 struct nlmsghdr *h;
205 struct sockaddr_nl nladdr; 222 struct sockaddr_nl nladdr;
206 struct iovec iov = { (void*)n, n->nlmsg_len }; 223 struct iovec iov = { (void*)n, n->nlmsg_len };
207 char buf[8192]; 224 char *buf = xmalloc(8*1024); /* avoid big stack buffer */
208 struct msghdr msg = { 225 struct msghdr msg = {
209 (void*)&nladdr, sizeof(nladdr), 226 (void*)&nladdr, sizeof(nladdr),
210 &iov, 1, 227 &iov, 1,
@@ -214,8 +231,8 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
214 231
215 memset(&nladdr, 0, sizeof(nladdr)); 232 memset(&nladdr, 0, sizeof(nladdr));
216 nladdr.nl_family = AF_NETLINK; 233 nladdr.nl_family = AF_NETLINK;
217 nladdr.nl_pid = peer; 234// nladdr.nl_pid = peer;
218 nladdr.nl_groups = groups; 235// nladdr.nl_groups = groups;
219 236
220 n->nlmsg_seq = seq = ++rtnl->seq; 237 n->nlmsg_seq = seq = ++rtnl->seq;
221 if (answer == NULL) { 238 if (answer == NULL) {
@@ -225,13 +242,13 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
225 242
226 if (status < 0) { 243 if (status < 0) {
227 bb_perror_msg("cannot talk to rtnetlink"); 244 bb_perror_msg("cannot talk to rtnetlink");
228 return -1; 245 goto ret;
229 } 246 }
230 247
231 iov.iov_base = buf; 248 iov.iov_base = buf;
232 249
233 while (1) { 250 while (1) {
234 iov.iov_len = sizeof(buf); 251 iov.iov_len = 8*1024;
235 status = recvmsg(rtnl->fd, &msg, 0); 252 status = recvmsg(rtnl->fd, &msg, 0);
236 253
237 if (status < 0) { 254 if (status < 0) {
@@ -243,20 +260,20 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
243 } 260 }
244 if (status == 0) { 261 if (status == 0) {
245 bb_error_msg("EOF on netlink"); 262 bb_error_msg("EOF on netlink");
246 return -1; 263 goto ret;
247 } 264 }
248 if (msg.msg_namelen != sizeof(nladdr)) { 265 if (msg.msg_namelen != sizeof(nladdr)) {
249 bb_error_msg_and_die("sender address length == %d", msg.msg_namelen); 266 bb_error_msg_and_die("sender address length == %d", msg.msg_namelen);
250 } 267 }
251 for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) { 268 for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) {
252 int l_err; 269// int l_err;
253 int len = h->nlmsg_len; 270 int len = h->nlmsg_len;
254 int l = len - sizeof(*h); 271 int l = len - sizeof(*h);
255 272
256 if (l<0 || len>status) { 273 if (l < 0 || len > status) {
257 if (msg.msg_flags & MSG_TRUNC) { 274 if (msg.msg_flags & MSG_TRUNC) {
258 bb_error_msg("truncated message"); 275 bb_error_msg("truncated message");
259 return -1; 276 goto ret;
260 } 277 }
261 bb_error_msg_and_die("malformed message: len=%d!", len); 278 bb_error_msg_and_die("malformed message: len=%d!", len);
262 } 279 }
@@ -264,12 +281,13 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
264 if (nladdr.nl_pid != peer || 281 if (nladdr.nl_pid != peer ||
265 h->nlmsg_pid != rtnl->local.nl_pid || 282 h->nlmsg_pid != rtnl->local.nl_pid ||
266 h->nlmsg_seq != seq) { 283 h->nlmsg_seq != seq) {
267 if (junk) { 284// if (junk) {
268 l_err = junk(&nladdr, h, jarg); 285// l_err = junk(&nladdr, h, jarg);
269 if (l_err < 0) { 286// if (l_err < 0) {
270 return l_err; 287// retval = l_err;
271 } 288// goto ret;
272 } 289// }
290// }
273 continue; 291 continue;
274 } 292 }
275 293
@@ -278,20 +296,20 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
278 if (l < sizeof(struct nlmsgerr)) { 296 if (l < sizeof(struct nlmsgerr)) {
279 bb_error_msg("ERROR truncated"); 297 bb_error_msg("ERROR truncated");
280 } else { 298 } else {
281 errno = -err->error; 299 errno = - err->error;
282 if (errno == 0) { 300 if (errno == 0) {
283 if (answer) { 301 if (answer) {
284 memcpy(answer, h, h->nlmsg_len); 302 memcpy(answer, h, h->nlmsg_len);
285 } 303 }
286 return 0; 304 goto ret_0;
287 } 305 }
288 bb_perror_msg("RTNETLINK answers"); 306 bb_perror_msg("RTNETLINK answers");
289 } 307 }
290 return -1; 308 goto ret;
291 } 309 }
292 if (answer) { 310 if (answer) {
293 memcpy(answer, h, h->nlmsg_len); 311 memcpy(answer, h, h->nlmsg_len);
294 return 0; 312 goto ret_0;
295 } 313 }
296 314
297 bb_error_msg("unexpected reply!"); 315 bb_error_msg("unexpected reply!");
@@ -306,7 +324,12 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
306 if (status) { 324 if (status) {
307 bb_error_msg_and_die("remnant of size %d!", status); 325 bb_error_msg_and_die("remnant of size %d!", status);
308 } 326 }
309 } 327 } /* while (1) */
328 ret_0:
329 retval++; /* = 0 */
330 ret:
331 free(buf);
332 return retval;
310} 333}
311 334
312int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data) 335int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data)
diff --git a/networking/libiproute/libnetlink.h b/networking/libiproute/libnetlink.h
index 316bd9b68..e149f52bf 100644
--- a/networking/libiproute/libnetlink.h
+++ b/networking/libiproute/libnetlink.h
@@ -24,10 +24,15 @@ extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int l
24extern int xrtnl_dump_filter(struct rtnl_handle *rth, 24extern int xrtnl_dump_filter(struct rtnl_handle *rth,
25 int (*filter)(struct sockaddr_nl*, struct nlmsghdr *n, void*), 25 int (*filter)(struct sockaddr_nl*, struct nlmsghdr *n, void*),
26 void *arg1); 26 void *arg1);
27
28/* bbox doesn't use parameters no. 3, 4, 6, 7, stub them out */
29#define rtnl_talk(rtnl, n, peer, groups, answer, junk, jarg) \
30 rtnl_talk(rtnl, n, answer)
27extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, 31extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
28 unsigned groups, struct nlmsghdr *answer, 32 unsigned groups, struct nlmsghdr *answer,
29 int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), 33 int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
30 void *jarg); 34 void *jarg);
35
31extern int rtnl_send(struct rtnl_handle *rth, char *buf, int); 36extern int rtnl_send(struct rtnl_handle *rth, char *buf, int);
32 37
33 38