diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-02-05 02:04:06 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-09-26 23:34:44 +0200 |
commit | e30c52d292d5f03883a83d0a6bec71335ab99342 (patch) | |
tree | 60d49c63deb8fa6ed4677428e49e7eacf9dc3225 /pkg/sentry/socket/netlink/route/protocol.go | |
parent | ea43d9ffc0fd7bc1f42bada76006dbcf26f752af (diff) |
Implement dummy network interfacesfeature/dummy-iface
Diffstat (limited to 'pkg/sentry/socket/netlink/route/protocol.go')
-rw-r--r-- | pkg/sentry/socket/netlink/route/protocol.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/pkg/sentry/socket/netlink/route/protocol.go b/pkg/sentry/socket/netlink/route/protocol.go index 38f714c48..359db6e99 100644 --- a/pkg/sentry/socket/netlink/route/protocol.go +++ b/pkg/sentry/socket/netlink/route/protocol.go @@ -161,6 +161,77 @@ func (p *Protocol) getLink(ctx context.Context, msg *netlink.Message, ms *netlin return nil } +// newLink handles RTM_NEWLINK requests. +func (p *Protocol) newLink(ctx context.Context, msg *netlink.Message, ms *netlink.MessageSet) *syserr.Error { + stack := inet.StackFromContext(ctx) + if stack == nil { + // No network devices. + return nil + } + + // Parse message. + var ifi linux.InterfaceInfoMessage + attrs, ok := msg.GetData(&ifi) + if !ok { + return syserr.ErrInvalidArgument + } + + if attrs.Empty() { + return nil + } + + // Parse attributes. + var name []byte + var kind string + + for !attrs.Empty() { + ahdr, value, rest, ok := attrs.ParseFirst() + if !ok { + return syserr.ErrInvalidArgument + } + attrs = rest + + switch ahdr.Type { + case linux.IFLA_IFNAME: + if len(value) < 1 { + return syserr.ErrInvalidArgument + } + name = value[:len(value)-1] + case linux.IFLA_LINKINFO: + attrs := netlink.AttrsView(value) + for !attrs.Empty() { + ahdr, value, rest, ok := attrs.ParseFirst() + if !ok { + return syserr.ErrInvalidArgument + } + attrs = rest + + switch ahdr.Type { + case linux.IFLA_INFO_KIND: + if len(value) < 1 { + return syserr.ErrInvalidArgument + } + kind = string(value) + } + } + } + } + + var ret *syserr.Error = nil + + switch kind { + case "dummy": + _, err := stack.AddDummyInterface(string(name)) + if err != nil { + ret = syserr.ErrInvalidArgument + } + default: + ret = syserr.ErrInvalidArgument + } + + return ret +} + // delLink handles RTM_DELLINK requests. func (p *Protocol) delLink(ctx context.Context, msg *netlink.Message, ms *netlink.MessageSet) *syserr.Error { stack := inet.StackFromContext(ctx) @@ -704,6 +775,8 @@ func (p *Protocol) ProcessMessage(ctx context.Context, msg *netlink.Message, ms switch hdr.Type { case linux.RTM_GETLINK: return p.getLink(ctx, msg, ms) + case linux.RTM_NEWLINK: + return p.newLink(ctx, msg, ms) case linux.RTM_DELLINK: return p.delLink(ctx, msg, ms) case linux.RTM_GETROUTE: |