其他分享
首页 > 其他分享> > k8s 的网络topology 探测utils

k8s 的网络topology 探测utils

作者:互联网

对于calico来说i,创建的interface都是veth类型

ipnet2dev(){
echo $(ip route | grep $1 | awk '{match($0, /.+dev\s([^ ]*)/, a);print a[1];exit}')
}


devtype(){
echo $(ethtool -i $1| grep "driver:" |awk '{print $2}')
}

# https://unix.stackexchange.com/questions/441876/how-to-find-the-network-namespace-of-a-veth-peer-ifindex
# ifindex=$(nsenter -t $pid -n ip link | sed -n -e 's/.*eth0@if\([0-9]*\):.*/\1/p')

ifindex(){
echo $( ip link | sed -n -e 's/.*'"$1"'@if\([0-9]*\):.*/\1/p')
}

# veth=$(ip -o link | grep ^$ifindex | sed -n -e 's/.*\(veth[[:alnum:]]*@if[[:digit:]]*\).*/\1/p')

vethpeer(){
echo $(ip -o link | grep ^$1 | sed -n -e 's/.*\(veth[[:alnum:]]*@if[[:digit:]]*\).*/\1/p')
}

index2peer(){
for peer in `ls /sys/class/net/`; do
  INDEX=`cat /sys/class/net/$peer/ifindex`
  if [[ $INDEX == $1 ]]; then
    echo $peer 
    return 0
  fi
done
echo "Error, not find peer"
return 1
}


index2peer(){
echo $(ip -o link | grep ^$1 | awk -F'[: ]' '{print $3}')
}

 

标签:grep,ip,utils,echo,ifindex,peer,k8s,veth,topology
来源: https://www.cnblogs.com/shaohef/p/14087959.html