本文整理汇总了Golang中github.com/vishvananda/netlink.RouteDel函数的典型用法代码示例。如果您正苦于以下问题:Golang RouteDel函数的具体用法?Golang RouteDel怎么用?Golang RouteDel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RouteDel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: delRouteIface
// delRouteIface clean up the required L3 mode default ns route
func delRouteIface(ipVlanL3Network *net.IPNet, iface netlink.Link) error {
return netlink.RouteDel(&netlink.Route{
LinkIndex: iface.Attrs().Index,
Scope: netlink.SCOPE_LINK,
Dst: ipVlanL3Network,
})
}
示例2: delRemoteRoute
// delRemoteRoute deletes a host-scoped route to a device.
func delRemoteRoute(neighborNetwork *net.IPNet, nextHop net.IP, iface netlink.Link) error {
return netlink.RouteDel(&netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
LinkIndex: iface.Attrs().Index,
Dst: neighborNetwork,
Gw: nextHop,
})
}
示例3: delRoute
// delRoute deletes any netlink route
func delRoute(route netlink.Route, iface netlink.Link) error {
return netlink.RouteDel(&netlink.Route{
Scope: route.Scope,
LinkIndex: iface.Attrs().Index,
Dst: route.Dst,
Gw: route.Gw,
})
}
示例4: DelRoute
func (dev *vxlanDevice) DelRoute(subnet ip.IP4Net) error {
route := &netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
Dst: subnet.ToIPNet(),
Gw: subnet.IP.ToIP(),
}
log.Infof("calling RouteDel: %s", subnet)
return netlink.RouteDel(route)
}
示例5: delRemoteRoute
// delRemoteRoute deletes a host-scoped route to a device.
func delRemoteRoute(neighborNetwork *net.IPNet, nextHop net.IP, iface netlink.Link) error {
log.Debugf("Deleting route: IP Prefix: [ %s ] - Next Hop: [ %s ] - Source Interface: [ %s ]", neighborNetwork, nextHop, iface.Attrs().Name)
return netlink.RouteDel(&netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
LinkIndex: iface.Attrs().Index,
Dst: neighborNetwork,
Gw: nextHop,
})
}
示例6: delRoute
// delRoute deletes any netlink route
func delRoute(route netlink.Route, iface netlink.Link) error {
log.Debugf("Deleting route in the default namespace for IPVlan L3 mode with the following:")
log.Debugf("IP Prefix: [ %s ] - Next Hop: [ %s ] - Source Interface: [ %s ]", route.Dst, route.Gw, iface.Attrs().Name)
return netlink.RouteDel(&netlink.Route{
Scope: route.Scope,
LinkIndex: iface.Attrs().Index,
Dst: route.Dst,
Gw: route.Gw,
})
}
示例7: deleteHostRoute
func (t *AWSVPCTracker) deleteHostRoute(cidr string) error {
dst, err := parseCIDR(cidr)
if err != nil {
return err
}
route := &netlink.Route{
LinkIndex: t.linkIndex,
Dst: dst,
Scope: netlink.SCOPE_LINK,
}
return netlink.RouteDel(route)
}
示例8: delDefaultRoute
//delete default routes
//FIXME all default routes will be erased
func delDefaultRoute() error {
routes, _ := netlink.RouteList(nil, netlink.FAMILY_V4)
for _, route := range routes {
if route.Dst != nil || route.Src != nil {
continue
}
if err := netlink.RouteDel(&route); err != nil {
return err
}
}
return nil
}
示例9: delNetlinkRoute
// AddHostRoute adds a route to a device using netlink into the Linux default namespace.
func delNetlinkRoute(neighborNetwork *net.IPNet, nextHop net.IP, netIface string) error {
iface, err := netlink.LinkByName(netIface)
if err != nil {
return err
}
log.Infof("IP Prefix: [ %s ] - Next Hop: [ %s ] - Source Interface: [ %s ]", neighborNetwork, nextHop, iface.Attrs().Name)
return netlink.RouteDel(&netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
LinkIndex: iface.Attrs().Index,
Dst: neighborNetwork,
Gw: nextHop,
})
}
示例10: removeAllRoutesOnLink
func removeAllRoutesOnLink(link netlink.Link) error {
routes, err := netlink.RouteList(link, netlink.FAMILY_V4)
if err != nil {
return errwrap.Wrap(fmt.Errorf("cannot list routes on link %q", link.Attrs().Name), err)
}
for _, route := range routes {
if err := netlink.RouteDel(&route); err != nil {
return errwrap.Wrap(fmt.Errorf("error in time of route removal for route %q", route), err)
}
}
return nil
}
示例11: removeRoute
// Delete a route from the namespace routing table.
func removeRoute(path string, dest *net.IPNet, nh net.IP) error {
return nsInvoke(path, func(nsFD int) error { return nil }, func(callerFD int) error {
gwRoutes, err := netlink.RouteGet(nh)
if err != nil {
return fmt.Errorf("route for the next hop could not be found: %v", err)
}
return netlink.RouteDel(&netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
LinkIndex: gwRoutes[0].LinkIndex,
Gw: gwRoutes[0].Gw,
Dst: dest,
})
})
}
示例12: delAllRoutesVia
func delAllRoutesVia(s net.Addr) error {
src := s.(*net.TCPAddr).IP
routes, err := netlink.RouteList(nil, netlink.FAMILY_ALL)
if err != nil {
log.Error("Failed to get routes")
log.Error(err)
return err
}
for _, r := range routes {
if r.Gw.Equal(src) {
netlink.RouteDel(&r)
}
}
return nil
}
示例13: handleSubnetEvents
func (rb *HostgwBackend) handleSubnetEvents(batch subnet.EventBatch) {
for _, evt := range batch {
switch evt.Type {
case subnet.SubnetAdded:
log.Infof("Subnet added: %v via %v", evt.Lease.Network, evt.Lease.Attrs.PublicIP)
if evt.Lease.Attrs.BackendType != "host-gw" {
log.Warningf("Ignoring non-host-gw subnet: type=%v", evt.Lease.Attrs.BackendType)
continue
}
route := netlink.Route{
Dst: evt.Lease.Network.ToIPNet(),
Gw: evt.Lease.Attrs.PublicIP.ToIP(),
LinkIndex: rb.extIface.Index,
}
if err := netlink.RouteAdd(&route); err != nil {
log.Errorf("Error adding route to %v via %v: %v", evt.Lease.Network, evt.Lease.Attrs.PublicIP, err)
continue
}
case subnet.SubnetRemoved:
log.Info("Subnet removed: ", evt.Lease.Network)
if evt.Lease.Attrs.BackendType != "host-gw" {
log.Warningf("Ignoring non-host-gw subnet: type=%v", evt.Lease.Attrs.BackendType)
continue
}
route := netlink.Route{
Dst: evt.Lease.Network.ToIPNet(),
Gw: evt.Lease.Attrs.PublicIP.ToIP(),
LinkIndex: rb.extIface.Index,
}
if err := netlink.RouteDel(&route); err != nil {
log.Errorf("Error deleting route to %v: %v", evt.Lease.Network, err)
continue
}
default:
log.Error("Internal error: unknown event type: ", int(evt.Type))
}
}
}
示例14: routingDown
func routingDown() {
veth, err := netlink.LinkByName("myveth1")
if err != nil {
panic(err)
}
routes := createRoutes(veth)
for _, route := range routes {
fmt.Println("Removing route", route)
err := netlink.RouteDel(route)
if err != nil {
// panic(err)
fmt.Println(err)
}
}
err = netlink.LinkSetDown(veth)
if err != nil {
panic(err)
}
}
示例15: programGateway
func programGateway(path string, gw net.IP, isAdd bool) error {
return nsInvoke(path, func(nsFD int) error { return nil }, func(callerFD int) error {
gwRoutes, err := netlink.RouteGet(gw)
if err != nil {
return fmt.Errorf("route for the gateway could not be found: %v", err)
}
if isAdd {
return netlink.RouteAdd(&netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
LinkIndex: gwRoutes[0].LinkIndex,
Gw: gw,
})
}
return netlink.RouteDel(&netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
LinkIndex: gwRoutes[0].LinkIndex,
Gw: gw,
})
})
}