ipv6.c File Reference

IPv6 (Internet Protocol Version 6) More...

#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_misc.h"
#include "ipv6/slaac_misc.h"
#include "dhcpv6/dhcpv6_client_misc.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 ipv6SetDefaultHopLimit (NetInterface *interface, uint8_t hopLimit)
 Set default Hop Limit value for outgoing IPv6 packets. 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...
 
Ipv6AddrState ipv6GetLinkLocalAddrState (NetInterface *interface)
 Get the state of the 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...
 
Ipv6AddrState ipv6GetGlobalAddrState (NetInterface *interface, uint_t index)
 Get the state of the specified 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 ipv6ParseAhHeader (NetInterface *interface, const NetBuffer *ipPacket, size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset)
 Parse AH header. More...
 
error_t ipv6ParseEspHeader (NetInterface *interface, const NetBuffer *ipPacket, size_t ipPacketOffset, size_t *headerOffset, size_t *nextHeaderOffset)
 Parse ESP 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, const Ipv6PseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
 Send an IPv6 datagram. More...
 
error_t ipv6SendPacket (NetInterface *interface, const 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-2024 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
2.4.0

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 2376 of file ipv6.c.

◆ ipv6DumpHeader()

void ipv6DumpHeader ( const Ipv6Header ipHeader)

Dump IPv6 header for debugging purpose.

Parameters
[in]ipHeaderIPv6 header

Definition at line 2447 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 548 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 759 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 844 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 392 of file ipv6.c.

◆ ipv6GetGlobalAddrState()

Ipv6AddrState ipv6GetGlobalAddrState ( NetInterface interface,
uint_t  index 
)

Get the state of the specified global address.

Parameters
[in]interfacePointer to the desired network interface
[in]indexZero-based index
Returns
Address state

Definition at line 443 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 285 of file ipv6.c.

◆ ipv6GetLinkLocalAddrState()

Ipv6AddrState ipv6GetLinkLocalAddrState ( NetInterface interface)

Get the state of the link-local address.

Parameters
[in]interfacePointer to the desired network interface
Returns
Address state

Definition at line 326 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 647 of file ipv6.c.

◆ ipv6Init()

error_t ipv6Init ( NetInterface interface)

IPv6 related initialization.

Parameters
[in]interfaceUnderlying network interface
Returns
Error code

Definition at line 95 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 2035 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 2145 of file ipv6.c.

◆ ipv6LinkChangeEvent()

void ipv6LinkChangeEvent ( NetInterface interface)

Callback function for link change event.

Parameters
[in]interfaceUnderlying network interface

Definition at line 876 of file ipv6.c.

◆ ipv6ParseAhHeader()

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

Parse AH 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 1501 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 1367 of file ipv6.c.

◆ ipv6ParseEspHeader()

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

Parse ESP 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 1521 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 1289 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 1541 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 1430 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 968 of file ipv6.c.

◆ ipv6SendDatagram()

error_t ipv6SendDatagram ( NetInterface interface,
const 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 1667 of file ipv6.c.

◆ ipv6SendPacket()

error_t ipv6SendPacket ( NetInterface interface,
const 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 1745 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 470 of file ipv6.c.

◆ ipv6SetDefaultHopLimit()

error_t ipv6SetDefaultHopLimit ( NetInterface interface,
uint8_t  hopLimit 
)

Set default Hop Limit value for outgoing IPv6 packets.

Parameters
[in]interfaceUnderlying network interface
[in]hopLimitDefault Hop Limit value
Returns
Error code

Definition at line 219 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 702 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 810 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 353 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 247 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 583 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 2221 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)
#define IPV6_ADDR(a, b, c, d, e, f, g, h)
Definition: ipv6.h:111

Definition at line 81 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 73 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 77 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 69 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 85 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 65 of file ipv6.c.