tls: can download kernels now :)
[oweals/busybox.git] / networking / udhcp / d6_packet.c
index 3a1bb3df1a1a5fd1273528f60789f224c6d1a5bf..e166f520de994b50c2c9f77094297ee4dc4e103e 100644 (file)
@@ -17,12 +17,12 @@ void FAST_FUNC d6_dump_packet(struct d6_packet *packet)
        if (dhcp_verbose < 2)
                return;
 
-       bb_info_msg(
-               " xid %x"
+       bb_error_msg(
+               "xid %x"
                , packet->d6_xid32
        );
        //*bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0';
-       //bb_info_msg(" chaddr %s", buf);
+       //bb_error_msg(" chaddr %s", buf);
 }
 #endif
 
@@ -35,15 +35,15 @@ int FAST_FUNC d6_recv_kernel_packet(struct in6_addr *peer_ipv6
        memset(packet, 0, sizeof(*packet));
        bytes = safe_read(fd, packet, sizeof(*packet));
        if (bytes < 0) {
-               log1("Packet read error, ignoring");
+               log1("packet read error, ignoring");
                return bytes; /* returns -1 */
        }
 
        if (bytes < offsetof(struct d6_packet, d6_options)) {
-               bb_info_msg("Packet with bad magic, ignoring");
+               bb_error_msg("packet with bad magic, ignoring");
                return -2;
        }
-       log1("Received a packet");
+       log1("received %s", "a packet");
        d6_dump_packet(packet);
 
        return bytes;
@@ -92,16 +92,20 @@ int FAST_FUNC d6_send_raw_packet(
        /* size, excluding IP header: */
        packet.udp.len = htons(sizeof(struct udphdr) + d6_pkt_size);
        packet.ip6.ip6_plen = packet.udp.len;
-       /* UDP checksum skips first four bytes of IP header.
-        * IPv6 'hop limit' field should be 0.
-        * 'next header' field should be summed as if it is in a different
-        * position, therefore we write its value into ip6_hlim:
+       /*
+        * Someone was smoking weed (at least) while inventing UDP checksumming:
+        * UDP checksum skips first four bytes of IPv6 header.
+        * 'next header' field should be summed as if it is one more byte
+        * to the right, therefore we write its value (IPPROTO_UDP)
+        * into ip6_hlim, and its 'real' location remains zero-filled for now.
         */
        packet.ip6.ip6_hlim = IPPROTO_UDP;
-       packet.udp.check = inet_cksum((uint16_t *)&packet + 2,
-                               offsetof(struct ip6_udp_d6_packet, data) - 4 + d6_pkt_size);
+       packet.udp.check = inet_cksum(
+                               (uint16_t *)&packet + 2,
+                               offsetof(struct ip6_udp_d6_packet, data) - 4 + d6_pkt_size
+       );
        /* fix 'hop limit' and 'next header' after UDP checksumming */
-       packet.ip6.ip6_hlim = 8;
+       packet.ip6.ip6_hlim = 1; /* observed Windows machines to use hlim=1 */
        packet.ip6.ip6_nxt = IPPROTO_UDP;
 
        d6_dump_packet(d6_pkt);