void us_mfa::data_available(raw_socket *sock) { #ifndef LINUX_NO_MMAP if (sock->m_mmapped) { int i = 0; while (i < MAX_EAT_ONE_CYCLE && *(unsigned long *)sock->m_mmapbuf) { tpacket_hdr *hdr = (tpacket_hdr *)sock->m_mmapbuf; sockaddr_ll *sa = (sockaddr_ll *)(((uint8_t *)hdr) + TPACKET_ALIGN(sizeof(*hdr))); uint8_t *bp = ((uint8_t *)hdr) + hdr->tp_mac; if (sa->sll_protocol == htons(ETH_P_IPV6) && sa->sll_pkttype != PACKET_OUTGOING) handle_ipv6(sa->sll_ifindex, bp, hdr->tp_len); hdr->tp_status = 0; sock->m_mmapbuf += sock->m_framesize; if (sock->m_mmapbuf >= (((uint8_t *)sock->m_mmapped) + sock->m_mmappedlen)) sock->m_mmapbuf = (uint8_t *)sock->m_mmapped; i++; } } else { #endif sockaddr_ll sa; socklen_t salen = sizeof(sa); int len; while ((len = g_mrd->ipktb->recvfrom(sock->fd(), (sockaddr *)&sa, &salen)) > 0) { if (sa.sll_protocol == htons(ETH_P_IPV6) && sa.sll_pkttype != PACKET_OUTGOING) handle_ipv6(sa.sll_ifindex, g_mrd->ipktb->buffer(), len); } #ifndef LINUX_NO_MMAP } #endif }
void handle_ip(const struct ip *ip, int len, void *userdata) { /* note: ip->ip_v does not work if header is not int-aligned */ /* fprintf(stderr, "IPv %d\n", (*(uint8_t *) ip) >> 4); */ switch ((*(uint8_t *) ip) >> 4) { case 4: handle_ipv4(ip, len, userdata); break; case 6: handle_ipv6((struct ip6_hdr *)ip, len, userdata); break; default: break; } }
dns_message * handle_ip(const struct ip * ip, int len) { switch(ip->ip_v) { case 4: return handle_ipv4(ip, len); break; #if USE_IPV6 case 6: return handle_ipv6((struct ip6_hdr *)ip, len); break; #endif default: return NULL; break; } }