September 23, 2016

Where to download broadcom Netgear R7000 toolchain binary

The toolchain file is hndtools-arm-linux-2.6.36-uclibc-4.5.3.tar.bz2

Download URL:

This tarball also contains the Broadcom code drop bcm963xx_4.06L.03_consumer_release.tar.gz, which was created using Broadcom's source code redistribution process, bcm47xx.tar.bz2 which is the 5GHz code, hndtools-arm-linux-2.6.36-uclibc-4.5.3.tar.bz2, which is the toolchain for the 5Ghz code, and axis.tar.bz2 which is the code that runs on the main SOC.

September 20, 2016

vim matching IP address


September 15, 2016

configure linux strongswan vpn client

1. generate a vpn client cert, and its private key
2. /etc/ipsec.conf
conn %default

conn iosIKE2

/etc/strongswan.conf : add logging
charon {
        load_modular = yes
        plugins {
                include strongswan.d/charon/*.conf
    filelog {
        /var/log/charon.log {
            # add a timestamp prefix
            time_format = %b %e %T
            # prepend connection name, simplifies grepping
            ike_name = yes
            # overwrite existing files
            append = no
            # increase default loglevel for all daemon subsystems
            #default = 1
            # flush each line to disk
            flush_line = yes

: RSA vpncert.key

copy the cert file to /etc/ipsec.d/certs
copy the CA certs file to /etc/ipsec.d/cacerts, one CA cert per file
copy the private key file to /etc/ipsec.d/private

use ipsec start to start
check file /var/log/charon.log to see logs
ipsec stop to stop 
ipsec status  (or statusall) to status.

The above will make the linux client computer not accessible locally.
If you need split tunnel, add the following:
ip rule add from all pref 100 table 100
ip route add dev eth0 table 100 is your local subnet
eth0 is your local network interface.

September 8, 2016

How to use curl with a specific network interface

The goal is to direct curl's request to a specific interface, for example, tun0.

Assume tun0 has the IPv4 address of Below is the command line:

mycurl --dns-ipv4-addr --dns-interface tun0 --interface tun0 -4

The default "curl" program in Debian/Ubuntu is not (as is Ubuntu 14.04) compiled with the lib-ares library, which is required for the above arguments to work. You will need to download the lib-ares library first (hosted by curl project), compile it, and then compile your own curl binary.  To configure curl to use your newly installed lib-ares lib, do this:

./configure --enable-ares=/usr/local/

"-4" argument is to tell curl to only use IPv4 IP. Otherwise it will wait for the IPv6 DNS resolving result, which for many sites may not be available and therefore causing curl to hang.

September 6, 2016

tmux start multiple windows

put this in a shell script:

tmux new-session -s main -n workspace -d
tmux neww -t main:1 -n local bash
tmux neww -t main:2 -n local bash
tmux neww -t main:3 -n gw 'mosh gw'
tmux neww -t main:4 -n git 'mosh git'
tmux neww -t main:5 -n download 'mosh download'
tmux attach -t main

September 2, 2016

C operator priority: Shift is lesser than +/-

int main(){
        unsigned char buf[2];
        int x;

The above code returns wrong values (not 0xF0A5). You need to add parenthesis around the shift operator: 


Or use multiplication


August 31, 2016

Linux route and rule

1. There are 3 default route tables: local, main, and default
2. Their priority and selector is defined by "rules".  use "ip rule list" to see the priority and selector of each table.

$ ip rule list
0:      from all lookup local
32766:  from all lookup main
32767:  from all lookup default

by default, local has highest priority (0). default has lowest priority (it's usually empty). main has next to lowest priority. You can all three tables match "from all" packets. So table local consulted first, then table main, then table default.  

$ ip route show table default
(return nothing)
$ ip route show table main
default via dev eth0
(this is the default gateway)

Routing tables goes by number 1-255.  You can find the names at  /etc/iproute2/rt_tables

255 local
254 main
253 default
0 unspec

You can add your own table number like
100 mytable

or you can just use a number if you like.

You can add selector to specify which table should be consulted (or not). For example, you can use 
ip rule add from table mytable    OR 
ip rule add to  OR
ip rule add iif eth0 OR
ip rule add oif eth2 OR
ip rule add fwmark MARK 

ip rule help gives you all the list

Then use "ip route add default via dev eth1 table mytable" to add a default gateway rule to this table. "via ..." "dev ..." just tells the kernel how to route it.