1*86d7f5d3SJohn Marino#!/bin/sh 2*86d7f5d3SJohn Marino# $FreeBSD: src/share/examples/netgraph/udp.tunnel,v 1.1 2000/01/28 00:44:30 archie Exp $ 3*86d7f5d3SJohn Marino# $DragonFly: src/share/examples/netgraph/udp.tunnel,v 1.2 2003/06/17 04:36:57 dillon Exp $ 4*86d7f5d3SJohn Marino 5*86d7f5d3SJohn Marino# This script sets up a virtual point-to-point WAN link between 6*86d7f5d3SJohn Marino# two subnets, using UDP packets as the ``WAN connection.'' 7*86d7f5d3SJohn Marino# The two subnets might be non-routable addresses behind a 8*86d7f5d3SJohn Marino# firewall. 9*86d7f5d3SJohn Marino# 10*86d7f5d3SJohn Marino 11*86d7f5d3SJohn Marino# Here define the local and remote inside networks as well 12*86d7f5d3SJohn Marino# as the local and remote outside IP addresses and UDP port 13*86d7f5d3SJohn Marino# number that will be used for the tunnel. 14*86d7f5d3SJohn Marino# 15*86d7f5d3SJohn MarinoLOC_INTERIOR_IP=192.168.1.1 16*86d7f5d3SJohn MarinoLOC_EXTERIOR_IP=1.1.1.1 17*86d7f5d3SJohn MarinoREM_INTERIOR_IP=192.168.2.1 18*86d7f5d3SJohn MarinoREM_EXTERIOR_IP=2.2.2.2 19*86d7f5d3SJohn MarinoREM_INSIDE_NET=192.168.2.0 20*86d7f5d3SJohn MarinoUDP_TUNNEL_PORT=4028 21*86d7f5d3SJohn Marino 22*86d7f5d3SJohn Marino# Create the interface node ``ng0'' if it doesn't exist already, 23*86d7f5d3SJohn Marino# otherwise just make sure it's not connected to anything. 24*86d7f5d3SJohn Marino# In FreeBSD, interfaces cannot be removed so it might already 25*86d7f5d3SJohn Marino# be there from before. 26*86d7f5d3SJohn Marino# 27*86d7f5d3SJohn Marinoif ifconfig ng0 >/dev/null 2>&1; then 28*86d7f5d3SJohn Marino ifconfig ng0 inet down delete >/dev/null 2>&1 29*86d7f5d3SJohn Marino ngctl shutdown ng0: 30*86d7f5d3SJohn Marinoelse 31*86d7f5d3SJohn Marino ngctl mkpeer iface dummy inet 32*86d7f5d3SJohn Marinofi 33*86d7f5d3SJohn Marino 34*86d7f5d3SJohn Marino# Attach a UDP socket to the ``inet'' hook of the interface node 35*86d7f5d3SJohn Marino# using the ng_ksocket(8) node type. 36*86d7f5d3SJohn Marino# 37*86d7f5d3SJohn Marinongctl mkpeer ng0: ksocket inet inet/dgram/udp 38*86d7f5d3SJohn Marino 39*86d7f5d3SJohn Marino# Bind the UDP socket to the local external IP address and port 40*86d7f5d3SJohn Marino# 41*86d7f5d3SJohn Marinongctl msg ng0:inet bind inet/${LOC_EXTERIOR_IP}:${UDP_TUNNEL_PORT} 42*86d7f5d3SJohn Marino 43*86d7f5d3SJohn Marino# Connect the UDP socket to the peer's external IP address and port 44*86d7f5d3SJohn Marino# 45*86d7f5d3SJohn Marinongctl msg ng0:inet connect inet/${REM_EXTERIOR_IP}:${UDP_TUNNEL_PORT} 46*86d7f5d3SJohn Marino 47*86d7f5d3SJohn Marino# Configure the point-to-point interface 48*86d7f5d3SJohn Marino# 49*86d7f5d3SJohn Marinoifconfig ng0 ${LOC_INTERIOR_IP} ${REM_INTERIOR_IP} 50*86d7f5d3SJohn Marino 51*86d7f5d3SJohn Marino# Add a route to the peer's interior network via the tunnel 52*86d7f5d3SJohn Marino# 53*86d7f5d3SJohn Marinoroute add ${REM_INSIDE_NET} ${REM_INTERIOR_IP} 54*86d7f5d3SJohn Marino 55