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

Function stf_encapcheck

freebsd/net/if_stf.c:312–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

310DECLARE_MODULE(if_stf, stf_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
311
312static int
313stf_encapcheck(const struct mbuf *m, int off, int proto, void *arg)
314{
315 struct ip ip;
316 struct stf_softc *sc;
317 struct in_addr a, b, mask;
318 struct in6_addr addr6, mask6;
319
320 sc = (struct stf_softc *)arg;
321 if (sc == NULL)
322 return 0;
323
324 if ((STF2IFP(sc)->if_flags & IFF_UP) == 0)
325 return 0;
326
327 /* IFF_LINK0 means "no decapsulation" */
328 if ((STF2IFP(sc)->if_flags & IFF_LINK0) != 0)
329 return 0;
330
331 if (proto != IPPROTO_IPV6)
332 return 0;
333
334 m_copydata(m, 0, sizeof(ip), (caddr_t)&ip);
335
336 if (ip.ip_v != 4)
337 return 0;
338
339 if (stf_getsrcifa6(STF2IFP(sc), &addr6, &mask6) != 0)
340 return (0);
341
342 /*
343 * check if IPv4 dst matches the IPv4 address derived from the
344 * local 6to4 address.
345 * success on: dst = 10.1.1.1, ia6->ia_addr = 2002:0a01:0101:...
346 */
347 if (bcmp(GET_V4(&addr6), &ip.ip_dst, sizeof(ip.ip_dst)) != 0)
348 return 0;
349
350 /*
351 * check if IPv4 src matches the IPv4 address derived from the
352 * local 6to4 address masked by prefixmask.
353 * success on: src = 10.1.1.1, ia6->ia_addr = 2002:0a00:.../24
354 * fail on: src = 10.1.1.1, ia6->ia_addr = 2002:0b00:.../24
355 */
356 bzero(&a, sizeof(a));
357 bcopy(GET_V4(&addr6), &a, sizeof(a));
358 bcopy(GET_V4(&mask6), &mask, sizeof(mask));
359 a.s_addr &= mask.s_addr;
360 b = ip.ip_src;
361 b.s_addr &= mask.s_addr;
362 if (a.s_addr != b.s_addr)
363 return 0;
364
365 /* stf interface makes single side match only */
366 return 32;
367}
368
369static int

Callers

nothing calls this directly

Calls 3

m_copydataFunction · 0.85
stf_getsrcifa6Function · 0.85
bzeroFunction · 0.85

Tested by

no test coverage detected