ipv6_misc.c File Reference

Helper functions for IPv6. More...

#include "core/net.h"
#include "ipv6/ipv6.h"
#include "ipv6/ipv6_misc.h"
#include "ipv6/ndp.h"
#include "ipv6/ndp_cache.h"
#include "mdns/mdns_responder.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

Ipv6AddrState ipv6GetAddrState (NetInterface *interface, const Ipv6Addr *addr)
 Get the state of the specified IPv6 address. More...
 
error_t ipv6SetAddr (NetInterface *interface, uint_t index, const Ipv6Addr *addr, Ipv6AddrState state, systime_t validLifetime, systime_t preferredLifetime, bool_t permanent)
 Set IPv6 address and address state. More...
 
void ipv6AddAddr (NetInterface *interface, const Ipv6Addr *addr, uint32_t validLifetime, uint32_t preferredLifetime)
 Add a new entry to the list of IPv6 addresses. More...
 
void ipv6RemoveAddr (NetInterface *interface, const Ipv6Addr *addr)
 Remove an entry from the list of IPv6 addresses. More...
 
void ipv6AddPrefix (NetInterface *interface, const Ipv6Addr *prefix, uint_t length, bool_t onLinkFlag, bool_t autonomousFlag, uint32_t validLifetime, uint32_t preferredLifetime)
 Add a new entry to the Prefix List. More...
 
void ipv6RemovePrefix (NetInterface *interface, const Ipv6Addr *prefix, uint_t length)
 Remove an entry from the Prefix List. More...
 
void ipv6AddDefaultRouter (NetInterface *interface, const Ipv6Addr *addr, uint16_t lifetime, uint8_t preference)
 Add a new entry to the Default Router List. More...
 
void ipv6RemoveDefaultRouter (NetInterface *interface, const Ipv6Addr *addr)
 Remove an entry from the Default Router List. More...
 
void ipv6FlushAddrList (NetInterface *interface)
 Flush the list of IPv6 addresses. More...
 
void ipv6FlushPrefixList (NetInterface *interface)
 Flush the Prefix List. More...
 
void ipv6FlushDefaultRouterList (NetInterface *interface)
 Flush the Default Router List. More...
 
void ipv6FlushDnsServerList (NetInterface *interface)
 Flush the list of DNS servers. More...
 
error_t ipv6CheckSourceAddr (NetInterface *interface, const Ipv6Addr *ipAddr)
 Source IPv6 address filtering. More...
 
error_t ipv6CheckDestAddr (NetInterface *interface, const Ipv6Addr *ipAddr)
 Destination IPv6 address filtering. More...
 
error_t ipv6SelectSourceAddr (NetInterface **interface, const Ipv6Addr *destAddr, Ipv6Addr *srcAddr)
 IPv6 source address selection. More...
 
bool_t ipv6IsOnLink (NetInterface *interface, const Ipv6Addr *ipAddr)
 Check whether an IPv6 address is on-link. More...
 
bool_t ipv6IsAnycastAddr (NetInterface *interface, const Ipv6Addr *ipAddr)
 Check whether an IPv6 address is an anycast address. More...
 
bool_t ipv6IsTentativeAddr (NetInterface *interface, const Ipv6Addr *ipAddr)
 Check whether an IPv6 address is a tentative address. More...
 
bool_t ipv6IsLocalHostAddr (const Ipv6Addr *ipAddr)
 Check whether the specified IPv6 is assigned to the host. More...
 
bool_t ipv6CompPrefix (const Ipv6Addr *ipAddr1, const Ipv6Addr *ipAddr2, size_t length)
 Compare IPv6 address prefixes. More...
 
uint_t ipv6GetAddrScope (const Ipv6Addr *ipAddr)
 Retrieve the scope of an IPv6 address. More...
 
uint_t ipv6GetMulticastAddrScope (const Ipv6Addr *ipAddr)
 Retrieve the scope of an IPv6 multicast address. More...
 
uint_t ipv6GetCommonPrefixLength (const Ipv6Addr *ipAddr1, const Ipv6Addr *ipAddr2)
 Compute the length of the longest common prefix. More...
 
error_t ipv6ComputeSolicitedNodeAddr (const Ipv6Addr *ipAddr, Ipv6Addr *solicitedNodeAddr)
 Form a solicited-node address from an IPv6 address. More...
 
error_t ipv6MapMulticastAddrToMac (const Ipv6Addr *ipAddr, MacAddr *macAddr)
 Map an IPv6 multicast address to a MAC-layer multicast address. More...
 
void ipv6GenerateLinkLocalAddr (const Eui64 *interfaceId, Ipv6Addr *ipAddr)
 Generate a IPv6 link-local address from an interface identifier. More...
 
void ipv6UpdateInStats (NetInterface *interface, const Ipv6Addr *destIpAddr, size_t length)
 Update IPv6 input statistics. More...
 
void ipv6UpdateOutStats (NetInterface *interface, const Ipv6Addr *destIpAddr, size_t length)
 Update IPv6 output statistics. More...
 

Detailed Description

Helper functions for IPv6.

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.

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

Definition in file ipv6_misc.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   IPV6_TRACE_LEVEL

Definition at line 32 of file ipv6_misc.c.

Function Documentation

◆ ipv6AddAddr()

void ipv6AddAddr ( NetInterface interface,
const Ipv6Addr addr,
uint32_t  validLifetime,
uint32_t  preferredLifetime 
)

Add a new entry to the list of IPv6 addresses.

Parameters
[in]interfaceUnderlying network interface
[in]addrIPv6 address
[in]validLifetimeValid lifetime, in seconds
[in]preferredLifetimePreferred lifetime, in seconds

Definition at line 220 of file ipv6_misc.c.

◆ ipv6AddDefaultRouter()

void ipv6AddDefaultRouter ( NetInterface interface,
const Ipv6Addr addr,
uint16_t  lifetime,
uint8_t  preference 
)

Add a new entry to the Default Router List.

Parameters
[in]interfaceUnderlying network interface
[in]addrIPv6 address of the router
[in]lifetimeRouter lifetime, in seconds
[in]preferencePreference value

Definition at line 537 of file ipv6_misc.c.

◆ ipv6AddPrefix()

void ipv6AddPrefix ( NetInterface interface,
const Ipv6Addr prefix,
uint_t  length,
bool_t  onLinkFlag,
bool_t  autonomousFlag,
uint32_t  validLifetime,
uint32_t  preferredLifetime 
)

Add a new entry to the Prefix List.

Parameters
[in]interfaceUnderlying network interface
[in]prefixIPv6 prefix
[in]lengthThe number of leading bits in the prefix that are valid
[in]onLinkFlagOn-link flag
[in]autonomousFlagAutonomous flag
[in]validLifetimeValid lifetime, in seconds
[in]preferredLifetimePreferred lifetime, in seconds

Definition at line 379 of file ipv6_misc.c.

◆ ipv6CheckDestAddr()

error_t ipv6CheckDestAddr ( NetInterface interface,
const Ipv6Addr ipAddr 
)

Destination IPv6 address filtering.

Parameters
[in]interfaceUnderlying network interface
[in]ipAddrDestination IPv6 address to be checked
Returns
Error code

Definition at line 789 of file ipv6_misc.c.

◆ ipv6CheckSourceAddr()

error_t ipv6CheckSourceAddr ( NetInterface interface,
const Ipv6Addr ipAddr 
)

Source IPv6 address filtering.

Parameters
[in]interfaceUnderlying network interface
[in]ipAddrSource IPv6 address to be checked
Returns
Error code

Definition at line 766 of file ipv6_misc.c.

◆ ipv6CompPrefix()

bool_t ipv6CompPrefix ( const Ipv6Addr ipAddr1,
const Ipv6Addr ipAddr2,
size_t  length 
)

Compare IPv6 address prefixes.

Parameters
[in]ipAddr1Pointer to the first IPv6 address
[in]ipAddr2Pointer to the second IPv6 address
[in]lengthPrefix length
Returns
TRUE if the prefixes match each other, else FALSE

Definition at line 1221 of file ipv6_misc.c.

◆ ipv6ComputeSolicitedNodeAddr()

error_t ipv6ComputeSolicitedNodeAddr ( const Ipv6Addr ipAddr,
Ipv6Addr solicitedNodeAddr 
)

Form a solicited-node address from an IPv6 address.

Parameters
[in]ipAddrUnicast or anycast address
[out]solicitedNodeAddrCorresponding solicited-node address
Returns
Error code

Definition at line 1390 of file ipv6_misc.c.

◆ ipv6FlushAddrList()

void ipv6FlushAddrList ( NetInterface interface)

Flush the list of IPv6 addresses.

Parameters
[in]interfaceUnderlying network interface

Definition at line 656 of file ipv6_misc.c.

◆ ipv6FlushDefaultRouterList()

void ipv6FlushDefaultRouterList ( NetInterface interface)

Flush the Default Router List.

Parameters
[in]interfaceUnderlying network interface

Definition at line 719 of file ipv6_misc.c.

◆ ipv6FlushDnsServerList()

void ipv6FlushDnsServerList ( NetInterface interface)

Flush the list of DNS servers.

Parameters
[in]interfaceUnderlying network interface

Definition at line 751 of file ipv6_misc.c.

◆ ipv6FlushPrefixList()

void ipv6FlushPrefixList ( NetInterface interface)

Flush the Prefix List.

Parameters
[in]interfaceUnderlying network interface

Definition at line 687 of file ipv6_misc.c.

◆ ipv6GenerateLinkLocalAddr()

void ipv6GenerateLinkLocalAddr ( const Eui64 interfaceId,
Ipv6Addr ipAddr 
)

Generate a IPv6 link-local address from an interface identifier.

Parameters
[in]interfaceIdInterface identifier
[out]ipAddrCorresponding IPv6 link-local address

Definition at line 1468 of file ipv6_misc.c.

◆ ipv6GetAddrScope()

uint_t ipv6GetAddrScope ( const Ipv6Addr ipAddr)

Retrieve the scope of an IPv6 address.

Parameters
[in]ipAddrPointer to an IPv6 address
Returns
IPv6 address scope

Definition at line 1266 of file ipv6_misc.c.

◆ ipv6GetAddrState()

Ipv6AddrState ipv6GetAddrState ( NetInterface interface,
const Ipv6Addr addr 
)

Get the state of the specified IPv6 address.

Parameters
[in]interfaceUnderlying network interface
[in]addrIPv6 address
Returns
Address state

Definition at line 55 of file ipv6_misc.c.

◆ ipv6GetCommonPrefixLength()

uint_t ipv6GetCommonPrefixLength ( const Ipv6Addr ipAddr1,
const Ipv6Addr ipAddr2 
)

Compute the length of the longest common prefix.

Parameters
[in]ipAddr1Pointer to the first IPv6 address
[in]ipAddr2Pointer to the second IPv6 address
Returns
The length of the longest common prefix, in bits

Definition at line 1340 of file ipv6_misc.c.

◆ ipv6GetMulticastAddrScope()

uint_t ipv6GetMulticastAddrScope ( const Ipv6Addr ipAddr)

Retrieve the scope of an IPv6 multicast address.

Parameters
[in]ipAddrPointer to an IPv6 multicast address
Returns
IPv6 address scope

Definition at line 1313 of file ipv6_misc.c.

◆ ipv6IsAnycastAddr()

bool_t ipv6IsAnycastAddr ( NetInterface interface,
const Ipv6Addr ipAddr 
)

Check whether an IPv6 address is an anycast address.

Parameters
[in]interfaceUnderlying network interface
[in]ipAddrIPv6 address to be checked
Returns
TRUE if the IPv6 address is an anycast address, else FALSE

Definition at line 1089 of file ipv6_misc.c.

◆ ipv6IsLocalHostAddr()

bool_t ipv6IsLocalHostAddr ( const Ipv6Addr ipAddr)

Check whether the specified IPv6 is assigned to the host.

Parameters
[in]ipAddrIPv6 address to be checked
Returns
TRUE if the IPv6 address matches any address assigned to the host, else FALSE

Definition at line 1161 of file ipv6_misc.c.

◆ ipv6IsOnLink()

bool_t ipv6IsOnLink ( NetInterface interface,
const Ipv6Addr ipAddr 
)

Check whether an IPv6 address is on-link.

Parameters
[in]interfaceUnderlying network interface
[in]ipAddrIPv6 address to be checked
Returns
TRUE if the IPv6 address is on-link, else FALSE

Definition at line 1045 of file ipv6_misc.c.

◆ ipv6IsTentativeAddr()

bool_t ipv6IsTentativeAddr ( NetInterface interface,
const Ipv6Addr ipAddr 
)

Check whether an IPv6 address is a tentative address.

Parameters
[in]interfaceUnderlying network interface
[in]ipAddrIPv6 address to be checked
Returns
TRUE if the IPv6 address is a tentative address, else FALSE

Definition at line 1125 of file ipv6_misc.c.

◆ ipv6MapMulticastAddrToMac()

error_t ipv6MapMulticastAddrToMac ( const Ipv6Addr ipAddr,
MacAddr macAddr 
)

Map an IPv6 multicast address to a MAC-layer multicast address.

Parameters
[in]ipAddrIPv6 multicast address
[out]macAddrCorresponding MAC-layer multicast address
Returns
Error code

Definition at line 1428 of file ipv6_misc.c.

◆ ipv6RemoveAddr()

void ipv6RemoveAddr ( NetInterface interface,
const Ipv6Addr addr 
)

Remove an entry from the list of IPv6 addresses.

Parameters
[in]interfaceUnderlying network interface
[in]addrIPv6 address

Definition at line 338 of file ipv6_misc.c.

◆ ipv6RemoveDefaultRouter()

void ipv6RemoveDefaultRouter ( NetInterface interface,
const Ipv6Addr addr 
)

Remove an entry from the Default Router List.

Parameters
[in]interfaceUnderlying network interface
[in]addrIPv6 address of the router to be removed from the list

Definition at line 602 of file ipv6_misc.c.

◆ ipv6RemovePrefix()

void ipv6RemovePrefix ( NetInterface interface,
const Ipv6Addr prefix,
uint_t  length 
)

Remove an entry from the Prefix List.

Parameters
[in]interfaceUnderlying network interface
[in]prefixIPv6 prefix
[in]lengthThe number of leading bits in the prefix that are valid

Definition at line 492 of file ipv6_misc.c.

◆ ipv6SelectSourceAddr()

error_t ipv6SelectSourceAddr ( NetInterface **  interface,
const Ipv6Addr destAddr,
Ipv6Addr srcAddr 
)

IPv6 source address selection.

This function selects the source address and the relevant network interface to be used in order to join the specified destination address

Parameters
[in,out]interfaceA pointer to a valid network interface may be provided as a hint. The function returns a pointer identifying the interface to be used
[in]destAddrDestination IPv6 address
[out]srcAddrLocal IPv6 address to be used
Returns
Error code

Definition at line 895 of file ipv6_misc.c.

◆ ipv6SetAddr()

error_t ipv6SetAddr ( NetInterface interface,
uint_t  index,
const Ipv6Addr addr,
Ipv6AddrState  state,
systime_t  validLifetime,
systime_t  preferredLifetime,
bool_t  permanent 
)

Set IPv6 address and address state.

Parameters
[in]interfacePointer to the desired network interface
[in]indexZero-based index
[in]addrIPv6 address
[in]stateState of the IPv6 address
[in]validLifetimeValid lifetime
[in]preferredLifetimePreferred lifetime
[in]permanentPermanently assigned address
Returns
Error code

Definition at line 95 of file ipv6_misc.c.

◆ ipv6UpdateInStats()

void ipv6UpdateInStats ( NetInterface interface,
const Ipv6Addr destIpAddr,
size_t  length 
)

Update IPv6 input statistics.

Parameters
[in]interfaceUnderlying network interface
[in]destIpAddrDestination IP address
[in]lengthLength of the incoming IP packet

Definition at line 1490 of file ipv6_misc.c.

◆ ipv6UpdateOutStats()

void ipv6UpdateOutStats ( NetInterface interface,
const Ipv6Addr destIpAddr,
size_t  length 
)

Update IPv6 output statistics.

Parameters
[in]interfaceUnderlying network interface
[in]destIpAddrDestination IP address
[in]lengthLength of the outgoing IP packet

Definition at line 1518 of file ipv6_misc.c.