This file is indexed.

/sbin/ifenslave is in ifenslave 2.4ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh

#    Copyright (C) 2012-2013  Guus Sliepen <guus@debian.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/>.

set -e

version() {
	echo 'ifenslave.sh version 2 (2013-05-05)'
	echo 'Copyright (c) 2012-2013 Guus Sliepen <guus@debian.org>'
	exit 0
}

usage() {
	echo 'Usage: ifenslave [-acdfhuvV] <master> <slave> ...'
	exit 0
}

error() {
	echo "$@" >&2
	exit 1
}

all_interfaces() {
	# I guess this was a debugging feature.
	ip link show
	exit 0
}

# Parse options

while true; do
	if [ "$1" = "-a" -o "$1" = "--all-interfaces" ]; then
		all_interfaces
	elif [ "$1" = "-c" -o "$1" = "--change-active" ]; then
		CHANGE_ACTIVE=1; shift
	elif [ "$1" = "-d" -o "$1" = "--detach" ]; then
		DETACH=1; shift
	elif [ "$1" = "-f" -o "$1" = "--force" ]; then
		FORCE=1; shift
	elif [ "$1" = "-h" -o "$1" = "--help" ]; then
		exec man 8 ifenslave
	elif [ "$1" = "-u" -o "$1" = "--usage" ]; then
		usage
	elif [ "$1" = "-v" -o "$1" = "--verbose" ]; then
		VERBOSE=1; shift
	elif [ "$1" = "-V" -o "$1" = "--version" ]; then
		version
	elif [ "$1" = "--" ]; then
		shift
		break
	else
		break
	fi
done

# Check that we have enough arguments remaining.

[ -z "$2" ] && error "Not enough arguments"

master="$1"
shift

# Check that the master is really a bonding interface.

[ -d "/sys/class/net/$master" ] || error "$master: no such interface"
[ -d "/sys/class/net/$master/bonding" ] || error "$master: is not a bonding interface"

# Do we need to change the active interface?

if [ "$CHANGE_ACTIVE" = 1 ]; then
	[ -z "$2" ] || error 'You can only set one interface to be the active slave!'
	[ "$VERBOSE" = 1 ] && echo "Changing active slave of $master to $slave"
	echo "$1" >"/sys/class/net/$master/bonding/active_slave" || error "$master: could not set $slave to active slave"
	exit 0
fi

# Otherwise, loop over all slaves and either attach or detach them.

for slave in "$@"; do
	[ -d "/sys/class/net/$slave" ] || error "$slave: no such interface"

	if [ -z "$DETACH" ]; then
		if [ -h "/sys/class/net/$master/slave_$slave" ]; then
			echo "$slave: already enslaved to $master" >&2
			continue
		fi

		read type <"/sys/class/net/$slave/type"
		if [ -z "$FORCE" -a "$type" != "1" ]; then
			error "$slave: does not appear to be an Ethernet interface (use -f to force)"
		fi

		[ "$VERBOSE" = 1 ] && echo "Adding slave $slave to master $master"
		ip link set "$slave" down
		echo "+$slave" >"/sys/class/net/$master/bonding/slaves" || error "$slave: could not add interface"
	else
		if [ ! -h "/sys/class/net/$master/slave_$slave" ]; then
			echo "$slave: is not enslaved to $master" >&2
			continue
		fi

		[ "$VERBOSE" = 1 ] && echo "Detaching slave $slave from master $master"
		echo "-$slave" >"/sys/class/net/$master/bonding/slaves" || error "$slave: could not detach interface"
	fi
done

exit 0