ifAlias 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. # Generic magic removed.
  47. # FFHO local
  48. case "${IFACE}" in
  49. # Transit
  50. tun42)
  51. if_alias="Transit: Perfect Privacy"
  52. ;;
  53. he-ipv6)
  54. if_alias="Transit: HE-IPv6"
  55. ;;
  56. gre_ffrl*)
  57. if_alias="Transit: FFRL"
  58. ;;
  59. # Peerings
  60. icvpn)
  61. if_alias="Peering: ICVPN"
  62. ;;
  63. # Core
  64. core*)
  65. if_alias="Core: core-vpn"
  66. ;;
  67. bb-*)
  68. if_alias="Core: Backbone-vpn"
  69. ;;
  70. vlan1*)
  71. if_alias="Core: X-Connect"
  72. ;;
  73. inter-gw-vpn)
  74. if_alias="Core: Inter-Gateway-B.A.T.M.A.N."
  75. ;;
  76. # Server
  77. infra-srv-vpn|user-srv-vpn)
  78. if_alias="Server: ${IFACE}"
  79. ;;
  80. vlan3*)
  81. if_alias="Server: Mgmt"
  82. ;;
  83. # Customer
  84. mesh-*)
  85. if_alias="Cust: B.A.T.M.A.N. mesh"
  86. ;;
  87. vlan23)
  88. if_alias="Cust: Local Mesh break-out"
  89. ;;
  90. esac
  91. echo "string"
  92. echo ${if_alias}
  93. fi
  94. exit 0