Skip to content

Commit 8bbca20

Browse files
committed
repair: add net hack also to sock tile
1 parent 569b93a commit 8bbca20

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

src/disco/net/fd_net_common.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef HEADER_fd_src_disco_net_fd_net_common_h
2+
#define HEADER_fd_src_disco_net_fd_net_common_h
3+
4+
/* fd_net_common.h contains common definitions across net tile implementations. */
5+
6+
/* REPAIR_PING_SZ is the sz of a ping packet for the repair protocol.
7+
Because pings are routed to the same port as shreds without any
8+
discriminant encoding, we have to use the packet sz to interpret the
9+
payload. Note that any valid shred must be either FD_SHRED_MAX_SZ
10+
or FD_SHRED_MIN_SZ ie. will never be FD_REPAIR_PING_SZ.*/
11+
12+
#define REPAIR_PING_SZ (174UL)
13+
14+
#endif /* HEADER_fd_src_disco_net_fd_net_common_h */

src/disco/net/sock/fd_sock_tile.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#define _GNU_SOURCE /* dup3 */
22
#include "fd_sock_tile_private.h"
3+
#include "../fd_net_common.h"
34
#include "../../topo/fd_topo.h"
45
#include "../../../util/net/fd_eth.h"
56
#include "../../../util/net/fd_ip4.h"
@@ -27,6 +28,11 @@
2728
Must be aligned by alignof(struct cmsghdr) */
2829
#define FD_SOCK_CMSG_MAX (64UL)
2930

31+
/* Value of the sock_idx for Firedancer repair intake.
32+
Used to determine whether repair packets should go to shred vs repair tile.
33+
This value is validated at startup. */
34+
#define REPAIR_SHRED_SOCKET_ID (4U)
35+
3036
static ulong
3137
populate_allowed_seccomp( fd_topo_t const * topo,
3238
fd_topo_tile_t const * tile,
@@ -200,7 +206,7 @@ privileged_init( fd_topo_t * topo,
200206
DST_PROTO_TPU_QUIC, /* quic_transaction_listen_port */
201207
DST_PROTO_SHRED, /* shred_listen_port (turbine) */
202208
DST_PROTO_GOSSIP, /* gossip_listen_port */
203-
DST_PROTO_SHRED, /* shred_listen_port (repair) */
209+
DST_PROTO_REPAIR, /* shred_listen_port (repair) */
204210
DST_PROTO_REPAIR /* repair_serve_listen_port */
205211
};
206212
for( uint candidate_idx=0U; candidate_idx<6; candidate_idx++ ) {
@@ -209,6 +215,12 @@ privileged_init( fd_topo_t * topo,
209215
if( candidate_idx>FD_SOCK_TILE_MAX_SOCKETS ) FD_LOG_ERR(( "too many sockets" ));
210216
ushort port = (ushort)udp_port_candidates[ candidate_idx ];
211217

218+
/* Validate value of REPAIR_SHRED_SOCKET_ID */
219+
if( udp_port_candidates[sock_idx]==tile->sock.net.repair_intake_listen_port )
220+
FD_TEST( sock_idx==REPAIR_SHRED_SOCKET_ID );
221+
if( udp_port_candidates[sock_idx]==tile->sock.net.repair_serve_listen_port )
222+
FD_TEST( sock_idx==REPAIR_SHRED_SOCKET_ID+1 );
223+
212224
char const * target_link = udp_port_links[ candidate_idx ];
213225
ctx->link_rx_map[ sock_idx ] = 0xFF;
214226
for( ulong j=0UL; j<(tile->out_cnt); j++ ) {
@@ -351,7 +363,6 @@ poll_rx_socket( fd_sock_tile_t * ctx,
351363
if( FD_UNLIKELY( sa->sin_family!=AF_INET ) ) {
352364
/* unreachable */
353365
FD_LOG_ERR(( "Received packet with unexpected sin_family %i", sa->sin_family ));
354-
continue;
355366
}
356367

357368
long daddr = -1;
@@ -397,7 +408,20 @@ poll_rx_socket( fd_sock_tile_t * ctx,
397408
ulong chunk = fd_laddr_to_chunk( base, eth_hdr );
398409
ulong sig = fd_disco_netmux_sig( sa->sin_addr.s_addr, fd_ushort_bswap( sa->sin_port ), 0U, proto, hdr_sz );
399410
ulong tspub = fd_frag_meta_ts_comp( ts );
400-
fd_stem_publish( stem, rx_link, sig, chunk, frame_sz, 0UL, 0UL, tspub );
411+
412+
/* default for repair intake is to send to [shreds] to shred tile.
413+
ping messages should be routed to the repair. */
414+
if( FD_UNLIKELY( sock_idx==REPAIR_SHRED_SOCKET_ID && frame_sz==REPAIR_PING_SZ ) ) {
415+
uchar repair_rx_link = ctx->link_rx_map[ REPAIR_SHRED_SOCKET_ID+1 ];
416+
fd_sock_link_rx_t * repair_link = ctx->link_rx + repair_rx_link;
417+
uchar * repair_buf = fd_chunk_to_laddr( repair_link->base, repair_link->chunk );
418+
memcpy( repair_buf, eth_hdr, frame_sz );
419+
fd_stem_publish( stem, repair_rx_link, sig, repair_link->chunk, frame_sz, 0UL, 0UL, tspub );
420+
repair_link->chunk = fd_dcache_compact_next( repair_link->chunk, FD_NET_MTU, repair_link->chunk0, repair_link->wmark );
421+
} else {
422+
fd_stem_publish( stem, rx_link, sig, chunk, frame_sz, 0UL, 0UL, tspub );
423+
}
424+
401425
last_chunk = chunk;
402426
}
403427

src/disco/net/sock/fd_sock_tile_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/* MAX_NET_OUTS controls the max number of RX links that a sock tile can
2222
serve. */
2323

24-
#define MAX_NET_OUTS (4UL)
24+
#define MAX_NET_OUTS (5UL)
2525

2626
/* Local metrics. Periodically copied to the metric_in shm region. */
2727

src/disco/net/xdp/fd_xdp_tile.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <sys/socket.h> /* MSG_DONTWAIT needed before importing the net seccomp filter */
1010
#include <linux/if_xdp.h>
1111

12+
#include "../fd_net_common.h"
1213
#include "../../metrics/fd_metrics.h"
1314
#include "../../netlink/fd_netlink_tile.h" /* neigh4_solicit */
1415
#include "../../topo/fd_topo.h"
@@ -43,14 +44,6 @@
4344

4445
#define FD_XDP_STATS_INTERVAL_NS (11e6) /* 11ms */
4546

46-
/* REPAIR_PING_SZ is the sz of a ping packet for the repair protocol.
47-
Because pings are routed to the same port as shreds without any
48-
discriminant encoding, we have to use the packet sz to interpret the
49-
payload. Note that any valid shred must be either FD_SHRED_MAX_SZ
50-
or FD_SHRED_MIN_SZ ie. will never be FD_REPAIR_PING_SZ.*/
51-
52-
#define REPAIR_PING_SZ (174UL)
53-
5447
/* fd_net_in_ctx_t contains consumer information for an incoming tango
5548
link. It is used as part of the TX path. */
5649

0 commit comments

Comments
 (0)