Skip to content

Commit

Permalink
net: Add link-local addressing support
Browse files Browse the repository at this point in the history
Code based on networking/zcip.c in busybox
commit 8531d76a15890c2c535908ce888b2e2aed35b172

Signed-off-by: Joe Hershberger <[email protected]>
  • Loading branch information
jhershbe committed May 23, 2012
1 parent 2280418 commit d22c338
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,8 @@ The following options need to be configured:
CONFIG_CMD_JFFS2 * JFFS2 Support
CONFIG_CMD_KGDB * kgdb
CONFIG_CMD_LDRINFO ldrinfo (display Blackfin loader)
CONFIG_CMD_LINK_LOCAL * link-local IP address auto-configuration
(169.254.*.*)
CONFIG_CMD_LOADB loadb
CONFIG_CMD_LOADS loads
CONFIG_CMD_MD5SUM print md5 message digest
Expand Down Expand Up @@ -1633,6 +1635,14 @@ The following options need to be configured:
the DHCP timeout and retry process takes a longer than
this delay.

- Link-local IP address negotiation:
Negotiate with other link-local clients on the local network
for an address that doesn't require explicit configuration.
This is especially useful if a DHCP server cannot be guaranteed
to exist in all environments that the device must operate.

See doc/README.link-local for more information.

- CDP Options:
CONFIG_CDP_DEVICE_ID

Expand Down
31 changes: 31 additions & 0 deletions common/cmd_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,34 @@ U_BOOT_CMD(
);

#endif /* CONFIG_CMD_DNS */

#if defined(CONFIG_CMD_LINK_LOCAL)
static int do_link_local(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
char tmp[22];

if (NetLoop(LINKLOCAL) < 0)
return 1;

NetOurGatewayIP = 0;
ip_to_string(NetOurGatewayIP, tmp);
setenv("gatewayip", tmp);

ip_to_string(NetOurSubnetMask, tmp);
setenv("netmask", tmp);

ip_to_string(NetOurIP, tmp);
setenv("ipaddr", tmp);
setenv("llipaddr", tmp); /* store this for next time */

return 0;
}

U_BOOT_CMD(
linklocal, 1, 1, do_link_local,
"acquire a network IP address using the link-local protocol",
""
);

#endif /* CONFIG_CMD_LINK_LOCAL */
76 changes: 76 additions & 0 deletions doc/README.link-local
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
------------------------------------------
Link-local IP address auto-configuration
------------------------------------------

Negotiate with other link-local clients on the local network
for an address that doesn't require explicit configuration.
This is especially useful if a DHCP server cannot be guaranteed
to exist in all environments that the device must operate.

This is an implementation of RFC3927.

----------
Commands
----------

When CONFIG_CMD_LINK_LOCAL is defined in the board config file,
the "linklocal" command is available. This running this will
take approximately 5 seconds while the address is negotiated.

------------------------
Environment interation
------------------------

The "llipaddr" variable is set with the most recently
negotiated address and is preferred in future negotiations.

The "ipaddr", "netmask", and "gatewayip" variables are set
after successful negotiation to enable network access.

-------------
Limitations
-------------

RFC3927 requires that addresses are continuously checked to
avoid conflicts, however this can only happen when the NetLoop
is getting called. It is possible for a conflict to go undetected
until a command that accesses the network is executed.

Using NetConsole is one way to ensure that NetLoop is always
processing packets and monitoring for conflicts.

This is also not a concern if the feature is use to connect
directly to another machine that may not be running a DHCP server.

----------------
Example script
----------------

This script allows use of DHCP and/or Link-local controlled
by env variables. It depends on CONFIG_CMD_LINK_LOCAL, CONFIG_CMD_DHCP,
and CONFIG_BOOTP_MAY_FAIL.
If both fail or are disabled, static settings are used.

#define CONFIG_EXTRA_ENV_SETTINGS \
"ipconfigcmd=if test \\\"$dhcpenabled\\\" -ne 0;" \
"then " \
"dhcpfail=0;dhcp || dhcpfail=1;" \
"else " \
"dhcpfail=-1;" \
"fi;" \
"if test \\\"$linklocalenabled\\\" -ne 0 -a " \
"\\\"$dhcpfail\\\" -ne 0;" \
"then " \
"linklocal;" \
"llfail=0;" \
"else " \
"llfail=-1;" \
"fi;" \
"if test \\\"$llfail\\\" -ne 0 -a " \
"\\\"$dhcpfail\\\" -ne 0; " \
"then " \
"setenv ipaddr $sipaddr; " \
"setenv netmask $snetmask; " \
"setenv gatewayip $sgatewayip; " \
"fi;\0" \

2 changes: 1 addition & 1 deletion include/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ extern int NetRestartWrap; /* Tried all network devices */

enum proto_t {
BOOTP, RARP, ARP, TFTPGET, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
TFTPSRV, TFTPPUT
TFTPSRV, TFTPPUT, LINKLOCAL
};

/* from net/net.c */
Expand Down
4 changes: 3 additions & 1 deletion net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ COBJS-$(CONFIG_CMD_NET) += bootp.o
COBJS-$(CONFIG_CMD_CDP) += cdp.o
COBJS-$(CONFIG_CMD_DNS) += dns.o
COBJS-$(CONFIG_CMD_NET) += eth.o
COBJS-$(CONFIG_CMD_LINK_LOCAL) += link_local.o
COBJS-$(CONFIG_CMD_NET) += net.o
COBJS-$(CONFIG_BOOTP_RANDOM_DELAY) += net_rand.o
COBJS-$(CONFIG_CMD_LINK_LOCAL) += net_rand.o
COBJS-$(CONFIG_CMD_NFS) += nfs.o
COBJS-$(CONFIG_CMD_PING) += ping.o
COBJS-$(CONFIG_CMD_RARP) += rarp.o
COBJS-$(CONFIG_CMD_SNTP) += sntp.o
COBJS-$(CONFIG_CMD_NET) += tftp.o

COBJS := $(COBJS-y)
COBJS := $(sort $(COBJS-y))
SRCS := $(COBJS:.o=.c)
OBJS := $(addprefix $(obj),$(COBJS))

Expand Down
Loading

0 comments on commit d22c338

Please sign in to comment.