Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # init script for the Ethernet Bridge filter tables |
| 4 | # |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 5 | # Written by Dag Wieers <dag@wieers.com> |
| 6 | # Modified by Rok Papez <rok.papez@arnes.si> |
| 7 | # Bart De Schuymer <bdschuym@pandora.be> |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 8 | # |
| 9 | # chkconfig: - 15 85 |
| 10 | # description: Ethernet Bridge filtering tables |
| 11 | # |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 12 | # config: __SYSCONFIG__/ebtables (text) |
| 13 | # __SYSCONFIG__/ebtables.<table> (binary) |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 14 | |
| 15 | source /etc/init.d/functions |
| 16 | source /etc/sysconfig/network |
| 17 | |
| 18 | # Check that networking is up. |
| 19 | [ ${NETWORKING} = "no" ] && exit 0 |
| 20 | |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 21 | [ -x __EXEC_PATH__/ebtables ] || exit 1 |
| 22 | [ -x __EXEC_PATH__/ebtables-save ] || exit 1 |
| 23 | [ -x __EXEC_PATH__/ebtables-restore ] || exit 1 |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 24 | |
| 25 | RETVAL=0 |
| 26 | prog="ebtables" |
| 27 | desc="Ethernet bridge filtering" |
Bart De Schuymer | 9d1e3ff | 2005-11-12 22:22:39 +0000 | [diff] [blame] | 28 | umask 0077 |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 29 | |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 30 | #default configuration |
| 31 | EBTABLES_TEXT_FORMAT="yes" |
| 32 | EBTABLES_BINARY_FORMAT="yes" |
| 33 | EBTABLES_MODULES_UNLOAD="yes" |
| 34 | EBTABLES_SAVE_ON_STOP="no" |
| 35 | EBTABLES_SAVE_ON_RESTART="no" |
| 36 | EBTABLES_SAVE_COUNTER="no" |
| 37 | |
| 38 | config=__SYSCONFIG__/$prog-config |
| 39 | [ -f "$config" ] && . "$config" |
| 40 | |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 41 | start() { |
| 42 | echo -n $"Starting $desc ($prog): " |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 43 | if [ "$EBTABLES_BINARY_FORMAT" = "yes" ]; then |
Bart De Schuymer | f8a68cb | 2008-02-03 19:55:26 +0000 | [diff] [blame] | 44 | for table in $(ls __SYSCONFIG__/ebtables.* 2>/dev/null | sed -e 's/.*ebtables\.//' -e '/save/d' ); do |
Bart De Schuymer | 17b3f09 | 2005-10-25 18:08:09 +0000 | [diff] [blame] | 45 | __EXEC_PATH__/ebtables -t $table --atomic-file __SYSCONFIG__/ebtables.$table --atomic-commit || RETVAL=1 |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 46 | done |
| 47 | else |
| 48 | __EXEC_PATH__/ebtables-restore < /etc/sysconfig/ebtables || RETVAL=1 |
| 49 | fi |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 50 | |
| 51 | if [ $RETVAL -eq 0 ]; then |
| 52 | success "$prog startup" |
| 53 | rm -f /var/lock/subsys/$prog |
| 54 | else |
| 55 | failure "$prog startup" |
| 56 | fi |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 57 | echo |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | stop() { |
| 61 | echo -n $"Stopping $desc ($prog): " |
Bart De Schuymer | f8a68cb | 2008-02-03 19:55:26 +0000 | [diff] [blame] | 62 | for table in $(grep '^ebtable_' /proc/modules | sed -e 's/ebtable_\([^ ]*\).*/\1/'); do |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 63 | __EXEC_PATH__/ebtables -t $table --init-table || RETVAL=1 |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 64 | done |
| 65 | |
Bart De Schuymer | 17b3f09 | 2005-10-25 18:08:09 +0000 | [diff] [blame] | 66 | if [ "$EBTABLES_MODULES_UNLOAD" = "yes" ]; then |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 67 | for mod in $(grep -E '^(ebt|ebtable)_' /proc/modules | cut -f1 -d' ') ebtables; do |
Bart De Schuymer | f8a95ce | 2005-10-25 18:36:11 +0000 | [diff] [blame] | 68 | rmmod $mod 2> /dev/null |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 69 | done |
| 70 | fi |
| 71 | |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 72 | if [ $RETVAL -eq 0 ]; then |
| 73 | success "$prog shutdown" |
Bart De Schuymer | 28fa090 | 2005-10-25 17:53:18 +0000 | [diff] [blame] | 74 | rm -f /var/lock/subsys/$prog |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 75 | else |
| 76 | failure "$prog shutdown" |
| 77 | fi |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 78 | echo |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | restart() { |
| 82 | stop |
| 83 | start |
| 84 | } |
| 85 | |
| 86 | save() { |
| 87 | echo -n $"Saving $desc ($prog): " |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 88 | if [ "$EBTABLES_TEXT_FORMAT" = "yes" ]; then |
Bart De Schuymer | 9d1e3ff | 2005-11-12 22:22:39 +0000 | [diff] [blame] | 89 | if [ -e __SYSCONFIG__/ebtables ]; then |
| 90 | chmod 0600 __SYSCONFIG__/ebtables |
| 91 | mv -f __SYSCONFIG__/ebtables __SYSCONFIG__/ebtables.save |
| 92 | fi |
| 93 | __EXEC_PATH__/ebtables-save > __SYSCONFIG__/ebtables || RETVAL=1 |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 94 | fi |
| 95 | if [ "$EBTABLES_BINARY_FORMAT" = "yes" ]; then |
Bart De Schuymer | 9d1e3ff | 2005-11-12 22:22:39 +0000 | [diff] [blame] | 96 | rm -f __SYSCONFIG__/ebtables.*.save |
Bart De Schuymer | f8a68cb | 2008-02-03 19:55:26 +0000 | [diff] [blame] | 97 | for oldtable in $(ls __SYSCONFIG__/ebtables.* 2>/dev/null | grep -vF 'ebtables.save'); do |
| 98 | chmod 0600 $oldtable |
| 99 | mv -f $oldtable $oldtable.save |
Bart De Schuymer | 9d1e3ff | 2005-11-12 22:22:39 +0000 | [diff] [blame] | 100 | done |
Bart De Schuymer | f8a68cb | 2008-02-03 19:55:26 +0000 | [diff] [blame] | 101 | for table in $(grep '^ebtable_' /proc/modules | sed -e 's/ebtable_\([^ ]*\).*/\1/'); do |
Bart De Schuymer | 17b3f09 | 2005-10-25 18:08:09 +0000 | [diff] [blame] | 102 | __EXEC_PATH__/ebtables -t $table --atomic-file __SYSCONFIG__/ebtables.$table --atomic-save || RETVAL=1 |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 103 | if [ "$EBTABLES_SAVE_COUNTER" = "no" ]; then |
Bart De Schuymer | 17b3f09 | 2005-10-25 18:08:09 +0000 | [diff] [blame] | 104 | __EXEC_PATH__/ebtables -t $table --atomic-file __SYSCONFIG__/ebtables.$table -Z || RETVAL=1 |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 105 | fi |
| 106 | done |
| 107 | fi |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 108 | |
| 109 | if [ $RETVAL -eq 0 ]; then |
| 110 | success "$prog saved" |
| 111 | else |
| 112 | failure "$prog saved" |
| 113 | fi |
| 114 | echo |
| 115 | } |
| 116 | |
| 117 | case "$1" in |
| 118 | start) |
| 119 | start |
| 120 | ;; |
| 121 | stop) |
Bart De Schuymer | f8a68cb | 2008-02-03 19:55:26 +0000 | [diff] [blame] | 122 | [ "$EBTABLES_SAVE_ON_STOP" = "yes" ] && save |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 123 | stop |
| 124 | ;; |
| 125 | restart|reload) |
Bart De Schuymer | f8a68cb | 2008-02-03 19:55:26 +0000 | [diff] [blame] | 126 | [ "$EBTABLES_SAVE_ON_RESTART" = "yes" ] && save |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 127 | restart |
| 128 | ;; |
| 129 | condrestart) |
| 130 | [ -e /var/lock/subsys/$prog ] && restart |
| 131 | RETVAL=$? |
| 132 | ;; |
| 133 | save) |
| 134 | save |
| 135 | ;; |
| 136 | status) |
Bart De Schuymer | 50441e9 | 2005-08-30 21:20:55 +0000 | [diff] [blame] | 137 | __EXEC_PATH__/ebtables-save |
Bart De Schuymer | e8b0a25 | 2005-06-14 19:20:43 +0000 | [diff] [blame] | 138 | RETVAL=$? |
| 139 | ;; |
| 140 | *) |
| 141 | echo $"Usage $0 {start|stop|restart|condrestart|save|status}" |
| 142 | RETVAL=1 |
| 143 | esac |
| 144 | |
| 145 | exit $RETVAL |