lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] [lwip] changes in IP/UDP for DHCP


From: leon . woestenberg
Subject: [lwip-users] [lwip] changes in IP/UDP for DHCP
Date: Wed, 08 Jan 2003 22:51:43 -0000

Hello Adam,

pretty long email, so a table of contents here:

1) DHCP
1.1) typical DHCP msg
1.2) changes necessary to ip.c
1.3) changes necessary to udp.c
2) speed improvement in 0.5.0 ip.c/ip_input()


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):

-----
Ethernet II
    Destination: ff:ff:ff:ff:ff:ff (ff:ff:ff:ff:ff:ff)
    Source: 00:03:41:bb:aa:dd (00:03:41:bb:aa:dd)
    Type: IP (0x0800)
Internet Protocol
    Protocol: UDP (0x11)
    Source: 192.168.0.10 (192.168.0.10)
    Destination: 255.255.255.255 (255.255.255.255)
User Datagram Protocol
    Source port: 68 (68)
    Destination port: 67 (67)
Bootstrap Protocol
    Boot Request
    Hardware type: Ethernet
    Hardware address length: 6
    Hops: 0
    Transaction ID: 0x00000001
    Seconds elapsed: 0
    Broadcast flag: 0x0000
    Client IP address: 192.168.0.10 (192.168.0.10)
    Your (client) IP address: 0.0.0.0 (0.0.0.0)
    Next server IP address: 0.0.0.0 (0.0.0.0)
    Relay agent IP address: 0.0.0.0 (0.0.0.0)
    Client hardware address: 00:03:41:bb:aa:dd
    Server host name not given
    Boot file name not given
    Magic cookie: (OK)
    Option 53: DHCP Message Type = DHCP Discover
    Option 57: Maximum DHCP Message Size = 576
    Option 55: Parameter Request List
        1 = Subnet Mask
        3 = Router
        28 = Broadcast Address
    End Option
    Padding

Ethernet II
    Destination: 00:03:41:bb:aa:dd (00:03:41:bb:aa:dd)
    Source: 00:a0:24:c5:72:6d (00:a0:24:c5:72:6d)
    Type: IP (0x0800)
Internet Protocol
    Protocol: UDP (0x11)
    Source: 192.168.0.1 (192.168.0.1)
    Destination: 192.168.0.51 (192.168.0.51)   <------------- the NEW client's 
IP address, not 192.168.0.10
User Datagram Protocol
    Source port: 67 (67)
    Destination port: 68 (68)
Bootstrap Protocol
    Boot Reply
    Hardware type: Ethernet
    Hardware address length: 6
    Hops: 0
    Transaction ID: 0x00000001
    Seconds elapsed: 0
    Broadcast flag: 0x0000
    Client IP address: 192.168.0.10 (192.168.0.10)
    Your (client) IP address: 192.168.0.51 (192.168.0.51)
    Next server IP address: 192.168.0.1 (192.168.0.1)
    Relay agent IP address: 0.0.0.0 (0.0.0.0)
    Client hardware address: 00:03:41:bb:aa:dd
    Server host name not given
    Boot file name not given
    Magic cookie: (OK)
    Option 53: DHCP Message Type = DHCP Offer
    Option 54: Server Identifier = 192.168.0.1
    Option 51: IP Address Lease Time = 1 hour
    Option 1: Subnet Mask = 255.255.255.0
    Option 3: Router = 192.168.0.1
    End Option
    Padding
----


1.1) Changes to ip.c for DHCP

--start--
  /* is this packet for us? */
  for(netif = netif_list; netif != NULL; netif = netif->next) {
    ...
  }

// udp and dhcp enabled?
#if ((LWIP_UDP > 0) && (LWIP_DHCP > 0))
  // udp packet?
  if (IPH_PROTO(iphdr) == IP_PROTO_UDP)
     {
    struct udp_hdr *udphdr = (struct udp_hdr *)((char *)p->payload +
IP_HLEN);
    // from DHCP server udp port?
    if (udphdr->src == DHCP_SERVER_PORT)
    {
     // the interface the packet is meant for, is where it has arrived
     // on, as DHCP messages are addressed through the hardware address
     netif = inp;
    }
  } else
#endif

  if(netif == NULL) {
    /* packet not for us, route or discard */
  ...
--end--

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--

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.

Regards,


Leon Woestenberg.



[This message was sent through the lwip discussion list.]




reply via email to

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