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

Function pf_scrub_ip

freebsd/netpfil/pf/pf_norm.c:1983–2023  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1981
1982#ifdef INET
1983static void
1984pf_scrub_ip(struct mbuf **m0, u_int32_t flags, u_int8_t min_ttl, u_int8_t tos)
1985{
1986 struct mbuf *m = *m0;
1987 struct ip *h = mtod(m, struct ip *);
1988
1989 /* Clear IP_DF if no-df was requested */
1990 if (flags & PFRULE_NODF && h->ip_off & htons(IP_DF)) {
1991 u_int16_t ip_off = h->ip_off;
1992
1993 h->ip_off &= htons(~IP_DF);
1994 h->ip_sum = pf_cksum_fixup(h->ip_sum, ip_off, h->ip_off, 0);
1995 }
1996
1997 /* Enforce a minimum ttl, may cause endless packet loops */
1998 if (min_ttl && h->ip_ttl < min_ttl) {
1999 u_int16_t ip_ttl = h->ip_ttl;
2000
2001 h->ip_ttl = min_ttl;
2002 h->ip_sum = pf_cksum_fixup(h->ip_sum, ip_ttl, h->ip_ttl, 0);
2003 }
2004
2005 /* Enforce tos */
2006 if (flags & PFRULE_SET_TOS) {
2007 u_int16_t ov, nv;
2008
2009 ov = *(u_int16_t *)h;
2010 h->ip_tos = tos | (h->ip_tos & IPTOS_ECN_MASK);
2011 nv = *(u_int16_t *)h;
2012
2013 h->ip_sum = pf_cksum_fixup(h->ip_sum, ov, nv, 0);
2014 }
2015
2016 /* random-id, but not for fragments */
2017 if (flags & PFRULE_RANDOMID && !(h->ip_off & ~htons(IP_DF))) {
2018 uint16_t ip_id = h->ip_id;
2019
2020 ip_fillid(h);
2021 h->ip_sum = pf_cksum_fixup(h->ip_sum, ip_id, h->ip_id, 0);
2022 }
2023}
2024#endif /* INET */
2025
2026#ifdef INET6

Callers 1

pf_normalize_ipFunction · 0.85

Calls 2

pf_cksum_fixupFunction · 0.85
ip_fillidFunction · 0.85

Tested by

no test coverage detected