Lines Matching +full:ip +full:- +full:addr
8 * SPDX-License-Identifier: Apache-2.0
51 while (!k_fifo_is_empty(&entry->pending_queue)) { in arp_entry_cleanup()
52 pkt = k_fifo_get(&entry->pending_queue, K_FOREVER); in arp_entry_cleanup()
55 atomic_get(&pkt->atomic_ref) - 1); in arp_entry_cleanup()
60 entry->iface = NULL; in arp_entry_cleanup()
62 (void)memset(&entry->ip, 0, sizeof(struct in_addr)); in arp_entry_cleanup()
63 (void)memset(&entry->eth, 0, sizeof(struct net_eth_addr)); in arp_entry_cleanup()
76 net_sprint_ipv4_addr(&entry->ip)); in arp_entry_find()
78 if (entry->iface == iface && in arp_entry_find()
79 net_ipv4_addr_cmp(&entry->ip, dst)) { in arp_entry_find()
84 *previous = &entry->node; in arp_entry_find()
106 if (&entry->node != sys_slist_peek_head(&arp_table)) { in arp_entry_find_move_first()
107 sys_slist_remove(&arp_table, prev, &entry->node); in arp_entry_find_move_first()
108 sys_slist_prepend(&arp_table, &entry->node); in arp_entry_find_move_first()
135 sys_slist_remove(&arp_pending_entries, prev, &entry->node); in arp_entry_get_pending()
181 NET_DBG("dst %s", net_sprint_ipv4_addr(&entry->ip)); in arp_entry_register_pending()
183 sys_slist_append(&arp_pending_entries, &entry->node); in arp_entry_register_pending()
185 entry->req_start = k_uptime_get_32(); in arp_entry_register_pending()
205 if ((int32_t)(entry->req_start + in arp_request_timeout()
206 ARP_REQUEST_TIMEOUT - current) > 0) { in arp_request_timeout()
212 sys_slist_remove(&arp_pending_entries, NULL, &entry->node); in arp_request_timeout()
213 sys_slist_append(&arp_free_entries, &entry->node); in arp_request_timeout()
220 K_MSEC(entry->req_start + in arp_request_timeout()
221 ARP_REQUEST_TIMEOUT - current)); in arp_request_timeout()
228 struct in_addr *addr) in if_get_addr() argument
230 struct net_if_ipv4 *ipv4 = iface->config.ip.ipv4; in if_get_addr()
236 ARRAY_FOR_EACH(ipv4->unicast, i) { in if_get_addr()
237 if (ipv4->unicast[i].ipv4.is_used && in if_get_addr()
238 ipv4->unicast[i].ipv4.address.family == AF_INET && in if_get_addr()
239 ipv4->unicast[i].ipv4.addr_state == NET_ADDR_PREFERRED && in if_get_addr()
240 (!addr || in if_get_addr()
241 net_ipv4_addr_cmp(addr, in if_get_addr()
242 &ipv4->unicast[i].ipv4.address.in_addr))) { in if_get_addr()
243 return &ipv4->unicast[i].ipv4.address.in_addr; in if_get_addr()
283 net_buf_add(pkt->buffer, sizeof(struct net_arp_hdr)); in arp_prepare()
295 k_fifo_put(&entry->pending_queue, pending); in arp_prepare()
298 entry->iface = net_pkt_iface(pkt); in arp_prepare()
300 net_ipaddr_copy(&entry->ip, next_addr); in arp_prepare()
302 net_pkt_lladdr_src(pkt)->addr = in arp_prepare()
303 (uint8_t *)net_if_get_link_addr(entry->iface)->addr; in arp_prepare()
307 net_pkt_lladdr_src(pkt)->addr = in arp_prepare()
308 (uint8_t *)net_if_get_link_addr(iface)->addr; in arp_prepare()
311 net_pkt_lladdr_src(pkt)->len = sizeof(struct net_eth_addr); in arp_prepare()
313 net_pkt_lladdr_dst(pkt)->addr = (uint8_t *)net_eth_broadcast_addr(); in arp_prepare()
314 net_pkt_lladdr_dst(pkt)->len = sizeof(struct net_eth_addr); in arp_prepare()
316 hdr->hwtype = htons(NET_ARP_HTYPE_ETH); in arp_prepare()
317 hdr->protocol = htons(NET_ETH_PTYPE_IP); in arp_prepare()
318 hdr->hwlen = sizeof(struct net_eth_addr); in arp_prepare()
319 hdr->protolen = sizeof(struct in_addr); in arp_prepare()
320 hdr->opcode = htons(NET_ARP_REQUEST); in arp_prepare()
322 (void)memset(&hdr->dst_hwaddr.addr, 0x00, sizeof(struct net_eth_addr)); in arp_prepare()
324 net_ipv4_addr_copy_raw(hdr->dst_ipaddr, (uint8_t *)next_addr); in arp_prepare()
326 memcpy(hdr->src_hwaddr.addr, net_pkt_lladdr_src(pkt)->addr, in arp_prepare()
332 my_addr = (struct in_addr *)NET_IPV4_HDR(pending)->src; in arp_prepare()
334 my_addr = if_get_addr(entry->iface, current_ip); in arp_prepare()
338 net_ipv4_addr_copy_raw(hdr->src_ipaddr, (uint8_t *)my_addr); in arp_prepare()
340 (void)memset(&hdr->src_ipaddr, 0, sizeof(struct in_addr)); in arp_prepare()
353 struct in_addr *addr; in net_arp_prepare() local
355 if (!pkt || !pkt->buffer) { in net_arp_prepare()
366 &NET_IPV4_HDR(pkt)->src) || in net_arp_prepare()
368 &NET_IPV4_HDR(pkt)->dst); in net_arp_prepare()
376 struct net_if_ipv4 *ipv4 = net_pkt_iface(pkt)->config.ip.ipv4; in net_arp_prepare()
379 addr = &ipv4->gw; in net_arp_prepare()
380 if (net_ipv4_is_addr_unspecified(addr)) { in net_arp_prepare()
389 addr = request_ip; in net_arp_prepare()
392 addr = request_ip; in net_arp_prepare()
400 entry = arp_entry_find_move_first(net_pkt_iface(pkt), addr); in net_arp_prepare()
404 entry = arp_entry_find_pending(net_pkt_iface(pkt), addr); in net_arp_prepare()
417 if (k_queue_unique_append(&entry->pending_queue._queue, in net_arp_prepare()
420 net_sprint_ipv4_addr(addr), pkt); in net_arp_prepare()
428 req = arp_prepare(net_pkt_iface(pkt), addr, entry, pkt, in net_arp_prepare()
433 * or there is already a pending query to this IP in net_arp_prepare()
443 sys_slist_prepend(&arp_free_entries, &entry->node); in net_arp_prepare()
452 net_pkt_lladdr_src(pkt)->addr = in net_arp_prepare()
453 (uint8_t *)net_if_get_link_addr(entry->iface)->addr; in net_arp_prepare()
454 net_pkt_lladdr_src(pkt)->len = sizeof(struct net_eth_addr); in net_arp_prepare()
456 net_pkt_lladdr_dst(pkt)->addr = (uint8_t *)&entry->eth; in net_arp_prepare()
457 net_pkt_lladdr_dst(pkt)->len = sizeof(struct net_eth_addr); in net_arp_prepare()
459 NET_DBG("ARP using ll %s for IP %s", in net_arp_prepare()
460 net_sprint_ll_addr(net_pkt_lladdr_dst(pkt)->addr, in net_arp_prepare()
462 net_sprint_ipv4_addr(&NET_IPV4_HDR(pkt)->dst)); in net_arp_prepare()
476 NET_DBG("Gratuitous ARP hwaddr %s -> %s", in arp_gratuitous()
477 net_sprint_ll_addr((const uint8_t *)&entry->eth, in arp_gratuitous()
482 memcpy(&entry->eth, hwaddr, sizeof(struct net_eth_addr)); in arp_gratuitous()
499 net_buf_add(pkt->buffer, sizeof(struct net_arp_hdr)); in arp_gratuitous_send()
504 hdr->hwtype = htons(NET_ARP_HTYPE_ETH); in arp_gratuitous_send()
505 hdr->protocol = htons(NET_ETH_PTYPE_IP); in arp_gratuitous_send()
506 hdr->hwlen = sizeof(struct net_eth_addr); in arp_gratuitous_send()
507 hdr->protolen = sizeof(struct in_addr); in arp_gratuitous_send()
508 hdr->opcode = htons(NET_ARP_REQUEST); in arp_gratuitous_send()
510 memcpy(&hdr->dst_hwaddr.addr, net_eth_broadcast_addr(), in arp_gratuitous_send()
512 memcpy(&hdr->src_hwaddr.addr, net_if_get_link_addr(iface)->addr, in arp_gratuitous_send()
515 net_ipv4_addr_copy_raw(hdr->dst_ipaddr, (uint8_t *)ipaddr); in arp_gratuitous_send()
516 net_ipv4_addr_copy_raw(hdr->src_ipaddr, (uint8_t *)ipaddr); in arp_gratuitous_send()
518 net_pkt_lladdr_src(pkt)->addr = net_if_get_link_addr(iface)->addr; in arp_gratuitous_send()
519 net_pkt_lladdr_src(pkt)->len = sizeof(struct net_eth_addr); in arp_gratuitous_send()
521 net_pkt_lladdr_dst(pkt)->addr = (uint8_t *)net_eth_broadcast_addr(); in arp_gratuitous_send()
522 net_pkt_lladdr_dst(pkt)->len = sizeof(struct net_eth_addr); in arp_gratuitous_send()
533 struct net_if_ipv4 *ipv4 = iface->config.ip.ipv4; in notify_all_ipv4_addr()
541 if (ipv4->unicast[i].ipv4.is_used && in notify_all_ipv4_addr()
542 ipv4->unicast[i].ipv4.address.family == AF_INET && in notify_all_ipv4_addr()
543 ipv4->unicast[i].ipv4.addr_state == NET_ADDR_PREFERRED) { in notify_all_ipv4_addr()
545 &ipv4->unicast[i].ipv4.address.in_addr); in notify_all_ipv4_addr()
585 if (cb->info_length != sizeof(struct in_addr)) { in ipv4_event_handler()
589 ipaddr = (struct in_addr *)cb->info; in ipv4_event_handler()
647 memcpy(&arp_ent->eth, hwaddr, in net_arp_update()
660 arp_ent->req_start = k_uptime_get_32(); in net_arp_update()
661 arp_ent->iface = iface; in net_arp_update()
662 net_ipaddr_copy(&arp_ent->ip, src); in net_arp_update()
663 memcpy(&arp_ent->eth, hwaddr, sizeof(arp_ent->eth)); in net_arp_update()
664 sys_slist_prepend(&arp_table, &arp_ent->node); in net_arp_update()
674 memcpy(&entry->eth, hwaddr, sizeof(struct net_eth_addr)); in net_arp_update()
677 sys_slist_prepend(&arp_table, &entry->node); in net_arp_update()
679 while (!k_fifo_is_empty(&entry->pending_queue)) { in net_arp_update()
682 pkt = k_fifo_get(&entry->pending_queue, K_FOREVER); in net_arp_update()
685 net_pkt_lladdr_dst(pkt)->len = sizeof(struct net_eth_addr); in net_arp_update()
686 net_pkt_lladdr_dst(pkt)->addr = in net_arp_update()
687 (uint8_t *) &NET_ETH_HDR(pkt)->dst.addr; in net_arp_update()
691 net_sprint_ipv4_addr(&entry->ip), in net_arp_update()
692 pkt, pkt->frags); in net_arp_update()
701 ret = net_if_l2(iface)->send(iface, pkt); in net_arp_update()
725 net_buf_add(pkt->buffer, sizeof(struct net_arp_hdr)); in arp_prepare_reply()
734 hdr->hwtype = htons(NET_ARP_HTYPE_ETH); in arp_prepare_reply()
735 hdr->protocol = htons(NET_ETH_PTYPE_IP); in arp_prepare_reply()
736 hdr->hwlen = sizeof(struct net_eth_addr); in arp_prepare_reply()
737 hdr->protolen = sizeof(struct in_addr); in arp_prepare_reply()
738 hdr->opcode = htons(NET_ARP_REPLY); in arp_prepare_reply()
740 memcpy(&hdr->dst_hwaddr.addr, &dst_addr->addr, in arp_prepare_reply()
742 memcpy(&hdr->src_hwaddr.addr, net_if_get_link_addr(iface)->addr, in arp_prepare_reply()
745 net_ipv4_addr_copy_raw(hdr->dst_ipaddr, query->src_ipaddr); in arp_prepare_reply()
746 net_ipv4_addr_copy_raw(hdr->src_ipaddr, query->dst_ipaddr); in arp_prepare_reply()
748 net_pkt_lladdr_src(pkt)->addr = net_if_get_link_addr(iface)->addr; in arp_prepare_reply()
749 net_pkt_lladdr_src(pkt)->len = sizeof(struct net_eth_addr); in arp_prepare_reply()
751 net_pkt_lladdr_dst(pkt)->addr = (uint8_t *)&hdr->dst_hwaddr.addr; in arp_prepare_reply()
752 net_pkt_lladdr_dst(pkt)->len = sizeof(struct net_eth_addr); in arp_prepare_reply()
759 if (ntohs(arp_hdr->hwtype) != NET_ARP_HTYPE_ETH || in arp_hdr_check()
760 ntohs(arp_hdr->protocol) != NET_ETH_PTYPE_IP || in arp_hdr_check()
761 arp_hdr->hwlen != sizeof(struct net_eth_addr) || in arp_hdr_check()
762 arp_hdr->protolen != NET_ARP_IPV4_PTYPE_SIZE || in arp_hdr_check()
763 net_ipv4_is_addr_loopback((struct in_addr *)arp_hdr->src_ipaddr)) { in arp_hdr_check()
777 struct in_addr *addr; in net_arp_input() local
779 if (net_pkt_get_len(pkt) < (sizeof(struct net_arp_hdr) - in net_arp_input()
780 (net_pkt_ip_data(pkt) - (uint8_t *)eth_hdr))) { in net_arp_input()
782 net_pkt_get_len(pkt), sizeof(struct net_arp_hdr) - in net_arp_input()
783 (net_pkt_ip_data(pkt) - (uint8_t *)eth_hdr), pkt); in net_arp_input()
792 switch (ntohs(arp_hdr->opcode)) { in net_arp_input()
797 if (memcmp(&arp_hdr->src_hwaddr, in net_arp_input()
798 net_if_get_link_addr(net_pkt_iface(pkt))->addr, in net_arp_input()
804 if (net_eth_is_addr_broadcast(ð_hdr->dst) && in net_arp_input()
805 (net_eth_is_addr_broadcast(&arp_hdr->dst_hwaddr) || in net_arp_input()
806 net_eth_is_addr_all_zeroes(&arp_hdr->dst_hwaddr)) && in net_arp_input()
807 net_ipv4_addr_cmp_raw(arp_hdr->dst_ipaddr, in net_arp_input()
808 arp_hdr->src_ipaddr)) { in net_arp_input()
809 /* If the IP address is in our cache, in net_arp_input()
813 (struct in_addr *)arp_hdr->src_ipaddr, in net_arp_input()
814 &arp_hdr->src_hwaddr, in net_arp_input()
821 * and Source IP address is Multicast address. in net_arp_input()
823 if (memcmp(ð_hdr->dst, net_eth_broadcast_addr(), in net_arp_input()
825 net_ipv4_is_addr_mcast((struct in_addr *)arp_hdr->src_ipaddr)) { in net_arp_input()
826 NET_DBG("DROP: eth addr is bcast, src addr is mcast"); in net_arp_input()
831 addr = if_get_addr(net_pkt_iface(pkt), in net_arp_input()
832 (struct in_addr *)arp_hdr->dst_ipaddr); in net_arp_input()
833 if (!addr) { in net_arp_input()
839 net_sprint_ipv4_addr(&arp_hdr->src_ipaddr), in net_arp_input()
840 net_sprint_ll_addr((uint8_t *)&arp_hdr->src_hwaddr, in net_arp_input()
841 arp_hdr->hwlen), in net_arp_input()
842 net_sprint_ipv4_addr(&arp_hdr->dst_ipaddr)); in net_arp_input()
846 * and the target IP address is our address. in net_arp_input()
848 if (net_eth_is_addr_unspecified(&arp_hdr->dst_hwaddr)) { in net_arp_input()
850 net_sprint_ipv4_addr(&arp_hdr->src_ipaddr), in net_arp_input()
851 net_sprint_ll_addr((uint8_t *)&arp_hdr->src_hwaddr, in net_arp_input()
852 arp_hdr->hwlen), in net_arp_input()
856 (struct in_addr *)arp_hdr->src_ipaddr, in net_arp_input()
857 &arp_hdr->src_hwaddr, in net_arp_input()
860 dst_hw_addr = &arp_hdr->src_hwaddr; in net_arp_input()
862 dst_hw_addr = ð_hdr->src; in net_arp_input()
876 if (net_ipv4_is_my_addr((struct in_addr *)arp_hdr->dst_ipaddr)) { in net_arp_input()
877 NET_DBG("Received ll %s for IP %s", in net_arp_input()
878 net_sprint_ll_addr(arp_hdr->src_hwaddr.addr, in net_arp_input()
880 net_sprint_ipv4_addr(arp_hdr->src_ipaddr)); in net_arp_input()
882 (struct in_addr *)arp_hdr->src_ipaddr, in net_arp_input()
883 &arp_hdr->src_hwaddr, in net_arp_input()
905 if (iface && iface != entry->iface) { in net_arp_clear_cache()
906 prev = &entry->node; in net_arp_clear_cache()
912 sys_slist_remove(&arp_table, prev, &entry->node); in net_arp_clear_cache()
913 sys_slist_prepend(&arp_free_entries, &entry->node); in net_arp_clear_cache()
922 if (iface && iface != entry->iface) { in net_arp_clear_cache()
923 prev = &entry->node; in net_arp_clear_cache()
929 sys_slist_remove(&arp_pending_entries, prev, &entry->node); in net_arp_clear_cache()
930 sys_slist_prepend(&arp_free_entries, &entry->node); in net_arp_clear_cache()
945 return -ENOENT; in net_arp_clear_pending()