ipv6.c File Reference

IPv6 (Internet Protocol Version 6) More...

#include <string.h>
#include <ctype.h>
#include "core/net.h"
#include "core/ip.h"
#include "core/udp.h"
#include "core/tcp_fsm.h"
#include "core/raw_socket.h"
#include "ipv6/ipv6.h"
#include "ipv6/ipv6_frag.h"
#include "ipv6/ipv6_misc.h"
#include "ipv6/ipv6_pmtu.h"
#include "ipv6/ipv6_routing.h"
#include "ipv6/icmpv6.h"
#include "ipv6/mld.h"
#include "ipv6/ndp.h"
#include "ipv6/ndp_cache.h"
#include "ipv6/ndp_misc.h"
#include "ipv6/ndp_router_adv.h"
#include "ipv6/slaac.h"
#include "dhcpv6/dhcpv6_client.h"
#include "mibs/ip_mib_module.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   IPV6_TRACE_LEVEL
 

Functions

error_t ipv6Init (NetInterface *interface)
 IPv6 related initialization. More...
 
error_t ipv6SetMtu (NetInterface *interface, size_t mtu)
 Change the MTU of a network interface. More...
 
error_t ipv6GetMtu (NetInterface *interface, size_t *mtu)
 Retrieve the MTU for the specified interface. More...
 
error_t ipv6SetLinkLocalAddr (NetInterface *interface, const Ipv6Addr *addr)
 Assign link-local address. More...
 
error_t ipv6GetLinkLocalAddr (NetInterface *interface, Ipv6Addr *addr)
 Retrieve link-local address. More...
 
error_t ipv6SetGlobalAddr (NetInterface *interface, uint_t index, const Ipv6Addr *addr)
 Assign global address. More...
 
error_t ipv6GetGlobalAddr (NetInterface *interface, uint_t index, Ipv6Addr *addr)
 Retrieve global address. More...
 
error_t ipv6SetAnycastAddr (NetInterface *interface, uint_t index, const Ipv6Addr *addr)
 Assign anycast address. More...
 
error_t ipv6GetAnycastAddr (NetInterface *interface, uint_t index, Ipv6Addr *addr)
 Retrieve anycast address. More...
 
error_t ipv6SetPrefix (NetInterface *interface, uint_t index, const Ipv6Addr *prefix, uint_t length)
 Configure IPv6 prefix. More...
 
error_t ipv6GetPrefix (NetInterface *interface, uint_t index, Ipv6Addr *prefix, uint_t *length)
 Retrieve IPv6 prefix. More...
 
error_t ipv6SetDefaultRouter (NetInterface *interface, uint_t index, const Ipv6Addr *addr)
 Configure default router. More...
 
error_t ipv6GetDefaultRouter (NetInterface *interface, uint_t index, Ipv6Addr *addr)
 Retrieve default router. More...
 
error_t ipv6SetDnsServer (NetInterface *interface, uint_t index, const Ipv6Addr *addr)
 Configure DNS server. More...
 
error_t ipv6GetDnsServer (NetInterface *interface, uint_t index, Ipv6Addr *addr)
 Retrieve DNS server. More...
 
void ipv6LinkChangeEvent (NetInterface *interface)
 Callback function for link change event. More...
 
void ipv6ProcessPacket (NetInterface *interface, NetBuffer *ipPacket, size_t ipPacketOffset, NetRxAncillary *ancillary)
 Incoming IPv6 packet processing. More...
 
error_t ipv6ParseHopByHopOptHeader (NetInterface *interface, const NetBuffer *ipPacket, size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset)
 Parse Hop-by-Hop Options header. More...
 
error_t ipv6ParseDestOptHeader (NetInterface *interface, const NetBuffer *ipPacket, size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset)
 Parse Destination Options header. More...
 
error_t ipv6ParseRoutingHeader (NetInterface *interface, const NetBuffer *ipPacket, size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset)
 Parse Routing header. More...
 
error_t ipv6ParseAuthHeader (NetInterface *interface, const NetBuffer *ipPacket, size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset)
 Parse Authentication header. More...
 
error_t ipv6ParseEspHeader (NetInterface *interface, const NetBuffer *ipPacket, size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset)
 Parse Encapsulating Security Payload header. More...
 
error_t ipv6ParseOptions (NetInterface *interface, const NetBuffer *ipPacket, size_t ipPacketOffset, size_t optionOffset, size_t optionLen)
 Parse IPv6 options. More...
 
error_t ipv6SendDatagram (NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
 Send an IPv6 datagram. More...
 
error_t ipv6SendPacket (NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, uint32_t fragId, size_t fragOffset, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
 Send an IPv6 packet. More...
 
error_t ipv6JoinMulticastGroup (NetInterface *interface, const Ipv6Addr *groupAddr)
 Join an IPv6 multicast group. More...
 
error_t ipv6LeaveMulticastGroup (NetInterface *interface, const Ipv6Addr *groupAddr)
 Leave an IPv6 multicast group. More...
 
error_t ipv6StringToAddr (const char_t *str, Ipv6Addr *ipAddr)
 Convert a string representation of an IPv6 address to a binary IPv6 address. More...
 
char_tipv6AddrToString (const Ipv6Addr *ipAddr, char_t *str)
 Convert a binary IPv6 address to a string representation. More...
 
void ipv6DumpHeader (const Ipv6Header *ipHeader)
 Dump IPv6 header for debugging purpose. More...
 

Variables

const Ipv6Addr IPV6_UNSPECIFIED_ADDR
 
const Ipv6Addr IPV6_LOOPBACK_ADDR
 
const Ipv6Addr IPV6_LINK_LOCAL_ALL_NODES_ADDR
 
const Ipv6Addr IPV6_LINK_LOCAL_ALL_ROUTERS_ADDR
 
const Ipv6Addr IPV6_LINK_LOCAL_ADDR_PREFIX
 
const Ipv6Addr IPV6_SOLICITED_NODE_ADDR_PREFIX
 

Detailed Description

IPv6 (Internet Protocol Version 6)

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2020 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Description

IP version 6 (IPv6) is a new version of the Internet Protocol, designed as the successor to IP version 4 (IPv4). Refer to RFC 2460

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.8

Definition in file ipv6.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   IPV6_TRACE_LEVEL

Definition at line 37 of file ipv6.c.

Function Documentation

◆ ipv6AddrToString()

char_t* ipv6AddrToString ( const Ipv6Addr ipAddr,
char_t str 
)

Convert a binary IPv6 address to a string representation.

Call ipv6AddrToString() to convert an IPv6 address to a text representation. The implementation of ipv6AddrToString() function follows RFC 5952 recommendations

Parameters
[in]ipAddrBinary representation of the IPv6 address
[out]strNULL-terminated string representing the IPv6 address
Returns
Pointer to the formatted string

Definition at line 2281 of file ipv6.c.

◆ ipv6DumpHeader()

void ipv6DumpHeader ( const Ipv6Header ipHeader)

Dump IPv6 header for debugging purpose.

Parameters
[in]ipHeaderIPv6 header

Definition at line 2350 of file ipv6.c.

◆ ipv6GetAnycastAddr()

error_t ipv6GetAnycastAddr ( NetInterface interface,
uint_t  index,
Ipv6Addr addr 
)

Retrieve anycast address.

Parameters
[in]interfacePointer to the desired network interface
[in]indexZero-based index
[out]addrAnycast address
Returns
Error code

Definition at line 469 of file ipv6.c.

◆ ipv6GetDefaultRouter()

error_t ipv6GetDefaultRouter ( NetInterface interface,
uint_t  index,
Ipv6Addr addr 
)

Retrieve default router.

Parameters
[in]interfacePointer to the desired network interface
[in]indexZero-based index
[out]addrDefault router address
Returns
Error code

Definition at line 680 of file ipv6.c.

◆ ipv6GetDnsServer()

error_t ipv6GetDnsServer ( NetInterface interface,
uint_t  index,
Ipv6Addr addr 
)

Retrieve DNS server.

Parameters
[in]interfacePointer to the desired network interface
[in]indexThis parameter selects between the primary and secondary DNS server
[out]addrDNS server address
Returns
Error code

Definition at line 765 of file ipv6.c.

◆ ipv6GetGlobalAddr()

error_t ipv6GetGlobalAddr ( NetInterface interface,
uint_t  index,
Ipv6Addr addr 
)

Retrieve global address.

Parameters
[in]interfacePointer to the desired network interface
[in]indexZero-based index
[out]addrGlobal address
Returns
Error code

Definition at line 339 of file ipv6.c.

◆ ipv6GetLinkLocalAddr()

error_t ipv6GetLinkLocalAddr ( NetInterface interface,
Ipv6Addr addr 
)

Retrieve link-local address.

Parameters
[in]interfacePointer to the desired network interface
[out]addrlink-local address
Returns
Error code

Definition at line 257 of file ipv6.c.

◆ ipv6GetMtu()

error_t ipv6GetMtu ( NetInterface interface,
size_t *  mtu 
)

Retrieve the MTU for the specified interface.

Parameters
[in]interfacePointer to the desired network interface
[out]mtuMaximum transmit unit
Returns
Error code

Definition at line 194 of file ipv6.c.

◆ ipv6GetPrefix()

error_t ipv6GetPrefix ( NetInterface interface,
uint_t  index,
Ipv6Addr prefix,
uint_t length 
)

Retrieve IPv6 prefix.

Parameters
[in]interfacePointer to the desired network interface
[in]indexZero-based index
[out]prefixIPv6 prefix
[out]lengthThe number of leading bits in the prefix that are valid
Returns
Error code

Definition at line 568 of file ipv6.c.

◆ ipv6Init()

error_t ipv6Init ( NetInterface interface)

IPv6 related initialization.

Parameters
[in]interfaceUnderlying network interface
Returns
Error code

Definition at line 97 of file ipv6.c.

◆ ipv6JoinMulticastGroup()

error_t ipv6JoinMulticastGroup ( NetInterface interface,
const Ipv6Addr groupAddr 
)

Join an IPv6 multicast group.

Parameters
[in]interfaceUnderlying network interface
[in]groupAddrIPv6 Multicast address to join
Returns
Error code

Definition at line 1949 of file ipv6.c.

◆ ipv6LeaveMulticastGroup()

error_t ipv6LeaveMulticastGroup ( NetInterface interface,
const Ipv6Addr groupAddr 
)

Leave an IPv6 multicast group.

Parameters
[in]interfaceUnderlying network interface
[in]groupAddrIPv6 multicast address to drop
Returns
Error code

Definition at line 2059 of file ipv6.c.

◆ ipv6LinkChangeEvent()

void ipv6LinkChangeEvent ( NetInterface interface)

Callback function for link change event.

Parameters
[in]interfaceUnderlying network interface

Definition at line 797 of file ipv6.c.

◆ ipv6ParseAuthHeader()

error_t ipv6ParseAuthHeader ( NetInterface interface,
const NetBuffer ipPacket,
size_t  ipPacketOffset,
size_t *  headerOffset,
size_t *  nextHeaderOffset 
)

Parse Authentication header.

Parameters
[in]interfaceUnderlying network interface
[in]ipPacketMulti-part buffer containing the IPv6 packet
[in]ipPacketOffsetOffset to the first byte of the IPv6 packet
[in,out]headerOffsetOffset to the Authentication header
[in,out]nextHeaderOffsetOffset to the Next Header field

Error code

Definition at line 1418 of file ipv6.c.

◆ ipv6ParseDestOptHeader()

error_t ipv6ParseDestOptHeader ( NetInterface interface,
const NetBuffer ipPacket,
size_t  ipPacketOffset,
size_t *  headerOffset,
size_t *  nextHeaderOffset 
)

Parse Destination Options header.

Parameters
[in]interfaceUnderlying network interface
[in]ipPacketMulti-part buffer containing the IPv6 packet
[in]ipPacketOffsetOffset to the first byte of the IPv6 packet
[in,out]headerOffsetOffset to the Destination Options header
[in,out]nextHeaderOffsetOffset to the Next Header field

Error code

Definition at line 1284 of file ipv6.c.

◆ ipv6ParseEspHeader()

error_t ipv6ParseEspHeader ( NetInterface interface,
const NetBuffer ipPacket,
size_t  ipPacketOffset,
size_t *  headerOffset,
size_t *  nextHeaderOffset 
)

Parse Encapsulating Security Payload header.

Parameters
[in]interfaceUnderlying network interface
[in]ipPacketMulti-part buffer containing the IPv6 packet
[in]ipPacketOffsetOffset to the first byte of the IPv6 packet
[in,out]headerOffsetOffset to the Encapsulating Security Payload header
[in,out]nextHeaderOffsetOffset to the Next Header field

Error code

Definition at line 1438 of file ipv6.c.

◆ ipv6ParseHopByHopOptHeader()

error_t ipv6ParseHopByHopOptHeader ( NetInterface interface,
const NetBuffer ipPacket,
size_t  ipPacketOffset,
size_t *  headerOffset,
size_t *  nextHeaderOffset 
)

Parse Hop-by-Hop Options header.

Parameters
[in]interfaceUnderlying network interface
[in]ipPacketMulti-part buffer containing the IPv6 packet
[in]ipPacketOffsetOffset to the first byte of the IPv6 packet
[in,out]headerOffsetOffset to the Hop-by-Hop Options header
[in,out]nextHeaderOffsetOffset to the Next Header field

Error code

Definition at line 1206 of file ipv6.c.

◆ ipv6ParseOptions()

error_t ipv6ParseOptions ( NetInterface interface,
const NetBuffer ipPacket,
size_t  ipPacketOffset,
size_t  optionOffset,
size_t  optionLen 
)

Parse IPv6 options.

Parameters
[in]interfaceUnderlying network interface
[in]ipPacketMulti-part buffer containing the IPv6 packet
[in]ipPacketOffsetOffset to the first byte of the IPv6 packet
[in]optionOffsetOffset to the first byte of the Options field
[in]optionLenLength of the Options field

Error code

Definition at line 1458 of file ipv6.c.

◆ ipv6ParseRoutingHeader()

error_t ipv6ParseRoutingHeader ( NetInterface interface,
const NetBuffer ipPacket,
size_t  ipPacketOffset,
size_t *  headerOffset,
size_t *  nextHeaderOffset 
)

Parse Routing header.

Parameters
[in]interfaceUnderlying network interface
[in]ipPacketMulti-part buffer containing the IPv6 packet
[in]ipPacketOffsetOffset to the first byte of the IPv6 packet
[in,out]headerOffsetOffset to the Routing header
[in,out]nextHeaderOffsetOffset to the Next Header field

Error code

Definition at line 1347 of file ipv6.c.

◆ ipv6ProcessPacket()

void ipv6ProcessPacket ( NetInterface interface,
NetBuffer ipPacket,
size_t  ipPacketOffset,
NetRxAncillary ancillary 
)

Incoming IPv6 packet processing.

Parameters
[in]interfaceUnderlying network interface
[in]ipPacketMulti-part buffer that holds the incoming IPv6 packet
[in]ipPacketOffsetOffset to the first byte of the IPv6 packet
[in]ancillaryAdditional options passed to the stack along with the packet

Definition at line 889 of file ipv6.c.

◆ ipv6SendDatagram()

error_t ipv6SendDatagram ( NetInterface interface,
Ipv6PseudoHeader pseudoHeader,
NetBuffer buffer,
size_t  offset,
NetTxAncillary ancillary 
)

Send an IPv6 datagram.

Parameters
[in]interfaceUnderlying network interface
[in]pseudoHeaderIPv6 pseudo header
[in]bufferMulti-part buffer containing the payload
[in]offsetOffset to the first byte of the payload
[in]ancillaryAdditional options passed to the stack along with the packet
Returns
Error code

Definition at line 1584 of file ipv6.c.

◆ ipv6SendPacket()

error_t ipv6SendPacket ( NetInterface interface,
Ipv6PseudoHeader pseudoHeader,
uint32_t  fragId,
size_t  fragOffset,
NetBuffer buffer,
size_t  offset,
NetTxAncillary ancillary 
)

Send an IPv6 packet.

Parameters
[in]interfaceUnderlying network interface
[in]pseudoHeaderIPv6 pseudo header
[in]fragIdFragment identification field
[in]fragOffsetFragment offset field
[in]bufferMulti-part buffer containing the payload
[in]offsetOffset to the first byte of the payload
[in]ancillaryAdditional options passed to the stack along with the packet
Returns
Error code

Definition at line 1653 of file ipv6.c.

◆ ipv6SetAnycastAddr()

error_t ipv6SetAnycastAddr ( NetInterface interface,
uint_t  index,
const Ipv6Addr addr 
)

Assign anycast address.

Parameters
[in]interfacePointer to the desired network interface
[in]indexZero-based index
[in]addrAnycast address
Returns
Error code

Definition at line 391 of file ipv6.c.

◆ ipv6SetDefaultRouter()

error_t ipv6SetDefaultRouter ( NetInterface interface,
uint_t  index,
const Ipv6Addr addr 
)

Configure default router.

Parameters
[in]interfacePointer to the desired network interface
[in]indexZero-based index
[in]addrDefault router address
Returns
Error code

Definition at line 623 of file ipv6.c.

◆ ipv6SetDnsServer()

error_t ipv6SetDnsServer ( NetInterface interface,
uint_t  index,
const Ipv6Addr addr 
)

Configure DNS server.

Parameters
[in]interfacePointer to the desired network interface
[in]indexThis parameter selects between the primary and secondary DNS server
[in]addrDNS server address
Returns
Error code

Definition at line 731 of file ipv6.c.

◆ ipv6SetGlobalAddr()

error_t ipv6SetGlobalAddr ( NetInterface interface,
uint_t  index,
const Ipv6Addr addr 
)

Assign global address.

Parameters
[in]interfacePointer to the desired network interface
[in]indexZero-based index
[in]addrGlobal address
Returns
Error code

Definition at line 300 of file ipv6.c.

◆ ipv6SetLinkLocalAddr()

error_t ipv6SetLinkLocalAddr ( NetInterface interface,
const Ipv6Addr addr 
)

Assign link-local address.

Parameters
[in]interfacePointer to the desired network interface
[in]addrLink-local address
Returns
Error code

Definition at line 219 of file ipv6.c.

◆ ipv6SetMtu()

error_t ipv6SetMtu ( NetInterface interface,
size_t  mtu 
)

Change the MTU of a network interface.

Parameters
[in]interfacePointer to the desired network interface
[in]mtuMaximum transmit unit
Returns
Error code

Definition at line 149 of file ipv6.c.

◆ ipv6SetPrefix()

error_t ipv6SetPrefix ( NetInterface interface,
uint_t  index,
const Ipv6Addr prefix,
uint_t  length 
)

Configure IPv6 prefix.

Parameters
[in]interfacePointer to the desired network interface
[in]indexZero-based index
[in]prefixIPv6 prefix
[in]lengthThe number of leading bits in the prefix that are valid

Definition at line 504 of file ipv6.c.

◆ ipv6StringToAddr()

error_t ipv6StringToAddr ( const char_t str,
Ipv6Addr ipAddr 
)

Convert a string representation of an IPv6 address to a binary IPv6 address.

Parameters
[in]strNULL-terminated string representing the IPv6 address
[out]ipAddrBinary representation of the IPv6 address
Returns
Error code

Definition at line 2135 of file ipv6.c.

Variable Documentation

◆ IPV6_LINK_LOCAL_ADDR_PREFIX

const Ipv6Addr IPV6_LINK_LOCAL_ADDR_PREFIX
Initial value:
=
IPV6_ADDR(0xFE80, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000)

Definition at line 83 of file ipv6.c.

◆ IPV6_LINK_LOCAL_ALL_NODES_ADDR

const Ipv6Addr IPV6_LINK_LOCAL_ALL_NODES_ADDR
Initial value:
=
IPV6_ADDR(0xFF02, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001)

Definition at line 75 of file ipv6.c.

◆ IPV6_LINK_LOCAL_ALL_ROUTERS_ADDR

const Ipv6Addr IPV6_LINK_LOCAL_ALL_ROUTERS_ADDR
Initial value:
=
IPV6_ADDR(0xFF02, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002)

Definition at line 79 of file ipv6.c.

◆ IPV6_LOOPBACK_ADDR

const Ipv6Addr IPV6_LOOPBACK_ADDR
Initial value:
=
IPV6_ADDR(0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001)

Definition at line 71 of file ipv6.c.

◆ IPV6_SOLICITED_NODE_ADDR_PREFIX

const Ipv6Addr IPV6_SOLICITED_NODE_ADDR_PREFIX
Initial value:
=
IPV6_ADDR(0xFF02, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0xFF00, 0x0000)

Definition at line 87 of file ipv6.c.

◆ IPV6_UNSPECIFIED_ADDR

const Ipv6Addr IPV6_UNSPECIFIED_ADDR
Initial value:
=
IPV6_ADDR(0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000)

Definition at line 67 of file ipv6.c.

#define IPV6_ADDR(a, b, c, d, e, f, g, h)
Definition: ipv6.h:112