Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
network: specify netlink protocol
Browse files Browse the repository at this point in the history
The go netlink package has added more netlink socket protocols
than we need. Specify one to avoid failure due to unsupported
protocols.

Fixes: #209

Signed-off-by: Peng Tao <bergwolf@gmail.com>
  • Loading branch information
bergwolf committed Apr 9, 2018
1 parent a80ad16 commit 131554d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"reflect"
"sync"

"golang.org/x/sys/unix"

pb "github.com/kata-containers/agent/protocols/grpc"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
Expand Down Expand Up @@ -101,7 +103,7 @@ func (s *sandbox) addInterface(netHandle *netlink.Handle, iface *pb.Interface) (
defer s.network.ifacesLock.Unlock()

if netHandle == nil {
netHandle, err = netlink.NewHandle()
netHandle, err = netlink.NewHandle(unix.NETLINK_ROUTE)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -146,7 +148,7 @@ func (s *sandbox) removeInterface(netHandle *netlink.Handle, iface *pb.Interface
defer s.network.ifacesLock.Unlock()

if netHandle == nil {
netHandle, err = netlink.NewHandle()
netHandle, err = netlink.NewHandle(unix.NETLINK_ROUTE)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -192,7 +194,7 @@ func (s *sandbox) updateInterface(netHandle *netlink.Handle, iface *pb.Interface
}

if netHandle == nil {
netHandle, err = netlink.NewHandle()
netHandle, err = netlink.NewHandle(unix.NETLINK_ROUTE)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -288,7 +290,7 @@ func getInterface(netHandle *netlink.Handle, link netlink.Link) (*pb.Interface,
func (s *sandbox) updateRoutes(netHandle *netlink.Handle, requestedRoutes *pb.Routes) (resultingRoutes *pb.Routes, err error) {

if netHandle == nil {
netHandle, err = netlink.NewHandle()
netHandle, err = netlink.NewHandle(unix.NETLINK_ROUTE)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -365,7 +367,7 @@ func (s *sandbox) updateRoutes(netHandle *netlink.Handle, requestedRoutes *pb.Ro
func getCurrentRoutes(netHandle *netlink.Handle) (*pb.Routes, error) {

if netHandle == nil {
netHandle, err := netlink.NewHandle()
netHandle, err := netlink.NewHandle(unix.NETLINK_ROUTE)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -416,7 +418,7 @@ func (s *sandbox) updateRoute(netHandle *netlink.Handle, route *pb.Route, add bo
defer s.network.routesLock.Unlock()

if netHandle == nil {
netHandle, err = netlink.NewHandle()
netHandle, err = netlink.NewHandle(unix.NETLINK_ROUTE)
if err != nil {
return err
}
Expand Down Expand Up @@ -500,7 +502,7 @@ func removeDNS(dns []string) error {

// Remove everything related to network.
func (s *sandbox) removeNetwork() error {
netHandle, err := netlink.NewHandle()
netHandle, err := netlink.NewHandle(unix.NETLINK_ROUTE)
if err != nil {
return err
}
Expand Down

0 comments on commit 131554d

Please sign in to comment.