mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-11 16:18:02 +08:00
增加基于tap设备的桥接访问模式
This commit is contained in:
@@ -3,10 +3,12 @@ package handler
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/bjdgyc/anylink/common"
|
||||
"github.com/bjdgyc/anylink/sessdata"
|
||||
)
|
||||
|
||||
var hn string
|
||||
@@ -20,7 +22,7 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO 调试信息输出
|
||||
// hd, _ := httputil.DumpRequest(r, true)
|
||||
// fmt.Println("DumpRequest: ", string(hd))
|
||||
fmt.Println("LinkTunnel", r.RemoteAddr)
|
||||
// fmt.Println("LinkTunnel", r.RemoteAddr)
|
||||
|
||||
// 判断session-token的值
|
||||
cookie, err := r.Cookie("webvpn")
|
||||
@@ -29,31 +31,41 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := SToken2Sess(cookie.Value)
|
||||
sess := sessdata.SToken2Sess(cookie.Value)
|
||||
if sess == nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// 开启link
|
||||
cSess := sess.StartConn()
|
||||
cSess := sess.NewConn()
|
||||
if cSess == nil {
|
||||
log.Println(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
fmt.Println(cSess.Ip, cSess.MacHw)
|
||||
|
||||
// 客户端信息
|
||||
cstp_mtu := r.Header.Get("X-CSTP-MTU")
|
||||
master_Secret := r.Header.Get("X-DTLS-Master-Secret")
|
||||
local_ip := r.Header.Get("X-Cstp-Local-Address-Ip4")
|
||||
mobile := r.Header.Get("X-Cstp-License")
|
||||
cSess.SetMtu(cstp_mtu)
|
||||
cSess.MasterSecret = master_Secret
|
||||
cSess.Mtu = cstp_mtu
|
||||
cSess.RemoteAddr = r.RemoteAddr
|
||||
cSess.LocalIp = net.ParseIP(local_ip)
|
||||
cstpDpd := common.ServerCfg.CstpDpd
|
||||
if mobile == "mobile" {
|
||||
// 手机客户端
|
||||
cstpDpd = common.ServerCfg.MobileDpd
|
||||
}
|
||||
|
||||
// 返回客户端数据
|
||||
w.Header().Set("Server", fmt.Sprintf("%s %s", common.APP_NAME, common.APP_VER))
|
||||
w.Header().Set("X-CSTP-Version", "1")
|
||||
w.Header().Set("X-CSTP-Protocol", "Copyright (c) 2004 Cisco Systems, Inc.")
|
||||
w.Header().Set("X-CSTP-Address", cSess.NetIp.String()) // 分配的ip地址
|
||||
w.Header().Set("X-CSTP-Address", cSess.Ip.String()) // 分配的ip地址
|
||||
w.Header().Set("X-CSTP-Netmask", common.ServerCfg.Ipv4Netmask) // 子网掩码
|
||||
w.Header().Set("X-CSTP-Hostname", hn) // 机器名称
|
||||
for _, v := range common.ServerCfg.ClientDns {
|
||||
@@ -74,7 +86,7 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
|
||||
// w.Header().Add("X-CSTP-Split-Include", "192.168.0.0/255.255.0.0")
|
||||
// w.Header().Add("X-CSTP-Split-Exclude", "10.1.5.2/255.255.255.255")
|
||||
|
||||
w.Header().Set("X-CSTP-Lease-Duration", fmt.Sprintf("%d", common.IpLease)) // ip地址租期
|
||||
w.Header().Set("X-CSTP-Lease-Duration", fmt.Sprintf("%d", sessdata.IpLease)) // ip地址租期
|
||||
w.Header().Set("X-CSTP-Session-Timeout", "none")
|
||||
w.Header().Set("X-CSTP-Session-Timeout-Alert-Interval", "60")
|
||||
w.Header().Set("X-CSTP-Session-Timeout-Remaining", "none")
|
||||
@@ -82,16 +94,18 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("X-CSTP-Disconnected-Timeout", "18000")
|
||||
w.Header().Set("X-CSTP-Keep", "true")
|
||||
w.Header().Set("X-CSTP-Tunnel-All-DNS", "false")
|
||||
w.Header().Set("X-CSTP-Rekey-Time", "5400")
|
||||
|
||||
w.Header().Set("X-CSTP-Rekey-Time", "172800")
|
||||
w.Header().Set("X-CSTP-Rekey-Method", "new-tunnel")
|
||||
w.Header().Set("X-CSTP-DPD", fmt.Sprintf("%d", common.ServerCfg.CstpDpd)) // 30 Dead peer detection in seconds
|
||||
|
||||
w.Header().Set("X-CSTP-DPD", fmt.Sprintf("%d", cstpDpd)) // 30 Dead peer detection in seconds
|
||||
w.Header().Set("X-CSTP-Keepalive", fmt.Sprintf("%d", common.ServerCfg.CstpKeepalive)) // 20
|
||||
w.Header().Set("X-CSTP-Banner", "welcome") // urlencode
|
||||
w.Header().Set("X-CSTP-Banner", common.ServerCfg.Banner) // urlencode
|
||||
w.Header().Set("X-CSTP-MSIE-Proxy-Lockdown", "true")
|
||||
w.Header().Set("X-CSTP-Smartcard-Removal-Disconnect", "true")
|
||||
|
||||
w.Header().Set("X-CSTP-MTU", cstp_mtu) // 1399
|
||||
w.Header().Set("X-DTLS-MTU", cstp_mtu)
|
||||
w.Header().Set("X-CSTP-MTU", fmt.Sprintf("%d", cSess.Mtu)) // 1399
|
||||
w.Header().Set("X-DTLS-MTU", fmt.Sprintf("%d", cSess.Mtu))
|
||||
|
||||
w.Header().Set("X-DTLS-Session-ID", sess.DtlsSid)
|
||||
w.Header().Set("X-DTLS-Port", "4433")
|
||||
@@ -117,6 +131,12 @@ func LinkTunnel(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// 开始数据处理
|
||||
go LinkTun(cSess)
|
||||
switch common.ServerCfg.LinkMode {
|
||||
case common.LinkModeTUN:
|
||||
go LinkTun(cSess)
|
||||
case common.LinkModeTAP:
|
||||
go LinkTap(cSess)
|
||||
}
|
||||
|
||||
go LinkCstp(conn, cSess)
|
||||
}
|
||||
|
Reference in New Issue
Block a user