Implement IFLA_IFNAME which specifies an interface's name.

IFLA_IFNAME is used to set an interface's name when being used
with RTM_NEWLINK and RTM_SETLINK. RTM_NEWLINK is the preferred way, it
is backwards compatible with RTM_SETLINK. For gVisor, when RTM_SETLINK is
introduced, it shall just share the implementation.

PiperOrigin-RevId: 647833657
This commit is contained in:
Jing Chen
2024-06-28 17:02:31 -07:00
committed by gVisor bot
parent a5573312e0
commit 59adcc9b1e
4 changed files with 93 additions and 9 deletions
+11 -9
View File
@@ -123,15 +123,13 @@ func (s *Stack) SetInterface(ctx context.Context, msg *nlmsg.Message) *syserr.Er
if len(value) < 1 {
return syserr.ErrInvalidArgument
}
if ifinfomsg.Index != 0 {
// Device name changing isn't supported yet.
return syserr.ErrNotSupported
}
ifname = value.String()
for idx, ifa := range s.Interfaces() {
if ifname == ifa.Name {
ifinfomsg.Index = idx
break
if ifinfomsg.Index == 0 {
ifname = value.String()
for idx, ifa := range s.Interfaces() {
if ifname == ifa.Name {
ifinfomsg.Index = idx
break
}
}
}
case linux.IFLA_MASTER:
@@ -190,6 +188,10 @@ func (s *Stack) setLink(id tcpip.NICID, linkAttrs map[uint16]nlmsg.BytesView) *s
if err := s.Stack.SetNICAddress(id, addr); err != nil {
return syserr.TranslateNetstackError(err)
}
case linux.IFLA_IFNAME:
if err := s.Stack.SetNICName(id, v.String()); err != nil {
return syserr.TranslateNetstackError(err)
}
}
}
return nil