123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #!/bin/bash
- # (c) 2013, 2014, f0o@devilcode.org
- # (c) 2015 by Maximilian Wilhelm <max@rfc2324.org>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- ALIASES_FILE="/etc/snmp/if_aliases"
- BASE='.1.3.6.1.2.1.31.1.1.1.18'
- ID=$(cut -d . -f 13 <<< $2)
- cache=$(ip l)
- if [ -z "$ID" ]; then
- ID=0
- fi
- if [ "$1" = "-n" ]; then
- IFS="
- "
- for dev in $(grep mtu <<<"$cache" | cut -d : -f 1|sort -n); do
- if [ "$LAST" == "$ID" ]; then
- ID=$dev
- BRK=1
- break
- else
- LAST=$dev
- fi
- done
- if [ -z "$BRK" ]; then
- exit 0
- fi
- fi
- IFACE=$(grep "^${ID}: " <<<"$cache" | sed 's/[:@]\s/ /g'| cut -d " " -f 2)
- echo ${BASE}.${ID}
- if [ "X${IFACE}" = "X" ]; then
- echo noSuchName
- else
- if_alias=""
- # Try to figure out current Linux distribution to guess network configuration file
- distro=""
- if [ -x /usr/bin/distro ]; then
- distro=$(distro | cut -d " " -f 1)
- elif which lsb_release >/dev/null 2>/dev/null; then
- distro="$(lsb_release -a 2>/dev/null | awk -F: '/^Distributor ID/ { print $2 }' | tr -d '[[:space:]]')"
- fi
- if [ "${distro}" ]; then
- case "${distro}" in
- Debian)
- cnf="/etc/network/interfaces"
- # TODO: Support /etc/network/interfaces.d/
- ;;
- Gentoo)
- cnf="/etc/conf.d/net"
- ;;
- CentOS|RedHat|SuSE|Mandriva|Mandrake)
- cnf="/etc/sysconfig/network-scripts/ifcfg-$IFACE"
- ;;
- Archlinux)
- cnf="/etc/conf.d/net-conf-$IFACE"
- ;;
- *)
- cnf=""
- ;;
- esac
- fi
- if [ -n "$cnf" ]; then
- if_alias=$(grep -i "^# $IFACE:" "${cnf}" | sed "s/^# $IFACE: //i")
- fi
- if [ ! "${if_alias}" -a -f "${ALIASES_FILE}" ]; then
- if_alias=$(grep -i "^$IFACE:" "${ALIASES_FILE}" | sed -e "s/^$IFACE:[[:space:]]*//")
- fi
- # FFHO local
- case "${IFACE}" in
- # Transit
- tun42)
- if_alias="Transit: Perfect Privacy"
- ;;
- he-ipv6)
- if_alias="Transit: HE-IPv6"
- ;;
- gre_ffrl*)
- if_alias="Transit: FFRL"
- ;;
- # Peerings
- icvpn)
- if_alias="Peering: ICVPN"
- ;;
- # Core
- core*)
- if_alias="Core: core-vpn"
- ;;
- bb-*)
- if_alias="Core: Backbone-vpn"
- ;;
- vlan1*)
- if_alias="Core: X-Connect"
- ;;
- inter-gw-vpn)
- if_alias="Core: Inter-Gateway-B.A.T.M.A.N."
- ;;
- # Server
- infra-srv-vpn|user-srv-vpn)
- if_alias="Server: ${IFACE}"
- ;;
- vlan3*)
- if_alias="Server: Mgmt"
- ;;
- # Customer
- mesh-*)
- if_alias="Cust: B.A.T.M.A.N. mesh"
- ;;
- vlan23)
- if_alias="Cust: Local Mesh break-out"
- ;;
- esac
- echo "string"
- echo ${if_alias}
- fi
- exit 0
|