diff options
author | Kristóf Marussy <kris7topher@gmail.com> | 2020-01-27 21:04:35 +0100 |
---|---|---|
committer | Kristóf Marussy <kris7topher@gmail.com> | 2020-01-27 21:04:35 +0100 |
commit | a7e6138ad09e77a8792a03640a43660a063a1e2d (patch) | |
tree | afae50ccb705f56851aece3d92757e457dfbbfc3 /src/fnet/interface.c | |
parent | clarify dropping python2 support in meld.profile (#3167) (diff) | |
download | firejail-a7e6138ad09e77a8792a03640a43660a063a1e2d.tar.gz firejail-a7e6138ad09e77a8792a03640a43660a063a1e2d.tar.zst firejail-a7e6138ad09e77a8792a03640a43660a063a1e2d.zip |
Fix indentation for dhcp client code
Diffstat (limited to 'src/fnet/interface.c')
-rw-r--r-- | src/fnet/interface.c | 186 |
1 files changed, 93 insertions, 93 deletions
diff --git a/src/fnet/interface.c b/src/fnet/interface.c index 3b44b70e3..6a9208898 100644 --- a/src/fnet/interface.c +++ b/src/fnet/interface.c | |||
@@ -374,81 +374,81 @@ void net_if_ip6(const char *ifname, const char *addr6) { | |||
374 | } | 374 | } |
375 | 375 | ||
376 | static int net_netlink_address_tentative(struct nlmsghdr *current_header) { | 376 | static int net_netlink_address_tentative(struct nlmsghdr *current_header) { |
377 | struct ifaddrmsg *msg = NLMSG_DATA(current_header); | 377 | struct ifaddrmsg *msg = NLMSG_DATA(current_header); |
378 | struct rtattr *rta = IFA_RTA(msg); | 378 | struct rtattr *rta = IFA_RTA(msg); |
379 | size_t msg_len = IFA_PAYLOAD(current_header); | 379 | size_t msg_len = IFA_PAYLOAD(current_header); |
380 | int has_flags = 0; | 380 | int has_flags = 0; |
381 | while (RTA_OK(rta, msg_len)) { | 381 | while (RTA_OK(rta, msg_len)) { |
382 | if (rta->rta_type == IFA_FLAGS) { | 382 | if (rta->rta_type == IFA_FLAGS) { |
383 | has_flags = 1; | 383 | has_flags = 1; |
384 | uint32_t *flags = RTA_DATA(rta); | 384 | uint32_t *flags = RTA_DATA(rta); |
385 | if (*flags & IFA_F_TENTATIVE) | 385 | if (*flags & IFA_F_TENTATIVE) |
386 | return 1; | 386 | return 1; |
387 | } | 387 | } |
388 | rta = RTA_NEXT(rta, msg_len); | 388 | rta = RTA_NEXT(rta, msg_len); |
389 | } | 389 | } |
390 | // According to <linux/if_addr.h>, if an IFA_FLAGS attribute is present, | 390 | // According to <linux/if_addr.h>, if an IFA_FLAGS attribute is present, |
391 | // the field ifa_flags should be ignored. | 391 | // the field ifa_flags should be ignored. |
392 | return !has_flags && (msg->ifa_flags & IFA_F_TENTATIVE); | 392 | return !has_flags && (msg->ifa_flags & IFA_F_TENTATIVE); |
393 | } | 393 | } |
394 | 394 | ||
395 | static int net_netlink_if_has_ll(int sock, int index) { | 395 | static int net_netlink_if_has_ll(int sock, int index) { |
396 | struct { | 396 | struct { |
397 | struct nlmsghdr header; | 397 | struct nlmsghdr header; |
398 | struct ifaddrmsg message; | 398 | struct ifaddrmsg message; |
399 | } req; | 399 | } req; |
400 | memset(&req, 0, sizeof(req)); | 400 | memset(&req, 0, sizeof(req)); |
401 | req.header.nlmsg_len = NLMSG_LENGTH(sizeof(req.message)); | 401 | req.header.nlmsg_len = NLMSG_LENGTH(sizeof(req.message)); |
402 | req.header.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; | 402 | req.header.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; |
403 | req.header.nlmsg_type = RTM_GETADDR; | 403 | req.header.nlmsg_type = RTM_GETADDR; |
404 | req.message.ifa_family = AF_INET6; | 404 | req.message.ifa_family = AF_INET6; |
405 | if (send(sock, &req, req.header.nlmsg_len, 0) != req.header.nlmsg_len) | 405 | if (send(sock, &req, req.header.nlmsg_len, 0) != req.header.nlmsg_len) |
406 | errExit("send"); | 406 | errExit("send"); |
407 | 407 | ||
408 | int found = 0; | 408 | int found = 0; |
409 | int all_parts_processed = 0; | 409 | int all_parts_processed = 0; |
410 | while (!all_parts_processed) { | 410 | while (!all_parts_processed) { |
411 | char buf[16384]; | 411 | char buf[16384]; |
412 | ssize_t len = recv(sock, buf, sizeof(buf), 0); | 412 | ssize_t len = recv(sock, buf, sizeof(buf), 0); |
413 | if (len < 0) | 413 | if (len < 0) |
414 | errExit("recv"); | 414 | errExit("recv"); |
415 | if (len < sizeof(struct nlmsghdr)) { | 415 | if (len < sizeof(struct nlmsghdr)) { |
416 | fprintf(stderr, "Received incomplete netlink message\n"); | 416 | fprintf(stderr, "Received incomplete netlink message\n"); |
417 | exit(1); | 417 | exit(1); |
418 | } | 418 | } |
419 | 419 | ||
420 | struct nlmsghdr *current_header = (struct nlmsghdr *) buf; | 420 | struct nlmsghdr *current_header = (struct nlmsghdr *) buf; |
421 | while (NLMSG_OK(current_header, len)) { | 421 | while (NLMSG_OK(current_header, len)) { |
422 | switch (current_header->nlmsg_type) { | 422 | switch (current_header->nlmsg_type) { |
423 | case RTM_NEWADDR: { | 423 | case RTM_NEWADDR: { |
424 | struct ifaddrmsg *msg = NLMSG_DATA(current_header); | 424 | struct ifaddrmsg *msg = NLMSG_DATA(current_header); |
425 | if (!found && msg->ifa_index == index && msg->ifa_scope == RT_SCOPE_LINK && | 425 | if (!found && msg->ifa_index == index && msg->ifa_scope == RT_SCOPE_LINK && |
426 | !net_netlink_address_tentative(current_header)) | 426 | !net_netlink_address_tentative(current_header)) |
427 | found = 1; | 427 | found = 1; |
428 | } | 428 | } |
429 | break; | 429 | break; |
430 | case NLMSG_NOOP: | 430 | case NLMSG_NOOP: |
431 | break; | 431 | break; |
432 | case NLMSG_DONE: | 432 | case NLMSG_DONE: |
433 | all_parts_processed = 1; | 433 | all_parts_processed = 1; |
434 | break; | 434 | break; |
435 | case NLMSG_ERROR: { | 435 | case NLMSG_ERROR: { |
436 | struct nlmsgerr *err = NLMSG_DATA(current_header); | 436 | struct nlmsgerr *err = NLMSG_DATA(current_header); |
437 | fprintf(stderr, "Netlink error: %d\n", err->error); | 437 | fprintf(stderr, "Netlink error: %d\n", err->error); |
438 | exit(1); | 438 | exit(1); |
439 | } | 439 | } |
440 | break; | 440 | break; |
441 | default: | 441 | default: |
442 | fprintf(stderr, "Unknown netlink message type: %u\n", current_header->nlmsg_type); | 442 | fprintf(stderr, "Unknown netlink message type: %u\n", current_header->nlmsg_type); |
443 | exit(1); | 443 | exit(1); |
444 | break; | 444 | break; |
445 | } | 445 | } |
446 | 446 | ||
447 | current_header = NLMSG_NEXT(current_header, len); | 447 | current_header = NLMSG_NEXT(current_header, len); |
448 | } | 448 | } |
449 | } | 449 | } |
450 | 450 | ||
451 | return found; | 451 | return found; |
452 | } | 452 | } |
453 | 453 | ||
454 | // wait for a link-local IPv6 address for DHCPv6 | 454 | // wait for a link-local IPv6 address for DHCPv6 |
@@ -468,27 +468,27 @@ void net_if_waitll(const char *ifname) { | |||
468 | perror("ioctl SIOGIFINDEX"); | 468 | perror("ioctl SIOGIFINDEX"); |
469 | exit(1); | 469 | exit(1); |
470 | } | 470 | } |
471 | close(inet6_sock); | 471 | close(inet6_sock); |
472 | int index = ifr.ifr_ifindex; | 472 | int index = ifr.ifr_ifindex; |
473 | 473 | ||
474 | // poll for link-local address | 474 | // poll for link-local address |
475 | int netlink_sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); | 475 | int netlink_sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); |
476 | if (netlink_sock < 0) | 476 | if (netlink_sock < 0) |
477 | errExit("socket"); | 477 | errExit("socket"); |
478 | int tries = 0; | 478 | int tries = 0; |
479 | int found = 0; | 479 | int found = 0; |
480 | while (tries < 60 && !found) { | 480 | while (tries < 60 && !found) { |
481 | if (tries >= 1) | 481 | if (tries >= 1) |
482 | usleep(500000); | 482 | usleep(500000); |
483 | 483 | ||
484 | found = net_netlink_if_has_ll(netlink_sock, index); | 484 | found = net_netlink_if_has_ll(netlink_sock, index); |
485 | 485 | ||
486 | tries++; | 486 | tries++; |
487 | } | 487 | } |
488 | close(netlink_sock); | 488 | close(netlink_sock); |
489 | 489 | ||
490 | if (!found) { | 490 | if (!found) { |
491 | fprintf(stderr, "Waiting for link-local IPv6 address of %s timed out\n", ifname); | 491 | fprintf(stderr, "Waiting for link-local IPv6 address of %s timed out\n", ifname); |
492 | exit(1); | 492 | exit(1); |
493 | } | 493 | } |
494 | } | 494 | } |