diff options
| author | Xiang Dai <long0dai@foxmail.com> | 2020-07-17 09:46:01 +0800 |
|---|---|---|
| committer | Xiang Dai <long0dai@foxmail.com> | 2020-07-17 09:46:01 +0800 |
| commit | 7c8d091e4c493f139199182bcf397c90bd168542 (patch) | |
| tree | f0adc67fc6b7eeacf8ecbdea68b5ea7c26eb7d09 /edgemesh | |
| parent | Merge pull request #1936 from kubeedge/dependabot/npm_and_yarn/mappers/modbus... (diff) | |
| download | kubeedge-7c8d091e4c493f139199182bcf397c90bd168542.tar.gz | |
EdgeMesh: remove useless scripts
Signed-off-by: Xiang Dai <long0dai@foxmail.com>
Diffstat (limited to 'edgemesh')
| -rw-r--r-- | edgemesh/tools/initContainer/createImg.sh | 33 | ||||
| -rw-r--r-- | edgemesh/tools/initContainer/deb/Dockerfile | 6 | ||||
| -rw-r--r-- | edgemesh/tools/initContainer/rpm/Dockerfile | 7 | ||||
| -rw-r--r-- | edgemesh/tools/initContainer/script/edgemesh-iptables.sh | 273 |
4 files changed, 0 insertions, 319 deletions
diff --git a/edgemesh/tools/initContainer/createImg.sh b/edgemesh/tools/initContainer/createImg.sh deleted file mode 100644 index 8b7c485be..000000000 --- a/edgemesh/tools/initContainer/createImg.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -echo 'create edgemesh init Container image' - -function usage() { - echo "execute 'sh createImg.sh [rpm | deb]' to create docker image" - echo "execute 'sh createImg.sh help for use help'" -} - -path="${1}" - -if [ "${path}" != "rpm" ] && [ "${path}" != "deb" ]; then - usage - exit 0 -fi - -echo "create a ${path} docker image" - -cp ./script/edgemesh-iptables.sh ./"${path}"/ - -cd ./"${path}"/ - -chmod 0777 edgemesh-iptables.sh - -if command -v docker > /dev/null 2>&1 ; then - #docker build - docker build -t edgemesh_init . - # delete iptables script - rm ./edgemesh-iptables.sh -else - echo 'the docker command is no found!!' - exit 1 -fi diff --git a/edgemesh/tools/initContainer/deb/Dockerfile b/edgemesh/tools/initContainer/deb/Dockerfile deleted file mode 100644 index 4413853a7..000000000 --- a/edgemesh/tools/initContainer/deb/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM ubuntu - -ADD edgemesh-iptables.sh /usr/local/bin -RUN apt-get update && apt-get install -y iproute2 iptables - -ENTRYPOINT ["usr/local/bin/edgemesh-iptables.sh"] diff --git a/edgemesh/tools/initContainer/rpm/Dockerfile b/edgemesh/tools/initContainer/rpm/Dockerfile deleted file mode 100644 index 2f3122c7d..000000000 --- a/edgemesh/tools/initContainer/rpm/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM centos:latest - -ADD edgemesh-iptables.sh /usr/local/bin - -RUN yum -y update && yum install -y iproute iptables - -ENTRYPOINT ["/usr/local/bin/edgemesh-iptables.sh"] diff --git a/edgemesh/tools/initContainer/script/edgemesh-iptables.sh b/edgemesh/tools/initContainer/script/edgemesh-iptables.sh deleted file mode 100644 index 86a7dc582..000000000 --- a/edgemesh/tools/initContainer/script/edgemesh-iptables.sh +++ /dev/null @@ -1,273 +0,0 @@ -#!/usr/bin/env bash - -function usage() { - echo 'this is the edgemesh-iptables usage' - echo "${0} -p PROXY_PORT [-i HIJACK_IP] [-t HIJACK_PORT] [-b EXCLUDE_IP] [-c EXCLUDE_PORT] [-h]" - echo '' - echo ' -p: Specify the edgemesh port to which all TCP traffic from the Pod will be redirected to. (default 10001)' - echo ' -i: Comma separated list of outbound IP for which traffic is to be redirected to edgemesh. The' - echo ' wildcard character "*" can be used to configure redirection for all IPs. (default "*")' - echo ' -t: Comma separated list of outbound Port for which traffic is to be redirected to edgemesh. The' - echo ' wildcard character "*" can be used to configure redirection for all Ports. (default "*")' - echo ' -b: Comma separated list of outbound IP range in CIDR to be excluded from redirection to edgemesh.' - echo ' The Empty character "" can be used to configure redirection for all IPs. (default "")' - echo ' -c: Comma separated list of outbound Port to be excluded from redirection to edgemesh. The' - echo ' Empty character "" can be used to configure redirection for all Ports. (default "")' - echo ' -h: for some help' -} - -# network namespace -NETMODE= - -# get the container network mode -function getContainerNetMode() { - if ip link |grep docker0 > /dev/null; then - echo 'this is the host mode,share with net namespace with host' - NETMODE='HOST' - else - echo 'this is the ohter container net mode(none,bridge),independent of the host net namespace' - NETMODE='OTHER' - fi -} - -# judge if argument is a valid ip address -function isValidIP() { - if isIPv4 "${1}"; then - true - elif isIPv6 "${1}"; then - true - else - false - fi -} - -function isIPv4() { - local ipv4matchString="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" - if [[ ${1} =~ ${ipv4matchString} ]]; then - true - else - false - fi -} - -function isIPv6() { - local ipv6matchString="^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$" - if [[ ${1} =~ ${ipv6matchString} ]]; then - true - else - false - fi -} - -function hostNetMode() { - echo 'this func used for host net mode' - echo 'TODO' -} - -function bridgeNetMode() { - echo 'this func used for bridge net mode' - # get default route - default_route=$(ip route show |grep default |awk '{print $3}') - - #clear EDGEMESH chain and rule,if exist - iptables -t nat -D OUTPUT -p tcp -j EDGEMESH_OUTBOUND 2>/dev/null - iptables -t nat -D OUTPUT -p udp --dport "53" -j EDGEMESH_OUTBOUND_DNS 2>/dev/null - iptables -t nat -F EDGEMESH_OUTBOUND 2>/dev/null - iptables -t nat -X EDGEMESH_OUTBOUND 2>/dev/null - - iptables -t nat -F EDGEMESH_OUTBOUND_REDIRECT 2>/dev/null - iptables -t nat -X EDGEMESH_OUTBOUND_REDIRECT 2>/dev/null - - iptables -t nat -F EDGEMESH_OUTBOUND_DNS 2>/dev/null - iptables -t nat -X EDGEMESH_OUTBOUND_DNS 2>/dev/null - - # make chain for edgemesh hijacking - iptables -t nat -N EDGEMESH_OUTBOUND_REDIRECT - iptables -t nat -A EDGEMESH_OUTBOUND_REDIRECT -p tcp -j DNAT --to-destination "${default_route}:${EDGEMESH_PROXY_PORT}" - iptables -t nat -N EDGEMESH_OUTBOUND - iptables -t nat -A OUTPUT -p tcp -j EDGEMESH_OUTBOUND - - # support dns use udp for dest port 53 - iptables -t nat -N EDGEMESH_OUTBOUND_DNS - iptables -t nat -A EDGEMESH_OUTBOUND_DNS -j DNAT --to-destination "${default_route}" - iptables -t nat -A OUTPUT -p udp --dport "53" -j EDGEMESH_OUTBOUND_DNS - - # excluded traffic for some port incloude some special port,such as 22 - iptables -t nat -A EDGEMESH_OUTBOUND -p tcp --dport "22" -j RETURN - if [ -n "${EDGEMESH_EXCLUDE_PORT}" ]; then - for port in "${port_exclude_list[@]}"; do - iptables -t nat -A EDGEMESH_OUTBOUND -p tcp --dport "${port}" -j RETURN - done - fi - # excluded traffic for some ips - if [ ${#ipv4_exclude_list[@]} -gt 0 ]; then - for ip in "${ipv4_exclude_list[@]}"; do - iptables -t nat -A EDGEMESH_OUTBOUND -d "${ip}" -j RETURN - done - fi - - # Redirect app callback to itself via Service IP (default not redirected) - get_local_IP=$(ip addr |grep inet|grep -v inet6|awk '{print $2}'|tr -d "addr:") - - for LOCAL_IP in $get_local_IP; do - ele=${LOCAL_IP%$splt} - echo "LOCAL_IP: $LOCAL_IP , $ele" - if isIPv4 $ele; then - iptables -t nat -A EDGEMESH_OUTBOUND -o lo ! -d "${LOCAL_IP}" -j EDGEMESH_OUTBOUND_REDIRECT - fi - done - # loopback traffic - iptables -t nat -A EDGEMESH_OUTBOUND -d 127.0.0.1/32 -j RETURN - - # hijacking - if [ ${#ipv4_include_list[@]} -gt 0 ]; then - # include Ips and ports are * - if [[ "${ipv4_include_list}" == "*" && "${EDGEMESH_HIJACK_PORT}" == "*" ]]; then - iptables -t nat -A EDGEMESH_OUTBOUND -p tcp -j EDGEMESH_OUTBOUND_REDIRECT - else - if [ "${ipv4_include_list}" != "*" ]; then - for ip in "${ipv4_include_list[@]}"; do - iptables -t nat -A EDGEMESH_OUTBOUND -p tcp -d "${ip}" -j EDGEMESH_OUTBOUND_REDIRECT - done - fi - if [ "${EDGEMESH_HIJACK_PORT}" != "*" ]; then - for port in "${port_include_list[@]}"; do - iptables -t nat -A EDGEMESH_OUTBOUND -p tcp --dport "${port}" -j EDGEMESH_OUTBOUND_REDIRECT - done - fi - - iptables -t nat -A EDGEMESH_OUTBOUND -j RETURN - fi - fi -} - -# variable -ipv4_exclude_list=() -ipv4_include_list=() -ipv6_exclude_list=() -ipv6_exclude_list=() -port_exclude_list=() -port_include_list=() - -splt='/*' -EDGEMESH_PROXY_PORT=${PROXY_PORT-10001} # default PROXY_PORT 10001 -EDGEMESH_HIJACK_IP=${HIJACK_IP-"*"} -EDGEMESH_HIJACK_PORT=${HIJACK_PORT-"*"} -EDGEMESH_EXCLUDE_IP=${EXCLUDE_IP-} -EDGEMESH_EXCLUDE_PORT=${EXCLUDE_PORT-} - -function main() { - getContainerNetMode - - while getopts ":p:i:t:b:c:h" opt; do - case ${opt} in - p) - EDGEMESH_PROXY_PORT=${OPTARG} - ;; - i) - EDGEMESH_HIJACK_IP=${OPTARG} - ;; - t) - EDGEMESH_HIJACK_PORT=${OPTARG} - ;; - b) - EDGEMESH_EXCLUDE_IP=${OPTARG} - ;; - c) - EDGEMESH_EXCLUDE_PORT=${OPTARG} - ;; - h) - usage - exit 0 - ;; - ?) - echo "Invalid option: -$OPTARG" >&2 - usage - exit 1 - ;; - esac - done - - echo "EdgeMesh iptables configration:" - echo "=====================================" - echo "Container Network mode is: ${NETMODE}" - echo "Variables:" - echo "EDGEMESH_PROXY_PORT=${EDGEMESH_PROXY_PORT-10001}" - echo "EDGEMESH_HIJACK_IP=${EDGEMESH_HIJACK_IP-"*"}" - echo "EDGEMESH_HIJACK_PORT=${EDGEMESH_HIJACK_PORT-"*"}" - echo "EDGEMESH_EXCLUDE_IP=${EDGEMESH_EXCLUDE_IP-}" - echo "EDGEMESH_EXCLUDE_PORT=${EDGEMESH_EXCLUDE_PORT-}" - - # parse parameter - IFS=',' read -ra EXCLUDE_IP <<< "${EDGEMESH_EXCLUDE_IP}" - IFS=',' read -ra INCLUDE_IP <<< "${EDGEMESH_HIJACK_IP}" - # echo "EXCLUDE_IP: ${EXCLUDE_IP}" - for range in "${EXCLUDE_IP[@]}"; do - r=${range%$splt} - if isValidIP "$r"; then - if isIPv4 "$r"; then - ipv4_exclude_list+=("$range") - elif isIPv6 "$r"; then - ipv6_exclude_list+=("$range") - fi - fi - done - - if [ "${EDGEMESH_HIJACK_IP}" == "*" ]; then - ipv4_include_list=("*") - ipv6_include_list=("*") - else - for range in "${INCLUDE_IP[@]}"; do - r=${range%$splt} - if isValidIP "$r";then - if isIPv4 "$r"; then - ipv4_include_list+=("$range") - elif isIPv6 "$r"; then - ipv6_include_list+=("$range") - fi - fi - done - fi - - IFS=',' read -ra INCLUDE_PORT <<< "${EDGEMESH_HIJACK_PORT}" - IFS=',' read -ra EXCLUDE_PORT <<< "${EDGEMESH_EXCLUDE_PORT}" - if [ "${EDGEMESH_HIJACK_PORT}" != "*" ]; then - for port in "${INCLUDE_PORT[@]}"; do - port_include_list+=("$port") - done - fi - - if [ -n "${EDGEMESH_EXCLUDE_PORT}" ]; then - for port in "${EXCLUDE_PORT[@]}"; do - port_exclude_list+=("$port") - done - fi - - echo "ipv4_include_list : ${ipv4_include_list[@]}" - echo "ipv4_exclude_list : ${ipv4_exclude_list[@]}" - echo "port_include_list : ${port_include_list[@]}" - echo "port_exclude_list : ${port_exclude_list[@]}" - - # bridge mode(port map) container network - if [ "${NETMODE}" = "OTHER" ]; then - echo " ${NETMODE} iptables configration" - bridgeNetMode - # if set ipv6 option - if false; then - echo 'TODO' - fi - # host mode container network - elif [ "${NETMODE}" = "HOST" ]; then - #hostNetMode - echo ${NETMODE} - # if set ipv6 option - if false; then - echo 'TODO' - fi - else - echo 'Dont support this container network ' - fi -} - -# start to configure -main "${@}" |
