218 results for "":

Thoughts on going down the network stack

So!

I have no shortage of ongoing writing projects - I still need to edit and publish the final parts of making our own executable packer, and I’ve recently announced I was working on a Rust book/series. Those are still both on the table.

Buuut… I’m also looking at other things. My best writing happens when I’m learning about something at the same time I’m writing about it. So for example, the Rust book is a bit harder to write, because I’m mostly trying to distill knowledge I’ve already absorbed (for the most part).

ktls now under the rustls org

What’s a ktls

I started work on ktls and ktls-sys, a pair of crates exposing Kernel TLS offload to Rust, about two years ago.

kTLS lets the kernel (and, in turn, any network interface that supports it) take care of encryption, framing, etc., for the entire duration of a TLS connection… as soon as you have a TLS connection.

For the handshake itself (hellos, change cipher, encrypted extensions, certificate verification, etc.), you still have to use a userland TLS implementation.

The virtue of unsynn

Addressing the rumors

There have been rumors going around, in the Reddit thread for facet, my take on reflection in Rust, which happened a bit too early, but here we are, cat’s out of the bag, let’s talk about it!

Rumors that I, podcaster/youtuber fasterthanlime, want to kill serde, serialization / deserialization framework loved by many and which contributed greatly to Rust’s success, and I just wanted to address those rumors and say that…

Day 10 (Advent of Code 2020)

Cool bear

Day, 10! Day, 10!

Okay, Day 10.

Again, the problem statement is very confusing - but what it all boils down to is this. We have a list of numbers:

16 10 15 5 1 11 7 19 6 12 4

To which we need to add 0 and whatever the maximum was, plus three:

16 10 15 5 1 11 7 19 6 12 4 0 22

From there on, if we take them in order, we’ll have gaps of 1 and gaps of 3:

Day 4 (Advent of Code 2022)

Part 1

Let’s tackle the day 4 challenge!

In this one, we get an input like this:

2-4,6-8 2-3,4-5 5-7,7-9 2-8,3-7 6-6,4-6 2-6,4-8

Each line has two ranges: the first line has ranges containing 2, 3, 4, and 6, 7, 8. We must count how many pairs have ranges where one fully contains the other.

In Rust, we can express this with “inclusive ranges” (std::ops::RangeInclusive), and those implement Iterator, so we can do:

Setting up a local Ubuntu Server VM

The first step to using Nix to build Rust is to do so without Nix, so that when we finally do, we can feel the difference.

There’s many ways to go about this: everyone has their favorite code editor, base Linux distribution (there’s even a NixOS distribution, which I won’t cover). Some folks like to develop on macOS first, and then build for Linux.

Updating fasterthanli.me for 2022

In 2020, I switched from a static site generator to something homemade.

And, as tradition commands, I did a whole write-up about it.

Since writing articles and making videos is now my full-time occupation, I took some time to upgrade futile, my server software, to the latest and greatest the Rust ecosystem has to offer.

Day 10 (Advent of Code 2022)

Onwards! To the day 10 puzzle.

I don’t see a way to make part 1 especially fun — so let’s just get to it.

Parsing

As usual, let’s reach for the nom crate

$ cargo add nom@7 (cut)

…to parse the input into nicely-organized Rust data structures:

// in `src/main.rs` use nom::{ branch::alt, bytes::complete::tag, combinator::{map, value}, sequence::preceded, IResult, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] enum Instruction { Noop, Addx(i32), } impl Instruction { fn parse(i: &str) -> IResult<&str, Self> { let noop = tag("noop"); let addx = preceded(tag("addx "), nom::character::complete::i32); alt((value(Self::Noop, noop), map(addx, Self::Addx)))(i) } fn cycles(self) -> u32 { match self { Self::Noop => 1, Self::Addx(_) => 2, } } }

Fine, we'll relocate our own binary!

Welcome back to the eighteenth and final part of “Making our own executable packer”.

In the last article, we had a lot of fun. We already had a “packer” executable, minipak, which joined together stage1 (a launcher), and a compressed version of whichever executable we wanted to pack.

What we added, was a whole bunch of abstractions to parse ELF headers using deku, which we used from stage1 to be able to launch the guest executable from memory, instead of writing it to a file and using execve on it.

Consuming Ethernet frames with the nom crate

Now that we’ve found the best way to find the “default network interface”… what can we do with that interface?

Well, listen for network traffic of course!

use rawsock::open_best_library; use std::time::Instant; fn main() -> Result<(), Error> { let lib = open_best_library()?; let iface_name = format!(r#"\Device\NPF_{}"#, netinfo::default_nic_guid()?); let iface = lib.open_interface(&iface_name)?; println!("Listening for packets..."); // doing some low-cost logging over here let start = Instant::now(); iface.loop_infinite_dyn(&mut |packet| { println!( "{:?} | received {} bytes", start.elapsed(), packet.len() ); })?; Ok(()) }