LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   rc.inet1 patch for DHCP on multiple network interfaces (https://www.linuxquestions.org/questions/slackware-14/rc-inet1-patch-for-dhcp-on-multiple-network-interfaces-4175410942/)

irfan.acar 06-11-2012 07:19 PM

rc.inet1 patch for DHCP on multiple network interfaces
 
Hello,

When polling DHCP servers on multiple network interfaces, DHCP options for
one interface might end up being used for another interface. Included is a
patch for /etc/rc.d/rc.inet1 in Slackware 13.37 which fixes this.

For example, assume that /etc/rc.d/rc.inet1.conf is configured as below:

USE_DHCP[0]="yes"
DHCP_KEEPGW[0]="yes"
USE_DHCP[1]="yes"

This will cause the execution of two instances of the DHCP client as:

/sbin/dhcpcd -t 10 -G eth0
/sbin/dhcpcd -t 10 -G eth1

whereas what we had intended was to run:

/sbin/dhcpcd -t 10 -G eth0
/sbin/dhcpcd -t 10 eth1

The patch below fixes this by replacing the variable DHCP_OPTIONS with an
array.

-irfan



--- rc.inet1 2009-08-26 17:25:44.000000000 +0300
+++ rc.inet1 2012-06-12 03:01:10.531000082 +0300
@@ -105,13 +105,13 @@
. /etc/rc.d/rc.wireless ${1} start # Initialize any wireless parameters
fi
if [ "${USE_DHCP[$i]}" = "yes" ]; then # use DHCP to bring interface up
- [ ${DHCP_HOSTNAME[$i]} ] && DHCP_OPTIONS="-h ${DHCP_HOSTNAME[$i]}"
- [ "${DHCP_KEEPRESOLV[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -C resolv.conf"
- [ "${DHCP_KEEPNTP[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -C ntp.conf"
- [ "${DHCP_KEEPGW[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -G"
- [ "${DHCP_DEBUG[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -d"
- [ "${DHCP_NOIPV4LL[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -L"
- [ ${DHCP_IPADDR[$i]} ] && DHCP_OPTIONS="$DHCP_OPTIONS -r ${DHCP_IPADDR[$i]}"
+ [ ${DHCP_HOSTNAME[$i]} ] && DHCP_OPTIONS[$i]="-h ${DHCP_HOSTNAME[$i]}"
+ [ "${DHCP_KEEPRESOLV[$i]}" = "yes" ] && DHCP_OPTIONS[$i]="${DHCP_OPTIONS[$i]} -C resolv.conf"
+ [ "${DHCP_KEEPNTP[$i]}" = "yes" ] && DHCP_OPTIONS[$i]="${DHCP_OPTIONS[$i]} -C ntp.conf"
+ [ "${DHCP_KEEPGW[$i]}" = "yes" ] && DHCP_OPTIONS[$i]="${DHCP_OPTIONS[$i]} -G"
+ [ "${DHCP_DEBUG[$i]}" = "yes" ] && DHCP_OPTIONS[$i]="${DHCP_OPTIONS[$i]} -d"
+ [ "${DHCP_NOIPV4LL[$i]}" = "yes" ] && DHCP_OPTIONS[$i]="${DHCP_OPTIONS[$i]} -L"
+ [ ${DHCP_IPADDR[$i]} ] && DHCP_OPTIONS[$i]="${DHCP_OPTIONS[$i]} -r ${DHCP_IPADDR[$i]}"
echo "Polling for DHCP server on interface ${1}:"
# If you set a timeout, you get one, even if the kernel doesn't think that
# your device is connected, in case /sys isn't right (which it usually isn't
@@ -132,8 +132,8 @@
#fi
#### (end commented out)
# 10 seconds should be a reasonable default DHCP timeout. 30 was too much.
- echo "/etc/rc.d/rc.inet1: /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}" | $LOGGER
- /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}
+ echo "/etc/rc.d/rc.inet1: /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS[$i]} ${1}" | $LOGGER
+ /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS[$i]} ${1}
else # bring up interface using a static IP address
if [ ! "${IPADDR[$i]}" = "" ]; then # skip unconfigured interfaces
# Determine broadcast address from the IP address and netmask:

FeyFre 06-12-2012 03:32 AM

You did a lot of unnecessary changes. It was enough to add line `DHCP_OPTIONS=""` right after `if [ "${USE_DHCP[$i]}" = "yes" ]; then # use DHCP to bring interface up` condition check. There is no reason to save each option. It will be never used.

XGizzmo 06-12-2012 04:23 AM

FayFre is 100% correct, DHCP_OPTIONS just needs to be cleared out for each iteration of the loop.

irfan.acar 06-20-2012 06:31 AM

Different strokes for different folks... Although clearing DHCP_OPTIONS in if_up() is sufficient, I prefer to use an array to emphasize that each network interface has its own DHCP options.

-irfan


All times are GMT -5. The time now is 11:48 AM.