Treat xid as a uint32_t in network byte order on the wire.
authorflorian <florian@openbsd.org>
Mon, 13 Dec 2021 11:03:23 +0000 (11:03 +0000)
committerflorian <florian@openbsd.org>
Mon, 13 Dec 2021 11:03:23 +0000 (11:03 +0000)
Internally this doesn't matter since we only care about equality.
This makes logging output comparable to tcpdump(8).

Pointed out by joel@
OK claudio

sbin/dhcpleased/engine.c
sbin/dhcpleased/frontend.c

index 5b7ac0c..7c7cb45 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: engine.c,v 1.31 2021/12/13 11:02:26 florian Exp $     */
+/*     $OpenBSD: engine.c,v 1.32 2021/12/13 11:03:23 florian Exp $     */
 
 /*
  * Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@@ -848,7 +848,7 @@ parse_dhcp(struct dhcpleased_iface *iface, struct imsg_dhcp *dhcp)
                return;
        }
 
-       if (dhcp_hdr->xid != iface->xid)
+       if (ntohl(dhcp_hdr->xid) != iface->xid)
                return; /* silently ignore wrong xid */
 
        if (rem < sizeof(cookie))
@@ -1770,7 +1770,7 @@ log_dhcp_hdr(struct dhcp_hdr *dhcp_hdr)
            "Unknown", dhcp_hdr->htype);
        log_debug("dhcp_hdr hlen: %d", dhcp_hdr->hlen);
        log_debug("dhcp_hdr hops: %d", dhcp_hdr->hops);
-       log_debug("dhcp_hdr xid: 0x%x", dhcp_hdr->xid);
+       log_debug("dhcp_hdr xid: 0x%x", ntohl(dhcp_hdr->xid));
        log_debug("dhcp_hdr secs: %u", dhcp_hdr->secs);
        log_debug("dhcp_hdr flags: 0x%x", dhcp_hdr->flags);
        log_debug("dhcp_hdr ciaddr: %s", inet_ntop(AF_INET, &dhcp_hdr->ciaddr,
index 903d380..90b6c20 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: frontend.c,v 1.26 2021/12/13 11:02:26 florian Exp $   */
+/*     $OpenBSD: frontend.c,v 1.27 2021/12/13 11:03:23 florian Exp $   */
 
 /*
  * Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
@@ -935,7 +935,7 @@ build_packet(uint8_t message_type, char *if_name, uint32_t xid,
        hdr->htype = HTYPE_ETHER;
        hdr->hlen = 6;
        hdr->hops = 0;
-       hdr->xid = xid;
+       hdr->xid = htonl(xid);
        hdr->secs = 0;
        hdr->ciaddr = *ciaddr;
        memcpy(hdr->chaddr, hw_address, sizeof(*hw_address));