添加网卡 alias

This commit is contained in:
bjdgyc 2023-10-30 11:38:31 +08:00
parent 6788a875a2
commit 57990d3d2a
3 changed files with 12 additions and 6 deletions

View File

@ -28,19 +28,19 @@ func checkTun() {
if err != nil { if err != nil {
base.Fatal("testTun err: ", err) base.Fatal("testTun err: ", err)
} }
//开启服务器转发 // 开启服务器转发
if err := execCmd([]string{"sysctl -w net.ipv4.ip_forward=1"}); err != nil { if err := execCmd([]string{"sysctl -w net.ipv4.ip_forward=1"}); err != nil {
base.Fatal(err) base.Fatal(err)
} }
if base.Cfg.IptablesNat { if base.Cfg.IptablesNat {
//添加NAT转发规则 // 添加NAT转发规则
ipt, err := iptables.New() ipt, err := iptables.New()
if err != nil { if err != nil {
base.Fatal(err) base.Fatal(err)
return return
} }
//修复 rockyos nat 不生效 // 修复 rockyos nat 不生效
cmdstr0 := fmt.Sprintln("modprobe -i iptable_filter") cmdstr0 := fmt.Sprintln("modprobe -i iptable_filter")
cmdstr1 := fmt.Sprintf("modprobe -i iptable_nat") cmdstr1 := fmt.Sprintf("modprobe -i iptable_nat")
err = execCmd([]string{cmdstr0, cmdstr1}) err = execCmd([]string{cmdstr0, cmdstr1})
@ -75,7 +75,8 @@ func LinkTun(cSess *sessdata.ConnSession) error {
// log.Printf("Interface Name: %s\n", ifce.Name()) // log.Printf("Interface Name: %s\n", ifce.Name())
cSess.SetIfName(ifce.Name()) cSess.SetIfName(ifce.Name())
cmdstr1 := fmt.Sprintf("ip link set dev %s up mtu %d multicast off", ifce.Name(), cSess.Mtu) cmdstr1 := fmt.Sprintf("ip link set dev %s up mtu %d multicast off alias %s.%s", ifce.Name(), cSess.Mtu,
cSess.Group.Name, cSess.Username)
cmdstr2 := fmt.Sprintf("ip addr add dev %s local %s peer %s/32", cmdstr2 := fmt.Sprintf("ip addr add dev %s local %s peer %s/32",
ifce.Name(), base.Cfg.Ipv4Gateway, cSess.IpAddr) ifce.Name(), base.Cfg.Ipv4Gateway, cSess.IpAddr)
err = execCmd([]string{cmdstr1, cmdstr2}) err = execCmd([]string{cmdstr1, cmdstr2})

View File

@ -238,7 +238,11 @@ func SetPostAuthXml(g *dbdata.Group, w http.ResponseWriter) error {
if err != nil { if err != nil {
return err return err
} }
HttpSetHeader(w, "X-CSTP-Post-Auth-XML", result.String()) xmlAuth := ""
for _, v := range strings.Split(result.String(), "\n") {
xmlAuth += strings.TrimSpace(v)
}
HttpSetHeader(w, "X-CSTP-Post-Auth-XML", xmlAuth)
return nil return nil
} }

View File

@ -54,7 +54,8 @@ func LinkMacvtap(cSess *sessdata.ConnSession) error {
cSess.SetIfName(ifName) cSess.SetIfName(ifName)
cmdstr1 := fmt.Sprintf("ip link add link %s name %s type macvtap mode bridge", base.Cfg.Ipv4Master, ifName) cmdstr1 := fmt.Sprintf("ip link add link %s name %s type macvtap mode bridge", base.Cfg.Ipv4Master, ifName)
cmdstr2 := fmt.Sprintf("ip link set dev %s up mtu %d address %s", ifName, cSess.Mtu, cSess.MacHw) cmdstr2 := fmt.Sprintf("ip link set dev %s up mtu %d address %s alias %s.%s", ifName, cSess.Mtu, cSess.MacHw,
cSess.Group.Name, cSess.Username)
err := execCmd([]string{cmdstr1, cmdstr2}) err := execCmd([]string{cmdstr1, cmdstr2})
if err != nil { if err != nil {
base.Error(err) base.Error(err)