diff options
Diffstat (limited to 'networking/libiproute/libnetlink.c')
-rw-r--r-- | networking/libiproute/libnetlink.c | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c index fbc555dfe..04411931d 100644 --- a/networking/libiproute/libnetlink.c +++ b/networking/libiproute/libnetlink.c | |||
@@ -34,7 +34,7 @@ int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions) | |||
34 | 34 | ||
35 | rth->fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); | 35 | rth->fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); |
36 | if (rth->fd < 0) { | 36 | if (rth->fd < 0) { |
37 | perror_msg("Cannot open netlink socket"); | 37 | bb_perror_msg("Cannot open netlink socket"); |
38 | return -1; | 38 | return -1; |
39 | } | 39 | } |
40 | 40 | ||
@@ -43,20 +43,20 @@ int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions) | |||
43 | rth->local.nl_groups = subscriptions; | 43 | rth->local.nl_groups = subscriptions; |
44 | 44 | ||
45 | if (bind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)) < 0) { | 45 | if (bind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)) < 0) { |
46 | perror_msg("Cannot bind netlink socket"); | 46 | bb_perror_msg("Cannot bind netlink socket"); |
47 | return -1; | 47 | return -1; |
48 | } | 48 | } |
49 | addr_len = sizeof(rth->local); | 49 | addr_len = sizeof(rth->local); |
50 | if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) { | 50 | if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) { |
51 | perror_msg("Cannot getsockname"); | 51 | bb_perror_msg("Cannot getsockname"); |
52 | return -1; | 52 | return -1; |
53 | } | 53 | } |
54 | if (addr_len != sizeof(rth->local)) { | 54 | if (addr_len != sizeof(rth->local)) { |
55 | error_msg("Wrong address length %d", addr_len); | 55 | bb_error_msg("Wrong address length %d", addr_len); |
56 | return -1; | 56 | return -1; |
57 | } | 57 | } |
58 | if (rth->local.nl_family != AF_NETLINK) { | 58 | if (rth->local.nl_family != AF_NETLINK) { |
59 | error_msg("Wrong address family %d", rth->local.nl_family); | 59 | bb_error_msg("Wrong address family %d", rth->local.nl_family); |
60 | return -1; | 60 | return -1; |
61 | } | 61 | } |
62 | rth->seq = time(NULL); | 62 | rth->seq = time(NULL); |
@@ -144,15 +144,15 @@ int rtnl_dump_filter(struct rtnl_handle *rth, | |||
144 | if (status < 0) { | 144 | if (status < 0) { |
145 | if (errno == EINTR) | 145 | if (errno == EINTR) |
146 | continue; | 146 | continue; |
147 | perror_msg("OVERRUN"); | 147 | bb_perror_msg("OVERRUN"); |
148 | continue; | 148 | continue; |
149 | } | 149 | } |
150 | if (status == 0) { | 150 | if (status == 0) { |
151 | error_msg("EOF on netlink"); | 151 | bb_error_msg("EOF on netlink"); |
152 | return -1; | 152 | return -1; |
153 | } | 153 | } |
154 | if (msg.msg_namelen != sizeof(nladdr)) { | 154 | if (msg.msg_namelen != sizeof(nladdr)) { |
155 | error_msg_and_die("sender address length == %d", msg.msg_namelen); | 155 | bb_error_msg_and_die("sender address length == %d", msg.msg_namelen); |
156 | } | 156 | } |
157 | 157 | ||
158 | h = (struct nlmsghdr*)buf; | 158 | h = (struct nlmsghdr*)buf; |
@@ -176,10 +176,10 @@ int rtnl_dump_filter(struct rtnl_handle *rth, | |||
176 | if (h->nlmsg_type == NLMSG_ERROR) { | 176 | if (h->nlmsg_type == NLMSG_ERROR) { |
177 | struct nlmsgerr *l_err = (struct nlmsgerr*)NLMSG_DATA(h); | 177 | struct nlmsgerr *l_err = (struct nlmsgerr*)NLMSG_DATA(h); |
178 | if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) { | 178 | if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) { |
179 | error_msg("ERROR truncated"); | 179 | bb_error_msg("ERROR truncated"); |
180 | } else { | 180 | } else { |
181 | errno = -l_err->error; | 181 | errno = -l_err->error; |
182 | perror_msg("RTNETLINK answers"); | 182 | bb_perror_msg("RTNETLINK answers"); |
183 | } | 183 | } |
184 | return -1; | 184 | return -1; |
185 | } | 185 | } |
@@ -192,11 +192,11 @@ skip_it: | |||
192 | h = NLMSG_NEXT(h, status); | 192 | h = NLMSG_NEXT(h, status); |
193 | } | 193 | } |
194 | if (msg.msg_flags & MSG_TRUNC) { | 194 | if (msg.msg_flags & MSG_TRUNC) { |
195 | error_msg("Message truncated"); | 195 | bb_error_msg("Message truncated"); |
196 | continue; | 196 | continue; |
197 | } | 197 | } |
198 | if (status) { | 198 | if (status) { |
199 | error_msg_and_die("!!!Remnant of size %d", status); | 199 | bb_error_msg_and_die("!!!Remnant of size %d", status); |
200 | } | 200 | } |
201 | } | 201 | } |
202 | } | 202 | } |
@@ -231,7 +231,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, | |||
231 | status = sendmsg(rtnl->fd, &msg, 0); | 231 | status = sendmsg(rtnl->fd, &msg, 0); |
232 | 232 | ||
233 | if (status < 0) { | 233 | if (status < 0) { |
234 | perror_msg("Cannot talk to rtnetlink"); | 234 | bb_perror_msg("Cannot talk to rtnetlink"); |
235 | return -1; | 235 | return -1; |
236 | } | 236 | } |
237 | 237 | ||
@@ -245,15 +245,15 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, | |||
245 | if (errno == EINTR) { | 245 | if (errno == EINTR) { |
246 | continue; | 246 | continue; |
247 | } | 247 | } |
248 | perror_msg("OVERRUN"); | 248 | bb_perror_msg("OVERRUN"); |
249 | continue; | 249 | continue; |
250 | } | 250 | } |
251 | if (status == 0) { | 251 | if (status == 0) { |
252 | error_msg("EOF on netlink"); | 252 | bb_error_msg("EOF on netlink"); |
253 | return -1; | 253 | return -1; |
254 | } | 254 | } |
255 | if (msg.msg_namelen != sizeof(nladdr)) { | 255 | if (msg.msg_namelen != sizeof(nladdr)) { |
256 | error_msg_and_die("sender address length == %d", msg.msg_namelen); | 256 | bb_error_msg_and_die("sender address length == %d", msg.msg_namelen); |
257 | } | 257 | } |
258 | for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) { | 258 | for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) { |
259 | int l_err; | 259 | int l_err; |
@@ -262,10 +262,10 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, | |||
262 | 262 | ||
263 | if (l<0 || len>status) { | 263 | if (l<0 || len>status) { |
264 | if (msg.msg_flags & MSG_TRUNC) { | 264 | if (msg.msg_flags & MSG_TRUNC) { |
265 | error_msg("Truncated message"); | 265 | bb_error_msg("Truncated message"); |
266 | return -1; | 266 | return -1; |
267 | } | 267 | } |
268 | error_msg_and_die("!!!malformed message: len=%d", len); | 268 | bb_error_msg_and_die("!!!malformed message: len=%d", len); |
269 | } | 269 | } |
270 | 270 | ||
271 | if (h->nlmsg_pid != rtnl->local.nl_pid || | 271 | if (h->nlmsg_pid != rtnl->local.nl_pid || |
@@ -282,7 +282,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, | |||
282 | if (h->nlmsg_type == NLMSG_ERROR) { | 282 | if (h->nlmsg_type == NLMSG_ERROR) { |
283 | struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); | 283 | struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); |
284 | if (l < sizeof(struct nlmsgerr)) { | 284 | if (l < sizeof(struct nlmsgerr)) { |
285 | error_msg("ERROR truncated"); | 285 | bb_error_msg("ERROR truncated"); |
286 | } else { | 286 | } else { |
287 | errno = -err->error; | 287 | errno = -err->error; |
288 | if (errno == 0) { | 288 | if (errno == 0) { |
@@ -291,7 +291,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, | |||
291 | } | 291 | } |
292 | return 0; | 292 | return 0; |
293 | } | 293 | } |
294 | perror_msg("RTNETLINK answers"); | 294 | bb_perror_msg("RTNETLINK answers"); |
295 | } | 295 | } |
296 | return -1; | 296 | return -1; |
297 | } | 297 | } |
@@ -300,17 +300,17 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, | |||
300 | return 0; | 300 | return 0; |
301 | } | 301 | } |
302 | 302 | ||
303 | error_msg("Unexpected reply!!!"); | 303 | bb_error_msg("Unexpected reply!!!"); |
304 | 304 | ||
305 | status -= NLMSG_ALIGN(len); | 305 | status -= NLMSG_ALIGN(len); |
306 | h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len)); | 306 | h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len)); |
307 | } | 307 | } |
308 | if (msg.msg_flags & MSG_TRUNC) { | 308 | if (msg.msg_flags & MSG_TRUNC) { |
309 | error_msg("Message truncated"); | 309 | bb_error_msg("Message truncated"); |
310 | continue; | 310 | continue; |
311 | } | 311 | } |
312 | if (status) { | 312 | if (status) { |
313 | error_msg_and_die("!!!Remnant of size %d", status); | 313 | bb_error_msg_and_die("!!!Remnant of size %d", status); |
314 | } | 314 | } |
315 | } | 315 | } |
316 | } | 316 | } |
@@ -346,15 +346,15 @@ int rtnl_listen(struct rtnl_handle *rtnl, | |||
346 | if (status < 0) { | 346 | if (status < 0) { |
347 | if (errno == EINTR) | 347 | if (errno == EINTR) |
348 | continue; | 348 | continue; |
349 | perror_msg("OVERRUN"); | 349 | bb_perror_msg("OVERRUN"); |
350 | continue; | 350 | continue; |
351 | } | 351 | } |
352 | if (status == 0) { | 352 | if (status == 0) { |
353 | error_msg("EOF on netlink"); | 353 | bb_error_msg("EOF on netlink"); |
354 | return -1; | 354 | return -1; |
355 | } | 355 | } |
356 | if (msg.msg_namelen != sizeof(nladdr)) { | 356 | if (msg.msg_namelen != sizeof(nladdr)) { |
357 | error_msg_and_die("Sender address length == %d", msg.msg_namelen); | 357 | bb_error_msg_and_die("Sender address length == %d", msg.msg_namelen); |
358 | } | 358 | } |
359 | for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) { | 359 | for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) { |
360 | int err; | 360 | int err; |
@@ -363,10 +363,10 @@ int rtnl_listen(struct rtnl_handle *rtnl, | |||
363 | 363 | ||
364 | if (l<0 || len>status) { | 364 | if (l<0 || len>status) { |
365 | if (msg.msg_flags & MSG_TRUNC) { | 365 | if (msg.msg_flags & MSG_TRUNC) { |
366 | error_msg("Truncated message"); | 366 | bb_error_msg("Truncated message"); |
367 | return -1; | 367 | return -1; |
368 | } | 368 | } |
369 | error_msg_and_die("!!!malformed message: len=%d", len); | 369 | bb_error_msg_and_die("!!!malformed message: len=%d", len); |
370 | } | 370 | } |
371 | 371 | ||
372 | err = handler(&nladdr, h, jarg); | 372 | err = handler(&nladdr, h, jarg); |
@@ -378,11 +378,11 @@ int rtnl_listen(struct rtnl_handle *rtnl, | |||
378 | h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len)); | 378 | h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len)); |
379 | } | 379 | } |
380 | if (msg.msg_flags & MSG_TRUNC) { | 380 | if (msg.msg_flags & MSG_TRUNC) { |
381 | error_msg("Message truncated"); | 381 | bb_error_msg("Message truncated"); |
382 | continue; | 382 | continue; |
383 | } | 383 | } |
384 | if (status) { | 384 | if (status) { |
385 | error_msg_and_die("!!!Remnant of size %d", status); | 385 | bb_error_msg_and_die("!!!Remnant of size %d", status); |
386 | } | 386 | } |
387 | } | 387 | } |
388 | } | 388 | } |
@@ -410,7 +410,7 @@ int rtnl_from_file(FILE *rtnl, | |||
410 | if (status < 0) { | 410 | if (status < 0) { |
411 | if (errno == EINTR) | 411 | if (errno == EINTR) |
412 | continue; | 412 | continue; |
413 | perror_msg("rtnl_from_file: fread"); | 413 | bb_perror_msg("rtnl_from_file: fread"); |
414 | return -1; | 414 | return -1; |
415 | } | 415 | } |
416 | if (status == 0) | 416 | if (status == 0) |
@@ -421,7 +421,7 @@ int rtnl_from_file(FILE *rtnl, | |||
421 | l = len - sizeof(*h); | 421 | l = len - sizeof(*h); |
422 | 422 | ||
423 | if (l<0 || len>sizeof(buf)) { | 423 | if (l<0 || len>sizeof(buf)) { |
424 | error_msg("!!!malformed message: len=%d @%lu", | 424 | bb_error_msg("!!!malformed message: len=%d @%lu", |
425 | len, ftell(rtnl)); | 425 | len, ftell(rtnl)); |
426 | return -1; | 426 | return -1; |
427 | } | 427 | } |
@@ -429,11 +429,11 @@ int rtnl_from_file(FILE *rtnl, | |||
429 | status = fread(NLMSG_DATA(h), 1, NLMSG_ALIGN(l), rtnl); | 429 | status = fread(NLMSG_DATA(h), 1, NLMSG_ALIGN(l), rtnl); |
430 | 430 | ||
431 | if (status < 0) { | 431 | if (status < 0) { |
432 | perror_msg("rtnl_from_file: fread"); | 432 | bb_perror_msg("rtnl_from_file: fread"); |
433 | return -1; | 433 | return -1; |
434 | } | 434 | } |
435 | if (status < l) { | 435 | if (status < l) { |
436 | error_msg("rtnl-from_file: truncated message"); | 436 | bb_error_msg("rtnl-from_file: truncated message"); |
437 | return -1; | 437 | return -1; |
438 | } | 438 | } |
439 | 439 | ||
@@ -514,7 +514,7 @@ int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len) | |||
514 | rta = RTA_NEXT(rta,len); | 514 | rta = RTA_NEXT(rta,len); |
515 | } | 515 | } |
516 | if (len) { | 516 | if (len) { |
517 | error_msg("!!!Deficit %d, rta_len=%d", len, rta->rta_len); | 517 | bb_error_msg("!!!Deficit %d, rta_len=%d", len, rta->rta_len); |
518 | } | 518 | } |
519 | return 0; | 519 | return 0; |
520 | } | 520 | } |