Repo created
This commit is contained in:
parent
51cf8bb4f9
commit
ee0cddf35c
548 changed files with 93129 additions and 2 deletions
4
external/.gitignore
vendored
Normal file
4
external/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
aarch64-linux-android/
|
||||
arm-linux-androideabi/
|
||||
i686-linux-android/
|
||||
sources/
|
||||
10
external/Android.mk
vendored
Normal file
10
external/Android.mk
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
LOCAL_PATH := $(call my-dir)
|
||||
# Clear variables here.
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
ZPATH := $(LOCAL_PATH)
|
||||
|
||||
include $(ZPATH)/nflog/Android.mk
|
||||
|
||||
# run pie is no longer supported
|
||||
# include $(ZPATH)/run_pie/Android.mk
|
||||
161
external/Makefile
vendored
Normal file
161
external/Makefile
vendored
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
#
|
||||
# Based somewhat on android/Makefile in OpenConnect (David Woodhouse)
|
||||
#
|
||||
|
||||
NDK := /opt/android-ndk-r10e
|
||||
ARCH := arm
|
||||
GCCVER := 4.9
|
||||
|
||||
# You should be able to just 'make ARCH=x86' and it should DTRT.
|
||||
ARCH_LIST := arm arm64 x86
|
||||
APIVER := 21
|
||||
ifeq ($(ARCH),arm)
|
||||
TRIPLET := arm-linux-androideabi
|
||||
TOOLCHAIN := $(TRIPLET)-$(GCCVER)
|
||||
NDK_ABINAME := armeabi
|
||||
endif
|
||||
ifeq ($(ARCH),arm64)
|
||||
TRIPLET := aarch64-linux-android
|
||||
TOOLCHAIN := $(TRIPLET)-$(GCCVER)
|
||||
APIVER := 21
|
||||
NDK_ABINAME := arm64-v8a
|
||||
endif
|
||||
ifeq ($(ARCH),x86)
|
||||
TRIPLET := i686-linux-android
|
||||
TOOLCHAIN := x86-$(GCCVER)
|
||||
NDK_ABINAME := x86
|
||||
endif
|
||||
|
||||
NDK_SYSROOT := $(NDK)/platforms/android-$(APIVER)/arch-$(ARCH)
|
||||
|
||||
BINDIR := $(firstword $(wildcard $(NDK)/toolchains/$(TOOLCHAIN)/prebuilt/*/bin))
|
||||
PATH := $(BINDIR):$(NDK):$(PATH)
|
||||
|
||||
RESDIR := $(shell pwd)/../app/src/main/res/raw/
|
||||
DESTDIR := $(shell pwd)/$(TRIPLET)/out
|
||||
|
||||
CONFIGURE_ARGS := --host=$(TRIPLET) --disable-shared --enable-static \
|
||||
CFLAGS="--sysroot=$(NDK_SYSROOT) -O2 -fvisibility=default -fPIE" \
|
||||
LDFLAGS="-rdynamic -pie" \
|
||||
|
||||
PER_ARCH_TARGETS := iptables busybox nflog
|
||||
|
||||
.PHONY: all unpack clean
|
||||
all: $(addsuffix -binaries,$(ARCH_LIST))
|
||||
clean: $(addsuffix -clean,$(ARCH_LIST))
|
||||
rm -rf sources
|
||||
unpack: $(addsuffix -unpack,$(PER_ARCH_TARGETS))
|
||||
|
||||
#####################################################################
|
||||
#
|
||||
# Build iptables
|
||||
#
|
||||
IPTABLES_VER := 1.4.20
|
||||
IPTABLES_SRC := sources/iptables-$(IPTABLES_VER)
|
||||
IPTABLES_BUILD := $(TRIPLET)/iptables
|
||||
|
||||
dist/iptables-$(IPTABLES_VER).tar.bz2:
|
||||
mkdir -p dist
|
||||
curl http://ftp.netfilter.org/pub/iptables/iptables-$(IPTABLES_VER).tar.bz2 -o $@.tmp && mv $@.tmp $@
|
||||
|
||||
$(IPTABLES_SRC)/configure: dist/iptables-$(IPTABLES_VER).tar.bz2
|
||||
rm -rf $(IPTABLES_SRC)
|
||||
mkdir -p sources
|
||||
tar -jxf $< -C sources
|
||||
cd $(IPTABLES_SRC) && \
|
||||
for x in ../../dist/iptables-patches/*; do \
|
||||
patch -p1 < $$x || exit 1; \
|
||||
done
|
||||
cd $(IPTABLES_SRC) && ./autogen.sh
|
||||
|
||||
$(IPTABLES_BUILD)/Makefile: $(IPTABLES_SRC)/configure
|
||||
mkdir -p $(IPTABLES_BUILD)
|
||||
cd $(IPTABLES_BUILD) && ../../$(IPTABLES_SRC)/configure \
|
||||
$(CONFIGURE_ARGS) --prefix=/
|
||||
|
||||
$(DESTDIR)/sbin/iptables: $(IPTABLES_BUILD)/Makefile
|
||||
$(MAKE) -C $(IPTABLES_BUILD)
|
||||
$(MAKE) -C $(IPTABLES_BUILD) install DESTDIR=$(DESTDIR)
|
||||
|
||||
.PHONY: iptables iptables-unpack
|
||||
iptables: $(DESTDIR)/sbin/iptables
|
||||
cp -L $(DESTDIR)/sbin/iptables $(RESDIR)/iptables_$(ARCH)
|
||||
cp -L $(DESTDIR)/sbin/ip6tables $(RESDIR)/ip6tables_$(ARCH)
|
||||
iptables-unpack: $(IPTABLES_SRC)/configure
|
||||
|
||||
#####################################################################
|
||||
#
|
||||
# Build busybox
|
||||
#
|
||||
BUSYBOX_VER := 1.26.2
|
||||
BUSYBOX_BUILD := $(TRIPLET)/busybox
|
||||
|
||||
dist/busybox-$(BUSYBOX_VER).tar.bz2:
|
||||
mkdir -p dist
|
||||
curl http://busybox.net/downloads/busybox-$(BUSYBOX_VER).tar.bz2 -o $@.tmp && mv $@.tmp $@
|
||||
|
||||
$(BUSYBOX_BUILD)/.unpacked: dist/busybox-$(BUSYBOX_VER).tar.bz2
|
||||
rm -rf $(BUSYBOX_BUILD)
|
||||
mkdir -p $(BUSYBOX_BUILD)
|
||||
tar --strip 1 -jxf $< -C $(BUSYBOX_BUILD)
|
||||
cd $(BUSYBOX_BUILD) && \
|
||||
for x in ../../dist/busybox-patches/*; do \
|
||||
patch -p1 < $$x || exit 1; \
|
||||
done
|
||||
touch $@
|
||||
|
||||
$(BUSYBOX_BUILD)/.configured: $(BUSYBOX_BUILD)/.unpacked
|
||||
cp -f dist/busybox-config $(BUSYBOX_BUILD)/.config
|
||||
echo "CONFIG_CROSS_COMPILER_PREFIX=\"$(TRIPLET)-\"" >> $(BUSYBOX_BUILD)/.config
|
||||
echo "CONFIG_SYSROOT=\"$(NDK_SYSROOT)\"" >> $(BUSYBOX_BUILD)/.config
|
||||
touch $@
|
||||
|
||||
$(BUSYBOX_BUILD)/busybox: $(BUSYBOX_BUILD)/.configured
|
||||
$(MAKE) -C $(BUSYBOX_BUILD) KCONFIG_NOTIMESTAMP=1
|
||||
|
||||
.PHONY: busybox busybox-unpack
|
||||
busybox: $(BUSYBOX_BUILD)/busybox
|
||||
cp $< $(RESDIR)/busybox_$(ARCH)
|
||||
busybox-unpack: $(BUSYBOX_BUILD)/.configured
|
||||
|
||||
#####################################################################
|
||||
#
|
||||
# Build nflog
|
||||
#
|
||||
NDK_OUTDIR := ../libs/$(NDK_ABINAME)
|
||||
|
||||
$(NDK_OUTDIR)/nflog: .FORCE
|
||||
ndk-build APP_ABI=$(NDK_ABINAME) APP_PLATFORM=$(APIVER) NDK_TOOLCHAIN=$(TOOLCHAIN)
|
||||
|
||||
.FORCE:
|
||||
.PHONY: nflog nflog-unpack
|
||||
nflog: $(NDK_OUTDIR)/nflog
|
||||
cp $< $(RESDIR)/nflog_$(ARCH)
|
||||
nflog-unpack:
|
||||
|
||||
#####################################################################
|
||||
#
|
||||
# Build Run PIE
|
||||
#
|
||||
# NDK_OUTDIR := ../libs/$(NDK_ABINAME)
|
||||
|
||||
# $(NDK_OUTDIR)/run_pie:
|
||||
# ndk-build APP_ABI=$(NDK_ABINAME)
|
||||
|
||||
#.PHONY: run_pie run_pie-unpack
|
||||
#run_pie: $(NDK_OUTDIR)/run_pie
|
||||
# cp $< $(RESDIR)/run_pie_$(ARCH)
|
||||
# run_pie-unpack:
|
||||
|
||||
#####################################################################
|
||||
#
|
||||
# Common targets
|
||||
#
|
||||
.PHONY: arch-clean %-clean %-binaries
|
||||
arch-clean:
|
||||
rm -rf $(TRIPLET) $(NDK_OUTDIR)
|
||||
%-clean:
|
||||
$(MAKE) ARCH=$* arch-clean
|
||||
ndk-build APP_ABI=$(NDK_ABINAME) clean
|
||||
%-binaries: unpack
|
||||
$(MAKE) ARCH=$* $(PER_ARCH_TARGETS)
|
||||
1077
external/dist/busybox-config
vendored
Normal file
1077
external/dist/busybox-config
vendored
Normal file
File diff suppressed because it is too large
Load diff
1069
external/dist/busybox-config_womount
vendored
Normal file
1069
external/dist/busybox-config_womount
vendored
Normal file
File diff suppressed because it is too large
Load diff
1010
external/dist/busybox-defconfig
vendored
Normal file
1010
external/dist/busybox-defconfig
vendored
Normal file
File diff suppressed because it is too large
Load diff
24
external/dist/busybox-patches/000-customMakefile.patch
vendored
Normal file
24
external/dist/busybox-patches/000-customMakefile.patch
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Tue, 10 Jan 2017 13:51:10 -0400
|
||||
Subject: [PATCH] Add custom busybox version tagging
|
||||
|
||||
---
|
||||
Makefile | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/Makefile b/Makefile
|
||||
index ea9dd3d..c378593 100644
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -1,7 +1,7 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 26
|
||||
SUBLEVEL = 2
|
||||
-EXTRAVERSION =
|
||||
+EXTRAVERSION = -osm0sis
|
||||
NAME = Unnamed
|
||||
|
||||
# *DOCUMENTATION*
|
||||
--
|
||||
2.5.3
|
||||
|
||||
21
external/dist/busybox-patches/000-gcc-version.patch
vendored
Normal file
21
external/dist/busybox-patches/000-gcc-version.patch
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Fri, 27 Nov 2015 09:47:41 -0400
|
||||
Subject: [PATCH] Fix "invalid number" stderr during build despite printf stdout being as expected
|
||||
|
||||
---
|
||||
scripts/gcc-version.sh | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/scripts/gcc-version.sh b/scripts/gcc-version.sh
|
||||
index 3451080..d7bf002 100755
|
||||
--- a/scripts/gcc-version.sh
|
||||
+++ b/scripts/gcc-version.sh
|
||||
@@ -9,4 +9,4 @@
|
||||
compiler="$*"
|
||||
|
||||
MAJ_MIN=$(echo __GNUC__ __GNUC_MINOR__ | $compiler -E -xc - | tail -n 1)
|
||||
-printf '%02d%02d\n' $MAJ_MIN
|
||||
+printf '%02d%02d\n' $MAJ_MIN 2>/dev/null
|
||||
--
|
||||
2.5.3
|
||||
|
||||
26
external/dist/busybox-patches/001-mconf+lkc.patch
vendored
Normal file
26
external/dist/busybox-patches/001-mconf+lkc.patch
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Fri, 27 Nov 2015 11:40:52 -0400
|
||||
Subject: [PATCH 2/2] Fix mconf/lkc host "warning statement with no effect"
|
||||
|
||||
---
|
||||
scripts/kconfig/lkc.h | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
|
||||
index 527f60c..1972cb9 100644
|
||||
--- a/scripts/kconfig/lkc.h
|
||||
+++ b/scripts/kconfig/lkc.h
|
||||
@@ -12,8 +12,8 @@
|
||||
# include <libintl.h>
|
||||
#else
|
||||
# define gettext(Msgid) ((const char *) (Msgid))
|
||||
-# define textdomain(Domainname) ((const char *) (Domainname))
|
||||
-# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
|
||||
+# define textdomain(Domainname)
|
||||
+# define bindtextdomain(Domainname, Dirname)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
--
|
||||
2.5.3
|
||||
|
||||
23
external/dist/busybox-patches/002-checklist.patch
vendored
Normal file
23
external/dist/busybox-patches/002-checklist.patch
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Tue, 10 Jan 2017 13:38:38 -0400
|
||||
Subject: [PATCH] Fix checklist host "warning implicit declaration of function 'strcasecmp'"
|
||||
|
||||
---
|
||||
scripts/kconfig/lxdialog/checklist.c | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
|
||||
index be0200e..934fbf2 100644
|
||||
--- a/scripts/kconfig/lxdialog/checklist.c
|
||||
+++ b/scripts/kconfig/lxdialog/checklist.c
|
||||
@@ -21,6 +21,7 @@
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
+#include <strings.h>
|
||||
#include "dialog.h"
|
||||
|
||||
static int list_width, check_x, item_x;
|
||||
--
|
||||
2.8.3
|
||||
|
||||
323
external/dist/busybox-patches/003-a-mount-umount-fsck-df.patch
vendored
Normal file
323
external/dist/busybox-patches/003-a-mount-umount-fsck-df.patch
vendored
Normal file
|
|
@ -0,0 +1,323 @@
|
|||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Sun, 18 Mar 2012 14:12:41 +0000
|
||||
Subject: [PATCH] android: fix 'mount', 'umount', 'fsck', 'df'
|
||||
|
||||
patch modified from 'Bionic Patch V1.0 (Vitaly Greck)'
|
||||
https://code.google.com/p/busybox-android/downloads/detail?name=patch
|
||||
---
|
||||
libbb/Kbuild.src | 3 +
|
||||
libbb/mntent_r.c | 288 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 291 insertions(+)
|
||||
create mode 100644 libbb/mntent_r.c
|
||||
|
||||
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src
|
||||
index 61eec26..d456c3d 100644
|
||||
--- a/libbb/Kbuild.src
|
||||
+++ b/libbb/Kbuild.src
|
||||
@@ -115,6 +115,9 @@ lib-y += xgethostbyname.o
|
||||
lib-y += xreadlink.o
|
||||
lib-y += xrealloc_vector.o
|
||||
|
||||
+# for android-busybox-ndk
|
||||
+lib-y += mntent_r.o
|
||||
+
|
||||
lib-$(CONFIG_PLATFORM_LINUX) += match_fstype.o
|
||||
|
||||
lib-$(CONFIG_FEATURE_UTMP) += utmp.o
|
||||
diff --git a/libbb/mntent_r.c b/libbb/mntent_r.c
|
||||
new file mode 100644
|
||||
index 0000000..1077487
|
||||
--- /dev/null
|
||||
+++ b/libbb/mntent_r.c
|
||||
@@ -0,0 +1,288 @@
|
||||
+/* Utilities for reading/writing fstab, mtab, etc.
|
||||
+ Copyright (C) 1995-2000, 2001, 2002, 2003, 2006, 2010, 2011
|
||||
+ Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, see
|
||||
+ <http://www.gnu.org/licenses/>. */
|
||||
+
|
||||
+// file extracted from patch 'Bionic Patch V1.0 (Vitaly Greck)':
|
||||
+// https://busybox-android.googlecode.com/files/patch
|
||||
+//
|
||||
+// looks like its based on misc/mntent_r.c from glibc,
|
||||
+// contains all fixes in current master (2012-03-19),
|
||||
+// but is not source identical (mostly stuff removed)
|
||||
+// using the upstream one fails to build
|
||||
+
|
||||
+
|
||||
+#include <alloca.h>
|
||||
+#include <mntent.h>
|
||||
+#include <stdio.h>
|
||||
+#include <string.h>
|
||||
+#include <sys/types.h>
|
||||
+
|
||||
+
|
||||
+/* Prepare to begin reading and/or writing mount table entries from the
|
||||
+ beginning of FILE. MODE is as for `fopen'. */
|
||||
+FILE *setmntent (const char *file, const char *mode)
|
||||
+{
|
||||
+ /* Extend the mode parameter with "c" to disable cancellation in the
|
||||
+ I/O functions and "e" to set FD_CLOEXEC. */
|
||||
+ size_t modelen = strlen (mode);
|
||||
+ char newmode[modelen + 3];
|
||||
+ memcpy (newmode, mode, modelen);
|
||||
+ memcpy (newmode + modelen, "ce", 3);
|
||||
+ FILE *result = fopen (file, newmode);
|
||||
+
|
||||
+ return result;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+/* Close a stream opened with `setmntent'. */
|
||||
+int endmntent (FILE *stream)
|
||||
+{
|
||||
+ if (stream) /* SunOS 4.x allows for NULL stream */
|
||||
+ fclose (stream);
|
||||
+ return 1; /* SunOS 4.x says to always return 1 */
|
||||
+}
|
||||
+
|
||||
+
|
||||
+/* Since the values in a line are separated by spaces, a name cannot
|
||||
+ contain a space. Therefore some programs encode spaces in names
|
||||
+ by the strings "\040". We undo the encoding when reading an entry.
|
||||
+ The decoding happens in place. */
|
||||
+static char *
|
||||
+decode_name (char *buf)
|
||||
+{
|
||||
+ char *rp = buf;
|
||||
+ char *wp = buf;
|
||||
+
|
||||
+ do
|
||||
+ if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '4' && rp[3] == '0')
|
||||
+ {
|
||||
+ /* \040 is a SPACE. */
|
||||
+ *wp++ = ' ';
|
||||
+ rp += 3;
|
||||
+ }
|
||||
+ else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' && rp[3] == '1')
|
||||
+ {
|
||||
+ /* \011 is a TAB. */
|
||||
+ *wp++ = '\t';
|
||||
+ rp += 3;
|
||||
+ }
|
||||
+ else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' && rp[3] == '2')
|
||||
+ {
|
||||
+ /* \012 is a NEWLINE. */
|
||||
+ *wp++ = '\n';
|
||||
+ rp += 3;
|
||||
+ }
|
||||
+ else if (rp[0] == '\\' && rp[1] == '\\')
|
||||
+ {
|
||||
+ /* We have to escape \\ to be able to represent all characters. */
|
||||
+ *wp++ = '\\';
|
||||
+ rp += 1;
|
||||
+ }
|
||||
+ else if (rp[0] == '\\' && rp[1] == '1' && rp[2] == '3' && rp[3] == '4')
|
||||
+ {
|
||||
+ /* \134 is also \\. */
|
||||
+ *wp++ = '\\';
|
||||
+ rp += 3;
|
||||
+ }
|
||||
+ else
|
||||
+ *wp++ = *rp;
|
||||
+ while (*rp++ != '\0');
|
||||
+
|
||||
+ return buf;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+/* Read one mount table entry from STREAM. Returns a pointer to storage
|
||||
+ reused on the next call, or null for EOF or error (use feof/ferror to
|
||||
+ check). */
|
||||
+struct mntent *getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)
|
||||
+{
|
||||
+ char *cp;
|
||||
+ char *head;
|
||||
+
|
||||
+ do
|
||||
+ {
|
||||
+ char *end_ptr;
|
||||
+
|
||||
+ if (fgets (buffer, bufsiz, stream) == NULL)
|
||||
+ {
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ end_ptr = strchr (buffer, '\n');
|
||||
+ if (end_ptr != NULL) /* chop newline */
|
||||
+ *end_ptr = '\0';
|
||||
+ else
|
||||
+ {
|
||||
+ /* Not the whole line was read. Do it now but forget it. */
|
||||
+ char tmp[1024];
|
||||
+ while (fgets (tmp, sizeof tmp, stream) != NULL)
|
||||
+ if (strchr (tmp, '\n') != NULL)
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ head = buffer + strspn (buffer, " \t");
|
||||
+ /* skip empty lines and comment lines: */
|
||||
+ }
|
||||
+ while (head[0] == '\0' || head[0] == '#');
|
||||
+
|
||||
+ cp = strsep (&head, " \t");
|
||||
+ mp->mnt_fsname = cp != NULL ? decode_name (cp) : (char *) "";
|
||||
+ if (head)
|
||||
+ head += strspn (head, " \t");
|
||||
+ cp = strsep (&head, " \t");
|
||||
+ mp->mnt_dir = cp != NULL ? decode_name (cp) : (char *) "";
|
||||
+ if (head)
|
||||
+ head += strspn (head, " \t");
|
||||
+ cp = strsep (&head, " \t");
|
||||
+ mp->mnt_type = cp != NULL ? decode_name (cp) : (char *) "";
|
||||
+ if (head)
|
||||
+ head += strspn (head, " \t");
|
||||
+ cp = strsep (&head, " \t");
|
||||
+ mp->mnt_opts = cp != NULL ? decode_name (cp) : (char *) "";
|
||||
+ switch (head ? sscanf (head, " %d %d ", &mp->mnt_freq, &mp->mnt_passno) : 0)
|
||||
+ {
|
||||
+ case 0:
|
||||
+ mp->mnt_freq = 0;
|
||||
+ case 1:
|
||||
+ mp->mnt_passno = 0;
|
||||
+ case 2:
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ return mp;
|
||||
+}
|
||||
+
|
||||
+struct mntent *getmntent (FILE *stream)
|
||||
+{
|
||||
+ static struct mntent m;
|
||||
+ static char *getmntent_buffer;
|
||||
+
|
||||
+ #define BUFFER_SIZE 4096
|
||||
+ if (getmntent_buffer == NULL) {
|
||||
+ getmntent_buffer = (char *) malloc (BUFFER_SIZE);
|
||||
+ }
|
||||
+
|
||||
+ return getmntent_r (stream, &m, getmntent_buffer, BUFFER_SIZE);
|
||||
+ #undef BUFFER_SIZE
|
||||
+}
|
||||
+
|
||||
+
|
||||
+/* We have to use an encoding for names if they contain spaces or tabs.
|
||||
+ To be able to represent all characters we also have to escape the
|
||||
+ backslash itself. This "function" must be a macro since we use
|
||||
+ `alloca'. */
|
||||
+#define encode_name(name) \
|
||||
+ do { \
|
||||
+ const char *rp = name; \
|
||||
+ \
|
||||
+ while (*rp != '\0') \
|
||||
+ if (*rp == ' ' || *rp == '\t' || *rp == '\n' || *rp == '\\') \
|
||||
+ break; \
|
||||
+ else \
|
||||
+ ++rp; \
|
||||
+ \
|
||||
+ if (*rp != '\0') \
|
||||
+ { \
|
||||
+ /* In the worst case the length of the string can increase to \
|
||||
+ four times the current length. */ \
|
||||
+ char *wp; \
|
||||
+ \
|
||||
+ rp = name; \
|
||||
+ name = wp = (char *) alloca (strlen (name) * 4 + 1); \
|
||||
+ \
|
||||
+ do \
|
||||
+ if (*rp == ' ') \
|
||||
+ { \
|
||||
+ *wp++ = '\\'; \
|
||||
+ *wp++ = '0'; \
|
||||
+ *wp++ = '4'; \
|
||||
+ *wp++ = '0'; \
|
||||
+ } \
|
||||
+ else if (*rp == '\t') \
|
||||
+ { \
|
||||
+ *wp++ = '\\'; \
|
||||
+ *wp++ = '0'; \
|
||||
+ *wp++ = '1'; \
|
||||
+ *wp++ = '1'; \
|
||||
+ } \
|
||||
+ else if (*rp == '\n') \
|
||||
+ { \
|
||||
+ *wp++ = '\\'; \
|
||||
+ *wp++ = '0'; \
|
||||
+ *wp++ = '1'; \
|
||||
+ *wp++ = '2'; \
|
||||
+ } \
|
||||
+ else if (*rp == '\\') \
|
||||
+ { \
|
||||
+ *wp++ = '\\'; \
|
||||
+ *wp++ = '\\'; \
|
||||
+ } \
|
||||
+ else \
|
||||
+ *wp++ = *rp; \
|
||||
+ while (*rp++ != '\0'); \
|
||||
+ } \
|
||||
+ } while (0)
|
||||
+
|
||||
+
|
||||
+/* Write the mount table entry described by MNT to STREAM.
|
||||
+ Return zero on success, nonzero on failure. */
|
||||
+int addmntent (FILE *stream, const struct mntent *mnt)
|
||||
+{
|
||||
+ struct mntent mntcopy = *mnt;
|
||||
+ if (fseek (stream, 0, SEEK_END))
|
||||
+ return 1;
|
||||
+
|
||||
+ /* Encode spaces and tabs in the names. */
|
||||
+ encode_name (mntcopy.mnt_fsname);
|
||||
+ encode_name (mntcopy.mnt_dir);
|
||||
+ encode_name (mntcopy.mnt_type);
|
||||
+ encode_name (mntcopy.mnt_opts);
|
||||
+
|
||||
+ return (fprintf (stream, "%s %s %s %s %d %d\n",
|
||||
+ mntcopy.mnt_fsname,
|
||||
+ mntcopy.mnt_dir,
|
||||
+ mntcopy.mnt_type,
|
||||
+ mntcopy.mnt_opts,
|
||||
+ mntcopy.mnt_freq,
|
||||
+ mntcopy.mnt_passno) < 0
|
||||
+ || fflush (stream) != 0);
|
||||
+}
|
||||
+
|
||||
+
|
||||
+/* Search MNT->mnt_opts for an option matching OPT.
|
||||
+ Returns the address of the substring, or null if none found. */
|
||||
+char *hasmntopt (const struct mntent *mnt, const char *opt)
|
||||
+{
|
||||
+ const size_t optlen = strlen (opt);
|
||||
+ char *rest = mnt->mnt_opts, *p;
|
||||
+
|
||||
+ while ((p = strstr (rest, opt)) != NULL)
|
||||
+ {
|
||||
+ if ((p == rest || p[-1] == ',')
|
||||
+ && (p[optlen] == '\0' || p[optlen] == '=' || p[optlen] == ','))
|
||||
+ return p;
|
||||
+
|
||||
+ rest = strchr (p, ',');
|
||||
+ if (rest == NULL)
|
||||
+ break;
|
||||
+ ++rest;
|
||||
+ }
|
||||
+
|
||||
+ return NULL;
|
||||
+}
|
||||
--
|
||||
1.7.10.4
|
||||
|
||||
38
external/dist/busybox-patches/003-b-platform-mntent_r.patch
vendored
Normal file
38
external/dist/busybox-patches/003-b-platform-mntent_r.patch
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Tue, 15 Mar 2016 11:21:17 -0300
|
||||
Subject: [PATCH] Fix mntent patch linking error "multiple definition of `getmntent'"
|
||||
|
||||
---
|
||||
include/platform.h | 1 +
|
||||
libbb/mntent_r.c | 3 ++-
|
||||
2 files changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/include/platform.h b/include/platform.h
|
||||
index 0fb8f7b..0f3a688 100644
|
||||
--- a/include/platform.h
|
||||
+++ b/include/platform.h
|
||||
@@ -481,6 +481,7 @@ typedef unsigned smalluint;
|
||||
#endif
|
||||
|
||||
#if defined(ANDROID) || defined(__ANDROID__)
|
||||
+# define getmntent bb_getmntent
|
||||
# if __ANDROID_API__ < 8
|
||||
# undef HAVE_DPRINTF
|
||||
# else
|
||||
diff --git a/libbb/mntent_r.c b/libbb/mntent_r.c
|
||||
index 1077487..146b917 100644
|
||||
--- a/libbb/mntent_r.c
|
||||
+++ b/libbb/mntent_r.c
|
||||
@@ -168,7 +168,8 @@ struct mntent *getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int b
|
||||
return mp;
|
||||
}
|
||||
|
||||
-struct mntent *getmntent (FILE *stream)
|
||||
+/* override getmntent definition in bionic/stubs.c using platform.h */
|
||||
+struct mntent *bb_getmntent (FILE *stream)
|
||||
{
|
||||
static struct mntent m;
|
||||
static char *getmntent_buffer;
|
||||
--
|
||||
2.7.0
|
||||
|
||||
336
external/dist/busybox-patches/004-telnet-telnetd.patch
vendored
Normal file
336
external/dist/busybox-patches/004-telnet-telnetd.patch
vendored
Normal file
|
|
@ -0,0 +1,336 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Sat, 28 Nov 2015 11:27:28 -0400
|
||||
Subject: [PATCH] telnet/telnetd: add missing header
|
||||
|
||||
Imported from dorimanx's combined ported header toolchain:
|
||||
https://github.com/dorimanx/android-busybox-ndk
|
||||
---
|
||||
include/arpa/telnet.h | 316 ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 316 insertions(+)
|
||||
create mode 100644 include/arpa/telnet.h
|
||||
|
||||
diff --git a/include/arpa/telnet.h b/include/arpa/telnet.h
|
||||
new file mode 100644
|
||||
index 0000000..3774c89
|
||||
--- /dev/null
|
||||
+++ b/include/arpa/telnet.h
|
||||
@@ -0,0 +1,316 @@
|
||||
+/*
|
||||
+ * Copyright (c) 1983, 1993
|
||||
+ * The Regents of the University of California. All rights reserved.
|
||||
+ *
|
||||
+ * Redistribution and use in source and binary forms, with or without
|
||||
+ * modification, are permitted provided that the following conditions
|
||||
+ * are met:
|
||||
+ * 1. Redistributions of source code must retain the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer.
|
||||
+ * 2. Redistributions in binary form must reproduce the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer in the
|
||||
+ * documentation and/or other materials provided with the distribution.
|
||||
+ * 4. Neither the name of the University nor the names of its contributors
|
||||
+ * may be used to endorse or promote products derived from this software
|
||||
+ * without specific prior written permission.
|
||||
+ *
|
||||
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
+ * SUCH DAMAGE.
|
||||
+ *
|
||||
+ * @(#)telnet.h 8.2 (Berkeley) 12/15/93
|
||||
+ */
|
||||
+
|
||||
+#ifndef _ARPA_TELNET_H
|
||||
+#define _ARPA_TELNET_H 1
|
||||
+
|
||||
+/*
|
||||
+ * Definitions for the TELNET protocol.
|
||||
+ */
|
||||
+#define IAC 255 /* interpret as command: */
|
||||
+#define DONT 254 /* you are not to use option */
|
||||
+#define DO 253 /* please, you use option */
|
||||
+#define WONT 252 /* I won't use option */
|
||||
+#define WILL 251 /* I will use option */
|
||||
+#define SB 250 /* interpret as subnegotiation */
|
||||
+#define GA 249 /* you may reverse the line */
|
||||
+#define EL 248 /* erase the current line */
|
||||
+#define EC 247 /* erase the current character */
|
||||
+#define AYT 246 /* are you there */
|
||||
+#define AO 245 /* abort output--but let prog finish */
|
||||
+#define IP 244 /* interrupt process--permanently */
|
||||
+#define BREAK 243 /* break */
|
||||
+#define DM 242 /* data mark--for connect. cleaning */
|
||||
+#define NOP 241 /* nop */
|
||||
+#define SE 240 /* end sub negotiation */
|
||||
+#define EOR 239 /* end of record (transparent mode) */
|
||||
+#define ABORT 238 /* Abort process */
|
||||
+#define SUSP 237 /* Suspend process */
|
||||
+#define xEOF 236 /* End of file: EOF is already used... */
|
||||
+
|
||||
+#define SYNCH 242 /* for telfunc calls */
|
||||
+
|
||||
+#ifdef TELCMDS
|
||||
+char *telcmds[] = {
|
||||
+ "EOF", "SUSP", "ABORT", "EOR",
|
||||
+ "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
|
||||
+ "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0,
|
||||
+};
|
||||
+#else
|
||||
+extern char *telcmds[];
|
||||
+#endif
|
||||
+
|
||||
+#define TELCMD_FIRST xEOF
|
||||
+#define TELCMD_LAST IAC
|
||||
+#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \
|
||||
+ (unsigned int)(x) >= TELCMD_FIRST)
|
||||
+#define TELCMD(x) telcmds[(x)-TELCMD_FIRST]
|
||||
+
|
||||
+/* telnet options */
|
||||
+#define TELOPT_BINARY 0 /* 8-bit data path */
|
||||
+#define TELOPT_ECHO 1 /* echo */
|
||||
+#define TELOPT_RCP 2 /* prepare to reconnect */
|
||||
+#define TELOPT_SGA 3 /* suppress go ahead */
|
||||
+#define TELOPT_NAMS 4 /* approximate message size */
|
||||
+#define TELOPT_STATUS 5 /* give status */
|
||||
+#define TELOPT_TM 6 /* timing mark */
|
||||
+#define TELOPT_RCTE 7 /* remote controlled transmission and echo */
|
||||
+#define TELOPT_NAOL 8 /* negotiate about output line width */
|
||||
+#define TELOPT_NAOP 9 /* negotiate about output page size */
|
||||
+#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */
|
||||
+#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */
|
||||
+#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */
|
||||
+#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */
|
||||
+#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */
|
||||
+#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */
|
||||
+#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */
|
||||
+#define TELOPT_XASCII 17 /* extended ascii character set */
|
||||
+#define TELOPT_LOGOUT 18 /* force logout */
|
||||
+#define TELOPT_BM 19 /* byte macro */
|
||||
+#define TELOPT_DET 20 /* data entry terminal */
|
||||
+#define TELOPT_SUPDUP 21 /* supdup protocol */
|
||||
+#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */
|
||||
+#define TELOPT_SNDLOC 23 /* send location */
|
||||
+#define TELOPT_TTYPE 24 /* terminal type */
|
||||
+#define TELOPT_EOR 25 /* end or record */
|
||||
+#define TELOPT_TUID 26 /* TACACS user identification */
|
||||
+#define TELOPT_OUTMRK 27 /* output marking */
|
||||
+#define TELOPT_TTYLOC 28 /* terminal location number */
|
||||
+#define TELOPT_3270REGIME 29 /* 3270 regime */
|
||||
+#define TELOPT_X3PAD 30 /* X.3 PAD */
|
||||
+#define TELOPT_NAWS 31 /* window size */
|
||||
+#define TELOPT_TSPEED 32 /* terminal speed */
|
||||
+#define TELOPT_LFLOW 33 /* remote flow control */
|
||||
+#define TELOPT_LINEMODE 34 /* Linemode option */
|
||||
+#define TELOPT_XDISPLOC 35 /* X Display Location */
|
||||
+#define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */
|
||||
+#define TELOPT_AUTHENTICATION 37/* Authenticate */
|
||||
+#define TELOPT_ENCRYPT 38 /* Encryption option */
|
||||
+#define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */
|
||||
+#define TELOPT_EXOPL 255 /* extended-options-list */
|
||||
+
|
||||
+
|
||||
+#define NTELOPTS (1+TELOPT_NEW_ENVIRON)
|
||||
+#ifdef TELOPTS
|
||||
+char *telopts[NTELOPTS+1] = {
|
||||
+ "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
|
||||
+ "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
|
||||
+ "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
|
||||
+ "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
|
||||
+ "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
|
||||
+ "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
|
||||
+ "TACACS UID", "OUTPUT MARKING", "TTYLOC",
|
||||
+ "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
|
||||
+ "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
|
||||
+ "ENCRYPT", "NEW-ENVIRON",
|
||||
+ 0,
|
||||
+};
|
||||
+#define TELOPT_FIRST TELOPT_BINARY
|
||||
+#define TELOPT_LAST TELOPT_NEW_ENVIRON
|
||||
+#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST)
|
||||
+#define TELOPT(x) telopts[(x)-TELOPT_FIRST]
|
||||
+#endif
|
||||
+
|
||||
+/* sub-option qualifiers */
|
||||
+#define TELQUAL_IS 0 /* option is... */
|
||||
+#define TELQUAL_SEND 1 /* send option */
|
||||
+#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */
|
||||
+#define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */
|
||||
+#define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */
|
||||
+
|
||||
+#define LFLOW_OFF 0 /* Disable remote flow control */
|
||||
+#define LFLOW_ON 1 /* Enable remote flow control */
|
||||
+#define LFLOW_RESTART_ANY 2 /* Restart output on any char */
|
||||
+#define LFLOW_RESTART_XON 3 /* Restart output only on XON */
|
||||
+
|
||||
+/*
|
||||
+ * LINEMODE suboptions
|
||||
+ */
|
||||
+
|
||||
+#define LM_MODE 1
|
||||
+#define LM_FORWARDMASK 2
|
||||
+#define LM_SLC 3
|
||||
+
|
||||
+#define MODE_EDIT 0x01
|
||||
+#define MODE_TRAPSIG 0x02
|
||||
+#define MODE_ACK 0x04
|
||||
+#define MODE_SOFT_TAB 0x08
|
||||
+#define MODE_LIT_ECHO 0x10
|
||||
+
|
||||
+#define MODE_MASK 0x1f
|
||||
+
|
||||
+/* Not part of protocol, but needed to simplify things... */
|
||||
+#define MODE_FLOW 0x0100
|
||||
+#define MODE_ECHO 0x0200
|
||||
+#define MODE_INBIN 0x0400
|
||||
+#define MODE_OUTBIN 0x0800
|
||||
+#define MODE_FORCE 0x1000
|
||||
+
|
||||
+#define SLC_SYNCH 1
|
||||
+#define SLC_BRK 2
|
||||
+#define SLC_IP 3
|
||||
+#define SLC_AO 4
|
||||
+#define SLC_AYT 5
|
||||
+#define SLC_EOR 6
|
||||
+#define SLC_ABORT 7
|
||||
+#define SLC_EOF 8
|
||||
+#define SLC_SUSP 9
|
||||
+#define SLC_EC 10
|
||||
+#define SLC_EL 11
|
||||
+#define SLC_EW 12
|
||||
+#define SLC_RP 13
|
||||
+#define SLC_LNEXT 14
|
||||
+#define SLC_XON 15
|
||||
+#define SLC_XOFF 16
|
||||
+#define SLC_FORW1 17
|
||||
+#define SLC_FORW2 18
|
||||
+
|
||||
+#define NSLC 18
|
||||
+
|
||||
+/*
|
||||
+ * For backwards compatibility, we define SLC_NAMES to be the
|
||||
+ * list of names if SLC_NAMES is not defined.
|
||||
+ */
|
||||
+#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \
|
||||
+ "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \
|
||||
+ "LNEXT", "XON", "XOFF", "FORW1", "FORW2", 0,
|
||||
+#ifdef SLC_NAMES
|
||||
+char *slc_names[] = {
|
||||
+ SLC_NAMELIST
|
||||
+};
|
||||
+#else
|
||||
+extern char *slc_names[];
|
||||
+#define SLC_NAMES SLC_NAMELIST
|
||||
+#endif
|
||||
+
|
||||
+#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC)
|
||||
+#define SLC_NAME(x) slc_names[x]
|
||||
+
|
||||
+#define SLC_NOSUPPORT 0
|
||||
+#define SLC_CANTCHANGE 1
|
||||
+#define SLC_VARIABLE 2
|
||||
+#define SLC_DEFAULT 3
|
||||
+#define SLC_LEVELBITS 0x03
|
||||
+
|
||||
+#define SLC_FUNC 0
|
||||
+#define SLC_FLAGS 1
|
||||
+#define SLC_VALUE 2
|
||||
+
|
||||
+#define SLC_ACK 0x80
|
||||
+#define SLC_FLUSHIN 0x40
|
||||
+#define SLC_FLUSHOUT 0x20
|
||||
+
|
||||
+#define OLD_ENV_VAR 1
|
||||
+#define OLD_ENV_VALUE 0
|
||||
+#define NEW_ENV_VAR 0
|
||||
+#define NEW_ENV_VALUE 1
|
||||
+#define ENV_ESC 2
|
||||
+#define ENV_USERVAR 3
|
||||
+
|
||||
+/*
|
||||
+ * AUTHENTICATION suboptions
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * Who is authenticating who ...
|
||||
+ */
|
||||
+#define AUTH_WHO_CLIENT 0 /* Client authenticating server */
|
||||
+#define AUTH_WHO_SERVER 1 /* Server authenticating client */
|
||||
+#define AUTH_WHO_MASK 1
|
||||
+
|
||||
+/*
|
||||
+ * amount of authentication done
|
||||
+ */
|
||||
+#define AUTH_HOW_ONE_WAY 0
|
||||
+#define AUTH_HOW_MUTUAL 2
|
||||
+#define AUTH_HOW_MASK 2
|
||||
+
|
||||
+#define AUTHTYPE_NULL 0
|
||||
+#define AUTHTYPE_KERBEROS_V4 1
|
||||
+#define AUTHTYPE_KERBEROS_V5 2
|
||||
+#define AUTHTYPE_SPX 3
|
||||
+#define AUTHTYPE_MINK 4
|
||||
+#define AUTHTYPE_CNT 5
|
||||
+
|
||||
+#define AUTHTYPE_TEST 99
|
||||
+
|
||||
+#ifdef AUTH_NAMES
|
||||
+char *authtype_names[] = {
|
||||
+ "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0,
|
||||
+};
|
||||
+#else
|
||||
+extern char *authtype_names[];
|
||||
+#endif
|
||||
+
|
||||
+#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT)
|
||||
+#define AUTHTYPE_NAME(x) authtype_names[x]
|
||||
+
|
||||
+/*
|
||||
+ * ENCRYPTion suboptions
|
||||
+ */
|
||||
+#define ENCRYPT_IS 0 /* I pick encryption type ... */
|
||||
+#define ENCRYPT_SUPPORT 1 /* I support encryption types ... */
|
||||
+#define ENCRYPT_REPLY 2 /* Initial setup response */
|
||||
+#define ENCRYPT_START 3 /* Am starting to send encrypted */
|
||||
+#define ENCRYPT_END 4 /* Am ending encrypted */
|
||||
+#define ENCRYPT_REQSTART 5 /* Request you start encrypting */
|
||||
+#define ENCRYPT_REQEND 6 /* Request you send encrypting */
|
||||
+#define ENCRYPT_ENC_KEYID 7
|
||||
+#define ENCRYPT_DEC_KEYID 8
|
||||
+#define ENCRYPT_CNT 9
|
||||
+
|
||||
+#define ENCTYPE_ANY 0
|
||||
+#define ENCTYPE_DES_CFB64 1
|
||||
+#define ENCTYPE_DES_OFB64 2
|
||||
+#define ENCTYPE_CNT 3
|
||||
+
|
||||
+#ifdef ENCRYPT_NAMES
|
||||
+char *encrypt_names[] = {
|
||||
+ "IS", "SUPPORT", "REPLY", "START", "END",
|
||||
+ "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID",
|
||||
+ 0,
|
||||
+};
|
||||
+char *enctype_names[] = {
|
||||
+ "ANY", "DES_CFB64", "DES_OFB64", 0,
|
||||
+};
|
||||
+#else
|
||||
+extern char *encrypt_names[];
|
||||
+extern char *enctype_names[];
|
||||
+#endif
|
||||
+
|
||||
+
|
||||
+#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT)
|
||||
+#define ENCRYPT_NAME(x) encrypt_names[x]
|
||||
+
|
||||
+#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT)
|
||||
+#define ENCTYPE_NAME(x) enctype_names[x]
|
||||
+
|
||||
+#endif /* arpa/telnet.h */
|
||||
--
|
||||
2.5.3
|
||||
|
||||
127
external/dist/busybox-patches/005-rfkill.patch
vendored
Normal file
127
external/dist/busybox-patches/005-rfkill.patch
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Sat, 28 Nov 2015 11:45:26 -0400
|
||||
Subject: [PATCH] rfkill: add missing header
|
||||
|
||||
Imported from dorimanx's combined ported header toolchain:
|
||||
https://github.com/dorimanx/android-busybox-ndk
|
||||
---
|
||||
include/linux/rfkill.h | 107 +++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 107 insertions(+)
|
||||
create mode 100644 include/linux/rfkill.h
|
||||
|
||||
diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
|
||||
new file mode 100644
|
||||
index 0000000..abb2c66
|
||||
--- /dev/null
|
||||
+++ b/include/linux/rfkill.h
|
||||
@@ -0,0 +1,107 @@
|
||||
+#ifndef __RFKILL_H
|
||||
+#define __RFKILL_H
|
||||
+
|
||||
+/*
|
||||
+ * Copyright (C) 2006 - 2007 Ivo van Doorn
|
||||
+ * Copyright (C) 2007 Dmitry Torokhov
|
||||
+ * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
|
||||
+ *
|
||||
+ * Permission to use, copy, modify, and/or distribute this software for any
|
||||
+ * purpose with or without fee is hereby granted, provided that the above
|
||||
+ * copyright notice and this permission notice appear in all copies.
|
||||
+ *
|
||||
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
+ */
|
||||
+
|
||||
+#include <linux/types.h>
|
||||
+
|
||||
+/* define userspace visible states */
|
||||
+#define RFKILL_STATE_SOFT_BLOCKED 0
|
||||
+#define RFKILL_STATE_UNBLOCKED 1
|
||||
+#define RFKILL_STATE_HARD_BLOCKED 2
|
||||
+
|
||||
+/**
|
||||
+ * enum rfkill_type - type of rfkill switch.
|
||||
+ *
|
||||
+ * @RFKILL_TYPE_ALL: toggles all switches (requests only - not a switch type)
|
||||
+ * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
|
||||
+ * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
|
||||
+ * @RFKILL_TYPE_UWB: switch is on a ultra wideband device.
|
||||
+ * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
|
||||
+ * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
|
||||
+ * @RFKILL_TYPE_GPS: switch is on a GPS device.
|
||||
+ * @RFKILL_TYPE_FM: switch is on a FM radio device.
|
||||
+ * @NUM_RFKILL_TYPES: number of defined rfkill types
|
||||
+ */
|
||||
+enum rfkill_type {
|
||||
+ RFKILL_TYPE_ALL = 0,
|
||||
+ RFKILL_TYPE_WLAN,
|
||||
+ RFKILL_TYPE_BLUETOOTH,
|
||||
+ RFKILL_TYPE_UWB,
|
||||
+ RFKILL_TYPE_WIMAX,
|
||||
+ RFKILL_TYPE_WWAN,
|
||||
+ RFKILL_TYPE_GPS,
|
||||
+ RFKILL_TYPE_FM,
|
||||
+ NUM_RFKILL_TYPES,
|
||||
+};
|
||||
+
|
||||
+/**
|
||||
+ * enum rfkill_operation - operation types
|
||||
+ * @RFKILL_OP_ADD: a device was added
|
||||
+ * @RFKILL_OP_DEL: a device was removed
|
||||
+ * @RFKILL_OP_CHANGE: a device's state changed -- userspace changes one device
|
||||
+ * @RFKILL_OP_CHANGE_ALL: userspace changes all devices (of a type, or all)
|
||||
+ */
|
||||
+enum rfkill_operation {
|
||||
+ RFKILL_OP_ADD = 0,
|
||||
+ RFKILL_OP_DEL,
|
||||
+ RFKILL_OP_CHANGE,
|
||||
+ RFKILL_OP_CHANGE_ALL,
|
||||
+};
|
||||
+
|
||||
+/**
|
||||
+ * struct rfkill_event - events for userspace on /dev/rfkill
|
||||
+ * @idx: index of dev rfkill
|
||||
+ * @type: type of the rfkill struct
|
||||
+ * @op: operation code
|
||||
+ * @hard: hard state (0/1)
|
||||
+ * @soft: soft state (0/1)
|
||||
+ *
|
||||
+ * Structure used for userspace communication on /dev/rfkill,
|
||||
+ * used for events from the kernel and control to the kernel.
|
||||
+ */
|
||||
+struct rfkill_event {
|
||||
+ __u32 idx;
|
||||
+ __u8 type;
|
||||
+ __u8 op;
|
||||
+ __u8 soft, hard;
|
||||
+} __attribute__((packed));
|
||||
+
|
||||
+/*
|
||||
+ * We are planning to be backward and forward compatible with changes
|
||||
+ * to the event struct, by adding new, optional, members at the end.
|
||||
+ * When reading an event (whether the kernel from userspace or vice
|
||||
+ * versa) we need to accept anything that's at least as large as the
|
||||
+ * version 1 event size, but might be able to accept other sizes in
|
||||
+ * the future.
|
||||
+ *
|
||||
+ * One exception is the kernel -- we already have two event sizes in
|
||||
+ * that we've made the 'hard' member optional since our only option
|
||||
+ * is to ignore it anyway.
|
||||
+ */
|
||||
+#define RFKILL_EVENT_SIZE_V1 8
|
||||
+
|
||||
+/* ioctl for turning off rfkill-input (if present) */
|
||||
+#define RFKILL_IOC_MAGIC 'R'
|
||||
+#define RFKILL_IOC_NOINPUT 1
|
||||
+#define RFKILL_IOCTL_NOINPUT _IO(RFKILL_IOC_MAGIC, RFKILL_IOC_NOINPUT)
|
||||
+
|
||||
+/* and that's all userspace gets */
|
||||
+
|
||||
+#endif /* RFKILL_H */
|
||||
--
|
||||
2.5.3
|
||||
|
||||
529
external/dist/busybox-patches/006-eject.patch
vendored
Normal file
529
external/dist/busybox-patches/006-eject.patch
vendored
Normal file
|
|
@ -0,0 +1,529 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Thu, 3 Dec 2015 17:01:57 -0400
|
||||
Subject: [PATCH] eject: add missing headers
|
||||
|
||||
Imported from dorimanx's combined ported header toolchain:
|
||||
https://github.com/dorimanx/android-busybox-ndk
|
||||
---
|
||||
include/scsi/scsi.h | 225 ++++++++++++++++++++++++++++++++++++++++++
|
||||
include/scsi/sg.h | 276 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 501 insertions(+)
|
||||
create mode 100644 include/scsi/scsi.h
|
||||
create mode 100644 include/scsi/sg.h
|
||||
|
||||
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
|
||||
new file mode 100644
|
||||
index 0000000..06377ab
|
||||
--- /dev/null
|
||||
+++ b/include/scsi/scsi.h
|
||||
@@ -0,0 +1,225 @@
|
||||
+/* Copyright (C) 1998-2015 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, see
|
||||
+ <http://www.gnu.org/licenses/>. */
|
||||
+
|
||||
+/*
|
||||
+ * This header file contains public constants and structures used by
|
||||
+ * the scsi code for linux.
|
||||
+ */
|
||||
+
|
||||
+#ifndef _SCSI_SCSI_H
|
||||
+#define _SCSI_SCSI_H 1
|
||||
+
|
||||
+#include <features.h>
|
||||
+
|
||||
+/*
|
||||
+ * SCSI opcodes
|
||||
+ */
|
||||
+
|
||||
+#define TEST_UNIT_READY 0x00
|
||||
+#define REZERO_UNIT 0x01
|
||||
+#define REQUEST_SENSE 0x03
|
||||
+#define FORMAT_UNIT 0x04
|
||||
+#define READ_BLOCK_LIMITS 0x05
|
||||
+#define REASSIGN_BLOCKS 0x07
|
||||
+#define READ_6 0x08
|
||||
+#define WRITE_6 0x0a
|
||||
+#define SEEK_6 0x0b
|
||||
+#define READ_REVERSE 0x0f
|
||||
+#define WRITE_FILEMARKS 0x10
|
||||
+#define SPACE 0x11
|
||||
+#define INQUIRY 0x12
|
||||
+#define RECOVER_BUFFERED_DATA 0x14
|
||||
+#define MODE_SELECT 0x15
|
||||
+#define RESERVE 0x16
|
||||
+#define RELEASE 0x17
|
||||
+#define COPY 0x18
|
||||
+#define ERASE 0x19
|
||||
+#define MODE_SENSE 0x1a
|
||||
+#define START_STOP 0x1b
|
||||
+#define RECEIVE_DIAGNOSTIC 0x1c
|
||||
+#define SEND_DIAGNOSTIC 0x1d
|
||||
+#define ALLOW_MEDIUM_REMOVAL 0x1e
|
||||
+
|
||||
+#define SET_WINDOW 0x24
|
||||
+#define READ_CAPACITY 0x25
|
||||
+#define READ_10 0x28
|
||||
+#define WRITE_10 0x2a
|
||||
+#define SEEK_10 0x2b
|
||||
+#define WRITE_VERIFY 0x2e
|
||||
+#define VERIFY 0x2f
|
||||
+#define SEARCH_HIGH 0x30
|
||||
+#define SEARCH_EQUAL 0x31
|
||||
+#define SEARCH_LOW 0x32
|
||||
+#define SET_LIMITS 0x33
|
||||
+#define PRE_FETCH 0x34
|
||||
+#define READ_POSITION 0x34
|
||||
+#define SYNCHRONIZE_CACHE 0x35
|
||||
+#define LOCK_UNLOCK_CACHE 0x36
|
||||
+#define READ_DEFECT_DATA 0x37
|
||||
+#define MEDIUM_SCAN 0x38
|
||||
+#define COMPARE 0x39
|
||||
+#define COPY_VERIFY 0x3a
|
||||
+#define WRITE_BUFFER 0x3b
|
||||
+#define READ_BUFFER 0x3c
|
||||
+#define UPDATE_BLOCK 0x3d
|
||||
+#define READ_LONG 0x3e
|
||||
+#define WRITE_LONG 0x3f
|
||||
+#define CHANGE_DEFINITION 0x40
|
||||
+#define WRITE_SAME 0x41
|
||||
+#define READ_TOC 0x43
|
||||
+#define LOG_SELECT 0x4c
|
||||
+#define LOG_SENSE 0x4d
|
||||
+#define MODE_SELECT_10 0x55
|
||||
+#define RESERVE_10 0x56
|
||||
+#define RELEASE_10 0x57
|
||||
+#define MODE_SENSE_10 0x5a
|
||||
+#define PERSISTENT_RESERVE_IN 0x5e
|
||||
+#define PERSISTENT_RESERVE_OUT 0x5f
|
||||
+#define MOVE_MEDIUM 0xa5
|
||||
+#define READ_12 0xa8
|
||||
+#define WRITE_12 0xaa
|
||||
+#define WRITE_VERIFY_12 0xae
|
||||
+#define SEARCH_HIGH_12 0xb0
|
||||
+#define SEARCH_EQUAL_12 0xb1
|
||||
+#define SEARCH_LOW_12 0xb2
|
||||
+#define READ_ELEMENT_STATUS 0xb8
|
||||
+#define SEND_VOLUME_TAG 0xb6
|
||||
+#define WRITE_LONG_2 0xea
|
||||
+
|
||||
+/*
|
||||
+ * Status codes
|
||||
+ */
|
||||
+
|
||||
+#define GOOD 0x00
|
||||
+#define CHECK_CONDITION 0x01
|
||||
+#define CONDITION_GOOD 0x02
|
||||
+#define BUSY 0x04
|
||||
+#define INTERMEDIATE_GOOD 0x08
|
||||
+#define INTERMEDIATE_C_GOOD 0x0a
|
||||
+#define RESERVATION_CONFLICT 0x0c
|
||||
+#define COMMAND_TERMINATED 0x11
|
||||
+#define QUEUE_FULL 0x14
|
||||
+
|
||||
+#define STATUS_MASK 0x3e
|
||||
+
|
||||
+/*
|
||||
+ * SENSE KEYS
|
||||
+ */
|
||||
+
|
||||
+#define NO_SENSE 0x00
|
||||
+#define RECOVERED_ERROR 0x01
|
||||
+#define NOT_READY 0x02
|
||||
+#define MEDIUM_ERROR 0x03
|
||||
+#define HARDWARE_ERROR 0x04
|
||||
+#define ILLEGAL_REQUEST 0x05
|
||||
+#define UNIT_ATTENTION 0x06
|
||||
+#define DATA_PROTECT 0x07
|
||||
+#define BLANK_CHECK 0x08
|
||||
+#define COPY_ABORTED 0x0a
|
||||
+#define ABORTED_COMMAND 0x0b
|
||||
+#define VOLUME_OVERFLOW 0x0d
|
||||
+#define MISCOMPARE 0x0e
|
||||
+
|
||||
+
|
||||
+/*
|
||||
+ * DEVICE TYPES
|
||||
+ */
|
||||
+
|
||||
+#define TYPE_DISK 0x00
|
||||
+#define TYPE_TAPE 0x01
|
||||
+#define TYPE_PROCESSOR 0x03 /* HP scanners use this */
|
||||
+#define TYPE_WORM 0x04 /* Treated as ROM by our system */
|
||||
+#define TYPE_ROM 0x05
|
||||
+#define TYPE_SCANNER 0x06
|
||||
+#define TYPE_MOD 0x07 /* Magneto-optical disk -
|
||||
+ * - treated as TYPE_DISK */
|
||||
+#define TYPE_MEDIUM_CHANGER 0x08
|
||||
+#define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
|
||||
+#define TYPE_NO_LUN 0x7f
|
||||
+
|
||||
+/*
|
||||
+ * standard mode-select header prepended to all mode-select commands
|
||||
+ *
|
||||
+ * moved here from cdrom.h -- kraxel
|
||||
+ */
|
||||
+
|
||||
+struct ccs_modesel_head
|
||||
+ {
|
||||
+ unsigned char _r1; /* reserved. */
|
||||
+ unsigned char medium; /* device-specific medium type. */
|
||||
+ unsigned char _r2; /* reserved. */
|
||||
+ unsigned char block_desc_length; /* block descriptor length. */
|
||||
+ unsigned char density; /* device-specific density code. */
|
||||
+ unsigned char number_blocks_hi; /* number of blocks in this block
|
||||
+ desc. */
|
||||
+ unsigned char number_blocks_med;
|
||||
+ unsigned char number_blocks_lo;
|
||||
+ unsigned char _r3;
|
||||
+ unsigned char block_length_hi; /* block length for blocks in this
|
||||
+ desc. */
|
||||
+ unsigned char block_length_med;
|
||||
+ unsigned char block_length_lo;
|
||||
+ };
|
||||
+
|
||||
+/*
|
||||
+ * MESSAGE CODES
|
||||
+ */
|
||||
+
|
||||
+#define COMMAND_COMPLETE 0x00
|
||||
+#define EXTENDED_MESSAGE 0x01
|
||||
+#define EXTENDED_MODIFY_DATA_POINTER 0x00
|
||||
+#define EXTENDED_SDTR 0x01
|
||||
+#define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */
|
||||
+#define EXTENDED_WDTR 0x03
|
||||
+#define SAVE_POINTERS 0x02
|
||||
+#define RESTORE_POINTERS 0x03
|
||||
+#define DISCONNECT 0x04
|
||||
+#define INITIATOR_ERROR 0x05
|
||||
+#define ABORT 0x06
|
||||
+#define MESSAGE_REJECT 0x07
|
||||
+#define NOP 0x08
|
||||
+#define MSG_PARITY_ERROR 0x09
|
||||
+#define LINKED_CMD_COMPLETE 0x0a
|
||||
+#define LINKED_FLG_CMD_COMPLETE 0x0b
|
||||
+#define BUS_DEVICE_RESET 0x0c
|
||||
+
|
||||
+#define INITIATE_RECOVERY 0x0f /* SCSI-II only */
|
||||
+#define RELEASE_RECOVERY 0x10 /* SCSI-II only */
|
||||
+
|
||||
+#define SIMPLE_QUEUE_TAG 0x20
|
||||
+#define HEAD_OF_QUEUE_TAG 0x21
|
||||
+#define ORDERED_QUEUE_TAG 0x22
|
||||
+
|
||||
+/*
|
||||
+ * Here are some scsi specific ioctl commands which are sometimes useful.
|
||||
+ */
|
||||
+/* These are a few other constants only used by scsi devices. */
|
||||
+
|
||||
+#define SCSI_IOCTL_GET_IDLUN 0x5382
|
||||
+
|
||||
+/* Used to turn on and off tagged queuing for scsi devices. */
|
||||
+
|
||||
+#define SCSI_IOCTL_TAGGED_ENABLE 0x5383
|
||||
+#define SCSI_IOCTL_TAGGED_DISABLE 0x5384
|
||||
+
|
||||
+/* Used to obtain the host number of a device. */
|
||||
+#define SCSI_IOCTL_PROBE_HOST 0x5385
|
||||
+
|
||||
+/* Used to get the bus number for a device. */
|
||||
+#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
|
||||
+
|
||||
+#endif /* scsi/scsi.h */
|
||||
diff --git a/include/scsi/sg.h b/include/scsi/sg.h
|
||||
new file mode 100644
|
||||
index 0000000..7679452
|
||||
--- /dev/null
|
||||
+++ b/include/scsi/sg.h
|
||||
@@ -0,0 +1,276 @@
|
||||
+/* Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, see
|
||||
+ <http://www.gnu.org/licenses/>. */
|
||||
+
|
||||
+/*
|
||||
+ History:
|
||||
+ Started: Aug 9 by Lawrence Foard (entropy@world.std.com), to allow user
|
||||
+ process control of SCSI devices.
|
||||
+ Development Sponsored by Killy Corp. NY NY
|
||||
+*/
|
||||
+
|
||||
+#ifndef _SCSI_SG_H
|
||||
+#define _SCSI_SG_H 1
|
||||
+
|
||||
+#include <features.h>
|
||||
+#define __need_size_t
|
||||
+#include <stddef.h>
|
||||
+
|
||||
+
|
||||
+/* New interface introduced in the 3.x SG drivers follows */
|
||||
+
|
||||
+/* Same structure as used by readv() Linux system call. It defines one
|
||||
+ scatter-gather element. */
|
||||
+typedef struct sg_iovec
|
||||
+{
|
||||
+ void * iov_base; /* Starting address */
|
||||
+ size_t iov_len; /* Length in bytes */
|
||||
+} sg_iovec_t;
|
||||
+
|
||||
+
|
||||
+typedef struct sg_io_hdr
|
||||
+{
|
||||
+ int interface_id; /* [i] 'S' for SCSI generic (required) */
|
||||
+ int dxfer_direction; /* [i] data transfer direction */
|
||||
+ unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
|
||||
+ unsigned char mx_sb_len; /* [i] max length to write to sbp */
|
||||
+ unsigned short int iovec_count; /* [i] 0 implies no scatter gather */
|
||||
+ unsigned int dxfer_len; /* [i] byte count of data transfer */
|
||||
+ void * dxferp; /* [i], [*io] points to data transfer memory
|
||||
+ or scatter gather list */
|
||||
+ unsigned char * cmdp; /* [i], [*i] points to command to perform */
|
||||
+ unsigned char * sbp; /* [i], [*o] points to sense_buffer memory */
|
||||
+ unsigned int timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
|
||||
+ unsigned int flags; /* [i] 0 -> default, see SG_FLAG... */
|
||||
+ int pack_id; /* [i->o] unused internally (normally) */
|
||||
+ void * usr_ptr; /* [i->o] unused internally */
|
||||
+ unsigned char status; /* [o] scsi status */
|
||||
+ unsigned char masked_status;/* [o] shifted, masked scsi status */
|
||||
+ unsigned char msg_status; /* [o] messaging level data (optional) */
|
||||
+ unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
|
||||
+ unsigned short int host_status; /* [o] errors from host adapter */
|
||||
+ unsigned short int driver_status;/* [o] errors from software driver */
|
||||
+ int resid; /* [o] dxfer_len - actual_transferred */
|
||||
+ unsigned int duration; /* [o] time taken by cmd (unit: millisec) */
|
||||
+ unsigned int info; /* [o] auxiliary information */
|
||||
+} sg_io_hdr_t;
|
||||
+
|
||||
+
|
||||
+/* Use negative values to flag difference from original sg_header structure. */
|
||||
+#define SG_DXFER_NONE -1 /* e.g. a SCSI Test Unit Ready command */
|
||||
+#define SG_DXFER_TO_DEV -2 /* e.g. a SCSI WRITE command */
|
||||
+#define SG_DXFER_FROM_DEV -3 /* e.g. a SCSI READ command */
|
||||
+#define SG_DXFER_TO_FROM_DEV -4 /* treated like SG_DXFER_FROM_DEV with the
|
||||
+ additional property than during indirect
|
||||
+ IO the user buffer is copied into the
|
||||
+ kernel buffers before the transfer */
|
||||
+
|
||||
+
|
||||
+/* following flag values can be "or"-ed together */
|
||||
+#define SG_FLAG_DIRECT_IO 1 /* default is indirect IO */
|
||||
+#define SG_FLAG_LUN_INHIBIT 2 /* default is to put device's lun into */
|
||||
+ /* the 2nd byte of SCSI command */
|
||||
+#define SG_FLAG_NO_DXFER 0x10000 /* no transfer of kernel buffers to/from */
|
||||
+ /* user space (debug indirect IO) */
|
||||
+
|
||||
+/* The following 'info' values are "or"-ed together. */
|
||||
+#define SG_INFO_OK_MASK 0x1
|
||||
+#define SG_INFO_OK 0x0 /* no sense, host nor driver "noise" */
|
||||
+#define SG_INFO_CHECK 0x1 /* something abnormal happened */
|
||||
+
|
||||
+#define SG_INFO_DIRECT_IO_MASK 0x6
|
||||
+#define SG_INFO_INDIRECT_IO 0x0 /* data xfer via kernel buffers (or no xfer) */
|
||||
+#define SG_INFO_DIRECT_IO 0x2 /* direct IO requested and performed */
|
||||
+#define SG_INFO_MIXED_IO 0x4 /* part direct, part indirect IO */
|
||||
+
|
||||
+
|
||||
+/* Request information about a specific SG device, used by
|
||||
+ SG_GET_SCSI_ID ioctl (). */
|
||||
+struct sg_scsi_id {
|
||||
+ /* Host number as in "scsi<n>" where 'n' is one of 0, 1, 2 etc. */
|
||||
+ int host_no;
|
||||
+ int channel;
|
||||
+ /* SCSI id of target device. */
|
||||
+ int scsi_id;
|
||||
+ int lun;
|
||||
+ /* TYPE_... defined in <scsi/scsi.h>. */
|
||||
+ int scsi_type;
|
||||
+ /* Host (adapter) maximum commands per lun. */
|
||||
+ short int h_cmd_per_lun;
|
||||
+ /* Device (or adapter) maximum queue length. */
|
||||
+ short int d_queue_depth;
|
||||
+ /* Unused, set to 0 for now. */
|
||||
+ int unused[2];
|
||||
+};
|
||||
+
|
||||
+/* Used by SG_GET_REQUEST_TABLE ioctl(). */
|
||||
+typedef struct sg_req_info {
|
||||
+ char req_state; /* 0 -> not used, 1 -> written, 2 -> ready to read */
|
||||
+ char orphan; /* 0 -> normal request, 1 -> from interruped SG_IO */
|
||||
+ char sg_io_owned; /* 0 -> complete with read(), 1 -> owned by SG_IO */
|
||||
+ char problem; /* 0 -> no problem detected, 1 -> error to report */
|
||||
+ int pack_id; /* pack_id associated with request */
|
||||
+ void * usr_ptr; /* user provided pointer (in new interface) */
|
||||
+ unsigned int duration; /* millisecs elapsed since written (req_state==1)
|
||||
+ or request duration (req_state==2) */
|
||||
+ int unused;
|
||||
+} sg_req_info_t;
|
||||
+
|
||||
+
|
||||
+/* IOCTLs: Those ioctls that are relevant to the SG 3.x drivers follow.
|
||||
+ [Those that only apply to the SG 2.x drivers are at the end of the file.]
|
||||
+ (_GET_s yield result via 'int *' 3rd argument unless otherwise indicated) */
|
||||
+
|
||||
+#define SG_EMULATED_HOST 0x2203 /* true for emulated host adapter (ATAPI) */
|
||||
+
|
||||
+/* Used to configure SCSI command transformation layer for ATAPI devices */
|
||||
+/* Only supported by the ide-scsi driver */
|
||||
+#define SG_SET_TRANSFORM 0x2204 /* N.B. 3rd arg is not pointer but value: */
|
||||
+ /* 3rd arg = 0 to disable transform, 1 to enable it */
|
||||
+#define SG_GET_TRANSFORM 0x2205
|
||||
+
|
||||
+#define SG_SET_RESERVED_SIZE 0x2275 /* request a new reserved buffer size */
|
||||
+#define SG_GET_RESERVED_SIZE 0x2272 /* actual size of reserved buffer */
|
||||
+
|
||||
+/* The following ioctl has a 'sg_scsi_id_t *' object as its 3rd argument. */
|
||||
+#define SG_GET_SCSI_ID 0x2276 /* Yields fd's bus, chan, dev, lun + type */
|
||||
+/* SCSI id information can also be obtained from SCSI_IOCTL_GET_IDLUN */
|
||||
+
|
||||
+/* Override host setting and always DMA using low memory ( <16MB on i386) */
|
||||
+#define SG_SET_FORCE_LOW_DMA 0x2279 /* 0-> use adapter setting, 1-> force */
|
||||
+#define SG_GET_LOW_DMA 0x227a /* 0-> use all ram for dma; 1-> low dma ram */
|
||||
+
|
||||
+/* When SG_SET_FORCE_PACK_ID set to 1, pack_id is input to read() which
|
||||
+ tries to fetch a packet with a matching pack_id, waits, or returns EAGAIN.
|
||||
+ If pack_id is -1 then read oldest waiting. When ...FORCE_PACK_ID set to 0
|
||||
+ then pack_id ignored by read() and oldest readable fetched. */
|
||||
+#define SG_SET_FORCE_PACK_ID 0x227b
|
||||
+#define SG_GET_PACK_ID 0x227c /* Yields oldest readable pack_id (or -1) */
|
||||
+
|
||||
+#define SG_GET_NUM_WAITING 0x227d /* Number of commands awaiting read() */
|
||||
+
|
||||
+/* Yields max scatter gather tablesize allowed by current host adapter */
|
||||
+#define SG_GET_SG_TABLESIZE 0x227F /* 0 implies can't do scatter gather */
|
||||
+
|
||||
+#define SG_GET_VERSION_NUM 0x2282 /* Example: version 2.1.34 yields 20134 */
|
||||
+
|
||||
+/* Returns -EBUSY if occupied. 3rd argument pointer to int (see next) */
|
||||
+#define SG_SCSI_RESET 0x2284
|
||||
+/* Associated values that can be given to SG_SCSI_RESET follow */
|
||||
+#define SG_SCSI_RESET_NOTHING 0
|
||||
+#define SG_SCSI_RESET_DEVICE 1
|
||||
+#define SG_SCSI_RESET_BUS 2
|
||||
+#define SG_SCSI_RESET_HOST 3
|
||||
+
|
||||
+/* synchronous SCSI command ioctl, (only in version 3 interface) */
|
||||
+#define SG_IO 0x2285 /* similar effect as write() followed by read() */
|
||||
+
|
||||
+#define SG_GET_REQUEST_TABLE 0x2286 /* yields table of active requests */
|
||||
+
|
||||
+/* How to treat EINTR during SG_IO ioctl(), only in SG 3.x series */
|
||||
+#define SG_SET_KEEP_ORPHAN 0x2287 /* 1 -> hold for read(), 0 -> drop (def) */
|
||||
+#define SG_GET_KEEP_ORPHAN 0x2288
|
||||
+
|
||||
+
|
||||
+#define SG_SCATTER_SZ (8 * 4096) /* PAGE_SIZE not available to user */
|
||||
+/* Largest size (in bytes) a single scatter-gather list element can have.
|
||||
+ The value must be a power of 2 and <= (PAGE_SIZE * 32) [131072 bytes on
|
||||
+ i386]. The minimum value is PAGE_SIZE. If scatter-gather not supported
|
||||
+ by adapter then this value is the largest data block that can be
|
||||
+ read/written by a single scsi command. The user can find the value of
|
||||
+ PAGE_SIZE by calling getpagesize() defined in unistd.h . */
|
||||
+
|
||||
+#define SG_DEFAULT_RETRIES 1
|
||||
+
|
||||
+/* Defaults, commented if they differ from original sg driver */
|
||||
+#define SG_DEF_FORCE_LOW_DMA 0 /* was 1 -> memory below 16MB on i386 */
|
||||
+#define SG_DEF_FORCE_PACK_ID 0
|
||||
+#define SG_DEF_KEEP_ORPHAN 0
|
||||
+#define SG_DEF_RESERVED_SIZE SG_SCATTER_SZ /* load time option */
|
||||
+
|
||||
+/* maximum outstanding requests, write() yields EDOM if exceeded */
|
||||
+#define SG_MAX_QUEUE 16
|
||||
+
|
||||
+#define SG_BIG_BUFF SG_DEF_RESERVED_SIZE /* for backward compatibility */
|
||||
+
|
||||
+/* Alternate style type names, "..._t" variants preferred */
|
||||
+typedef struct sg_io_hdr Sg_io_hdr;
|
||||
+typedef struct sg_io_vec Sg_io_vec;
|
||||
+typedef struct sg_scsi_id Sg_scsi_id;
|
||||
+typedef struct sg_req_info Sg_req_info;
|
||||
+
|
||||
+
|
||||
+/* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
|
||||
+/* The older SG interface based on the 'sg_header' structure follows. */
|
||||
+/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
|
||||
+
|
||||
+#define SG_MAX_SENSE 16 /* this only applies to the sg_header interface */
|
||||
+
|
||||
+struct sg_header
|
||||
+ {
|
||||
+ /* Length of incoming packet (including header). */
|
||||
+ int pack_len;
|
||||
+ /* Maximal length of expected reply. */
|
||||
+ int reply_len;
|
||||
+ /* Id number of packet. */
|
||||
+ int pack_id;
|
||||
+ /* 0==ok, otherwise error number. */
|
||||
+ int result;
|
||||
+ /* Force 12 byte command length for group 6 & 7 commands. */
|
||||
+ unsigned int twelve_byte:1;
|
||||
+ /* SCSI status from target. */
|
||||
+ unsigned int target_status:5;
|
||||
+ /* Host status (see "DID" codes). */
|
||||
+ unsigned int host_status:8;
|
||||
+ /* Driver status+suggestion. */
|
||||
+ unsigned int driver_status:8;
|
||||
+ /* Unused. */
|
||||
+ unsigned int other_flags:10;
|
||||
+ /* Output in 3 cases:
|
||||
+ when target_status is CHECK_CONDITION or
|
||||
+ when target_status is COMMAND_TERMINATED or
|
||||
+ when (driver_status & DRIVER_SENSE) is true. */
|
||||
+ unsigned char sense_buffer[SG_MAX_SENSE];
|
||||
+ };
|
||||
+
|
||||
+
|
||||
+/* IOCTLs: The following are not required (or ignored) when the sg_io_hdr_t
|
||||
+ interface is used. They are kept for backward compatibility with
|
||||
+ the original and version 2 drivers. */
|
||||
+
|
||||
+#define SG_SET_TIMEOUT 0x2201 /* Set timeout; *(int *)arg==timeout. */
|
||||
+#define SG_GET_TIMEOUT 0x2202 /* Get timeout; return timeout. */
|
||||
+
|
||||
+/* Get/set command queuing state per fd (default is SG_DEF_COMMAND_Q). */
|
||||
+#define SG_GET_COMMAND_Q 0x2270 /* Yields 0 (queuing off) or 1 (on). */
|
||||
+#define SG_SET_COMMAND_Q 0x2271 /* Change queuing state with 0 or 1. */
|
||||
+
|
||||
+/* Turn on error sense trace (1..8), dump this device to log/console (9)
|
||||
+ or dump all sg device states ( >9 ) to log/console. */
|
||||
+#define SG_SET_DEBUG 0x227e /* 0 -> turn off debug */
|
||||
+
|
||||
+#define SG_NEXT_CMD_LEN 0x2283 /* Override SCSI command length with given
|
||||
+ number on the next write() on this file
|
||||
+ descriptor. */
|
||||
+
|
||||
+/* Defaults, commented if they differ from original sg driver */
|
||||
+#define SG_DEFAULT_TIMEOUT (60*HZ) /* HZ == 'jiffies in 1 second' */
|
||||
+#define SG_DEF_COMMAND_Q 0 /* command queuing is always on when
|
||||
+ the new interface is used */
|
||||
+#define SG_DEF_UNDERRUN_FLAG 0
|
||||
+
|
||||
+
|
||||
+#endif /* scsi/sg.h */
|
||||
--
|
||||
2.5.3
|
||||
|
||||
82
external/dist/busybox-patches/007-ifconfig_slip.patch
vendored
Normal file
82
external/dist/busybox-patches/007-ifconfig_slip.patch
vendored
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Thu, 3 Dec 2015 18:02:41 -0400
|
||||
Subject: [PATCH] ifconfig_slip: add missing headers
|
||||
|
||||
Imported from dorimanx's combined ported header toolchain:
|
||||
https://github.com/dorimanx/android-busybox-ndk
|
||||
---
|
||||
include/linux/if_slip.h | 30 ++++++++++++++++++++++++++++++
|
||||
include/net/if_slip.h | 24 ++++++++++++++++++++++++
|
||||
2 files changed, 54 insertions(+)
|
||||
create mode 100644 include/linux/if_slip.h
|
||||
create mode 100644 include/net/if_slip.h
|
||||
|
||||
diff --git a/include/linux/if_slip.h b/include/linux/if_slip.h
|
||||
new file mode 100644
|
||||
index 0000000..1eb4e3a
|
||||
--- /dev/null
|
||||
+++ b/include/linux/if_slip.h
|
||||
@@ -0,0 +1,30 @@
|
||||
+/*
|
||||
+ * Swansea University Computer Society NET3
|
||||
+ *
|
||||
+ * This file declares the constants of special use with the SLIP/CSLIP/
|
||||
+ * KISS TNC driver.
|
||||
+ */
|
||||
+
|
||||
+#ifndef __LINUX_SLIP_H
|
||||
+#define __LINUX_SLIP_H
|
||||
+
|
||||
+#define SL_MODE_SLIP 0
|
||||
+#define SL_MODE_CSLIP 1
|
||||
+#define SL_MODE_KISS 4
|
||||
+
|
||||
+#define SL_OPT_SIXBIT 2
|
||||
+#define SL_OPT_ADAPTIVE 8
|
||||
+
|
||||
+/*
|
||||
+ * VSV = ioctl for keepalive & outfill in SLIP driver
|
||||
+ */
|
||||
+
|
||||
+#define SIOCSKEEPALIVE (SIOCDEVPRIVATE) /* Set keepalive timeout in sec */
|
||||
+#define SIOCGKEEPALIVE (SIOCDEVPRIVATE+1) /* Get keepalive timeout */
|
||||
+#define SIOCSOUTFILL (SIOCDEVPRIVATE+2) /* Set outfill timeout */
|
||||
+#define SIOCGOUTFILL (SIOCDEVPRIVATE+3) /* Get outfill timeout */
|
||||
+#define SIOCSLEASE (SIOCDEVPRIVATE+4) /* Set "leased" line type */
|
||||
+#define SIOCGLEASE (SIOCDEVPRIVATE+5) /* Get line type */
|
||||
+
|
||||
+
|
||||
+#endif
|
||||
diff --git a/include/net/if_slip.h b/include/net/if_slip.h
|
||||
new file mode 100644
|
||||
index 0000000..b29b964
|
||||
--- /dev/null
|
||||
+++ b/include/net/if_slip.h
|
||||
@@ -0,0 +1,24 @@
|
||||
+/* Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, see
|
||||
+ <http://www.gnu.org/licenses/>. */
|
||||
+
|
||||
+#ifndef _NET_IF_SLIP_H
|
||||
+#define _NET_IF_SLIP_H 1
|
||||
+
|
||||
+/* We can use the kernel header. */
|
||||
+#include <linux/if_slip.h>
|
||||
+
|
||||
+#endif /* net/if_slip.h. */
|
||||
--
|
||||
2.5.3
|
||||
|
||||
1096
external/dist/busybox-patches/008-ifenslave.patch
vendored
Normal file
1096
external/dist/busybox-patches/008-ifenslave.patch
vendored
Normal file
File diff suppressed because it is too large
Load diff
75
external/dist/busybox-patches/009-watchdog.patch
vendored
Normal file
75
external/dist/busybox-patches/009-watchdog.patch
vendored
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Mon, 19 Mar 2012 17:27:19 +0000
|
||||
Subject: [PATCH] add include/linux/watchdog.h from linux kernel
|
||||
|
||||
patch from 'missing-headers' by Dan Drown
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
---
|
||||
include/linux/watchdog.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++
|
||||
1 files changed, 55 insertions(+), 0 deletions(-)
|
||||
create mode 100644 include/linux/watchdog.h
|
||||
|
||||
diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h
|
||||
new file mode 100644
|
||||
index 0000000..5bc0c62
|
||||
--- /dev/null
|
||||
+++ b/include/linux/watchdog.h
|
||||
@@ -0,0 +1,55 @@
|
||||
+/*
|
||||
+ * Generic watchdog defines. Derived from..
|
||||
+ *
|
||||
+ * Berkshire PC Watchdog Defines
|
||||
+ * by Ken Hollis <khollis@bitgate.com>
|
||||
+ *
|
||||
+ */
|
||||
+
|
||||
+#ifndef _LINUX_WATCHDOG_H
|
||||
+#define _LINUX_WATCHDOG_H
|
||||
+
|
||||
+#include <linux/ioctl.h>
|
||||
+#include <linux/types.h>
|
||||
+
|
||||
+#define WATCHDOG_IOCTL_BASE 'W'
|
||||
+
|
||||
+struct watchdog_info {
|
||||
+ __u32 options; /* Options the card/driver supports */
|
||||
+ __u32 firmware_version; /* Firmware version of the card */
|
||||
+ __u8 identity[32]; /* Identity of the board */
|
||||
+};
|
||||
+
|
||||
+#define WDIOC_GETSUPPORT _IOR(WATCHDOG_IOCTL_BASE, 0, struct watchdog_info)
|
||||
+#define WDIOC_GETSTATUS _IOR(WATCHDOG_IOCTL_BASE, 1, int)
|
||||
+#define WDIOC_GETBOOTSTATUS _IOR(WATCHDOG_IOCTL_BASE, 2, int)
|
||||
+#define WDIOC_GETTEMP _IOR(WATCHDOG_IOCTL_BASE, 3, int)
|
||||
+#define WDIOC_SETOPTIONS _IOR(WATCHDOG_IOCTL_BASE, 4, int)
|
||||
+#define WDIOC_KEEPALIVE _IOR(WATCHDOG_IOCTL_BASE, 5, int)
|
||||
+#define WDIOC_SETTIMEOUT _IOWR(WATCHDOG_IOCTL_BASE, 6, int)
|
||||
+#define WDIOC_GETTIMEOUT _IOR(WATCHDOG_IOCTL_BASE, 7, int)
|
||||
+#define WDIOC_SETPRETIMEOUT _IOWR(WATCHDOG_IOCTL_BASE, 8, int)
|
||||
+#define WDIOC_GETPRETIMEOUT _IOR(WATCHDOG_IOCTL_BASE, 9, int)
|
||||
+#define WDIOC_GETTIMELEFT _IOR(WATCHDOG_IOCTL_BASE, 10, int)
|
||||
+
|
||||
+#define WDIOF_UNKNOWN -1 /* Unknown flag error */
|
||||
+#define WDIOS_UNKNOWN -1 /* Unknown status error */
|
||||
+
|
||||
+#define WDIOF_OVERHEAT 0x0001 /* Reset due to CPU overheat */
|
||||
+#define WDIOF_FANFAULT 0x0002 /* Fan failed */
|
||||
+#define WDIOF_EXTERN1 0x0004 /* External relay 1 */
|
||||
+#define WDIOF_EXTERN2 0x0008 /* External relay 2 */
|
||||
+#define WDIOF_POWERUNDER 0x0010 /* Power bad/power fault */
|
||||
+#define WDIOF_CARDRESET 0x0020 /* Card previously reset the CPU */
|
||||
+#define WDIOF_POWEROVER 0x0040 /* Power over voltage */
|
||||
+#define WDIOF_SETTIMEOUT 0x0080 /* Set timeout (in seconds) */
|
||||
+#define WDIOF_MAGICCLOSE 0x0100 /* Supports magic close char */
|
||||
+#define WDIOF_PRETIMEOUT 0x0200 /* Pretimeout (in seconds), get/set */
|
||||
+#define WDIOF_KEEPALIVEPING 0x8000 /* Keep alive ping reply */
|
||||
+
|
||||
+#define WDIOS_DISABLECARD 0x0001 /* Turn off the watchdog timer */
|
||||
+#define WDIOS_ENABLECARD 0x0002 /* Turn on the watchdog timer */
|
||||
+#define WDIOS_TEMPPANIC 0x0004 /* Kernel panic on temperature trip */
|
||||
+
|
||||
+
|
||||
+#endif /* ifndef _LINUX_WATCHDOG_H */
|
||||
--
|
||||
1.7.0.4
|
||||
|
||||
432
external/dist/busybox-patches/010-ubiX.patch
vendored
Normal file
432
external/dist/busybox-patches/010-ubiX.patch
vendored
Normal file
|
|
@ -0,0 +1,432 @@
|
|||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Mon, 19 Mar 2012 17:32:55 +0000
|
||||
Subject: [PATCH] add include/mtd/ubi-user.h from linux kernel
|
||||
|
||||
patch from 'missing-headers' by Dan Drown
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
---
|
||||
include/mtd/ubi-user.h | 412 ++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
1 files changed, 412 insertions(+), 0 deletions(-)
|
||||
create mode 100644 include/mtd/ubi-user.h
|
||||
|
||||
diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h
|
||||
new file mode 100644
|
||||
index 0000000..466a832
|
||||
--- /dev/null
|
||||
+++ b/include/mtd/ubi-user.h
|
||||
@@ -0,0 +1,412 @@
|
||||
+/*
|
||||
+ * Copyright (c) International Business Machines Corp., 2006
|
||||
+ *
|
||||
+ * This program is free software; you can redistribute it and/or modify
|
||||
+ * it under the terms of the GNU General Public License as published by
|
||||
+ * the Free Software Foundation; either version 2 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * This program is distributed in the hope that it will be useful,
|
||||
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||
+ * the GNU General Public License for more details.
|
||||
+ *
|
||||
+ * You should have received a copy of the GNU General Public License
|
||||
+ * along with this program; if not, write to the Free Software
|
||||
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
+ *
|
||||
+ * Author: Artem Bityutskiy (Битюцкий Артём)
|
||||
+ */
|
||||
+
|
||||
+#ifndef __UBI_USER_H__
|
||||
+#define __UBI_USER_H__
|
||||
+
|
||||
+#include <linux/types.h>
|
||||
+
|
||||
+/*
|
||||
+ * UBI device creation (the same as MTD device attachment)
|
||||
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * MTD devices may be attached using %UBI_IOCATT ioctl command of the UBI
|
||||
+ * control device. The caller has to properly fill and pass
|
||||
+ * &struct ubi_attach_req object - UBI will attach the MTD device specified in
|
||||
+ * the request and return the newly created UBI device number as the ioctl
|
||||
+ * return value.
|
||||
+ *
|
||||
+ * UBI device deletion (the same as MTD device detachment)
|
||||
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * An UBI device maybe deleted with %UBI_IOCDET ioctl command of the UBI
|
||||
+ * control device.
|
||||
+ *
|
||||
+ * UBI volume creation
|
||||
+ * ~~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * UBI volumes are created via the %UBI_IOCMKVOL ioctl command of UBI character
|
||||
+ * device. A &struct ubi_mkvol_req object has to be properly filled and a
|
||||
+ * pointer to it has to be passed to the ioctl.
|
||||
+ *
|
||||
+ * UBI volume deletion
|
||||
+ * ~~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * To delete a volume, the %UBI_IOCRMVOL ioctl command of the UBI character
|
||||
+ * device should be used. A pointer to the 32-bit volume ID hast to be passed
|
||||
+ * to the ioctl.
|
||||
+ *
|
||||
+ * UBI volume re-size
|
||||
+ * ~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * To re-size a volume, the %UBI_IOCRSVOL ioctl command of the UBI character
|
||||
+ * device should be used. A &struct ubi_rsvol_req object has to be properly
|
||||
+ * filled and a pointer to it has to be passed to the ioctl.
|
||||
+ *
|
||||
+ * UBI volumes re-name
|
||||
+ * ~~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * To re-name several volumes atomically at one go, the %UBI_IOCRNVOL command
|
||||
+ * of the UBI character device should be used. A &struct ubi_rnvol_req object
|
||||
+ * has to be properly filled and a pointer to it has to be passed to the ioctl.
|
||||
+ *
|
||||
+ * UBI volume update
|
||||
+ * ~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * Volume update should be done via the %UBI_IOCVOLUP ioctl command of the
|
||||
+ * corresponding UBI volume character device. A pointer to a 64-bit update
|
||||
+ * size should be passed to the ioctl. After this, UBI expects user to write
|
||||
+ * this number of bytes to the volume character device. The update is finished
|
||||
+ * when the claimed number of bytes is passed. So, the volume update sequence
|
||||
+ * is something like:
|
||||
+ *
|
||||
+ * fd = open("/dev/my_volume");
|
||||
+ * ioctl(fd, UBI_IOCVOLUP, &image_size);
|
||||
+ * write(fd, buf, image_size);
|
||||
+ * close(fd);
|
||||
+ *
|
||||
+ * Logical eraseblock erase
|
||||
+ * ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * To erase a logical eraseblock, the %UBI_IOCEBER ioctl command of the
|
||||
+ * corresponding UBI volume character device should be used. This command
|
||||
+ * unmaps the requested logical eraseblock, makes sure the corresponding
|
||||
+ * physical eraseblock is successfully erased, and returns.
|
||||
+ *
|
||||
+ * Atomic logical eraseblock change
|
||||
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * Atomic logical eraseblock change operation is called using the %UBI_IOCEBCH
|
||||
+ * ioctl command of the corresponding UBI volume character device. A pointer to
|
||||
+ * a &struct ubi_leb_change_req object has to be passed to the ioctl. Then the
|
||||
+ * user is expected to write the requested amount of bytes (similarly to what
|
||||
+ * should be done in case of the "volume update" ioctl).
|
||||
+ *
|
||||
+ * Logical eraseblock map
|
||||
+ * ~~~~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * To map a logical eraseblock to a physical eraseblock, the %UBI_IOCEBMAP
|
||||
+ * ioctl command should be used. A pointer to a &struct ubi_map_req object is
|
||||
+ * expected to be passed. The ioctl maps the requested logical eraseblock to
|
||||
+ * a physical eraseblock and returns. Only non-mapped logical eraseblocks can
|
||||
+ * be mapped. If the logical eraseblock specified in the request is already
|
||||
+ * mapped to a physical eraseblock, the ioctl fails and returns error.
|
||||
+ *
|
||||
+ * Logical eraseblock unmap
|
||||
+ * ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * To unmap a logical eraseblock to a physical eraseblock, the %UBI_IOCEBUNMAP
|
||||
+ * ioctl command should be used. The ioctl unmaps the logical eraseblocks,
|
||||
+ * schedules corresponding physical eraseblock for erasure, and returns. Unlike
|
||||
+ * the "LEB erase" command, it does not wait for the physical eraseblock being
|
||||
+ * erased. Note, the side effect of this is that if an unclean reboot happens
|
||||
+ * after the unmap ioctl returns, you may find the LEB mapped again to the same
|
||||
+ * physical eraseblock after the UBI is run again.
|
||||
+ *
|
||||
+ * Check if logical eraseblock is mapped
|
||||
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * To check if a logical eraseblock is mapped to a physical eraseblock, the
|
||||
+ * %UBI_IOCEBISMAP ioctl command should be used. It returns %0 if the LEB is
|
||||
+ * not mapped, and %1 if it is mapped.
|
||||
+ *
|
||||
+ * Set an UBI volume property
|
||||
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
+ *
|
||||
+ * To set an UBI volume property the %UBI_IOCSETPROP ioctl command should be
|
||||
+ * used. A pointer to a &struct ubi_set_prop_req object is expected to be
|
||||
+ * passed. The object describes which property should be set, and to which value
|
||||
+ * it should be set.
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * When a new UBI volume or UBI device is created, users may either specify the
|
||||
+ * volume/device number they want to create or to let UBI automatically assign
|
||||
+ * the number using these constants.
|
||||
+ */
|
||||
+#define UBI_VOL_NUM_AUTO (-1)
|
||||
+#define UBI_DEV_NUM_AUTO (-1)
|
||||
+
|
||||
+/* Maximum volume name length */
|
||||
+#define UBI_MAX_VOLUME_NAME 127
|
||||
+
|
||||
+/* ioctl commands of UBI character devices */
|
||||
+
|
||||
+#define UBI_IOC_MAGIC 'o'
|
||||
+
|
||||
+/* Create an UBI volume */
|
||||
+#define UBI_IOCMKVOL _IOW(UBI_IOC_MAGIC, 0, struct ubi_mkvol_req)
|
||||
+/* Remove an UBI volume */
|
||||
+#define UBI_IOCRMVOL _IOW(UBI_IOC_MAGIC, 1, __s32)
|
||||
+/* Re-size an UBI volume */
|
||||
+#define UBI_IOCRSVOL _IOW(UBI_IOC_MAGIC, 2, struct ubi_rsvol_req)
|
||||
+/* Re-name volumes */
|
||||
+#define UBI_IOCRNVOL _IOW(UBI_IOC_MAGIC, 3, struct ubi_rnvol_req)
|
||||
+
|
||||
+/* ioctl commands of the UBI control character device */
|
||||
+
|
||||
+#define UBI_CTRL_IOC_MAGIC 'o'
|
||||
+
|
||||
+/* Attach an MTD device */
|
||||
+#define UBI_IOCATT _IOW(UBI_CTRL_IOC_MAGIC, 64, struct ubi_attach_req)
|
||||
+/* Detach an MTD device */
|
||||
+#define UBI_IOCDET _IOW(UBI_CTRL_IOC_MAGIC, 65, __s32)
|
||||
+
|
||||
+/* ioctl commands of UBI volume character devices */
|
||||
+
|
||||
+#define UBI_VOL_IOC_MAGIC 'O'
|
||||
+
|
||||
+/* Start UBI volume update */
|
||||
+#define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, __s64)
|
||||
+/* LEB erasure command, used for debugging, disabled by default */
|
||||
+#define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, __s32)
|
||||
+/* Atomic LEB change command */
|
||||
+#define UBI_IOCEBCH _IOW(UBI_VOL_IOC_MAGIC, 2, __s32)
|
||||
+/* Map LEB command */
|
||||
+#define UBI_IOCEBMAP _IOW(UBI_VOL_IOC_MAGIC, 3, struct ubi_map_req)
|
||||
+/* Unmap LEB command */
|
||||
+#define UBI_IOCEBUNMAP _IOW(UBI_VOL_IOC_MAGIC, 4, __s32)
|
||||
+/* Check if LEB is mapped command */
|
||||
+#define UBI_IOCEBISMAP _IOR(UBI_VOL_IOC_MAGIC, 5, __s32)
|
||||
+/* Set an UBI volume property */
|
||||
+#define UBI_IOCSETPROP _IOW(UBI_VOL_IOC_MAGIC, 6, struct ubi_set_prop_req)
|
||||
+
|
||||
+/* Maximum MTD device name length supported by UBI */
|
||||
+#define MAX_UBI_MTD_NAME_LEN 127
|
||||
+
|
||||
+/* Maximum amount of UBI volumes that can be re-named at one go */
|
||||
+#define UBI_MAX_RNVOL 32
|
||||
+
|
||||
+/*
|
||||
+ * UBI data type hint constants.
|
||||
+ *
|
||||
+ * UBI_LONGTERM: long-term data
|
||||
+ * UBI_SHORTTERM: short-term data
|
||||
+ * UBI_UNKNOWN: data persistence is unknown
|
||||
+ *
|
||||
+ * These constants are used when data is written to UBI volumes in order to
|
||||
+ * help the UBI wear-leveling unit to find more appropriate physical
|
||||
+ * eraseblocks.
|
||||
+ */
|
||||
+enum {
|
||||
+ UBI_LONGTERM = 1,
|
||||
+ UBI_SHORTTERM = 2,
|
||||
+ UBI_UNKNOWN = 3,
|
||||
+};
|
||||
+
|
||||
+/*
|
||||
+ * UBI volume type constants.
|
||||
+ *
|
||||
+ * @UBI_DYNAMIC_VOLUME: dynamic volume
|
||||
+ * @UBI_STATIC_VOLUME: static volume
|
||||
+ */
|
||||
+enum {
|
||||
+ UBI_DYNAMIC_VOLUME = 3,
|
||||
+ UBI_STATIC_VOLUME = 4,
|
||||
+};
|
||||
+
|
||||
+/*
|
||||
+ * UBI set property ioctl constants
|
||||
+ *
|
||||
+ * @UBI_PROP_DIRECT_WRITE: allow / disallow user to directly write and
|
||||
+ * erase individual eraseblocks on dynamic volumes
|
||||
+ */
|
||||
+enum {
|
||||
+ UBI_PROP_DIRECT_WRITE = 1,
|
||||
+};
|
||||
+
|
||||
+/**
|
||||
+ * struct ubi_attach_req - attach MTD device request.
|
||||
+ * @ubi_num: UBI device number to create
|
||||
+ * @mtd_num: MTD device number to attach
|
||||
+ * @vid_hdr_offset: VID header offset (use defaults if %0)
|
||||
+ * @padding: reserved for future, not used, has to be zeroed
|
||||
+ *
|
||||
+ * This data structure is used to specify MTD device UBI has to attach and the
|
||||
+ * parameters it has to use. The number which should be assigned to the new UBI
|
||||
+ * device is passed in @ubi_num. UBI may automatically assign the number if
|
||||
+ * @UBI_DEV_NUM_AUTO is passed. In this case, the device number is returned in
|
||||
+ * @ubi_num.
|
||||
+ *
|
||||
+ * Most applications should pass %0 in @vid_hdr_offset to make UBI use default
|
||||
+ * offset of the VID header within physical eraseblocks. The default offset is
|
||||
+ * the next min. I/O unit after the EC header. For example, it will be offset
|
||||
+ * 512 in case of a 512 bytes page NAND flash with no sub-page support. Or
|
||||
+ * it will be 512 in case of a 2KiB page NAND flash with 4 512-byte sub-pages.
|
||||
+ *
|
||||
+ * But in rare cases, if this optimizes things, the VID header may be placed to
|
||||
+ * a different offset. For example, the boot-loader might do things faster if
|
||||
+ * the VID header sits at the end of the first 2KiB NAND page with 4 sub-pages.
|
||||
+ * As the boot-loader would not normally need to read EC headers (unless it
|
||||
+ * needs UBI in RW mode), it might be faster to calculate ECC. This is weird
|
||||
+ * example, but it real-life example. So, in this example, @vid_hdr_offer would
|
||||
+ * be 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes
|
||||
+ * aligned, which is OK, as UBI is clever enough to realize this is 4th
|
||||
+ * sub-page of the first page and add needed padding.
|
||||
+ */
|
||||
+struct ubi_attach_req {
|
||||
+ __s32 ubi_num;
|
||||
+ __s32 mtd_num;
|
||||
+ __s32 vid_hdr_offset;
|
||||
+ __s8 padding[12];
|
||||
+};
|
||||
+
|
||||
+/**
|
||||
+ * struct ubi_mkvol_req - volume description data structure used in
|
||||
+ * volume creation requests.
|
||||
+ * @vol_id: volume number
|
||||
+ * @alignment: volume alignment
|
||||
+ * @bytes: volume size in bytes
|
||||
+ * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
|
||||
+ * @padding1: reserved for future, not used, has to be zeroed
|
||||
+ * @name_len: volume name length
|
||||
+ * @padding2: reserved for future, not used, has to be zeroed
|
||||
+ * @name: volume name
|
||||
+ *
|
||||
+ * This structure is used by user-space programs when creating new volumes. The
|
||||
+ * @used_bytes field is only necessary when creating static volumes.
|
||||
+ *
|
||||
+ * The @alignment field specifies the required alignment of the volume logical
|
||||
+ * eraseblock. This means, that the size of logical eraseblocks will be aligned
|
||||
+ * to this number, i.e.,
|
||||
+ * (UBI device logical eraseblock size) mod (@alignment) = 0.
|
||||
+ *
|
||||
+ * To put it differently, the logical eraseblock of this volume may be slightly
|
||||
+ * shortened in order to make it properly aligned. The alignment has to be
|
||||
+ * multiple of the flash minimal input/output unit, or %1 to utilize the entire
|
||||
+ * available space of logical eraseblocks.
|
||||
+ *
|
||||
+ * The @alignment field may be useful, for example, when one wants to maintain
|
||||
+ * a block device on top of an UBI volume. In this case, it is desirable to fit
|
||||
+ * an integer number of blocks in logical eraseblocks of this UBI volume. With
|
||||
+ * alignment it is possible to update this volume using plane UBI volume image
|
||||
+ * BLOBs, without caring about how to properly align them.
|
||||
+ */
|
||||
+struct ubi_mkvol_req {
|
||||
+ __s32 vol_id;
|
||||
+ __s32 alignment;
|
||||
+ __s64 bytes;
|
||||
+ __s8 vol_type;
|
||||
+ __s8 padding1;
|
||||
+ __s16 name_len;
|
||||
+ __s8 padding2[4];
|
||||
+ char name[UBI_MAX_VOLUME_NAME + 1];
|
||||
+} __attribute__ ((packed));
|
||||
+
|
||||
+/**
|
||||
+ * struct ubi_rsvol_req - a data structure used in volume re-size requests.
|
||||
+ * @vol_id: ID of the volume to re-size
|
||||
+ * @bytes: new size of the volume in bytes
|
||||
+ *
|
||||
+ * Re-sizing is possible for both dynamic and static volumes. But while dynamic
|
||||
+ * volumes may be re-sized arbitrarily, static volumes cannot be made to be
|
||||
+ * smaller than the number of bytes they bear. To arbitrarily shrink a static
|
||||
+ * volume, it must be wiped out first (by means of volume update operation with
|
||||
+ * zero number of bytes).
|
||||
+ */
|
||||
+struct ubi_rsvol_req {
|
||||
+ __s64 bytes;
|
||||
+ __s32 vol_id;
|
||||
+} __attribute__ ((packed));
|
||||
+
|
||||
+/**
|
||||
+ * struct ubi_rnvol_req - volumes re-name request.
|
||||
+ * @count: count of volumes to re-name
|
||||
+ * @padding1: reserved for future, not used, has to be zeroed
|
||||
+ * @vol_id: ID of the volume to re-name
|
||||
+ * @name_len: name length
|
||||
+ * @padding2: reserved for future, not used, has to be zeroed
|
||||
+ * @name: new volume name
|
||||
+ *
|
||||
+ * UBI allows to re-name up to %32 volumes at one go. The count of volumes to
|
||||
+ * re-name is specified in the @count field. The ID of the volumes to re-name
|
||||
+ * and the new names are specified in the @vol_id and @name fields.
|
||||
+ *
|
||||
+ * The UBI volume re-name operation is atomic, which means that should power cut
|
||||
+ * happen, the volumes will have either old name or new name. So the possible
|
||||
+ * use-cases of this command is atomic upgrade. Indeed, to upgrade, say, volumes
|
||||
+ * A and B one may create temporary volumes %A1 and %B1 with the new contents,
|
||||
+ * then atomically re-name A1->A and B1->B, in which case old %A and %B will
|
||||
+ * be removed.
|
||||
+ *
|
||||
+ * If it is not desirable to remove old A and B, the re-name request has to
|
||||
+ * contain 4 entries: A1->A, A->A1, B1->B, B->B1, in which case old A1 and B1
|
||||
+ * become A and B, and old A and B will become A1 and B1.
|
||||
+ *
|
||||
+ * It is also OK to request: A1->A, A1->X, B1->B, B->Y, in which case old A1
|
||||
+ * and B1 become A and B, and old A and B become X and Y.
|
||||
+ *
|
||||
+ * In other words, in case of re-naming into an existing volume name, the
|
||||
+ * existing volume is removed, unless it is re-named as well at the same
|
||||
+ * re-name request.
|
||||
+ */
|
||||
+struct ubi_rnvol_req {
|
||||
+ __s32 count;
|
||||
+ __s8 padding1[12];
|
||||
+ struct {
|
||||
+ __s32 vol_id;
|
||||
+ __s16 name_len;
|
||||
+ __s8 padding2[2];
|
||||
+ char name[UBI_MAX_VOLUME_NAME + 1];
|
||||
+ } ents[UBI_MAX_RNVOL];
|
||||
+} __attribute__ ((packed));
|
||||
+
|
||||
+/**
|
||||
+ * struct ubi_leb_change_req - a data structure used in atomic LEB change
|
||||
+ * requests.
|
||||
+ * @lnum: logical eraseblock number to change
|
||||
+ * @bytes: how many bytes will be written to the logical eraseblock
|
||||
+ * @dtype: data type (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN)
|
||||
+ * @padding: reserved for future, not used, has to be zeroed
|
||||
+ */
|
||||
+struct ubi_leb_change_req {
|
||||
+ __s32 lnum;
|
||||
+ __s32 bytes;
|
||||
+ __s8 dtype;
|
||||
+ __s8 padding[7];
|
||||
+} __attribute__ ((packed));
|
||||
+
|
||||
+/**
|
||||
+ * struct ubi_map_req - a data structure used in map LEB requests.
|
||||
+ * @lnum: logical eraseblock number to unmap
|
||||
+ * @dtype: data type (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN)
|
||||
+ * @padding: reserved for future, not used, has to be zeroed
|
||||
+ */
|
||||
+struct ubi_map_req {
|
||||
+ __s32 lnum;
|
||||
+ __s8 dtype;
|
||||
+ __s8 padding[3];
|
||||
+} __attribute__ ((packed));
|
||||
+
|
||||
+
|
||||
+/**
|
||||
+ * struct ubi_set_prop_req - a data structure used to set an ubi volume
|
||||
+ * property.
|
||||
+ * @property: property to set (%UBI_PROP_DIRECT_WRITE)
|
||||
+ * @padding: reserved for future, not used, has to be zeroed
|
||||
+ * @value: value to set
|
||||
+ */
|
||||
+struct ubi_set_prop_req {
|
||||
+ __u8 property;
|
||||
+ __u8 padding[7];
|
||||
+ __u64 value;
|
||||
+} __attribute__ ((packed));
|
||||
+
|
||||
+#endif /* __UBI_USER_H__ */
|
||||
--
|
||||
1.7.0.4
|
||||
|
||||
171
external/dist/busybox-patches/011-ifplugd.patch
vendored
Normal file
171
external/dist/busybox-patches/011-ifplugd.patch
vendored
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Fri, 4 Dec 2015 10:52:31 -0400
|
||||
Subject: [PATCH] ifplugd: add missing header
|
||||
|
||||
Imported from dorimanx's combined ported header toolchain:
|
||||
https://github.com/dorimanx/android-busybox-ndk
|
||||
---
|
||||
include/linux/mii.h | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 151 insertions(+)
|
||||
create mode 100644 include/linux/mii.h
|
||||
|
||||
diff --git a/include/linux/mii.h b/include/linux/mii.h
|
||||
new file mode 100644
|
||||
index 0000000..def553a
|
||||
--- /dev/null
|
||||
+++ b/include/linux/mii.h
|
||||
@@ -0,0 +1,151 @@
|
||||
+/*
|
||||
+ * linux/mii.h: definitions for MII-compatible transceivers
|
||||
+ * Originally drivers/net/sunhme.h.
|
||||
+ *
|
||||
+ * Copyright (C) 1996, 1999, 2001 David S. Miller (davem@redhat.com)
|
||||
+ */
|
||||
+
|
||||
+#ifndef __LINUX_MII_H__
|
||||
+#define __LINUX_MII_H__
|
||||
+
|
||||
+#include <linux/types.h>
|
||||
+
|
||||
+/* Generic MII registers. */
|
||||
+#define MII_BMCR 0x00 /* Basic mode control register */
|
||||
+#define MII_BMSR 0x01 /* Basic mode status register */
|
||||
+#define MII_PHYSID1 0x02 /* PHYS ID 1 */
|
||||
+#define MII_PHYSID2 0x03 /* PHYS ID 2 */
|
||||
+#define MII_ADVERTISE 0x04 /* Advertisement control reg */
|
||||
+#define MII_LPA 0x05 /* Link partner ability reg */
|
||||
+#define MII_EXPANSION 0x06 /* Expansion register */
|
||||
+#define MII_CTRL1000 0x09 /* 1000BASE-T control */
|
||||
+#define MII_STAT1000 0x0a /* 1000BASE-T status */
|
||||
+#define MII_ESTATUS 0x0f /* Extended Status */
|
||||
+#define MII_DCOUNTER 0x12 /* Disconnect counter */
|
||||
+#define MII_FCSCOUNTER 0x13 /* False carrier counter */
|
||||
+#define MII_NWAYTEST 0x14 /* N-way auto-neg test reg */
|
||||
+#define MII_RERRCOUNTER 0x15 /* Receive error counter */
|
||||
+#define MII_SREVISION 0x16 /* Silicon revision */
|
||||
+#define MII_RESV1 0x17 /* Reserved... */
|
||||
+#define MII_LBRERROR 0x18 /* Lpback, rx, bypass error */
|
||||
+#define MII_PHYADDR 0x19 /* PHY address */
|
||||
+#define MII_RESV2 0x1a /* Reserved... */
|
||||
+#define MII_TPISTATUS 0x1b /* TPI status for 10mbps */
|
||||
+#define MII_NCONFIG 0x1c /* Network interface config */
|
||||
+
|
||||
+/* Basic mode control register. */
|
||||
+#define BMCR_RESV 0x003f /* Unused... */
|
||||
+#define BMCR_SPEED1000 0x0040 /* MSB of Speed (1000) */
|
||||
+#define BMCR_CTST 0x0080 /* Collision test */
|
||||
+#define BMCR_FULLDPLX 0x0100 /* Full duplex */
|
||||
+#define BMCR_ANRESTART 0x0200 /* Auto negotiation restart */
|
||||
+#define BMCR_ISOLATE 0x0400 /* Isolate data paths from MII */
|
||||
+#define BMCR_PDOWN 0x0800 /* Enable low power state */
|
||||
+#define BMCR_ANENABLE 0x1000 /* Enable auto negotiation */
|
||||
+#define BMCR_SPEED100 0x2000 /* Select 100Mbps */
|
||||
+#define BMCR_LOOPBACK 0x4000 /* TXD loopback bits */
|
||||
+#define BMCR_RESET 0x8000 /* Reset to default state */
|
||||
+
|
||||
+/* Basic mode status register. */
|
||||
+#define BMSR_ERCAP 0x0001 /* Ext-reg capability */
|
||||
+#define BMSR_JCD 0x0002 /* Jabber detected */
|
||||
+#define BMSR_LSTATUS 0x0004 /* Link status */
|
||||
+#define BMSR_ANEGCAPABLE 0x0008 /* Able to do auto-negotiation */
|
||||
+#define BMSR_RFAULT 0x0010 /* Remote fault detected */
|
||||
+#define BMSR_ANEGCOMPLETE 0x0020 /* Auto-negotiation complete */
|
||||
+#define BMSR_RESV 0x00c0 /* Unused... */
|
||||
+#define BMSR_ESTATEN 0x0100 /* Extended Status in R15 */
|
||||
+#define BMSR_100HALF2 0x0200 /* Can do 100BASE-T2 HDX */
|
||||
+#define BMSR_100FULL2 0x0400 /* Can do 100BASE-T2 FDX */
|
||||
+#define BMSR_10HALF 0x0800 /* Can do 10mbps, half-duplex */
|
||||
+#define BMSR_10FULL 0x1000 /* Can do 10mbps, full-duplex */
|
||||
+#define BMSR_100HALF 0x2000 /* Can do 100mbps, half-duplex */
|
||||
+#define BMSR_100FULL 0x4000 /* Can do 100mbps, full-duplex */
|
||||
+#define BMSR_100BASE4 0x8000 /* Can do 100mbps, 4k packets */
|
||||
+
|
||||
+/* Advertisement control register. */
|
||||
+#define ADVERTISE_SLCT 0x001f /* Selector bits */
|
||||
+#define ADVERTISE_CSMA 0x0001 /* Only selector supported */
|
||||
+#define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */
|
||||
+#define ADVERTISE_1000XFULL 0x0020 /* Try for 1000BASE-X full-duplex */
|
||||
+#define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
|
||||
+#define ADVERTISE_1000XHALF 0x0040 /* Try for 1000BASE-X half-duplex */
|
||||
+#define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */
|
||||
+#define ADVERTISE_1000XPAUSE 0x0080 /* Try for 1000BASE-X pause */
|
||||
+#define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */
|
||||
+#define ADVERTISE_1000XPSE_ASYM 0x0100 /* Try for 1000BASE-X asym pause */
|
||||
+#define ADVERTISE_100BASE4 0x0200 /* Try for 100mbps 4k packets */
|
||||
+#define ADVERTISE_PAUSE_CAP 0x0400 /* Try for pause */
|
||||
+#define ADVERTISE_PAUSE_ASYM 0x0800 /* Try for asymetric pause */
|
||||
+#define ADVERTISE_RESV 0x1000 /* Unused... */
|
||||
+#define ADVERTISE_RFAULT 0x2000 /* Say we can detect faults */
|
||||
+#define ADVERTISE_LPACK 0x4000 /* Ack link partners response */
|
||||
+#define ADVERTISE_NPAGE 0x8000 /* Next page bit */
|
||||
+
|
||||
+#define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
|
||||
+ ADVERTISE_CSMA)
|
||||
+#define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
|
||||
+ ADVERTISE_100HALF | ADVERTISE_100FULL)
|
||||
+
|
||||
+/* Link partner ability register. */
|
||||
+#define LPA_SLCT 0x001f /* Same as advertise selector */
|
||||
+#define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
|
||||
+#define LPA_1000XFULL 0x0020 /* Can do 1000BASE-X full-duplex */
|
||||
+#define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
|
||||
+#define LPA_1000XHALF 0x0040 /* Can do 1000BASE-X half-duplex */
|
||||
+#define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
|
||||
+#define LPA_1000XPAUSE 0x0080 /* Can do 1000BASE-X pause */
|
||||
+#define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
|
||||
+#define LPA_1000XPAUSE_ASYM 0x0100 /* Can do 1000BASE-X pause asym*/
|
||||
+#define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
|
||||
+#define LPA_PAUSE_CAP 0x0400 /* Can pause */
|
||||
+#define LPA_PAUSE_ASYM 0x0800 /* Can pause asymetrically */
|
||||
+#define LPA_RESV 0x1000 /* Unused... */
|
||||
+#define LPA_RFAULT 0x2000 /* Link partner faulted */
|
||||
+#define LPA_LPACK 0x4000 /* Link partner acked us */
|
||||
+#define LPA_NPAGE 0x8000 /* Next page bit */
|
||||
+
|
||||
+#define LPA_DUPLEX (LPA_10FULL | LPA_100FULL)
|
||||
+#define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
|
||||
+
|
||||
+/* Expansion register for auto-negotiation. */
|
||||
+#define EXPANSION_NWAY 0x0001 /* Can do N-way auto-nego */
|
||||
+#define EXPANSION_LCWP 0x0002 /* Got new RX page code word */
|
||||
+#define EXPANSION_ENABLENPAGE 0x0004 /* This enables npage words */
|
||||
+#define EXPANSION_NPCAPABLE 0x0008 /* Link partner supports npage */
|
||||
+#define EXPANSION_MFAULTS 0x0010 /* Multiple faults detected */
|
||||
+#define EXPANSION_RESV 0xffe0 /* Unused... */
|
||||
+
|
||||
+#define ESTATUS_1000_TFULL 0x2000 /* Can do 1000BT Full */
|
||||
+#define ESTATUS_1000_THALF 0x1000 /* Can do 1000BT Half */
|
||||
+
|
||||
+/* N-way test register. */
|
||||
+#define NWAYTEST_RESV1 0x00ff /* Unused... */
|
||||
+#define NWAYTEST_LOOPBACK 0x0100 /* Enable loopback for N-way */
|
||||
+#define NWAYTEST_RESV2 0xfe00 /* Unused... */
|
||||
+
|
||||
+/* 1000BASE-T Control register */
|
||||
+#define ADVERTISE_1000FULL 0x0200 /* Advertise 1000BASE-T full duplex */
|
||||
+#define ADVERTISE_1000HALF 0x0100 /* Advertise 1000BASE-T half duplex */
|
||||
+#define CTL1000_AS_MASTER 0x0800
|
||||
+#define CTL1000_ENABLE_MASTER 0x1000
|
||||
+
|
||||
+/* 1000BASE-T Status register */
|
||||
+#define LPA_1000LOCALRXOK 0x2000 /* Link partner local receiver status */
|
||||
+#define LPA_1000REMRXOK 0x1000 /* Link partner remote receiver status */
|
||||
+#define LPA_1000FULL 0x0800 /* Link partner 1000BASE-T full duplex */
|
||||
+#define LPA_1000HALF 0x0400 /* Link partner 1000BASE-T half duplex */
|
||||
+
|
||||
+/* Flow control flags */
|
||||
+#define FLOW_CTRL_TX 0x01
|
||||
+#define FLOW_CTRL_RX 0x02
|
||||
+
|
||||
+/* This structure is used in all SIOCxMIIxxx ioctl calls */
|
||||
+struct mii_ioctl_data {
|
||||
+ __u16 phy_id;
|
||||
+ __u16 reg_num;
|
||||
+ __u16 val_in;
|
||||
+ __u16 val_out;
|
||||
+};
|
||||
+
|
||||
+#endif /* __LINUX_MII_H__ */
|
||||
--
|
||||
2.5.3
|
||||
|
||||
251
external/dist/busybox-patches/012-a-ether_ntoa-udhcpd.patch
vendored
Normal file
251
external/dist/busybox-patches/012-a-ether_ntoa-udhcpd.patch
vendored
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Tue, 10 Jan 2017 10:24:29 -0400
|
||||
Subject: [PATCH] fix udhcpd and nameif, add ether_ntoa_r and ether_aton_r from glibc
|
||||
|
||||
this patch also fixes part of arping and ether-wake, but not sufficiently yet
|
||||
|
||||
Patch modified by Tias Guns <tias@ulyssis.org> from 'ether_XtoY-from-glibc' by Dan Drown
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
Rebased for busybox 1.26.1 by Chris Renshaw <osm0sis@outlook.com>
|
||||
---
|
||||
networking/arping.c | 1 +
|
||||
networking/ether-wake.c | 6 +++--
|
||||
networking/ether_aton_r.c | 63 +++++++++++++++++++++++++++++++++++++++++++++
|
||||
networking/ether_ntoa_r.c | 33 ++++++++++++++++++++++++
|
||||
networking/ether_port.h | 29 +++++++++++++++++++++
|
||||
networking/nameif.c | 1 +
|
||||
networking/udhcp/Kbuild.src | 1 +
|
||||
networking/udhcp/dhcpd.c | 4 +++
|
||||
8 files changed, 136 insertions(+), 2 deletions(-)
|
||||
create mode 100644 networking/ether_aton_r.c
|
||||
create mode 100644 networking/ether_ntoa_r.c
|
||||
create mode 100644 networking/ether_port.h
|
||||
|
||||
diff --git a/networking/arping.c b/networking/arping.c
|
||||
index 5bfeb1b..1980620 100644
|
||||
--- a/networking/arping.c
|
||||
+++ b/networking/arping.c
|
||||
@@ -16,6 +16,7 @@
|
||||
//applet:IF_ARPING(APPLET(arping, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_ARPING) += arping.o
|
||||
+//kbuild:lib-$(CONFIG_ARPING) += ether_ntoa_r.o
|
||||
|
||||
//usage:#define arping_trivial_usage
|
||||
//usage: "[-fqbDUA] [-c CNT] [-w TIMEOUT] [-I IFACE] [-s SRC_IP] DST_IP"
|
||||
diff --git a/networking/ether-wake.c b/networking/ether-wake.c
|
||||
index d7d6917..7a1fc45 100644
|
||||
--- a/networking/ether-wake.c
|
||||
+++ b/networking/ether-wake.c
|
||||
@@ -73,6 +73,7 @@
|
||||
//applet:IF_ETHER_WAKE(APPLET_ODDNAME(ether-wake, ether_wake, BB_DIR_USR_SBIN, BB_SUID_DROP, ether_wake))
|
||||
|
||||
//kbuild:lib-$(CONFIG_ETHER_WAKE) += ether-wake.o
|
||||
+//kbuild:lib-$(CONFIG_ETHER_WAKE) += ether_aton_r.o ether_ntoa_r.o
|
||||
|
||||
//usage:#define ether_wake_trivial_usage
|
||||
//usage: "[-b] [-i IFACE] [-p aa:bb:cc:dd[:ee:ff]/a.b.c.d] MAC"
|
||||
@@ -127,13 +128,14 @@ void bb_debug_dump_packet(unsigned char *outpack, int pktsize)
|
||||
static void get_dest_addr(const char *hostid, struct ether_addr *eaddr)
|
||||
{
|
||||
struct ether_addr *eap;
|
||||
+ char ether_buf[20];
|
||||
|
||||
eap = ether_aton_r(hostid, eaddr);
|
||||
if (eap) {
|
||||
- bb_debug_msg("The target station address is %s\n\n", ether_ntoa(eap));
|
||||
+ bb_debug_msg("The target station address is %s\n\n", ether_ntoa_r(eap, ether_buf));
|
||||
#if !defined(__UCLIBC__) || UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30)
|
||||
} else if (ether_hostton(hostid, eaddr) == 0) {
|
||||
- bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa(eaddr));
|
||||
+ bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa_r(eaddr, ether_buf));
|
||||
#endif
|
||||
} else {
|
||||
bb_show_usage();
|
||||
diff --git a/networking/ether_aton_r.c b/networking/ether_aton_r.c
|
||||
new file mode 100644
|
||||
index 0000000..0215f16
|
||||
--- /dev/null
|
||||
+++ b/networking/ether_aton_r.c
|
||||
@@ -0,0 +1,63 @@
|
||||
+/* Copyright (C) 1996,97,98,99,2002 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, write to the Free
|
||||
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
+ 02111-1307 USA. */
|
||||
+
|
||||
+#include <ctype.h>
|
||||
+#include <sys/types.h>
|
||||
+#include <netinet/ether.h>
|
||||
+#include <netinet/if_ether.h>
|
||||
+
|
||||
+
|
||||
+struct ether_addr *
|
||||
+ether_aton_r (const char *asc, struct ether_addr *addr)
|
||||
+{
|
||||
+ size_t cnt;
|
||||
+
|
||||
+ for (cnt = 0; cnt < 6; ++cnt)
|
||||
+ {
|
||||
+ unsigned int number;
|
||||
+ char ch;
|
||||
+
|
||||
+ ch = tolower (*asc++);
|
||||
+ if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
|
||||
+ return NULL;
|
||||
+ number = isdigit (ch) ? (ch - '0') : (ch - 'a' + 10);
|
||||
+
|
||||
+ ch = tolower (*asc);
|
||||
+ if ((cnt < 5 && ch != ':') || (cnt == 5 && ch != '\0' && !isspace (ch)))
|
||||
+ {
|
||||
+ ++asc;
|
||||
+ if ((ch < '0' || ch > '9') && (ch < 'a' || ch > 'f'))
|
||||
+ return NULL;
|
||||
+ number <<= 4;
|
||||
+ number += isdigit (ch) ? (ch - '0') : (ch - 'a' + 10);
|
||||
+
|
||||
+ ch = *asc;
|
||||
+ if (cnt < 5 && ch != ':')
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ /* Store result. */
|
||||
+ addr->ether_addr_octet[cnt] = (unsigned char) number;
|
||||
+
|
||||
+ /* Skip ':'. */
|
||||
+ ++asc;
|
||||
+ }
|
||||
+
|
||||
+ return addr;
|
||||
+}
|
||||
diff --git a/networking/ether_ntoa_r.c b/networking/ether_ntoa_r.c
|
||||
new file mode 100644
|
||||
index 0000000..cd50614
|
||||
--- /dev/null
|
||||
+++ b/networking/ether_ntoa_r.c
|
||||
@@ -0,0 +1,33 @@
|
||||
+/* Copyright (C) 1996,97,2002 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, write to the Free
|
||||
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
+ 02111-1307 USA. */
|
||||
+
|
||||
+#include <stdio.h>
|
||||
+#include <netinet/ether.h>
|
||||
+#include <netinet/if_ether.h>
|
||||
+
|
||||
+
|
||||
+char *
|
||||
+ether_ntoa_r (const struct ether_addr *addr, char *buf)
|
||||
+{
|
||||
+ sprintf (buf, "%x:%x:%x:%x:%x:%x",
|
||||
+ addr->ether_addr_octet[0], addr->ether_addr_octet[1],
|
||||
+ addr->ether_addr_octet[2], addr->ether_addr_octet[3],
|
||||
+ addr->ether_addr_octet[4], addr->ether_addr_octet[5]);
|
||||
+ return buf;
|
||||
+}
|
||||
diff --git a/networking/ether_port.h b/networking/ether_port.h
|
||||
new file mode 100644
|
||||
index 0000000..5e0146b
|
||||
--- /dev/null
|
||||
+++ b/networking/ether_port.h
|
||||
@@ -0,0 +1,29 @@
|
||||
+/* Copyright (C) 1996,97,98,99,2002 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, write to the Free
|
||||
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
+ 02111-1307 USA. */
|
||||
+
|
||||
+#ifndef ETHER_PORT_H
|
||||
+#define ETHER_PORT_H 1
|
||||
+
|
||||
+#include <netinet/ether.h>
|
||||
+#include <netinet/if_ether.h>
|
||||
+
|
||||
+struct ether_addr * ether_aton_r (const char *asc, struct ether_addr *addr);
|
||||
+char * ether_ntoa_r (const struct ether_addr *addr, char *buf);
|
||||
+
|
||||
+#endif /* ETHER_PORT_H */
|
||||
diff --git a/networking/nameif.c b/networking/nameif.c
|
||||
index cffd5bf..f634375 100644
|
||||
--- a/networking/nameif.c
|
||||
+++ b/networking/nameif.c
|
||||
@@ -43,6 +43,7 @@
|
||||
//applet:IF_NAMEIF(APPLET(nameif, BB_DIR_SBIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_NAMEIF) += nameif.o
|
||||
+//kbuild:lib-$(CONFIG_NAMEIF) += ether_aton_r.o
|
||||
|
||||
//usage:#define nameif_trivial_usage
|
||||
//usage: IF_NOT_FEATURE_NAMEIF_EXTENDED(
|
||||
diff --git a/networking/udhcp/Kbuild.src b/networking/udhcp/Kbuild.src
|
||||
index fcb725f..2d5739c 100644
|
||||
--- a/networking/udhcp/Kbuild.src
|
||||
+++ b/networking/udhcp/Kbuild.src
|
||||
@@ -14,6 +14,7 @@ lib-$(CONFIG_UDHCPD) += common.o packet.o signalpipe.o socket.o
|
||||
|
||||
lib-$(CONFIG_UDHCPC) += dhcpc.o
|
||||
lib-$(CONFIG_UDHCPD) += dhcpd.o arpping.o
|
||||
+lib-$(CONFIG_UDHCPD) += ../ether_aton_r.o ../ether_ntoa_r.o
|
||||
lib-$(CONFIG_DUMPLEASES) += dumpleases.o
|
||||
lib-$(CONFIG_DHCPRELAY) += dhcprelay.o common.o socket.o packet.o
|
||||
|
||||
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
|
||||
index e116ba3..ef5024c 100644
|
||||
--- a/networking/udhcp/dhcpd.c
|
||||
+++ b/networking/udhcp/dhcpd.c
|
||||
@@ -38,8 +38,12 @@
|
||||
//usage: "\n -P N Use port N (default 67)"
|
||||
//usage: )
|
||||
|
||||
+#include <sys/types.h>
|
||||
#include <netinet/ether.h>
|
||||
#include <syslog.h>
|
||||
+
|
||||
+#include "../ether_port.h"
|
||||
+
|
||||
#include "common.h"
|
||||
#include "dhcpc.h"
|
||||
#include "dhcpd.h"
|
||||
--
|
||||
2.8.3
|
||||
|
||||
27
external/dist/busybox-patches/012-b-arping.patch
vendored
Normal file
27
external/dist/busybox-patches/012-b-arping.patch
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Mon, 19 Mar 2012 18:03:19 +0000
|
||||
Subject: [PATCH] fix arping: include if_arp.h (for arphdr) and add mempcpy.c
|
||||
|
||||
fixing arping also requires adding ether_ntoa_r, see 'fix udhcpd' patch
|
||||
|
||||
patch from 'struct-arphdr' and 'mempcpy-function' by Dan Drown
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
---
|
||||
networking/arping.c | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/networking/arping.c b/networking/arping.c
|
||||
index 37dfec1..c34e002 100644
|
||||
--- a/networking/arping.c
|
||||
+++ b/networking/arping.c
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <net/if.h>
|
||||
#include <netinet/ether.h>
|
||||
#include <netpacket/packet.h>
|
||||
+#include <linux/if_arp.h> /* for arphdr */
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
--
|
||||
1.7.10.4
|
||||
|
||||
36
external/dist/busybox-patches/012-c-ether-wake.patch
vendored
Normal file
36
external/dist/busybox-patches/012-c-ether-wake.patch
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Wed, 2 Dec 2015 23:44:06 -0400
|
||||
Subject: [PATCH] fix ether-wake, avoid ether_hostton and include if_ether
|
||||
|
||||
Patch by Tias Guns <tias@ulyssis.org>, based on 'no-ether_hostton' by Dan Drown
|
||||
"there is no /etc/ethers or ether_hostton on bionic"
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
Rebased for busybox 1.24.1 by Chris Renshaw <osm0sis@outlook.com>
|
||||
---
|
||||
networking/ether-wake.c | 3 ++-
|
||||
1 files changed, 2 insertions(+), 1 deletions(-)
|
||||
|
||||
diff --git a/networking/ether-wake.c b/networking/ether-wake.c
|
||||
index 103a421..ee33dc5 100644
|
||||
--- a/networking/ether-wake.c
|
||||
+++ b/networking/ether-wake.c
|
||||
@@ -77,6 +77,7 @@
|
||||
#include "libbb.h"
|
||||
#include <netpacket/packet.h>
|
||||
#include <netinet/ether.h>
|
||||
+#include <netinet/if_ether.h>
|
||||
#include <linux/if.h>
|
||||
|
||||
/* Note: PF_INET, SOCK_DGRAM, IPPROTO_UDP would allow SIOCGIFHWADDR to
|
||||
@@ -122,7 +123,7 @@ static void get_dest_addr(const char *hostid, struct ether_addr *eaddr)
|
||||
eap = ether_aton_r(hostid, eaddr);
|
||||
if (eap) {
|
||||
bb_debug_msg("The target station address is %s\n\n", ether_ntoa_r(eap, ether_buf));
|
||||
-#if !defined(__UCLIBC__) || UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30)
|
||||
+#if !defined(__BIONIC__) && (!defined(__UCLIBC__) || UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30))
|
||||
} else if (ether_hostton(hostid, eaddr) == 0) {
|
||||
bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa_r(eaddr, ether_buf));
|
||||
#endif
|
||||
--
|
||||
2.5.3
|
||||
|
||||
54
external/dist/busybox-patches/013-loadfont-setfont-conspy.patch
vendored
Normal file
54
external/dist/busybox-patches/013-loadfont-setfont-conspy.patch
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Thu, 3 Dec 2015 01:29:35 -0400
|
||||
Subject: [PATCH] loadfont/setfont/conspy: add missing header
|
||||
|
||||
Imported from dorimanx's combined ported header toolchain:
|
||||
https://github.com/dorimanx/android-busybox-ndk
|
||||
---
|
||||
include/sys/kd.h | 34 ++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 34 insertions(+)
|
||||
create mode 100644 include/sys/kd.h
|
||||
|
||||
diff --git a/include/sys/kd.h b/include/sys/kd.h
|
||||
new file mode 100644
|
||||
index 0000000..8b8e56d
|
||||
--- /dev/null
|
||||
+++ b/include/sys/kd.h
|
||||
@@ -0,0 +1,34 @@
|
||||
+/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, see
|
||||
+ <http://www.gnu.org/licenses/>. */
|
||||
+
|
||||
+#ifndef _SYS_KD_H
|
||||
+#define _SYS_KD_H 1
|
||||
+
|
||||
+/* Make sure the <linux/types.h> header is not loaded. */
|
||||
+#ifndef _LINUX_TYPES_H
|
||||
+# define _LINUX_TYPES_H 1
|
||||
+# define __undef_LINUX_TYPES_H
|
||||
+#endif
|
||||
+
|
||||
+#include <linux/kd.h>
|
||||
+
|
||||
+#ifdef __undef_LINUX_TYPES_H
|
||||
+# undef _LINUX_TYPES_H
|
||||
+# undef __undef_LINUX_TYPES_H
|
||||
+#endif
|
||||
+
|
||||
+#endif /* sys/kd.h */
|
||||
--
|
||||
2.5.3
|
||||
|
||||
338
external/dist/busybox-patches/014-nandwrite-nanddump.patch
vendored
Normal file
338
external/dist/busybox-patches/014-nandwrite-nanddump.patch
vendored
Normal file
|
|
@ -0,0 +1,338 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Sun, 6 Dec 2015 12:27:41 -0400
|
||||
Subject: [PATCH] nandwrite/nanddump: add missing headers
|
||||
needed for Android API 21
|
||||
|
||||
---
|
||||
include/mtd/mtd-abi.h | 277 +++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
include/mtd/mtd-user.h | 34 ++++++
|
||||
2 files changed, 311 insertions(+)
|
||||
create mode 100644 include/mtd/mtd-abi.h
|
||||
create mode 100644 include/mtd/mtd-user.h
|
||||
|
||||
diff --git a/include/mtd/mtd-abi.h b/include/mtd/mtd-abi.h
|
||||
new file mode 100644
|
||||
index 0000000..4de167b
|
||||
--- /dev/null
|
||||
+++ b/include/mtd/mtd-abi.h
|
||||
@@ -0,0 +1,277 @@
|
||||
+/*
|
||||
+ * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> et al.
|
||||
+ *
|
||||
+ * This program is free software; you can redistribute it and/or modify
|
||||
+ * it under the terms of the GNU General Public License as published by
|
||||
+ * the Free Software Foundation; either version 2 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * This program is distributed in the hope that it will be useful,
|
||||
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
+ * GNU General Public License for more details.
|
||||
+ *
|
||||
+ * You should have received a copy of the GNU General Public License
|
||||
+ * along with this program; if not, write to the Free Software
|
||||
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+ *
|
||||
+ */
|
||||
+
|
||||
+#ifndef __MTD_ABI_H__
|
||||
+#define __MTD_ABI_H__
|
||||
+
|
||||
+#include <linux/types.h>
|
||||
+
|
||||
+struct erase_info_user {
|
||||
+ __u32 start;
|
||||
+ __u32 length;
|
||||
+};
|
||||
+
|
||||
+struct erase_info_user64 {
|
||||
+ __u64 start;
|
||||
+ __u64 length;
|
||||
+};
|
||||
+
|
||||
+struct mtd_oob_buf {
|
||||
+ __u32 start;
|
||||
+ __u32 length;
|
||||
+ unsigned char *ptr;
|
||||
+};
|
||||
+
|
||||
+struct mtd_oob_buf64 {
|
||||
+ __u64 start;
|
||||
+ __u32 pad;
|
||||
+ __u32 length;
|
||||
+ __u64 usr_ptr;
|
||||
+};
|
||||
+
|
||||
+/**
|
||||
+ * MTD operation modes
|
||||
+ *
|
||||
+ * @MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default)
|
||||
+ * @MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas
|
||||
+ * which are defined by the internal ecclayout
|
||||
+ * @MTD_OPS_RAW: data are transferred as-is, with no error correction;
|
||||
+ * this mode implies %MTD_OPS_PLACE_OOB
|
||||
+ *
|
||||
+ * These modes can be passed to ioctl(MEMWRITE) and are also used internally.
|
||||
+ * See notes on "MTD file modes" for discussion on %MTD_OPS_RAW vs.
|
||||
+ * %MTD_FILE_MODE_RAW.
|
||||
+ */
|
||||
+enum {
|
||||
+ MTD_OPS_PLACE_OOB = 0,
|
||||
+ MTD_OPS_AUTO_OOB = 1,
|
||||
+ MTD_OPS_RAW = 2,
|
||||
+};
|
||||
+
|
||||
+/**
|
||||
+ * struct mtd_write_req - data structure for requesting a write operation
|
||||
+ *
|
||||
+ * @start: start address
|
||||
+ * @len: length of data buffer
|
||||
+ * @ooblen: length of OOB buffer
|
||||
+ * @usr_data: user-provided data buffer
|
||||
+ * @usr_oob: user-provided OOB buffer
|
||||
+ * @mode: MTD mode (see "MTD operation modes")
|
||||
+ * @padding: reserved, must be set to 0
|
||||
+ *
|
||||
+ * This structure supports ioctl(MEMWRITE) operations, allowing data and/or OOB
|
||||
+ * writes in various modes. To write to OOB-only, set @usr_data == NULL, and to
|
||||
+ * write data-only, set @usr_oob == NULL. However, setting both @usr_data and
|
||||
+ * @usr_oob to NULL is not allowed.
|
||||
+ */
|
||||
+struct mtd_write_req {
|
||||
+ __u64 start;
|
||||
+ __u64 len;
|
||||
+ __u64 ooblen;
|
||||
+ __u64 usr_data;
|
||||
+ __u64 usr_oob;
|
||||
+ __u8 mode;
|
||||
+ __u8 padding[7];
|
||||
+};
|
||||
+
|
||||
+#define MTD_ABSENT 0
|
||||
+#define MTD_RAM 1
|
||||
+#define MTD_ROM 2
|
||||
+#define MTD_NORFLASH 3
|
||||
+#define MTD_NANDFLASH 4
|
||||
+#define MTD_DATAFLASH 6
|
||||
+#define MTD_UBIVOLUME 7
|
||||
+#define MTD_MLCNANDFLASH 8
|
||||
+
|
||||
+#define MTD_WRITEABLE 0x400 /* Device is writeable */
|
||||
+#define MTD_BIT_WRITEABLE 0x800 /* Single bits can be flipped */
|
||||
+#define MTD_NO_ERASE 0x1000 /* No erase necessary */
|
||||
+#define MTD_POWERUP_LOCK 0x2000 /* Always locked after reset */
|
||||
+
|
||||
+/* Some common devices / combinations of capabilities */
|
||||
+#define MTD_CAP_ROM 0
|
||||
+#define MTD_CAP_RAM (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE)
|
||||
+#define MTD_CAP_NORFLASH (MTD_WRITEABLE | MTD_BIT_WRITEABLE)
|
||||
+#define MTD_CAP_NANDFLASH (MTD_WRITEABLE)
|
||||
+
|
||||
+/* Obsolete ECC byte placement modes (used with obsolete MEMGETOOBSEL) */
|
||||
+#define MTD_NANDECC_OFF 0 // Switch off ECC (Not recommended)
|
||||
+#define MTD_NANDECC_PLACE 1 // Use the given placement in the structure (YAFFS1 legacy mode)
|
||||
+#define MTD_NANDECC_AUTOPLACE 2 // Use the default placement scheme
|
||||
+#define MTD_NANDECC_PLACEONLY 3 // Use the given placement in the structure (Do not store ecc result on read)
|
||||
+#define MTD_NANDECC_AUTOPL_USR 4 // Use the given autoplacement scheme rather than using the default
|
||||
+
|
||||
+/* OTP mode selection */
|
||||
+#define MTD_OTP_OFF 0
|
||||
+#define MTD_OTP_FACTORY 1
|
||||
+#define MTD_OTP_USER 2
|
||||
+
|
||||
+struct mtd_info_user {
|
||||
+ __u8 type;
|
||||
+ __u32 flags;
|
||||
+ __u32 size; /* Total size of the MTD */
|
||||
+ __u32 erasesize;
|
||||
+ __u32 writesize;
|
||||
+ __u32 oobsize; /* Amount of OOB data per block (e.g. 16) */
|
||||
+ __u64 padding; /* Old obsolete field; do not use */
|
||||
+};
|
||||
+
|
||||
+struct region_info_user {
|
||||
+ __u32 offset; /* At which this region starts,
|
||||
+ * from the beginning of the MTD */
|
||||
+ __u32 erasesize; /* For this region */
|
||||
+ __u32 numblocks; /* Number of blocks in this region */
|
||||
+ __u32 regionindex;
|
||||
+};
|
||||
+
|
||||
+struct otp_info {
|
||||
+ __u32 start;
|
||||
+ __u32 length;
|
||||
+ __u32 locked;
|
||||
+};
|
||||
+
|
||||
+/*
|
||||
+ * Note, the following ioctl existed in the past and was removed:
|
||||
+ * #define MEMSETOOBSEL _IOW('M', 9, struct nand_oobinfo)
|
||||
+ * Try to avoid adding a new ioctl with the same ioctl number.
|
||||
+ */
|
||||
+
|
||||
+/* Get basic MTD characteristics info (better to use sysfs) */
|
||||
+#define MEMGETINFO _IOR('M', 1, struct mtd_info_user)
|
||||
+/* Erase segment of MTD */
|
||||
+#define MEMERASE _IOW('M', 2, struct erase_info_user)
|
||||
+/* Write out-of-band data from MTD */
|
||||
+#define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf)
|
||||
+/* Read out-of-band data from MTD */
|
||||
+#define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf)
|
||||
+/* Lock a chip (for MTD that supports it) */
|
||||
+#define MEMLOCK _IOW('M', 5, struct erase_info_user)
|
||||
+/* Unlock a chip (for MTD that supports it) */
|
||||
+#define MEMUNLOCK _IOW('M', 6, struct erase_info_user)
|
||||
+/* Get the number of different erase regions */
|
||||
+#define MEMGETREGIONCOUNT _IOR('M', 7, int)
|
||||
+/* Get information about the erase region for a specific index */
|
||||
+#define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user)
|
||||
+/* Get info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface */
|
||||
+#define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo)
|
||||
+/* Check if an eraseblock is bad */
|
||||
+#define MEMGETBADBLOCK _IOW('M', 11, __kernel_loff_t)
|
||||
+/* Mark an eraseblock as bad */
|
||||
+#define MEMSETBADBLOCK _IOW('M', 12, __kernel_loff_t)
|
||||
+/* Set OTP (One-Time Programmable) mode (factory vs. user) */
|
||||
+#define OTPSELECT _IOR('M', 13, int)
|
||||
+/* Get number of OTP (One-Time Programmable) regions */
|
||||
+#define OTPGETREGIONCOUNT _IOW('M', 14, int)
|
||||
+/* Get all OTP (One-Time Programmable) info about MTD */
|
||||
+#define OTPGETREGIONINFO _IOW('M', 15, struct otp_info)
|
||||
+/* Lock a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER) */
|
||||
+#define OTPLOCK _IOR('M', 16, struct otp_info)
|
||||
+/* Get ECC layout (deprecated) */
|
||||
+#define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout_user)
|
||||
+/* Get statistics about corrected/uncorrected errors */
|
||||
+#define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats)
|
||||
+/* Set MTD mode on a per-file-descriptor basis (see "MTD file modes") */
|
||||
+#define MTDFILEMODE _IO('M', 19)
|
||||
+/* Erase segment of MTD (supports 64-bit address) */
|
||||
+#define MEMERASE64 _IOW('M', 20, struct erase_info_user64)
|
||||
+/* Write data to OOB (64-bit version) */
|
||||
+#define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64)
|
||||
+/* Read data from OOB (64-bit version) */
|
||||
+#define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64)
|
||||
+/* Check if chip is locked (for MTD that supports it) */
|
||||
+#define MEMISLOCKED _IOR('M', 23, struct erase_info_user)
|
||||
+/*
|
||||
+ * Most generic write interface; can write in-band and/or out-of-band in various
|
||||
+ * modes (see "struct mtd_write_req")
|
||||
+ */
|
||||
+#define MEMWRITE _IOWR('M', 24, struct mtd_write_req)
|
||||
+
|
||||
+/*
|
||||
+ * Obsolete legacy interface. Keep it in order not to break userspace
|
||||
+ * interfaces
|
||||
+ */
|
||||
+struct nand_oobinfo {
|
||||
+ __u32 useecc;
|
||||
+ __u32 eccbytes;
|
||||
+ __u32 oobfree[8][2];
|
||||
+ __u32 eccpos[32];
|
||||
+};
|
||||
+
|
||||
+struct nand_oobfree {
|
||||
+ __u32 offset;
|
||||
+ __u32 length;
|
||||
+};
|
||||
+
|
||||
+#define MTD_MAX_OOBFREE_ENTRIES 8
|
||||
+#define MTD_MAX_ECCPOS_ENTRIES 64
|
||||
+/*
|
||||
+ * OBSOLETE: ECC layout control structure. Exported to user-space via ioctl
|
||||
+ * ECCGETLAYOUT for backwards compatbility and should not be mistaken as a
|
||||
+ * complete set of ECC information. The ioctl truncates the larger internal
|
||||
+ * structure to retain binary compatibility with the static declaration of the
|
||||
+ * ioctl. Note that the "MTD_MAX_..._ENTRIES" macros represent the max size of
|
||||
+ * the user struct, not the MAX size of the internal struct nand_ecclayout.
|
||||
+ */
|
||||
+struct nand_ecclayout_user {
|
||||
+ __u32 eccbytes;
|
||||
+ __u32 eccpos[MTD_MAX_ECCPOS_ENTRIES];
|
||||
+ __u32 oobavail;
|
||||
+ struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
|
||||
+};
|
||||
+
|
||||
+/**
|
||||
+ * struct mtd_ecc_stats - error correction stats
|
||||
+ *
|
||||
+ * @corrected: number of corrected bits
|
||||
+ * @failed: number of uncorrectable errors
|
||||
+ * @badblocks: number of bad blocks in this partition
|
||||
+ * @bbtblocks: number of blocks reserved for bad block tables
|
||||
+ */
|
||||
+struct mtd_ecc_stats {
|
||||
+ __u32 corrected;
|
||||
+ __u32 failed;
|
||||
+ __u32 badblocks;
|
||||
+ __u32 bbtblocks;
|
||||
+};
|
||||
+
|
||||
+/*
|
||||
+ * MTD file modes - for read/write access to MTD
|
||||
+ *
|
||||
+ * @MTD_FILE_MODE_NORMAL: OTP disabled, ECC enabled
|
||||
+ * @MTD_FILE_MODE_OTP_FACTORY: OTP enabled in factory mode
|
||||
+ * @MTD_FILE_MODE_OTP_USER: OTP enabled in user mode
|
||||
+ * @MTD_FILE_MODE_RAW: OTP disabled, ECC disabled
|
||||
+ *
|
||||
+ * These modes can be set via ioctl(MTDFILEMODE). The mode mode will be retained
|
||||
+ * separately for each open file descriptor.
|
||||
+ *
|
||||
+ * Note: %MTD_FILE_MODE_RAW provides the same functionality as %MTD_OPS_RAW -
|
||||
+ * raw access to the flash, without error correction or autoplacement schemes.
|
||||
+ * Wherever possible, the MTD_OPS_* mode will override the MTD_FILE_MODE_* mode
|
||||
+ * (e.g., when using ioctl(MEMWRITE)), but in some cases, the MTD_FILE_MODE is
|
||||
+ * used out of necessity (e.g., `write()', ioctl(MEMWRITEOOB64)).
|
||||
+ */
|
||||
+enum mtd_file_modes {
|
||||
+ MTD_FILE_MODE_NORMAL = MTD_OTP_OFF,
|
||||
+ MTD_FILE_MODE_OTP_FACTORY = MTD_OTP_FACTORY,
|
||||
+ MTD_FILE_MODE_OTP_USER = MTD_OTP_USER,
|
||||
+ MTD_FILE_MODE_RAW,
|
||||
+};
|
||||
+
|
||||
+#endif /* __MTD_ABI_H__ */
|
||||
diff --git a/include/mtd/mtd-user.h b/include/mtd/mtd-user.h
|
||||
new file mode 100644
|
||||
index 0000000..83327c8
|
||||
--- /dev/null
|
||||
+++ b/include/mtd/mtd-user.h
|
||||
@@ -0,0 +1,34 @@
|
||||
+/*
|
||||
+ * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
|
||||
+ *
|
||||
+ * This program is free software; you can redistribute it and/or modify
|
||||
+ * it under the terms of the GNU General Public License as published by
|
||||
+ * the Free Software Foundation; either version 2 of the License, or
|
||||
+ * (at your option) any later version.
|
||||
+ *
|
||||
+ * This program is distributed in the hope that it will be useful,
|
||||
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
+ * GNU General Public License for more details.
|
||||
+ *
|
||||
+ * You should have received a copy of the GNU General Public License
|
||||
+ * along with this program; if not, write to the Free Software
|
||||
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
+ *
|
||||
+ */
|
||||
+
|
||||
+#ifndef __MTD_USER_H__
|
||||
+#define __MTD_USER_H__
|
||||
+
|
||||
+#include <stdint.h>
|
||||
+
|
||||
+/* This file is blessed for inclusion by userspace */
|
||||
+#include <mtd/mtd-abi.h>
|
||||
+
|
||||
+typedef struct mtd_info_user mtd_info_t;
|
||||
+typedef struct erase_info_user erase_info_t;
|
||||
+typedef struct region_info_user region_info_t;
|
||||
+typedef struct nand_oobinfo nand_oobinfo_t;
|
||||
+typedef struct nand_ecclayout_user nand_ecclayout_t;
|
||||
+
|
||||
+#endif /* __MTD_USER_H__ */
|
||||
--
|
||||
2.5.3
|
||||
|
||||
108
external/dist/busybox-patches/015-zcip.patch
vendored
Normal file
108
external/dist/busybox-patches/015-zcip.patch
vendored
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Mon, 19 Mar 2012 18:34:51 +0000
|
||||
Subject: [PATCH] fix zcip: struct ether_arp missing, use FreeBSD's
|
||||
|
||||
patch from 'struct-etherarp' by Dan Drown
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
---
|
||||
networking/struct-etherarp.h | 75 ++++++++++++++++++++++++++++++++++++++++++
|
||||
networking/zcip.c | 1 +
|
||||
2 files changed, 76 insertions(+), 0 deletions(-)
|
||||
create mode 100644 networking/struct-etherarp.h
|
||||
|
||||
diff --git a/networking/struct-etherarp.h b/networking/struct-etherarp.h
|
||||
new file mode 100644
|
||||
index 0000000..02a9c5b
|
||||
--- /dev/null
|
||||
+++ b/networking/struct-etherarp.h
|
||||
@@ -0,0 +1,75 @@
|
||||
+/*
|
||||
+ * Copyright (c) 1982, 1986, 1993
|
||||
+ * The Regents of the University of California. All rights reserved.
|
||||
+ *
|
||||
+ * Redistribution and use in source and binary forms, with or without
|
||||
+ * modification, are permitted provided that the following conditions
|
||||
+ * are met:
|
||||
+ * 1. Redistributions of source code must retain the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer.
|
||||
+ * 2. Redistributions in binary form must reproduce the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer in the
|
||||
+ * documentation and/or other materials provided with the distribution.
|
||||
+ * 4. Neither the name of the University nor the names of its contributors
|
||||
+ * may be used to endorse or promote products derived from this software
|
||||
+ * without specific prior written permission.
|
||||
+ *
|
||||
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
+ * SUCH DAMAGE.
|
||||
+ *
|
||||
+ * @(#)if_ether.h 8.3 (Berkeley) 5/2/95
|
||||
+ * $FreeBSD$
|
||||
+ */
|
||||
+#ifndef STRUCT_ETHERARP_H
|
||||
+#define STRUCT_ETHERARP_H 1
|
||||
+
|
||||
+#include <net/if_arp.h>
|
||||
+
|
||||
+/*
|
||||
+ * Macro to map an IP multicast address to an Ethernet multicast address.
|
||||
+ * The high-order 25 bits of the Ethernet address are statically assigned,
|
||||
+ * and the low-order 23 bits are taken from the low end of the IP address.
|
||||
+ */
|
||||
+#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
|
||||
+ /* struct in_addr *ipaddr; */ \
|
||||
+ /* u_char enaddr[ETH_ALEN]; */ \
|
||||
+{ \
|
||||
+ (enaddr)[0] = 0x01; \
|
||||
+ (enaddr)[1] = 0x00; \
|
||||
+ (enaddr)[2] = 0x5e; \
|
||||
+ (enaddr)[3] = ((u_int8_t *)ipaddr)[1] & 0x7f; \
|
||||
+ (enaddr)[4] = ((u_int8_t *)ipaddr)[2]; \
|
||||
+ (enaddr)[5] = ((u_int8_t *)ipaddr)[3]; \
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Ethernet Address Resolution Protocol.
|
||||
+ *
|
||||
+ * See RFC 826 for protocol description. Structure below is adapted
|
||||
+ * to resolving internet addresses. Field names used correspond to
|
||||
+ * RFC 826.
|
||||
+ */
|
||||
+struct ether_arp {
|
||||
+ struct arphdr ea_hdr; /* fixed-size header */
|
||||
+ u_int8_t arp_sha[ETH_ALEN]; /* sender hardware address */
|
||||
+ u_int8_t arp_spa[4]; /* sender protocol address */
|
||||
+ u_int8_t arp_tha[ETH_ALEN]; /* target hardware address */
|
||||
+ u_int8_t arp_tpa[4]; /* target protocol address */
|
||||
+};
|
||||
+#define arp_hrd ea_hdr.ar_hrd
|
||||
+#define arp_pro ea_hdr.ar_pro
|
||||
+#define arp_hln ea_hdr.ar_hln
|
||||
+#define arp_pln ea_hdr.ar_pln
|
||||
+#define arp_op ea_hdr.ar_op
|
||||
+
|
||||
+
|
||||
+#endif /* STRUCT_ETHERARP_H */
|
||||
diff --git a/networking/zcip.c b/networking/zcip.c
|
||||
index 7314ff8..52fcf57 100644
|
||||
--- a/networking/zcip.c
|
||||
+++ b/networking/zcip.c
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <net/if.h>
|
||||
#include <net/if_arp.h>
|
||||
#include <linux/sockios.h>
|
||||
+#include "struct-etherarp.h"
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
--
|
||||
1.7.0.4
|
||||
|
||||
32
external/dist/busybox-patches/016-a-swaponoff-syscalls.patch
vendored
Normal file
32
external/dist/busybox-patches/016-a-swaponoff-syscalls.patch
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Mon, 12 Sep 2016 14:31:31 -0300
|
||||
Subject: [PATCH 1/2] add swapoff/swapon syscalls for android
|
||||
|
||||
Patch by Tias Guns <tias@ulyssis.org>
|
||||
Rebased for busybox 1.25.0 by Chris Renshaw <osm0sis@outlook.com>
|
||||
---
|
||||
libbb/missing_syscalls.c | 10 ++++++++++
|
||||
1 file changed, 10 insertions(+)
|
||||
|
||||
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
|
||||
index dd430e3..235f4b8 100644
|
||||
--- a/libbb/missing_syscalls.c
|
||||
+++ b/libbb/missing_syscalls.c
|
||||
@@ -39,4 +39,14 @@ int pivot_root(const char *new_root, const char *put_old)
|
||||
{
|
||||
return syscall(__NR_pivot_root, new_root, put_old);
|
||||
}
|
||||
+
|
||||
+int swapoff(const char *path)
|
||||
+{
|
||||
+ return syscall(__NR_swapoff, path);
|
||||
+}
|
||||
+
|
||||
+int swapon(const char *path, int swapflags)
|
||||
+{
|
||||
+ return syscall(__NR_swapon, path, swapflags);
|
||||
+}
|
||||
|
||||
--
|
||||
2.8.3
|
||||
|
||||
32
external/dist/busybox-patches/016-b-swapon-swapoff.patch
vendored
Normal file
32
external/dist/busybox-patches/016-b-swapon-swapoff.patch
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Thu, 3 Dec 2015 11:19:25 -0400
|
||||
Subject: [PATCH] fix swapon, swapoff: comment out MNTOPT_NOAUTO
|
||||
|
||||
Patch modified by Tias Guns <tias@ulyssis.org> from 'swap-on-off' by Dan Drown
|
||||
"syscalls for swapon/swapoff and defines"
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
Rebased for busybox 1.24.1 by Chris Renshaw <osm0sis@outlook.com>
|
||||
---
|
||||
util-linux/swaponoff.c | 6 +++++-
|
||||
1 files changed, 5 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
|
||||
index 5cd1fbe..e447526 100644
|
||||
--- a/util-linux/swaponoff.c
|
||||
+++ b/util-linux/swaponoff.c
|
||||
@@ -186,7 +186,11 @@ static int do_em_all_in_fstab(void)
|
||||
/* swapon -a should ignore entries with noauto,
|
||||
* but swapoff -a should process them
|
||||
*/
|
||||
- if (do_swapoff || hasmntopt(m, MNTOPT_NOAUTO) == NULL) {
|
||||
+ if (do_swapoff
|
||||
+#ifdef MNTOPT_NOAUTO
|
||||
+ || hasmntopt(m, MNTOPT_NOAUTO) == NULL
|
||||
+#endif
|
||||
+ ) {
|
||||
/* each swap space might have different flags */
|
||||
/* save global flags for the next round */
|
||||
save_g_flags();
|
||||
--
|
||||
2.5.3
|
||||
|
||||
38
external/dist/busybox-patches/017-a-shmget-msgget-semget-syscalls.patch
vendored
Normal file
38
external/dist/busybox-patches/017-a-shmget-msgget-semget-syscalls.patch
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Mon, 12 Sep 2016 14:45:35 -0300
|
||||
Subject: [PATCH] android syscalls: shmget/msgget/semget
|
||||
|
||||
Patch modified by Tias Guns <tias@ulyssis.org> from 'no-sys-shm,msg,sem' by Dan Drown
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
Rebased for busybox 1.25.0 by Chris Renshaw <osm0sis@outlook.com>
|
||||
---
|
||||
libbb/missing_syscalls.c | 15 +++++++++++++++
|
||||
1 file changed, 15 insertions(+)
|
||||
|
||||
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
|
||||
index 235f4b8..a75a332 100644
|
||||
--- a/libbb/missing_syscalls.c
|
||||
+++ b/libbb/missing_syscalls.c
|
||||
@@ -49,4 +49,19 @@ int swapon(const char *path, int swapflags)
|
||||
{
|
||||
return syscall(__NR_swapon, path, swapflags);
|
||||
}
|
||||
+
|
||||
+int shmget(key_t key, size_t size, int shmflg)
|
||||
+{
|
||||
+ return syscall(__NR_shmget, key, size, shmflg);
|
||||
+}
|
||||
+
|
||||
+int msgget(key_t key, int msgflg)
|
||||
+{
|
||||
+ return syscall(__NR_msgget, key, msgflg);
|
||||
+}
|
||||
+
|
||||
+int semget(key_t key, int nsems, int semflg)
|
||||
+{
|
||||
+ return syscall(__NR_semget, key, nsems, semflg);
|
||||
+}
|
||||
|
||||
--
|
||||
2.8.3
|
||||
|
||||
35
external/dist/busybox-patches/017-b-msgctl-shmctl-syscalls.patch
vendored
Normal file
35
external/dist/busybox-patches/017-b-msgctl-shmctl-syscalls.patch
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Mon, 12 Sep 2016 14:46:40 -0300
|
||||
Subject: [PATCH] android syscalls: msgctl shmctl
|
||||
|
||||
Patch by Tias Guns <tias@ulyssis.org>
|
||||
Rebased for busybox 1.25.0 by Chris Renshaw <osm0sis@outlook.com>
|
||||
---
|
||||
libbb/missing_syscalls.c | 13 +++++++++++++
|
||||
1 file changed, 13 insertions(+)
|
||||
|
||||
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
|
||||
index a75a332..ac75829 100644
|
||||
--- a/libbb/missing_syscalls.c
|
||||
+++ b/libbb/missing_syscalls.c
|
||||
@@ -64,4 +64,17 @@ int semget(key_t key, int nsems, int semflg)
|
||||
{
|
||||
return syscall(__NR_semget, key, nsems, semflg);
|
||||
}
|
||||
+
|
||||
+struct msqid_ds; /* #include <linux/msg.h> */
|
||||
+int msgctl(int msqid, int cmd, struct msqid_ds *buf)
|
||||
+{
|
||||
+ return syscall(__NR_msgctl, msqid, cmd, buf);
|
||||
+}
|
||||
+
|
||||
+struct shmid_ds; /* #include <linux/shm.h> */
|
||||
+// NOTE: IPC_INFO takes a struct shminfo64
|
||||
+int shmctl(int shmid, int cmd, struct shmid_ds *buf)
|
||||
+{
|
||||
+ return syscall(__NR_shmctl, shmid, cmd, buf);
|
||||
+}
|
||||
|
||||
--
|
||||
2.8.3
|
||||
|
||||
83
external/dist/busybox-patches/017-c-semctl-syscall.patch
vendored
Normal file
83
external/dist/busybox-patches/017-c-semctl-syscall.patch
vendored
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Sun, 5 Aug 2012 15:25:34 +0200
|
||||
Subject: [PATCH] android syscall (non-trivial): semctl
|
||||
|
||||
needed by ipcs and ipcrm, also needed (but not sufficient) for syslogd and logread
|
||||
|
||||
semctl from glibc
|
||||
patch from 'no-sys-shm,msg,sem' by Dan Drown
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
|
||||
Signed-off-by: Tias Guns <tias@ulyssis.org>
|
||||
---
|
||||
libbb/semctl.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 58 insertions(+)
|
||||
create mode 100644 libbb/semctl.c
|
||||
|
||||
diff --git a/libbb/semctl.c b/libbb/semctl.c
|
||||
new file mode 100644
|
||||
index 0000000..68f846a
|
||||
--- /dev/null
|
||||
+++ b/libbb/semctl.c
|
||||
@@ -0,0 +1,58 @@
|
||||
+/* Copyright (C) 1995,1997,1998,2000,2003,2004,2006
|
||||
+ Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+ Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, write to the Free
|
||||
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
+ 02111-1307 USA. */
|
||||
+/* originally from glibc-2.14/sysdeps/unix/sysv/linux/semctl.c, modified */
|
||||
+
|
||||
+// syscall used by syslogd, ipcrm, ipcs
|
||||
+//kbuild:lib-y += semctl.o
|
||||
+
|
||||
+#include <sys/syscall.h> /* For __NR_xxx definitions */
|
||||
+#include <stdarg.h>
|
||||
+#include <linux/sem.h>
|
||||
+#include "libbb.h"
|
||||
+
|
||||
+/* code from GLIBC */
|
||||
+int semctl(int semid, int semnum, int cmd, ...) {
|
||||
+ union semun arg;
|
||||
+ va_list ap;
|
||||
+
|
||||
+ va_start (ap, cmd);
|
||||
+
|
||||
+ /* Get the argument only if required. */
|
||||
+ arg.buf = NULL;
|
||||
+ switch (cmd)
|
||||
+ {
|
||||
+ case SETVAL: /* arg.val */
|
||||
+ case GETALL: /* arg.array */
|
||||
+ case SETALL:
|
||||
+ case IPC_STAT: /* arg.buf */
|
||||
+ case IPC_SET:
|
||||
+ case SEM_STAT:
|
||||
+ case IPC_INFO: /* arg.__buf */
|
||||
+ case SEM_INFO:
|
||||
+ va_start (ap, cmd);
|
||||
+ arg = va_arg (ap, union semun);
|
||||
+ va_end (ap);
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ va_end (ap);
|
||||
+
|
||||
+ return syscall(__NR_semctl, semid, semnum, cmd, arg);
|
||||
+}
|
||||
--
|
||||
1.7.10.4
|
||||
|
||||
64
external/dist/busybox-patches/017-d-ipcs-ipcrm.patch
vendored
Normal file
64
external/dist/busybox-patches/017-d-ipcs-ipcrm.patch
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Tue, 20 Mar 2012 21:26:07 +0000
|
||||
Subject: [PATCH] fix ipcs, ipcrm no sys/sem-shm-msg, use linux/sem.h etc
|
||||
|
||||
patch from 'no-sys-shm,msg,sem' by Dan Drown
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
|
||||
Signed-off-by: Tias Guns <tias@ulyssis.org>
|
||||
---
|
||||
util-linux/ipcrm.c | 9 +++++----
|
||||
util-linux/ipcs.c | 9 +++++----
|
||||
2 files changed, 10 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/util-linux/ipcrm.c b/util-linux/ipcrm.c
|
||||
index 274050c..b65e8ef 100644
|
||||
--- a/util-linux/ipcrm.c
|
||||
+++ b/util-linux/ipcrm.c
|
||||
@@ -22,11 +22,12 @@
|
||||
/* X/OPEN tells us to use <sys/{types,ipc,sem}.h> for semctl() */
|
||||
/* X/OPEN tells us to use <sys/{types,ipc,msg}.h> for msgctl() */
|
||||
#include <sys/ipc.h>
|
||||
-#include <sys/shm.h>
|
||||
-#include <sys/msg.h>
|
||||
-#include <sys/sem.h>
|
||||
+#include <linux/shm.h>
|
||||
+#include <linux/msg.h>
|
||||
+#include <linux/sem.h>
|
||||
|
||||
-#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
|
||||
+#if (defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)) || \
|
||||
+ defined(__ANDROID__)
|
||||
/* union semun is defined by including <sys/sem.h> */
|
||||
#else
|
||||
/* according to X/OPEN we have to define it ourselves */
|
||||
diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c
|
||||
index ee7df5e..fafe4e3 100644
|
||||
--- a/util-linux/ipcs.c
|
||||
+++ b/util-linux/ipcs.c
|
||||
@@ -29,9 +29,9 @@
|
||||
/* X/OPEN tells us to use <sys/{types,ipc,shm}.h> for shmctl() */
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
-#include <sys/sem.h>
|
||||
-#include <sys/msg.h>
|
||||
-#include <sys/shm.h>
|
||||
+#include <linux/sem.h>
|
||||
+#include <linux/msg.h>
|
||||
+#include <linux/shm.h>
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
@@ -77,7 +77,8 @@ struct shm_info {
|
||||
/* The last arg of semctl is a union semun, but where is it defined?
|
||||
X/OPEN tells us to define it ourselves, but until recently
|
||||
Linux include files would also define it. */
|
||||
-#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
|
||||
+#if (defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)) || \
|
||||
+ defined(__ANDROID__)
|
||||
/* union semun is defined by including <sys/sem.h> */
|
||||
#else
|
||||
/* according to X/OPEN we have to define it ourselves */
|
||||
--
|
||||
1.7.10.4
|
||||
|
||||
45
external/dist/busybox-patches/017-e-semop-shmdt-syscalls.patch
vendored
Normal file
45
external/dist/busybox-patches/017-e-semop-shmdt-syscalls.patch
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Mon, 12 Sep 2016 14:48:30 -0300
|
||||
Subject: [PATCH] android syscalls: shmdt shmat sembuf
|
||||
|
||||
Patch by Tias Guns <tias@ulyssis.org>
|
||||
Rebased for busybox 1.25.0 by Chris Renshaw <osm0sis@outlook.com>
|
||||
---
|
||||
libbb/missing_syscalls.c | 16 ++++++++++++++++
|
||||
1 file changed, 16 insertions(+)
|
||||
|
||||
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
|
||||
index ac75829..474accb 100644
|
||||
--- a/libbb/missing_syscalls.c
|
||||
+++ b/libbb/missing_syscalls.c
|
||||
@@ -55,6 +55,16 @@ int shmget(key_t key, size_t size, int shmflg)
|
||||
return syscall(__NR_shmget, key, size, shmflg);
|
||||
}
|
||||
|
||||
+int shmdt(const void *shmaddr)
|
||||
+{
|
||||
+ return syscall(__NR_shmdt, shmaddr);
|
||||
+}
|
||||
+
|
||||
+void *shmat(int shmid, const void *shmaddr, int shmflg)
|
||||
+{
|
||||
+ return (void *)syscall(__NR_shmat, shmid, shmaddr, shmflg);
|
||||
+}
|
||||
+
|
||||
int msgget(key_t key, int msgflg)
|
||||
{
|
||||
return syscall(__NR_msgget, key, msgflg);
|
||||
@@ -77,4 +87,10 @@ int shmctl(int shmid, int cmd, struct shmid_ds *buf)
|
||||
{
|
||||
return syscall(__NR_shmctl, shmid, cmd, buf);
|
||||
}
|
||||
+
|
||||
+struct sembuf; /* #include <linux/sem.h> */
|
||||
+int semop(int semid, struct sembuf *sops, unsigned nsops)
|
||||
+{
|
||||
+ return syscall(__NR_semop, semid, sops, nsops);
|
||||
+}
|
||||
|
||||
--
|
||||
2.8.3
|
||||
|
||||
204
external/dist/busybox-patches/017-f-syslogd-logread.patch
vendored
Normal file
204
external/dist/busybox-patches/017-f-syslogd-logread.patch
vendored
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Tue, 20 Mar 2012 21:30:10 +0000
|
||||
Subject: [PATCH] fix syslogd, logread: add syslog.h, semop shmdt-at
|
||||
|
||||
patch from 'no-sys-shm,msg,sem' and 'sys-syslog' by Dan Drown
|
||||
"sys/syslog.h header for syslogd"
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
---
|
||||
include/sys/syslog.h | 138 +++++++++++++++++++++++++++++++++++++++++
|
||||
sysklogd/logread.c | 4 +-
|
||||
sysklogd/syslogd.c | 4 +-
|
||||
sysklogd/syslogd_and_logger.c | 1 +
|
||||
4 files changed, 143 insertions(+), 4 deletions(-)
|
||||
create mode 100644 include/sys/syslog.h
|
||||
|
||||
diff --git a/include/sys/syslog.h b/include/sys/syslog.h
|
||||
new file mode 100644
|
||||
index 0000000..3c749a0
|
||||
--- /dev/null
|
||||
+++ b/include/sys/syslog.h
|
||||
@@ -0,0 +1,138 @@
|
||||
+/*
|
||||
+ * Copyright (c) 1982, 1986, 1988, 1993
|
||||
+ * The Regents of the University of California. All rights reserved.
|
||||
+ *
|
||||
+ * Redistribution and use in source and binary forms, with or without
|
||||
+ * modification, are permitted provided that the following conditions
|
||||
+ * are met:
|
||||
+ * 1. Redistributions of source code must retain the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer.
|
||||
+ * 2. Redistributions in binary form must reproduce the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer in the
|
||||
+ * documentation and/or other materials provided with the distribution.
|
||||
+ * 4. Neither the name of the University nor the names of its contributors
|
||||
+ * may be used to endorse or promote products derived from this software
|
||||
+ * without specific prior written permission.
|
||||
+ *
|
||||
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
+ * SUCH DAMAGE.
|
||||
+ *
|
||||
+ * @(#)syslog.h 8.1 (Berkeley) 6/2/93
|
||||
+ *
|
||||
+ * 2011/7/5 - DD - modified to fit android Bionic environment
|
||||
+ */
|
||||
+
|
||||
+#ifndef _SYS_SYSLOG_H
|
||||
+#define _SYS_SYSLOG_H 1
|
||||
+
|
||||
+#include <features.h>
|
||||
+#define __need___va_list
|
||||
+#include <stdarg.h>
|
||||
+
|
||||
+/*
|
||||
+ * priorities/facilities are encoded into a single 32-bit quantity, where the
|
||||
+ * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
|
||||
+ * (0-big number). Both the priorities and the facilities map roughly
|
||||
+ * one-to-one to strings in the syslogd(8) source code. This mapping is
|
||||
+ * included in this file.
|
||||
+ *
|
||||
+ * priorities (these are ordered)
|
||||
+ */
|
||||
+#define LOG_EMERG 0 /* system is unusable */
|
||||
+#define LOG_ALERT 1 /* action must be taken immediately */
|
||||
+#define LOG_CRIT 2 /* critical conditions */
|
||||
+#define LOG_ERR 3 /* error conditions */
|
||||
+#define LOG_WARNING 4 /* warning conditions */
|
||||
+#define LOG_NOTICE 5 /* normal but significant condition */
|
||||
+#define LOG_INFO 6 /* informational */
|
||||
+#define LOG_DEBUG 7 /* debug-level messages */
|
||||
+
|
||||
+#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
|
||||
+
|
||||
+#ifdef SYSLOG_NAMES
|
||||
+#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
|
||||
+ /* mark "facility" */
|
||||
+#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0)
|
||||
+typedef struct _code {
|
||||
+ char *c_name;
|
||||
+ int c_val;
|
||||
+} CODE;
|
||||
+
|
||||
+CODE prioritynames[] =
|
||||
+ {
|
||||
+ { "alert", LOG_ALERT },
|
||||
+ { "crit", LOG_CRIT },
|
||||
+ { "debug", LOG_DEBUG },
|
||||
+ { "emerg", LOG_EMERG },
|
||||
+ { "err", LOG_ERR },
|
||||
+ { "error", LOG_ERR }, /* DEPRECATED */
|
||||
+ { "info", LOG_INFO },
|
||||
+ { "none", INTERNAL_NOPRI }, /* INTERNAL */
|
||||
+ { "notice", LOG_NOTICE },
|
||||
+ { "panic", LOG_EMERG }, /* DEPRECATED */
|
||||
+ { "warn", LOG_WARNING }, /* DEPRECATED */
|
||||
+ { "warning", LOG_WARNING },
|
||||
+ { NULL, -1 }
|
||||
+ };
|
||||
+#endif
|
||||
+
|
||||
+#define LOG_NFACILITIES 24 /* current number of facilities */
|
||||
+
|
||||
+#ifdef SYSLOG_NAMES
|
||||
+CODE facilitynames[] =
|
||||
+ {
|
||||
+ { "auth", LOG_AUTH },
|
||||
+ { "authpriv", LOG_AUTHPRIV },
|
||||
+ { "cron", LOG_CRON },
|
||||
+ { "daemon", LOG_DAEMON },
|
||||
+ { "ftp", LOG_FTP },
|
||||
+ { "kern", LOG_KERN },
|
||||
+ { "lpr", LOG_LPR },
|
||||
+ { "mail", LOG_MAIL },
|
||||
+ { "mark", INTERNAL_MARK }, /* INTERNAL */
|
||||
+ { "news", LOG_NEWS },
|
||||
+ { "security", LOG_AUTH }, /* DEPRECATED */
|
||||
+ { "syslog", LOG_SYSLOG },
|
||||
+ { "user", LOG_USER },
|
||||
+ { "uucp", LOG_UUCP },
|
||||
+ { "local0", LOG_LOCAL0 },
|
||||
+ { "local1", LOG_LOCAL1 },
|
||||
+ { "local2", LOG_LOCAL2 },
|
||||
+ { "local3", LOG_LOCAL3 },
|
||||
+ { "local4", LOG_LOCAL4 },
|
||||
+ { "local5", LOG_LOCAL5 },
|
||||
+ { "local6", LOG_LOCAL6 },
|
||||
+ { "local7", LOG_LOCAL7 },
|
||||
+ { NULL, -1 }
|
||||
+ };
|
||||
+#endif
|
||||
+
|
||||
+/*
|
||||
+ * arguments to setlogmask.
|
||||
+ */
|
||||
+#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */
|
||||
+#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */
|
||||
+
|
||||
+/*
|
||||
+ * Option flags for openlog.
|
||||
+ *
|
||||
+ * LOG_ODELAY no longer does anything.
|
||||
+ * LOG_NDELAY is the inverse of what it used to be.
|
||||
+ */
|
||||
+#define LOG_PID 0x01 /* log the pid with each message */
|
||||
+#define LOG_CONS 0x02 /* log on the console if errors in sending */
|
||||
+#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */
|
||||
+#define LOG_NDELAY 0x08 /* don't delay open */
|
||||
+#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
|
||||
+#define LOG_PERROR 0x20 /* log to stderr as well */
|
||||
+
|
||||
+#endif /* sys/syslog.h */
|
||||
diff --git a/sysklogd/logread.c b/sysklogd/logread.c
|
||||
index 9939569..e978a5d 100644
|
||||
--- a/sysklogd/logread.c
|
||||
+++ b/sysklogd/logread.c
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
#include "libbb.h"
|
||||
#include <sys/ipc.h>
|
||||
-#include <sys/sem.h>
|
||||
-#include <sys/shm.h>
|
||||
+#include <linux/sem.h>
|
||||
+#include <linux/shm.h>
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
|
||||
index fc380d9..1365bb8 100644
|
||||
--- a/sysklogd/syslogd.c
|
||||
+++ b/sysklogd/syslogd.c
|
||||
@@ -65,8 +65,8 @@
|
||||
|
||||
#if ENABLE_FEATURE_IPC_SYSLOG
|
||||
#include <sys/ipc.h>
|
||||
-#include <sys/sem.h>
|
||||
-#include <sys/shm.h>
|
||||
+#include <linux/sem.h>
|
||||
+#include <linux/shm.h>
|
||||
#endif
|
||||
|
||||
|
||||
diff --git a/sysklogd/syslogd_and_logger.c b/sysklogd/syslogd_and_logger.c
|
||||
index 0964f23..81c8909 100644
|
||||
--- a/sysklogd/syslogd_and_logger.c
|
||||
+++ b/sysklogd/syslogd_and_logger.c
|
||||
@@ -11,6 +11,7 @@
|
||||
#define SYSLOG_NAMES
|
||||
#define SYSLOG_NAMES_CONST
|
||||
#include <syslog.h>
|
||||
+#include <sys/syslog.h>
|
||||
|
||||
#if 0
|
||||
/* For the record: with SYSLOG_NAMES <syslog.h> defines
|
||||
--
|
||||
1.7.10.4
|
||||
|
||||
29
external/dist/busybox-patches/018-blkdiscard.patch
vendored
Normal file
29
external/dist/busybox-patches/018-blkdiscard.patch
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Tue, 13 Sep 2016 00:24:56 -0300
|
||||
Subject: [PATCH] blkdiscard; add missing linux/fs.h defines to libbb.h for ANDROID API <21
|
||||
|
||||
Imported from dorimanx's combined ported header toolchain:
|
||||
https://github.com/dorimanx/android-busybox-ndk
|
||||
---
|
||||
include/libbb.h | 5 +++++
|
||||
1 file changed, 5 insertions(+)
|
||||
|
||||
diff --git a/include/libbb.h b/include/libbb.h
|
||||
index 657fff1..e55e575 100644
|
||||
--- a/include/libbb.h
|
||||
+++ b/include/libbb.h
|
||||
@@ -65,6 +65,11 @@
|
||||
#if defined(ANDROID) || defined(__ANDROID__)
|
||||
# define endpwent() ((void)0)
|
||||
# define endgrent() ((void)0)
|
||||
+# if __ANDROID_API__ < 21
|
||||
+# define BLKDISCARD _IO(0x12,119)
|
||||
+# define BLKDISCARDZEROES _IO(0x12,124)
|
||||
+# define BLKSECDISCARD _IO(0x12,125)
|
||||
+# endif
|
||||
#endif
|
||||
#ifdef HAVE_MNTENT_H
|
||||
# include <mntent.h>
|
||||
--
|
||||
2.8.3
|
||||
|
||||
46
external/dist/busybox-patches/019-fsck.minix-mkfs.minix.patch
vendored
Normal file
46
external/dist/busybox-patches/019-fsck.minix-mkfs.minix.patch
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Tue, 20 Mar 2012 22:05:07 +0000
|
||||
Subject: [PATCH] fix fsck.minix, mkfs.minix: undef HAVE_SETBIT,
|
||||
MINIX2_SUPER_MAGIC, MINIX2_SUPER_MAGIC
|
||||
|
||||
from 'no-setbit' by Dan Drown
|
||||
"there is no setbit/clrbit in bionic"
|
||||
from 'undefine-minix2-magic-to-use-in-enum' by Dan Drown
|
||||
"MINIX2_SUPER_MAGIC / MINIX2_SUPER_MAGIC2 defined in sys/vfs.h, undefine
|
||||
it to use it in the enum"
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
|
||||
Signed-off-by: Tias Guns <tias@ulyssis.org>
|
||||
---
|
||||
include/platform.h | 1 +
|
||||
util-linux/minix.h | 2 ++
|
||||
2 files changed, 3 insertions(+)
|
||||
|
||||
diff --git a/include/platform.h b/include/platform.h
|
||||
index 3e101ba..30bcff6 100644
|
||||
--- a/include/platform.h
|
||||
+++ b/include/platform.h
|
||||
@@ -449,6 +449,7 @@ typedef unsigned smalluint;
|
||||
# undef HAVE_STRVERSCMP
|
||||
# undef HAVE_UNLOCKED_LINE_OPS
|
||||
# undef HAVE_NET_ETHERNET_H
|
||||
+# undef HAVE_SETBIT
|
||||
#endif
|
||||
|
||||
/*
|
||||
diff --git a/util-linux/minix.h b/util-linux/minix.h
|
||||
index e0fbcf7..060fab0 100644
|
||||
--- a/util-linux/minix.h
|
||||
+++ b/util-linux/minix.h
|
||||
@@ -54,6 +54,8 @@ struct minix_dir_entry {
|
||||
/* Believe it or not, but mount.h has this one #defined */
|
||||
#undef BLOCK_SIZE
|
||||
|
||||
+#undef MINIX2_SUPER_MAGIC
|
||||
+#undef MINIX2_SUPER_MAGIC2
|
||||
enum {
|
||||
BLOCK_SIZE = 1024,
|
||||
BITS_PER_BLOCK = BLOCK_SIZE << 3,
|
||||
--
|
||||
1.7.10.4
|
||||
|
||||
67
external/dist/busybox-patches/01_missing_interface_x86_patch.patch
vendored
Normal file
67
external/dist/busybox-patches/01_missing_interface_x86_patch.patch
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
diff -Naur busybox-1.26.2-orig/libbb/missing_syscalls.c busybox-1.26.2/libbb/missing_syscalls.c
|
||||
--- busybox-1.26.2-orig/libbb/missing_syscalls.c 2016-09-27 22:23:50.000000000 +0530
|
||||
+++ busybox-1.26.2/libbb/missing_syscalls.c 2017-03-01 21:20:34.367667904 +0530
|
||||
@@ -10,6 +10,50 @@
|
||||
#include <sys/syscall.h>
|
||||
#include "libbb.h"
|
||||
|
||||
+#ifndef __NR_shmget
|
||||
+#define __NR_shmget 29
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __NR_shmat
|
||||
+#define __NR_shmat 30
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __NR_shmctl
|
||||
+#define __NR_shmctl 31
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __NR_semget
|
||||
+#define __NR_semget 64
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __NR_semop
|
||||
+#define __NR_semop 65
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __NR_semctl
|
||||
+#define __NR_semctl 66
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __NR_shmdt
|
||||
+#define __NR_shmdt 67
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __NR_msgget
|
||||
+#define __NR_msgget 68
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __NR_msgsnd
|
||||
+#define __NR_msgsnd 69
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __NR_msgrcv
|
||||
+#define __NR_msgrcv 70
|
||||
+#endif
|
||||
+
|
||||
+#ifndef __NR_msgctl
|
||||
+#define __NR_msgctl 71
|
||||
+#endif
|
||||
+
|
||||
#if defined(ANDROID) || defined(__ANDROID__)
|
||||
pid_t getsid(pid_t pid)
|
||||
{
|
||||
diff -Naur busybox-1.26.2-orig/libbb/semctl.c busybox-1.26.2/libbb/semctl.c
|
||||
--- busybox-1.26.2-orig/libbb/semctl.c 2017-03-01 21:13:12.851652181 +0530
|
||||
+++ busybox-1.26.2/libbb/semctl.c 2017-02-28 08:35:47.947890893 +0530
|
||||
@@ -27,6 +27,9 @@
|
||||
#include <linux/sem.h>
|
||||
#include "libbb.h"
|
||||
|
||||
+#ifndef __NR_semctl
|
||||
+#define __NR_semctl 66
|
||||
+#endif
|
||||
/* code from GLIBC */
|
||||
int semctl(int semid, int semnum, int cmd, ...) {
|
||||
union semun arg;
|
||||
187
external/dist/busybox-patches/020-microcom.patch
vendored
Normal file
187
external/dist/busybox-patches/020-microcom.patch
vendored
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Tue, 20 Mar 2012 23:45:32 +0000
|
||||
Subject: [PATCH] fix microcom, add cfsetspeed syscall from glibc
|
||||
|
||||
based on 'misc-syscalls' by Dan Drown
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
|
||||
Signed-off-by: Tias Guns <tias@ulyssis.org>
|
||||
---
|
||||
libbb/cfsetspeed.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 165 insertions(+)
|
||||
create mode 100644 libbb/cfsetspeed.c
|
||||
|
||||
diff --git a/libbb/cfsetspeed.c b/libbb/cfsetspeed.c
|
||||
new file mode 100644
|
||||
index 0000000..ccf321a
|
||||
--- /dev/null
|
||||
+++ b/libbb/cfsetspeed.c
|
||||
@@ -0,0 +1,165 @@
|
||||
+/* Copyright (C) 1992,93,96,97,98,2001 Free Software Foundation, Inc.
|
||||
+ This file is part of the GNU C Library.
|
||||
+
|
||||
+ The GNU C Library is free software; you can redistribute it and/or
|
||||
+ modify it under the terms of the GNU Lesser General Public
|
||||
+ License as published by the Free Software Foundation; either
|
||||
+ version 2.1 of the License, or (at your option) any later version.
|
||||
+
|
||||
+ The GNU C Library is distributed in the hope that it will be useful,
|
||||
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
+ Lesser General Public License for more details.
|
||||
+
|
||||
+ You should have received a copy of the GNU Lesser General Public
|
||||
+ License along with the GNU C Library; if not, write to the Free
|
||||
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
+ 02111-1307 USA. */
|
||||
+
|
||||
+//kbuild:lib-$(CONFIG_MICROCOM) += cfsetspeed.o
|
||||
+//kbuild:lib-$(CONFIG_GETTY) += cfsetspeed.o
|
||||
+
|
||||
+#include <termios.h>
|
||||
+#include <errno.h>
|
||||
+#include <stddef.h>
|
||||
+
|
||||
+struct speed_struct
|
||||
+{
|
||||
+ speed_t value;
|
||||
+ speed_t internal;
|
||||
+};
|
||||
+
|
||||
+static const struct speed_struct speeds[] =
|
||||
+ {
|
||||
+#ifdef B0
|
||||
+ { 0, B0 },
|
||||
+#endif
|
||||
+#ifdef B50
|
||||
+ { 50, B50 },
|
||||
+#endif
|
||||
+#ifdef B75
|
||||
+ { 75, B75 },
|
||||
+#endif
|
||||
+#ifdef B110
|
||||
+ { 110, B110 },
|
||||
+#endif
|
||||
+#ifdef B134
|
||||
+ { 134, B134 },
|
||||
+#endif
|
||||
+#ifdef B150
|
||||
+ { 150, B150 },
|
||||
+#endif
|
||||
+#ifdef B200
|
||||
+ { 200, B200 },
|
||||
+#endif
|
||||
+#ifdef B300
|
||||
+ { 300, B300 },
|
||||
+#endif
|
||||
+#ifdef B600
|
||||
+ { 600, B600 },
|
||||
+#endif
|
||||
+#ifdef B1200
|
||||
+ { 1200, B1200 },
|
||||
+#endif
|
||||
+#ifdef B1200
|
||||
+ { 1200, B1200 },
|
||||
+#endif
|
||||
+#ifdef B1800
|
||||
+ { 1800, B1800 },
|
||||
+#endif
|
||||
+#ifdef B2400
|
||||
+ { 2400, B2400 },
|
||||
+#endif
|
||||
+#ifdef B4800
|
||||
+ { 4800, B4800 },
|
||||
+#endif
|
||||
+#ifdef B9600
|
||||
+ { 9600, B9600 },
|
||||
+#endif
|
||||
+#ifdef B19200
|
||||
+ { 19200, B19200 },
|
||||
+#endif
|
||||
+#ifdef B38400
|
||||
+ { 38400, B38400 },
|
||||
+#endif
|
||||
+#ifdef B57600
|
||||
+ { 57600, B57600 },
|
||||
+#endif
|
||||
+#ifdef B76800
|
||||
+ { 76800, B76800 },
|
||||
+#endif
|
||||
+#ifdef B115200
|
||||
+ { 115200, B115200 },
|
||||
+#endif
|
||||
+#ifdef B153600
|
||||
+ { 153600, B153600 },
|
||||
+#endif
|
||||
+#ifdef B230400
|
||||
+ { 230400, B230400 },
|
||||
+#endif
|
||||
+#ifdef B307200
|
||||
+ { 307200, B307200 },
|
||||
+#endif
|
||||
+#ifdef B460800
|
||||
+ { 460800, B460800 },
|
||||
+#endif
|
||||
+#ifdef B500000
|
||||
+ { 500000, B500000 },
|
||||
+#endif
|
||||
+#ifdef B576000
|
||||
+ { 576000, B576000 },
|
||||
+#endif
|
||||
+#ifdef B921600
|
||||
+ { 921600, B921600 },
|
||||
+#endif
|
||||
+#ifdef B1000000
|
||||
+ { 1000000, B1000000 },
|
||||
+#endif
|
||||
+#ifdef B1152000
|
||||
+ { 1152000, B1152000 },
|
||||
+#endif
|
||||
+#ifdef B1500000
|
||||
+ { 1500000, B1500000 },
|
||||
+#endif
|
||||
+#ifdef B2000000
|
||||
+ { 2000000, B2000000 },
|
||||
+#endif
|
||||
+#ifdef B2500000
|
||||
+ { 2500000, B2500000 },
|
||||
+#endif
|
||||
+#ifdef B3000000
|
||||
+ { 3000000, B3000000 },
|
||||
+#endif
|
||||
+#ifdef B3500000
|
||||
+ { 3500000, B3500000 },
|
||||
+#endif
|
||||
+#ifdef B4000000
|
||||
+ { 4000000, B4000000 },
|
||||
+#endif
|
||||
+ };
|
||||
+
|
||||
+
|
||||
+/* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */
|
||||
+int
|
||||
+cfsetspeed (struct termios *termios_p, speed_t speed)
|
||||
+{
|
||||
+ size_t cnt;
|
||||
+
|
||||
+ for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt)
|
||||
+ if (speed == speeds[cnt].internal)
|
||||
+ {
|
||||
+ cfsetispeed (termios_p, speed);
|
||||
+ cfsetospeed (termios_p, speed);
|
||||
+ return 0;
|
||||
+ }
|
||||
+ else if (speed == speeds[cnt].value)
|
||||
+ {
|
||||
+ cfsetispeed (termios_p, speeds[cnt].internal);
|
||||
+ cfsetospeed (termios_p, speeds[cnt].internal);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ __set_errno (EINVAL);
|
||||
+
|
||||
+ return -1;
|
||||
+}
|
||||
--
|
||||
1.7.10.4
|
||||
|
||||
1249
external/dist/busybox-patches/021-ipneigh-iproute-iprule.patch
vendored
Normal file
1249
external/dist/busybox-patches/021-ipneigh-iproute-iprule.patch
vendored
Normal file
File diff suppressed because it is too large
Load diff
114
external/dist/busybox-patches/022-ipv6.patch
vendored
Normal file
114
external/dist/busybox-patches/022-ipv6.patch
vendored
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
From c04d001c962e756d152abc1dbd58edfdbfee45a1 Mon Sep 17 00:00:00 2001
|
||||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Mon, 19 Mar 2012 18:24:29 +0000
|
||||
Subject: [PATCH] fix ipv6, add ipv6_route.h
|
||||
|
||||
from 'in6_rtmsg' by Dan Drown
|
||||
"in6_rtmsg defined in linux/ipv6_route.h"
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
---
|
||||
include/linux/ipv6_route.h | 58 ++++++++++++++++++++++++++++++++++++++++++++
|
||||
networking/ifconfig.c | 2 +
|
||||
networking/route.c | 2 +
|
||||
3 files changed, 62 insertions(+), 0 deletions(-)
|
||||
create mode 100644 include/linux/ipv6_route.h
|
||||
|
||||
diff --git a/include/linux/ipv6_route.h b/include/linux/ipv6_route.h
|
||||
new file mode 100644
|
||||
index 0000000..144875d
|
||||
--- /dev/null
|
||||
+++ b/include/linux/ipv6_route.h
|
||||
@@ -0,0 +1,58 @@
|
||||
+/*
|
||||
+ * Linux INET6 implementation
|
||||
+ *
|
||||
+ * Authors:
|
||||
+ * Pedro Roque <roque@di.fc.ul.pt>
|
||||
+ *
|
||||
+ * This program is free software; you can redistribute it and/or
|
||||
+ * modify it under the terms of the GNU General Public License
|
||||
+ * as published by the Free Software Foundation; either version
|
||||
+ * 2 of the License, or (at your option) any later version.
|
||||
+ */
|
||||
+
|
||||
+#ifndef _LINUX_IPV6_ROUTE_H
|
||||
+#define _LINUX_IPV6_ROUTE_H
|
||||
+
|
||||
+#include <linux/types.h>
|
||||
+
|
||||
+#define RTF_DEFAULT 0x00010000 /* default - learned via ND */
|
||||
+#define RTF_ALLONLINK 0x00020000 /* (deprecated and will be removed)
|
||||
+ fallback, no routers on link */
|
||||
+#define RTF_ADDRCONF 0x00040000 /* addrconf route - RA */
|
||||
+#define RTF_PREFIX_RT 0x00080000 /* A prefix only route - RA */
|
||||
+#define RTF_ANYCAST 0x00100000 /* Anycast */
|
||||
+
|
||||
+#define RTF_NONEXTHOP 0x00200000 /* route with no nexthop */
|
||||
+#define RTF_EXPIRES 0x00400000
|
||||
+
|
||||
+#define RTF_ROUTEINFO 0x00800000 /* route information - RA */
|
||||
+
|
||||
+#define RTF_CACHE 0x01000000 /* cache entry */
|
||||
+#define RTF_FLOW 0x02000000 /* flow significant route */
|
||||
+#define RTF_POLICY 0x04000000 /* policy route */
|
||||
+
|
||||
+#define RTF_PREF(pref) ((pref) << 27)
|
||||
+#define RTF_PREF_MASK 0x18000000
|
||||
+
|
||||
+#define RTF_LOCAL 0x80000000
|
||||
+
|
||||
+
|
||||
+struct in6_rtmsg {
|
||||
+ struct in6_addr rtmsg_dst;
|
||||
+ struct in6_addr rtmsg_src;
|
||||
+ struct in6_addr rtmsg_gateway;
|
||||
+ __u32 rtmsg_type;
|
||||
+ __u16 rtmsg_dst_len;
|
||||
+ __u16 rtmsg_src_len;
|
||||
+ __u32 rtmsg_metric;
|
||||
+ unsigned long rtmsg_info;
|
||||
+ __u32 rtmsg_flags;
|
||||
+ int rtmsg_ifindex;
|
||||
+};
|
||||
+
|
||||
+#define RTMSG_NEWDEVICE 0x11
|
||||
+#define RTMSG_DELDEVICE 0x12
|
||||
+#define RTMSG_NEWROUTE 0x21
|
||||
+#define RTMSG_DELROUTE 0x22
|
||||
+
|
||||
+#endif
|
||||
diff --git a/networking/ifconfig.c b/networking/ifconfig.c
|
||||
index b6604f5..12e8198 100644
|
||||
--- a/networking/ifconfig.c
|
||||
+++ b/networking/ifconfig.c
|
||||
@@ -79,12 +79,14 @@
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_IPV6
|
||||
+#ifndef __BIONIC__
|
||||
struct in6_ifreq {
|
||||
struct in6_addr ifr6_addr;
|
||||
uint32_t ifr6_prefixlen;
|
||||
int ifr6_ifindex;
|
||||
};
|
||||
#endif
|
||||
+#endif
|
||||
|
||||
/*
|
||||
* Here are the bit masks for the "flags" member of struct options below.
|
||||
diff --git a/networking/route.c b/networking/route.c
|
||||
index b7b5a02..a060eb2 100644
|
||||
--- a/networking/route.c
|
||||
+++ b/networking/route.c
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
#include <net/route.h>
|
||||
#include <net/if.h>
|
||||
+#include <linux/in6.h>
|
||||
+#include <linux/ipv6_route.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "inet_common.h"
|
||||
--
|
||||
1.7.0.4
|
||||
|
||||
970
external/dist/busybox-patches/024-hush.patch
vendored
Normal file
970
external/dist/busybox-patches/024-hush.patch
vendored
Normal file
|
|
@ -0,0 +1,970 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Tue, 10 Jan 2017 10:49:59 -0400
|
||||
Subject: [PATCH] fix hush, add glob and sigisemptyset
|
||||
|
||||
Patch by Tias Guns <tias@ulyssis.org>, based on 'glob' by Dan Drown
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
Rebased for busybox 1.26.1 by Chris Renshaw <osm0sis@outlook.com>
|
||||
---
|
||||
shell/glob.c | 786 +++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
shell/glob.h | 113 +++++++
|
||||
shell/hush.c | 5 ++++-
|
||||
shell/sigisemptyset.c | 8 +
|
||||
4 files changed, 911 insertions(+), 1 deletion(-)
|
||||
create mode 100644 shell/glob.c
|
||||
create mode 100644 shell/glob.h
|
||||
create mode 100644 shell/sigisemptyset.c
|
||||
|
||||
diff --git a/shell/glob.c b/shell/glob.c
|
||||
new file mode 100644
|
||||
index 0000000..556d720
|
||||
--- /dev/null
|
||||
+++ b/shell/glob.c
|
||||
@@ -0,0 +1,786 @@
|
||||
+/*
|
||||
+ * Modified for the Android NDK by Gabor Cselle, http://www.gaborcselle.com/
|
||||
+ * Tested with Android NDK version 5b: http://developer.android.com/sdk/ndk/index.html
|
||||
+ * Last modified: March 3 2011
|
||||
+ *
|
||||
+ * Copyright (c) 1989, 1993
|
||||
+ * The Regents of the University of California. All rights reserved.
|
||||
+ *
|
||||
+ * This code is derived from software contributed to Berkeley by
|
||||
+ * Guido van Rossum.
|
||||
+ *
|
||||
+ * Redistribution and use in source and binary forms, with or without
|
||||
+ * modification, are permitted provided that the following conditions
|
||||
+ * are met:
|
||||
+ * 1. Redistributions of source code must retain the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer.
|
||||
+ * 2. Redistributions in binary form must reproduce the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer in the
|
||||
+ * documentation and/or other materials provided with the distribution.
|
||||
+ * 4. Neither the name of the University nor the names of its contributors
|
||||
+ * may be used to endorse or promote products derived from this software
|
||||
+ * without specific prior written permission.
|
||||
+ *
|
||||
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
+ * SUCH DAMAGE.
|
||||
+ */
|
||||
+
|
||||
+#if defined(LIBC_SCCS) && !defined(lint)
|
||||
+static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
|
||||
+#endif /* LIBC_SCCS and not lint */
|
||||
+#include <sys/cdefs.h>
|
||||
+
|
||||
+
|
||||
+/*
|
||||
+ * glob(3) -- a superset of the one defined in POSIX 1003.2.
|
||||
+ *
|
||||
+ * The [!...] convention to negate a range is supported (SysV, Posix, ksh).
|
||||
+ *
|
||||
+ * Optional extra services, controlled by flags not defined by POSIX:
|
||||
+ *
|
||||
+ * GLOB_QUOTE:
|
||||
+ * Escaping convention: \ inhibits any special meaning the following
|
||||
+ * character might have (except \ at end of string is retained).
|
||||
+ * GLOB_MAGCHAR:
|
||||
+ * Set in gl_flags if pattern contained a globbing character.
|
||||
+ * GLOB_NOMAGIC:
|
||||
+ * Same as GLOB_NOCHECK, but it will only append pattern if it did
|
||||
+ * not contain any magic characters. [Used in csh style globbing]
|
||||
+ * GLOB_ALTDIRFUNC:
|
||||
+ * Use alternately specified directory access functions.
|
||||
+ * GLOB_TILDE:
|
||||
+ * expand ~user/foo to the /home/dir/of/user/foo
|
||||
+ * GLOB_BRACE:
|
||||
+ * expand {1,2}{a,b} to 1a 1b 2a 2b
|
||||
+ * gl_matchc:
|
||||
+ * Number of matches in the current invocation of glob.
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * Some notes on multibyte character support:
|
||||
+ * 1. Patterns with illegal byte sequences match nothing - even if
|
||||
+ * GLOB_NOCHECK is specified.
|
||||
+ * 2. Illegal byte sequences in filenames are handled by treating them as
|
||||
+ * single-byte characters with a value of the first byte of the sequence
|
||||
+ * cast to wchar_t.
|
||||
+ * 3. State-dependent encodings are not currently supported.
|
||||
+ */
|
||||
+
|
||||
+#include <sys/param.h>
|
||||
+#include <sys/stat.h>
|
||||
+
|
||||
+#include <ctype.h>
|
||||
+#include <dirent.h>
|
||||
+#include <errno.h>
|
||||
+#include "glob.h"
|
||||
+#include <limits.h>
|
||||
+#include <pwd.h>
|
||||
+#include <stdint.h>
|
||||
+#include <stdio.h>
|
||||
+#include <stdlib.h>
|
||||
+#include <string.h>
|
||||
+#include <unistd.h>
|
||||
+
|
||||
+//#include "collate.h" - NOTE(gabor): I took this out because it's not available for Android
|
||||
+// and collate is only used once for string comparisons. As a side-effect, you might not
|
||||
+// be able to match non-ASCII filenames.
|
||||
+
|
||||
+#define DOLLAR '$'
|
||||
+#define DOT '.'
|
||||
+#define EOS '\0'
|
||||
+#define LBRACKET '['
|
||||
+#define NOT '!'
|
||||
+#define QUESTION '?'
|
||||
+#define QUOTE '\\'
|
||||
+#define RANGE '-'
|
||||
+#define RBRACKET ']'
|
||||
+#define SEP '/'
|
||||
+#define STAR '*'
|
||||
+#define TILDE '~'
|
||||
+#define UNDERSCORE '_'
|
||||
+#define LBRACE '{'
|
||||
+#define RBRACE '}'
|
||||
+#define SLASH '/'
|
||||
+#define COMMA ','
|
||||
+
|
||||
+#define M_PROTECT 0x40
|
||||
+#define M_MASK 0xff
|
||||
+
|
||||
+
|
||||
+#define M_ALL '*'
|
||||
+#define M_END ']'
|
||||
+#define M_NOT '!'
|
||||
+#define M_ONE '?'
|
||||
+#define M_RNG '-'
|
||||
+#define M_SET '['
|
||||
+
|
||||
+
|
||||
+static int g_stat(char *, struct stat *, glob_t *);
|
||||
+static int g_lstat(char *, struct stat *, glob_t *);
|
||||
+static DIR *g_opendir(char *, glob_t *);
|
||||
+static int compare(const void *, const void *);
|
||||
+static int glob0(const char *, glob_t *, size_t *);
|
||||
+static int glob1(char *, glob_t *, size_t *);
|
||||
+static int glob2(char *, char *, char *, char *, glob_t *, size_t *);
|
||||
+static int glob3(char *, char *, char *, char *, char *, glob_t *, size_t *);
|
||||
+static int globextend(const char *, glob_t *, size_t *);
|
||||
+static const char *
|
||||
+ globtilde(const char *, char *, size_t, glob_t *);
|
||||
+static int globexp1(const char *, glob_t *, size_t *);
|
||||
+static int globexp2(const char *, const char *, glob_t *, int *, size_t *);
|
||||
+static int match(char *, char *, char *);
|
||||
+
|
||||
+int ismeta(char c) {
|
||||
+ return c == M_ALL || c == M_END || c == M_NOT || c == M_ONE || c == M_RNG || c == M_SET;
|
||||
+}
|
||||
+
|
||||
+int
|
||||
+glob(const char *pattern, int flags, int (*errfunc)(const char *, int), glob_t *pglob)
|
||||
+{
|
||||
+ const char *patnext;
|
||||
+ size_t limit;
|
||||
+ char *bufnext, *bufend, patbuf[MAXPATHLEN], prot;
|
||||
+
|
||||
+ patnext = pattern;
|
||||
+ if (!(flags & GLOB_APPEND)) {
|
||||
+ pglob->gl_pathc = 0;
|
||||
+ pglob->gl_pathv = NULL;
|
||||
+ if (!(flags & GLOB_DOOFFS))
|
||||
+ pglob->gl_offs = 0;
|
||||
+ }
|
||||
+ if (flags & GLOB_LIMIT) {
|
||||
+ limit = pglob->gl_matchc;
|
||||
+ if (limit == 0)
|
||||
+ limit = 131072;
|
||||
+ } else
|
||||
+ limit = 0;
|
||||
+ pglob->gl_flags = flags & ~GLOB_MAGCHAR;
|
||||
+ pglob->gl_errfunc = errfunc;
|
||||
+ pglob->gl_matchc = 0;
|
||||
+
|
||||
+ bufnext = patbuf;
|
||||
+ bufend = bufnext + MAXPATHLEN - 1;
|
||||
+ if (flags & GLOB_NOESCAPE) {
|
||||
+ strncpy(bufnext, patnext, sizeof(patbuf));
|
||||
+ } else {
|
||||
+ /* Protect the quoted characters. */
|
||||
+ while (bufend >= bufnext && *patnext != EOS) {
|
||||
+ if (*patnext == QUOTE) {
|
||||
+ if (*++patnext == EOS) {
|
||||
+ *bufnext++ = QUOTE | M_PROTECT;
|
||||
+ continue;
|
||||
+ }
|
||||
+ prot = M_PROTECT;
|
||||
+ } else
|
||||
+ prot = 0;
|
||||
+ *bufnext++ = *patnext;
|
||||
+ patnext++;
|
||||
+ }
|
||||
+ }
|
||||
+ *bufnext = EOS;
|
||||
+
|
||||
+ if (flags & GLOB_BRACE)
|
||||
+ return globexp1(patbuf, pglob, &limit);
|
||||
+ else
|
||||
+ return glob0(patbuf, pglob, &limit);
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Expand recursively a glob {} pattern. When there is no more expansion
|
||||
+ * invoke the standard globbing routine to glob the rest of the magic
|
||||
+ * characters
|
||||
+ */
|
||||
+static int
|
||||
+globexp1(const char *pattern, glob_t *pglob, size_t *limit)
|
||||
+{
|
||||
+ const char* ptr = pattern;
|
||||
+ int rv;
|
||||
+
|
||||
+ /* Protect a single {}, for find(1), like csh */
|
||||
+ if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
|
||||
+ return glob0(pattern, pglob, limit);
|
||||
+
|
||||
+ while ((ptr = strchr(ptr, LBRACE)) != NULL)
|
||||
+ if (!globexp2(ptr, pattern, pglob, &rv, limit))
|
||||
+ return rv;
|
||||
+
|
||||
+ return glob0(pattern, pglob, limit);
|
||||
+}
|
||||
+
|
||||
+
|
||||
+/*
|
||||
+ * Recursive brace globbing helper. Tries to expand a single brace.
|
||||
+ * If it succeeds then it invokes globexp1 with the new pattern.
|
||||
+ * If it fails then it tries to glob the rest of the pattern and returns.
|
||||
+ */
|
||||
+static int
|
||||
+globexp2(const char *ptr, const char *pattern, glob_t *pglob, int *rv, size_t *limit)
|
||||
+{
|
||||
+ int i;
|
||||
+ char *lm, *ls;
|
||||
+ const char *pe, *pm, *pm1, *pl;
|
||||
+ char patbuf[MAXPATHLEN];
|
||||
+
|
||||
+ /* copy part up to the brace */
|
||||
+ for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
|
||||
+ continue;
|
||||
+ *lm = EOS;
|
||||
+ ls = lm;
|
||||
+
|
||||
+ /* Find the balanced brace */
|
||||
+ for (i = 0, pe = ++ptr; *pe; pe++)
|
||||
+ if (*pe == LBRACKET) {
|
||||
+ /* Ignore everything between [] */
|
||||
+ for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
|
||||
+ continue;
|
||||
+ if (*pe == EOS) {
|
||||
+ /*
|
||||
+ * We could not find a matching RBRACKET.
|
||||
+ * Ignore and just look for RBRACE
|
||||
+ */
|
||||
+ pe = pm;
|
||||
+ }
|
||||
+ }
|
||||
+ else if (*pe == LBRACE)
|
||||
+ i++;
|
||||
+ else if (*pe == RBRACE) {
|
||||
+ if (i == 0)
|
||||
+ break;
|
||||
+ i--;
|
||||
+ }
|
||||
+
|
||||
+ /* Non matching braces; just glob the pattern */
|
||||
+ if (i != 0 || *pe == EOS) {
|
||||
+ *rv = glob0(patbuf, pglob, limit);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ for (i = 0, pl = pm = ptr; pm <= pe; pm++)
|
||||
+ switch (*pm) {
|
||||
+ case LBRACKET:
|
||||
+ /* Ignore everything between [] */
|
||||
+ for (pm1 = pm++; *pm != RBRACKET && *pm != EOS; pm++)
|
||||
+ continue;
|
||||
+ if (*pm == EOS) {
|
||||
+ /*
|
||||
+ * We could not find a matching RBRACKET.
|
||||
+ * Ignore and just look for RBRACE
|
||||
+ */
|
||||
+ pm = pm1;
|
||||
+ }
|
||||
+ break;
|
||||
+
|
||||
+ case LBRACE:
|
||||
+ i++;
|
||||
+ break;
|
||||
+
|
||||
+ case RBRACE:
|
||||
+ if (i) {
|
||||
+ i--;
|
||||
+ break;
|
||||
+ }
|
||||
+ /* FALLTHROUGH */
|
||||
+ case COMMA:
|
||||
+ if (i && *pm == COMMA)
|
||||
+ break;
|
||||
+ else {
|
||||
+ /* Append the current string */
|
||||
+ for (lm = ls; (pl < pm); *lm++ = *pl++)
|
||||
+ continue;
|
||||
+ /*
|
||||
+ * Append the rest of the pattern after the
|
||||
+ * closing brace
|
||||
+ */
|
||||
+ for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
|
||||
+ continue;
|
||||
+
|
||||
+ /* Expand the current pattern */
|
||||
+ *rv = globexp1(patbuf, pglob, limit);
|
||||
+
|
||||
+ /* move after the comma, to the next string */
|
||||
+ pl = pm + 1;
|
||||
+ }
|
||||
+ break;
|
||||
+
|
||||
+ default:
|
||||
+ break;
|
||||
+ }
|
||||
+ *rv = 0;
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+
|
||||
+/*
|
||||
+ * expand tilde from the passwd file.
|
||||
+ */
|
||||
+static const char *
|
||||
+globtilde(const char *pattern, char *patbuf, size_t patbuf_len, glob_t *pglob)
|
||||
+{
|
||||
+ struct passwd *pwd;
|
||||
+ char *h;
|
||||
+ const char *p;
|
||||
+ char *b, *eb;
|
||||
+
|
||||
+ if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
|
||||
+ return pattern;
|
||||
+
|
||||
+ /*
|
||||
+ * Copy up to the end of the string or /
|
||||
+ */
|
||||
+ eb = &patbuf[patbuf_len - 1];
|
||||
+ for (p = pattern + 1, h = (char *) patbuf;
|
||||
+ h < (char *)eb && *p && *p != SLASH; *h++ = *p++)
|
||||
+ continue;
|
||||
+
|
||||
+ *h = EOS;
|
||||
+
|
||||
+ if (((char *) patbuf)[0] == EOS) {
|
||||
+ /*
|
||||
+ * handle a plain ~ or ~/ by expanding $HOME first (iff
|
||||
+ * we're not running setuid or setgid) and then trying
|
||||
+ * the password file
|
||||
+ */
|
||||
+#ifndef __GLIBC__
|
||||
+ if (issetugid() != 0 ||
|
||||
+ (h = getenv("HOME")) == NULL) {
|
||||
+ if (((h = getlogin()) != NULL &&
|
||||
+ (pwd = getpwnam(h)) != NULL) ||
|
||||
+ (pwd = getpwuid(getuid())) != NULL)
|
||||
+ h = pwd->pw_dir;
|
||||
+ else
|
||||
+ return pattern;
|
||||
+ }
|
||||
+#endif
|
||||
+ }
|
||||
+ else {
|
||||
+ /*
|
||||
+ * Expand a ~user
|
||||
+ */
|
||||
+ if ((pwd = getpwnam((char*) patbuf)) == NULL)
|
||||
+ return pattern;
|
||||
+ else
|
||||
+ h = pwd->pw_dir;
|
||||
+ }
|
||||
+
|
||||
+ /* Copy the home directory */
|
||||
+ for (b = patbuf; b < eb && *h; *b++ = *h++)
|
||||
+ continue;
|
||||
+
|
||||
+ /* Append the rest of the pattern */
|
||||
+ while (b < eb && (*b++ = *p++) != EOS)
|
||||
+ continue;
|
||||
+ *b = EOS;
|
||||
+
|
||||
+ return patbuf;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+/*
|
||||
+ * The main glob() routine: compiles the pattern (optionally processing
|
||||
+ * quotes), calls glob1() to do the real pattern matching, and finally
|
||||
+ * sorts the list (unless unsorted operation is requested). Returns 0
|
||||
+ * if things went well, nonzero if errors occurred.
|
||||
+ */
|
||||
+static int
|
||||
+glob0(const char *pattern, glob_t *pglob, size_t *limit)
|
||||
+{
|
||||
+ const char *qpatnext;
|
||||
+ int err;
|
||||
+ size_t oldpathc;
|
||||
+ char *bufnext, c, patbuf[MAXPATHLEN];
|
||||
+
|
||||
+ qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
|
||||
+ oldpathc = pglob->gl_pathc;
|
||||
+ bufnext = patbuf;
|
||||
+
|
||||
+ /* We don't need to check for buffer overflow any more. */
|
||||
+ while ((c = *qpatnext++) != EOS) {
|
||||
+ switch (c) {
|
||||
+ case LBRACKET:
|
||||
+ c = *qpatnext;
|
||||
+ if (c == NOT)
|
||||
+ ++qpatnext;
|
||||
+ if (*qpatnext == EOS ||
|
||||
+ strchr(qpatnext+1, RBRACKET) == NULL) {
|
||||
+ *bufnext++ = LBRACKET;
|
||||
+ if (c == NOT)
|
||||
+ --qpatnext;
|
||||
+ break;
|
||||
+ }
|
||||
+ *bufnext++ = M_SET;
|
||||
+ if (c == NOT)
|
||||
+ *bufnext++ = M_NOT;
|
||||
+ c = *qpatnext++;
|
||||
+ do {
|
||||
+ *bufnext++ = c;
|
||||
+ if (*qpatnext == RANGE &&
|
||||
+ (c = qpatnext[1]) != RBRACKET) {
|
||||
+ *bufnext++ = M_RNG;
|
||||
+ *bufnext++ = c;
|
||||
+ qpatnext += 2;
|
||||
+ }
|
||||
+ } while ((c = *qpatnext++) != RBRACKET);
|
||||
+ pglob->gl_flags |= GLOB_MAGCHAR;
|
||||
+ *bufnext++ = M_END;
|
||||
+ break;
|
||||
+ case QUESTION:
|
||||
+ pglob->gl_flags |= GLOB_MAGCHAR;
|
||||
+ *bufnext++ = M_ONE;
|
||||
+ break;
|
||||
+ case STAR:
|
||||
+ pglob->gl_flags |= GLOB_MAGCHAR;
|
||||
+ /* collapse adjacent stars to one,
|
||||
+ * to avoid exponential behavior
|
||||
+ */
|
||||
+ if (bufnext == patbuf || bufnext[-1] != M_ALL)
|
||||
+ *bufnext++ = M_ALL;
|
||||
+ break;
|
||||
+ default:
|
||||
+ *bufnext++ = c;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ *bufnext = EOS;
|
||||
+
|
||||
+ if ((err = glob1(patbuf, pglob, limit)) != 0)
|
||||
+ return(err);
|
||||
+
|
||||
+ /*
|
||||
+ * If there was no match we are going to append the pattern
|
||||
+ * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
|
||||
+ * and the pattern did not contain any magic characters
|
||||
+ * GLOB_NOMAGIC is there just for compatibility with csh.
|
||||
+ */
|
||||
+ if (pglob->gl_pathc == oldpathc) {
|
||||
+ if (((pglob->gl_flags & GLOB_NOCHECK) ||
|
||||
+ ((pglob->gl_flags & GLOB_NOMAGIC) &&
|
||||
+ !(pglob->gl_flags & GLOB_MAGCHAR))))
|
||||
+ return(globextend(pattern, pglob, limit));
|
||||
+ else
|
||||
+ return(GLOB_NOMATCH);
|
||||
+ }
|
||||
+ if (!(pglob->gl_flags & GLOB_NOSORT))
|
||||
+ qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
|
||||
+ pglob->gl_pathc - oldpathc, sizeof(char *), compare);
|
||||
+ return(0);
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
+compare(const void *p, const void *q)
|
||||
+{
|
||||
+ return(strcmp(*(char **)p, *(char **)q));
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
+glob1(char *pattern, glob_t *pglob, size_t *limit)
|
||||
+{
|
||||
+ char pathbuf[MAXPATHLEN];
|
||||
+
|
||||
+ /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
|
||||
+ if (*pattern == EOS)
|
||||
+ return(0);
|
||||
+ return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1,
|
||||
+ pattern, pglob, limit));
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * The functions glob2 and glob3 are mutually recursive; there is one level
|
||||
+ * of recursion for each segment in the pattern that contains one or more
|
||||
+ * meta characters.
|
||||
+ */
|
||||
+static int
|
||||
+glob2(char *pathbuf, char *pathend, char *pathend_last, char *pattern,
|
||||
+ glob_t *pglob, size_t *limit)
|
||||
+{
|
||||
+ struct stat sb;
|
||||
+ char *p, *q;
|
||||
+ int anymeta;
|
||||
+
|
||||
+ /*
|
||||
+ * Loop over pattern segments until end of pattern or until
|
||||
+ * segment with meta character found.
|
||||
+ */
|
||||
+ for (anymeta = 0;;) {
|
||||
+ if (*pattern == EOS) { /* End of pattern? */
|
||||
+ *pathend = EOS;
|
||||
+ if (g_lstat(pathbuf, &sb, pglob))
|
||||
+ return(0);
|
||||
+
|
||||
+ if (((pglob->gl_flags & GLOB_MARK) &&
|
||||
+ pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
|
||||
+ || (S_ISLNK(sb.st_mode) &&
|
||||
+ (g_stat(pathbuf, &sb, pglob) == 0) &&
|
||||
+ S_ISDIR(sb.st_mode)))) {
|
||||
+ if (pathend + 1 > pathend_last)
|
||||
+ return (GLOB_ABORTED);
|
||||
+ *pathend++ = SEP;
|
||||
+ *pathend = EOS;
|
||||
+ }
|
||||
+ ++pglob->gl_matchc;
|
||||
+ return(globextend(pathbuf, pglob, limit));
|
||||
+ }
|
||||
+
|
||||
+ /* Find end of next segment, copy tentatively to pathend. */
|
||||
+ q = pathend;
|
||||
+ p = pattern;
|
||||
+ while (*p != EOS && *p != SEP) {
|
||||
+ if (ismeta(*p))
|
||||
+ anymeta = 1;
|
||||
+ if (q + 1 > pathend_last)
|
||||
+ return (GLOB_ABORTED);
|
||||
+ *q++ = *p++;
|
||||
+ }
|
||||
+
|
||||
+ if (!anymeta) { /* No expansion, do next segment. */
|
||||
+ pathend = q;
|
||||
+ pattern = p;
|
||||
+ while (*pattern == SEP) {
|
||||
+ if (pathend + 1 > pathend_last)
|
||||
+ return (GLOB_ABORTED);
|
||||
+ *pathend++ = *pattern++;
|
||||
+ }
|
||||
+ } else /* Need expansion, recurse. */
|
||||
+ return(glob3(pathbuf, pathend, pathend_last, pattern, p,
|
||||
+ pglob, limit));
|
||||
+ }
|
||||
+ /* NOTREACHED */
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
+glob3(char *pathbuf, char *pathend, char *pathend_last,
|
||||
+ char *pattern, char *restpattern,
|
||||
+ glob_t *pglob, size_t *limit)
|
||||
+{
|
||||
+ struct dirent *dp;
|
||||
+ DIR *dirp;
|
||||
+ int err;
|
||||
+ char buf[MAXPATHLEN];
|
||||
+
|
||||
+ /*
|
||||
+ * The readdirfunc declaration can't be prototyped, because it is
|
||||
+ * assigned, below, to two functions which are prototyped in glob.h
|
||||
+ * and dirent.h as taking pointers to differently typed opaque
|
||||
+ * structures.
|
||||
+ */
|
||||
+ struct dirent *(*readdirfunc)();
|
||||
+
|
||||
+ if (pathend > pathend_last)
|
||||
+ return (GLOB_ABORTED);
|
||||
+ *pathend = EOS;
|
||||
+ errno = 0;
|
||||
+
|
||||
+ if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
|
||||
+ /* TODO: don't call for ENOENT or ENOTDIR? */
|
||||
+ if (pglob->gl_errfunc) {
|
||||
+ if (pglob->gl_errfunc(buf, errno) ||
|
||||
+ pglob->gl_flags & GLOB_ERR)
|
||||
+ return (GLOB_ABORTED);
|
||||
+ }
|
||||
+ return(0);
|
||||
+ }
|
||||
+
|
||||
+ err = 0;
|
||||
+
|
||||
+ /* Search directory for matching names. */
|
||||
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
+ readdirfunc = pglob->gl_readdir;
|
||||
+ else
|
||||
+ readdirfunc = readdir;
|
||||
+ while ((dp = (*readdirfunc)(dirp))) {
|
||||
+ char *sc;
|
||||
+ char *dc;
|
||||
+
|
||||
+ /* Initial DOT must be matched literally. */
|
||||
+ if (dp->d_name[0] == DOT && *pattern != DOT)
|
||||
+ continue;
|
||||
+ dc = pathend;
|
||||
+ sc = dp->d_name;
|
||||
+ while (dc < pathend_last) {
|
||||
+ if ((*dc++ = *sc) == EOS)
|
||||
+ break;
|
||||
+ sc++;
|
||||
+ }
|
||||
+ if (!match(pathend, pattern, restpattern)) {
|
||||
+ *pathend = EOS;
|
||||
+ continue;
|
||||
+ }
|
||||
+ err = glob2(pathbuf, --dc, pathend_last, restpattern,
|
||||
+ pglob, limit);
|
||||
+ if (err)
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
+ (*pglob->gl_closedir)(dirp);
|
||||
+ else
|
||||
+ closedir(dirp);
|
||||
+ return(err);
|
||||
+}
|
||||
+
|
||||
+
|
||||
+/*
|
||||
+ * Extend the gl_pathv member of a glob_t structure to accomodate a new item,
|
||||
+ * add the new item, and update gl_pathc.
|
||||
+ *
|
||||
+ * This assumes the BSD realloc, which only copies the block when its size
|
||||
+ * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
|
||||
+ * behavior.
|
||||
+ *
|
||||
+ * Return 0 if new item added, error code if memory couldn't be allocated.
|
||||
+ *
|
||||
+ * Invariant of the glob_t structure:
|
||||
+ * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
|
||||
+ * gl_pathv points to (gl_offs + gl_pathc + 1) items.
|
||||
+ */
|
||||
+static int
|
||||
+globextend(const char *path, glob_t *pglob, size_t *limit)
|
||||
+{
|
||||
+ char **pathv;
|
||||
+ size_t i, newsize, len;
|
||||
+ char *copy;
|
||||
+ const char *p;
|
||||
+
|
||||
+ if (*limit && pglob->gl_pathc > *limit) {
|
||||
+ errno = 0;
|
||||
+ return (GLOB_NOSPACE);
|
||||
+ }
|
||||
+
|
||||
+ newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
|
||||
+ pathv = pglob->gl_pathv ?
|
||||
+ realloc((char *)pglob->gl_pathv, newsize) :
|
||||
+ malloc(newsize);
|
||||
+ if (pathv == NULL) {
|
||||
+ if (pglob->gl_pathv) {
|
||||
+ free(pglob->gl_pathv);
|
||||
+ pglob->gl_pathv = NULL;
|
||||
+ }
|
||||
+ return(GLOB_NOSPACE);
|
||||
+ }
|
||||
+
|
||||
+ if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
|
||||
+ /* first time around -- clear initial gl_offs items */
|
||||
+ pathv += pglob->gl_offs;
|
||||
+ for (i = pglob->gl_offs + 1; --i > 0; )
|
||||
+ *--pathv = NULL;
|
||||
+ }
|
||||
+ pglob->gl_pathv = pathv;
|
||||
+
|
||||
+ for (p = path; *p++;)
|
||||
+ continue;
|
||||
+ len = (size_t)(p - path); /* XXX overallocation */
|
||||
+ if ((copy = malloc(len)) != NULL) {
|
||||
+ strncpy(copy, path, len);
|
||||
+ pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
|
||||
+ }
|
||||
+ pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
|
||||
+ return(copy == NULL ? GLOB_NOSPACE : 0);
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * pattern matching function for filenames. Each occurrence of the *
|
||||
+ * pattern causes a recursion level.
|
||||
+ */
|
||||
+static int
|
||||
+match(char *name, char *pat, char *patend)
|
||||
+{
|
||||
+ int ok, negate_range;
|
||||
+ char c, k;
|
||||
+
|
||||
+ while (pat < patend) {
|
||||
+ c = *pat++;
|
||||
+ switch (c & M_MASK) {
|
||||
+ case M_ALL:
|
||||
+ if (pat == patend)
|
||||
+ return(1);
|
||||
+ do
|
||||
+ if (match(name, pat, patend))
|
||||
+ return(1);
|
||||
+ while (*name++ != EOS);
|
||||
+ return(0);
|
||||
+ case M_ONE:
|
||||
+ if (*name++ == EOS)
|
||||
+ return(0);
|
||||
+ break;
|
||||
+ case M_SET:
|
||||
+ ok = 0;
|
||||
+ if ((k = *name++) == EOS)
|
||||
+ return(0);
|
||||
+ if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
|
||||
+ ++pat;
|
||||
+ while (((c = *pat++) & M_MASK) != M_END)
|
||||
+ if ((*pat & M_MASK) == M_RNG) {
|
||||
+ // NOTE(gabor): This used to be as below, but I took out the collate.h
|
||||
+ // if (__collate_load_error ?
|
||||
+ // CHAR(c) <= CHAR(k) && CHAR(k) <= CHAR(pat[1]) :
|
||||
+ // __collate_range_cmp(CHAR(c), CHAR(k)) <= 0
|
||||
+ // && __collate_range_cmp(CHAR(k), CHAR(pat[1])) <= 0
|
||||
+ // )
|
||||
+
|
||||
+ if (c <= k && k <= pat[1])
|
||||
+ ok = 1;
|
||||
+ pat += 2;
|
||||
+ } else if (c == k)
|
||||
+ ok = 1;
|
||||
+ if (ok == negate_range)
|
||||
+ return(0);
|
||||
+ break;
|
||||
+ default:
|
||||
+ if (*name++ != c)
|
||||
+ return(0);
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ return(*name == EOS);
|
||||
+}
|
||||
+
|
||||
+/* Free allocated data belonging to a glob_t structure. */
|
||||
+void
|
||||
+globfree(glob_t *pglob)
|
||||
+{
|
||||
+ size_t i;
|
||||
+ char **pp;
|
||||
+
|
||||
+ if (pglob->gl_pathv != NULL) {
|
||||
+ pp = pglob->gl_pathv + pglob->gl_offs;
|
||||
+ for (i = pglob->gl_pathc; i--; ++pp)
|
||||
+ if (*pp)
|
||||
+ free(*pp);
|
||||
+ free(pglob->gl_pathv);
|
||||
+ pglob->gl_pathv = NULL;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
+g_stat(char *fn, struct stat *sb, glob_t *pglob)
|
||||
+{
|
||||
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
+ return((*pglob->gl_stat)(fn, sb));
|
||||
+ return(stat(fn, sb));
|
||||
+}
|
||||
+
|
||||
+static DIR *
|
||||
+g_opendir(char *str, glob_t *pglob)
|
||||
+{
|
||||
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
+ return((*pglob->gl_opendir)(str));
|
||||
+
|
||||
+ return(opendir(str));
|
||||
+}
|
||||
+
|
||||
+static int
|
||||
+g_lstat(char *fn, struct stat *sb, glob_t *pglob)
|
||||
+{
|
||||
+ if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
+ return((*pglob->gl_lstat)(fn, sb));
|
||||
+ return(lstat(fn, sb));
|
||||
+}
|
||||
diff --git a/shell/glob.h b/shell/glob.h
|
||||
new file mode 100644
|
||||
index 0000000..e8e6578
|
||||
--- /dev/null
|
||||
+++ b/shell/glob.h
|
||||
@@ -0,0 +1,113 @@
|
||||
+/*
|
||||
+ * Modified for the Android NDK by Gabor Cselle, http://www.gaborcselle.com/
|
||||
+ * Tested with Android NDK version 5b: http://developer.android.com/sdk/ndk/index.html
|
||||
+ * Last modified: March 3 2011
|
||||
+ *
|
||||
+ * Copyright (c) 1989, 1993
|
||||
+ * The Regents of the University of California. All rights reserved.
|
||||
+ *
|
||||
+ * This code is derived from software contributed to Berkeley by
|
||||
+ * Guido van Rossum.
|
||||
+ *
|
||||
+ * Redistribution and use in source and binary forms, with or without
|
||||
+ * modification, are permitted provided that the following conditions
|
||||
+ * are met:
|
||||
+ * 1. Redistributions of source code must retain the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer.
|
||||
+ * 2. Redistributions in binary form must reproduce the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer in the
|
||||
+ * documentation and/or other materials provided with the distribution.
|
||||
+ * 3. All advertising materials mentioning features or use of this software
|
||||
+ * must display the following acknowledgement:
|
||||
+ * This product includes software developed by the University of
|
||||
+ * California, Berkeley and its contributors.
|
||||
+ * 4. Neither the name of the University nor the names of its contributors
|
||||
+ * may be used to endorse or promote products derived from this software
|
||||
+ * without specific prior written permission.
|
||||
+ *
|
||||
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
+ * SUCH DAMAGE.
|
||||
+ *
|
||||
+ * @(#)glob.h 8.1 (Berkeley) 6/2/93
|
||||
+ * $FreeBSD$
|
||||
+ */
|
||||
+
|
||||
+#ifndef _GLOB_H_
|
||||
+#define _GLOB_H_
|
||||
+
|
||||
+#include <sys/cdefs.h>
|
||||
+//#include <sys/_types.h>
|
||||
+
|
||||
+#ifndef _SIZE_T_DECLARED
|
||||
+typedef __size_t size_t;
|
||||
+#define _SIZE_T_DECLARED
|
||||
+#endif
|
||||
+
|
||||
+struct stat;
|
||||
+typedef struct {
|
||||
+ size_t gl_pathc; /* Count of total paths so far. */
|
||||
+ size_t gl_matchc; /* Count of paths matching pattern. */
|
||||
+ size_t gl_offs; /* Reserved at beginning of gl_pathv. */
|
||||
+ int gl_flags; /* Copy of flags parameter to glob. */
|
||||
+ char **gl_pathv; /* List of paths matching pattern. */
|
||||
+ /* Copy of errfunc parameter to glob. */
|
||||
+ int (*gl_errfunc)(const char *, int);
|
||||
+
|
||||
+ /*
|
||||
+ * Alternate filesystem access methods for glob; replacement
|
||||
+ * versions of closedir(3), readdir(3), opendir(3), stat(2)
|
||||
+ * and lstat(2).
|
||||
+ */
|
||||
+ void (*gl_closedir)(void *);
|
||||
+ struct dirent *(*gl_readdir)(void *);
|
||||
+ void *(*gl_opendir)(const char *);
|
||||
+ int (*gl_lstat)(const char *, struct stat *);
|
||||
+ int (*gl_stat)(const char *, struct stat *);
|
||||
+} glob_t;
|
||||
+
|
||||
+#if __POSIX_VISIBLE >= 199209
|
||||
+/* Believed to have been introduced in 1003.2-1992 */
|
||||
+#define GLOB_APPEND 0x0001 /* Append to output from previous call. */
|
||||
+#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
|
||||
+#define GLOB_ERR 0x0004 /* Return on error. */
|
||||
+#define GLOB_MARK 0x0008 /* Append / to matching directories. */
|
||||
+#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */
|
||||
+#define GLOB_NOSORT 0x0020 /* Don't sort. */
|
||||
+#define GLOB_NOESCAPE 0x2000 /* Disable backslash escaping. */
|
||||
+
|
||||
+/* Error values returned by glob(3) */
|
||||
+#define GLOB_NOSPACE (-1) /* Malloc call failed. */
|
||||
+#define GLOB_ABORTED (-2) /* Unignored error. */
|
||||
+#define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK was not set. */
|
||||
+#define GLOB_NOSYS (-4) /* Obsolete: source comptability only. */
|
||||
+#endif /* __POSIX_VISIBLE >= 199209 */
|
||||
+
|
||||
+#if __BSD_VISIBLE
|
||||
+#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
|
||||
+#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
|
||||
+#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
|
||||
+#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */
|
||||
+#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */
|
||||
+#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */
|
||||
+#define GLOB_LIMIT 0x1000 /* limit number of returned paths */
|
||||
+
|
||||
+/* source compatibility, these are the old names */
|
||||
+#define GLOB_MAXPATH GLOB_LIMIT
|
||||
+#define GLOB_ABEND GLOB_ABORTED
|
||||
+#endif /* __BSD_VISIBLE */
|
||||
+
|
||||
+__BEGIN_DECLS
|
||||
+int glob(const char *, int, int (*)(const char *, int), glob_t *);
|
||||
+void globfree(glob_t *);
|
||||
+__END_DECLS
|
||||
+
|
||||
+#endif /* !_GLOB_H_ */
|
||||
diff --git a/shell/hush.c b/shell/hush.c
|
||||
index fecc892..52c925d 100644
|
||||
--- a/shell/hush.c
|
||||
+++ b/shell/hush.c
|
||||
@@ -223,8 +223,11 @@
|
||||
//applet:IF_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, hush))
|
||||
|
||||
//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o
|
||||
+//kbuild:lib-$(CONFIG_HUSH) += glob.o sigisemptyset.o
|
||||
//kbuild:lib-$(CONFIG_SH_IS_HUSH) += hush.o match.o shell_common.o
|
||||
+//kbuild:lib-$(CONFIG_SH_IS_HUSH) += glob.o sigisemptyset.o
|
||||
//kbuild:lib-$(CONFIG_BASH_IS_HUSH) += hush.o match.o shell_common.o
|
||||
+//kbuild:lib-$(CONFIG_BASH_IS_HUSH) += glob.o sigisemptyset.o
|
||||
//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o
|
||||
|
||||
/* -i (interactive) and -s (read stdin) are also accepted,
|
||||
@@ -242,7 +245,7 @@
|
||||
)
|
||||
# include <malloc.h> /* for malloc_trim */
|
||||
#endif
|
||||
-#include <glob.h>
|
||||
+#include "glob.h"
|
||||
/* #include <dmalloc.h> */
|
||||
#if ENABLE_HUSH_CASE
|
||||
# include <fnmatch.h>
|
||||
diff --git a/shell/sigisemptyset.c b/shell/sigisemptyset.c
|
||||
new file mode 100644
|
||||
index 0000000..8297313
|
||||
--- /dev/null
|
||||
+++ b/shell/sigisemptyset.c
|
||||
@@ -0,0 +1,8 @@
|
||||
+// in androids asm/signal.h, sigset_t is a simple unsigned long
|
||||
+
|
||||
+#include <signal.h>
|
||||
+
|
||||
+int sigisemptyset(const sigset_t *set)
|
||||
+{
|
||||
+ return set;
|
||||
+}
|
||||
--
|
||||
1.7.10.4
|
||||
|
||||
32
external/dist/busybox-patches/025-readahead.patch
vendored
Normal file
32
external/dist/busybox-patches/025-readahead.patch
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Sun, 5 Aug 2012 16:00:19 +0200
|
||||
Subject: [PATCH] fix readahead, add syscall
|
||||
|
||||
fix readahead, add simple syscall
|
||||
Can only be tested with LFS support (not patched yet)
|
||||
|
||||
from 'misc-syscalls' by Dan Drown
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
---
|
||||
libbb/missing_syscalls.c | 5 +++++
|
||||
1 file changed, 5 insertions(+)
|
||||
|
||||
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
|
||||
index 474accb..913f00e 100644
|
||||
--- a/libbb/missing_syscalls.c
|
||||
+++ b/libbb/missing_syscalls.c
|
||||
@@ -75,6 +75,11 @@ int semget(key_t key, int nsems, int semflg)
|
||||
return syscall(__NR_semget, key, nsems, semflg);
|
||||
}
|
||||
|
||||
+ssize_t readahead(int fd, off64_t offset, size_t count)
|
||||
+{
|
||||
+ return syscall(__NR_readahead, fd, offset, count);
|
||||
+}
|
||||
+
|
||||
struct msqid_ds; /* #include <linux/msg.h> */
|
||||
int msgctl(int msqid, int cmd, struct msqid_ds *buf)
|
||||
{
|
||||
--
|
||||
1.7.10.4
|
||||
|
||||
151
external/dist/busybox-patches/026-modinfo-modprobe-without-utsrel.patch
vendored
Normal file
151
external/dist/busybox-patches/026-modinfo-modprobe-without-utsrel.patch
vendored
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Mon, 12 Sep 2016 16:25:51 -0300
|
||||
Subject: [PATCH] modinfo/modprobe: use ifdef block for android without-utsrel modules path
|
||||
|
||||
and fixes the modules.dep requirement, it is now optional...
|
||||
|
||||
Patch by Tanguy Pruvot <tanguy.pruvot@gmail.com>
|
||||
Change-Id: Ifccb530fa23b021fd12e2395f5d0c66600b25c04
|
||||
from https://github.com/tpruvot/android_external_busybox
|
||||
|
||||
and commit 2df42d3971f1e260e67c3fa4831cb9195fb276c4
|
||||
from https://github.com/tpruvot/android_external_busybox
|
||||
|
||||
Rebased for busybox 1.25.0 by Chris Renshaw <osm0sis@outlook.com>
|
||||
---
|
||||
modutils/modinfo.c | 33 +++++++++++++++++++++++++++++----
|
||||
modutils/modprobe.c | 18 +++++++++++++++++-
|
||||
2 files changed, 46 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/modutils/modinfo.c b/modutils/modinfo.c
|
||||
index aa641ad..dbc679a 100644
|
||||
--- a/modutils/modinfo.c
|
||||
+++ b/modutils/modinfo.c
|
||||
@@ -21,6 +21,10 @@
|
||||
#include "libbb.h"
|
||||
#include "modutils.h"
|
||||
|
||||
+#if defined(ANDROID) || defined(__ANDROID__)
|
||||
+#define DONT_USE_UTS_REL_FOLDER
|
||||
+#endif
|
||||
+
|
||||
static const char *const shortcuts[] = {
|
||||
"filename", // -n
|
||||
"author", // -a
|
||||
@@ -64,7 +68,7 @@ static void modinfo(const char *path, const char *version,
|
||||
{
|
||||
size_t len;
|
||||
int j;
|
||||
- char *ptr, *the_module;
|
||||
+ char *ptr, *fullpath, *the_module;
|
||||
char *allocated;
|
||||
int tags = option_mask32;
|
||||
|
||||
@@ -75,8 +79,14 @@ static void modinfo(const char *path, const char *version,
|
||||
if (path[0] == '/')
|
||||
return;
|
||||
/* Newer depmod puts relative paths in modules.dep */
|
||||
- path = allocated = xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, version, path);
|
||||
- the_module = xmalloc_open_zipped_read_close(path, &len);
|
||||
+ fullpath = allocated = xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, version, path);
|
||||
+ the_module = xmalloc_open_zipped_read_close(fullpath, &len);
|
||||
+#ifdef DONT_USE_UTS_REL_FOLDER
|
||||
+ if (!the_module) {
|
||||
+ fullpath = allocated = xasprintf("%s/%s", CONFIG_DEFAULT_MODULES_DIR, path);
|
||||
+ the_module = xmalloc_open_zipped_read_close(fullpath, &len);
|
||||
+ }
|
||||
+#endif
|
||||
if (!the_module) {
|
||||
bb_error_msg("module '%s' not found", path);
|
||||
goto ret;
|
||||
@@ -158,9 +168,23 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv)
|
||||
uname(&uts);
|
||||
parser = config_open2(
|
||||
xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, uts.release, CONFIG_DEFAULT_DEPMOD_FILE),
|
||||
- xfopen_for_read
|
||||
+ fopen_for_read
|
||||
);
|
||||
|
||||
+#ifdef DONT_USE_UTS_REL_FOLDER
|
||||
+ if (!parser) {
|
||||
+ parser = config_open2(
|
||||
+ xasprintf("%s/%s", CONFIG_DEFAULT_MODULES_DIR, CONFIG_DEFAULT_DEPMOD_FILE),
|
||||
+ fopen_for_read
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ if (!parser) {
|
||||
+ strcpy(uts.release,"");
|
||||
+ goto no_modules_dep;
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
while (config_read(parser, tokens, 2, 1, "# \t", PARSE_NORMAL)) {
|
||||
colon = last_char_is(tokens[0], ':');
|
||||
if (colon == NULL)
|
||||
@@ -177,6 +201,7 @@ int modinfo_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
config_close(parser);
|
||||
|
||||
+no_modules_dep:
|
||||
for (i = 0; argv[i]; i++) {
|
||||
if (argv[i][0]) {
|
||||
modinfo(argv[i], uts.release, field);
|
||||
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
|
||||
index 8130c40..585de5c 100644
|
||||
--- a/modutils/modprobe.c
|
||||
+++ b/modutils/modprobe.c
|
||||
@@ -150,6 +150,10 @@ static const char modprobe_longopts[] ALIGN1 =
|
||||
#define MODULE_FLAG_FOUND_IN_MODDEP 0x0004
|
||||
#define MODULE_FLAG_BLACKLISTED 0x0008
|
||||
|
||||
+#if defined(ANDROID) || defined(__ANDROID__)
|
||||
+#define DONT_USE_UTS_REL_FOLDER
|
||||
+#endif
|
||||
+
|
||||
struct globals {
|
||||
llist_t *probes; /* MEs of module(s) requested on cmdline */
|
||||
char *cmdline_mopts; /* module options from cmdline */
|
||||
@@ -440,10 +444,17 @@ static int do_modprobe(struct module_entry *m)
|
||||
options = gather_options_str(options, G.cmdline_mopts);
|
||||
|
||||
if (option_mask32 & OPT_SHOW_DEPS) {
|
||||
+#ifndef DONT_USE_UTS_REL_FOLDER
|
||||
printf(options ? "insmod %s/%s/%s %s\n"
|
||||
: "insmod %s/%s/%s\n",
|
||||
CONFIG_DEFAULT_MODULES_DIR, G.uts.release, fn,
|
||||
options);
|
||||
+#else
|
||||
+ printf(options ? "insmod %s/%s %s\n"
|
||||
+ : "insmod %s/%s\n",
|
||||
+ CONFIG_DEFAULT_MODULES_DIR, fn,
|
||||
+ options);
|
||||
+#endif
|
||||
free(options);
|
||||
continue;
|
||||
}
|
||||
@@ -525,6 +536,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
int rc;
|
||||
unsigned opt;
|
||||
struct module_entry *me;
|
||||
+ struct stat info;
|
||||
|
||||
INIT_G();
|
||||
|
||||
@@ -535,8 +547,12 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
/* Goto modules location */
|
||||
xchdir(CONFIG_DEFAULT_MODULES_DIR);
|
||||
+#ifndef DONT_USE_UTS_REL_FOLDER
|
||||
uname(&G.uts);
|
||||
- xchdir(G.uts.release);
|
||||
+ if (stat(G.uts.release, &info) == 0) {
|
||||
+ xchdir(G.uts.release);
|
||||
+ }
|
||||
+#endif
|
||||
|
||||
if (opt & OPT_LIST_ONLY) {
|
||||
int i;
|
||||
--
|
||||
2.8.3
|
||||
|
||||
31
external/dist/busybox-patches/027-depmod-parameter.patch
vendored
Normal file
31
external/dist/busybox-patches/027-depmod-parameter.patch
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Mon, 12 Sep 2016 16:55:01 -0300
|
||||
Subject: [PATCH] depmod: fix syntax with modules in parameter
|
||||
|
||||
Patch by Tanguy Pruvot <tanguy.pruvot@gmail.com>
|
||||
Change-Id: I21b8664db01cf0132db82f8d6caa1a0e77e71004
|
||||
from https://github.com/tpruvot/android_external_busybox
|
||||
Rebased for busybox 1.25.0 by Chris Renshaw <osm0sis@outlook.com>
|
||||
---
|
||||
modutils/depmod.c | 5 ++++-
|
||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/modutils/depmod.c b/modutils/depmod.c
|
||||
index 9713aef..4050494 100644
|
||||
--- a/modutils/depmod.c
|
||||
+++ b/modutils/depmod.c
|
||||
@@ -37,7 +37,10 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
|
||||
image = xmalloc_open_zipped_read_close(fname, &len);
|
||||
|
||||
e = moddb_get_or_create(modules, bb_get_last_path_component_nostrip(fname));
|
||||
- e->name = xstrdup(fname + 2); /* skip "./" */
|
||||
+ if (strncmp(fname, "./", 2) == 0)
|
||||
+ e->name = xstrdup(fname + 2);
|
||||
+ else
|
||||
+ e->name = xstrdup(fname);
|
||||
|
||||
for (ptr = image; ptr < image + len - 10; ptr++) {
|
||||
if (is_prefixed_with(ptr, "depends=")) {
|
||||
--
|
||||
2.8.3
|
||||
|
||||
1243
external/dist/busybox-patches/050-dietlibc_resolver-nslookup.patch
vendored
Normal file
1243
external/dist/busybox-patches/050-dietlibc_resolver-nslookup.patch
vendored
Normal file
File diff suppressed because it is too large
Load diff
87
external/dist/busybox-patches/051-ash-history.patch
vendored
Normal file
87
external/dist/busybox-patches/051-ash-history.patch
vendored
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
From: Chris Renshaw <osm0sis@outlook.com>
|
||||
Date: Sat, 28 Nov 2015 06:33:57 -0400
|
||||
Subject: [PATCH] ash history
|
||||
|
||||
allows ash history to work on Android
|
||||
|
||||
Patch modified by Tias Guns <tias@ulyssis.org> from 'busybox-android.patch' by Alexandre Courbot
|
||||
https://github.com/Gnurou/busybox-android
|
||||
Rebased for busybox 1.24.1 by Chris Renshaw <osm0sis@outlook.com>
|
||||
---
|
||||
include/libbb.h | 4 ++--
|
||||
init/init.c | 2 +-
|
||||
shell/ash.c | 8 +++++++-
|
||||
3 files changed, 10 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/include/libbb.h b/include/libbb.h
|
||||
index a8ceb44..b78a99a 100644
|
||||
--- a/include/libbb.h
|
||||
+++ b/include/libbb.h
|
||||
@@ -1844,12 +1844,12 @@ extern struct globals *const ptr_to_globals;
|
||||
* use bb_default_login_shell and following defines.
|
||||
* If you change LIBBB_DEFAULT_LOGIN_SHELL,
|
||||
* don't forget to change increment constant. */
|
||||
-#define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh"
|
||||
+#define LIBBB_DEFAULT_LOGIN_SHELL "-/sbin/sh"
|
||||
extern const char bb_default_login_shell[] ALIGN1;
|
||||
/* "/bin/sh" */
|
||||
#define DEFAULT_SHELL (bb_default_login_shell+1)
|
||||
/* "sh" */
|
||||
-#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6)
|
||||
+#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+7)
|
||||
|
||||
/* The following devices are the same on all systems. */
|
||||
#define CURRENT_TTY "/dev/tty"
|
||||
diff --git a/init/init.c b/init/init.c
|
||||
index 80c5d0f..5299c4f 100644
|
||||
--- a/init/init.c
|
||||
+++ b/init/init.c
|
||||
@@ -1072,7 +1072,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Make sure environs is set to something sane */
|
||||
putenv((char *) "HOME=/");
|
||||
putenv((char *) bb_PATH_root_path);
|
||||
- putenv((char *) "SHELL=/bin/sh");
|
||||
+ putenv((char *) "SHELL=/sbin/sh");
|
||||
putenv((char *) "USER=root"); /* needed? why? */
|
||||
|
||||
if (argv[1])
|
||||
diff --git a/shell/ash.c b/shell/ash.c
|
||||
index 8a1628e..d69cfff 100644
|
||||
--- a/shell/ash.c
|
||||
+++ b/shell/ash.c
|
||||
@@ -13154,11 +13154,13 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
if (argv[0] && argv[0][0] == '-')
|
||||
isloginsh = 1;
|
||||
+ else
|
||||
+ isloginsh = 1;
|
||||
if (isloginsh) {
|
||||
const char *hp;
|
||||
|
||||
state = 1;
|
||||
- read_profile("/etc/profile");
|
||||
+ read_profile("/system/etc/profile");
|
||||
state1:
|
||||
state = 2;
|
||||
hp = lookupvar("HOME");
|
||||
@@ -13199,6 +13201,9 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (iflag) {
|
||||
const char *hp = lookupvar("HISTFILE");
|
||||
if (!hp) {
|
||||
+#ifdef __ANDROID__
|
||||
+ setvar("HISTFILE", "/mnt/sdcard/ash_history", 0);
|
||||
+#else
|
||||
hp = lookupvar("HOME");
|
||||
if (hp) {
|
||||
hp = concat_path_file(hp, ".ash_history");
|
||||
@@ -13206,6 +13211,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
|
||||
free((char*)hp);
|
||||
hp = lookupvar("HISTFILE");
|
||||
}
|
||||
+#endif
|
||||
}
|
||||
if (hp)
|
||||
line_input_state->hist_file = hp;
|
||||
--
|
||||
2.5.3
|
||||
|
||||
33
external/dist/iptables-patches/0001-iptables-correctly-reference-generated-file.patch
vendored
Normal file
33
external/dist/iptables-patches/0001-iptables-correctly-reference-generated-file.patch
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
From e693b5be1f4320c3db64ddb9f3a473de6bb6bc5f Mon Sep 17 00:00:00 2001
|
||||
From: Lutz Jaenicke <ljaenicke@innominate.com>
|
||||
Date: Wed, 7 Aug 2013 10:09:16 +0200
|
||||
Subject: [PATCH 1/7] iptables: correctly reference generated file
|
||||
|
||||
Since (14bca55 iptables: use autoconf to process .in man pages),
|
||||
the file "iptables-extensions.8.tmpl" is generated from
|
||||
"iptables-extensions.8.tmpl.in" and is consequently no
|
||||
longer found in ${srcdir} but in the build directory.
|
||||
(Becomes visible with builddir != srcdir)
|
||||
|
||||
Signed-off-by: Lutz Jaenicke <ljaenicke@innominate.com>
|
||||
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
|
||||
---
|
||||
iptables/Makefile.am | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/iptables/Makefile.am b/iptables/Makefile.am
|
||||
index 46d2463..501e825 100644
|
||||
--- a/iptables/Makefile.am
|
||||
+++ b/iptables/Makefile.am
|
||||
@@ -38,7 +38,7 @@ if ENABLE_IPV6
|
||||
v6_sbin_links = ip6tables ip6tables-restore ip6tables-save
|
||||
endif
|
||||
|
||||
-iptables-extensions.8: ${srcdir}/iptables-extensions.8.tmpl ../extensions/matches.man ../extensions/targets.man
|
||||
+iptables-extensions.8: iptables-extensions.8.tmpl ../extensions/matches.man ../extensions/targets.man
|
||||
${AM_VERBOSE_GEN} sed \
|
||||
-e '/@MATCH@/ r ../extensions/matches.man' \
|
||||
-e '/@TARGET@/ r ../extensions/targets.man' $< >$@;
|
||||
--
|
||||
1.7.9.5
|
||||
|
||||
45
external/dist/iptables-patches/0002-android-libiptc-Fix-socklen_t-type-mismatch-on-Andro.patch
vendored
Normal file
45
external/dist/iptables-patches/0002-android-libiptc-Fix-socklen_t-type-mismatch-on-Andro.patch
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
From faa4da018eccbf60bfd6e40bc764cae078e12b8d Mon Sep 17 00:00:00 2001
|
||||
From: Kevin Cernekee <cernekee@gmail.com>
|
||||
Date: Sat, 26 Oct 2013 10:35:06 -0700
|
||||
Subject: [PATCH 2/7] android: libiptc: Fix socklen_t type mismatch on Android
|
||||
|
||||
Bionic defines socklen_t as a signed int, so redefining it as unsigned
|
||||
breaks the build.
|
||||
|
||||
This change comes from AOSP.
|
||||
|
||||
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
|
||||
---
|
||||
libiptc/libip4tc.c | 2 +-
|
||||
libiptc/libip6tc.c | 2 +-
|
||||
2 files changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/libiptc/libip4tc.c b/libiptc/libip4tc.c
|
||||
index dd59951..2b029d4 100644
|
||||
--- a/libiptc/libip4tc.c
|
||||
+++ b/libiptc/libip4tc.c
|
||||
@@ -22,7 +22,7 @@
|
||||
#define inline
|
||||
#endif
|
||||
|
||||
-#if !defined(__GLIBC__) || (__GLIBC__ < 2)
|
||||
+#if !defined(__ANDROID__) && (!defined(__GLIBC__) || (__GLIBC__ < 2))
|
||||
typedef unsigned int socklen_t;
|
||||
#endif
|
||||
|
||||
diff --git a/libiptc/libip6tc.c b/libiptc/libip6tc.c
|
||||
index ca01bcb..4e47e69 100644
|
||||
--- a/libiptc/libip6tc.c
|
||||
+++ b/libiptc/libip6tc.c
|
||||
@@ -23,7 +23,7 @@
|
||||
#define inline
|
||||
#endif
|
||||
|
||||
-#if !defined(__GLIBC__) || (__GLIBC__ < 2)
|
||||
+#if !defined(__ANDROID__) && (!defined(__GLIBC__) || (__GLIBC__ < 2))
|
||||
typedef unsigned int socklen_t;
|
||||
#endif
|
||||
|
||||
--
|
||||
1.7.9.5
|
||||
|
||||
32
external/dist/iptables-patches/0003-android-Don-t-include-conflicting-headers.patch
vendored
Normal file
32
external/dist/iptables-patches/0003-android-Don-t-include-conflicting-headers.patch
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
From 2f7755e416c284c3fd96248fcb5401c46a3ba6bf Mon Sep 17 00:00:00 2001
|
||||
From: Kevin Cernekee <cernekee@gmail.com>
|
||||
Date: Sat, 26 Oct 2013 10:42:55 -0700
|
||||
Subject: [PATCH 3/7] android: Don't include conflicting headers
|
||||
|
||||
<netinet/ip.h> and <linux/ip.h> redefine a couple of structs, including
|
||||
iphdr. Handle this the same way as on glibc, i.e. don't include
|
||||
<linux/ip.h>.
|
||||
|
||||
This change comes from AOSP.
|
||||
|
||||
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
|
||||
---
|
||||
include/libiptc/ipt_kernel_headers.h | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/include/libiptc/ipt_kernel_headers.h b/include/libiptc/ipt_kernel_headers.h
|
||||
index 18861fe..60c7998 100644
|
||||
--- a/include/libiptc/ipt_kernel_headers.h
|
||||
+++ b/include/libiptc/ipt_kernel_headers.h
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
-#if defined(__GLIBC__) && __GLIBC__ == 2
|
||||
+#if defined(__ANDROID__) || (defined(__GLIBC__) && __GLIBC__ == 2)
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
--
|
||||
1.7.9.5
|
||||
|
||||
36
external/dist/iptables-patches/0004-android-build-Blacklist-TCPOPTSTRIP-on-systems-that-.patch
vendored
Normal file
36
external/dist/iptables-patches/0004-android-build-Blacklist-TCPOPTSTRIP-on-systems-that-.patch
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
From 337d40956909c71c3bd527adf9ed6783de631303 Mon Sep 17 00:00:00 2001
|
||||
From: Kevin Cernekee <cernekee@gmail.com>
|
||||
Date: Sat, 26 Oct 2013 11:03:06 -0700
|
||||
Subject: [PATCH 4/7] android: build: Blacklist TCPOPTSTRIP on systems that
|
||||
lack TCPOPT_*
|
||||
|
||||
Bionic's <netinet/tcp.h> is missing constants needed to build this module,
|
||||
so have autoconf check for this condition before trying to build it.
|
||||
|
||||
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
|
||||
---
|
||||
configure.ac | 8 ++++++++
|
||||
1 file changed, 8 insertions(+)
|
||||
|
||||
diff --git a/configure.ac b/configure.ac
|
||||
index f8affed..9607560 100644
|
||||
--- a/configure.ac
|
||||
+++ b/configure.ac
|
||||
@@ -91,6 +91,14 @@ if test "$nfconntrack" -ne 1; then
|
||||
echo "WARNING: libnetfilter_conntrack not found, connlabel match will not be built";
|
||||
fi;
|
||||
|
||||
+AC_CHECK_DECL([TCPOPT_WINDOW], [tcpopt_ok=1], [tcpopt_ok=0],
|
||||
+ [[#include <netinet/tcp.h>]])
|
||||
+
|
||||
+if test "$tcpopt_ok" -ne 1; then
|
||||
+ blacklist_modules="$blacklist_modules TCPOPTSTRIP";
|
||||
+ echo "WARNING: TCPOPT_* constants not found, TCPOPTSTRIP target will not be built";
|
||||
+fi;
|
||||
+
|
||||
AC_SUBST([blacklist_modules])
|
||||
AC_CHECK_SIZEOF([struct ip6_hdr], [], [#include <netinet/ip6.h>])
|
||||
|
||||
--
|
||||
1.7.9.5
|
||||
|
||||
113
external/dist/iptables-patches/0005-Modify-iptables-to-talk-to-xt_IDLETIMER-version-1.patch
vendored
Normal file
113
external/dist/iptables-patches/0005-Modify-iptables-to-talk-to-xt_IDLETIMER-version-1.patch
vendored
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
From b790e5feab45ed0bcb68399bd270c13e83da6641 Mon Sep 17 00:00:00 2001
|
||||
From: Ashish Sharma <ashishsharma@google.com>
|
||||
Date: Thu, 29 Mar 2012 19:51:43 -0700
|
||||
Subject: [PATCH 5/7] Modify iptables to talk to xt_IDLETIMER version 1.
|
||||
|
||||
Change-Id: Ib144c5289681cdff21b21be74173164d097710e7
|
||||
---
|
||||
extensions/libxt_IDLETIMER.c | 9 ++++++++-
|
||||
extensions/libxt_IDLETIMER.man | 4 ++++
|
||||
include/linux/netfilter/xt_IDLETIMER.h | 8 ++++++++
|
||||
3 files changed, 20 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/extensions/libxt_IDLETIMER.c b/extensions/libxt_IDLETIMER.c
|
||||
index 21004a4..5f1b9fe 100644
|
||||
--- a/extensions/libxt_IDLETIMER.c
|
||||
+++ b/extensions/libxt_IDLETIMER.c
|
||||
@@ -27,6 +27,7 @@
|
||||
enum {
|
||||
O_TIMEOUT = 0,
|
||||
O_LABEL,
|
||||
+ O_NETLINK,
|
||||
};
|
||||
|
||||
#define s struct idletimer_tg_info
|
||||
@@ -35,6 +36,8 @@ static const struct xt_option_entry idletimer_tg_opts[] = {
|
||||
.flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, timeout)},
|
||||
{.name = "label", .id = O_LABEL, .type = XTTYPE_STRING,
|
||||
.flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, label)},
|
||||
+ {.name = "send_nl_msg", .id = O_NETLINK, .type = XTTYPE_UINT8,
|
||||
+ .flags = XTOPT_PUT, XTOPT_POINTER(s, send_nl_msg)},
|
||||
XTOPT_TABLEEND,
|
||||
};
|
||||
#undef s
|
||||
@@ -45,6 +48,8 @@ static void idletimer_tg_help(void)
|
||||
"IDLETIMER target options:\n"
|
||||
" --timeout time Timeout until the notification is sent (in seconds)\n"
|
||||
" --label string Unique rule identifier\n"
|
||||
+" --send_nl_msg (0/1) Enable netlink messages,"
|
||||
+ " and show remaining time in sysfs. Defaults to 0.\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
@@ -57,6 +62,7 @@ static void idletimer_tg_print(const void *ip,
|
||||
|
||||
printf(" timeout:%u", info->timeout);
|
||||
printf(" label:%s", info->label);
|
||||
+ printf(" send_nl_msg:%u", info->send_nl_msg);
|
||||
}
|
||||
|
||||
static void idletimer_tg_save(const void *ip,
|
||||
@@ -67,13 +73,14 @@ static void idletimer_tg_save(const void *ip,
|
||||
|
||||
printf(" --timeout %u", info->timeout);
|
||||
printf(" --label %s", info->label);
|
||||
+ printf(" --send_nl_msg %u", info->send_nl_msg);
|
||||
}
|
||||
|
||||
static struct xtables_target idletimer_tg_reg = {
|
||||
.family = NFPROTO_UNSPEC,
|
||||
.name = "IDLETIMER",
|
||||
.version = XTABLES_VERSION,
|
||||
- .revision = 0,
|
||||
+ .revision = 1,
|
||||
.size = XT_ALIGN(sizeof(struct idletimer_tg_info)),
|
||||
.userspacesize = offsetof(struct idletimer_tg_info, timer),
|
||||
.help = idletimer_tg_help,
|
||||
diff --git a/extensions/libxt_IDLETIMER.man b/extensions/libxt_IDLETIMER.man
|
||||
index e3c91ce..3b5188d 100644
|
||||
--- a/extensions/libxt_IDLETIMER.man
|
||||
+++ b/extensions/libxt_IDLETIMER.man
|
||||
@@ -18,3 +18,7 @@ This is the time in seconds that will trigger the notification.
|
||||
\fB\-\-label\fP \fIstring\fP
|
||||
This is a unique identifier for the timer. The maximum length for the
|
||||
label string is 27 characters.
|
||||
+.TP
|
||||
+\fB\-\---send_nl_msg\fP \fI(0/1)\fP
|
||||
+Send netlink messages in addition to sysfs notifications and show remaining
|
||||
+time. Defaults to 0.
|
||||
diff --git a/include/linux/netfilter/xt_IDLETIMER.h b/include/linux/netfilter/xt_IDLETIMER.h
|
||||
index 208ae93..faaa28b 100644
|
||||
--- a/include/linux/netfilter/xt_IDLETIMER.h
|
||||
+++ b/include/linux/netfilter/xt_IDLETIMER.h
|
||||
@@ -4,6 +4,7 @@
|
||||
* Header file for Xtables timer target module.
|
||||
*
|
||||
* Copyright (C) 2004, 2010 Nokia Corporation
|
||||
+ *
|
||||
* Written by Timo Teras <ext-timo.teras@nokia.com>
|
||||
*
|
||||
* Converted to x_tables and forward-ported to 2.6.34
|
||||
@@ -32,12 +33,19 @@
|
||||
#include <linux/types.h>
|
||||
|
||||
#define MAX_IDLETIMER_LABEL_SIZE 28
|
||||
+#define NLMSG_MAX_SIZE 64
|
||||
+
|
||||
+#define NL_EVENT_TYPE_INACTIVE 0
|
||||
+#define NL_EVENT_TYPE_ACTIVE 1
|
||||
|
||||
struct idletimer_tg_info {
|
||||
__u32 timeout;
|
||||
|
||||
char label[MAX_IDLETIMER_LABEL_SIZE];
|
||||
|
||||
+ /* Use netlink messages for notification in addition to sysfs */
|
||||
+ __u8 send_nl_msg;
|
||||
+
|
||||
/* for kernel module internal use only */
|
||||
struct idletimer_tg *timer __attribute__((aligned(8)));
|
||||
};
|
||||
--
|
||||
1.7.9.5
|
||||
|
||||
39
external/dist/iptables-patches/0006-ignore-SIGPIPES.patch
vendored
Normal file
39
external/dist/iptables-patches/0006-ignore-SIGPIPES.patch
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
From d0c05e88231609ddd8b1e8ab0698f3f22c4e9aff Mon Sep 17 00:00:00 2001
|
||||
From: JP Abgrall <jpa@google.com>
|
||||
Date: Mon, 12 Nov 2012 11:59:43 -0800
|
||||
Subject: [PATCH 6/7] ignore SIGPIPES
|
||||
|
||||
During bugreports mostly, when adb goes away it leads to apps crashing
|
||||
because their output stream got closed.
|
||||
Let's just ignore it.
|
||||
|
||||
Bug: 6447319
|
||||
Change-Id: I1b293ebef737014162edebd5fd9bf254345b2ce8
|
||||
---
|
||||
iptables/iptables-standalone.c | 3 +++
|
||||
1 file changed, 3 insertions(+)
|
||||
|
||||
diff --git a/iptables/iptables-standalone.c b/iptables/iptables-standalone.c
|
||||
index 4da1d7f..c60b4b7 100644
|
||||
--- a/iptables/iptables-standalone.c
|
||||
+++ b/iptables/iptables-standalone.c
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
+#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <iptables.h>
|
||||
#include "iptables-multi.h"
|
||||
@@ -45,6 +46,8 @@ iptables_main(int argc, char *argv[])
|
||||
char *table = "filter";
|
||||
struct xtc_handle *handle = NULL;
|
||||
|
||||
+ signal(SIGPIPE, SIG_IGN);
|
||||
+
|
||||
iptables_globals.program_name = "iptables";
|
||||
ret = xtables_init_all(&iptables_globals, NFPROTO_IPV4);
|
||||
if (ret < 0) {
|
||||
--
|
||||
1.7.9.5
|
||||
|
||||
252
external/dist/iptables-patches/0007-android-Import-latest-libxt_quota2-code-from-AOSP-4..patch
vendored
Normal file
252
external/dist/iptables-patches/0007-android-Import-latest-libxt_quota2-code-from-AOSP-4..patch
vendored
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
From 81b9c73f49774ba820bb27c9eaa98b36ab8bdbc2 Mon Sep 17 00:00:00 2001
|
||||
From: Kevin Cernekee <cernekee@gmail.com>
|
||||
Date: Sat, 26 Oct 2013 12:04:25 -0700
|
||||
Subject: [PATCH 7/7] android: Import latest libxt_quota2 code from AOSP 4.2.2
|
||||
|
||||
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
|
||||
---
|
||||
extensions/libxt_quota.c | 1 +
|
||||
extensions/libxt_quota2.c | 141 +++++++++++++++++++++++++++++++++++
|
||||
extensions/libxt_quota2.man | 37 +++++++++
|
||||
include/linux/netfilter/xt_quota2.h | 25 +++++++
|
||||
4 files changed, 204 insertions(+)
|
||||
create mode 100644 extensions/libxt_quota2.c
|
||||
create mode 100644 extensions/libxt_quota2.man
|
||||
create mode 100644 include/linux/netfilter/xt_quota2.h
|
||||
|
||||
diff --git a/extensions/libxt_quota.c b/extensions/libxt_quota.c
|
||||
index ff498da..26fba0b 100644
|
||||
--- a/extensions/libxt_quota.c
|
||||
+++ b/extensions/libxt_quota.c
|
||||
@@ -48,6 +48,7 @@ static void quota_parse(struct xt_option_call *cb)
|
||||
xtables_option_parse(cb);
|
||||
if (cb->invert)
|
||||
info->flags |= XT_QUOTA_INVERT;
|
||||
+ info->quota = cb->val.u64;
|
||||
}
|
||||
|
||||
static struct xtables_match quota_match = {
|
||||
diff --git a/extensions/libxt_quota2.c b/extensions/libxt_quota2.c
|
||||
new file mode 100644
|
||||
index 0000000..d004cca
|
||||
--- /dev/null
|
||||
+++ b/extensions/libxt_quota2.c
|
||||
@@ -0,0 +1,141 @@
|
||||
+/*
|
||||
+ * "quota2" match extension for iptables
|
||||
+ * Sam Johnston <samj [at] samj net>
|
||||
+ * Jan Engelhardt <jengelh [at] medozas de>, 2008
|
||||
+ *
|
||||
+ * This program is free software; you can redistribute it and/or
|
||||
+ * modify it under the terms of the GNU General Public License; either
|
||||
+ * version 2 of the License, or any later version, as published by the
|
||||
+ * Free Software Foundation.
|
||||
+ */
|
||||
+#include <getopt.h>
|
||||
+#include <stddef.h>
|
||||
+#include <stdio.h>
|
||||
+#include <stdlib.h>
|
||||
+#include <string.h>
|
||||
+#include <xtables.h>
|
||||
+#include <linux/netfilter/xt_quota2.h>
|
||||
+
|
||||
+enum {
|
||||
+ FL_QUOTA = 1 << 0,
|
||||
+ FL_NAME = 1 << 1,
|
||||
+ FL_GROW = 1 << 2,
|
||||
+ FL_PACKET = 1 << 3,
|
||||
+ FL_NO_CHANGE = 1 << 4,
|
||||
+};
|
||||
+
|
||||
+enum {
|
||||
+ O_QUOTA = 0,
|
||||
+ O_NAME,
|
||||
+ O_GROW,
|
||||
+ O_PACKET,
|
||||
+ O_NO_CHANGE,
|
||||
+};
|
||||
+
|
||||
+
|
||||
+static const struct xt_option_entry quota_mt2_opts[] = {
|
||||
+ {.name = "grow", .id = O_GROW, .type = XTTYPE_NONE},
|
||||
+ {.name = "no-change", .id = O_NO_CHANGE, .type = XTTYPE_NONE},
|
||||
+ {.name = "name", .id = O_NAME, .type = XTTYPE_STRING,
|
||||
+ .flags = XTOPT_PUT, XTOPT_POINTER(struct xt_quota_mtinfo2, name)},
|
||||
+ {.name = "quota", .id = O_QUOTA, .type = XTTYPE_UINT64,
|
||||
+ .flags = XTOPT_INVERT | XTOPT_PUT,
|
||||
+ XTOPT_POINTER(struct xt_quota_mtinfo2, quota)},
|
||||
+ {.name = "packets", .id = O_PACKET, .type = XTTYPE_NONE},
|
||||
+ XTOPT_TABLEEND,
|
||||
+};
|
||||
+
|
||||
+static void quota_mt2_help(void)
|
||||
+{
|
||||
+ printf(
|
||||
+ "quota match options:\n"
|
||||
+ " --grow provide an increasing counter\n"
|
||||
+ " --no-change never change counter/quota value for matching packets\n"
|
||||
+ " --name name name for the file in sysfs\n"
|
||||
+ "[!] --quota quota initial quota (bytes or packets)\n"
|
||||
+ " --packets count packets instead of bytes\n"
|
||||
+ );
|
||||
+}
|
||||
+
|
||||
+static void quota_mt2_parse(struct xt_option_call *cb)
|
||||
+{
|
||||
+ struct xt_quota_mtinfo2 *info = cb->data;
|
||||
+
|
||||
+ xtables_option_parse(cb);
|
||||
+ switch (cb->entry->id) {
|
||||
+ case O_GROW:
|
||||
+ info->flags |= XT_QUOTA_GROW;
|
||||
+ break;
|
||||
+ case O_NO_CHANGE:
|
||||
+ info->flags |= XT_QUOTA_NO_CHANGE;
|
||||
+ break;
|
||||
+ case O_NAME:
|
||||
+ break;
|
||||
+ case O_PACKET:
|
||||
+ info->flags |= XT_QUOTA_PACKET;
|
||||
+ break;
|
||||
+ case O_QUOTA:
|
||||
+ if (cb->invert)
|
||||
+ info->flags |= XT_QUOTA_INVERT;
|
||||
+ break;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+quota_mt2_save(const void *ip, const struct xt_entry_match *match)
|
||||
+{
|
||||
+ const struct xt_quota_mtinfo2 *q = (void *)match->data;
|
||||
+
|
||||
+ if (q->flags & XT_QUOTA_INVERT)
|
||||
+ printf(" !");
|
||||
+ if (q->flags & XT_QUOTA_GROW)
|
||||
+ printf(" --grow ");
|
||||
+ if (q->flags & XT_QUOTA_NO_CHANGE)
|
||||
+ printf(" --no-change ");
|
||||
+ if (q->flags & XT_QUOTA_PACKET)
|
||||
+ printf(" --packets ");
|
||||
+ if (*q->name != '\0')
|
||||
+ printf(" --name %s ", q->name);
|
||||
+ printf(" --quota %llu ", (unsigned long long)q->quota);
|
||||
+}
|
||||
+
|
||||
+static void quota_mt2_print(const void *ip, const struct xt_entry_match *match,
|
||||
+ int numeric)
|
||||
+{
|
||||
+ const struct xt_quota_mtinfo2 *q = (const void *)match->data;
|
||||
+
|
||||
+ if (q->flags & XT_QUOTA_INVERT)
|
||||
+ printf(" !");
|
||||
+ if (q->flags & XT_QUOTA_GROW)
|
||||
+ printf(" counter");
|
||||
+ else
|
||||
+ printf(" quota");
|
||||
+ if (*q->name != '\0')
|
||||
+ printf(" %s:", q->name);
|
||||
+ printf(" %llu ", (unsigned long long)q->quota);
|
||||
+ if (q->flags & XT_QUOTA_PACKET)
|
||||
+ printf("packets ");
|
||||
+ else
|
||||
+ printf("bytes ");
|
||||
+ if (q->flags & XT_QUOTA_NO_CHANGE)
|
||||
+ printf("(no-change mode) ");
|
||||
+}
|
||||
+
|
||||
+static struct xtables_match quota_mt2_reg = {
|
||||
+ .family = NFPROTO_UNSPEC,
|
||||
+ .revision = 3,
|
||||
+ .name = "quota2",
|
||||
+ .version = XTABLES_VERSION,
|
||||
+ .size = XT_ALIGN(sizeof (struct xt_quota_mtinfo2)),
|
||||
+ .userspacesize = offsetof(struct xt_quota_mtinfo2, quota),
|
||||
+ .help = quota_mt2_help,
|
||||
+ .x6_parse = quota_mt2_parse,
|
||||
+ .print = quota_mt2_print,
|
||||
+ .save = quota_mt2_save,
|
||||
+ .x6_options = quota_mt2_opts,
|
||||
+};
|
||||
+
|
||||
+void _init(void)
|
||||
+{
|
||||
+ xtables_register_match("a_mt2_reg);
|
||||
+}
|
||||
diff --git a/extensions/libxt_quota2.man b/extensions/libxt_quota2.man
|
||||
new file mode 100644
|
||||
index 0000000..c2e6b44
|
||||
--- /dev/null
|
||||
+++ b/extensions/libxt_quota2.man
|
||||
@@ -0,0 +1,37 @@
|
||||
+The "quota2" implements a named counter which can be increased or decreased
|
||||
+on a per-match basis. Available modes are packet counting or byte counting.
|
||||
+The value of the counter can be read and reset through procfs, thereby making
|
||||
+this match a minimalist accounting tool.
|
||||
+.PP
|
||||
+When counting down from the initial quota, the counter will stop at 0 and
|
||||
+the match will return false, just like the original "quota" match. In growing
|
||||
+(upcounting) mode, it will always return true.
|
||||
+.TP
|
||||
+\fB\-\-grow\fP
|
||||
+Count upwards instead of downwards.
|
||||
+.TP
|
||||
+\fB\-\-no\-change\fP
|
||||
+Makes it so the counter or quota amount is never changed by packets matching
|
||||
+this rule. This is only really useful in "quota" mode, as it will allow you to
|
||||
+use complex prerouting rules in association with the quota system, without
|
||||
+counting a packet twice.
|
||||
+.TP
|
||||
+\fB\-\-name\fP \fIname\fP
|
||||
+Assign the counter a specific name. This option must be present, as an empty
|
||||
+name is not allowed. Names starting with a dot or names containing a slash are
|
||||
+prohibited.
|
||||
+.TP
|
||||
+[\fB!\fP] \fB\-\-quota\fP \fIiq\fP
|
||||
+Specify the initial quota for this counter. If the counter already exists,
|
||||
+it is not reset. An "!" may be used to invert the result of the match. The
|
||||
+negation has no effect when \fB\-\-grow\fP is used.
|
||||
+.TP
|
||||
+\fB\-\-packets\fP
|
||||
+Count packets instead of bytes that passed the quota2 match.
|
||||
+.PP
|
||||
+Because counters in quota2 can be shared, you can combine them for various
|
||||
+purposes, for example, a bytebucket filter that only lets as much traffic go
|
||||
+out as has come in:
|
||||
+.PP
|
||||
+\-A INPUT \-p tcp \-\-dport 6881 \-m quota \-\-name bt \-\-grow;
|
||||
+\-A OUTPUT \-p tcp \-\-sport 6881 \-m quota \-\-name bt;
|
||||
diff --git a/include/linux/netfilter/xt_quota2.h b/include/linux/netfilter/xt_quota2.h
|
||||
new file mode 100644
|
||||
index 0000000..eadc690
|
||||
--- /dev/null
|
||||
+++ b/include/linux/netfilter/xt_quota2.h
|
||||
@@ -0,0 +1,25 @@
|
||||
+#ifndef _XT_QUOTA_H
|
||||
+#define _XT_QUOTA_H
|
||||
+
|
||||
+enum xt_quota_flags {
|
||||
+ XT_QUOTA_INVERT = 1 << 0,
|
||||
+ XT_QUOTA_GROW = 1 << 1,
|
||||
+ XT_QUOTA_PACKET = 1 << 2,
|
||||
+ XT_QUOTA_NO_CHANGE = 1 << 3,
|
||||
+ XT_QUOTA_MASK = 0x0F,
|
||||
+};
|
||||
+
|
||||
+struct xt_quota_counter;
|
||||
+
|
||||
+struct xt_quota_mtinfo2 {
|
||||
+ char name[15];
|
||||
+ u_int8_t flags;
|
||||
+
|
||||
+ /* Comparison-invariant */
|
||||
+ aligned_u64 quota;
|
||||
+
|
||||
+ /* Used internally by the kernel */
|
||||
+ struct xt_quota_counter *master __attribute__((aligned(8)));
|
||||
+};
|
||||
+
|
||||
+#endif /* _XT_QUOTA_H */
|
||||
--
|
||||
1.7.9.5
|
||||
|
||||
33
external/dist/iptables-patches/0008-android-Work-around-broken-Bionic-getaddrinfo.patch
vendored
Normal file
33
external/dist/iptables-patches/0008-android-Work-around-broken-Bionic-getaddrinfo.patch
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
From 796e8ae853183e0361441b62f9995cb37e267f55 Mon Sep 17 00:00:00 2001
|
||||
From: Kevin Cernekee <cernekee@gmail.com>
|
||||
Date: Sun, 27 Oct 2013 11:27:27 -0700
|
||||
Subject: [PATCH 8/8] android: Work around broken Bionic getaddrinfo()
|
||||
|
||||
The first argument to getaddrifo(), "hostname", is normally allowed
|
||||
to be NULL. However, some Bionic implementations erroneously call
|
||||
strlen() on this parameter without first checking to see if it is
|
||||
NULL. Work around this by passing in a hostname of "0.0.0.0".
|
||||
|
||||
This problem was seen on the HTC One SV stock ROM, JB 4.1.2.
|
||||
|
||||
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
|
||||
---
|
||||
libxtables/xtoptions.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/libxtables/xtoptions.c b/libxtables/xtoptions.c
|
||||
index 78e9abd..c206c1d 100644
|
||||
--- a/libxtables/xtoptions.c
|
||||
+++ b/libxtables/xtoptions.c
|
||||
@@ -561,7 +561,7 @@ static int xtables_getportbyname(const char *name)
|
||||
struct addrinfo *res = NULL, *p;
|
||||
int ret;
|
||||
|
||||
- ret = getaddrinfo(NULL, name, NULL, &res);
|
||||
+ ret = getaddrinfo("0.0.0.0", name, NULL, &res);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
ret = -1;
|
||||
--
|
||||
1.7.9.5
|
||||
|
||||
33
external/dist/iptables-patches/0009-ip6tables-Use-consistent-exit-code-for-EAGAIN.patch
vendored
Normal file
33
external/dist/iptables-patches/0009-ip6tables-Use-consistent-exit-code-for-EAGAIN.patch
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
From bb7abec605cf7bc3bb1b1d65e5cd9f57921fc020 Mon Sep 17 00:00:00 2001
|
||||
From: Kevin Cernekee <cernekee@gmail.com>
|
||||
Date: Fri, 1 Nov 2013 20:48:33 -0700
|
||||
Subject: [PATCH 9/9] ip6tables: Use consistent exit code for EAGAIN
|
||||
|
||||
As of commit 056564f6a (Add new exit value to indicate concurrency
|
||||
issues), the IPv4 iptables binary returns exit status 4 to indicate that
|
||||
the kernel returned EAGAIN when trying to update a table. But ip6tables
|
||||
still returns exit status 1 under the same circumstances. Update
|
||||
ip6tables to bring it in line with iptables behavior.
|
||||
|
||||
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
|
||||
---
|
||||
iptables/ip6tables-standalone.c | 3 +++
|
||||
1 file changed, 3 insertions(+)
|
||||
|
||||
diff --git a/iptables/ip6tables-standalone.c b/iptables/ip6tables-standalone.c
|
||||
index 656e08d..4e20fe6 100644
|
||||
--- a/iptables/ip6tables-standalone.c
|
||||
+++ b/iptables/ip6tables-standalone.c
|
||||
@@ -73,6 +73,9 @@ ip6tables_main(int argc, char *argv[])
|
||||
fprintf(stderr, "ip6tables: %s.\n",
|
||||
ip6tc_strerror(errno));
|
||||
}
|
||||
+ if (errno == EAGAIN) {
|
||||
+ exit(RESOURCE_PROBLEM);
|
||||
+ }
|
||||
}
|
||||
|
||||
exit(!ret);
|
||||
--
|
||||
1.7.9.5
|
||||
|
||||
114
external/dist/old-pathches/busybox-022-ipv6.patch
vendored
Normal file
114
external/dist/old-pathches/busybox-022-ipv6.patch
vendored
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
From c04d001c962e756d152abc1dbd58edfdbfee45a1 Mon Sep 17 00:00:00 2001
|
||||
From: Tias Guns <tias@ulyssis.org>
|
||||
Date: Mon, 19 Mar 2012 18:24:29 +0000
|
||||
Subject: [PATCH] fix ipv6, add ipv6_route.h
|
||||
|
||||
from 'in6_rtmsg' by Dan Drown
|
||||
"in6_rtmsg defined in linux/ipv6_route.h"
|
||||
http://dan.drown.org/android/src/busybox/
|
||||
---
|
||||
include/linux/ipv6_route.h | 58 ++++++++++++++++++++++++++++++++++++++++++++
|
||||
networking/ifconfig.c | 2 +
|
||||
networking/route.c | 2 +
|
||||
3 files changed, 62 insertions(+), 0 deletions(-)
|
||||
create mode 100644 include/linux/ipv6_route.h
|
||||
|
||||
diff --git a/include/linux/ipv6_route.h b/include/linux/ipv6_route.h
|
||||
new file mode 100644
|
||||
index 0000000..144875d
|
||||
--- /dev/null
|
||||
+++ b/include/linux/ipv6_route.h
|
||||
@@ -0,0 +1,58 @@
|
||||
+/*
|
||||
+ * Linux INET6 implementation
|
||||
+ *
|
||||
+ * Authors:
|
||||
+ * Pedro Roque <roque@di.fc.ul.pt>
|
||||
+ *
|
||||
+ * This program is free software; you can redistribute it and/or
|
||||
+ * modify it under the terms of the GNU General Public License
|
||||
+ * as published by the Free Software Foundation; either version
|
||||
+ * 2 of the License, or (at your option) any later version.
|
||||
+ */
|
||||
+
|
||||
+#ifndef _LINUX_IPV6_ROUTE_H
|
||||
+#define _LINUX_IPV6_ROUTE_H
|
||||
+
|
||||
+#include <linux/types.h>
|
||||
+
|
||||
+#define RTF_DEFAULT 0x00010000 /* default - learned via ND */
|
||||
+#define RTF_ALLONLINK 0x00020000 /* (deprecated and will be removed)
|
||||
+ fallback, no routers on link */
|
||||
+#define RTF_ADDRCONF 0x00040000 /* addrconf route - RA */
|
||||
+#define RTF_PREFIX_RT 0x00080000 /* A prefix only route - RA */
|
||||
+#define RTF_ANYCAST 0x00100000 /* Anycast */
|
||||
+
|
||||
+#define RTF_NONEXTHOP 0x00200000 /* route with no nexthop */
|
||||
+#define RTF_EXPIRES 0x00400000
|
||||
+
|
||||
+#define RTF_ROUTEINFO 0x00800000 /* route information - RA */
|
||||
+
|
||||
+#define RTF_CACHE 0x01000000 /* cache entry */
|
||||
+#define RTF_FLOW 0x02000000 /* flow significant route */
|
||||
+#define RTF_POLICY 0x04000000 /* policy route */
|
||||
+
|
||||
+#define RTF_PREF(pref) ((pref) << 27)
|
||||
+#define RTF_PREF_MASK 0x18000000
|
||||
+
|
||||
+#define RTF_LOCAL 0x80000000
|
||||
+
|
||||
+
|
||||
+struct in6_rtmsg {
|
||||
+ struct in6_addr rtmsg_dst;
|
||||
+ struct in6_addr rtmsg_src;
|
||||
+ struct in6_addr rtmsg_gateway;
|
||||
+ __u32 rtmsg_type;
|
||||
+ __u16 rtmsg_dst_len;
|
||||
+ __u16 rtmsg_src_len;
|
||||
+ __u32 rtmsg_metric;
|
||||
+ unsigned long rtmsg_info;
|
||||
+ __u32 rtmsg_flags;
|
||||
+ int rtmsg_ifindex;
|
||||
+};
|
||||
+
|
||||
+#define RTMSG_NEWDEVICE 0x11
|
||||
+#define RTMSG_DELDEVICE 0x12
|
||||
+#define RTMSG_NEWROUTE 0x21
|
||||
+#define RTMSG_DELROUTE 0x22
|
||||
+
|
||||
+#endif
|
||||
diff --git a/networking/ifconfig.c b/networking/ifconfig.c
|
||||
index b6604f5..12e8198 100644
|
||||
--- a/networking/ifconfig.c
|
||||
+++ b/networking/ifconfig.c
|
||||
@@ -79,12 +79,14 @@
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_IPV6
|
||||
+#ifndef __BIONIC__
|
||||
struct in6_ifreq {
|
||||
struct in6_addr ifr6_addr;
|
||||
uint32_t ifr6_prefixlen;
|
||||
int ifr6_ifindex;
|
||||
};
|
||||
#endif
|
||||
+#endif
|
||||
|
||||
/*
|
||||
* Here are the bit masks for the "flags" member of struct options below.
|
||||
diff --git a/networking/route.c b/networking/route.c
|
||||
index b7b5a02..a060eb2 100644
|
||||
--- a/networking/route.c
|
||||
+++ b/networking/route.c
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
#include <net/route.h>
|
||||
#include <net/if.h>
|
||||
+#include <linux/in6.h>
|
||||
+#include <linux/ipv6_route.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "inet_common.h"
|
||||
--
|
||||
1.7.0.4
|
||||
|
||||
10
external/nflog/Android.mk
vendored
Normal file
10
external/nflog/Android.mk
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
# Build original nflog
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_CFLAGS += -fvisibility=default -fPIE
|
||||
LOCAL_LDFLAGS += -rdynamic -fPIE -pie
|
||||
LOCAL_MODULE := nflog
|
||||
LOCAL_SRC_FILES := attr.c callback.c nflog.c nlmsg.c socket.c
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
753
external/nflog/attr.c
vendored
Normal file
753
external/nflog/attr.c
vendored
Normal file
|
|
@ -0,0 +1,753 @@
|
|||
/*
|
||||
* (C) 2008-2012 by Pablo Neira Ayuso <pablo@netfilter.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
#include <limits.h> /* for INT_MAX */
|
||||
#include <libmnl/libmnl.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "internal.h"
|
||||
|
||||
/**
|
||||
* \defgroup attr Netlink attribute helpers
|
||||
*
|
||||
* Netlink Type-Length-Value (TLV) attribute:
|
||||
* \verbatim
|
||||
|<-- 2 bytes -->|<-- 2 bytes -->|<-- variable -->|
|
||||
-------------------------------------------------
|
||||
| length | type | value |
|
||||
-------------------------------------------------
|
||||
|<--------- header ------------>|<-- payload --->|
|
||||
\endverbatim
|
||||
* The payload of the Netlink message contains sequences of attributes that are
|
||||
* expressed in TLV format.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* mnl_attr_get_type - get type of netlink attribute
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the attribute type.
|
||||
*/
|
||||
uint16_t mnl_attr_get_type(const struct nlattr *attr)
|
||||
{
|
||||
return attr->nla_type & NLA_TYPE_MASK;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_get_type);
|
||||
|
||||
/**
|
||||
* mnl_attr_get_len - get length of netlink attribute
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the attribute length that is the attribute header
|
||||
* plus the attribute payload.
|
||||
*/
|
||||
uint16_t mnl_attr_get_len(const struct nlattr *attr)
|
||||
{
|
||||
return attr->nla_len;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_get_len);
|
||||
|
||||
/**
|
||||
* mnl_attr_get_payload_len - get the attribute payload-value length
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the attribute payload-value length.
|
||||
*/
|
||||
uint16_t mnl_attr_get_payload_len(const struct nlattr *attr)
|
||||
{
|
||||
return attr->nla_len - MNL_ATTR_HDRLEN;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_get_payload_len);
|
||||
|
||||
/**
|
||||
* mnl_attr_get_payload - get pointer to the attribute payload
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function return a pointer to the attribute payload.
|
||||
*/
|
||||
void *mnl_attr_get_payload(const struct nlattr *attr)
|
||||
{
|
||||
return (void *)attr + MNL_ATTR_HDRLEN;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_get_payload);
|
||||
|
||||
/**
|
||||
* mnl_attr_ok - check if there is room for an attribute in a buffer
|
||||
* \param attr attribute that we want to check if there is room for
|
||||
* \param len remaining bytes in a buffer that contains the attribute
|
||||
*
|
||||
* This function is used to check that a buffer, which is supposed to contain
|
||||
* an attribute, has enough room for the attribute that it stores, i.e. this
|
||||
* function can be used to verify that an attribute is neither malformed nor
|
||||
* truncated.
|
||||
*
|
||||
* This function does not set errno in case of error since it is intended
|
||||
* for iterations. Thus, it returns 1 on success and 0 on error.
|
||||
*
|
||||
* The len parameter may be negative in the case of malformed messages during
|
||||
* attribute iteration, that is why we use a signed integer.
|
||||
*/
|
||||
bool mnl_attr_ok(const struct nlattr *attr, int len)
|
||||
{
|
||||
return len >= (int)sizeof(struct nlattr) &&
|
||||
attr->nla_len >= sizeof(struct nlattr) &&
|
||||
(int)attr->nla_len <= len;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_ok);
|
||||
|
||||
/**
|
||||
* mnl_attr_next - get the next attribute in the payload of a netlink message
|
||||
* \param attr pointer to the current attribute
|
||||
* \param len length of the remaining bytes in the buffer (passed by reference).
|
||||
*
|
||||
* This function returns a pointer to the next attribute after the one passed
|
||||
* as parameter. You have to use mnl_attr_ok() to ensure that the next
|
||||
* attribute is valid.
|
||||
*/
|
||||
struct nlattr *mnl_attr_next(const struct nlattr *attr)
|
||||
{
|
||||
return (struct nlattr *)((void *)attr + MNL_ALIGN(attr->nla_len));
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_next);
|
||||
|
||||
/**
|
||||
* mnl_attr_type_valid - check if the attribute type is valid
|
||||
* \param attr pointer to attribute to be checked
|
||||
* \param max maximum attribute type
|
||||
*
|
||||
* This function allows to check if the attribute type is higher than the
|
||||
* maximum supported type. If the attribute type is invalid, this function
|
||||
* returns -1 and errno is explicitly set. On success, this function returns 1.
|
||||
*
|
||||
* Strict attribute checking in user-space is not a good idea since you may
|
||||
* run an old application with a newer kernel that supports new attributes.
|
||||
* This leads to backward compatibility breakages in user-space. Better check
|
||||
* if you support an attribute, if not, skip it.
|
||||
*/
|
||||
int mnl_attr_type_valid(const struct nlattr *attr, uint16_t max)
|
||||
{
|
||||
if (mnl_attr_get_type(attr) > max) {
|
||||
errno = EOPNOTSUPP;
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_type_valid);
|
||||
|
||||
static int __mnl_attr_validate(const struct nlattr *attr,
|
||||
enum mnl_attr_data_type type, size_t exp_len)
|
||||
{
|
||||
uint16_t attr_len = mnl_attr_get_payload_len(attr);
|
||||
const char *attr_data = mnl_attr_get_payload(attr);
|
||||
|
||||
if (attr_len < exp_len) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
switch(type) {
|
||||
case MNL_TYPE_FLAG:
|
||||
if (attr_len > 0) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case MNL_TYPE_NUL_STRING:
|
||||
if (attr_len == 0) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
if (attr_data[attr_len-1] != '\0') {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case MNL_TYPE_STRING:
|
||||
if (attr_len == 0) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case MNL_TYPE_NESTED:
|
||||
/* empty nested attributes are OK. */
|
||||
if (attr_len == 0)
|
||||
break;
|
||||
/* if not empty, they must contain one header, eg. flag */
|
||||
if (attr_len < MNL_ATTR_HDRLEN) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* make gcc happy. */
|
||||
break;
|
||||
}
|
||||
if (exp_len && attr_len > exp_len) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const size_t mnl_attr_data_type_len[MNL_TYPE_MAX] = {
|
||||
[MNL_TYPE_U8] = sizeof(uint8_t),
|
||||
[MNL_TYPE_U16] = sizeof(uint16_t),
|
||||
[MNL_TYPE_U32] = sizeof(uint32_t),
|
||||
[MNL_TYPE_U64] = sizeof(uint64_t),
|
||||
};
|
||||
|
||||
/**
|
||||
* mnl_attr_validate - validate netlink attribute (simplified version)
|
||||
* \param attr pointer to netlink attribute that we want to validate
|
||||
* \param type data type (see enum mnl_attr_data_type)
|
||||
*
|
||||
* The validation is based on the data type. Specifically, it checks that
|
||||
* integers (u8, u16, u32 and u64) have enough room for them. This function
|
||||
* returns -1 in case of error, and errno is explicitly set.
|
||||
*/
|
||||
int mnl_attr_validate(const struct nlattr *attr, enum mnl_attr_data_type type)
|
||||
{
|
||||
int exp_len;
|
||||
|
||||
if (type >= MNL_TYPE_MAX) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
exp_len = mnl_attr_data_type_len[type];
|
||||
return __mnl_attr_validate(attr, type, exp_len);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_validate);
|
||||
|
||||
/**
|
||||
* mnl_attr_validate2 - validate netlink attribute (extended version)
|
||||
* \param attr pointer to netlink attribute that we want to validate
|
||||
* \param type attribute type (see enum mnl_attr_data_type)
|
||||
* \param exp_len expected attribute data size
|
||||
*
|
||||
* This function allows to perform a more accurate validation for attributes
|
||||
* whose size is variable. If the size of the attribute is not what we expect,
|
||||
* this functions returns -1 and errno is explicitly set.
|
||||
*/
|
||||
int
|
||||
mnl_attr_validate2(const struct nlattr *attr, enum mnl_attr_data_type type,
|
||||
size_t exp_len)
|
||||
{
|
||||
if (type >= MNL_TYPE_MAX) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
return __mnl_attr_validate(attr, type, exp_len);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_validate2);
|
||||
|
||||
/**
|
||||
* mnl_attr_parse - parse attributes
|
||||
* \param nlh pointer to netlink message
|
||||
* \param offset offset to start parsing from (if payload is after any header)
|
||||
* \param cb callback function that is called for each attribute
|
||||
* \param data pointer to data that is passed to the callback function
|
||||
*
|
||||
* This function allows to iterate over the sequence of attributes that compose
|
||||
* the Netlink message. You can then put the attribute in an array as it
|
||||
* usually happens at this stage or you can use any other data structure (such
|
||||
* as lists or trees).
|
||||
*
|
||||
* This function propagates the return value of the callback, which can be
|
||||
* MNL_CB_ERROR, MNL_CB_OK or MNL_CB_STOP.
|
||||
*/
|
||||
int
|
||||
mnl_attr_parse(const struct nlmsghdr *nlh, unsigned int offset,
|
||||
mnl_attr_cb_t cb, void *data)
|
||||
{
|
||||
int ret = MNL_CB_OK;
|
||||
const struct nlattr *attr;
|
||||
|
||||
mnl_attr_for_each(attr, nlh, offset)
|
||||
if ((ret = cb(attr, data)) <= MNL_CB_STOP)
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_parse);
|
||||
|
||||
/**
|
||||
* mnl_attr_parse_nested - parse attributes inside a nest
|
||||
* \param nested pointer to netlink attribute that contains a nest
|
||||
* \param cb callback function that is called for each attribute in the nest
|
||||
* \param data pointer to data passed to the callback function
|
||||
*
|
||||
* This function allows to iterate over the sequence of attributes that compose
|
||||
* the Netlink message. You can then put the attribute in an array as it
|
||||
* usually happens at this stage or you can use any other data structure (such
|
||||
* as lists or trees).
|
||||
*
|
||||
* This function propagates the return value of the callback, which can be
|
||||
* MNL_CB_ERROR, MNL_CB_OK or MNL_CB_STOP.
|
||||
*/
|
||||
int
|
||||
mnl_attr_parse_nested(const struct nlattr *nested, mnl_attr_cb_t cb,
|
||||
void *data)
|
||||
{
|
||||
int ret = MNL_CB_OK;
|
||||
const struct nlattr *attr;
|
||||
|
||||
mnl_attr_for_each_nested(attr, nested)
|
||||
if ((ret = cb(attr, data)) <= MNL_CB_STOP)
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_parse_nested);
|
||||
|
||||
/**
|
||||
* mnl_attr_parse_payload - parse attributes in payload of Netlink message
|
||||
* \param payload pointer to payload of the Netlink message
|
||||
* \param payload_len payload length that contains the attributes
|
||||
* \param cb callback function that is called for each attribute
|
||||
* \param data pointer to data that is passed to the callback function
|
||||
*
|
||||
* This function takes a pointer to the area that contains the attributes,
|
||||
* commonly known as the payload of the Netlink message. Thus, you have to
|
||||
* pass a pointer to the Netlink message payload, instead of the entire
|
||||
* message.
|
||||
*
|
||||
* This function allows you to iterate over the sequence of attributes that are
|
||||
* located at some payload offset. You can then put the attributes in one array
|
||||
* as usual, or you can use any other data structure (such as lists or trees).
|
||||
*
|
||||
* This function propagates the return value of the callback, which can be
|
||||
* MNL_CB_ERROR, MNL_CB_OK or MNL_CB_STOP.
|
||||
*/
|
||||
int
|
||||
mnl_attr_parse_payload(const void *payload, size_t payload_len,
|
||||
mnl_attr_cb_t cb, void *data)
|
||||
{
|
||||
int ret = MNL_CB_OK;
|
||||
const struct nlattr *attr;
|
||||
|
||||
mnl_attr_for_each_payload(payload, payload_len)
|
||||
if ((ret = cb(attr, data)) <= MNL_CB_STOP)
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_parse_payload);
|
||||
|
||||
/**
|
||||
* mnl_attr_get_u8 - returns 8-bit unsigned integer attribute payload
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the 8-bit value of the attribute payload.
|
||||
*/
|
||||
uint8_t mnl_attr_get_u8(const struct nlattr *attr)
|
||||
{
|
||||
return *((uint8_t *)mnl_attr_get_payload(attr));
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_get_u8);
|
||||
|
||||
/**
|
||||
* mnl_attr_get_u16 - returns 16-bit unsigned integer attribute payload
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the 16-bit value of the attribute payload.
|
||||
*/
|
||||
uint16_t mnl_attr_get_u16(const struct nlattr *attr)
|
||||
{
|
||||
return *((uint16_t *)mnl_attr_get_payload(attr));
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_get_u16);
|
||||
|
||||
/**
|
||||
* mnl_attr_get_u32 - returns 32-bit unsigned integer attribute payload
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the 32-bit value of the attribute payload.
|
||||
*/
|
||||
uint32_t mnl_attr_get_u32(const struct nlattr *attr)
|
||||
{
|
||||
return *((uint32_t *)mnl_attr_get_payload(attr));
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_get_u32);
|
||||
|
||||
/**
|
||||
* mnl_attr_get_u64 - returns 64-bit unsigned integer attribute.
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the 64-bit value of the attribute payload. This
|
||||
* function is align-safe, since accessing 64-bit Netlink attributes is a
|
||||
* common source of alignment issues.
|
||||
*/
|
||||
uint64_t mnl_attr_get_u64(const struct nlattr *attr)
|
||||
{
|
||||
uint64_t tmp;
|
||||
memcpy(&tmp, mnl_attr_get_payload(attr), sizeof(tmp));
|
||||
return tmp;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_get_u64);
|
||||
|
||||
/**
|
||||
* mnl_attr_get_str - returns pointer to string attribute.
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the payload of string attribute value.
|
||||
*/
|
||||
const char *mnl_attr_get_str(const struct nlattr *attr)
|
||||
{
|
||||
return mnl_attr_get_payload(attr);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_get_str);
|
||||
|
||||
/**
|
||||
* mnl_attr_put - add an attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type that you want to add
|
||||
* \param len netlink attribute payload length
|
||||
* \param data pointer to the data that will be stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void
|
||||
mnl_attr_put(struct nlmsghdr *nlh, uint16_t type, size_t len, const void *data)
|
||||
{
|
||||
struct nlattr *attr = mnl_nlmsg_get_payload_tail(nlh);
|
||||
uint16_t payload_len = MNL_ALIGN(sizeof(struct nlattr)) + len;
|
||||
|
||||
attr->nla_type = type;
|
||||
attr->nla_len = payload_len;
|
||||
memcpy(mnl_attr_get_payload(attr), data, len);
|
||||
nlh->nlmsg_len += MNL_ALIGN(payload_len);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u8 - add 8-bit unsigned integer attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param len netlink attribute payload size
|
||||
* \param data 8-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_u8(struct nlmsghdr *nlh, uint16_t type, uint8_t data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, sizeof(uint8_t), &data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_u8);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u16 - add 16-bit unsigned integer attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param data 16-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_u16(struct nlmsghdr *nlh, uint16_t type, uint16_t data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, sizeof(uint16_t), &data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_u16);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u32 - add 32-bit unsigned integer attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param data 32-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_u32(struct nlmsghdr *nlh, uint16_t type, uint32_t data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, sizeof(uint32_t), &data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_u32);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u64 - add 64-bit unsigned integer attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param data 64-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_u64(struct nlmsghdr *nlh, uint16_t type, uint64_t data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, sizeof(uint64_t), &data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_u64);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_str - add string attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param data pointer to string data that is stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_str(struct nlmsghdr *nlh, uint16_t type, const char *data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, strlen(data), data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_str);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_strz - add string attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param data pointer to string data that is stored by the new attribute
|
||||
*
|
||||
* This function is similar to mnl_attr_put_str, but it includes the
|
||||
* NUL/zero ('\0') terminator at the end of the string.
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_strz(struct nlmsghdr *nlh, uint16_t type, const char *data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, strlen(data)+1, data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_strz);
|
||||
|
||||
/**
|
||||
* mnl_attr_nest_start - start an attribute nest
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
*
|
||||
* This function adds the attribute header that identifies the beginning of
|
||||
* an attribute nest. This function always returns a valid pointer to the
|
||||
* beginning of the nest.
|
||||
*/
|
||||
struct nlattr *mnl_attr_nest_start(struct nlmsghdr *nlh, uint16_t type)
|
||||
{
|
||||
struct nlattr *start = mnl_nlmsg_get_payload_tail(nlh);
|
||||
|
||||
/* set start->nla_len in mnl_attr_nest_end() */
|
||||
start->nla_type = NLA_F_NESTED | type;
|
||||
nlh->nlmsg_len += MNL_ALIGN(sizeof(struct nlattr));
|
||||
|
||||
return start;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_nest_start);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_check - add an attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type that you want to add
|
||||
* \param len netlink attribute payload length
|
||||
* \param data pointer to the data that will be stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
*/
|
||||
bool
|
||||
mnl_attr_put_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, size_t len, const void *data)
|
||||
{
|
||||
if (nlh->nlmsg_len + MNL_ATTR_HDRLEN + MNL_ALIGN(len) > buflen)
|
||||
return false;
|
||||
mnl_attr_put(nlh, type, len, data);
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_check);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u8_check - add 8-bit unsigned int attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param len netlink attribute payload size
|
||||
* \param data 8-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
*/
|
||||
bool
|
||||
mnl_attr_put_u8_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, uint8_t data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, sizeof(uint8_t), &data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_u8_check);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u16_check - add 16-bit unsigned int attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param data 16-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
bool
|
||||
mnl_attr_put_u16_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, uint16_t data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, sizeof(uint16_t), &data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_u16_check);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u32_check - add 32-bit unsigned int attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param data 32-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
bool
|
||||
mnl_attr_put_u32_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, uint32_t data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, sizeof(uint32_t), &data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_u32_check);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u64_check - add 64-bit unsigned int attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param data 64-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
bool
|
||||
mnl_attr_put_u64_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, uint64_t data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, sizeof(uint64_t), &data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_u64_check);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_str_check - add string attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param data pointer to string data that is stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
bool
|
||||
mnl_attr_put_str_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, const char *data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, strlen(data), data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_str_check);
|
||||
|
||||
/**
|
||||
* mnl_attr_put_strz_check - add string attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param data pointer to string data that is stored by the new attribute
|
||||
*
|
||||
* This function is similar to mnl_attr_put_str, but it includes the
|
||||
* NUL/zero ('\0') terminator at the end of the string.
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
*/
|
||||
bool
|
||||
mnl_attr_put_strz_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, const char *data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, strlen(data)+1, data);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_put_strz_check);
|
||||
|
||||
/**
|
||||
* mnl_attr_nest_start_check - start an attribute nest
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
*
|
||||
* This function adds the attribute header that identifies the beginning of
|
||||
* an attribute nest. If the nested attribute cannot be added then NULL,
|
||||
* otherwise valid pointer to the beginning of the nest is returned.
|
||||
*/
|
||||
struct nlattr *
|
||||
mnl_attr_nest_start_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type)
|
||||
{
|
||||
if (nlh->nlmsg_len + MNL_ATTR_HDRLEN > buflen)
|
||||
return NULL;
|
||||
return mnl_attr_nest_start(nlh, type);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_nest_start_check);
|
||||
|
||||
/**
|
||||
* mnl_attr_nest_end - end an attribute nest
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param start pointer to the attribute nest returned by mnl_attr_nest_start()
|
||||
*
|
||||
* This function updates the attribute header that identifies the nest.
|
||||
*/
|
||||
void
|
||||
mnl_attr_nest_end(struct nlmsghdr *nlh, struct nlattr *start)
|
||||
{
|
||||
start->nla_len = mnl_nlmsg_get_payload_tail(nlh) - (void *)start;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_nest_end);
|
||||
|
||||
/**
|
||||
* mnl_attr_nest_cancel - cancel an attribute nest
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param start pointer to the attribute nest returned by mnl_attr_nest_start()
|
||||
*
|
||||
* This function updates the attribute header that identifies the nest.
|
||||
*/
|
||||
void
|
||||
mnl_attr_nest_cancel(struct nlmsghdr *nlh, struct nlattr *start)
|
||||
{
|
||||
nlh->nlmsg_len -= mnl_nlmsg_get_payload_tail(nlh) - (void *)start;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_attr_nest_cancel);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
161
external/nflog/callback.c
vendored
Normal file
161
external/nflog/callback.c
vendored
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* (C) 2008-2010 by Pablo Neira Ayuso <pablo@netfilter.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <libmnl/libmnl.h>
|
||||
#include "internal.h"
|
||||
|
||||
static int mnl_cb_noop(const struct nlmsghdr *nlh, void *data)
|
||||
{
|
||||
return MNL_CB_OK;
|
||||
}
|
||||
|
||||
static int mnl_cb_error(const struct nlmsghdr *nlh, void *data)
|
||||
{
|
||||
const struct nlmsgerr *err = mnl_nlmsg_get_payload(nlh);
|
||||
|
||||
if (nlh->nlmsg_len < mnl_nlmsg_size(sizeof(struct nlmsgerr))) {
|
||||
errno = EBADMSG;
|
||||
return MNL_CB_ERROR;
|
||||
}
|
||||
/* Netlink subsystems returns the errno value with different signess */
|
||||
if (err->error < 0)
|
||||
errno = -err->error;
|
||||
else
|
||||
errno = err->error;
|
||||
|
||||
return err->error == 0 ? MNL_CB_STOP : MNL_CB_ERROR;
|
||||
}
|
||||
|
||||
static int mnl_cb_stop(const struct nlmsghdr *nlh, void *data)
|
||||
{
|
||||
return MNL_CB_STOP;
|
||||
}
|
||||
|
||||
static const mnl_cb_t default_cb_array[NLMSG_MIN_TYPE] = {
|
||||
[NLMSG_NOOP] = mnl_cb_noop,
|
||||
[NLMSG_ERROR] = mnl_cb_error,
|
||||
[NLMSG_DONE] = mnl_cb_stop,
|
||||
[NLMSG_OVERRUN] = mnl_cb_noop,
|
||||
};
|
||||
|
||||
static inline int
|
||||
__mnl_cb_run(const void *buf, size_t numbytes, unsigned int seq,
|
||||
unsigned int portid, mnl_cb_t cb_data, void *data,
|
||||
mnl_cb_t *cb_ctl_array, unsigned int cb_ctl_array_len)
|
||||
{
|
||||
int ret = MNL_CB_OK, len = numbytes;
|
||||
const struct nlmsghdr *nlh = buf;
|
||||
|
||||
while (mnl_nlmsg_ok(nlh, len)) {
|
||||
/* check message source */
|
||||
if (!mnl_nlmsg_portid_ok(nlh, portid)) {
|
||||
errno = ESRCH;
|
||||
return -1;
|
||||
}
|
||||
/* perform sequence tracking */
|
||||
if (!mnl_nlmsg_seq_ok(nlh, seq)) {
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* netlink data message handling */
|
||||
if (nlh->nlmsg_type >= NLMSG_MIN_TYPE) {
|
||||
if (cb_data){
|
||||
ret = cb_data(nlh, data);
|
||||
if (ret <= MNL_CB_STOP)
|
||||
goto out;
|
||||
}
|
||||
} else if (nlh->nlmsg_type < cb_ctl_array_len) {
|
||||
if (cb_ctl_array && cb_ctl_array[nlh->nlmsg_type]) {
|
||||
ret = cb_ctl_array[nlh->nlmsg_type](nlh, data);
|
||||
if (ret <= MNL_CB_STOP)
|
||||
goto out;
|
||||
}
|
||||
} else if (default_cb_array[nlh->nlmsg_type]) {
|
||||
ret = default_cb_array[nlh->nlmsg_type](nlh, data);
|
||||
if (ret <= MNL_CB_STOP)
|
||||
goto out;
|
||||
}
|
||||
nlh = mnl_nlmsg_next(nlh, &len);
|
||||
}
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* \defgroup callback Callback helpers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* mnl_cb_run2 - callback runqueue for netlink messages
|
||||
* \param buf buffer that contains the netlink messages
|
||||
* \param numbytes number of bytes stored in the buffer
|
||||
* \param seq sequence number that we expect to receive
|
||||
* \param portid Netlink PortID that we expect to receive
|
||||
* \param cb_data callback handler for data messages
|
||||
* \param data pointer to data that will be passed to the data callback handler
|
||||
* \param cb_ctl_array array of custom callback handlers from control messages
|
||||
* \param cb_ctl_array_len array length of custom control callback handlers
|
||||
*
|
||||
* You can set the cb_ctl_array to NULL if you want to use the default control
|
||||
* callback handlers, in that case, the parameter cb_ctl_array_len is not
|
||||
* checked.
|
||||
*
|
||||
* Your callback may return three possible values:
|
||||
* - MNL_CB_ERROR (<=-1): an error has occurred. Stop callback runqueue.
|
||||
* - MNL_CB_STOP (=0): stop callback runqueue.
|
||||
* - MNL_CB_OK (>=1): no problem has occurred.
|
||||
*
|
||||
* This function propagates the callback return value. On error, it returns
|
||||
* -1 and errno is explicitly set. If the portID is not the expected, errno
|
||||
* is set to ESRCH. If the sequence number is not the expected, errno is set
|
||||
* to EPROTO.
|
||||
*/
|
||||
int
|
||||
mnl_cb_run2(const void *buf, size_t numbytes, unsigned int seq,
|
||||
unsigned int portid, mnl_cb_t cb_data, void *data,
|
||||
mnl_cb_t *cb_ctl_array, unsigned int cb_ctl_array_len)
|
||||
{
|
||||
return __mnl_cb_run(buf, numbytes, seq, portid, cb_data, data,
|
||||
cb_ctl_array, cb_ctl_array_len);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_cb_run2);
|
||||
|
||||
/**
|
||||
* mnl_cb_run - callback runqueue for netlink messages (simplified version)
|
||||
* \param buf buffer that contains the netlink messages
|
||||
* \param numbytes number of bytes stored in the buffer
|
||||
* \param seq sequence number that we expect to receive
|
||||
* \param portid Netlink PortID that we expect to receive
|
||||
* \param cb_data callback handler for data messages
|
||||
* \param data pointer to data that will be passed to the data callback handler
|
||||
*
|
||||
* This function is like mnl_cb_run2() but it does not allow you to set
|
||||
* the control callback handlers.
|
||||
*
|
||||
* Your callback may return three possible values:
|
||||
* - MNL_CB_ERROR (<=-1): an error has occurred. Stop callback runqueue.
|
||||
* - MNL_CB_STOP (=0): stop callback runqueue.
|
||||
* - MNL_CB_OK (>=1): no problems has occurred.
|
||||
*
|
||||
* This function propagates the callback return value.
|
||||
*/
|
||||
int
|
||||
mnl_cb_run(const void *buf, size_t numbytes, unsigned int seq,
|
||||
unsigned int portid, mnl_cb_t cb_data, void *data)
|
||||
{
|
||||
return __mnl_cb_run(buf, numbytes, seq, portid, cb_data, data, NULL, 0);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_cb_run);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
69
external/nflog/config.h
vendored
Normal file
69
external/nflog/config.h
vendored
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/* config.h. Generated from config.h.in by configure. */
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* True if compiler supports -fvisibility=hidden */
|
||||
#define HAVE_VISIBILITY_HIDDEN 1
|
||||
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
#define LT_OBJDIR ".libs/"
|
||||
|
||||
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
|
||||
/* #undef NO_MINUS_C_MINUS_O */
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "libmnl"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libmnl"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libmnl 1.0.3"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libmnl"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL ""
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.0.3"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "1.0.3"
|
||||
12
external/nflog/internal.h
vendored
Normal file
12
external/nflog/internal.h
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef INTERNAL_H
|
||||
#define INTERNAL_H 1
|
||||
|
||||
#include "config.h"
|
||||
#ifdef HAVE_VISIBILITY_HIDDEN
|
||||
# define __visible __attribute__((visibility("default")))
|
||||
# define EXPORT_SYMBOL(x) typeof(x) (x) __visible
|
||||
#else
|
||||
# define EXPORT_SYMBOL
|
||||
#endif
|
||||
|
||||
#endif
|
||||
203
external/nflog/libmnl/libmnl.h
vendored
Normal file
203
external/nflog/libmnl/libmnl.h
vendored
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
#ifndef _LIBMNL_H_
|
||||
#define _LIBMNL_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
# include <cstdio>
|
||||
# include <cstdint>
|
||||
#else
|
||||
# include <stdbool.h> /* not in C++ */
|
||||
# include <stdio.h>
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h> /* for sa_family_t */
|
||||
#include <linux/netlink.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Netlink socket API
|
||||
*/
|
||||
|
||||
#define MNL_SOCKET_AUTOPID 0
|
||||
#define MNL_SOCKET_BUFFER_SIZE (getpagesize() < 8192L ? getpagesize() : 8192L)
|
||||
|
||||
struct mnl_socket;
|
||||
|
||||
extern struct mnl_socket *mnl_socket_open(int type);
|
||||
extern int mnl_socket_bind(struct mnl_socket *nl, unsigned int groups, pid_t pid);
|
||||
extern int mnl_socket_close(struct mnl_socket *nl);
|
||||
extern int mnl_socket_get_fd(const struct mnl_socket *nl);
|
||||
extern unsigned int mnl_socket_get_portid(const struct mnl_socket *nl);
|
||||
extern ssize_t mnl_socket_sendto(const struct mnl_socket *nl, const void *req, size_t siz);
|
||||
extern ssize_t mnl_socket_recvfrom(const struct mnl_socket *nl, void *buf, size_t siz);
|
||||
extern int mnl_socket_setsockopt(const struct mnl_socket *nl, int type, void *buf, socklen_t len);
|
||||
extern int mnl_socket_getsockopt(const struct mnl_socket *nl, int type, void *buf, socklen_t *len);
|
||||
|
||||
/*
|
||||
* Netlink message API
|
||||
*/
|
||||
|
||||
#define MNL_ALIGNTO 4
|
||||
#define MNL_ALIGN(len) (((len)+MNL_ALIGNTO-1) & ~(MNL_ALIGNTO-1))
|
||||
#define MNL_NLMSG_HDRLEN MNL_ALIGN(sizeof(struct nlmsghdr))
|
||||
|
||||
extern size_t mnl_nlmsg_size(size_t len);
|
||||
extern size_t mnl_nlmsg_get_payload_len(const struct nlmsghdr *nlh);
|
||||
|
||||
/* Netlink message header builder */
|
||||
extern struct nlmsghdr *mnl_nlmsg_put_header(void *buf);
|
||||
extern void *mnl_nlmsg_put_extra_header(struct nlmsghdr *nlh, size_t size);
|
||||
|
||||
/* Netlink message iterators */
|
||||
extern bool mnl_nlmsg_ok(const struct nlmsghdr *nlh, int len);
|
||||
extern struct nlmsghdr *mnl_nlmsg_next(const struct nlmsghdr *nlh, int *len);
|
||||
|
||||
/* Netlink sequence tracking */
|
||||
extern bool mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq);
|
||||
|
||||
/* Netlink portID checking */
|
||||
extern bool mnl_nlmsg_portid_ok(const struct nlmsghdr *nlh, unsigned int portid);
|
||||
|
||||
/* Netlink message getters */
|
||||
extern void *mnl_nlmsg_get_payload(const struct nlmsghdr *nlh);
|
||||
extern void *mnl_nlmsg_get_payload_offset(const struct nlmsghdr *nlh, size_t offset);
|
||||
extern void *mnl_nlmsg_get_payload_tail(const struct nlmsghdr *nlh);
|
||||
|
||||
/* Netlink message printer */
|
||||
extern void mnl_nlmsg_fprintf(FILE *fd, const void *data, size_t datalen, size_t extra_header_size);
|
||||
|
||||
/* Message batch helpers */
|
||||
struct mnl_nlmsg_batch;
|
||||
extern struct mnl_nlmsg_batch *mnl_nlmsg_batch_start(void *buf, size_t bufsiz);
|
||||
extern bool mnl_nlmsg_batch_next(struct mnl_nlmsg_batch *b);
|
||||
extern void mnl_nlmsg_batch_stop(struct mnl_nlmsg_batch *b);
|
||||
extern size_t mnl_nlmsg_batch_size(struct mnl_nlmsg_batch *b);
|
||||
extern void mnl_nlmsg_batch_reset(struct mnl_nlmsg_batch *b);
|
||||
extern void *mnl_nlmsg_batch_head(struct mnl_nlmsg_batch *b);
|
||||
extern void *mnl_nlmsg_batch_current(struct mnl_nlmsg_batch *b);
|
||||
extern bool mnl_nlmsg_batch_is_empty(struct mnl_nlmsg_batch *b);
|
||||
|
||||
/*
|
||||
* Netlink attributes API
|
||||
*/
|
||||
#define MNL_ATTR_HDRLEN MNL_ALIGN(sizeof(struct nlattr))
|
||||
|
||||
/* TLV attribute getters */
|
||||
extern uint16_t mnl_attr_get_type(const struct nlattr *attr);
|
||||
extern uint16_t mnl_attr_get_len(const struct nlattr *attr);
|
||||
extern uint16_t mnl_attr_get_payload_len(const struct nlattr *attr);
|
||||
extern void *mnl_attr_get_payload(const struct nlattr *attr);
|
||||
extern uint8_t mnl_attr_get_u8(const struct nlattr *attr);
|
||||
extern uint16_t mnl_attr_get_u16(const struct nlattr *attr);
|
||||
extern uint32_t mnl_attr_get_u32(const struct nlattr *attr);
|
||||
extern uint64_t mnl_attr_get_u64(const struct nlattr *attr);
|
||||
extern const char *mnl_attr_get_str(const struct nlattr *attr);
|
||||
|
||||
/* TLV attribute putters */
|
||||
extern void mnl_attr_put(struct nlmsghdr *nlh, uint16_t type, size_t len, const void *data);
|
||||
extern void mnl_attr_put_u8(struct nlmsghdr *nlh, uint16_t type, uint8_t data);
|
||||
extern void mnl_attr_put_u16(struct nlmsghdr *nlh, uint16_t type, uint16_t data);
|
||||
extern void mnl_attr_put_u32(struct nlmsghdr *nlh, uint16_t type, uint32_t data);
|
||||
extern void mnl_attr_put_u64(struct nlmsghdr *nlh, uint16_t type, uint64_t data);
|
||||
extern void mnl_attr_put_str(struct nlmsghdr *nlh, uint16_t type, const char *data);
|
||||
extern void mnl_attr_put_strz(struct nlmsghdr *nlh, uint16_t type, const char *data);
|
||||
|
||||
/* TLV attribute putters with buffer boundary checkings */
|
||||
extern bool mnl_attr_put_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, size_t len, const void *data);
|
||||
extern bool mnl_attr_put_u8_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint8_t data);
|
||||
extern bool mnl_attr_put_u16_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint16_t data);
|
||||
extern bool mnl_attr_put_u32_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint32_t data);
|
||||
extern bool mnl_attr_put_u64_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, uint64_t data);
|
||||
extern bool mnl_attr_put_str_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, const char *data);
|
||||
extern bool mnl_attr_put_strz_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type, const char *data);
|
||||
|
||||
/* TLV attribute nesting */
|
||||
extern struct nlattr *mnl_attr_nest_start(struct nlmsghdr *nlh, uint16_t type);
|
||||
extern struct nlattr *mnl_attr_nest_start_check(struct nlmsghdr *nlh, size_t buflen, uint16_t type);
|
||||
extern void mnl_attr_nest_end(struct nlmsghdr *nlh, struct nlattr *start);
|
||||
extern void mnl_attr_nest_cancel(struct nlmsghdr *nlh, struct nlattr *start);
|
||||
|
||||
/* TLV validation */
|
||||
extern int mnl_attr_type_valid(const struct nlattr *attr, uint16_t maxtype);
|
||||
|
||||
enum mnl_attr_data_type {
|
||||
MNL_TYPE_UNSPEC,
|
||||
MNL_TYPE_U8,
|
||||
MNL_TYPE_U16,
|
||||
MNL_TYPE_U32,
|
||||
MNL_TYPE_U64,
|
||||
MNL_TYPE_STRING,
|
||||
MNL_TYPE_FLAG,
|
||||
MNL_TYPE_MSECS,
|
||||
MNL_TYPE_NESTED,
|
||||
MNL_TYPE_NESTED_COMPAT,
|
||||
MNL_TYPE_NUL_STRING,
|
||||
MNL_TYPE_BINARY,
|
||||
MNL_TYPE_MAX,
|
||||
};
|
||||
|
||||
extern int mnl_attr_validate(const struct nlattr *attr, enum mnl_attr_data_type type);
|
||||
extern int mnl_attr_validate2(const struct nlattr *attr, enum mnl_attr_data_type type, size_t len);
|
||||
|
||||
/* TLV iterators */
|
||||
extern bool mnl_attr_ok(const struct nlattr *attr, int len);
|
||||
extern struct nlattr *mnl_attr_next(const struct nlattr *attr);
|
||||
|
||||
#define mnl_attr_for_each(attr, nlh, offset) \
|
||||
for ((attr) = mnl_nlmsg_get_payload_offset((nlh), (offset)); \
|
||||
mnl_attr_ok((attr), (char *)mnl_nlmsg_get_payload_tail(nlh) - (char *)(attr)); \
|
||||
(attr) = mnl_attr_next(attr))
|
||||
|
||||
#define mnl_attr_for_each_nested(attr, nest) \
|
||||
for ((attr) = mnl_attr_get_payload(nest); \
|
||||
mnl_attr_ok((attr), (char *)mnl_attr_get_payload(nest) + mnl_attr_get_payload_len(nest) - (char *)(attr)); \
|
||||
(attr) = mnl_attr_next(attr))
|
||||
|
||||
#define mnl_attr_for_each_payload(payload, payload_size) \
|
||||
for ((attr) = (payload); \
|
||||
mnl_attr_ok((attr), (char *)(payload) + payload_size - (char *)(attr)); \
|
||||
(attr) = mnl_attr_next(attr))
|
||||
|
||||
/* TLV callback-based attribute parsers */
|
||||
typedef int (*mnl_attr_cb_t)(const struct nlattr *attr, void *data);
|
||||
|
||||
extern int mnl_attr_parse(const struct nlmsghdr *nlh, unsigned int offset, mnl_attr_cb_t cb, void *data);
|
||||
extern int mnl_attr_parse_nested(const struct nlattr *attr, mnl_attr_cb_t cb, void *data);
|
||||
extern int mnl_attr_parse_payload(const void *payload, size_t payload_len, mnl_attr_cb_t cb, void *data);
|
||||
|
||||
/*
|
||||
* callback API
|
||||
*/
|
||||
#define MNL_CB_ERROR -1
|
||||
#define MNL_CB_STOP 0
|
||||
#define MNL_CB_OK 1
|
||||
|
||||
typedef int (*mnl_cb_t)(const struct nlmsghdr *nlh, void *data);
|
||||
|
||||
extern int mnl_cb_run(const void *buf, size_t numbytes, unsigned int seq,
|
||||
unsigned int portid, mnl_cb_t cb_data, void *data);
|
||||
|
||||
extern int mnl_cb_run2(const void *buf, size_t numbytes, unsigned int seq,
|
||||
unsigned int portid, mnl_cb_t cb_data, void *data,
|
||||
mnl_cb_t *cb_ctl_array, unsigned int cb_ctl_array_len);
|
||||
|
||||
/*
|
||||
* other declarations
|
||||
*/
|
||||
|
||||
#ifndef SOL_NETLINK
|
||||
#define SOL_NETLINK 270
|
||||
#endif
|
||||
|
||||
#ifndef MNL_ARRAY_SIZE
|
||||
#define MNL_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
99
external/nflog/linux/netfilter/nfnetlink_log.h
vendored
Normal file
99
external/nflog/linux/netfilter/nfnetlink_log.h
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/* Android NDK r8d is missing nfnetlink_log.h */
|
||||
|
||||
#ifndef _NFNETLINK_LOG_H
|
||||
#define _NFNETLINK_LOG_H
|
||||
|
||||
/* This file describes the netlink messages (i.e. 'protocol packets'),
|
||||
* and not any kind of function definitions. It is shared between kernel and
|
||||
* userspace. Don't put kernel specific stuff in here */
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/netfilter/nfnetlink.h>
|
||||
|
||||
enum nfulnl_msg_types {
|
||||
NFULNL_MSG_PACKET, /* packet from kernel to userspace */
|
||||
NFULNL_MSG_CONFIG, /* connect to a particular queue */
|
||||
|
||||
NFULNL_MSG_MAX
|
||||
};
|
||||
|
||||
struct nfulnl_msg_packet_hdr {
|
||||
__be16 hw_protocol; /* hw protocol (network order) */
|
||||
__u8 hook; /* netfilter hook */
|
||||
__u8 _pad;
|
||||
};
|
||||
|
||||
struct nfulnl_msg_packet_hw {
|
||||
__be16 hw_addrlen;
|
||||
__u16 _pad;
|
||||
__u8 hw_addr[8];
|
||||
};
|
||||
|
||||
struct nfulnl_msg_packet_timestamp {
|
||||
aligned_be64 sec;
|
||||
aligned_be64 usec;
|
||||
};
|
||||
|
||||
enum nfulnl_attr_type {
|
||||
NFULA_UNSPEC,
|
||||
NFULA_PACKET_HDR,
|
||||
NFULA_MARK, /* __u32 nfmark */
|
||||
NFULA_TIMESTAMP, /* nfulnl_msg_packet_timestamp */
|
||||
NFULA_IFINDEX_INDEV, /* __u32 ifindex */
|
||||
NFULA_IFINDEX_OUTDEV, /* __u32 ifindex */
|
||||
NFULA_IFINDEX_PHYSINDEV, /* __u32 ifindex */
|
||||
NFULA_IFINDEX_PHYSOUTDEV, /* __u32 ifindex */
|
||||
NFULA_HWADDR, /* nfulnl_msg_packet_hw */
|
||||
NFULA_PAYLOAD, /* opaque data payload */
|
||||
NFULA_PREFIX, /* string prefix */
|
||||
NFULA_UID, /* user id of socket */
|
||||
NFULA_SEQ, /* instance-local sequence number */
|
||||
NFULA_SEQ_GLOBAL, /* global sequence number */
|
||||
NFULA_GID, /* group id of socket */
|
||||
NFULA_HWTYPE, /* hardware type */
|
||||
NFULA_HWHEADER, /* hardware header */
|
||||
NFULA_HWLEN, /* hardware header length */
|
||||
|
||||
__NFULA_MAX
|
||||
};
|
||||
#define NFULA_MAX (__NFULA_MAX - 1)
|
||||
|
||||
enum nfulnl_msg_config_cmds {
|
||||
NFULNL_CFG_CMD_NONE,
|
||||
NFULNL_CFG_CMD_BIND,
|
||||
NFULNL_CFG_CMD_UNBIND,
|
||||
NFULNL_CFG_CMD_PF_BIND,
|
||||
NFULNL_CFG_CMD_PF_UNBIND,
|
||||
};
|
||||
|
||||
struct nfulnl_msg_config_cmd {
|
||||
__u8 command; /* nfulnl_msg_config_cmds */
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct nfulnl_msg_config_mode {
|
||||
__be32 copy_range;
|
||||
__u8 copy_mode;
|
||||
__u8 _pad;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
enum nfulnl_attr_config {
|
||||
NFULA_CFG_UNSPEC,
|
||||
NFULA_CFG_CMD, /* nfulnl_msg_config_cmd */
|
||||
NFULA_CFG_MODE, /* nfulnl_msg_config_mode */
|
||||
NFULA_CFG_NLBUFSIZ, /* __u32 buffer size */
|
||||
NFULA_CFG_TIMEOUT, /* __u32 in 1/100 s */
|
||||
NFULA_CFG_QTHRESH, /* __u32 */
|
||||
NFULA_CFG_FLAGS, /* __u16 */
|
||||
__NFULA_CFG_MAX
|
||||
};
|
||||
#define NFULA_CFG_MAX (__NFULA_CFG_MAX -1)
|
||||
|
||||
#define NFULNL_COPY_NONE 0x00
|
||||
#define NFULNL_COPY_META 0x01
|
||||
#define NFULNL_COPY_PACKET 0x02
|
||||
/* 0xff is reserved, don't use it for new copy modes. */
|
||||
|
||||
#define NFULNL_CFG_F_SEQ 0x0001
|
||||
#define NFULNL_CFG_F_SEQ_GLOBAL 0x0002
|
||||
|
||||
#endif /* _NFNETLINK_LOG_H */
|
||||
148
external/nflog/linux/netlink.h
vendored
Normal file
148
external/nflog/linux/netlink.h
vendored
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
#ifndef __LINUX_NETLINK_H
|
||||
#define __LINUX_NETLINK_H
|
||||
|
||||
#include <linux/socket.h> /* for sa_family_t */
|
||||
#include <linux/types.h>
|
||||
|
||||
#define NETLINK_ROUTE 0 /* Routing/device hook */
|
||||
#define NETLINK_UNUSED 1 /* Unused number */
|
||||
#define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */
|
||||
#define NETLINK_FIREWALL 3 /* Firewalling hook */
|
||||
#define NETLINK_INET_DIAG 4 /* INET socket monitoring */
|
||||
#define NETLINK_NFLOG 5 /* netfilter/iptables ULOG */
|
||||
#define NETLINK_XFRM 6 /* ipsec */
|
||||
#define NETLINK_SELINUX 7 /* SELinux event notifications */
|
||||
#define NETLINK_ISCSI 8 /* Open-iSCSI */
|
||||
#define NETLINK_AUDIT 9 /* auditing */
|
||||
#define NETLINK_FIB_LOOKUP 10
|
||||
#define NETLINK_CONNECTOR 11
|
||||
#define NETLINK_NETFILTER 12 /* netfilter subsystem */
|
||||
#define NETLINK_IP6_FW 13
|
||||
#define NETLINK_DNRTMSG 14 /* DECnet routing messages */
|
||||
#define NETLINK_KOBJECT_UEVENT 15 /* Kernel messages to userspace */
|
||||
#define NETLINK_GENERIC 16
|
||||
/* leave room for NETLINK_DM (DM Events) */
|
||||
#define NETLINK_SCSITRANSPORT 18 /* SCSI Transports */
|
||||
#define NETLINK_ECRYPTFS 19
|
||||
|
||||
#define MAX_LINKS 32
|
||||
|
||||
struct sockaddr_nl {
|
||||
sa_family_t nl_family; /* AF_NETLINK */
|
||||
unsigned short nl_pad; /* zero */
|
||||
__u32 nl_pid; /* port ID */
|
||||
__u32 nl_groups; /* multicast groups mask */
|
||||
};
|
||||
|
||||
struct nlmsghdr {
|
||||
__u32 nlmsg_len; /* Length of message including header */
|
||||
__u16 nlmsg_type; /* Message content */
|
||||
__u16 nlmsg_flags; /* Additional flags */
|
||||
__u32 nlmsg_seq; /* Sequence number */
|
||||
__u32 nlmsg_pid; /* Sending process port ID */
|
||||
};
|
||||
|
||||
/* Flags values */
|
||||
|
||||
#define NLM_F_REQUEST 1 /* It is request message. */
|
||||
#define NLM_F_MULTI 2 /* Multipart message, terminated by NLMSG_DONE */
|
||||
#define NLM_F_ACK 4 /* Reply with ack, with zero or error code */
|
||||
#define NLM_F_ECHO 8 /* Echo this request */
|
||||
|
||||
/* Modifiers to GET request */
|
||||
#define NLM_F_ROOT 0x100 /* specify tree root */
|
||||
#define NLM_F_MATCH 0x200 /* return all matching */
|
||||
#define NLM_F_ATOMIC 0x400 /* atomic GET */
|
||||
#define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
|
||||
|
||||
/* Modifiers to NEW request */
|
||||
#define NLM_F_REPLACE 0x100 /* Override existing */
|
||||
#define NLM_F_EXCL 0x200 /* Do not touch, if it exists */
|
||||
#define NLM_F_CREATE 0x400 /* Create, if it does not exist */
|
||||
#define NLM_F_APPEND 0x800 /* Add to end of list */
|
||||
|
||||
/*
|
||||
4.4BSD ADD NLM_F_CREATE|NLM_F_EXCL
|
||||
4.4BSD CHANGE NLM_F_REPLACE
|
||||
|
||||
True CHANGE NLM_F_CREATE|NLM_F_REPLACE
|
||||
Append NLM_F_CREATE
|
||||
Check NLM_F_EXCL
|
||||
*/
|
||||
|
||||
#define NLMSG_ALIGNTO 4U
|
||||
#define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
|
||||
#define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
|
||||
#define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(NLMSG_HDRLEN))
|
||||
#define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
|
||||
#define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
|
||||
#define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
|
||||
(struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
|
||||
#define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
|
||||
(nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
|
||||
(nlh)->nlmsg_len <= (len))
|
||||
#define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
|
||||
|
||||
#define NLMSG_NOOP 0x1 /* Nothing. */
|
||||
#define NLMSG_ERROR 0x2 /* Error */
|
||||
#define NLMSG_DONE 0x3 /* End of a dump */
|
||||
#define NLMSG_OVERRUN 0x4 /* Data lost */
|
||||
|
||||
#define NLMSG_MIN_TYPE 0x10 /* < 0x10: reserved control messages */
|
||||
|
||||
struct nlmsgerr {
|
||||
int error;
|
||||
struct nlmsghdr msg;
|
||||
};
|
||||
|
||||
#define NETLINK_ADD_MEMBERSHIP 1
|
||||
#define NETLINK_DROP_MEMBERSHIP 2
|
||||
#define NETLINK_PKTINFO 3
|
||||
#define NETLINK_BROADCAST_ERROR 4
|
||||
#define NETLINK_NO_ENOBUFS 5
|
||||
|
||||
struct nl_pktinfo {
|
||||
__u32 group;
|
||||
};
|
||||
|
||||
#define NET_MAJOR 36 /* Major 36 is reserved for networking */
|
||||
|
||||
enum {
|
||||
NETLINK_UNCONNECTED = 0,
|
||||
NETLINK_CONNECTED,
|
||||
};
|
||||
|
||||
/*
|
||||
* <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
|
||||
* +---------------------+- - -+- - - - - - - - - -+- - -+
|
||||
* | Header | Pad | Payload | Pad |
|
||||
* | (struct nlattr) | ing | | ing |
|
||||
* +---------------------+- - -+- - - - - - - - - -+- - -+
|
||||
* <-------------- nlattr->nla_len -------------->
|
||||
*/
|
||||
|
||||
struct nlattr {
|
||||
__u16 nla_len;
|
||||
__u16 nla_type;
|
||||
};
|
||||
|
||||
/*
|
||||
* nla_type (16 bits)
|
||||
* +---+---+-------------------------------+
|
||||
* | N | O | Attribute Type |
|
||||
* +---+---+-------------------------------+
|
||||
* N := Carries nested attributes
|
||||
* O := Payload stored in network byte order
|
||||
*
|
||||
* Note: The N and O flag are mutually exclusive.
|
||||
*/
|
||||
#define NLA_F_NESTED (1 << 15)
|
||||
#define NLA_F_NET_BYTEORDER (1 << 14)
|
||||
#define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
|
||||
|
||||
#define NLA_ALIGNTO 4
|
||||
#define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
|
||||
#define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
|
||||
|
||||
|
||||
#endif /* __LINUX_NETLINK_H */
|
||||
672
external/nflog/nflog.c
vendored
Normal file
672
external/nflog/nflog.c
vendored
Normal file
|
|
@ -0,0 +1,672 @@
|
|||
/* Enhanced NFLOG implementation for AFWall+
|
||||
* (C) 2012 Pragmatic Software - Original implementation
|
||||
* (C) 2025 AFWall+ Project - Enhancements and optimizations
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/
|
||||
*
|
||||
* Enhanced features:
|
||||
* - Improved memory management and leak prevention
|
||||
* - Better error handling and recovery
|
||||
* - Optimized interface name caching
|
||||
* - Enhanced buffer management
|
||||
* - Signal handling for graceful shutdown
|
||||
* - Backward compatibility maintained
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <libmnl/libmnl.h>
|
||||
#include <linux/netfilter.h>
|
||||
#include <linux/netfilter/nfnetlink.h>
|
||||
#include <linux/ip.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/ipv6.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <linux/udp.h>
|
||||
#include <linux/icmp.h>
|
||||
#include <linux/icmpv6.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#ifndef aligned_be64
|
||||
#define aligned_be64 u_int64_t __attribute__((aligned(8)))
|
||||
#endif
|
||||
|
||||
#include <linux/netfilter/nfnetlink_log.h>
|
||||
|
||||
// Enhanced configuration constants
|
||||
#define MAX_NETDEVICES 64 // Increased from 32 for better device support
|
||||
#define INTERFACE_CACHE_TTL 300 // Cache interfaces for 5 minutes
|
||||
#define DEFAULT_BUFFER_SIZE (32 * 1024) // 32KB default buffer
|
||||
|
||||
// Enhanced structures for interface caching
|
||||
struct interface_cache_entry {
|
||||
int ifindex;
|
||||
char ifname[IFNAMSIZ];
|
||||
time_t timestamp;
|
||||
int valid;
|
||||
};
|
||||
|
||||
// Global state with better organization
|
||||
static struct interface_cache_entry device_cache[MAX_NETDEVICES] = {{0}};
|
||||
static struct mnl_socket *nl = NULL;
|
||||
static int shutdown_requested = 0;
|
||||
static char *recv_buffer = NULL;
|
||||
static size_t recv_buffer_size = DEFAULT_BUFFER_SIZE;
|
||||
|
||||
// Function declarations
|
||||
char *enhanced_if_indextoname(unsigned int ifindex, char *ifname);
|
||||
void cleanup_enhanced(void);
|
||||
void signal_handler(int sig);
|
||||
static int parse_attr_cb(const struct nlattr *attr, void *data);
|
||||
static int log_cb(const struct nlmsghdr *nlh, void *data);
|
||||
|
||||
// Enhanced interface name resolution with caching and proper error handling
|
||||
char *enhanced_if_indextoname(unsigned int ifindex, char *ifname) {
|
||||
if (ifindex == 0 || ifindex >= MAX_NETDEVICES || !ifname) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct interface_cache_entry *entry = &device_cache[ifindex];
|
||||
|
||||
// Check cache validity
|
||||
if (entry->valid && entry->ifindex == ifindex &&
|
||||
(now - entry->timestamp) < INTERFACE_CACHE_TTL) {
|
||||
strncpy(ifname, entry->ifname, IFNAMSIZ - 1);
|
||||
ifname[IFNAMSIZ - 1] = '\0';
|
||||
return ifname;
|
||||
}
|
||||
|
||||
// Cache miss or expired - lookup interface name
|
||||
struct ifreq ifr;
|
||||
int fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
ifr.ifr_ifindex = ifindex;
|
||||
int status = ioctl(fd, SIOCGIFNAME, &ifr);
|
||||
close(fd);
|
||||
|
||||
if (status < 0) {
|
||||
if (errno == ENODEV) {
|
||||
errno = ENXIO;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Update cache with proper bounds checking
|
||||
entry->ifindex = ifindex;
|
||||
strncpy(entry->ifname, ifr.ifr_name, IFNAMSIZ - 1);
|
||||
entry->ifname[IFNAMSIZ - 1] = '\0';
|
||||
entry->timestamp = now;
|
||||
entry->valid = 1;
|
||||
|
||||
// Return the cached name
|
||||
strncpy(ifname, entry->ifname, IFNAMSIZ - 1);
|
||||
ifname[IFNAMSIZ - 1] = '\0';
|
||||
return ifname;
|
||||
}
|
||||
|
||||
// Original function maintained for compatibility
|
||||
char *netlog_if_indextoname(unsigned int ifindex, char *ifname) {
|
||||
return enhanced_if_indextoname(ifindex, ifname);
|
||||
}
|
||||
|
||||
// Enhanced cleanup function
|
||||
void cleanup_enhanced(void) {
|
||||
shutdown_requested = 1;
|
||||
|
||||
if (nl) {
|
||||
mnl_socket_close(nl);
|
||||
nl = NULL;
|
||||
}
|
||||
|
||||
if (recv_buffer) {
|
||||
free(recv_buffer);
|
||||
recv_buffer = NULL;
|
||||
}
|
||||
|
||||
// Clear interface cache
|
||||
memset(device_cache, 0, sizeof(device_cache));
|
||||
|
||||
fprintf(stderr, "Enhanced NFLOG shutdown complete\n");
|
||||
}
|
||||
|
||||
// Original cleanup function maintained for compatibility
|
||||
void cleanup(void) {
|
||||
cleanup_enhanced();
|
||||
}
|
||||
|
||||
// Free net devices function maintained for compatibility
|
||||
void free_net_devices(void) {
|
||||
// In enhanced version, we use static cache, so just clear it
|
||||
memset(device_cache, 0, sizeof(device_cache));
|
||||
}
|
||||
|
||||
// Signal handler for graceful shutdown
|
||||
void signal_handler(int sig) {
|
||||
fprintf(stderr, "Received signal %d, shutting down gracefully...\n", sig);
|
||||
shutdown_requested = 1;
|
||||
}
|
||||
|
||||
// Enhanced attribute parsing with better error handling
|
||||
static int parse_attr_cb(const struct nlattr *attr, void *data) {
|
||||
const struct nlattr **tb = data;
|
||||
int type = mnl_attr_get_type(attr);
|
||||
|
||||
/* skip unsupported attribute in user-space */
|
||||
if (mnl_attr_type_valid(attr, NFULA_MAX) < 0) {
|
||||
return MNL_CB_OK;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case NFULA_HWTYPE:
|
||||
if (mnl_attr_validate(attr, MNL_TYPE_U16) < 0) {
|
||||
perror("mnl_attr_validate HWTYPE");
|
||||
return MNL_CB_ERROR;
|
||||
}
|
||||
break;
|
||||
case NFULA_MARK:
|
||||
case NFULA_IFINDEX_INDEV:
|
||||
case NFULA_IFINDEX_OUTDEV:
|
||||
case NFULA_IFINDEX_PHYSINDEV:
|
||||
case NFULA_IFINDEX_PHYSOUTDEV:
|
||||
if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) {
|
||||
perror("mnl_attr_validate U32");
|
||||
return MNL_CB_ERROR;
|
||||
}
|
||||
break;
|
||||
case NFULA_TIMESTAMP:
|
||||
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC,
|
||||
sizeof(struct nfulnl_msg_packet_timestamp)) < 0) {
|
||||
perror("mnl_attr_validate TIMESTAMP");
|
||||
return MNL_CB_ERROR;
|
||||
}
|
||||
break;
|
||||
case NFULA_HWADDR:
|
||||
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC,
|
||||
sizeof(struct nfulnl_msg_packet_hw)) < 0) {
|
||||
perror("mnl_attr_validate HWADDR");
|
||||
return MNL_CB_ERROR;
|
||||
}
|
||||
break;
|
||||
case NFULA_PACKET_HDR:
|
||||
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC,
|
||||
sizeof(struct nfulnl_msg_packet_hdr)) < 0) {
|
||||
perror("mnl_attr_validate PACKET_HDR");
|
||||
return MNL_CB_ERROR;
|
||||
}
|
||||
break;
|
||||
case NFULA_PREFIX:
|
||||
if (mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0) {
|
||||
perror("mnl_attr_validate PREFIX");
|
||||
return MNL_CB_ERROR;
|
||||
}
|
||||
break;
|
||||
case NFULA_PAYLOAD:
|
||||
// Payload doesn't need validation
|
||||
break;
|
||||
default:
|
||||
// Unknown attribute type, skip
|
||||
break;
|
||||
}
|
||||
|
||||
tb[type] = attr;
|
||||
return MNL_CB_OK;
|
||||
}
|
||||
|
||||
// Enhanced log callback with improved error handling and memory safety
|
||||
static int log_cb(const struct nlmsghdr *nlh, void *data) {
|
||||
struct nlattr *tb[NFULA_MAX+1] = {};
|
||||
char ifname_buf[IFNAMSIZ];
|
||||
|
||||
if (!nlh) {
|
||||
return MNL_CB_ERROR;
|
||||
}
|
||||
|
||||
if (mnl_attr_parse(nlh, sizeof(struct nfgenmsg), parse_attr_cb, tb) < 0) {
|
||||
return MNL_CB_ERROR;
|
||||
}
|
||||
|
||||
// Print prefix if available
|
||||
if (tb[NFULA_PREFIX]) {
|
||||
const char *prefix = mnl_attr_get_str(tb[NFULA_PREFIX]);
|
||||
if (prefix) {
|
||||
printf("%s ", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle input interface
|
||||
if (tb[NFULA_IFINDEX_INDEV]) {
|
||||
uint32_t indev = ntohl(mnl_attr_get_u32(tb[NFULA_IFINDEX_INDEV]));
|
||||
char *instr = enhanced_if_indextoname(indev, ifname_buf);
|
||||
printf("IN=%s ", instr ? instr : "");
|
||||
} else {
|
||||
printf("IN= ");
|
||||
}
|
||||
|
||||
// Handle output interface
|
||||
if (tb[NFULA_IFINDEX_OUTDEV]) {
|
||||
uint32_t outdev = ntohl(mnl_attr_get_u32(tb[NFULA_IFINDEX_OUTDEV]));
|
||||
char *outstr = enhanced_if_indextoname(outdev, ifname_buf);
|
||||
printf("OUT=%s ", outstr ? outstr : "");
|
||||
} else {
|
||||
printf("OUT= ");
|
||||
}
|
||||
|
||||
// Process packet payload
|
||||
uint16_t hwProtocol = 0;
|
||||
if (tb[NFULA_PACKET_HDR]) {
|
||||
struct nfulnl_msg_packet_hdr* pktHdr =
|
||||
(struct nfulnl_msg_packet_hdr*)mnl_attr_get_payload(tb[NFULA_PACKET_HDR]);
|
||||
if (pktHdr) {
|
||||
hwProtocol = ntohs(pktHdr->hw_protocol);
|
||||
}
|
||||
}
|
||||
|
||||
if (tb[NFULA_PAYLOAD]) {
|
||||
switch (hwProtocol) {
|
||||
case ETH_P_IP: {
|
||||
struct iphdr *iph = (struct iphdr *) mnl_attr_get_payload(tb[NFULA_PAYLOAD]);
|
||||
if (iph && mnl_attr_get_payload_len(tb[NFULA_PAYLOAD]) >= sizeof(struct iphdr)) {
|
||||
char addressStr[INET_ADDRSTRLEN];
|
||||
|
||||
// Source address
|
||||
if (inet_ntop(AF_INET, &iph->saddr, addressStr, sizeof(addressStr))) {
|
||||
printf("SRC=%s ", addressStr);
|
||||
}
|
||||
|
||||
// Destination address
|
||||
if (inet_ntop(AF_INET, &iph->daddr, addressStr, sizeof(addressStr))) {
|
||||
printf("DST=%s ", addressStr);
|
||||
}
|
||||
|
||||
printf("LEN=%u ", ntohs(iph->tot_len));
|
||||
|
||||
// Protocol-specific processing with bounds checking
|
||||
int header_len = iph->ihl * 4;
|
||||
if (header_len >= sizeof(struct iphdr) &&
|
||||
mnl_attr_get_payload_len(tb[NFULA_PAYLOAD]) >= header_len) {
|
||||
|
||||
switch(iph->protocol) {
|
||||
case IPPROTO_TCP: {
|
||||
if (mnl_attr_get_payload_len(tb[NFULA_PAYLOAD]) >=
|
||||
header_len + sizeof(struct tcphdr)) {
|
||||
struct tcphdr *th = (struct tcphdr *)
|
||||
((uint8_t*)iph + header_len);
|
||||
printf("PROTO=TCP SPT=%u DPT=%u ",
|
||||
ntohs(th->source), ntohs(th->dest));
|
||||
} else {
|
||||
printf("PROTO=TCP ");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IPPROTO_UDP: {
|
||||
if (mnl_attr_get_payload_len(tb[NFULA_PAYLOAD]) >=
|
||||
header_len + sizeof(struct udphdr)) {
|
||||
struct udphdr *uh = (struct udphdr *)
|
||||
((uint8_t*)iph + header_len);
|
||||
printf("PROTO=UDP SPT=%u DPT=%u LEN=%u ",
|
||||
ntohs(uh->source), ntohs(uh->dest), ntohs(uh->len));
|
||||
} else {
|
||||
printf("PROTO=UDP ");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IPPROTO_ICMP: {
|
||||
if (mnl_attr_get_payload_len(tb[NFULA_PAYLOAD]) >=
|
||||
header_len + sizeof(struct icmphdr)) {
|
||||
struct icmphdr *ich = (struct icmphdr *)
|
||||
((uint8_t*)iph + header_len);
|
||||
printf("PROTO=ICMP TYPE=%u CODE=%u ",
|
||||
ich->type, ich->code);
|
||||
} else {
|
||||
printf("PROTO=ICMP ");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf("PROTO=%u ", iph->protocol);
|
||||
}
|
||||
} else {
|
||||
printf("PROTO=%u ", iph->protocol);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ETH_P_IPV6: {
|
||||
struct ipv6hdr *iph = (struct ipv6hdr *) mnl_attr_get_payload(tb[NFULA_PAYLOAD]);
|
||||
if (iph && mnl_attr_get_payload_len(tb[NFULA_PAYLOAD]) >= sizeof(struct ipv6hdr)) {
|
||||
char addressStr[INET6_ADDRSTRLEN];
|
||||
|
||||
// Source address
|
||||
if (inet_ntop(AF_INET6, &iph->saddr, addressStr, sizeof(addressStr))) {
|
||||
printf("SRC=%s ", addressStr);
|
||||
}
|
||||
|
||||
// Destination address
|
||||
if (inet_ntop(AF_INET6, &iph->daddr, addressStr, sizeof(addressStr))) {
|
||||
printf("DST=%s ", addressStr);
|
||||
}
|
||||
|
||||
// Protocol-specific processing with bounds checking
|
||||
if (mnl_attr_get_payload_len(tb[NFULA_PAYLOAD]) >=
|
||||
sizeof(struct ipv6hdr) + 4) { // At least IPv6 header + some payload
|
||||
|
||||
switch (iph->nexthdr) {
|
||||
case IPPROTO_TCP: {
|
||||
if (mnl_attr_get_payload_len(tb[NFULA_PAYLOAD]) >=
|
||||
sizeof(struct ipv6hdr) + sizeof(struct tcphdr)) {
|
||||
struct tcphdr *th = (struct tcphdr *)
|
||||
((uint8_t*) iph + sizeof(*iph));
|
||||
printf("PROTO=TCP SPT=%u DPT=%u ",
|
||||
ntohs(th->source), ntohs(th->dest));
|
||||
} else {
|
||||
printf("PROTO=TCP ");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IPPROTO_UDP: {
|
||||
if (mnl_attr_get_payload_len(tb[NFULA_PAYLOAD]) >=
|
||||
sizeof(struct ipv6hdr) + sizeof(struct udphdr)) {
|
||||
struct udphdr *uh = (struct udphdr *)
|
||||
((uint8_t *) iph + sizeof(*iph));
|
||||
printf("PROTO=UDP SPT=%u DPT=%u LEN=%u ",
|
||||
ntohs(uh->source), ntohs(uh->dest), ntohs(uh->len));
|
||||
} else {
|
||||
printf("PROTO=UDP ");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IPPROTO_ICMPV6: {
|
||||
if (mnl_attr_get_payload_len(tb[NFULA_PAYLOAD]) >=
|
||||
sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr)) {
|
||||
struct icmp6hdr *icmpv6h = (struct icmp6hdr *)
|
||||
((uint8_t *) iph + sizeof(*iph));
|
||||
printf("PROTO=ICMP6 TYPE=%u CODE=%u ",
|
||||
icmpv6h->icmp6_type, icmpv6h->icmp6_code);
|
||||
} else {
|
||||
printf("PROTO=ICMP6 ");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf("PROTO=%d ", iph->nexthdr);
|
||||
}
|
||||
} else {
|
||||
printf("PROTO=%d ", iph->nexthdr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Unknown or unsupported protocol
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// UID information
|
||||
if (tb[NFULA_UID]) {
|
||||
uint32_t uid = ntohl(mnl_attr_get_u32(tb[NFULA_UID]));
|
||||
printf("UID=%u ", uid);
|
||||
}
|
||||
|
||||
// End the log line
|
||||
puts("");
|
||||
fflush(stdout);
|
||||
|
||||
return MNL_CB_OK;
|
||||
}
|
||||
|
||||
// Configuration helper functions (enhanced with error checking)
|
||||
static struct nlmsghdr *nflog_build_cfg_pf_request(char *buf, uint8_t command) {
|
||||
if (!buf) return NULL;
|
||||
|
||||
struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf);
|
||||
nlh->nlmsg_type = (NFNL_SUBSYS_ULOG << 8) | NFULNL_MSG_CONFIG;
|
||||
nlh->nlmsg_flags = NLM_F_REQUEST;
|
||||
|
||||
struct nfgenmsg *nfg = mnl_nlmsg_put_extra_header(nlh, sizeof(*nfg));
|
||||
nfg->nfgen_family = AF_INET;
|
||||
nfg->version = NFNETLINK_V0;
|
||||
|
||||
struct nfulnl_msg_config_cmd cmd = {
|
||||
.command = command,
|
||||
};
|
||||
mnl_attr_put(nlh, NFULA_CFG_CMD, sizeof(cmd), &cmd);
|
||||
|
||||
return nlh;
|
||||
}
|
||||
|
||||
static struct nlmsghdr *nflog_build_cfg_request(char *buf, uint8_t command, int qnum) {
|
||||
if (!buf || qnum < 0 || qnum > 65535) return NULL;
|
||||
|
||||
struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf);
|
||||
nlh->nlmsg_type = (NFNL_SUBSYS_ULOG << 8) | NFULNL_MSG_CONFIG;
|
||||
nlh->nlmsg_flags = NLM_F_REQUEST;
|
||||
|
||||
struct nfgenmsg *nfg = mnl_nlmsg_put_extra_header(nlh, sizeof(*nfg));
|
||||
nfg->nfgen_family = AF_INET;
|
||||
nfg->version = NFNETLINK_V0;
|
||||
nfg->res_id = htons(qnum);
|
||||
|
||||
struct nfulnl_msg_config_cmd cmd = {
|
||||
.command = command,
|
||||
};
|
||||
mnl_attr_put(nlh, NFULA_CFG_CMD, sizeof(cmd), &cmd);
|
||||
|
||||
return nlh;
|
||||
}
|
||||
|
||||
static struct nlmsghdr *nflog_build_cfg_params(char *buf, uint8_t mode, int range, int qnum) {
|
||||
if (!buf || qnum < 0 || qnum > 65535 || range < 0) return NULL;
|
||||
|
||||
struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf);
|
||||
nlh->nlmsg_type = (NFNL_SUBSYS_ULOG << 8) | NFULNL_MSG_CONFIG;
|
||||
nlh->nlmsg_flags = NLM_F_REQUEST;
|
||||
|
||||
struct nfgenmsg *nfg = mnl_nlmsg_put_extra_header(nlh, sizeof(*nfg));
|
||||
nfg->nfgen_family = AF_UNSPEC;
|
||||
nfg->version = NFNETLINK_V0;
|
||||
nfg->res_id = htons(qnum);
|
||||
|
||||
struct nfulnl_msg_config_mode params = {
|
||||
.copy_range = htonl(range),
|
||||
.copy_mode = mode,
|
||||
};
|
||||
mnl_attr_put(nlh, NFULA_CFG_MODE, sizeof(params), ¶ms);
|
||||
|
||||
return nlh;
|
||||
}
|
||||
|
||||
// Enhanced main function with better error handling and resource management
|
||||
int main(int argc, char *argv[]) {
|
||||
char buf[MNL_SOCKET_BUFFER_SIZE];
|
||||
struct nlmsghdr *nlh;
|
||||
int ret, nfds, sock_fd, stdin_fd;
|
||||
unsigned int portid, qnum;
|
||||
|
||||
// Install signal handlers for graceful shutdown
|
||||
signal(SIGINT, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGPIPE, SIG_IGN); // Ignore broken pipe
|
||||
|
||||
atexit(cleanup_enhanced);
|
||||
|
||||
// Validate command line arguments
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s [queue_num]\n", argv[0]);
|
||||
fprintf(stderr, "Enhanced NFLOG implementation with improved reliability\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Parse and validate queue number
|
||||
char *endptr;
|
||||
long qnum_long = strtol(argv[1], &endptr, 10);
|
||||
if (*endptr != '\0' || qnum_long < 0 || qnum_long > 65535) {
|
||||
fprintf(stderr, "Error: Invalid queue number. Must be 0-65535\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
qnum = (unsigned int)qnum_long;
|
||||
|
||||
// Allocate enhanced receive buffer
|
||||
recv_buffer = malloc(recv_buffer_size);
|
||||
if (!recv_buffer) {
|
||||
perror("Failed to allocate receive buffer");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Initialize netlink socket
|
||||
nl = mnl_socket_open(NETLINK_NETFILTER);
|
||||
if (nl == NULL) {
|
||||
perror("mnl_socket_open");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
|
||||
perror("mnl_socket_bind");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
portid = mnl_socket_get_portid(nl);
|
||||
|
||||
// Set socket buffer size for better performance
|
||||
int sock_buffer_size = recv_buffer_size * 2;
|
||||
if (setsockopt(mnl_socket_get_fd(nl), SOL_SOCKET, SO_RCVBUF,
|
||||
&sock_buffer_size, sizeof(sock_buffer_size)) < 0) {
|
||||
perror("Warning: setsockopt SO_RCVBUF failed");
|
||||
// Continue anyway - not fatal
|
||||
}
|
||||
|
||||
// Configure NFLOG with enhanced error checking
|
||||
nlh = nflog_build_cfg_pf_request(buf, NFULNL_CFG_CMD_PF_UNBIND);
|
||||
if (!nlh) {
|
||||
fprintf(stderr, "Error: Failed to build PF unbind request\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
|
||||
perror("mnl_socket_send PF unbind");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nlh = nflog_build_cfg_pf_request(buf, NFULNL_CFG_CMD_PF_BIND);
|
||||
if (!nlh) {
|
||||
fprintf(stderr, "Error: Failed to build PF bind request\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
|
||||
perror("mnl_socket_send PF bind");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nlh = nflog_build_cfg_request(buf, NFULNL_CFG_CMD_BIND, qnum);
|
||||
if (!nlh) {
|
||||
fprintf(stderr, "Error: Failed to build queue bind request\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
|
||||
perror("mnl_socket_send queue bind");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nlh = nflog_build_cfg_params(buf, NFULNL_COPY_PACKET, 0xFFFF, qnum);
|
||||
if (!nlh) {
|
||||
fprintf(stderr, "Error: Failed to build config params request\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
|
||||
perror("mnl_socket_send config params");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sock_fd = mnl_socket_get_fd(nl);
|
||||
stdin_fd = fileno(stdin);
|
||||
nfds = (sock_fd > stdin_fd ? sock_fd : stdin_fd) + 1;
|
||||
|
||||
if (fcntl(sock_fd, F_SETFL, O_NONBLOCK) < 0 ||
|
||||
fcntl(stdin_fd, F_SETFL, O_NONBLOCK) < 0) {
|
||||
perror("fcntl");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fprintf(stderr, "Enhanced NFLOG started on queue %u\n", qnum);
|
||||
|
||||
// Enhanced main loop with better error handling
|
||||
while (!shutdown_requested) {
|
||||
fd_set fds;
|
||||
char c;
|
||||
int select_result;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(sock_fd, &fds);
|
||||
FD_SET(stdin_fd, &fds);
|
||||
|
||||
select_result = select(nfds, &fds, NULL, NULL, NULL);
|
||||
|
||||
if (select_result < 0) {
|
||||
if (errno == EINTR) {
|
||||
// Interrupted by signal, check shutdown flag
|
||||
continue;
|
||||
}
|
||||
perror("select");
|
||||
break;
|
||||
}
|
||||
|
||||
if (FD_ISSET(stdin_fd, &fds)) {
|
||||
// Check for stdin closure or input
|
||||
if (read(stdin_fd, &c, 1) <= 0) {
|
||||
fprintf(stderr, "stdin closed, shutting down...\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!FD_ISSET(sock_fd, &fds)) {
|
||||
// No data on socket
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = mnl_socket_recvfrom(nl, recv_buffer, recv_buffer_size);
|
||||
if (ret == -1) {
|
||||
if (errno == ENOSPC || errno == ENOBUFS) {
|
||||
// Buffer overrun - usually recoverable
|
||||
fprintf(stderr, "Warning: Buffer overrun, some packets may be lost\n");
|
||||
continue;
|
||||
} else if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
// No data available - normal with O_NONBLOCK
|
||||
continue;
|
||||
} else {
|
||||
perror("mnl_socket_recvfrom");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
fprintf(stderr, "Socket closed by remote end\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (mnl_cb_run(recv_buffer, ret, 0, portid, log_cb, NULL) < 0) {
|
||||
perror("mnl_cb_run");
|
||||
// Don't exit on callback errors - try to continue
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "Enhanced NFLOG shutting down gracefully\n");
|
||||
return 0;
|
||||
}
|
||||
573
external/nflog/nlmsg.c
vendored
Normal file
573
external/nflog/nlmsg.c
vendored
Normal file
|
|
@ -0,0 +1,573 @@
|
|||
/*
|
||||
* (C) 2008-2010 by Pablo Neira Ayuso <pablo@netfilter.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <libmnl/libmnl.h>
|
||||
#include "internal.h"
|
||||
|
||||
/**
|
||||
* \defgroup nlmsg Netlink message helpers
|
||||
*
|
||||
* Netlink message:
|
||||
* \verbatim
|
||||
|<----------------- 4 bytes ------------------->|
|
||||
|<----- 2 bytes ------>|<------- 2 bytes ------>|
|
||||
|-----------------------------------------------|
|
||||
| Message length (including header) |
|
||||
|-----------------------------------------------|
|
||||
| Message type | Message flags |
|
||||
|-----------------------------------------------|
|
||||
| Message sequence number |
|
||||
|-----------------------------------------------|
|
||||
| Netlink PortID |
|
||||
|-----------------------------------------------|
|
||||
| |
|
||||
. Payload .
|
||||
|_______________________________________________|
|
||||
\endverbatim
|
||||
*
|
||||
* There is usually an extra header after the the Netlink header (at the
|
||||
* beginning of the payload). This extra header is specific of the Netlink
|
||||
* subsystem. After this extra header, it comes the sequence of attributes
|
||||
* that are expressed in Type-Length-Value (TLV) format.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_size - calculate the size of Netlink message (without alignment)
|
||||
* \param len length of the Netlink payload
|
||||
*
|
||||
* This function returns the size of a netlink message (header plus payload)
|
||||
* without alignment.
|
||||
*/
|
||||
size_t mnl_nlmsg_size(size_t len)
|
||||
{
|
||||
return len + MNL_NLMSG_HDRLEN;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_size);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_get_payload_len - get the length of the Netlink payload
|
||||
* \param nlh pointer to the header of the Netlink message
|
||||
*
|
||||
* This function returns the Length of the netlink payload, ie. the length
|
||||
* of the full message minus the size of the Netlink header.
|
||||
*/
|
||||
size_t mnl_nlmsg_get_payload_len(const struct nlmsghdr *nlh)
|
||||
{
|
||||
return nlh->nlmsg_len - MNL_NLMSG_HDRLEN;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_get_payload_len);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_put_header - reserve and prepare room for Netlink header
|
||||
* \param buf memory already allocated to store the Netlink header
|
||||
*
|
||||
* This function sets to zero the room that is required to put the Netlink
|
||||
* header in the memory buffer passed as parameter. This function also
|
||||
* initializes the nlmsg_len field to the size of the Netlink header. This
|
||||
* function returns a pointer to the Netlink header structure.
|
||||
*/
|
||||
struct nlmsghdr *mnl_nlmsg_put_header(void *buf)
|
||||
{
|
||||
int len = MNL_ALIGN(sizeof(struct nlmsghdr));
|
||||
struct nlmsghdr *nlh = buf;
|
||||
|
||||
memset(buf, 0, len);
|
||||
nlh->nlmsg_len = len;
|
||||
return nlh;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_put_header);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_put_extra_header - reserve and prepare room for an extra header
|
||||
* \param nlh pointer to Netlink header
|
||||
* \param size size of the extra header that we want to put
|
||||
*
|
||||
* This function sets to zero the room that is required to put the extra
|
||||
* header after the initial Netlink header. This function also increases
|
||||
* the nlmsg_len field. You have to invoke mnl_nlmsg_put_header() before
|
||||
* you call this function. This function returns a pointer to the extra
|
||||
* header.
|
||||
*/
|
||||
void *
|
||||
mnl_nlmsg_put_extra_header(struct nlmsghdr *nlh, size_t size)
|
||||
{
|
||||
char *ptr = (char *)nlh + nlh->nlmsg_len;
|
||||
size_t len = MNL_ALIGN(size);
|
||||
nlh->nlmsg_len += len;
|
||||
memset(ptr, 0, len);
|
||||
return ptr;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_put_extra_header);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_get_payload - get a pointer to the payload of the netlink message
|
||||
* \param nlh pointer to a netlink header
|
||||
*
|
||||
* This function returns a pointer to the payload of the netlink message.
|
||||
*/
|
||||
void *mnl_nlmsg_get_payload(const struct nlmsghdr *nlh)
|
||||
{
|
||||
return (void *)nlh + MNL_NLMSG_HDRLEN;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_get_payload);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_get_payload_offset - get a pointer to the payload of the message
|
||||
* \param nlh pointer to a netlink header
|
||||
* \param offset offset to the payload of the attributes TLV set
|
||||
*
|
||||
* This function returns a pointer to the payload of the netlink message plus
|
||||
* a given offset.
|
||||
*/
|
||||
void *
|
||||
mnl_nlmsg_get_payload_offset(const struct nlmsghdr *nlh, size_t offset)
|
||||
{
|
||||
return (void *)nlh + MNL_NLMSG_HDRLEN + MNL_ALIGN(offset);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_get_payload_offset);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_ok - check a there is room for netlink message
|
||||
* \param nlh netlink message that we want to check
|
||||
* \param len remaining bytes in a buffer that contains the netlink message
|
||||
*
|
||||
* This function is used to check that a buffer that contains a netlink
|
||||
* message has enough room for the netlink message that it stores, ie. this
|
||||
* function can be used to verify that a netlink message is not malformed nor
|
||||
* truncated.
|
||||
*
|
||||
* This function does not set errno in case of error since it is intended
|
||||
* for iterations. Thus, it returns 1 on success and 0 on error.
|
||||
*
|
||||
* The len parameter may become negative in malformed messages during message
|
||||
* iteration, that is why we use a signed integer.
|
||||
*/
|
||||
bool mnl_nlmsg_ok(const struct nlmsghdr *nlh, int len)
|
||||
{
|
||||
return len >= (int)sizeof(struct nlmsghdr) &&
|
||||
nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
|
||||
(int)nlh->nlmsg_len <= len;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_ok);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_next - get the next netlink message in a multipart message
|
||||
* \param nlh current netlink message that we are handling
|
||||
* \param len length of the remaining bytes in the buffer (passed by reference).
|
||||
*
|
||||
* This function returns a pointer to the next netlink message that is part
|
||||
* of a multi-part netlink message. Netlink can batch several messages into
|
||||
* one buffer so that the receiver has to iterate over the whole set of
|
||||
* Netlink messages.
|
||||
*
|
||||
* You have to use mnl_nlmsg_ok() to check if the next Netlink message is
|
||||
* valid.
|
||||
*/
|
||||
struct nlmsghdr *
|
||||
mnl_nlmsg_next(const struct nlmsghdr *nlh, int *len)
|
||||
{
|
||||
*len -= MNL_ALIGN(nlh->nlmsg_len);
|
||||
return (struct nlmsghdr *)((void *)nlh + MNL_ALIGN(nlh->nlmsg_len));
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_next);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_get_payload_tail - get the ending of the netlink message
|
||||
* \param nlh pointer to netlink message
|
||||
*
|
||||
* This function returns a pointer to the netlink message tail. This is useful
|
||||
* to build a message since we continue adding attributes at the end of the
|
||||
* message.
|
||||
*/
|
||||
void *mnl_nlmsg_get_payload_tail(const struct nlmsghdr *nlh)
|
||||
{
|
||||
return (void *)nlh + MNL_ALIGN(nlh->nlmsg_len);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_get_payload_tail);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_seq_ok - perform sequence tracking
|
||||
* \param nlh current netlink message that we are handling
|
||||
* \param seq last sequence number used to send a message
|
||||
*
|
||||
* This functions returns true if the sequence tracking is fulfilled, otherwise
|
||||
* false is returned. We skip the tracking for netlink messages whose sequence
|
||||
* number is zero since it is usually reserved for event-based kernel
|
||||
* notifications. On the other hand, if seq is set but the message sequence
|
||||
* number is not set (i.e. this is an event message coming from kernel-space),
|
||||
* then we also skip the tracking. This approach is good if we use the same
|
||||
* socket to send commands to kernel-space (that we want to track) and to
|
||||
* listen to events (that we do not track).
|
||||
*/
|
||||
bool
|
||||
mnl_nlmsg_seq_ok(const struct nlmsghdr *nlh, unsigned int seq)
|
||||
{
|
||||
return nlh->nlmsg_seq && seq ? nlh->nlmsg_seq == seq : true;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_seq_ok);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_portid_ok - perform portID origin check
|
||||
* \param nlh current netlink message that we are handling
|
||||
* \param seq netlink portid that we want to check
|
||||
*
|
||||
* This functions returns true if the origin is fulfilled, otherwise
|
||||
* false is returned. We skip the tracking for netlink message whose portID
|
||||
* is zero since it is reserved for event-based kernel notifications. On the
|
||||
* other hand, if portid is set but the message PortID is not (i.e. this
|
||||
* is an event message coming from kernel-space), then we also skip the
|
||||
* tracking. This approach is good if we use the same socket to send commands
|
||||
* to kernel-space (that we want to track) and to listen to events (that we
|
||||
* do not track).
|
||||
*/
|
||||
bool
|
||||
mnl_nlmsg_portid_ok(const struct nlmsghdr *nlh, unsigned int portid)
|
||||
{
|
||||
return nlh->nlmsg_pid && portid ? nlh->nlmsg_pid == portid : true;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_portid_ok);
|
||||
|
||||
static void mnl_nlmsg_fprintf_header(FILE *fd, const struct nlmsghdr *nlh)
|
||||
{
|
||||
fprintf(fd, "----------------\t------------------\n");
|
||||
fprintf(fd, "| %.010u |\t| message length |\n", nlh->nlmsg_len);
|
||||
fprintf(fd, "| %.05u | %c%c%c%c |\t| type | flags |\n",
|
||||
nlh->nlmsg_type,
|
||||
nlh->nlmsg_flags & NLM_F_REQUEST ? 'R' : '-',
|
||||
nlh->nlmsg_flags & NLM_F_MULTI ? 'M' : '-',
|
||||
nlh->nlmsg_flags & NLM_F_ACK ? 'A' : '-',
|
||||
nlh->nlmsg_flags & NLM_F_ECHO ? 'E' : '-');
|
||||
fprintf(fd, "| %.010u |\t| sequence number|\n", nlh->nlmsg_seq);
|
||||
fprintf(fd, "| %.010u |\t| port ID |\n", nlh->nlmsg_pid);
|
||||
fprintf(fd, "----------------\t------------------\n");
|
||||
}
|
||||
|
||||
static void
|
||||
mnl_nlmsg_fprintf_payload(FILE *fd, const struct nlmsghdr *nlh,
|
||||
size_t extra_header_size)
|
||||
{
|
||||
int rem = 0;
|
||||
unsigned int i;
|
||||
|
||||
for (i=sizeof(struct nlmsghdr); i<nlh->nlmsg_len; i+=4) {
|
||||
char *b = (char *) nlh;
|
||||
struct nlattr *attr = (struct nlattr *) (b+i);
|
||||
|
||||
/* netlink control message. */
|
||||
if (nlh->nlmsg_type < NLMSG_MIN_TYPE) {
|
||||
fprintf(fd, "| %.2x %.2x %.2x %.2x |\t",
|
||||
0xff & b[i], 0xff & b[i+1],
|
||||
0xff & b[i+2], 0xff & b[i+3]);
|
||||
fprintf(fd, "| |\n");
|
||||
/* special handling for the extra header. */
|
||||
} else if (extra_header_size > 0) {
|
||||
extra_header_size -= 4;
|
||||
fprintf(fd, "| %.2x %.2x %.2x %.2x |\t",
|
||||
0xff & b[i], 0xff & b[i+1],
|
||||
0xff & b[i+2], 0xff & b[i+3]);
|
||||
fprintf(fd, "| extra header |\n");
|
||||
/* this seems like an attribute header. */
|
||||
} else if (rem == 0 && (attr->nla_type & NLA_TYPE_MASK) != 0) {
|
||||
fprintf(fd, "|%c[%d;%dm"
|
||||
"%.5u"
|
||||
"%c[%dm"
|
||||
"|"
|
||||
"%c[%d;%dm"
|
||||
"%c%c"
|
||||
"%c[%dm"
|
||||
"|"
|
||||
"%c[%d;%dm"
|
||||
"%.5u"
|
||||
"%c[%dm|\t",
|
||||
27, 1, 31,
|
||||
attr->nla_len,
|
||||
27, 0,
|
||||
27, 1, 32,
|
||||
attr->nla_type & NLA_F_NESTED ? 'N' : '-',
|
||||
attr->nla_type &
|
||||
NLA_F_NET_BYTEORDER ? 'B' : '-',
|
||||
27, 0,
|
||||
27, 1, 34,
|
||||
attr->nla_type & NLA_TYPE_MASK,
|
||||
27, 0);
|
||||
fprintf(fd, "|len |flags| type|\n");
|
||||
|
||||
if (!(attr->nla_type & NLA_F_NESTED)) {
|
||||
rem = NLA_ALIGN(attr->nla_len) -
|
||||
sizeof(struct nlattr);
|
||||
}
|
||||
/* this is the attribute payload. */
|
||||
} else if (rem > 0) {
|
||||
rem -= 4;
|
||||
fprintf(fd, "| %.2x %.2x %.2x %.2x |\t",
|
||||
0xff & b[i], 0xff & b[i+1],
|
||||
0xff & b[i+2], 0xff & b[i+3]);
|
||||
fprintf(fd, "| data |");
|
||||
fprintf(fd, "\t %c %c %c %c\n",
|
||||
isalnum(b[i]) ? b[i] : 0,
|
||||
isalnum(b[i+1]) ? b[i+1] : 0,
|
||||
isalnum(b[i+2]) ? b[i+2] : 0,
|
||||
isalnum(b[i+3]) ? b[i+3] : 0);
|
||||
}
|
||||
}
|
||||
fprintf(fd, "----------------\t------------------\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_fprintf - print netlink message to file
|
||||
* \param fd pointer to file type
|
||||
* \param data pointer to the buffer that contains messages to be printed
|
||||
* \param datalen length of data stored in the buffer
|
||||
* \param extra_header_size size of the extra header (if any)
|
||||
*
|
||||
* This function prints the netlink header to a file handle.
|
||||
* It may be useful for debugging purposes. One example of the output
|
||||
* is the following:
|
||||
*
|
||||
*\verbatim
|
||||
---------------- ------------------
|
||||
| 0000000040 | | message length |
|
||||
| 00016 | R-A- | | type | flags |
|
||||
| 1289148991 | | sequence number|
|
||||
| 0000000000 | | port ID |
|
||||
---------------- ------------------
|
||||
| 00 00 00 00 | | extra header |
|
||||
| 00 00 00 00 | | extra header |
|
||||
| 01 00 00 00 | | extra header |
|
||||
| 01 00 00 00 | | extra header |
|
||||
|00008|--|00003| |len |flags| type|
|
||||
| 65 74 68 30 | | data | e t h 0
|
||||
---------------- ------------------
|
||||
\endverbatim
|
||||
*
|
||||
* This example above shows the netlink message that is send to kernel-space
|
||||
* to set up the link interface eth0. The netlink and attribute header data
|
||||
* are displayed in base 10 whereas the extra header and the attribute payload
|
||||
* are expressed in base 16. The possible flags in the netlink header are:
|
||||
*
|
||||
* - R, that indicates that NLM_F_REQUEST is set.
|
||||
* - M, that indicates that NLM_F_MULTI is set.
|
||||
* - A, that indicates that NLM_F_ACK is set.
|
||||
* - E, that indicates that NLM_F_ECHO is set.
|
||||
*
|
||||
* The lack of one flag is displayed with '-'. On the other hand, the possible
|
||||
* attribute flags available are:
|
||||
*
|
||||
* - N, that indicates that NLA_F_NESTED is set.
|
||||
* - B, that indicates that NLA_F_NET_BYTEORDER is set.
|
||||
*/
|
||||
void
|
||||
mnl_nlmsg_fprintf(FILE *fd, const void *data, size_t datalen,
|
||||
size_t extra_header_size)
|
||||
{
|
||||
const struct nlmsghdr *nlh = data;
|
||||
int len = datalen;
|
||||
|
||||
while (mnl_nlmsg_ok(nlh, len)) {
|
||||
mnl_nlmsg_fprintf_header(fd, nlh);
|
||||
mnl_nlmsg_fprintf_payload(fd, nlh, extra_header_size);
|
||||
nlh = mnl_nlmsg_next(nlh, &len);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_fprintf);
|
||||
|
||||
/**
|
||||
* \defgroup batch Netlink message batch helpers
|
||||
*
|
||||
* This library provides helpers to batch several messages into one single
|
||||
* datagram. These helpers do not perform strict memory boundary checkings.
|
||||
*
|
||||
* The following figure represents a Netlink message batch:
|
||||
*
|
||||
* |<-------------- MNL_SOCKET_BUFFER_SIZE ------------->|
|
||||
* |<-------------------- batch ------------------>| |
|
||||
* |-----------|-----------|-----------|-----------|-----------|
|
||||
* |<- nlmsg ->|<- nlmsg ->|<- nlmsg ->|<- nlmsg ->|<- nlmsg ->|
|
||||
* |-----------|-----------|-----------|-----------|-----------|
|
||||
* ^ ^
|
||||
* | |
|
||||
* message N message N+1
|
||||
*
|
||||
* To start the batch, you have to call mnl_nlmsg_batch_start() and you can
|
||||
* use mnl_nlmsg_batch_stop() to release it.
|
||||
*
|
||||
* You have to invoke mnl_nlmsg_batch_next() to get room for a new message
|
||||
* in the batch. If this function returns NULL, it means that the last
|
||||
* message that was added (message N+1 in the figure above) does not fit the
|
||||
* batch. Thus, you have to send the batch (which includes until message N)
|
||||
* and, then, you have to call mnl_nlmsg_batch_reset() to re-initialize
|
||||
* the batch (this moves message N+1 to the head of the buffer). For that
|
||||
* reason, the buffer that you have to use to store the batch must be double
|
||||
* of MNL_SOCKET_BUFFER_SIZE to ensure that the last message (message N+1)
|
||||
* that did not fit into the batch is written inside valid memory boundaries.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
struct mnl_nlmsg_batch {
|
||||
/* the buffer that is used to store the batch. */
|
||||
void *buf;
|
||||
size_t limit;
|
||||
size_t buflen;
|
||||
/* the current netlink message in the batch. */
|
||||
void *cur;
|
||||
bool overflow;
|
||||
};
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_batch_start - initialize a batch
|
||||
* \param buf pointer to the buffer that will store this batch
|
||||
* \param limit maximum size of the batch (should be MNL_SOCKET_BUFFER_SIZE).
|
||||
*
|
||||
* The buffer that you pass must be double of MNL_SOCKET_BUFFER_SIZE. The
|
||||
* limit must be half of the buffer size, otherwise expect funny memory
|
||||
* corruptions 8-).
|
||||
*
|
||||
* You can allocate the buffer that you use to store the batch in the stack or
|
||||
* the heap, no restrictions in this regard. This function returns NULL on
|
||||
* error.
|
||||
*/
|
||||
struct mnl_nlmsg_batch *mnl_nlmsg_batch_start(void *buf, size_t limit)
|
||||
{
|
||||
struct mnl_nlmsg_batch *b;
|
||||
|
||||
b = malloc(sizeof(struct mnl_nlmsg_batch));
|
||||
if (b == NULL)
|
||||
return NULL;
|
||||
|
||||
b->buf = buf;
|
||||
b->limit = limit;
|
||||
b->buflen = 0;
|
||||
b->cur = buf;
|
||||
b->overflow = false;
|
||||
|
||||
return b;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_batch_start);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_batch_stop - release a batch
|
||||
* \param b pointer to batch
|
||||
*
|
||||
* This function returns the amount of data that is part of this batch.
|
||||
*/
|
||||
void mnl_nlmsg_batch_stop(struct mnl_nlmsg_batch *b)
|
||||
{
|
||||
free(b);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_batch_stop);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_batch_next - get room for the next message in the batch
|
||||
* \param b pointer to batch
|
||||
*
|
||||
* This function returns false if the last message did not fit into the
|
||||
* batch. Otherwise, it prepares the batch to provide room for the new
|
||||
* Netlink message in the batch and returns true.
|
||||
*
|
||||
* You have to put at least one message in the batch before calling this
|
||||
* function, otherwise your application is likely to crash.
|
||||
*/
|
||||
bool mnl_nlmsg_batch_next(struct mnl_nlmsg_batch *b)
|
||||
{
|
||||
struct nlmsghdr *nlh = b->cur;
|
||||
|
||||
if (b->buflen + nlh->nlmsg_len > b->limit) {
|
||||
b->overflow = true;
|
||||
return false;
|
||||
}
|
||||
b->cur = b->buf + b->buflen + nlh->nlmsg_len;
|
||||
b->buflen += nlh->nlmsg_len;
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_batch_next);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_batch_reset - reset the batch
|
||||
* \param b pointer to batch
|
||||
*
|
||||
* This function allows to reset a batch, so you can reuse it to create a
|
||||
* new one. This function moves the last message which does not fit the
|
||||
* batch to the head of the buffer, if any.
|
||||
*/
|
||||
void mnl_nlmsg_batch_reset(struct mnl_nlmsg_batch *b)
|
||||
{
|
||||
if (b->overflow) {
|
||||
struct nlmsghdr *nlh = b->cur;
|
||||
memcpy(b->buf, b->cur, nlh->nlmsg_len);
|
||||
b->buflen = nlh->nlmsg_len;
|
||||
b->cur = b->buf + b->buflen;
|
||||
b->overflow = false;
|
||||
} else {
|
||||
b->buflen = 0;
|
||||
b->cur = b->buf;
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_batch_reset);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_batch_size - get current size of the batch
|
||||
* \param b pointer to batch
|
||||
*
|
||||
* This function returns the current size of the batch.
|
||||
*/
|
||||
size_t mnl_nlmsg_batch_size(struct mnl_nlmsg_batch *b)
|
||||
{
|
||||
return b->buflen;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_batch_size);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_batch_head - get head of this batch
|
||||
* \param b pointer to batch
|
||||
*
|
||||
* This function returns a pointer to the head of the batch, which is the
|
||||
* beginning of the buffer that is used.
|
||||
*/
|
||||
void *mnl_nlmsg_batch_head(struct mnl_nlmsg_batch *b)
|
||||
{
|
||||
return b->buf;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_batch_head);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_batch_current - returns current position in the batch
|
||||
* \param b pointer to batch
|
||||
*
|
||||
* This function returns a pointer to the current position in the buffer
|
||||
* that is used to store the batch.
|
||||
*/
|
||||
void *mnl_nlmsg_batch_current(struct mnl_nlmsg_batch *b)
|
||||
{
|
||||
return b->cur;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_batch_current);
|
||||
|
||||
/**
|
||||
* mnl_nlmsg_batch_is_empty - check if there is any message in the batch
|
||||
* \param b pointer to batch
|
||||
*
|
||||
* This function returns true if the batch is empty.
|
||||
*/
|
||||
bool mnl_nlmsg_batch_is_empty(struct mnl_nlmsg_batch *b)
|
||||
{
|
||||
return b->buflen == 0;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_nlmsg_batch_is_empty);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
304
external/nflog/socket.c
vendored
Normal file
304
external/nflog/socket.c
vendored
Normal file
|
|
@ -0,0 +1,304 @@
|
|||
/*
|
||||
* (C) 2008-2010 by Pablo Neira Ayuso <pablo@netfilter.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include <libmnl/libmnl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include "internal.h"
|
||||
|
||||
/**
|
||||
* \mainpage
|
||||
*
|
||||
* libmnl is a minimalistic user-space library oriented to Netlink developers.
|
||||
* There are a lot of common tasks in parsing, validating, constructing of
|
||||
* both the Netlink header and TLVs that are repetitive and easy to get wrong.
|
||||
* This library aims to provide simple helpers that allows you to avoid
|
||||
* re-inventing the wheel in common Netlink tasks.
|
||||
*
|
||||
* \verbatim
|
||||
"Simplify, simplify" -- Henry David Thoureau. Walden (1854)
|
||||
\endverbatim
|
||||
*
|
||||
* The acronym libmnl stands for LIBrary Minimalistic NetLink.
|
||||
*
|
||||
* libmnl homepage is:
|
||||
* http://www.netfilter.org/projects/libmnl/
|
||||
*
|
||||
* \section features Main Features
|
||||
* - Small: the shared library requires around 30KB for an x86-based computer.
|
||||
* - Simple: this library avoids complex abstractions that tend to hide Netlink
|
||||
* details. It avoids elaborated object-oriented infrastructure and complex
|
||||
* callback-based workflow.
|
||||
* - Easy to use: the library simplifies the work for Netlink-wise developers.
|
||||
* It provides functions to make socket handling, message building,
|
||||
* validating, parsing and sequence tracking, easier.
|
||||
* - Easy to re-use: you can use this library to build your own abstraction
|
||||
* layer upon this library, if you want to provide another library that
|
||||
* hides Netlink details to your users.
|
||||
* - Decoupling: the interdependency of the main bricks that compose this
|
||||
* library is reduced, i.e. the library provides many helpers, but the
|
||||
* programmer is not forced to use them.
|
||||
*
|
||||
* \section licensing Licensing terms
|
||||
* This library is released under the LGPLv2.1 or any later (at your option).
|
||||
*
|
||||
* \section Dependencies
|
||||
* You have to install the Linux kernel headers that you want to use to develop
|
||||
* your application. Moreover, this library requires that you have some basics
|
||||
* on Netlink.
|
||||
*
|
||||
* \section scm Git Tree
|
||||
* The current development version of libmnl can be accessed at:
|
||||
* http://git.netfilter.org/cgi-bin/gitweb.cgi?p=libmnl.git;a=summary
|
||||
*
|
||||
* \section using Using libmnl
|
||||
* You can access several example files under examples/ in the libmnl source
|
||||
* code tree.
|
||||
*/
|
||||
|
||||
struct mnl_socket {
|
||||
int fd;
|
||||
struct sockaddr_nl addr;
|
||||
};
|
||||
|
||||
/**
|
||||
* \defgroup socket Netlink socket helpers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* mnl_socket_get_fd - obtain file descriptor from netlink socket
|
||||
* \param nl netlink socket obtained via mnl_socket_open()
|
||||
*
|
||||
* This function returns the file descriptor of a given netlink socket.
|
||||
*/
|
||||
int mnl_socket_get_fd(const struct mnl_socket *nl)
|
||||
{
|
||||
return nl->fd;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_socket_get_fd);
|
||||
|
||||
/**
|
||||
* mnl_socket_get_portid - obtain Netlink PortID from netlink socket
|
||||
* \param nl netlink socket obtained via mnl_socket_open()
|
||||
*
|
||||
* This function returns the Netlink PortID of a given netlink socket.
|
||||
* It's a common mistake to assume that this PortID equals the process ID
|
||||
* which is not always true. This is the case if you open more than one
|
||||
* socket that is binded to the same Netlink subsystem from the same process.
|
||||
*/
|
||||
unsigned int mnl_socket_get_portid(const struct mnl_socket *nl)
|
||||
{
|
||||
return nl->addr.nl_pid;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_socket_get_portid);
|
||||
|
||||
/**
|
||||
* mnl_socket_open - open a netlink socket
|
||||
* \param bus the netlink socket bus ID (see NETLINK_* constants)
|
||||
*
|
||||
* On error, it returns -1 and errno is appropriately set. Otherwise, it
|
||||
* returns a valid pointer to the mnl_socket structure.
|
||||
*/
|
||||
struct mnl_socket *mnl_socket_open(int bus)
|
||||
{
|
||||
struct mnl_socket *nl;
|
||||
|
||||
nl = calloc(sizeof(struct mnl_socket), 1);
|
||||
if (nl == NULL)
|
||||
return NULL;
|
||||
|
||||
nl->fd = socket(AF_NETLINK, SOCK_RAW, bus);
|
||||
if (nl->fd == -1) {
|
||||
free(nl);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return nl;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_socket_open);
|
||||
|
||||
/**
|
||||
* mnl_socket_bind - bind netlink socket
|
||||
* \param nl netlink socket obtained via mnl_socket_open()
|
||||
* \param groups the group of message you're interested in
|
||||
* \param pid the port ID you want to use (use zero for automatic selection)
|
||||
*
|
||||
* On error, this function returns -1 and errno is appropriately set. On
|
||||
* success, 0 is returned. You can use MNL_SOCKET_AUTOPID which is 0 for
|
||||
* automatic port ID selection.
|
||||
*/
|
||||
int mnl_socket_bind(struct mnl_socket *nl, unsigned int groups, pid_t pid)
|
||||
{
|
||||
int ret;
|
||||
socklen_t addr_len;
|
||||
|
||||
nl->addr.nl_family = AF_NETLINK;
|
||||
nl->addr.nl_groups = groups;
|
||||
nl->addr.nl_pid = pid;
|
||||
|
||||
ret = bind(nl->fd, (struct sockaddr *) &nl->addr, sizeof (nl->addr));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
addr_len = sizeof(nl->addr);
|
||||
ret = getsockname(nl->fd, (struct sockaddr *) &nl->addr, &addr_len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (addr_len != sizeof(nl->addr)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (nl->addr.nl_family != AF_NETLINK) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_socket_bind);
|
||||
|
||||
/**
|
||||
* mnl_socket_sendto - send a netlink message of a certain size
|
||||
* \param nl netlink socket obtained via mnl_socket_open()
|
||||
* \param buf buffer containing the netlink message to be sent
|
||||
* \param len number of bytes in the buffer that you want to send
|
||||
*
|
||||
* On error, it returns -1 and errno is appropriately set. Otherwise, it
|
||||
* returns the number of bytes sent.
|
||||
*/
|
||||
ssize_t
|
||||
mnl_socket_sendto(const struct mnl_socket *nl, const void *buf, size_t len)
|
||||
{
|
||||
static const struct sockaddr_nl snl = {
|
||||
.nl_family = AF_NETLINK
|
||||
};
|
||||
return sendto(nl->fd, buf, len, 0,
|
||||
(struct sockaddr *) &snl, sizeof(snl));
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_socket_sendto);
|
||||
|
||||
/**
|
||||
* mnl_socket_recvfrom - receive a netlink message
|
||||
* \param nl netlink socket obtained via mnl_socket_open()
|
||||
* \param buf buffer that you want to use to store the netlink message
|
||||
* \param bufsiz size of the buffer passed to store the netlink message
|
||||
*
|
||||
* On error, it returns -1 and errno is appropriately set. If errno is set
|
||||
* to ENOSPC, it means that the buffer that you have passed to store the
|
||||
* netlink message is too small, so you have received a truncated message.
|
||||
* To avoid this, you have to allocate a buffer of MNL_SOCKET_BUFFER_SIZE
|
||||
* (which is 8KB, see linux/netlink.h for more information). Using this
|
||||
* buffer size ensures that your buffer is big enough to store the netlink
|
||||
* message without truncating it.
|
||||
*/
|
||||
ssize_t
|
||||
mnl_socket_recvfrom(const struct mnl_socket *nl, void *buf, size_t bufsiz)
|
||||
{
|
||||
ssize_t ret;
|
||||
struct sockaddr_nl addr;
|
||||
struct iovec iov = {
|
||||
.iov_base = buf,
|
||||
.iov_len = bufsiz,
|
||||
};
|
||||
struct msghdr msg = {
|
||||
.msg_name = &addr,
|
||||
.msg_namelen = sizeof(struct sockaddr_nl),
|
||||
.msg_iov = &iov,
|
||||
.msg_iovlen = 1,
|
||||
.msg_control = NULL,
|
||||
.msg_controllen = 0,
|
||||
.msg_flags = 0,
|
||||
};
|
||||
ret = recvmsg(nl->fd, &msg, 0);
|
||||
if (ret == -1)
|
||||
return ret;
|
||||
|
||||
if (msg.msg_flags & MSG_TRUNC) {
|
||||
errno = ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
if (msg.msg_namelen != sizeof(struct sockaddr_nl)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_socket_recvfrom);
|
||||
|
||||
/**
|
||||
* mnl_socket_close - close a given netlink socket
|
||||
* \param nl netlink socket obtained via mnl_socket_open()
|
||||
*
|
||||
* On error, this function returns -1 and errno is appropriately set.
|
||||
* On success, it returns 0.
|
||||
*/
|
||||
int mnl_socket_close(struct mnl_socket *nl)
|
||||
{
|
||||
int ret = close(nl->fd);
|
||||
free(nl);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_socket_close);
|
||||
|
||||
/**
|
||||
* mnl_socket_setsockopt - set Netlink socket option
|
||||
* \param nl netlink socket obtained via mnl_socket_open()
|
||||
* \param type type of Netlink socket options
|
||||
* \param buf the buffer that contains the data about this option
|
||||
* \param len the size of the buffer passed
|
||||
*
|
||||
* This function allows you to set some Netlink socket option. As of writing
|
||||
* this (see linux/netlink.h), the existing options are:
|
||||
*
|
||||
* - \#define NETLINK_ADD_MEMBERSHIP 1
|
||||
* - \#define NETLINK_DROP_MEMBERSHIP 2
|
||||
* - \#define NETLINK_PKTINFO 3
|
||||
* - \#define NETLINK_BROADCAST_ERROR 4
|
||||
* - \#define NETLINK_NO_ENOBUFS 5
|
||||
*
|
||||
* In the early days, Netlink only supported 32 groups expressed in a
|
||||
* 32-bits mask. However, since 2.6.14, Netlink may have up to 2^32 multicast
|
||||
* groups but you have to use setsockopt() with NETLINK_ADD_MEMBERSHIP to
|
||||
* join a given multicast group. This function internally calls setsockopt()
|
||||
* to join a given netlink multicast group. You can still use mnl_bind()
|
||||
* and the 32-bit mask to join a set of Netlink multicast groups.
|
||||
*
|
||||
* On error, this function returns -1 and errno is appropriately set.
|
||||
*/
|
||||
int mnl_socket_setsockopt(const struct mnl_socket *nl, int type,
|
||||
void *buf, socklen_t len)
|
||||
{
|
||||
return setsockopt(nl->fd, SOL_NETLINK, type, buf, len);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_socket_setsockopt);
|
||||
|
||||
/**
|
||||
* mnl_socket_getsockopt - get a Netlink socket option
|
||||
* \param nl netlink socket obtained via mnl_socket_open()
|
||||
* \param type type of Netlink socket options
|
||||
* \param buf pointer to the buffer to store the value of this option
|
||||
* \param len size of the information written in the buffer
|
||||
*
|
||||
* On error, this function returns -1 and errno is appropriately set.
|
||||
*/
|
||||
int mnl_socket_getsockopt(const struct mnl_socket *nl, int type,
|
||||
void *buf, socklen_t *len)
|
||||
{
|
||||
return getsockopt(nl->fd, SOL_NETLINK, type, buf, len);
|
||||
}
|
||||
EXPORT_SYMBOL(mnl_socket_getsockopt);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
9
external/run_pie/Android.mk
vendored
Normal file
9
external/run_pie/Android.mk
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
# include $(CLEAR_VARS)
|
||||
|
||||
# LOCAL_MODULE := run_pie
|
||||
|
||||
# LOCAL_SRC_FILES := run_pie.c
|
||||
|
||||
# include $(BUILD_EXECUTABLE)
|
||||
56
external/run_pie/run_pie.c
vendored
Normal file
56
external/run_pie/run_pie.c
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <unistd.h>
|
||||
// This is a wrapper to run position independent executables on Android ICS,
|
||||
// where the linker doesn't support PIE. This requires the PIE binaries to be
|
||||
// built with CFLAGS +=-fvisibility=default -fPIE, and LDFLAGS += -rdynamic -pie
|
||||
// such that the main() symbol remains exported and can be dlsym-ed.
|
||||
#define ERR_PREFIX "[PIE Loader] "
|
||||
typedef int (*main_t)(int, char**);
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s path_to_pie_executable [args]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
// Shift left the argv[]. argv is what /proc/PID/cmdline prints out. In turn
|
||||
// cmdline is what Android "ps" prints out. In turn "ps" is what many scripts
|
||||
// look for to decide which processes to kill / killall.
|
||||
int i;
|
||||
char* next_argv_start = argv[0];
|
||||
for (i = 1; i < argc; ++i) {
|
||||
const size_t argv_len = strlen(argv[i]) + 1;
|
||||
memcpy(argv[i - 1], argv[i], argv_len);
|
||||
next_argv_start += argv_len;
|
||||
argv[i] = next_argv_start;
|
||||
}
|
||||
argv[argc - 1] = NULL; // The last argv must be a NULL ptr.
|
||||
// Set also the proc name accordingly (/proc/PID/comm).
|
||||
prctl(PR_SET_NAME, (long) argv[0]);
|
||||
// dlopen should not fail, unless:
|
||||
// - The target binary does not exists:
|
||||
// - The dependent .so libs cannot be loaded.
|
||||
// In both cases, just bail out with an explicit error message.
|
||||
void* handle = dlopen(argv[0], RTLD_NOW);
|
||||
if (handle == NULL) {
|
||||
printf(ERR_PREFIX "dlopen() failed: %s.\n", dlerror());
|
||||
return -1;
|
||||
}
|
||||
main_t pie_main = (main_t) dlsym(handle, "main");
|
||||
if (pie_main) {
|
||||
return pie_main(argc - 1, argv);
|
||||
}
|
||||
// If we reached this point dlsym failed, very likely because the target
|
||||
// binary has not been compiled with the proper CFLAGS / LDFLAGS.
|
||||
// At this point the most sensible thing to do is running that normally
|
||||
// via exec and hope that the target binary wasn't a PIE.
|
||||
execv(argv[0], argv);
|
||||
// exevc is supposed to never return, unless it fails.
|
||||
printf(ERR_PREFIX "Both dlsym() and the execv() fallback failed.\n");
|
||||
perror("execv");
|
||||
return -1;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue