- Begin veth support...

This commit is contained in:
2025-06-30 18:06:00 +02:00
parent 91a6d88485
commit 41ad7590d9
2 changed files with 142 additions and 32 deletions

View File

@@ -124,7 +124,7 @@ network_dst_tab_load()
ndtl_host_name="vpn${ndtl_id}.vpn.rx3" ndtl_host_name="vpn${ndtl_id}.vpn.rx3"
tab_assign NETWORK_DST_TAB "${ndtl_id},Host_Name" "${ndtl_host_name}" tab_assign NETWORK_DST_TAB "${ndtl_id},Host_Name" "${ndtl_host_name}"
dns_lookup A "${ndtl_host_name}" "NOCACHE" dns_lookup "A" "${ndtl_host_name}" "NOCACHE"
tab_assign NETWORK_DST_TAB "${ndtl_id},IP" "${dns_value}" tab_assign NETWORK_DST_TAB "${ndtl_id},IP" "${dns_value}"
case "${ndtl_type}" case "${ndtl_type}"
@@ -191,7 +191,6 @@ network_dst_tab_get()
dst_bytes_sent=${NETWORK_DST_TAB["${dst_id},Bytes_Sent"]} dst_bytes_sent=${NETWORK_DST_TAB["${dst_id},Bytes_Sent"]}
dst_start_date=${NETWORK_DST_TAB["${dst_id},Start_Date"]} dst_start_date=${NETWORK_DST_TAB["${dst_id},Start_Date"]}
dst_uptime=${NETWORK_DST_TAB["${dst_id},Uptime"]} dst_uptime=${NETWORK_DST_TAB["${dst_id},Uptime"]}
} }
@@ -568,6 +567,111 @@ network_table_set()
#--------------------------------------------------------------------------------------------------------------------------
# veth_up
#--------------------------------------------------------------------------------------------------------------------------
function veth_up
{
vu_eth_dev_eth=$1
vu_peer_dev=$2
vu_eth_addr=$3
vu_eth_mask=$4
vu_peer_addr=$5
vu_table=$6
${LOG} "Create veth pair [${vu_eth_dev}]/[${vu_peer_dev}]..."
${DEBUG} ip link add ${vu_eth_dev} type veth peer name ${vu_peer_dev}
${LOG} "Configure host side [${vu_eth_dev}:${vu_eth_addr}/${vu_eth_mask}]..."
${DEBUG} ip link set ${vu_eth_dev} up
${DEBUG} ip addr add ${vu_eth_addr}/${vu_eth_mask} dev ${vu_eth_dev}
${LOG} "Configure IP rule and routing..."
${DEBUG} ip rule add from ${vu_peer_addr} table ${vu_table}
TABLE_LIST=${vu_table}
vu_route="$(ip route list table main | grep -e ${vu_eth_dev} | grep -e ${vu_eth_addr} | sed 's/ proto.*//')"
for vu_tab in ${TABLE_LIST}
do
${DEBUG} ip route add ${vu_route} table ${vu_tab}
done
}
#--------------------------------------------------------------------------------------------------------------------------
# veth_down
#--------------------------------------------------------------------------------------------------------------------------
function veth_down
{
vd_eth_dev_eth=$1
vd_peer_dev=$2
vd_eth_addr=$3
vd_eth_mask=$4
vd_peer_addr=$5
vd_table=$6
${LOG} "Remove IP routing and rule..."
TABLE_LIST=${vd_table}
vd_route="$(ip route list table main | grep -e ${vd_eth_dev} | grep -e ${vd_eth_addr} | sed 's/ proto.*//')"
for tab in ${TABLE_LIST}
do
${DEBUG} ip route show ${vd_route} table ${tab} &> /dev/null && ${DEBUG} ip route del ${route} table ${tab} &> /dev/null || true
done
${DEBUG} ip rule del from ${vd_peer_addr} &> /dev/null || true
${LOG} "Remove veth pair..."
${DEBUG} ip link show ${vd_eth_dev} &> /dev/null && ${DEBUG} ip link del ${vd_eth_dev} &> /dev/null
}
#--------------------------------------------------------------------------------------------------------------------------
# network_veth_init
#--------------------------------------------------------------------------------------------------------------------------
network_veth_init()
{
${LOG} "Add VEth"
}
#--------------------------------------------------------------------------------------------------------------------------
# network_veth_deinit
#--------------------------------------------------------------------------------------------------------------------------
network_veth_deinit()
{
${LOG} "Remove VEth"
}
#-------------------------------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------------------------
# network_forward_add # network_forward_add
#-------------------------------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------------------------
@@ -691,6 +795,40 @@ network_forward_stop()
#--------------------------------------------------------------------------------------------------------------------------
# network_start
#--------------------------------------------------------------------------------------------------------------------------
network_start()
{
network_table_init
network_veth_init
network_forward_start
}
#--------------------------------------------------------------------------------------------------------------------------
# network_stop
#--------------------------------------------------------------------------------------------------------------------------
network_stop()
{
network_forward_stop
network_veth_deinit
network_table_deinit
}
#-------------------------------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------------------------
# network_status # network_status
#-------------------------------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------------------------

View File

@@ -21,34 +21,6 @@ LOG=":"
# Some functions to make the below more readable # Some functions to make the below more readable
#--------------------------------------------------------------------------------------------------------------------------
# Rx3-Start
#--------------------------------------------------------------------------------------------------------------------------
rx3-start()
{
network_table_init
network_forward_start
}
#--------------------------------------------------------------------------------------------------------------------------
# Rx3-Stop
#--------------------------------------------------------------------------------------------------------------------------
rx3-stop()
{
network_forward_stop
network_table_deinit
return 0
}
#-------------------------------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------------------------
# Start # Start
#-------------------------------------------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------------------------------------------
@@ -62,7 +34,7 @@ start()
echo "already started" echo "already started"
RETVAL=0 RETVAL=0
else else
rx3-start network_start
RETVAL=$? RETVAL=$?
[ "$RETVAL" = 0 ] && touch /var/lock/subsys/rx3-net [ "$RETVAL" = 0 ] && touch /var/lock/subsys/rx3-net
@@ -83,7 +55,7 @@ stop()
if [ -r /var/lock/subsys/rx3-net ] if [ -r /var/lock/subsys/rx3-net ]
then then
rx3-stop network_stop
RETVAL=$? RETVAL=$?
else else