69 #if LWIP_NETIF_LOOPBACK_MULTITHREADING
92 #if LWIP_NETIF_STATUS_CALLBACK
93 #define NETIF_STATUS_CALLBACK(n) do{ if (n->status_callback) { (n->status_callback)(n); }}while(0)
95 #define NETIF_STATUS_CALLBACK(n)
98 #if LWIP_NETIF_LINK_CALLBACK
99 #define NETIF_LINK_CALLBACK(n) do{ if (n->link_callback) { (n->link_callback)(n); }}while(0)
101 #define NETIF_LINK_CALLBACK(n)
107 static u8_t netif_num;
109 #if LWIP_NUM_NETIF_CLIENT_DATA > 0
110 static u8_t netif_client_id;
113 #define NETIF_REPORT_TYPE_IPV4 0x01
114 #define NETIF_REPORT_TYPE_IPV6 0x02
115 static void netif_issue_reports(
struct netif*
netif,
u8_t report_type);
118 static err_t netif_null_output_ip6(
struct netif *
netif,
struct pbuf *p,
const ip6_addr_t *ipaddr);
123 static err_t netif_loop_output_ipv4(
struct netif *
netif,
struct pbuf *p,
const ip4_addr_t* addr);
126 static err_t netif_loop_output_ipv6(
struct netif *
netif,
struct pbuf *p,
const ip6_addr_t* addr);
130 static struct netif loop_netif;
150 netif->output = netif_loop_output_ipv4;
153 netif->output_ip6 = netif_loop_output_ipv6;
155 #if LWIP_LOOPIF_MULTICAST
167 #define LOOPIF_ADDRINIT &loop_ipaddr, &loop_netmask, &loop_gw,
168 ip4_addr_t loop_ipaddr, loop_netmask, loop_gw;
169 IP4_ADDR(&loop_gw, 127,0,0,1);
170 IP4_ADDR(&loop_ipaddr, 127,0,0,1);
171 IP4_ADDR(&loop_netmask, 255,0,0,0);
173 #define LOOPIF_ADDRINIT
177 netif_add(&loop_netif, LOOPIF_ADDRINIT
NULL, netif_loopif_init, ip_input);
184 loop_netif.ip6_addr_state[0] = IP6_ADDR_VALID;
207 return ethernet_input(p, inp);
210 return ip_input(p, inp);
243 const ip4_addr_t *ipaddr,
const ip4_addr_t *netmask,
const ip4_addr_t *gw,
255 ip_addr_set_zero_ip4(&
netif->ip_addr);
256 ip_addr_set_zero_ip4(&
netif->netmask);
257 ip_addr_set_zero_ip4(&
netif->gw);
262 netif->ip6_addr_state[i] = IP6_ADDR_INVALID;
264 netif->output_ip6 = netif_null_output_ip6;
268 #ifdef netif_get_client_data
271 #if LWIP_IPV6_AUTOCONFIG
273 netif->ip6_autoconfig_enabled = 0;
275 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
278 #if LWIP_NETIF_STATUS_CALLBACK
281 #if LWIP_NETIF_LINK_CALLBACK
287 #if LWIP_IPV6 && LWIP_IPV6_MLD
301 #if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
302 netif->loop_cnt_current = 0;
306 netif_set_addr(
netif, ipaddr, netmask, gw);
352 netif_set_addr(
struct netif *
netif,
const ip4_addr_t *ipaddr,
const ip4_addr_t *netmask,
353 const ip4_addr_t *gw)
355 if (ip4_addr_isany(ipaddr)) {
358 netif_set_ipaddr(
netif, ipaddr);
359 netif_set_netmask(
netif, netmask);
360 netif_set_gw(
netif, gw);
362 netif_set_netmask(
netif, netmask);
363 netif_set_gw(
netif, gw);
365 netif_set_ipaddr(
netif, ipaddr);
388 if (!ip4_addr_isany_val(*netif_ip4_addr(
netif))) {
390 tcp_netif_ip_addr_changed(netif_ip_addr4(
netif),
NULL);
393 udp_netif_ip_addr_changed(netif_ip_addr4(
netif),
NULL);
396 raw_netif_ip_addr_changed(netif_ip_addr4(
netif),
NULL);
410 if (ip6_addr_isvalid(netif_ip6_addr_state(
netif, i))) {
412 tcp_netif_ip_addr_changed(netif_ip_addr6(
netif, i),
NULL);
415 udp_netif_ip_addr_changed(netif_ip_addr6(
netif, i),
NULL);
418 raw_netif_ip_addr_changed(netif_ip_addr6(
netif, i),
NULL);
444 struct netif * tmp_netif;
451 if (tmp_netif ==
NULL) {
456 #if LWIP_NETIF_REMOVE_CALLBACK
457 if (
netif->remove_callback) {
507 netif_set_ipaddr(
struct netif *
netif,
const ip4_addr_t *ipaddr)
510 *ip_2_ip4(&new_addr) = (ipaddr ? *ipaddr : *IP4_ADDR_ANY4);
514 if (ip4_addr_cmp(ip_2_ip4(&new_addr), netif_ip4_addr(
netif)) == 0) {
517 tcp_netif_ip_addr_changed(netif_ip_addr4(
netif), &new_addr);
520 udp_netif_ip_addr_changed(netif_ip_addr4(
netif), &new_addr);
523 raw_netif_ip_addr_changed(netif_ip_addr4(
netif), &new_addr);
529 ip4_addr_set(ip_2_ip4(&
netif->ip_addr), ipaddr);
541 ip4_addr1_16(netif_ip4_addr(
netif)),
542 ip4_addr2_16(netif_ip4_addr(
netif)),
543 ip4_addr3_16(netif_ip4_addr(
netif)),
544 ip4_addr4_16(netif_ip4_addr(
netif))));
557 netif_set_gw(
struct netif *
netif,
const ip4_addr_t *gw)
559 ip4_addr_set(ip_2_ip4(&
netif->gw), gw);
563 ip4_addr1_16(netif_ip4_gw(
netif)),
564 ip4_addr2_16(netif_ip4_gw(
netif)),
565 ip4_addr3_16(netif_ip4_gw(
netif)),
566 ip4_addr4_16(netif_ip4_gw(
netif))));
580 netif_set_netmask(
struct netif *
netif,
const ip4_addr_t *netmask)
584 ip4_addr_set(ip_2_ip4(&
netif->netmask), netmask);
589 ip4_addr1_16(netif_ip4_netmask(
netif)),
590 ip4_addr2_16(netif_ip4_netmask(
netif)),
591 ip4_addr3_16(netif_ip4_netmask(
netif)),
592 ip4_addr4_16(netif_ip4_netmask(
netif))));
646 !ip4_addr_isany_val(*netif_ip4_addr(
netif))) {
650 etharp_gratuitous(
netif);
657 igmp_report_groups(
netif);
667 mld6_report_groups(
netif);
669 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
688 #if LWIP_IPV4 && LWIP_ARP
690 etharp_cleanup_netif(
netif);
695 nd6_cleanup_netif(
netif);
702 #if LWIP_NETIF_STATUS_CALLBACK
711 netif->status_callback = status_callback;
716 #if LWIP_NETIF_REMOVE_CALLBACK
725 netif->remove_callback = remove_callback;
741 dhcp_network_changed(
netif);
745 autoip_network_changed(
netif);
768 #if LWIP_NETIF_LINK_CALLBACK
777 netif->link_callback = link_callback;
803 #if LWIP_LOOPBACK_MAX_PBUFS
810 struct netif *stats_if = &loop_netif;
825 #if LWIP_LOOPBACK_MAX_PBUFS
828 if (((
netif->loop_cnt_current + clen) <
netif->loop_cnt_current) ||
836 netif->loop_cnt_current += clen;
860 netif->loop_last = last;
862 netif->loop_first = r;
863 netif->loop_last = last;
871 #if LWIP_NETIF_LOOPBACK_MULTITHREADING
882 netif_loop_output_ipv4(
struct netif *
netif,
struct pbuf *p,
const ip4_addr_t* addr)
885 return netif_loop_output(
netif, p);
891 netif_loop_output_ipv6(
struct netif *
netif,
struct pbuf *p,
const ip6_addr_t* addr)
894 return netif_loop_output(
netif, p);
913 struct netif *stats_if = &loop_netif;
923 struct pbuf *in, *in_end;
924 #if LWIP_LOOPBACK_MAX_PBUFS
928 in = in_end =
netif->loop_first;
931 in_end = in_end->
next;
932 #if LWIP_LOOPBACK_MAX_PBUFS
936 #if LWIP_LOOPBACK_MAX_PBUFS
939 ((
netif->loop_cnt_current - clen) <
netif->loop_cnt_current));
940 netif->loop_cnt_current -= clen;
944 if (in_end ==
netif->loop_last) {
968 #if !LWIP_NETIF_LOOPBACK_MULTITHREADING
986 #if LWIP_NUM_NETIF_CLIENT_DATA > 0
994 netif_alloc_client_data_id(
void)
996 u8_t result = netif_client_id;
1016 netif_ip6_addr_set(
struct netif *
netif,
s8_t addr_idx,
const ip6_addr_t *addr6)
1019 netif_ip6_addr_set_parts(
netif, addr_idx, addr6->addr[0], addr6->addr[1],
1020 addr6->addr[2], addr6->addr[3]);
1036 const ip6_addr_t *old_addr;
1040 old_addr = netif_ip6_addr(
netif, addr_idx);
1042 if ((old_addr->addr[0] != i0) || (old_addr->addr[1] != i1) ||
1043 (old_addr->addr[2] != i2) || (old_addr->addr[3] != i3)) {
1046 if (netif_ip6_addr_state(
netif, addr_idx) & IP6_ADDR_VALID) {
1047 #if LWIP_TCP || LWIP_UDP
1049 IP_ADDR6(&new_ipaddr, i0, i1, i2, i3);
1052 tcp_netif_ip_addr_changed(netif_ip_addr6(
netif, addr_idx), &new_ipaddr);
1055 udp_netif_ip_addr_changed(netif_ip_addr6(
netif, addr_idx), &new_ipaddr);
1058 raw_netif_ip_addr_changed(netif_ip_addr6(
netif, addr_idx), &new_ipaddr);
1063 IP6_ADDR(
ip_2_ip6(&(
netif->ip6_addr[addr_idx])), i0, i1, i2, i3);
1066 if (netif_ip6_addr_state(
netif, addr_idx) & IP6_ADDR_VALID) {
1074 netif_ip6_addr_state(
netif, addr_idx)));
1094 old_state = netif_ip6_addr_state(
netif, addr_idx);
1096 if (old_state !=
state) {
1097 u8_t old_valid = old_state & IP6_ADDR_VALID;
1098 u8_t new_valid =
state & IP6_ADDR_VALID;
1104 nd6_adjust_mld_membership(
netif, addr_idx,
state);
1108 if (old_valid && !new_valid) {
1111 tcp_netif_ip_addr_changed(netif_ip_addr6(
netif, addr_idx),
NULL);
1114 udp_netif_ip_addr_changed(netif_ip_addr6(
netif, addr_idx),
NULL);
1117 raw_netif_ip_addr_changed(netif_ip_addr6(
netif, addr_idx),
NULL);
1123 if (!old_valid && new_valid) {
1128 if ((old_state & IP6_ADDR_PREFERRED) != (
state & IP6_ADDR_PREFERRED)) {
1137 netif_ip6_addr_state(
netif, addr_idx)));
1150 netif_get_ip6_addr_match(
struct netif *
netif,
const ip6_addr_t *ip6addr)
1154 if (!ip6_addr_isinvalid(netif_ip6_addr_state(
netif, i)) &&
1155 ip6_addr_cmp(netif_ip6_addr(
netif, i), ip6addr)) {
1171 netif_create_ip6_linklocal_address(
struct netif *
netif,
u8_t from_mac_48bit)
1180 if (from_mac_48bit) {
1196 for (i = 0; (i < 8) && (i < netif->
hwaddr_len); i++) {
1205 #if LWIP_IPV6_DUP_DETECT_ATTEMPTS
1207 netif_ip6_addr_set_state(
netif, 0, IP6_ADDR_TENTATIVE);
1210 netif_ip6_addr_set_state(
netif, 0, IP6_ADDR_PREFERRED);
1225 netif_add_ip6_address(
struct netif *
netif,
const ip6_addr_t *ip6addr,
s8_t *chosen_idx)
1229 i = netif_get_ip6_addr_match(
netif, ip6addr);
1232 if (chosen_idx !=
NULL) {
1240 if (ip6_addr_isinvalid(netif_ip6_addr_state(
netif, i))) {
1242 netif_ip6_addr_set_state(
netif, i, IP6_ADDR_TENTATIVE);
1243 if (chosen_idx !=
NULL) {
1250 if (chosen_idx !=
NULL) {
1259 netif_null_output_ip6(
struct netif *
netif,
struct pbuf *p,
const ip6_addr_t *ipaddr)