[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] Re: [lwip] changes in IP/UDP for DHCP
From: |
Adam Dunkels |
Subject: |
[lwip-users] Re: [lwip] changes in IP/UDP for DHCP |
Date: |
Wed, 08 Jan 2003 22:11:44 -0000 |
Hi Leon!
On Wednesday 09 January 2002 16.15, you wrote:
> 1) DHCP
>
> I had to put in some "holes" in the IP and UDP code in order to
> let through DHCP packets from a DHCP server. Why? See here:
>
> A DHCP server sets iphdr->dest *as if* the client was already
> configured to use this address. Below, I've added the interface to
> use 192.168.0.10 in lwIP, I then started my lwIP DHCP client on this
> interface. The typical first REQUEST and REPLY looks like this
> (192.168.0.1 is my DHCP server):
[...]
> 1.1) Changes to ip.c for DHCP
Fixed!
> 1.2) Changes to udp.c for DHCP
>
> --begin--
>
> for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
> DEBUGF(UDP_DEBUG, ("udp_input: pcb local port %d (dgram %d)\n",
> pcb->local_port, udphdr->dest));
> if(pcb->local_port == udphdr->dest &&
> (ip_addr_isany(&pcb->dest_ip) ||
> ip_addr_cmp(&(pcb->dest_ip), &(iphdr->src))) &&
> (ip_addr_isany(&pcb->local_ip) ||
> ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) {
> pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src), udphdr->src);
> return;
> }
> #if (LWIP_DHCP > 0)
> // pcb that accepts DHCP msg from DHCP server port?
> if((pcb->local_port == udphdr->dest) && (udphdr->src ==
> DHCP_SERVER_PORT))
> {
> return;
> }
> #endif
> }
>
> --end--
Is this really necessary? The DHCP client should have a UDP PCB in the list
anyway (with the IP addresses left unspecified, i.e., ip_addr_isany(pcb->ips)
== 1).
> 2) Speed improvement in 0.5.0
>
> In ip.c/ip_input(), you first search for a network interface
> matching the incoming packet.
>
> After that, you decide whether to drop packets (bad checksum,
> options present).
>
> I think this order can be reversed. This spares the netinf
> search in case of unsupported packets.
No, it shouldn't be done that way since a fragmented packet could be
forwarded. We therefore need to check the destination before dropping it
based on what kind of packets lwIP is able to handle. The IP checksum can be
checked either before or after we decide if we need to forward the packet,
but really should be done before forwarding (so that we don't forward broken
packets).
The funny thing is that I already had swapped the order in the manner you
suggest, but now that I thought of it again, it became clear that it was
flawed ;-)
Thanks for your input!
/adam
--
Adam Dunkels <address@hidden>
http://www.sics.se/~adam
[This message was sent through the lwip discussion list.]