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

Function tcp_log_expandlogbuf

freebsd/netinet/tcp_log_buf.c:2090–2138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2088}
2089
2090static struct tcp_log_common_header *
2091tcp_log_expandlogbuf(struct tcp_log_dev_queue *param)
2092{
2093 struct tcp_log_dev_log_queue *entry;
2094 struct tcp_log_header *hdr;
2095 uint8_t *end;
2096 struct sockopt sopt;
2097 int error;
2098
2099 entry = (struct tcp_log_dev_log_queue *)param;
2100
2101 /* Take a worst-case guess at space needs. */
2102 sopt.sopt_valsize = sizeof(struct tcp_log_header) +
2103 entry->tldl_count * (sizeof(struct tcp_log_buffer) +
2104 sizeof(struct tcp_log_verbose));
2105 hdr = malloc(sopt.sopt_valsize, M_TCPLOGDEV, M_NOWAIT);
2106 if (hdr == NULL) {
2107#ifdef TCPLOG_DEBUG_COUNTERS
2108 counter_u64_add(tcp_log_que_fail5, entry->tldl_count);
2109#endif
2110 return (NULL);
2111 }
2112 sopt.sopt_val = hdr + 1;
2113 sopt.sopt_valsize -= sizeof(struct tcp_log_header);
2114 sopt.sopt_td = NULL;
2115
2116 error = tcp_log_logs_to_buf(&sopt, &entry->tldl_entries,
2117 (struct tcp_log_buffer **)&end, entry->tldl_count);
2118 if (error) {
2119 free(hdr, M_TCPLOGDEV);
2120 return (NULL);
2121 }
2122
2123 /* Free the entries. */
2124 tcp_log_free_entries(&entry->tldl_entries, &entry->tldl_count);
2125 entry->tldl_count = 0;
2126
2127 memset(hdr, 0, sizeof(struct tcp_log_header));
2128 hdr->tlh_version = TCP_LOG_BUF_VER;
2129 hdr->tlh_type = TCP_LOG_DEV_TYPE_BBR;
2130 hdr->tlh_length = end - (uint8_t *)hdr;
2131 hdr->tlh_ie = entry->tldl_ie;
2132 hdr->tlh_af = entry->tldl_af;
2133 getboottime(&hdr->tlh_offset);
2134 strlcpy(hdr->tlh_id, entry->tldl_id, TCP_LOG_ID_LEN);
2135 strlcpy(hdr->tlh_tag, entry->tldl_tag, TCP_LOG_TAG_LEN);
2136 strlcpy(hdr->tlh_reason, entry->tldl_reason, TCP_LOG_REASON_LEN);
2137 return ((struct tcp_log_common_header *)hdr);
2138}
2139
2140/*
2141 * Queue the tcpcb's log buffer for transmission via the log buffer facility.

Callers

nothing calls this directly

Calls 8

mallocFunction · 0.85
tcp_log_logs_to_bufFunction · 0.85
tcp_log_free_entriesFunction · 0.85
memsetFunction · 0.85
getboottimeFunction · 0.85
counter_u64_addFunction · 0.50
freeFunction · 0.50
strlcpyFunction · 0.50

Tested by

no test coverage detected