Commit 3344e8b8 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[1230] Changes after review:

- Vector initialization clean-ups
- Typo in comment
parent a9f48f11
...@@ -169,9 +169,8 @@ void Dhcpv4Srv::copyDefaultFields(const boost::shared_ptr<Pkt4>& question, ...@@ -169,9 +169,8 @@ void Dhcpv4Srv::copyDefaultFields(const boost::shared_ptr<Pkt4>& question,
answer->setHops(question->getHops()); answer->setHops(question->getHops());
// copy MAC address // copy MAC address
vector<uint8_t> mac; vector<uint8_t> mac(question->getChaddr(),
mac.resize(Pkt4::MAX_CHADDR_LEN); question->getChaddr() + Pkt4::MAX_CHADDR_LEN);
memcpy(&mac[0], question->getChaddr(), Pkt4::MAX_CHADDR_LEN);
answer->setHWAddr(question->getHtype(), question->getHlen(), mac); answer->setHWAddr(question->getHtype(), question->getHlen(), mac);
// relay address // relay address
...@@ -230,6 +229,7 @@ void Dhcpv4Srv::assignLease(boost::shared_ptr<Pkt4>& msg) { ...@@ -230,6 +229,7 @@ void Dhcpv4Srv::assignLease(boost::shared_ptr<Pkt4>& msg) {
opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DHCP_LEASE_TIME)); opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DHCP_LEASE_TIME));
opt->setUint32(HARDCODED_LEASE_TIME); opt->setUint32(HARDCODED_LEASE_TIME);
msg->addOption(opt); msg->addOption(opt);
// TODO: create Option_IntArray that holds list of integers, similar to Option4_AddrLst
// Subnet mask (type 1) // Subnet mask (type 1)
opt = boost::shared_ptr<Option> opt = boost::shared_ptr<Option>
...@@ -247,8 +247,6 @@ Dhcpv4Srv::processDiscover(boost::shared_ptr<Pkt4>& discover) { ...@@ -247,8 +247,6 @@ Dhcpv4Srv::processDiscover(boost::shared_ptr<Pkt4>& discover) {
boost::shared_ptr<Pkt4> offer = boost::shared_ptr<Pkt4> boost::shared_ptr<Pkt4> offer = boost::shared_ptr<Pkt4>
(new Pkt4(DHCPOFFER, discover->getTransid())); (new Pkt4(DHCPOFFER, discover->getTransid()));
boost::shared_ptr<Option> opt;
copyDefaultFields(discover, offer); copyDefaultFields(discover, offer);
appendDefaultOptions(offer, DHCPOFFER); appendDefaultOptions(offer, DHCPOFFER);
appendRequestedOptions(offer); appendRequestedOptions(offer);
...@@ -263,29 +261,11 @@ Dhcpv4Srv::processRequest(boost::shared_ptr<Pkt4>& request) { ...@@ -263,29 +261,11 @@ Dhcpv4Srv::processRequest(boost::shared_ptr<Pkt4>& request) {
boost::shared_ptr<Pkt4> ack = boost::shared_ptr<Pkt4> boost::shared_ptr<Pkt4> ack = boost::shared_ptr<Pkt4>
(new Pkt4(DHCPACK, request->getTransid())); (new Pkt4(DHCPACK, request->getTransid()));
boost::shared_ptr<Option> opt;
copyDefaultFields(request, ack); copyDefaultFields(request, ack);
appendDefaultOptions(ack, DHCPACK); appendDefaultOptions(ack, DHCPACK);
appendRequestedOptions(ack); appendRequestedOptions(ack);
// TODO: Implement actual lease assignment here assignLease(ack);
ack->setYiaddr(IOAddress(HARDCODED_LEASE));
// IP Address Lease time (type 51)
opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DHCP_LEASE_TIME));
opt->setUint32(HARDCODED_LEASE_TIME);
ack->addOption(opt);
// TODO: create Option_IntArray that holds list of integers, similar to Option4_AddrLst
// Subnet mask (type 1)
opt = boost::shared_ptr<Option>
(new Option4AddrLst(DHO_SUBNET_MASK, IOAddress(HARDCODED_NETMASK)));
ack->addOption(opt);
// Router (type 3)
opt = boost::shared_ptr<Option>(new Option4AddrLst(DHO_ROUTERS, IOAddress(HARDCODED_GATEWAY)));
ack->addOption(opt);
return (ack); return (ack);
} }
......
...@@ -111,8 +111,7 @@ TEST_F(Dhcpv4SrvTest, basic) { ...@@ -111,8 +111,7 @@ TEST_F(Dhcpv4SrvTest, basic) {
TEST_F(Dhcpv4SrvTest, processDiscover) { TEST_F(Dhcpv4SrvTest, processDiscover) {
NakedDhcpv4Srv* srv = new NakedDhcpv4Srv(); NakedDhcpv4Srv* srv = new NakedDhcpv4Srv();
vector<uint8_t> mac; vector<uint8_t> mac(6);
mac.resize(6);
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
mac[i] = 255 - i; mac[i] = 255 - i;
} }
...@@ -170,8 +169,7 @@ TEST_F(Dhcpv4SrvTest, processDiscover) { ...@@ -170,8 +169,7 @@ TEST_F(Dhcpv4SrvTest, processDiscover) {
TEST_F(Dhcpv4SrvTest, processRequest) { TEST_F(Dhcpv4SrvTest, processRequest) {
NakedDhcpv4Srv* srv = new NakedDhcpv4Srv(); NakedDhcpv4Srv* srv = new NakedDhcpv4Srv();
vector<uint8_t> mac; vector<uint8_t> mac(6);
mac.resize(6);
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
mac[i] = i*10; mac[i] = i*10;
} }
......
...@@ -172,7 +172,7 @@ Pkt4::unpack() { ...@@ -172,7 +172,7 @@ Pkt4::unpack() {
size_t opts_len = bufferIn.getLength() - bufferIn.getPosition(); size_t opts_len = bufferIn.getLength() - bufferIn.getPosition();
vector<uint8_t> optsBuffer; vector<uint8_t> optsBuffer;
// fist use of readVector // First use of readVector.
bufferIn.readVector(optsBuffer, opts_len); bufferIn.readVector(optsBuffer, opts_len);
LibDHCP::unpackOptions4(optsBuffer, options_); LibDHCP::unpackOptions4(optsBuffer, options_);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment