From: Colin Foster <colin.foster@in-advantage.com>
To: buildroot@buildroot.org
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: [Buildroot] [v1 2/2] bootpc: add dhcp-like configuration ability
Date: Tue, 23 May 2023 10:21:20 -0700 [thread overview]
Message-ID: <20230523172120.1948573-3-colin.foster@in-advantage.com> (raw)
In-Reply-To: <20230523172120.1948573-1-colin.foster@in-advantage.com>
bootpc only works on interfaces that are up. If BOOTP is desired to get
an IP address to a running kernel, bootpc won't work.
This scenario was brought up as a bug in Debian forums [1] in 2007. The
response was to run the attached script to bring up the network without
an IP address. Sure enough, it still works!
Implement this bootpc script to allow IP configuration by way of
"iface eth0 inet bootp" in /etc/network/interfaces.
[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=436443
Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
---
package/bootpc/Config.in | 15 ++++++
package/bootpc/bootpc.mk | 20 ++++++-
package/bootpc/bootpc_dhcp_script | 86 +++++++++++++++++++++++++++++++
3 files changed, 119 insertions(+), 2 deletions(-)
create mode 100644 package/bootpc/bootpc_dhcp_script
diff --git a/package/bootpc/Config.in b/package/bootpc/Config.in
index 2936142b7f..fd3cd58d40 100644
--- a/package/bootpc/Config.in
+++ b/package/bootpc/Config.in
@@ -3,3 +3,18 @@ config BR2_PACKAGE_BOOTPC
help
Application to perform BOOTP
+if BR2_PACKAGE_BOOTPC
+
+config BR2_PACKAGE_BOOTPC_FULL_CONFIG
+ bool "bootpc interface configuration script"
+ help
+ BOOTP can be used to fully configure a network interface in a
+ similar manner to DHCP. bootpc requires the network interface to
+ be configured before this can happen.
+
+ Replace the bootpc binary with a script that allows an
+ unconfigured network interface to work as a BOOTP client. The
+ setting can be applied with "iface eth0 inet bootp" in
+ /etc/network/interfaces.
+
+endif
diff --git a/package/bootpc/bootpc.mk b/package/bootpc/bootpc.mk
index d3c5ce5198..ebd7490ea1 100644
--- a/package/bootpc/bootpc.mk
+++ b/package/bootpc/bootpc.mk
@@ -8,12 +8,28 @@ BOOTPC_VERSION = 80c0811dc69f9f3923661be4f9f9c09a44313f62
BOOTPC_SITE_METHOD = git
BOOTPC_SITE = https://salsa.debian.org/debian/bootpc.git
+ifeq ($(BR2_PACKAGE_BOOTPC_FULL_CONFIG),y)
+BOOTPC_TARGET_BIN_NAME = bootpc-bin
+else
+BOOTPC_TARGET_BIN_NAME = bootpc
+endif
+
define BOOTPC_BUILD_CMDS
- $(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) -C $(@D) all
+ $(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) PROG=$(BOOTPC_TARGET_BIN_NAME) -C $(@D) all
+endef
+
+ifeq ($(BR2_PACKAGE_BOOTPC_FULL_CONFIG),y)
+define BOOTPC_INSTALL_CONFIG_SCRIPT
+ $(INSTALL) -m 0755 $(BR2_EXTERNAL_BR2INADVANTAGE_PATH)/package/bootpc/bootpc_dhcp_script $(TARGET_DIR)/sbin/bootpc
+endef
+else
+define BOOTPC_INSTALL_CONFIG_SCRIPT ""
endef
+endif
define BOOTPC_INSTALL_TARGET_CMDS
- $(INSTALL) -D -m 0755 $(@D)/bootpc $(TARGET_DIR)/sbin
+ $(INSTALL) -D -m 0755 $(@D)/$(BOOTPC_TARGET_BIN_NAME) $(TARGET_DIR)/sbin
+ $(BOOTPC_INSTALL_CONFIG_SCRIPT)
endef
$(eval $(generic-package))
diff --git a/package/bootpc/bootpc_dhcp_script b/package/bootpc/bootpc_dhcp_script
new file mode 100644
index 0000000000..c7de8280f1
--- /dev/null
+++ b/package/bootpc/bootpc_dhcp_script
@@ -0,0 +1,86 @@
+#!/bin/sh
+#
+# script to initialize a network interface using bootp
+#
+# Copyright (C) 2008 by Fuji Xerox Co., Ltd. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# written by Kohei Tanaka <Kohei.Tanaka@fujixerox.co.jp>
+
+INTERFACE=eth0
+
+# load configuration file
+[ -f /etc/default/bootpc ] && . /etc/default/bootpc
+
+# to get the interface looping over arguments
+while [ $# -ne 0 ]
+do
+ case $1 in
+ --dev) INTERFACE=$2
+ break;;
+ *) shift
+ continue;;
+ esac
+done
+
+# up the interface for sending broadcast packet
+ifconfig $INTERFACE up 0.0.0.0
+route add default dev $INTERFACE
+
+TMPFILE=`mktemp /tmp/bootpc.XXXXXX`
+
+/sbin/bootpc-bin --dev $INTERFACE --returniffail --serverbcast > $TMPFILE
+RET=$?
+route del default
+ifconfig $INTERFACE down
+if [ $RET -ne 0 ]
+then
+ rm -rf $TMPFILE
+ exit 1
+fi
+
+. $TMPFILE
+rm -rf $TMPFILE
+
+[ -z "$IPADDR" ] && exit 1
+
+OPT_NETMASK=""
+OPT_BROADCAST=""
+if [ -n "$NETMASK" ]
+then
+ OPT_NETMASK="netmask $NETMASK"
+fi
+if [ -n "$BROADCAST" ]
+then
+ OPT_BROADCAST="broadcast $BROADCAST"
+fi
+ifconfig $INTERFACE $IPADDR $OPT_NETMASK $OPT_BROADCAST
+
+# already added a route to the network. just add default gateway.
+for i in $GATEWAYS
+do
+ route add default gw $i
+done
+
+[ x"$SETDNS" == xno ] && exit 0
+if [ -n "$DOMAIN" ] || [ -n "$DNSSRVS" ]
+then
+ mv -f /etc/resolv.conf /etc/resolv.conf.old
+ if [ -n "$DOMAIN" ]
+ then
+ echo "search $DOMAIN" >> /etc/resolv.conf
+ fi
+ for i in $DNSSRVS
+ do
+ echo "nameserver $i" >> /etc/resolv.conf
+ done
+fi
--
2.25.1
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
next prev parent reply other threads:[~2023-05-23 17:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 17:21 [Buildroot] [v1 0/2] add bootpc package Colin Foster
2023-05-23 17:21 ` [Buildroot] [v1 1/2] package/bootpc: new package Colin Foster
2023-05-23 20:43 ` Yann E. MORIN
2023-05-24 17:49 ` Colin Foster
2023-05-23 17:21 ` Colin Foster [this message]
2023-05-23 21:18 ` [Buildroot] [v1 2/2] bootpc: add dhcp-like configuration ability Yann E. MORIN
2023-05-24 17:58 ` Colin Foster
2023-05-25 15:31 ` Colin Foster
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=20230523172120.1948573-3-colin.foster@in-advantage.com \
--to=colin.foster@in-advantage.com \
--cc=buildroot@buildroot.org \
--cc=thomas.petazzoni@bootlin.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.