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

gcoap: propagate local tx aux to gcoap_req_send() and in _handler_req() #20711

Merged
merged 5 commits into from
Jul 5, 2024

Conversation

fabian18
Copy link
Contributor

@fabian18 fabian18 commented May 29, 2024

Contribution description

The gcoap forward proxy must respond to the client from the same address and port where it has received the request.
The address towards the server can be different.
For that the usual information in sock_udp_aux_tx_t are propated to where they are needed in gcoap_req_send() and _handle_req() in gcoap.c

Another fix is included by setting the correct payload size in the forwarded PDU right after it is copied.

Testing procedure

Use this branch to run a client and proxy with examples/gcoap

./dist/tools/tapsetup

Client:

CFLAGS+=-DCONFIG_GCOAP_PDU_BUF_SIZE=512 make flash term

Proxy:

Add another link local address only to the proxy by adding the following to examples/gcoap/Makefile:

+# Uncomment the following 2 lines to specify static link lokal IPv6 address
+# this might be useful for testing, in cases where you cannot or do not want to
+# run a shell with ifconfig to get the real link lokal address.
+IPV6_STATIC_LLADDR ?= '"fe80::cafe:cafe:cafe:1"'
+CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR=$(IPV6_STATIC_LLADDR)
+# uncomment to not increment the last digit by the inderface number
+CFLAGS += -DCONFIG_GNRC_IPV6_STATIC_LLADDR_IS_FIXED=1
+CFLAGS += -DCONFIG_GNRC_NETIF_IPV6_ADDRS_NUMOF=4

CFLAGS+=-DCONFIG_GCOAP_PDU_BUF_SIZE=512 USEMODULE+=gcoap_forward_proxy make flash term PORT=tap1

2024-05-29 20:38:18,501 # ifconfig
2024-05-29 20:38:18,502 # Iface  6  HWaddr: A2:AE:A2:2F:AF:16 
2024-05-29 20:38:18,502 #           L2-PDU:1500  MTU:1500  HL:64  Source address length: 6
2024-05-29 20:38:18,502 #           Link type: wired
2024-05-29 20:38:18,503 #           inet6 addr: fe80::cafe:cafe:cafe:1  scope: link  VAL
2024-05-29 20:38:18,503 #           inet6 addr: fe80::a0ae:a2ff:fe2f:af16  scope: link  VAL
2024-05-29 20:38:18,503 #           inet6 group: ff02::1
2024-05-29 20:38:18,503 #           inet6 group: ff02::1:fffe:1
2024-05-29 20:38:18,503 #           inet6 group: ff02::1:ff2f:af16
2024-05-29 20:38:18,503 # 

Server:

Run a libcoap server on the tapbr0 interface:
coap-server-openssl -A fe80::f0da:e9ff:fe74:594a%tapbr0

Client:

Set the proxy:
coap proxy set coap:https://[fe80::a0ae:a2ff:fe2f:af16]:5683

Send a request to the server:
coap get coap:https://[fe80::f0da:e9ff:fe74:594a]:5683/.well-known/core

As you can see in the wireshark picture, the proxy uses different address toward the client and towards the server.

Screenshot from 2024-05-29 20-42-49

The same procedure does not work in master right now.

Issues/PRs references

This is the next split out of #20696.

@github-actions github-actions bot added Area: network Area: Networking Area: CoAP Area: Constrained Application Protocol implementations Area: sys Area: System Area: examples Area: Example Applications labels May 29, 2024
@fabian18 fabian18 added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels May 29, 2024
@riot-ci
Copy link

riot-ci commented May 30, 2024

Murdock results

✔️ PASSED

f50dd7d gcoap/forward_proxy: set payload length in forwarded PDU

Success Failures Total Runtime
10161 0 10161 17m:32s

Artifacts

Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

Thx. The change looks good to me.

I guess it would be possible to rename the function and provide a backward compatible version. But I do believe that having a gcoap_req_send() and a gcoap_req_send2() or whatever would cause more confusion than it would save time for app developers that would profit from a deprecation period. And updating the calls is relatively easy by adding the additional parameter.

sys/net/application_layer/cord/ep/cord_ep.c Outdated Show resolved Hide resolved
sys/net/application_layer/gcoap/forward_proxy.c Outdated Show resolved Hide resolved
@maribu maribu requested a review from chrysn May 30, 2024 07:16
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Looks good to me and the explanation makes sense.

@benpicco benpicco added this pull request to the merge queue Jul 4, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 4, 2024
@benpicco benpicco added this pull request to the merge queue Jul 5, 2024
Merged via the queue into RIOT-OS:master with commit 4ba7c46 Jul 5, 2024
26 checks passed
@maribu
Copy link
Member

maribu commented Jul 5, 2024

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CoAP Area: Constrained Application Protocol implementations Area: examples Area: Example Applications Area: network Area: Networking Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants