void net_nbr_clear_table(struct net_nbr_table *table) { int i; for (i = 0; i < CONFIG_NET_IPV6_MAX_NEIGHBORS; i++) { struct net_nbr *nbr = get_nbr(table->nbr, i); struct net_linkaddr lladdr = { .addr = net_neighbor_lladdr[i].lladdr.addr, .len = net_neighbor_lladdr[i].lladdr.len }; net_nbr_unlink(nbr, &lladdr); } if (table->clear) { table->clear(table); } } #if defined(CONFIG_NET_DEBUG_IPV6_NBR_CACHE) void net_nbr_print(struct net_nbr_table *table) { int i; for (i = 0; i < CONFIG_NET_IPV6_MAX_NEIGHBORS; i++) { struct net_nbr *nbr = get_nbr(table->nbr, i); if (!nbr->ref) { continue; } NET_DBG("[%d] nbr %p data %p ref %d iface %p idx %d ll %s", i, nbr, nbr->data, nbr->ref, nbr->iface, nbr->idx, nbr->idx == NET_NBR_LLADDR_UNKNOWN ? "<unknown>" : net_sprint_ll_addr( net_neighbor_lladdr[nbr->idx].lladdr.addr, net_neighbor_lladdr[nbr->idx].lladdr.len)); } }
static int tester_send(struct net_if *iface, struct net_pkt *pkt) { struct net_eth_hdr *hdr; if (!pkt->frags) { printk("No data to send!\n"); return -ENODATA; } if (net_pkt_ll_reserve(pkt) != sizeof(struct net_eth_hdr)) { printk("No ethernet header in pkt %p", pkt); send_status = -EINVAL; return send_status; } hdr = (struct net_eth_hdr *)net_pkt_ll(pkt); if (ntohs(hdr->type) == NET_ETH_PTYPE_ARP) { struct net_arp_hdr *arp_hdr = NET_ARP_HDR(pkt); if (ntohs(arp_hdr->opcode) == NET_ARP_REPLY) { if (!req_test && pkt != pending_pkt) { printk("Pending data but to be sent is wrong, " "expecting %p but got %p\n", pending_pkt, pkt); return -EINVAL; } if (!req_test && memcmp(&hdr->dst, &hwaddr, sizeof(struct net_eth_addr))) { char out[sizeof("xx:xx:xx:xx:xx:xx")]; snprintk(out, sizeof(out), "%s", net_sprint_ll_addr( (u8_t *)&hdr->dst, sizeof(struct net_eth_addr))); printk("Invalid hwaddr %s, should be %s\n", out, net_sprint_ll_addr( (u8_t *)&hwaddr, sizeof(struct net_eth_addr))); send_status = -EINVAL; return send_status; } } else if (ntohs(arp_hdr->opcode) == NET_ARP_REQUEST) { if (memcmp(&hdr->src, &hwaddr, sizeof(struct net_eth_addr))) { char out[sizeof("xx:xx:xx:xx:xx:xx")]; snprintk(out, sizeof(out), "%s", net_sprint_ll_addr( (u8_t *)&hdr->src, sizeof(struct net_eth_addr))); printk("Invalid hwaddr %s, should be %s\n", out, net_sprint_ll_addr( (u8_t *)&hwaddr, sizeof(struct net_eth_addr))); send_status = -EINVAL; return send_status; } } } printk("Data was sent successfully\n"); net_pkt_unref(pkt); send_status = 0; return 0; }
static enum net_verdict net_dhcpv4_input(struct net_conn *conn, struct net_buf *buf, void *user_data) { struct dhcp_msg *msg; struct net_buf *frag; struct net_if *iface; uint8_t msg_type; uint8_t min; uint16_t pos; if (!conn) { NET_DBG("Invalid connection"); return NET_DROP; } if (!buf || !buf->frags) { NET_DBG("Invalid buffer, no fragments"); return NET_DROP; } iface = net_nbuf_iface(buf); if (!iface) { return NET_DROP; } frag = buf->frags; min = NET_IPV4UDPH_LEN + sizeof(struct dhcp_msg); /* * If the message is not DHCP then continue passing to * related handlers. */ if (net_buf_frags_len(frag) < min) { NET_DBG("Input msg is not related to DHCPv4"); return NET_CONTINUE; } msg = (struct dhcp_msg *)(frag->data + NET_IPV4UDPH_LEN); NET_DBG("received dhcp msg [op=0x%x htype=0x%x hlen=%u xid=0x%x " "secs=%u flags=0x%x ciaddr=%d.%d.%d.%d yiaddr=%d.%d.%d.%d " "siaddr=%d.%d.%d.%d giaddr=%d.%d.%d.%d chaddr=%s]", msg->op, msg->htype, msg->hlen, ntohl(msg->xid), msg->secs, msg->flags, msg->ciaddr[0], msg->ciaddr[1], msg->ciaddr[2], msg->ciaddr[3], msg->yiaddr[0], msg->yiaddr[1], msg->yiaddr[2], msg->yiaddr[3], msg->siaddr[0], msg->siaddr[1], msg->siaddr[2], msg->siaddr[3], msg->giaddr[0], msg->giaddr[1], msg->giaddr[2], msg->giaddr[3], net_sprint_ll_addr(msg->chaddr, 6)); if (!(msg->op == DHCPV4_MSG_BOOT_REPLY && iface->dhcpv4.xid == ntohl(msg->xid) && !memcmp(msg->chaddr, iface->link_addr.addr, iface->link_addr.len))) { NET_DBG("Unexpected op (%d), xid (%x vs %x) or chaddr", msg->op, iface->dhcpv4.xid, ntohl(msg->xid)); goto drop; } memcpy(iface->dhcpv4.requested_ip.s4_addr, msg->yiaddr, sizeof(msg->yiaddr)); /* sname, file are not used at the moment, skip it */ frag = net_nbuf_skip(frag, min, &pos, SIZE_OF_SNAME + SIZE_OF_FILE); if (!frag && pos) { goto drop; } if (parse_options(iface, frag, pos, &msg_type) == NET_DROP) { NET_DBG("Invalid Options"); goto drop; } net_nbuf_unref(buf); handle_dhcpv4_reply(iface, msg_type); return NET_OK; drop: return NET_DROP; }