You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "xiaoxiang781216 (via GitHub)" <gi...@apache.org> on 2023/01/27 10:36:40 UTC
[GitHub] [nuttx] xiaoxiang781216 opened a new pull request, #8285: Force sockaddr_storage to the desired alignment
xiaoxiang781216 opened a new pull request, #8285:
URL: https://github.com/apache/nuttx/pull/8285
## Summary
First configure nuttx to support ipv4 and ipv6 dual stack, then start two simulators and run Iperf ipv4 udp speed test, unaligned access exception to sockaddr_in occours.
The root cause is that struct sockaddr_storage isn't set to the desired alignment.
## Impact
Minor
## Testing
CI
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] luojun1234 commented on pull request #8285: Force sockaddr_storage to the desired alignment
Posted by "luojun1234 (via GitHub)" <gi...@apache.org>.
luojun1234 commented on PR #8285:
URL: https://github.com/apache/nuttx/pull/8285#issuecomment-1413221778
> @xiaoxiang781216 why `struct sockaddr` does not need similar alignment requirement? What was the place of error during iperf test?
1.iperf2/iperf2/include/Settings.hpp:
`typedef struct thread_Settings
{
...
// structs or miscellaneous
iperf_sockaddr peer; ==>the peer socket Addr
Socklen_t size_peer;
iperf_sockaddr local; ==>the local socket Addr
Socklen_t size_local;
...
}`
2.iperf2/iperf2/include/headers.h:
` #ifdef HAVE_IPV6
#define REPORT_ADDRLEN (INET6_ADDRSTRLEN + 1)
typedef struct sockaddr_storage iperf_sockaddr;
#else
#define REPORT_ADDRLEN (INET_ADDRSTRLEN + 1)
typedef struct sockaddr_in iperf_sockaddr;
#endif`
3.Configure nuttx to support dual stack, in the logic of iperf souce code, sockaddr_storage is cast to sockaddr_in(as follow), unaligned access occurs(sockaddr_in requires 4-byte alignment)
`
void Settings_GenerateClientSettings( thread_Settings *server,
thread_Settings **client,
client_hdr *hdr ) {
...
if ( server->mLocalhost != NULL ) {
(*client)->mLocalhost = new char[strlen( server->mLocalhost ) + 1];
strcpy( (*client)->mLocalhost, server->mLocalhost );
}
(*client)->mHost = new char[REPORT_ADDRLEN];
if ( ((sockaddr*)&server->peer)->sa_family == AF_INET ) {
inet_ntop( AF_INET, &((sockaddr_in*)&server->peer)->sin_addr, <== type casting
(*client)->mHost, REPORT_ADDRLEN);
}
#ifdef HAVE_IPV6
else {
inet_ntop( AF_INET6, &((sockaddr_in6*)&server->peer)->sin6_addr,
(*client)->mHost, REPORT_ADDRLEN);
}
#endif
} else {
*client = NULL;
}
}
`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #8285: Force sockaddr_storage to the desired alignment
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #8285:
URL: https://github.com/apache/nuttx/pull/8285#discussion_r1088892565
##########
include/sys/socket.h:
##########
@@ -279,6 +279,12 @@
#define SCM_CREDENTIALS 0x02 /* rw: struct ucred */
#define SCM_SECURITY 0x03 /* rw: security label */
+/* Desired design of maximum size and alignment (see RFC2553) */
+
+#define SS_MAXSIZE 128 /* Implementation specific max size */
+#define SS_ALIGNSIZE (sizeof(FAR struct sockaddr *))
+ /* Implementation specific desired alignment */
+
Review Comment:
Don't need, the compiler will stop and complain that the array length is negative.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #8285: Force sockaddr_storage to the desired alignment
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #8285:
URL: https://github.com/apache/nuttx/pull/8285#discussion_r1088892565
##########
include/sys/socket.h:
##########
@@ -279,6 +279,12 @@
#define SCM_CREDENTIALS 0x02 /* rw: struct ucred */
#define SCM_SECURITY 0x03 /* rw: security label */
+/* Desired design of maximum size and alignment (see RFC2553) */
+
+#define SS_MAXSIZE 128 /* Implementation specific max size */
+#define SS_ALIGNSIZE (sizeof(FAR struct sockaddr *))
+ /* Implementation specific desired alignment */
+
Review Comment:
Don't need the compiler will stop and complain that the array length is negative.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] acassis commented on a diff in pull request #8285: Force sockaddr_storage to the desired alignment
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on code in PR #8285:
URL: https://github.com/apache/nuttx/pull/8285#discussion_r1088888505
##########
include/sys/socket.h:
##########
@@ -279,6 +279,12 @@
#define SCM_CREDENTIALS 0x02 /* rw: struct ucred */
#define SCM_SECURITY 0x03 /* rw: security label */
+/* Desired design of maximum size and alignment (see RFC2553) */
+
+#define SS_MAXSIZE 128 /* Implementation specific max size */
+#define SS_ALIGNSIZE (sizeof(FAR struct sockaddr *))
+ /* Implementation specific desired alignment */
+
Review Comment:
Should be interesting to add a DEBUG_ASSERTION to check if SS_MAXSIZE is greater than sa_family_t !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] acassis merged pull request #8285: Force sockaddr_storage to the desired alignment
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis merged PR #8285:
URL: https://github.com/apache/nuttx/pull/8285
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nuttx] pkarashchenko commented on pull request #8285: Force sockaddr_storage to the desired alignment
Posted by "pkarashchenko (via GitHub)" <gi...@apache.org>.
pkarashchenko commented on PR #8285:
URL: https://github.com/apache/nuttx/pull/8285#issuecomment-1412846213
@xiaoxiang781216 why `struct sockaddr` does not need similar alignment requirement? What was the place of error during iperf test?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org