@@ -19,9 +19,12 @@ CommandResponse ArpResponder::CommandAdd(const bess::pb::ArpResponderArg &arg) {
1919 return CommandFailure (EINVAL , " Invalid IP Address: %s" , arg.ip ().c_str ());
2020 }
2121
22- entry.mac_addr .FromString (arg.mac_addr ());
22+ if (!entry.mac_addr .FromString (arg.mac_addr ())) {
23+ return CommandFailure (EINVAL , " Invalid MAC Address: %s" , arg.mac_addr ().c_str ());
24+ }
25+
2326 entry.ip_addr = ip_addr;
24- entries [ip_addr] = entry;
27+ entries_ [ip_addr] = entry;
2528 return CommandSuccess ();
2629}
2730
@@ -44,27 +47,27 @@ void ArpResponder::ProcessBatch(bess::PacketBatch *batch) {
4447
4548 Arp *arp = reinterpret_cast <Arp *>(eth + 1 );
4649 if (arp->opcode == be16_t (Arp::Opcode::kRequest )) {
47- // TODO When learn is added, learn SRC MAC here
50+ // TODO(galsagie) When learn is added, learn SRC MAC here
4851
4952 // Try to find target IP in cache, if exists convert request to reply
50- auto it = entries .find (arp->target_ip_addr );
51- if (it != entries .end ()) {
52- struct arp_entry * entry = & it->second ;
53+ auto it = entries_ .find (arp->target_ip_addr );
54+ if (it != entries_ .end ()) {
55+ const struct arp_entry & entry = it->second ;
5356 arp->opcode = be16_t (Arp::Opcode::kReply );
5457
5558 eth->dst_addr = eth->src_addr ;
56- eth->src_addr = entry-> mac_addr ;
59+ eth->src_addr = entry. mac_addr ;
5760
5861 arp->target_hw_addr = arp->sender_hw_addr ;
59- arp->sender_hw_addr = entry-> mac_addr ;
62+ arp->sender_hw_addr = entry. mac_addr ;
6063
6164 arp->target_ip_addr = arp->sender_ip_addr ;
62- arp->sender_ip_addr = entry-> ip_addr ;
65+ arp->sender_ip_addr = entry. ip_addr ;
6366 }
6467 } else if (arp->opcode == be16_t (Arp::Opcode::kReply )) {
65- // TODO When learn is added, learn SRC MAC here
68+ // TODO(galsagie) When learn is added, learn SRC MAC here
6669 } else {
67- // TODO Other opcodes are not handled yet.
70+ // TODO(galsagie) Other opcodes are not handled yet.
6871 }
6972 }
7073
0 commit comments