Changeset bbb7ffe in mainline


Ignore:
Timestamp:
2022-06-24T09:40:05Z (2 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b7155d7
Parents:
52214a2
git-author:
Jiri Svoboda <jiri@…> (2022-07-23 19:39:46)
git-committer:
Jiri Svoboda <jiri@…> (2022-06-24 09:40:05)
Message:

Randomize DHCP XID, cosmetic flag fix

Set XID to a random 32-bit number, instead of 42.
DHCP flags is technically 16-bit field, although this has no effect on
the function.

Location:
uspace/srv/net/dhcp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/dhcp/dhcp.c

    r52214a2 rbbb7ffe  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4747#include <io/log.h>
    4848#include <loc.h>
     49#include <rndgen.h>
    4950#include <stdio.h>
    5051#include <stdlib.h>
     
    9596        /** DNS server */
    9697        inet_addr_t dns_server;
     98        /** Transaction ID */
     99        uint32_t xid;
    97100} dhcp_offer_t;
    98101
     
    114117        /** Last received offer */
    115118        dhcp_offer_t offer;
     119        /** Random number generator */
     120        rndgen_t *rndgen;
    116121} dhcp_link_t;
    117122
     
    154159        dhcp_hdr_t *hdr = (dhcp_hdr_t *)msgbuf;
    155160        uint8_t *opt = msgbuf + sizeof(dhcp_hdr_t);
     161        uint32_t xid;
     162        errno_t rc;
     163
     164        rc = rndgen_uint32(dlink->rndgen, &xid);
     165        if (rc != EOK)
     166                return rc;
    156167
    157168        memset(msgbuf, 0, MAX_MSG_SIZE);
     
    159170        hdr->htype = 1; /* AHRD_ETHERNET */
    160171        hdr->hlen = ETH_ADDR_SIZE;
    161         hdr->xid = host2uint32_t_be(42);
    162         hdr->flags = flag_broadcast;
     172        hdr->xid = host2uint32_t_be(xid);
     173        hdr->flags = host2uint16_t_be(flag_broadcast);
    163174
    164175        eth_addr_encode(&dlink->link_info.mac_addr, hdr->chaddr);
     
    168179        opt[1] = 1;
    169180        opt[2] = msg_dhcpdiscover;
     181
    170182        opt[3] = opt_end;
    171183
     
    183195        hdr->htype = 1; /* AHRD_ETHERNET */
    184196        hdr->hlen = 6;
    185         hdr->xid = host2uint32_t_be(42);
    186         hdr->flags = flag_broadcast;
     197        hdr->xid = host2uint32_t_be(offer->xid);
     198        hdr->flags = host2uint16_t_be(flag_broadcast);
    187199        eth_addr_encode(&dlink->link_info.mac_addr, hdr->chaddr);
    188200        hdr->opt_magic = host2uint32_t_be(dhcp_opt_magic);
     
    257269
    258270        inet_naddr_set(yiaddr.addr, 0, &offer->oaddr);
     271        offer->xid = uint32_t_be2host(hdr->xid);
    259272
    260273        msgb = (uint8_t *)msg;
     
    456469                return ENOMEM;
    457470
     471        rc = rndgen_create(&dlink->rndgen);
     472        if (rc != EOK)
     473                goto error;
     474
    458475        dlink->link_id = link_id;
    459476        dlink->timeout = fibril_timer_create(NULL);
     
    493510        return EOK;
    494511error:
     512        if (dlink != NULL && dlink->rndgen != NULL)
     513                rndgen_destroy(dlink->rndgen);
    495514        if (dlink != NULL && dlink->timeout != NULL)
    496515                fibril_timer_destroy(dlink->timeout);
  • uspace/srv/net/dhcp/dhcp_std.h

    r52214a2 rbbb7ffe  
    11/*
    2  * Copyright (c) 2013 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    8787/** Values for dhcp_hdr_t.flags */
    8888enum dhcp_flags {
    89         flag_broadcast = 0x80
     89        flag_broadcast = 0x8000
    9090};
    9191
Note: See TracChangeset for help on using the changeset viewer.