forked from nuttx/nuttx-update
net/utils: Add net_ipv6_payload to get IPv6 L4 payload
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
parent
f2ff5cee03
commit
676826cb7c
4 changed files with 96 additions and 2 deletions
|
@ -37,7 +37,7 @@ set(SRCS
|
|||
# IPv6 utilities
|
||||
|
||||
if(CONFIG_NET_IPv6)
|
||||
list(APPEND SRCS net_ipv6_maskcmp.c net_ipv6_pref2mask.c)
|
||||
list(APPEND SRCS net_ipv6_maskcmp.c net_ipv6_pref2mask.c net_ipv6_payload.c)
|
||||
endif()
|
||||
|
||||
# TCP utilities
|
||||
|
|
|
@ -27,7 +27,7 @@ NET_CSRCS += net_cmsg.c net_iob_concat.c net_getrandom.c net_mask2pref.c
|
|||
# IPv6 utilities
|
||||
|
||||
ifeq ($(CONFIG_NET_IPv6),y)
|
||||
NET_CSRCS += net_ipv6_maskcmp.c net_ipv6_pref2mask.c
|
||||
NET_CSRCS += net_ipv6_maskcmp.c net_ipv6_pref2mask.c net_ipv6_payload.c
|
||||
endif
|
||||
|
||||
# TCP utilities
|
||||
|
|
74
net/utils/net_ipv6_payload.c
Normal file
74
net/utils/net_ipv6_payload.c
Normal file
|
@ -0,0 +1,74 @@
|
|||
/****************************************************************************
|
||||
* net/utils/net_ipv6_payload.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/ipv6ext.h>
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_ipv6_payload
|
||||
*
|
||||
* Description:
|
||||
* Given a pointer to the IPv6 header, this function will return a pointer
|
||||
* to the beginning of the L4 payload.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ipv6 - A pointer to the IPv6 header.
|
||||
* proto - The location to return the protocol number in the IPv6 header.
|
||||
*
|
||||
* Returned Value:
|
||||
* A pointer to the beginning of the payload.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *net_ipv6_payload(FAR struct ipv6_hdr_s *ipv6, FAR uint8_t *proto)
|
||||
{
|
||||
FAR struct ipv6_extension_s *exthdr;
|
||||
FAR uint8_t *payload = (FAR uint8_t *)ipv6 + IPv6_HDRLEN;
|
||||
uint8_t nxthdr = ipv6->proto;
|
||||
uint16_t extlen;
|
||||
|
||||
while (ipv6_exthdr(nxthdr))
|
||||
{
|
||||
/* Just skip over the extension header */
|
||||
|
||||
exthdr = (FAR struct ipv6_extension_s *)payload;
|
||||
extlen = EXTHDR_LEN(exthdr->len);
|
||||
|
||||
payload += extlen;
|
||||
nxthdr = exthdr->nxthdr;
|
||||
}
|
||||
|
||||
*proto = nxthdr;
|
||||
return payload;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_IPv6 */
|
|
@ -254,6 +254,26 @@ uint8_t net_ipv6_mask2pref(FAR const uint16_t *mask);
|
|||
void net_ipv6_pref2mask(net_ipv6addr_t mask, uint8_t preflen);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_ipv6_payload
|
||||
*
|
||||
* Description:
|
||||
* Given a pointer to the IPv6 header, this function will return a pointer
|
||||
* to the beginning of the L4 payload.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ipv6 - A pointer to the IPv6 header.
|
||||
* proto - The location to return the protocol number in the IPv6 header.
|
||||
*
|
||||
* Returned Value:
|
||||
* A pointer to the beginning of the payload.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
FAR void *net_ipv6_payload(FAR struct ipv6_hdr_s *ipv6, FAR uint8_t *proto);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_iob_concat
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue