public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Robin Farine <acnrf@dial.eunet.ch>
To: ecos-discuss@sources.redhat.com
Subject: Re: [ECOS] dhcp XID generation
Date: Thu, 03 May 2001 10:52:00 -0000	[thread overview]
Message-ID: <86elu6jpa0.fsf@halftrack.hq.acn-group.ch> (raw)
In-Reply-To: <wwt7kzybgjb.fsf@masala.cambridge.redhat.com>

Hugo Tyson <hmt@redhat.com> writes:

> Robin Farine <acnrf@dial.eunet.ch> writes:
> > In a system with a single power supply but many independent boards
> > running eCos and using the DHCP client, switching the system on sometimes
> > results into some boards configured with the *same* parameters (IP
> > address, ...).
> 
> ...and all using the same application binary, so (int)res is the same,
> right, I can see that would be a problem.
> 
> > The problem resides in the method used to generate the DHCP request's XID
> > field. A solution that seems to work for us follows:
> > 
> > <Changelog>
> > 2001-05-03  Robin Farine  <acnrf@dial.eunet.ch>
> > 
> > 	* src/lib/dhcp_prot.c (do_dhcp): Uses arc4random() instead of
> > 	cyg_current_time() to generate the XID field to improve randomness.
> > </Changelog>
> > 
> > <patch>
> > Index: packages/net/tcpip/current/src/lib/dhcp_prot.c
> > ===================================================================
> > RCS file: /usr/cvs/eCos/packages/net/net/tcpip/current/src/lib/dhcp_prot.c,v
> > retrieving revision 1.1.1.1
> > retrieving revision 1.2
> > diff -r1.1.1.1 -r1.2
> > 397c397
> > <         xid = (cyg_uint32)res + (cyg_uint32)(0xffffffff & cyg_current_time());
> > ---
> > >         xid = (cyg_uint32)res + (cyg_uint32)arc4random();
> > </patch>
> 
> Is that really random enough?  (Yes, I know the question has no meaning to
> a true mathematician).  Yeah, the clock is free-running fast, in general.
> 
> You could just pick up the ESA from ifr.ifr_hwaddr.sa_data at that point, I
> believe, to salt the token further.  It was set in bring_half_up(), as well
> as later on in the routine.

Yes right, we could use the two most significant bytes of the ESA as the most
significant 16 bits of the XID and the 16 least significant bits of the
arc4random() result as the 16 least significant bits of the XID. Something like:

<patch>
Index: packages/net/tcpip/current/src/lib/dhcp_prot.c
===================================================================
RCS file: /usr/cvs/eCos/packages/net/net/tcpip/current/src/lib/dhcp_prot.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -r1.1.1.1 -r1.2
397c397,399
<         xid = (cyg_uint32)res + (cyg_uint32)(0xffffffff & cyg_current_time());
---
>         xid = ((cyg_uint32)ifr.ifr_hwaddr.sa_data[5] << 24) |
> 	  ((cyg_uint32)ifr.ifr_hwaddr.sa_data[4] << 16) |
> 	  ((cyg_uint32)arc4random() & 0xffff);
</patch>

<Changelog>
2001-05-03  Robin Farine  <acnrf@dial.eunet.ch>

	* src/lib/dhcp_prot.c (do_dhcp): Decreases the probability that
	two clients on a given IP subnet generate the same XID.
</Changelog>

Robin

  reply	other threads:[~2001-05-03 10:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-03  8:08 Robin Farine
2001-05-03  8:30 ` Hugo Tyson
2001-05-03 10:52   ` Robin Farine [this message]
2001-05-04 10:40   ` Robin Farine
2001-05-09 10:30     ` Hugo Tyson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86elu6jpa0.fsf@halftrack.hq.acn-group.ch \
    --to=acnrf@dial.eunet.ch \
    --cc=ecos-discuss@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).