MCPcopy Create free account
hub / github.com/F-Stack/f-stack / if_vmove_loan

Function if_vmove_loan

freebsd/net/if.c:1377–1432  ·  view source on GitHub ↗

* Move an ifnet to or from another child prison/vnet, specified by the jail id. */

Source from the content-addressed store, hash-verified

1375 * Move an ifnet to or from another child prison/vnet, specified by the jail id.
1376 */
1377static int
1378if_vmove_loan(struct thread *td, struct ifnet *ifp, char *ifname, int jid)
1379{
1380 struct prison *pr;
1381 struct ifnet *difp;
1382 int error;
1383 bool found;
1384 bool shutdown;
1385
1386 /* Try to find the prison within our visibility. */
1387 sx_slock(&allprison_lock);
1388 pr = prison_find_child(td->td_ucred->cr_prison, jid);
1389 sx_sunlock(&allprison_lock);
1390 if (pr == NULL)
1391 return (ENXIO);
1392 prison_hold_locked(pr);
1393 mtx_unlock(&pr->pr_mtx);
1394
1395 /* Do not try to move the iface from and to the same prison. */
1396 if (pr->pr_vnet == ifp->if_vnet) {
1397 prison_free(pr);
1398 return (EEXIST);
1399 }
1400
1401 /* Make sure the named iface does not exists in the dst. prison/vnet. */
1402 /* XXX Lock interfaces to avoid races. */
1403 CURVNET_SET_QUIET(pr->pr_vnet);
1404 difp = ifunit(ifname);
1405 if (difp != NULL) {
1406 CURVNET_RESTORE();
1407 prison_free(pr);
1408 return (EEXIST);
1409 }
1410
1411 /* Make sure the VNET is stable. */
1412 shutdown = VNET_IS_SHUTTING_DOWN(ifp->if_vnet);
1413 if (shutdown) {
1414 CURVNET_RESTORE();
1415 prison_free(pr);
1416 return (EBUSY);
1417 }
1418 CURVNET_RESTORE();
1419
1420 found = if_unlink_ifnet(ifp, true);
1421 MPASS(found);
1422
1423 /* Move the interface into the child jail/vnet. */
1424 error = if_vmove(ifp, pr->pr_vnet);
1425
1426 /* Report the new if_xname back to the userland on success. */
1427 if (error == 0)
1428 sprintf(ifname, "%s", ifp->if_xname);
1429
1430 prison_free(pr);
1431 return (error);
1432}
1433
1434static int

Callers 1

ifhwioctlFunction · 0.85

Calls 8

ifunitFunction · 0.85
if_unlink_ifnetFunction · 0.85
if_vmoveFunction · 0.85
sprintfFunction · 0.85
prison_find_childFunction · 0.50
prison_hold_lockedFunction · 0.50
mtx_unlockFunction · 0.50
prison_freeFunction · 0.50

Tested by

no test coverage detected