Skip to content

Commit

Permalink
CI
Browse files Browse the repository at this point in the history
  • Loading branch information
igankevich committed Apr 21, 2024
1 parent 47e585b commit 68b1bde
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 27 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ jobs:
password: ${{ secrets.GHCR_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CIJAIL_ALLOWED_ENDPOINTS: 9.9.9.9:53 github.com:443 index.crates.io:443
CIJAIL_ALLOWED_DNS_NAMES: github.com index.crates.io
steps:
- name: Checkout
uses: actions/checkout@v3
- name: DNS
run: echo 'nameserver 9.9.9.9' > /etc/resolv.conf
- name: Lint
run: ./ci/lint.sh
run: cijail ./ci/lint.sh
- name: Test
run: ./ci/test.sh
run: cijail ./ci/test.sh
- name: Build
run: ./ci/binaries.sh
- name: Release
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 50 additions & 23 deletions src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,20 @@ pub(crate) fn main(notify_fd: RawFd) -> Result<ExitCode, Box<dyn std::error::Err
request.data.args[4] as usize,
request.data.args[5] as u32,
)?;
read_dns_packet(
request.pid as i32,
request.data.args[1] as usize,
request.data.args[2] as usize,
&mut dns_names,
)?;
sockaddr.into_iter().collect()
}
"sendmsg" => {
let sockaddr = read_msghdr(request.pid as i32, request.data.args[1] as usize)?;
let sockaddr = read_msghdr(
request.pid as i32,
request.data.args[1] as usize,
&mut dns_names,
)?;
sockaddr.into_iter().collect()
}
"sendmmsg" => read_mmsghdr(
Expand Down Expand Up @@ -124,7 +134,11 @@ fn read_socket_addr(pid: i32, base: usize, len: u32) -> Result<Option<SocketAddr
Ok(sockaddr)
}

fn read_msghdr(pid: i32, base: usize) -> Result<Option<SocketAddr>, std::io::Error> {
fn read_msghdr(
pid: i32,
base: usize,
dns_names: &mut Vec<DnsName>,
) -> Result<Option<SocketAddr>, std::io::Error> {
if base == 0 {
return Ok(None);
}
Expand All @@ -137,7 +151,15 @@ fn read_msghdr(pid: i32, base: usize) -> Result<Option<SocketAddr>, std::io::Err
)?;
let message = buf.as_mut_slice().as_ptr() as *const socket::msghdr;
let message = unsafe { from_raw_parts::<socket::msghdr>(message, 1) }[0];
read_socket_addr(pid, message.msg_name as usize, message.msg_namelen)
let socketaddr = read_socket_addr(pid, message.msg_name as usize, message.msg_namelen)?;
if let Ok((iovecs, _storage)) =
read_array::<socket::iovec>(pid, message.msg_iov as usize, message.msg_iovlen)
{
for iovec in iovecs {
read_dns_packet(pid, iovec.iov_base as usize, iovec.iov_len, dns_names)?;
}
}
Ok(socketaddr)
}

fn read_mmsghdr(
Expand All @@ -159,32 +181,37 @@ fn read_mmsghdr(
message.msg_hdr.msg_iovlen,
) {
for iovec in iovecs {
let bytes = read_bytes(pid, iovec.iov_base as usize, iovec.iov_len)?;
match DnsPacket::read(bytes.as_slice()) {
Ok((packet, _)) => {
for question in packet.questions {
match from_utf8(question.name.as_slice()) {
Ok(name) => {
dns_names.push(name.parse().map_err(|e: DnsNameError| {
std::io::Error::new(ErrorKind::Other, e.to_string())
})?);
}
Err(e) => {
error!("failed to read dns name: {}", e);
}
}
}
}
Err(e) => {
error!("failed to read dns packet: {}", e);
}
}
read_dns_packet(pid, iovec.iov_base as usize, iovec.iov_len, dns_names)?;
}
}
}
Ok(sockaddrs)
}

fn read_dns_packet(
pid: i32,
base: usize,
len: usize,
dns_names: &mut Vec<DnsName>,
) -> Result<(), std::io::Error> {
let bytes = read_bytes(pid, base, len)?;
if let Ok((packet, _)) = DnsPacket::read(bytes.as_slice()) {
for question in packet.questions {
match from_utf8(question.name.as_slice()) {
Ok(name) => {
dns_names.push(name.parse().map_err(|e: DnsNameError| {
std::io::Error::new(ErrorKind::Other, e.to_string())
})?);
}
Err(e) => {
error!("failed to read dns name: {}", e);
}
}
}
}
Ok(())
}

fn read_array<'a, T>(
pid: i32,
base: usize,
Expand Down

0 comments on commit 68b1bde

Please sign in to comment.