lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] TFTP client - Accepting UDP packets with random source port


From: Peter Tyser
Subject: [lwip-users] TFTP client - Accepting UDP packets with random source port number
Date: Thu, 31 Aug 2006 12:38:46 -0500

Hello,
I've integrated lwip into a custom firmware/booloader and have written a
simple TFTP client using the raw api.  I ran into a problem concerning
the TFTP protocol and lwip's UDP implementation.  A typical TFTP
transaction goes something like:

client: send read/write request to server, dst port=69, src
port=<client's randomly chosen port>

server: send response to client, dst port=<client's randomly chosen src
port number>, src port=<server's randomly chosen port>

data transfers follow....



The problem I'm having is how to best have my lwip-based client accept
the server's response which uses a randomly chosen src port.  Since I
don't know the server's src port ahead of time, I cannot use the
udp_connect() function to associate my tftp pcb's remote_port with the
server's randomly chosen port number.

The code from udp_input() in udp.c below is what I believe is causing my
problem.  The TFTP handler is never called since the tftp pcb is never
matched due to the incorrect remote_port value.

...

/* compare PCB remote addr+port to UDP source addr+port */
if ((local_match != 0) &&
    (pcb->remote_port == src) &&       <=== problem here
    (ip_addr_isany(&pcb->remote_ip) ||
    ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)))) {
      /* the first fully matching PCB */
      break;
}

...


The 2 possible solutions I came up with were to
1. Use the raw_* functions for the initial server response until I know
the server's port number when I would then reconnect using the udp_*
functions.  This would require more complicated logic in the TFTP
client, but I think would work with the existing lwip implementation.

2. Add a UDP_PORT_ANY define which can be used to associate a udp pcb
with any port number.  Adding this would allow my TFTP client to receive
the initial server response, then reconnect my udp_pcb to its randomly
chosen src port.  This would require a change similar to the following
to the above code section:

/* compare PCB remote addr+port to UDP source addr+port */
if ((local_match != 0) &&
    ((pcb->remote_port == src) || (pcb->remote_port == UDP_PORT_ANY)) &&
     (ip_addr_isany(&pcb->remote_ip) ||
     ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)))) {
       /* the first fully matching PCB */
       break;
}


I'm not all that familiar with lwip and may be missing something simple,
so if anyone has any suggestions or comments, they would be greatly
appreciated.  Many thanks to the lwip team - its a great project.

Thanks,
Peter Tyser






reply via email to

[Prev in Thread] Current Thread [Next in Thread]