patchlwIP - A Lightweight TCP/IP stack - Patches: patch #6683, Customizable AUTOIP...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #6683: Customizable AUTOIP "seed" address

Submitted by:  Luca Ceresoli <lucaceresoli>
Submitted on:  Wed 03 Dec 2008 11:48:27 AM UTC  
 
Category:  None Priority:  3 - Low
Status:  Done Privacy:  Public
Assigned to:  Simon Goldschmidt <goldsimon> Open/Closed:  Closed
Planned Release:  None

( Jump to the original submission)

Fri 19 Dec 2008 06:17:27 PM UTC, comment #7: 

Yep, checked that in. And sorry for forgetting the s in your name!

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Fri 12 Dec 2008 09:45:34 AM UTC, comment #6: 

One more little patch, attached. It fixes a subtle bug on operator precedence (and a typo).
The rest is OK to me.

(file #17034)

Luca Ceresoli <lucaceresoli>
Wed 10 Dec 2008 05:09:32 PM UTC, comment #5: 

That's great, I've checked it in (plus an assert the range is correct afterwards). As I can only compile it, not test it, I would be pleased if you could try it.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Tue 09 Dec 2008 01:57:50 PM UTC, comment #4: 

You are 100% right.

I sketched out a tentative improvement:

// 169.254.0.0
#define AUTOIP_NET 0xA9FE0000
...
static void
autoip_create_addr(struct netif *netif, struct ip_addr *IPAddr)
{
  /* Here we create an IP-Address out of range 169.254.1.0 to 169.254.254.255
   * compliant to RFC 3927 Section 2.1
   * We have 254 * 256 possibilities
   */
  u32_t addr = ntohl(LWIP_AUTOIP_CREATE_SEED_ADDR(netif));
  addr += netif->autoip->tried_llipaddr;
  addr = AUTOIP_NET | (addr & 0xffff);
  /* Now, 169.254.0.0 <= addr <= 169.254.255.255 */

  if (addr < AUTOIP_RANGE_START) {
    addr += AUTOIP_RANGE_END - AUTOIP_RANGE_START + 1;
  }
  if (addr > AUTOIP_RANGE_END) {
    addr -= AUTOIP_RANGE_END - AUTOIP_RANGE_START + 1;
  }
  IPAddr->addr = htonl(addr);

  LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | 1,
    ("autoip_create_addr(): tried_llipaddr=%"U16_F", 0x%08"X32_F"\n",
    (u16_t)(netif->autoip->tried_llipaddr), (u32_t)(IPAddr->addr)));
}

Pros:

  • The seed is a complete IP address (in ip_addr byte order).
  • It is safe (no risk to go out of range).
Luca Ceresoli <lucaceresoli>
Thu 04 Dec 2008 06:36:28 PM UTC, comment #3: 

The reason I change the seed to be an offset is to make sure we stay in the given range for autoip. I admin there's an overbiasing of 0x100, but I don't think the check is double: If the address given by LWIP_AUTOIP_CREATE_SEED_ADDR is too high, the calculations below can fail to get the address into the autoip range.

But I also can see it would be nice to just save the old address. While you could just substract AUTOIP_RANGE_START from it in your implementation of LWIP_AUTOIP_CREATE_SEED_ADDR, maybe I'll change it again. But I don't have the time for that right now, I'm sorry.

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Thu 04 Dec 2008 11:33:47 AM UTC, comment #2: 

> I've checked in a slightly modified version of the patch

Much cleaner, but I don't like the new meaning you gave to the seed.
In my original patch it is an entire IP address (hence the name "SEED_ADDR").
In your checkin it is simply a seed, not a copy of the IP address.
E.g. from seed 0x1234 the IP 0xa9fe1334 (1334, not 1234) will be generated.

Why the hell do I care?
My implementation was meant to eliminate conflicts on big networks (10-20.000 devices) that are rarely physically modified after installation.
This can be achieved by saving in non-volatile memory the IP address obtained via AUTOIP, and used as a default at the next reboot. Result: no conflicts after reboot -- even across temporary network partitions!
This would be a bit of a hack to implement unless the LWIP_AUTOIP_CREATE_SEED_ADDR() macro returned a whole IPv4 address.

A few minor notes follow.

>  /* creates random LL IP-Address for a network interface */
> -static void autoip_create_rand_addr(struct netif netif, struct ip_addr RandomIPAddr);
> +static void autoip_create_addr(struct netif netif, struct ip_addr RandomIPAddr);

The "random" part was removed elsewhere, but not here.

In function autoip_create_addr():

> +  /* seed must be between .1.0 and .254.255 */
> +  if(seed < 0x0100) {
> +    seed += 0x0100;
> +  }
> +  if(seed > 0xFEFF) {
> +    see -= 0x0100;
> +  }

Also, these ifs should not be here since they are present a few lines later (where also the effect of tried_llipaddr is taken into account).
There's also a typo (see -> seed) and an overbiasing of 0x0100.

Luca Ceresoli <lucaceresoli>
Wed 03 Dec 2008 03:16:01 PM UTC, comment #1: 

That's a good idea. The current implementation 'leaves room for improvement'...

I've checked in a slightly modified version of the patch (macros are uppercase, defined 2 constants). Please let me know if that works for you (and if it's correct at all, since this is the first time I've checked in from my new computer/OS...).

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
Wed 03 Dec 2008 11:48:27 AM UTC, original submission:  

The current AUTOIP implementation generates the first address to probe from the two LSBs of the MAC address.

The attached patch allows the lwIP application developer to override this algorithm providing an extern function. The default behaviour is unchanged.
It also renames RandomIPAddr and autoip_create_rand_addr() to IPAddr and autoip_create_addr(). The original names are misleading since the address is by no means random (and never has been).

Might it be of anybody's interest?

Luca Ceresoli <lucaceresoli>

 

Attached Files
file #17034:  autoip-seed2.patch added by lucaceresoli (850B - text/x-diff)
file #16979:  autoip-seed.patch added by lucaceresoli (3KiB - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by lucaceresoli (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2008-12-19 goldsimon StatusReady For Test => Done
        Open/ClosedOpen => Closed
    2008-12-12 lucaceresoli Attached File- => Added autoip-seed2.patch, #17034
    2008-12-03 goldsimon Assigned toNone => goldsimon
    2008-12-03 goldsimon StatusNone => Ready For Test
    2008-12-03 lucaceresoli Attached File- => Added autoip-seed.patch, #16979

    Back to the top


    Powered by Savane 3.5