-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #45 Signed-off-by: Andrew Stoycos <[email protected]>
- Loading branch information
Showing
21 changed files
with
472 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
config/tests/kustomization.yaml → config/tests/blixt/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
bases: | ||
- ../default | ||
- ../../default | ||
|
||
images: | ||
- name: ghcr.io/kong/blixt-dataplane | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
resources: | ||
- ../../samples/udproute | ||
|
||
patchesStrategicMerge: | ||
- |- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: blixt-udproute-sample | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: server | ||
command: | ||
- ./udp-test-server | ||
# --dry-run disables UDP listeners in order to test failures to send | ||
# data, and trigger ICMP port failure responses from the kernel | ||
- --dry-run | ||
images: | ||
- name: ghcr.io/kong/blixt-udp-test-server | ||
newTag: integration-tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
bases: | ||
- ../../samples/udproute | ||
|
||
images: | ||
- name: ghcr.io/kong/blixt-udp-test-server | ||
newTag: integration-tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use core::mem; | ||
|
||
use aya_bpf::{ | ||
bindings::TC_ACT_PIPE, | ||
helpers::bpf_csum_diff, | ||
programs::TcContext, | ||
}; | ||
use aya_log_ebpf::info; | ||
|
||
use crate::{ | ||
bindings::{iphdr, icmphdr}, | ||
utils::{csum_fold_helper, ip_from_int, ptr_at, ETH_HDR_LEN, IP_HDR_LEN}, | ||
BLIXT_CONNTRACK, | ||
}; | ||
|
||
const ICMP_HDR_LEN: usize = mem::size_of::<icmphdr>(); | ||
const ICMP_PROTO_TYPE_UNREACH: u8 = 3; | ||
|
||
pub fn handle_icmp_egress(ctx: TcContext) -> Result<i32, i64> { | ||
let ip_hdr: *mut iphdr = unsafe { ptr_at(&ctx, ETH_HDR_LEN) }?; | ||
|
||
let icmp_header_offset = ETH_HDR_LEN + IP_HDR_LEN; | ||
|
||
let icmp_hdr: *mut icmphdr = unsafe { | ||
ptr_at( | ||
&ctx, | ||
icmp_header_offset | ||
)? | ||
}; | ||
|
||
// We only care about redirecting port unreachable messages currently so a | ||
// UDP client can tell when the server is shutdown | ||
if unsafe { (*icmp_hdr).type_ } != ICMP_PROTO_TYPE_UNREACH { | ||
return Ok(TC_ACT_PIPE); | ||
} | ||
|
||
let dest_addr = unsafe { (*ip_hdr).daddr }; | ||
|
||
let new_src = unsafe { BLIXT_CONNTRACK.get(&dest_addr) }.ok_or(TC_ACT_PIPE)?; | ||
|
||
let daddr_dot_dec = ip_from_int(unsafe { (*ip_hdr).daddr }); | ||
info!( | ||
&ctx, | ||
"Received a ICMP Unreachable packet destined for svc ip: {}.{}.{}.{}", | ||
daddr_dot_dec[0], | ||
daddr_dot_dec[1], | ||
daddr_dot_dec[2], | ||
daddr_dot_dec[3], | ||
); | ||
|
||
// redirect icmp unreachable message back to client | ||
unsafe { | ||
(*ip_hdr).saddr = *new_src; | ||
(*ip_hdr).check = 0; | ||
} | ||
|
||
let full_cksum = unsafe { | ||
bpf_csum_diff( | ||
mem::MaybeUninit::zeroed().assume_init(), | ||
0, | ||
ip_hdr as *mut u32, | ||
mem::size_of::<iphdr>() as u32, | ||
0 | ||
) | ||
} as u64; | ||
unsafe { (*ip_hdr).check = csum_fold_helper(full_cksum) }; | ||
|
||
// Get inner ipheader since we need to update that as well | ||
let icmp_inner_ip_hdr: *mut iphdr = unsafe { ptr_at(&ctx, icmp_header_offset + ICMP_HDR_LEN)}?; | ||
|
||
unsafe { | ||
(*icmp_inner_ip_hdr).daddr = *new_src; | ||
(*icmp_inner_ip_hdr).check = 0; | ||
} | ||
|
||
let full_cksum = unsafe { | ||
bpf_csum_diff( | ||
mem::MaybeUninit::zeroed().assume_init(), | ||
0, | ||
icmp_inner_ip_hdr as *mut u32, | ||
mem::size_of::<iphdr>() as u32, | ||
0 | ||
) | ||
} as u64; | ||
unsafe { (*icmp_inner_ip_hdr).check = csum_fold_helper(full_cksum) }; | ||
|
||
unsafe { BLIXT_CONNTRACK.remove(&dest_addr)? }; | ||
|
||
return Ok(TC_ACT_PIPE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod icmp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.