Unable to setup IP with nic.ipconfig() while works with obsolete nic.ifconfig() network.WIZNET5K
Port, board and/or hardware
RPi Pico, W5500-EVB-Pico
MicroPython version
MicroPython v1.24.1 on 2024-11-29; W5500-EVB-Pico with RP2040
Reproduction
Run below code with
# nic.ipconfig(addr4="192.168.9.12/24",gw4="192.168.9.3") # No pings reply
nor
# nic.ipconfig(addr4=("192.168.9.12","255.255.255.0"),gw4="192.168.9.3") # No ping reply
import network
import time
nic = network.WIZNET5K()
print (nic)
nic.active(True)
print (f"Activated {nic=}")
# nic.ifconfig(('192.168.9.12', '255.255.255.0', '192.168.9.3', '192.168.9.3')) # Pings OK
nic.ipconfig(addr4="192.168.9.12/24",gw4="192.168.9.3") # No pings reply
# nic.ipconfig(addr4=("192.168.9.12","255.255.255.0"),gw4="192.168.9.3") # No ping reply
network.ipconfig(dns="192.168.9.3", prefer=4)
print(f'After static nic config {nic=} {nic.ifconfig()=}')
print(f'After static network config {network.ipconfig("dns")=} {network.ipconfig("prefer")=}')
# In all three cases prints same:
# After static nic config nic=<WIZNET5K> nic.ifconfig()=('192.168.9.12', '255.255.255.0', '192.168.9.3', '192.168.9.3')
# After static network config network.ipconfig("dns")=192.168.9.3 network.ipconfig("prefer")=4
# nic.connect() AttributeError: 'WIZNET5K' object has no attribute 'connect'
print("Waiting for connection...")
while not nic.isconnected():
print ("Not connected")
time.sleep(1)
print ("Connected")
while 1:
time.sleep(3)
print (f"{nic.isconnected()=}")
Expected behaviour
Reply to ICMP ping when NIC configured with nic.ipconfig()
Observed behaviour
No reply to ICMP Ping when configured with nic.ipconfig()
But ICMP Ping replies received after init via nic.ifconfig().
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
extmod/network: Implement IPv6 API to set and retrieve nic configuration.
fixes #12600
This change implements a new <AbstractNIC>.ipconfig function for the CYW43 NIC class, to set and retrieve network configuration for a NIC. Currently this change supports:
ipconfig("addr4")obtain a tuple(addr, netmask)of the currently configured ipv4 addressipconfig("addr6")obtain a list of tuples(addr, state, prefered_lifetime, valid_lifetime)of all currently active ipv6 addresses. This includes static, slaac and link-local addressesipconfig(addr4="1.2.3.4/24")to set the ipv4 address and netmaskipconfig(addr6="2a01::2")to set a static ipv6 address. Note that this does not configure an interface route, as this does not seem supported by lwipipconfig(autoconf6=True)to enable ipv6 network configuration with slaac (and wait up to 10s for an address to be received)ipconfig(gw4="1.2.3.1")to set the ipv4 gatewasnetwork.ipconfig(dns="2a01::2")set the primary dns server (can be a ipv4 or ipv6 address).ipconfig(dhcp4=True)enable, and wait for (up to 10s), ipv4 dhcp. This sets ipv4 address, netmask, gateway and a dns server.ipconfig(dhcp4=False)stops dhcp, releases the ip, and clears the configured ipv4 address.ipconfig(dhcp6=True)enable stateless dhcpv6 to obtain a dns servernetwok.ipconfig(prefer=6)to prefer ipv6 addresses to be returned as dns responses (falling back to ipv4 if the host does not have an ipv6 address). Note that this does not flush the dns cache, so if a host is already in the dns cache with its v4 address, subsequent lookups will return that address even ifprefer=6is set.
This interface replaces network.ifconfig completely, and ifconfig should be marked as deprecated and removed in a future version.