Tyblog | Building my ideal router for $50

Thanks for a nice post!

I did something similar - built my router using an Espressobin. I used Ubuntu rather than arch.
Works very nicely. Today I’ve had fiber based Internet service installed - 1Gb/s downsteam (replacing the meager 50-60Mb/s I had previously). Suddenly I hit a performance wall. The board goes to high CPU when I speedtest it, and hits a ceiling at ~125Mb/s.
Looking at what’s going on I see pppoe using very high CPU. Tried to upgrade rp-pppoe, but to no avail.
Any thoughts on that one?

EDIT: Typically after giving up on solving it and posting, you hit the solution. So I did. I’ve been using userland pppoe - and sure enough, it hits userland limits. Once I moved to kernel pppoe, Performance skyrocketed to what I believe is the ISP limit - at this moment, well over 500Mb/s.

It seems I am also having speed issues as well with lan to wan traffic. Lan to Lan I am getting gigabit, from the Espressobin OS console outbound I am getting gigabit, but from a machine plugged into the lan to a machine hooked directly into the wan port I am only getting about a 3rd of a gig. Have you tried a bandwidth test on your router with something capable of gigabit speeds? I am getting these speeds from stock installs of Arch and Armbian, with no mods and no FW…

I saw doron’s comment, I do not believe the issue is pppoe on mine, at least I am not seeing that in the logs. Any ideas?

Sorry - didnt reply to doron correctly, reposing
If you don’t mind me asking, what did you do to upgrade it? I am running into the exact same issue, as in hitting a ceiling…

@RickS - what I did is change my pppoe configuration template. It had a “pty” line calling /usr/sbin/pppoe with some flags, which translates to running pppoe as a userland process. (When I was on VDSL, it worked just fine; when I connected to FTTH, CPU went to the roof and performance was blocked.)

Instead, I –

  1. Made sure my kernel is compiled with PPP and PPPOE (as modules, in my case, but that’s unimportant)
  2. Remove the pty lines from my pppoe configuration
  3. Add “plugin rp-pppoe.so” to that configuration

This makes pppoe use the kernel module. Performance upped 5-7 times once I did that.

Hope this helps!

@Andy : I’m now getting slightly over 500 Mb/s from lan1 to wan routed by the EB. But, read on.

There’s another, more “subtle” performance limit, which is based on the architecture of the EB.
As you probably know, the board has a SOC with one 1Gb/s port; and an Ethernet switch (topaz), with 4 1Gb/s ports, one of which internally connected to the SOC.

Now, as long as LAN switching can be done inside the switch, you can get full 1Gb in / 1Gb out performance between, say, wan and lan1. The board, and, mainly, the kernel code, are very smart in offloading functionality into the switch. So stuff like basic routing, and even some iptables filtering, - can mostly be offloaded into the switch so there’s little performance impact.

But: when you consider traffic between two of the switch’s ports, with processing that must be done at the CPU level, - all that traffic needs to flow into the CPU and then back into the switch. This will now hit the limits of both the internal port (each packet needs to go over it twice - in and out), and the kernel which now needs to deal with double the packet handling interrupts (on a single core). While the port is full duplex, this translates to high load processing those packets, and on Linux you may see Soft IRQ overload.

Case in point (mine): I needed to terminate the ISP PPPOE tunnel on the EB. This means that the board needs to perform both PPPOE tunneling and point-to-multipoint NAT (aka masquerading). These can’t be offloaded to the switch chip; hence all my wan port traffic flows into the CPU and then down to lan port. High interrupt load on CPU. Net effect: tops at somewhat over 500Mb/s.

If you will terminate your tunnel (and do your inevitable NATing) outside of (i.e. in front of) your EB wan port, you may probably get much closer to the 1Gb/s theoretical limit.

Hope this helps!

@doron - I actually don’t think I have the same issue as you, also I wouldn’t mind 2/3rds of a gig’s performance, but its far lower. Also I have a fiber box that I connect my router to, so I am not using PPPOE, and just to be sure, I made sure it wasn’t even installed. I did some searching, any my problem accurately matches this guys issue:

I’ve played around with the IRQ, but I cant get it to balance, its always running on either CPU 0 or 1, and at nearly 100% during a load, which is probably why its at 1/3rd performance. Again, not even sure if that is the issue, I just don’t know how to go about troubleshooting this…

Hi , can you share your 3d print file ?

Thanks

@m7mdcc the STL file from the picture of my router is this one from Thingiverse.

I’ve also printed this case which houses a drive; as I’ve started experimenting running the espressobin with a drive attached as the root volume instead of an SD card and the setup works fairly well.

Does anyone have any advice for what to do in case of a power outage? My espressobin was running great until a storm rolled through and killed the power for a few hours. My UPS isn’t large enough to run my network forever and eventually it all came down while I was away at work. I came back to a corrupt sd card and my attempts at fixing it resulted in kernel panics. I’m hoping I can recover my config and set it all back up again. Is there a clever way to shutdown cleanly?

APC makes an Arch linux package for a clean shutdown!

What version of Espressobin did you do this on? My guess that your build was the V5 just because of the timing of your post … I want to replicate what you have done. It seems to me that the only major difference between V5 and V7 is DDR3 => DDR4 … I think I will purchase the V7 Espressobin.

BTW, this was an amazing blog post! I have been reading about building my own firewall for a while and you seem to be the best resource for doing that :slight_smile:

Hi!
I bought a Espressobin V7 with the newest Arch Linux ARM 64bit seems to have dnsmasq as default DHCP an DNS Server… now im failing to set up! Can be someone be so frendly and post the hole dnsmasq.conf of his router!

Thanks Mates

Yep! This was on a V5. I think a V7 would be a great option for a router; the additional CPU horsepower means that you could probably use more intelligent QoS schedulers like CAKE without hitting any bottlenecks.

Hi @Morta! Here’s the relevant parts of my dnsmasq.conf. I have a couple of extra cname= and similar entries for some other names I have setup note that there are a few things specific to my setup here:

  • I start the DHCP range at 5 since I have a few reserved static IPs.
  • The last few lines are there only because I have dnsmasq configured for PXE booting, they’re not necessary for the functionality described in this blog post.
  • The conf-dir= option is also just optional, I have some dynamically-generated files there.
  • server=/consul/127.0.0.1#8500 lets any requests for foo.service.consul resolve from any host in my LAN.
domain-needed
bogus-priv
server=/consul/127.0.0.1#8600
no-hosts
domain=<my domain>
expand-hosts
conf-dir=/etc/dnsmasq.d
interface=br0
dhcp-range=192.168.1.5,192.168.1.250,255.255.255.0,24h
dhcp-option=option:router,192.168.1.1
address=/router/192.168.1.1
dhcp-boot=ipxe.a56af4e6a9a9.pxe
enable-tftp
tftp-root=/srv/ftp

Hi Tyler.
Very good article indeed. I am already running a router on arch linux myself on an APU1D4 and custom intel motherboard with dnsmasq,unbound and shorewall.
I came across your article while searching for a way to visualize network data.
I tried the instructions on elasti.co but I am unable to set it up and getting nowhere.
Would it be possible for you to post how you set it up on arch linux? The second machine where I want to send netflow data is also running arch.
Than you.

I need a dual-WAN solution. Think it’s possible to use this as a router, but just treat the “wan” interface as LAN and use eth0 and eth1 for my PPPoE connections?

Is there any reason why that wouldn’t work? Otherwise I suppose I could buy a USB-to-Ethernet adapter and use it for the second WAN port

Why not use these imported firewall pfsense?

Hi @fabiolourenco, I think I mention why not pfsense in the post, but the short version is that I wanted Linux since I would be best able to administer it instead of a *BSD and had some additional features I wanted to experiment with in the Linux kernel.

Hi @manpreet! In short terms, here’s what I’m doing in order to visualize my network data:

On my Arch Linux ARM-based router, I’ve installed
the ipt-netflow-dkms-git AUR package. I then load that kernel module on-demand by including the following lines in /etc/shorewall/start:

run_iptables -I INPUT -j NETFLOW
run_iptables -I FORWARD -j NETFLOW
run_iptables -I OUTPUT -j NETFLOW

return 0

You configure the destination for netflow packets in /etc/modprobe.d/ipt-netflow.conf, mine looks like this:

options ipt_NETFLOW destination=127.0.0.1:2055 protocol=5

This is because I run a dynamic reverse proxy on the router to send netflow packets wherever Nomad is currently running logstash, but the tl;dr is that you point the module at wherever you’re running logstash.

The logstash config is simple due to the netflow module:

http.host: "0.0.0.0"
modules:
  - name: netflow
    var.elasticsearch.hosts: elasticsearch.service.consul
    var.kibana.host: <my kibana hostname>
    var.kibana.scheme: https

The steps to get Logstash connected to Elasticsearch is outside the scope of the guide I’ve written here. Does that make sense/are there other parts I could clarify?

@jrutley I think that use case should be doable. I haven’t tweaked my setup very comprehensively, but at the very least, each of the three network interfaces do show up distinctly. I’m not sure what might be implied by the fact that most are of the form @eth0, though.

$ [root@charon network]# ip l | grep -A1 eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1508 qdisc mq state UP mode DEFAULT group default qlen 1024
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
--
4: wan@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc hfsc state UP mode DEFAULT group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
5: lan0@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br0 state UP mode DEFAULT group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
6: lan1@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br0 state LOWERLAYERDOWN mode DEFAULT group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff