1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-04 23:40:26 +08:00

optimize(lower): nic route setting

This commit is contained in:
源文雨
2024-07-17 14:08:59 +09:00
parent 04a3c9a10b
commit 58cb7e09a8
5 changed files with 38 additions and 26 deletions

View File

@@ -72,6 +72,10 @@ func (wg *WG) init(srcport, dstport uint16) {
if err != nil {
panic(err)
}
myip := net.ParseIP(wg.c.IP)
if myip == nil {
panic("invalid ip " + wg.c.IP)
}
for _, p := range wg.c.Peers {
for _, ip := range p.AllowedIPs {
if len(ip) == 0 || ip[0] == 'x' {
@@ -94,11 +98,11 @@ func (wg *WG) init(srcport, dstport uint16) {
}
wg.me = link.NewMe(&link.MyConfig{
MyIPwithMask: wg.c.IP + "/32",
MyIPwithMask: myip.String() + "/32",
MyEndpoint: wg.c.EndPoint,
Network: wg.c.Network,
PrivateKey: &wg.key,
NIC: lower.NewNIC(wg.c.IP, wg.c.SubNet, strconv.FormatInt(wg.c.MTU, 10), cidrs...),
NIC: lower.NewNIC(myip, mysubnet, strconv.FormatInt(wg.c.MTU, 10), cidrs...),
SrcPort: srcport,
DstPort: dstport,
MTU: uint16(wg.c.MTU),