Skip to content

Commit

Permalink
api: add node with name instead of edge
Browse files Browse the repository at this point in the history
Reduce boiler plate code when we add new ether proto or ip proto.

- gr_eth_input_add_type
- ip_input_local_add_proto

Signed-off-by: Christophe Fontaine <cfontain@redhat.com>
  • Loading branch information
christophefontaine committed Jul 9, 2024
1 parent e7e19ba commit 1103268
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 20 deletions.
5 changes: 4 additions & 1 deletion modules/infra/datapath/eth_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ enum {

static rte_edge_t l2l3_edges[1 << 16] = {UNKNOWN_ETHER_TYPE};

void gr_eth_input_add_type(rte_be16_t eth_type, rte_edge_t edge) {
void gr_eth_input_add_type(rte_be16_t eth_type, const char *node_name) {
rte_edge_t edge = gr_node_attach_parent("eth_input", node_name);
if (edge == RTE_EDGE_ID_INVALID)
ABORT("gr_node_attach_parent(eth_input, %s) failed", node_name);
l2l3_edges[eth_type] = edge;
LOG(DEBUG, "eth_input: type=0x%04x -> edge %u", rte_be_to_cpu_16(eth_type), edge);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/infra/datapath/gr_eth_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

GR_MBUF_PRIV_DATA_TYPE(eth_input_mbuf_data, { const struct iface *iface; });

void gr_eth_input_add_type(rte_be16_t eth_type, rte_edge_t edge);
void gr_eth_input_add_type(rte_be16_t eth_type, const char *node_name);

#endif
5 changes: 1 addition & 4 deletions modules/ip/datapath/arp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ arp_input_process(struct rte_graph *graph, struct rte_node *node, void **objs, u
}

static void arp_input_register(void) {
rte_edge_t edge = gr_node_attach_parent("eth_input", "arp_input");
if (edge == RTE_EDGE_ID_INVALID)
ABORT("gr_node_attach_parent(eth_input, arp_input) failed");
gr_eth_input_add_type(rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP), edge);
gr_eth_input_add_type(rte_cpu_to_be_16(RTE_ETHER_TYPE_ARP), "arp_input");
}

static struct rte_node_register node = {
Expand Down
2 changes: 1 addition & 1 deletion modules/ip/datapath/gr_ip4_datapath.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ GR_MBUF_PRIV_DATA_TYPE(ip_local_mbuf_data, {
uint8_t proto;
});

void ip_input_local_add_proto(uint8_t proto, rte_edge_t edge);
void ip_input_local_add_proto(uint8_t proto, const char *node_name);
void ip_output_add_tunnel(uint16_t iface_type_id, rte_edge_t edge);
int arp_output_request_solicit(struct nexthop *nh);

Expand Down
5 changes: 1 addition & 4 deletions modules/ip/datapath/icmp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ icmp_input_process(struct rte_graph *graph, struct rte_node *node, void **objs,
}

static void icmp_input_register(void) {
rte_edge_t edge = gr_node_attach_parent("ip_input_local", "icmp_input");
if (edge == RTE_EDGE_ID_INVALID)
ABORT("gr_node_attach_parent(classify, icmp_input) failed");
ip_input_local_add_proto(IPPROTO_ICMP, edge);
ip_input_local_add_proto(IPPROTO_ICMP, "icmp_input");
}

static struct rte_node_register icmp_input_node = {
Expand Down
5 changes: 1 addition & 4 deletions modules/ip/datapath/ip_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ ip_input_process(struct rte_graph *graph, struct rte_node *node, void **objs, ui
}

static void ip_input_register(void) {
rte_edge_t edge = gr_node_attach_parent("eth_input", "ip_input");
if (edge == RTE_EDGE_ID_INVALID)
ABORT("gr_node_attach_parent(eth_input, ip_input) failed");
gr_eth_input_add_type(rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4), edge);
gr_eth_input_add_type(rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4), "ip_input");
}

static struct rte_node_register input_node = {
Expand Down
5 changes: 4 additions & 1 deletion modules/ip/datapath/ip_local.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
#define UNKNOWN_PROTO 0
static rte_edge_t edges[256] = {UNKNOWN_PROTO};

void ip_input_local_add_proto(uint8_t proto, rte_edge_t edge) {
void ip_input_local_add_proto(uint8_t proto, const char *node_name) {
rte_edge_t edge = gr_node_attach_parent("ip_input_local", node_name);
if (edge == RTE_EDGE_ID_INVALID)
ABORT("gr_node_attach_parent(ip_input_local, %s) failed", node_name);
edges[proto] = edge;
LOG(DEBUG, "ip_input_local: proto=%u -> edge %u", proto, edge);
}
Expand Down
5 changes: 1 addition & 4 deletions modules/ipip/datapath_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ ipip_input_process(struct rte_graph *graph, struct rte_node *node, void **objs,
}

static void ipip_input_register(void) {
rte_edge_t edge = gr_node_attach_parent("ip_input_local", "ipip_input");
if (edge == RTE_EDGE_ID_INVALID)
ABORT("gr_node_attach_parent(ip_input_local, ipip_input) failed");
ip_input_local_add_proto(IPPROTO_IPIP, edge);
ip_input_local_add_proto(IPPROTO_IPIP, "ipip_input");
}

static struct rte_node_register ipip_input_node = {
Expand Down

0 comments on commit 1103268

Please sign in to comment.