WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: eth0 hotplug  (Read 1527 times)

Offline Demontager

  • Newbie
  • *
  • Posts: 18
eth0 hotplug
« on: July 05, 2022, 12:54:03 AM »
I'm running piCore-13.0.1 on RPI B Plus Rev 1.2. I found that when internet cable plugged and then unplugged eth0 not going up automatically.
Is it possible to bring it up automatically once cable plugged?
p.s. eth0 getting address via dhcp
« Last Edit: July 05, 2022, 12:58:16 AM by Demontager »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1063
Re: eth0 hotplug
« Reply #1 on: July 05, 2022, 05:40:43 AM »
Everything works fine for me.

Offline Demontager

  • Newbie
  • *
  • Posts: 18
Re: eth0 hotplug
« Reply #2 on: July 05, 2022, 09:02:18 AM »
For me not. Probably it is device specific.
If RPI booted but no cable connected then after plug it in eth0 going up ok. But if booted with cable connected and then disconnected and reconnected not going up.
Code: [Select]
tc@box:~$ uname -a
Linux box 5.10.16-piCore #1 Wed Feb 17 04:05:50 UTC 2021 armv6l GNU/Linux

tc@box:~$ cat /proc/cpuinfo
processor       : 0
model name      : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS        : 697.95
Features        : half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xb76
CPU revision    : 7

Hardware        : BCM2835
Revision        : 0010
Serial          : 00000000fd30af6f
Model           : Raspberry Pi Model B Plus Rev 1.2

« Last Edit: July 05, 2022, 09:07:34 AM by Demontager »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1063
Re: eth0 hotplug
« Reply #3 on: July 05, 2022, 09:21:43 AM »
When you unplug the cable, there is nothing "Downing" the interface.  As there is not a network manager running.

What are you doing when unplugging?  Are you plugging back into the same network?

Offline Demontager

  • Newbie
  • *
  • Posts: 18
Re: eth0 hotplug
« Reply #4 on: July 05, 2022, 09:33:23 AM »
udhcpc remain running. Also i do run dnsmasq openvpn sshd. I do plugging in the same RPI internal lan port.

Code: [Select]
tc@box:~$ ps aux
PID   USER     COMMAND
    1 root     /sbin/init
    2 root     [kthreadd]
    3 root     [kworker/0:0-eve]
    6 root     [mm_percpu_wq]
    7 root     [rcu_tasks_rude_]
    8 root     [rcu_tasks_trace]
    9 root     [ksoftirqd/0]
   10 root     [kdevtmpfs]
   11 root     [netns]
   13 root     [kauditd]
   14 root     [khungtaskd]
   15 root     [oom_reaper]
   16 root     [writeback]
   17 root     [kcompactd0]
   32 root     [kblockd]
   33 root     [blkcg_punt_bio]
   34 root     [watchdogd]
   35 root     [rpciod]
   36 root     [kworker/u3:0]
   37 root     [xprtiod]
   38 root     [kswapd0]
   39 root     [nfsiod]
   40 root     [iscsi_eh]
   41 root     [iscsi_destroy]
   42 root     [dwc_otg]
   43 root     [DWC Notificatio]
   44 root     [kworker/0:2-eve]
   45 root     [vchiq-slot/0]
   46 root     [vchiq-recy/0]
   47 root     [vchiq-sync/0]
   48 root     [zswap-shrink]
   51 root     [mmc_complete]
   52 root     [kworker/0:1H-kb]
   58 root     [kworker/u2:1-ev]
   83 root     /sbin/udevd --daemon
  249 root     [kworker/0:2H-kb]
  334 root     [jbd2/mmcblk0p2-]
  335 root     [ext4-rsv-conver]
  351 root     [loop0]
  354 root     [loop1]
  355 root     [kworker/u2:2-ev]
  358 root     [loop2]
  363 root     [loop3]
  366 root     [loop4]
  369 root     [loop5]
  372 root     [loop6]
  375 root     [loop7]
  378 root     [loop8]
  381 root     [loop9]
  384 root     [loop10]
  387 root     [loop11]
  390 root     [loop12]
  394 root     [loop13]
  397 root     [loop14]
  400 root     [loop15]
  403 root     [loop16]
  406 root     [loop17]
  409 root     [loop18]
  412 root     [loop19]
  415 root     [loop20]
  418 root     [loop21]
  566 root     /sbin/udevd --daemon
  567 root     /sbin/udevd --daemon
  616 tc       -sh
  672 root     [ipv6_addrconf]
  674 root     sshd: /usr/local/sbin/sshd [listener] 0 of 10-100 startups
  748 root     /usr/local/sbin/openvpn --daemon --config /home/tc/kimsufi.ovpn --log /var/log/openvpn.log
  751 nobody   dnsmasq -q -C /usr/local/etc/dnsmasq.conf --log-queries --log-facility=/var/log/dnsmasq.log
  753 root     crond -L /dev/null
  758 root     /sbin/udhcpc -b -i eth0 -x hostname:box -p /var/run/udhcpc.eth0.pid
  788 root     sshd: root@pts/0
  790 tc       -sh
  825 root     [kworker/0:1-eve]
  827 tc       ps aux
« Last Edit: July 05, 2022, 09:35:09 AM by Demontager »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1063
Re: eth0 hotplug
« Reply #5 on: July 05, 2022, 09:43:36 AM »
Sounds like you have a complicated solution running there.  You probably need to use a network manager, or script your own.

Offline Demontager

  • Newbie
  • *
  • Posts: 18
Re: eth0 hotplug
« Reply #6 on: July 05, 2022, 11:41:29 AM »
BTW checked another RPI 2 B box and same behavior.
Also i have tested raspbian buster image and such problem not exists. Means after lan cable plugged in again network also  brings up. Tested several time no issues.
I may use raspbian, but i don't like very long boot and shutdown time and overall slow work. TC performs much much faster.
« Last Edit: July 05, 2022, 12:05:03 PM by Demontager »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1063
Re: eth0 hotplug
« Reply #7 on: July 06, 2022, 06:21:35 AM »
RaspiOS runs a network manager.  And is a full OS

TinyCore/Picore is a toolkit,  Add what you need to make it work.   You could easily script your ethernet cable plug/unplug events manually.


Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: eth0 hotplug
« Reply #8 on: July 08, 2022, 08:09:21 AM »
Hi Demontager
I've put together a small script that monitors and prints out network cable status.
Status is determined as follows:
Quote
# The script monitors the file  /sys/class/net/NIC/carrier
# where  NIC  is your Network Interface Card,  eth0  for example.
# If the file contains 0, the cable is currently unplugged.
# If the file contains 1, the cable is currently plugged in.
# If the file does not exist, the NIC is down, possibly because:
#    1. The NIC was never brought up.
#    2. Someone ran the command  ifconfig NIC down
#    3. Some other reason.

The script prints out the current status when it first starts, after that, it will print out status any time it changes:
Code: [Select]
tc@E310:~/net$ ./CableSense.sh
Cable is plugged in.
Cable was unplugged.
Cable was plugged in.

You will need to decide what commands (if any) you want to run when the script starts and when there is a state change.
Look at the 2 sections that begin with  case $Cable in  and end in  esac.
Look at the  echo  commands to pick where you want to execute a command(s) and add it/them like this:
Code: [Select]
1)
echo. "Cable was plugged in." >>$LogFile
Add your commands here
and here
and so on
;;

If you want to stop messages from being echoed to the screen, find the section labeled  # Where to send messages to:
and  uncomment  the appropriate line.

The script is fairly well commented, but feel free to ask questions.

Offline Demontager

  • Newbie
  • *
  • Posts: 18
Re: eth0 hotplug
« Reply #9 on: July 30, 2022, 04:49:08 AM »
Hi Rich!
Thanks for your script and efforts to help. Sorry for late reply, just seen it. Your script is doing well, but unfortunately can't test it on hardware i had when posted this topic. I passed over two of these RPIs boxes to other people to have them VPN running. (We are on occupied territory by russian hordes and mostly all ukrainian internet resources are blocked). I only have RPI 3 Model B Plus Rev 1.3 right now and it has no issues with plugging in/out. Anyway i may say that problem was hardware specific and affect RPI B and 2 models.