Skip to content

Commit 397e7e2

Browse files
infra: remove control_output_node
Remove all references to control output node and the associated code. This control_output node is no longer required as all features are implemented as nodes. Signed-off-by: Christophe Fontaine <[email protected]>
1 parent 018fc1a commit 397e7e2

File tree

19 files changed

+450
-661
lines changed

19 files changed

+450
-661
lines changed

docs/graph.svg

Lines changed: 340 additions & 376 deletions
Loading

modules/infra/control/control_output.c

Lines changed: 0 additions & 75 deletions
This file was deleted.

modules/infra/control/gr_loopback.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77

88
#include <rte_byteorder.h>
99

10-
void loopback_tx(struct rte_mbuf *m);
1110
control_input_t loopback_get_control_id(void);
1211
void loopback_input_add_type(rte_be16_t eth_type, const char *next_node);
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2024 Christophe Fontaine
3+
4+
#include "loopback.h"
5+
6+
#include <gr_graph.h>
7+
#include <gr_infra.h>
8+
#include <gr_ip4_datapath.h>
9+
#include <gr_ip6_datapath.h>
10+
#include <gr_log.h>
11+
#include <gr_loopback.h>
12+
#include <gr_trace.h>
13+
14+
#include <rte_malloc.h>
15+
16+
#include <linux/if_tun.h>
17+
#include <sys/uio.h>
18+
19+
static uint16_t
20+
loopback_output_process(struct rte_graph *, struct rte_node *, void **objs, uint16_t nb_objs) {
21+
struct iface_info_loopback *lo;
22+
struct iovec iov[2];
23+
struct mbuf_data *d;
24+
struct rte_mbuf *m;
25+
struct tun_pi pi;
26+
char *data;
27+
28+
for (uint16_t i = 0; i < nb_objs; i++) {
29+
m = objs[i];
30+
d = mbuf_data(m);
31+
32+
lo = (struct iface_info_loopback *)d->iface->info;
33+
if (rte_pktmbuf_linearize(m) == 0) {
34+
data = rte_pktmbuf_mtod(m, char *);
35+
} else {
36+
data = rte_malloc(NULL, rte_pktmbuf_pkt_len(m), 0);
37+
if (data == NULL) {
38+
LOG(ERR, "rte_malloc failed %s", rte_strerror(rte_errno));
39+
goto next;
40+
}
41+
// with a non-contiguous mbuf, rte_pktmbuf_read returns a pointer
42+
// to the user provided buffer.
43+
rte_pktmbuf_read(m, 0, rte_pktmbuf_pkt_len(m), data);
44+
}
45+
pi.flags = 0;
46+
if ((data[0] & 0xf0) == 0x40)
47+
pi.proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
48+
else if ((data[0] & 0xf0) == 0x60)
49+
pi.proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
50+
else {
51+
LOG(ERR, "Bad proto: 0x%x - drop packet", data[0]);
52+
goto next;
53+
}
54+
// Do not retry even in case of if EAGAIN || EWOULDBLOCK
55+
// If the tun device queue is full, something really bad is
56+
// already happening on the management plane side.
57+
iov[0].iov_base = &pi;
58+
iov[0].iov_len = sizeof(pi);
59+
iov[1].iov_base = data;
60+
iov[1].iov_len = rte_pktmbuf_pkt_len(m);
61+
62+
if (writev(lo->fd, iov, ARRAY_DIM(iov)) < 0) {
63+
// The user messed up and removed gr-loopX
64+
// release resources on our side to try to recover
65+
if (errno == EBADFD) {
66+
iface_destroy(d->iface->id);
67+
}
68+
LOG(ERR, "write to tun device failed %s", strerror(errno));
69+
}
70+
71+
next:
72+
if (!rte_pktmbuf_is_contiguous(m))
73+
rte_free(data);
74+
rte_pktmbuf_free(m);
75+
}
76+
return nb_objs;
77+
}
78+
79+
static struct rte_node_register loopback_output_node = {
80+
.name = "loopback_output",
81+
.process = loopback_output_process,
82+
.nb_edges = 0,
83+
.next_nodes = {},
84+
};
85+
86+
static void loopback_output_register(void) {
87+
ip_output_register_interface_type(GR_IFACE_TYPE_LOOPBACK, "loopback_output");
88+
ip6_output_register_interface_type(GR_IFACE_TYPE_LOOPBACK, "loopback_output");
89+
}
90+
91+
static struct gr_node_info info = {
92+
.node = &loopback_output_node,
93+
.register_callback = loopback_output_register,
94+
};
95+
96+
GR_NODE_REGISTER(info);

modules/infra/control/loopback.c

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2024 Christophe Fontaine
33

4+
#include "loopback.h"
5+
46
#include <gr_control_input.h>
5-
#include <gr_control_output.h>
67
#include <gr_eth.h>
78
#include <gr_iface.h>
89
#include <gr_infra.h>
@@ -29,69 +30,12 @@
2930
static struct rte_mempool *loopback_pool;
3031
static struct event_base *ev_base;
3132

32-
struct iface_info_loopback {
33-
int fd;
34-
struct event *ev;
35-
};
36-
3733
static void finalize_fd(struct event *ev, void * /*priv*/) {
3834
int fd = event_get_fd(ev);
3935
if (fd >= 0)
4036
close(fd);
4137
}
4238

43-
void loopback_tx(struct rte_mbuf *m) {
44-
struct mbuf_data *d = mbuf_data(m);
45-
struct iface_info_loopback *lo;
46-
struct iovec iov[2];
47-
struct tun_pi pi;
48-
char *data;
49-
50-
lo = (struct iface_info_loopback *)d->iface->info;
51-
if (rte_pktmbuf_linearize(m) == 0) {
52-
data = rte_pktmbuf_mtod(m, char *);
53-
} else {
54-
data = rte_malloc(NULL, rte_pktmbuf_pkt_len(m), 0);
55-
if (data == NULL) {
56-
LOG(ERR, "rte_malloc failed %s", rte_strerror(rte_errno));
57-
goto end;
58-
}
59-
// with a non-contiguous mbuf, rte_pktmbuf_read returns a pointer
60-
// to the user provided buffer.
61-
rte_pktmbuf_read(m, 0, rte_pktmbuf_pkt_len(m), data);
62-
}
63-
pi.flags = 0;
64-
if ((data[0] & 0xf0) == 0x40)
65-
pi.proto = RTE_BE16(RTE_ETHER_TYPE_IPV4);
66-
else if ((data[0] & 0xf0) == 0x60)
67-
pi.proto = RTE_BE16(RTE_ETHER_TYPE_IPV6);
68-
else {
69-
LOG(ERR, "Bad proto: 0x%x - drop packet", data[0]);
70-
goto end;
71-
}
72-
// Do not retry even in case of if EAGAIN || EWOULDBLOCK
73-
// If the tun device queue is full, something really bad is
74-
// already happening on the management plane side.
75-
iov[0].iov_base = &pi;
76-
iov[0].iov_len = sizeof(pi);
77-
iov[1].iov_base = data;
78-
iov[1].iov_len = rte_pktmbuf_pkt_len(m);
79-
80-
if (writev(lo->fd, iov, ARRAY_DIM(iov)) < 0) {
81-
// The user messed up and removed gr-loopX
82-
// release resources on our side to try to recover
83-
if (errno == EBADFD) {
84-
iface_destroy(d->iface->id);
85-
}
86-
LOG(ERR, "write to tun device failed %s", strerror(errno));
87-
}
88-
89-
end:
90-
if (!rte_pktmbuf_is_contiguous(m))
91-
rte_free(data);
92-
rte_pktmbuf_free(m);
93-
}
94-
9539
static void iface_loopback_poll(evutil_socket_t, short reason, void *ev_iface) {
9640
struct eth_input_mbuf_data *e;
9741
struct iface_info_loopback *lo;

modules/infra/control/loopback.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2025 Christophe Fontaine
3+
4+
#pragma once
5+
6+
struct iface_info_loopback {
7+
int fd;
8+
struct event *ev;
9+
};

modules/infra/control/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# Copyright (c) 2023 Robin Jarry
33

44
src += files(
5-
'control_output.c',
65
'iface.c',
6+
'loop_output.c',
77
'loopback.c',
88
'main_loop.c',
99
'mempool.c',

modules/infra/control/worker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ static void worker_fini(struct event_base *) {
421421

422422
static struct gr_module worker_module = {
423423
.name = "worker",
424-
.depends_on = "control_output",
424+
.depends_on = "graph",
425425
.init = worker_init,
426426
.fini = worker_fini,
427427
};

modules/infra/datapath/control_output.c

Lines changed: 0 additions & 56 deletions
This file was deleted.

modules/infra/datapath/gr_control_output.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)