ifAlias 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/bin/bash
  2. # (c) 2013, 2014, f0o@devilcode.org
  3. # (c) 2015 by Maximilian Wilhelm <max@rfc2324.org>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ALIASES_FILE="/etc/snmp/if_aliases"
  18. BASE='.1.3.6.1.2.1.31.1.1.1.18'
  19. ID=$(cut -d . -f 13 <<< $2)
  20. cache=$(ip l)
  21. if [ -z "$ID" ]; then
  22. ID=0
  23. fi
  24. if [ "$1" = "-n" ]; then
  25. IFS="
  26. "
  27. for dev in $(grep mtu <<<"$cache" | cut -d : -f 1|sort -n); do
  28. if [ "$LAST" == "$ID" ]; then
  29. ID=$dev
  30. BRK=1
  31. break
  32. else
  33. LAST=$dev
  34. fi
  35. done
  36. if [ -z "$BRK" ]; then
  37. exit 0
  38. fi
  39. fi
  40. IFACE=$(grep "^${ID}: " <<<"$cache" | sed 's/[:@]\s/ /g'| cut -d " " -f 2)
  41. echo ${BASE}.${ID}
  42. if [ "X${IFACE}" = "X" ]; then
  43. echo noSuchName
  44. else
  45. if_alias=""
  46. # Try to figure out current Linux distribution to guess network configuration file
  47. distro=""
  48. if [ -x /usr/bin/distro ]; then
  49. distro=$(distro | cut -d " " -f 1)
  50. elif which lsb_release >/dev/null 2>/dev/null; then
  51. distro="$(lsb_release -a 2>/dev/null | awk -F: '/^Distributor ID/ { print $2 }' | tr -d '[[:space:]]')"
  52. fi
  53. if [ "${distro}" ]; then
  54. case "${distro}" in
  55. Debian)
  56. cnf="/etc/network/interfaces"
  57. # TODO: Support /etc/network/interfaces.d/
  58. ;;
  59. Gentoo)
  60. cnf="/etc/conf.d/net"
  61. ;;
  62. CentOS|RedHat|SuSE|Mandriva|Mandrake)
  63. cnf="/etc/sysconfig/network-scripts/ifcfg-$IFACE"
  64. ;;
  65. Archlinux)
  66. cnf="/etc/conf.d/net-conf-$IFACE"
  67. ;;
  68. *)
  69. cnf=""
  70. ;;
  71. esac
  72. fi
  73. if [ -n "$cnf" ]; then
  74. if_alias=$(grep -i "^# $IFACE:" "${cnf}" | sed "s/^# $IFACE: //i")
  75. fi
  76. if [ ! "${if_alias}" -a -f "${ALIASES_FILE}" ]; then
  77. if_alias=$(grep -i "^$IFACE:" "${ALIASES_FILE}" | sed -e "s/^$IFACE:[[:space:]]*//")
  78. fi
  79. # FFHO local
  80. case "${IFACE}" in
  81. # Transit
  82. tun42)
  83. if_alias="Transit: Perfect Privacy"
  84. ;;
  85. he-ipv6)
  86. if_alias="Transit: HE-IPv6"
  87. ;;
  88. gre_ffrl*)
  89. if_alias="Transit: FFRL"
  90. ;;
  91. # Peerings
  92. icvpn)
  93. if_alias="Peering: ICVPN"
  94. ;;
  95. # Core
  96. core*)
  97. if_alias="Core: core-vpn"
  98. ;;
  99. bb-*)
  100. if_alias="Core: Backbone-vpn"
  101. ;;
  102. vlan1*)
  103. if_alias="Core: X-Connect"
  104. ;;
  105. inter-gw-vpn)
  106. if_alias="Core: Inter-Gateway-B.A.T.M.A.N."
  107. ;;
  108. # Server
  109. infra-srv-vpn|user-srv-vpn)
  110. if_alias="Server: ${IFACE}"
  111. ;;
  112. vlan3*)
  113. if_alias="Server: Mgmt"
  114. ;;
  115. # Customer
  116. mesh-*)
  117. if_alias="Cust: B.A.T.M.A.N. mesh"
  118. ;;
  119. vlan23)
  120. if_alias="Cust: Local Mesh break-out"
  121. ;;
  122. esac
  123. echo "string"
  124. echo ${if_alias}
  125. fi
  126. exit 0