1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-20 02:16:17 +08:00

feat(route): support x grammar

This commit is contained in:
源文雨
2024-07-13 01:56:02 +09:00
parent 03021e5d69
commit af3aa02105
3 changed files with 35 additions and 24 deletions

View File

@@ -81,6 +81,16 @@ func (m *Me) AddPeer(cfg *PeerConfig) (l *Link) {
if cfg.AllowedIPs != nil {
l.allowedips = make([]*net.IPNet, 0, len(cfg.AllowedIPs))
for _, ipnet := range cfg.AllowedIPs {
if len(ipnet) == 0 {
continue
}
noroute := ipnet[0] == 'x'
if noroute {
ipnet = ipnet[1:]
if len(ipnet) == 0 {
continue
}
}
_, cidr, err := net.ParseCIDR(ipnet)
if err == nil {
l.allowedips = append(l.allowedips, cidr)

View File

@@ -81,7 +81,7 @@ func (r *Router) SetItem(ip *net.IPNet, l *Link) {
if r.list[i].Contains(ip.IP) {
// 是同一个网络
if ip.Mask.String() == r.list[i].Mask.String() {
logrus.Infoln("[router] change link of item", r.list[i], "from", r.table[r.list[i].String()], "to", l)
logrus.Warnln("[router] change link of item", r.list[i], "from", r.table[r.list[i].String()], "to", l)
r.table[r.list[i].String()] = l
break
}