Skip to content

Commit

Permalink
bpfd integration: allow programs to generate btf
Browse files Browse the repository at this point in the history
This commit makes the necessary changes which allow the
bpf programs to be build with btf.  It requires:
- The `fix-di` branch of bpf-linker
- A patched version of aya (https://github.com/aya-rs/aya/tree/fix-verifier-blixt)
- A patched version of bpfd (https://github.com/bpfd-dev/bpfd/tree/blixt-custom-build)

Additionally it adds a check in the loader program to check if the blixt
programs are installed by bpfd.

Signed-off-by: astoycos <[email protected]>
  • Loading branch information
astoycos authored and shaneutt committed Oct 26, 2023
1 parent 8af75b2 commit 2ede3a0
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 133 deletions.
6 changes: 5 additions & 1 deletion dataplane/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[alias]
xtask = "run --package xtask --"
xtask = "run --package xtask --"

## Needed to build blixt's programs with BTF + custom bpf-linker build.
[build]
rustflags = ["-C", "debuginfo=2"]
22 changes: 22 additions & 0 deletions dataplane/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,25 @@ build.image:
load.image: build.image
kind load docker-image $(IMAGE):$(TAG) --name $(KIND_CLUSTER) && \
kubectl -n blixt-system rollout restart daemonset blixt-dataplane

.PHONY: build.bytecode.images
build.bytecode.images: build
docker build \
--build-arg PROGRAM_NAME=blixt-tc-ingress \
--build-arg BPF_FUNCTION_NAME=tc_ingress \
--build-arg PROGRAM_TYPE=tc \
--build-arg BYTECODE_FILENAME=loader \
-f https://raw.githubusercontent.com/bpfd-dev/bpfd/main/packaging/container-deployment/Containerfile.bytecode \
./target/bpfel-unknown-none/debug -t quay.io/bpfd-bytecode/blixt-tc-ingress:latest
docker build \
--build-arg PROGRAM_NAME=blixt-tc-egress \
--build-arg BPF_FUNCTION_NAME=tc_egress \
--build-arg PROGRAM_TYPE=tc \
--build-arg BYTECODE_FILENAME=loader \
-f https://raw.githubusercontent.com/bpfd-dev/bpfd/main/packaging/container-deployment/Containerfile.bytecode \
./target/bpfel-unknown-none/debug -t quay.io/bpfd-bytecode/blixt-tc-egress:latest

.PHONY: push.bytecode.images
push.bytecode.images: build.bytecode.images
docker push quay.io/bpfd-bytecode/blixt-tc-egress:latest
docker push quay.io/bpfd-bytecode/blixt-tc-ingress:latest
136 changes: 47 additions & 89 deletions dataplane/api-server/src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ pub struct InterfaceIndexConfirmation {
/// Generated client implementations.
pub mod backends_client {
#![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
use tonic::codegen::*;
use tonic::codegen::http::Uri;
use tonic::codegen::*;
#[derive(Debug, Clone)]
pub struct BackendsClient<T> {
inner: tonic::client::Grpc<T>,
Expand Down Expand Up @@ -90,9 +90,8 @@ pub mod backends_client {
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
>,
>,
<T as tonic::codegen::Service<
http::Request<tonic::body::BoxBody>,
>>::Error: Into<StdError> + Send + Sync,
<T as tonic::codegen::Service<http::Request<tonic::body::BoxBody>>>::Error:
Into<StdError> + Send + Sync,
{
BackendsClient::new(InterceptedService::new(inner, interceptor))
}
Expand Down Expand Up @@ -130,23 +129,16 @@ pub mod backends_client {
pub async fn get_interface_index(
&mut self,
request: impl tonic::IntoRequest<super::PodIp>,
) -> std::result::Result<
tonic::Response<super::InterfaceIndexConfirmation>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
) -> std::result::Result<tonic::Response<super::InterfaceIndexConfirmation>, tonic::Status>
{
self.inner.ready().await.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/backends.backends/GetInterfaceIndex",
);
let path = http::uri::PathAndQuery::from_static("/backends.backends/GetInterfaceIndex");
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("backends.backends", "GetInterfaceIndex"));
Expand All @@ -156,38 +148,34 @@ pub mod backends_client {
&mut self,
request: impl tonic::IntoRequest<super::Targets>,
) -> std::result::Result<tonic::Response<super::Confirmation>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
self.inner.ready().await.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/backends.backends/Update");
let mut req = request.into_request();
req.extensions_mut().insert(GrpcMethod::new("backends.backends", "Update"));
req.extensions_mut()
.insert(GrpcMethod::new("backends.backends", "Update"));
self.inner.unary(req, path, codec).await
}
pub async fn delete(
&mut self,
request: impl tonic::IntoRequest<super::Vip>,
) -> std::result::Result<tonic::Response<super::Confirmation>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
self.inner.ready().await.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/backends.backends/Delete");
let mut req = request.into_request();
req.extensions_mut().insert(GrpcMethod::new("backends.backends", "Delete"));
req.extensions_mut()
.insert(GrpcMethod::new("backends.backends", "Delete"));
self.inner.unary(req, path, codec).await
}
}
Expand All @@ -202,10 +190,7 @@ pub mod backends_server {
async fn get_interface_index(
&self,
request: tonic::Request<super::PodIp>,
) -> std::result::Result<
tonic::Response<super::InterfaceIndexConfirmation>,
tonic::Status,
>;
) -> std::result::Result<tonic::Response<super::InterfaceIndexConfirmation>, tonic::Status>;
async fn update(
&self,
request: tonic::Request<super::Targets>,
Expand Down Expand Up @@ -238,10 +223,7 @@ pub mod backends_server {
max_encoding_message_size: None,
}
}
pub fn with_interceptor<F>(
inner: T,
interceptor: F,
) -> InterceptedService<Self, F>
pub fn with_interceptor<F>(inner: T, interceptor: F) -> InterceptedService<Self, F>
where
F: tonic::service::Interceptor,
{
Expand Down Expand Up @@ -297,21 +279,12 @@ pub mod backends_server {
"/backends.backends/GetInterfaceIndex" => {
#[allow(non_camel_case_types)]
struct GetInterfaceIndexSvc<T: Backends>(pub Arc<T>);
impl<T: Backends> tonic::server::UnaryService<super::PodIp>
for GetInterfaceIndexSvc<T> {
impl<T: Backends> tonic::server::UnaryService<super::PodIp> for GetInterfaceIndexSvc<T> {
type Response = super::InterfaceIndexConfirmation;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::PodIp>,
) -> Self::Future {
type Future = BoxFuture<tonic::Response<Self::Response>, tonic::Status>;
fn call(&mut self, request: tonic::Request<super::PodIp>) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
(*inner).get_interface_index(request).await
};
let fut = async move { (*inner).get_interface_index(request).await };
Box::pin(fut)
}
}
Expand Down Expand Up @@ -341,13 +314,9 @@ pub mod backends_server {
"/backends.backends/Update" => {
#[allow(non_camel_case_types)]
struct UpdateSvc<T: Backends>(pub Arc<T>);
impl<T: Backends> tonic::server::UnaryService<super::Targets>
for UpdateSvc<T> {
impl<T: Backends> tonic::server::UnaryService<super::Targets> for UpdateSvc<T> {
type Response = super::Confirmation;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
type Future = BoxFuture<tonic::Response<Self::Response>, tonic::Status>;
fn call(
&mut self,
request: tonic::Request<super::Targets>,
Expand Down Expand Up @@ -383,17 +352,10 @@ pub mod backends_server {
"/backends.backends/Delete" => {
#[allow(non_camel_case_types)]
struct DeleteSvc<T: Backends>(pub Arc<T>);
impl<T: Backends> tonic::server::UnaryService<super::Vip>
for DeleteSvc<T> {
impl<T: Backends> tonic::server::UnaryService<super::Vip> for DeleteSvc<T> {
type Response = super::Confirmation;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::Vip>,
) -> Self::Future {
type Future = BoxFuture<tonic::Response<Self::Response>, tonic::Status>;
fn call(&mut self, request: tonic::Request<super::Vip>) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).delete(request).await };
Box::pin(fut)
Expand Down Expand Up @@ -422,18 +384,14 @@ pub mod backends_server {
};
Box::pin(fut)
}
_ => {
Box::pin(async move {
Ok(
http::Response::builder()
.status(200)
.header("grpc-status", "12")
.header("content-type", "application/grpc")
.body(empty_body())
.unwrap(),
)
})
}
_ => Box::pin(async move {
Ok(http::Response::builder()
.status(200)
.header("grpc-status", "12")
.header("content-type", "application/grpc")
.body(empty_body())
.unwrap())
}),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions dataplane/ebpf/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[build]
target-dir = "../target"
target = "bpfel-unknown-none"
rustflags = ["-C", "save-temps"]

[unstable]
build-std = ["core"]
3 changes: 2 additions & 1 deletion dataplane/ebpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ path = "src/main.rs"

[profile.dev]
opt-level = 3
debug = false
debug = true
debug-assertions = false
overflow-checks = false
lto = true
Expand All @@ -29,6 +29,7 @@ rpath = false
lto = true
panic = "abort"
codegen-units = 1
debug-assertions = false

[workspace]
members = []
2 changes: 1 addition & 1 deletion dataplane/ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,5 @@ fn try_tc_egress(ctx: TcContext) -> Result<i32, i64> {

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
loop {}
}
Loading

0 comments on commit 2ede3a0

Please sign in to comment.