Skip to content

Commit 80920ad

Browse files
riptlmmcgee-jump
authored andcommitted
net: fix IPv6 packet drops
Fixes an issue where IPv6 traffic unrelated to Firedancer is dropped by the BPF program.
1 parent 5540a59 commit 80920ad

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/disco/net/xdp/fd_xdp_tile.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -911,13 +911,15 @@ net_rx_packet( fd_net_ctx_t * ctx,
911911
ctx->metrics.rx_gre_ignored_cnt++; // drop. No gre interface in netdev table
912912
return;
913913
}
914-
if( FD_UNLIKELY( FD_IP4_GET_VERSION( *iphdr )!=0x4 ) ) {
915-
ctx->metrics.rx_gre_inv_pkt_cnt++; // drop. IP version!=IPv4
914+
ulong gre_ipver = FD_IP4_GET_VERSION( *iphdr );
915+
ulong gre_iplen = FD_IP4_GET_LEN( *iphdr );
916+
if( FD_UNLIKELY( gre_ipver!=0x4 || gre_iplen<20 ) ) {
917+
FD_DTRACE_PROBE( net_tile_err_rx_noip );
918+
ctx->metrics.rx_gre_inv_pkt_cnt++; /* drop IPv6 packets */
916919
return;
917920
}
918921

919-
ulong overhead = FD_IP4_GET_LEN( *iphdr ) + sizeof(fd_gre_hdr_t);
920-
922+
ulong overhead = gre_iplen + sizeof(fd_gre_hdr_t);
921923
if( FD_UNLIKELY( (uchar *)iphdr+overhead+sizeof(fd_ip4_hdr_t)>packet_end ) ) {
922924
FD_DTRACE_PROBE( net_tile_err_rx_undersz );
923925
ctx->metrics.rx_undersz_cnt++; // inner ip4 header invalid
@@ -939,13 +941,16 @@ net_rx_packet( fd_net_ctx_t * ctx,
939941
ulong ctl = umem_off & 0x3fUL;
940942

941943
/* Filter for UDP/IPv4 packets. */
942-
if( FD_UNLIKELY( ( FD_IP4_GET_VERSION( *iphdr )!=0x4 ) ||
943-
( iphdr->protocol!=FD_IP4_HDR_PROTOCOL_UDP ) ) ) return;
944+
ulong ipver = FD_IP4_GET_VERSION( *iphdr );
945+
ulong iplen = FD_IP4_GET_LEN ( *iphdr );
946+
if( FD_UNLIKELY( ipver!=0x4 || iplen<20 ||
947+
iphdr->protocol!=FD_IP4_HDR_PROTOCOL_UDP ) ) {
948+
FD_DTRACE_PROBE( net_tile_err_rx_noip );
949+
ctx->metrics.rx_undersz_cnt++; /* drop IPv6 packets */
950+
return;
951+
}
944952

945-
/* IPv4 is variable-length, so lookup IHL to find start of UDP */
946-
uint iplen = FD_IP4_GET_LEN( *iphdr );
947953
uchar const * udp = (uchar *)iphdr + iplen;
948-
949954
if( FD_UNLIKELY( udp+sizeof(fd_udp_hdr_t) > packet_end ) ) {
950955
FD_DTRACE_PROBE( net_tile_err_rx_undersz );
951956
ctx->metrics.rx_undersz_cnt++;

src/waltz/ebpf/fd_ebpf_asm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define FD_EBPF_ASM_jeq_imm( dst, imm, off ) FD_EBPF_ASM_JUMP_COND_IMM( 0x15, dst, imm, off )
3030
#define FD_EBPF_ASM_jne_imm( dst, imm, off ) FD_EBPF_ASM_JUMP_COND_IMM( 0x55, dst, imm, off )
3131
#define FD_EBPF_ASM_jgt_reg( dst, src, off ) FD_EBPF_ASM_JUMP_COND_REG( 0x2d, dst, src, off )
32+
#define FD_EBPF_ASM_jlt_imm( dst, imm, off ) FD_EBPF_ASM_JUMP_COND_IMM( 0xa5, dst, imm, off )
3233

3334
#define FD_EBPF_ASM_call( off ) (0x85 | ((off&0xFFFFFFFFUL)<<32))
3435

src/waltz/xdp/fd_xdp1.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ fd_xdp_gen_program( ulong code_buf[ 512 ],
108108
*(code++) = FD_EBPF( ldxb, r4, r2, 0 ); // r4 = ip4_hdr->verihl
109109
*(code++) = FD_EBPF( and64_imm, r4, 0x0f ); // r4 = ip4_hdr->ihl (lsb of ip4_hrd->verihl)
110110
*(code++) = FD_EBPF( lsh64_imm, r4, 2 ); // r4 = ip4_hdr->ihl*4 (length of ipv4 header)
111+
*(code++) = FD_EBPF( jlt_imm, r4, 20, LBL_PASS ); // if r4<20 goto LBL_PASS
111112
*(code++) = FD_EBPF( add64_reg, r4, r2 ); // r4 = &ip4_hdr + length of ip4_hdr = start of next hdr
112113

113114
/* Check if the next hdr is udp or gre */
@@ -160,6 +161,7 @@ fd_xdp_gen_program( ulong code_buf[ 512 ],
160161
*(code++) = FD_EBPF( ldxb, r4, r2, 0 ); // r4 = inner ip4_hdr->verihl
161162
*(code++) = FD_EBPF( and64_imm, r4, 0x0f ); // r4 = inner ip4_hdr->ihl
162163
*(code++) = FD_EBPF( lsh64_imm, r4, 2 ); // r4 = ip4_hdr->ihl*4 (length of ipv4 header)
164+
*(code++) = FD_EBPF( jlt_imm, r4, 20, LBL_PASS ); // if r4<20 goto LBL_PASS
163165
*(code++) = FD_EBPF( add64_reg, r4, r2 ); // r4 = start of udp_hdr
164166

165167
/*

0 commit comments

Comments
 (0)