diff mbox series

[v11,14/29] lwip: tftp: bind to TFTP port only when in server mode

Message ID c29c2aa6fc0f1a97afff121e2f42abcac5b671f2.1727968902.git.jerome.forissier@linaro.org
State New
Headers show
Series Introduce the lwIP network stack | expand

Commit Message

Jerome Forissier Oct. 3, 2024, 3:46 p.m. UTC
The TFTP app should not bind to the TFTP server port when configured as
a client. Instead, the local port should be chosen from the dynamic
range (49152 ~ 65535) so that if the application is stopped and started
again, the remote server will not consider the new packets as part of
the same context (which would cause an error since a new RRQ would be
unexpected).

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
 lib/lwip/lwip/src/apps/tftp/tftp.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Ilias Apalodimas Oct. 4, 2024, 6:11 a.m. UTC | #1
Hi Jerome,

On Thu, 3 Oct 2024 at 18:47, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> The TFTP app should not bind to the TFTP server port when configured as
> a client. Instead, the local port should be chosen from the dynamic
> range (49152 ~ 65535) so that if the application is stopped and started
> again, the remote server will not consider the new packets as part of
> the same context (which would cause an error since a new RRQ would be
> unexpected).
>
> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> ---
>  lib/lwip/lwip/src/apps/tftp/tftp.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/lib/lwip/lwip/src/apps/tftp/tftp.c b/lib/lwip/lwip/src/apps/tftp/tftp.c
> index ddfdbfc0c1b..74fc1fbe586 100644
> --- a/lib/lwip/lwip/src/apps/tftp/tftp.c
> +++ b/lib/lwip/lwip/src/apps/tftp/tftp.c
> @@ -454,10 +454,12 @@ tftp_init_common(u8_t mode, const struct tftp_context *ctx)
>      return ERR_MEM;
>    }
>
> -  ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
> -  if (ret != ERR_OK) {
> -    udp_remove(pcb);
> -    return ret;
> +  if (mode == LWIP_TFTP_MODE_SERVER) {
> +    ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
> +    if (ret != ERR_OK) {
> +      udp_remove(pcb);
> +      return ret;
> +    }

This should be sent to lwip as well right?

>    }
>
>    tftp_state.handle    = NULL;
> --
> 2.40.1
>

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Jerome Forissier Oct. 4, 2024, 9:07 a.m. UTC | #2
On 10/4/24 08:11, Ilias Apalodimas wrote:
> Hi Jerome,
> 
> On Thu, 3 Oct 2024 at 18:47, Jerome Forissier
> <jerome.forissier@linaro.org> wrote:
>>
>> The TFTP app should not bind to the TFTP server port when configured as
>> a client. Instead, the local port should be chosen from the dynamic
>> range (49152 ~ 65535) so that if the application is stopped and started
>> again, the remote server will not consider the new packets as part of
>> the same context (which would cause an error since a new RRQ would be
>> unexpected).
>>
>> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
>> ---
>>  lib/lwip/lwip/src/apps/tftp/tftp.c | 10 ++++++----
>>  1 file changed, 6 insertions(+), 4 deletions(-)
>>
>> diff --git a/lib/lwip/lwip/src/apps/tftp/tftp.c b/lib/lwip/lwip/src/apps/tftp/tftp.c
>> index ddfdbfc0c1b..74fc1fbe586 100644
>> --- a/lib/lwip/lwip/src/apps/tftp/tftp.c
>> +++ b/lib/lwip/lwip/src/apps/tftp/tftp.c
>> @@ -454,10 +454,12 @@ tftp_init_common(u8_t mode, const struct tftp_context *ctx)
>>      return ERR_MEM;
>>    }
>>
>> -  ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
>> -  if (ret != ERR_OK) {
>> -    udp_remove(pcb);
>> -    return ret;
>> +  if (mode == LWIP_TFTP_MODE_SERVER) {
>> +    ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
>> +    if (ret != ERR_OK) {
>> +      udp_remove(pcb);
>> +      return ret;
>> +    }
> 
> This should be sent to lwip as well right?

Yes: https://savannah.nongnu.org/patch/?10480

Link added to the patch description.

> 
>>    }
>>
>>    tftp_state.handle    = NULL;
>> --
>> 2.40.1
>>
> 
> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

Thanks,
diff mbox series

Patch

diff --git a/lib/lwip/lwip/src/apps/tftp/tftp.c b/lib/lwip/lwip/src/apps/tftp/tftp.c
index ddfdbfc0c1b..74fc1fbe586 100644
--- a/lib/lwip/lwip/src/apps/tftp/tftp.c
+++ b/lib/lwip/lwip/src/apps/tftp/tftp.c
@@ -454,10 +454,12 @@  tftp_init_common(u8_t mode, const struct tftp_context *ctx)
     return ERR_MEM;
   }
 
-  ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
-  if (ret != ERR_OK) {
-    udp_remove(pcb);
-    return ret;
+  if (mode == LWIP_TFTP_MODE_SERVER) {
+    ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
+    if (ret != ERR_OK) {
+      udp_remove(pcb);
+      return ret;
+    }
   }
 
   tftp_state.handle    = NULL;