Compare commits

...

12 Commits

Author SHA1 Message Date
Marcus Dreier
eaf9c5b3a9
Merge 149e52f2c5 into d0efd9ef7b 2024-02-20 13:47:30 +08:00
Simon Goldschmidt
d0efd9ef7b tcpip: fix that TCPIP_CORE_LOCK is not released for LWIP_TIMERS==0
See bug #65328

Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
2024-02-19 21:44:18 +01:00
Krzysztof Mazur
e799c266fa makefsdata: extend file type matching with .shtml and .shtm
[Problem]
When using makefsdata perl script to convert shtml files with SSI tags
the shtml files get generated with text/plain content type, making
browsers not render them correctly

[Solution]
Extend the regex to generate text/html content type for any of:
.htm, .html, .shtm, .shtml extensions
2024-02-19 20:58:58 +01:00
Brian
cb511019b0 Update codeql-buildscript.sh
Adding install dependencies step
2024-02-19 20:03:32 +01:00
Brian
9004e7bd77 Add CodeQL Workflow for Code Security Analysis
Add CodeQL Workflow for Code Security Analysis

This pull request introduces a CodeQL workflow to enhance the security analysis of our repository. CodeQL is a powerful static analysis tool that helps identify and mitigate security vulnerabilities in our codebase. By integrating this workflow into our GitHub Actions, we can proactively identify and address potential issues before they become security threats.

We added a new CodeQL workflow file (.github/workflows/codeql.yml) that
- Runs on every pull request (functionality to run on every push to main branches is included as a comment for convenience).
- Runs daily.
- Excludes queries with a high false positive rate or low-severity findings.
- Does not display results for git submodules, focusing only on our own codebase.

Testing:
To validate the functionality of this workflow, we have run several test scans on the codebase and reviewed the results. The workflow successfully compiles the project, identifies issues, and provides actionable insights while reducing noise by excluding certain queries and third-party code.

Deployment:
Once this pull request is merged, the CodeQL workflow will be active and automatically run on every push and pull request to the main branch. To view the results of these code scans, please follow these steps:
1. Under the repository name, click on the Security tab.
2. In the left sidebar, click Code scanning alerts.

Additional Information:
- You can further customize the workflow to adapt to your specific needs by modifying the workflow file.
- For more information on CodeQL and how to interpret its results, refer to the GitHub documentation and the CodeQL documentation (https://codeql.github.com/ and https://codeql.github.com/docs/).

Signed-off-by: Brian <bayuan@purdue.edu>
2024-02-19 20:03:32 +01:00
Brian
17b1f5d382 Add CodeQL Workflow for Code Security Analysis
Add CodeQL Workflow for Code Security Analysis

This pull request introduces a CodeQL workflow to enhance the security analysis of our repository. CodeQL is a powerful static analysis tool that helps identify and mitigate security vulnerabilities in our codebase. By integrating this workflow into our GitHub Actions, we can proactively identify and address potential issues before they become security threats.

We added a new CodeQL workflow file (.github/workflows/codeql.yml) that
- Runs on every pull request (functionality to run on every push to main branches is included as a comment for convenience).
- Runs daily.
- Excludes queries with a high false positive rate or low-severity findings.
- Does not display results for git submodules, focusing only on our own codebase.

Testing:
To validate the functionality of this workflow, we have run several test scans on the codebase and reviewed the results. The workflow successfully compiles the project, identifies issues, and provides actionable insights while reducing noise by excluding certain queries and third-party code.

Deployment:
Once this pull request is merged, the CodeQL workflow will be active and automatically run on every push and pull request to the main branch. To view the results of these code scans, please follow these steps:
1. Under the repository name, click on the Security tab.
2. In the left sidebar, click Code scanning alerts.

Additional Information:
- You can further customize the workflow to adapt to your specific needs by modifying the workflow file.
- For more information on CodeQL and how to interpret its results, refer to the GitHub documentation and the CodeQL documentation (https://codeql.github.com/ and https://codeql.github.com/docs/).

Signed-off-by: Brian <bayuan@purdue.edu>
2024-02-19 20:03:32 +01:00
Brian
10dc9b7eb3 Add CodeQL Workflow for Code Security Analysis
Add CodeQL Workflow for Code Security Analysis

This pull request introduces a CodeQL workflow to enhance the security analysis of our repository. CodeQL is a powerful static analysis tool that helps identify and mitigate security vulnerabilities in our codebase. By integrating this workflow into our GitHub Actions, we can proactively identify and address potential issues before they become security threats.

We added a new CodeQL workflow file (.github/workflows/codeql.yml) that
- Runs on every pull request (functionality to run on every push to main branches is included as a comment for convenience).
- Runs daily.
- Excludes queries with a high false positive rate or low-severity findings.
- Does not display results for git submodules, focusing only on our own codebase.

Testing:
To validate the functionality of this workflow, we have run several test scans on the codebase and reviewed the results. The workflow successfully compiles the project, identifies issues, and provides actionable insights while reducing noise by excluding certain queries and third-party code.

Deployment:
Once this pull request is merged, the CodeQL workflow will be active and automatically run on every push and pull request to the main branch. To view the results of these code scans, please follow these steps:
1. Under the repository name, click on the Security tab.
2. In the left sidebar, click Code scanning alerts.

Additional Information:
- You can further customize the workflow to adapt to your specific needs by modifying the workflow file.
- For more information on CodeQL and how to interpret its results, refer to the GitHub documentation and the CodeQL documentation (https://codeql.github.com/ and https://codeql.github.com/docs/).

Signed-off-by: Brian <bayuan@purdue.edu>
2024-02-19 20:03:32 +01:00
Brian
c3d6fe9d72 Add CodeQL Workflow for Code Security Analysis
Add CodeQL Workflow for Code Security Analysis

This pull request introduces a CodeQL workflow to enhance the security analysis of our repository. CodeQL is a powerful static analysis tool that helps identify and mitigate security vulnerabilities in our codebase. By integrating this workflow into our GitHub Actions, we can proactively identify and address potential issues before they become security threats.

We added a new CodeQL workflow file (.github/workflows/codeql.yml) that
- Runs on every push and pull request to the main branch.
- Excludes queries with a high false positive rate or low-severity findings.
- Does not display results for third-party code, focusing only on our own codebase.

Testing:
To validate the functionality of this workflow, we have run several test scans on the codebase and reviewed the results. The workflow successfully compiles the project, identifies issues, and provides actionable insights while reducing noise by excluding certain queries and third-party code.

Deployment:
Once this pull request is merged, the CodeQL workflow will be active and automatically run on every push and pull request to the main branch. To view the results of these code scans, please follow these steps:
1. Under the repository name, click on the Security tab.
2. In the left sidebar, click Code scanning alerts.

Additional Information:
- You can further customize the workflow to adapt to your specific needs by modifying the workflow file.
- For more information on CodeQL and how to interpret its results, refer to the GitHub documentation and the CodeQL documentation.

Signed-off-by: Brian <bayuan@purdue.edu>
2024-02-19 20:03:32 +01:00
Kirill Lokotkov
93821fc437 Fixed netdb.c when LWIP_SOCKET_HAVE_SA_LEN == 0
Fields sin6_len and sin_len are always used in the file but not all implementations of sockaddr_in or sockaddr_in6 have this fields (including Linux implementation).
Added #if-check to avoid compilation errors in such cases.
2024-02-19 18:13:28 +01:00
Kirill Lokotkov
7c494b3829 Added "lwip/errno.h" to netdb.c includes
Defines EINVAL and ERANGE are used in the file but not included directly. When I try to use <sys/socket.h> and <arpa/inet.h> as LWIP_SOCKET_EXTERNAL_HEADERS it causes errors with this defines.
2024-02-19 18:13:28 +01:00
Sebastian Michel
e1b8080346 contrib: fixed c++ compatibility of unix port 2024-02-19 18:04:02 +01:00
Marcus Dreier
149e52f2c5 Patch #9977: New socket option IPV6_RECVPKTINFO 2023-08-09 16:46:06 +02:00
18 changed files with 336 additions and 24 deletions

View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
sudo apt-get install check ninja-build doxygen
cp contrib/examples/example_app/lwipcfg.h.ci contrib/examples/example_app/lwipcfg.h
make -C contrib/ports/unix/check
mkdir build && cd build && cmake .. -G Ninja && cmake --build .

126
.github/workflows/codeql.yml vendored Normal file
View File

@ -0,0 +1,126 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
# push:
# branches: [ "main", "master" ]
schedule:
- cron: '0 0 * * *'
pull_request:
branches: '*'
jobs:
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-20.04' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'cpp' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
queries: security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
#- name: Autobuild
# uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
- run: |
./.github/workflows/codeql-buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
upload: false
id: step1
# Filter out rules with low severity or high false positve rate
# Also filter out warnings in third-party code
- name: Filter out unwanted errors and warnings
uses: advanced-security/filter-sarif@v1
with:
patterns: |
-**:cpp/path-injection
-**:cpp/world-writable-file-creation
-**:cpp/poorly-documented-function
-**:cpp/potentially-dangerous-function
-**:cpp/use-of-goto
-**:cpp/integer-multiplication-cast-to-long
-**:cpp/comparison-with-wider-type
-**:cpp/leap-year/*
-**:cpp/ambiguously-signed-bit-field
-**:cpp/suspicious-pointer-scaling
-**:cpp/suspicious-pointer-scaling-void
-**:cpp/unsigned-comparison-zero
-**/cmake*/Modules/**
input: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
- name: Upload CodeQL results to code scanning
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ steps.step1.outputs.sarif-output }}
category: "/language:${{matrix.language}}"
- name: Upload CodeQL results as an artifact
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: codeql-results
path: ${{ steps.step1.outputs.sarif-output }}
retention-days: 5
- name: Fail if an error is found
run: |
./.github/workflows/fail_on_error.py \
${{ steps.step1.outputs.sarif-output }}/cpp.sarif

34
.github/workflows/fail_on_error.py vendored Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
import json
import sys
# Return whether SARIF file contains error-level results
def codeql_sarif_contain_error(filename):
with open(filename, 'r') as f:
s = json.load(f)
for run in s.get('runs', []):
rules_metadata = run['tool']['driver']['rules']
if not rules_metadata:
rules_metadata = run['tool']['extensions'][0]['rules']
for res in run.get('results', []):
if 'ruleIndex' in res:
rule_index = res['ruleIndex']
elif 'rule' in res and 'index' in res['rule']:
rule_index = res['rule']['index']
else:
continue
try:
rule_level = rules_metadata[rule_index]['defaultConfiguration']['level']
except IndexError as e:
print(e, rule_index, len(rules_metadata))
else:
if rule_level == 'error':
return True
return False
if __name__ == "__main__":
if codeql_sarif_contain_error(sys.argv[1]):
sys.exit(1)

View File

@ -52,6 +52,10 @@
#define LWIP_TIMEVAL_PRIVATE 0
#include <sys/time.h>
#ifdef __cplusplus
extern "C" {
#endif
#define LWIP_ERRNO_INCLUDE <errno.h>
#if defined(LWIP_UNIX_LINUX) || defined(LWIP_UNIX_HURD) || defined(LWIP_UNIX_KFREEBSD)
@ -86,4 +90,8 @@ typedef struct sio_status_s sio_status_t;
typedef unsigned int sys_prot_t;
#ifdef __cplusplus
}
#endif
#endif /* LWIP_ARCH_CC_H */

View File

@ -34,6 +34,10 @@
#include <sys/times.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef PERF
#define PERF_START { \
unsigned long __c1l, __c1h, __c2l, __c2h; \
@ -60,4 +64,8 @@ void perf_print_times(struct tms *start, struct tms *end, char *key);
void perf_init(char *fname);
#ifdef __cplusplus
}
#endif
#endif /* LWIP_ARCH_PERF_H */

View File

@ -32,6 +32,10 @@
#ifndef LWIP_ARCH_SYS_ARCH_H
#define LWIP_ARCH_SYS_ARCH_H
#ifdef __cplusplus
extern "C" {
#endif
#define SYS_MBOX_NULL NULL
#define SYS_SEM_NULL NULL
@ -87,4 +91,8 @@ void sys_unlock_tcpip_core(void);
#define UNLOCK_TCPIP_CORE() sys_unlock_tcpip_core()
#endif
#ifdef __cplusplus
}
#endif
#endif /* LWIP_ARCH_SYS_ARCH_H */

View File

@ -3,6 +3,10 @@
#include "lwip/sys.h"
#ifdef __cplusplus
extern "C" {
#endif
/** How many bytes in fifo */
#define FIFOSIZE 2048
@ -50,5 +54,9 @@ void fifoPut(fifo_t * fifo, int fd);
*/
void fifoInit(fifo_t * fifo);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -2,6 +2,10 @@
#ifndef LWIP_LIST_H
#define LWIP_LIST_H
#ifdef __cplusplus
extern "C" {
#endif
struct elem;
struct list {
@ -23,4 +27,8 @@ void list_delete(struct list *list);
int list_remove(struct list *list, void *elem);
void list_map(struct list *list, void (* func)(void *arg));
#ifdef __cplusplus
}
#endif
#endif

View File

@ -34,6 +34,14 @@
#include "lwip/netif.h"
#ifdef __cplusplus
extern "C" {
#endif
err_t pcapif_init(struct netif *netif);
#ifdef __cplusplus
}
#endif
#endif /* LWIP_PCAPIF_H */

View File

@ -6,6 +6,10 @@
#include "netif/fifo.h"
/*#include "netif/pppif.h"*/
#ifdef __cplusplus
extern "C" {
#endif
struct sio_status_s {
int fd;
fifo_t myfifo;
@ -56,5 +60,9 @@ void sio_flush( sio_status_t * siostat );
*/
void sio_change_baud( sioBaudrates baud, sio_status_t * siostat );
#ifdef __cplusplus
}
#endif
#endif

View File

@ -34,10 +34,18 @@
#include "lwip/netif.h"
#ifdef __cplusplus
extern "C" {
#endif
err_t tapif_init(struct netif *netif);
void tapif_poll(struct netif *netif);
#if NO_SYS
int tapif_select(struct netif *netif);
#endif /* NO_SYS */
#ifdef __cplusplus
}
#endif
#endif /* LWIP_TAPIF_H */

View File

@ -34,10 +34,18 @@
#include "lwip/netif.h"
#ifdef __cplusplus
extern "C" {
#endif
err_t vdeif_init(struct netif *netif);
void vdeif_poll(struct netif *netif);
#if NO_SYS
int vdeif_select(struct netif *netif);
#endif /* NO_SYS */
#ifdef __cplusplus
}
#endif
#endif /* LWIP_VDEIF_H */

View File

@ -40,6 +40,7 @@
#if LWIP_DNS && LWIP_SOCKET
#include "lwip/err.h"
#include "lwip/errno.h"
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/ip_addr.h"
@ -382,7 +383,9 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
/* set up sockaddr */
inet6_addr_from_ip6addr(&sa6->sin6_addr, ip_2_ip6(&addr));
sa6->sin6_family = AF_INET6;
#if LWIP_SOCKET_HAVE_SA_LEN
sa6->sin6_len = sizeof(struct sockaddr_in6);
#endif /* LWIP_SOCKET_HAVE_SA_LEN */
sa6->sin6_port = lwip_htons((u16_t)port_nr);
sa6->sin6_scope_id = ip6_addr_zone(ip_2_ip6(&addr));
ai->ai_family = AF_INET6;
@ -393,7 +396,9 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
/* set up sockaddr */
inet_addr_from_ip4addr(&sa4->sin_addr, ip_2_ip4(&addr));
sa4->sin_family = AF_INET;
#if LWIP_SOCKET_HAVE_SA_LEN
sa4->sin_len = sizeof(struct sockaddr_in);
#endif /* LWIP_SOCKET_HAVE_SA_LEN */
sa4->sin_port = lwip_htons((u16_t)port_nr);
ai->ai_family = AF_INET;
#endif /* LWIP_IPV4 */

View File

@ -1215,6 +1215,22 @@ lwip_recvfrom_udp_raw(struct lwip_sock *sock, int flags, struct msghdr *msg, u16
msg->msg_flags |= MSG_CTRUNC;
}
#endif /* LWIP_IPV4 */
} else if (IP_IS_V6(&buf->toaddr)) {
#if LWIP_IPV6
if (msg->msg_controllen >= CMSG_SPACE(sizeof(struct in6_pktinfo))) {
struct cmsghdr *chdr = CMSG_FIRSTHDR(msg); /* This will always return a header!! */
struct in6_pktinfo *pkti = (struct in6_pktinfo *)CMSG_DATA(chdr);
chdr->cmsg_level = IPPROTO_IPV6;
chdr->cmsg_type = IPV6_PKTINFO;
chdr->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
pkti->ipi6_ifindex = buf->p->if_idx;
inet6_addr_from_ip6addr(&pkti->ipi6_addr, ip_2_ip6(netbuf_destaddr(buf)));
msg->msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
wrote_msg = 1;
} else {
msg->msg_flags |= MSG_CTRUNC;
}
#endif /* LWIP_IPV6 */
}
}
#endif /* LWIP_NETBUF_RECVINFO */
@ -3711,6 +3727,16 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IPV6, IPV6_V6ONLY, ..) -> %d\n",
s, (netconn_get_ipv6only(sock->conn) ? 1 : 0)));
break;
#if LWIP_NETBUF_RECVINFO
case IPV6_RECVPKTINFO:
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_UDP);
if (*(const int *)optval) {
sock->conn->flags |= NETCONN_FLAG_PKTINFO;
} else {
sock->conn->flags &= ~NETCONN_FLAG_PKTINFO;
}
break;
#endif /* LWIP_NETBUF_RECVINFO */
#if LWIP_IPV6_MLD
case IPV6_JOIN_GROUP:
case IPV6_LEAVE_GROUP: {

View File

@ -68,11 +68,20 @@ sys_mutex_t lock_tcpip_core;
static void tcpip_thread_handle_msg(struct tcpip_msg *msg);
#if !LWIP_TIMERS
/* wait for a message with timers disabled (e.g. pass a timer-check trigger into tcpip_thread) */
#define TCPIP_MBOX_FETCH(mbox, msg) sys_mbox_fetch(mbox, msg)
/** Wait for a message with timers disabled (e.g. pass a timer-check trigger into tcpip_thread) */
static void
tcpip_mbox_fetch(sys_mbox_t* mbox, void** msg)
{
LWIP_ASSERT_CORE_LOCKED();
UNLOCK_TCPIP_CORE();
sys_mbox_fetch(mbox, msg);
LOCK_TCPIP_CORE();
}
#else /* !LWIP_TIMERS */
/* wait for a message, timeouts are processed while waiting */
#define TCPIP_MBOX_FETCH(mbox, msg) tcpip_timeouts_mbox_fetch(mbox, msg)
/**
* Wait (forever) for a message to arrive in an mbox.
* While waiting, timeouts are processed.
@ -81,7 +90,7 @@ static void tcpip_thread_handle_msg(struct tcpip_msg *msg);
* @param msg the place to store the message
*/
static void
tcpip_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg)
tcpip_mbox_fetch(sys_mbox_t *mbox, void **msg)
{
u32_t sleeptime, res;
@ -139,7 +148,7 @@ tcpip_thread(void *arg)
while (1) { /* MAIN Loop */
LWIP_TCPIP_THREAD_ALIVE();
/* wait for a message, timeouts are processed while waiting */
TCPIP_MBOX_FETCH(&tcpip_mbox, (void **)&msg);
tcpip_mbox_fetch(&tcpip_mbox, (void **)&msg);
if (msg == NULL) {
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: NULL\n"));
LWIP_ASSERT("tcpip_thread: invalid message", 0);

View File

@ -21,7 +21,7 @@ while($file = <FILES>) {
print(HEADER "HTTP/1.0 200 OK\r\n");
}
print(HEADER "Server: lwIP/pre-0.6 (http://www.sics.se/~adam/lwip/)\r\n");
if($file =~ /\.html$/) {
if($file =~ /\.s?html?$/) {
print(HEADER "Content-type: text/html\r\n");
} elsif($file =~ /\.gif$/) {
print(HEADER "Content-type: image/gif\r\n");

View File

@ -298,6 +298,8 @@ struct linger {
*/
#define IPV6_CHECKSUM 7 /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */
#define IPV6_V6ONLY 27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */
#define IPV6_RECVPKTINFO 49 /* RFC3542: enables the receiving of ancillary data via setsockopt() */
#define IPV6_PKTINFO 50 /* RFC3542: ancillary data in recvmsg() received */
#endif /* LWIP_IPV6 */
#if LWIP_UDP && LWIP_UDPLITE
@ -338,6 +340,13 @@ struct in_pktinfo {
};
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
struct in6_pktinfo {
unsigned int ipi6_ifindex; /* Interface index */
struct in6_addr ipi6_addr; /* Destination (from header) address */
};
#endif /* LWIP_IPV6 */
#if LWIP_IPV6_MLD
/*
* Options and types related to IPv6 multicast membership

View File

@ -10,6 +10,7 @@
#include "lwip/priv/tcp_priv.h"
#include "lwip/api.h"
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
static int
test_sockets_get_used_count(void)
@ -255,7 +256,7 @@ static void test_sockets_msgapi_update_iovs(struct msghdr *msg, size_t bytes)
/* note: this modifies the underlying iov_base and iov_len for a partial
read for an individual vector. This updates the msg->msg_iov pointer
to skip fully consumed vectors */
/* process fully consumed vectors */
for (i = 0; i < msg->msg_iovlen; i++) {
if (msg->msg_iov[i].iov_len <= bytes) {
@ -395,7 +396,7 @@ static void test_sockets_msgapi_tcp(int domain)
/* note: since we always receive after sending, there will be open
space in the send buffer */
fail_unless(ret > 0);
bytes_written += ret;
if (bytes_written < TOTAL_DATA_SZ) {
test_sockets_msgapi_update_iovs(&smsg, (size_t)ret);
@ -432,7 +433,7 @@ static void test_sockets_msgapi_tcp(int domain)
}
} while(ret > 0);
}
ret = lwip_close(s1);
fail_unless(ret == 0);
ret = lwip_close(s2);
@ -544,7 +545,6 @@ static void test_sockets_msgapi_udp(int domain)
fail_unless(ret == 0);
}
#if LWIP_IPV4
static void test_sockets_msgapi_cmsg(int domain)
{
int s, ret, enable;
@ -553,10 +553,10 @@ static void test_sockets_msgapi_cmsg(int domain)
struct iovec iov;
struct msghdr msg;
struct cmsghdr *cmsg;
struct in_pktinfo *pktinfo;
u8_t rcv_buf[4];
u8_t snd_buf[4] = {0xDE, 0xAD, 0xBE, 0xEF};
u8_t cmsg_buf[CMSG_SPACE(sizeof(struct in_pktinfo))];
u8_t cmsg_buf[CMSG_SPACE(MAX(sizeof(struct in_pktinfo),
sizeof(struct in6_pktinfo)))];
test_sockets_init_loopback_addr(domain, &addr_storage, &addr_size);
@ -571,7 +571,15 @@ static void test_sockets_msgapi_cmsg(int domain)
fail_unless(ret == 0);
enable = 1;
ret = lwip_setsockopt(s, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable));
if (domain == AF_INET) {
#if LWIP_IPV4
ret = lwip_setsockopt(s, IPPROTO_IP, IP_PKTINFO, &enable, sizeof(enable));
#endif
} else {
#if LWIP_IPV6
ret = lwip_setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &enable, sizeof(enable));
#endif
}
fail_unless(ret == 0);
/* Receive full message, including control message */
@ -588,25 +596,42 @@ static void test_sockets_msgapi_cmsg(int domain)
memset(rcv_buf, 0, sizeof(rcv_buf));
ret = lwip_sendto(s, snd_buf, sizeof(snd_buf), 0, (struct sockaddr*)&addr_storage, addr_size);
fail_unless(ret == sizeof(snd_buf));
tcpip_thread_poll_one();
ret = lwip_recvmsg(s, &msg, 0);
fail_unless(ret == sizeof(rcv_buf));
fail_unless(!memcmp(rcv_buf, snd_buf, sizeof(rcv_buf)));
/* Verify message header */
cmsg = CMSG_FIRSTHDR(&msg);
fail_unless(cmsg != NULL);
fail_unless(cmsg->cmsg_len > 0);
fail_unless(cmsg->cmsg_level == IPPROTO_IP);
fail_unless(cmsg->cmsg_type == IP_PKTINFO);
/* Verify message data */
pktinfo = (struct in_pktinfo*)CMSG_DATA(cmsg);
/* We only have loopback interface enabled */
fail_unless(pktinfo->ipi_ifindex == 1);
fail_unless(pktinfo->ipi_addr.s_addr == PP_HTONL(INADDR_LOOPBACK));
if (domain == AF_INET) {
struct in_pktinfo *pktinfo;
fail_unless(cmsg->cmsg_level == IPPROTO_IP);
fail_unless(cmsg->cmsg_type == IP_PKTINFO);
/* Verify message data */
pktinfo = (struct in_pktinfo*)CMSG_DATA(cmsg);
/* We only have loopback interface enabled */
fail_unless(pktinfo->ipi_ifindex == 1);
fail_unless(pktinfo->ipi_addr.s_addr == PP_HTONL(INADDR_LOOPBACK));
} else {
struct in6_pktinfo *pktinfo;
struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT;
fail_unless(cmsg->cmsg_level == IPPROTO_IPV6);
fail_unless(cmsg->cmsg_type == IPV6_PKTINFO);
/* Verify message data */
pktinfo = (struct in6_pktinfo*)CMSG_DATA(cmsg);
/* We only have loopback interface enabled */
fail_unless(pktinfo->ipi6_ifindex == 1);
fail_unless(!memcmp(&pktinfo->ipi6_addr, &lo6, sizeof(pktinfo->ipi6_addr)));
}
/* Verify there are no additional messages */
cmsg = CMSG_NXTHDR(&msg, cmsg);
@ -632,7 +657,6 @@ static void test_sockets_msgapi_cmsg(int domain)
ret = lwip_close(s);
fail_unless(ret == 0);
}
#endif /* LWIP_IPV4 */
START_TEST(test_sockets_msgapis)
{
@ -645,6 +669,7 @@ START_TEST(test_sockets_msgapis)
#if LWIP_IPV6
test_sockets_msgapi_udp(AF_INET6);
test_sockets_msgapi_tcp(AF_INET6);
test_sockets_msgapi_cmsg(AF_INET6);
#endif
}
END_TEST