MCPcopy
hub / github.com/google/gvisor / SetInterface

Method SetInterface

pkg/sentry/socket/netstack/stack.go:175–242  ·  view source on GitHub ↗

SetInterface implements inet.Stack.SetInterface.

(ctx context.Context, msg *nlmsg.Message)

Source from the content-addressed store, hash-verified

173
174// SetInterface implements inet.Stack.SetInterface.
175func (s *Stack) SetInterface(ctx context.Context, msg *nlmsg.Message) *syserr.Error {
176 var ifinfomsg linux.InterfaceInfoMessage
177 attrsView, ok := msg.GetData(&ifinfomsg)
178 if !ok {
179 return syserr.ErrInvalidArgument
180 }
181 attrs, ok := attrsView.Parse()
182 if !ok {
183 return syserr.ErrInvalidArgument
184 }
185 ifname := ""
186 for attr := range attrs {
187 value := attrs[attr]
188 switch attr {
189 case linux.IFLA_IFNAME:
190 if len(value) < 1 {
191 return syserr.ErrInvalidArgument
192 }
193 if ifinfomsg.Index == 0 {
194 ifname = value.String()
195 for idx, ifa := range s.Interfaces() {
196 if ifname == ifa.Name {
197 ifinfomsg.Index = idx
198 break
199 }
200 }
201 }
202 case linux.IFLA_MASTER:
203 case linux.IFLA_LINKINFO:
204 case linux.IFLA_ADDRESS:
205 case linux.IFLA_MTU:
206 case linux.IFLA_NET_NS_FD:
207 case linux.IFLA_TXQLEN:
208 default:
209 ctx.Warningf("unexpected attribute: %x", attr)
210 return syserr.ErrNotSupported
211 }
212 }
213 flags := msg.Header().Flags
214 if ifinfomsg.Index == 0 {
215 if flags&linux.NLM_F_CREATE != 0 {
216 return s.newInterface(ctx, msg, attrs)
217 }
218 return syserr.ErrNoDevice
219 }
220
221 if flags&(linux.NLM_F_EXCL|linux.NLM_F_REPLACE) != 0 {
222 return syserr.ErrExists
223 }
224 if ifinfomsg.Flags != 0 || ifinfomsg.Change != 0 {
225 if ifinfomsg.Change & ^uint32(linux.IFF_UP) != 0 {
226 ctx.Warningf("Unsupported ifi_change flags: %x", ifinfomsg.Change)
227 return syserr.ErrInvalidArgument
228 }
229 if ifinfomsg.Flags & ^uint32(linux.IFF_UP) != 0 {
230 ctx.Warningf("Unsupported ifi_flags: %x", ifinfomsg.Flags)
231 return syserr.ErrInvalidArgument
232 }

Callers

nothing calls this directly

Calls 11

InterfacesMethod · 0.95
newInterfaceMethod · 0.95
lockSrcAndDstMethod · 0.95
unlockSrcAndDstMethod · 0.95
setLinkLockedMethod · 0.95
NICIDTypeAlias · 0.92
GetDataMethod · 0.80
ParseMethod · 0.65
StringMethod · 0.65
WarningfMethod · 0.65
HeaderMethod · 0.45

Tested by

no test coverage detected