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

Function ng_ppp_rcvdata

freebsd/netgraph/ng_ppp.c:1404–1463  ·  view source on GitHub ↗

* Receive data on a hook linkX. */

Source from the content-addressed store, hash-verified

1402 * Receive data on a hook linkX.
1403 */
1404static int
1405ng_ppp_rcvdata(hook_p hook, item_p item)
1406{
1407 const node_p node = NG_HOOK_NODE(hook);
1408 const priv_p priv = NG_NODE_PRIVATE(node);
1409 const int index = (intptr_t)NG_HOOK_PRIVATE(hook);
1410 const uint16_t linkNum = (uint16_t)~index;
1411 struct ng_ppp_link * const link = &priv->links[linkNum];
1412 uint16_t proto;
1413 struct mbuf *m;
1414 int error = 0;
1415
1416 KASSERT(linkNum < NG_PPP_MAX_LINKS,
1417 ("%s: bogus index 0x%x", __func__, index));
1418
1419 NGI_GET_M(item, m);
1420
1421 mtx_lock(&priv->rmtx);
1422
1423 /* Stats */
1424 link->stats.recvFrames++;
1425 link->stats.recvOctets += m->m_pkthdr.len;
1426
1427 /* Strip address and control fields, if present. */
1428 if (m->m_len < 2 && (m = m_pullup(m, 2)) == NULL)
1429 ERROUT(ENOBUFS);
1430 if (mtod(m, uint8_t *)[0] == 0xff &&
1431 mtod(m, uint8_t *)[1] == 0x03)
1432 m_adj(m, 2);
1433
1434 /* Get protocol number */
1435 if ((m = ng_ppp_cutproto(m, &proto)) == NULL)
1436 ERROUT(ENOBUFS);
1437 NGI_M(item) = m; /* Put changed m back into item. */
1438
1439 if (!PROT_VALID(proto)) {
1440 link->stats.badProtos++;
1441 ERROUT(EIO);
1442 }
1443
1444 /* LCP packets must go directly to bypass. */
1445 if (proto >= 0xB000) {
1446 mtx_unlock(&priv->rmtx);
1447 return (ng_ppp_bypass(node, item, proto, linkNum));
1448 }
1449
1450 /* Other packets are denied on a disabled link. */
1451 if (!link->conf.enableLink)
1452 ERROUT(ENXIO);
1453
1454 /* Proceed to multilink layer. Mutex will be unlocked inside. */
1455 error = ng_ppp_mp_recv(node, item, proto, linkNum);
1456 mtx_assert(&priv->rmtx, MA_NOTOWNED);
1457 return (error);
1458
1459done:
1460 mtx_unlock(&priv->rmtx);
1461 NG_FREE_ITEM(item);

Callers

nothing calls this directly

Calls 8

m_pullupFunction · 0.85
m_adjFunction · 0.85
ng_ppp_cutprotoFunction · 0.85
ng_ppp_bypassFunction · 0.85
ng_ppp_mp_recvFunction · 0.85
mtx_assertFunction · 0.85
mtx_lockFunction · 0.50
mtx_unlockFunction · 0.50

Tested by

no test coverage detected