From c2fea58ce74361f355bedc3ab580a514d615809f Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Thu, 16 Jul 2009 15:02:53 -0700 Subject: [PATCH] Fix DHCP request source port and add port #define's DHCP requests were sent with a source port of 66, when it should be 68. This code has been tested, so apparently many DHCP servers don't pay attention to the source port. This commit also adds #define's for the DHCP ports, so that magic numbers don't need to be used. --- lib/dhcp-client.c | 6 +++--- lib/dhcp.h | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/dhcp-client.c b/lib/dhcp-client.c index 06937ec6..9057121d 100644 --- a/lib/dhcp-client.c +++ b/lib/dhcp-client.c @@ -923,7 +923,7 @@ do_receive_msg(struct dhclient *cli, struct dhcp_msg *msg) flow_extract(&b, 0, &flow); if (flow.dl_type != htons(ETH_TYPE_IP) || flow.nw_proto != IP_TYPE_UDP - || flow.tp_dst != htons(68) + || flow.tp_dst != htons(DHCP_CLIENT_PORT) || !(eth_addr_is_broadcast(flow.dl_dst) || eth_addr_equals(flow.dl_dst, netdev_get_etheraddr(cli->netdev)))) { @@ -1006,8 +1006,8 @@ do_send_msg(struct dhclient *cli, const struct dhcp_msg *msg) nh.ip_dst = INADDR_BROADCAST; nh.ip_csum = csum(&nh, sizeof nh); - th.udp_src = htons(66); - th.udp_dst = htons(67); + th.udp_src = htons(DHCP_CLIENT_PORT); + th.udp_dst = htons(DHCP_SERVER_PORT); th.udp_len = htons(UDP_HEADER_LEN + b.size); th.udp_csum = 0; udp_csum = csum_add32(0, nh.ip_src); diff --git a/lib/dhcp.h b/lib/dhcp.h index 07452c91..96696a24 100644 --- a/lib/dhcp.h +++ b/lib/dhcp.h @@ -24,6 +24,10 @@ struct ds; struct ofpbuf; +/* Ports used by DHCP. */ +#define DHCP_SERVER_PORT 67 /* Port used by DHCP server. */ +#define DHCP_CLIENT_PORT 68 /* Port used by DHCP client. */ + /* Values for 'op' field. */ #define DHCP_BOOTREQUEST 1 /* Message sent by DHCP client. */ #define DHCP_BOOTREPLY 2 /* Message sent by DHCP server. */ -- 2.30.2