Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/ip/dhcpv4: Set source IP address for DHCP renewal requests #15179

Merged
merged 1 commit into from
Apr 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions subsys/net/ip/dhcpv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,22 @@ static inline bool dhcpv4_add_sname(struct net_pkt *pkt)
/* Create DHCPv4 message and add options as per message type */
static struct net_pkt *dhcpv4_create_message(struct net_if *iface, u8_t type,
const struct in_addr *ciaddr,
const struct in_addr *src_addr,
const struct in_addr *server_addr,
bool server_id, bool requested_ip)
{
NET_PKT_DATA_ACCESS_DEFINE(dhcp_access, struct dhcp_msg);
const struct in_addr src = INADDR_ANY_INIT;
const struct in_addr *addr;
size_t size = DHCPV4_MESSAGE_SIZE;
struct net_pkt *pkt;
struct dhcp_msg *msg;

if (src_addr == NULL) {
addr = net_ipv4_unspecified_address();
} else {
addr = src_addr;
}

if (server_id) {
size += DHCPV4_OLV_MSG_SERVER_ID;
}
Expand All @@ -176,7 +183,7 @@ static struct net_pkt *dhcpv4_create_message(struct net_if *iface, u8_t type,

net_pkt_set_ipv4_ttl(pkt, 0xFF);

if (net_ipv4_create(pkt, &src, server_addr) ||
if (net_ipv4_create(pkt, addr, server_addr) ||
net_udp_create(pkt, htons(DHCPV4_CLIENT_PORT),
htons(DHCPV4_SERVER_PORT))) {
goto fail;
Expand Down Expand Up @@ -247,6 +254,7 @@ static u32_t dhcpv4_send_request(struct net_if *iface)
{
const struct in_addr *server_addr = net_ipv4_broadcast_address();
const struct in_addr *ciaddr = NULL;
const struct in_addr *src_addr = NULL;
bool with_server_id = false;
bool with_requested_ip = false;
struct net_pkt *pkt;
Expand All @@ -273,6 +281,7 @@ static u32_t dhcpv4_send_request(struct net_if *iface)
ciaddr = &iface->config.dhcpv4.requested_ip;

/* UNICAST the DHCPREQUEST */
src_addr = ciaddr;
server_addr = &iface->config.dhcpv4.server_id;

/* RFC2131 4.4.5 Client MUST NOT include server
Expand All @@ -283,13 +292,14 @@ static u32_t dhcpv4_send_request(struct net_if *iface)
/* Since we have an address populate the ciaddr field.
*/
ciaddr = &iface->config.dhcpv4.requested_ip;
src_addr = ciaddr;

break;
}

pkt = dhcpv4_create_message(iface, DHCPV4_MSG_TYPE_REQUEST,
ciaddr, server_addr, with_server_id,
with_requested_ip);
ciaddr, src_addr, server_addr,
with_server_id, with_requested_ip);
if (!pkt) {
goto fail;
}
Expand Down Expand Up @@ -333,7 +343,7 @@ static u32_t dhcpv4_send_discover(struct net_if *iface)
iface->config.dhcpv4.xid++;

pkt = dhcpv4_create_message(iface, DHCPV4_MSG_TYPE_DISCOVER,
NULL, net_ipv4_broadcast_address(),
NULL, NULL, net_ipv4_broadcast_address(),
false, false);
if (!pkt) {
goto fail;
Expand Down