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

Function m_striphdr

freebsd/netipsec/ipsec_mbuf.c:244–307  ·  view source on GitHub ↗

* Remove hlen data at offset skip in the packet. This is used by * the protocols strip protocol headers and associated data (e.g. IV, * authenticator) on input. */

Source from the content-addressed store, hash-verified

242 * authenticator) on input.
243 */
244int
245m_striphdr(struct mbuf *m, int skip, int hlen)
246{
247 struct mbuf *m1;
248 int roff;
249
250 /* Find beginning of header */
251 m1 = m_getptr(m, skip, &roff);
252 if (m1 == NULL)
253 return (EINVAL);
254
255 /* Remove the header and associated data from the mbuf. */
256 if (roff == 0) {
257 /* The header was at the beginning of the mbuf */
258 IPSECSTAT_INC(ips_input_front);
259 m_adj(m1, hlen);
260 if (m1 != m)
261 m->m_pkthdr.len -= hlen;
262 } else if (roff + hlen >= m1->m_len) {
263 struct mbuf *mo;
264 int adjlen;
265
266 /*
267 * Part or all of the header is at the end of this mbuf,
268 * so first let's remove the remainder of the header from
269 * the beginning of the remainder of the mbuf chain, if any.
270 */
271 IPSECSTAT_INC(ips_input_end);
272 if (roff + hlen > m1->m_len) {
273 adjlen = roff + hlen - m1->m_len;
274
275 /* Adjust the next mbuf by the remainder */
276 m_adj(m1->m_next, adjlen);
277
278 /* The second mbuf is guaranteed not to have a pkthdr... */
279 m->m_pkthdr.len -= adjlen;
280 }
281
282 /* Now, let's unlink the mbuf chain for a second...*/
283 mo = m1->m_next;
284 m1->m_next = NULL;
285
286 /* ...and trim the end of the first part of the chain...sick */
287 adjlen = m1->m_len - roff;
288 m_adj(m1, -adjlen);
289 if (m1 != m)
290 m->m_pkthdr.len -= adjlen;
291
292 /* Finally, let's relink */
293 m1->m_next = mo;
294 } else {
295 /*
296 * The header lies in the "middle" of the mbuf; copy
297 * the remainder of the mbuf down over the header.
298 */
299 IPSECSTAT_INC(ips_input_middle);
300 bcopy(mtod(m1, u_char *) + roff + hlen,
301 mtod(m1, u_char *) + roff,

Callers 7

ipsec4_common_input_cbFunction · 0.85
ifFunction · 0.85
ipsec6_common_input_cbFunction · 0.85
udp_ipsec_inputFunction · 0.85
ipcomp_input_cbFunction · 0.85
ah_input_cbFunction · 0.85
esp_input_cbFunction · 0.85

Calls 2

m_getptrFunction · 0.85
m_adjFunction · 0.85

Tested by

no test coverage detected