mirror of
https://github.com/espressif/openthread.git
synced 2026-08-31 06:19:54 +00:00
[nat64] add functions for processing IPv4 packets (#7824)
With NAT64, we need to handle the IPv4 packets inside the border router functions in OpenThread core. This commit introduces a few new classes for NAT64: - Add `Ip4::Cidr` (for specifying CIDR block of translated packets) - Updated Ip4 address format -- use a union of (m8[4], m16[2], m32) instead of 4 bytes. - Extend `Checksum` for supporting ICMP in Ip4 (and TCP4 / UDP4) and IPv4 header.
This commit is contained in:
@@ -70,6 +70,7 @@ openthread_headers = \
|
||||
openthread/logging.h \
|
||||
openthread/message.h \
|
||||
openthread/multi_radio.h \
|
||||
openthread/nat64.h \
|
||||
openthread/ncp.h \
|
||||
openthread/netdata.h \
|
||||
openthread/netdata_publisher.h \
|
||||
|
||||
@@ -74,6 +74,7 @@ source_set("openthread") {
|
||||
"logging.h",
|
||||
"message.h",
|
||||
"multi_radio.h",
|
||||
"nat64.h",
|
||||
"ncp.h",
|
||||
"netdata.h",
|
||||
"netdata_publisher.h",
|
||||
|
||||
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (226)
|
||||
#define OPENTHREAD_API_VERSION (227)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2022, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
* This file defines the OpenThread API for NAT64 on a border router.
|
||||
*/
|
||||
|
||||
#ifndef OPENTHREAD_NAT64_H_
|
||||
#define OPENTHREAD_NAT64_H_
|
||||
|
||||
#include <openthread/message.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup api-nat64
|
||||
*
|
||||
* @brief This module includes functions and structs for the NAT64 function on the border router. These functions are
|
||||
* only available when `OPENTHREAD_CONFIG_BORDER_ROUTING_NAT64_ENABLE` is enabled.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
#define OT_IP4_ADDRESS_SIZE 4 ///< Size of an IPv4 address (bytes)
|
||||
|
||||
/**
|
||||
* @struct otIp4Address
|
||||
*
|
||||
* This structure represents an IPv4 address.
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
struct otIp4Address
|
||||
{
|
||||
union OT_TOOL_PACKED_FIELD
|
||||
{
|
||||
uint8_t m8[OT_IP4_ADDRESS_SIZE]; ///< 8-bit fields
|
||||
uint32_t m32; ///< 32-bit representation
|
||||
} mFields;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* This structure represents an IPv4 address.
|
||||
*
|
||||
*/
|
||||
typedef struct otIp4Address otIp4Address;
|
||||
|
||||
/**
|
||||
* @struct otIp4Cidr
|
||||
*
|
||||
* This structure represents an IPv4 CIDR block.
|
||||
*
|
||||
*/
|
||||
typedef struct otIp4Cidr
|
||||
{
|
||||
otIp4Address mAddress;
|
||||
uint8_t mLength;
|
||||
} otIp4Cidr;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OPENTHREAD_NAT64_H_
|
||||
Reference in New Issue
Block a user