diff options
author | Chen Qi <Qi.Chen@windriver.com> | 2014-09-29 14:24:17 +0800 |
---|---|---|
committer | Joe MacDonald <joe_macdonald@mentor.com> | 2014-10-21 14:02:14 -0400 |
commit | fd7b22c3f503e677c801d19a7dd1074d6cb66730 (patch) | |
tree | 75f349e05d954477a59df5c291d02c066227bf3c /meta-networking/recipes-filter | |
parent | 71d2fe7c9e2681fede255d7f5b430d63a122ab18 (diff) | |
download | meta-openembedded-fd7b22c3f503e677c801d19a7dd1074d6cb66730.tar.gz |
ebtables: fix for sysvinit and systemd
The solution mainly references Fedora20.
Extract the common part of the code and install it into ${sbindir}.
Add systemd service file.
Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
Signed-off-by: Joe MacDonald <joe_macdonald@mentor.com>
Diffstat (limited to 'meta-networking/recipes-filter')
4 files changed, 192 insertions, 166 deletions
diff --git a/meta-networking/recipes-filter/ebtables/ebtables-2.0.10-4/ebtables.common b/meta-networking/recipes-filter/ebtables/ebtables-2.0.10-4/ebtables.common new file mode 100644 index 000000000..640025dba --- /dev/null +++ b/meta-networking/recipes-filter/ebtables/ebtables-2.0.10-4/ebtables.common | |||
@@ -0,0 +1,163 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | [ -x /sbin/ebtables ] || exit 1 | ||
4 | |||
5 | EBTABLES_DUMPFILE_STEM=/etc/ebtables/dump | ||
6 | |||
7 | RETVAL=0 | ||
8 | prog="ebtables" | ||
9 | desc="Ethernet bridge filtering" | ||
10 | umask 0077 | ||
11 | |||
12 | #default configuration | ||
13 | EBTABLES_MODULES_UNLOAD="yes" | ||
14 | EBTABLES_LOAD_ON_START="no" | ||
15 | EBTABLES_SAVE_ON_STOP="no" | ||
16 | EBTABLES_SAVE_ON_RESTART="no" | ||
17 | EBTABLES_SAVE_COUNTER="no" | ||
18 | EBTABLES_BACKUP_SUFFIX="~" | ||
19 | |||
20 | config=/etc/default/$prog | ||
21 | [ -f "$config" ] && . "$config" | ||
22 | |||
23 | function get_supported_tables() { | ||
24 | EBTABLES_SUPPORTED_TABLES= | ||
25 | /sbin/ebtables -t filter -L 2>&1 1>/dev/null | grep -q permission | ||
26 | if [ $? -eq 0 ]; then | ||
27 | echo "Error: insufficient privileges to access the ebtables rulesets." | ||
28 | exit 1 | ||
29 | fi | ||
30 | for table in filter nat broute; do | ||
31 | /sbin/ebtables -t $table -L &> /dev/null | ||
32 | if [ $? -eq 0 ]; then | ||
33 | EBTABLES_SUPPORTED_TABLES="${EBTABLES_SUPPORTED_TABLES} $table" | ||
34 | fi | ||
35 | done | ||
36 | } | ||
37 | |||
38 | function load() { | ||
39 | RETVAL=0 | ||
40 | get_supported_tables | ||
41 | echo -n "Restoring ebtables rulesets: " | ||
42 | for table in $EBTABLES_SUPPORTED_TABLES; do | ||
43 | echo -n "$table " | ||
44 | if [ -s ${EBTABLES_DUMPFILE_STEM}.$table ]; then | ||
45 | /sbin/ebtables -t $table --atomic-file ${EBTABLES_DUMPFILE_STEM}.$table --atomic-commit | ||
46 | RET=$? | ||
47 | if [ $RET -ne 0 ]; then | ||
48 | echo -n "(failed) " | ||
49 | RETVAL=$RET | ||
50 | fi | ||
51 | else | ||
52 | echo -n "(no saved state) " | ||
53 | fi | ||
54 | done | ||
55 | if [ -z "$EBTABLES_SUPPORTED_TABLES" ]; then | ||
56 | echo -n "no kernel support. " | ||
57 | else | ||
58 | echo -n "done. " | ||
59 | fi | ||
60 | if [ $RETVAL -eq 0 ]; then | ||
61 | echo "ok" | ||
62 | else | ||
63 | echo "fail" | ||
64 | fi | ||
65 | } | ||
66 | |||
67 | function clear() { | ||
68 | RETVAL=0 | ||
69 | get_supported_tables | ||
70 | echo -n "Clearing ebtables rulesets: " | ||
71 | for table in $EBTABLES_SUPPORTED_TABLES; do | ||
72 | echo -n "$table " | ||
73 | /sbin/ebtables -t $table --init-table | ||
74 | done | ||
75 | |||
76 | if [ "$EBTABLES_MODULES_UNLOAD" = "yes" ]; then | ||
77 | for mod in $(grep -E '^(ebt|ebtable)_' /proc/modules | cut -d' ' -f1) ebtables; do | ||
78 | rmmod $mod 2> /dev/null | ||
79 | done | ||
80 | fi | ||
81 | if [ -z "$EBTABLES_SUPPORTED_TABLES" ]; then | ||
82 | echo -n "no kernel support. " | ||
83 | else | ||
84 | echo -n "done. " | ||
85 | fi | ||
86 | if [ $RETVAL -eq 0 ]; then | ||
87 | echo "ok" | ||
88 | else | ||
89 | echo "fail" | ||
90 | fi | ||
91 | } | ||
92 | |||
93 | function save() { | ||
94 | RETVAL=0 | ||
95 | get_supported_tables | ||
96 | echo -n "Saving ebtables rulesets: " | ||
97 | for table in $EBTABLES_SUPPORTED_TABLES; do | ||
98 | echo -n "$table " | ||
99 | [ -n "$EBTABLES_BACKUP_SUFFIX" ] && [ -s ${EBTABLES_DUMPFILE_STEM}.$table ] && \ | ||
100 | mv ${EBTABLES_DUMPFILE_STEM}.$table ${EBTABLES_DUMPFILE_STEM}.$table$EBTABLES_BACKUP_SUFFIX | ||
101 | /sbin/ebtables -t $table --atomic-file ${EBTABLES_DUMPFILE_STEM}.$table --atomic-save | ||
102 | RET=$? | ||
103 | if [ $RET -ne 0 ]; then | ||
104 | echo -n "(failed) " | ||
105 | RETVAL=$RET | ||
106 | else | ||
107 | if [ "$EBTABLES_SAVE_COUNTER" = "no" ]; then | ||
108 | /sbin/ebtables -t $table --atomic-file ${EBTABLES_DUMPFILE_STEM}.$table -Z | ||
109 | fi | ||
110 | fi | ||
111 | done | ||
112 | if [ -z "$EBTABLES_SUPPORTED_TABLES" ]; then | ||
113 | echo -n "no kernel support. " | ||
114 | else | ||
115 | echo -n "done. " | ||
116 | fi | ||
117 | if [ $RETVAL -eq 0 ]; then | ||
118 | echo "ok" | ||
119 | else | ||
120 | echo "fail" | ||
121 | fi | ||
122 | } | ||
123 | |||
124 | case "$1" in | ||
125 | start) | ||
126 | [ "$EBTABLES_LOAD_ON_START" = "yes" ] && load | ||
127 | ;; | ||
128 | stop) | ||
129 | [ "$EBTABLES_SAVE_ON_STOP" = "yes" ] && save | ||
130 | clear | ||
131 | ;; | ||
132 | restart|reload|force-reload) | ||
133 | [ "$EBTABLES_SAVE_ON_RESTART" = "yes" ] && save | ||
134 | clear | ||
135 | [ "$EBTABLES_LOAD_ON_START" = "yes" ] && load | ||
136 | ;; | ||
137 | load) | ||
138 | load | ||
139 | ;; | ||
140 | save) | ||
141 | save | ||
142 | ;; | ||
143 | status) | ||
144 | get_supported_tables | ||
145 | if [ -z "$EBTABLES_SUPPORTED_TABLES" ]; then | ||
146 | echo "No kernel support for ebtables." | ||
147 | RETVAL=1 | ||
148 | else | ||
149 | echo -n "Ebtables support available, number of installed rules: " | ||
150 | for table in $EBTABLES_SUPPORTED_TABLES; do | ||
151 | COUNT=$(( $(/sbin/ebtables -t $table -L | sed -e "/^Bridge chain/! d" -e "s/^.*entries: //" -e "s/,.*$/ +/") 0 )) | ||
152 | echo -n "$table($COUNT) " | ||
153 | done | ||
154 | echo ok | ||
155 | RETVAL=0 | ||
156 | fi | ||
157 | ;; | ||
158 | *) | ||
159 | echo "Usage: $0 {start|stop|restart|reload|force-reload|load|save|status}" >&2 | ||
160 | RETVAL=1 | ||
161 | esac | ||
162 | |||
163 | exit $RETVAL | ||
diff --git a/meta-networking/recipes-filter/ebtables/ebtables-2.0.10-4/ebtables.init b/meta-networking/recipes-filter/ebtables/ebtables-2.0.10-4/ebtables.init index 0044e9825..c9a77a29e 100755 --- a/meta-networking/recipes-filter/ebtables/ebtables-2.0.10-4/ebtables.init +++ b/meta-networking/recipes-filter/ebtables/ebtables-2.0.10-4/ebtables.init | |||
@@ -23,164 +23,4 @@ | |||
23 | # Description: Saves and restores the state of the ebtables rulesets. | 23 | # Description: Saves and restores the state of the ebtables rulesets. |
24 | ### END INIT INFO | 24 | ### END INIT INFO |
25 | 25 | ||
26 | [ -x /sbin/ebtables ] || exit 1 | 26 | /usr/sbin/ebtables.common $1 |
27 | |||
28 | EBTABLES_DUMPFILE_STEM=/etc/ebtables/dump | ||
29 | |||
30 | RETVAL=0 | ||
31 | prog="ebtables" | ||
32 | desc="Ethernet bridge filtering" | ||
33 | umask 0077 | ||
34 | |||
35 | #default configuration | ||
36 | EBTABLES_MODULES_UNLOAD="yes" | ||
37 | EBTABLES_LOAD_ON_START="no" | ||
38 | EBTABLES_SAVE_ON_STOP="no" | ||
39 | EBTABLES_SAVE_ON_RESTART="no" | ||
40 | EBTABLES_SAVE_COUNTER="no" | ||
41 | EBTABLES_BACKUP_SUFFIX="~" | ||
42 | |||
43 | config=/etc/default/$prog | ||
44 | [ -f "$config" ] && . "$config" | ||
45 | |||
46 | function get_supported_tables() { | ||
47 | EBTABLES_SUPPORTED_TABLES= | ||
48 | /sbin/ebtables -t filter -L 2>&1 1>/dev/null | grep -q permission | ||
49 | if [ $? -eq 0 ]; then | ||
50 | echo "Error: insufficient privileges to access the ebtables rulesets." | ||
51 | exit 1 | ||
52 | fi | ||
53 | for table in filter nat broute; do | ||
54 | /sbin/ebtables -t $table -L &> /dev/null | ||
55 | if [ $? -eq 0 ]; then | ||
56 | EBTABLES_SUPPORTED_TABLES="${EBTABLES_SUPPORTED_TABLES} $table" | ||
57 | fi | ||
58 | done | ||
59 | } | ||
60 | |||
61 | function load() { | ||
62 | RETVAL=0 | ||
63 | get_supported_tables | ||
64 | echo -n "Restoring ebtables rulesets: " | ||
65 | for table in $EBTABLES_SUPPORTED_TABLES; do | ||
66 | echo -n "$table " | ||
67 | if [ -s ${EBTABLES_DUMPFILE_STEM}.$table ]; then | ||
68 | /sbin/ebtables -t $table --atomic-file ${EBTABLES_DUMPFILE_STEM}.$table --atomic-commit | ||
69 | RET=$? | ||
70 | if [ $RET -ne 0 ]; then | ||
71 | echo -n "(failed) " | ||
72 | RETVAL=$RET | ||
73 | fi | ||
74 | else | ||
75 | echo -n "(no saved state) " | ||
76 | fi | ||
77 | done | ||
78 | if [ -z "$EBTABLES_SUPPORTED_TABLES" ]; then | ||
79 | echo -n "no kernel support. " | ||
80 | else | ||
81 | echo -n "done. " | ||
82 | fi | ||
83 | if [ $RETVAL -eq 0 ]; then | ||
84 | echo "ok" | ||
85 | else | ||
86 | echo "fail" | ||
87 | fi | ||
88 | } | ||
89 | |||
90 | function clear() { | ||
91 | RETVAL=0 | ||
92 | get_supported_tables | ||
93 | echo -n "Clearing ebtables rulesets: " | ||
94 | for table in $EBTABLES_SUPPORTED_TABLES; do | ||
95 | echo -n "$table " | ||
96 | /sbin/ebtables -t $table --init-table | ||
97 | done | ||
98 | |||
99 | if [ "$EBTABLES_MODULES_UNLOAD" = "yes" ]; then | ||
100 | for mod in $(grep -E '^(ebt|ebtable)_' /proc/modules | cut -d' ' -f1) ebtables; do | ||
101 | rmmod $mod 2> /dev/null | ||
102 | done | ||
103 | fi | ||
104 | if [ -z "$EBTABLES_SUPPORTED_TABLES" ]; then | ||
105 | echo -n "no kernel support. " | ||
106 | else | ||
107 | echo -n "done. " | ||
108 | fi | ||
109 | if [ $RETVAL -eq 0 ]; then | ||
110 | echo "ok" | ||
111 | else | ||
112 | echo "fail" | ||
113 | fi | ||
114 | } | ||
115 | |||
116 | function save() { | ||
117 | RETVAL=0 | ||
118 | get_supported_tables | ||
119 | echo -n "Saving ebtables rulesets: " | ||
120 | for table in $EBTABLES_SUPPORTED_TABLES; do | ||
121 | echo -n "$table " | ||
122 | [ -n "$EBTABLES_BACKUP_SUFFIX" ] && [ -s ${EBTABLES_DUMPFILE_STEM}.$table ] && \ | ||
123 | mv ${EBTABLES_DUMPFILE_STEM}.$table ${EBTABLES_DUMPFILE_STEM}.$table$EBTABLES_BACKUP_SUFFIX | ||
124 | /sbin/ebtables -t $table --atomic-file ${EBTABLES_DUMPFILE_STEM}.$table --atomic-save | ||
125 | RET=$? | ||
126 | if [ $RET -ne 0 ]; then | ||
127 | echo -n "(failed) " | ||
128 | RETVAL=$RET | ||
129 | else | ||
130 | if [ "$EBTABLES_SAVE_COUNTER" = "no" ]; then | ||
131 | /sbin/ebtables -t $table --atomic-file ${EBTABLES_DUMPFILE_STEM}.$table -Z | ||
132 | fi | ||
133 | fi | ||
134 | done | ||
135 | if [ -z "$EBTABLES_SUPPORTED_TABLES" ]; then | ||
136 | echo -n "no kernel support. " | ||
137 | else | ||
138 | echo -n "done. " | ||
139 | fi | ||
140 | if [ $RETVAL -eq 0 ]; then | ||
141 | echo "ok" | ||
142 | else | ||
143 | echo "fail" | ||
144 | fi | ||
145 | } | ||
146 | |||
147 | case "$1" in | ||
148 | start) | ||
149 | [ "$EBTABLES_LOAD_ON_START" = "yes" ] && load | ||
150 | ;; | ||
151 | stop) | ||
152 | [ "$EBTABLES_SAVE_ON_STOP" = "yes" ] && save | ||
153 | clear | ||
154 | ;; | ||
155 | restart|reload|force-reload) | ||
156 | [ "$EBTABLES_SAVE_ON_RESTART" = "yes" ] && save | ||
157 | clear | ||
158 | [ "$EBTABLES_LOAD_ON_START" = "yes" ] && load | ||
159 | ;; | ||
160 | load) | ||
161 | load | ||
162 | ;; | ||
163 | save) | ||
164 | save | ||
165 | ;; | ||
166 | status) | ||
167 | get_supported_tables | ||
168 | if [ -z "$EBTABLES_SUPPORTED_TABLES" ]; then | ||
169 | echo "No kernel support for ebtables." | ||
170 | RETVAL=1 | ||
171 | else | ||
172 | echo -n "Ebtables support available, number of installed rules: " | ||
173 | for table in $EBTABLES_SUPPORTED_TABLES; do | ||
174 | COUNT=$(( $(/sbin/ebtables -t $table -L | sed -e "/^Bridge chain/! d" -e "s/^.*entries: //" -e "s/,.*$/ +/") 0 )) | ||
175 | echo -n "$table($COUNT) " | ||
176 | done | ||
177 | echo ok | ||
178 | RETVAL=0 | ||
179 | fi | ||
180 | ;; | ||
181 | *) | ||
182 | echo "Usage: $0 {start|stop|restart|reload|force-reload|load|save|status}" >&2 | ||
183 | RETVAL=1 | ||
184 | esac | ||
185 | |||
186 | exit $RETVAL | ||
diff --git a/meta-networking/recipes-filter/ebtables/ebtables-2.0.10-4/ebtables.service b/meta-networking/recipes-filter/ebtables/ebtables-2.0.10-4/ebtables.service new file mode 100644 index 000000000..3abd1fe3e --- /dev/null +++ b/meta-networking/recipes-filter/ebtables/ebtables-2.0.10-4/ebtables.service | |||
@@ -0,0 +1,11 @@ | |||
1 | [Unit] | ||
2 | Description=Ethernet Bridge Filtering Tables | ||
3 | |||
4 | [Service] | ||
5 | Type=oneshot | ||
6 | RemainAfterExit=yes | ||
7 | ExecStart=@SBINDIR@/ebtables.common start | ||
8 | ExecStop=@SBINDIR@/ebtables.common stop | ||
9 | |||
10 | [Install] | ||
11 | WantedBy=multi-user.target | ||
diff --git a/meta-networking/recipes-filter/ebtables/ebtables_2.0.10-4.bb b/meta-networking/recipes-filter/ebtables/ebtables_2.0.10-4.bb index 9222b2d44..32cfc752b 100644 --- a/meta-networking/recipes-filter/ebtables/ebtables_2.0.10-4.bb +++ b/meta-networking/recipes-filter/ebtables/ebtables_2.0.10-4.bb | |||
@@ -15,6 +15,8 @@ SRC_URI = "${SOURCEFORGE_MIRROR}/ebtables/ebtables-v${PV}.tar.gz \ | |||
15 | file://installnonroot.patch \ | 15 | file://installnonroot.patch \ |
16 | file://01debian_defaultconfig.patch \ | 16 | file://01debian_defaultconfig.patch \ |
17 | file://ebtables.init \ | 17 | file://ebtables.init \ |
18 | file://ebtables.common \ | ||
19 | file://ebtables.service \ | ||
18 | file://no-as-needed.patch \ | 20 | file://no-as-needed.patch \ |
19 | " | 21 | " |
20 | 22 | ||
@@ -23,7 +25,7 @@ SRC_URI[sha256sum] = "dc6f7b484f207dc712bfca81645f45120cb6aee3380e77a1771e9c34a9 | |||
23 | 25 | ||
24 | S = "${WORKDIR}/ebtables-v${PV}" | 26 | S = "${WORKDIR}/ebtables-v${PV}" |
25 | 27 | ||
26 | inherit update-rc.d | 28 | inherit update-rc.d systemd |
27 | 29 | ||
28 | EXTRA_OEMAKE = " \ | 30 | EXTRA_OEMAKE = " \ |
29 | BINDIR=${base_sbindir} \ | 31 | BINDIR=${base_sbindir} \ |
@@ -39,21 +41,29 @@ EXTRA_OEMAKE = " \ | |||
39 | " | 41 | " |
40 | 42 | ||
41 | do_install () { | 43 | do_install () { |
44 | install -d ${D}${sbindir} | ||
45 | install -m 0755 ${WORKDIR}/ebtables.common ${D}${sbindir}/ebtables.common | ||
46 | # Fix hardcoded paths in scripts | ||
47 | sed -i 's!/sbin/!${base_sbindir}/!g' ${D}${sbindir}/ebtables.common | ||
48 | sed -i 's!/etc/!${sysconfdir}/!g' ${D}${sbindir}/ebtables.common | ||
49 | |||
42 | install -d ${D}${sysconfdir}/init.d | 50 | install -d ${D}${sysconfdir}/init.d |
43 | install -d ${D}${sysconfdir}/default | 51 | install -d ${D}${sysconfdir}/default |
44 | install -d ${D}${sysconfdir}/ebtables | 52 | install -d ${D}${sysconfdir}/ebtables |
45 | oe_runmake DESTDIR='${D}' install | 53 | oe_runmake DESTDIR='${D}' install |
46 | install -m 0755 ${WORKDIR}/ebtables.init ${D}/${sysconfdir}/init.d/ebtables | 54 | install -m 0755 ${WORKDIR}/ebtables.init ${D}/${sysconfdir}/init.d/ebtables |
47 | mv ${D}${sysconfdir}/default/ebtables-config ${D}${sysconfdir}/default/ebtables | 55 | mv ${D}${sysconfdir}/default/ebtables-config ${D}${sysconfdir}/default/ebtables |
48 | 56 | sed -i 's!/usr/sbin/!${sbindir}/!g' ${D}${sysconfdir}/init.d/ebtables | |
49 | # Fix hardcoded paths in scripts | ||
50 | sed -i 's!/sbin/!${base_sbindir}/!g' ${D}/${sysconfdir}/init.d/ebtables | ||
51 | sed -i 's!/etc/!${sysconfdir}/!g' ${D}/${sysconfdir}/init.d/ebtables | ||
52 | 57 | ||
53 | # The script ebtables-save refernces perl in exec_prefix, so | 58 | # The script ebtables-save refernces perl in exec_prefix, so |
54 | # move it to sbindir to avoid QA issue | 59 | # move it to sbindir to avoid QA issue |
55 | install -d ${D}/${sbindir} | 60 | install -d ${D}/${sbindir} |
56 | mv ${D}/${base_sbindir}/ebtables-save ${D}/${sbindir} | 61 | mv ${D}/${base_sbindir}/ebtables-save ${D}/${sbindir} |
62 | |||
63 | # Install systemd service files | ||
64 | install -d ${D}${systemd_unitdir}/system | ||
65 | install -m 0644 ${WORKDIR}/ebtables.service ${D}${systemd_unitdir}/system | ||
66 | sed -i -e 's#@SBINDIR@#${sbindir}#g' ${D}${systemd_unitdir}/system/ebtables.service | ||
57 | } | 67 | } |
58 | 68 | ||
59 | CONFFILES_${PN} += "${sysconfdir}/default/ebtables" | 69 | CONFFILES_${PN} += "${sysconfdir}/default/ebtables" |
@@ -61,5 +71,7 @@ CONFFILES_${PN} += "${sysconfdir}/default/ebtables" | |||
61 | INITSCRIPT_NAME = "ebtables" | 71 | INITSCRIPT_NAME = "ebtables" |
62 | INITSCRIPT_PARAMS = "start 41 S . stop 41 6 ." | 72 | INITSCRIPT_PARAMS = "start 41 S . stop 41 6 ." |
63 | 73 | ||
74 | SYSTEMD_SERVICE_${PN} = "ebtables.service" | ||
75 | |||
64 | FILES_${PN}-dbg += "${base_libdir}/ebtables/.debug" | 76 | FILES_${PN}-dbg += "${base_libdir}/ebtables/.debug" |
65 | FILES_${PN} += "${base_libdir}/ebtables/*.so" | 77 | FILES_${PN} += "${base_libdir}/ebtables/*.so" |