Skip to content

Commit ff08f0f

Browse files
committed
ipconfig: lwip: Add support for autoconf4 configuration.
Auto IP configuration is a method of picking a random IP address in the 169.254.0.0/16 subnet. It is analogous to the IPv6 stateless autoconfiguration on link-local interfaces. It's actually recommended by LwIP for use with mDNS and is useful for networks where devices should be configured without a DHCP server and then discovered by name via mDNS. Currently only implemented for the LWIP software IP stack. Signed-off-by: Jared Hancock <jared.hancock@centeredsolutions.com>
1 parent c72a3e5 commit ff08f0f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

docs/library/network.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ parameter should be `id`.
124124
server via DHCP. This method does not block and wait for an address
125125
to be obtained. To check if an address was obtained, use the read-only
126126
property ``has_dhcp4``.
127+
* ``autoconf4`` (``True/False``) obtain an IPv4 address randomly in the
128+
169.254.0.0/16 address space. This method does not block and wait for
129+
an address to be selected and confirmed to be unused on the network. To
130+
check if an address has been selected, use the read-only property
131+
``has_autoconf4``.
127132
* ``gw4`` Get/set the IPv4 default-gateway.
128133
* ``dhcp6`` (``True/False``) obtain a DNS server via stateless DHCPv6.
129134
Obtaining IP Addresses via DHCPv6 is currently not implemented.

extmod/network_lwip.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include "lwip/netif.h"
4141
#include "lwip/timeouts.h"
42+
#include "lwip/autoip.h"
4243
#include "lwip/dns.h"
4344
#include "lwip/dhcp.h"
4445
#include "lwip/nd6.h"
@@ -191,6 +192,11 @@ mp_obj_t mod_network_nic_ipconfig(struct netif *netif, size_t n_args, const mp_o
191192
case MP_QSTR_has_dhcp4: {
192193
return mp_obj_new_bool(dhcp_supplied_address(netif));
193194
}
195+
#if LWIP_AUTOIP
196+
case MP_QSTR_has_autoconf4: {
197+
return mp_obj_new_bool(autoip_supplied_address(netif));
198+
}
199+
#endif
194200
#if LWIP_IPV6_DHCP6
195201
case MP_QSTR_dhcp6: {
196202
struct dhcp6 *dhcp = netif_dhcp6_data(netif);
@@ -268,13 +274,24 @@ mp_obj_t mod_network_nic_ipconfig(struct netif *netif, size_t n_args, const mp_o
268274
dhcp_renew(netif);
269275
} else {
270276
dhcp_release_and_stop(netif);
277+
#if LWIP_AUTOIP
278+
if (autoip_supplied_address(netif)) {
279+
autoip_stop(netif);
280+
}
281+
#endif
271282
dhcp_start(netif);
272283
}
273284
} else {
274285
dhcp_release_and_stop(netif);
275286
}
276287
break;
277288
}
289+
#if LWIP_AUTOIP
290+
case MP_QSTR_autoconf4: {
291+
dhcp_release_and_stop(netif);
292+
autoip_start(netif);
293+
}
294+
#endif
278295
#if LWIP_IPV6_DHCP6
279296
case MP_QSTR_dhcp6: {
280297
dhcp6_disable(netif);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy