]> git.proxmox.com Git - mirror_qemu.git/blob - slirp/ip6_input.c
usb: rearrange usb_ep_get()
[mirror_qemu.git] / slirp / ip6_input.c
1 /*
2 * Copyright (c) 2013
3 * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
4 */
5
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;
26 Slirp *slirp = m->slirp;
27
28 if (!slirp->in6_enabled) {
29 goto bad;
30 }
31
32 DEBUG_CALL("ip6_input");
33 DEBUG_ARG("m = %p", m);
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
46 if (ntohs(ip6->ip_pl) > IF_MTU) {
47 icmp6_send_error(m, ICMP6_TOOBIG, 0);
48 goto bad;
49 }
50
51 /* check ip_ttl for a correct ICMP reply */
52 if (ip6->ip_hl == 0) {
53 icmp6_send_error(m, ICMP6_TIMXCEED, ICMP6_TIMXCEED_INTRANS);
54 goto bad;
55 }
56
57 /*
58 * Switch out to protocol's input routine.
59 */
60 switch (ip6->ip_nh) {
61 case IPPROTO_TCP:
62 NTOHS(ip6->ip_pl);
63 tcp_input(m, sizeof(struct ip6), (struct socket *)NULL, AF_INET6);
64 break;
65 case IPPROTO_UDP:
66 udp6_input(m);
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 }