Skip to content

Commit

Permalink
Optimize tftp server option handling to store siaddr
Browse files Browse the repository at this point in the history
This fix allows to store siaddr in variable and restore it to
update DHCP.

Change-Id: I892f632a27b389899ac5691950324686990f634c
Partial-Bug: #1724595
  • Loading branch information
Sergey Matov committed Dec 25, 2017
1 parent 04425bf commit 8c8adff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/vnsw/agent/services/dhcp_handler.cc
Expand Up @@ -1023,20 +1023,9 @@ uint16_t DhcpHandler::DhcpHdr(in_addr_t yiaddr, in_addr_t siaddr) {
opt_len = AddDomainNameOption(opt_len);
}

// update dhcp siaddr with stored value
if (is_flag_set(DHCP_OPTION_TFTP_SERVER_NAME)) {
std::vector<autogen::DhcpOptionType> options;
vm_itf_->GetInterfaceDhcpOptions(&options);
for (unsigned int i = 0; i < options.size(); ++i) {
uint32_t option = OptionCode(options[i].dhcp_option_name);
if (option != DHCP_OPTION_TFTP_SERVER_NAME)
continue;
// handle DHCP_OPTION_TFTP_SERVER_NAME
boost::system::error_code ec;
Ip4Address siaddr =
Ip4Address::from_string(options[i].dhcp_option_value, ec);
if (ec.value() == 0)
dhcp_->siaddr = htonl(siaddr.to_ulong());
}
dhcp_->siaddr = siaddr_tftp_;
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/vnsw/agent/services/dhcp_handler_base.cc
Expand Up @@ -656,6 +656,15 @@ uint16_t DhcpHandlerBase::AddDhcpOptions(
break;
}

// store siaddr for tftp server name to apply it later
if (option == DHCP_OPTION_TFTP_SERVER_NAME) {
boost::system::error_code ec;
Ip4Address siaddr =
Ip4Address::from_string(options[i].dhcp_option_value, ec);
if (ec.value() == 0)
siaddr_tftp_ = htonl(siaddr.to_ulong());
}

if (opt_len != old_opt_len)
set_flag(option);
}
Expand Down
3 changes: 3 additions & 0 deletions src/vnsw/agent/services/dhcp_handler_base.h
Expand Up @@ -159,6 +159,9 @@ class DhcpHandlerBase : public ProtoHandler {
autogen::IpamType ipam_type_;
autogen::VirtualDnsType vdns_type_;

// siaddr for tftp used for baremetal deployment
uint32_t siaddr_tftp_;

DISALLOW_COPY_AND_ASSIGN(DhcpHandlerBase);
};

Expand Down

0 comments on commit 8c8adff

Please sign in to comment.