github.com/cloudfoundry-attic/garden-linux@v0.333.2-candidate/linux_backend/skeleton/net.sh (about)

     1  #!/bin/bash
     2  
     3  [ -n "$DEBUG" ] && set -o xtrace
     4  set -o nounset
     5  set -o errexit
     6  shopt -s nullglob
     7  
     8  cd $(dirname "${0}")
     9  
    10  source ./etc/config
    11  
    12  filter_instance_prefix="${GARDEN_IPTABLES_FILTER_INSTANCE_PREFIX}"
    13  nat_instance_chain="${filter_instance_prefix}${id}"
    14  
    15  case "${1}" in
    16     "in")
    17      if [ -z "${HOST_PORT:-}" ]; then
    18        echo "Please specify HOST_PORT..." 1>&2
    19        exit 1
    20      fi
    21  
    22      if [ -z "${CONTAINER_PORT:-}" ]; then
    23        echo "Please specify CONTAINER_PORT..." 1>&2
    24        exit 1
    25      fi
    26  
    27      iptables --wait --table nat -A ${nat_instance_chain} \
    28        --protocol tcp \
    29        --destination "${external_ip}" \
    30        --destination-port "${HOST_PORT}" \
    31        --jump DNAT \
    32        --to-destination "${network_container_ip}:${CONTAINER_PORT}"
    33  
    34      ;;
    35  
    36    "get_ingress_info")
    37      if [ -z "${ID:-}" ]; then
    38        echo "Please specify container ID..." 1>&2
    39        exit 1
    40      fi
    41      tc filter show dev ${network_host_iface} parent ffff:
    42  
    43      ;;
    44    "get_egress_info")
    45      if [ -z "${ID:-}" ]; then
    46        echo "Please specify container ID..." 1>&2
    47        exit 1
    48      fi
    49      tc qdisc show dev ${network_host_iface}
    50  
    51      ;;
    52    *)
    53      echo "Unknown command: ${1}" 1>&2
    54      exit 1
    55  
    56      ;;
    57  esac