Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent network setup when using DHCP static IP #17

Open
nerocide opened this issue May 4, 2023 · 9 comments
Open

Inconsistent network setup when using DHCP static IP #17

nerocide opened this issue May 4, 2023 · 9 comments

Comments

@nerocide
Copy link

nerocide commented May 4, 2023

When using static reserved IP on DHCP with a defined MAC (in tpi.ini on sdCard) for BMC.

For example i want 192.164.1.41 for f6:5a:84:cc:a0:94

# cat /mnt/sdcard/tpi.ini
mac=f6:5a:84:cc:a0:94

Looks like BMC's NIC starts up with a random MAC then applies configuration found in tpi.ini

Serial console output

Starting network: [   19.203945] libphy: 4500000.eth: probed
[   19.214370] sunxi-gmac 4500000.eth eth0: eth0: Type(7) PHY ID 001cc816 at 0 IRQ poll (4500000.eth-0:00)
udhcpc: started, v1.35.0
udhcpc: broadcasting discover
udhcpc: broadcasting discover
[   23.448425] sunxi-gmac 4500000.eth eth0: Link is Up - 100Mbps/Full - flow control off
[   23.457252] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
udhcpc: broadcasting discover
udhcpc: broadcasting select for 192.168.1.70, server 192.168.1.2
udhcpc: lease of 192.168.1.70 obtained from 192.168.1.2, lease time 86400
deleting routers
adding dns 192.168.1.2
adding dns 192.168.1.2
OK

MAC is correct but network configuration isn't setup properly. This prevents BMC to reach the Internet.

  • default gateway is missing
  • static IP is not set
# uname -a
Linux turing 5.4.61 #31 SMP PREEMPT Thu Oct 20 00:11:14 CST 2022 armv7l GNU/Linux
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether f6:5a:84:cc:a0:94 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.70/24 brd 255.255.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::f45a:84ff:fecc:a094/64 scope link
       valid_lft forever preferred_lft forever
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
4: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop qlen 1000
    link/tunnel6 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 brd 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
# ip r
192.168.1.0/24 dev eth0 scope link  src 192.168.1.70

Workarround for correct network setup, (also ensure dhcpc is working fine after bootup).

# ifdown eth0
# ifup eth0
udhcpc: started, v1.35.0
udhcpc: broadcasting discover
iprudhcpc: broadcasting discover
udhcpc: broadcasting discover
udhcpc: broadcasting select for 192.168.1.41, server 192.168.1.2
udhcpc: lease of 192.168.1.41 obtained from 192.168.1.2, lease time 86400
deleting routers
adding dns 192.168.1.2
adding dns 192.168.1.2
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether f6:5a:84:cc:a0:94 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.41/24 brd 255.255.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::f45a:84ff:fecc:a094/64 scope link
       valid_lft forever preferred_lft forever
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
4: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop qlen 1000
    link/tunnel6 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 brd 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
# ip r
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 scope link  src 192.168.1.41
@nerocide
Copy link
Author

nerocide commented May 4, 2023

Same issue when no sdcard is present but configuration still exists in /etc/tpi.cfg.

# cat /mnt/sdcard/tpi.ini
cat: can't open '/mnt/sdcard/tpi.ini': No such file or directory
# cat /etc/tpi.cfg
mac=f6:5a:84:cc:a0:94
# reboot
# ip r
192.168.1.0/24 dev eth0 scope link  src 192.168.1.70

Everything works fine (correct nework setup) when configuration is cleared and not sdcard/tpi.ini present

# cat /mnt/sdcard/tpi.ini
cat: can't open '/mnt/sdcard/tpi.ini': No such file or directory
# echo > /etc/tpi.cfg
# reboot
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 1e:4c:11:96:e5:97 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.70/24 brd 255.255.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::1c4c:11ff:fe96:e597/64 scope link
       valid_lft forever preferred_lft forever
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
4: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop qlen 1000
    link/tunnel6 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 brd 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
# ip r
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 scope link  src 192.168.1.70

@nerocide nerocide changed the title Inconsistent network setup when using DHCP Inconsistent network setup when using DHCP static IP May 4, 2023
@wenyi0421
Copy link
Owner

Your ini only sets mac but not ip

# cat /mnt/sdcard/tpi.ini
ip=192.164.1.41
mac=f6:5a:84:cc:a0:94

The static ip will first use udhcpc -r 192.164.1.41 -nto request, if it fails, use ifconfig eth0 192.164.1.41 to set it

It is recommended to set the static ip as the router network segment, so that the network can be accessed.

you should set

# cat /mnt/sdcard/tpi.ini
ip=192.168.1.41
mac=f6:5a:84:cc:a0:94

@ShigeakiAsai
Copy link

Hello, wenyi0421 and nerocide

I also happend this issue using only MAC address (without IP address) in tpi.ini.

There is a workaround for this issue.
https://help.turingpi.com/hc/en-us/articles/8686945524893-Baseboard-Management-Controller-BMC-
Set Fixed MAC

Simply put, wite MAC address into /etc/network/interfaces.

But, I hope to fix this issue.
Because, this workaround needs to SSH terminal access and modify interfaces file.
If tpi.ini allows to have MAC address only, I think it is very easy with SD card access only.

Thanks, ASAI

@nerocide
Copy link
Author

nerocide commented May 6, 2023

Thanks @wenyi0421 & @ShigeakiAsai for your suggestions.

@wenyi0421 indeed i didn't set ip= in tpi.ini on purpose, thinking the forced mac= in tpi.ini would suffise be applied, then a dhcp request would be made.
I'm also not using static ip here on purpose for testing.
My DHCP server is on same network segment just not my router, but in a container.

New try, after specifying the ip= in tpi.ini

# cat /mnt/sdcard/tpi.ini
ip=192.168.1.41
mac=f6:5a:84:cc:a0:94

It appears 2 dhcp requests are made, one before mounting sdcartd, an other after.

serial output

Starting network: [   20.085748] libphy: 4500000.eth: probed
[   20.095527] sunxi-gmac 4500000.eth eth0: eth0: Type(7) PHY ID 001cc816 at 0 IRQ poll (4500000.eth-0:00)
udhcpc: started, v1.35.0
udhcpc: broadcasting discover
[   23.289672] sunxi-gmac 4500000.eth eth0: Link is Up - 100Mbps/Full - flow control off
[   23.298493] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
udhcpc: broadcasting discover
udhcpc: broadcasting select for 192.168.1.33, server 192.168.1.2
udhcpc: lease of 192.168.1.33 obtained from 192.168.1.2, lease time 86400
deleting routers
adding dns 192.168.1.2
adding dns 192.168.1.2
OK
Starting sshd: OK
Starting swupdate: OK
Starting collectd: OK
 _____ _   _ ____  ___ _   _  ____
|_   _| | | |  _ \|_ _| \ | |/ ___|
  | | | | | | |_) || ||  \| | |  _
  | | | |_| |  _ < | || |\  | |_| |
  |_|  \___/|_| \_\___|_| \_|\____|
[   25.655395] [EXFAT] trying to mount...
[   25.723769] [EXFAT] mounted successfully
input ip:192.168.1.41
input mac:f6:5a:84:cc:a0:94
set mac: f6:5a:84:cc:a0:94
set ip: 192.168.1.41
udhcpc: started, v1.35.0
udhcpc: broadcasting discover
udhcpc: broadcasting discover
udhcpc: broadcasting discover
udhcpc: broadcasting select for 192.168.1.41, server 192.168.1.2
udhcpc: lease of 192.168.1.41 obtained from 192.168.1.2, lease time 86400
deleting routers
adding dns 192.168.1.2
adding dns 192.168.1.2

But at the end ip comes from dhcp. NIC's still not static.

# cat /etc/network/interfaces
# interface file auto-generated by buildroot

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
  pre-up /etc/network/nfs_check
  wait-delay 15
  hostname $(hostname)

# ip a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether f6:5a:84:cc:a0:94 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.41/24 brd 255.255.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::f45a:84ff:fecc:a094/64 scope link
       valid_lft forever preferred_lft forever

This is not problematic, and probably less invasive than @ShigeakiAsai workarround, might just need to be specified somewhere in documentation.

@ShigeakiAsai i'll try your workarround. I thought mac= in tpi.ini would manage it already.

@ShigeakiAsai
Copy link

Hello, @nerocide and @wenyi0421

I have a suggestion temporary fix for this issue.

tpi.ini file is used in \etc\setStaticNet.sh.

In this script, MAC address is replaced in Line 70-76.

# 如果不为空则设置mac
if [ $mac ]; then
	ifconfig eth0 down
	echo set mac: $mac
	ifconfig eth0  hw ether $mac
	ifconfig eth0 up
fi

It looks like DHCP client is not updated, only MAC address is changed.
After that, IP address is replaced using udhcpc in this script line 77-89.
If both MAC address and IP address are used, I think it has no problem.

But, I would like to IP address is controlled by DHCP server.

My suggestion is :

# 如果不为空则设置mac
if [ $mac ]; then
        ifconfig eth0 down
        echo set mac: $mac
        ifconfig eth0  hw ether $mac
        ifconfig eth0 up
        if [ ! $ip ]; then
            udhcpc -n
        fi
fi

So, DHCP clent is updated when MAC address is valid and IP address is not valid.

This modification works in my environment.

How is it?

Thanks, ASAI

@wenyi0421
Copy link
Owner

ok i will fix it

@ShigeakiAsai
Copy link

Hello, @wenyi0421

I want to replace my temporary fix because 2 udhcpc process remaind on system.

from:
"udhcpc -n"
to:
"kill -s USR1 $(pidof udhcpc)"

When udhcpc receive USR1 signal, udhcpc renew IP address.
Please see "udhcpc -h" and following information.
https://www.incredigeek.com/home/linux-send-usr1-signal-to-pid/

Replaced code is here

# 如果不为空则设置mac
if [ $mac ]; then
        ifconfig eth0 down
        echo set mac: $mac
        ifconfig eth0  hw ether $mac
        ifconfig eth0 up
        if [ ! $ip ]; then
            kill -s USR1 $(pidof udhcpc)
        fi
fi

Thanks, ASAI

@nerocide
Copy link
Author

@ShigeakiAsai @wenyi0421

If you execute /etc/setStaticNet.sh 5 times (i know this should never happen), you'll get 6 processes

# ps -ef | grep dhcp | grep -v grep
 1191 root     udhcpc -b -R -O search -p /var/run/udhcpc.eth0.pid -i eth0 -x hostname:turing
 3144 root     udhcpc -r 192.168.1.30 -n
 3218 root     udhcpc -r 192.168.1.30 -n
 3430 root     udhcpc -r 192.168.1.30 -n
 3500 root     udhcpc -r 192.168.1.30 -n
 3579 root     udhcpc -r 192.168.1.30 -n

If number of processes matters, same change you provide should be applied line 83?

--- setStaticNet.sh
+++ setStaticNet.new.sh
@@ -73,11 +73,14 @@
         echo set mac: $mac
         ifconfig eth0  hw ether $mac
         ifconfig eth0 up
+        if [ ! $ip ]; then
+            kill -s USR1 $(pidof udhcpc)
+        fi
 fi
 # 如果不为空则设置IP
 if [ $ip ]; then
        echo set ip: $ip
-    udhcpc -r $ip -n
+    kill -s USR1 $(pidof udhcpc)
     if [ $? -eq 0 ]; then
         curip=$(ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d ':' -f 2)
         if [ "$ip" != "$curip" ]; then
#

This way only first process is asking for the new IP.

# ps -ef | grep dhcp | grep -v grep
 1191 root     udhcpc -b -R -O search -p /var/run/udhcpc.eth0.pid -i eth0 -x hostname:turing

@ShigeakiAsai
Copy link

Hello @nerocide @wenyi0421

If you execute /etc/setStaticNet.sh 5 times (i know this should never happen), you'll get 6 processes

Thank you for your information!

My suggestion was "temporary fix" when just only using MAC address in tpi.ini.
I mean...
If there is MAC address in tpi.ini only, $ip will be not set in /etc/setStaticNet.sh.
And so, udhcpc is not executed in /etc/setStaticNet.sh Line 80.

...But there was another issue, I found.
/etc/tpi.cfg has IP= and MAC= both.
/mnt/sdcard/tpi.ini has MAC= only.
MAC address is used of /mnt/sdcard/tpi.ini, but IP address is used of /etc/tpi.cfg.

I will report this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants