Thursday, January 31, 2013

TP-Link, openwrt, openflow bro-ids and usb flash mounting

OpenWRT, OpenFlow and bro-ids on TP-Link TL-WR1043ND


I was given a task to mount USB Flash on tp-link router, here's how I did. here you can find detailed information about this hardware.




The development platform I used is ubuntu vm on virtualbox.
lets start the build process:

Building the image

apt-get install build-essential binutils flex bison autoconf gettext texinfo sharutils subversion libncurses5-dev ncurses-term zlib1g-dev gawk 

mkdir ~/ofwrt
cd ~/ofwrt

svn co svn://svn.openwrt.org/openwrt/trunk/
cd trunk/
sudo ./scripts/feeds update -a
sudo ./scripts/feeds install -a
cd ~/ofwrt/
git clone git://gitosis.stanford.edu/openflow-openwrt
cd ~/ofwrt/trunk/packages/ 
ln -s ~/ofwrt/openflow-openwrt/openflow-1.0/
cd ~/ofwrt/trunk/ 
ln -s ~/ofwrt/openflow-openwrt/openflow-1.0/files
cd ~/ofwrt/
 
make menuconfig
  • Select your platform for Target System (Atheros AR71xx)    Target System (Atheros AR7xxx/AR9xxx)  --->
  • Target Profile (TP-LINK TL-WR1043N/ND)  --->
  • Kernel modules  --->     
    • Filesystems  --->
      •  <*> kmod-fs-vfat..................................... VFAT filesystem
  •  --- kmod-usb-core............................................ Support
    •  <*> kmod-usb-ohci............................... Support for OHCI
    •  <*>   kmod-usb-serial-option................... Support for Option
    •  <*> kmod-usb-storage..................................... USB Storage
    • <M> kmod-usb-storage-extras.................... Extra drivers for usb-storage                                                                             
    •  <*> kmod-usb-uhci............................... Support for UHCI controllers 
    •  <*> kmod-usb2................................... Support for USB2 controllers
    •  <*> kmod-usb-uhci............................... Support for UHCI controllers
  • Save & Quit
  • I could not find few of the lines in menuconfig thats why I added them manually.
  • cd trunk
  • vi .config
  • uncomment the following lines and put =y at the end
    • CONFIG_PACKAGE_kmod-nls-base=y
    • CONFIG_PACKAGE_kmod-nls-cp437=y

  • Select OpenFlow package under network
  • Select tc package under network
  • Select kmod-tun under Kernel Modules->Network Support
  • in Target Images -> select  [ ] ramdisk  --->
  • Save and Exit



  • Add support for queueing : 
  • make kernel_menuconfig 
  • Under Networking Support->Networking options->QoS and/or fair queueing select Hierarchical Token Bucket (HTB)
  • Save and Exit
  •  

  •  
Build the image

makeV=99

Upgrading the Router
 
1. ssh or telnet the router copy 'openwrt-ar71xx-generic-tl-wr1043nd-v1-squashfs-sysupgrade.bin' file from your development system to your tp-link.
2. populate your /etc/sysupgrade.conf
   add file and directory names where which you want to preserve during upgrade, i have added /etc/config/ only to save my network configurations.
3. sysupgrade -v /tmp/openwrt-ar71xx-generic-tl-wr1043nd-v1-squashfs-sysupgrade.bin
After the upgrade the router will reboot with new image. For more information on upgrade visit here
 
Mounting the USB Flash:
before mounting verify usb kernel support,
lsmod | grep usb
lsmod | grep vfat
lsmod | grep nls

if any of the above are missing you can add them using insmod kmod-fs-fat (example)

if all the above modules are present go ahead
mkdir -p /mnt/usb # directory where Flash should be mounted.

mount -t vfat /dev/sda1 /mnt/usb

ls /mnt/usb # here you should be able to see all the files on flash.

Mounting flash on startup

vi /etc/config/fstab 

config 'mount' 
      option 'device' '/dev/sda1' 
      option 'options' 'rw,sync' 
      option 'enabled_fsck' '0' 
      option 'enabled' '1' 
      option 'target' '/mnt/share'
 
And to make the fstab settings effective in current session run:
/etc/init.d/fstab start
To make the fstab settings effective after every reboot run:
/etc/init.d/fstab enable

start the openflow service...
/etc/init.d/openflow start

root@OpenWrt:~# /etc/init.d/openflow start
eth1.1
Configuring OpenFlow switch for out-of-band control
No need for further configuration for out-of-band control
Jan 25 12:52:24|00001|vlog|INFO|opened log file /var/log/ofprotocol.log
Jan 25 12:52:24|00002|secchan|INFO|OpenFlow reference implementation version 1.0.0
Jan 25 12:52:24|00003|secchan|INFO|OpenFlow protocol version 0x01
Jan 25 12:52:24|00004|secchan|WARN|new management connection will receive asynchronous messages
Jan 25 12:52:24|00005|rconn|INFO|unix:/var/run/dp0.sock: connecting...
Jan 25 12:52:24|00006|rconn|INFO|tcp:192.168.1.2:6633: connecting...
Jan 25 12:52:24|00007|rconn|INFO|unix:/var/run/dp0.sock: connected


root@OpenWrt:~# ps | grep of
3 root 0 SW [ksoftirqd/0]
1355 root 1268 S ofdatapath punix:/var/run/dp0.sock -i eth1.1 --no-lo
1371 root 1068 S ofprotocol unix:/var/run/dp0.sock tcp:192.168.1.2:66
1373 root 1500 S grep of


if you have successfully installed the package, both daemons ofdatapath and pfprotcol must be running.

lets install bro-ids

wget http://sysnet.org.pk/upload/rc_shrimpFiles/openwrt-bro.tar.gz

it will download and install dependencies.
http://www.openflow.org/wk/index.php/OpenFlow_1.0_for_OpenWRT

1 comment:

  1. do you actually have this thing up and running ? how's its performance so far?

    ReplyDelete