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

Function tcp_log_drain

freebsd/netinet/tcp_log_buf.c:1782–1835  ·  view source on GitHub ↗

If tcp_drain() is called, flush half the log entries. */

Source from the content-addressed store, hash-verified

1780
1781/* If tcp_drain() is called, flush half the log entries. */
1782void
1783tcp_log_drain(struct tcpcb *tp)
1784{
1785 struct tcp_log_mem *log_entry, *next;
1786 int target, skip;
1787
1788 INP_WLOCK_ASSERT(tp->t_inpcb);
1789 if ((target = tp->t_lognum / 2) == 0)
1790 return;
1791
1792 /*
1793 * If we are logging the "head" packets, we want to discard
1794 * from the tail of the queue. Otherwise, we want to discard
1795 * from the head.
1796 */
1797 if (tp->t_logstate == TCP_LOG_STATE_HEAD ||
1798 tp->t_logstate == TCP_LOG_STATE_HEAD_AUTO) {
1799 skip = tp->t_lognum - target;
1800 STAILQ_FOREACH(log_entry, &tp->t_logs, tlm_queue)
1801 if (!--skip)
1802 break;
1803 KASSERT(log_entry != NULL,
1804 ("%s: skipped through all entries!", __func__));
1805 if (log_entry == NULL)
1806 return;
1807 while ((next = STAILQ_NEXT(log_entry, tlm_queue)) != NULL) {
1808 STAILQ_REMOVE_AFTER(&tp->t_logs, log_entry, tlm_queue);
1809 tcp_log_entry_refcnt_rem(next);
1810 tcp_log_remove_log_cleanup(tp, next);
1811#ifdef INVARIANTS
1812 target--;
1813#endif
1814 }
1815 KASSERT(target == 0,
1816 ("%s: After removing from tail, target was %d", __func__,
1817 target));
1818 } else if (tp->t_logstate == TCP_LOG_STATE_CONTINUAL) {
1819 (void)tcp_log_dump_tp_logbuf(tp, "auto-dumped from continual",
1820 M_NOWAIT, false);
1821 } else {
1822 while ((log_entry = STAILQ_FIRST(&tp->t_logs)) != NULL &&
1823 target--)
1824 tcp_log_remove_log_head(tp, log_entry);
1825 KASSERT(target <= 0,
1826 ("%s: After removing from head, target was %d", __func__,
1827 target));
1828 KASSERT(tp->t_lognum > 0,
1829 ("%s: After removing from head, tp->t_lognum was %d",
1830 __func__, target));
1831 KASSERT(log_entry != NULL,
1832 ("%s: After removing from head, the tailq was empty",
1833 __func__));
1834 }
1835}
1836
1837static inline int
1838tcp_log_copyout(struct sockopt *sopt, void *src, void *dst, size_t len)

Callers 1

tcp_drainFunction · 0.85

Calls 3

tcp_log_dump_tp_logbufFunction · 0.85
tcp_log_remove_log_headFunction · 0.85

Tested by

no test coverage detected