Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posix: add networking apis #70635

Merged
merged 13 commits into from Mar 27, 2024
Merged

Conversation

cfriedt
Copy link
Member

@cfriedt cfriedt commented Mar 23, 2024

Add implementations (some fully supported, some stubs) for the remaining POSIX networking API calls

endhostent
endnetent
endprotoent
endservent
gethostent
getnetbyaddr
getnetbyname
getnetent
getprotobyname
getprotobynumber
getprotoent
getservbyname
getservbyport
getservent
if_freenameindex
if_indextoname
if_nameindex
if_nametoindex
inet_addr
inet_ntoa
sethostent
setnetent
setprotoent
setservent
sockatmark

With this, and with existing network subsystem API, we have mostly complete support for the POSIX_NETWORKING Option Group, as described in Section E.1 of IEEE 1003.1-2017.

The POSIX_NETWORKING Option Group is required by PSE53 and PSE54 Application Environment Profiles.

@cfriedt cfriedt requested review from jukkar and rlubos March 23, 2024 01:56
@cfriedt cfriedt force-pushed the posix-networking branch 7 times, most recently from b169e65 to 0003e5f Compare March 23, 2024 12:56
jukkar
jukkar previously approved these changes Mar 23, 2024
Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Chris, looks very good 🙇‍♂️

@cfriedt
Copy link
Member Author

cfriedt commented Mar 23, 2024

Had to add a cast to int in calls to isdigit() and isspace() for newlib to avoid these warnings being promoted to errors.

/__w/zephyr/zephyr/lib/posix/options/net.c: In function 'inet_addr':
/__w/zephyr/zephyr/lib/posix/options/net.c:41:38: error: array subscript has type 'char' [-Werror=char-subscripts]
   41 |                 } else if (isdigit(cp[i])) {
      |                                    ~~^~~
/__w/zephyr/zephyr/lib/posix/options/net.c:45:38: error: array subscript has type 'char' [-Werror=char-subscripts]
   45 |                 } else if (isspace(cp[i])) {
      |                                    ~~^~~
cc1: all warnings being treated as errors

The log subsystem defines LOG_ERR as a macro, which conflicts
with the standard POSIX LOG_ERR log level (3).

Reorder includes to avoid errors.

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Add a Kconfig option for POSIX_NETWORKING and implement
inet_addr().

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
@cfriedt cfriedt force-pushed the posix-networking branch 3 times, most recently from 826c27d to 064b91c Compare March 24, 2024 22:28
@cfriedt
Copy link
Member Author

cfriedt commented Mar 24, 2024

This is running fine locally with net-setup.sh from net-tools first and then west build -p auto -b qemu_x86 -t run tests/posix/net. Twister runs fine locally too with twister -i -p qemu_x86 -T tests/posix/net/

Am I missing something obvious for CI to pass?

*** Booting Zephyr OS build v3.6.0-1560-g064b91cf8792 ***
Running TESTSUITE net
===================================================================
START - test_if_freenameindex
 PASS - test_if_freenameindex in 0.001 seconds
===================================================================
START - test_if_indextoname
1 interfaces
interface 1: eth0
 PASS - test_if_indextoname in 0.001 seconds
===================================================================
START - test_if_nameindex
1 interfaces
interface 1: eth0
 PASS - test_if_nameindex in 0.001 seconds
===================================================================
START - test_if_nametoindex
1 interfaces
interface 1: eth0
 PASS - test_if_nametoindex in 0.001 seconds
===================================================================
START - test_inet_addr
 PASS - test_inet_addr in 0.001 seconds
===================================================================
START - test_inet_ntoa
 PASS - test_inet_ntoa in 0.001 seconds
===================================================================
TESTSUITE net succeeded

------ TESTSUITE SUMMARY START ------

SUITE PASS - 100.00% [net]: pass = 6, fail = 0, skip = 0, total = 6 duration = 0.006 seconds
 - PASS - [net.test_if_freenameindex] duration = 0.001 seconds
 - PASS - [net.test_if_indextoname] duration = 0.001 seconds
 - PASS - [net.test_if_nameindex] duration = 0.001 seconds
 - PASS - [net.test_if_nametoindex] duration = 0.001 seconds
 - PASS - [net.test_inet_addr] duration = 0.001 seconds
 - PASS - [net.test_inet_ntoa] duration = 0.001 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION SUCCESSFUL

@cfriedt cfriedt marked this pull request as ready for review March 24, 2024 22:40
@zephyrbot zephyrbot added the area: POSIX POSIX API Library label Mar 24, 2024
@zephyrbot zephyrbot requested a review from ycsin March 24, 2024 22:41
@cfriedt cfriedt added area: Documentation area: Tests Issues related to a particular existing or missing test labels Mar 24, 2024
@cfriedt cfriedt force-pushed the posix-networking branch 2 times, most recently from eb414ef to aeddf53 Compare March 26, 2024 11:25
Add a testsuite for posix networking apis with an initial
test for inet_addr().

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Add an implementation of inet_ntoa().

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Add tests for inet_ntoa()

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Implement if_indextoname(), if_freenameindex(), if_nameindex(),
and if_nametoindex() by wrapping around networking subystem
calls.

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Uncomment net/if.h tests in tests/posix/headers since we now
have an implementation and can check for the existence of
structures, functions, etc.

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Add tests for if_indextoname(), if_freenameindex(),
if_nameindex(), and if_nametoindex().

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Add trivial function implementations for those declared in
netdb.h .

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Uncomment netdb.h tests now that we have an implementation and
can check for the existence of e.g. hostent, netent, protoent,
and servent structure fields, as well as associated accessor
functions.

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Add a trivial implementation of sockatmark().

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Uncomment the check for sockatmark() to ensure that the function
is declared in sys/socket.h, as a stub implementation was added
in the previous commit.

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
Mark the POSIX_NETWORKING Option Group as supported. The
POSIX_NETWORKING Option Group is required for PSE53 Conformance.

Signed-off-by: Chris Friedt <chrisfriedt@gmail.com>
@cfriedt cfriedt merged commit 0bcf71e into zephyrproject-rtos:main Mar 27, 2024
34 checks passed
@cfriedt cfriedt deleted the posix-networking branch March 27, 2024 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Documentation area: Networking area: POSIX POSIX API Library area: Tests Issues related to a particular existing or missing test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants