Merge lp:~hipl-core/hipl/android-hipfw into lp:hipl

Proposed by Pupu Toivonen
Status: Superseded
Proposed branch: lp:~hipl-core/hipl/android-hipfw
Merge into: lp:hipl
Diff against target: 560 lines (+315/-89)
8 files modified
INSTALL (+32/-18)
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
Reviewer Review Type Date Requested Status
René Hummen Needs Fixing
Miika Komu Needs Information
Review via email: mp+232635@code.launchpad.net

This proposal has been superseded by a proposal from 2014-09-23.

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_android_toolchain.sh script now downloads
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.

To post a comment you must log in.
Revision history for this message
Miika Komu (miika-iki) wrote :

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.

review: Needs Information
Revision history for this message
René Hummen (rene-hummen) wrote :

I agree with Miika that the patches should be separated from 'tools/prepare_android_toolchain.sh'. Probably, you could even download them in your script. We then would not need to include external code in our repository.

In addition, please see my two diff comments.

review: Needs Fixing
Revision history for this message
Pupu Toivonen (scolphoy) wrote :
Download full text (4.1 KiB)

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_TOOLCHAIN}/bin/arm-linux-androideabi-gcc \
>> - CFLAGS="-std=c99 -mbionic -fPIC -fno-exceptions \
>> - --sysroot=${ANDROID_SYSROOT}" \
>> + ./configure --enable-android --host=arm-linux \
>> + --prefix=/usr --sysconfdir=/etc \
>> + CC=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc \
>> + CFLAGS="-std=c99 -mbionic -fPIC -pie -fno-exceptions \
>> + --sysroot=${ANDROID_SYSROOT}" \
>> LDFLAGS="-Wl,-rpath-link=${ANDROID_SYSROOT}/usr/lib,\
>> --L${ANDROID_SYSROOT}/usr/lib" \
>> +-L${ANDROID_SYSROOT}/usr/lib" \
>> 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_android_toolchain.sh 2013-11-18 14:14:39 +0000
>> +++ tools/prepare_android_toolchain.sh 2014-08-28 20:13:36 +0000
>> @@ -91,17 +91,206 @@
>>
>> +patch_toolchain()
>> +{
>> +# ------------------------------ PATCH ------------------------------ #
>> +# ---- Add definition for __fswab64 needed by libnetfilter_queue ---- #
>> +# ---- https://code.google.com/p/android/issues/detail?id=14475 ---- #
>> +
>> +patch -N ${ANDROID_SYSROOT}/usr/include/linux/byteorder/swab.h << EOF
>> +--- swab.h 2011-02-02 13:43:37.711530000 +0000
>> ++++ platforms/android-9/arch-arm/usr/include/linux/byteorder/swab.h 2011-02-02 13:37:58.011530001 +0000
>> +@@ -64,9 +64,52 @@
>> + #define __swab64(x) __fswab64(x)
>> + #endif
>> +
>> ++
>> ++static __inline__ __attribute_const__ __u16 __fswab16(__u16 x)
>> ++{
>> ++ return __arch__swab16(x);
>...

Read more...

Revision history for this message
Diego Biurrun (diego-biurrun) wrote :

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_TOOLCHAIN}/bin/arm-linux-androideabi-gcc \
> >> - CFLAGS="-std=c99 -mbionic -fPIC -fno-exceptions \
> >> - --sysroot=${ANDROID_SYSROOT}" \
> >> + ./configure --enable-android --host=arm-linux \
> >> + --prefix=/usr --sysconfdir=/etc \
> >> + CC=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc \
> >> + CFLAGS="-std=c99 -mbionic -fPIC -pie -fno-exceptions \
> >> + --sysroot=${ANDROID_SYSROOT}" \
> >> LDFLAGS="-Wl,-rpath-link=${ANDROID_SYSROOT}/usr/lib,\
> >> --L${ANDROID_SYSROOT}/usr/lib" \
> >> +-L${ANDROID_SYSROOT}/usr/lib" \
> >> 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

lp:~hipl-core/hipl/android-hipfw updated
6469. By Pupu Toivonen

Separate patches from prepare_android_toolchain.sh, fix a command's formatting in documentation.

6470. By Pupu Toivonen

Add newlines to end of patch files, fix finding patch directory.

6471. By Pupu Toivonen

Return accidentally commented out patch.

6472. By Pupu Toivonen

Convert tabs to spaces.

Revision history for this message
Pupu Toivonen (scolphoy) 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/src/android-hipfw'
  CC libcore/builder.lo
libcore/builder.c: Assembler messages:
libcore/builder.c:144: Error: no such instruction: `rev %edx,%edx'
libcore/builder.c:133: Error: no such instruction: `rev16 %dx,%dx'
libcore/builder.c:137: Error: no such instruction: `rev16 %dx,%dx'
libcore/builder.c:148: Error: no such instruction: `rev %edx,%edx'
libcore/builder.c:410: Error: no such instruction: `rev16 %dx,%dx'
libcore/builder.c:410: Error: no such instruction: `rev16 %ax,%ax'
libcore/builder.c:166: Error: no such instruction: `rev16 %dx,%dx'
libcore/builder.c:172: Error: no such instruction: `rev16 %dx,%dx'
libcore/builder.c:424: Error: no such instruction: `rev16 %ax,%ax’
. . .

Revision history for this message
Pupu Toivonen (scolphoy) wrote :

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/src/android-hipfw'
> CC libcore/builder.lo
> libcore/builder.c: Assembler messages:
> libcore/builder.c:144: Error: no such instruction: `rev %edx,%edx'
> libcore/builder.c:133: Error: no such instruction: `rev16 %dx,%dx'
> libcore/builder.c:137: Error: no such instruction: `rev16 %dx,%dx'
> libcore/builder.c:148: Error: no such instruction: `rev %edx,%edx'
> libcore/builder.c:410: Error: no such instruction: `rev16 %dx,%dx'
> libcore/builder.c:410: Error: no such instruction: `rev16 %ax,%ax'
> libcore/builder.c:166: Error: no such instruction: `rev16 %dx,%dx'
> libcore/builder.c:172: Error: no such instruction: `rev16 %dx,%dx'
> libcore/builder.c:424: Error: no such instruction: `rev16 %ax,%ax’
> . . .

Nevermind. It didn’t know which CC to use. Working on fixing it now.

lp:~hipl-core/hipl/android-hipfw updated
6473. By Pupu Toivonen

Fix disable compilation as non-PIE for Android, update instructions.

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

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'INSTALL'
--- INSTALL 2014-03-27 21:25:22 +0000
+++ INSTALL 2014-09-23 11:52:52 +0000
@@ -115,29 +115,43 @@
1154. Follow the instructions printed at the end of the script.1154. Follow the instructions printed at the end of the script.
116116
1175. In the HIPL source tree, run:1175. In the HIPL source tree, run:
118 ./configure --enable-android --disable-firewall --host=arm-linux \118 export CC="${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc"
119 --prefix=/usr --sysconfdir=/etc \119 ./configure --enable-android --host=arm-linux \
120 CC=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc \120 --prefix=/usr --sysconfdir=/etc
121 CFLAGS="-std=c99 -mbionic -fPIC -fno-exceptions \121
122 --sysroot=${ANDROID_SYSROOT}" \122For Android-versions older than 4.1, add '--disable-android-pie' to
123 LDFLAGS="-Wl,-rpath-link=${ANDROID_SYSROOT}/usr/lib,\123the configure line.
124-L${ANDROID_SYSROOT}/usr/lib" \
125 LIBS="-lc -lm -lgcc -lcrypto"
126124
127It is important that there are no spaces after commas in LDFLAGS.125It is important that there are no spaces after commas in LDFLAGS.
128126
129You can then compile the source using 'make'.127You can then compile the source using 'make'.
130128
131Currently to install HIP you need to run the following commands on your device:129Currently to install HIP you need to run the following commands on the computer:
132mount -o remount,rw /130adb root
133mount -o remount,rw /system131adb shell mount -o remount,rw /
134mkdir -p /var/lock132adb shell mount -o remount,rw /system
135mkdir /etc/hip133adb shell mkdir -p /var/lock
136ln -s /system/lib/libcrypto.so /system/lib/libcrypto.so.1.0.0134adb shell mkdir /etc/hip
137135adb shell ln -s /system/lib/libcrypto.so /system/lib/libcrypto.so.1.0.0
138Then copy (adb push) the config files hipd.conf and relay.conf /etc/hip and136
139the binaries hipd and hipconf to /system/xbin in your device. You should then be137Then using 'adb push' on your computer
140able to run hipd and hipconf normally.138Copy hipd/hipd.conf hipd/relay.conf and hipfw/hipfw.conf to /etc/hip/
139Copy hipd/hipd hipfw/hipfw and tools/hipconf to /system/xbin
140Copy all libmnl.* , libnfnetlink.* and libnetfilter_queue.* from
141the toolchain's sysroot/usr/lib/ to /system/lib/ on the device.
142This is usually $HOME/android_tools/toolchain/sysroot/usr/lib/
143DO NOT copy all the files under that directory, they do not all
144work on your device. Commands:
145
146adb push hipd/hipd /system/xbin
147adb push hipfw/hipfw /system/xbin
148adb push tools/hipconf /system/xbin
149adb push hipd/hipd.conf /etc/hip
150adb push hipd/relay.conf /etc/hip
151adb push hipfw/hipfw.conf /etc/hip
152for file in ${ANDROID_SYSROOT}/usr/lib/lib{netfilter_queue,nfnetlink,mnl}.*; do
153 adb push $file /system/lib ;
154done
141155
142You need to run hipd with the -a flag.156You need to run hipd with the -a flag.
143The /var/lock directory does not survive reboot, it needs to be157The /var/lock directory does not survive reboot, it needs to be
144158
=== modified file 'configure.ac'
--- configure.ac 2013-11-01 06:40:17 +0000
+++ configure.ac 2014-09-23 11:52:52 +0000
@@ -139,6 +139,20 @@
139fi139fi
140AM_CONDITIONAL(HIP_ANDROID, test x"$ac_cv_use_android" = x"yes")140AM_CONDITIONAL(HIP_ANDROID, test x"$ac_cv_use_android" = x"yes")
141141
142AC_ARG_ENABLE(android-pie,
143 AS_HELP_STRING([--disable-android-pie],
144 [Don't compile as PIE (Position Independent Executable)]),
145 [ac_cv_use_android_pie=$enableval],
146 [ac_cv_use_android_pie=yes])
147AC_CACHE_CHECK([whether to build as PIE],
148 [ac_cv_use_android_pie],
149 [ac_cv_use_android_pie=yes])
150if test x"$ac_cv_use_android" = x"yes"; then
151 if test x"$ac_cv_use_android_pie" = x"yes"; then
152 AC_SUBST(AM_CFLAGS, "$AM_CFLAGS -pie")
153 fi
154fi
155
142AC_ARG_ENABLE(firewall,156AC_ARG_ENABLE(firewall,
143 AS_HELP_STRING([--disable-firewall],157 AS_HELP_STRING([--disable-firewall],
144 [HIP firewall daemon (default is YES)]),158 [HIP firewall daemon (default is YES)]),
145159
=== modified file 'doc/HOWTO.xml.in'
--- doc/HOWTO.xml.in 2013-11-01 08:28:46 +0000
+++ doc/HOWTO.xml.in 2014-09-23 11:52:52 +0000
@@ -280,15 +280,12 @@
280 steps to compile for Android are almost similar to normal Linux builds.280 steps to compile for Android are almost similar to normal Linux builds.
281 You start with autoreconf --install; then you run the configure script:281 You start with autoreconf --install; then you run the configure script:
282 <programlisting>282 <programlisting>
283./configure --enable-android --disable-firewall --host=arm-linux \283CC=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc
284 --prefix=/usr --sysconfdir=/etc \284./configure --enable-android --host=arm-linux \
285 CC=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc \285 --prefix=/usr --sysconfdir=/etc
286 CFLAGS="-std=c99 -mbionic -fPIC -fno-exceptions \
287 --sysroot=${ANDROID_SYSROOT}" \
288 LDFLAGS="-Wl,-rpath-link=${ANDROID_SYSROOT}/usr/lib,-L${ANDROID_SYSROOT}/usr/lib" \
289 LIBS="-lc -lm -lgcc -lcrypto" \
290 </programlisting>286 </programlisting>
291 and run 'make'.287 and run 'make'. If you are building for an Android version older than 4.1,
288 add '--disable-android-pie' to the configure line.
292 </para>289 </para>
293 <para>290 <para>
294 After the build process completes, open a root privileged shell session on291 After the build process completes, open a root privileged shell session on
@@ -305,10 +302,16 @@
305 Afterwards, you can return to your normal terminal and push hipd, hipconf302 Afterwards, you can return to your normal terminal and push hipd, hipconf
306 and the configuration in:303 and the configuration in:
307 <programlisting>304 <programlisting>
308adb push tools/hipconf /system/xbin305adb push hipd/hipd /system/xbin
309adb push hipd/hipd /system/xbin306adb push hipfw/hipfw /system/xbin
310adb push hipd/hipd.conf /etc/hip307adb push tools/hipconf /system/xbin
311adb push hipd/relay.conf /etc/hip308adb push hipd/hipd.conf /etc/hip
309adb push hipd/relay.conf /etc/hip
310adb push hipfw/hipfw.conf /etc/hip
311
312for file in ${ANDROID_SYSROOT}/usr/lib/lib{netfilter_queue,nfnetlink,mnl}.*; do
313 adb push $file /system/lib ;
314done
312 </programlisting>315 </programlisting>
313 </para>316 </para>
314 <para>317 <para>
@@ -316,7 +319,10 @@
316 supports the same parameters as the normal Linux version does,319 supports the same parameters as the normal Linux version does,
317 i.e. '-k' kills an already running instance and '-b' starts hipd in the320 i.e. '-k' kills an already running instance and '-b' starts hipd in the
318 background. By e.g. running 'hipd -ab' and configuring hosts in /etc/hosts321 background. By e.g. running 'hipd -ab' and configuring hosts in /etc/hosts
319 you should be able to use HIP on any program that supports IPv6.322 you should be able to use HIP on any program that supports IPv6. If you
323 compiled all the required kernel features inside the kernel, instead of modules
324 the '-m' flag ignores the fact that loading those modules fails.
325 hipfw supports the same flags as on Linux.
320 </para>326 </para>
321 <para>327 <para>
322 As the root file system on Android typically resides on a ramdisk,328 As the root file system on Android typically resides on a ramdisk,
323329
=== added directory 'patches/android'
=== added directory 'patches/android/libnetfilter_queue'
=== added file 'patches/android/libnetfilter_queue/tcp.c.patch'
--- patches/android/libnetfilter_queue/tcp.c.patch 1970-01-01 00:00:00 +0000
+++ patches/android/libnetfilter_queue/tcp.c.patch 2014-09-23 11:52:52 +0000
@@ -0,0 +1,18 @@
1--- a/src/extra/tcp.c 2014-04-14 06:09:08.933915830 -0700
2+++ b/src/extra/tcp.c 2014-04-14 06:09:48.305916775 -0700
3@@ -109,16 +109,6 @@
4 }
5 EXPORT_SYMBOL(nfq_tcp_compute_checksum_ipv6);
6
7-/*
8- * The union cast uses a gcc extension to avoid aliasing problems
9- * (union is compatible to any of its members)
10- * This means this part of the code is -fstrict-aliasing safe now.
11- */
12-union tcp_word_hdr {
13- struct tcphdr hdr;
14- uint32_t words[5];
15-};
16-
17 #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words[3])
18
0\ No newline at end of file19\ No newline at end of file
120
=== added directory 'patches/android/ndk'
=== added file 'patches/android/ndk/ip.h.patch'
--- patches/android/ndk/ip.h.patch 1970-01-01 00:00:00 +0000
+++ patches/android/ndk/ip.h.patch 2014-09-23 11:52:52 +0000
@@ -0,0 +1,21 @@
1--- old/netinet/ip.h 2014-04-30 22:30:15.572177205 -0700
2+++ new/netinet/ip.h 2014-04-30 22:31:51.096180484 -0700
3@@ -80,6 +80,8 @@
4 /*
5 * Definitions for IP type of service (ip_tos)
6 */
7+#define IPTOS_TOS_MASK 0x1E
8+#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
9 #define IPTOS_LOWDELAY 0x10
10 #define IPTOS_THROUGHPUT 0x08
11 #define IPTOS_RELIABILITY 0x04
12@@ -93,6 +95,8 @@
13 /*
14 * Definitions for IP precedence (also in ip_tos) (hopefully unused)
15 */
16+#define IPTOS_PREC_MASK 0xe0
17+#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
18 #define IPTOS_PREC_NETCONTROL 0xe0
19 #define IPTOS_PREC_INTERNETCONTROL 0xc0
20 #define IPTOS_PREC_CRITIC_ECP 0xa0
21
0\ No newline at end of file22\ No newline at end of file
123
=== added file 'patches/android/ndk/ip_icmp.h.patch'
--- patches/android/ndk/ip_icmp.h.patch 1970-01-01 00:00:00 +0000
+++ patches/android/ndk/ip_icmp.h.patch 2014-09-23 11:52:52 +0000
@@ -0,0 +1,33 @@
1--- old/netinet/ip_icmp.h 2014-04-30 21:35:23.976064195 -0700
2+++ new/netinet/ip_icmp.h 2014-04-30 21:52:21.520099130 -0700
3@@ -119,6 +119,29 @@
4 #define icmp_data icmp_dun.id_data
5 };
6
7+
8+struct icmphdr
9+{
10+ u_int8_t type; /* message type */
11+ u_int8_t code; /* type sub-code */
12+ u_int16_t checksum;
13+ union
14+ {
15+ struct
16+ {
17+ u_int16_t id;
18+ u_int16_t sequence;
19+ } echo; /* echo datagram */
20+ u_int32_t gateway; /* gateway address */
21+ struct
22+ {
23+ u_int16_t __unused;
24+ u_int16_t mtu;
25+ } frag; /* path mtu discovery */
26+ } un;
27+};
28+
29+
30 /*
31 * For IPv6 transition related ICMP errors.
32 */
33
0\ No newline at end of file34\ No newline at end of file
135
=== added file 'patches/android/ndk/swab.h.patch'
--- patches/android/ndk/swab.h.patch 1970-01-01 00:00:00 +0000
+++ patches/android/ndk/swab.h.patch 2014-09-23 11:52:52 +0000
@@ -0,0 +1,60 @@
1--- swab.h 2011-02-02 13:43:37.711530000 +0000
2+++ platforms/android-9/arch-arm/usr/include/linux/byteorder/swab.h 2011-02-02 13:37:58.011530001 +0000
3@@ -64,9 +64,52 @@
4 #define __swab64(x) __fswab64(x)
5 #endif
6
7+
8+static __inline__ __attribute_const__ __u16 __fswab16(__u16 x)
9+{
10+ return __arch__swab16(x);
11+}
12+static __inline__ __u16 __swab16p(__u16 *x)
13+{
14+ return __arch__swab16p(x);
15+}
16+static __inline__ void __swab16s(__u16 *addr)
17+{
18+ __arch__swab16s(addr);
19+}
20+
21+static __inline__ __attribute_const__ __u32 __fswab32(__u32 x)
22+{
23+ return __arch__swab32(x);
24+}
25+static __inline__ __u32 __swab32p(__u32 *x)
26+{
27+ return __arch__swab32p(x);
28+}
29+static __inline__ void __swab32s(__u32 *addr)
30+{
31+ __arch__swab32s(addr);
32+}
33+
34 #ifdef __BYTEORDER_HAS_U64__
35-#ifdef __SWAB_64_THRU_32__
36-#else
37-#endif
38-#endif
39+static __inline__ __attribute_const__ __u64 __fswab64(__u64 x)
40+{
41+# ifdef __SWAB_64_THRU_32__
42+ __u32 h = x >> 32;
43+ __u32 l = x & ((1ULL<<32)-1);
44+ return (((__u64)__swab32(l)) << 32) | ((__u64)(__swab32(h)));
45+# else
46+ return __arch__swab64(x);
47+# endif
48+}
49+static __inline__ __u64 __swab64p(__u64 *x)
50+{
51+ return __arch__swab64p(x);
52+}
53+static __inline__ void __swab64s(__u64 *addr)
54+{
55+ __arch__swab64s(addr);
56+}
57+#endif /* __BYTEORDER_HAS_U64__ */
58+
59 #endif
60
0\ No newline at end of file61\ No newline at end of file
162
=== modified file 'tools/prepare_android_toolchain.sh'
--- tools/prepare_android_toolchain.sh 2013-11-18 14:14:39 +0000
+++ tools/prepare_android_toolchain.sh 2014-09-23 11:52:52 +0000
@@ -1,14 +1,18 @@
1#!/bin/bash1#!/bin/bash
2
3# Script is for building an Android cross-compilation environment on linux.2# Script is for building an Android cross-compilation environment on linux.
43
5# If you want to change the install folder, do it here.4# If you want to change the install folder, do it here.
6TOOLCHAIN_INSTALL_FOLDER=${HOME}/android_tools5TOOLCHAIN_INSTALL_FOLDER=${HOME}/android_tools
7OPENSSL_VERSION='1.0.1e'
8NDK_VERSION=r96NDK_VERSION=r9
9SYSTEM=linux-x86_647SYSTEM=linux-x86_64
108
9OPENSSL_VERSION='1.0.1g'
10LIBMNL_VERSION='1.0.3'
11LIBNFNETLINK_VERSION='1.0.1'
12LIBNFQUEUE_VERSION='1.0.2'
13
11# These are for the script's internals14# These are for the script's internals
15PATCHES_DIR=$(dirname $(readlink -f ${0}))/../patches/android
12NDK_PACKAGE=android-ndk-${NDK_VERSION}-${SYSTEM}16NDK_PACKAGE=android-ndk-${NDK_VERSION}-${SYSTEM}
13NDK_ROOT=${TOOLCHAIN_INSTALL_FOLDER}/android-ndk-${NDK_VERSION}17NDK_ROOT=${TOOLCHAIN_INSTALL_FOLDER}/android-ndk-${NDK_VERSION}
14ANDROID_TOOLCHAIN=${TOOLCHAIN_INSTALL_FOLDER}/toolchain18ANDROID_TOOLCHAIN=${TOOLCHAIN_INSTALL_FOLDER}/toolchain
@@ -43,40 +47,36 @@
43 fi47 fi
44}48}
4549
46get_android_ndk()50get_package()
47{51{
48 # If NDK is not found, download and install52 PACKAGENAME=$1
49 if [ ! -d ${NDK_ROOT} ]; then53 URI=$2
50 echo "Android NDK not found."54 FILENAME=$(basename $2)
51 if [ ! -f ${NDK_PACKAGE}.tar.bz2 ]; then55 TARGET=$3
52 echo "Android NDK package not found, downloading.."56
53 wget http://dl.google.com/android/ndk/${NDK_PACKAGE}.tar.bz257 if [ ! -d ${TARGET} ]; then
58 echo "$PACKAGENAME not found."
59 if [ ! -f ${FILENAME} ]; then
60 echo "$PACKAGENAME package not found, downloading.."
61 wget $URI
54 else62 else
55 echo "Android NDK package found, using that."63 echo "$PACKAGENAME package found, using that."
56 fi64 fi
57 echo "Extracting Android NDK.."65 echo "Extracting $PACKAGENAME.."
58 tar xf ${NDK_PACKAGE}.tar.bz266 tar xf $FILENAME
59 else67 else
60 echo "Android NDK found, using that."68 echo "$PACKAGENAME found, using that."
61 fi69 fi
62}70}
6371
64get_openssl()72install_sdk_platform_tools()
65{73{
66 # If OpenSSL sources are not found, download them74 cd ${TOOLCHAIN_INSTALL_FOLDER}/android-sdk-linux/
67 if [ ! -d openssl-${OPENSSL_VERSION} ]; then75 if [ ! -f platform-tools/adb ]; then
68 echo "OpenSSL source not found."76 echo "Installing android platform tools"
69 if [ ! -f openssl-${OPENSSL_VERSION}.tar.gz ]; then77 tools/android update sdk --no-ui -t platform-tool
70 echo "OpenSSL source package not found, downloading.."78 fi;
71 wget http://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz79 cd ..
72 else
73 echo "OpenSSL source package found, using that."
74 fi
75 echo "Extracting OpenSSL source.."
76 tar xf openssl-${OPENSSL_VERSION}.tar.gz
77 else
78 echo "OpenSSL source found, using that."
79 fi
80}80}
8181
82build_ndk_toolchain()82build_ndk_toolchain()
@@ -91,17 +91,62 @@
91 --install-dir=${ANDROID_TOOLCHAIN}91 --install-dir=${ANDROID_TOOLCHAIN}
92}92}
9393
94patch_toolchain()
95{
96
97# ---- Add definition for __fswab64 needed by libnetfilter_queue ---- #
98# ---- https://code.google.com/p/android/issues/detail?id=14475 ---- #
99patch -N ${ANDROID_SYSROOT}/usr/include/linux/byteorder/swab.h < ${PATCHES_DIR}/ndk/swab.h.patch
100
101# --------- Add some depricated stuff back to netinet/ip.h ---------- #
102patch -N ${ANDROID_SYSROOT}/usr/include/netinet/ip.h < ${PATCHES_DIR}/ndk/ip.h.patch
103
104# --------- Add the icmphdr definition to netinet/ip_icmp.h --------- #
105patch -N ${ANDROID_SYSROOT}/usr/include/netinet/ip_icmp.h < ${PATCHES_DIR}/ndk/ip_icmp.h.patch
106
107}
108
109
94build_openssl()110build_openssl()
95{111{
96 # Configure and install OpenSSL in the toolchain112 # Configure and install OpenSSL in the toolchain
97 cd ${TOOLCHAIN_INSTALL_FOLDER}/openssl-${OPENSSL_VERSION}113 cd ${TOOLCHAIN_INSTALL_FOLDER}/openssl-${OPENSSL_VERSION}
98 ./config no-asm shared --prefix=${ANDROID_SYSROOT}/usr114 ./config no-asm shared --prefix=${ANDROID_SYSROOT}/usr
99 sed 's/-m64//g' -i Makefile # The arm compiler doesn't support -m64115 sed 's/-m64//g' -i Makefile # The arm compiler doesn't support -m64
100 make install116 make
101 cd ${TOOLCHAIN_INSTALL_FOLDER}117 make install_sw
102}118 cd ${TOOLCHAIN_INSTALL_FOLDER}
103119}
104set_openssl_build_env_vars()120
121build_libmnl()
122{
123 cd ${TOOLCHAIN_INSTALL_FOLDER}/libmnl-${LIBMNL_VERSION}
124 ./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"
125 make install
126 cd ${TOOLCHAIN_INSTALL_FOLDER}
127}
128
129build_libnfnetlink()
130{
131 cd ${TOOLCHAIN_INSTALL_FOLDER}/libnfnetlink-${LIBNFNETLINK_VERSION}
132 ./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"
133 make install
134 cd ${TOOLCHAIN_INSTALL_FOLDER}
135}
136
137build_libnetfilter_queue()
138{
139 cd ${TOOLCHAIN_INSTALL_FOLDER}/libnetfilter_queue-${LIBNFQUEUE_VERSION}
140
141 # -------- Remove duplicate definition for tcp_word_hdr -------- #
142 patch -N src/extra/tcp.c < ${PATCHES_DIR}/libnetfilter_queue/tcp.c.patch
143
144 ./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"
145 make install
146 cd ${TOOLCHAIN_INSTALL_FOLDER}
147}
148
149set_build_env_vars()
105{150{
106 export CC=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc151 export CC=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc
107 export AR=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-ar r152 export AR=${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-ar r
@@ -111,6 +156,7 @@
111 -DOPENSSL_N -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer \156 -DOPENSSL_N -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer \
112 -Wall -fPIC"157 -Wall -fPIC"
113 export PLATFORM="arm-linux"158 export PLATFORM="arm-linux"
159 export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${ANDROID_SYSROOT}/usr/lib/pkgconfig
114}160}
115161
116print_instructions()162print_instructions()
@@ -128,49 +174,63 @@
128 echo "We also recommend adding them to ${HOME}/.bashrc"174 echo "We also recommend adding them to ${HOME}/.bashrc"
129 echo "so they will be ready for future builds."175 echo "so they will be ready for future builds."
130 echo ""176 echo ""
131 echo "Then in HIPL root run: "\177 echo "Then in HIPL root run:"
132 ./configure \178
133 --enable-android \179 echo "For Android >= 4.1: " \
134 --disable-firewall \180 ./configure --enable-android --host=arm-linux \
135 --host=arm-linux \181 --prefix=/usr --sysconfdir=/etc \
136 --prefix=/usr \182 CC="${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc"
137 --sysconfdir=/etc \183 echo ""
138 CC=\${ANDROID_TOOLCHAIN}/bin/arm-linux-androideabi-gcc \184 echo "For Android < 4.1, add --disable-android-pie"
139 \
140 CFLAGS=\"-std=c99 -mbionic -fPIC -fno-exceptions \
141 --sysroot=\${ANDROID_SYSROOT}\" \
142 \
143 LDFLAGS=\"-Wl,-rpath-link=\${ANDROID_SYSROOT}/usr/lib,-L\${ANDROID_SYSROOT}/usr/lib\" \
144 \
145 LIBS=\"-lc -lm -lgcc -lcrypto\"
146185
147 # It is important that there are no spaces after commas in LDFLAGS.186 # It is important that there are no spaces after commas in LDFLAGS.
148}187}
149188
150print_invocation_help()189print_invocation_help()
151{190{
152 echo "Invocation: $0 [--auto-insert-bashrc]"191 echo "Invocation: $0 [--auto-insert-bashrc|--install-sdk]"
153 echo "--auto-insert-bashrc adds the NDK toolchain paths to .bashrc automatically."192 echo "--auto-insert-bashrc adds the NDK toolchain paths to .bashrc automatically."
193 echo "--install-sdk Downloads the Android SDK platform tools (adb, fastboot etc.)."
154}194}
155195
156# Main script196
197####################
198# Main script
199####################
200make_install_folder
201cd ${TOOLCHAIN_INSTALL_FOLDER}
202
157if [ ! "${1}xxx" = "xxx" ]; then203if [ ! "${1}xxx" = "xxx" ]; then
158 if [ "$1" = "--auto-insert-bashrc" ]; then204 if [ "$1" = "--auto-insert-bashrc" ]; then
159 insert_vars_to_bashrc205 insert_vars_to_bashrc
206 elif [ "$1" = "--install-sdk" ]; then
207 get_package "Android SDK" http://dl.google.com/android/android-sdk_r22.6.2-linux.tgz android-sdk-linux
208 install_sdk_platform_tools
209 echo "To add adb etc. to your path, run:"
210 echo "export PATH=${PATH}:${TOOLCHAIN_INSTALL_FOLDER}/android-sdk-linux/platform-tools"
211 exit
160 else212 else
161 print_invocation_help213 print_invocation_help
162 exit214 exit
163 fi # if --auto-insert-bashrc215 fi # if $1 known
164fi # if $1 defined216fi # if $1 defined
165217
166make_install_folder218get_package "Android NDK" http://dl.google.com/android/ndk/${NDK_PACKAGE}.tar.bz2 ${NDK_ROOT}
167cd ${TOOLCHAIN_INSTALL_FOLDER}
168
169get_android_ndk
170build_ndk_toolchain219build_ndk_toolchain
171220patch_toolchain
172get_openssl221
173set_openssl_build_env_vars222set_build_env_vars
223
224get_package "OpenSSL" http://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz openssl-${OPENSSL_VERSION}
174build_openssl225build_openssl
175226
227get_package "libmnl" http://netfilter.org/projects/libmnl/files/libmnl-${LIBMNL_VERSION}.tar.bz2 libmnl-${LIBMNL_VERSION}
228build_libmnl
229
230get_package "libnfnetlink" http://netfilter.org/projects/libnfnetlink/files/libnfnetlink-${LIBNFNETLINK_VERSION}.tar.bz2 libnfnetlink-${LIBNFNETLINK_VERSION}
231build_libnfnetlink
232
233get_package "libnetfilter_queue" http://netfilter.org/projects/libnetfilter_queue/files/libnetfilter_queue-${LIBNFQUEUE_VERSION}.tar.bz2 libnetfilter_queue-${LIBNFQUEUE_VERSION}
234build_libnetfilter_queue
235
176print_instructions236print_instructions

Subscribers

People subscribed via source and target branches

to all changes: