1#!/bin/bash
2
3EBTABLES="/usr/sbin/ebtables-legacy"
4
5[ -x "$EBTABLES" ] || exit 1
6
7echo "# Generated by ebtables-save v1.0 on $(date)"
8
9cnt=""
10[ "x$EBTABLES_SAVE_COUNTER" = "xyes" ] && cnt="--Lc"
11
12for table_name in $(grep -E '^ebtable_' /proc/modules | cut -f1 -d' ' | sed s/ebtable_//); do
13    table=$($EBTABLES -t $table_name -L $cnt)
14    [ $? -eq 0 ] || { echo "$table"; exit -1; }
15
16    chain=""
17    rules=""
18    while read line; do
19	[ -z "$line" ] && continue
20
21	case "$line" in
22	    Bridge\ table:\ *)
23		echo "*${line:14}"
24		;;
25	    Bridge\ chain:\ *)
26		chain="${line:14}"
27		chain="${chain%%,*}"
28		policy="${line##*policy: }"
29		echo ":$chain $policy"
30		;;
31	    *)
32		if [ "$cnt" = "--Lc" ]; then
33		    line=${line/, pcnt \=/ -c}
34		    line=${line/-- bcnt \=/}
35		fi
36		rules="$rules-A $chain $line\n"
37		;;
38	esac
39    done <<EOF
40$table
41EOF
42    echo -e $rules
43done
44