This file is indexed.

/etc/fcoe/scripts/fcoeplumb is in fcoe-utils 1.0.9-0ubuntu4.

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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#! /bin/bash
#
# Copyright(c) 2009 Intel Corporation. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope 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, write to the Free Software Foundation, Inc.,
# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
#
# Maintained at www.Open-FCoE.org

cmdname=`basename $0`

usage()
{
	echo usage: $cmdname \
		'[--fcoeif <ethX> --reset | --create | --destroy]' \
		'[--debug] [--syslog]' \
		'[--netif <ethX> --qos-disable |' \
		'--qos-enable  <pri>[,<pri>]...]' >&2
	exit 1
}

#
# Tunable parameters
#
QOS_DEF=3			# default user priority
FCOE_ETHERTYPE=35078		# Ethertype (0x8906): tc filter show is base 10
FIP_ETHERTYPE=35092             # Ethertype (0x8914): tc filter show is base 10
FCOE_FILTER=0xfc0e		# filter handle (must be lower-case hex)

FCOE_FILTER_KEY=12345
FIP_FILTER_KEY=67890

qdisc_id=1:
qos_list=
cmd=
# automake paths
prefix=/usr
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
sbindir=${exec_prefix}/sbin
sysconfdir=/etc
# make sure there's a sane path to find basic commands and system tools (tc)
PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
FCOEADM=${sbindir}/fcoeadm	# command to create/destroy FCoE instances
CONFIG_DIR=${sysconfdir}/fcoe
LOGGER=
DEBUG_LOGGING=

find_multiq_qdisc()
{
	ifname=$1

	found=0
	type=unknown
	if set -- `tc qdisc show dev $ifname` none none none
	then
		type=$2
		qdisc_id=$3
	fi
	[ "$type" == "multiq" ] && found=1

	return $found
}

add_multiq_qdisc()
{
	ifname=$1
	qdisc_id=$2

	[ ${DEBUG_LOGGING} ] && $LOGGER \
		"tc qdisc add dev $ifname root handle $qdisc_id multiq"
	tc qdisc add dev $ifname root handle $qdisc_id multiq
}

get_filter_id()
{
	ifname=$1
	filter_key=$2

	retry_count=0
	while true
	do
		[ $retry_count -eq 0 ] && break
		[ -f /var/run/fcoemon.pid ] && break
		sleep 1
		retry_count=$(($retry_count-1))
	done

	echo "`echo "$ifname $filter_key" | \
	    awk '{ printf("0x%x%06x", substr($1,4), $2) }'`"
}

find_skbedit_filter()
{
	ifname=$1
	ethertype=$2
	filter_id=$3

	found=`tc filter show dev $ifname | awk '
	BEGIN {
		x1 = 0
		x2 = 0
		x3 = 0
		queue = 8
	}
	/^filter.*parent.*protocol \['$ethertype'\].* handle '$filter_id'/ {
		if (x1 == 0 && x2 == 0 && x3 == 0)
			x1 = 1
	}
	/cmp.*u16 at 12 layer 1 mask 0xffff eq '$ethertype'.*\)/ {
		if (x1 == 1 && x2 == 0 && x3 == 0)
			x2 = 1
	}
	/action order [0-9][0-9]*:  skbedit queue_mapping/ {
		if (x1 == 1 && x2 == 1 && x3 == 0) {
			x3 = 1
			queue = $6
		}
	}
	END {
		print queue
	}'`

	return $found
}

delete_skbedit_filter()
{
	ifname=$1
	queue=$2
	ethertype=$3
	filter_id=$4

	[ ${DEBUG_LOGGING} ] && $LOGGER \
		"tc filter delete dev $ifname skbedit queue_mapping $queue"
	PARENT=`tc filter show dev $ifname | awk \
		'/^filter.*parent.*protocol \['$ethertype'\].* handle '$filter_id'/ \
		{ print $3 }'`
	PRIO=`tc filter show dev $ifname | awk \
		'/^filter.*parent.*protocol \['$ethertype'\].* handle '$filter_id'/ \
		{ print $7 }'`
	tc filter delete dev $ifname parent $PARENT \
		protocol $ethertype pref $PRIO handle $filter_id basic match \
		'cmp(u16' at 12 layer 1 mask 0xffff eq $ethertype')' \
		action skbedit queue_mapping $queue
	tc filter delete dev $ifname parent $PARENT \
		protocol $ethertype pref $PRIO basic
}

add_skbedit_filter()
{
	ifname=$1
	qdisc_id=$2
	queue=$3
	ethertype=$4
	filter_id=$5

	[ ${DEBUG_LOGGING} ] && $LOGGER \
		"tc filter add dev $ifname skbedit queue_mapping $queue"
	tc filter add dev $ifname parent $qdisc_id protocol $ethertype \
		handle $filter_id basic match 'cmp(u16' at 12 \
		layer 1 mask 0xffff eq $ethertype')' \
		action skbedit queue_mapping $queue
}

replace_skbedit_filter()
{
	ifname=$1
	queue=$2
	ethertype=$3
	filter_id=$4

	[ ${DEBUG_LOGGING} ] && $LOGGER \
		"tc filter replace dev $ifname skbedit queue_mapping $queue"
	PARENT=`tc filter show dev $ifname | awk \
		'/^filter.*parent.*protocol \['$ethertype'\].* handle '$filter_id'/ \
		{ print $3 }'`
	PRIO=`tc filter show dev $ifname | \
		awk '/^filter.*parent.*protocol \['$ethertype'\].* handle '$filter_id'/ \
		{ print $7 }'`
	tc filter replace dev $ifname parent $PARENT protocol \
		$ethertype pref $PRIO handle $filter_id basic match \
		'cmp(u16' at 12 layer 1 mask 0xffff eq $ethertype')' \
		action skbedit queue_mapping $queue
}

remove_fcoe_interface()
{
	ifname=$1

	STATUS=`$FCOEADM -i $ifname 2>&1 | \
		awk '/Symbolic Name:/ && /'$ifname'$/{print $6}'`
	if [ "$STATUS" == "$ifname" ]; then
		[ ${DEBUG_LOGGING} ] && $LOGGER "$FCOEADM -d $ifname"
		$FCOEADM -d $ifname
	else
		[ ${DEBUG_LOGGING} ] && $LOGGER \
			"FCoE interface $ifname doesn't exist"
	fi
}

create_fcoe_interface()
{
	ifname=$1

	STATUS=`$FCOEADM -i $ifname 2>&1 | \
		awk '/Symbolic Name:/ && /'$ifname'$/{print $6}'`
	if [ -z "$STATUS" ]; then
		[ ${DEBUG_LOGGING} ] && $LOGGER "$FCOEADM -c $ifname"
		$FCOEADM -c $ifname
	else
		[ ${DEBUG_LOGGING} ] && $LOGGER \
			"FCoE interface $ifname already created"
	fi
}

config_logging()
{
    if [ $DEBUG_LOGGING ] ; then
	if [ $USE_SYSLOG ] ; then
	    LOGGER="logger -t fcoeplumb"
	else
	    LOGGER="echo"
	fi
    else
	LOGGER=
    fi
}

[ "$#" -lt 2 ] && usage

[ ${DEBUG_LOGGING} ] && $LOGGER "fcoeplumb arguments: ($*)"

while [ "$#" -ge 1 ]
do
	case "$1" in
	    --fcoeif)
		shift
		fcoe_ifname=$1
		shift
		case "$1" in
		    --reset | -r)
			cmd=reset
			;;
		    --create | -c)
			cmd=create
			;;
		    --destroy | -d)
			cmd=destroy
			;;
		    *)
			echo "$cmdname: unknown fcoe parameter '$1'" >&2
			usage
			;;
		esac
		;;
	    --netif)
		shift
		net_ifname=$1
		shift
		case "$1" in
		    --qos-enable)
			[ "$#" -lt 2 ] && usage
			qos_list=$2
			shift
			;;
		    --qos-disable)
			[[ "$2" =~ ^[0-9]+$ ]] && shift
			qos_list="disable"
			;;
		    *)
			echo "$cmdname: unknown qos parameter '$1'" >&2
			usage
			;;
		esac
		;;
	    --debug)
		DEBUG_LOGGING=1
		config_logging
		;;
            --syslog)
		USE_SYSLOG=1
		config_logging
		;;
	    *)
		echo "$cmdname: unknown parameter '$1'" >&2
		usage
		;;
	esac
	shift
done

# This must be the first to do after parsing the command arguments!
# Notice that the filter ID is used in find_skbedit_filter(),
# add_skbedit_filter(), replace_skbedit_filter().
fcoe_filter_id=`get_filter_id $net_ifname $FCOE_FILTER_KEY`
fip_filter_id=`get_filter_id $net_ifname $FIP_FILTER_KEY`

if [ "$cmd" == "destroy" ]; then
	remove_fcoe_interface $fcoe_ifname

elif [ "$cmd" == "create" ]; then
	create_fcoe_interface $fcoe_ifname
fi

if [ "$qos_list" == "disable" ]; then
	# Remove the FCoE filters
	find_skbedit_filter $net_ifname $FCOE_ETHERTYPE $fcoe_filter_id
	found_filter=$?
	[ $found_filter -le 7 ] && delete_skbedit_filter $net_ifname \
		$found_filter $FCOE_ETHERTYPE $fcoe_filter_id

	# Remove the FIP filters
	find_skbedit_filter $net_ifname $FIP_ETHERTYPE $fip_filter_id
	found_filter=$?
	[ $found_filter -le 7 ] && delete_skbedit_filter $net_ifname \
		$found_filter $FIP_ETHERTYPE $fip_filter_id

elif [ -n $qos_list ]; then
	#
	# Choose the best QOS to use for FCoE out of the listed choices.
	#

	# Parse QOS List
	QOS_BEST=
	if [ -n "$qos_list" ]; then
		OLD_IFS="$IFS"
		IFS=,"$IFS"
		set -- $qos_list
		IFS="$OLD_IFS"

		while [ "$#" -ge 1 ]
		do
			case "$1" in
			[0-7])
				;;
			*)
				echo "$cmdname: bad QOS value '$1'" >&2
				usage
				;;
			esac
			if [ -z "$QOS_BEST" ]; then
				QOS_BEST=$1
			elif [ "$1" -eq "$QOS_DEF" ]; then
				QOS_BEST=$1
			fi
			shift
		done
	fi

	# If the best QOS is not found, do nothing.
	[ -z "$QOS_BEST" ] && exit 0

	[ ${DEBUG_LOGGING} ] && $LOGGER "$net_ifname - Choosing QOS '$QOS_BEST'"

	#
	# Setup the traffic classifier for FCoE
	# First see if it is already set up.
	#
	qos_queue=`expr $QOS_BEST`

	find_multiq_qdisc $net_ifname
	found_qdisc=$?

	if [ $found_qdisc -eq 1 ]; then
	        # Adjust the FCoE filter
		[ ${DEBUG_LOGGING} ] && $LOGGER "$net_ifname: Qdisc is found"
		find_skbedit_filter $net_ifname $FCOE_ETHERTYPE $fcoe_filter_id
		found_filter=$?
		if [ $found_filter -gt 7 ]; then
			add_skbedit_filter $net_ifname $qdisc_id $qos_queue \
			    $FCOE_ETHERTYPE $fcoe_filter_id
		elif [ $found_filter -ne $qos_queue ]; then
			[ ${DEBUG_LOGGING} ] && $LOGGER \
			    "$net_ifname: Filter is found and QOS is different"
			replace_skbedit_filter $net_ifname $qos_queue \
				$FCOE_ETHERTYPE $fcoe_filter_id
		else
			[ ${DEBUG_LOGGING} ] && $LOGGER \
				"$net_ifname: Filter is found and is identical"
		fi

		# Adjust the FIP filter
		[ ${DEBUG_LOGGING} ] && $LOGGER "$net_ifname: Qdisc is found"
		find_skbedit_filter $net_ifname $FIP_ETHERTYPE $fip_filter_id
		found_filter=$?
		if [ $found_filter -gt 7 ]; then
			add_skbedit_filter $net_ifname $qdisc_id $qos_queue \
			    $FIP_ETHERTYPE $fip_filter_id
		elif [ $found_filter -ne $qos_queue ]; then
			[ ${DEBUG_LOGGING} ] && $LOGGER \
			    "$net_ifname: Filter is found and QOS is different"
			replace_skbedit_filter $net_ifname $qos_queue \
				$FIP_ETHERTYPE $fip_filter_id
		else
			[ ${DEBUG_LOGGING} ] && $LOGGER \
				"$net_ifname: Filter is found and is identical"
		fi
	else
		add_multiq_qdisc $net_ifname $qdisc_id
		add_skbedit_filter $net_ifname $qdisc_id $qos_queue \
			$FCOE_ETHERTYPE $fcoe_filter_id
		add_skbedit_filter $net_ifname $qdisc_id $qos_queue \
			$FIP_ETHERTYPE $fip_filter_id
	fi
fi

exit 0