From fab107a9dfd03d6620b5d074afd27ca6645f25f5 Mon Sep 17 00:00:00 2001 From: likewise Date: Thu, 25 Nov 2004 11:10:53 +0000 Subject: [PATCH] DECLINE message was unicast instead of broadcast --- src/core/dhcp.c | 6 ++++-- src/core/udp.c | 9 ++++++--- src/include/ipv4/lwip/ip_addr.h | 8 ++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/core/dhcp.c b/src/core/dhcp.c index 69337567..2a9c1887 100644 --- a/src/core/dhcp.c +++ b/src/core/dhcp.c @@ -679,8 +679,10 @@ static err_t dhcp_decline(struct netif *netif) pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); - udp_connect(dhcp->pcb, &dhcp->server_ip_addr, DHCP_SERVER_PORT); - udp_send(dhcp->pcb, dhcp->p_out); + /* @todo: should we really connect here? we are performing sendto() */ + udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); + /* per section 4.4.4, broadcast DECLINE messages */ + udp_sendto(dhcp->pcb, dhcp->p_out, IP_ADDR_BROADCAST, DHCP_SERVER_PORT); dhcp_delete_request(netif); LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_decline: BACKING OFF\n")); } else { diff --git a/src/core/udp.c b/src/core/udp.c index 43fae895..8343d34d 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -356,9 +356,10 @@ udp_sendto(struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *dst_ip, u16_t dst_port) { err_t err; + /* temporary space for current PCB remote address */ struct ip_addr pcb_remote_ip; u16_t pcb_remote_port; - /* remember remote peer address of PCB */ + /* remember current remote peer address of PCB */ pcb_remote_ip.addr = pcb->remote_ip.addr; pcb_remote_port = pcb->remote_port; /* copy packet destination address to PCB remote peer address */ @@ -366,7 +367,7 @@ udp_sendto(struct udp_pcb *pcb, struct pbuf *p, pcb->remote_port = dst_port; /* send to the packet destination address */ err = udp_send(pcb, p); - /* reset PCB remote peer address */ + /* restore PCB remote peer address */ pcb->remote_ip.addr = pcb_remote_ip.addr; pcb->remote_port = pcb_remote_port; return err; @@ -433,7 +434,9 @@ udp_send(struct udp_pcb *pcb, struct pbuf *p) udphdr->chksum = 0x0000; /* find the outgoing network interface for this packet */ - if ((netif = ip_route(&(pcb->remote_ip))) == NULL) { + netif = ip_route(&(pcb->remote_ip)); + /* no outgoing network interface could be found? */ + if (netif == NULL) { LWIP_DEBUGF(UDP_DEBUG | 1, ("udp_send: No route to 0x%lx\n", pcb->remote_ip.addr)); UDP_STATS_INC(udp.rterr); return ERR_RTE; diff --git a/src/include/ipv4/lwip/ip_addr.h b/src/include/ipv4/lwip/ip_addr.h index 7ac4954b..58820bdf 100644 --- a/src/include/ipv4/lwip/ip_addr.h +++ b/src/include/ipv4/lwip/ip_addr.h @@ -117,6 +117,14 @@ extern const struct ip_addr ip_addr_broadcast; #define ip_addr_set(dest, src) (dest)->addr = \ ((src) == NULL? 0:\ (src)->addr) +/** + * Determine if two address are on the same network. + * + * @arg addr1 IP address 1 + * @arg addr2 IP address 2 + * @arg mask network identifier mask + * @return !0 if the network identifiers of both address match + */ #define ip_addr_maskcmp(addr1, addr2, mask) (((addr1)->addr & \ (mask)->addr) == \ ((addr2)->addr & \