找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 1519|回复: 1

openwrt 6in4隧道使用其它隧道服务时自动更新endpoint的方法

[复制链接]

openwrt自带的6in4自动更新endpoint脚本只对tunnelbroker有效,使用其它隧道的话需要修改脚本
下面的脚本是针对shiratunnel的,使用其他隧道服务或使用github的6in4项目自建tunnel服务器时只需要替换里面的url
  1. #!/bin/sh
  2. # 6in4.sh - IPv6-in-IPv4 tunnel backend
  3. # Copyright (c) 2010-2015 OpenWrt.org

  4. [ -n "$INCLUDE_ONLY" ] || {
  5.         . /lib/functions.sh
  6.         . /lib/functions/network.sh
  7.         . ../netifd-proto.sh
  8.         init_proto "$@"
  9. }

  10. proto_6in4_update() {
  11.         sh -c '
  12.                 timeout=5

  13.                 (while [ $((timeout--)) -gt 0 ]; do
  14.                         sleep 1
  15.                         kill -0 $ || exit 0
  16.                 done; kill -9 $) 2>/dev/null &

  17.                 exec "$@"
  18.         ' "$1" "$@"
  19. }

  20. proto_6in4_setup() {
  21.         local cfg="$1"
  22.         local iface="$2"
  23.         local link="6in4-$cfg"

  24.         local mtu ttl tos ipaddr peeraddr ip6addr ip6prefix tunlink tunnelid username password updatekey
  25.         json_get_vars mtu ttl tos ipaddr peeraddr ip6addr ip6prefix tunlink tunnelid username password updatekey

  26.         [ -z "$peeraddr" ] && {
  27.                 proto_notify_error "$cfg" "MISSING_ADDRESS"
  28.                 proto_block_restart "$cfg"
  29.                 return
  30.         }

  31.         ( proto_add_host_dependency "$cfg" "$peeraddr" "$tunlink" )

  32.         [ -z "$ipaddr" ] && {
  33.                 local wanif="$tunlink"
  34.                 if [ -z "$wanif" ] && ! network_find_wan wanif; then
  35.                         proto_notify_error "$cfg" "NO_WAN_LINK"
  36.                         return
  37.                 fi

  38.                 if ! network_get_ipaddr ipaddr "$wanif"; then
  39.                         proto_notify_error "$cfg" "NO_WAN_LINK"
  40.                         return
  41.                 fi
  42.         }

  43.         proto_init_update "$link" 1

  44.         [ -n "$ip6addr" ] && {
  45.                 local local6="${ip6addr%%/*}"
  46.                 local mask6="${ip6addr##*/}"
  47.                 [[ "$local6" = "$mask6" ]] && mask6=
  48.                 proto_add_ipv6_address "$local6" "$mask6"
  49.                 proto_add_ipv6_route "::" 0 "" "" "" "$local6/$mask6"
  50.         }

  51.         [ -n "$ip6prefix" ] && {
  52.                 proto_add_ipv6_prefix "$ip6prefix"
  53.                 proto_add_ipv6_route "::" 0 "" "" "" "$ip6prefix"
  54.         }

  55.         proto_add_tunnel
  56.         json_add_string mode sit
  57.         json_add_int mtu "${mtu:-1280}"
  58.         json_add_int ttl "${ttl:-64}"
  59.         [ -n "$tos" ] && json_add_string tos "$tos"
  60.         json_add_string local "$ipaddr"
  61.         json_add_string remote "$peeraddr"
  62.         [ -n "$tunlink" ] && json_add_string link "$tunlink"
  63.         proto_close_tunnel

  64.         proto_send_update "$cfg"

  65.         [ -n "$tunnelid" -a -n "$username" -a \( -n "$password" -o -n "$updatekey" \) ] && {
  66.                 [ -n "$updatekey" ] && password="$updatekey"

  67.                 local http="http"
  68.                 local urlget="uclient-fetch"
  69.                 local urlget_opts="-qO-"
  70.                 local ca_path="${SSL_CERT_DIR:-/etc/ssl/certs}"

  71.                 [ -f /lib/libustream-ssl.so ] && http=https
  72.                 [ "$http" = "https" -a -z "$(find $ca_path -name "*.0" 2>/dev/null)" ] && {
  73.                         urlget_opts="$urlget_opts --no-check-certificate"
  74.                 }

  75.                 local url="$http://ipv4.tunnel.shiralabs.com/nic/update?hostname=$tunnelid"
  76.                 local try=0
  77.                 local max=3

  78.                 (
  79.                         set -o pipefail
  80.                         while [ $((++try)) -le $max ]; do
  81.                                 if proto_6in4_update $urlget $urlget_opts --user="$username" --password="$password" "$url" 2>&1 | \
  82.                                         sed -e 's,^Killed$,timeout,' -e "s,^,update $try/$max: ," | \
  83.                                         logger -t "$link";
  84.                                 then
  85.                                         logger -t "$link" "updated"
  86.                                         return 0
  87.                                 fi
  88.                                 sleep 5
  89.                         done
  90.                         logger -t "$link" "update failed"
  91.                 )
  92.         }
  93. }

  94. proto_6in4_teardown() {
  95.         local cfg="$1"
  96. }

  97. proto_6in4_init_config() {
  98.         no_device=1
  99.         available=1

  100.         proto_config_add_string "ipaddr"
  101.         proto_config_add_string "ip6addr"
  102.         proto_config_add_string "ip6prefix"
  103.         proto_config_add_string "peeraddr"
  104.         proto_config_add_string "tunlink"
  105.         proto_config_add_string "tunnelid"
  106.         proto_config_add_string "username"
  107.         proto_config_add_string "password"
  108.         proto_config_add_string "updatekey"
  109.         proto_config_add_int "mtu"
  110.         proto_config_add_int "ttl"
  111.         proto_config_add_string "tos"
  112. }

  113. [ -n "$INCLUDE_ONLY" ] || {
  114.         add_protocol 6in4
  115. }
复制代码



替换以下文件的内容即可
/lib/netifd/proto/6in4.sh
/overlay/upper/lib/netifd/proto/6in4.sh



我的恩山、我的无线 The best wifi forum is right here.
完全看不懂,不知道该怎么操作,呵呵
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-27 06:31

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表