Path: blob/a-new-beginning/SharedDependencies/Sources/libslirp/ip6_input.c
2 views
/* SPDX-License-Identifier: BSD-3-Clause */1/*2* Copyright (c) 20133* Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.4*/56#include "slirp.h"7#include "ip6_icmp.h"89/*10* IP initialization: fill in IP protocol switch table.11* All protocols not implemented in kernel go to raw IP protocol handler.12*/13void ip6_post_init(Slirp *slirp)14{15icmp6_post_init(slirp);16}1718void ip6_cleanup(Slirp *slirp)19{20icmp6_cleanup(slirp);21}2223void ip6_input(struct mbuf *m)24{25Slirp *slirp = m->slirp;26/* NDP reads the ethernet header for gratuitous NDP */27M_DUP_DEBUG(slirp, m, 1, TCPIPHDR_DELTA + 2 + ETH_HLEN);2829struct ip6 *ip6;3031if (!slirp->in6_enabled) {32goto bad;33}3435DEBUG_CALL("ip6_input");36DEBUG_ARG("m = %p", m);37DEBUG_ARG("m_len = %d", m->m_len);3839if (m->m_len < sizeof(struct ip6)) {40goto bad;41}4243ip6 = mtod(m, struct ip6 *);4445if (ip6->ip_v != IP6VERSION) {46goto bad;47}4849if (ntohs(ip6->ip_pl) + sizeof(struct ip6) > slirp->if_mtu) {50icmp6_send_error(m, ICMP6_TOOBIG, 0);51goto bad;52}5354// Check if the message size is big enough to hold what's55// set in the payload length header. If not this is an invalid56// packet57if (m->m_len < ntohs(ip6->ip_pl) + sizeof(struct ip6)) {58goto bad;59}6061/* check ip_ttl for a correct ICMP reply */62if (ip6->ip_hl == 0) {63icmp6_send_error(m, ICMP6_TIMXCEED, ICMP6_TIMXCEED_INTRANS);64goto bad;65}6667/*68* Switch out to protocol's input routine.69*/70switch (ip6->ip_nh) {71case IPPROTO_TCP:72NTOHS(ip6->ip_pl);73tcp_input(m, sizeof(struct ip6), (struct socket *)NULL, AF_INET6);74break;75case IPPROTO_UDP:76udp6_input(m);77break;78case IPPROTO_ICMPV6:79icmp6_input(m);80break;81default:82m_free(m);83}84return;85bad:86m_free(m);87}888990