Merge lp:~hipl-core/hipl/android-hipfw into lp:hipl
- android-hipfw
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 6454 |
Proposed branch: | lp:~hipl-core/hipl/android-hipfw |
Merge into: | lp:hipl |
Diff against target: |
555 lines (+314/-90) 8 files modified
INSTALL (+31/-19) configure.ac (+14/-0) doc/HOWTO.xml.in (+19/-13) patches/android/libnetfilter_queue/tcp.c.patch (+18/-0) patches/android/ndk/ip.h.patch (+21/-0) patches/android/ndk/ip_icmp.h.patch (+33/-0) patches/android/ndk/swab.h.patch (+60/-0) tools/prepare_android_toolchain.sh (+118/-58) |
To merge this branch: | bzr merge lp:~hipl-core/hipl/android-hipfw |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Miika Komu | Approve | ||
René Hummen | Pending | ||
Review via email: mp+235619@code.launchpad.net |
This proposal supersedes a proposal from 2014-08-28.
Commit message
Description of the change
Bring hipfw support to Android.
Fixes Bug #1313729
hipfw would not compile for Android previously mostly due to missing
dependencies. The prepare_
and compiles libmnl, libnfnetlink and libnetfilter_queue in addition
to OpenSSL. A couple of patches were needed to remove definitions that
were already somewhere in Bionic, and to add definitions that were missing.
Android has supported Position Independent Executables (PIE) since 4.1
and enforces them by default since around 4.4.2. Trying to run a
non-PIE executable on a recent version of Android should result in
"error: only position independent executables (PIE) are supported."
The script now gives two ./configure -lines from which the user
should choose depending on their target device.
configure.ac and documentation has been updated for hipfw support.
hipfw/helpers.c uses the function WEXITSTATUS from <sys/wait.h> which
seems to have been included indirectly on Linux, but not on Android.
LSI support has been tested on Android 4.4.4, kernel version 3.4.0
with the features listed in installation instructions, on a Nexus 5,
and seems to work just fine.
Feedback from previous merge proposal was taken into account;
commands to compile for Android are now simpler and make better
use of Autotools.
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal | # |
René Hummen (rene-hummen) wrote : Posted in a previous version of this proposal | # |
I agree with Miika that the patches should be separated from 'tools/
In addition, please see my two diff comments.
Pupu Toivonen (scolphoy) wrote : Posted in a previous version of this proposal | # |
On 31.08.2014, at 21:01, Diego Biurrun <email address hidden> wrote:
> review needs-changes
>
> On Thu, Aug 28, 2014 at 08:14:21PM -0000, Juhani Toivonen wrote:
>> --- INSTALL 2014-03-27 21:25:22 +0000
>> +++ INSTALL 2014-08-28 20:13:36 +0000
>> @@ -115,29 +115,47 @@
>>
>> 5. In the HIPL source tree, run:
>> - ./configure --enable-android --disable-firewall --host=arm-linux \
>> - --prefix=/usr --sysconfdir=/etc \
>> - CC=${ANDROID_
>> - CFLAGS="-std=c99 -mbionic -fPIC -fno-exceptions \
>> - --sysroot=
>> + ./configure --enable-android --host=arm-linux \
>> + --prefix=/usr --sysconfdir=/etc \
>> + CC=${ANDROID_
>> + CFLAGS="-std=c99 -mbionic -fPIC -pie -fno-exceptions \
>> + --sysroot=
>> LDFLAGS=
>> --L${ANDROID_
>> +-L${ANDROID_
>> LIBS="-lc -lm -lgcc -lcrypto"
>
> If you prettyprint this, don't leave out the LDFLAGS line.
The LDFLAGS line is like that by intention.
It’s too long to fit into 80 characters, and it doesn’t work if there’s whitespace inside it. Like that, at least copying and pasting the line into terminal works.
To how I see, my options are:
a) Leave it like that. It’s a small eyesore but it works.
b) Ignore the instruction that lines longer than 80 characters should be divided.
c) Make the line pretty like the others and instruct user to remove whitespace from within LDFLAGS before executing.
d) For consistency, not pretty print the command at all because of that one part.
>
>> --- hipfw/helpers.c 2012-05-12 06:54:33 +0000
>> +++ hipfw/helpers.c 2014-08-28 20:13:36 +0000
>> @@ -35,6 +35,7 @@
>> #include <stdarg.h>
>> #include <arpa/inet.h>
>> #include <netinet/in.h>
>> +#include <sys/wait.h>
>>
>> #include "libcore/debug.h"
>> #include "helpers.h"
>
> I suggest pushing such fixes directly, independent of this patch set.
Ok, will do.
>> --- tools/prepare_
>> +++ tools/prepare_
>> @@ -91,17 +91,206 @@
>>
>> +patch_toolchain()
>> +{
>> +# -------
>> +# ---- Add definition for __fswab64 needed by libnetfilter_queue ---- #
>> +# ---- https:/
>> +
>> +patch -N ${ANDROID_
>> +--- swab.h 2011-02-02 13:43:37.711530000 +0000
>> ++++ platforms/
>> +@@ -64,9 +64,52 @@
>> + #define __swab64(x) __fswab64(x)
>> + #endif
>> +
>> ++
>> ++static __inline__ __attribute_const__ __u16 __fswab16(__u16 x)
>> ++{
>> ++ return __arch__swab16(x);
>...
Diego Biurrun (diego-biurrun) wrote : Posted in a previous version of this proposal | # |
On Sun, Aug 31, 2014 at 09:25:30PM +0300, Juhani Toivonen wrote:
> On 31.08.2014, at 21:01, Diego Biurrun <email address hidden> wrote:
> > On Thu, Aug 28, 2014 at 08:14:21PM -0000, Juhani Toivonen wrote:
> >> --- INSTALL 2014-03-27 21:25:22 +0000
> >> +++ INSTALL 2014-08-28 20:13:36 +0000
> >> @@ -115,29 +115,47 @@
> >>
> >> 5. In the HIPL source tree, run:
> >> - ./configure --enable-android --disable-firewall --host=arm-linux \
> >> - --prefix=/usr --sysconfdir=/etc \
> >> - CC=${ANDROID_
> >> - CFLAGS="-std=c99 -mbionic -fPIC -fno-exceptions \
> >> - --sysroot=
> >> + ./configure --enable-android --host=arm-linux \
> >> + --prefix=/usr --sysconfdir=/etc \
> >> + CC=${ANDROID_
> >> + CFLAGS="-std=c99 -mbionic -fPIC -pie -fno-exceptions \
> >> + --sysroot=
> >> LDFLAGS=
> >> --L${ANDROID_
> >> +-L${ANDROID_
> >> LIBS="-lc -lm -lgcc -lcrypto"
> >
> > If you prettyprint this, don't leave out the LDFLAGS line.
>
> The LDFLAGS line is like that by intention.
>
> It’s too long to fit into 80 characters, and it doesn’t work if there’s whitespace inside it. Like that, at least copying and pasting the line into terminal works.
>
> To how I see, my options are:
> a) Leave it like that. It’s a small eyesore but it works.
> b) Ignore the instruction that lines longer than 80 characters should be divided.
> c) Make the line pretty like the others and instruct user to remove whitespace from within LDFLAGS before executing.
> d) For consistency, not pretty print the command at all because of that one part.
b)
> > I fully agree with René, these inline patches are ugly.
>
> Fine, I’ll find a place to host them and have the script pull them in.
You don't need to. Adding the files to HIPL is not a problem, but why
have them inlined into the script?
Diego
Pupu Toivonen (scolphoy) wrote : Posted in a previous version of this proposal | # |
On 01.09.2014, at 00:10, Diego Biurrun <email address hidden> wrote:
>>> I fully agree with René, these inline patches are ugly.
>>
>> Fine, I’ll find a place to host them and have the script pull them in.
>
> You don't need to. Adding the files to HIPL is not a problem, but why
> have them inlined into the script?
>
> Diego
>
I have now fixed all the other parts except Rene’s suggestion to remove the CC, CFLAGS etc. from the configure command-line.
I haven’t figured out what goes wrong with that yet. I’m guessing the environment variables are not being resolved correctly when left to just the configure.ac
$ ./configure --enable-android --host=arm-linux --prefix=/usr --sysconfdir=/etc
. . .
$ make
make all-am
make[1]: Entering directory `/android/
CC libcore/builder.lo
libcore/builder.c: Assembler messages:
libcore/
libcore/
libcore/
libcore/
libcore/
libcore/
libcore/
libcore/
libcore/
. . .
Pupu Toivonen (scolphoy) wrote : Posted in a previous version of this proposal | # |
On 01.09.2014, at 14:14, Juhani Toivonen <email address hidden> wrote:
> On 01.09.2014, at 00:10, Diego Biurrun <email address hidden> wrote:
>
>>>> I fully agree with René, these inline patches are ugly.
>>>
>>> Fine, I’ll find a place to host them and have the script pull them in.
>>
>> You don't need to. Adding the files to HIPL is not a problem, but why
>> have them inlined into the script?
>>
>> Diego
>>
>
> I have now fixed all the other parts except Rene’s suggestion to remove the CC, CFLAGS etc. from the configure command-line.
> I haven’t figured out what goes wrong with that yet. I’m guessing the environment variables are not being resolved correctly when left to just the configure.ac
>
>
> $ ./configure --enable-android --host=arm-linux --prefix=/usr --sysconfdir=/etc
> . . .
>
> $ make
> make all-am
> make[1]: Entering directory `/android/
> CC libcore/builder.lo
> libcore/builder.c: Assembler messages:
> libcore/
> libcore/
> libcore/
> libcore/
> libcore/
> libcore/
> libcore/
> libcore/
> libcore/
> . . .
Nevermind. It didn’t know which CC to use. Working on fixing it now.
Miika Komu (miika-iki) wrote : | # |
I suggest to merge in this in one week unless somebody disapproves by then.
- 6474. By Pupu Toivonen
-
Correct typos, remove old instructions, fix style a little.
- 6475. By Pupu Toivonen
-
Change path finding back the way it was
- 6476. By Pupu Toivonen
-
Add newlines to ends of patch-files.
- 6477. By Pupu Toivonen
-
Sync with trunk
Preview Diff
1 | === modified file 'INSTALL' |
2 | --- INSTALL 2014-03-27 21:25:22 +0000 |
3 | +++ INSTALL 2014-10-01 13:19:56 +0000 |
4 | @@ -115,29 +115,41 @@ |
5 | 4. Follow the instructions printed at the end of the script. |
6 | |
7 | 5. In the HIPL source tree, run: |
8 | - ./configure --enable-android --disable-firewall --host=arm-linux \ |
9 | - --prefix=/usr --sysconfdir=/etc \ |
10 | - CC=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc \ |
11 | - CFLAGS="-std=c99 -mbionic -fPIC -fno-exceptions \ |
12 | - --sysroot=${ANDROID_SYSROOT}" \ |
13 | - LDFLAGS="-Wl,-rpath-link=${ANDROID_SYSROOT}/usr/lib,\ |
14 | --L${ANDROID_SYSROOT}/usr/lib" \ |
15 | - LIBS="-lc -lm -lgcc -lcrypto" |
16 | + export CC="${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc" |
17 | + ./configure --enable-android --host=arm-linux \ |
18 | + --prefix=/usr --sysconfdir=/etc |
19 | |
20 | -It is important that there are no spaces after commas in LDFLAGS. |
21 | +For Android-versions older than 4.1, add '--disable-android-pie' to |
22 | +the configure line. |
23 | |
24 | You can then compile the source using 'make'. |
25 | |
26 | -Currently to install HIP you need to run the following commands on your device: |
27 | -mount -o remount,rw / |
28 | -mount -o remount,rw /system |
29 | -mkdir -p /var/lock |
30 | -mkdir /etc/hip |
31 | -ln -s /system/lib/libcrypto.so /system/lib/libcrypto.so.1.0.0 |
32 | - |
33 | -Then copy (adb push) the config files hipd.conf and relay.conf /etc/hip and |
34 | -the binaries hipd and hipconf to /system/xbin in your device. You should then be |
35 | -able to run hipd and hipconf normally. |
36 | +Currently to install HIP you need to run the following commands on the computer: |
37 | +adb root |
38 | +adb shell mount -o remount,rw / |
39 | +adb shell mount -o remount,rw /system |
40 | +adb shell mkdir -p /var/lock |
41 | +adb shell mkdir /etc/hip |
42 | +adb shell ln -s /system/lib/libcrypto.so /system/lib/libcrypto.so.1.0.0 |
43 | + |
44 | +Then using 'adb push' on your computer |
45 | +- Copy hipd/hipd.conf, hipd/relay.conf and hipfw/hipfw.conf to /etc/hip/ |
46 | +- Copy hipd/hipd, hipfw/hipfw and tools/hipconf to /system/xbin |
47 | +- Copy all libmnl.* , libnfnetlink.* and libnetfilter_queue.* from |
48 | + the toolchain's sysroot/usr/lib/ to /system/lib/ on the device. |
49 | + This is usually $HOME/android_tools/toolchain/sysroot/usr/lib/ |
50 | + DO NOT copy all the files under that directory, they do not all |
51 | + work on your device. Commands: |
52 | + |
53 | +adb push hipd/hipd /system/xbin |
54 | +adb push hipfw/hipfw /system/xbin |
55 | +adb push tools/hipconf /system/xbin |
56 | +adb push hipd/hipd.conf /etc/hip |
57 | +adb push hipd/relay.conf /etc/hip |
58 | +adb push hipfw/hipfw.conf /etc/hip |
59 | +for file in ${ANDROID_SYSROOT}/usr/lib/lib{netfilter_queue,nfnetlink,mnl}.*; do |
60 | + adb push $file /system/lib; |
61 | +done |
62 | |
63 | You need to run hipd with the -a flag. |
64 | The /var/lock directory does not survive reboot, it needs to be |
65 | |
66 | === modified file 'configure.ac' |
67 | --- configure.ac 2013-11-01 06:40:17 +0000 |
68 | +++ configure.ac 2014-10-01 13:19:56 +0000 |
69 | @@ -139,6 +139,20 @@ |
70 | fi |
71 | AM_CONDITIONAL(HIP_ANDROID, test x"$ac_cv_use_android" = x"yes") |
72 | |
73 | +AC_ARG_ENABLE(android-pie, |
74 | + AS_HELP_STRING([--disable-android-pie], |
75 | + [Don't compile as PIE (Position Independent Executable)]), |
76 | + [ac_cv_use_android_pie=$enableval], |
77 | + [ac_cv_use_android_pie=yes]) |
78 | +AC_CACHE_CHECK([whether to build as PIE], |
79 | + [ac_cv_use_android_pie], |
80 | + [ac_cv_use_android_pie=yes]) |
81 | +if test x"$ac_cv_use_android" = x"yes"; then |
82 | + if test x"$ac_cv_use_android_pie" = x"yes"; then |
83 | + AC_SUBST(AM_CFLAGS, "$AM_CFLAGS -pie") |
84 | + fi |
85 | +fi |
86 | + |
87 | AC_ARG_ENABLE(firewall, |
88 | AS_HELP_STRING([--disable-firewall], |
89 | [HIP firewall daemon (default is YES)]), |
90 | |
91 | === modified file 'doc/HOWTO.xml.in' |
92 | --- doc/HOWTO.xml.in 2013-11-01 08:28:46 +0000 |
93 | +++ doc/HOWTO.xml.in 2014-10-01 13:19:56 +0000 |
94 | @@ -280,15 +280,12 @@ |
95 | steps to compile for Android are almost similar to normal Linux builds. |
96 | You start with autoreconf --install; then you run the configure script: |
97 | <programlisting> |
98 | -./configure --enable-android --disable-firewall --host=arm-linux \ |
99 | - --prefix=/usr --sysconfdir=/etc \ |
100 | - CC=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc \ |
101 | - CFLAGS="-std=c99 -mbionic -fPIC -fno-exceptions \ |
102 | - --sysroot=${ANDROID_SYSROOT}" \ |
103 | - LDFLAGS="-Wl,-rpath-link=${ANDROID_SYSROOT}/usr/lib,-L${ANDROID_SYSROOT}/usr/lib" \ |
104 | - LIBS="-lc -lm -lgcc -lcrypto" \ |
105 | +CC=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc |
106 | +./configure --enable-android --host=arm-linux \ |
107 | + --prefix=/usr --sysconfdir=/etc |
108 | </programlisting> |
109 | - and run 'make'. |
110 | + and run 'make'. If you are building for an Android version older than 4.1, |
111 | + add '--disable-android-pie' to the configure line. |
112 | </para> |
113 | <para> |
114 | After the build process completes, open a root privileged shell session on |
115 | @@ -305,10 +302,16 @@ |
116 | Afterwards, you can return to your normal terminal and push hipd, hipconf |
117 | and the configuration in: |
118 | <programlisting> |
119 | -adb push tools/hipconf /system/xbin |
120 | -adb push hipd/hipd /system/xbin |
121 | -adb push hipd/hipd.conf /etc/hip |
122 | -adb push hipd/relay.conf /etc/hip |
123 | +adb push hipd/hipd /system/xbin |
124 | +adb push hipfw/hipfw /system/xbin |
125 | +adb push tools/hipconf /system/xbin |
126 | +adb push hipd/hipd.conf /etc/hip |
127 | +adb push hipd/relay.conf /etc/hip |
128 | +adb push hipfw/hipfw.conf /etc/hip |
129 | + |
130 | +for file in ${ANDROID_SYSROOT}/usr/lib/lib{netfilter_queue,nfnetlink,mnl}.*; do |
131 | + adb push $file /system/lib ; |
132 | +done |
133 | </programlisting> |
134 | </para> |
135 | <para> |
136 | @@ -316,7 +319,10 @@ |
137 | supports the same parameters as the normal Linux version does, |
138 | i.e. '-k' kills an already running instance and '-b' starts hipd in the |
139 | background. By e.g. running 'hipd -ab' and configuring hosts in /etc/hosts |
140 | - you should be able to use HIP on any program that supports IPv6. |
141 | + you should be able to use HIP on any program that supports IPv6. If you |
142 | + compiled all the required features into the kernel, instead of as modules, |
143 | + then the '-m' flag makes hipd ignore the fact that loading those modules |
144 | + fails. hipfw supports the same flags as on Linux. |
145 | </para> |
146 | <para> |
147 | As the root file system on Android typically resides on a ramdisk, |
148 | |
149 | === added directory 'patches/android' |
150 | === added directory 'patches/android/libnetfilter_queue' |
151 | === added file 'patches/android/libnetfilter_queue/tcp.c.patch' |
152 | --- patches/android/libnetfilter_queue/tcp.c.patch 1970-01-01 00:00:00 +0000 |
153 | +++ patches/android/libnetfilter_queue/tcp.c.patch 2014-10-01 13:19:56 +0000 |
154 | @@ -0,0 +1,18 @@ |
155 | +--- a/src/extra/tcp.c 2014-04-14 06:09:08.933915830 -0700 |
156 | ++++ b/src/extra/tcp.c 2014-04-14 06:09:48.305916775 -0700 |
157 | +@@ -109,16 +109,6 @@ |
158 | + } |
159 | + EXPORT_SYMBOL(nfq_tcp_compute_checksum_ipv6); |
160 | + |
161 | +-/* |
162 | +- * The union cast uses a gcc extension to avoid aliasing problems |
163 | +- * (union is compatible to any of its members) |
164 | +- * This means this part of the code is -fstrict-aliasing safe now. |
165 | +- */ |
166 | +-union tcp_word_hdr { |
167 | +- struct tcphdr hdr; |
168 | +- uint32_t words[5]; |
169 | +-}; |
170 | +- |
171 | + #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words[3]) |
172 | + |
173 | |
174 | === added directory 'patches/android/ndk' |
175 | === added file 'patches/android/ndk/ip.h.patch' |
176 | --- patches/android/ndk/ip.h.patch 1970-01-01 00:00:00 +0000 |
177 | +++ patches/android/ndk/ip.h.patch 2014-10-01 13:19:56 +0000 |
178 | @@ -0,0 +1,21 @@ |
179 | +--- old/netinet/ip.h 2014-04-30 22:30:15.572177205 -0700 |
180 | ++++ new/netinet/ip.h 2014-04-30 22:31:51.096180484 -0700 |
181 | +@@ -80,6 +80,8 @@ |
182 | + /* |
183 | + * Definitions for IP type of service (ip_tos) |
184 | + */ |
185 | ++#define IPTOS_TOS_MASK 0x1E |
186 | ++#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) |
187 | + #define IPTOS_LOWDELAY 0x10 |
188 | + #define IPTOS_THROUGHPUT 0x08 |
189 | + #define IPTOS_RELIABILITY 0x04 |
190 | +@@ -93,6 +95,8 @@ |
191 | + /* |
192 | + * Definitions for IP precedence (also in ip_tos) (hopefully unused) |
193 | + */ |
194 | ++#define IPTOS_PREC_MASK 0xe0 |
195 | ++#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) |
196 | + #define IPTOS_PREC_NETCONTROL 0xe0 |
197 | + #define IPTOS_PREC_INTERNETCONTROL 0xc0 |
198 | + #define IPTOS_PREC_CRITIC_ECP 0xa0 |
199 | + |
200 | |
201 | === added file 'patches/android/ndk/ip_icmp.h.patch' |
202 | --- patches/android/ndk/ip_icmp.h.patch 1970-01-01 00:00:00 +0000 |
203 | +++ patches/android/ndk/ip_icmp.h.patch 2014-10-01 13:19:56 +0000 |
204 | @@ -0,0 +1,33 @@ |
205 | +--- old/netinet/ip_icmp.h 2014-04-30 21:35:23.976064195 -0700 |
206 | ++++ new/netinet/ip_icmp.h 2014-04-30 21:52:21.520099130 -0700 |
207 | +@@ -119,6 +119,29 @@ |
208 | + #define icmp_data icmp_dun.id_data |
209 | + }; |
210 | + |
211 | ++ |
212 | ++struct icmphdr |
213 | ++{ |
214 | ++ u_int8_t type; /* message type */ |
215 | ++ u_int8_t code; /* type sub-code */ |
216 | ++ u_int16_t checksum; |
217 | ++ union |
218 | ++ { |
219 | ++ struct |
220 | ++ { |
221 | ++ u_int16_t id; |
222 | ++ u_int16_t sequence; |
223 | ++ } echo; /* echo datagram */ |
224 | ++ u_int32_t gateway; /* gateway address */ |
225 | ++ struct |
226 | ++ { |
227 | ++ u_int16_t __unused; |
228 | ++ u_int16_t mtu; |
229 | ++ } frag; /* path mtu discovery */ |
230 | ++ } un; |
231 | ++}; |
232 | ++ |
233 | ++ |
234 | + /* |
235 | + * For IPv6 transition related ICMP errors. |
236 | + */ |
237 | + |
238 | |
239 | === added file 'patches/android/ndk/swab.h.patch' |
240 | --- patches/android/ndk/swab.h.patch 1970-01-01 00:00:00 +0000 |
241 | +++ patches/android/ndk/swab.h.patch 2014-10-01 13:19:56 +0000 |
242 | @@ -0,0 +1,60 @@ |
243 | +--- swab.h 2011-02-02 13:43:37.711530000 +0000 |
244 | ++++ platforms/android-9/arch-arm/usr/include/linux/byteorder/swab.h 2011-02-02 13:37:58.011530001 +0000 |
245 | +@@ -64,9 +64,52 @@ |
246 | + #define __swab64(x) __fswab64(x) |
247 | + #endif |
248 | + |
249 | ++ |
250 | ++static __inline__ __attribute_const__ __u16 __fswab16(__u16 x) |
251 | ++{ |
252 | ++ return __arch__swab16(x); |
253 | ++} |
254 | ++static __inline__ __u16 __swab16p(__u16 *x) |
255 | ++{ |
256 | ++ return __arch__swab16p(x); |
257 | ++} |
258 | ++static __inline__ void __swab16s(__u16 *addr) |
259 | ++{ |
260 | ++ __arch__swab16s(addr); |
261 | ++} |
262 | ++ |
263 | ++static __inline__ __attribute_const__ __u32 __fswab32(__u32 x) |
264 | ++{ |
265 | ++ return __arch__swab32(x); |
266 | ++} |
267 | ++static __inline__ __u32 __swab32p(__u32 *x) |
268 | ++{ |
269 | ++ return __arch__swab32p(x); |
270 | ++} |
271 | ++static __inline__ void __swab32s(__u32 *addr) |
272 | ++{ |
273 | ++ __arch__swab32s(addr); |
274 | ++} |
275 | ++ |
276 | + #ifdef __BYTEORDER_HAS_U64__ |
277 | +-#ifdef __SWAB_64_THRU_32__ |
278 | +-#else |
279 | +-#endif |
280 | +-#endif |
281 | ++static __inline__ __attribute_const__ __u64 __fswab64(__u64 x) |
282 | ++{ |
283 | ++# ifdef __SWAB_64_THRU_32__ |
284 | ++ __u32 h = x >> 32; |
285 | ++ __u32 l = x & ((1ULL<<32)-1); |
286 | ++ return (((__u64)__swab32(l)) << 32) | ((__u64)(__swab32(h))); |
287 | ++# else |
288 | ++ return __arch__swab64(x); |
289 | ++# endif |
290 | ++} |
291 | ++static __inline__ __u64 __swab64p(__u64 *x) |
292 | ++{ |
293 | ++ return __arch__swab64p(x); |
294 | ++} |
295 | ++static __inline__ void __swab64s(__u64 *addr) |
296 | ++{ |
297 | ++ __arch__swab64s(addr); |
298 | ++} |
299 | ++#endif /* __BYTEORDER_HAS_U64__ */ |
300 | ++ |
301 | + #endif |
302 | + |
303 | |
304 | === modified file 'tools/prepare_android_toolchain.sh' |
305 | --- tools/prepare_android_toolchain.sh 2013-11-18 14:14:39 +0000 |
306 | +++ tools/prepare_android_toolchain.sh 2014-10-01 13:19:56 +0000 |
307 | @@ -1,14 +1,18 @@ |
308 | #!/bin/bash |
309 | - |
310 | # Script is for building an Android cross-compilation environment on linux. |
311 | |
312 | # If you want to change the install folder, do it here. |
313 | TOOLCHAIN_INSTALL_FOLDER=${HOME}/android_tools |
314 | -OPENSSL_VERSION='1.0.1e' |
315 | NDK_VERSION=r9 |
316 | SYSTEM=linux-x86_64 |
317 | |
318 | +OPENSSL_VERSION='1.0.1g' |
319 | +LIBMNL_VERSION='1.0.3' |
320 | +LIBNFNETLINK_VERSION='1.0.1' |
321 | +LIBNFQUEUE_VERSION='1.0.2' |
322 | + |
323 | # These are for the script's internals |
324 | +PATCHES_DIR=$(dirname $(readlink -f ${0}))/../patches/android |
325 | NDK_PACKAGE=android-ndk-${NDK_VERSION}-${SYSTEM} |
326 | NDK_ROOT=${TOOLCHAIN_INSTALL_FOLDER}/android-ndk-${NDK_VERSION} |
327 | ANDROID_TOOLCHAIN=${TOOLCHAIN_INSTALL_FOLDER}/toolchain |
328 | @@ -43,40 +47,36 @@ |
329 | fi |
330 | } |
331 | |
332 | -get_android_ndk() |
333 | +get_package() |
334 | { |
335 | - # If NDK is not found, download and install |
336 | - if [ ! -d ${NDK_ROOT} ]; then |
337 | - echo "Android NDK not found." |
338 | - if [ ! -f ${NDK_PACKAGE}.tar.bz2 ]; then |
339 | - echo "Android NDK package not found, downloading.." |
340 | - wget http://dl.google.com/android/ndk/${NDK_PACKAGE}.tar.bz2 |
341 | + PACKAGENAME=$1 |
342 | + URI=$2 |
343 | + FILENAME=$(basename $2) |
344 | + TARGET=$3 |
345 | + |
346 | + if [ ! -d ${TARGET} ]; then |
347 | + echo "$PACKAGENAME not found." |
348 | + if [ ! -f ${FILENAME} ]; then |
349 | + echo "$PACKAGENAME package not found, downloading.." |
350 | + wget $URI |
351 | else |
352 | - echo "Android NDK package found, using that." |
353 | + echo "$PACKAGENAME package found, using that." |
354 | fi |
355 | - echo "Extracting Android NDK.." |
356 | - tar xf ${NDK_PACKAGE}.tar.bz2 |
357 | + echo "Extracting $PACKAGENAME.." |
358 | + tar xf $FILENAME |
359 | else |
360 | - echo "Android NDK found, using that." |
361 | + echo "$PACKAGENAME found, using that." |
362 | fi |
363 | } |
364 | |
365 | -get_openssl() |
366 | +install_sdk_platform_tools() |
367 | { |
368 | - # If OpenSSL sources are not found, download them |
369 | - if [ ! -d openssl-${OPENSSL_VERSION} ]; then |
370 | - echo "OpenSSL source not found." |
371 | - if [ ! -f openssl-${OPENSSL_VERSION}.tar.gz ]; then |
372 | - echo "OpenSSL source package not found, downloading.." |
373 | - wget http://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz |
374 | - else |
375 | - echo "OpenSSL source package found, using that." |
376 | - fi |
377 | - echo "Extracting OpenSSL source.." |
378 | - tar xf openssl-${OPENSSL_VERSION}.tar.gz |
379 | - else |
380 | - echo "OpenSSL source found, using that." |
381 | - fi |
382 | + cd ${TOOLCHAIN_INSTALL_FOLDER}/android-sdk-linux/ |
383 | + if [ ! -f platform-tools/adb ]; then |
384 | + echo "Installing android platform tools" |
385 | + tools/android update sdk --no-ui -t platform-tool |
386 | + fi; |
387 | + cd .. |
388 | } |
389 | |
390 | build_ndk_toolchain() |
391 | @@ -91,17 +91,62 @@ |
392 | --install-dir=${ANDROID_TOOLCHAIN} |
393 | } |
394 | |
395 | +patch_toolchain() |
396 | +{ |
397 | + |
398 | +# ---- Add definition for __fswab64 needed by libnetfilter_queue ---- # |
399 | +# ---- https://code.google.com/p/android/issues/detail?id=14475 ---- # |
400 | +patch -N ${ANDROID_SYSROOT}/usr/include/linux/byteorder/swab.h < ${PATCHES_DIR}/ndk/swab.h.patch |
401 | + |
402 | +# --------- Add some deprecated stuff back to netinet/ip.h ---------- # |
403 | +patch -N ${ANDROID_SYSROOT}/usr/include/netinet/ip.h < ${PATCHES_DIR}/ndk/ip.h.patch |
404 | + |
405 | +# --------- Add the icmphdr definition to netinet/ip_icmp.h --------- # |
406 | +patch -N ${ANDROID_SYSROOT}/usr/include/netinet/ip_icmp.h < ${PATCHES_DIR}/ndk/ip_icmp.h.patch |
407 | + |
408 | +} |
409 | + |
410 | + |
411 | build_openssl() |
412 | { |
413 | # Configure and install OpenSSL in the toolchain |
414 | cd ${TOOLCHAIN_INSTALL_FOLDER}/openssl-${OPENSSL_VERSION} |
415 | ./config no-asm shared --prefix=${ANDROID_SYSROOT}/usr |
416 | sed 's/-m64//g' -i Makefile # The arm compiler doesn't support -m64 |
417 | - make install |
418 | - cd ${TOOLCHAIN_INSTALL_FOLDER} |
419 | -} |
420 | - |
421 | -set_openssl_build_env_vars() |
422 | + make |
423 | + make install_sw |
424 | + cd ${TOOLCHAIN_INSTALL_FOLDER} |
425 | +} |
426 | + |
427 | +build_libmnl() |
428 | +{ |
429 | + cd ${TOOLCHAIN_INSTALL_FOLDER}/libmnl-${LIBMNL_VERSION} |
430 | + ./configure --prefix=${ANDROID_SYSROOT}/usr --host=arm-linux CFLAGS="-mbionic -fPIC -fno-exceptions -I${ANDROID_SYSROOT}/usr/include" LDFLAGS="-Wl,-rpath-link=${ANDROID_SYSROOT}/usr/lib,-L${ANDROID_SYSROOT}/usr/lib" |
431 | + make install |
432 | + cd ${TOOLCHAIN_INSTALL_FOLDER} |
433 | +} |
434 | + |
435 | +build_libnfnetlink() |
436 | +{ |
437 | + cd ${TOOLCHAIN_INSTALL_FOLDER}/libnfnetlink-${LIBNFNETLINK_VERSION} |
438 | + ./configure --prefix=${ANDROID_SYSROOT}/usr --host=arm-linux CFLAGS="-mbionic -fPIC -fno-exceptions -I${ANDROID_SYSROOT}/usr/include" LDFLAGS="-Wl,-rpath-link=${ANDROID_SYSROOT}/usr/lib,-L${ANDROID_SYSROOT}/usr/lib" |
439 | + make install |
440 | + cd ${TOOLCHAIN_INSTALL_FOLDER} |
441 | +} |
442 | + |
443 | +build_libnetfilter_queue() |
444 | +{ |
445 | + cd ${TOOLCHAIN_INSTALL_FOLDER}/libnetfilter_queue-${LIBNFQUEUE_VERSION} |
446 | + |
447 | + # -------- Remove duplicate definition for tcp_word_hdr -------- # |
448 | + patch -N src/extra/tcp.c < ${PATCHES_DIR}/libnetfilter_queue/tcp.c.patch |
449 | + |
450 | + ./configure --prefix=${ANDROID_SYSROOT}/usr --host=arm-linux CFLAGS="-mbionic -fPIC -fno-exceptions -I${ANDROID_SYSROOT}/usr/include" LDFLAGS="-Wl,-rpath-link=${ANDROID_SYSROOT}/usr/lib,-L${ANDROID_SYSROOT}/usr/lib" |
451 | + make install |
452 | + cd ${TOOLCHAIN_INSTALL_FOLDER} |
453 | +} |
454 | + |
455 | +set_build_env_vars() |
456 | { |
457 | export CC=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc |
458 | export AR=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-ar r |
459 | @@ -111,6 +156,7 @@ |
460 | -DOPENSSL_N -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer \ |
461 | -Wall -fPIC" |
462 | export PLATFORM="arm-linux" |
463 | + export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${ANDROID_SYSROOT}/usr/lib/pkgconfig |
464 | } |
465 | |
466 | print_instructions() |
467 | @@ -128,49 +174,63 @@ |
468 | echo "We also recommend adding them to ${HOME}/.bashrc" |
469 | echo "so they will be ready for future builds." |
470 | echo "" |
471 | - echo "Then in HIPL root run: "\ |
472 | - ./configure \ |
473 | - --enable-android \ |
474 | - --disable-firewall \ |
475 | - --host=arm-linux \ |
476 | - --prefix=/usr \ |
477 | - --sysconfdir=/etc \ |
478 | - CC=\${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc \ |
479 | - \ |
480 | - CFLAGS=\"-std=c99 -mbionic -fPIC -fno-exceptions \ |
481 | - --sysroot=\${ANDROID_SYSROOT}\" \ |
482 | - \ |
483 | - LDFLAGS=\"-Wl,-rpath-link=\${ANDROID_SYSROOT}/usr/lib,-L\${ANDROID_SYSROOT}/usr/lib\" \ |
484 | - \ |
485 | - LIBS=\"-lc -lm -lgcc -lcrypto\" |
486 | + echo "Then in HIPL root run:" |
487 | + |
488 | + echo "For Android >= 4.1: " \ |
489 | + ./configure --enable-android --host=arm-linux \ |
490 | + --prefix=/usr --sysconfdir=/etc \ |
491 | + CC="${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc" |
492 | + echo "" |
493 | + echo "For Android < 4.1, add --disable-android-pie" |
494 | |
495 | # It is important that there are no spaces after commas in LDFLAGS. |
496 | } |
497 | |
498 | print_invocation_help() |
499 | { |
500 | - echo "Invocation: $0 [--auto-insert-bashrc]" |
501 | + echo "Invocation: $0 [--auto-insert-bashrc|--install-sdk]" |
502 | echo "--auto-insert-bashrc adds the NDK toolchain paths to .bashrc automatically." |
503 | + echo "--install-sdk Downloads the Android SDK platform tools (adb, fastboot etc.)." |
504 | } |
505 | |
506 | -# Main script |
507 | + |
508 | +#################### |
509 | +# Main script |
510 | +#################### |
511 | +make_install_folder |
512 | +cd ${TOOLCHAIN_INSTALL_FOLDER} |
513 | + |
514 | if [ ! "${1}xxx" = "xxx" ]; then |
515 | if [ "$1" = "--auto-insert-bashrc" ]; then |
516 | insert_vars_to_bashrc |
517 | + elif [ "$1" = "--install-sdk" ]; then |
518 | + get_package "Android SDK" http://dl.google.com/android/android-sdk_r22.6.2-linux.tgz android-sdk-linux |
519 | + install_sdk_platform_tools |
520 | + echo "To add adb etc. to your path, run:" |
521 | + echo "export PATH=${PATH}:${TOOLCHAIN_INSTALL_FOLDER}/android-sdk-linux/platform-tools" |
522 | + exit |
523 | else |
524 | print_invocation_help |
525 | exit |
526 | - fi # if --auto-insert-bashrc |
527 | + fi # if $1 known |
528 | fi # if $1 defined |
529 | |
530 | -make_install_folder |
531 | -cd ${TOOLCHAIN_INSTALL_FOLDER} |
532 | - |
533 | -get_android_ndk |
534 | +get_package "Android NDK" http://dl.google.com/android/ndk/${NDK_PACKAGE}.tar.bz2 ${NDK_ROOT} |
535 | build_ndk_toolchain |
536 | - |
537 | -get_openssl |
538 | -set_openssl_build_env_vars |
539 | +patch_toolchain |
540 | + |
541 | +set_build_env_vars |
542 | + |
543 | +get_package "OpenSSL" http://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz openssl-${OPENSSL_VERSION} |
544 | build_openssl |
545 | |
546 | +get_package "libmnl" http://netfilter.org/projects/libmnl/files/libmnl-${LIBMNL_VERSION}.tar.bz2 libmnl-${LIBMNL_VERSION} |
547 | +build_libmnl |
548 | + |
549 | +get_package "libnfnetlink" http://netfilter.org/projects/libnfnetlink/files/libnfnetlink-${LIBNFNETLINK_VERSION}.tar.bz2 libnfnetlink-${LIBNFNETLINK_VERSION} |
550 | +build_libnfnetlink |
551 | + |
552 | +get_package "libnetfilter_queue" http://netfilter.org/projects/libnetfilter_queue/files/libnetfilter_queue-${LIBNFQUEUE_VERSION}.tar.bz2 libnetfilter_queue-${LIBNFQUEUE_VERSION} |
553 | +build_libnetfilter_queue |
554 | + |
555 | print_instructions |
Seems good otherwise, but why are the patches embedded inside the script? I'd suggest separating them to patches/android, but perhaps you have a good reason for this.