aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute/libnetlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/libiproute/libnetlink.c')
-rw-r--r--networking/libiproute/libnetlink.c128
1 files changed, 0 insertions, 128 deletions
diff --git a/networking/libiproute/libnetlink.c b/networking/libiproute/libnetlink.c
index efbb6f104..ad5bcd70f 100644
--- a/networking/libiproute/libnetlink.c
+++ b/networking/libiproute/libnetlink.c
@@ -319,134 +319,6 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
319 } 319 }
320} 320}
321 321
322int rtnl_listen(struct rtnl_handle *rtnl,
323 int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
324 void *jarg)
325{
326 int status;
327 struct nlmsghdr *h;
328 struct sockaddr_nl nladdr;
329 struct iovec iov;
330 char buf[8192];
331 struct msghdr msg = {
332 (void*)&nladdr, sizeof(nladdr),
333 &iov, 1,
334 NULL, 0,
335 0
336 };
337
338 memset(&nladdr, 0, sizeof(nladdr));
339 nladdr.nl_family = AF_NETLINK;
340 nladdr.nl_pid = 0;
341 nladdr.nl_groups = 0;
342
343
344 iov.iov_base = buf;
345
346 while (1) {
347 iov.iov_len = sizeof(buf);
348 status = recvmsg(rtnl->fd, &msg, 0);
349
350 if (status < 0) {
351 if (errno == EINTR)
352 continue;
353 bb_perror_msg("OVERRUN");
354 continue;
355 }
356 if (status == 0) {
357 bb_error_msg("EOF on netlink");
358 return -1;
359 }
360 if (msg.msg_namelen != sizeof(nladdr)) {
361 bb_error_msg_and_die("Sender address length == %d", msg.msg_namelen);
362 }
363 for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) {
364 int err;
365 int len = h->nlmsg_len;
366 int l = len - sizeof(*h);
367
368 if (l<0 || len>status) {
369 if (msg.msg_flags & MSG_TRUNC) {
370 bb_error_msg("Truncated message");
371 return -1;
372 }
373 bb_error_msg_and_die("!!!malformed message: len=%d", len);
374 }
375
376 err = handler(&nladdr, h, jarg);
377 if (err < 0) {
378 return err;
379 }
380
381 status -= NLMSG_ALIGN(len);
382 h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
383 }
384 if (msg.msg_flags & MSG_TRUNC) {
385 bb_error_msg("Message truncated");
386 continue;
387 }
388 if (status) {
389 bb_error_msg_and_die("!!!Remnant of size %d", status);
390 }
391 }
392}
393
394int rtnl_from_file(FILE *rtnl,
395 int (*handler)(struct sockaddr_nl *,struct nlmsghdr *n, void *),
396 void *jarg)
397{
398 int status;
399 struct sockaddr_nl nladdr;
400 char buf[8192];
401 struct nlmsghdr *h = (void*)buf;
402
403 memset(&nladdr, 0, sizeof(nladdr));
404 nladdr.nl_family = AF_NETLINK;
405 nladdr.nl_pid = 0;
406 nladdr.nl_groups = 0;
407
408 while (1) {
409 int err, len, type;
410 int l;
411
412 status = fread(&buf, 1, sizeof(*h), rtnl);
413
414 if (status < 0) {
415 if (errno == EINTR)
416 continue;
417 bb_perror_msg("rtnl_from_file: fread");
418 return -1;
419 }
420 if (status == 0)
421 return 0;
422
423 len = h->nlmsg_len;
424 type= h->nlmsg_type;
425 l = len - sizeof(*h);
426
427 if (l<0 || len>sizeof(buf)) {
428 bb_error_msg("!!!malformed message: len=%d @%lu",
429 len, ftell(rtnl));
430 return -1;
431 }
432
433 status = fread(NLMSG_DATA(h), 1, NLMSG_ALIGN(l), rtnl);
434
435 if (status < 0) {
436 bb_perror_msg("rtnl_from_file: fread");
437 return -1;
438 }
439 if (status < l) {
440 bb_error_msg("rtnl-from_file: truncated message");
441 return -1;
442 }
443
444 err = handler(&nladdr, h, jarg);
445 if (err < 0)
446 return err;
447 }
448}
449
450int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data) 322int addattr32(struct nlmsghdr *n, int maxlen, int type, __u32 data)
451{ 323{
452 int len = RTA_LENGTH(4); 324 int len = RTA_LENGTH(4);