mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Support IFLA_ADDRESS which changes a device's hardware address.
PiperOrigin-RevId: 645611089
This commit is contained in:
@@ -136,6 +136,7 @@ func (s *Stack) SetInterface(ctx context.Context, msg *nlmsg.Message) *syserr.Er
|
||||
}
|
||||
case linux.IFLA_MASTER:
|
||||
case linux.IFLA_LINKINFO:
|
||||
case linux.IFLA_ADDRESS:
|
||||
default:
|
||||
ctx.Warningf("unexpected attribute: %x", attr)
|
||||
return syserr.ErrNotSupported
|
||||
@@ -169,13 +170,24 @@ func (s *Stack) SetInterface(ctx context.Context, msg *nlmsg.Message) *syserr.Er
|
||||
}
|
||||
|
||||
func (s *Stack) setLink(id tcpip.NICID, linkAttrs map[uint16]nlmsg.BytesView) *syserr.Error {
|
||||
if v, ok := linkAttrs[linux.IFLA_MASTER]; ok {
|
||||
master, ok := v.Uint32()
|
||||
if !ok {
|
||||
return syserr.ErrInvalidArgument
|
||||
}
|
||||
if master != 0 {
|
||||
if err := s.Stack.SetNICCoordinator(id, tcpip.NICID(master)); err != nil {
|
||||
for t, v := range linkAttrs {
|
||||
switch t {
|
||||
case linux.IFLA_MASTER:
|
||||
master, ok := v.Uint32()
|
||||
if !ok {
|
||||
return syserr.ErrInvalidArgument
|
||||
}
|
||||
if master != 0 {
|
||||
if err := s.Stack.SetNICCoordinator(id, tcpip.NICID(master)); err != nil {
|
||||
return syserr.TranslateNetstackError(err)
|
||||
}
|
||||
}
|
||||
case linux.IFLA_ADDRESS:
|
||||
addr, err := tcpip.ParseMACAddress(v.String())
|
||||
if err != nil {
|
||||
return syserr.ErrInvalidArgument
|
||||
}
|
||||
if err := s.Stack.SetNICAddress(id, addr); err != nil {
|
||||
return syserr.TranslateNetstackError(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1025,6 +1025,19 @@ func (s *Stack) SetNICCoordinator(id tcpip.NICID, mid tcpip.NICID) tcpip.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetNICAddress sets the hardware address which is identified by the nic ID.
|
||||
func (s *Stack) SetNICAddress(id tcpip.NICID, addr tcpip.LinkAddress) tcpip.Error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
nic, ok := s.nics[id]
|
||||
if !ok {
|
||||
return &tcpip.ErrUnknownNICID{}
|
||||
}
|
||||
nic.NetworkLinkEndpoint.SetLinkAddress(addr)
|
||||
return nil
|
||||
}
|
||||
|
||||
// NICInfo captures the name and addresses assigned to a NIC.
|
||||
type NICInfo struct {
|
||||
Name string
|
||||
|
||||
Reference in New Issue
Block a user