Bind an outgoing IP address while using jumpgate

jumpgate is a simple TCP proxy for lazy people like me.
This is my patch. You can use it freely under the 2 clause BSD license.

Usage: jumpgate -B

FreeBSD: policy routing with pf in 7-STABLE is BROKEN

pass in quick on $wan1 reply-to ($wan1 $wan1gw) from !$wan1net to ($wan1) keep state
pass out  route-to ($wan1 $wan1gw) proto {udp, icmp} from $wan1net to any no state
pass out  route-to ($wan1 $wan1gw) proto tcp from $wan1net to any flags any no state

In FreeBSD 7.0, the pf.conf above worked. But it doesn’t work in recent 7-STABLE. The TCP session may connect successfully, but the performance is very very poor (~ 1KB/s).

I have do some research for days, but have no idea. Now I use ipfw to do policy routing…

Happy New Year, 2009!

IMG_2086
Fireworks in Taipei 101, to celebrate 2009.

IMG_2096
We love Taiwan!

IMG_2107
People running into the MRT station after the firework. About 1.95 million passengers served by TRTC yesterday.

TRTC Train

DSCF7432

To celebrate Nangan Station available to service, TRTC runs a “panda” train in the MRT blue line.

Hinting MP4 Files for Flash Player

Today, I found my MP4 files are full-downloaded, then played. If the size of the MP4 file is very large, I must wait for a long time. So, I tried to find some solution to hint MP4 files. mp4box just can do this job.

Although mp4box is a multiplexor for MP4 files, I just use it to hint my MP4 file:

# cd /usr/ports/multimedia/gpac-mp4box
# make install clean
# mp4box -hint video.mp4

Now, I can stream my MP4 files with Flash player.

Linux: Move / to Software RAID 1

It’s a simple thought: build a software RAID 1 disk array with an empty hard disk, and copy data on / to it. After data copied, add the old disk to the array.

For example,

(sda is the old /, and sdb is the new disk)
# sfdisk -d /dev/sda | sfdisk /dev/sdb
# mdadm -C /dev/md0 –level=raid1 –raid-devices=2 /dev/sdb1 missing
# mkfs -t ext3 /dev/md0
# mount /dev/md0 /mnt
# rsync -ax / /mnt/
# vim /etc/fstab
# vim /boot/grub/menu.lst

Modify fstab and menu.lst, and make sure all /dev/sda is changed to /dev/md0.

# reboot

Make sure that md0 is mounted successfully.

# mdadm –manage /dev/md0 –add /dev/sda1

Now, we successfully moved / to software RAID 1 :)

Bug in net/iscsi-target?

I found that the block count sent from net/iscsi-target to a initiator is round to 2^31:

(In FreeBSD, iSCSI Target)

Starting iscsi_target.
Reading configuration from `/usr/local/etc/iscsi/targets’
target0:rw:10.1.1.0/24
       extent0:/dev/stripe/gs0:0:2500582432768
DISK: 1 logical unit (4883950064 blocks, 512 bytes/block), type iscsi fs
DISK: LUN 0: 2384741 MB disk storage for “target0″
TARGET: TargetName is iqn.1994-04.org.netbsd.iscsi-target

(In Debian Linux, iSCSI initiator)

scsi 3:0:0:0: Direct-Access     NetBSD   NetBSD iSCSI     0    PQ: 0 ANSI: 3
sd 3:0:0:0: [sdc] 588982768 512-byte hardware sectors (301559 MB)
sd 3:0:0:0: [sdc] Write Protect is off
sd 3:0:0:0: [sdc] Mode Sense: 0e 00 00 08
sd 3:0:0:0: [sdc] Got wrong page
sd 3:0:0:0: [sdc] Assuming drive cache: write through
sd 3:0:0:0: [sdc] 588982768 512-byte hardware sectors (301559 MB)
sd 3:0:0:0: [sdc] Write Protect is off
sd 3:0:0:0: [sdc] Mode Sense: 0e 00 00 08
sd 3:0:0:0: [sdc] Got wrong page
sd 3:0:0:0: [sdc] Assuming drive cache: write through
sdc: unknown partition table
sd 3:0:0:0: [sdc] Attached SCSI disk

I don’t know if it is a iSCSI protocol or a implementation limitation.

FreeBSD: i386 inside a jail in amd64

The key point: make a symlink of jailed /libexec/ld-elf.so.1 to /libexec/ld-elf32.so.1. Of course, your kernel should have COMPAT_IA32 option compiled.

# cd /usr/src && make TARGET_ARCH=i386 TARGET=i386 buildworld
# mkdir -p /home/jails/i386 && make TARGET_ARCH=i386 TARGET=i386 DESTDIR=/home/jails/i386 installworld
# make TARGET_ARCH=i386 TARGET=i386 DESTDIR=/home/jails/i386 distribution
# ln -s /home/jails/i386/libexec/ld-elf.so.1 /home/jails/i386/libexec/ld-elf32.so.1

Then, edit rc.conf in jail to run sshd and start jails. Some utilities, like w/ps/top can not run because they retrieve data from FreeBSD kernel, and the kernel returns 64-bit structures, not 32-bit.

w
4:37AM  up 12 days,  8:40, 1 user, load averages: 0.03, 0.18, 0.20
USER             TTY      FROM              LOGIN@  IDLE WHAT
w: kinfo_proc size mismatch (expected 768, got 1088): No such file or directory

I am doing further test to make sure there aren’t any mines :)

FreeBSD: Use ZFS volume as an iSCSI Target

Briefly, we can set the extent of iscsi-target to a ZFS volume…
But I have no idea what will happen if the size of extent is larger than it of the ZFS volume…:)

# zfs create -V 10g tank/iscsi
# cd /usr/ports/net/iscsi-target/ ; make install clean
# cat > /usr/local/etc/iscsi/targets
extent0         /dev/zvol/tank/iscsi     0       10GB
target0         rw      extent0         10.0.0.0/24
^D
# /usr/local/etc/rc.d/iscsi_target forcestart

Now we can connect this iSCSI Target with some iSCSI initiator.

Taking KMRT

I went to Kaohsiung last weekend, and took KMRT, which officially started passenger service in March 2008.

IMG_1878
The World Games Station.

IMG_1879
Kaohsiung Main Station. There are platform screen doors for all underground stations.

IMG_1884
Central Park Station.

I feel the KMRT is very like TMRT, but it is more crowded because of only 3 carriages for each train.
And the turnstiles are not functioned so well. I failed to return the single journey ticket in my 3 trips, and tried for the second time for success.