Page MenuHomeFreeBSD

Allow dhcp/bootp server-provided values to be overriden from environment variables in loader(8) and other libstand applications.
ClosedPublic

Authored by ian on Dec 15 2015, 3:22 AM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 29 2023, 9:03 PM
Unknown Object (File)
Dec 23 2023, 7:26 AM
Unknown Object (File)
Dec 20 2023, 12:51 AM
Unknown Object (File)
Nov 29 2023, 1:56 AM
Unknown Object (File)
Nov 29 2023, 12:05 AM
Unknown Object (File)
Nov 24 2023, 12:02 AM
Unknown Object (File)
Oct 30 2023, 10:32 PM
Unknown Object (File)
Oct 29 2023, 7:54 AM
Subscribers

Details

Summary

Sometimes a dhcp server provides incorrect information along with the IP address. It would be useful to have a way to override this with locally-supplied information, such as command line parameters passed from a prior-stage bootloader. This change allows pre-existing env vars to take precedence over values delivered by the dhcp or bootp server.

The bootp/dhcp code in libstand automatically creates environment variables from the data provided by the server (dhcp.root-path, dhcp.domain-name, etc). It also transcribes the values to some global variables such as 'rootpath' and 'hostname'.

This change does two things:

  • When adding dhcp.* vars to the environment, don't replace existing vars/values.
  • When setting the global vars rootpath and hostname, use the dhcp.root-path and dhcp.host-name env var values if they exist.

This allows the platform-specific part of loader(8) to obtain override values in some platform-specific way and store them in the environment before opening the network device. The set of values that can be overriden is currently limited to just string options. The values that are delivered as binary data are things that probably shouldn't be overridden (IP, netmask, gateway, etc).

The original patch this evolved from was submitted by Ganael LAPLANCHE in PR 202098

Test Plan

Tested on arm using ubldr.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

ian retitled this revision from to Allow dhcp/bootp server-provided values to be overriden from environment variables in loader(8) and other libstand applications..
ian updated this object.
ian edited the test plan for this revision. (Show Details)
ian set the repository for this revision to rS FreeBSD src repository - subversion.
bapt added a reviewer: bapt.
bapt added a subscriber: bapt.

I really like this patch and would be useful to me. It deserves a release notes!

This revision is now accepted and ready to land.Dec 17 2015, 12:25 AM
martymac added a reviewer: martymac.

This patch looks good to me, but I had to enable strlcpy() in libstand32 (as done in r292234 but for libstand) to build it :

--- sys/boot/libstand32/Makefile        (revision 292326)
+++ sys/boot/libstand32/Makefile        (working copy)
@@ -41,8 +41,8 @@
 .PATH: ${LIBC_SRC}/string
 SRCS+= bcmp.c bcopy.c bzero.c ffs.c memccpy.c memchr.c memcmp.c memcpy.c \
        memmove.c memset.c qdivrem.c strcat.c strchr.c strcmp.c strcpy.c \
-       strcspn.c strlen.c strncat.c strncmp.c strncpy.c strpbrk.c \
-       strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c
+       strcspn.c strlcat.c strlcpy.c strlen.c strncat.c strncmp.c strncpy.c \
+       strpbrk.c strrchr.c strsep.c strspn.c strstr.c strtok.c swab.c
 .if ${MACHINE_CPUARCH} == "arm"
 .PATH: ${LIBC_SRC}/arm/gen
 
This revision now requires changes to proceed.Dec 17 2015, 7:17 AM

This patch looks good to me, but I had to enable strlcpy() in libstand32 (as done in r292234 but for libstand) to build it :

Doh! I forgot there was a libstand32. I just committed that separately as r292527.

martymac edited edge metadata.

So this looks good to me, thanks :)

This revision is now accepted and ready to land.Dec 21 2015, 7:04 AM
In D4559#98129, @ian wrote:

Doh! I forgot there was a libstand32. I just committed that separately as r292527.

We really need to split the common parts of libstand into a Makefile.inc - I'll have a go at that.

This revision was automatically updated to reflect the committed changes.

As pointed out by bapt, I think it would be nice to add a relnote for that patch (r292583) as well as its friend (r292584).