]>
Commit | Line | Data |
---|---|---|
0d6ff71a GS |
1 | /* |
2 | * Copyright (c) 2013 | |
3 | * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. | |
4 | */ | |
5 | ||
0d6ff71a GS |
6 | #include "slirp.h" |
7 | #include "ip6_icmp.h" | |
8 | ||
9 | /* | |
10 | * IP initialization: fill in IP protocol switch table. | |
11 | * All protocols not implemented in kernel go to raw IP protocol handler. | |
12 | */ | |
13 | void ip6_init(Slirp *slirp) | |
14 | { | |
15 | icmp6_init(slirp); | |
16 | } | |
17 | ||
18 | void ip6_cleanup(Slirp *slirp) | |
19 | { | |
20 | icmp6_cleanup(slirp); | |
21 | } | |
22 | ||
23 | void ip6_input(struct mbuf *m) | |
24 | { | |
25 | struct ip6 *ip6; | |
0b11c036 ST |
26 | Slirp *slirp = m->slirp; |
27 | ||
28 | if (!slirp->in6_enabled) { | |
29 | goto bad; | |
30 | } | |
0d6ff71a GS |
31 | |
32 | DEBUG_CALL("ip6_input"); | |
3402618c | 33 | DEBUG_ARG("m = %p", m); |
0d6ff71a GS |
34 | DEBUG_ARG("m_len = %d", m->m_len); |
35 | ||
36 | if (m->m_len < sizeof(struct ip6)) { | |
37 | goto bad; | |
38 | } | |
39 | ||
40 | ip6 = mtod(m, struct ip6 *); | |
41 | ||
42 | if (ip6->ip_v != IP6VERSION) { | |
43 | goto bad; | |
44 | } | |
45 | ||
fc6c9257 YB |
46 | if (ntohs(ip6->ip_pl) > IF_MTU) { |
47 | icmp6_send_error(m, ICMP6_TOOBIG, 0); | |
48 | goto bad; | |
49 | } | |
50 | ||
0d6ff71a GS |
51 | /* check ip_ttl for a correct ICMP reply */ |
52 | if (ip6->ip_hl == 0) { | |
fc6c9257 | 53 | icmp6_send_error(m, ICMP6_TIMXCEED, ICMP6_TIMXCEED_INTRANS); |
0d6ff71a GS |
54 | goto bad; |
55 | } | |
56 | ||
57 | /* | |
58 | * Switch out to protocol's input routine. | |
59 | */ | |
60 | switch (ip6->ip_nh) { | |
61 | case IPPROTO_TCP: | |
3feea444 GS |
62 | NTOHS(ip6->ip_pl); |
63 | tcp_input(m, sizeof(struct ip6), (struct socket *)NULL, AF_INET6); | |
0d6ff71a GS |
64 | break; |
65 | case IPPROTO_UDP: | |
15d62af4 | 66 | udp6_input(m); |
0d6ff71a GS |
67 | break; |
68 | case IPPROTO_ICMPV6: | |
69 | icmp6_input(m); | |
70 | break; | |
71 | default: | |
72 | m_free(m); | |
73 | } | |
74 | return; | |
75 | bad: | |
76 | m_free(m); | |
77 | } |