本文整理汇总了Golang中github.com/vishvananda/netlink.RouteDel函数的典型用法代码示例。如果您正苦于以下问题:Golang RouteDel函数的具体用法?Golang RouteDel怎么用?Golang RouteDel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RouteDel函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,
})
}
开发者ID:zenvdeluca,项目名称:ipvlan-docker-plugin,代码行数:8,代码来源:driver.go
示例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,
})
}
开发者ID:jc-m,项目名称:ipvlan-docker-plugin,代码行数:9,代码来源:del_routes.go
示例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,
})
}
开发者ID:jc-m,项目名称:ipvlan-docker-plugin,代码行数:9,代码来源:del_routes.go
示例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)
}
开发者ID:ably-forks,项目名称:flynn,代码行数:9,代码来源:device.go
示例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,
})
}
开发者ID:nerdalert,项目名称:bgp-ipvlan-docker,代码行数:10,代码来源:del_routes.go
示例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,
})
}
开发者ID:nerdalert,项目名称:bgp-ipvlan-docker,代码行数:12,代码来源:del_routes.go
示例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)
}
开发者ID:n054,项目名称:weave,代码行数:12,代码来源:awsvpc.go
示例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
}
开发者ID:CMGS,项目名称:eru-agent,代码行数:15,代码来源:route_linux.go
示例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,
})
}
开发者ID:nerdalert,项目名称:ipvlan-docker-plugin,代码行数:14,代码来源:routes.go
示例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
}
开发者ID:nhlfr,项目名称:rkt,代码行数:14,代码来源:kvm.go
示例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,
})
})
}
开发者ID:MathewAniyan,项目名称:docker,代码行数:16,代码来源:route_linux.go
示例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
}
开发者ID:clinta,项目名称:routeShare,代码行数:16,代码来源:processRoute.go
示例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))
}
}
}
开发者ID:ably-forks,项目名称:flynn,代码行数:44,代码来源:hostgw.go
示例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)
}
}
开发者ID:mycroft,项目名称:go-snippets,代码行数:22,代码来源:main.go
示例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,
})
})
}
开发者ID:MathewAniyan,项目名称:docker,代码行数:22,代码来源:route_linux.go
示例16: processRoute
func processRoute(ru *exportRoute, s net.Addr) error {
src := s.(*net.TCPAddr).IP
_, err := netlink.AddrList(nil, netlink.FAMILY_ALL)
if err != nil {
log.Error("Failed to get addresses")
log.Error(err)
return err
}
switch {
case ru.Type == syscall.RTM_NEWROUTE:
r := &netlink.Route{
Dst: ru.Dst,
Gw: src,
Priority: ru.Priority + 100,
}
err := netlink.RouteAdd(r)
if err != nil {
log.Errorf("Failed to add route: %v", r)
log.Error(err)
return err
}
case ru.Type == syscall.RTM_DELROUTE:
routes, err := netlink.RouteGet(ru.Dst.IP)
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
}
开发者ID:clinta,项目名称:routeShare,代码行数:38,代码来源:processRoute.go
示例17: RouteDel
func RouteDel(cResp chan<- *Response, rawArgs *json.RawMessage, tag string) {
args := &struct {
Ifname string `json:"ifname"`
Dst string `json:"dst"`
Src string `json:"src"`
Gw string `json:"gateway"`
Scope netlink.Scope `json:"scope"`
}{}
json.Unmarshal(*rawArgs, &args)
route, err := NewNetlinkRoute(args.Ifname, args.Dst, args.Src, args.Gw, args.Scope)
if err != nil {
cResp <- &Response{nil, tag, NewRTNetlinkError(err)}
return
}
if err := netlink.RouteDel(route); err != nil {
cResp <- &Response{nil, tag, NewRTNetlinkError(err)}
return
}
cResp <- &Response{true, tag, nil}
}
开发者ID:0xef53,项目名称:phoenix-guest-agent,代码行数:24,代码来源:network.go
示例18: deleteNetwork
func (d *driver) deleteNetwork(w http.ResponseWriter, r *http.Request) {
var req deleteNetworkRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
panic(err)
}
if req.NetworkID != d.networkID {
panic(fmt.Errorf("no network with ID %s", req.NetworkID))
}
route := &netlink.Route{
LinkIndex: d.hostLink.Attrs().Index,
Scope: netlink.SCOPE_LINK,
Dst: d.ipnet,
}
if err := netlink.RouteDel(route); err != nil {
Warn.Printf("RouteDel failed: %s\n", err.Error())
}
d.networkID = ""
w.Header().Set("Content-Type", "application/json")
fmt.Fprint(w, `{}`)
}
开发者ID:drzaeus77,项目名称:docker-plugin,代码行数:24,代码来源:driver.go
示例19: handleSubnetEvents
func (n *network) handleSubnetEvents(batch []subnet.Event) {
for _, evt := range batch {
switch evt.Type {
case subnet.EventAdded:
log.Infof("Subnet added: %v via %v", evt.Lease.Subnet, 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.Subnet.ToIPNet(),
Gw: evt.Lease.Attrs.PublicIP.ToIP(),
LinkIndex: n.linkIndex,
}
// Check if route exists before attempting to add it
routeList, err := netlink.RouteListFiltered(netlink.FAMILY_V4, &netlink.Route{
Dst: route.Dst,
}, netlink.RT_FILTER_DST)
if err != nil {
log.Warningf("Unable to list routes: %v", err)
}
// Check match on Dst for match on Gw
if len(routeList) > 0 && !routeList[0].Gw.Equal(route.Gw) {
// Same Dst different Gw. Remove it, correct route will be added below.
log.Warningf("Replacing existing route to %v via %v with %v via %v.", evt.Lease.Subnet, routeList[0].Gw, evt.Lease.Subnet, evt.Lease.Attrs.PublicIP)
if err := netlink.RouteDel(&route); err != nil {
log.Errorf("Error deleting route to %v: %v", evt.Lease.Subnet, err)
continue
}
}
if len(routeList) > 0 && routeList[0].Gw.Equal(route.Gw) {
// Same Dst and same Gw, keep it and do not attempt to add it.
log.Infof("Route to %v via %v already exists, skipping.", evt.Lease.Subnet, evt.Lease.Attrs.PublicIP)
} else if err := netlink.RouteAdd(&route); err != nil {
log.Errorf("Error adding route to %v via %v: %v", evt.Lease.Subnet, evt.Lease.Attrs.PublicIP, err)
continue
}
n.addToRouteList(route)
case subnet.EventRemoved:
log.Info("Subnet removed: ", evt.Lease.Subnet)
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.Subnet.ToIPNet(),
Gw: evt.Lease.Attrs.PublicIP.ToIP(),
LinkIndex: n.linkIndex,
}
if err := netlink.RouteDel(&route); err != nil {
log.Errorf("Error deleting route to %v: %v", evt.Lease.Subnet, err)
continue
}
n.removeFromRouteList(route)
default:
log.Error("Internal error: unknown event type: ", int(evt.Type))
}
}
}
开发者ID:luxas,项目名称:flannel,代码行数:66,代码来源:network.go
示例20: AddDHCPNetwork
func AddDHCPNetwork() {
if ok := utils.ValidateHostIface(flat.CliIF); !ok {
log.Fatalf("the host-interface [ %s ] was not found.", flat.CliIF)
}
hostmacvlanname, _ := utils.GenerateRandomName(hostprefix, hostlen)
hostEth, _ := netlink.LinkByName(flat.CliIF)
//create the macvlan device
macvlandev := &netlink.Macvlan{
LinkAttrs: netlink.LinkAttrs{
Name: hostmacvlanname,
ParentIndex: hostEth.Attrs().Index,
},
Mode: netlink.MACVLAN_MODE_BRIDGE,
}
if err := netlink.LinkAdd(macvlandev); err != nil {
log.Fatalf("failed to create Macvlan: [ %v ] with the error: %s", macvlandev.Attrs().Name, err)
}
dockerPid := utils.DockerPid(flat.CliCName)
netlink.LinkSetNsPid(macvlandev, dockerPid)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
//get root network namespace
origns, _ := netns.Get()
defer origns.Close()
//enter the docker container network
dockerNS, _ := netns.GetFromPid(dockerPid)
defer dockerNS.Close()
//get the dochclient name
dhcpClientPath := "/home/fmzhen/go/src/github.com/fmzhen/docker-macvlan/macvlan/dhcp/dhcpclient.sh"
out, err := exec.Command(dhcpClientPath).Output()
if err != nil {
log.Fatal("exec the dhcpclient.sh error: ", err)
}
dhcpClient := string(out)
// like ip netns exec xxx, just the netns ,so the command in host can exec
netns.Set(dockerNS)
// use macvlandev can cause error,need type assertion. netlink.Macvlan not must be netlink.Link,fmz
macvlandev1, _ := netlink.LinkByName(macvlandev.Attrs().Name)
netlink.LinkSetDown(macvlandev1)
netlink.LinkSetName(macvlandev1, "eth1")
netlink.LinkSetUp(macvlandev1)
//delete the default route
routes, _ := netlink.RouteList(nil, netlink.FAMILY_V4)
for _, r := range routes {
if r.Dst == nil {
if err := netlink.RouteDel(&r); err != nil {
log.Warnf("delete the default error: ", err)
}
}
}
//it doesn't work, the problem at the atgs don't pass to the shell script
dhcpReqpath := "/home/fmzhen/go/src/github.com/fmzhen/docker-macvlan/macvlan/dhcp/dhcpReq.sh"
exec.Command(dhcpReqpath, dhcpClient, string(dockerPid), flat.CliCName).Run()
netns.Set(origns)
}
开发者ID:fmzhen,项目名称:docker-macvlan,代码行数:68,代码来源:dhcp.go
注:本文中的github.com/vishvananda/netlink.RouteDel函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论