summaryrefslogtreecommitdiff
path: root/community/arptables/arptables.rc
blob: dae90ac2a699b6bde1a9b8934fc339b1c474920b (plain)
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
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

[[ -x /usr/sbin/arptables ]] || exit 1
[[ -x /usr/sbin/arptables-save ]] || exit 1
[[ -x /usr/sbin/arptables-restore ]] || exit 1

do_start() {
  stat_busy "Restore arptables rules"
  if [[ -r /etc/arptables/arptables ]]; then
    /usr/sbin/arptables-restore </etc/arptables/arptables
    (( $? == 0 )) && stat_done && add_daemon arptables && return
  fi
  stat_fail
}

do_stop() {
  stat_busy "Flushing arptables rules"
  /usr/sbin/arptables-restore </dev/null
  if (( $? == 0 )); then
    stat_done
    rm_daemon arptables
  else
    stat_fail
  fi
}

do_save() {
  stat_busy "Saving arptables rules"
  /usr/sbin/arptables-save >/etc/arptables/arptables
  (( $? == 0 )) && stat_done || stat_fail
}

case "$1" in
  start)
    do_start
  ;;
  stop)
    do_stop
  ;;
  restart)
    do_stop
    do_start
  ;;
  save)
    do_save
  ;;
  status)
    /usr/sbin/arptables-save
  ;;
  *)
    echo "Usage $0 {start|stop|restart|save|status}" >&2
    exit 1
esac

# vim:set ts=2 sw=2 ft=sh et: