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

Function ng_l2tp_xmit_ctrl

freebsd/netgraph/ng_l2tp.c:1505–1583  ·  view source on GitHub ↗

* Transmit a control stream packet, payload optional. * The transmit sequence number is not incremented. */

Source from the content-addressed store, hash-verified

1503 * The transmit sequence number is not incremented.
1504 */
1505static int
1506ng_l2tp_xmit_ctrl(priv_p priv, struct mbuf *m, u_int16_t ns)
1507{
1508 struct l2tp_seq *const seq = &priv->seq;
1509 uint8_t *p;
1510 u_int16_t session_id = 0;
1511 int error;
1512
1513 mtx_lock(&seq->mtx);
1514
1515 /* Stop ack timer: we're sending an ack with this packet.
1516 Doing this before to keep state predictable after error. */
1517 if (callout_active(&seq->xack_timer))
1518 ng_uncallout(&seq->xack_timer, priv->node);
1519
1520 seq->xack = seq->nr;
1521
1522 mtx_unlock(&seq->mtx);
1523
1524 /* If no mbuf passed, send an empty packet (ZLB) */
1525 if (m == NULL) {
1526 /* Create a new mbuf for ZLB packet */
1527 MGETHDR(m, M_NOWAIT, MT_DATA);
1528 if (m == NULL) {
1529 priv->stats.memoryFailures++;
1530 return (ENOBUFS);
1531 }
1532 m->m_len = m->m_pkthdr.len = 12;
1533 m->m_pkthdr.rcvif = NULL;
1534 priv->stats.xmitZLBs++;
1535 } else {
1536 /* Strip off session ID */
1537 if (m->m_len < 2 && (m = m_pullup(m, 2)) == NULL) {
1538 priv->stats.memoryFailures++;
1539 return (ENOBUFS);
1540 }
1541 session_id = (mtod(m, u_int8_t *)[0] << 8) + mtod(m, u_int8_t *)[1];
1542
1543 /* Make room for L2TP header */
1544 M_PREPEND(m, 10, M_NOWAIT); /* - 2 + 12 = 10 */
1545 if (m == NULL) {
1546 priv->stats.memoryFailures++;
1547 return (ENOBUFS);
1548 }
1549
1550 /*
1551 * The below requires 12 contiguous bytes for the L2TP header
1552 * to be written into.
1553 */
1554 m = m_pullup(m, 12);
1555 if (m == NULL) {
1556 priv->stats.memoryFailures++;
1557 return (ENOBUFS);
1558 }
1559 }
1560
1561 /* Fill in L2TP header */
1562 p = mtod(m, u_int8_t *);

Callers 5

ng_l2tp_rcvdata_lowerFunction · 0.85
ng_l2tp_rcvdata_ctrlFunction · 0.85
ng_l2tp_seq_recv_nrFunction · 0.85
ng_l2tp_seq_xack_timeoutFunction · 0.85
ng_l2tp_seq_rack_timeoutFunction · 0.85

Calls 4

m_pullupFunction · 0.85
ng_uncalloutFunction · 0.70
mtx_lockFunction · 0.50
mtx_unlockFunction · 0.50

Tested by

no test coverage detected