Skip to content

Commit 103164b

Browse files
committed
Add ARP Responder module
Address code review comments, 1) Drop ARP packets in case no cache entry is found and not an ARP request 2) Update TODO's 3) Use 0 as the default incoming gate
1 parent b45491d commit 103164b

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

bessctl/conf/samples/arp.bess

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import scapy.all as scapy
22

33
eth_header = scapy.Ether(src='02:1e:67:9f:4d:ae', dst='ff:ff:ff:ff:ff:ff')
4-
arp_header = scapy.ARP(op=1, pdst='1.1.1.1')
4+
arp_header = scapy.ARP(op=1, pdst='1.2.3.4')
55
pkt = eth_header/arp_header
66
packets = [str(pkt)]
77

8-
arp = ArpResponder(name="arp")
9-
arp.add(ip='1.1.1.1', mac_addr='11:22:33:44:55:66')
8+
arp::ArpResponder()
9+
arp.add(ip='1.2.3.4', mac_addr='A0:22:33:44:55:66')
1010

1111
Source() -> Rewrite(templates=packets) -> arp -> Sink()

core/modules/arp_responder.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ CommandResponse ArpResponder::CommandAdd(const bess::pb::ArpResponderArg &arg) {
3131

3232
void ArpResponder::ProcessBatch(bess::PacketBatch *batch) {
3333
gate_idx_t out_gates[bess::PacketBatch::kMaxBurst];
34-
gate_idx_t incoming_gate = get_igate();
3534

3635
int cnt = batch->cnt();
3736
for (int i = 0; i < cnt; i++) {
3837
bess::Packet *pkt = batch->pkts()[i];
3938

40-
out_gates[i] = incoming_gate;
39+
out_gates[i] = 0;
4140

4241
Ethernet *eth = pkt->head_data<Ethernet *>();
4342
if (eth->ether_type != be16_t(Ethernet::Type::kArp)) {
@@ -64,11 +63,17 @@ void ArpResponder::ProcessBatch(bess::PacketBatch *batch) {
6463

6564
arp->target_ip_addr = arp->sender_ip_addr;
6665
arp->sender_ip_addr = entry.ip_addr;
66+
} else {
67+
// Did not find an ARP entry in cache, drop packet
68+
// TODO(galsagie) Optinally continue packet to next module here
69+
out_gates[i] = DROP_GATE;
6770
}
6871
} else if (arp->opcode == be16_t(Arp::Opcode::kReply)) {
6972
// TODO(galsagie) When learn is added, learn SRC MAC here
73+
out_gates[i] = DROP_GATE;
7074
} else {
7175
// TODO(galsagie) Other opcodes are not handled yet.
76+
out_gates[i] = DROP_GATE;
7277
}
7378
}
7479

protobuf/module_msg.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,8 @@ message WildcardMatchArg {
974974
}
975975

976976
/**
977-
* The ARP Responder module is responding to ARP requests and can optionally learn new MAC's-IP's mapping
977+
* The ARP Responder module is responding to ARP requests
978+
* TODO: Dynamic learn new MAC's-IP's mapping
978979
*
979980
* __Input Gates__: 1
980981
* __Output Gates__: 1

0 commit comments

Comments
 (0)