X7ROOT File Manager
Current Path:
/usr/local/VMOptimizationTools_2.69.0
usr
/
local
/
VMOptimizationTools_2.69.0
/
📁
..
📄
LinuxUpdate.XML
(647 B)
📄
SangforVMSTool
(3.11 KB)
📄
SangforVMSTool.service
(194 B)
📄
action_common.sh
(13.34 KB)
📄
busybox_cmd_ln.sh
(2.24 KB)
📄
collect_test_data.sh
(1.16 KB)
📄
common_config.sh
(278 B)
📄
data_test_tool.sh
(16.62 KB)
📄
debian_vmconfig.sh
(13.48 KB)
📁
driver
📄
guest_system_config.sh
(1.82 KB)
📄
hostname_config
(1 B)
📄
ipv6_network_config
(94 B)
📄
log.sh
(1.36 KB)
📄
mod_test.sh
(3.69 KB)
📄
mod_test1.sh
(914 B)
📄
net_common.sh
(915 B)
📄
network_compat_flag
(0 B)
📄
network_config
(86 B)
📄
pwd_info_config
(1 B)
📄
redhat_vmconfig.sh
(17.93 KB)
📄
reset_duid_config
(21 B)
📄
sangfor_guest_datareport
(25.63 KB)
📄
sangfor_heartalive.sh
(2.37 KB)
📄
sangfor_module_update
(28.11 KB)
📄
sangfor_set_network.sh
(504 B)
📄
sangfor_sfping
(4.23 KB)
📄
sangfor_sshkey_gen
(1.29 KB)
📄
sangfor_update_ipc_callback
(5.29 KB)
📄
sangfor_vm_proxyd
(3.45 KB)
📄
sangfor_vm_proxyd_r
(4.4 KB)
📄
sangfor_vm_proxyd_w
(1.32 KB)
📄
sangfor_vmconfig
(3.55 KB)
📄
sangfor_vmconfig_common
(38.34 KB)
📄
sangfor_vmconfig_ipc_callback
(4.75 KB)
📄
sangfor_watchdog
(3.95 KB)
📄
sfping
(17.7 KB)
📄
sfping.pl
(8.57 KB)
📄
startall
(1.78 KB)
📄
stopall
(1.11 KB)
📄
suse_vmconfig.sh
(10.07 KB)
📁
tools_x64
📁
tools_x86
📄
uni_test.sh
(2.59 KB)
📄
update_common_func
(4.35 KB)
📄
update_common_header
(4.86 KB)
📄
update_config
(2.89 KB)
📄
update_install
(33.63 KB)
📄
update_network.flag
(1 B)
📄
virtio_nic_attr_set.sh
(2.42 KB)
📄
virtio_nic_compat.sh.old1610337499
(5.64 KB)
📄
vm_ip_recover.sh
(16.66 KB)
📄
vm_ipc.sh
(9.06 KB)
📄
vmconfig_common_func
(23.11 KB)
📄
vmconfig_common_header
(3.37 KB)
📄
vmconfig_config
(1.02 KB)
📄
vmtools-install.sh
(31.16 KB)
📄
watch_test.sh
(313 B)
📄
watchdog.sh
(1.39 KB)
📁
x64
📁
x86
Editing: vmconfig_common_func
#!/bin/bash #The common file. declare g_debian_network_cfg="/etc/network/interfaces" declare g_debian_network_cfg_dir="/etc/network/interfaces.d" declare g_redhat_network_cfg_dir="/etc/sysconfig/network-scripts" declare g_network_manager_connection_dir="/etc/NetworkManager/system-connections" declare g_suse_network_cfg_dir="/etc/sysconfig/network" declare g_suse_routes_config_file="/etc/sysconfig/network/routes" declare g_dns_config_file="/etc/resolv.conf" declare g_dns_netconfig_file="/etc/resolv.conf.netconfig" declare g_suse_netconfig_file="/etc/sysconfig/network/config" declare g_networkmanager_config_file="/etc/NetworkManager/NetworkManager.conf" # get the CIDR prefix from a dot-decimal netmask # param $1: netmask. eg: 255.255.255.0 # output: CIDR prefix. eg: 24 # return: none mask2cdr () { # Assumes there's no "255." after a non-255 byte in the mask local x=${1##*255.} set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) ${x%%.*} x=${1%%$3*} echo $(( $2 + (${#x}/4) )) } # get the dot-decimal netmask from a CIDR prefix # param $1: CIDR prefix. eg: 24 # output: netmask. eg: 255.255.255.0 # return: none cdr2mask () { # Number of args to shift, 255..255, first non-255 byte, zeroes set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0 [ $1 -gt 1 ] && shift $1 || shift echo ${1-0}.${2-0}.${3-0}.${4-0} } # 根据mac地址获取网卡名 # param $1: macaddr get_ifname_by_mac() { local macaddr=$1 ip link >/dev/null 2>&1 if [ $? -eq 0 ];then ip link |grep -i -B 1 ${macaddr} |awk '{if (NR==1)print $2}'|awk -F: '{print $1}' fi return 0 } # get ip address of interface # param $1: ifname, eg: eth0 # output: ip address eg:192.168.10.10 get_if_ip() { local ifname=$1 test -z "$ifname" && return 1 ip link >/dev/null 2>&1 if [ $? -eq 0 ];then ip addr show dev ${ifname} 2>/dev/null |awk '{if($1~/^inet$/)print $2}'|awk -F/ '{print $1}' else ifconfig >/dev/null 2>&1 if [ $? -eq 0 ];then ifconfig ${ifname} 2>/dev/null |awk '{if($1~/^inet$/)print $2}'|awk -F: '{print $2}' fi fi } # 获取之后并且比较ipv6地址 # param $1: ifname, eg: eth0 # param $2: ipv6_and_prefixlen # return 0 有相同的 1 没有相同的 get_if_ipv6_and_prefixlen() { local ifname=$1 local ipv6_and_prefixlen=$2 local cur_ipv6_and_prefixlen="" test -z "$ifname" && return 1 ip link >/dev/null 2>&1 if [ $? -eq 0 ];then cur_ipv6_and_prefixlen=`ip addr show dev ${ifname} 2>/dev/null |awk '{if($1~/^inet6$/)print $2}' | sed '/^fe80/d'` fi for i in $cur_ipv6_and_prefixlen do if [ x"$ipv6_and_prefixlen" == x"$i" ];then return 0 fi done log_debug "ipv6:$cur_ipv6_and_prefixlen $ipv6_and_prefixlen is diff" return 1 } #因为ip配置文件中只生效一个ipv6的地址,因此只获取一个ipv6地址,写入文件中 # param $1: ifname, eg: eth0 ##todo:支持获取和配置多个ip get_if_ipv6() { local ifname=$1 test -z "$ifname" && return 1 ip link >/dev/null 2>&1 if [ $? -eq 0 ];then ip addr show dev ${ifname} 2>/dev/null |awk '{if($1~/^inet6$/)print $2}'|awk -F/ '{print $1}' | sed '/^fe80/d' | head -n 1 else ifconfig >/dev/null 2>&1 if [ $? -eq 0 ];then ifconfig ${ifname} 2>/dev/null |awk '{if($1~/^inet6$/)print $3}' |awk -F/ '{print $1}' | sed '/^fe80/d' | head -n 1 fi fi } # get netmask of interface # param $1: ifname, eg: eth0 # output: netmask eg:255.255.255.0 get_if_mask() { local ifname=$1 local int_netmask="" test -z "$ifname" && return 1 ip link >/dev/null 2>&1 if [ $? -eq 0 ];then int_netmask=`ip addr show dev ${ifname} 2>/dev/null |awk '{if($1~/^inet$/)print $2}'|awk -F/ '{print $2}'` cdr2mask ${int_netmask} else ifconfig >/dev/null 2>&1 if [ $? -eq 0 ];then ifconfig ${ifname} 2>/dev/null |awk '{if($1~/^inet$/)print $4}'|awk -F: '{print $2}' fi fi } # get prefixlen # param $1: ifname, eg: eth0 # output: prefixlen get_if_ipv6_prefix_len() { local ifname=$1 test -z "$ifname" && return 1 ip link >/dev/null 2>&1 if [ $? -eq 0 ];then ip addr show dev ${ifname} 2>/dev/null |awk '{if($1~/^inet6$/)print $2}' | sed '/^fe80/d' |awk -F/ '{print $2}' | head -n 1 else ifconfig >/dev/null 2>&1 if [ $? -eq 0 ];then ifconfig ${ifname} 2>/dev/null |awk '{if($1~/^inet6$/)print $3}'| sed '/^fe80/d'|awk -F/ '{print $2}' | head -n 1 fi fi } # get default gateway of interface # param $1: ifname, eg: eth0 # output: gateway eg: 192.168.10.1 get_if_gateway() { local ifname=$1 test -z "$ifname" && return 1 ip route >/dev/null 2>&1 if [ $? -eq 0 ];then ip route 2>/dev/null | grep default | awk -v ifname="$ifname" '{if ($5==ifname) print $3}' fi } #因为只有第一个默认网关有效所以取第一个 # get ipv6 default gateway of interface # param $1: ifname, eg: eth0 get_if_ipv6_gateway() { local ifname=$1 test -z "$ifname" && return 1 log_info "get $ifname ipv6 gateway" ip -6 route >/dev/null 2>&1 if [ $? -eq 0 ];then ip -6 route 2>/dev/null | grep default | awk -v ifname="$ifname" '{if ($5==ifname) print $3}'| head -n 1 fi } # get current conneted uuid of interface # param $1: ifname,eg:eth0 nmcli_get_connected_uuid() { local ifname=$1 local uuid="" test -z "$ifname" && return 1 nmcli c list >/dev/null 2>&1 if [ $? -eq 0 ];then uuid=`nmcli -f UUID,DEVICES c status |awk -v ifname="$ifname" '{if ($2==ifname) print $1}'` else uuid=`nmcli -f UUID,DEVICE c show --active |awk -v ifname="$ifname" '{if ($2==ifname) print $1}'` fi echo $uuid } # get current conneted config id of interface by nmcli # param $1: ifname,eg:eth0 # param $2: ip_type # output: method(manual|auto|"") nmcli_get_config_ip_method() { local ifname=$1 local ip_type=$2 local uuid="" local ip_method="" test -z "$ifname" && return 1 uuid=`nmcli_get_connected_uuid "$ifname"` test -z "$uuid" && return 1 if [ x"$ip_type" == x"ipv4" ];then ip_method="ipv4.method" elif [ x"$ip_type" == x"ipv6" ];then ip_method="ipv6.method" else log_error "ip_type $ip_type is not ipv4 or ipv6" return 1 fi nmcli c list >/dev/null 2>&1 if [ $? -eq 0 ];then method=`nmcli c list uuid "$uuid" 2>/dev/null | grep "${ip_method}" |awk -F: '{print $2}'` else method=`nmcli c show uuid "$uuid" 2>/dev/null | grep "${ip_method}" |awk -F: '{print $2}'` fi echo $method } # get current config ip of interface by nmcli # param $1: ifname,eg:eth0 # param $2: ip_type # output: ipaddr,eg. 192.168.100.10 nmcli_get_config_ip() { local ifname=$1 local ip_type=$2 local uuid="" local ipaddr_type="" test -z "$ifname" && return 1 uuid=`nmcli_get_connected_uuid "$ifname"` test -z "$uuid" && return 1 ipaddr_type=`trans_ipaddr_type "$ip_type"` if [ x"$ipaddr_type" == x"" ];then log_error "no ip_type $ip_type ipaddr_type $ipaddr_type" return 1 fi nmcli c list >/dev/null 2>&1 if [ $? -eq 0 ];then addresses_value=`nmcli c list uuid "$uuid" 2>/dev/null | grep "${ipaddr_type}" | awk '{print $2}'` ip=`echo $addresses_value | awk -F "ip =" '{print $2}'|awk -F "/" '{print $1}'` # { ip = 192.168.1.10/24, gw = 192.168.1.1 }; { ip = 192.168.2.10/24, gw = 192.168.2.1 } else addresses_value=`nmcli c show uuid "$uuid" 2>/dev/null | grep "${ipaddr_type}" | awk '{print $2}'` # 192.168.50.12/24, 192.168.51.12/24 ip_cdr=`echo $addresses_value |awk -F "," '{print $1}'` ip=`echo "$ip_cdr" | awk -F "/" '{print $1}'` fi echo $ip } # get current config ip of interface by nmcli # param $1: ifname,eg:eth0 # output: netmask,eg. 255.255.255.0 nmcli_get_config_mask() { local ifname=$1 local ip_type=$2 local uuid="" local ipaddr_type="" test -z "$ifname" && return 1 uuid=`nmcli_get_connected_uuid "$ifname"` test -z "$uuid" && return 1 ipaddr_type=`trans_ipaddr_type "$ip_type"` if [ x"$ipaddr_type" == x"" ];then log_error "no ip_type $ip_type ipaddr_type $ipaddr_type" return 1 fi nmcli c list >/dev/null 2>&1 if [ $? -eq 0 ];then addresses_value=`nmcli c list uuid "$uuid" 2>/dev/null | grep "${ipaddr_type}" | awk '{print $2}'` # { ip = 192.168.1.10/24, gw = 192.168.1.1 }; { ip = 192.168.2.10/24, gw = 192.168.2.1 } ip_cdr=`echo $addresses_value | awk -F "ip =" '{print $2}'|awk -F "," '{print $1}'` else addresses_value=`nmcli c show uuid "$uuid" 2>/dev/null | grep "${ipaddr_type}" | awk '{print $2}'` # 192.168.50.12/24, 192.168.51.12/24 ip_cdr=`echo $addresses_value |awk -F "," '{print $1}'` fi if ! test -z "$ip_cdr";then cdr=`echo "$ip_cdr" | awk -F "/" '{print $2}'` if [ x"$ip_type" == x"ipv4" ];then cdr2mask $cdr elif [ x"$ip_type" == x"ipv6" ];then echo $cdr fi fi } # get current config gateway of interface by nmcli # param $1: ifname,eg:eth0 # output: gateway,eg. 192.168.100.1 # return none nmcli_get_config_gateway() { local ifname=$1 local ip_type=$2 local uuid="" local ip_gateway_type="" test -z "$ifname" && return 1 uuid=`nmcli_get_connected_uuid "$ifname"` test -z "$uuid" && return 1 if [ x"$ip_type" == x"ipv4" ];then ip_gateway_type="ipv4.gateway" elif [ x"$ip_type" == x"ipv6" ];then ip_gateway_type="ipv6.gateway" else log_error "ip_type $ip_type is not ipv4 or ipv6" return 1 fi nmcli c list >/dev/null 2>&1 if [ $? -eq 0 ];then addresses_value=`nmcli c list uuid "$uuid" 2>/dev/null | grep "${ip_gateway_type}" | awk '{print $2}'` # { ip = 192.168.1.10/24, gw = 192.168.1.1 }; { ip = 192.168.2.10/24, gw = 192.168.2.1 } gateway=`echo $addresses_value | awk -F "gw =" '{print $2}'|awk -F "}" '{print $1}'` else gateway=`nmcli c show uuid "$uuid" 2>/dev/null | grep "${ip_gateway_type}" | awk '{print $2}'` fi if [ x"$gateway" == x"--" ];then gateway="" fi echo $gateway } # check dns is already exist in config # param $1: dns # return 0(exist),1(not exist) check_dns_exist() { local dns=$1 local dns_num=0 for i in `cat /etc/resolv.conf | grep "^\s*nameserver"|awk '{print $2}'` do dns_num=`expr $dns_num + 1` if [ x"$dns" == x"$i" ];then log_debug "found dns:$dns" return 0 fi if [ ${dns_num} -gt 3 ];then log_debug "dns_num gt 3" break fi done log_debug "not found dns:$dns" return 1 } # 判断ip类型,为获取ip_net与ip6_net信息 # param $1: ip类型 ipv6 or ipv4 # output: ip_net or ip6_net trans_ip_type() { local ip_type=$1 local ip_tmp="" if [ x"$ip_type" == x"ipv4" ];then ip_tmp="ip_net" elif [ x"$ip_type" == x"ipv6" ];then ip_tmp="ip6_net" else ip_tmp="" fi echo $ip_tmp } # 判断ip类型,为命令获取对应类型地址所赋值 # param $1: ip类型 ipv6 or ipv4 # output: ipv4.addresses or ipv6.addresses trans_ipaddr_type() { local ip_type=$1 local ipaddr="" if [ x"$ip_type" == x"ipv4" ];then ipaddr="ipv4.addresses" elif [ x"$ip_type" == x"ipv6" ];then ipaddr="ipv6.addresses" else ipaddr="" fi echo $ipaddr } #因为添加了ipv6的信息格式inet6,使用grep查找inet时不加空格会使ipv6的也匹配上,所以空格不能取消,echo输出也必须加双引号 # param $1: ip类型 ipv6 or ipv4 # output: inet or inet6 trans_inet_type() { local ip_type=$1 local inet="" if [ x"$ip_type" == x"ipv4" ];then inet="inet " elif [ x"$ip_type" == x"ipv6" ];then inet="inet6 " else inet="" fi echo "$inet" } #检测ip_type是否为ipv4 or ipv6 # param $1: ip类型 ipv6 or ipv4 # return 0(是ipv4 or ipv6类型),1(not) check_iptype_is_ipv4_or_ipv6() { local ip_type=$1 if [ x"$ip_type" == x"ipv4" ] || [ x"$ip_type" == x"ipv6" ];then return 0 fi return 1 } # get current dns num # param: none # output: dns num # return: none get_sys_dns_num() { cat /etc/resolv.conf |grep "^\s*nameserver" | wc -l } # remove quotation mark of str # param$1: str # output: str after remove quotation mark # return: none remove_quotation_mark() { local str=$1 if ! test -z "$str";then str=`echo $str | sed $'s/\'//g'` str=`echo $str | sed $'s/"//g'` fi echo $str } # get value from config file # key value format: key=value # param $1: config file # param $2: key # output: value of key # return: none get_value_from_config() { local file=$1 local key=$2 #grep -w表示整个字符串的精确匹配,该字符串可以包含数字、字符、下划线,不同字符串之间以非数字、字符、下划线分割,目的是为区分IPADDR和IPADDR_0 value=`cat "$file" |grep -w "^\s*$key" |awk -F= '{if (NR==1) print $2}'` if ! test -z "$value";then value=`remove_quotation_mark "$value"` fi echo $value } is_network_manager_enable() { if [ ! -e "$g_networkmanager_config_file" ];then return 1 fi enable=`cat $g_networkmanager_config_file | grep "managed"|awk -F= '{print $2}'` if [ x"$enable" == x"true" ];then return 0 else return 1 fi } enable_network_manager() { if test -f "$g_networkmanager_config_file";then sed -i '/^\s*managed/s/false/true/' "$g_networkmanager_config_file" fi } disable_network_manager() { if test -f "$g_networkmanager_config_file";then sed -i '/^\s*managed/s/true/false/' "$g_networkmanager_config_file" fi } # 判断ip与网关等信息是否改变 # param $1: ip_type,eg:ipv4 or ipv6 # param $2: ifname,eg:eth0 # param $3: ipaddr,eg:192.168.100.100 # param $4: netmask,eg:255.255.255.0 # param $5: gateway,eg:192.168.100.1 # return 0(changed),1(not changed) check_if_config_changed() { local ip_type=$1 local ifname=$2 local ip=$3 local mask=$4 local gateway=$5 local cur_ip="" local cur_mask="" local cur_gateway="" if [ x"$ip" == x"" ];then log_debug "$ip_type ip:$ip is none" return 1 fi if [ x"$ip_type" == x"ipv4" ];then cur_ip=`get_if_ip $ifname` if [ x"$ip" != x"$cur_ip" ];then log_debug "$ifname $ip_type ip:$ip $cur_ip is diff" return 0 fi if [ x"$mask" != x"" ];then cur_mask=`get_if_mask $ifname` if [ x"$mask" != x"$cur_mask" ];then log_debug "$ifname $ip_type mask:$mask $cur_mask is diff" return 0 fi fi if [ x"$gateway" != x"" ];then cur_gateway=`get_if_gateway $ifname` if [ x"$gateway" != x"$cur_gateway" ];then log_debug "$ifname $ip_type gateway:$gateway $cur_gateway is diff" return 0 fi fi elif [ x"$ip_type" == x"ipv6" ]; then get_if_ipv6_and_prefixlen "$ifname" "${ip}/${mask}" check_cur_ip_exist=$? if [ ${check_cur_ip_exist} -eq 1 ];then log_debug "$ifname $ip_type is diff" return 0 fi if [ x"$gateway" != x"" ];then cur_gateway=`get_if_ipv6_gateway $ifname` if [ x"$gateway" != x"$cur_gateway" ];then log_debug "$ifname $ip_type gateway:$gateway $cur_gateway is diff" return 0 fi fi else log_error "$ifname ip_type $ip_type is not ipv4 or ipv6" fi log_debug "$ifname network status not change" return 1 } #更新dns change_update_linux_dns() { local dns1=$1 local dns2=$2 local cfg_dns_file=$3 local file_dns1="" local file_dns2="" if [ x"$dns1" != x"" ];then file_dns1=`cat $cfg_dns_file | grep "$dns1"` if [ x"$file_dns1" != x"" ]; then sed -i "/$dns1/d" $cfg_dns_file fi change_linux_dns "$dns1" "$cfg_dns_file" fi if [ x"$dns2" != x"" ];then file_dns2=`cat $cfg_dns_file | grep "$dns2"` if [ x"$file_dns2" != x"" ]; then sed -i "/$dns2/d" $cfg_dns_file fi change_linux_dns "$dns2" "$cfg_dns_file" fi return 0 } # acmp端提出的需求为仅修改dns的下直接覆盖系统原有的所有DNS # param $1 dns1 # return 0(success),1(fail) change_linux_dns() { local dns=$1 local cfg_dns_file=$2 local dns_num=0 local first_dns="" local orig_dns_list="" check_dns_num if [ $? -eq 1 ]; then first_dns=`cat $cfg_dns_file | grep "^\s*nameserver" | head -n 1` sed -i "/$first_dns/d" $cfg_dns_file fi echo "nameserver $dns" >> $cfg_dns_file return 0 } # 查看dns配置文件中的dns数有几个 check_dns_num() { local dns_num=0 for i in `cat /etc/resolv.conf | grep "^\s*nameserver" | awk '{print $2}'` do dns_num=`expr $dns_num + 1` done if [ $dns_num -ge 3 ];then return 1 fi return 0 } #检测ipv4的地址等合法性 # param $1: inet address,eg: 192.168.10.10 # return 0(valid),1(not valid) is_valid_inet_address() { if [ $# -ne 1 ];then return 1 fi addr=$1 if [[ $addr =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then field1=$(echo $addr|cut -d. -f1) field2=$(echo $addr|cut -d. -f2) field3=$(echo $addr|cut -d. -f3) field4=$(echo $addr|cut -d. -f4) if [ $field1 -le 255 -a $field2 -le 255 -a $field3 -le 255 -a $field4 -le 255 ]; then return 0 else return 1 fi else return 1 fi } # brief 检查是否是有效的网卡mac地址,例如 FE:FC:FE:66:82:31 # return 0(valid),1(not valid) is_valid_mac_address() { if [ $# -ne 1 ];then return 1 fi macaddr=$1 if [[ $macaddr =~ ^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$ ]]; then return 0 fi return 1 } #判断ipv6的地址是否合法 is_valid_inet6_address() { if [ $# -ne 1 ];then return 1 fi local addr=$1 local tmp_addr=$1 local old_ipv6_list="" local ipv6_ipv4="" local ipv4="" local ipv6=$1 local num=0 local ipv6_all_num=0 local three_str="" local space="" #过滤掉中间有空格的地址 space=`echo "$addr" | grep " "` if [ x"$space" != x"" ];then return 1 fi #过滤掉"::"除一个或者0个之外 num=`echo "$addr" |grep -o "::" |wc -l` if [ $num -ne 1 ] && [ $num -ne 0 ];then return 1 elif [ $num -eq 1 ];then ipv6_all_num=1 fi #过滤掉有一个或者多个":::" three_str=`echo "$addr" | grep ":::"` if [ x"$three_str" != x"" ];then return 1 fi #判断2001::1:192.168.10.11是否为内嵌ipv4,如果是则截取最后一个":"之后的192.168.10.11,并判断是否符合v4 ipv6_ipv4=`echo "$addr" | awk -F '[:]' '{print $NF}'` is_valid_inet_address "$ipv6_ipv4" if [ $? -eq 0 ];then #如果符合,将字段数置为2 ipv6_all_num=2 #将2001::1截取出来 ipv6=`echo $tmp_addr | sed "s/:$ipv6_ipv4//g"` fi #":"切割,判断每一段是否符合[0-9a-fA-F]{1,4} old_ipv6_list=`echo "$ipv6" | sed "s/:/ /g"` for get_ipv6 in $old_ipv6_list;do #判断字段总和数等于8,即过滤字段数大于8的ipv6地址 if [[ $get_ipv6 =~ ^[0-9a-fA-F]{1,4}$ ]];then ipv6_all_num=`expr $ipv6_all_num + 1` else return 1 fi done if [ $num -eq 0 ] && [ $ipv6_all_num -ne 8 ];then return 1 elif [ $num -eq 1 ] && [ $ipv6_all_num -gt 8 ];then return 1 fi return 0 } is_valid_inet6_prefixlen() { if [ $# -ne 1 ];then return 1 fi prefixlen=$1 if [ $prefixlen -le 128 ] && [ $prefixlen -gt 0 ]; then return 0 fi return 1 } # 将下发配置中的dns和网卡中的dns进行拼接取前三个 joint_config_net_dns() { local config_dns_list=$1 local net_dns_list=$2 local joint_dns_list="" local three_dns="" test -z "$config_dns_list" && return 1 if [ x"$net_dns_list" == x"" ];then echo "$config_dns_list" return 0 fi joint_dns_list="$config_dns_list $net_dns_list" log_info "joint_dns_list $joint_dns_list" #获取前面三个dns three_dns=`get_three_dns "$joint_dns_list"` echo $three_dns return 0 } #判断dns是否为空并且拼接 joint_dns() { local dns1=$1 local dns2=$2 local dns_list="" for dns in $@; do if [ x"$dns" != x"" ];then dns_list="$dns_list $dns" fi done #去掉字符串首尾空格(如果不去掉,cut用法不会过滤掉空格,取不到想要的字符串) echo "$dns_list" | awk '{gsub(/^\s+|\s+$/, "");print}' } #获取前面三个dns get_three_dns() { local all_ifname_dns=$1 local three_dns="" log_info "all_ifname_dns $all_ifname_dns" test -z "$all_ifname_dns" && return 1 three_dns=`echo $all_ifname_dns | cut -d " " -f 1-3` #去掉字符串首尾空格(如果不去掉,cut用法不会过滤掉空格,取不到想要的字符串) echo "$three_dns" | awk '{gsub(/^\s+|\s+$/, "");print}' } #更新linux的dns update_linux_dns() { local dns_list=$1 local cfg_dns_file=$2 test -z "$dns_list" && return 1 test -z "$cfg_dns_file" && return 1 check_resolv_cfg_dns "$dns_list" if [ $? -eq 0 ];then log_info "config and resolv dns is same,dns:$dns_list" return 1 fi #删除网卡中全部的dns sed -i "/nameserver/d" $cfg_dns_file for dns in $dns_list; do is_valid_ip_address "$dns" if [ $? -eq 0 ];then echo "nameserver $dns" >> $cfg_dns_file else log_error "dns:$dns is not vaild" fi done # Ubuntu系统中如果文件/etc/resolvconf/resolv.conf.d/base存在,则写入此文件中, # 需要执行命令才会写入/etc/resolv.conf文件 if [ x"$cfg_dns_file" != x"$g_dns_config_file" ];then resolvconf -u >/dev/null 2>&1 fi } #判断dns配置中的dns与配置中的dns是否相同 check_resolv_cfg_dns() { local config_dns_list=$1 local resolv_dns_list="" local num=1 local resolv_dns="" resolv_dns_list=`cat $g_dns_config_file | grep -w nameserver` for config_dns in $config_dns_list; do resolv_dns=`echo "$resolv_dns_list" | awk '{if(NR=="'"$num"'"){print $2}}'` if [ x"$resolv_dns" != x"$config_dns" ];then log_info "config_dns:$config_dns and resolv_dns:$resolv_dns is diff" return 1 fi if [ $num -eq 3 ];then return 0 fi num=`expr $num + 1` done return 0 } #判断下ip的合法性 is_valid_ip_address() { local ip=$1 local ip_type="" test -z "$ip" && return 1 is_valid_inet_address "$ip" if [ $? -eq 0 ];then return 0 fi is_valid_inet6_address "$ip" if [ $? -eq 0 ];then return 0 fi log_error "ip:$ip is not valid" return 1 }
Upload File
Create Folder