commit 876c4280f73d4b4030392851a6be950307b2f962 Author: GnomeZworc Date: Sun Apr 27 19:23:58 2025 +0200 first commit Signed-off-by: GnomeZworc diff --git a/README.md b/README.md new file mode 100644 index 0000000..3da1e82 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Two + +this project is Two with bash on first move \ No newline at end of file diff --git a/start_net.sh b/start_net.sh new file mode 100644 index 0000000..96f58f0 --- /dev/null +++ b/start_net.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +function exec_command { + eval "${1}" +} + +function up_bridge { + local vpc="${1}" + local bridge="br-${2}" + local exec="" + + if [[ "${vpc}" != "" ]] + then + exec="ip netns exec ${vpc}" + fi + + exec_command "${exec} brctl addbr ${bridge}" + exec_command "${exec} brctl stp ${bridge} off" + exec_command "${exec} ip link set up dev ${bridge}" +} + +function up_vxlan { + local id="${1}" + local local_ip="${2}" + local bridge="br-${3}" + + ip link add "vxlan-${id}" type vxlan \ + id "${id}" \ + dstport 4789 \ + local "${local_ip}" \ + nolearning + brctl addif "${bridge}" "vxlan-${id}" + ip link set up dev "vxlan-${id}" +} + +function up_netns { + local netns="${1}" + local subnet="${2}" + local veth="veth-${subnet}" + + ip netns add "${netns}" + ip link add "${veth}-ext" type veth peer name "${veth}-int" netns ${netns} + ip link set up dev "${veth}-ext" + ip -n "${netns}" link set up dev "${veth}-int" +} + +INTERFACE="eno1" +LOCAL_IP=$(ip a | grep -E "^ .*${INTERFACE}$" | sed 's/ */ /g' | cut -d\ -f 3|cut -d\/ -f1) +VXLAN_ID="${2}" +SUBNET_NAME="${3}" +VPC_NAME="${4}" +TAP_NAME="${5}" + +echo "Create vm subnet" +echo " -> interface name : ${INTERFACE}" +echo " -> interface ip : ${LOCAL_IP}" +echo " -> vxlan id : ${VXLAN_ID}" +echo " -> subnet name : ${SUBNET_NAME}" +echo " -> vpn : ${VPC_NAME}" +echo " -> tapid : ${TAP_NAME}" + +up_netns "${VPC_NAME}" "${SUBNET_NAME}" + +up_bridge "" "${SUBNET_NAME}" +up_bridge "${VPC_NAME}" "${SUBNET_NAME}" + +up_vxlan "${VXLAN_ID}" "${LOCAL_IP}" "${SUBNET_NAME}" + + +brctl addif "br-${SUBNET_NAME}" "veth-${SUBNET_NAME}-ext" +ip netns exec "${VPC_NAME}" brctl addif "br-${SUBNET_NAME}" "veth-${SUBNET_NAME}-int" + +ip -n "${VPC_NAME}" tuntap add dev "tap${TAP_NAME}" mode tap +ip -n "${VPC_NAME}" link set up dev "tap${TAP_NAME}" +ip netns exec "${VPC_NAME}" brctl addif "br-${SUBNET_NAME}" "tap${TAP_NAME}" \ No newline at end of file