示例#1
0
func matchNetwork(s string) error {
	_, n, err := net.ParseCIDR(s)
	if err != nil {
		return fmt.Errorf("matchNetwork: parse error addr=[%s]: %v", s, err)
	}
	if err1 := addr.CheckMask(n); err1 != nil {
		return fmt.Errorf("matchNetwork: bad mask: addr=[%s]: %v", s, err1)
	}
	return nil // accept
}
示例#2
0
文件: router.go 项目: udhos/nexthop
func (v *ripVrf) NetMetricAdd(prefix string, nexthop net.IP, metric int, r *RipRouter) error {
	_, ipnet, err := net.ParseCIDR(prefix)
	if err != nil {
		return fmt.Errorf("ripVrf.NetMetricAdd: parse error: addr=[%s]: %v", prefix, err)
	}
	if err1 := addr.CheckMask(ipnet); err1 != nil {
		return fmt.Errorf("ripVrf.NetMetricAdd: bad mask: addr=[%s]: %v", prefix, err1)
	}
	n := v.nexthopSet(ipnet, nexthop)
	n.metric = metric
	v.localRouteAdd(n, r)
	return nil
}
示例#3
0
文件: router.go 项目: udhos/nexthop
func (v *ripVrf) NetMetricDel(prefix string, nexthop net.IP, metric int) error {
	_, ipnet, err := net.ParseCIDR(prefix)
	if err != nil {
		return fmt.Errorf("ripVrf.NetMetricDel: parse error: addr=[%s]: %v", prefix, err)
	}
	if err1 := addr.CheckMask(ipnet); err1 != nil {
		return fmt.Errorf("ripVrf.NetMetricDel: bad mask: addr=[%s]: %v", prefix, err1)
	}
	_, n := v.nexthopGet(ipnet, nexthop)
	if n == nil {
		return fmt.Errorf("ripVrf.NetMetricDel: not found: prefix=%s nexthop=%v", prefix, nexthop)
	}
	n.metric = 1
	v.localRouteDel(n)
	return nil
}
示例#4
0
文件: router.go 项目: udhos/nexthop
func (v *ripVrf) NetDel(prefix string) error {
	_, ipnet, err := net.ParseCIDR(prefix)
	if err != nil {
		return fmt.Errorf("ripVrf.NetDel: parse error: addr=[%s]: %v", prefix, err)
	}
	if err1 := addr.CheckMask(ipnet); err1 != nil {
		return fmt.Errorf("ripVrf.NetDel: bad mask: addr=[%s]: %v", prefix, err1)
	}
	i, n := v.netGet(ipnet)
	if n == nil {
		return fmt.Errorf("ripVrf.NetNet: not found: '%s'", prefix)
	}
	v.netDel(i)
	v.localRouteDel(n)
	return nil
}
示例#5
0
文件: router.go 项目: udhos/nexthop
func (v *ripVrf) NetAdd(prefix string, r *RipRouter) error {
	_, ipnet, err := net.ParseCIDR(prefix)
	if err != nil {
		return fmt.Errorf("ripVrf.NetAdd: parse error: addr=[%s]: %v", prefix, err)
	}
	if err1 := addr.CheckMask(ipnet); err1 != nil {
		return fmt.Errorf("ripVrf.NetAdd: bad mask: addr=[%s]: %v", prefix, err1)
	}
	_, n := v.netGet(ipnet)
	if n != nil {
		return fmt.Errorf("ripVrf.NetAdd: net exists: '%s'", prefix)
	}
	n = v.netAdd(ipnet)
	v.localRouteAdd(n, r)
	return nil
}