The invention is directed towards routing a packet using both IPSec and
common routing protocols within dynamic network topologies in a VPN. The
routing of IPSec packets employs Open System Interconnection (OSI) layer
three information. In one embodiment, a tree mechanism is used for
looking up layer three information that may be associated with a
protected subnetwork. When a packet is identified as being associated
with a protected subnetwork, the packet may be encrypted and
encapsulated, including the original destination and source IP address
header information within another packet employing the IP Encapsulating
Security Payload (ESP) protocol. New source and destination IP addresses
are provided for the new packet using IP addresses associated with an
entry gateway and an exit gateway to the VPN. The new packet may then be
routed through the VPN using traditional routing protocols.