2011年11月23日 星期三

IPv6 PPPoE Server on ubuntu 10 + PPPoE Client on ARM 架設

Server端


PPPoE Server是端利用/etc/ppp下的ipv6-up/ipv6-down來轉發v6 IP給client 要轉發v6 ip主要是透過radvd. 如果需要發送dns資訊, 則需要透過dhcpv6, 目前可用的PPP over dhcpv6只有tchdpd能用.

程式下載
  1. apt-get install radvd
  2. apt-get install pppoe

參數設定

編輯/etc/ppp/pppoe-server-options:
#require-chap
require-pap
lcp-echo-interval 10
lcp-echo-failure 2
ipv6 ,
逗號前面要有一個空格
編輯/etc/ppp/options:(以我現有的作範例)
asyncmap 0
noauth
crtscts
lock
hide-password
modem
+pap
-chap
proxyarp
lcp-echo-interval 30
lcp-echo-failure 4
noipx
建立目錄/etc/ppp/ipv6-radvd
建立ipv6-up script:/etc/ppp/ipv6-up
#!/bin/sh

# These variables are for the use of the scripts run by run-parts.
PPP_IFACE="$1"
PPP_TTY="$2"
PPP_SPEED="$3"
PPP_LOCAL="$4"
PPP_REMOTE="$5"
PPP_IPPARAM="$6"
export PPP_IFACE PPP_TTY PPP_SPEED PPP_LOCAL PPP_REMOTE PPP_IPPARAM

# The environment is cleared before executing this script.
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
export PATH

# If /var/log/ppp-ipupdown.log exists use it for logging.
if [ -e /var/log/ppp-ipupdown.log ]; then
  exec >> /var/log/ppp-ipupdown.log 2>&1
fi

# This script can be used to override the .d files supplied by other packages.
if [ -x /etc/ppp/ipv6-up.local ]; then
  exec /etc/ppp/ipv6-up.local "$*"
fi

run-parts /etc/ppp/ipv6-up.d \
  --arg="$1" --arg="$2" --arg="$3" --arg="$4" --arg="$5" --arg="$6"

# if pon was called with the "quick" argument, stop pppd
if [ -e /var/run/ppp-quick ]; then
  rm /var/run/ppp-quick
  wait
  kill $PPPD_PID
fi
建立檔案/etc/ppp/ipv6-up.d/radvd
#!/bin/sh
ADDR=$(echo $PPP_REMOTE | cut -d : -f 3,4,5,6)

if test x$ADDR == x ; then
    echo "Unable to generate IPv6 address"
    exit 0
fi

ADDR=2001:470:8192:BEEF:$ADDR

#add route
route -6 add $ADDR/128 dev $PPP_IFACE

#generate radvd config
RAP=/etc/ppp/ipv6-radvd/$PPP_IFACE
RA=$RAP.conf

cat <$RA
interface $PPP_IFACE{
        AdvManagedFlag off;
        AdvOtherConfigFlag on;
        AdvSendAdvert on;
        MinRtrAdvInterval 5;
        MaxRtrAdvInterval 100;
        UnicastOnly on;
        AdvSourceLLAddress on;
        prefix 2001:470:8192:BEEF::/64 {};
};
EOF

#start radvd
/usr/sbin/radvd -C $RA -p $RAP.pid
#如果有dhcpv6, 則在此加tchdpd的資訊
#start tchdpd
/usr/sbin/tdhcpd --dns-server=2001:470:20::2 --dns-name=$PPP_IFACE.tunnel.ipv6.icybear.net --pid-file=$RAP.dhcp.pid  --local-id=test --log-level=debug $PPP_IFACE
# --local-id=tunnel.ipv6.icybear.net -L debug\

#update dns
ARPA=$(ipv6_rev $ADDR)
nsupdate << EOF
update delete $ARPA
update add $ARPA 10 ptr $PPP_IFACE.tunnel.ipv6.icybear.net
send
update delete $PPP_IFACE.tunnel.ipv6.icybear.net
update add $PPP_IFACE.tunnel.ipv6.icybear.net 10 aaaa $ADDR
send
EOF

exit 0

建立ipv6-down script:/etc/ppp/ipv6-down
#!/bin/sh

# These variables are for the use of the scripts run by run-parts.
PPP_IFACE="$1"
PPP_TTY="$2"
PPP_SPEED="$3"
PPP_LOCAL="$4"
PPP_REMOTE="$5"
PPP_IPPARAM="$6"
export PPP_IFACE PPP_TTY PPP_SPEED PPP_LOCAL PPP_REMOTE PPP_IPPARAM

# The environment is cleared before executing this script.
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
export PATH

# If /var/log/ppp-ipupdown.log exists use it for logging.
if [ -e /var/log/ppp-ipupdown.log ]; then
  exec >> /var/log/ppp-ipupdown.log 2>&1
fi

# This script can be used to override the .d files supplied by other packages.
if [ -x /etc/ppp/ipv6-down.local ]; then
  exec /etc/ppp/ipv6-down.local "$*"
fi

run-parts /etc/ppp/ipv6-down.d \
  --arg="$1" --arg="$2" --arg="$3" --arg="$4" --arg="$5" --arg="$6"
建立檔案/etc/ppp/ipv6-down.d/radvd
#!/bin/sh
RAP=/etc/ppp/ipv6-radvd/$PPP_IFACE
kill `cat $RAP.pid` || true
kill `cat $RAP.dhcp.pid` || true
rm -f $RAP.*
ADDR=$(echo $PPP_REMOTE | cut -d : -f 3,4,5,6)
ADDR=2001:470:8192:BEEF:$ADDR
ARPA=$(ipv6_rev $ADDR)
nsupdate << EOF
update delete $ARPA
send
update delete $PPP_IFACE.tunnel.ipv6.icybear.net
send
EOF
exit 0
修改帳號資訊檔/etc/ppp/pap-secrets or chap-secrets
加入 "test" * "test" *
中間用tab鍵隔開
撥號時使用test/test作連接
執行Server:pppoe-server -F -l eth0 -L 192.192.192.200 -R 192.192.192.201 -N 10


Client端


程式下載
  1. libpcap http://www.tcpdump.org/
  2. pppd http://ppp.samba.org/
  3. rp-pppoe http://www.roaringpenguin.com/products/pppoe
編譯過程

kernel options
Device Drivers->Network Device Support->PPP Support (PPP support for async serial ports, PPP support for sync tty ports必選, 其它看情況)
Device Drivers->Network Device Support->Universal TUN/TAP device driver support (PPP在連接時是利用/dev/net/tun)

libpcap
1.下載程式碼 http://www.tcpdump.org/release/libpcap-1.1.1.tar.gz
2. tar zxvf libpcap-1.1.1.tar.gz; cd libpcap-1.1.1
3. ./configure --host=arm-none-linux-gnueabi --with-pcap=null && make && make install
pppd
1.下載程式碼 git clone git://git.ozlabs.org/~paulus/ppp.git
2.編輯 ppp/pppd/Makefile.linux:
<1>打開 HAVE_INET6=y
<2>
ifdef FILTER
ifneq ($(wildcard /usr/include/pcap-bpf.h),)

改成安裝pcap的目錄
ifneq ($(wildcard /home/shaw/work/qemu/src/toolchain/lib/sysroot/usr/include/pcap-bpf.h),)

LIBS += -lpcap
CFLAGS += -DPPP_FILTER
增加
CFLAGS += -DPPP_FILTER -I/home/shaw/work/qemu/src/toolchain/usr/include -L/home/shaw/work/qemu/src/toolchain/usr/lib
3. ./configure && make CC=arm-none-linux-gnueabi && cp pppd/pppd target_dir
rp-pppoe
1.下載程式碼 http://www.roaringpenguin.com/files/download/rp-pppoe-3.10.tar.gz
2. tar zxvf rp-pppoe-3.10.tar.gz && cd rp-pppoe-3.10
3. ./configure
4. sed -i 's/gcc/arm-none-linux-gnueabi-gcc/g' Makefile && sed -i 's/gcc/arm-none-linux-gnueabi-gcc/g' libevent/Makefile
5. make && cp src/pppoe target_dir
6.將./configs下的文件copy到target的/etc/ppp/,並開啟write權限
7.將./scripts下的文件copy到target的/sbin,並修改其中內容使能順利在板子上執行

參數設定
pppoe連接主要是靠pppd+pppoe程式和Server進行連結.
設定檔主要會放在/etc/ppp/
要啟動pppoe的話, 必須先讓eth0 up, 再輸入
/* 產生設定檔 */
pppoe-setup

/* 執行 */
pppoe-start
如果要執行IPv6, 要在pppoe.conf中加入PPPD_EXTRA="ipv6 ,"
逗號前面要有一個空格


最後輸入ifconfig 看ppp0有沒有被啟動 & 設定ip

2 則留言:

Unknown 提到...

大大您好:

想請問一下您的pppoe server是否是用rp-pppoe (Roaring Penguin公司的產品)
還是是pppd (最後似乎由google買下版權, 2.4.5版)

還是同時存在於Ubuntu的機器上? (當server那台)
因為用rp-pppoe那套的話 似乎完全不會吃進script檔 導致radvd沒有啟動.

而用pppd的話不知道要怎麼當成pppoe server

所以要讓 rp-pppoe可以吃進ip-up或ipv6-up等script的話需要特殊的設定嗎?(我用的是3.8版)


Thanks

sunghau 提到...

pppd, rp-pppoe 兩個都要裝.

pppd是負責底層溝通, rp-pppoe是幫你把pppd的執行設定作包裝, 變的更簡單一些.

如果你覺得麻煩你的ubuntu server直接用apt裝一下就好了. 我測試的ubuntu是10.04版. 你可以裝這版試看看. 原則上只要step by step就能安裝完畢.