AutoIP Automatic LinkLocal IP Configuration.
#include "lwip/opt.h"
#include "lwip/mem.h"
#include "lwip/udp.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/autoip.h"
#include "netif/etharp.h"
#include <stdlib.h>
#include <string.h>
Macros | |
#define | AUTOIP_NET 0xA9FE0000 |
#define | AUTOIP_RANGE_END (AUTOIP_NET | 0xFEFF) |
#define | AUTOIP_RANGE_START (AUTOIP_NET | 0x0100) |
#define | LWIP_AUTOIP_CREATE_SEED_ADDR(netif) |
Macro that generates the initial IP address to be tried by AUTOIP. More... | |
#define | LWIP_AUTOIP_RAND(netif) |
Pseudo random macro based on netif informations. More... | |
Functions | |
static err_t | autoip_arp_announce (struct netif *netif) |
Sends an ARP announce from a network interface. More... | |
static err_t | autoip_arp_probe (struct netif *netif) |
Sends an ARP probe from a network interface. More... | |
void | autoip_arp_reply (struct netif *netif, struct etharp_hdr *hdr) |
Handles every incoming ARP Packet, called by etharp_arp_input. More... | |
static err_t | autoip_bind (struct netif *netif) |
Configure interface for use with current LL IP-Address. More... | |
static void | autoip_create_addr (struct netif *netif, ip_addr_t *ipaddr) |
Create an IP-Address out of range 169.254.1.0 to 169.254.254.255. More... | |
static void | autoip_handle_arp_conflict (struct netif *netif) |
Handle a IP address conflict after an ARP conflict detection. More... | |
void | autoip_network_changed (struct netif *netif) |
Handle a possible change in the network configuration. More... | |
static void | autoip_restart (struct netif *netif) |
Restart AutoIP client and check the next address (conflict detected) More... | |
void | autoip_set_struct (struct netif *netif, struct autoip *autoip) |
Set a statically allocated struct autoip to work with. More... | |
err_t | autoip_start (struct netif *netif) |
Start AutoIP client. More... | |
static void | autoip_start_probing (struct netif *netif) |
err_t | autoip_stop (struct netif *netif) |
Stop AutoIP client. More... | |
void | autoip_tmr () |
Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds. More... | |
#define AUTOIP_NET 0xA9FE0000 |
Referenced by autoip_create_addr().
#define AUTOIP_RANGE_END (AUTOIP_NET | 0xFEFF) |
Referenced by autoip_create_addr().
#define AUTOIP_RANGE_START (AUTOIP_NET | 0x0100) |
Referenced by autoip_create_addr().
#define LWIP_AUTOIP_CREATE_SEED_ADDR | ( | netif | ) |
Macro that generates the initial IP address to be tried by AUTOIP.
If you want to override this, define it to something else in lwipopts.h.
Referenced by autoip_create_addr().
#define LWIP_AUTOIP_RAND | ( | netif | ) |
Pseudo random macro based on netif informations.
You could use "rand()" from the C Library if you define LWIP_AUTOIP_RAND in lwipopts.h
Referenced by autoip_start_probing(), and autoip_tmr().
Sends an ARP announce from a network interface.
netif | network interface used to send the announce |
References ARP_REQUEST, netif::autoip, etharp_raw(), ethbroadcast, ethzero, netif::hwaddr, and autoip::llipaddr.
Referenced by autoip_handle_arp_conflict(), and autoip_tmr().
Sends an ARP probe from a network interface.
netif | network interface used to send the probe |
References ARP_REQUEST, netif::autoip, etharp_raw(), ethbroadcast, ethzero, netif::hwaddr, IP_ADDR_ANY, and autoip::llipaddr.
Referenced by autoip_tmr().
void autoip_arp_reply | ( | struct netif * | netif, |
struct etharp_hdr * | hdr | ||
) |
Handles every incoming ARP Packet, called by etharp_arp_input.
netif | network interface to use for autoip processing |
hdr | Incoming ARP packet |
References netif::autoip, AUTOIP_DEBUG, autoip_handle_arp_conflict(), autoip_restart(), AUTOIP_STATE_ANNOUNCING, AUTOIP_STATE_OFF, AUTOIP_STATE_PROBING, eth_addr_cmp, ETHADDR16_COPY, netif::hwaddr, ip_addr_cmp, IPADDR2_COPY, autoip::llipaddr, LWIP_DBG_LEVEL_WARNING, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, NULL, autoip::sent_num, and autoip::state.
Referenced by etharp_arp_input().
Configure interface for use with current LL IP-Address.
netif | network interface to configure with current LL IP-Address |
References netif::autoip, AUTOIP_DEBUG, ERR_OK, IP4_ADDR, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, autoip::llipaddr, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::name, netif_set_gw(), netif_set_ipaddr(), netif_set_netmask(), netif_set_up(), netif::num, and U16_F.
Referenced by autoip_tmr().
Create an IP-Address out of range 169.254.1.0 to 169.254.254.255.
netif | network interface on which create the IP-Address |
ipaddr | ip address to initialize |
References netif::autoip, AUTOIP_DEBUG, AUTOIP_NET, AUTOIP_RANGE_END, AUTOIP_RANGE_START, htonl, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, ip4_addr_set_u32, LWIP_ASSERT, LWIP_AUTOIP_CREATE_SEED_ADDR, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, ntohl, autoip::tried_llipaddr, and U16_F.
Referenced by autoip_start().
Handle a IP address conflict after an ARP conflict detection.
References netif::autoip, autoip_arp_announce(), AUTOIP_DEBUG, autoip_restart(), AUTOIP_TICKS_PER_SECOND, DEFEND_INTERVAL, autoip::lastconflict, LWIP_DBG_STATE, LWIP_DBG_TRACE, and LWIP_DEBUGF.
Referenced by autoip_arp_reply().
Handle a possible change in the network configuration.
If there is an AutoIP address configured, take the interface down and begin probing with the same address.
References netif::autoip, autoip_start_probing(), AUTOIP_STATE_OFF, netif_set_down(), and autoip::state.
Referenced by netif_set_link_up().
Restart AutoIP client and check the next address (conflict detected)
netif | The netif under AutoIP control |
References netif::autoip, autoip_start(), and autoip::tried_llipaddr.
Referenced by autoip_arp_reply(), and autoip_handle_arp_conflict().
Set a statically allocated struct autoip to work with.
Set a struct autoip allocated by the application to work with.
Using this prevents autoip_start to allocate it using mem_malloc.
netif | the netif for which to set the struct autoip |
dhcp | (uninitialised) dhcp struct allocated by the application |
References netif::autoip, LWIP_ASSERT, and NULL.
Start AutoIP client.
netif | network interface on which start the AutoIP client |
References netif::autoip, autoip_create_addr(), AUTOIP_DEBUG, autoip_start_probing(), AUTOIP_STATE_OFF, ERR_MEM, ERR_OK, netif::gw, netif::ip_addr, ip_addr_set_zero, autoip::lastconflict, autoip::llipaddr, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, mem_malloc, netif::name, netif_is_up, netif_set_down(), netif::netmask, NULL, netif::num, autoip::sent_num, autoip::state, autoip::ttw, and U16_F.
Referenced by autoip_restart(), dhcp_discover(), and net_interface_up_imp().
References netif::autoip, AUTOIP_DEBUG, AUTOIP_STATE_PROBING, AUTOIP_TICKS_PER_SECOND, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, autoip::llipaddr, LWIP_AUTOIP_RAND, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, MAX_CONFLICTS, PROBE_WAIT, RATE_LIMIT_INTERVAL, autoip::sent_num, autoip::state, autoip::tried_llipaddr, autoip::ttw, and U16_F.
Referenced by autoip_network_changed(), and autoip_start().
Stop AutoIP client.
netif | network interface on which stop the AutoIP client |
References netif::autoip, AUTOIP_STATE_OFF, ERR_OK, netif_set_down(), and autoip::state.
Referenced by dhcp_bind(), dhcp_network_changed(), dhcp_stop(), and net_interface_down_imp().
Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds.
References ANNOUNCE_INTERVAL, ANNOUNCE_NUM, ANNOUNCE_WAIT, netif::autoip, autoip_arp_announce(), autoip_arp_probe(), autoip_bind(), AUTOIP_DEBUG, AUTOIP_STATE_ANNOUNCING, AUTOIP_STATE_BOUND, AUTOIP_STATE_PROBING, AUTOIP_TICKS_PER_SECOND, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, autoip::lastconflict, autoip::llipaddr, LWIP_AUTOIP_RAND, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, netif_list, netif::next, NULL, PROBE_MAX, PROBE_MIN, PROBE_NUM, autoip::sent_num, autoip::state, autoip::ttw, and U16_F.
Referenced by autoip_timer().