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

Function ng_tcpmss_rcvdata

freebsd/netgraph/ng_tcpmss.c:266–357  ·  view source on GitHub ↗

* Receive data on a hook, and hack MSS. * */

Source from the content-addressed store, hash-verified

264 *
265 */
266static int
267ng_tcpmss_rcvdata(hook_p hook, item_p item)
268{
269 hpriv_p priv = NG_HOOK_PRIVATE(hook);
270 struct mbuf *m = NULL;
271 struct ip *ip;
272 struct tcphdr *tcp;
273 int iphlen, tcphlen, pktlen;
274 int pullup_len = 0;
275 int error = 0;
276
277 /* Drop packets if filter is not configured on this hook. */
278 if (priv->outHook == NULL)
279 goto done;
280
281 NGI_GET_M(item, m);
282
283 /* Update stats on incoming hook. */
284 pktlen = m->m_pkthdr.len;
285 priv->stats.Octets += pktlen;
286 priv->stats.Packets++;
287
288 /* Check whether we configured to fix MSS. */
289 if (priv->stats.maxMSS == 0)
290 goto send;
291
292#define M_CHECK(length) do { \
293 pullup_len += length; \
294 if ((m)->m_pkthdr.len < pullup_len) \
295 goto send; \
296 if ((m)->m_len < pullup_len && \
297 (((m) = m_pullup((m), pullup_len)) == NULL)) \
298 ERROUT(ENOBUFS); \
299 } while (0)
300
301 /* Check mbuf packet size and arrange for IP header. */
302 M_CHECK(sizeof(struct ip));
303 ip = mtod(m, struct ip *);
304
305 /* Check IP version. */
306 if (ip->ip_v != IPVERSION)
307 ERROUT(EINVAL);
308
309 /* Check IP header length. */
310 iphlen = ip->ip_hl << 2;
311 if (iphlen < sizeof(struct ip) || iphlen > pktlen )
312 ERROUT(EINVAL);
313
314 /* Check if it is TCP. */
315 if (!(ip->ip_p == IPPROTO_TCP))
316 goto send;
317
318 /* Check mbuf packet size and arrange for IP+TCP header */
319 M_CHECK(iphlen - sizeof(struct ip) + sizeof(struct tcphdr));
320 ip = mtod(m, struct ip *);
321 tcp = (struct tcphdr *)((caddr_t )ip + iphlen);
322
323 /* Check TCP header length. */

Callers

nothing calls this directly

Calls 1

correct_mssFunction · 0.85

Tested by

no test coverage detected