54 #if LWIP_NETIF_LOOPBACK_MULTITHREADING 72 #if LWIP_NETIF_STATUS_CALLBACK 73 #define NETIF_STATUS_CALLBACK(n) do{ if (n->status_callback) { (n->status_callback)(n); }}while(0) 75 #define NETIF_STATUS_CALLBACK(n) 78 #if LWIP_NETIF_LINK_CALLBACK 79 #define NETIF_LINK_CALLBACK(n) do{ if (n->link_callback) { (n->link_callback)(n); }}while(0) 81 #define NETIF_LINK_CALLBACK(n) 87 static u8_t netif_num;
89 #define NETIF_REPORT_TYPE_IPV4 0x01 90 #define NETIF_REPORT_TYPE_IPV6 0x02 91 static void netif_issue_reports(
struct netif*
netif,
u8_t report_type);
94 static err_t netif_null_output_ip6(
struct netif *
netif,
struct pbuf *p,
const ip6_addr_t *ipaddr);
99 static err_t netif_loop_output_ipv4(
struct netif *
netif,
struct pbuf *p,
const ip4_addr_t* addr);
102 static err_t netif_loop_output_ipv6(
struct netif *
netif,
struct pbuf *p,
const ip6_addr_t* addr);
106 static struct netif loop_netif;
123 netif->
name[0] =
'l';
124 netif->
name[1] =
'o';
126 netif->output = netif_loop_output_ipv4;
129 netif->output_ip6 = netif_loop_output_ipv6;
131 #if LWIP_LOOPIF_MULTICAST 143 #define LOOPIF_ADDRINIT &loop_ipaddr, &loop_netmask, &loop_gw, 144 ip4_addr_t loop_ipaddr, loop_netmask, loop_gw;
145 IP4_ADDR(&loop_gw, 127,0,0,1);
146 IP4_ADDR(&loop_ipaddr, 127,0,0,1);
147 IP4_ADDR(&loop_netmask, 255,0,0,0);
149 #define LOOPIF_ADDRINIT 160 loop_netif.ip6_addr_state[0] = IP6_ADDR_VALID;
186 const ip4_addr_t *ipaddr,
const ip4_addr_t *netmask,
const ip4_addr_t *gw,
198 ip_addr_set_zero_ip4(&netif->ip_addr);
199 ip_addr_set_zero_ip4(&netif->netmask);
200 ip_addr_set_zero_ip4(&netif->gw);
205 netif_ip6_addr_set_state(netif, i, IP6_ADDR_INVALID);
207 netif->output_ip6 = netif_null_output_ip6;
217 netif->autoip =
NULL;
219 #if LWIP_IPV6_AUTOCONFIG 221 netif->ip6_autoconfig_enabled = 0;
223 #if LWIP_IPV6_SEND_ROUTER_SOLICIT 230 #if LWIP_NETIF_STATUS_CALLBACK 231 netif->status_callback =
NULL;
233 #if LWIP_NETIF_LINK_CALLBACK 234 netif->link_callback =
NULL;
237 netif->igmp_mac_filter =
NULL;
239 #if LWIP_IPV6 && LWIP_IPV6_MLD 240 netif->mld_mac_filter =
NULL;
243 netif->loop_first =
NULL;
244 netif->loop_last =
NULL;
249 netif->
num = netif_num++;
252 #if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS 253 netif->loop_cnt_current = 0;
257 netif_set_addr(netif, ipaddr, netmask, gw);
262 if (init(netif) !=
ERR_OK) {
303 netif_set_addr(
struct netif *
netif,
const ip4_addr_t *ipaddr,
const ip4_addr_t *netmask,
304 const ip4_addr_t *gw)
306 netif_set_netmask(netif, netmask);
307 netif_set_gw(netif, gw);
309 netif_set_ipaddr(netif, ipaddr);
326 if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) {
328 tcp_netif_ipv4_addr_changed(netif_ip4_addr(netif),
NULL);
341 #if LWIP_IPV6 && LWIP_IPV6_MLD 353 if (netif_default == netif) {
358 if (netif_list == netif) {
359 netif_list = netif->
next;
362 struct netif * tmp_netif;
363 for (tmp_netif = netif_list; tmp_netif !=
NULL; tmp_netif = tmp_netif->
next) {
364 if (tmp_netif->
next == netif) {
369 if (tmp_netif ==
NULL) {
374 #if LWIP_NETIF_REMOVE_CALLBACK 375 if (netif->remove_callback) {
376 netif->remove_callback(netif);
400 for (netif = netif_list; netif !=
NULL; netif = netif->
next) {
401 if (num == netif->
num &&
402 name[0] == netif->
name[0] &&
403 name[1] == netif->
name[1]) {
423 netif_set_ipaddr(
struct netif *netif,
const ip4_addr_t *ipaddr)
425 ip4_addr_t new_addr = (ipaddr ? *ipaddr : *IP4_ADDR_ANY);
427 if (ip4_addr_cmp(&new_addr, netif_ip4_addr(netif)) == 0) {
430 tcp_netif_ipv4_addr_changed(netif_ip4_addr(netif), ipaddr);
433 udp_netif_ipv4_addr_changed(netif_ip4_addr(netif), ipaddr);
439 ip4_addr_set(ip_2_ip4(&netif->ip_addr), ipaddr);
451 ip4_addr1_16(netif_ip4_addr(netif)),
452 ip4_addr2_16(netif_ip4_addr(netif)),
453 ip4_addr3_16(netif_ip4_addr(netif)),
454 ip4_addr4_16(netif_ip4_addr(netif))));
466 netif_set_gw(
struct netif *netif,
const ip4_addr_t *gw)
468 ip4_addr_set(ip_2_ip4(&netif->gw), gw);
472 ip4_addr1_16(netif_ip4_gw(netif)),
473 ip4_addr2_16(netif_ip4_gw(netif)),
474 ip4_addr3_16(netif_ip4_gw(netif)),
475 ip4_addr4_16(netif_ip4_gw(netif))));
488 netif_set_netmask(
struct netif *netif,
const ip4_addr_t *netmask)
492 ip4_addr_set(ip_2_ip4(&netif->netmask), netmask);
497 ip4_addr1_16(netif_ip4_netmask(netif)),
498 ip4_addr2_16(netif_ip4_netmask(netif)),
499 ip4_addr3_16(netif_ip4_netmask(netif)),
500 ip4_addr4_16(netif_ip4_netmask(netif))));
520 netif_default = netif;
522 netif ? netif->
name[0] :
'\'', netif ? netif->
name[1] :
'\''));
548 netif_issue_reports(
struct netif* netif,
u8_t report_type)
552 !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
556 etharp_gratuitous(netif);
563 igmp_report_groups(netif);
573 mld6_report_groups(netif);
575 #if LWIP_IPV6_SEND_ROUTER_SOLICIT 593 #if LWIP_IPV4 && LWIP_ARP 595 etharp_cleanup_netif(netif);
602 #if LWIP_NETIF_STATUS_CALLBACK 610 netif->status_callback = status_callback;
615 #if LWIP_NETIF_REMOVE_CALLBACK 623 netif->remove_callback = remove_callback;
639 dhcp_network_changed(netif);
645 autoip_network_changed(netif);
668 #if LWIP_NETIF_LINK_CALLBACK 676 netif->link_callback = link_callback;
696 netif_loop_output(
struct netif *netif,
struct pbuf *p)
701 #if LWIP_LOOPBACK_MAX_PBUFS 708 struct netif *stats_if = &loop_netif;
710 struct netif *stats_if = netif;
723 #if LWIP_LOOPBACK_MAX_PBUFS 726 if (((netif->loop_cnt_current + clen) < netif->loop_cnt_current) ||
734 netif->loop_cnt_current += clen;
753 if (netif->loop_first !=
NULL) {
754 LWIP_ASSERT(
"if first != NULL, last must also be != NULL", netif->loop_last !=
NULL);
755 netif->loop_last->
next = r;
756 netif->loop_last = last;
758 netif->loop_first = r;
759 netif->loop_last = last;
767 #if LWIP_NETIF_LOOPBACK_MULTITHREADING 778 netif_loop_output_ipv4(
struct netif *netif,
struct pbuf *p,
const ip4_addr_t* addr)
781 return netif_loop_output(netif, p);
787 netif_loop_output_ipv6(
struct netif *netif,
struct pbuf *p,
const ip6_addr_t* addr)
790 return netif_loop_output(netif, p);
803 netif_poll(
struct netif *netif)
810 struct netif *stats_if = &loop_netif;
812 struct netif *stats_if = netif;
820 in = netif->loop_first;
822 struct pbuf *in_end = in;
823 #if LWIP_LOOPBACK_MAX_PBUFS 828 in_end = in_end->
next;
829 #if LWIP_LOOPBACK_MAX_PBUFS 833 #if LWIP_LOOPBACK_MAX_PBUFS 836 ((netif->loop_cnt_current - clen) < netif->loop_cnt_current));
837 netif->loop_cnt_current -= clen;
841 if (in_end == netif->loop_last) {
843 netif->loop_first = netif->loop_last =
NULL;
846 netif->loop_first = in_end->
next;
847 LWIP_ASSERT(
"should not be null since first != last!", netif->loop_first !=
NULL);
866 }
while (netif->loop_first !=
NULL);
869 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING 878 while (netif !=
NULL) {
897 netif_get_ip6_addr_match(
struct netif *netif,
const ip6_addr_t *ip6addr)
901 if (!ip6_addr_isinvalid(netif_ip6_addr_state(netif, i)) &&
902 ip6_addr_cmp(netif_ip6_addr(netif, i), ip6addr)) {
916 netif_create_ip6_linklocal_address(
struct netif *netif,
u8_t from_mac_48bit)
922 ip_2_ip6(&netif->ip6_addr[0])->addr[1] = 0;
925 if (from_mac_48bit) {
931 ip_2_ip6(&netif->ip6_addr[0])->addr[3] =
htonl((0xfeul << 24) |
937 ip_2_ip6(&netif->ip6_addr[0])->addr[2] = 0;
938 ip_2_ip6(&netif->ip6_addr[0])->addr[3] = 0;
941 for (i = 0; (i < 8) && (i < netif->
hwaddr_len); i++) {
950 #if LWIP_IPV6_DUP_DETECT_ATTEMPTS 952 netif->ip6_addr_state[0] = IP6_ADDR_TENTATIVE;
955 netif->ip6_addr_state[0] = IP6_ADDR_PREFERRED;
968 netif_add_ip6_address(
struct netif *netif,
const ip6_addr_t *ip6addr,
s8_t *chosen_idx)
972 i = netif_get_ip6_addr_match(netif, ip6addr);
975 if (chosen_idx !=
NULL) {
983 if (!ip6_addr_isvalid(netif->ip6_addr_state[i])) {
985 netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE);
986 if (chosen_idx !=
NULL) {
993 if (chosen_idx !=
NULL) {
1002 netif_null_output_ip6(
struct netif *netif,
struct pbuf *p,
const ip6_addr_t *ipaddr)
err_t(* netif_input_fn)(struct pbuf *p, struct netif *inp)
#define NETIF_REPORT_TYPE_IPV4
struct netif * netif_list
void(* netif_status_callback_fn)(struct netif *netif)
struct netif * netif_default
void(* tcpip_callback_fn)(void *ctx)
#define ip_addr_set_zero_ip6(ipaddr)
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
void netif_set_link_down(struct netif *netif)
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
#define mib2_remove_ip4(ni)
#define NETIF_FLAG_LINK_UP
err_t ip_input(struct pbuf *p, struct netif *inp)
void netif_set_default(struct netif *netif)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
#define MIB2_STATS_NETIF_ADD(n, x, val)
#define mib2_add_route_ip4(dflt, ni)
void netif_set_up(struct netif *netif)
#define SYS_ARCH_DECL_PROTECT(lev)
#define NETIF_STATUS_CALLBACK(n)
#define mib2_netif_added(ni)
u8_t pbuf_free(struct pbuf *p)
err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)
#define NETIF_FLAG_ETHARP
#define MIB2_COPY_SYSUPTIME_TO(ptrToVal)
struct netif * netif_find(const char *name)
err_t tcpip_input(struct pbuf *p, struct netif *inp)
#define NETIF_SET_HWADDRHINT(netif, hint)
#define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
#define LINK_STATS_INC(x)
#define LWIP_ASSERT(message, assertion)
void netif_remove(struct netif *netif)
#define IP_SET_TYPE_VAL(ipaddr, iptype)
#define IP_ADDR6(ipaddr, i0, i1, i2, i3)
err_t(* netif_init_fn)(struct netif *netif)
#define ip_addr_copy_from_ip6(dest, src)
#define LWIP_IPV6_NUM_ADDRESSES
void netif_set_down(struct netif *netif)
u8_t pbuf_clen(struct pbuf *p)
#define NETIF_REPORT_TYPE_IPV6
#define NETIF_LINK_CALLBACK(n)
#define LWIP_ND6_MAX_MULTICAST_SOLICIT
#define LWIP_LOOPBACK_MAX_PBUFS
#define SYS_ARCH_PROTECT(lev)
#define mib2_remove_route_ip4(dflt, ni)
#define SYS_ARCH_UNPROTECT(lev)
#define MIB2_INIT_NETIF(netif, type, speed)
#define mib2_netif_removed(ni)
#define MIB2_STATS_NETIF_INC(n, x)
void netif_set_link_up(struct netif *netif)
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
#define netif_is_up(netif)
#define LWIP_DEBUGF(debug, message)
#define LWIP_UNUSED_ARG(x)