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

Function vlan_config

freebsd/net/if_vlan.c:1386–1535  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1384}
1385
1386static int
1387vlan_config(struct ifvlan *ifv, struct ifnet *p, uint16_t vid,
1388 uint16_t proto)
1389{
1390 struct epoch_tracker et;
1391 struct ifvlantrunk *trunk;
1392 struct ifnet *ifp;
1393 int error = 0;
1394
1395 /*
1396 * We can handle non-ethernet hardware types as long as
1397 * they handle the tagging and headers themselves.
1398 */
1399 if (p->if_type != IFT_ETHER &&
1400 p->if_type != IFT_L2VLAN &&
1401 (p->if_capenable & IFCAP_VLAN_HWTAGGING) == 0)
1402 return (EPROTONOSUPPORT);
1403 if ((p->if_flags & VLAN_IFFLAGS) != VLAN_IFFLAGS)
1404 return (EPROTONOSUPPORT);
1405 /*
1406 * Don't let the caller set up a VLAN VID with
1407 * anything except VLID bits.
1408 * VID numbers 0x0 and 0xFFF are reserved.
1409 */
1410 if (vid == 0 || vid == 0xFFF || (vid & ~EVL_VLID_MASK))
1411 return (EINVAL);
1412 if (ifv->ifv_trunk)
1413 return (EBUSY);
1414
1415 VLAN_XLOCK();
1416 if (p->if_vlantrunk == NULL) {
1417 trunk = malloc(sizeof(struct ifvlantrunk),
1418 M_VLAN, M_WAITOK | M_ZERO);
1419 vlan_inithash(trunk);
1420 TRUNK_LOCK_INIT(trunk);
1421 TRUNK_WLOCK(trunk);
1422 p->if_vlantrunk = trunk;
1423 trunk->parent = p;
1424 if_ref(trunk->parent);
1425 TRUNK_WUNLOCK(trunk);
1426 } else {
1427 trunk = p->if_vlantrunk;
1428 }
1429
1430 ifv->ifv_vid = vid; /* must set this before vlan_inshash() */
1431 ifv->ifv_pcp = 0; /* Default: best effort delivery. */
1432 error = vlan_inshash(trunk, ifv);
1433 if (error)
1434 goto done;
1435 ifv->ifv_proto = proto;
1436 ifv->ifv_encaplen = ETHER_VLAN_ENCAP_LEN;
1437 ifv->ifv_mintu = ETHERMIN;
1438 ifv->ifv_pflags = 0;
1439 ifv->ifv_capenable = -1;
1440
1441 /*
1442 * If the parent supports the VLAN_MTU capability,
1443 * i.e. can Tx/Rx larger than ETHER_MAX_LEN frames,

Callers 2

vlan_clone_createFunction · 0.85
vlan_ioctlFunction · 0.85

Calls 8

mallocFunction · 0.85
vlan_inithashFunction · 0.85
if_refFunction · 0.85
vlan_inshashFunction · 0.85
vlan_capabilitiesFunction · 0.85
taskqueue_enqueueFunction · 0.85
vlan_setflagsFunction · 0.85
vlan_setmultiFunction · 0.85

Tested by

no test coverage detected