Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/SharedDependencies/Sources/libslirp/ip6_input.c
2 views
1
/* SPDX-License-Identifier: BSD-3-Clause */
2
/*
3
* Copyright (c) 2013
4
* Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
5
*/
6
7
#include "slirp.h"
8
#include "ip6_icmp.h"
9
10
/*
11
* IP initialization: fill in IP protocol switch table.
12
* All protocols not implemented in kernel go to raw IP protocol handler.
13
*/
14
void ip6_post_init(Slirp *slirp)
15
{
16
icmp6_post_init(slirp);
17
}
18
19
void ip6_cleanup(Slirp *slirp)
20
{
21
icmp6_cleanup(slirp);
22
}
23
24
void ip6_input(struct mbuf *m)
25
{
26
Slirp *slirp = m->slirp;
27
/* NDP reads the ethernet header for gratuitous NDP */
28
M_DUP_DEBUG(slirp, m, 1, TCPIPHDR_DELTA + 2 + ETH_HLEN);
29
30
struct ip6 *ip6;
31
32
if (!slirp->in6_enabled) {
33
goto bad;
34
}
35
36
DEBUG_CALL("ip6_input");
37
DEBUG_ARG("m = %p", m);
38
DEBUG_ARG("m_len = %d", m->m_len);
39
40
if (m->m_len < sizeof(struct ip6)) {
41
goto bad;
42
}
43
44
ip6 = mtod(m, struct ip6 *);
45
46
if (ip6->ip_v != IP6VERSION) {
47
goto bad;
48
}
49
50
if (ntohs(ip6->ip_pl) + sizeof(struct ip6) > slirp->if_mtu) {
51
icmp6_send_error(m, ICMP6_TOOBIG, 0);
52
goto bad;
53
}
54
55
// Check if the message size is big enough to hold what's
56
// set in the payload length header. If not this is an invalid
57
// packet
58
if (m->m_len < ntohs(ip6->ip_pl) + sizeof(struct ip6)) {
59
goto bad;
60
}
61
62
/* check ip_ttl for a correct ICMP reply */
63
if (ip6->ip_hl == 0) {
64
icmp6_send_error(m, ICMP6_TIMXCEED, ICMP6_TIMXCEED_INTRANS);
65
goto bad;
66
}
67
68
/*
69
* Switch out to protocol's input routine.
70
*/
71
switch (ip6->ip_nh) {
72
case IPPROTO_TCP:
73
NTOHS(ip6->ip_pl);
74
tcp_input(m, sizeof(struct ip6), (struct socket *)NULL, AF_INET6);
75
break;
76
case IPPROTO_UDP:
77
udp6_input(m);
78
break;
79
case IPPROTO_ICMPV6:
80
icmp6_input(m);
81
break;
82
default:
83
m_free(m);
84
}
85
return;
86
bad:
87
m_free(m);
88
}
89
90