FreeBSD/sys/netinet6/ip6_ipsec.c
/*
 * Compute the MTU for a forwarded packet that gets IPSEC encapsulated.
 * Called from ip_forward().
 * Returns MTU suggestion for ICMP needfrag reply.
 */
Compute the MTU for a forwarded packet that gets IPSEC encapsulated.
Compute the MTU for a forwarded packet that gets IPSEC encapsulated .
int
ip6_ipsec_mtu(struct mbuf *m)
{
	int mtu = 0;
#ifdef IPSEC
	struct secpolicy *sp = NULL;
	int ipsecerror;
	int ipsechdr;
	struct route *ro;
	sp = ipsec_getpolicybyaddr(m,
				   IPSEC_DIR_OUTBOUND,
				   IP_FORWARDING,
				   &ipsecerror);
	if (sp != NULL) {
		ipsechdr = ipsec_hdrsiz(m, IPSEC_DIR_OUTBOUND, NULL);
		if (sp->req != NULL &&
		    sp->req->sav != NULL &&
		    sp->req->sav->sah != NULL) {
			ro = &sp->req->sav->sah->route_cache.sa_route;
			if (ro->ro_rt && ro->ro_rt->rt_ifp) {
				mtu = ro->ro_rt->rt_mtu ? ro->ro_rt->rt_mtu :
				    ro->ro_rt->rt_ifp->if_mtu;
				mtu -= ipsechdr;
			}
		}
		KEY_FREESP(&sp);
	}
#endif 
	return mtu;
}
int ip6_ipsec_mtu ( struct mbuf * m ) { int mtu = 0 ; #ifdef IPSEC struct secpolicy * sp = NULL ; int ipsecerror ; int ipsechdr ; struct route * ro ; sp = ipsec_getpolicybyaddr ( m , IPSEC_DIR_OUTBOUND , IP_FORWARDING , & ipsecerror ) ; if ( sp != NULL ) { ipsechdr = ipsec_hdrsiz ( m , IPSEC_DIR_OUTBOUND , NULL ) ; if ( sp -> req != NULL && sp -> req -> sav != NULL && sp -> req -> sav -> sah != NULL ) { ro = & sp -> req -> sav -> sah -> route_cache . sa_route ; if ( ro -> ro_rt && ro -> ro_rt -> rt_ifp ) { mtu = ro -> ro_rt -> rt_mtu ? ro -> ro_rt -> rt_mtu : ro -> ro_rt -> rt_ifp -> if_mtu ; mtu -= ipsechdr ; } } KEY_FREESP ( & sp ) ; } #endif return mtu ; }
Compute the MTU for a forwarded packet that gets IPSEC encapsulated.
Compute the MTU for a forwarded packet that gets IPSEC encapsulated .
/*
	 * If the packet is routed over IPsec tunnel, tell the
	 * originator the tunnel MTU.
	 *	tunnel MTU = if MTU - sizeof(IP) - ESP/AH hdrsiz
	 * XXX quickhack!!!
	 */ /* count IPsec header size */ /*
		 * find the correct route for outer IPv4
		 * header, compute tunnel MTU.
		 */ /* IPSEC */ /* XXX else case missing. */