Skip to content

Commit

Permalink
ip/arp: use generic ctlplane to datapath
Browse files Browse the repository at this point in the history
Signed-off-by: Christophe Fontaine <cfontain@redhat.com>
  • Loading branch information
christophefontaine committed Jul 6, 2024
1 parent 589d26a commit 1ff3868
Showing 1 changed file with 16 additions and 43 deletions.
59 changes: 16 additions & 43 deletions modules/ip/datapath/arp_output_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <gr_ip4_control.h>
#include <gr_ip4_datapath.h>
#include <gr_log.h>
#include <gr_slow_path.h>

#include <rte_arp.h>
#include <rte_byteorder.h>
Expand All @@ -26,53 +27,50 @@ enum {
EDGE_COUNT,
};

static struct rte_ring *nexthop_ring;

int arp_output_request_solicit(struct nexthop *nh) {
int ret;
if (nh == NULL)
return errno_set(EINVAL);
ip4_nexthop_incref(nh);
ret = rte_ring_enqueue(nexthop_ring, nh);
ret = slow_path_post(RTE_ETHER_TYPE_LLDP, sizeof(nh), (void *)&nh);
if (ret < 0) {
ip4_nexthop_decref(nh);
return errno_set(-ret);
}
return 0;
}

static struct rte_mempool *arp_pool;

static uint16_t
arp_output_request_process(struct rte_graph *graph, struct rte_node *node, void **, uint16_t) {
static uint16_t arp_output_request_process(
struct rte_graph *graph,
struct rte_node *node,
void **objs,
uint16_t n_objs
) {
struct eth_output_mbuf_data *eth_data;
struct gr_slow_path_msg *msg;
struct nexthop *local, *nh;
struct rte_arp_hdr *arp;
struct rte_mbuf *mbuf;
rte_edge_t next;
uint16_t sent;
uint64_t now;
unsigned n;

now = rte_get_tsc_cycles();
n = rte_ring_dequeue_burst(nexthop_ring, node->objs, RTE_GRAPH_BURST_SIZE, NULL);
sent = 0;

for (unsigned i = 0; i < n; i++) {
nh = node->objs[i];
for (unsigned i = 0; i < n_objs; i++) {
mbuf = objs[i];
msg = rte_pktmbuf_mtod(mbuf, struct gr_slow_path_msg *);
nh = *(struct nexthop **)msg->payload;

// Create a brand new mbuf to hold the ARP request.
mbuf = rte_pktmbuf_alloc(arp_pool);
if (mbuf == NULL) {
next = ERROR;
goto next;
}
local = ip4_addr_get(nh->iface_id);
if (local == NULL) {
next = ERROR;
goto next;
}

rte_pktmbuf_reset(mbuf);

// Set all ARP request fields. TODO: upstream this in dpdk.
arp = (struct rte_arp_hdr *)rte_pktmbuf_append(mbuf, sizeof(struct rte_arp_hdr));
arp->arp_hardware = rte_cpu_to_be_16(RTE_ARP_HRD_ETHER);
Expand Down Expand Up @@ -115,34 +113,10 @@ arp_output_request_process(struct rte_graph *graph, struct rte_node *node, void
}

static void arp_output_request_register(void) {
nexthop_ring = rte_ring_create(
"arp_output_request",
RTE_GRAPH_BURST_SIZE * 4,
SOCKET_ID_ANY,
RING_F_MP_RTS_ENQ | RING_F_MC_RTS_DEQ
);
if (nexthop_ring == NULL)
ABORT("rte_ring_create(arp_output_request): %s", rte_strerror(rte_errno));

arp_pool = rte_pktmbuf_pool_create(
"arp_output_request",
RTE_GRAPH_BURST_SIZE * 4,
256, // cache_size
0, // priv_size
RTE_MBUF_DEFAULT_BUF_SIZE,
SOCKET_ID_ANY
);
if (arp_pool == NULL)
ABORT("rte_pktmbuf_pool_create(arp_output_request): %s", rte_strerror(rte_errno));
}

static void arp_output_request_unregister(void) {
rte_ring_free(nexthop_ring);
rte_mempool_free(arp_pool);
gr_slow_path_input_add_handler(RTE_ETHER_TYPE_IPV4, "arp_output_request");
}

static struct rte_node_register arp_output_request_node = {
.flags = RTE_NODE_SOURCE_F,
.name = "arp_output_request",
.process = arp_output_request_process,
.nb_edges = EDGE_COUNT,
Expand All @@ -155,7 +129,6 @@ static struct rte_node_register arp_output_request_node = {
static struct gr_node_info arp_output_request_info = {
.node = &arp_output_request_node,
.register_callback = arp_output_request_register,
.unregister_callback = arp_output_request_unregister,
};

GR_NODE_REGISTER(arp_output_request_info);
Expand Down

0 comments on commit 1ff3868

Please sign in to comment.