Skip to content

Commit

Permalink
IP6NDSolicitor: Make batch compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarbette committed Feb 20, 2025
1 parent fd993f5 commit 2e36e21
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
52 changes: 43 additions & 9 deletions elements/ethernet/ip6ndsolicitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,14 @@ IP6NDSolicitor::send_query_for(const u_char want_ip6[16])
ea->checksum = htons(in6_fast_cksum(&ip6->ip6_src, &ip6->ip6_dst, ip6->ip6_plen, ip6->ip6_nxt, 0, (unsigned char *)(ip6+1), htons(sizeof(click_nd_sol))));

_arp_queries++;
output(noutputs()-1).push(q);
#if HAVE_BATCH
if (in_batch_mode) {
output_push_batch(noutputs()-1,PacketBatch::make_from_packet(q));
} else
#endif
{
output(noutputs()-1).push(q);
}
}

/*
Expand All @@ -191,7 +198,7 @@ IP6NDSolicitor::send_query_for(const u_char want_ip6[16])
* May save the packet in the NDEntry table for later sending.
* May call p->kill().
*/
void
Packet*
IP6NDSolicitor::handle_ip6(Packet *p)
{
IP6Address ipa = DST_IP6_ANNO(p);
Expand All @@ -212,11 +219,11 @@ IP6NDSolicitor::handle_ip6(Packet *p)
memcpy(e->ether_shost, _my_en.data(), 6);
memcpy(e->ether_dhost, ae->en.data(), 6);
e->ether_type = htons(ETHERTYPE_IP6);
output(0).push(q);
return q;
} else {
if (ae->p) {
ae->p->kill();
_pkts_killed++;
_pkts_killed++;
}
ae->p = p;
send_query_for(DST_IP6_ANNO(p).data());
Expand All @@ -232,14 +239,15 @@ IP6NDSolicitor::handle_ip6(Packet *p)

send_query_for(DST_IP6_ANNO(p).data());
}
return 0;
}

/*
* Got an Neighborhood Advertisement (response to N. Solicitation Message)
* Update our NDEntry table.
* If there was a packet waiting to be sent, return it.
*/
void
Packet*
IP6NDSolicitor::handle_response(Packet *p)
{
if (p->length() < sizeof(click_ether) + sizeof(click_ip6) + sizeof(click_nd_sol))
Expand Down Expand Up @@ -270,22 +278,48 @@ IP6NDSolicitor::handle_response(Packet *p)
Packet *cached_packet = ae->p;
ae->p = 0;

if (cached_packet){
handle_ip6(cached_packet);}
if (cached_packet) {
return handle_ip6(cached_packet);
}
}
return 0;
}

void
IP6NDSolicitor::push(int port, Packet *p)
{
if (port == 0){
handle_ip6(p); }
Packet* p = handle_ip6(p);
if (p)
output_push(0, p);
}
else {
handle_response(p);
Packet* q = handle_response(p);
if (q)
output_push(0, q);
p->kill();
}
}

#if HAVE_BATCH
void
IP6NDSolicitor::push_batch(int port, PacketBatch *batch)
{
auto fnt = [this,port](Packet* p) -> Packet* {
if (port == 0){
return handle_ip6(p);
} else {
Packet* q = handle_response(p);
p->kill();
return q;
}
};
EXECUTE_FOR_EACH_PACKET_DROPPABLE(fnt, batch);
if (batch)
output_push_batch(0, batch);
}
#endif

String
IP6NDSolicitor::read_table(Element *e, void *)
{
Expand Down
11 changes: 7 additions & 4 deletions elements/ethernet/ip6ndsolicitor.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef CLICK_IP6NDSOLICITOR_HH
#define CLICK_IP6NDSOLICITOR_HH
#include <click/element.hh>
#include <click/batchelement.hh>
#include <click/etheraddress.hh>
#include <click/ip6address.hh>
#include <click/timer.hh>
Expand Down Expand Up @@ -47,7 +47,7 @@ CLICK_DECLS
* IP6NDAdvertiser
*/

class IP6NDSolicitor : public Element {
class IP6NDSolicitor : public BatchElement {
public:

IP6NDSolicitor();
Expand All @@ -66,6 +66,9 @@ class IP6NDSolicitor : public Element {
void take_state(Element *, ErrorHandler *);

void push(int port, Packet *);
#if HAVE_BATCH
void push_batch(int port, PacketBatch *);
#endif

Packet *make_query(unsigned char tpa[16],
unsigned char sha[6], unsigned char spa[16]);
Expand Down Expand Up @@ -96,8 +99,8 @@ class IP6NDSolicitor : public Element {

void send_query_for(const u_char want_ip6[16]);

void handle_ip6(Packet *);
void handle_response(Packet *);
Packet* handle_ip6(Packet *);
Packet* handle_response(Packet *);

enum { EXPIRE_TIMEOUT_MS = 15 * 1000 };
static void expire_hook(Timer *, void *);
Expand Down

0 comments on commit 2e36e21

Please sign in to comment.