diff options
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index dfd5ca606..660b943ce 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -561,7 +561,7 @@ static void udhcp_run_script(struct dhcp_packet *packet, const char *name) | |||
561 | envp = fill_envp(packet); | 561 | envp = fill_envp(packet); |
562 | 562 | ||
563 | /* call script */ | 563 | /* call script */ |
564 | log1("Executing %s %s", client_config.script, name); | 564 | log1("executing %s %s", client_config.script, name); |
565 | argv[0] = (char*) client_config.script; | 565 | argv[0] = (char*) client_config.script; |
566 | argv[1] = (char*) name; | 566 | argv[1] = (char*) name; |
567 | argv[2] = NULL; | 567 | argv[2] = NULL; |
@@ -714,7 +714,7 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested) | |||
714 | */ | 714 | */ |
715 | add_client_options(&packet); | 715 | add_client_options(&packet); |
716 | 716 | ||
717 | bb_info_msg("Sending discover..."); | 717 | bb_error_msg("sending %s", "discover"); |
718 | return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); | 718 | return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); |
719 | } | 719 | } |
720 | 720 | ||
@@ -758,7 +758,7 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste | |||
758 | add_client_options(&packet); | 758 | add_client_options(&packet); |
759 | 759 | ||
760 | addr.s_addr = requested; | 760 | addr.s_addr = requested; |
761 | bb_info_msg("Sending select for %s...", inet_ntoa(addr)); | 761 | bb_error_msg("sending select for %s", inet_ntoa(addr)); |
762 | return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); | 762 | return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); |
763 | } | 763 | } |
764 | 764 | ||
@@ -797,7 +797,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) | |||
797 | */ | 797 | */ |
798 | add_client_options(&packet); | 798 | add_client_options(&packet); |
799 | 799 | ||
800 | bb_info_msg("Sending renew..."); | 800 | bb_error_msg("sending %s", "renew"); |
801 | return bcast_or_ucast(&packet, ciaddr, server); | 801 | return bcast_or_ucast(&packet, ciaddr, server); |
802 | } | 802 | } |
803 | 803 | ||
@@ -826,7 +826,7 @@ static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t req | |||
826 | 826 | ||
827 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); | 827 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); |
828 | 828 | ||
829 | bb_info_msg("Sending decline..."); | 829 | bb_error_msg("sending %s", "decline"); |
830 | return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); | 830 | return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY); |
831 | } | 831 | } |
832 | #endif | 832 | #endif |
@@ -846,7 +846,7 @@ static int send_release(uint32_t server, uint32_t ciaddr) | |||
846 | 846 | ||
847 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); | 847 | udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); |
848 | 848 | ||
849 | bb_info_msg("Sending release..."); | 849 | bb_error_msg("sending %s", "release"); |
850 | /* Note: normally we unicast here since "server" is not zero. | 850 | /* Note: normally we unicast here since "server" is not zero. |
851 | * However, there _are_ people who run "address-less" DHCP servers, | 851 | * However, there _are_ people who run "address-less" DHCP servers, |
852 | * and reportedly ISC dhcp client and Windows allow that. | 852 | * and reportedly ISC dhcp client and Windows allow that. |
@@ -881,7 +881,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
881 | if (bytes < 0) { | 881 | if (bytes < 0) { |
882 | if (errno == EINTR) | 882 | if (errno == EINTR) |
883 | continue; | 883 | continue; |
884 | log1("Packet read error, ignoring"); | 884 | log1("packet read error, ignoring"); |
885 | /* NB: possible down interface, etc. Caller should pause. */ | 885 | /* NB: possible down interface, etc. Caller should pause. */ |
886 | return bytes; /* returns -1 */ | 886 | return bytes; /* returns -1 */ |
887 | } | 887 | } |
@@ -889,13 +889,13 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
889 | } | 889 | } |
890 | 890 | ||
891 | if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) { | 891 | if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) { |
892 | log1("Packet is too short, ignoring"); | 892 | log1("packet is too short, ignoring"); |
893 | return -2; | 893 | return -2; |
894 | } | 894 | } |
895 | 895 | ||
896 | if (bytes < ntohs(packet.ip.tot_len)) { | 896 | if (bytes < ntohs(packet.ip.tot_len)) { |
897 | /* packet is bigger than sizeof(packet), we did partial read */ | 897 | /* packet is bigger than sizeof(packet), we did partial read */ |
898 | log1("Oversized packet, ignoring"); | 898 | log1("oversized packet, ignoring"); |
899 | return -2; | 899 | return -2; |
900 | } | 900 | } |
901 | 901 | ||
@@ -910,7 +910,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
910 | /* || bytes > (int) sizeof(packet) - can't happen */ | 910 | /* || bytes > (int) sizeof(packet) - can't happen */ |
911 | || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) | 911 | || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) |
912 | ) { | 912 | ) { |
913 | log1("Unrelated/bogus packet, ignoring"); | 913 | log1("unrelated/bogus packet, ignoring"); |
914 | return -2; | 914 | return -2; |
915 | } | 915 | } |
916 | 916 | ||
@@ -918,7 +918,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
918 | check = packet.ip.check; | 918 | check = packet.ip.check; |
919 | packet.ip.check = 0; | 919 | packet.ip.check = 0; |
920 | if (check != inet_cksum((uint16_t *)&packet.ip, sizeof(packet.ip))) { | 920 | if (check != inet_cksum((uint16_t *)&packet.ip, sizeof(packet.ip))) { |
921 | log1("Bad IP header checksum, ignoring"); | 921 | log1("bad IP header checksum, ignoring"); |
922 | return -2; | 922 | return -2; |
923 | } | 923 | } |
924 | 924 | ||
@@ -943,17 +943,17 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) | |||
943 | check = packet.udp.check; | 943 | check = packet.udp.check; |
944 | packet.udp.check = 0; | 944 | packet.udp.check = 0; |
945 | if (check && check != inet_cksum((uint16_t *)&packet, bytes)) { | 945 | if (check && check != inet_cksum((uint16_t *)&packet, bytes)) { |
946 | log1("Packet with bad UDP checksum received, ignoring"); | 946 | log1("packet with bad UDP checksum received, ignoring"); |
947 | return -2; | 947 | return -2; |
948 | } | 948 | } |
949 | skip_udp_sum_check: | 949 | skip_udp_sum_check: |
950 | 950 | ||
951 | if (packet.data.cookie != htonl(DHCP_MAGIC)) { | 951 | if (packet.data.cookie != htonl(DHCP_MAGIC)) { |
952 | bb_info_msg("Packet with bad magic, ignoring"); | 952 | bb_error_msg("packet with bad magic, ignoring"); |
953 | return -2; | 953 | return -2; |
954 | } | 954 | } |
955 | 955 | ||
956 | log1("Received a packet"); | 956 | log1("received %s", "a packet"); |
957 | udhcp_dump_packet(&packet.data); | 957 | udhcp_dump_packet(&packet.data); |
958 | 958 | ||
959 | bytes -= sizeof(packet.ip) + sizeof(packet.udp); | 959 | bytes -= sizeof(packet.ip) + sizeof(packet.udp); |
@@ -992,14 +992,14 @@ static int udhcp_raw_socket(int ifindex) | |||
992 | int fd; | 992 | int fd; |
993 | struct sockaddr_ll sock; | 993 | struct sockaddr_ll sock; |
994 | 994 | ||
995 | log1("Opening raw socket on ifindex %d", ifindex); //log2? | 995 | log1("opening raw socket on ifindex %d", ifindex); //log2? |
996 | 996 | ||
997 | fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); | 997 | fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); |
998 | /* ^^^^^ | 998 | /* ^^^^^ |
999 | * SOCK_DGRAM: remove link-layer headers on input (SOCK_RAW keeps them) | 999 | * SOCK_DGRAM: remove link-layer headers on input (SOCK_RAW keeps them) |
1000 | * ETH_P_IP: want to receive only packets with IPv4 eth type | 1000 | * ETH_P_IP: want to receive only packets with IPv4 eth type |
1001 | */ | 1001 | */ |
1002 | log1("Got raw socket fd"); //log2? | 1002 | log1("got raw socket fd"); //log2? |
1003 | 1003 | ||
1004 | sock.sll_family = AF_PACKET; | 1004 | sock.sll_family = AF_PACKET; |
1005 | sock.sll_protocol = htons(ETH_P_IP); | 1005 | sock.sll_protocol = htons(ETH_P_IP); |
@@ -1055,23 +1055,23 @@ static int udhcp_raw_socket(int ifindex) | |||
1055 | /* Ignoring error (kernel may lack support for this) */ | 1055 | /* Ignoring error (kernel may lack support for this) */ |
1056 | if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, | 1056 | if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, |
1057 | sizeof(filter_prog)) >= 0) | 1057 | sizeof(filter_prog)) >= 0) |
1058 | log1("Attached filter to raw socket fd"); // log? | 1058 | log1("attached filter to raw socket fd"); // log? |
1059 | } | 1059 | } |
1060 | #endif | 1060 | #endif |
1061 | 1061 | ||
1062 | if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) { | 1062 | if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) { |
1063 | if (errno != ENOPROTOOPT) | 1063 | if (errno != ENOPROTOOPT) |
1064 | log1("Can't set PACKET_AUXDATA on raw socket"); | 1064 | log1("can't set PACKET_AUXDATA on raw socket"); |
1065 | } | 1065 | } |
1066 | 1066 | ||
1067 | log1("Created raw socket"); | 1067 | log1("created raw socket"); |
1068 | 1068 | ||
1069 | return fd; | 1069 | return fd; |
1070 | } | 1070 | } |
1071 | 1071 | ||
1072 | static void change_listen_mode(int new_mode) | 1072 | static void change_listen_mode(int new_mode) |
1073 | { | 1073 | { |
1074 | log1("Entering listen mode: %s", | 1074 | log1("entering listen mode: %s", |
1075 | new_mode != LISTEN_NONE | 1075 | new_mode != LISTEN_NONE |
1076 | ? (new_mode == LISTEN_KERNEL ? "kernel" : "raw") | 1076 | ? (new_mode == LISTEN_KERNEL ? "kernel" : "raw") |
1077 | : "none" | 1077 | : "none" |
@@ -1092,7 +1092,7 @@ static void change_listen_mode(int new_mode) | |||
1092 | /* Called only on SIGUSR1 */ | 1092 | /* Called only on SIGUSR1 */ |
1093 | static void perform_renew(void) | 1093 | static void perform_renew(void) |
1094 | { | 1094 | { |
1095 | bb_info_msg("Performing a DHCP renew"); | 1095 | bb_error_msg("performing DHCP renew"); |
1096 | switch (state) { | 1096 | switch (state) { |
1097 | case BOUND: | 1097 | case BOUND: |
1098 | change_listen_mode(LISTEN_KERNEL); | 1098 | change_listen_mode(LISTEN_KERNEL); |
@@ -1122,12 +1122,12 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip) | |||
1122 | temp_addr.s_addr = server_addr; | 1122 | temp_addr.s_addr = server_addr; |
1123 | strcpy(buffer, inet_ntoa(temp_addr)); | 1123 | strcpy(buffer, inet_ntoa(temp_addr)); |
1124 | temp_addr.s_addr = requested_ip; | 1124 | temp_addr.s_addr = requested_ip; |
1125 | bb_info_msg("Unicasting a release of %s to %s", | 1125 | bb_error_msg("unicasting a release of %s to %s", |
1126 | inet_ntoa(temp_addr), buffer); | 1126 | inet_ntoa(temp_addr), buffer); |
1127 | send_release(server_addr, requested_ip); /* unicast */ | 1127 | send_release(server_addr, requested_ip); /* unicast */ |
1128 | udhcp_run_script(NULL, "deconfig"); | 1128 | udhcp_run_script(NULL, "deconfig"); |
1129 | } | 1129 | } |
1130 | bb_info_msg("Entering released state"); | 1130 | bb_error_msg("entering released state"); |
1131 | 1131 | ||
1132 | change_listen_mode(LISTEN_NONE); | 1132 | change_listen_mode(LISTEN_NONE); |
1133 | state = RELEASED; | 1133 | state = RELEASED; |
@@ -1395,7 +1395,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1395 | /* Create pidfile */ | 1395 | /* Create pidfile */ |
1396 | write_pidfile(client_config.pidfile); | 1396 | write_pidfile(client_config.pidfile); |
1397 | /* Goes to stdout (unless NOMMU) and possibly syslog */ | 1397 | /* Goes to stdout (unless NOMMU) and possibly syslog */ |
1398 | bb_info_msg("%s (v"BB_VER") started", applet_name); | 1398 | bb_error_msg("started, v"BB_VER); |
1399 | /* Set up the signal pipe */ | 1399 | /* Set up the signal pipe */ |
1400 | udhcp_sp_setup(); | 1400 | udhcp_sp_setup(); |
1401 | /* We want random_xid to be random... */ | 1401 | /* We want random_xid to be random... */ |
@@ -1434,7 +1434,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1434 | retval = 0; | 1434 | retval = 0; |
1435 | /* If we already timed out, fall through with retval = 0, else... */ | 1435 | /* If we already timed out, fall through with retval = 0, else... */ |
1436 | if ((int)tv.tv_sec > 0) { | 1436 | if ((int)tv.tv_sec > 0) { |
1437 | log1("Waiting on select %u seconds", (int)tv.tv_sec); | 1437 | log1("waiting on select %u seconds", (int)tv.tv_sec); |
1438 | timestamp_before_wait = (unsigned)monotonic_sec(); | 1438 | timestamp_before_wait = (unsigned)monotonic_sec(); |
1439 | retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); | 1439 | retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); |
1440 | if (retval < 0) { | 1440 | if (retval < 0) { |
@@ -1485,14 +1485,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1485 | udhcp_run_script(NULL, "leasefail"); | 1485 | udhcp_run_script(NULL, "leasefail"); |
1486 | #if BB_MMU /* -b is not supported on NOMMU */ | 1486 | #if BB_MMU /* -b is not supported on NOMMU */ |
1487 | if (opt & OPT_b) { /* background if no lease */ | 1487 | if (opt & OPT_b) { /* background if no lease */ |
1488 | bb_info_msg("No lease, forking to background"); | 1488 | bb_error_msg("no lease, forking to background"); |
1489 | client_background(); | 1489 | client_background(); |
1490 | /* do not background again! */ | 1490 | /* do not background again! */ |
1491 | opt = ((opt & ~OPT_b) | OPT_f); | 1491 | opt = ((opt & ~OPT_b) | OPT_f); |
1492 | } else | 1492 | } else |
1493 | #endif | 1493 | #endif |
1494 | if (opt & OPT_n) { /* abort if no lease */ | 1494 | if (opt & OPT_n) { /* abort if no lease */ |
1495 | bb_info_msg("No lease, failing"); | 1495 | bb_error_msg("no lease, failing"); |
1496 | retval = 1; | 1496 | retval = 1; |
1497 | goto ret; | 1497 | goto ret; |
1498 | } | 1498 | } |
@@ -1520,7 +1520,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1520 | state = RENEWING; | 1520 | state = RENEWING; |
1521 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1521 | client_config.first_secs = 0; /* make secs field count from 0 */ |
1522 | change_listen_mode(LISTEN_KERNEL); | 1522 | change_listen_mode(LISTEN_KERNEL); |
1523 | log1("Entering renew state"); | 1523 | log1("entering renew state"); |
1524 | /* fall right through */ | 1524 | /* fall right through */ |
1525 | case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ | 1525 | case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ |
1526 | case_RENEW_REQUESTED: | 1526 | case_RENEW_REQUESTED: |
@@ -1540,7 +1540,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1540 | continue; | 1540 | continue; |
1541 | } | 1541 | } |
1542 | /* Timed out, enter rebinding state */ | 1542 | /* Timed out, enter rebinding state */ |
1543 | log1("Entering rebinding state"); | 1543 | log1("entering rebinding state"); |
1544 | state = REBINDING; | 1544 | state = REBINDING; |
1545 | /* fall right through */ | 1545 | /* fall right through */ |
1546 | case REBINDING: | 1546 | case REBINDING: |
@@ -1555,7 +1555,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1555 | continue; | 1555 | continue; |
1556 | } | 1556 | } |
1557 | /* Timed out, enter init state */ | 1557 | /* Timed out, enter init state */ |
1558 | bb_info_msg("Lease lost, entering init state"); | 1558 | bb_error_msg("lease lost, entering init state"); |
1559 | udhcp_run_script(NULL, "deconfig"); | 1559 | udhcp_run_script(NULL, "deconfig"); |
1560 | state = INIT_SELECTING; | 1560 | state = INIT_SELECTING; |
1561 | client_config.first_secs = 0; /* make secs field count from 0 */ | 1561 | client_config.first_secs = 0; /* make secs field count from 0 */ |
@@ -1603,7 +1603,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1603 | timeout = INT_MAX; | 1603 | timeout = INT_MAX; |
1604 | continue; | 1604 | continue; |
1605 | case SIGTERM: | 1605 | case SIGTERM: |
1606 | bb_info_msg("Received SIGTERM"); | 1606 | bb_error_msg("received %s", "SIGTERM"); |
1607 | goto ret0; | 1607 | goto ret0; |
1608 | } | 1608 | } |
1609 | 1609 | ||
@@ -1621,7 +1621,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1621 | len = udhcp_recv_raw_packet(&packet, sockfd); | 1621 | len = udhcp_recv_raw_packet(&packet, sockfd); |
1622 | if (len == -1) { | 1622 | if (len == -1) { |
1623 | /* Error is severe, reopen socket */ | 1623 | /* Error is severe, reopen socket */ |
1624 | bb_info_msg("Read error: %s, reopening socket", strerror(errno)); | 1624 | bb_error_msg("read error: %s, reopening socket", strerror(errno)); |
1625 | sleep(discover_timeout); /* 3 seconds by default */ | 1625 | sleep(discover_timeout); /* 3 seconds by default */ |
1626 | change_listen_mode(listen_mode); /* just close and reopen */ | 1626 | change_listen_mode(listen_mode); /* just close and reopen */ |
1627 | } | 1627 | } |
@@ -1744,7 +1744,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1744 | client_config.interface, | 1744 | client_config.interface, |
1745 | arpping_ms) | 1745 | arpping_ms) |
1746 | ) { | 1746 | ) { |
1747 | bb_info_msg("Offered address is in use " | 1747 | bb_error_msg("offered address is in use " |
1748 | "(got ARP reply), declining"); | 1748 | "(got ARP reply), declining"); |
1749 | send_decline(/*xid,*/ server_addr, packet.yiaddr); | 1749 | send_decline(/*xid,*/ server_addr, packet.yiaddr); |
1750 | 1750 | ||
@@ -1763,7 +1763,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1763 | #endif | 1763 | #endif |
1764 | /* enter bound state */ | 1764 | /* enter bound state */ |
1765 | temp_addr.s_addr = packet.yiaddr; | 1765 | temp_addr.s_addr = packet.yiaddr; |
1766 | bb_info_msg("Lease of %s obtained, lease time %u", | 1766 | bb_error_msg("lease of %s obtained, lease time %u", |
1767 | inet_ntoa(temp_addr), (unsigned)lease_seconds); | 1767 | inet_ntoa(temp_addr), (unsigned)lease_seconds); |
1768 | requested_ip = packet.yiaddr; | 1768 | requested_ip = packet.yiaddr; |
1769 | 1769 | ||
@@ -1817,7 +1817,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1817 | goto non_matching_svid; | 1817 | goto non_matching_svid; |
1818 | } | 1818 | } |
1819 | /* return to init state */ | 1819 | /* return to init state */ |
1820 | bb_info_msg("Received DHCP NAK"); | 1820 | bb_error_msg("received %s", "DHCP NAK"); |
1821 | udhcp_run_script(&packet, "nak"); | 1821 | udhcp_run_script(&packet, "nak"); |
1822 | if (state != REQUESTING) | 1822 | if (state != REQUESTING) |
1823 | udhcp_run_script(NULL, "deconfig"); | 1823 | udhcp_run_script(NULL, "deconfig"); |