ivshmem: Fix unplug of device "ivshmem-plain"
[qemu/armbru.git] / slirp / ip6_input.c
blobac2e3ea882a7b184e3156855a647c4c0c4c60208
1 /*
2 * Copyright (c) 2013
3 * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.
4 */
6 #include "qemu/osdep.h"
7 #include "slirp.h"
8 #include "ip6_icmp.h"
11 * IP initialization: fill in IP protocol switch table.
12 * All protocols not implemented in kernel go to raw IP protocol handler.
14 void ip6_init(Slirp *slirp)
16 icmp6_init(slirp);
19 void ip6_cleanup(Slirp *slirp)
21 icmp6_cleanup(slirp);
24 void ip6_input(struct mbuf *m)
26 struct ip6 *ip6;
27 Slirp *slirp = m->slirp;
29 if (!slirp->in6_enabled) {
30 goto bad;
33 DEBUG_CALL("ip6_input");
34 DEBUG_ARG("m = %lx", (long)m);
35 DEBUG_ARG("m_len = %d", m->m_len);
37 if (m->m_len < sizeof(struct ip6)) {
38 goto bad;
41 ip6 = mtod(m, struct ip6 *);
43 if (ip6->ip_v != IP6VERSION) {
44 goto bad;
47 if (ntohs(ip6->ip_pl) > IF_MTU) {
48 icmp6_send_error(m, ICMP6_TOOBIG, 0);
49 goto bad;
52 /* check ip_ttl for a correct ICMP reply */
53 if (ip6->ip_hl == 0) {
54 icmp6_send_error(m, ICMP6_TIMXCEED, ICMP6_TIMXCEED_INTRANS);
55 goto bad;
59 * Switch out to protocol's input routine.
61 switch (ip6->ip_nh) {
62 case IPPROTO_TCP:
63 NTOHS(ip6->ip_pl);
64 tcp_input(m, sizeof(struct ip6), (struct socket *)NULL, AF_INET6);
65 break;
66 case IPPROTO_UDP:
67 udp6_input(m);
68 break;
69 case IPPROTO_ICMPV6:
70 icmp6_input(m);
71 break;
72 default:
73 m_free(m);
75 return;
76 bad:
77 m_free(m);