Skip to content

Commit

Permalink
bump deps update loader for aya:main
Browse files Browse the repository at this point in the history
bump deps so build-ebpf doesn't fail + bump all deps that had
more recent versions, like tonic clap etc.

make sure to run `cargo install bpf-linker` locally to ensure
that its up to date.

use the `take_map` aya API to take ownership of the CONNTRACK map before
passing it to our "api-server".

Signed-off-by: astoycos <[email protected]>
  • Loading branch information
astoycos committed Aug 31, 2023
1 parent cbc28e9 commit c94b66c
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 86 deletions.
4 changes: 4 additions & 0 deletions dataplane/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[workspace]
members = ["api-server", "loader", "common", "xtask"]

[patch.crates-io]
aya = { git = "https://github.com/aya-rs/aya", branch="main" }
aya-log = { git = "https://github.com/aya-rs/aya", branch = "main" }
4 changes: 2 additions & 2 deletions dataplane/api-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish = false

[dependencies]
prost = "0.11.9"
tonic = "0.8.3"
tonic = "0.9.2"
anyhow = "1"
log = "0.4"
aya = { version = ">=0.11", features=["async_tokio"] }
Expand All @@ -16,4 +16,4 @@ regex = "1"
libc = "0.2"

[build-dependencies]
tonic-build = "0.8.4"
tonic-build = "0.9.2"
99 changes: 84 additions & 15 deletions dataplane/api-server/src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub mod backends_client {
/// Attempt to create a new client by connecting to a given endpoint.
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
where
D: std::convert::TryInto<tonic::transport::Endpoint>,
D: TryInto<tonic::transport::Endpoint>,
D::Error: Into<StdError>,
{
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
Expand Down Expand Up @@ -111,10 +111,29 @@ pub mod backends_client {
self.inner = self.inner.accept_compressed(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_decoding_message_size(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.inner = self.inner.max_encoding_message_size(limit);
self
}
pub async fn get_interface_index(
&mut self,
request: impl tonic::IntoRequest<super::PodIp>,
) -> Result<tonic::Response<super::InterfaceIndexConfirmation>, tonic::Status> {
) -> std::result::Result<
tonic::Response<super::InterfaceIndexConfirmation>,
tonic::Status,
> {
self.inner
.ready()
.await
Expand All @@ -128,12 +147,15 @@ pub mod backends_client {
let path = http::uri::PathAndQuery::from_static(
"/backends.backends/GetInterfaceIndex",
);
self.inner.unary(request.into_request(), path, codec).await
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("backends.backends", "GetInterfaceIndex"));
self.inner.unary(req, path, codec).await
}
pub async fn update(
&mut self,
request: impl tonic::IntoRequest<super::Targets>,
) -> Result<tonic::Response<super::Confirmation>, tonic::Status> {
) -> std::result::Result<tonic::Response<super::Confirmation>, tonic::Status> {
self.inner
.ready()
.await
Expand All @@ -145,12 +167,14 @@ pub mod backends_client {
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/backends.backends/Update");
self.inner.unary(request.into_request(), path, codec).await
let mut req = request.into_request();
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>,
) -> Result<tonic::Response<super::Confirmation>, tonic::Status> {
) -> std::result::Result<tonic::Response<super::Confirmation>, tonic::Status> {
self.inner
.ready()
.await
Expand All @@ -162,7 +186,9 @@ pub mod backends_client {
})?;
let codec = tonic::codec::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static("/backends.backends/Delete");
self.inner.unary(request.into_request(), path, codec).await
let mut req = request.into_request();
req.extensions_mut().insert(GrpcMethod::new("backends.backends", "Delete"));
self.inner.unary(req, path, codec).await
}
}
}
Expand All @@ -176,21 +202,26 @@ pub mod backends_server {
async fn get_interface_index(
&self,
request: tonic::Request<super::PodIp>,
) -> 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>,
) -> Result<tonic::Response<super::Confirmation>, tonic::Status>;
) -> std::result::Result<tonic::Response<super::Confirmation>, tonic::Status>;
async fn delete(
&self,
request: tonic::Request<super::Vip>,
) -> Result<tonic::Response<super::Confirmation>, tonic::Status>;
) -> std::result::Result<tonic::Response<super::Confirmation>, tonic::Status>;
}
#[derive(Debug)]
pub struct BackendsServer<T: Backends> {
inner: _Inner<T>,
accept_compression_encodings: EnabledCompressionEncodings,
send_compression_encodings: EnabledCompressionEncodings,
max_decoding_message_size: Option<usize>,
max_encoding_message_size: Option<usize>,
}
struct _Inner<T>(Arc<T>);
impl<T: Backends> BackendsServer<T> {
Expand All @@ -203,6 +234,8 @@ pub mod backends_server {
inner,
accept_compression_encodings: Default::default(),
send_compression_encodings: Default::default(),
max_decoding_message_size: None,
max_encoding_message_size: None,
}
}
pub fn with_interceptor<F>(
Expand All @@ -226,6 +259,22 @@ pub mod backends_server {
self.send_compression_encodings.enable(encoding);
self
}
/// Limits the maximum size of a decoded message.
///
/// Default: `4MB`
#[must_use]
pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
self.max_decoding_message_size = Some(limit);
self
}
/// Limits the maximum size of an encoded message.
///
/// Default: `usize::MAX`
#[must_use]
pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
self.max_encoding_message_size = Some(limit);
self
}
}
impl<T, B> tonic::codegen::Service<http::Request<B>> for BackendsServer<T>
where
Expand All @@ -239,7 +288,7 @@ pub mod backends_server {
fn poll_ready(
&mut self,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>> {
) -> Poll<std::result::Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
fn call(&mut self, req: http::Request<B>) -> Self::Future {
Expand All @@ -259,7 +308,7 @@ pub mod backends_server {
&mut self,
request: tonic::Request<super::PodIp>,
) -> Self::Future {
let inner = self.0.clone();
let inner = Arc::clone(&self.0);
let fut = async move {
(*inner).get_interface_index(request).await
};
Expand All @@ -268,6 +317,8 @@ pub mod backends_server {
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
Expand All @@ -277,6 +328,10 @@ pub mod backends_server {
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
Expand All @@ -297,13 +352,15 @@ pub mod backends_server {
&mut self,
request: tonic::Request<super::Targets>,
) -> Self::Future {
let inner = self.0.clone();
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).update(request).await };
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
Expand All @@ -313,6 +370,10 @@ pub mod backends_server {
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
Expand All @@ -333,13 +394,15 @@ pub mod backends_server {
&mut self,
request: tonic::Request<super::Vip>,
) -> Self::Future {
let inner = self.0.clone();
let inner = Arc::clone(&self.0);
let fut = async move { (*inner).delete(request).await };
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
Expand All @@ -349,6 +412,10 @@ pub mod backends_server {
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
Expand Down Expand Up @@ -377,12 +444,14 @@ pub mod backends_server {
inner,
accept_compression_encodings: self.accept_compression_encodings,
send_compression_encodings: self.send_compression_encodings,
max_decoding_message_size: self.max_decoding_message_size,
max_encoding_message_size: self.max_encoding_message_size,
}
}
}
impl<T: Backends> Clone for _Inner<T> {
fn clone(&self) -> Self {
Self(self.0.clone())
Self(Arc::clone(&self.0))
}
}
impl<T: std::fmt::Debug> std::fmt::Debug for _Inner<T> {
Expand Down
4 changes: 2 additions & 2 deletions dataplane/api-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod server;
use std::net::{Ipv4Addr, SocketAddrV4};

use anyhow::Error;
use aya::maps::{HashMap, MapRefMut};
use aya::maps::{HashMap, MapData};
use tonic::transport::Server;

use backends::backends_server::BackendsServer;
Expand All @@ -14,7 +14,7 @@ use common::{Backend, BackendKey};
pub async fn start(
addr: Ipv4Addr,
port: u16,
bpf_map: HashMap<MapRefMut, BackendKey, Backend>,
bpf_map: HashMap<MapData, BackendKey, Backend>,
) -> Result<(), Error> {
let server = server::BackendService::new(bpf_map);
// TODO: mTLS https://github.com/Kong/blixt/issues/50
Expand Down
6 changes: 3 additions & 3 deletions dataplane/api-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::net::Ipv4Addr;
use std::sync::Arc;

use anyhow::Error;
use aya::maps::{HashMap, MapRefMut};
use aya::maps::{HashMap, MapData};
use tokio::sync::Mutex;
use tonic::{Request, Response, Status};

Expand All @@ -12,11 +12,11 @@ use crate::netutils::{if_name_for_routing_ip, if_nametoindex};
use common::{Backend, BackendKey};

pub struct BackendService {
bpf_map: Arc<Mutex<HashMap<MapRefMut, BackendKey, Backend>>>,
bpf_map: Arc<Mutex<HashMap<MapData, BackendKey, Backend>>>,
}

impl BackendService {
pub fn new(bpf_map: HashMap<MapRefMut, BackendKey, Backend>) -> BackendService {
pub fn new(bpf_map: HashMap<MapData, BackendKey, Backend>) -> BackendService {
BackendService {
bpf_map: Arc::new(Mutex::new(bpf_map)),
}
Expand Down
2 changes: 1 addition & 1 deletion dataplane/ebpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
aya-bpf = { git = "https://github.com/aya-rs/aya", branch = "main" }
aya-log-ebpf = { git = "https://github.com/aya-rs/aya", branch = "main" }
common = { path = "../common" }
memoffset = "0.8"
memoffset = "0.9"

[[bin]]
name = "loader"
Expand Down
Loading

0 comments on commit c94b66c

Please sign in to comment.