Dhcp server gives old subnet after ip+subnet change on rndis gadget (linux)

Our system typically has 6 imx6 devices per box with scalable boxes. The default gadget is hardcoded to 192.168.11.1. So obviously I can’t talk to my box with N x 6 ip’s that are the same when I plug into my host computer. I can dynamically configure the IP’s to 192.168…, but I can’t get the host to get a dynamic IP on the subnet.

If I change the ip addr of my usb0 gadget (just rndis not compound), the dhcp server will continue to give out leases on the old subnet.

There must be some way to reset the dhcp server so it gives leases on the new subnet, but I can’t even figure out which server is running (I cannot locate with the ps ax command, nor find /etc/dhcpd.conf or anything like that). I know servers expect to be on the same subnet forever once running, but embedded devices have novel use cases, so here I am…

Regards!

P.S. You can try this from a shell with:

imx6# ifconfig usb0

"192.168.11.1"

ubuntu# ifconfig eth3

 "192.168.11.188"

imx6# ifconfig usb0 192.168.231.1

"192.168.231.1"

ubuntu# sudo dhclient -r eth3

ubuntu# sudo dhclient eth3

ubuntu# ifconfig eth3

"192.168.11.189"

Hi

For RNDIS we use the systemd DHCP server which is only started on demand by systemd sockets. Its configuration file is here: /lib/systemd/network/rndis.network

I guess that V2.6B2 already did set the Ethernet MAC addresses from this configuration file: /etc/usbg/g1.schema
MAC addresses may or may not need to be different.

Max

Yes, I’m aware of that file. All it specifies is the initial IP for usb0. It doesn’t appear to configure the DHCP server, it just specifies that we will need one (“DHCPServer=yes”).

My problem is when I subsequently change that IP after bootup, the DHCP server fails to take the new IP into account when giving out new leases.

I would say that file, rndis.network, is more the configuration for the gadget network itself, not the DHCP server; I can’t seem to find files for the DHCP server anywhere: i.e. what domain for dhcpd? what DNS servers and gateway to hand out with the leases?

How do I change the subnet for the “systemd DHCP server”?

If the dhcp server won’t hand out leases on the same subnet as the system’s IP, what is it good for?

Did you try to change /usr/lib/systemd/network/rndis.network and then reboot?
E.g. setting it to a 192.168.12.1/24 network as follows?

--- /usr/lib/systemd/network/rndis.network~                                     
+++ /usr/lib/systemd/network/rndis.network                                      
@@ -4,5 +4,5 @@                                                                 
 Type=gadget                                                                    
                                                                                
 [Network]                                                                      
-Address=192.168.11.1/24                                                        
+Address=192.168.12.1/24                                                        
 DHCPServer=yes                                                                 

Max

Then it will just be stuck on 192.168.12.X for forever instead of 192.168.11.X forever. I need the dhcp server to rebe restarted when the interface’s IP changes.

I’m beginning to think systemd is incapable of supporting this.

Well, networkd is the network manager for the RNDIS network, so it is configured to set the NIC’s IP and to provide a DNS server for the connected network.
So, if you some other means of changing the IP address you’d bypass networkd.

Actually if you don’t want to reboot you can restart the service by

systemctl restart systemd-networkd.service

That would still require you to make the USB host side requesting a new IP from the DHCP server.
One way to do this would be to disable and reenable the USB gadget which will remove and recreate the USB Host side NIC.

echo "" > /sys/kernel/config/usb_gadget/g1/UDC
/bin/echo `ls /sys/class/udc/` > /sys/kernel/config/usb_gadget/g1/UDC

Or to put this together

  • change the rndis.network file to the new network address

  • restart the networkd service

  • disable and reenable the USB gadget

    sed -i ‘s/^Address.*/Address=192.168.12.1/24/g’ /usr/lib/systemd/network/rndis.network
    systemctl restart systemd-networkd.service echo “” > /sys/kernel/config/usb_gadget/g1/UDC
    echo “” > /sys/kernel/config/usb_gadget/g1/UDC
    /bin/echo ls /sys/class/udc/ > /sys/kernel/config/usb_gadget/g1/UDC

Should your question however mean that you expect your different Colibri’s to automatically choose a unique IP network then the answer would be indeed be that it is not that easily possible.
Likely for that use case it would be simpler to configure a DHCP server on the USB host side of things and configure the Colibri’s to be a DHCP client and fetch an address from the host.