The Pedigree Project 0.1
ethip6.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
26/*
27 * Copyright (c) 2010 Inico Technologies Ltd.
28 * All rights reserved.
29 *
30 * Redistribution and use in source and binary forms, with or without modification,
31 * are permitted provided that the following conditions are met:
32 *
33 * 1. Redistributions of source code must retain the above copyright notice,
34 * this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright notice,
36 * this list of conditions and the following disclaimer in the documentation
37 * and/or other materials provided with the distribution.
38 * 3. The name of the author may not be used to endorse or promote products
39 * derived from this software without specific prior written permission.
40 *
41 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
42 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
43 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
44 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
46 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
49 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
50 * OF SUCH DAMAGE.
51 *
52 * This file is part of the lwIP TCP/IP stack.
53 *
54 * Author: Ivan Delamer <delamer@inicotech.com>
55 *
56 *
57 * Please coordinate changes and requests with Ivan Delamer
58 * <delamer@inicotech.com>
59 */
60
61#include "lwip/opt.h"
62
63#if LWIP_IPV6 && LWIP_ETHERNET
64
65#include "lwip/ethip6.h"
66#include "lwip/nd6.h"
67#include "lwip/pbuf.h"
68#include "lwip/ip6.h"
69#include "lwip/ip6_addr.h"
70#include "lwip/inet_chksum.h"
71#include "lwip/netif.h"
72#include "lwip/icmp6.h"
73#include "lwip/prot/ethernet.h"
74#include "netif/ethernet.h"
75
76#include <string.h>
77
98ethip6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr)
99{
100 struct eth_addr dest;
101 const u8_t *hwaddr;
102 err_t result;
103
104 /* multicast destination IP address? */
105 if (ip6_addr_ismulticast(ip6addr)) {
106 /* Hash IP multicast address to MAC address.*/
107 dest.addr[0] = 0x33;
108 dest.addr[1] = 0x33;
109 dest.addr[2] = ((const u8_t *)(&(ip6addr->addr[3])))[0];
110 dest.addr[3] = ((const u8_t *)(&(ip6addr->addr[3])))[1];
111 dest.addr[4] = ((const u8_t *)(&(ip6addr->addr[3])))[2];
112 dest.addr[5] = ((const u8_t *)(&(ip6addr->addr[3])))[3];
113
114 /* Send out. */
115 return ethernet_output(netif, q, (const struct eth_addr*)(netif->hwaddr), &dest, ETHTYPE_IPV6);
116 }
117
118 /* We have a unicast destination IP address */
119 /* @todo anycast? */
120
121 /* Ask ND6 what to do with the packet. */
122 result = nd6_get_next_hop_addr_or_queue(netif, q, ip6addr, &hwaddr);
123 if (result != ERR_OK) {
124 return result;
125 }
126
127 /* If no hardware address is returned, nd6 has queued the packet for later. */
128 if (hwaddr == NULL) {
129 return ERR_OK;
130 }
131
132 /* Send out the packet using the returned hardware address. */
133 SMEMCPY(dest.addr, hwaddr, 6);
134 return ethernet_output(netif, q, (const struct eth_addr*)(netif->hwaddr), &dest, ETHTYPE_IPV6);
135}
136
137#endif /* LWIP_IPV6 && LWIP_ETHERNET */
@ ETHTYPE_IPV6
s8_t err_t
Definition err.h:76
@ ERR_OK
Definition err.h:82
Definition netif.h:244
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
Definition netif.h:322
Definition pbuf.h:161