Some Bits: Nelson's log

9 posts in October 2015

Automatic: driving history

For two years I’ve had an Automatic tracker in my car, a gizmo that downloads data off the diagnostic port and uploads it to an iPhone app via Bluetooth. It tracks things like speed, mileage, etc but it turns out the most interesting thing it’s actually tracking is where I drive. But it’s not that interesting, and I’ve always been a bit nervous about the privacy implications of it, and rather than pair it to my new phone’s Bluetooth I’m going to stop using it.

Some summary stats from it:

  • 613 trips since September 2013
  • 11,290 miles in 252 hours. Average speed: 45mph.
  • 25 MPG average, $1600 in fuel

By far most of the hours in the car have been the 150 miles on I-80 between SF and Grass Valley.

The main use case the developers have in mind seems to be a nanny to encourage you to drive better. You get a “Score” that’s dinged down for driving over 60 mph, or braking too hard, or whatever. I found that condescending and useless. The IFTTT integration was sort of nice for creating data in Dropbox, but it wouldn’t export the GPS track. The product got a lot more useful when they added the Dashboard, with some nice Mapbox views of the data. Still I don’t have much use for collecting the data.

Here’s a heatmap they produced of all my driving. You can see all the I-80 trips, plus a long trip down to LA and back. Occasional detours through Stockton or Yuba City.

Automatic heat map

OpenWRT: persistent DNS entries

One wrinkle with OpenWRT: if the router reboots, it loses the DNS entries it was giving based on DHCP leases. Even the ones you’ve configured as static DHCP leases, they don’t show up until the client host renews its DHCP lease. Forum discussion suggests this is because dnsmasq is reading from the dhcp.leases file which is stored on tmpfs, not permanent storage.

The simple workaround is just to manually add the host in /etc/hosts and restart dnsmasq. It will serve those entries to DNS clients. That means the client’s IP address is now stored in two different places, which is not ideal, but I can live with it. There’s some discussion of other solutions for this like moving the DHCP lease file to permanent storage or changing the configuration tool to manage parallel entries in both DHCP and dnsmasq. As of 15.05, none of that seems to be happening.

I’m liking OpenWRT now. It’s comforting working with a router that’s a full and proper Linux distribution. It’s also sort of overkill, but on the balance I like it.

Networking complication

I’m in over my head with this wireless ethernet bridge thing. Story isn’t complete, but collecting my notes. There are further writeups of this question in forum posts I’ve made: on OpenWRT forums and on Ubiquiti forums.

The real problem is I don’t understand Linux networking any more. Ethernet address aliases are new to me, and I’m confusing routing and bridging, and my knowledge feels too outdated to diagnose this properly. Honestly if it hadn’t all Just Worked on my old Tomato box I’d never have believed this was possible.

I have three subnets:

  1. My home LAN, managed by my OpenWRT box, running 192.168.0.1/24.
  2. My ISP’s network, managed by their gear, running at 10.33.1.1/24.
  3. My management IP addresses for the Ubiquiti wireless bridge, mostly invisible, but running at 192.168.1.110/24 and 192.168.1.111/24.

The challenge is getting my OpenWRT router to be able to talk to the boxes at 192.168.1.*. With Tomato I just added a static route and all was done. I tried that with OpenWRT and no luck.

A lightbulb went off thanks to an answer on the Ubiquiti forums. The WAN port on my OpenWRT boxes now has two addresses: 10.33.1.50/24, assigned by the ISP via DHCP. And also 192.168.1.1/24, assigned manually by me to talk to the Ubiquiti gear. I managed to make that actually work by manually running “ip addr add 192.168.1.1/24 dev eth0”. And now I can talk to the Ubiquiti boxes!

BTW, this whole “ip addr” thing is new to me. In my day we used ifconfig and every interface had one address, thankyouverymuch. Kids these days with their multihoming and aliases and VLAN tagging and stuff. Just don’t understand it.

Update: I added this IP address alias permanently to the routers config by following these docs, which led me to add this block at the end of /etc/config/network

config interface 'ubiqnet'
    option 'ifname' 'eth0'
    option 'proto' 'static'
    option 'ipaddr' '192.168.1.1'
    option 'netmask' '255.255.255.0'

Those same docs have a worrying warning “On openwrt 12.09, a lan interface that is first defined as dhcp interface and then has aliases with static ip address could cause problems in routing the lan traffic through the wan zone”. I think that’s exactly what I’m doing but I’m running 15.05; maybe it’s no longer a problem?

Remote Wireshark capture

It’s easier than I thought to capture network traffic from a remote machine and display it in WireShark running on your local computer.

# one liner with named pipe
$ wireshark -k -i <(ssh root@192.168.0.1 "tcpdump -s 0 -U -w - not port 22")

# more explicit version of named pipe
$ mkfifo p
$ ssh root@192.168.0.1 "tcpdump -s 0 -U -w - not port 22" > p &
$ wireshark -k -i /tmp/p

# one liner with a normal pipe
$ ssh root@192.168.0.1 "tcpdump -s 0 -U -w - not port 22" | wireshark -k -i -

All three variants are doing the same thing; they ssh into the remote host you want to monitor and fire up tcpdump to get the packet stream via SSH. Then wireshark is launched to read from the stream.

The official docs for this talk about using named pipes, which is what the first two versions do. The <(command) thing is a special bash syntax for creating a named pipe for you, it’s just a more concise version of explicitly using mkfifo. The last version using stdin also seems to work for me but the docs say “it is not clear whether it always works”. The only mysterious thing I can think of is buffering questions, but I don’t know why a named pipe would be better than a normal pipe for that.

The tcpdump command is a tiny bit subtle. It’s important to not capture ssh traffic, since we’re using ssh as the transport and that’d create a feedback loop. The other options are basically “capture everything and don’t buffer”.

OpenWRT first impressions

I decided to get yet another new router, a TP-Link Archer C7 on the WireCutter recommendation. Mostly for 5GHz radio, but also as an excuse to play with new firmware. I’d really like some sort of reboot watchdog. My impression is both Tomato and DD-WRT are a bit long in the tooth and it’s time to try something new. OpenWRT has a lot of mindshare right now, I first noticed it because it’s the home of the fq_codel work for better QOS. Worth a try.

My first impression of OpenWRT is it’s definitely not for civilian use. Really it feels more like a nice custom stripped down Linux distribution you use from the command line, not a network appliance. If you just install it and run it you do get a basic working router. But some fundamental features like detailed bandwidth monitoring, Dynamic DNS, or UPnP/NAT-PMP aren’t enabled by default. And the Luci web GUI, while nice, is very technically oriented. For instance the default configuration screens are yammering at you about bridging and WLAN1 and a bunch of confusing stuff that I understand but your basic user won’t. I get the impression that really I shouldn’t be using the Web GUI at all, just log in via ssh and editing text files.

One specific reason I installed OpenWRT is that it has a lot of third party packages. In theory a lot of this is manageable via the web GUI but I couldn’t even find the “update package list” button so ended up running “opkg update” on the command line instead. It is awesome that OpenWRT has a sane package management system!

I like that OpenWRT is clearly designed to support IPv6 well.

Some interesting packages:

  • tcpdump: for network diagnostics
  • luci-app-sqm: fq_codel QOS. traffic shaper.
  • wget curl netcat: some basic things on hand. these have to install SSL, so it’s a significant download / disk space.
  • nano, less: unix file utilities
  • luci-app-statistics and collectd-mod-*: historical stats for router
  • luci-app-vnstat: more historical traffic stats
  • luci-app-upnp miniupnpd: UPnP and NAT-PMP port forwarding
  • watchcat: reboot if ping fails for a long time
  • luci-app-*: applications that have a Web UI for them. Many useful things here.

All in all OpenWRT seems great for someone lwho wants to build and maintain a custom router software installation. If you just want a basic router that works I think stock firmware may be a reasonable choice these days. Or else Tomato/Shibby, but that’s pretty wonky.

Now I’m trying to figure out my weird network setup to talk to the usually-transparent Ubiquiti boxes.

Don’t store JSON blobs in text columns in sqlite3

I decided to try something naïve and put big JSON blobs in a sqlite3 database. About 1700 of them, 150k each, data from League of Legends matches. I knew this was dumb but I did it anyway. And it was dumb, like 300MB of dumb. To be fair sqlite3 handles this just fine, but the single big file makes backups and caching awkward. And I wasn’t even using the column!

I rewrote the code to store the JSON blobs as gzip files instead. 36MB instead of 300MB, and each file doesn’t ever change once written. Just nicer all around. Kind of a pain to remove the data though. sqlite3 doesn’t let you drop columns so you have to make a temporary table to remove it. And even then the file didn’t get smaller on disk; I ended up doing a dump / restore to reclaim the space.

I still want sqlite-for-JSON, a simple JSON datastore. I see the JSON1 module made it into sqlite3 3.9, no longer draft. I should try it out. It’s not compiled in by default. Also I assume it’s not compressed. sqlite3 does have compressed database support, but only as a paid extension.

3d touch on iPhone 6S

I was curious how the 3D Touch feature worked on the iPhone 6S. Here’s a reasonable explanation based on a iFixit teardown. tl;dr: low resolution capacitive sensors measure the distance between your finger and the base of the phone. The glass bends a bit.

I can’t say I find the UI gesture very useful. The lack of true tactile feedback makes it hard to know which gesture you’re making, and the lack of much in the UI using the sensor means often nothing happens. We need someone to figure out a great use for it, and that in turn probably requires more market saturation.

Notes on an iPhone upgrade

I just upgraded my iPhone 5S to a 6S. The basic backup-and-restore process works remarkably well, as did Verizon’s activation. However a bunch of stuff didn’t carry over. Some of this is my own fault, some of it is security, and some of it is just dumb.

  • Logins. I had to log back in to all these apps like Twitter, Gmail, etc. I’m not using the iCloud Keychain, perhaps that would have solved this. Some apps like Uber, Nest, and TriMet Tickets seem to not work after the restore to new device; the login hangs. It’s not consistent, some apps worked fine. Uber even asked for a password, then hung. I had to delete and reinstall it.
  • Authenticator tokens. I have three MFA tokens on Google Authenticator as well as a separate authenticator from Blizzard. Had to manually set those up again on the new device, which in many cases requires access to the old device’s authenticator. Again I think iCloud Keychain might have helped with this.
  • Music. None of my music copied over. That’s probably because I got hit with another iTunes debacle at some point and iTunes on my computer didn’t have access to my music library. Apple refuses to copy music off of an iPhone, I guess because they think that’s a meaningful piracy prevention mechanism.
  • Cached app data. Some apps cache data locally, like Overcast’s podcasts. That cache seems to have not been copied over. That’s not terrible, but mildly inconvenient.
  • Application data. iOS has a sort of per-app filesystem you can find, where some apps like Wiki Offline store data they downloaded. None of that data was saved or restored. This seems like a serious flaw to me; oftentimes that data is irreplaceable, or at least inconvenient to restore. I ended up copying it over manually.
  • OpenVPN setup. The basic “enable VPN” button still works, so something carried over. But the OpenVPN app was not installed correctly; greyed out for some reason. Also the OpenVPN app has a file in the per-app filesystem I need.

Hotel internet woes

Travelling in France, various problems with hotel Internet:

  • The one whose captive portal logs you out every 15 minutes
  • The one that resets HTTP requests for various Javascript libraries, including some basic things likes like JQuery and Dojo. On further inspection my guess is it has a whitelist of allowed Javascript URLs and blocks all others.
  • The one that requires an email address and gives you 10 minutes to verify a code sent to it. After entering the code your 10 minutes is not extended, but logging in again with the same credentials does work.
  • The one that doesn’t allow SSH connections.
  • The one whose captive portal aggressively intercepts connections sometimes breaking web page reloads.
  • The one that is just crushingly slow.
  • The one that is sort of fast on download but 400kbps on upload. Trying to Tweet a 2MB photo times out.
  • The one that works reasonably well, if slowly, but 1 of the 12 wifi access points is broken. The one closest to my room, and me with no idea how to tell my computer to ignore that single access point. They brought a new access point for me, some ZyXEL consumer hardware. It works better but the antenna is broken off so the WiFi is weaker than the rogue bad AP. Fortunately the ethernet switch on it worked so I was able to use my own wifi router.
  • The one whose captive portal can’t capture Google, so the obvious way of triggering the login capture process does not work.

France has a particular problem in that the law requires all Internet users have to identify themselves. A requirement which is not always reliably enforced, but it seems to be enough that few places are willing to just let you connect to a WiFi node; you have to type in some form of identification. Hotels love getting your email address, of course.

The real problem is all this captive portal hackery; it may be an even worse networking abomination than NAT. Wasn’t there some effort to at least standardize a captive portal response so your browser understands that “www.google.com” isn’t actually a page for a shitty Novotel?