am 01acea11: am 1f72fe99: am 7df080b2: am 3ddaa0ad: Merge "adb: Add USB vendor ID for Lenovo"
* commit '01acea112501f7d140f100591319781e59b90d0e':
adb: Add USB vendor ID for Lenovo
diff --git a/Android.mk b/Android.mk
index a307719..7c57258 100644
--- a/Android.mk
+++ b/Android.mk
@@ -15,17 +15,4 @@
#
LOCAL_PATH := $(my-dir)
-ifneq ($(TARGET_SIMULATOR),true)
- include $(call first-makefiles-under,$(LOCAL_PATH))
-else
- include $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
- adb \
- libcutils \
- libsysutils \
- liblog \
- libnetutils \
- libpixelflinger \
- libusbhost \
- libzipfile \
- ))
-endif
+include $(call first-makefiles-under,$(LOCAL_PATH))
diff --git a/adb/Android.mk b/adb/Android.mk
index 6ed31eb..7744d2b 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -95,11 +95,7 @@
# adbd device daemon
# =========================================================
-# build adbd in all non-simulator builds
-BUILD_ADBD := false
-ifneq ($(TARGET_SIMULATOR),true)
- BUILD_ADBD := true
-endif
+BUILD_ADBD := true
# build adbd for the Linux simulator build
# so we can use it to test the adb USB gadget driver on x86
@@ -113,6 +109,7 @@
LOCAL_SRC_FILES := \
adb.c \
+ backup_service.c \
fdevent.c \
transport.c \
transport_local.c \
@@ -142,21 +139,14 @@
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN)
LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)
-ifeq ($(TARGET_SIMULATOR),true)
- LOCAL_STATIC_LIBRARIES := libcutils
- LOCAL_LDLIBS += -lpthread
- include $(BUILD_HOST_EXECUTABLE)
-else
- LOCAL_STATIC_LIBRARIES := libcutils libc
- include $(BUILD_EXECUTABLE)
-endif
+LOCAL_STATIC_LIBRARIES := libcutils libc
+include $(BUILD_EXECUTABLE)
endif
# adb host tool for device-as-host
# =========================================================
-ifneq ($(TARGET_SIMULATOR),true)
ifneq ($(SDK_ONLY),true)
include $(CLEAR_VARS)
@@ -195,4 +185,3 @@
include $(BUILD_EXECUTABLE)
endif
-endif
diff --git a/adb/adb.c b/adb/adb.c
index f5e6e0c..b0a70dc 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -36,6 +36,9 @@
#include "usb_vendors.h"
#endif
+#if ADB_TRACE
+ADB_MUTEX_DEFINE( D_lock );
+#endif
int HOST = 0;
@@ -90,6 +93,7 @@
{ "sysdeps", TRACE_SYSDEPS },
{ "transport", TRACE_TRANSPORT },
{ "jdwp", TRACE_JDWP },
+ { "services", TRACE_SERVICES },
{ NULL, 0 }
};
@@ -591,14 +595,6 @@
return 0;
}
-#ifdef HAVE_FORKEXEC
-static void sigchld_handler(int n)
-{
- int status;
- while(waitpid(-1, &status, WNOHANG) > 0) ;
-}
-#endif
-
#ifdef HAVE_WIN32_PROC
static BOOL WINAPI ctrlc_handler(DWORD type)
{
@@ -641,6 +637,7 @@
fd = unix_open("/dev/null", O_RDONLY);
dup2(fd, 0);
+ adb_close(fd);
fd = unix_open("/tmp/adb.log", O_WRONLY | O_CREAT | O_APPEND, 0640);
if(fd < 0) {
@@ -648,6 +645,7 @@
}
dup2(fd, 1);
dup2(fd, 2);
+ adb_close(fd);
fprintf(stderr,"--- adb starting (pid %d) ---\n", getpid());
#endif
}
@@ -807,9 +805,10 @@
// wait for the "OK\n" message
adb_close(fd[1]);
int ret = adb_read(fd[0], temp, 3);
+ int saved_errno = errno;
adb_close(fd[0]);
if (ret < 0) {
- fprintf(stderr, "could not read ok from ADB Server, errno = %d\n", errno);
+ fprintf(stderr, "could not read ok from ADB Server, errno = %d\n", saved_errno);
return -1;
}
if (ret != 3 || temp[0] != 'O' || temp[1] != 'K' || temp[2] != '\n') {
@@ -848,7 +847,7 @@
#ifdef HAVE_WIN32_PROC
SetConsoleCtrlHandler( ctrlc_handler, TRUE );
#elif defined(HAVE_FORKEXEC)
- signal(SIGCHLD, sigchld_handler);
+ // No SIGCHLD. Let the service subproc handle its children.
signal(SIGPIPE, SIG_IGN);
#endif
@@ -957,7 +956,9 @@
// listen on default port
local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
}
+ D("adb_main(): pre init_jdwp()\n");
init_jdwp();
+ D("adb_main(): post init_jdwp()\n");
#endif
if (is_daemon)
@@ -971,6 +972,7 @@
#endif
start_logging();
}
+ D("Event loop starting\n");
fdevent_loop();
@@ -1269,8 +1271,9 @@
int main(int argc, char **argv)
{
#if ADB_HOST
- adb_trace_init();
adb_sysdeps_init();
+ adb_trace_init();
+ D("Handling commandline()\n");
return adb_commandline(argc - 1, argv + 1);
#else
if((argc > 1) && (!strcmp(argv[1],"recovery"))) {
@@ -1279,6 +1282,7 @@
}
start_device_log();
+ D("Handling main()\n");
return adb_main(0, DEFAULT_ADB_PORT);
#endif
}
diff --git a/adb/adb.h b/adb/adb.h
index 0aa98d3..ac31f11 100644
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -19,6 +19,8 @@
#include <limits.h>
+#include "transport.h" /* readx(), writex() */
+
#define MAX_PAYLOAD 4096
#define A_SYNC 0x434e5953
@@ -33,7 +35,7 @@
#define ADB_VERSION_MAJOR 1 // Used for help/version information
#define ADB_VERSION_MINOR 0 // Used for help/version information
-#define ADB_SERVER_VERSION 26 // Increment this when we want to force users to start a new adb server
+#define ADB_SERVER_VERSION 29 // Increment this when we want to force users to start a new adb server
typedef struct amessage amessage;
typedef struct apacket apacket;
@@ -302,6 +304,11 @@
#endif
#if !ADB_HOST
+typedef enum {
+ BACKUP,
+ RESTORE
+} BackupOperation;
+int backup_service(BackupOperation operation, char* args);
void framebuffer_service(int fd, void *cookie);
void log_service(int fd, void *cookie);
void remount_service(int fd, void *cookie);
@@ -315,13 +322,6 @@
int check_header(apacket *p);
int check_data(apacket *p);
-/* convenience wrappers around read/write that will retry on
-** EINTR and/or short read/write. Returns 0 on success, -1
-** on error or EOF.
-*/
-int readx(int fd, void *ptr, size_t len);
-int writex(int fd, const void *ptr, size_t len);
-
/* define ADB_TRACE to 1 to enable tracing support, or 0 to disable it */
#define ADB_TRACE 1
@@ -331,33 +331,56 @@
* the adb_trace_init() function implemented in adb.c
*/
typedef enum {
- TRACE_ADB = 0,
+ TRACE_ADB = 0, /* 0x001 */
TRACE_SOCKETS,
TRACE_PACKETS,
TRACE_TRANSPORT,
- TRACE_RWX,
+ TRACE_RWX, /* 0x010 */
TRACE_USB,
TRACE_SYNC,
TRACE_SYSDEPS,
- TRACE_JDWP,
+ TRACE_JDWP, /* 0x100 */
+ TRACE_SERVICES,
} AdbTrace;
#if ADB_TRACE
- int adb_trace_mask;
-
+ extern int adb_trace_mask;
+ extern unsigned char adb_trace_output_count;
void adb_trace_init(void);
# define ADB_TRACING ((adb_trace_mask & (1 << TRACE_TAG)) != 0)
/* you must define TRACE_TAG before using this macro */
- #define D(...) \
+# define D(...) \
do { \
- if (ADB_TRACING) \
+ if (ADB_TRACING) { \
+ int save_errno = errno; \
+ adb_mutex_lock(&D_lock); \
+ fprintf(stderr, "%s::%s():", \
+ __FILE__, __FUNCTION__); \
+ errno = save_errno; \
fprintf(stderr, __VA_ARGS__ ); \
+ fflush(stderr); \
+ adb_mutex_unlock(&D_lock); \
+ errno = save_errno; \
+ } \
+ } while (0)
+# define DR(...) \
+ do { \
+ if (ADB_TRACING) { \
+ int save_errno = errno; \
+ adb_mutex_lock(&D_lock); \
+ errno = save_errno; \
+ fprintf(stderr, __VA_ARGS__ ); \
+ fflush(stderr); \
+ adb_mutex_unlock(&D_lock); \
+ errno = save_errno; \
+ } \
} while (0)
#else
# define D(...) ((void)0)
+# define DR(...) ((void)0)
# define ADB_TRACING 0
#endif
@@ -413,6 +436,7 @@
#define CS_NOPERM 5 /* Insufficient permissions to communicate with the device */
extern int HOST;
+extern int SHELL_EXIT_NOTIFY_FD;
#define CHUNK_SIZE (64*1024)
diff --git a/adb/adb_client.c b/adb/adb_client.c
index 882810a..9a812f0 100644
--- a/adb/adb_client.c
+++ b/adb/adb_client.c
@@ -202,6 +202,7 @@
return -1;
}
+ D("_adb_connect: return fd %d\n", fd);
return fd;
}
@@ -210,6 +211,7 @@
// first query the adb server's version
int fd = _adb_connect("host:version");
+ D("adb_connect: service %s\n", service);
if(fd == -2) {
fprintf(stdout,"* daemon not running. starting it now on port %d *\n",
__adb_server_port);
@@ -266,6 +268,7 @@
if(fd == -2) {
fprintf(stderr,"** daemon still not running");
}
+ D("adb_connect: return fd %d\n", fd);
return fd;
error:
diff --git a/adb/backup_service.c b/adb/backup_service.c
new file mode 100644
index 0000000..669ff86
--- /dev/null
+++ b/adb/backup_service.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+
+#include "sysdeps.h"
+
+#define TRACE_TAG TRACE_ADB
+#include "adb.h"
+
+typedef struct {
+ pid_t pid;
+ int fd;
+} backup_harvest_params;
+
+// socketpair but do *not* mark as close_on_exec
+static int backup_socketpair(int sv[2]) {
+ int rc = unix_socketpair( AF_UNIX, SOCK_STREAM, 0, sv );
+ if (rc < 0)
+ return -1;
+
+ return 0;
+}
+
+// harvest the child process then close the read end of the socketpair
+static void* backup_child_waiter(void* args) {
+ int status;
+ backup_harvest_params* params = (backup_harvest_params*) args;
+
+ waitpid(params->pid, &status, 0);
+ adb_close(params->fd);
+ free(params);
+ return NULL;
+}
+
+/* returns the data socket passing the backup data here for forwarding */
+int backup_service(BackupOperation op, char* args) {
+ pid_t pid;
+ int s[2];
+ char* operation;
+ int socketnum;
+
+ // Command string and choice of stdin/stdout for the pipe depend on our invocation
+ if (op == BACKUP) {
+ operation = "backup";
+ socketnum = STDOUT_FILENO;
+ } else {
+ operation = "restore";
+ socketnum = STDIN_FILENO;
+ }
+
+ D("backup_service(%s, %s)\n", operation, args);
+
+ // set up the pipe from the subprocess to here
+ // parent will read s[0]; child will write s[1]
+ if (backup_socketpair(s)) {
+ D("can't create backup/restore socketpair\n");
+ fprintf(stderr, "unable to create backup/restore socketpair\n");
+ return -1;
+ }
+
+ D("Backup/restore socket pair: (send=%d, receive=%d)\n", s[1], s[0]);
+ close_on_exec(s[0]); // only the side we hold on to
+
+ // spin off the child process to run the backup command
+ pid = fork();
+ if (pid < 0) {
+ // failure
+ D("can't fork for %s\n", operation);
+ fprintf(stderr, "unable to fork for %s\n", operation);
+ adb_close(s[0]);
+ adb_close(s[1]);
+ return -1;
+ }
+
+ // Great, we're off and running.
+ if (pid == 0) {
+ // child -- actually run the backup here
+ char* p;
+ int argc;
+ char portnum[16];
+ char** bu_args;
+
+ // fixed args: [0] is 'bu', [1] is the port number, [2] is the 'operation' string
+ argc = 3;
+ for (p = (char*)args; p && *p; ) {
+ argc++;
+ while (*p && *p != ':') p++;
+ if (*p == ':') p++;
+ }
+
+ bu_args = (char**) alloca(argc*sizeof(char*) + 1);
+
+ // run through again to build the argv array
+ argc = 0;
+ bu_args[argc++] = "bu";
+ snprintf(portnum, sizeof(portnum), "%d", s[1]);
+ bu_args[argc++] = portnum;
+ bu_args[argc++] = operation;
+ for (p = (char*)args; p && *p; ) {
+ bu_args[argc++] = p;
+ while (*p && *p != ':') p++;
+ if (*p == ':') {
+ *p = 0;
+ p++;
+ }
+ }
+ bu_args[argc] = NULL;
+
+ // Close the half of the socket that we don't care about, route 'bu's console
+ // to the output socket, and off we go
+ adb_close(s[0]);
+
+ // off we go
+ execvp("/system/bin/bu", (char * const *)bu_args);
+ // oops error - close up shop and go home
+ fprintf(stderr, "Unable to exec 'bu', bailing\n");
+ exit(-1);
+ } else {
+ adb_thread_t t;
+ backup_harvest_params* params;
+
+ // parent, i.e. adbd -- close the sending half of the socket
+ D("fork() returned pid %d\n", pid);
+ adb_close(s[1]);
+
+ // spin a thread to harvest the child process
+ params = (backup_harvest_params*) malloc(sizeof(backup_harvest_params));
+ params->pid = pid;
+ params->fd = s[0];
+ if (adb_thread_create(&t, backup_child_waiter, params)) {
+ adb_close(s[0]);
+ free(params);
+ D("Unable to create child harvester\n");
+ return -1;
+ }
+ }
+
+ // we'll be reading from s[0] as the data is sent by the child process
+ return s[0];
+}
diff --git a/adb/commandline.c b/adb/commandline.c
index b0c2b80..28bae98 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -37,12 +37,6 @@
#include "adb_client.h"
#include "file_sync_service.h"
-enum {
- IGNORE_DATA,
- WIPE_DATA,
- FLASH_DATA
-};
-
static int do_cmd(transport_type ttype, char* serial, char *cmd, ...);
void get_my_path(char *s, size_t maxLen);
@@ -135,14 +129,24 @@
" adb bugreport - return all information from the device\n"
" that should be included in a bug report.\n"
"\n"
+ " adb backup [-f <file>] [-apk|-noapk] [-shared|-noshared] [-all] [<packages...>]\n"
+ " - Write a tarfile backup of the device's data to <file>.\n"
+ " If a -f option is not supplied then the data is\n"
+ " written to \"backup.tar\" in the current directory.\n"
+ " (-apk|-noapk enable/disable backup of the .apks themselves\n"
+ " in the tarfile; the default is noapk.)\n"
+ " (-shared|-noshared enable/disable backup of the device's\n"
+ " shared storage / SD card contents; the default is noshared.)\n"
+ " (-all means to back up all installed applications)\n"
+ " (<packages...> is the list of applications to be backed up. If\n"
+ " the -all or -shared flags are passed, then the package\n"
+ " list is optional.)\n"
+ "\n"
+ " adb restore <file> - restore device contents from the <file> backup tarfile\n"
+ "\n"
" adb help - show this help message\n"
" adb version - show version num\n"
"\n"
- "DATAOPTS:\n"
- " (no option) - don't touch the data partition\n"
- " -w - wipe the data partition\n"
- " -d - flash the data partition\n"
- "\n"
"scripting:\n"
" adb wait-for-device - block until device is online\n"
" adb start-server - ensure that there is a server running\n"
@@ -218,7 +222,9 @@
int len;
while(fd >= 0) {
+ D("read_and_dump(): pre adb_read(fd=%d)\n", fd);
len = adb_read(fd, buf, 4096);
+ D("read_and_dump(): post adb_read(fd=%d): len=%d\n", fd, len);
if(len == 0) {
break;
}
@@ -232,6 +238,34 @@
}
}
+static void copy_to_file(int inFd, int outFd) {
+ const size_t BUFSIZE = 32 * 1024;
+ char* buf = (char*) malloc(BUFSIZE);
+ int len;
+ long total = 0;
+
+ D("copy_to_file(%d -> %d)\n", inFd, outFd);
+ for (;;) {
+ len = adb_read(inFd, buf, BUFSIZE);
+ if (len == 0) {
+ D("copy_to_file() : read 0 bytes; exiting\n");
+ break;
+ }
+ if (len < 0) {
+ if (errno == EINTR) {
+ D("copy_to_file() : EINTR, retrying\n");
+ continue;
+ }
+ D("copy_to_file() : error %d\n", errno);
+ break;
+ }
+ adb_write(outFd, buf, len);
+ total += len;
+ }
+ D("copy_to_file() finished after %lu bytes\n", total);
+ free(buf);
+}
+
static void *stdin_read_thread(void *x)
{
int fd, fdi;
@@ -246,7 +280,9 @@
for(;;) {
/* fdi is really the client's stdin, so use read, not adb_read here */
+ D("stdin_read_thread(): pre unix_read(fdi=%d,...)\n", fdi);
r = unix_read(fdi, buf, 1024);
+ D("stdin_read_thread(): post unix_read(fdi=%d,...)\n", fdi);
if(r == 0) break;
if(r < 0) {
if(errno == EINTR) continue;
@@ -537,6 +573,85 @@
return 0;
}
+static int backup(int argc, char** argv) {
+ char buf[4096];
+ const char* filename = "./backup.tar";
+ int fd, outFd;
+ int i, j;
+
+ /* bare "adb backup" is not a valid command */
+ if (argc < 2) return usage();
+
+ /* find, extract, and use any -f argument */
+ for (i = 1; i < argc; i++) {
+ if (!strcmp("-f", argv[i])) {
+ if (i == argc-1) {
+ fprintf(stderr, "adb: -f passed with no filename\n");
+ return usage();
+ }
+ filename = argv[i+1];
+ for (j = i+2; j <= argc; ) {
+ argv[i++] = argv[j++];
+ }
+ argc -= 2;
+ argv[argc] = NULL;
+ }
+ }
+
+ outFd = adb_open_mode(filename, O_WRONLY | O_CREAT | O_TRUNC, 0640);
+ if (outFd < 0) {
+ fprintf(stderr, "adb: unable to open file %s\n", filename);
+ return -1;
+ }
+
+ snprintf(buf, sizeof(buf), "backup");
+ for (argc--, argv++; argc; argc--, argv++) {
+ strncat(buf, ":", sizeof(buf) - strlen(buf) - 1);
+ strncat(buf, argv[0], sizeof(buf) - strlen(buf) - 1);
+ }
+
+ D("backup. filename=%s buf=%s\n", filename, buf);
+ fd = adb_connect(buf);
+ if (fd < 0) {
+ fprintf(stderr, "adb: unable to connect for backup\n");
+ adb_close(outFd);
+ return -1;
+ }
+
+ copy_to_file(fd, outFd);
+
+ adb_close(fd);
+ adb_close(outFd);
+ return 0;
+}
+
+static int restore(int argc, char** argv) {
+ const char* filename;
+ int fd, tarFd;
+
+ if (argc != 2) return usage();
+
+ filename = argv[1];
+ tarFd = adb_open(filename, O_RDONLY);
+ if (tarFd < 0) {
+ fprintf(stderr, "adb: unable to open file %s\n", filename);
+ return -1;
+ }
+
+ fd = adb_connect("restore:");
+ if (fd < 0) {
+ fprintf(stderr, "adb: unable to connect for backup\n");
+ adb_close(tarFd);
+ return -1;
+ }
+
+ copy_to_file(tarFd, fd);
+
+ adb_close(fd);
+ adb_close(tarFd);
+ return 0;
+}
+
#define SENTINEL_FILE "config" OS_PATH_SEPARATOR_STR "envsetup.make"
static int top_works(const char *top)
{
@@ -853,6 +968,7 @@
}
if(argc < 2) {
+ D("starting interactive shell\n");
r = interactive_shell();
if (h) {
printf("\x1b[0m");
@@ -877,9 +993,12 @@
}
for(;;) {
+ D("interactive shell loop. buff=%s\n", buf);
fd = adb_connect(buf);
if(fd >= 0) {
+ D("about to read_and_dump(fd=%d)\n", fd);
read_and_dump(fd);
+ D("read_and_dump() done.\n");
adb_close(fd);
r = 0;
} else {
@@ -896,6 +1015,7 @@
printf("\x1b[0m");
fflush(stdout);
}
+ D("interactive shell loop. return r=%d\n", r);
return r;
}
}
@@ -1091,6 +1211,14 @@
return adb_connect("host:start-server");
}
+ if (!strcmp(argv[0], "backup")) {
+ return backup(argc, argv);
+ }
+
+ if (!strcmp(argv[0], "restore")) {
+ return restore(argc, argv);
+ }
+
if (!strcmp(argv[0], "jdwp")) {
int fd = adb_connect("jdwp");
if (fd >= 0) {
diff --git a/adb/fdevent.c b/adb/fdevent.c
index c179b20..5c374a7 100644
--- a/adb/fdevent.c
+++ b/adb/fdevent.c
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#include <sys/ioctl.h>
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -27,10 +29,20 @@
#include <stddef.h>
#include "fdevent.h"
+#include "transport.h"
+#include "sysdeps.h"
-#define TRACE(x...) fprintf(stderr,x)
-#define DEBUG 0
+/* !!! Do not enable DEBUG for the adb that will run as the server:
+** both stdout and stderr are used to communicate between the client
+** and server. Any extra output will cause failures.
+*/
+#define DEBUG 0 /* non-0 will break adb server */
+
+// This socket is used when a subproc shell service exists.
+// It wakes up the fdevent_loop() and cause the correct handling
+// of the shell's pseudo-tty master. I.e. force close it.
+int SHELL_EXIT_NOTIFY_FD = -1;
static void fatal(const char *fn, const char *fmt, ...)
{
@@ -45,15 +57,28 @@
#define FATAL(x...) fatal(__FUNCTION__, x)
#if DEBUG
+#define D(...) \
+ do { \
+ adb_mutex_lock(&D_lock); \
+ int save_errno = errno; \
+ fprintf(stderr, "%s::%s():", __FILE__, __FUNCTION__); \
+ errno = save_errno; \
+ fprintf(stderr, __VA_ARGS__); \
+ adb_mutex_unlock(&D_lock); \
+ errno = save_errno; \
+ } while(0)
static void dump_fde(fdevent *fde, const char *info)
{
+ adb_mutex_lock(&D_lock);
fprintf(stderr,"FDE #%03d %c%c%c %s\n", fde->fd,
fde->state & FDE_READ ? 'R' : ' ',
fde->state & FDE_WRITE ? 'W' : ' ',
fde->state & FDE_ERROR ? 'E' : ' ',
info);
+ adb_mutex_unlock(&D_lock);
}
#else
+#define D(...) ((void)0)
#define dump_fde(fde, info) do { } while(0)
#endif
@@ -67,6 +92,7 @@
static void fdevent_plist_enqueue(fdevent *node);
static void fdevent_plist_remove(fdevent *node);
static fdevent *fdevent_plist_dequeue(void);
+static void fdevent_subproc_event_func(int fd, unsigned events, void *userdata);
static fdevent list_pending = {
.next = &list_pending,
@@ -270,9 +296,72 @@
FD_CLR(fde->fd, &error_fds);
}
- fde->state = (fde->state & FDE_STATEMASK) | events;
+ fde->state = (fde->state & FDE_STATEMASK) | events;
}
+/* Looks at fd_table[] for bad FDs and sets bit in fds.
+** Returns the number of bad FDs.
+*/
+static int fdevent_fd_check(fd_set *fds)
+{
+ int i, n = 0;
+ fdevent *fde;
+
+ for(i = 0; i < select_n; i++) {
+ fde = fd_table[i];
+ if(fde == 0) continue;
+ if(fcntl(i, F_GETFL, NULL) < 0) {
+ FD_SET(i, fds);
+ n++;
+ // fde->state |= FDE_DONT_CLOSE;
+
+ }
+ }
+ return n;
+}
+
+#if !DEBUG
+static inline void dump_all_fds(const char *extra_msg) {}
+#else
+static void dump_all_fds(const char *extra_msg)
+{
+int i;
+ fdevent *fde;
+ // per fd: 4 digits (but really: log10(FD_SETSIZE)), 1 staus, 1 blank
+ char msg_buff[FD_SETSIZE*6 + 1], *pb=msg_buff;
+ size_t max_chars = FD_SETSIZE * 6 + 1;
+ int printed_out;
+#define SAFE_SPRINTF(...) \
+ do { \
+ printed_out = snprintf(pb, max_chars, __VA_ARGS__); \
+ if (printed_out <= 0) { \
+ D("... snprintf failed.\n"); \
+ return; \
+ } \
+ if (max_chars < (unsigned int)printed_out) { \
+ D("... snprintf out of space.\n"); \
+ return; \
+ } \
+ pb += printed_out; \
+ max_chars -= printed_out; \
+ } while(0)
+
+ for(i = 0; i < select_n; i++) {
+ fde = fd_table[i];
+ SAFE_SPRINTF("%d", i);
+ if(fde == 0) {
+ SAFE_SPRINTF("? ");
+ continue;
+ }
+ if(fcntl(i, F_GETFL, NULL) < 0) {
+ SAFE_SPRINTF("b");
+ }
+ SAFE_SPRINTF(" ");
+ }
+ D("%s fd_table[]->fd = {%s}\n", extra_msg, msg_buff);
+}
+#endif
+
static void fdevent_process()
{
int i, n;
@@ -284,28 +373,49 @@
memcpy(&wfd, &write_fds, sizeof(fd_set));
memcpy(&efd, &error_fds, sizeof(fd_set));
- n = select(select_n, &rfd, &wfd, &efd, 0);
+ dump_all_fds("pre select()");
+
+ n = select(select_n, &rfd, &wfd, &efd, NULL);
+ int saved_errno = errno;
+ D("select() returned n=%d, errno=%d\n", n, n<0?saved_errno:0);
+
+ dump_all_fds("post select()");
if(n < 0) {
- if(errno == EINTR) return;
- perror("select");
- return;
+ switch(saved_errno) {
+ case EINTR: return;
+ case EBADF:
+ // Can't trust the FD sets after an error.
+ FD_ZERO(&wfd);
+ FD_ZERO(&efd);
+ FD_ZERO(&rfd);
+ break;
+ default:
+ D("Unexpected select() error=%d\n", saved_errno);
+ return;
+ }
+ }
+ if(n <= 0) {
+ // We fake a read, as the rest of the code assumes
+ // that errors will be detected at that point.
+ n = fdevent_fd_check(&rfd);
}
for(i = 0; (i < select_n) && (n > 0); i++) {
events = 0;
- if(FD_ISSET(i, &rfd)) events |= FDE_READ;
- if(FD_ISSET(i, &wfd)) events |= FDE_WRITE;
- if(FD_ISSET(i, &efd)) events |= FDE_ERROR;
+ if(FD_ISSET(i, &rfd)) { events |= FDE_READ; n--; }
+ if(FD_ISSET(i, &wfd)) { events |= FDE_WRITE; n--; }
+ if(FD_ISSET(i, &efd)) { events |= FDE_ERROR; n--; }
if(events) {
- n--;
-
fde = fd_table[i];
- if(fde == 0) FATAL("missing fde for fd %d\n", i);
+ if(fde == 0)
+ FATAL("missing fde for fd %d\n", i);
fde->events |= events;
+ D("got events fde->fd=%d events=%04x, state=%04x\n",
+ fde->fd, fde->events, fde->state);
if(fde->state & FDE_PENDING) continue;
fde->state |= FDE_PENDING;
fdevent_plist_enqueue(fde);
@@ -350,14 +460,14 @@
}
if(fd_table[fde->fd] != fde) {
- FATAL("fd_table out of sync");
+ FATAL("fd_table out of sync [%d]\n", fde->fd);
}
fd_table[fde->fd] = 0;
if(!(fde->state & FDE_DONT_CLOSE)) {
dump_fde(fde, "close");
- close(fde->fd);
+ adb_close(fde->fd);
}
}
@@ -394,6 +504,74 @@
return node;
}
+static void fdevent_call_fdfunc(fdevent* fde)
+{
+ unsigned events = fde->events;
+ fde->events = 0;
+ if(!(fde->state & FDE_PENDING)) return;
+ fde->state &= (~FDE_PENDING);
+ dump_fde(fde, "callback");
+ fde->func(fde->fd, events, fde->arg);
+}
+
+static void fdevent_subproc_event_func(int fd, unsigned ev, void *userdata)
+{
+
+ D("subproc handling on fd=%d ev=%04x\n", fd, ev);
+
+ // Hook oneself back into the fde's suitable for select() on read.
+ if((fd < 0) || (fd >= fd_table_max)) {
+ FATAL("fd %d out of range for fd_table \n", fd);
+ }
+ fdevent *fde = fd_table[fd];
+ fdevent_add(fde, FDE_READ);
+
+ if(ev & FDE_READ){
+ int subproc_fd;
+
+ if(readx(fd, &subproc_fd, sizeof(subproc_fd))) {
+ FATAL("Failed to read the subproc's fd from fd=%d\n", fd);
+ }
+ if((subproc_fd < 0) || (subproc_fd >= fd_table_max)) {
+ D("subproc_fd %d out of range 0, fd_table_max=%d\n",
+ subproc_fd, fd_table_max);
+ return;
+ }
+ fdevent *subproc_fde = fd_table[subproc_fd];
+ if(!subproc_fde) {
+ D("subproc_fd %d cleared from fd_table\n", subproc_fd);
+ return;
+ }
+ if(subproc_fde->fd != subproc_fd) {
+ // Already reallocated?
+ D("subproc_fd %d != fd_table[].fd %d\n", subproc_fd, subproc_fde->fd);
+ return;
+ }
+
+ subproc_fde->force_eof = 1;
+
+ int rcount = 0;
+ ioctl(subproc_fd, FIONREAD, &rcount);
+ D("subproc with fd=%d has rcount=%d err=%d\n",
+ subproc_fd, rcount, errno);
+
+ if(rcount) {
+ // If there is data left, it will show up in the select().
+ // This works because there is no other thread reading that
+ // data when in this fd_func().
+ return;
+ }
+
+ D("subproc_fde.state=%04x\n", subproc_fde->state);
+ subproc_fde->events |= FDE_READ;
+ if(subproc_fde->state & FDE_PENDING) {
+ return;
+ }
+ subproc_fde->state |= FDE_PENDING;
+ fdevent_call_fdfunc(subproc_fde);
+ }
+}
+
fdevent *fdevent_create(int fd, fd_func func, void *arg)
{
fdevent *fde = (fdevent*) malloc(sizeof(fdevent));
@@ -412,11 +590,12 @@
fdevent_remove(fde);
}
-void fdevent_install(fdevent *fde, int fd, fd_func func, void *arg)
+void fdevent_install(fdevent *fde, int fd, fd_func func, void *arg)
{
memset(fde, 0, sizeof(fdevent));
fde->state = FDE_ACTIVE;
fde->fd = fd;
+ fde->force_eof = 0;
fde->func = func;
fde->arg = arg;
@@ -437,7 +616,7 @@
if(fde->state & FDE_ACTIVE) {
fdevent_disconnect(fde);
- dump_fde(fde, "disconnect");
+ dump_fde(fde, "disconnect");
fdevent_unregister(fde);
}
@@ -484,23 +663,33 @@
fde, (fde->state & FDE_EVENTMASK) & (~(events & FDE_EVENTMASK)));
}
+void fdevent_subproc_setup()
+{
+ int s[2];
+
+ if(adb_socketpair(s)) {
+ FATAL("cannot create shell-exit socket-pair\n");
+ }
+ SHELL_EXIT_NOTIFY_FD = s[0];
+ fdevent *fde;
+ fde = fdevent_create(s[1], fdevent_subproc_event_func, NULL);
+ if(!fde)
+ FATAL("cannot create fdevent for shell-exit handler\n");
+ fdevent_add(fde, FDE_READ);
+}
+
void fdevent_loop()
{
fdevent *fde;
+ fdevent_subproc_setup();
for(;;) {
-#if DEBUG
- fprintf(stderr,"--- ---- waiting for events\n");
-#endif
+ D("--- ---- waiting for events\n");
+
fdevent_process();
while((fde = fdevent_plist_dequeue())) {
- unsigned events = fde->events;
- fde->events = 0;
- fde->state &= (~FDE_PENDING);
- dump_fde(fde, "callback");
- fde->func(fde->fd, events, fde->arg);
+ fdevent_call_fdfunc(fde);
}
}
}
-
diff --git a/adb/fdevent.h b/adb/fdevent.h
index 6b7e7ec..a0ebe2a 100644
--- a/adb/fdevent.h
+++ b/adb/fdevent.h
@@ -70,6 +70,8 @@
fdevent *prev;
int fd;
+ int force_eof;
+
unsigned short state;
unsigned short events;
diff --git a/adb/file_sync_client.c b/adb/file_sync_client.c
index 5c7a26f..64e393c 100644
--- a/adb/file_sync_client.c
+++ b/adb/file_sync_client.c
@@ -641,8 +641,9 @@
} else {
ci = mkcopyinfo(lpath, rpath, name, 0);
if(lstat(ci->src, &st)) {
- closedir(d);
fprintf(stderr,"cannot stat '%s': %s\n", ci->src, strerror(errno));
+ closedir(d);
+
return -1;
}
if(!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) {
diff --git a/adb/file_sync_service.c b/adb/file_sync_service.c
index a231e93..d3e841b 100644
--- a/adb/file_sync_service.c
+++ b/adb/file_sync_service.c
@@ -193,9 +193,11 @@
if(fd < 0)
continue;
if(writex(fd, buffer, len)) {
+ int saved_errno = errno;
adb_close(fd);
adb_unlink(path);
fd = -1;
+ errno = saved_errno;
if(fail_errno(s)) return -1;
}
}
diff --git a/adb/mutex_list.h b/adb/mutex_list.h
index eebe0df..652dd73 100644
--- a/adb/mutex_list.h
+++ b/adb/mutex_list.h
@@ -1,8 +1,11 @@
-/* the list of mutexes used by addb */
+/* the list of mutexes used by adb */
+/* #ifndef __MUTEX_LIST_H
+ * Do not use an include-guard. This file is included once to declare the locks
+ * and once in win32 to actually do the runtime initialization.
+ */
#ifndef ADB_MUTEX
#error ADB_MUTEX not defined when including this file
#endif
-
ADB_MUTEX(dns_lock)
ADB_MUTEX(socket_list_lock)
ADB_MUTEX(transport_lock)
@@ -11,4 +14,13 @@
#endif
ADB_MUTEX(usb_lock)
+// Sadly logging to /data/adb/adb-... is not thread safe.
+// After modifying adb.h::D() to count invocations:
+// DEBUG(jpa):0:Handling main()
+// DEBUG(jpa):1:[ usb_init - starting thread ]
+// (Oopsies, no :2:, and matching message is also gone.)
+// DEBUG(jpa):3:[ usb_thread - opening device ]
+// DEBUG(jpa):4:jdwp control socket started (10)
+ADB_MUTEX(D_lock)
+
#undef ADB_MUTEX
diff --git a/adb/services.c b/adb/services.c
index 7eab17a..6940be8 100644
--- a/adb/services.c
+++ b/adb/services.c
@@ -22,7 +22,7 @@
#include "sysdeps.h"
-#define TRACE_TAG TRACE_ADB
+#define TRACE_TAG TRACE_SERVICES
#include "adb.h"
#include "file_sync_service.h"
@@ -30,6 +30,7 @@
# ifndef HAVE_WINSOCK
# include <netinet/in.h>
# include <netdb.h>
+# include <sys/ioctl.h>
# endif
#else
# include <cutils/android_reboot.h>
@@ -124,14 +125,12 @@
return;
}
- property_set("service.adb.root", "1");
snprintf(buf, sizeof(buf), "restarting adbd as root\n");
writex(fd, buf, strlen(buf));
adb_close(fd);
- // quit, and init will restart us as root
- sleep(1);
- exit(1);
+ // This will cause a property trigger in init.rc to restart us
+ property_set("service.adb.root", "1");
}
}
@@ -267,15 +266,16 @@
return s[0];
}
-static int create_subprocess(const char *cmd, const char *arg0, const char *arg1)
+#if !ADB_HOST
+static int create_subprocess(const char *cmd, const char *arg0, const char *arg1, pid_t *pid)
{
#ifdef HAVE_WIN32_PROC
- fprintf(stderr, "error: create_subprocess not implemented on Win32 (%s %s %s)\n", cmd, arg0, arg1);
- return -1;
+ D("create_subprocess(cmd=%s, arg0=%s, arg1=%s)\n", cmd, arg0, arg1);
+ fprintf(stderr, "error: create_subprocess not implemented on Win32 (%s %s %s)\n", cmd, arg0, arg1);
+ return -1;
#else /* !HAVE_WIN32_PROC */
char *devname;
int ptm;
- pid_t pid;
ptm = unix_open("/dev/ptmx", O_RDWR); // | O_NOCTTY);
if(ptm < 0){
@@ -287,22 +287,27 @@
if(grantpt(ptm) || unlockpt(ptm) ||
((devname = (char*) ptsname(ptm)) == 0)){
printf("[ trouble with /dev/ptmx - %s ]\n", strerror(errno));
+ adb_close(ptm);
return -1;
}
- pid = fork();
- if(pid < 0) {
+ *pid = fork();
+ if(*pid < 0) {
printf("- fork failed: %s -\n", strerror(errno));
+ adb_close(ptm);
return -1;
}
- if(pid == 0){
+ if(*pid == 0){
int pts;
setsid();
pts = unix_open(devname, O_RDWR);
- if(pts < 0) exit(-1);
+ if(pts < 0) {
+ fprintf(stderr, "child failed to open pseudo-term slave: %s\n", devname);
+ exit(-1);
+ }
dup2(pts, 0);
dup2(pts, 1);
@@ -311,15 +316,9 @@
adb_close(pts);
adb_close(ptm);
- execl(cmd, cmd, arg0, arg1, NULL);
- fprintf(stderr, "- exec '%s' failed: %s (%d) -\n",
- cmd, strerror(errno), errno);
- exit(-1);
- } else {
-#if !ADB_HOST
- // set child's OOM adjustment to zero
+ // set OOM adjustment to zero
char text[64];
- snprintf(text, sizeof text, "/proc/%d/oom_adj", pid);
+ snprintf(text, sizeof text, "/proc/%d/oom_adj", getpid());
int fd = adb_open(text, O_WRONLY);
if (fd >= 0) {
adb_write(fd, "0", 1);
@@ -327,11 +326,20 @@
} else {
D("adb: unable to open %s\n", text);
}
-#endif
+ execl(cmd, cmd, arg0, arg1, NULL);
+ fprintf(stderr, "- exec '%s' failed: %s (%d) -\n",
+ cmd, strerror(errno), errno);
+ exit(-1);
+ } else {
+ // Don't set child's OOM adjustment to zero.
+ // Let the child do it itself, as sometimes the parent starts
+ // running before the child has a /proc/pid/oom_adj.
+ // """adb: unable to open /proc/644/oom_adj""" seen in some logs.
return ptm;
}
#endif /* !HAVE_WIN32_PROC */
}
+#endif /* !ABD_HOST */
#if ADB_HOST
#define SHELL_COMMAND "/bin/sh"
@@ -339,6 +347,70 @@
#define SHELL_COMMAND "/system/bin/sh"
#endif
+#if !ADB_HOST
+static void subproc_waiter_service(int fd, void *cookie)
+{
+ pid_t pid = (pid_t)cookie;
+
+ D("entered. fd=%d of pid=%d\n", fd, pid);
+ for (;;) {
+ int status;
+ pid_t p = waitpid(pid, &status, 0);
+ if (p == pid) {
+ D("fd=%d, post waitpid(pid=%d) status=%04x\n", fd, p, status);
+ if (WIFSIGNALED(status)) {
+ D("*** Killed by signal %d\n", WTERMSIG(status));
+ break;
+ } else if (!WIFEXITED(status)) {
+ D("*** Didn't exit!!. status %d\n", status);
+ break;
+ } else if (WEXITSTATUS(status) >= 0) {
+ D("*** Exit code %d\n", WEXITSTATUS(status));
+ break;
+ }
+ }
+ usleep(100000); // poll every 0.1 sec
+ }
+ D("shell exited fd=%d of pid=%d err=%d\n", fd, pid, errno);
+ if (SHELL_EXIT_NOTIFY_FD >=0) {
+ int res;
+ res = writex(SHELL_EXIT_NOTIFY_FD, &fd, sizeof(fd));
+ D("notified shell exit via fd=%d for pid=%d res=%d errno=%d\n",
+ SHELL_EXIT_NOTIFY_FD, pid, res, errno);
+ }
+}
+
+static int create_subproc_thread(const char *name)
+{
+ stinfo *sti;
+ adb_thread_t t;
+ int ret_fd;
+ pid_t pid;
+ if(name) {
+ ret_fd = create_subprocess(SHELL_COMMAND, "-c", name, &pid);
+ } else {
+ ret_fd = create_subprocess(SHELL_COMMAND, "-", 0, &pid);
+ }
+ D("create_subprocess() ret_fd=%d pid=%d\n", ret_fd, pid);
+
+ sti = malloc(sizeof(stinfo));
+ if(sti == 0) fatal("cannot allocate stinfo");
+ sti->func = subproc_waiter_service;
+ sti->cookie = (void*)pid;
+ sti->fd = ret_fd;
+
+ if(adb_thread_create( &t, service_bootstrap_func, sti)){
+ free(sti);
+ adb_close(ret_fd);
+ printf("cannot create service thread\n");
+ return -1;
+ }
+
+ D("service thread started, fd=%d pid=%d\n",ret_fd, pid);
+ return ret_fd;
+}
+#endif
+
int service_to_fd(const char *name)
{
int ret = -1;
@@ -389,14 +461,12 @@
ret = create_jdwp_connection_fd(atoi(name+5));
} else if (!strncmp(name, "log:", 4)) {
ret = create_service_thread(log_service, get_log_file_path(name + 4));
-#endif
} else if(!HOST && !strncmp(name, "shell:", 6)) {
if(name[6]) {
- ret = create_subprocess(SHELL_COMMAND, "-c", name + 6);
+ ret = create_subproc_thread(name + 6);
} else {
- ret = create_subprocess(SHELL_COMMAND, "-", 0);
+ ret = create_subproc_thread(0);
}
-#if !ADB_HOST
} else if(!strncmp(name, "sync:", 5)) {
ret = create_service_thread(file_sync_service, NULL);
} else if(!strncmp(name, "remount:", 8)) {
@@ -407,6 +477,12 @@
ret = create_service_thread(reboot_service, arg);
} else if(!strncmp(name, "root:", 5)) {
ret = create_service_thread(restart_root_service, NULL);
+ } else if(!strncmp(name, "backup:", 7)) {
+ char* arg = strdup(name+7);
+ if (arg == NULL) return -1;
+ ret = backup_service(BACKUP, arg);
+ } else if(!strncmp(name, "restore:", 8)) {
+ ret = backup_service(RESTORE, NULL);
} else if(!strncmp(name, "tcpip:", 6)) {
int port;
if (sscanf(name + 6, "%d", &port) == 0) {
diff --git a/adb/sockets.c b/adb/sockets.c
index f0357d6..df223b1 100644
--- a/adb/sockets.c
+++ b/adb/sockets.c
@@ -199,6 +199,7 @@
static void local_socket_destroy(asocket *s)
{
apacket *p, *n;
+ D("LS(%d): destroying fde.fd=%d\n", s->id, s->fde.fd);
/* IMPORTANT: the remove closes the fd
** that belongs to this socket
@@ -218,7 +219,10 @@
static void local_socket_close_locked(asocket *s)
{
+ D("entered. LS(%d) fd=%d\n", s->id, s->fd);
if(s->peer) {
+ D("LS(%d): closing peer. peer->id=%d peer->fd=%d\n",
+ s->id, s->peer->id, s->peer->fd);
s->peer->peer = 0;
// tweak to avoid deadlock
if (s->peer->close == local_socket_close) {
@@ -245,6 +249,7 @@
s->closing = 1;
fdevent_del(&s->fde, FDE_READ);
remove_socket(s);
+ D("LS(%d): put on socket_closing_list fd=%d\n", s->id, s->fd);
insert_local_socket(s, &local_socket_closing_list);
}
@@ -252,6 +257,8 @@
{
asocket *s = _s;
+ D("LS(%d): event_func(fd=%d(==%d), ev=%04x)\n", s->id, s->fd, fd, ev);
+
/* put the FDE_WRITE processing before the FDE_READ
** in order to simplify the code.
*/
@@ -273,6 +280,7 @@
if(errno == EAGAIN) return;
if(errno == EINTR) continue;
}
+ D(" closing after write because r=%d and errno is %d\n", r, errno);
s->close(s);
return;
}
@@ -288,6 +296,7 @@
** we can now destroy it.
*/
if (s->closing) {
+ D(" closing because 'closing' is set after write\n");
s->close(s);
return;
}
@@ -310,6 +319,7 @@
while(avail > 0) {
r = adb_read(fd, x, avail);
+ D("LS(%d): post adb_read(fd=%d,...) r=%d (errno=%d) avail=%d\n", s->id, s->fd, r, r<0?errno:0, avail);
if(r > 0) {
avail -= r;
x += r;
@@ -324,13 +334,15 @@
is_eof = 1;
break;
}
-
+ D("LS(%d): fd=%d post avail loop. r=%d is_eof=%d forced_eof=%d\n",
+ s->id, s->fd, r, is_eof, s->fde.force_eof);
if((avail == MAX_PAYLOAD) || (s->peer == 0)) {
put_apacket(p);
} else {
p->len = MAX_PAYLOAD - avail;
r = s->peer->enqueue(s->peer, p);
+ D("LS(%d): fd=%d post peer->enqueue(). r=%d\n", s->id, s->fd, r);
if(r < 0) {
/* error return means they closed us as a side-effect
@@ -352,8 +364,9 @@
fdevent_del(&s->fde, FDE_READ);
}
}
-
- if(is_eof) {
+ /* Don't allow a forced eof if data is still there */
+ if((s->fde.force_eof && !r) || is_eof) {
+ D(" closing because is_eof=%d r=%d s->fde.force_eof=%d\n", is_eof, r, s->fde.force_eof);
s->close(s);
}
}
@@ -364,6 +377,8 @@
** bytes of readable data.
*/
// s->close(s);
+ D("LS(%d): FDE_ERROR (fd=%d)\n", s->id, s->fd);
+
return;
}
}
@@ -372,11 +387,11 @@
{
asocket *s = calloc(1, sizeof(asocket));
if (s == NULL) fatal("cannot allocate socket");
- install_local_socket(s);
s->fd = fd;
s->enqueue = local_socket_enqueue;
s->ready = local_socket_ready;
s->close = local_socket_close;
+ install_local_socket(s);
fdevent_install(&s->fde, fd, local_socket_event_func, s);
/* fdevent_add(&s->fde, FDE_ERROR); */
@@ -402,7 +417,7 @@
if(fd < 0) return 0;
s = create_local_socket(fd);
- D("LS(%d): bound to '%s'\n", s->id, name);
+ D("LS(%d): bound to '%s' via %d\n", s->id, name, fd);
return s;
}
@@ -432,7 +447,8 @@
static int remote_socket_enqueue(asocket *s, apacket *p)
{
- D("Calling remote_socket_enqueue\n");
+ D("entered remote_socket_enqueue RS(%d) WRITE fd=%d peer.fd=%d\n",
+ s->id, s->fd, s->peer->fd);
p->msg.command = A_WRTE;
p->msg.arg0 = s->peer->id;
p->msg.arg1 = s->id;
@@ -443,7 +459,8 @@
static void remote_socket_ready(asocket *s)
{
- D("Calling remote_socket_ready\n");
+ D("entered remote_socket_ready RS(%d) OKAY fd=%d peer.fd=%d\n",
+ s->id, s->fd, s->peer->fd);
apacket *p = get_apacket();
p->msg.command = A_OKAY;
p->msg.arg0 = s->peer->id;
@@ -453,12 +470,15 @@
static void remote_socket_close(asocket *s)
{
- D("Calling remote_socket_close\n");
+ D("entered remote_socket_close RS(%d) CLOSE fd=%d peer->fd=%d\n",
+ s->id, s->fd, s->peer?s->peer->fd:-1);
apacket *p = get_apacket();
p->msg.command = A_CLSE;
if(s->peer) {
p->msg.arg0 = s->peer->id;
s->peer->peer = 0;
+ D("RS(%d) peer->close()ing peer->id=%d peer->fd=%d\n",
+ s->id, s->peer->id, s->peer->fd);
s->peer->close(s->peer);
}
p->msg.arg1 = s->id;
@@ -503,7 +523,7 @@
void connect_to_remote(asocket *s, const char *destination)
{
- D("Connect_to_remote call \n");
+ D("Connect_to_remote call RS(%d) fd=%d\n", s->id, s->fd);
apacket *p = get_apacket();
int len = strlen(destination) + 1;
diff --git a/adb/sysdeps.h b/adb/sysdeps.h
index 74f4ed1..b518076 100644
--- a/adb/sysdeps.h
+++ b/adb/sysdeps.h
@@ -44,6 +44,7 @@
#define ADB_MUTEX_DEFINE(x) adb_mutex_t x
/* declare all mutexes */
+/* For win32, adb_sysdeps_init() will do the mutex runtime initialization. */
#define ADB_MUTEX(x) extern adb_mutex_t x;
#include "mutex_list.h"
@@ -195,6 +196,8 @@
fdevent *prev;
int fd;
+ int force_eof;
+
unsigned short state;
unsigned short events;
@@ -274,13 +277,14 @@
#define OS_PATH_SEPARATOR_STR "/"
typedef pthread_mutex_t adb_mutex_t;
+
#define ADB_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#define adb_mutex_init pthread_mutex_init
#define adb_mutex_lock pthread_mutex_lock
#define adb_mutex_unlock pthread_mutex_unlock
#define adb_mutex_destroy pthread_mutex_destroy
-#define ADB_MUTEX_DEFINE(m) static adb_mutex_t m = PTHREAD_MUTEX_INITIALIZER
+#define ADB_MUTEX_DEFINE(m) adb_mutex_t m = PTHREAD_MUTEX_INITIALIZER
#define adb_cond_t pthread_cond_t
#define adb_cond_init pthread_cond_init
@@ -289,6 +293,10 @@
#define adb_cond_signal pthread_cond_signal
#define adb_cond_destroy pthread_cond_destroy
+/* declare all mutexes */
+#define ADB_MUTEX(x) extern adb_mutex_t x;
+#include "mutex_list.h"
+
static __inline__ void close_on_exec(int fd)
{
fcntl( fd, F_SETFD, FD_CLOEXEC );
diff --git a/adb/transport.c b/adb/transport.c
index 2baf340..83a349a 100644
--- a/adb/transport.c
+++ b/adb/transport.c
@@ -35,24 +35,30 @@
ADB_MUTEX_DEFINE( transport_lock );
#if ADB_TRACE
+#define MAX_DUMP_HEX_LEN 16
static void dump_hex( const unsigned char* ptr, size_t len )
{
int nn, len2 = len;
+ // Build a string instead of logging each character.
+ // MAX chars in 2 digit hex, one space, MAX chars, one '\0'.
+ char buffer[MAX_DUMP_HEX_LEN *2 + 1 + MAX_DUMP_HEX_LEN + 1 ], *pb = buffer;
- if (len2 > 16) len2 = 16;
+ if (len2 > MAX_DUMP_HEX_LEN) len2 = MAX_DUMP_HEX_LEN;
- for (nn = 0; nn < len2; nn++)
- D("%02x", ptr[nn]);
- D(" ");
+ for (nn = 0; nn < len2; nn++) {
+ sprintf(pb, "%02x", ptr[nn]);
+ pb += 2;
+ }
+ sprintf(pb++, " ");
for (nn = 0; nn < len2; nn++) {
int c = ptr[nn];
if (c < 32 || c > 127)
c = '.';
- D("%c", c);
+ *pb++ = c;
}
- D("\n");
- fflush(stdout);
+ *pb++ = '\0';
+ DR("%s\n", buffer);
}
#endif
@@ -192,6 +198,7 @@
static void transport_socket_events(int fd, unsigned events, void *_t)
{
atransport *t = _t;
+ D("transport_socket_events(fd=%d, events=%04x,...)\n", fd, events);
if(events & FDE_READ){
apacket *p = 0;
if(read_packet(fd, t->serial, &p)){
@@ -221,8 +228,10 @@
print_packet("send", p);
if (t == NULL) {
- fatal_errno("Transport is null");
D("Transport is null \n");
+ // Zap errno because print_packet() and other stuff have errno effect.
+ errno = 0;
+ fatal_errno("Transport is null");
}
if(write_packet(t->transport_socket, t->serial, &p)){
@@ -1069,4 +1078,3 @@
return 0;
}
}
-
diff --git a/adb/transport.h b/adb/transport.h
new file mode 100644
index 0000000..992e052
--- /dev/null
+++ b/adb/transport.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TRANSPORT_H
+#define __TRANSPORT_H
+
+/* convenience wrappers around read/write that will retry on
+** EINTR and/or short read/write. Returns 0 on success, -1
+** on error or EOF.
+*/
+int readx(int fd, void *ptr, size_t len);
+int writex(int fd, const void *ptr, size_t len);
+#endif /* __TRANSPORT_H */
diff --git a/adb/usb_linux.c b/adb/usb_linux.c
index cd61083..4d55b74 100644
--- a/adb/usb_linux.c
+++ b/adb/usb_linux.c
@@ -45,7 +45,7 @@
/* usb scan debugging is waaaay too verbose */
#define DBGX(x...)
-static adb_mutex_t usb_lock = ADB_MUTEX_INITIALIZER;
+ADB_MUTEX_DEFINE( usb_lock );
struct usb_handle
{
@@ -369,6 +369,7 @@
h->reaper_thread = pthread_self();
adb_mutex_unlock(&h->lock);
res = ioctl(h->desc, USBDEVFS_REAPURB, &out);
+ int saved_errno = errno;
adb_mutex_lock(&h->lock);
h->reaper_thread = 0;
if(h->dead) {
@@ -376,7 +377,7 @@
break;
}
if(res < 0) {
- if(errno == EINTR) {
+ if(saved_errno == EINTR) {
continue;
}
D("[ reap urb - error ]\n");
@@ -604,6 +605,7 @@
ctrl.wIndex = 0;
ctrl.wLength = sizeof(languages);
ctrl.data = languages;
+ ctrl.timeout = 1000;
result = ioctl(usb->desc, USBDEVFS_CONTROL, &ctrl);
if (result > 0)
@@ -619,6 +621,7 @@
ctrl.wIndex = __le16_to_cpu(languages[i]);
ctrl.wLength = sizeof(buffer);
ctrl.data = buffer;
+ ctrl.timeout = 1000;
result = ioctl(usb->desc, USBDEVFS_CONTROL, &ctrl);
if (result > 0) {
@@ -685,4 +688,3 @@
fatal_errno("cannot create input thread");
}
}
-
diff --git a/adb/usb_linux_client.c b/adb/usb_linux_client.c
index 0a21c6f..635fa4b 100644
--- a/adb/usb_linux_client.c
+++ b/adb/usb_linux_client.c
@@ -83,14 +83,14 @@
{
int n;
- D("[ write %d ]\n", len);
+ D("about to write (fd=%d, len=%d)\n", h->fd, len);
n = adb_write(h->fd, data, len);
if(n != len) {
- D("ERROR: n = %d, errno = %d (%s)\n",
- n, errno, strerror(errno));
+ D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
+ h->fd, n, errno, strerror(errno));
return -1;
}
- D("[ done ]\n");
+ D("[ done fd=%d ]\n", h->fd);
return 0;
}
@@ -98,13 +98,14 @@
{
int n;
- D("[ read %d ]\n", len);
+ D("about to read (fd=%d, len=%d)\n", h->fd, len);
n = adb_read(h->fd, data, len);
if(n != len) {
- D("ERROR: n = %d, errno = %d (%s)\n",
- n, errno, strerror(errno));
+ D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
+ h->fd, n, errno, strerror(errno));
return -1;
}
+ D("[ done fd=%d ]\n", h->fd);
return 0;
}
diff --git a/adb/usb_windows.c b/adb/usb_windows.c
index 38c4cf4..b216999 100644
--- a/adb/usb_windows.c
+++ b/adb/usb_windows.c
@@ -246,10 +246,10 @@
}
// Something went wrong.
- errno = GetLastError();
+ int saved_errno = GetLastError();
usb_cleanup_handle(ret);
free(ret);
- SetLastError(errno);
+ SetLastError(saved_errno);
return NULL;
}
@@ -267,7 +267,7 @@
(unsigned long)len,
&written,
time_out);
- errno = GetLastError();
+ int saved_errno = GetLastError();
if (ret) {
// Make sure that we've written what we were asked to write
@@ -285,9 +285,10 @@
}
} else {
// assume ERROR_INVALID_HANDLE indicates we are disconnected
- if (errno == ERROR_INVALID_HANDLE)
+ if (saved_errno == ERROR_INVALID_HANDLE)
usb_kick(handle);
}
+ errno = saved_errno;
} else {
D("usb_write NULL handle\n");
SetLastError(ERROR_INVALID_HANDLE);
@@ -313,20 +314,21 @@
(unsigned long)xfer,
&read,
time_out);
- errno = GetLastError();
- D("usb_write got: %ld, expected: %d, errno: %d\n", read, xfer, errno);
+ int saved_errno = GetLastError();
+ D("usb_write got: %ld, expected: %d, errno: %d\n", read, xfer, saved_errno);
if (ret) {
data += read;
len -= read;
if (len == 0)
return 0;
- } else if (errno != ERROR_SEM_TIMEOUT) {
+ } else if (saved_errno != ERROR_SEM_TIMEOUT) {
// assume ERROR_INVALID_HANDLE indicates we are disconnected
- if (errno == ERROR_INVALID_HANDLE)
+ if (saved_errno == ERROR_INVALID_HANDLE)
usb_kick(handle);
break;
}
+ errno = saved_errno;
}
} else {
D("usb_read NULL handle\n");
diff --git a/debuggerd/debuggerd.c b/debuggerd/debuggerd.c
index 7a3e781..685f147 100644
--- a/debuggerd/debuggerd.c
+++ b/debuggerd/debuggerd.c
@@ -37,7 +37,6 @@
#include <private/android_filesystem_config.h>
-#include <byteswap.h>
#include "debuggerd.h"
#include "utility.h"
@@ -196,73 +195,6 @@
if(sig) dump_fault_addr(tfd, tid, sig);
}
-/* After randomization (ASLR), stack contents that point to randomized
- * code become uninterpretable (e.g. can't be resolved to line numbers).
- * Here, we bundle enough information so that stack analysis on the
- * server side can still be performed. This means we are leaking some
- * information about the device (its randomization base). We have to make
- * sure an attacker has no way of intercepting the tombstone.
- */
-
-typedef struct {
- int32_t mmap_addr;
- char tag[4]; /* 'P', 'R', 'E', ' ' */
-} prelink_info_t __attribute__((packed));
-
-static inline void set_prelink(long *prelink_addr,
- prelink_info_t *info)
-{
- // We will assume the binary is little-endian, and test the
- // host endianness here.
- unsigned long test_endianness = 0xFF;
-
- if (sizeof(prelink_info_t) == 8 && prelink_addr) {
- if (*(unsigned char *)&test_endianness)
- *prelink_addr = info->mmap_addr;
- else
- *prelink_addr = bswap_32(info->mmap_addr);
- }
-}
-
-static int check_prelinked(const char *fname,
- long *prelink_addr)
-{
- *prelink_addr = 0;
- if (sizeof(prelink_info_t) != 8) return 0;
-
- int fd = open(fname, O_RDONLY);
- if (fd < 0) return 0;
- off_t end = lseek(fd, 0, SEEK_END);
- int nr = sizeof(prelink_info_t);
-
- off_t sz = lseek(fd, -nr, SEEK_CUR);
- if ((long)(end - sz) != (long)nr) return 0;
- if (sz == (off_t)-1) return 0;
-
- prelink_info_t info;
- int num_read = read(fd, &info, nr);
- if (num_read < 0) return 0;
- if (num_read != sizeof(info)) return 0;
-
- int prelinked = 0;
- if (!strncmp(info.tag, "PRE ", 4)) {
- set_prelink(prelink_addr, &info);
- prelinked = 1;
- }
- if (close(fd) < 0) return 0;
- return prelinked;
-}
-
-void dump_randomization_base(int tfd, bool at_fault) {
- bool only_in_tombstone = !at_fault;
- long prelink_addr;
- check_prelinked("/system/lib/libc.so", &prelink_addr);
- _LOG(tfd, only_in_tombstone,
- "\nlibc base address: %08x\n", prelink_addr);
-}
-
-/* End of ASLR-related logic. */
-
static void parse_elf_info(mapinfo *milist, pid_t pid)
{
mapinfo *mi;
@@ -353,7 +285,6 @@
dump_pc_and_lr(tfd, tid, milist, stack_depth, at_fault);
}
- dump_randomization_base(tfd, at_fault);
dump_stack_and_code(tfd, tid, milist, stack_depth, sp_list, at_fault);
#elif __i386__
/* If stack unwinder fails, use the default solution to dump the stack
diff --git a/include/arch/darwin-x86/AndroidConfig.h b/include/arch/darwin-x86/AndroidConfig.h
index d99072a..c8ccc7e 100644
--- a/include/arch/darwin-x86/AndroidConfig.h
+++ b/include/arch/darwin-x86/AndroidConfig.h
@@ -305,12 +305,4 @@
*/
#define HAVE_PRINTF_ZD 1
-/*
- * We need to open binary files using O_BINARY on Windows.
- * Most systems lack (and actually don't need) this flag.
- */
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#endif /*_ANDROID_CONFIG_H*/
diff --git a/include/arch/freebsd-x86/AndroidConfig.h b/include/arch/freebsd-x86/AndroidConfig.h
index 9703c76..d828bd5 100644
--- a/include/arch/freebsd-x86/AndroidConfig.h
+++ b/include/arch/freebsd-x86/AndroidConfig.h
@@ -363,12 +363,4 @@
*/
#define HAVE_PRINTF_ZD 1
-/*
- * We need to open binary files using O_BINARY on Windows.
- * Most systems lack (and actually don't need) this flag.
- */
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#endif /*_ANDROID_CONFIG_H*/
diff --git a/include/arch/linux-arm/AndroidConfig.h b/include/arch/linux-arm/AndroidConfig.h
index 5138d90..83891cd 100644
--- a/include/arch/linux-arm/AndroidConfig.h
+++ b/include/arch/linux-arm/AndroidConfig.h
@@ -361,12 +361,4 @@
*/
#define HAVE_PRINTF_ZD 1
-/*
- * We need to open binary files using O_BINARY on Windows.
- * Most systems lack (and actually don't need) this flag.
- */
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#endif /* _ANDROID_CONFIG_H */
diff --git a/include/arch/linux-ppc/AndroidConfig.h b/include/arch/linux-ppc/AndroidConfig.h
index 60bddd6..00706dc 100644
--- a/include/arch/linux-ppc/AndroidConfig.h
+++ b/include/arch/linux-ppc/AndroidConfig.h
@@ -323,12 +323,4 @@
*/
#define HAVE_PREAD 1
-/*
- * We need to open binary files using O_BINARY on Windows.
- * Most systems lack (and actually don't need) this flag.
- */
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#endif /*_ANDROID_CONFIG_H*/
diff --git a/include/arch/linux-sh/AndroidConfig.h b/include/arch/linux-sh/AndroidConfig.h
index 9303bb6..5562eae 100644
--- a/include/arch/linux-sh/AndroidConfig.h
+++ b/include/arch/linux-sh/AndroidConfig.h
@@ -366,12 +366,4 @@
*/
#define HAVE_PRINTF_ZD 1
-/*
- * We need to open binary files using O_BINARY on Windows.
- * Most systems lack (and actually don't need) this flag.
- */
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#endif /* _ANDROID_CONFIG_H */
diff --git a/include/arch/linux-x86/AndroidConfig.h b/include/arch/linux-x86/AndroidConfig.h
index 6fd26ea..7dcaa98 100644
--- a/include/arch/linux-x86/AndroidConfig.h
+++ b/include/arch/linux-x86/AndroidConfig.h
@@ -333,12 +333,4 @@
*/
#define HAVE_PRINTF_ZD 1
-/*
- * We need to open binary files using O_BINARY on Windows.
- * Most systems lack (and actually don't need) this flag.
- */
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#endif /*_ANDROID_CONFIG_H*/
diff --git a/include/arch/target_linux-x86/AndroidConfig.h b/include/arch/target_linux-x86/AndroidConfig.h
index a6f7090..05dd220 100644
--- a/include/arch/target_linux-x86/AndroidConfig.h
+++ b/include/arch/target_linux-x86/AndroidConfig.h
@@ -350,12 +350,4 @@
*/
#define HAVE_PRINTF_ZD 1
-/*
- * We need to open binary files using O_BINARY on Windows.
- * Most systems lack (and actually don't need) this flag.
- */
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
#endif /* _ANDROID_CONFIG_H */
diff --git a/include/arch/windows/AndroidConfig.h b/include/arch/windows/AndroidConfig.h
index 8a7e062..ad890b4 100644
--- a/include/arch/windows/AndroidConfig.h
+++ b/include/arch/windows/AndroidConfig.h
@@ -338,10 +338,4 @@
*/
/* #define HAVE_PRINTF_ZD 1 */
-/*
- * We need to open binary files using O_BINARY on Windows.
- * We don't define it on Windows since it is part of the io headers.
- */
-/* #define O_BINARY 0 */
-
#endif /*_ANDROID_CONFIG_H*/
diff --git a/include/cutils/atomic-inline.h b/include/cutils/atomic-inline.h
index 6acb67c..49f3e70 100644
--- a/include/cutils/atomic-inline.h
+++ b/include/cutils/atomic-inline.h
@@ -17,6 +17,10 @@
#ifndef ANDROID_CUTILS_ATOMIC_INLINE_H
#define ANDROID_CUTILS_ATOMIC_INLINE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Inline declarations and macros for some special-purpose atomic
* operations. These are intended for rare circumstances where a
@@ -61,4 +65,8 @@
#define ANDROID_MEMBAR_STORE android_memory_store_barrier
#endif
+#ifdef __cplusplus
+}
+#endif
+
#endif /* ANDROID_CUTILS_ATOMIC_INLINE_H */
diff --git a/include/cutils/config_utils.h b/include/cutils/config_utils.h
index f3fb370..2dea6f1 100644
--- a/include/cutils/config_utils.h
+++ b/include/cutils/config_utils.h
@@ -54,6 +54,9 @@
/* add a named child to a config node (or modify it if it already exists) */
void config_set(cnode *root, const char *name, const char *value);
+/* free a config node tree */
+void config_free(cnode *root);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/cutils/log.h b/include/cutils/log.h
index f602017..42d7382 100644
--- a/include/cutils/log.h
+++ b/include/cutils/log.h
@@ -289,13 +289,17 @@
* It is NOT stripped from release builds. Note that the condition test
* is -inverted- from the normal assert() semantics.
*/
+#ifndef LOG_ALWAYS_FATAL_IF
#define LOG_ALWAYS_FATAL_IF(cond, ...) \
( (CONDITION(cond)) \
? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
: (void)0 )
+#endif
+#ifndef LOG_ALWAYS_FATAL
#define LOG_ALWAYS_FATAL(...) \
( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
+#endif
/*
* Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
@@ -303,13 +307,21 @@
*/
#if LOG_NDEBUG
+#ifndef LOG_FATAL_IF
#define LOG_FATAL_IF(cond, ...) ((void)0)
+#endif
+#ifndef LOG_FATAL
#define LOG_FATAL(...) ((void)0)
+#endif
#else
+#ifndef LOG_FATAL_IF
#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
+#endif
+#ifndef LOG_FATAL
#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
+#endif
#endif
@@ -317,8 +329,10 @@
* Assertion that generates a log message when the assertion fails.
* Stripped out of release builds. Uses the current LOG_TAG.
*/
+#ifndef LOG_ASSERT
#define LOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
//#define LOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
+#endif
// ---------------------------------------------------------------------
@@ -377,18 +391,24 @@
} AndroidEventLogType;
+#ifndef LOG_EVENT_INT
#define LOG_EVENT_INT(_tag, _value) { \
int intBuf = _value; \
(void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
sizeof(intBuf)); \
}
+#endif
+#ifndef LOG_EVENT_LONG
#define LOG_EVENT_LONG(_tag, _value) { \
long long longBuf = _value; \
(void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
sizeof(longBuf)); \
}
+#endif
+#ifndef LOG_EVENT_STRING
#define LOG_EVENT_STRING(_tag, _value) \
((void) 0) /* not implemented -- must combine len with string */
+#endif
/* TODO: something for LIST */
/*
diff --git a/include/cutils/native_handle.h b/include/cutils/native_handle.h
index 89d6b65..268c5d3 100644
--- a/include/cutils/native_handle.h
+++ b/include/cutils/native_handle.h
@@ -21,7 +21,7 @@
extern "C" {
#endif
-typedef struct
+typedef struct native_handle
{
int version; /* sizeof(native_handle_t) */
int numFds; /* number of file-descriptors at &data[0] */
@@ -29,10 +29,6 @@
int data[0]; /* numFds + numInts ints */
} native_handle_t;
-
-/* keep the old definition for backward source-compatibility */
-typedef native_handle_t native_handle;
-
/*
* native_handle_close
*
diff --git a/include/cutils/partition_utils.h b/include/cutils/partition_utils.h
new file mode 100644
index 0000000..597df92
--- /dev/null
+++ b/include/cutils/partition_utils.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CUTILS_PARTITION_WIPED_H__
+#define __CUTILS_PARTITION_WIPED_H__
+
+__BEGIN_DECLS
+
+int partition_wiped(char *source);
+void erase_footer(const char *dev_path, long long size);
+
+__END_DECLS
+
+#endif /* __CUTILS_PARTITION_WIPED_H__ */
diff --git a/include/cutils/qtaguid.h b/include/cutils/qtaguid.h
new file mode 100644
index 0000000..8aa34ea
--- /dev/null
+++ b/include/cutils/qtaguid.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CUTILS_QTAGUID_H
+#define __CUTILS_QTAGUID_H
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Set tags (and owning UIDs) for network sockets.
+*/
+extern int set_qtaguid(int sockfd, int tag, uid_t uid);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CUTILS_QTAG_UID_H */
diff --git a/include/cutils/sockets.h b/include/cutils/sockets.h
index aa8682e..19cae0c 100644
--- a/include/cutils/sockets.h
+++ b/include/cutils/sockets.h
@@ -20,6 +20,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <stdbool.h>
#ifdef HAVE_WINSOCK
#include <winsock2.h>
@@ -92,7 +93,18 @@
const char *name, int namespaceId, int type);
extern int socket_local_client(const char *name, int namespaceId, int type);
extern int socket_inaddr_any_server(int port, int type);
-
+
+/*
+ * socket_peer_is_trusted - Takes a socket which is presumed to be a
+ * connected local socket (e.g. AF_LOCAL) and returns whether the peer
+ * (the userid that owns the process on the other end of that socket)
+ * is one of the two trusted userids, root or shell.
+ *
+ * Note: This only works as advertised on the Android OS and always
+ * just returns true when called on other operating systems.
+ */
+extern bool socket_peer_is_trusted(int fd);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/cutils/uevent.h b/include/cutils/uevent.h
index 587149c..5f5e6ca 100644
--- a/include/cutils/uevent.h
+++ b/include/cutils/uevent.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-ssize_t uevent_checked_recv(int socket, void *buffer, size_t length);
+ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length);
#ifdef __cplusplus
}
diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
index f23c235..fc71a1e 100644
--- a/include/private/android_filesystem_config.h
+++ b/include/private/android_filesystem_config.h
@@ -71,6 +71,8 @@
#define AID_INET 3003 /* can create AF_INET and AF_INET6 sockets */
#define AID_NET_RAW 3004 /* can create raw INET sockets */
#define AID_NET_ADMIN 3005 /* can configure interfaces and routing tables. */
+#define AID_NET_BW_STATS 3006 /* read bandwidth statistics */
+#define AID_NET_BW_ACCT 3007 /* change bandwidth statistics accounting */
#define AID_MISC 9998 /* access to misc storage */
#define AID_NOBODY 9999
@@ -118,6 +120,8 @@
{ "inet", AID_INET, },
{ "net_raw", AID_NET_RAW, },
{ "net_admin", AID_NET_ADMIN, },
+ { "net_bw_stats", AID_NET_BW_STATS, },
+ { "net_bw_acct", AID_NET_BW_ACCT, },
{ "misc", AID_MISC, },
{ "nobody", AID_NOBODY, },
};
diff --git a/include/system/audio.h b/include/system/audio.h
index 8f2ac0c..2e261ce 100644
--- a/include/system/audio.h
+++ b/include/system/audio.h
@@ -88,8 +88,10 @@
/* PCM sub formats */
typedef enum {
- AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE */
- AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE */
+ AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */
+ AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */
+ AUDIO_FORMAT_PCM_SUB_32_BIT = 0x3, /* PCM signed .31 fixed point */
+ AUDIO_FORMAT_PCM_SUB_8_24_BIT = 0x4, /* PCM signed 7.24 fixed point */
} audio_format_pcm_sub_fmt_t;
/* MP3 sub format field definition : can use 11 LSBs in the same way as MP3
@@ -144,6 +146,10 @@
AUDIO_FORMAT_PCM_SUB_16_BIT),
AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM |
AUDIO_FORMAT_PCM_SUB_8_BIT),
+ AUDIO_FORMAT_PCM_32_BIT = (AUDIO_FORMAT_PCM |
+ AUDIO_FORMAT_PCM_SUB_32_BIT),
+ AUDIO_FORMAT_PCM_8_24_BIT = (AUDIO_FORMAT_PCM |
+ AUDIO_FORMAT_PCM_SUB_8_24_BIT),
} audio_format_t;
/* Channel mask definitions must be kept in sync with JAVA values in
@@ -363,6 +369,10 @@
{
switch (format & AUDIO_FORMAT_MAIN_MASK) {
case AUDIO_FORMAT_PCM:
+ if (format != AUDIO_FORMAT_PCM_16_BIT &&
+ format != AUDIO_FORMAT_PCM_8_BIT) {
+ return false;
+ }
case AUDIO_FORMAT_MP3:
case AUDIO_FORMAT_AMR_NB:
case AUDIO_FORMAT_AMR_WB:
@@ -378,15 +388,29 @@
static inline bool audio_is_linear_pcm(uint32_t format)
{
- switch (format) {
- case AUDIO_FORMAT_PCM_16_BIT:
- case AUDIO_FORMAT_PCM_8_BIT:
- return true;
- default:
- return false;
- }
+ return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM);
}
+static inline size_t audio_bytes_per_sample(uint32_t format)
+{
+ size_t size = 0;
+
+ switch (format) {
+ case AUDIO_FORMAT_PCM_32_BIT:
+ case AUDIO_FORMAT_PCM_8_24_BIT:
+ size = sizeof(int32_t);
+ break;
+ case AUDIO_FORMAT_PCM_16_BIT:
+ size = sizeof(int16_t);
+ break;
+ case AUDIO_FORMAT_PCM_8_BIT:
+ size = sizeof(uint8_t);
+ break;
+ default:
+ break;
+ }
+ return size;
+}
__END_DECLS
diff --git a/include/system/audio_policy.h b/include/system/audio_policy.h
new file mode 100644
index 0000000..1e0af7d
--- /dev/null
+++ b/include/system/audio_policy.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef ANDROID_AUDIO_POLICY_CORE_H
+#define ANDROID_AUDIO_POLICY_CORE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <cutils/bitops.h>
+
+__BEGIN_DECLS
+
+/* The enums were moved here mostly from
+ * frameworks/base/include/media/AudioSystem.h
+ */
+
+/* request to open a direct output with get_output() (by opposition to
+ * sharing an output with other AudioTracks)
+ */
+typedef enum {
+ AUDIO_POLICY_OUTPUT_FLAG_INDIRECT = 0x0,
+ AUDIO_POLICY_OUTPUT_FLAG_DIRECT = 0x1
+} audio_policy_output_flags_t;
+
+/* device categories used for audio_policy->set_force_use() */
+typedef enum {
+ AUDIO_POLICY_FORCE_NONE,
+ AUDIO_POLICY_FORCE_SPEAKER,
+ AUDIO_POLICY_FORCE_HEADPHONES,
+ AUDIO_POLICY_FORCE_BT_SCO,
+ AUDIO_POLICY_FORCE_BT_A2DP,
+ AUDIO_POLICY_FORCE_WIRED_ACCESSORY,
+ AUDIO_POLICY_FORCE_BT_CAR_DOCK,
+ AUDIO_POLICY_FORCE_BT_DESK_DOCK,
+ AUDIO_POLICY_FORCE_ANALOG_DOCK,
+ AUDIO_POLICY_FORCE_DIGITAL_DOCK,
+
+ AUDIO_POLICY_FORCE_CFG_CNT,
+ AUDIO_POLICY_FORCE_CFG_MAX = AUDIO_POLICY_FORCE_CFG_CNT - 1,
+
+ AUDIO_POLICY_FORCE_DEFAULT = AUDIO_POLICY_FORCE_NONE,
+} audio_policy_forced_cfg_t;
+
+/* usages used for audio_policy->set_force_use() */
+typedef enum {
+ AUDIO_POLICY_FORCE_FOR_COMMUNICATION,
+ AUDIO_POLICY_FORCE_FOR_MEDIA,
+ AUDIO_POLICY_FORCE_FOR_RECORD,
+ AUDIO_POLICY_FORCE_FOR_DOCK,
+
+ AUDIO_POLICY_FORCE_USE_CNT,
+ AUDIO_POLICY_FORCE_USE_MAX = AUDIO_POLICY_FORCE_USE_CNT - 1,
+} audio_policy_force_use_t;
+
+/* device connection states used for audio_policy->set_device_connection_state()
+ */
+typedef enum {
+ AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
+ AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
+
+ AUDIO_POLICY_DEVICE_STATE_CNT,
+ AUDIO_POLICY_DEVICE_STATE_MAX = AUDIO_POLICY_DEVICE_STATE_CNT - 1,
+} audio_policy_dev_state_t;
+
+typedef enum {
+ /* Used to generate a tone to notify the user of a
+ * notification/alarm/ringtone while they are in a call. */
+ AUDIO_POLICY_TONE_IN_CALL_NOTIFICATION = 0,
+
+ AUDIO_POLICY_TONE_CNT,
+ AUDIO_POLICY_TONE_MAX = AUDIO_POLICY_TONE_CNT - 1,
+} audio_policy_tone_t;
+
+
+static inline bool audio_is_low_visibility(audio_stream_type_t stream)
+{
+ switch (stream) {
+ case AUDIO_STREAM_SYSTEM:
+ case AUDIO_STREAM_NOTIFICATION:
+ case AUDIO_STREAM_RING:
+ return true;
+ default:
+ return false;
+ }
+}
+
+
+__END_DECLS
+
+#endif // ANDROID_AUDIO_POLICY_CORE_H
diff --git a/include/system/camera.h b/include/system/camera.h
new file mode 100644
index 0000000..58e0c6f
--- /dev/null
+++ b/include/system/camera.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SYSTEM_CORE_INCLUDE_ANDROID_CAMERA_H
+#define SYSTEM_CORE_INCLUDE_ANDROID_CAMERA_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <cutils/native_handle.h>
+#include <hardware/hardware.h>
+#include <hardware/gralloc.h>
+
+__BEGIN_DECLS
+
+/**
+ * A set of bit masks for specifying how the received preview frames are
+ * handled before the previewCallback() call.
+ *
+ * The least significant 3 bits of an "int" value are used for this purpose:
+ *
+ * ..... 0 0 0
+ * ^ ^ ^
+ * | | |---------> determine whether the callback is enabled or not
+ * | |-----------> determine whether the callback is one-shot or not
+ * |-------------> determine whether the frame is copied out or not
+ *
+ * WARNING: When a frame is sent directly without copying, it is the frame
+ * receiver's responsiblity to make sure that the frame data won't get
+ * corrupted by subsequent preview frames filled by the camera. This flag is
+ * recommended only when copying out data brings significant performance price
+ * and the handling/processing of the received frame data is always faster than
+ * the preview frame rate so that data corruption won't occur.
+ *
+ * For instance,
+ * 1. 0x00 disables the callback. In this case, copy out and one shot bits
+ * are ignored.
+ * 2. 0x01 enables a callback without copying out the received frames. A
+ * typical use case is the Camcorder application to avoid making costly
+ * frame copies.
+ * 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical
+ * use case is the Camera application.
+ * 4. 0x07 is enabling a callback with frame copied out only once. A typical
+ * use case is the Barcode scanner application.
+ */
+
+enum {
+ CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK = 0x01,
+ CAMERA_FRAME_CALLBACK_FLAG_ONE_SHOT_MASK = 0x02,
+ CAMERA_FRAME_CALLBACK_FLAG_COPY_OUT_MASK = 0x04,
+ /** Typical use cases */
+ CAMERA_FRAME_CALLBACK_FLAG_NOOP = 0x00,
+ CAMERA_FRAME_CALLBACK_FLAG_CAMCORDER = 0x01,
+ CAMERA_FRAME_CALLBACK_FLAG_CAMERA = 0x05,
+ CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER = 0x07
+};
+
+/** msgType in notifyCallback and dataCallback functions */
+enum {
+ CAMERA_MSG_ERROR = 0x0001,
+ CAMERA_MSG_SHUTTER = 0x0002,
+ CAMERA_MSG_FOCUS = 0x0004,
+ CAMERA_MSG_ZOOM = 0x0008,
+ CAMERA_MSG_PREVIEW_FRAME = 0x0010,
+ CAMERA_MSG_VIDEO_FRAME = 0x0020,
+ CAMERA_MSG_POSTVIEW_FRAME = 0x0040,
+ CAMERA_MSG_RAW_IMAGE = 0x0080,
+ CAMERA_MSG_COMPRESSED_IMAGE = 0x0100,
+ CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x0200,
+ CAMERA_MSG_ALL_MSGS = 0xFFFF
+};
+
+/** cmdType in sendCommand functions */
+enum {
+ CAMERA_CMD_START_SMOOTH_ZOOM = 1,
+ CAMERA_CMD_STOP_SMOOTH_ZOOM = 2,
+ /** Set the clockwise rotation of preview display (setPreviewDisplay) in
+ * degrees. This affects the preview frames and the picture displayed after
+ * snapshot. This method is useful for portrait mode applications. Note
+ * that preview display of front-facing cameras is flipped horizontally
+ * before the rotation, that is, the image is reflected along the central
+ * vertical axis of the camera sensor. So the users can see themselves as
+ * looking into a mirror.
+ *
+ * This does not affect the order of byte array of
+ * CAMERA_MSG_PREVIEW_FRAME, CAMERA_MSG_VIDEO_FRAME,
+ * CAMERA_MSG_POSTVIEW_FRAME, CAMERA_MSG_RAW_IMAGE, or
+ * CAMERA_MSG_COMPRESSED_IMAGE. This is not allowed to be set during
+ * preview
+ */
+ CAMERA_CMD_SET_DISPLAY_ORIENTATION = 3,
+
+ /** cmdType to disable/enable shutter sound. In sendCommand passing arg1 =
+ * 0 will disable, while passing arg1 = 1 will enable the shutter sound.
+ */
+ CAMERA_CMD_ENABLE_SHUTTER_SOUND = 4,
+
+ /* cmdType to play recording sound */
+ CAMERA_CMD_PLAY_RECORDING_SOUND = 5,
+};
+
+/** camera fatal errors */
+enum {
+ CAMERA_ERROR_UNKNOWN = 1,
+ CAMERA_ERROR_SERVER_DIED = 100
+};
+
+enum {
+ CAMERA_FACING_BACK = 0, /** The facing of the camera is opposite to that of
+ * the screen. */
+ CAMERA_FACING_FRONT = 1 /** The facing of the camera is the same as that of
+ * the screen. */
+};
+
+__END_DECLS
+
+#endif /* SYSTEM_CORE_INCLUDE_ANDROID_CAMERA_H */
diff --git a/include/system/graphics.h b/include/system/graphics.h
new file mode 100644
index 0000000..d39bd4e
--- /dev/null
+++ b/include/system/graphics.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
+#define SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
+
+__BEGIN_DECLS
+
+/**
+ * pixel format definitions
+ */
+
+enum {
+ HAL_PIXEL_FORMAT_RGBA_8888 = 1,
+ HAL_PIXEL_FORMAT_RGBX_8888 = 2,
+ HAL_PIXEL_FORMAT_RGB_888 = 3,
+ HAL_PIXEL_FORMAT_RGB_565 = 4,
+ HAL_PIXEL_FORMAT_BGRA_8888 = 5,
+ HAL_PIXEL_FORMAT_RGBA_5551 = 6,
+ HAL_PIXEL_FORMAT_RGBA_4444 = 7,
+
+ /* 0x8 - 0xFF range unavailable */
+
+ /*
+ * 0x100 - 0x1FF
+ *
+ * This range is reserved for pixel formats that are specific to the HAL
+ * implementation. Implementations can use any value in this range to
+ * communicate video pixel formats between their HAL modules. These formats
+ * must not have an alpha channel. Additionally, an EGLimage created from a
+ * gralloc buffer of one of these formats must be supported for use with the
+ * GL_OES_EGL_image_external OpenGL ES extension.
+ */
+
+ /*
+ * Android YUV format:
+ *
+ * This format is exposed outside of the HAL to software decoders and
+ * applications. EGLImageKHR must support it in conjunction with the
+ * OES_EGL_image_external extension.
+ *
+ * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
+ * by (W/2) x (H/2) Cr and Cb planes.
+ *
+ * This format assumes
+ * - an even width
+ * - an even height
+ * - a horizontal stride multiple of 16 pixels
+ * - a vertical stride equal to the height
+ *
+ * y_size = stride * height
+ * c_size = ALIGN(stride/2, 16) * height/2
+ * size = y_size + c_size * 2
+ * cr_offset = y_size
+ * cb_offset = y_size + c_size
+ *
+ */
+ HAL_PIXEL_FORMAT_YV12 = 0x32315659, // YCrCb 4:2:0 Planar
+
+
+
+ /* Legacy formats (deprecated), used by ImageFormat.java */
+ HAL_PIXEL_FORMAT_YCbCr_422_SP = 0x10, // NV16
+ HAL_PIXEL_FORMAT_YCrCb_420_SP = 0x11, // NV21
+ HAL_PIXEL_FORMAT_YCbCr_422_I = 0x14, // YUY2
+};
+
+
+/**
+ * Transformation definitions
+ *
+ * IMPORTANT NOTE:
+ * HAL_TRANSFORM_ROT_90 is applied CLOCKWISE and AFTER HAL_TRANSFORM_FLIP_{H|V}.
+ *
+ */
+
+enum {
+ /* flip source image horizontally (around the vertical axis) */
+ HAL_TRANSFORM_FLIP_H = 0x01,
+ /* flip source image vertically (around the horizontal axis)*/
+ HAL_TRANSFORM_FLIP_V = 0x02,
+ /* rotate source image 90 degrees clockwise */
+ HAL_TRANSFORM_ROT_90 = 0x04,
+ /* rotate source image 180 degrees */
+ HAL_TRANSFORM_ROT_180 = 0x03,
+ /* rotate source image 270 degrees clockwise */
+ HAL_TRANSFORM_ROT_270 = 0x07,
+};
+
+__END_DECLS
+
+#endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */
diff --git a/include/system/window.h b/include/system/window.h
new file mode 100644
index 0000000..edb3002
--- /dev/null
+++ b/include/system/window.h
@@ -0,0 +1,538 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H
+#define SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <system/graphics.h>
+#include <cutils/native_handle.h>
+
+__BEGIN_DECLS
+
+/*****************************************************************************/
+
+#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \
+ (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d))
+
+#define ANDROID_NATIVE_WINDOW_MAGIC \
+ ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
+
+#define ANDROID_NATIVE_BUFFER_MAGIC \
+ ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r')
+
+// ---------------------------------------------------------------------------
+
+typedef const native_handle_t* buffer_handle_t;
+
+// ---------------------------------------------------------------------------
+
+typedef struct android_native_rect_t
+{
+ int32_t left;
+ int32_t top;
+ int32_t right;
+ int32_t bottom;
+} android_native_rect_t;
+
+// ---------------------------------------------------------------------------
+
+typedef struct android_native_base_t
+{
+ /* a magic value defined by the actual EGL native type */
+ int magic;
+
+ /* the sizeof() of the actual EGL native type */
+ int version;
+
+ void* reserved[4];
+
+ /* reference-counting interface */
+ void (*incRef)(struct android_native_base_t* base);
+ void (*decRef)(struct android_native_base_t* base);
+} android_native_base_t;
+
+typedef struct ANativeWindowBuffer
+{
+#ifdef __cplusplus
+ ANativeWindowBuffer() {
+ common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
+ common.version = sizeof(ANativeWindowBuffer);
+ memset(common.reserved, 0, sizeof(common.reserved));
+ }
+
+ // Implement the methods that sp<ANativeWindowBuffer> expects so that it
+ // can be used to automatically refcount ANativeWindowBuffer's.
+ void incStrong(const void* id) const {
+ common.incRef(const_cast<android_native_base_t*>(&common));
+ }
+ void decStrong(const void* id) const {
+ common.decRef(const_cast<android_native_base_t*>(&common));
+ }
+#endif
+
+ struct android_native_base_t common;
+
+ int width;
+ int height;
+ int stride;
+ int format;
+ int usage;
+
+ void* reserved[2];
+
+ buffer_handle_t handle;
+
+ void* reserved_proc[8];
+} ANativeWindowBuffer_t;
+
+// Old typedef for backwards compatibility.
+typedef ANativeWindowBuffer_t android_native_buffer_t;
+
+// ---------------------------------------------------------------------------
+
+/* attributes queriable with query() */
+enum {
+ NATIVE_WINDOW_WIDTH = 0,
+ NATIVE_WINDOW_HEIGHT = 1,
+ NATIVE_WINDOW_FORMAT = 2,
+
+ /* The minimum number of buffers that must remain un-dequeued after a buffer
+ * has been queued. This value applies only if set_buffer_count was used to
+ * override the number of buffers and if a buffer has since been queued.
+ * Users of the set_buffer_count ANativeWindow method should query this
+ * value before calling set_buffer_count. If it is necessary to have N
+ * buffers simultaneously dequeued as part of the steady-state operation,
+ * and this query returns M then N+M buffers should be requested via
+ * native_window_set_buffer_count.
+ *
+ * Note that this value does NOT apply until a single buffer has been
+ * queued. In particular this means that it is possible to:
+ *
+ * 1. Query M = min undequeued buffers
+ * 2. Set the buffer count to N + M
+ * 3. Dequeue all N + M buffers
+ * 4. Cancel M buffers
+ * 5. Queue, dequeue, queue, dequeue, ad infinitum
+ */
+ NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = 3,
+
+ /* Check whether queueBuffer operations on the ANativeWindow send the buffer
+ * to the window compositor. The query sets the returned 'value' argument
+ * to 1 if the ANativeWindow DOES send queued buffers directly to the window
+ * compositor and 0 if the buffers do not go directly to the window
+ * compositor.
+ *
+ * This can be used to determine whether protected buffer content should be
+ * sent to the ANativeWindow. Note, however, that a result of 1 does NOT
+ * indicate that queued buffers will be protected from applications or users
+ * capturing their contents. If that behavior is desired then some other
+ * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
+ * conjunction with this query.
+ */
+ NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
+
+ /* Get the concrete type of a ANativeWindow. See below for the list of
+ * possible return values.
+ *
+ * This query should not be used outside the Android framework and will
+ * likely be removed in the near future.
+ */
+ NATIVE_WINDOW_CONCRETE_TYPE = 5,
+};
+
+/* valid operations for the (*perform)() hook */
+enum {
+ NATIVE_WINDOW_SET_USAGE = 0,
+ NATIVE_WINDOW_CONNECT = 1,
+ NATIVE_WINDOW_DISCONNECT = 2,
+ NATIVE_WINDOW_SET_CROP = 3,
+ NATIVE_WINDOW_SET_BUFFER_COUNT = 4,
+ NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = 5, /* deprecated */
+ NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6,
+ NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7,
+ NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8,
+ NATIVE_WINDOW_SET_BUFFERS_FORMAT = 9,
+ NATIVE_WINDOW_SET_SCALING_MODE = 10,
+ NATIVE_WINDOW_LOCK = 11, /* private */
+ NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */
+};
+
+/* parameter for NATIVE_WINDOW_[DIS]CONNECT */
+enum {
+ /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
+ * OpenGL ES.
+ */
+ NATIVE_WINDOW_API_EGL = 1,
+
+ /* Buffers will be queued after being filled using the CPU
+ */
+ NATIVE_WINDOW_API_CPU = 2,
+
+ /* Buffers will be queued by Stagefright after being filled by a video
+ * decoder. The video decoder can either be a software or hardware decoder.
+ */
+ NATIVE_WINDOW_API_MEDIA = 3,
+
+ /* Buffers will be queued by the the camera HAL.
+ */
+ NATIVE_WINDOW_API_CAMERA = 4,
+};
+
+/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
+enum {
+ /* flip source image horizontally */
+ NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
+ /* flip source image vertically */
+ NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
+ /* rotate source image 90 degrees clock-wise */
+ NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
+ /* rotate source image 180 degrees */
+ NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
+ /* rotate source image 270 degrees clock-wise */
+ NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
+};
+
+/* parameter for NATIVE_WINDOW_SET_SCALING_MODE */
+enum {
+ /* the window content is not updated (frozen) until a buffer of
+ * the window size is received (enqueued)
+ */
+ NATIVE_WINDOW_SCALING_MODE_FREEZE = 0,
+ /* the buffer is scaled in both dimensions to match the window size */
+ NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1,
+};
+
+/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
+enum {
+ NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */
+ NATIVE_WINDOW_SURFACE = 1, /* Surface */
+ NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT = 2, /* SurfaceTextureClient */
+};
+
+/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
+ *
+ * Special timestamp value to indicate that timestamps should be auto-generated
+ * by the native window when queueBuffer is called. This is equal to INT64_MIN,
+ * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
+ */
+static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
+
+struct ANativeWindow
+{
+#ifdef __cplusplus
+ ANativeWindow()
+ : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
+ {
+ common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
+ common.version = sizeof(ANativeWindow);
+ memset(common.reserved, 0, sizeof(common.reserved));
+ }
+
+ /* Implement the methods that sp<ANativeWindow> expects so that it
+ can be used to automatically refcount ANativeWindow's. */
+ void incStrong(const void* id) const {
+ common.incRef(const_cast<android_native_base_t*>(&common));
+ }
+ void decStrong(const void* id) const {
+ common.decRef(const_cast<android_native_base_t*>(&common));
+ }
+#endif
+
+ struct android_native_base_t common;
+
+ /* flags describing some attributes of this surface or its updater */
+ const uint32_t flags;
+
+ /* min swap interval supported by this updated */
+ const int minSwapInterval;
+
+ /* max swap interval supported by this updated */
+ const int maxSwapInterval;
+
+ /* horizontal and vertical resolution in DPI */
+ const float xdpi;
+ const float ydpi;
+
+ /* Some storage reserved for the OEM's driver. */
+ intptr_t oem[4];
+
+ /*
+ * Set the swap interval for this surface.
+ *
+ * Returns 0 on success or -errno on error.
+ */
+ int (*setSwapInterval)(struct ANativeWindow* window,
+ int interval);
+
+ /*
+ * hook called by EGL to acquire a buffer. After this call, the buffer
+ * is not locked, so its content cannot be modified.
+ * this call may block if no buffers are available.
+ *
+ * Returns 0 on success or -errno on error.
+ */
+ int (*dequeueBuffer)(struct ANativeWindow* window,
+ struct ANativeWindowBuffer** buffer);
+
+ /*
+ * hook called by EGL to lock a buffer. This MUST be called before modifying
+ * the content of a buffer. The buffer must have been acquired with
+ * dequeueBuffer first.
+ *
+ * Returns 0 on success or -errno on error.
+ */
+ int (*lockBuffer)(struct ANativeWindow* window,
+ struct ANativeWindowBuffer* buffer);
+ /*
+ * hook called by EGL when modifications to the render buffer are done.
+ * This unlocks and post the buffer.
+ *
+ * Buffers MUST be queued in the same order than they were dequeued.
+ *
+ * Returns 0 on success or -errno on error.
+ */
+ int (*queueBuffer)(struct ANativeWindow* window,
+ struct ANativeWindowBuffer* buffer);
+
+ /*
+ * hook used to retrieve information about the native window.
+ *
+ * Returns 0 on success or -errno on error.
+ */
+ int (*query)(const struct ANativeWindow* window,
+ int what, int* value);
+
+ /*
+ * hook used to perform various operations on the surface.
+ * (*perform)() is a generic mechanism to add functionality to
+ * ANativeWindow while keeping backward binary compatibility.
+ *
+ * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions
+ * defined below.
+ *
+ * (*perform)() returns -ENOENT if the 'what' parameter is not supported
+ * by the surface's implementation.
+ *
+ * The valid operations are:
+ * NATIVE_WINDOW_SET_USAGE
+ * NATIVE_WINDOW_CONNECT
+ * NATIVE_WINDOW_DISCONNECT
+ * NATIVE_WINDOW_SET_CROP
+ * NATIVE_WINDOW_SET_BUFFER_COUNT
+ * NATIVE_WINDOW_SET_BUFFERS_GEOMETRY (deprecated)
+ * NATIVE_WINDOW_SET_BUFFERS_TRANSFORM
+ * NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
+ * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS
+ * NATIVE_WINDOW_SET_BUFFERS_FORMAT
+ * NATIVE_WINDOW_SET_SCALING_MODE
+ * NATIVE_WINDOW_LOCK (private)
+ * NATIVE_WINDOW_UNLOCK_AND_POST (private)
+ *
+ */
+
+ int (*perform)(struct ANativeWindow* window,
+ int operation, ... );
+
+ /*
+ * hook used to cancel a buffer that has been dequeued.
+ * No synchronization is performed between dequeue() and cancel(), so
+ * either external synchronization is needed, or these functions must be
+ * called from the same thread.
+ */
+ int (*cancelBuffer)(struct ANativeWindow* window,
+ struct ANativeWindowBuffer* buffer);
+
+
+ void* reserved_proc[2];
+};
+
+ /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
+ * android_native_window_t is deprecated.
+ */
+typedef struct ANativeWindow ANativeWindow;
+typedef struct ANativeWindow android_native_window_t;
+
+/*
+ * native_window_set_usage(..., usage)
+ * Sets the intended usage flags for the next buffers
+ * acquired with (*lockBuffer)() and on.
+ * By default (if this function is never called), a usage of
+ * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE
+ * is assumed.
+ * Calling this function will usually cause following buffers to be
+ * reallocated.
+ */
+
+static inline int native_window_set_usage(
+ struct ANativeWindow* window, int usage)
+{
+ return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage);
+}
+
+/*
+ * native_window_connect(..., NATIVE_WINDOW_API_EGL)
+ * Must be called by EGL when the window is made current.
+ * Returns -EINVAL if for some reason the window cannot be connected, which
+ * can happen if it's connected to some other API.
+ */
+static inline int native_window_connect(
+ struct ANativeWindow* window, int api)
+{
+ return window->perform(window, NATIVE_WINDOW_CONNECT, api);
+}
+
+/*
+ * native_window_disconnect(..., NATIVE_WINDOW_API_EGL)
+ * Must be called by EGL when the window is made not current.
+ * An error is returned if for instance the window wasn't connected in the
+ * first place.
+ */
+static inline int native_window_disconnect(
+ struct ANativeWindow* window, int api)
+{
+ return window->perform(window, NATIVE_WINDOW_DISCONNECT, api);
+}
+
+/*
+ * native_window_set_crop(..., crop)
+ * Sets which region of the next queued buffers needs to be considered.
+ * A buffer's crop region is scaled to match the surface's size.
+ *
+ * The specified crop region applies to all buffers queued after it is called.
+ *
+ * if 'crop' is NULL, subsequently queued buffers won't be cropped.
+ *
+ * An error is returned if for instance the crop region is invalid,
+ * out of the buffer's bound or if the window is invalid.
+ */
+static inline int native_window_set_crop(
+ struct ANativeWindow* window,
+ android_native_rect_t const * crop)
+{
+ return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
+}
+
+/*
+ * native_window_set_buffer_count(..., count)
+ * Sets the number of buffers associated with this native window.
+ */
+static inline int native_window_set_buffer_count(
+ struct ANativeWindow* window,
+ size_t bufferCount)
+{
+ return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
+}
+
+/*
+ * native_window_set_buffers_geometry(..., int w, int h, int format)
+ * All buffers dequeued after this call will have the dimensions and format
+ * specified. A successful call to this function has the same effect as calling
+ * native_window_set_buffers_size and native_window_set_buffers_format.
+ *
+ * XXX: This function is deprecated. The native_window_set_buffers_dimensions
+ * and native_window_set_buffers_format functions should be used instead.
+ */
+static inline int native_window_set_buffers_geometry(
+ struct ANativeWindow* window,
+ int w, int h, int format)
+{
+ return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
+ w, h, format);
+}
+
+/*
+ * native_window_set_buffers_dimensions(..., int w, int h)
+ * All buffers dequeued after this call will have the dimensions specified.
+ * In particular, all buffers will have a fixed-size, independent form the
+ * native-window size. They will be scaled according to the scaling mode
+ * (see native_window_set_scaling_mode) upon window composition.
+ *
+ * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
+ * following this call will be sized to match the window's size.
+ *
+ * Calling this function will reset the window crop to a NULL value, which
+ * disables cropping of the buffers.
+ */
+static inline int native_window_set_buffers_dimensions(
+ struct ANativeWindow* window,
+ int w, int h)
+{
+ return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
+ w, h);
+}
+
+/*
+ * native_window_set_buffers_format(..., int format)
+ * All buffers dequeued after this call will have the format specified.
+ *
+ * If the specified format is 0, the default buffer format will be used.
+ */
+static inline int native_window_set_buffers_format(
+ struct ANativeWindow* window,
+ int format)
+{
+ return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
+}
+
+/*
+ * native_window_set_buffers_transform(..., int transform)
+ * All buffers queued after this call will be displayed transformed according
+ * to the transform parameter specified.
+ */
+static inline int native_window_set_buffers_transform(
+ struct ANativeWindow* window,
+ int transform)
+{
+ return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
+ transform);
+}
+
+/*
+ * native_window_set_buffers_timestamp(..., int64_t timestamp)
+ * All buffers queued after this call will be associated with the timestamp
+ * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
+ * (the default), timestamps will be generated automatically when queueBuffer is
+ * called. The timestamp is measured in nanoseconds, and is normally monotonically
+ * increasing. The timestamp should be unaffected by time-of-day adjustments,
+ * and for a camera should be strictly monotonic but for a media player may be
+ * reset when the position is set.
+ */
+static inline int native_window_set_buffers_timestamp(
+ struct ANativeWindow* window,
+ int64_t timestamp)
+{
+ return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
+ timestamp);
+}
+
+/*
+ * native_window_set_scaling_mode(..., int mode)
+ * All buffers queued after this call will be associated with the scaling mode
+ * specified.
+ */
+static inline int native_window_set_scaling_mode(
+ struct ANativeWindow* window,
+ int mode)
+{
+ return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
+ mode);
+}
+
+__END_DECLS
+
+#endif /* SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H */
diff --git a/include/sysutils/NetlinkEvent.h b/include/sysutils/NetlinkEvent.h
index b329b09..25a56f7 100644
--- a/include/sysutils/NetlinkEvent.h
+++ b/include/sysutils/NetlinkEvent.h
@@ -16,6 +16,8 @@
#ifndef _NETLINKEVENT_H
#define _NETLINKEVENT_H
+#include <sysutils/NetlinkListener.h>
+
#define NL_PARAMS_MAX 32
class NetlinkEvent {
@@ -30,17 +32,23 @@
const static int NlActionAdd;
const static int NlActionRemove;
const static int NlActionChange;
+ const static int NlActionLinkDown;
+ const static int NlActionLinkUp;
NetlinkEvent();
virtual ~NetlinkEvent();
- bool decode(char *buffer, int size);
+ bool decode(char *buffer, int size, int format = NetlinkListener::NETLINK_FORMAT_ASCII);
const char *findParam(const char *paramName);
const char *getSubsystem() { return mSubsystem; }
int getAction() { return mAction; }
void dump();
+
+ protected:
+ bool parseBinaryNetlinkMessage(char *buffer, int size);
+ bool parseAsciiNetlinkMessage(char *buffer, int size);
};
#endif
diff --git a/include/sysutils/NetlinkListener.h b/include/sysutils/NetlinkListener.h
index 2880046..beb8bda 100644
--- a/include/sysutils/NetlinkListener.h
+++ b/include/sysutils/NetlinkListener.h
@@ -22,13 +22,27 @@
class NetlinkListener : public SocketListener {
char mBuffer[64 * 1024];
+ int mFormat;
public:
+ static const int NETLINK_FORMAT_ASCII = 0;
+ static const int NETLINK_FORMAT_BINARY = 1;
+
+#if 1
+ /* temporary version until we can get Motorola to update their
+ * ril.so. Their prebuilt ril.so is using this private class
+ * so changing the NetlinkListener() constructor breaks their ril.
+ */
NetlinkListener(int socket);
+ NetlinkListener(int socket, int format);
+#else
+ NetlinkListener(int socket, int format = NETLINK_FORMAT_ASCII);
+#endif
virtual ~NetlinkListener() {}
protected:
virtual bool onDataAvailable(SocketClient *cli);
virtual void onEvent(NetlinkEvent *evt) = 0;
};
+
#endif
diff --git a/init/builtins.c b/init/builtins.c
index f2f76b7..06ef96d 100644
--- a/init/builtins.c
+++ b/init/builtins.c
@@ -30,6 +30,7 @@
#include <sys/mount.h>
#include <sys/resource.h>
#include <linux/loop.h>
+#include <cutils/partition_utils.h>
#include "init.h"
#include "keywords.h"
@@ -225,14 +226,10 @@
return do_insmod_inner(nargs, args, size);
}
-int do_import(int nargs, char **args)
-{
- return init_parse_config_file(args[1]);
-}
-
int do_mkdir(int nargs, char **args)
{
mode_t mode = 0755;
+ int ret;
/* mkdir <path> [mode] [owner] [group] */
@@ -240,7 +237,12 @@
mode = strtoul(args[2], 0, 8);
}
- if (mkdir(args[1], mode)) {
+ ret = mkdir(args[1], mode);
+ /* chmod in case the directory already exists */
+ if (ret == -1 && errno == EEXIST) {
+ ret = chmod(args[1], mode);
+ }
+ if (ret == -1) {
return -errno;
}
@@ -367,7 +369,9 @@
if (wait)
wait_for_file(source, COMMAND_RETRY_TIMEOUT);
if (mount(source, target, system, flags, options) < 0) {
- /* If this fails, it may be an encrypted filesystem.
+ /* If this fails, it may be an encrypted filesystem
+ * or it could just be wiped. If wiped, that will be
+ * handled later in the boot process.
* We only support encrypting /data. Check
* if we're trying to mount it, and if so,
* assume it's encrypted, mount a tmpfs instead.
@@ -375,7 +379,7 @@
* for vold to query when it mounts the real
* encrypted /data.
*/
- if (!strcmp(target, DATA_MNT_POINT)) {
+ if (!strcmp(target, DATA_MNT_POINT) && !partition_wiped(source)) {
const char *tmpfs_options;
tmpfs_options = property_get("ro.crypto.tmpfs_options");
@@ -442,7 +446,24 @@
int do_setprop(int nargs, char **args)
{
- property_set(args[1], args[2]);
+ const char *name = args[1];
+ const char *value = args[2];
+
+ if (value[0] == '$') {
+ /* Use the value of a system property if value starts with '$' */
+ value++;
+ if (value[0] != '$') {
+ value = property_get(value);
+ if (!value) {
+ ERROR("property %s has no value for assigning to %s\n", value, name);
+ return -EINVAL;
+ }
+ } /* else fall through to support double '$' prefix for setting properties
+ * to string literals that start with '$'
+ */
+ }
+
+ property_set(name, value);
return 0;
}
@@ -524,7 +545,23 @@
int do_write(int nargs, char **args)
{
- return write_file(args[1], args[2]);
+ const char *path = args[1];
+ const char *value = args[2];
+ if (value[0] == '$') {
+ /* Write the value of a system property if value starts with '$' */
+ value++;
+ if (value[0] != '$') {
+ value = property_get(value);
+ if (!value) {
+ ERROR("property %s has no value for writing to %s\n", value, path);
+ return -EINVAL;
+ }
+ } /* else fall through to support double '$' prefix for writing
+ * string literals that start with '$'
+ */
+ }
+
+ return write_file(path, value);
}
int do_copy(int nargs, char **args)
diff --git a/init/devices.c b/init/devices.c
index 9c07e99..60659ce 100644
--- a/init/devices.c
+++ b/init/devices.c
@@ -99,8 +99,15 @@
struct listnode plist;
};
+struct platform_node {
+ char *name;
+ int name_len;
+ struct listnode list;
+};
+
static list_declare(sys_perms);
static list_declare(dev_perms);
+static list_declare(platform_names);
int add_dev_perms(const char *name, const char *attr,
mode_t perm, unsigned int uid, unsigned int gid,
@@ -214,6 +221,68 @@
setegid(AID_ROOT);
}
+static void add_platform_device(const char *name)
+{
+ int name_len = strlen(name);
+ struct listnode *node;
+ struct platform_node *bus;
+
+ list_for_each_reverse(node, &platform_names) {
+ bus = node_to_item(node, struct platform_node, list);
+ if ((bus->name_len < name_len) &&
+ (name[bus->name_len] == '/') &&
+ !strncmp(name, bus->name, bus->name_len))
+ /* subdevice of an existing platform, ignore it */
+ return;
+ }
+
+ INFO("adding platform device %s\n", name);
+
+ bus = calloc(1, sizeof(struct platform_node));
+ bus->name = strdup(name);
+ bus->name_len = name_len;
+ list_add_tail(&platform_names, &bus->list);
+}
+
+/*
+ * given a name that may start with a platform device, find the length of the
+ * platform device prefix. If it doesn't start with a platform device, return
+ * 0.
+ */
+static const char *find_platform_device(const char *name)
+{
+ int name_len = strlen(name);
+ struct listnode *node;
+ struct platform_node *bus;
+
+ list_for_each_reverse(node, &platform_names) {
+ bus = node_to_item(node, struct platform_node, list);
+ if ((bus->name_len < name_len) &&
+ (name[bus->name_len] == '/') &&
+ !strncmp(name, bus->name, bus->name_len))
+ return bus->name;
+ }
+
+ return NULL;
+}
+
+static void remove_platform_device(const char *name)
+{
+ struct listnode *node;
+ struct platform_node *bus;
+
+ list_for_each_reverse(node, &platform_names) {
+ bus = node_to_item(node, struct platform_node, list);
+ if (!strcmp(name, bus->name)) {
+ INFO("removing platform device %s\n", name);
+ free(bus->name);
+ list_remove(node);
+ free(bus);
+ return;
+ }
+ }
+}
+
#if LOG_UEVENTS
static inline suseconds_t get_usecs(void)
@@ -334,7 +403,7 @@
static char **parse_platform_block_device(struct uevent *uevent)
{
- const char *driver;
+ const char *device;
const char *path;
char *slash;
int width;
@@ -354,16 +423,14 @@
/* Drop "/devices/platform/" */
path = uevent->path;
- driver = path + 18;
- slash = strchr(driver, '/');
- if (!slash)
- goto err;
- width = slash - driver;
- if (width <= 0)
+ device = path + 18;
+ device = find_platform_device(device);
+ if (!device)
goto err;
- snprintf(link_path, sizeof(link_path), "/dev/block/platform/%.*s",
- width, driver);
+ INFO("found platform device %s\n", device);
+
+ snprintf(link_path, sizeof(link_path), "/dev/block/platform/%s", device);
if (uevent->partition_name) {
p = strdup(uevent->partition_name);
@@ -395,104 +462,20 @@
return NULL;
}
-static void handle_device_event(struct uevent *uevent)
+static void handle_device(const char *action, const char *devpath,
+ const char *path, int block, int major, int minor, char **links)
{
- char devpath[96];
- int devpath_ready = 0;
- char *base, *name;
- char **links = NULL;
- int block;
int i;
- if (!strcmp(uevent->action,"add"))
- fixup_sys_perms(uevent->path);
-
- /* if it's not a /dev device, nothing else to do */
- if((uevent->major < 0) || (uevent->minor < 0))
- return;
-
- /* do we have a name? */
- name = strrchr(uevent->path, '/');
- if(!name)
- return;
- name++;
-
- /* too-long names would overrun our buffer */
- if(strlen(name) > 64)
- return;
-
- /* are we block or char? where should we live? */
- if(!strncmp(uevent->subsystem, "block", 5)) {
- block = 1;
- base = "/dev/block/";
- mkdir(base, 0755);
- if (!strncmp(uevent->path, "/devices/platform/", 18))
- links = parse_platform_block_device(uevent);
- } else {
- block = 0;
- /* this should probably be configurable somehow */
- if (!strncmp(uevent->subsystem, "usb", 3)) {
- if (!strcmp(uevent->subsystem, "usb")) {
- /* This imitates the file system that would be created
- * if we were using devfs instead.
- * Minors are broken up into groups of 128, starting at "001"
- */
- int bus_id = uevent->minor / 128 + 1;
- int device_id = uevent->minor % 128 + 1;
- /* build directories */
- mkdir("/dev/bus", 0755);
- mkdir("/dev/bus/usb", 0755);
- snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id);
- mkdir(devpath, 0755);
- snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id);
- devpath_ready = 1;
- } else {
- /* ignore other USB events */
- return;
- }
- } else if (!strncmp(uevent->subsystem, "graphics", 8)) {
- base = "/dev/graphics/";
- mkdir(base, 0755);
- } else if (!strncmp(uevent->subsystem, "oncrpc", 6)) {
- base = "/dev/oncrpc/";
- mkdir(base, 0755);
- } else if (!strncmp(uevent->subsystem, "adsp", 4)) {
- base = "/dev/adsp/";
- mkdir(base, 0755);
- } else if (!strncmp(uevent->subsystem, "msm_camera", 10)) {
- base = "/dev/msm_camera/";
- mkdir(base, 0755);
- } else if(!strncmp(uevent->subsystem, "input", 5)) {
- base = "/dev/input/";
- mkdir(base, 0755);
- } else if(!strncmp(uevent->subsystem, "mtd", 3)) {
- base = "/dev/mtd/";
- mkdir(base, 0755);
- } else if(!strncmp(uevent->subsystem, "sound", 5)) {
- base = "/dev/snd/";
- mkdir(base, 0755);
- } else if(!strncmp(uevent->subsystem, "misc", 4) &&
- !strncmp(name, "log_", 4)) {
- base = "/dev/log/";
- mkdir(base, 0755);
- name += 4;
- } else
- base = "/dev/";
- links = get_character_device_symlinks(uevent);
- }
-
- if (!devpath_ready)
- snprintf(devpath, sizeof(devpath), "%s%s", base, name);
-
- if(!strcmp(uevent->action, "add")) {
- make_device(devpath, uevent->path, block, uevent->major, uevent->minor);
+ if(!strcmp(action, "add")) {
+ make_device(devpath, path, block, major, minor);
if (links) {
for (i = 0; links[i]; i++)
make_link(devpath, links[i]);
}
}
- if(!strcmp(uevent->action, "remove")) {
+ if(!strcmp(action, "remove")) {
if (links) {
for (i = 0; links[i]; i++)
remove_link(devpath, links[i]);
@@ -507,6 +490,138 @@
}
}
+static void handle_platform_device_event(struct uevent *uevent)
+{
+ const char *name = uevent->path + 18; /* length of /devices/platform/ */
+
+ if (!strcmp(uevent->action, "add"))
+ add_platform_device(name);
+ else if (!strcmp(uevent->action, "remove"))
+ remove_platform_device(name);
+}
+
+static const char *parse_device_name(struct uevent *uevent, unsigned int len)
+{
+ const char *name;
+
+ /* if it's not a /dev device, nothing else to do */
+ if((uevent->major < 0) || (uevent->minor < 0))
+ return NULL;
+
+ /* do we have a name? */
+ name = strrchr(uevent->path, '/');
+ if(!name)
+ return NULL;
+ name++;
+
+ /* too-long names would overrun our buffer */
+ if(strlen(name) > len)
+ return NULL;
+
+ return name;
+}
+
+static void handle_block_device_event(struct uevent *uevent)
+{
+ const char *base = "/dev/block/";
+ const char *name;
+ char devpath[96];
+ char **links = NULL;
+
+ name = parse_device_name(uevent, 64);
+ if (!name)
+ return;
+
+ snprintf(devpath, sizeof(devpath), "%s%s", base, name);
+ mkdir(base, 0755);
+
+ if (!strncmp(uevent->path, "/devices/platform/", 18))
+ links = parse_platform_block_device(uevent);
+
+ handle_device(uevent->action, devpath, uevent->path, 1,
+ uevent->major, uevent->minor, links);
+}
+
+static void handle_generic_device_event(struct uevent *uevent)
+{
+ char *base;
+ const char *name;
+ char devpath[96] = {0};
+ char **links = NULL;
+
+ name = parse_device_name(uevent, 64);
+ if (!name)
+ return;
+
+ if (!strncmp(uevent->subsystem, "usb", 3)) {
+ if (!strcmp(uevent->subsystem, "usb")) {
+ /* This imitates the file system that would be created
+ * if we were using devfs instead.
+ * Minors are broken up into groups of 128, starting at "001"
+ */
+ int bus_id = uevent->minor / 128 + 1;
+ int device_id = uevent->minor % 128 + 1;
+ /* build directories */
+ mkdir("/dev/bus", 0755);
+ mkdir("/dev/bus/usb", 0755);
+ snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id);
+ mkdir(devpath, 0755);
+ snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id);
+ } else {
+ /* ignore other USB events */
+ return;
+ }
+ } else if (!strncmp(uevent->subsystem, "graphics", 8)) {
+ base = "/dev/graphics/";
+ mkdir(base, 0755);
+ } else if (!strncmp(uevent->subsystem, "oncrpc", 6)) {
+ base = "/dev/oncrpc/";
+ mkdir(base, 0755);
+ } else if (!strncmp(uevent->subsystem, "adsp", 4)) {
+ base = "/dev/adsp/";
+ mkdir(base, 0755);
+ } else if (!strncmp(uevent->subsystem, "msm_camera", 10)) {
+ base = "/dev/msm_camera/";
+ mkdir(base, 0755);
+ } else if(!strncmp(uevent->subsystem, "input", 5)) {
+ base = "/dev/input/";
+ mkdir(base, 0755);
+ } else if(!strncmp(uevent->subsystem, "mtd", 3)) {
+ base = "/dev/mtd/";
+ mkdir(base, 0755);
+ } else if(!strncmp(uevent->subsystem, "sound", 5)) {
+ base = "/dev/snd/";
+ mkdir(base, 0755);
+ } else if(!strncmp(uevent->subsystem, "misc", 4) &&
+ !strncmp(name, "log_", 4)) {
+ base = "/dev/log/";
+ mkdir(base, 0755);
+ name += 4;
+ } else
+ base = "/dev/";
+ links = get_character_device_symlinks(uevent);
+
+ if (!devpath[0])
+ snprintf(devpath, sizeof(devpath), "%s%s", base, name);
+
+ handle_device(uevent->action, devpath, uevent->path, 0,
+ uevent->major, uevent->minor, links);
+}
+
+static void handle_device_event(struct uevent *uevent)
+{
+ if (!strcmp(uevent->action,"add"))
+ fixup_sys_perms(uevent->path);
+
+ if (!strncmp(uevent->subsystem, "block", 5)) {
+ handle_block_device_event(uevent);
+ } else if (!strncmp(uevent->subsystem, "platform", 8)) {
+ handle_platform_device_event(uevent);
+ } else {
+ handle_generic_device_event(uevent);
+ }
+}
+
static int load_firmware(int fw_fd, int loading_fd, int data_fd)
{
struct stat st;
@@ -553,13 +668,19 @@
return ret;
}
+static int is_booting(void)
+{
+ return access("/dev/.booting", F_OK) == 0;
+}
+
static void process_firmware_event(struct uevent *uevent)
{
char *root, *loading, *data, *file1 = NULL, *file2 = NULL;
int l, loading_fd, data_fd, fw_fd;
+ int booting = is_booting();
- log_event_print("firmware event { '%s', '%s' }\n",
- uevent->path, uevent->firmware);
+ INFO("firmware: loading '%s' for '%s'\n",
+ uevent->firmware, uevent->path);
l = asprintf(&root, SYSFS_PREFIX"%s/", uevent->path);
if (l == -1)
@@ -589,19 +710,29 @@
if(data_fd < 0)
goto loading_close_out;
+try_loading_again:
fw_fd = open(file1, O_RDONLY);
if(fw_fd < 0) {
fw_fd = open(file2, O_RDONLY);
if (fw_fd < 0) {
+ if (booting) {
+ /* If we're not fully booted, we may be missing
+ * filesystems needed for firmware, wait and retry.
+ */
+ usleep(100000);
+ booting = is_booting();
+ goto try_loading_again;
+ }
+ INFO("firmware: could not open '%s' %d\n", uevent->firmware, errno);
write(loading_fd, "-1", 2);
goto data_close_out;
}
}
if(!load_firmware(fw_fd, loading_fd, data_fd))
- log_event_print("firmware copy success { '%s', '%s' }\n", root, uevent->firmware);
+ INFO("firmware: copy success { '%s', '%s' }\n", root, uevent->firmware);
else
- log_event_print("firmware copy failure { '%s', '%s' }\n", root, uevent->firmware);
+ INFO("firmware: copy failure { '%s', '%s' }\n", root, uevent->firmware);
close(fw_fd);
data_close_out:
@@ -622,7 +753,6 @@
static void handle_firmware_event(struct uevent *uevent)
{
pid_t pid;
- int status;
int ret;
if(strcmp(uevent->subsystem, "firmware"))
@@ -636,10 +766,6 @@
if (!pid) {
process_firmware_event(uevent);
exit(EXIT_SUCCESS);
- } else {
- do {
- ret = waitpid(pid, &status, 0);
- } while (ret == -1 && errno == EINTR);
}
}
@@ -648,7 +774,7 @@
{
char msg[UEVENT_MSG_LEN+2];
int n;
- while ((n = uevent_checked_recv(device_fd, msg, UEVENT_MSG_LEN)) > 0) {
+ while ((n = uevent_kernel_multicast_recv(device_fd, msg, UEVENT_MSG_LEN)) > 0) {
if(n >= UEVENT_MSG_LEN) /* overflow -- discard */
continue;
diff --git a/init/init.c b/init/init.c
index e13d4b1..1e31cf9 100755
--- a/init/init.c
+++ b/init/init.c
@@ -651,6 +651,10 @@
ERROR("init startup failure\n");
exit(1);
}
+
+ /* signal that we hit this point */
+ unlink("/dev/.booting");
+
return 0;
}
@@ -708,6 +712,9 @@
mount("proc", "/proc", "proc", 0, NULL);
mount("sysfs", "/sys", "sysfs", 0, NULL);
+ /* indicate that booting is in progress to background fw loaders, etc */
+ close(open("/dev/.booting", O_WRONLY | O_CREAT, 0000));
+
/* We must have some place other than / to create the
* device nodes for kmsg and null, otherwise we won't
* be able to remount / read-only later on.
diff --git a/init/init_parser.c b/init/init_parser.c
index e8e65ac..d9d3084 100644
--- a/init/init_parser.c
+++ b/init/init_parser.c
@@ -179,6 +179,14 @@
return;
}
break;
+ case K_import:
+ if (nargs != 2) {
+ ERROR("single argument needed for import\n");
+ } else {
+ int ret = init_parse_config_file(args[1]);
+ if (ret)
+ ERROR("could not import file %s\n", args[1]);
+ }
}
state->parse_line = parse_line_no_op;
}
@@ -347,7 +355,8 @@
if (!strncmp(name, test, name_length) &&
test[name_length] == '=' &&
- !strcmp(test + name_length + 1, value)) {
+ (!strcmp(test + name_length + 1, value) ||
+ !strcmp(test + name_length + 1, "*"))) {
action_add_queue_tail(act);
}
}
@@ -377,7 +386,8 @@
/* does the property exist, and match the trigger value? */
value = property_get(prop_name);
- if (value && !strcmp(equals + 1, value)) {
+ if (value && (!strcmp(equals + 1, value) ||
+ !strcmp(equals + 1, "*"))) {
action_add_queue_tail(act);
}
}
diff --git a/init/keywords.h b/init/keywords.h
index 95acd01..3e3733f 100644
--- a/init/keywords.h
+++ b/init/keywords.h
@@ -11,7 +11,6 @@
int do_hostname(int nargs, char **args);
int do_ifup(int nargs, char **args);
int do_insmod(int nargs, char **args);
-int do_import(int nargs, char **args);
int do_mkdir(int nargs, char **args);
int do_mount(int nargs, char **args);
int do_restart(int nargs, char **args);
@@ -54,7 +53,7 @@
KEYWORD(hostname, COMMAND, 1, do_hostname)
KEYWORD(ifup, COMMAND, 1, do_ifup)
KEYWORD(insmod, COMMAND, 1, do_insmod)
- KEYWORD(import, COMMAND, 1, do_import)
+ KEYWORD(import, SECTION, 1, 0)
KEYWORD(keycodes, OPTION, 0, 0)
KEYWORD(mkdir, COMMAND, 1, do_mkdir)
KEYWORD(mount, COMMAND, 3, do_mount)
diff --git a/init/property_service.c b/init/property_service.c
index c8d6c09..046b120 100644
--- a/init/property_service.c
+++ b/init/property_service.c
@@ -75,8 +75,6 @@
{ "wlan.", AID_SYSTEM, 0 },
{ "dhcp.", AID_SYSTEM, 0 },
{ "dhcp.", AID_DHCP, 0 },
- { "vpn.", AID_SYSTEM, 0 },
- { "vpn.", AID_VPN, 0 },
{ "debug.", AID_SHELL, 0 },
{ "log.", AID_SHELL, 0 },
{ "service.adb.root", AID_SHELL, 0 },
@@ -374,11 +372,11 @@
return;
}
- r = recv(s, &msg, sizeof(msg), 0);
+ r = TEMP_FAILURE_RETRY(recv(s, &msg, sizeof(msg), 0));
if(r != sizeof(prop_msg)) {
+ ERROR("sys_prop: mis-match msg size recieved: %d expected: %d errno: %d\n",
+ r, sizeof(prop_msg), errno);
close(s);
- ERROR("sys_prop: mis-match msg size recieved: %d expected: %d\n",
- r, sizeof(prop_msg));
return;
}
diff --git a/init/ueventd.c b/init/ueventd.c
index 0e97be7..1328d19 100644
--- a/init/ueventd.c
+++ b/init/ueventd.c
@@ -20,6 +20,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
+#include <signal.h>
+
#include <private/android_filesystem_config.h>
#include "ueventd.h"
@@ -37,6 +39,13 @@
int nr;
char tmp[32];
+ /* Prevent fire-and-forget children from becoming zombies.
+ * If we should need to wait() for some children in the future
+ * (as opposed to none right now), double-forking here instead
+ * of ignoring SIGCHLD may be the better solution.
+ */
+ signal(SIGCHLD, SIG_IGN);
+
open_devnull_stdio();
log_init();
diff --git a/libcutils/Android.mk b/libcutils/Android.mk
index 5f38bf6..0c4e235 100644
--- a/libcutils/Android.mk
+++ b/libcutils/Android.mk
@@ -35,6 +35,7 @@
socket_loopback_client.c \
socket_loopback_server.c \
socket_network_client.c \
+ sockets.c \
config_utils.c \
cpu_info.c \
load_file.c \
@@ -92,25 +93,11 @@
include $(BUILD_HOST_STATIC_LIBRARY)
-ifeq ($(TARGET_SIMULATOR),true)
-
-# Shared library for simulator
-# ========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := libcutils
-LOCAL_SRC_FILES := $(commonSources) $(commonHostSources) memory.c dlmalloc_stubs.c
-LOCAL_LDLIBS := -lpthread
-LOCAL_SHARED_LIBRARIES := liblog
-LOCAL_CFLAGS += $(targetSmpFlag)
-include $(BUILD_SHARED_LIBRARY)
-
-else #!sim
-
# Shared and static library for target
# ========================================================
include $(CLEAR_VARS)
LOCAL_MODULE := libcutils
-LOCAL_SRC_FILES := $(commonSources) ashmem-dev.c mq.c android_reboot.c uevent.c
+LOCAL_SRC_FILES := $(commonSources) ashmem-dev.c mq.c android_reboot.c partition_utils.c uevent.c qtaguid.c
ifeq ($(TARGET_ARCH),arm)
LOCAL_SRC_FILES += arch-arm/memset32.S
@@ -139,4 +126,10 @@
LOCAL_CFLAGS += $(targetSmpFlag)
include $(BUILD_SHARED_LIBRARY)
-endif #!sim
+include $(CLEAR_VARS)
+LOCAL_MODULE := tst_str_parms
+LOCAL_CFLAGS += -DTEST_STR_PARMS
+LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c
+LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_EXECUTABLE)
diff --git a/libcutils/config_utils.c b/libcutils/config_utils.c
index 75fa6c6..fc5ca78 100644
--- a/libcutils/config_utils.c
+++ b/libcutils/config_utils.c
@@ -315,3 +315,15 @@
data = load_file(fn, 0);
config_load(root, data);
}
+
+void config_free(cnode *root)
+{
+ cnode *cur = root->first_child;
+
+ while (cur) {
+ cnode *prev = cur;
+ config_free(cur);
+ cur = cur->next;
+ free(prev);
+ }
+}
diff --git a/libcutils/hashmap.c b/libcutils/hashmap.c
index e29bc24..65539ea 100644
--- a/libcutils/hashmap.c
+++ b/libcutils/hashmap.c
@@ -310,10 +310,11 @@
for (i = 0; i < map->bucketCount; i++) {
Entry* entry = map->buckets[i];
while (entry != NULL) {
+ Entry *next = entry->next;
if (!callback(entry->key, entry->value, context)) {
return;
}
- entry = entry->next;
+ entry = next;
}
}
}
diff --git a/libcutils/partition_utils.c b/libcutils/partition_utils.c
new file mode 100644
index 0000000..10539fa
--- /dev/null
+++ b/libcutils/partition_utils.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h> /* for BLKGETSIZE */
+#include <cutils/properties.h>
+
+static int only_one_char(char *buf, int len, char c)
+{
+ int i, ret;
+
+ ret = 1;
+ for (i=0; i<len; i++) {
+ if (buf[i] != c) {
+ ret = 0;
+ break;
+ }
+ }
+ return ret;
+}
+
+int partition_wiped(char *source)
+{
+ char buf[4096];
+ int fd, ret, wiped;
+
+ if ((fd = open(source, O_RDONLY)) < 0) {
+ return 0;
+ }
+
+ ret = read(fd, buf, sizeof(buf));
+ close(fd);
+
+ if (ret != sizeof(buf)) {
+ return 0;
+ }
+
+ /* Check for all zeros */
+ if (only_one_char(buf, sizeof(buf), 0)) {
+ return 1;
+ }
+
+ /* Check for all ones */
+ if (only_one_char(buf, sizeof(buf), 0xff)) {
+ return 1;
+ }
+
+ return 0;
+}
+
diff --git a/libcutils/qtaguid.c b/libcutils/qtaguid.c
new file mode 100644
index 0000000..517e784
--- /dev/null
+++ b/libcutils/qtaguid.c
@@ -0,0 +1,44 @@
+/* libcutils/qtaguid.c
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#define LOG_TAG "qtaguid"
+
+#include <cutils/qtaguid.h>
+#include <cutils/log.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+extern int set_qtaguid(int sockfd, int tag, uid_t uid) {
+ char lineBuf[128];
+ int fd, cnt = 0;
+ uint64_t kTag = (uint64_t)tag << 32;
+ snprintf(lineBuf, sizeof(lineBuf), "t %d %llu %d", sockfd, kTag, uid);
+
+ LOGV("Tagging Socket with command %s\n", lineBuf);
+ /* TODO: Enable after the kernel module is fixed.
+ fd = open("/proc/net/xt_qtaguid/ctrl", O_WRONLY);
+ if (fd < 0) {
+ return -1;
+ }
+
+ cnt = write(fd, lineBuf, strlen(lineBuf));
+ close(fd);
+ */
+ return (cnt>0?0:-1);
+}
diff --git a/libcutils/sockets.c b/libcutils/sockets.c
new file mode 100644
index 0000000..101a382
--- /dev/null
+++ b/libcutils/sockets.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <cutils/log.h>
+#include <cutils/sockets.h>
+
+#ifdef HAVE_ANDROID_OS
+/* For the socket trust (credentials) check */
+#include <private/android_filesystem_config.h>
+#endif
+
+bool socket_peer_is_trusted(int fd)
+{
+#ifdef HAVE_ANDROID_OS
+ struct ucred cr;
+ socklen_t len = sizeof(cr);
+ int n = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &len);
+
+ if (n != 0) {
+ LOGE("could not get socket credentials: %s\n", strerror(errno));
+ return false;
+ }
+
+ if ((cr.uid != AID_ROOT) && (cr.uid != AID_SHELL)) {
+ LOGE("untrusted userid on other end of socket: userid %d\n", cr.uid);
+ return false;
+ }
+#endif
+
+ return true;
+}
diff --git a/libcutils/uevent.c b/libcutils/uevent.c
index 3533c00..320f8d1 100644
--- a/libcutils/uevent.c
+++ b/libcutils/uevent.c
@@ -24,7 +24,7 @@
/**
* Like recv(), but checks that messages actually originate from the kernel.
*/
-ssize_t uevent_checked_recv(int socket, void *buffer, size_t length) {
+ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length) {
struct iovec iov = { buffer, length };
struct sockaddr_nl addr;
char control[CMSG_SPACE(sizeof(struct ucred))];
diff --git a/libdiskconfig/Android.mk b/libdiskconfig/Android.mk
index c887955..74be2d9 100644
--- a/libdiskconfig/Android.mk
+++ b/libdiskconfig/Android.mk
@@ -1,8 +1,6 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
-ifneq ($(TARGET_SIMULATOR),true)
-
commonSources := \
diskconfig.c \
diskutils.c \
@@ -23,5 +21,3 @@
LOCAL_CFLAGS := -O2 -g -W -Wall -Werror -D_LARGEFILE64_SOURCE
include $(BUILD_HOST_STATIC_LIBRARY)
endif # HOST_OS == linux
-
-endif # ! TARGET_SIMULATOR
diff --git a/liblog/Android.mk b/liblog/Android.mk
index 0eec87f..bd4fed4 100644
--- a/liblog/Android.mk
+++ b/liblog/Android.mk
@@ -48,25 +48,14 @@
LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1
include $(BUILD_HOST_STATIC_LIBRARY)
-ifeq ($(TARGET_SIMULATOR),true)
- # Shared library for simulator
- # ========================================================
- include $(CLEAR_VARS)
- LOCAL_MODULE := liblog
- LOCAL_SRC_FILES := $(liblog_host_sources)
- LOCAL_LDLIBS := -lpthread
- LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1
- include $(BUILD_SHARED_LIBRARY)
-else # !sim
- # Shared and static library for target
- # ========================================================
- include $(CLEAR_VARS)
- LOCAL_MODULE := liblog
- LOCAL_SRC_FILES := $(liblog_sources)
- include $(BUILD_STATIC_LIBRARY)
+# Shared and static library for target
+# ========================================================
+include $(CLEAR_VARS)
+LOCAL_MODULE := liblog
+LOCAL_SRC_FILES := $(liblog_sources)
+include $(BUILD_STATIC_LIBRARY)
- include $(CLEAR_VARS)
- LOCAL_MODULE := liblog
- LOCAL_WHOLE_STATIC_LIBRARIES := liblog
- include $(BUILD_SHARED_LIBRARY)
-endif # !sim
+include $(CLEAR_VARS)
+LOCAL_MODULE := liblog
+LOCAL_WHOLE_STATIC_LIBRARIES := liblog
+include $(BUILD_SHARED_LIBRARY)
diff --git a/libnetutils/Android.mk b/libnetutils/Android.mk
index 46102d5..1ef7da9 100644
--- a/libnetutils/Android.mk
+++ b/libnetutils/Android.mk
@@ -11,13 +11,6 @@
LOCAL_SHARED_LIBRARIES := \
libcutils
-# need "-lrt" on Linux simulator to pick up clock_gettime
-ifeq ($(TARGET_SIMULATOR),true)
- ifeq ($(HOST_OS),linux)
- LOCAL_LDLIBS += -lrt -lpthread
- endif
-endif
-
LOCAL_MODULE:= libnetutils
include $(BUILD_SHARED_LIBRARY)
diff --git a/libnetutils/dhcp_utils.c b/libnetutils/dhcp_utils.c
index 8496725..5991ea8 100644
--- a/libnetutils/dhcp_utils.c
+++ b/libnetutils/dhcp_utils.c
@@ -265,15 +265,16 @@
}
/**
- * DHCP renewal request
+ * Run WiMAX dhcp renew service.
+ * "wimax_renew" service shoud be included in init.rc.
*/
int dhcp_do_request_renew(const char *interface,
- char *ipaddr,
- char *gateway,
- uint32_t *prefixLength,
- char *dns1,
- char *dns2,
- char *server,
+ in_addr_t *ipaddr,
+ in_addr_t *gateway,
+ in_addr_t *mask,
+ in_addr_t *dns1,
+ in_addr_t *dns2,
+ in_addr_t *server,
uint32_t *lease)
{
char result_prop_name[PROPERTY_KEY_MAX];
@@ -305,10 +306,7 @@
return -1;
}
if (strcmp(prop_value, "ok") == 0) {
- if(fill_ip_info(interface, ipaddr, gateway, prefixLength, dns1, dns2, server, lease)
- == -1) {
- return -1;
- }
+ fill_ip_info(interface, ipaddr, gateway, mask, dns1, dns2, server, lease);
return 0;
} else {
snprintf(errmsg, sizeof(errmsg), "DHCP Renew result was %s", prop_value);
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c
index c9d6ed2..04b0dfa 100644
--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -51,6 +51,8 @@
static int ifc_ctl_sock6 = -1;
void printerr(char *fmt, ...);
+#define DBG 0
+
in_addr_t prefixLengthToIpv4Netmask(int prefix_length)
{
in_addr_t mask = 0;
@@ -88,13 +90,17 @@
int ifc_init(void)
{
+ int ret;
if (ifc_ctl_sock == -1) {
- ifc_ctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
+ ifc_ctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
if (ifc_ctl_sock < 0) {
printerr("socket() failed: %s\n", strerror(errno));
}
}
- return ifc_ctl_sock < 0 ? -1 : 0;
+
+ ret = ifc_ctl_sock < 0 ? -1 : 0;
+ if (DBG) printerr("ifc_init_returning %d", ret);
+ return ret;
}
int ifc_init6(void)
@@ -110,6 +116,7 @@
void ifc_close(void)
{
+ if (DBG) printerr("ifc_close");
if (ifc_ctl_sock != -1) {
(void)close(ifc_ctl_sock);
ifc_ctl_sock = -1;
@@ -141,7 +148,7 @@
if(r < 0) return -1;
memcpy(ptr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
- return 0;
+ return 0;
}
int ifc_get_ifindex(const char *name, int *if_indexp)
@@ -169,12 +176,16 @@
int ifc_up(const char *name)
{
- return ifc_set_flags(name, IFF_UP, 0);
+ int ret = ifc_set_flags(name, IFF_UP, 0);
+ if (DBG) printerr("ifc_up(%s) = %d", name, ret);
+ return ret;
}
int ifc_down(const char *name)
{
- return ifc_set_flags(name, 0, IFF_UP);
+ int ret = ifc_set_flags(name, 0, IFF_UP);
+ if (DBG) printerr("ifc_down(%s) = %d", name, ret);
+ return ret;
}
static void init_sockaddr_in(struct sockaddr *sa, in_addr_t addr)
@@ -188,11 +199,14 @@
int ifc_set_addr(const char *name, in_addr_t addr)
{
struct ifreq ifr;
+ int ret;
ifc_init_ifr(name, &ifr);
init_sockaddr_in(&ifr.ifr_addr, addr);
- return ioctl(ifc_ctl_sock, SIOCSIFADDR, &ifr);
+ ret = ioctl(ifc_ctl_sock, SIOCSIFADDR, &ifr);
+ if (DBG) printerr("ifc_set_addr(%s, xx) = %d", name, ret);
+ return ret;
}
int ifc_set_hwaddr(const char *name, const void *ptr)
@@ -206,6 +220,19 @@
return ioctl(ifc_ctl_sock, SIOCSIFHWADDR, &ifr);
}
+int ifc_set_mask(const char *name, in_addr_t mask)
+{
+ struct ifreq ifr;
+ int ret;
+
+ ifc_init_ifr(name, &ifr);
+ init_sockaddr_in(&ifr.ifr_addr, mask);
+
+ ret = ioctl(ifc_ctl_sock, SIOCSIFNETMASK, &ifr);
+ if (DBG) printerr("ifc_set_mask(%s, xx) = %d", name, ret);
+ return ret;
+}
+
int ifc_set_prefixLength(const char *name, int prefixLength)
{
struct ifreq ifr;
@@ -313,6 +340,7 @@
return result;
}
+/* deprecated - v4 only */
int ifc_create_default_route(const char *name, in_addr_t gw)
{
struct in_addr in_dst, in_gw;
@@ -320,7 +348,20 @@
in_dst.s_addr = 0;
in_gw.s_addr = gw;
- return ifc_act_on_route(SIOCADDRT, name, in_dst, 0, in_gw);
+ int ret = ifc_act_on_ipv4_route(SIOCADDRT, name, in_dst, 0, in_gw);
+ if (DBG) printerr("ifc_create_default_route(%s, %d) = %d", name, gw, ret);
+ return ret;
+}
+
+/* deprecated v4-only */
+int ifc_add_host_route(const char *name, in_addr_t dst)
+{
+ struct in_addr in_dst, in_gw;
+
+ in_dst.s_addr = dst;
+ in_gw.s_addr = 0;
+
+ return ifc_act_on_ipv4_route(SIOCADDRT, name, in_dst, 32, in_gw);
}
int ifc_enable(const char *ifname)
@@ -449,6 +490,70 @@
}
/*
+ * Return the address of the default gateway
+ *
+ * TODO: factor out common code from this and remove_host_routes()
+ * so that we only scan /proc/net/route in one place.
+ *
+ * DEPRECATED
+ */
+int ifc_get_default_route(const char *ifname)
+{
+ char name[64];
+ in_addr_t dest, gway, mask;
+ int flags, refcnt, use, metric, mtu, win, irtt;
+ int result;
+ FILE *fp;
+
+ fp = fopen("/proc/net/route", "r");
+ if (fp == NULL)
+ return 0;
+ /* Skip the header line */
+ if (fscanf(fp, "%*[^\n]\n") < 0) {
+ fclose(fp);
+ return 0;
+ }
+ ifc_init();
+ result = 0;
+ for (;;) {
+ int nread = fscanf(fp, "%63s%X%X%X%d%d%d%X%d%d%d\n",
+ name, &dest, &gway, &flags, &refcnt, &use, &metric, &mask,
+ &mtu, &win, &irtt);
+ if (nread != 11) {
+ break;
+ }
+ if ((flags & (RTF_UP|RTF_GATEWAY)) == (RTF_UP|RTF_GATEWAY)
+ && dest == 0
+ && strcmp(ifname, name) == 0) {
+ result = gway;
+ break;
+ }
+ }
+ fclose(fp);
+ ifc_close();
+ return result;
+}
+
+/*
+ * Sets the specified gateway as the default route for the named interface.
+ * DEPRECATED
+ */
+int ifc_set_default_route(const char *ifname, in_addr_t gateway)
+{
+ struct in_addr addr;
+ int result;
+
+ ifc_init();
+ addr.s_addr = gateway;
+ if ((result = ifc_create_default_route(ifname, gateway)) < 0) {
+ LOGD("failed to add %s as default route for %s: %s",
+ inet_ntoa(addr), ifname, strerror(errno));
+ }
+ ifc_close();
+ return result;
+}
+
+/*
* Removes the default route for the named interface.
*/
int ifc_remove_default_route(const char *ifname)
@@ -627,9 +732,31 @@
return ret;
}
+/*
+ * DEPRECATED
+ */
+int ifc_add_ipv4_route(const char *ifname, struct in_addr dst, int prefix_length,
+ struct in_addr gw)
+{
+ int i =ifc_act_on_ipv4_route(SIOCADDRT, ifname, dst, prefix_length, gw);
+ printerr("ifc_add_ipv4_route(%s, xx, %d, xx) = %d", ifname, prefix_length, i);
+ return i;
+}
+
+/*
+ * DEPRECATED
+ */
+int ifc_add_ipv6_route(const char *ifname, struct in6_addr dst, int prefix_length,
+ struct in6_addr gw)
+{
+ return ifc_act_on_ipv6_route(SIOCADDRT, ifname, dst, prefix_length, gw);
+}
+
int ifc_add_route(const char *ifname, const char *dst, int prefix_length, const char *gw)
{
- return ifc_act_on_route(SIOCADDRT, ifname, dst, prefix_length, gw);
+ int i = ifc_act_on_route(SIOCADDRT, ifname, dst, prefix_length, gw);
+ printerr("ifc_add_route(%s, %s, %d, %s) = %d", ifname, dst, prefix_length, gw, i);
+ return i;
}
int ifc_remove_route(const char *ifname, const char*dst, int prefix_length, const char *gw)
diff --git a/libnl_2/.gitignore b/libnl_2/.gitignore
new file mode 100644
index 0000000..d4ca744
--- /dev/null
+++ b/libnl_2/.gitignore
@@ -0,0 +1,2 @@
+include/netlink/version.h.in
+cscope.*
diff --git a/libnl_2/Android.mk b/libnl_2/Android.mk
new file mode 100644
index 0000000..800c2b2
--- /dev/null
+++ b/libnl_2/Android.mk
@@ -0,0 +1,29 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ attr.c \
+ cache.c \
+ genl/genl.c \
+ genl/family.c \
+ handlers.c \
+ msg.c \
+ netlink.c \
+ object.c \
+ socket.c
+
+LOCAL_C_INCLUDES += \
+ $(LOCAL_PATH)/include
+
+# Static Library
+LOCAL_MODULE := libnl_2
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_STATIC_LIBRARY)
+
+#######################################
+# Shared library currently unavailiable
+# * Netlink cache not implemented
+# * Library is not thread safe
+#######################################
+
diff --git a/libnl_2/README b/libnl_2/README
new file mode 100644
index 0000000..0e80718
--- /dev/null
+++ b/libnl_2/README
@@ -0,0 +1,35 @@
+Netlink Protocol Format (RFC3549)
++-----------------+-+-------------------+-+
+|Netlink Message |P| Generic Netlink |P|
+| Header |A| Message Header |A|
+|(struct nlmsghdr)|D|(struct genlmsghdr)|D|
++-----------------+-+-------------------+-+
++-----------------+-+-----------------+-+-----------------+-+-----------------+-+---+
+|Netlink Attribute|P|Netlink Attribute|P|Netlink Attribute|P|Netlink Attribute|P|...|
+| #0 Header |A| #0 Payload |A| #1 Header |A| #1 Payload |A| |
+| (struct nlattr) |D| (void) |D| (struct nlattr) |D| (void) |D| |
++-----------------+-+-----------------+-+-----------------+-+-----------------+-+---+
+
+* Each netlink message consists of a bitstream with a netlink header.
+* After this header a second header *can* be used specific to the netlink
+ family in use. This library was tested using the generic netlink
+ protocol defined by struct genlmsghdr to support nl80211.
+* After the header(s) netlink attributes can be appended to the message
+ which hold can hold basic types such as unsigned integers and strings.
+* All data structures in this implementation are byte-aligned (Currently 4 bytes).
+* Acknowledgements (ACKs) are sent as NLMSG_ERROR netlink message types (0x2) and
+ have an error value of 0.
+
+KNOWN BUGS
+* NOT THREAD SAFE!!!
+* nla_parse - does not use nla_policy argument
+* nl_recvmsgs - does not support nl_cb_overwrite_recv()
+* nl_recv - sets/unsets async. flag
+* genl_ctrl_alloc_cache - netlink send/recv funcs should be used
+
+REFERENCES
+* nl80211.h
+* netlink_types.h
+* $LINUX_KERNEL/net/wireless/nl80211.c
+* http://www.infradead.org/~tgr/libnl/doc-3.0/index.html
+* http://www.netfilter.org/projects/libmnl/doxygen/index.html
diff --git a/libnl_2/attr.c b/libnl_2/attr.c
new file mode 100644
index 0000000..9467668
--- /dev/null
+++ b/libnl_2/attr.c
@@ -0,0 +1,228 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* NOTICE: This is a clean room re-implementation of libnl */
+
+#include <errno.h>
+#include "netlink/netlink.h"
+#include "netlink/msg.h"
+#include "netlink/attr.h"
+#include "netlink-types.h"
+
+/* Return payload of string attribute. */
+char *nla_get_string(struct nlattr *nla)
+{
+ return (char *) nla_data(nla);
+}
+
+/* Return payload of 16 bit integer attribute. */
+uint16_t nla_get_u16(struct nlattr *nla)
+{
+ return *((uint16_t *) nla_data(nla));
+}
+
+/* Return payload of 32 bit integer attribute. */
+uint32_t nla_get_u32(struct nlattr *nla)
+{
+ return *((uint32_t *) nla_data(nla));
+}
+
+/* Return value of 8 bit integer attribute. */
+uint8_t nla_get_u8(struct nlattr *nla)
+{
+ return *((uint8_t *) nla_data(nla));
+}
+
+/* Return payload of uint64_t attribute. */
+uint64_t nla_get_u64(struct nlattr *nla)
+{
+ uint64_t tmp;
+ nla_memcpy(&tmp, nla, sizeof(tmp));
+ return tmp;
+}
+
+/* Head of payload */
+void *nla_data(const struct nlattr *nla)
+{
+ return (void *) ((char *) nla + NLA_HDRLEN);
+}
+
+/* Return length of the payload . */
+int nla_len(const struct nlattr *nla)
+{
+ return nla->nla_len - NLA_HDRLEN;
+}
+
+/* Start a new level of nested attributes. */
+struct nlattr *nla_nest_start(struct nl_msg *msg, int attrtype)
+{
+ if (!nla_put(msg, attrtype, 0, NULL)) {
+ /* Get ref to last (nested start) attr */
+ int padding;
+ struct nlattr *nla;
+
+ padding = nlmsg_padlen(nlmsg_datalen(nlmsg_hdr(msg)));
+ nla = (struct nlattr *) \
+ ((char *) nlmsg_tail(msg->nm_nlh) - padding);
+ return nla;
+
+ } else
+ return NULL;
+
+}
+
+/* Finalize nesting of attributes. */
+int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
+{
+ start->nla_len = (unsigned char *) \
+ nlmsg_tail(nlmsg_hdr(msg)) - (unsigned char *)start;
+ return 0;
+}
+
+/* Return next attribute in a stream of attributes. */
+struct nlattr *nla_next(const struct nlattr *nla, int *remaining)
+{
+ struct nlattr *next_nla = NULL;
+ if (nla->nla_len >= sizeof(struct nlattr) &&
+ nla->nla_len <= *remaining){
+ next_nla = (struct nlattr *) \
+ ((char *) nla + NLA_ALIGN(nla->nla_len));
+ *remaining = *remaining - NLA_ALIGN(nla->nla_len);
+ }
+
+ return next_nla;
+
+}
+
+/* Check if the attribute header and payload can be accessed safely. */
+int nla_ok(const struct nlattr *nla, int remaining)
+{
+ return remaining > 0 &&
+ nla->nla_len >= sizeof(struct nlattr) &&
+ sizeof(struct nlattr) <= (unsigned int) remaining &&
+ nla->nla_len <= remaining;
+}
+
+/* Create attribute index based on a stream of attributes. */
+/* NOTE: Policy not used ! */
+int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head,
+ int len, struct nla_policy *policy)
+{
+ struct nlattr *pos;
+ int rem;
+
+ /* First clear table */
+ memset(tb, 0, (maxtype+1) * sizeof(struct nlattr *));
+
+ nla_for_each_attr(pos, head, len, rem) {
+ const int type = nla_type(pos);
+
+ if (type <= maxtype)
+ tb[type] = pos;
+
+ }
+
+ return 0;
+}
+
+
+/* Create attribute index based on nested attribute. */
+int nla_parse_nested(struct nlattr *tb[], int maxtype,
+ struct nlattr *nla, struct nla_policy *policy)
+{
+ return nla_parse(tb, maxtype, nla_data(nla), nla_len(nla), policy);
+}
+
+
+/* Add a unspecific attribute to netlink message. */
+int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data)
+{
+ struct nlattr *nla;
+
+ /* Reserve space and init nla header */
+ nla = nla_reserve(msg, attrtype, datalen);
+ if (nla) {
+ memcpy(nla_data(nla), data, datalen);
+ return 0;
+ }
+
+ return -EINVAL;
+
+}
+
+
+/* Add nested attributes to netlink message. */
+/* Takes the attributes found in the nested message and appends them
+ * to the message msg nested in a container of the type attrtype. The
+ * nested message may not have a family specific header */
+int nla_put_nested(struct nl_msg *msg, int attrtype, struct nl_msg *nested)
+{
+ int rc = -1;
+ const int NO_HEADER = 0;
+
+ rc = nla_put(
+ msg,
+ attrtype,
+ nlmsg_attrlen(nlmsg_hdr(nested), NO_HEADER),
+ (const void *) nlmsg_attrdata(nlmsg_hdr(nested), NO_HEADER)
+ );
+ return rc;
+
+}
+
+/* Return type of the attribute. */
+int nla_type(const struct nlattr *nla)
+{
+ return (int) nla->nla_type;
+}
+
+/* Reserves room for an attribute in specified netlink message and fills
+ * in the attribute header (type,length). Return NULL if insufficient space */
+struct nlattr *nla_reserve(struct nl_msg * msg, int attrtype, int data_len)
+{
+
+ struct nlattr *nla;
+ const unsigned int NEW_SIZE = \
+ msg->nm_nlh->nlmsg_len + NLA_ALIGN(NLA_HDRLEN + data_len);
+
+ /* Check enough space for attribute */
+ if (NEW_SIZE <= msg->nm_size) {
+ const int fam_hdrlen = msg->nm_nlh->nlmsg_len - NLMSG_HDRLEN;
+ msg->nm_nlh->nlmsg_len = NEW_SIZE;
+ nla = nlmsg_attrdata(msg->nm_nlh, fam_hdrlen);
+ nla->nla_type = attrtype;
+ nla->nla_len = NLA_HDRLEN + data_len;
+ } else
+ goto fail;
+
+ return nla;
+fail:
+ return NULL;
+
+}
+
+/* Copy attribute payload to another memory area. */
+int nla_memcpy(void *dest, struct nlattr *src, int count)
+{
+ int rc;
+ void *ret_dest = memcpy(dest, nla_data(src), count);
+ if (!ret_dest)
+ return count;
+ else
+ return 0;
+}
+
+
diff --git a/libnl_2/cache.c b/libnl_2/cache.c
new file mode 100644
index 0000000..c21974d
--- /dev/null
+++ b/libnl_2/cache.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* NOTICE: This is a clean room re-implementation of libnl */
+
+#include "netlink/cache.h"
+#include "netlink/object.h"
+
+void nl_cache_free(struct nl_cache *cache)
+{
+
+}
+
+void nl_cache_clear(struct nl_cache *cache)
+{
+
+}
+
+void nl_cache_remove(struct nl_object *obj)
+{
+
+}
+
+
diff --git a/libnl_2/genl/family.c b/libnl_2/genl/family.c
new file mode 100644
index 0000000..1beee6e
--- /dev/null
+++ b/libnl_2/genl/family.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* NOTICE: This is a clean room re-implementation of libnl */
+
+#include "netlink-types.h"
+
+static struct genl_family *genl_family_find_byname(const char *name)
+{
+ return NULL;
+}
+
+/* Release reference and none outstanding */
+void genl_family_put(struct genl_family *family)
+{
+ family->ce_refcnt--;
+ if (family->ce_refcnt <= 0)
+ free(family);
+}
+
+unsigned int genl_family_get_id(struct genl_family *family)
+{
+ const int NO_FAMILY_ID = 0;
+
+ if (!family)
+ return NO_FAMILY_ID;
+ else
+ return family->gf_id;
+
+}
+
diff --git a/libnl_2/genl/genl.c b/libnl_2/genl/genl.c
new file mode 100644
index 0000000..dd20717
--- /dev/null
+++ b/libnl_2/genl/genl.c
@@ -0,0 +1,283 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* NOTICE: This is a clean room re-implementation of libnl */
+
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <linux/netlink.h>
+#include "netlink-types.h"
+
+/* Get head of attribute data. */
+struct nlattr *genlmsg_attrdata(const struct genlmsghdr *gnlh, int hdrlen)
+{
+ return (struct nlattr *) \
+ ((char *) gnlh + GENL_HDRLEN + NLMSG_ALIGN(hdrlen));
+
+}
+
+/* Get length of attribute data. */
+int genlmsg_attrlen(const struct genlmsghdr *gnlh, int hdrlen)
+{
+ struct nlattr *nla;
+ struct nlmsghdr *nlh;
+
+ nla = genlmsg_attrdata(gnlh, hdrlen);
+ nlh = (struct nlmsghdr *) ((char *) gnlh - NLMSG_HDRLEN);
+ return (char *) nlmsg_tail(nlh) - (char *) nla;
+}
+
+/* Add generic netlink header to netlink message. */
+void *genlmsg_put(struct nl_msg *msg, uint32_t pid, uint32_t seq, int family,
+ int hdrlen, int flags, uint8_t cmd, uint8_t version)
+{
+ int new_size;
+ struct nlmsghdr *nlh;
+ struct timeval tv;
+ struct genlmsghdr *gmh;
+
+ /* Make sure nl_msg has enough space */
+ new_size = NLMSG_HDRLEN + GENL_HDRLEN + hdrlen;
+ if ((sizeof(struct nl_msg) + new_size) > msg->nm_size)
+ goto fail;
+
+ /* Fill in netlink header */
+ nlh = msg->nm_nlh;
+ nlh->nlmsg_len = new_size;
+ nlh->nlmsg_type = family;
+ nlh->nlmsg_pid = getpid();
+ nlh->nlmsg_flags = flags | NLM_F_REQUEST | NLM_F_ACK;
+
+ /* Get current time for sequence number */
+ if (gettimeofday(&tv, NULL))
+ nlh->nlmsg_seq = 1;
+ else
+ nlh->nlmsg_seq = (int) tv.tv_sec;
+
+ /* Setup genlmsghdr in new message */
+ gmh = (struct genlmsghdr *) ((char *)nlh + NLMSG_HDRLEN);
+ gmh->cmd = (__u8) cmd;
+ gmh->version = version;
+
+ return gmh;
+fail:
+ return NULL;
+
+}
+
+/* Socket has already been alloced to connect it to kernel? */
+int genl_connect(struct nl_sock *sk)
+{
+ return nl_connect(sk, NETLINK_GENERIC);
+
+}
+
+int genl_ctrl_alloc_cache(struct nl_sock *sock, struct nl_cache **result)
+{
+ int rc = -1;
+ int nl80211_genl_id = -1;
+ char sendbuf[sizeof(struct nlmsghdr)+sizeof(struct genlmsghdr)];
+ struct nlmsghdr nlmhdr;
+ struct genlmsghdr gmhhdr;
+ struct iovec sendmsg_iov;
+ struct msghdr msg;
+ int num_char;
+ const int RECV_BUF_SIZE = getpagesize();
+ char *recvbuf;
+ struct iovec recvmsg_iov;
+ int nl80211_flag = 0, nlm_f_multi = 0, nlmsg_done = 0;
+ struct nlmsghdr *nlh;
+
+ /* REQUEST GENERIC NETLINK FAMILY ID */
+ /* Message buffer */
+ nlmhdr.nlmsg_len = sizeof(sendbuf);
+ nlmhdr.nlmsg_type = NETLINK_GENERIC;
+ nlmhdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP;
+ nlmhdr.nlmsg_seq = sock->s_seq_next;
+ nlmhdr.nlmsg_pid = sock->s_local.nl_pid;
+
+ /* Generic netlink header */
+ gmhhdr.cmd = CTRL_CMD_GETFAMILY;
+ gmhhdr.version = CTRL_ATTR_FAMILY_ID;
+
+ /* Combine netlink and generic netlink headers */
+ memcpy(&sendbuf[0], &nlmhdr, sizeof(nlmhdr));
+ memcpy(&sendbuf[0]+sizeof(nlmhdr), &gmhhdr, sizeof(gmhhdr));
+
+ /* Create IO vector with Netlink message */
+ sendmsg_iov.iov_base = &sendbuf;
+ sendmsg_iov.iov_len = sizeof(sendbuf);
+
+ /* Socket message */
+ msg.msg_name = (void *) &sock->s_peer;
+ msg.msg_namelen = sizeof(sock->s_peer);
+ msg.msg_iov = &sendmsg_iov;
+ msg.msg_iovlen = 1; /* Only sending one iov */
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+ msg.msg_flags = 0;
+
+ /* Send message and verify sent */
+ num_char = sendmsg(sock->s_fd, &msg, 0);
+ if (num_char == -1)
+ return -errno;
+
+ /* RECEIVE GENL CMD RESPONSE */
+
+ /* Create receive iov buffer */
+ recvbuf = (char *) malloc(RECV_BUF_SIZE);
+
+ /* Attach to iov */
+ recvmsg_iov.iov_base = recvbuf;
+ recvmsg_iov.iov_len = RECV_BUF_SIZE;
+
+ msg.msg_iov = &recvmsg_iov;
+ msg.msg_iovlen = 1;
+
+ /***************************************************************/
+ /* Receive message. If multipart message, keep receiving until */
+ /* message type is NLMSG_DONE */
+ /***************************************************************/
+
+ do {
+
+ int recvmsg_len, nlmsg_rem;
+
+ /* Receive message */
+ memset(recvbuf, 0, RECV_BUF_SIZE);
+ recvmsg_len = recvmsg(sock->s_fd, &msg, 0);
+
+ /* Make sure receive successful */
+ if (recvmsg_len < 0) {
+ rc = -errno;
+ goto error_recvbuf;
+ }
+
+ /* Parse nlmsghdr */
+ nlmsg_for_each_msg(nlh, (struct nlmsghdr *) recvbuf, \
+ recvmsg_len, nlmsg_rem) {
+ struct nlattr *nla;
+ int nla_rem;
+
+ /* Check type */
+ switch (nlh->nlmsg_type) {
+ case NLMSG_DONE:
+ goto return_genl_id;
+ break;
+ case NLMSG_ERROR:
+
+ /* Should check nlmsgerr struct received */
+ fprintf(stderr, "Receive message error\n");
+ goto error_recvbuf;
+ case NLMSG_OVERRUN:
+ fprintf(stderr, "Receive data partly lost\n");
+ goto error_recvbuf;
+ case NLMSG_MIN_TYPE:
+ case NLMSG_NOOP:
+ break;
+ default:
+ break;
+ }
+
+
+
+ /* Check flags */
+ if (nlh->nlmsg_flags & NLM_F_MULTI)
+ nlm_f_multi = 1;
+ else
+ nlm_f_multi = 0;
+
+ if (nlh->nlmsg_type & NLMSG_DONE)
+ nlmsg_done = 1;
+ else
+ nlmsg_done = 0;
+
+ /* Iteratve over attributes */
+ nla_for_each_attr(nla,
+ nlmsg_attrdata(nlh, GENL_HDRLEN),
+ nlmsg_attrlen(nlh, GENL_HDRLEN),
+ nla_rem){
+
+ /* If this family is nl80211 */
+ if (nla->nla_type == CTRL_ATTR_FAMILY_NAME &&
+ !strcmp((char *)nla_data(nla),
+ "nl80211"))
+ nl80211_flag = 1;
+
+ /* Save the family id */
+ else if (nl80211_flag &&
+ nla->nla_type == CTRL_ATTR_FAMILY_ID)
+ nl80211_genl_id = \
+ *((int *)nla_data(nla));
+
+ }
+
+ }
+
+ } while (nlm_f_multi && !nlmsg_done);
+
+return_genl_id:
+ /* Return family id as cache pointer */
+ *result = (struct nl_cache *) nl80211_genl_id;
+ rc = 0;
+error_recvbuf:
+ free(recvbuf);
+error:
+ return rc;
+}
+
+/* Checks the netlink cache to find family reference by name string */
+/* NOTE: Caller needs to call genl_family_put() when done with *
+ * returned object */
+struct genl_family *genl_ctrl_search_by_name(struct nl_cache *cache, \
+ const char *name)
+{
+ /* TODO: When will we release this memory ? */
+ struct genl_family *gf = (struct genl_family *) \
+ malloc(sizeof(struct genl_family));
+ if (!gf)
+ goto fail;
+ memset(gf, 0, sizeof(*gf));
+
+ /* Add ref */
+ gf->ce_refcnt++;
+
+ /* Overriding cache pointer as family id for now */
+ gf->gf_id = (uint16_t) ((uint32_t) cache);
+ strcpy(gf->gf_name, "nl80211");
+
+ return gf;
+fail:
+ return NULL;
+
+}
+
+int genl_ctrl_resolve(struct nl_sock *sk, const char *name)
+{
+ /* Hack to support wpa_supplicant */
+ if (strcmp(name, "nlctrl") == 0)
+ return NETLINK_GENERIC;
+ else {
+ int errsv = errno;
+ fprintf(stderr, \
+ "Only nlctrl supported by genl_ctrl_resolve!\n");
+ return -errsv;
+ }
+
+}
+
diff --git a/libnl_2/handlers.c b/libnl_2/handlers.c
new file mode 100644
index 0000000..ec8d512
--- /dev/null
+++ b/libnl_2/handlers.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* NOTICE: This is a clean room re-implementation of libnl */
+
+#include <malloc.h>
+#include "netlink-types.h"
+#include "netlink/handlers.h"
+
+/* Allocate a new callback handle. */
+struct nl_cb *nl_cb_alloc(enum nl_cb_kind kind)
+{
+ struct nl_cb *cb;
+
+ cb = (struct nl_cb *) malloc(sizeof(struct nl_cb));
+ if (cb == NULL)
+ goto fail;
+ memset(cb, 0, sizeof(*cb));
+
+ return nl_cb_get(cb);
+fail:
+ return NULL;
+}
+
+/* Clone an existing callback handle */
+struct nl_cb *nl_cb_clone(struct nl_cb *orig)
+{
+ struct nl_cb *new_cb;
+ int new_refcnt;
+
+ new_cb = nl_cb_alloc(NL_CB_DEFAULT);
+ if (new_cb == NULL)
+ goto fail;
+
+ /* Preserve reference count and copy original */
+ new_refcnt = new_cb->cb_refcnt;
+ memcpy(new_cb, orig, sizeof(*orig));
+ new_cb->cb_refcnt = new_refcnt;
+
+ return new_cb;
+fail:
+ return NULL;
+}
+
+/* Set up a callback. */
+int nl_cb_set(struct nl_cb *cb, enum nl_cb_type type, enum nl_cb_kind kind, \
+ nl_recvmsg_msg_cb_t func, void *arg)
+{
+ cb->cb_set[type] = func;
+ cb->cb_args[type] = arg;
+ return 0;
+}
+
+
+
+/* Set up an error callback. */
+int nl_cb_err(struct nl_cb *cb, enum nl_cb_kind kind, \
+ nl_recvmsg_err_cb_t func, void *arg)
+{
+ cb->cb_err = func;
+ cb->cb_err_arg = arg;
+ return 0;
+
+}
+
+struct nl_cb *nl_cb_get(struct nl_cb *cb)
+{
+ cb->cb_refcnt++;
+ return cb;
+}
+
+void nl_cb_put(struct nl_cb *cb)
+{
+ cb->cb_refcnt--;
+ if (cb->cb_refcnt <= 0)
+ free(cb);
+
+}
+
diff --git a/libnl_2/include/netlink-generic.h b/libnl_2/include/netlink-generic.h
new file mode 100644
index 0000000..10aa2f0
--- /dev/null
+++ b/libnl_2/include/netlink-generic.h
@@ -0,0 +1,20 @@
+/*
+ * netlink-generic.h Local Generic Netlink Interface
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_GENL_PRIV_H_
+#define NETLINK_GENL_PRIV_H_
+
+#include <netlink-local.h>
+#include <netlink/netlink.h>
+
+#define GENL_HDRSIZE(hdrlen) (GENL_HDRLEN + (hdrlen))
+
+#endif
diff --git a/libnl_2/include/netlink-local.h b/libnl_2/include/netlink-local.h
new file mode 100644
index 0000000..0d8c9ab
--- /dev/null
+++ b/libnl_2/include/netlink-local.h
@@ -0,0 +1,186 @@
+/*
+ * netlink-local.h Local Netlink Interface
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_LOCAL_H_
+#define NETLINK_LOCAL_H_
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <math.h>
+#include <time.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <inttypes.h>
+#include <assert.h>
+#include <limits.h>
+
+#include <arpa/inet.h>
+#include <netdb.h>
+
+#ifndef SOL_NETLINK
+#define SOL_NETLINK 270
+#endif
+
+#include <linux/types.h>
+
+/* local header copies */
+#include <linux/if.h>
+#include <linux/if_arp.h>
+#include <linux/if_ether.h>
+#include <linux/pkt_sched.h>
+#include <linux/pkt_cls.h>
+#include <linux/gen_stats.h>
+#include <linux/ip_mp_alg.h>
+
+#include <netlink/netlink.h>
+#include <netlink/handlers.h>
+#include <netlink/cache.h>
+#include <netlink/route/tc.h>
+#include <netlink/object-api.h>
+#include <netlink/cache-api.h>
+#include <netlink-types.h>
+
+struct trans_tbl {
+ int i;
+ const char *a;
+};
+
+#define __ADD(id, name) { .i = id, .a = #name },
+
+struct trans_list {
+ int i;
+ char *a;
+ struct nl_list_head list;
+};
+
+#define NL_DEBUG 1
+
+#define NL_DBG(LVL,FMT,ARG...) \
+ do { \
+ if (LVL <= nl_debug) \
+ fprintf(stderr, "DBG<" #LVL ">: " FMT, ##ARG); \
+ } while (0)
+
+#define BUG() \
+ do { \
+ fprintf(stderr, "BUG: %s:%d\n", \
+ __FILE__, __LINE__); \
+ assert(0); \
+ } while (0)
+
+extern int __nl_read_num_str_file(const char *path,
+ int (*cb)(long, const char *));
+
+extern int __trans_list_add(int, const char *, struct nl_list_head *);
+extern void __trans_list_clear(struct nl_list_head *);
+
+extern char *__type2str(int, char *, size_t, struct trans_tbl *, size_t);
+extern int __str2type(const char *, struct trans_tbl *, size_t);
+
+extern char *__list_type2str(int, char *, size_t, struct nl_list_head *);
+extern int __list_str2type(const char *, struct nl_list_head *);
+
+extern char *__flags2str(int, char *, size_t, struct trans_tbl *, size_t);
+extern int __str2flags(const char *, struct trans_tbl *, size_t);
+
+extern void dump_from_ops(struct nl_object *, struct nl_dump_params *);
+
+static inline struct nl_cache *dp_cache(struct nl_object *obj)
+{
+ if (obj->ce_cache == NULL)
+ return nl_cache_mngt_require(obj->ce_ops->oo_name);
+
+ return obj->ce_cache;
+}
+
+static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg)
+{
+ return cb->cb_set[type](msg, cb->cb_args[type]);
+}
+
+#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
+#ifndef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
+#define __init __attribute__ ((constructor))
+#define __exit __attribute__ ((destructor))
+#undef __deprecated
+#define __deprecated __attribute__ ((deprecated))
+
+#define min(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x < _y ? _x : _y; })
+
+#define max(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x > _y ? _x : _y; })
+
+#define min_t(type,x,y) \
+ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
+#define max_t(type,x,y) \
+ ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
+
+extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *,
+ struct nlmsghdr *, struct nl_parser_param *);
+
+
+static inline void rtnl_copy_ratespec(struct rtnl_ratespec *dst,
+ struct tc_ratespec *src)
+{
+ dst->rs_cell_log = src->cell_log;
+ dst->rs_feature = src->feature;
+ dst->rs_addend = src->addend;
+ dst->rs_mpu = src->mpu;
+ dst->rs_rate = src->rate;
+}
+
+static inline void rtnl_rcopy_ratespec(struct tc_ratespec *dst,
+ struct rtnl_ratespec *src)
+{
+ dst->cell_log = src->rs_cell_log;
+ dst->feature = src->rs_feature;
+ dst->addend = src->rs_addend;
+ dst->mpu = src->rs_mpu;
+ dst->rate = src->rs_rate;
+}
+
+static inline char *nl_cache_name(struct nl_cache *cache)
+{
+ return cache->c_ops ? cache->c_ops->co_name : "unknown";
+}
+
+#define GENL_FAMILY(id, name) \
+ { \
+ { id, NL_ACT_UNSPEC, name }, \
+ END_OF_MSGTYPES_LIST, \
+ }
+
+static inline int wait_for_ack(struct nl_sock *sk)
+{
+ if (sk->s_flags & NL_NO_AUTO_ACK)
+ return 0;
+ else
+ return nl_wait_for_ack(sk);
+}
+
+#endif
diff --git a/libnl_2/include/netlink-types.h b/libnl_2/include/netlink-types.h
new file mode 100644
index 0000000..92be87c
--- /dev/null
+++ b/libnl_2/include/netlink-types.h
@@ -0,0 +1,832 @@
+/*
+ * netlink-types.h Netlink Types (Private)
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_LOCAL_TYPES_H_
+#define NETLINK_LOCAL_TYPES_H_
+
+#include <netlink/list.h>
+#include <netlink/route/link.h>
+#include <netlink/route/qdisc.h>
+#include <netlink/route/rtnl.h>
+#include <netlink/route/route.h>
+#include <netlink/object-api.h>
+#include <linux/socket.h>
+#include <linux/pkt_sched.h>
+
+#define NL_SOCK_BUFSIZE_SET (1<<0)
+#define NL_SOCK_PASSCRED (1<<1)
+#define NL_OWN_PORT (1<<2)
+#define NL_MSG_PEEK (1<<3)
+#define NL_NO_AUTO_ACK (1<<4)
+
+#define NL_MSG_CRED_PRESENT 1
+
+struct nl_cache_ops;
+struct nl_sock;
+struct nl_object;
+
+struct nl_cb
+{
+ nl_recvmsg_msg_cb_t cb_set[NL_CB_TYPE_MAX+1];
+ void * cb_args[NL_CB_TYPE_MAX+1];
+
+ nl_recvmsg_err_cb_t cb_err;
+ void * cb_err_arg;
+
+ /** May be used to replace nl_recvmsgs with your own implementation
+ * in all internal calls to nl_recvmsgs. */
+ int (*cb_recvmsgs_ow)(struct nl_sock *,
+ struct nl_cb *);
+
+ /** Overwrite internal calls to nl_recv, must return the number of
+ * octets read and allocate a buffer for the received data. */
+ int (*cb_recv_ow)(struct nl_sock *,
+ struct sockaddr_nl *,
+ unsigned char **,
+ struct ucred **);
+
+ /** Overwrites internal calls to nl_send, must send the netlink
+ * message. */
+ int (*cb_send_ow)(struct nl_sock *,
+ struct nl_msg *);
+
+ int cb_refcnt;
+};
+
+struct nl_sock
+{
+ struct sockaddr_nl s_local;
+ struct sockaddr_nl s_peer;
+ int s_fd;
+ int s_proto;
+ unsigned int s_seq_next;
+ unsigned int s_seq_expect;
+ int s_flags;
+ struct nl_cb * s_cb;
+};
+
+struct nl_cache
+{
+ struct nl_list_head c_items;
+ int c_nitems;
+ int c_iarg1;
+ int c_iarg2;
+ struct nl_cache_ops * c_ops;
+};
+
+struct nl_cache_assoc
+{
+ struct nl_cache * ca_cache;
+ change_func_t ca_change;
+ void * ca_change_data;
+};
+
+struct nl_cache_mngr
+{
+ int cm_protocol;
+ int cm_flags;
+ int cm_nassocs;
+ struct nl_sock * cm_handle;
+ struct nl_cache_assoc * cm_assocs;
+};
+
+struct nl_parser_param;
+
+#define LOOSE_COMPARISON 1
+
+#define NL_OBJ_MARK 1
+
+struct nl_object
+{
+ NLHDR_COMMON
+};
+
+struct nl_data
+{
+ size_t d_size;
+ void * d_data;
+};
+
+struct nl_addr
+{
+ int a_family;
+ unsigned int a_maxsize;
+ unsigned int a_len;
+ int a_prefixlen;
+ int a_refcnt;
+ char a_addr[0];
+};
+
+struct nl_msg
+{
+ int nm_protocol;
+ int nm_flags;
+ struct sockaddr_nl nm_src;
+ struct sockaddr_nl nm_dst;
+ struct ucred nm_creds;
+ struct nlmsghdr * nm_nlh;
+ size_t nm_size;
+ int nm_refcnt;
+};
+
+struct rtnl_link_map
+{
+ uint64_t lm_mem_start;
+ uint64_t lm_mem_end;
+ uint64_t lm_base_addr;
+ uint16_t lm_irq;
+ uint8_t lm_dma;
+ uint8_t lm_port;
+};
+
+#define IFQDISCSIZ 32
+
+struct rtnl_link
+{
+ NLHDR_COMMON
+
+ char l_name[IFNAMSIZ];
+
+ uint32_t l_family;
+ uint32_t l_arptype;
+ uint32_t l_index;
+ uint32_t l_flags;
+ uint32_t l_change;
+ uint32_t l_mtu;
+ uint32_t l_link;
+ uint32_t l_txqlen;
+ uint32_t l_weight;
+ uint32_t l_master;
+ struct nl_addr *l_addr;
+ struct nl_addr *l_bcast;
+ char l_qdisc[IFQDISCSIZ];
+ struct rtnl_link_map l_map;
+ uint64_t l_stats[RTNL_LINK_STATS_MAX+1];
+ uint32_t l_flag_mask;
+ uint8_t l_operstate;
+ uint8_t l_linkmode;
+ /* 2 byte hole */
+ struct rtnl_link_info_ops *l_info_ops;
+ void * l_info;
+};
+
+struct rtnl_ncacheinfo
+{
+ uint32_t nci_confirmed; /**< Time since neighbour validty was last confirmed */
+ uint32_t nci_used; /**< Time since neighbour entry was last ued */
+ uint32_t nci_updated; /**< Time since last update */
+ uint32_t nci_refcnt; /**< Reference counter */
+};
+
+
+struct rtnl_neigh
+{
+ NLHDR_COMMON
+ uint32_t n_family;
+ uint32_t n_ifindex;
+ uint16_t n_state;
+ uint8_t n_flags;
+ uint8_t n_type;
+ struct nl_addr *n_lladdr;
+ struct nl_addr *n_dst;
+ uint32_t n_probes;
+ struct rtnl_ncacheinfo n_cacheinfo;
+ uint32_t n_state_mask;
+ uint32_t n_flag_mask;
+};
+
+
+struct rtnl_addr_cacheinfo
+{
+ /* Preferred lifetime in seconds */
+ uint32_t aci_prefered;
+
+ /* Valid lifetime in seconds */
+ uint32_t aci_valid;
+
+ /* Timestamp of creation in 1/100s seince boottime */
+ uint32_t aci_cstamp;
+
+ /* Timestamp of last update in 1/100s since boottime */
+ uint32_t aci_tstamp;
+};
+
+struct rtnl_addr
+{
+ NLHDR_COMMON
+
+ uint8_t a_family;
+ uint8_t a_prefixlen;
+ uint8_t a_flags;
+ uint8_t a_scope;
+ uint32_t a_ifindex;
+
+ struct nl_addr *a_peer;
+ struct nl_addr *a_local;
+ struct nl_addr *a_bcast;
+ struct nl_addr *a_anycast;
+ struct nl_addr *a_multicast;
+
+ struct rtnl_addr_cacheinfo a_cacheinfo;
+
+ char a_label[IFNAMSIZ];
+ uint32_t a_flag_mask;
+};
+
+struct rtnl_nexthop
+{
+ uint8_t rtnh_flags;
+ uint8_t rtnh_flag_mask;
+ uint8_t rtnh_weight;
+ /* 1 byte spare */
+ uint32_t rtnh_ifindex;
+ struct nl_addr * rtnh_gateway;
+ uint32_t ce_mask; /* HACK to support attr macros */
+ struct nl_list_head rtnh_list;
+ uint32_t rtnh_realms;
+};
+
+struct rtnl_route
+{
+ NLHDR_COMMON
+
+ uint8_t rt_family;
+ uint8_t rt_dst_len;
+ uint8_t rt_src_len;
+ uint8_t rt_tos;
+ uint8_t rt_protocol;
+ uint8_t rt_scope;
+ uint8_t rt_type;
+ uint8_t rt_nmetrics;
+ uint32_t rt_flags;
+ struct nl_addr * rt_dst;
+ struct nl_addr * rt_src;
+ uint32_t rt_table;
+ uint32_t rt_iif;
+ uint32_t rt_prio;
+ uint32_t rt_metrics[RTAX_MAX];
+ uint32_t rt_metrics_mask;
+ uint32_t rt_nr_nh;
+ struct nl_addr * rt_pref_src;
+ struct nl_list_head rt_nexthops;
+ struct rtnl_rtcacheinfo rt_cacheinfo;
+ uint32_t rt_flag_mask;
+};
+
+struct rtnl_rule
+{
+ NLHDR_COMMON
+
+ uint64_t r_mark;
+ uint32_t r_prio;
+ uint32_t r_realms;
+ uint32_t r_table;
+ uint8_t r_dsfield;
+ uint8_t r_type;
+ uint8_t r_family;
+ uint8_t r_src_len;
+ uint8_t r_dst_len;
+ char r_iif[IFNAMSIZ];
+ struct nl_addr *r_src;
+ struct nl_addr *r_dst;
+ struct nl_addr *r_srcmap;
+};
+
+struct rtnl_neightbl_parms
+{
+ /**
+ * Interface index of the device this parameter set is assigned
+ * to or 0 for the default set.
+ */
+ uint32_t ntp_ifindex;
+
+ /**
+ * Number of references to this parameter set.
+ */
+ uint32_t ntp_refcnt;
+
+ /**
+ * Queue length for pending arp requests, i.e. the number of
+ * packets which are accepted from other layers while the
+ * neighbour address is still being resolved
+ */
+ uint32_t ntp_queue_len;
+
+ /**
+ * Number of requests to send to the user level ARP daemon.
+ * Specify 0 to disable.
+ */
+ uint32_t ntp_app_probes;
+
+ /**
+ * Maximum number of retries for unicast solicitation.
+ */
+ uint32_t ntp_ucast_probes;
+
+ /**
+ * Maximum number of retries for multicast solicitation.
+ */
+ uint32_t ntp_mcast_probes;
+
+ /**
+ * Base value in milliseconds to ompute reachable time, see RFC2461.
+ */
+ uint64_t ntp_base_reachable_time;
+
+ /**
+ * Actual reachable time (read-only)
+ */
+ uint64_t ntp_reachable_time; /* secs */
+
+ /**
+ * The time in milliseconds between retransmitted Neighbor
+ * Solicitation messages.
+ */
+ uint64_t ntp_retrans_time;
+
+ /**
+ * Interval in milliseconds to check for stale neighbour
+ * entries.
+ */
+ uint64_t ntp_gc_stale_time; /* secs */
+
+ /**
+ * Delay in milliseconds for the first time probe if
+ * the neighbour is reachable.
+ */
+ uint64_t ntp_probe_delay; /* secs */
+
+ /**
+ * Maximum delay in milliseconds of an answer to a neighbour
+ * solicitation message.
+ */
+ uint64_t ntp_anycast_delay;
+
+ /**
+ * Minimum age in milliseconds before a neighbour entry
+ * may be replaced.
+ */
+ uint64_t ntp_locktime;
+
+ /**
+ * Delay in milliseconds before answering to an ARP request
+ * for which a proxy ARP entry exists.
+ */
+ uint64_t ntp_proxy_delay;
+
+ /**
+ * Queue length for the delayed proxy arp requests.
+ */
+ uint32_t ntp_proxy_qlen;
+
+ /**
+ * Mask of available parameter attributes
+ */
+ uint32_t ntp_mask;
+};
+
+#define NTBLNAMSIZ 32
+
+/**
+ * Neighbour table
+ * @ingroup neightbl
+ */
+struct rtnl_neightbl
+{
+ NLHDR_COMMON
+
+ char nt_name[NTBLNAMSIZ];
+ uint32_t nt_family;
+ uint32_t nt_gc_thresh1;
+ uint32_t nt_gc_thresh2;
+ uint32_t nt_gc_thresh3;
+ uint64_t nt_gc_interval;
+ struct ndt_config nt_config;
+ struct rtnl_neightbl_parms nt_parms;
+ struct ndt_stats nt_stats;
+};
+
+struct rtnl_ratespec
+{
+ uint8_t rs_cell_log;
+ uint16_t rs_feature;
+ uint16_t rs_addend;
+ uint16_t rs_mpu;
+ uint32_t rs_rate;
+};
+
+struct rtnl_tstats
+{
+ struct {
+ uint64_t bytes;
+ uint64_t packets;
+ } tcs_basic;
+
+ struct {
+ uint32_t bps;
+ uint32_t pps;
+ } tcs_rate_est;
+
+ struct {
+ uint32_t qlen;
+ uint32_t backlog;
+ uint32_t drops;
+ uint32_t requeues;
+ uint32_t overlimits;
+ } tcs_queue;
+};
+
+#define TCKINDSIZ 32
+
+#define NL_TCA_GENERIC(pre) \
+ NLHDR_COMMON \
+ uint32_t pre ##_family; \
+ uint32_t pre ##_ifindex; \
+ uint32_t pre ##_handle; \
+ uint32_t pre ##_parent; \
+ uint32_t pre ##_info; \
+ char pre ##_kind[TCKINDSIZ]; \
+ struct nl_data * pre ##_opts; \
+ uint64_t pre ##_stats[RTNL_TC_STATS_MAX+1]; \
+ struct nl_data * pre ##_xstats; \
+ struct nl_data * pre ##_subdata; \
+
+
+struct rtnl_tca
+{
+ NL_TCA_GENERIC(tc);
+};
+
+struct rtnl_qdisc
+{
+ NL_TCA_GENERIC(q);
+ struct rtnl_qdisc_ops *q_ops;
+};
+
+struct rtnl_class
+{
+ NL_TCA_GENERIC(c);
+ struct rtnl_class_ops *c_ops;
+};
+
+struct rtnl_cls
+{
+ NL_TCA_GENERIC(c);
+ uint16_t c_prio;
+ uint16_t c_protocol;
+ struct rtnl_cls_ops *c_ops;
+};
+
+struct rtnl_u32
+{
+ uint32_t cu_divisor;
+ uint32_t cu_hash;
+ uint32_t cu_classid;
+ uint32_t cu_link;
+ struct nl_data * cu_pcnt;
+ struct nl_data * cu_selector;
+ struct nl_data * cu_act;
+ struct nl_data * cu_police;
+ char cu_indev[IFNAMSIZ];
+ int cu_mask;
+};
+
+struct rtnl_cgroup
+{
+ struct rtnl_ematch_tree *cg_ematch;
+ int cg_mask;
+};
+
+struct rtnl_fw
+{
+ uint32_t cf_classid;
+ struct nl_data * cf_act;
+ struct nl_data * cf_police;
+ char cf_indev[IFNAMSIZ];
+ int cf_mask;
+};
+
+struct rtnl_ematch
+{
+ uint16_t e_id;
+ uint16_t e_kind;
+ uint16_t e_flags;
+
+ struct nl_list_head e_childs;
+ struct nl_list_head e_list;
+ struct rtnl_ematch_ops *e_ops;
+
+ char e_data[0];
+};
+
+struct rtnl_ematch_tree
+{
+ uint16_t et_progid;
+ struct nl_list_head et_list;
+
+};
+
+struct rtnl_dsmark_qdisc
+{
+ uint16_t qdm_indices;
+ uint16_t qdm_default_index;
+ uint32_t qdm_set_tc_index;
+ uint32_t qdm_mask;
+};
+
+struct rtnl_dsmark_class
+{
+ uint8_t cdm_bmask;
+ uint8_t cdm_value;
+ uint32_t cdm_mask;
+};
+
+struct rtnl_fifo
+{
+ uint32_t qf_limit;
+ uint32_t qf_mask;
+};
+
+struct rtnl_prio
+{
+ uint32_t qp_bands;
+ uint8_t qp_priomap[TC_PRIO_MAX+1];
+ uint32_t qp_mask;
+};
+
+struct rtnl_tbf
+{
+ uint32_t qt_limit;
+ uint32_t qt_mpu;
+ struct rtnl_ratespec qt_rate;
+ uint32_t qt_rate_bucket;
+ uint32_t qt_rate_txtime;
+ struct rtnl_ratespec qt_peakrate;
+ uint32_t qt_peakrate_bucket;
+ uint32_t qt_peakrate_txtime;
+ uint32_t qt_mask;
+};
+
+struct rtnl_sfq
+{
+ uint32_t qs_quantum;
+ uint32_t qs_perturb;
+ uint32_t qs_limit;
+ uint32_t qs_divisor;
+ uint32_t qs_flows;
+ uint32_t qs_mask;
+};
+
+struct rtnl_netem_corr
+{
+ uint32_t nmc_delay;
+ uint32_t nmc_loss;
+ uint32_t nmc_duplicate;
+};
+
+struct rtnl_netem_reo
+{
+ uint32_t nmro_probability;
+ uint32_t nmro_correlation;
+};
+
+struct rtnl_netem_crpt
+{
+ uint32_t nmcr_probability;
+ uint32_t nmcr_correlation;
+};
+
+struct rtnl_netem_dist
+{
+ int16_t * dist_data;
+ size_t dist_size;
+};
+
+struct rtnl_netem
+{
+ uint32_t qnm_latency;
+ uint32_t qnm_limit;
+ uint32_t qnm_loss;
+ uint32_t qnm_gap;
+ uint32_t qnm_duplicate;
+ uint32_t qnm_jitter;
+ uint32_t qnm_mask;
+ struct rtnl_netem_corr qnm_corr;
+ struct rtnl_netem_reo qnm_ro;
+ struct rtnl_netem_crpt qnm_crpt;
+ struct rtnl_netem_dist qnm_dist;
+};
+
+struct rtnl_htb_qdisc
+{
+ uint32_t qh_rate2quantum;
+ uint32_t qh_defcls;
+ uint32_t qh_mask;
+};
+
+struct rtnl_htb_class
+{
+ uint32_t ch_prio;
+ uint32_t ch_mtu;
+ struct rtnl_ratespec ch_rate;
+ struct rtnl_ratespec ch_ceil;
+ uint32_t ch_rbuffer;
+ uint32_t ch_cbuffer;
+ uint32_t ch_quantum;
+ uint8_t ch_overhead;
+ uint8_t ch_mpu;
+ uint32_t ch_mask;
+};
+
+struct rtnl_cbq
+{
+ struct tc_cbq_lssopt cbq_lss;
+ struct tc_ratespec cbq_rate;
+ struct tc_cbq_wrropt cbq_wrr;
+ struct tc_cbq_ovl cbq_ovl;
+ struct tc_cbq_fopt cbq_fopt;
+ struct tc_cbq_police cbq_police;
+};
+
+struct rtnl_red
+{
+ uint32_t qr_limit;
+ uint32_t qr_qth_min;
+ uint32_t qr_qth_max;
+ uint8_t qr_flags;
+ uint8_t qr_wlog;
+ uint8_t qr_plog;
+ uint8_t qr_scell_log;
+ uint32_t qr_mask;
+};
+
+struct flnl_request
+{
+ NLHDR_COMMON
+
+ struct nl_addr * lr_addr;
+ uint32_t lr_fwmark;
+ uint8_t lr_tos;
+ uint8_t lr_scope;
+ uint8_t lr_table;
+};
+
+
+struct flnl_result
+{
+ NLHDR_COMMON
+
+ struct flnl_request * fr_req;
+ uint8_t fr_table_id;
+ uint8_t fr_prefixlen;
+ uint8_t fr_nh_sel;
+ uint8_t fr_type;
+ uint8_t fr_scope;
+ uint32_t fr_error;
+};
+
+#define GENL_OP_HAS_POLICY 1
+#define GENL_OP_HAS_DOIT 2
+#define GENL_OP_HAS_DUMPIT 4
+
+struct genl_family_op
+{
+ uint32_t o_id;
+ uint32_t o_flags;
+
+ struct nl_list_head o_list;
+};
+
+struct genl_family
+{
+ NLHDR_COMMON
+
+ uint16_t gf_id;
+ char gf_name[GENL_NAMSIZ];
+ uint32_t gf_version;
+ uint32_t gf_hdrsize;
+ uint32_t gf_maxattr;
+
+ struct nl_list_head gf_ops;
+};
+
+union nfnl_ct_proto
+{
+ struct {
+ uint16_t src;
+ uint16_t dst;
+ } port;
+ struct {
+ uint16_t id;
+ uint8_t type;
+ uint8_t code;
+ } icmp;
+};
+
+struct nfnl_ct_dir {
+ struct nl_addr * src;
+ struct nl_addr * dst;
+ union nfnl_ct_proto proto;
+ uint64_t packets;
+ uint64_t bytes;
+};
+
+union nfnl_ct_protoinfo {
+ struct {
+ uint8_t state;
+ } tcp;
+};
+
+struct nfnl_ct {
+ NLHDR_COMMON
+
+ uint8_t ct_family;
+ uint8_t ct_proto;
+ union nfnl_ct_protoinfo ct_protoinfo;
+
+ uint32_t ct_status;
+ uint32_t ct_status_mask;
+ uint32_t ct_timeout;
+ uint32_t ct_mark;
+ uint32_t ct_use;
+ uint32_t ct_id;
+
+ struct nfnl_ct_dir ct_orig;
+ struct nfnl_ct_dir ct_repl;
+};
+
+struct nfnl_log {
+ NLHDR_COMMON
+
+ uint16_t log_group;
+ uint8_t log_copy_mode;
+ uint32_t log_copy_range;
+ uint32_t log_flush_timeout;
+ uint32_t log_alloc_size;
+ uint32_t log_queue_threshold;
+ uint32_t log_flags;
+ uint32_t log_flag_mask;
+};
+
+struct nfnl_log_msg {
+ NLHDR_COMMON
+
+ uint8_t log_msg_family;
+ uint8_t log_msg_hook;
+ uint16_t log_msg_hwproto;
+ uint32_t log_msg_mark;
+ struct timeval log_msg_timestamp;
+ uint32_t log_msg_indev;
+ uint32_t log_msg_outdev;
+ uint32_t log_msg_physindev;
+ uint32_t log_msg_physoutdev;
+ uint8_t log_msg_hwaddr[8];
+ int log_msg_hwaddr_len;
+ void * log_msg_payload;
+ int log_msg_payload_len;
+ char * log_msg_prefix;
+ uint32_t log_msg_uid;
+ uint32_t log_msg_gid;
+ uint32_t log_msg_seq;
+ uint32_t log_msg_seq_global;
+};
+
+struct nfnl_queue {
+ NLHDR_COMMON
+
+ uint16_t queue_group;
+ uint32_t queue_maxlen;
+ uint32_t queue_copy_range;
+ uint8_t queue_copy_mode;
+};
+
+struct nfnl_queue_msg {
+ NLHDR_COMMON
+
+ uint16_t queue_msg_group;
+ uint8_t queue_msg_family;
+ uint8_t queue_msg_hook;
+ uint16_t queue_msg_hwproto;
+ uint32_t queue_msg_packetid;
+ uint32_t queue_msg_mark;
+ struct timeval queue_msg_timestamp;
+ uint32_t queue_msg_indev;
+ uint32_t queue_msg_outdev;
+ uint32_t queue_msg_physindev;
+ uint32_t queue_msg_physoutdev;
+ uint8_t queue_msg_hwaddr[8];
+ int queue_msg_hwaddr_len;
+ void * queue_msg_payload;
+ int queue_msg_payload_len;
+ uint32_t queue_msg_verdict;
+};
+
+#endif
diff --git a/libnl_2/include/netlink/addr.h b/libnl_2/include/netlink/addr.h
new file mode 100644
index 0000000..cc3d201
--- /dev/null
+++ b/libnl_2/include/netlink/addr.h
@@ -0,0 +1,69 @@
+/*
+ * netlink/addr.h Abstract Address
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_ADDR_H_
+#define NETLINK_ADDR_H_
+
+#include <netlink/netlink.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_addr;
+
+/* Creation */
+extern struct nl_addr * nl_addr_alloc(size_t);
+extern struct nl_addr * nl_addr_alloc_attr(struct nlattr *, int);
+extern struct nl_addr * nl_addr_build(int, void *, size_t);
+extern int nl_addr_parse(const char *, int, struct nl_addr **);
+extern struct nl_addr * nl_addr_clone(struct nl_addr *);
+
+/* Destroyage */
+extern void nl_addr_destroy(struct nl_addr *);
+
+/* Usage Management */
+extern struct nl_addr * nl_addr_get(struct nl_addr *);
+extern void nl_addr_put(struct nl_addr *);
+extern int nl_addr_shared(struct nl_addr *);
+
+extern int nl_addr_cmp(struct nl_addr *, struct nl_addr *);
+extern int nl_addr_cmp_prefix(struct nl_addr *, struct nl_addr *);
+extern int nl_addr_iszero(struct nl_addr *);
+extern int nl_addr_valid(char *, int);
+extern int nl_addr_guess_family(struct nl_addr *);
+extern int nl_addr_fill_sockaddr(struct nl_addr *,
+ struct sockaddr *, socklen_t *);
+extern int nl_addr_info(struct nl_addr *, struct addrinfo **);
+extern int nl_addr_resolve(struct nl_addr *addr, char *host, size_t hostlen);
+
+/* Access Functions */
+extern void nl_addr_set_family(struct nl_addr *, int);
+extern int nl_addr_get_family(struct nl_addr *);
+extern int nl_addr_set_binary_addr(struct nl_addr *, void *,
+ size_t);
+extern void * nl_addr_get_binary_addr(struct nl_addr *);
+extern unsigned int nl_addr_get_len(struct nl_addr *);
+extern void nl_addr_set_prefixlen(struct nl_addr *, int);
+extern unsigned int nl_addr_get_prefixlen(struct nl_addr *);
+
+/* Address Family Translations */
+extern char * nl_af2str(int, char *, size_t);
+extern int nl_str2af(const char *);
+
+/* Translations to Strings */
+extern char * nl_addr2str(struct nl_addr *, char *, size_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/attr.h b/libnl_2/include/netlink/attr.h
new file mode 100644
index 0000000..8479c23
--- /dev/null
+++ b/libnl_2/include/netlink/attr.h
@@ -0,0 +1,283 @@
+/*
+ * netlink/attr.h Netlink Attributes
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_ATTR_H_
+#define NETLINK_ATTR_H_
+
+#include <netlink/netlink.h>
+#include <netlink/object.h>
+#include <netlink/addr.h>
+#include <netlink/data.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_msg;
+
+/**
+ * @name Basic Attribute Data Types
+ * @{
+ */
+
+ /**
+ * @ingroup attr
+ * Basic attribute data types
+ *
+ * See \ref attr_datatypes for more details.
+ */
+enum {
+ NLA_UNSPEC, /**< Unspecified type, binary data chunk */
+ NLA_U8, /**< 8 bit integer */
+ NLA_U16, /**< 16 bit integer */
+ NLA_U32, /**< 32 bit integer */
+ NLA_U64, /**< 64 bit integer */
+ NLA_STRING, /**< NUL terminated character string */
+ NLA_FLAG, /**< Flag */
+ NLA_MSECS, /**< Micro seconds (64bit) */
+ NLA_NESTED, /**< Nested attributes */
+ __NLA_TYPE_MAX,
+};
+
+#define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
+
+/** @} */
+
+/**
+ * @ingroup attr
+ * Attribute validation policy.
+ *
+ * See \ref attr_datatypes for more details.
+ */
+struct nla_policy {
+ /** Type of attribute or NLA_UNSPEC */
+ uint16_t type;
+
+ /** Minimal length of payload required */
+ uint16_t minlen;
+
+ /** Maximal length of payload allowed */
+ uint16_t maxlen;
+};
+
+/* Size calculations */
+extern int nla_attr_size(int payload);
+extern int nla_total_size(int payload);
+extern int nla_padlen(int payload);
+
+/* Attribute parsing */
+extern int nla_type(const struct nlattr *);
+extern void * nla_data(const struct nlattr *);
+extern int nla_len(const struct nlattr *);
+extern int nla_ok(const struct nlattr *, int);
+extern struct nlattr * nla_next(const struct nlattr *, int *);
+extern int nla_parse(struct nlattr **, int, struct nlattr *,
+ int, struct nla_policy *);
+extern int nla_validate(struct nlattr *, int, int,
+ struct nla_policy *);
+extern struct nlattr * nla_find(struct nlattr *, int, int);
+
+/* Helper Functions */
+extern int nla_memcpy(void *, struct nlattr *, int);
+extern size_t nla_strlcpy(char *, const struct nlattr *, size_t);
+extern int nla_memcmp(const struct nlattr *, const void *, size_t);
+extern int nla_strcmp(const struct nlattr *, const char *);
+
+/* Unspecific attribute */
+extern struct nlattr * nla_reserve(struct nl_msg *, int, int);
+extern int nla_put(struct nl_msg *, int, int, const void *);
+extern int nla_put_data(struct nl_msg *, int, struct nl_data *);
+extern int nla_put_addr(struct nl_msg *, int, struct nl_addr *);
+
+/* Integer attribute */
+extern uint8_t nla_get_u8(struct nlattr *);
+extern int nla_put_u8(struct nl_msg *, int, uint8_t);
+extern uint16_t nla_get_u16(struct nlattr *);
+extern int nla_put_u16(struct nl_msg *, int, uint16_t);
+extern uint32_t nla_get_u32(struct nlattr *);
+extern int nla_put_u32(struct nl_msg *, int, uint32_t);
+extern uint64_t nla_get_u64(struct nlattr *);
+extern int nla_put_u64(struct nl_msg *, int, uint64_t);
+
+/* String attribute */
+extern char * nla_get_string(struct nlattr *);
+extern char * nla_strdup(struct nlattr *);
+extern int nla_put_string(struct nl_msg *, int, const char *);
+
+/* Flag attribute */
+extern int nla_get_flag(struct nlattr *);
+extern int nla_put_flag(struct nl_msg *, int);
+
+/* Msec attribute */
+extern unsigned long nla_get_msecs(struct nlattr *);
+extern int nla_put_msecs(struct nl_msg *, int, unsigned long);
+
+/* Attribute nesting */
+extern int nla_put_nested(struct nl_msg *, int, struct nl_msg *);
+extern struct nlattr * nla_nest_start(struct nl_msg *, int);
+extern int nla_nest_end(struct nl_msg *, struct nlattr *);
+extern int nla_parse_nested(struct nlattr **, int, struct nlattr *,
+ struct nla_policy *);
+
+/**
+ * @name Attribute Construction (Exception Based)
+ * @{
+ */
+
+/**
+ * @ingroup attr
+ * Add unspecific attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg attrlen Length of attribute payload.
+ * @arg data Head of attribute payload.
+ */
+#define NLA_PUT(msg, attrtype, attrlen, data) \
+ do { \
+ if (nla_put(msg, attrtype, attrlen, data) < 0) \
+ goto nla_put_failure; \
+ } while(0)
+
+/**
+ * @ingroup attr
+ * Add atomic type attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg type Atomic type.
+ * @arg attrtype Attribute type.
+ * @arg value Head of attribute payload.
+ */
+#define NLA_PUT_TYPE(msg, type, attrtype, value) \
+ do { \
+ type __tmp = value; \
+ NLA_PUT(msg, attrtype, sizeof(type), &__tmp); \
+ } while(0)
+
+/**
+ * Add 8 bit integer attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg value Numeric value.
+ */
+#define NLA_PUT_U8(msg, attrtype, value) \
+ NLA_PUT_TYPE(msg, uint8_t, attrtype, value)
+
+/**
+ * Add 16 bit integer attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg value Numeric value.
+ */
+#define NLA_PUT_U16(msg, attrtype, value) \
+ NLA_PUT_TYPE(msg, uint16_t, attrtype, value)
+
+/**
+ * Add 32 bit integer attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg value Numeric value.
+ */
+#define NLA_PUT_U32(msg, attrtype, value) \
+ NLA_PUT_TYPE(msg, uint32_t, attrtype, value)
+
+/**
+ * Add 64 bit integer attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg value Numeric value.
+ */
+#define NLA_PUT_U64(msg, attrtype, value) \
+ NLA_PUT_TYPE(msg, uint64_t, attrtype, value)
+
+/**
+ * Add string attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg value NUL terminated character string.
+ */
+#define NLA_PUT_STRING(msg, attrtype, value) \
+ NLA_PUT(msg, attrtype, strlen(value) + 1, value)
+
+/**
+ * Add flag attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ */
+#define NLA_PUT_FLAG(msg, attrtype) \
+ NLA_PUT(msg, attrtype, 0, NULL)
+
+/**
+ * Add msecs attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg msecs Numeric value in micro seconds.
+ */
+#define NLA_PUT_MSECS(msg, attrtype, msecs) \
+ NLA_PUT_U64(msg, attrtype, msecs)
+
+/**
+ * Add address attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg addr Abstract address object.
+ */
+#define NLA_PUT_ADDR(msg, attrtype, addr) \
+ NLA_PUT(msg, attrtype, nl_addr_get_len(addr), \
+ nl_addr_get_binary_addr(addr))
+
+/**
+ * Add abstract data attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg data Abstract data object.
+ */
+#define NLA_PUT_DATA(msg, attrtype, data) \
+ NLA_PUT(msg, attrtype, nl_data_get_size(data), \
+ nl_data_get(data))
+
+/** @} */
+
+/**
+ * @name Iterators
+ * @{
+ */
+
+/**
+ * @ingroup attr
+ * Iterate over a stream of attributes
+ * @arg pos loop counter, set to current attribute
+ * @arg head head of attribute stream
+ * @arg len length of attribute stream
+ * @arg rem initialized to len, holds bytes currently remaining in stream
+ */
+#define nla_for_each_attr(pos, head, len, rem) \
+ for (pos = head, rem = len; \
+ nla_ok(pos, rem); \
+ pos = nla_next(pos, &(rem)))
+
+/**
+ * @ingroup attr
+ * Iterate over a stream of nested attributes
+ * @arg pos loop counter, set to current attribute
+ * @arg nla attribute containing the nested attributes
+ * @arg rem initialized to len, holds bytes currently remaining in stream
+ */
+#define nla_for_each_nested(pos, nla, rem) \
+ for (pos = nla_data(nla), rem = nla_len(nla); \
+ nla_ok(pos, rem); \
+ pos = nla_next(pos, &(rem)))
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/cache-api.h b/libnl_2/include/netlink/cache-api.h
new file mode 100644
index 0000000..22fc449
--- /dev/null
+++ b/libnl_2/include/netlink/cache-api.h
@@ -0,0 +1,199 @@
+/*
+ * netlink/cache-api.h Caching API
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_CACHE_API_H_
+#define NETLINK_CACHE_API_H_
+
+#include <netlink/netlink.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @ingroup cache
+ * @defgroup cache_api Cache Implementation
+ * @brief
+ *
+ * @par 1) Cache Definition
+ * @code
+ * struct nl_cache_ops my_cache_ops = {
+ * .co_name = "route/link",
+ * .co_protocol = NETLINK_ROUTE,
+ * .co_hdrsize = sizeof(struct ifinfomsg),
+ * .co_obj_ops = &my_obj_ops,
+ * };
+ * @endcode
+ *
+ * @par 2)
+ * @code
+ * // The simplest way to fill a cache is by providing a request-update
+ * // function which must trigger a complete dump on the kernel-side of
+ * // whatever the cache covers.
+ * static int my_request_update(struct nl_cache *cache,
+ * struct nl_sock *socket)
+ * {
+ * // In this example, we request a full dump of the interface table
+ * return nl_rtgen_request(socket, RTM_GETLINK, AF_UNSPEC, NLM_F_DUMP);
+ * }
+ *
+ * // The resulting netlink messages sent back will be fed into a message
+ * // parser one at a time. The message parser has to extract all relevant
+ * // information from the message and create an object reflecting the
+ * // contents of the message and pass it on to the parser callback function
+ * // provide which will add the object to the cache.
+ * static int my_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
+ * struct nlmsghdr *nlh, struct nl_parser_param *pp)
+ * {
+ * struct my_obj *obj;
+ *
+ * obj = my_obj_alloc();
+ * obj->ce_msgtype = nlh->nlmsg_type;
+ *
+ * // Parse the netlink message and continue creating the object.
+ *
+ * err = pp->pp_cb((struct nl_object *) obj, pp);
+ * if (err < 0)
+ * goto errout;
+ * }
+ *
+ * struct nl_cache_ops my_cache_ops = {
+ * ...
+ * .co_request_update = my_request_update,
+ * .co_msg_parser = my_msg_parser,
+ * };
+ * @endcode
+ *
+ * @par 3) Notification based Updates
+ * @code
+ * // Caches can be kept up-to-date based on notifications if the kernel
+ * // sends out notifications whenever an object is added/removed/changed.
+ * //
+ * // It is trivial to support this, first a list of groups needs to be
+ * // defined which are required to join in order to receive all necessary
+ * // notifications. The groups are separated by address family to support
+ * // the common situation where a separate group is used for each address
+ * // family. If there is only one group, simply specify AF_UNSPEC.
+ * static struct nl_af_group addr_groups[] = {
+ * { AF_INET, RTNLGRP_IPV4_IFADDR },
+ * { AF_INET6, RTNLGRP_IPV6_IFADDR },
+ * { END_OF_GROUP_LIST },
+ * };
+ *
+ * // In order for the caching system to know the meaning of each message
+ * // type it requires a table which maps each supported message type to
+ * // a cache action, e.g. RTM_NEWADDR means address has been added or
+ * // updated, RTM_DELADDR means address has been removed.
+ * static struct nl_cache_ops rtnl_addr_ops = {
+ * ...
+ * .co_msgtypes = {
+ * { RTM_NEWADDR, NL_ACT_NEW, "new" },
+ * { RTM_DELADDR, NL_ACT_DEL, "del" },
+ * { RTM_GETADDR, NL_ACT_GET, "get" },
+ * END_OF_MSGTYPES_LIST,
+ * },
+ * .co_groups = addr_groups,
+ * };
+ *
+ * // It is now possible to keep the cache up-to-date using the cache manager.
+ * @endcode
+ * @{
+ */
+
+enum {
+ NL_ACT_UNSPEC,
+ NL_ACT_NEW,
+ NL_ACT_DEL,
+ NL_ACT_GET,
+ NL_ACT_SET,
+ NL_ACT_CHANGE,
+ __NL_ACT_MAX,
+};
+
+#define NL_ACT_MAX (__NL_ACT_MAX - 1)
+
+#define END_OF_MSGTYPES_LIST { -1, -1, NULL }
+
+/**
+ * Message type to cache action association
+ */
+struct nl_msgtype
+{
+ /** Netlink message type */
+ int mt_id;
+
+ /** Cache action to take */
+ int mt_act;
+
+ /** Name of operation for human-readable printing */
+ char * mt_name;
+};
+
+/**
+ * Address family to netlink group association
+ */
+struct nl_af_group
+{
+ /** Address family */
+ int ag_family;
+
+ /** Netlink group identifier */
+ int ag_group;
+};
+
+#define END_OF_GROUP_LIST AF_UNSPEC, 0
+
+struct nl_parser_param
+{
+ int (*pp_cb)(struct nl_object *, struct nl_parser_param *);
+ void * pp_arg;
+};
+
+/**
+ * Cache Operations
+ */
+struct nl_cache_ops
+{
+ char * co_name;
+
+ int co_hdrsize;
+ int co_protocol;
+ struct nl_af_group * co_groups;
+
+ /**
+ * Called whenever an update of the cache is required. Must send
+ * a request message to the kernel requesting a complete dump.
+ */
+ int (*co_request_update)(struct nl_cache *, struct nl_sock *);
+
+ /**
+ * Called whenever a message was received that needs to be parsed.
+ * Must parse the message and call the paser callback function
+ * (nl_parser_param) provided via the argument.
+ */
+ int (*co_msg_parser)(struct nl_cache_ops *, struct sockaddr_nl *,
+ struct nlmsghdr *, struct nl_parser_param *);
+
+ struct nl_object_ops * co_obj_ops;
+
+ struct nl_cache_ops *co_next;
+ struct nl_cache *co_major_cache;
+ struct genl_ops * co_genl;
+ struct nl_msgtype co_msgtypes[];
+};
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/cache.h b/libnl_2/include/netlink/cache.h
new file mode 100644
index 0000000..c752920
--- /dev/null
+++ b/libnl_2/include/netlink/cache.h
@@ -0,0 +1,129 @@
+/*
+ * netlink/cache.h Caching Module
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_CACHE_H_
+#define NETLINK_CACHE_H_
+
+#include <netlink/netlink.h>
+#include <netlink/msg.h>
+#include <netlink/utils.h>
+#include <netlink/object.h>
+#include <netlink/cache-api.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_cache;
+
+typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int, void *);
+
+/* Access Functions */
+extern int nl_cache_nitems(struct nl_cache *);
+extern int nl_cache_nitems_filter(struct nl_cache *,
+ struct nl_object *);
+extern struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *);
+extern struct nl_object * nl_cache_get_first(struct nl_cache *);
+extern struct nl_object * nl_cache_get_last(struct nl_cache *);
+extern struct nl_object * nl_cache_get_next(struct nl_object *);
+extern struct nl_object * nl_cache_get_prev(struct nl_object *);
+
+extern struct nl_cache * nl_cache_alloc(struct nl_cache_ops *);
+extern int nl_cache_alloc_and_fill(struct nl_cache_ops *,
+ struct nl_sock *,
+ struct nl_cache **);
+extern int nl_cache_alloc_name(const char *,
+ struct nl_cache **);
+extern struct nl_cache * nl_cache_subset(struct nl_cache *,
+ struct nl_object *);
+extern void nl_cache_clear(struct nl_cache *);
+extern void nl_cache_free(struct nl_cache *);
+
+/* Cache modification */
+extern int nl_cache_add(struct nl_cache *,
+ struct nl_object *);
+extern int nl_cache_parse_and_add(struct nl_cache *,
+ struct nl_msg *);
+extern void nl_cache_remove(struct nl_object *);
+extern int nl_cache_refill(struct nl_sock *,
+ struct nl_cache *);
+extern int nl_cache_pickup(struct nl_sock *,
+ struct nl_cache *);
+extern int nl_cache_resync(struct nl_sock *,
+ struct nl_cache *,
+ change_func_t,
+ void *);
+extern int nl_cache_include(struct nl_cache *,
+ struct nl_object *,
+ change_func_t,
+ void *);
+
+/* General */
+extern int nl_cache_is_empty(struct nl_cache *);
+extern void nl_cache_mark_all(struct nl_cache *);
+
+/* Dumping */
+extern void nl_cache_dump(struct nl_cache *,
+ struct nl_dump_params *);
+extern void nl_cache_dump_filter(struct nl_cache *,
+ struct nl_dump_params *,
+ struct nl_object *);
+
+/* Iterators */
+extern void nl_cache_foreach(struct nl_cache *,
+ void (*cb)(struct nl_object *,
+ void *),
+ void *arg);
+extern void nl_cache_foreach_filter(struct nl_cache *,
+ struct nl_object *,
+ void (*cb)(struct
+ nl_object *,
+ void *),
+ void *arg);
+
+/* --- cache management --- */
+
+/* Cache type management */
+extern struct nl_cache_ops * nl_cache_ops_lookup(const char *);
+extern struct nl_cache_ops * nl_cache_ops_associate(int, int);
+extern struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int);
+extern void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
+extern int nl_cache_mngt_register(struct nl_cache_ops *);
+extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
+
+/* Global cache provisioning/requiring */
+extern void nl_cache_mngt_provide(struct nl_cache *);
+extern void nl_cache_mngt_unprovide(struct nl_cache *);
+extern struct nl_cache * nl_cache_mngt_require(const char *);
+
+struct nl_cache_mngr;
+
+#define NL_AUTO_PROVIDE 1
+
+extern int nl_cache_mngr_alloc(struct nl_sock *,
+ int, int,
+ struct nl_cache_mngr **);
+extern int nl_cache_mngr_add(struct nl_cache_mngr *,
+ const char *,
+ change_func_t,
+ void *,
+ struct nl_cache **);
+extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
+extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
+ int);
+extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *);
+extern void nl_cache_mngr_free(struct nl_cache_mngr *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/cli/utils.h b/libnl_2/include/netlink/cli/utils.h
new file mode 100644
index 0000000..2a23208
--- /dev/null
+++ b/libnl_2/include/netlink/cli/utils.h
@@ -0,0 +1,80 @@
+/*
+ * src/utils.h Utilities
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef __NETLINK_CLI_UTILS_H_
+#define __NETLINK_CLI_UTILS_H_
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <stdint.h>
+#include <ctype.h>
+#include <getopt.h>
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netlink/netlink.h>
+#include <netlink/utils.h>
+#include <netlink/addr.h>
+#include <netlink/list.h>
+#include <netlink/route/rtnl.h>
+#include <netlink/route/link.h>
+#include <netlink/route/addr.h>
+#include <netlink/route/neighbour.h>
+#include <netlink/route/neightbl.h>
+#include <netlink/route/route.h>
+#include <netlink/route/rule.h>
+#include <netlink/route/qdisc.h>
+#include <netlink/route/class.h>
+#include <netlink/route/classifier.h>
+#include <netlink/route/cls/ematch.h>
+#include <netlink/fib_lookup/lookup.h>
+#include <netlink/fib_lookup/request.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/ctrl.h>
+#include <netlink/genl/mngt.h>
+#include <netlink/netfilter/ct.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef __init
+#define __init __attribute__((constructor))
+#endif
+
+#ifndef __exit
+#define __exit __attribute__((destructor))
+#endif
+
+extern uint32_t nl_cli_parse_u32(const char *);
+extern void nl_cli_print_version(void);
+extern void nl_cli_fatal(int, const char *, ...);
+extern struct nl_addr * nl_cli_addr_parse(const char *, int);
+extern int nl_cli_connect(struct nl_sock *, int);
+extern struct nl_sock * nl_cli_alloc_socket(void);
+extern int nl_cli_parse_dumptype(const char *);
+extern int nl_cli_confirm(struct nl_object *,
+ struct nl_dump_params *, int);
+
+extern struct nl_cache *nl_cli_alloc_cache(struct nl_sock *, const char *,
+ int (*ac)(struct nl_sock *, struct nl_cache **));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/data.h b/libnl_2/include/netlink/data.h
new file mode 100644
index 0000000..071159e
--- /dev/null
+++ b/libnl_2/include/netlink/data.h
@@ -0,0 +1,41 @@
+/*
+ * netlink/data.h Abstract Data
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_DATA_H_
+#define NETLINK_DATA_H_
+
+#include <netlink/netlink.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_data;
+
+/* General */
+extern struct nl_data * nl_data_alloc(void *, size_t);
+extern struct nl_data * nl_data_alloc_attr(struct nlattr *);
+extern struct nl_data * nl_data_clone(struct nl_data *);
+extern int nl_data_append(struct nl_data *, void *, size_t);
+extern void nl_data_free(struct nl_data *);
+
+/* Access Functions */
+extern void * nl_data_get(struct nl_data *);
+extern size_t nl_data_get_size(struct nl_data *);
+
+/* Misc */
+extern int nl_data_cmp(struct nl_data *, struct nl_data *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/errno.h b/libnl_2/include/netlink/errno.h
new file mode 100644
index 0000000..c8a376e
--- /dev/null
+++ b/libnl_2/include/netlink/errno.h
@@ -0,0 +1,60 @@
+/*
+ * netlink/errno.h Error Numbers
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_ERRNO_H_
+#define NETLINK_ERRNO_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NLE_SUCCESS 0
+#define NLE_FAILURE 1
+#define NLE_INTR 2
+#define NLE_BAD_SOCK 3
+#define NLE_AGAIN 4
+#define NLE_NOMEM 5
+#define NLE_EXIST 6
+#define NLE_INVAL 7
+#define NLE_RANGE 8
+#define NLE_MSGSIZE 9
+#define NLE_OPNOTSUPP 10
+#define NLE_AF_NOSUPPORT 11
+#define NLE_OBJ_NOTFOUND 12
+#define NLE_NOATTR 13
+#define NLE_MISSING_ATTR 14
+#define NLE_AF_MISMATCH 15
+#define NLE_SEQ_MISMATCH 16
+#define NLE_MSG_OVERFLOW 17
+#define NLE_MSG_TRUNC 18
+#define NLE_NOADDR 19
+#define NLE_SRCRT_NOSUPPORT 20
+#define NLE_MSG_TOOSHORT 21
+#define NLE_MSGTYPE_NOSUPPORT 22
+#define NLE_OBJ_MISMATCH 23
+#define NLE_NOCACHE 24
+#define NLE_BUSY 25
+#define NLE_PROTO_MISMATCH 26
+#define NLE_NOACCESS 27
+#define NLE_PERM 28
+#define NLE_PKTLOC_FILE 29
+
+#define NLE_MAX NLE_PKTLOC_FILE
+
+extern const char * nl_geterror(int);
+extern void nl_perror(int, const char *);
+extern int nl_syserr2nlerr(int);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/fib_lookup/lookup.h b/libnl_2/include/netlink/fib_lookup/lookup.h
new file mode 100644
index 0000000..8bf27b8
--- /dev/null
+++ b/libnl_2/include/netlink/fib_lookup/lookup.h
@@ -0,0 +1,42 @@
+/*
+ * netlink/fib_lookup/fib_lookup.h FIB Lookup
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_FIB_LOOKUP_H_
+#define NETLINK_FIB_LOOKUP_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+#include <netlink/fib_lookup/request.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct flnl_result;
+
+extern struct flnl_result * flnl_result_alloc(void);
+extern void flnl_result_put(struct flnl_result *);
+
+extern struct nl_cache * flnl_result_alloc_cache(void);
+
+extern int flnl_lookup_build_request(struct flnl_request *,
+ int,
+ struct nl_msg **);
+extern int flnl_lookup(struct nl_sock *,
+ struct flnl_request *,
+ struct nl_cache *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/fib_lookup/request.h b/libnl_2/include/netlink/fib_lookup/request.h
new file mode 100644
index 0000000..60e8820
--- /dev/null
+++ b/libnl_2/include/netlink/fib_lookup/request.h
@@ -0,0 +1,51 @@
+/*
+ * netlink/fib_lookup/request.h FIB Lookup Request
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_FIB_LOOKUP_REQUEST_H_
+#define NETLINK_FIB_LOOKUP_REQUEST_H_
+
+#include <netlink/netlink.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct flnl_request;
+
+#define REQUEST_CAST(ptr) ((struct flnl_request *) (ptr))
+
+extern struct flnl_request * flnl_request_alloc(void);
+
+extern void flnl_request_set_fwmark(struct flnl_request *,
+ uint64_t);
+extern uint64_t flnl_request_get_fwmark(struct flnl_request *);
+extern void flnl_request_set_tos(struct flnl_request *,
+ int);
+extern int flnl_request_get_tos(struct flnl_request *);
+extern void flnl_request_set_scope(struct flnl_request *,
+ int);
+extern int flnl_request_get_scope(struct flnl_request *);
+extern void flnl_request_set_table(struct flnl_request *,
+ int);
+extern int flnl_request_get_table(struct flnl_request *);
+extern int flnl_request_set_addr(struct flnl_request *,
+ struct nl_addr *);
+extern struct nl_addr * flnl_request_get_addr(struct flnl_request *);
+
+extern int flnl_request_cmp(struct flnl_request *,
+ struct flnl_request *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/genl/ctrl.h b/libnl_2/include/netlink/genl/ctrl.h
new file mode 100644
index 0000000..1ae62f4
--- /dev/null
+++ b/libnl_2/include/netlink/genl/ctrl.h
@@ -0,0 +1,37 @@
+/*
+ * netlink/genl/ctrl.h Generic Netlink Controller
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_GENL_CTRL_H_
+#define NETLINK_GENL_CTRL_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct genl_family;
+
+extern int genl_ctrl_alloc_cache(struct nl_sock *,
+ struct nl_cache **);
+extern struct genl_family * genl_ctrl_search(struct nl_cache *, int);
+extern struct genl_family * genl_ctrl_search_by_name(struct nl_cache *,
+ const char *);
+extern int genl_ctrl_resolve(struct nl_sock *,
+ const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/genl/family.h b/libnl_2/include/netlink/genl/family.h
new file mode 100644
index 0000000..74319e5
--- /dev/null
+++ b/libnl_2/include/netlink/genl/family.h
@@ -0,0 +1,50 @@
+/*
+ * netlink/genl/family.h Generic Netlink Family
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_GENL_FAMILY_H_
+#define NETLINK_GENL_FAMILY_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct genl_family;
+
+extern struct genl_family * genl_family_alloc(void);
+extern void genl_family_put(struct genl_family *);
+
+extern unsigned int genl_family_get_id(struct genl_family *);
+extern void genl_family_set_id(struct genl_family *,
+ unsigned int);
+extern char * genl_family_get_name(struct genl_family *);
+extern void genl_family_set_name(struct genl_family *,
+ const char *name);
+extern uint8_t genl_family_get_version(struct genl_family *);
+extern void genl_family_set_version(struct genl_family *,
+ uint8_t);
+extern uint32_t genl_family_get_hdrsize(struct genl_family *);
+extern void genl_family_set_hdrsize(struct genl_family *,
+ uint32_t);
+extern uint32_t genl_family_get_maxattr(struct genl_family *);
+extern void genl_family_set_maxattr(struct genl_family *,
+ uint32_t);
+
+extern int genl_family_add_op(struct genl_family *,
+ int, int);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/genl/genl.h b/libnl_2/include/netlink/genl/genl.h
new file mode 100644
index 0000000..3f3340c
--- /dev/null
+++ b/libnl_2/include/netlink/genl/genl.h
@@ -0,0 +1,47 @@
+/*
+ * netlink/genl/genl.h Generic Netlink
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_GENL_H_
+#define NETLINK_GENL_H_
+
+#include <netlink/netlink.h>
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int genl_connect(struct nl_sock *);
+
+extern int genl_send_simple(struct nl_sock *, int, int,
+ int, int);
+
+extern void * genlmsg_put(struct nl_msg *, uint32_t, uint32_t,
+ int, int, int, uint8_t, uint8_t);
+
+extern int genlmsg_valid_hdr(struct nlmsghdr *, int);
+extern int genlmsg_validate(struct nlmsghdr *, int, int,
+ struct nla_policy *);
+extern int genlmsg_parse(struct nlmsghdr *, int, struct nlattr **,
+ int, struct nla_policy *);
+extern void * genlmsg_data(const struct genlmsghdr *);
+extern int genlmsg_len(const struct genlmsghdr *);
+extern struct nlattr * genlmsg_attrdata(const struct genlmsghdr *, int);
+extern int genlmsg_attrlen(const struct genlmsghdr *, int);
+
+extern char * genl_op2name(int, int, char *, size_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/genl/mngt.h b/libnl_2/include/netlink/genl/mngt.h
new file mode 100644
index 0000000..8b0244f
--- /dev/null
+++ b/libnl_2/include/netlink/genl/mngt.h
@@ -0,0 +1,87 @@
+/*
+ * netlink/genl/mngt.h Generic Netlink Management
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_GENL_MNGT_H_
+#define NETLINK_GENL_MNGT_H_
+
+#include <netlink/netlink.h>
+#include <netlink/attr.h>
+#include <netlink/list.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_cache_ops;
+
+struct genl_info
+{
+ struct sockaddr_nl * who;
+ struct nlmsghdr * nlh;
+ struct genlmsghdr * genlhdr;
+ void * userhdr;
+ struct nlattr ** attrs;
+};
+
+/**
+ * @ingroup genl_mngt
+ * Generic Netlink Command
+ */
+struct genl_cmd
+{
+ /** Unique command identifier */
+ int c_id;
+
+ /** Name/description of command */
+ char * c_name;
+
+ /**
+ * Maximum attribute identifier, must be provided if
+ * a message parser is available.
+ */
+ int c_maxattr;
+
+ int (*c_msg_parser)(struct nl_cache_ops *,
+ struct genl_cmd *,
+ struct genl_info *, void *);
+
+ /**
+ * Attribute validation policy (optional)
+ */
+ struct nla_policy * c_attr_policy;
+};
+
+/**
+ * @ingroup genl_mngt
+ * Generic Netlink Operations
+ */
+struct genl_ops
+{
+ int o_family;
+ int o_id;
+ char * o_name;
+ struct nl_cache_ops * o_cache_ops;
+ struct genl_cmd * o_cmds;
+ int o_ncmds;
+
+ /* linked list of all genl cache operations */
+ struct nl_list_head o_list;
+};
+
+
+extern int genl_register(struct nl_cache_ops *);
+extern void genl_unregister(struct nl_cache_ops *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/handlers.h b/libnl_2/include/netlink/handlers.h
new file mode 100644
index 0000000..f373f58
--- /dev/null
+++ b/libnl_2/include/netlink/handlers.h
@@ -0,0 +1,144 @@
+/*
+ * netlink/handlers.c default netlink message handlers
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_HANDLERS_H_
+#define NETLINK_HANDLERS_H_
+
+#include <stdio.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <netlink/netlink-compat.h>
+#include <netlink/netlink-kernel.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_cb;
+struct nl_sock;
+struct nl_msg;
+struct ucred;
+
+/**
+ * @name Callback Typedefs
+ * @{
+ */
+
+/**
+ * nl_recvmsgs() callback for message processing customization
+ * @ingroup cb
+ * @arg msg netlink message being processed
+ * @arg arg argument passwd on through caller
+ */
+typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg);
+
+/**
+ * nl_recvmsgs() callback for error message processing customization
+ * @ingroup cb
+ * @arg nla netlink address of the peer
+ * @arg nlerr netlink error message being processed
+ * @arg arg argument passed on through caller
+ */
+typedef int (*nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla,
+ struct nlmsgerr *nlerr, void *arg);
+
+/** @} */
+
+/**
+ * Callback actions
+ * @ingroup cb
+ */
+enum nl_cb_action {
+ /** Proceed with wathever would come next */
+ NL_OK,
+ /** Skip this message */
+ NL_SKIP,
+ /** Stop parsing altogether and discard remaining messages */
+ NL_STOP,
+};
+
+/**
+ * Callback kinds
+ * @ingroup cb
+ */
+enum nl_cb_kind {
+ /** Default handlers (quiet) */
+ NL_CB_DEFAULT,
+ /** Verbose default handlers (error messages printed) */
+ NL_CB_VERBOSE,
+ /** Debug handlers for debugging */
+ NL_CB_DEBUG,
+ /** Customized handler specified by the user */
+ NL_CB_CUSTOM,
+ __NL_CB_KIND_MAX,
+};
+
+#define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
+
+/**
+ * Callback types
+ * @ingroup cb
+ */
+enum nl_cb_type {
+ /** Message is valid */
+ NL_CB_VALID,
+ /** Last message in a series of multi part messages received */
+ NL_CB_FINISH,
+ /** Report received that data was lost */
+ NL_CB_OVERRUN,
+ /** Message wants to be skipped */
+ NL_CB_SKIPPED,
+ /** Message is an acknowledge */
+ NL_CB_ACK,
+ /** Called for every message received */
+ NL_CB_MSG_IN,
+ /** Called for every message sent out except for nl_sendto() */
+ NL_CB_MSG_OUT,
+ /** Message is malformed and invalid */
+ NL_CB_INVALID,
+ /** Called instead of internal sequence number checking */
+ NL_CB_SEQ_CHECK,
+ /** Sending of an acknowledge message has been requested */
+ NL_CB_SEND_ACK,
+ __NL_CB_TYPE_MAX,
+};
+
+#define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
+
+extern struct nl_cb * nl_cb_alloc(enum nl_cb_kind);
+extern struct nl_cb * nl_cb_clone(struct nl_cb *);
+extern struct nl_cb * nl_cb_get(struct nl_cb *);
+extern void nl_cb_put(struct nl_cb *);
+
+extern int nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
+ nl_recvmsg_msg_cb_t, void *);
+extern int nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
+ nl_recvmsg_msg_cb_t, void *);
+extern int nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
+ void *);
+
+extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
+ int (*func)(struct nl_sock *,
+ struct nl_cb *));
+extern void nl_cb_overwrite_recv(struct nl_cb *,
+ int (*func)(struct nl_sock *,
+ struct sockaddr_nl *,
+ unsigned char **,
+ struct ucred **));
+extern void nl_cb_overwrite_send(struct nl_cb *,
+ int (*func)(struct nl_sock *,
+ struct nl_msg *));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/list.h b/libnl_2/include/netlink/list.h
new file mode 100644
index 0000000..28712ed
--- /dev/null
+++ b/libnl_2/include/netlink/list.h
@@ -0,0 +1,93 @@
+/*
+ * netlink/list.h Netlink List Utilities
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_LIST_H_
+#define NETLINK_LIST_H_
+
+struct nl_list_head
+{
+ struct nl_list_head * next;
+ struct nl_list_head * prev;
+};
+
+static inline void NL_INIT_LIST_HEAD(struct nl_list_head *list)
+{
+ list->next = list;
+ list->prev = list;
+}
+
+static inline void __nl_list_add(struct nl_list_head *obj,
+ struct nl_list_head *prev,
+ struct nl_list_head *next)
+{
+ prev->next = obj;
+ obj->prev = prev;
+ next->prev = obj;
+ obj->next = next;
+}
+
+static inline void nl_list_add_tail(struct nl_list_head *obj,
+ struct nl_list_head *head)
+{
+ __nl_list_add(obj, head->prev, head);
+}
+
+static inline void nl_list_add_head(struct nl_list_head *obj,
+ struct nl_list_head *head)
+{
+ __nl_list_add(obj, head, head->next);
+}
+
+static inline void nl_list_del(struct nl_list_head *obj)
+{
+ obj->next->prev = obj->prev;
+ obj->prev->next = obj->next;
+}
+
+static inline int nl_list_empty(struct nl_list_head *head)
+{
+ return head->next == head;
+}
+
+#define nl_container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - ((size_t) &((type *)0)->member));})
+
+#define nl_list_entry(ptr, type, member) \
+ nl_container_of(ptr, type, member)
+
+#define nl_list_at_tail(pos, head, member) \
+ ((pos)->member.next == (head))
+
+#define nl_list_at_head(pos, head, member) \
+ ((pos)->member.prev == (head))
+
+#define NL_LIST_HEAD(name) \
+ struct nl_list_head name = { &(name), &(name) }
+
+#define nl_list_first_entry(head, type, member) \
+ nl_list_entry((head)->next, type, member)
+
+#define nl_list_for_each_entry(pos, head, member) \
+ for (pos = nl_list_entry((head)->next, typeof(*pos), member); \
+ &(pos)->member != (head); \
+ (pos) = nl_list_entry((pos)->member.next, typeof(*(pos)), member))
+
+#define nl_list_for_each_entry_safe(pos, n, head, member) \
+ for (pos = nl_list_entry((head)->next, typeof(*pos), member), \
+ n = nl_list_entry(pos->member.next, typeof(*pos), member); \
+ &(pos)->member != (head); \
+ pos = n, n = nl_list_entry(n->member.next, typeof(*n), member))
+
+#define nl_init_list_head(head) \
+ do { (head)->next = (head); (head)->prev = (head); } while (0)
+
+#endif
diff --git a/libnl_2/include/netlink/msg.h b/libnl_2/include/netlink/msg.h
new file mode 100644
index 0000000..e9be456
--- /dev/null
+++ b/libnl_2/include/netlink/msg.h
@@ -0,0 +1,145 @@
+/*
+ * netlink/msg.c Netlink Messages Interface
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_MSG_H_
+#define NETLINK_MSG_H_
+
+#include <netlink/netlink.h>
+#include <netlink/object.h>
+#include <netlink/attr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NL_DONTPAD 0
+
+/**
+ * @ingroup msg
+ * @brief
+ * Will cause the netlink pid to be set to the pid assigned to
+ * the netlink handle (socket) just before sending the message off.
+ * @note Requires the use of nl_send_auto_complete()!
+ */
+#define NL_AUTO_PID 0
+
+/**
+ * @ingroup msg
+ * @brief
+ * May be used to refer to a sequence number which should be
+ * automatically set just before sending the message off.
+ * @note Requires the use of nl_send_auto_complete()!
+ */
+#define NL_AUTO_SEQ 0
+
+struct nl_msg;
+struct nl_tree;
+struct ucred;
+
+/* size calculations */
+extern int nlmsg_msg_size(int);
+extern int nlmsg_total_size(int);
+extern int nlmsg_padlen(int);
+
+/* payload access */
+extern void * nlmsg_data(const struct nlmsghdr *);
+extern int nlmsg_datalen(const struct nlmsghdr *);
+extern int nlmsg_len(const struct nlmsghdr *);
+extern void * nlmsg_tail(const struct nlmsghdr *);
+
+/* attribute access */
+extern struct nlattr * nlmsg_attrdata(const struct nlmsghdr *, int);
+extern int nlmsg_attrlen(const struct nlmsghdr *, int);
+
+/* message parsing */
+extern int nlmsg_valid_hdr(const struct nlmsghdr *, int);
+extern int nlmsg_ok(const struct nlmsghdr *, int);
+extern struct nlmsghdr * nlmsg_next(struct nlmsghdr *, int *);
+extern int nlmsg_parse(struct nlmsghdr *, int, struct nlattr **,
+ int, struct nla_policy *);
+extern struct nlattr * nlmsg_find_attr(struct nlmsghdr *, int, int);
+extern int nlmsg_validate(struct nlmsghdr *, int, int,
+ struct nla_policy *);
+
+extern struct nl_msg * nlmsg_alloc(void);
+extern struct nl_msg * nlmsg_alloc_size(size_t);
+extern struct nl_msg * nlmsg_alloc_simple(int, int);
+extern void nlmsg_set_default_size(size_t);
+extern struct nl_msg * nlmsg_inherit(struct nlmsghdr *);
+extern struct nl_msg * nlmsg_convert(struct nlmsghdr *);
+extern void * nlmsg_reserve(struct nl_msg *, size_t, int);
+extern int nlmsg_append(struct nl_msg *, void *, size_t, int);
+extern int nlmsg_expand(struct nl_msg *, size_t);
+
+extern struct nlmsghdr * nlmsg_put(struct nl_msg *, uint32_t, uint32_t,
+ int, int, int);
+extern struct nlmsghdr * nlmsg_hdr(struct nl_msg *);
+extern void nlmsg_get(struct nl_msg *);
+extern void nlmsg_free(struct nl_msg *);
+
+/* attribute modification */
+extern void nlmsg_set_proto(struct nl_msg *, int);
+extern int nlmsg_get_proto(struct nl_msg *);
+extern size_t nlmsg_get_max_size(struct nl_msg *);
+extern void nlmsg_set_src(struct nl_msg *, struct sockaddr_nl *);
+extern struct sockaddr_nl *nlmsg_get_src(struct nl_msg *);
+extern void nlmsg_set_dst(struct nl_msg *, struct sockaddr_nl *);
+extern struct sockaddr_nl *nlmsg_get_dst(struct nl_msg *);
+extern void nlmsg_set_creds(struct nl_msg *, struct ucred *);
+extern struct ucred * nlmsg_get_creds(struct nl_msg *);
+
+extern char * nl_nlmsgtype2str(int, char *, size_t);
+extern int nl_str2nlmsgtype(const char *);
+
+extern char * nl_nlmsg_flags2str(int, char *, size_t);
+
+extern int nl_msg_parse(struct nl_msg *,
+ void (*cb)(struct nl_object *, void *),
+ void *);
+
+extern void nl_msg_dump(struct nl_msg *, FILE *);
+
+/**
+ * @name Iterators
+ * @{
+ */
+
+/**
+ * @ingroup msg
+ * Iterate over a stream of attributes in a message
+ * @arg pos loop counter, set to current attribute
+ * @arg nlh netlink message header
+ * @arg hdrlen length of family header
+ * @arg rem initialized to len, holds bytes currently remaining in stream
+ */
+#define nlmsg_for_each_attr(pos, nlh, hdrlen, rem) \
+ nla_for_each_attr(pos, nlmsg_attrdata(nlh, hdrlen), \
+ nlmsg_attrlen(nlh, hdrlen), rem)
+
+/**
+ * Iterate over a stream of messages
+ * @arg pos loop counter, set to current message
+ * @arg head head of message stream
+ * @arg len length of message stream
+ * @arg rem initialized to len, holds bytes currently remaining in stream
+ */
+#define nlmsg_for_each_msg(pos, head, len, rem) \
+ for (pos = head, rem = len; \
+ nlmsg_ok(pos, rem); \
+ pos = nlmsg_next(pos, &(rem)))
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/netfilter/ct.h b/libnl_2/include/netlink/netfilter/ct.h
new file mode 100644
index 0000000..c4402b3
--- /dev/null
+++ b/libnl_2/include/netlink/netfilter/ct.h
@@ -0,0 +1,126 @@
+/*
+ * netlink/netfilter/ct.h Conntrack
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2007 Philip Craig <philipc@snapgear.com>
+ * Copyright (c) 2007 Secure Computing Corporation
+ */
+
+#ifndef NETLINK_CT_H_
+#define NETLINK_CT_H_
+
+#include <netlink/netlink.h>
+#include <netlink/addr.h>
+#include <netlink/cache.h>
+#include <netlink/msg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nfnl_ct;
+
+extern struct nl_object_ops ct_obj_ops;
+
+extern struct nfnl_ct * nfnl_ct_alloc(void);
+extern int nfnl_ct_alloc_cache(struct nl_sock *, struct nl_cache **);
+
+extern int nfnlmsg_ct_group(struct nlmsghdr *);
+extern int nfnlmsg_ct_parse(struct nlmsghdr *, struct nfnl_ct **);
+
+extern void nfnl_ct_get(struct nfnl_ct *);
+extern void nfnl_ct_put(struct nfnl_ct *);
+
+extern int nfnl_ct_dump_request(struct nl_sock *);
+
+extern int nfnl_ct_build_add_request(const struct nfnl_ct *, int,
+ struct nl_msg **);
+extern int nfnl_ct_add(struct nl_sock *, const struct nfnl_ct *, int);
+
+extern int nfnl_ct_build_delete_request(const struct nfnl_ct *, int,
+ struct nl_msg **);
+extern int nfnl_ct_delete(struct nl_sock *, const struct nfnl_ct *, int);
+
+extern int nfnl_ct_build_query_request(const struct nfnl_ct *, int,
+ struct nl_msg **);
+extern int nfnl_ct_query(struct nl_sock *, const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_family(struct nfnl_ct *, uint8_t);
+extern uint8_t nfnl_ct_get_family(const struct nfnl_ct *);
+
+extern void nfnl_ct_set_proto(struct nfnl_ct *, uint8_t);
+extern int nfnl_ct_test_proto(const struct nfnl_ct *);
+extern uint8_t nfnl_ct_get_proto(const struct nfnl_ct *);
+
+extern void nfnl_ct_set_tcp_state(struct nfnl_ct *, uint8_t);
+extern int nfnl_ct_test_tcp_state(const struct nfnl_ct *);
+extern uint8_t nfnl_ct_get_tcp_state(const struct nfnl_ct *);
+extern char * nfnl_ct_tcp_state2str(uint8_t, char *, size_t);
+extern int nfnl_ct_str2tcp_state(const char *name);
+
+extern void nfnl_ct_set_status(struct nfnl_ct *, uint32_t);
+extern void nfnl_ct_unset_status(struct nfnl_ct *, uint32_t);
+extern uint32_t nfnl_ct_get_status(const struct nfnl_ct *);
+extern char * nfnl_ct_status2str(int, char *, size_t);
+extern int nfnl_ct_str2status(const char *);
+
+extern void nfnl_ct_set_timeout(struct nfnl_ct *, uint32_t);
+extern int nfnl_ct_test_timeout(const struct nfnl_ct *);
+extern uint32_t nfnl_ct_get_timeout(const struct nfnl_ct *);
+
+extern void nfnl_ct_set_mark(struct nfnl_ct *, uint32_t);
+extern int nfnl_ct_test_mark(const struct nfnl_ct *);
+extern uint32_t nfnl_ct_get_mark(const struct nfnl_ct *);
+
+extern void nfnl_ct_set_use(struct nfnl_ct *, uint32_t);
+extern int nfnl_ct_test_use(const struct nfnl_ct *);
+extern uint32_t nfnl_ct_get_use(const struct nfnl_ct *);
+
+extern void nfnl_ct_set_id(struct nfnl_ct *, uint32_t);
+extern int nfnl_ct_test_id(const struct nfnl_ct *);
+extern uint32_t nfnl_ct_get_id(const struct nfnl_ct *);
+
+extern int nfnl_ct_set_src(struct nfnl_ct *, int, struct nl_addr *);
+extern struct nl_addr * nfnl_ct_get_src(const struct nfnl_ct *, int);
+
+extern int nfnl_ct_set_dst(struct nfnl_ct *, int, struct nl_addr *);
+extern struct nl_addr * nfnl_ct_get_dst(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_src_port(struct nfnl_ct *, int, uint16_t);
+extern int nfnl_ct_test_src_port(const struct nfnl_ct *, int);
+extern uint16_t nfnl_ct_get_src_port(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_dst_port(struct nfnl_ct *, int, uint16_t);
+extern int nfnl_ct_test_dst_port(const struct nfnl_ct *, int);
+extern uint16_t nfnl_ct_get_dst_port(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_icmp_id(struct nfnl_ct *, int, uint16_t);
+extern int nfnl_ct_test_icmp_id(const struct nfnl_ct *, int);
+extern uint16_t nfnl_ct_get_icmp_id(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_icmp_type(struct nfnl_ct *, int, uint8_t);
+extern int nfnl_ct_test_icmp_type(const struct nfnl_ct *, int);
+extern uint8_t nfnl_ct_get_icmp_type(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_icmp_code(struct nfnl_ct *, int, uint8_t);
+extern int nfnl_ct_test_icmp_code(const struct nfnl_ct *, int);
+extern uint8_t nfnl_ct_get_icmp_code(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_packets(struct nfnl_ct *, int, uint64_t);
+extern int nfnl_ct_test_packets(const struct nfnl_ct *, int);
+extern uint64_t nfnl_ct_get_packets(const struct nfnl_ct *,int);
+
+extern void nfnl_ct_set_bytes(struct nfnl_ct *, int, uint64_t);
+extern int nfnl_ct_test_bytes(const struct nfnl_ct *, int);
+extern uint64_t nfnl_ct_get_bytes(const struct nfnl_ct *, int);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/netlink-compat.h b/libnl_2/include/netlink/netlink-compat.h
new file mode 100644
index 0000000..17ec9fc
--- /dev/null
+++ b/libnl_2/include/netlink/netlink-compat.h
@@ -0,0 +1,50 @@
+/*
+ * netlink/netlink-compat.h Netlink Compatability
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_COMPAT_H_
+#define NETLINK_COMPAT_H_
+
+#if !defined _LINUX_SOCKET_H && !defined _BITS_SOCKADDR_H
+typedef unsigned short sa_family_t;
+#endif
+
+#ifndef IFNAMSIZ
+/** Maximum length of a interface name */
+#define IFNAMSIZ 16
+#endif
+
+/* patch 2.4.x if_arp */
+#ifndef ARPHRD_INFINIBAND
+#define ARPHRD_INFINIBAND 32
+#endif
+
+/* patch 2.4.x eth header file */
+#ifndef ETH_P_MPLS_UC
+#define ETH_P_MPLS_UC 0x8847
+#endif
+
+#ifndef ETH_P_MPLS_MC
+#define ETH_P_MPLS_MC 0x8848
+#endif
+
+#ifndef ETH_P_EDP2
+#define ETH_P_EDP2 0x88A2
+#endif
+
+#ifndef ETH_P_HDLC
+#define ETH_P_HDLC 0x0019
+#endif
+
+#ifndef AF_LLC
+#define AF_LLC 26
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/netlink-kernel.h b/libnl_2/include/netlink/netlink-kernel.h
new file mode 100644
index 0000000..a0f5535
--- /dev/null
+++ b/libnl_2/include/netlink/netlink-kernel.h
@@ -0,0 +1,196 @@
+#ifndef __LINUX_NETLINK_H
+#define __LINUX_NETLINK_H
+
+/**
+ * Netlink socket address
+ * @ingroup nl
+ */
+struct sockaddr_nl
+{
+ /** socket family (AF_NETLINK) */
+ sa_family_t nl_family;
+
+ /** Padding (unused) */
+ unsigned short nl_pad;
+
+ /** Unique process ID */
+ uint32_t nl_pid;
+
+ /** Multicast group subscriptions */
+ uint32_t nl_groups;
+};
+
+/**
+ * Netlink message header
+ * @ingroup msg
+ */
+struct nlmsghdr
+{
+ /**
+ * Length of message including header.
+ */
+ uint32_t nlmsg_len;
+
+ /**
+ * Message type (content type)
+ */
+ uint16_t nlmsg_type;
+
+ /**
+ * Message flags
+ */
+ uint16_t nlmsg_flags;
+
+ /**
+ * Sequence number
+ */
+ uint32_t nlmsg_seq;
+
+ /**
+ * Netlink PID of the proccess sending the message.
+ */
+ uint32_t nlmsg_pid;
+};
+
+/**
+ * @name Standard message flags
+ * @{
+ */
+
+/**
+ * Must be set on all request messages (typically from user space to
+ * kernel space).
+ * @ingroup msg
+ */
+#define NLM_F_REQUEST 1
+
+/**
+ * Indicates the message is part of a multipart message terminated
+ * by NLMSG_DONE.
+ */
+#define NLM_F_MULTI 2
+
+/**
+ * Request for an acknowledgment on success.
+ */
+#define NLM_F_ACK 4
+
+/**
+ * Echo this request
+ */
+#define NLM_F_ECHO 8
+
+/** @} */
+
+/**
+ * @name Additional message flags for GET requests
+ * @{
+ */
+
+/**
+ * Return the complete table instead of a single entry.
+ * @ingroup msg
+ */
+#define NLM_F_ROOT 0x100
+
+/**
+ * Return all entries matching criteria passed in message content.
+ */
+#define NLM_F_MATCH 0x200
+
+/**
+ * Return an atomic snapshot of the table being referenced. This
+ * may require special privileges because it has the potential to
+ * interrupt service in the FE for a longer time.
+ */
+#define NLM_F_ATOMIC 0x400
+
+/**
+ * Dump all entries
+ */
+#define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
+
+/** @} */
+
+/**
+ * @name Additional messsage flags for NEW requests
+ * @{
+ */
+
+/**
+ * Replace existing matching config object with this request.
+ * @ingroup msg
+ */
+#define NLM_F_REPLACE 0x100
+
+/**
+ * Don't replace the config object if it already exists.
+ */
+#define NLM_F_EXCL 0x200
+
+/**
+ * Create config object if it doesn't already exist.
+ */
+#define NLM_F_CREATE 0x400
+
+/**
+ * Add to the end of the object list.
+ */
+#define NLM_F_APPEND 0x800
+
+/** @} */
+
+/**
+ * @name Standard Message types
+ * @{
+ */
+
+/**
+ * No operation, message must be ignored
+ * @ingroup msg
+ */
+#define NLMSG_NOOP 0x1
+
+/**
+ * The message signals an error and the payload contains a nlmsgerr
+ * structure. This can be looked at as a NACK and typically it is
+ * from FEC to CPC.
+ */
+#define NLMSG_ERROR 0x2
+
+/**
+ * Message terminates a multipart message.
+ */
+#define NLMSG_DONE 0x3
+
+/**
+ * The message signals that data got lost
+ */
+#define NLMSG_OVERRUN 0x4
+
+/**
+ * Lower limit of reserved message types
+ */
+#define NLMSG_MIN_TYPE 0x10
+
+/** @} */
+
+/**
+ * Netlink error message
+ * @ingroup msg
+ */
+struct nlmsgerr
+{
+ /** Error code (errno number) */
+ int error;
+
+ /** Original netlink message causing the error */
+ struct nlmsghdr msg;
+};
+
+struct nl_pktinfo
+{
+ __u32 group;
+};
+
+#endif /* __LINUX_NETLINK_H */
diff --git a/libnl_2/include/netlink/netlink.h b/libnl_2/include/netlink/netlink.h
new file mode 100644
index 0000000..1cfe220
--- /dev/null
+++ b/libnl_2/include/netlink/netlink.h
@@ -0,0 +1,81 @@
+/*
+ * netlink/netlink.h Netlink Interface
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_NETLINK_H_
+#define NETLINK_NETLINK_H_
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/poll.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <netdb.h>
+#include <netlink/netlink-compat.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <linux/genetlink.h>
+#include <linux/netfilter/nfnetlink.h>
+#include <netlink/version.h>
+#include <netlink/errno.h>
+#include <netlink/types.h>
+#include <netlink/handlers.h>
+#include <netlink/socket.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ucred;
+
+extern int nl_debug;
+extern struct nl_dump_params nl_debug_dp;
+
+/* Connection Management */
+extern int nl_connect(struct nl_sock *, int);
+extern void nl_close(struct nl_sock *);
+
+/* Send */
+extern int nl_sendto(struct nl_sock *, void *, size_t);
+extern int nl_sendmsg(struct nl_sock *, struct nl_msg *,
+ struct msghdr *);
+extern int nl_send(struct nl_sock *, struct nl_msg *);
+extern int nl_send_iovec(struct nl_sock *, struct nl_msg *,
+ struct iovec *, unsigned);
+extern void nl_auto_complete(struct nl_sock *,
+ struct nl_msg *);
+extern int nl_send_auto_complete(struct nl_sock *,
+ struct nl_msg *);
+extern int nl_send_simple(struct nl_sock *, int, int,
+ void *, size_t);
+
+/* Receive */
+extern int nl_recv(struct nl_sock *,
+ struct sockaddr_nl *, unsigned char **,
+ struct ucred **);
+
+extern int nl_recvmsgs(struct nl_sock *, struct nl_cb *);
+
+extern int nl_recvmsgs_default(struct nl_sock *);
+
+extern int nl_wait_for_ack(struct nl_sock *);
+
+/* Netlink Family Translations */
+extern char * nl_nlfamily2str(int, char *, size_t);
+extern int nl_str2nlfamily(const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/object-api.h b/libnl_2/include/netlink/object-api.h
new file mode 100644
index 0000000..b3337f0
--- /dev/null
+++ b/libnl_2/include/netlink/object-api.h
@@ -0,0 +1,342 @@
+/*
+ * netlink/object-api.c Object API
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2007 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_OBJECT_API_H_
+#define NETLINK_OBJECT_API_H_
+
+#include <netlink/netlink.h>
+#include <netlink/utils.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @ingroup object
+ * @defgroup object_api Object API
+ * @brief
+ *
+ * @par 1) Object Definition
+ * @code
+ * // Define your object starting with the common object header
+ * struct my_obj {
+ * NLHDR_COMMON
+ * int my_data;
+ * };
+ *
+ * // Fill out the object operations structure
+ * struct nl_object_ops my_ops = {
+ * .oo_name = "my_obj",
+ * .oo_size = sizeof(struct my_obj),
+ * };
+ *
+ * // At this point the object can be allocated, you may want to provide a
+ * // separate _alloc() function to ease allocting objects of this kind.
+ * struct nl_object *obj = nl_object_alloc(&my_ops);
+ *
+ * // And release it again...
+ * nl_object_put(obj);
+ * @endcode
+ *
+ * @par 2) Allocating additional data
+ * @code
+ * // You may require to allocate additional data and store it inside
+ * // object, f.e. assuming there is a field `ptr'.
+ * struct my_obj {
+ * NLHDR_COMMON
+ * void * ptr;
+ * };
+ *
+ * // And at some point you may assign allocated data to this field:
+ * my_obj->ptr = calloc(1, ...);
+ *
+ * // In order to not introduce any memory leaks you have to release
+ * // this data again when the last reference is given back.
+ * static void my_obj_free_data(struct nl_object *obj)
+ * {
+ * struct my_obj *my_obj = nl_object_priv(obj);
+ *
+ * free(my_obj->ptr);
+ * }
+ *
+ * // Also when the object is cloned, you must ensure for your pointer
+ * // stay valid even if one of the clones is freed by either making
+ * // a clone as well or increase the reference count.
+ * static int my_obj_clone(struct nl_object *src, struct nl_object *dst)
+ * {
+ * struct my_obj *my_src = nl_object_priv(src);
+ * struct my_obj *my_dst = nl_object_priv(dst);
+ *
+ * if (src->ptr) {
+ * dst->ptr = calloc(1, ...);
+ * memcpy(dst->ptr, src->ptr, ...);
+ * }
+ * }
+ *
+ * struct nl_object_ops my_ops = {
+ * ...
+ * .oo_free_data = my_obj_free_data,
+ * .oo_clone = my_obj_clone,
+ * };
+ * @endcode
+ *
+ * @par 3) Object Dumping
+ * @code
+ * static int my_obj_dump_detailed(struct nl_object *obj,
+ * struct nl_dump_params *params)
+ * {
+ * struct my_obj *my_obj = nl_object_priv(obj);
+ *
+ * // It is absolutely essential to use nl_dump() when printing
+ * // any text to make sure the dumping parameters are respected.
+ * nl_dump(params, "Obj Integer: %d\n", my_obj->my_int);
+ *
+ * // Before we can dump the next line, make sure to prefix
+ * // this line correctly.
+ * nl_new_line(params);
+ *
+ * // You may also split a line into multiple nl_dump() calls.
+ * nl_dump(params, "String: %s ", my_obj->my_string);
+ * nl_dump(params, "String-2: %s\n", my_obj->another_string);
+ * }
+ *
+ * struct nl_object_ops my_ops = {
+ * ...
+ * .oo_dump[NL_DUMP_FULL] = my_obj_dump_detailed,
+ * };
+ * @endcode
+ *
+ * @par 4) Object Attributes
+ * @code
+ * // The concept of object attributes is optional but can ease the typical
+ * // case of objects that have optional attributes, e.g. a route may have a
+ * // nexthop assigned but it is not required to.
+ *
+ * // The first step to define your object specific bitmask listing all
+ * // attributes
+ * #define MY_ATTR_FOO (1<<0)
+ * #define MY_ATTR_BAR (1<<1)
+ *
+ * // When assigning an optional attribute to the object, make sure
+ * // to mark its availability.
+ * my_obj->foo = 123123;
+ * my_obj->ce_mask |= MY_ATTR_FOO;
+ *
+ * // At any time you may use this mask to check for the availability
+ * // of the attribute, e.g. while dumping
+ * if (my_obj->ce_mask & MY_ATTR_FOO)
+ * nl_dump(params, "foo %d ", my_obj->foo);
+ *
+ * // One of the big advantages of this concept is that it allows for
+ * // standardized comparisons which make it trivial for caches to
+ * // identify unique objects by use of unified comparison functions.
+ * // In order for it to work, your object implementation must provide
+ * // a comparison function and define a list of attributes which
+ * // combined together make an object unique.
+ *
+ * static int my_obj_compare(struct nl_object *_a, struct nl_object *_b,
+ * uint32_t attrs, int flags)
+ * {
+ * struct my_obj *a = nl_object_priv(_a):
+ * struct my_obj *b = nl_object_priv(_b):
+ * int diff = 0;
+ *
+ * // We help ourselves in defining our own DIFF macro which will
+ * // call ATTR_DIFF() on both objects which will make sure to only
+ * // compare the attributes if required.
+ * #define MY_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, MY_ATTR_##ATTR, a, b, EXPR)
+ *
+ * // Call our own diff macro for each attribute to build a bitmask
+ * // representing the attributes which mismatch.
+ * diff |= MY_DIFF(FOO, a->foo != b->foo)
+ * diff |= MY_DIFF(BAR, strcmp(a->bar, b->bar))
+ *
+ * return diff;
+ * }
+ *
+ * // In order to identify identical objects with differing attributes
+ * // you must specify the attributes required to uniquely identify
+ * // your object. Make sure to not include too many attributes, this
+ * // list is used when caches look for an old version of an object.
+ * struct nl_object_ops my_ops = {
+ * ...
+ * .oo_id_attrs = MY_ATTR_FOO,
+ * .oo_compare = my_obj_compare,
+ * };
+ * @endcode
+ * @{
+ */
+
+/**
+ * Common Object Header
+ *
+ * This macro must be included as first member in every object
+ * definition to allow objects to be cached.
+ */
+#define NLHDR_COMMON \
+ int ce_refcnt; \
+ struct nl_object_ops * ce_ops; \
+ struct nl_cache * ce_cache; \
+ struct nl_list_head ce_list; \
+ int ce_msgtype; \
+ int ce_flags; \
+ uint32_t ce_mask;
+
+/**
+ * Return true if attribute is available in both objects
+ * @arg A an object
+ * @arg B another object
+ * @arg ATTR attribute bit
+ *
+ * @return True if the attribute is available, otherwise false is returned.
+ */
+#define AVAILABLE(A, B, ATTR) (((A)->ce_mask & (B)->ce_mask) & (ATTR))
+
+/**
+ * Return true if attribute is available in only one of both objects
+ * @arg A an object
+ * @arg B another object
+ * @arg ATTR attribute bit
+ *
+ * @return True if the attribute is available in only one of both objects,
+ * otherwise false is returned.
+ */
+#define AVAILABLE_MISMATCH(A, B, ATTR) (((A)->ce_mask ^ (B)->ce_mask) & (ATTR))
+
+/**
+ * Return true if attributes mismatch
+ * @arg A an object
+ * @arg B another object
+ * @arg ATTR attribute bit
+ * @arg EXPR Comparison expression
+ *
+ * This function will check if the attribute in question is available
+ * in both objects, if not this will count as a mismatch.
+ *
+ * If available the function will execute the expression which must
+ * return true if the attributes mismatch.
+ *
+ * @return True if the attribute mismatch, or false if they match.
+ */
+#define ATTR_MISMATCH(A, B, ATTR, EXPR) (AVAILABLE_MISMATCH(A, B, ATTR) || \
+ (AVAILABLE(A, B, ATTR) && (EXPR)))
+
+/**
+ * Return attribute bit if attribute does not match
+ * @arg LIST list of attributes to be compared
+ * @arg ATTR attribute bit
+ * @arg A an object
+ * @arg B another object
+ * @arg EXPR Comparison expression
+ *
+ * This function will check if the attribute in question is available
+ * in both objects, if not this will count as a mismatch.
+ *
+ * If available the function will execute the expression which must
+ * return true if the attributes mismatch.
+ *
+ * In case the attributes mismatch, the attribute is returned, otherwise
+ * 0 is returned.
+ *
+ * @code
+ * diff |= ATTR_DIFF(attrs, MY_ATTR_FOO, a, b, a->foo != b->foo);
+ * @endcode
+ */
+#define ATTR_DIFF(LIST, ATTR, A, B, EXPR) \
+({ int diff = 0; \
+ if (((LIST) & (ATTR)) && ATTR_MISMATCH(A, B, ATTR, EXPR)) \
+ diff = ATTR; \
+ diff; })
+
+/**
+ * Object Operations
+ */
+struct nl_object_ops
+{
+ /**
+ * Unique name of object type
+ *
+ * Must be in the form family/name, e.g. "route/addr"
+ */
+ char * oo_name;
+
+ /** Size of object including its header */
+ size_t oo_size;
+
+ /* List of attributes needed to uniquely identify the object */
+ uint32_t oo_id_attrs;
+
+ /**
+ * Constructor function
+ *
+ * Will be called when a new object of this type is allocated.
+ * Can be used to initialize members such as lists etc.
+ */
+ void (*oo_constructor)(struct nl_object *);
+
+ /**
+ * Destructor function
+ *
+ * Will be called when an object is freed. Must free all
+ * resources which may have been allocated as part of this
+ * object.
+ */
+ void (*oo_free_data)(struct nl_object *);
+
+ /**
+ * Cloning function
+ *
+ * Will be called when an object needs to be cloned. Please
+ * note that the generic object code will make an exact
+ * copy of the object first, therefore you only need to take
+ * care of members which require reference counting etc.
+ *
+ * May return a negative error code to abort cloning.
+ */
+ int (*oo_clone)(struct nl_object *, struct nl_object *);
+
+ /**
+ * Dumping functions
+ *
+ * Will be called when an object is dumped. The implementations
+ * have to use nl_dump(), nl_dump_line(), and nl_new_line() to
+ * dump objects.
+ *
+ * The functions must return the number of lines printed.
+ */
+ void (*oo_dump[NL_DUMP_MAX+1])(struct nl_object *,
+ struct nl_dump_params *);
+
+ /**
+ * Comparison function
+ *
+ * Will be called when two objects of the same type are
+ * compared. It takes the two objects in question, an object
+ * specific bitmask defining which attributes should be
+ * compared and flags to control the behaviour.
+ *
+ * The function must return a bitmask with the relevant bit
+ * set for each attribute that mismatches.
+ */
+ int (*oo_compare)(struct nl_object *, struct nl_object *,
+ uint32_t, int);
+
+
+ char *(*oo_attrs2str)(int, char *, size_t);
+};
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/object.h b/libnl_2/include/netlink/object.h
new file mode 100644
index 0000000..ef1ed9f
--- /dev/null
+++ b/libnl_2/include/netlink/object.h
@@ -0,0 +1,69 @@
+/*
+ * netlink/object.c Generic Cacheable Object
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_OBJECT_H_
+#define NETLINK_OBJECT_H_
+
+#include <netlink/netlink.h>
+#include <netlink/utils.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_cache;
+struct nl_object;
+struct nl_object_ops;
+
+#define OBJ_CAST(ptr) ((struct nl_object *) (ptr))
+
+/* General */
+extern struct nl_object * nl_object_alloc(struct nl_object_ops *);
+extern int nl_object_alloc_name(const char *,
+ struct nl_object **);
+extern void nl_object_free(struct nl_object *);
+extern struct nl_object * nl_object_clone(struct nl_object *obj);
+extern void nl_object_get(struct nl_object *);
+extern void nl_object_put(struct nl_object *);
+extern int nl_object_shared(struct nl_object *);
+extern void nl_object_dump(struct nl_object *,
+ struct nl_dump_params *);
+extern int nl_object_identical(struct nl_object *,
+ struct nl_object *);
+extern uint32_t nl_object_diff(struct nl_object *,
+ struct nl_object *);
+extern int nl_object_match_filter(struct nl_object *,
+ struct nl_object *);
+extern char * nl_object_attrs2str(struct nl_object *,
+ uint32_t attrs, char *buf,
+ size_t);
+extern char * nl_object_attr_list(struct nl_object *,
+ char *, size_t);
+
+/* Marks */
+extern void nl_object_mark(struct nl_object *);
+extern void nl_object_unmark(struct nl_object *);
+extern int nl_object_is_marked(struct nl_object *);
+
+/* Access Functions */
+extern int nl_object_get_refcnt(struct nl_object *);
+extern struct nl_cache * nl_object_get_cache(struct nl_object *);
+static inline void * nl_object_priv(struct nl_object *obj)
+{
+ return obj;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/addr.h b/libnl_2/include/netlink/route/addr.h
new file mode 100644
index 0000000..1381486
--- /dev/null
+++ b/libnl_2/include/netlink/route/addr.h
@@ -0,0 +1,91 @@
+/*
+ * netlink/route/addr.c rtnetlink addr layer
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2006 Baruch Even <baruch@ev-en.org>,
+ * Mediatrix Telecom, inc. <ericb@mediatrix.com>
+ */
+
+#ifndef NETADDR_ADDR_H_
+#define NETADDR_ADDR_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_addr;
+
+/* General */
+extern struct rtnl_addr *rtnl_addr_alloc(void);
+extern void rtnl_addr_put(struct rtnl_addr *);
+
+extern int rtnl_addr_alloc_cache(struct nl_sock *, struct nl_cache **);
+
+extern int rtnl_addr_build_add_request(struct rtnl_addr *, int,
+ struct nl_msg **);
+extern int rtnl_addr_add(struct nl_sock *, struct rtnl_addr *, int);
+
+extern int rtnl_addr_build_delete_request(struct rtnl_addr *, int,
+ struct nl_msg **);
+extern int rtnl_addr_delete(struct nl_sock *,
+ struct rtnl_addr *, int);
+
+extern char * rtnl_addr_flags2str(int, char *, size_t);
+extern int rtnl_addr_str2flags(const char *);
+
+extern int rtnl_addr_set_label(struct rtnl_addr *, const char *);
+extern char * rtnl_addr_get_label(struct rtnl_addr *);
+
+extern void rtnl_addr_set_ifindex(struct rtnl_addr *, int);
+extern int rtnl_addr_get_ifindex(struct rtnl_addr *);
+
+extern void rtnl_addr_set_family(struct rtnl_addr *, int);
+extern int rtnl_addr_get_family(struct rtnl_addr *);
+
+extern void rtnl_addr_set_prefixlen(struct rtnl_addr *, int);
+extern int rtnl_addr_get_prefixlen(struct rtnl_addr *);
+
+extern void rtnl_addr_set_scope(struct rtnl_addr *, int);
+extern int rtnl_addr_get_scope(struct rtnl_addr *);
+
+extern void rtnl_addr_set_flags(struct rtnl_addr *, unsigned int);
+extern void rtnl_addr_unset_flags(struct rtnl_addr *, unsigned int);
+extern unsigned int rtnl_addr_get_flags(struct rtnl_addr *);
+
+extern int rtnl_addr_set_local(struct rtnl_addr *,
+ struct nl_addr *);
+extern struct nl_addr *rtnl_addr_get_local(struct rtnl_addr *);
+
+extern int rtnl_addr_set_peer(struct rtnl_addr *, struct nl_addr *);
+extern struct nl_addr *rtnl_addr_get_peer(struct rtnl_addr *);
+
+extern int rtnl_addr_set_broadcast(struct rtnl_addr *, struct nl_addr *);
+extern struct nl_addr *rtnl_addr_get_broadcast(struct rtnl_addr *);
+
+extern int rtnl_addr_set_multicast(struct rtnl_addr *, struct nl_addr *);
+extern struct nl_addr *rtnl_addr_get_multicast(struct rtnl_addr *);
+
+extern int rtnl_addr_set_anycast(struct rtnl_addr *, struct nl_addr *);
+extern struct nl_addr *rtnl_addr_get_anycast(struct rtnl_addr *);
+
+extern uint32_t rtnl_addr_get_valid_lifetime(struct rtnl_addr *);
+extern void rtnl_addr_set_valid_lifetime(struct rtnl_addr *, uint32_t);
+extern uint32_t rtnl_addr_get_preferred_lifetime(struct rtnl_addr *);
+extern void rtnl_addr_set_preferred_lifetime(struct rtnl_addr *, uint32_t);
+extern uint32_t rtnl_addr_get_create_time(struct rtnl_addr *);
+extern uint32_t rtnl_addr_get_last_update_time(struct rtnl_addr *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/class.h b/libnl_2/include/netlink/route/class.h
new file mode 100644
index 0000000..480095e
--- /dev/null
+++ b/libnl_2/include/netlink/route/class.h
@@ -0,0 +1,73 @@
+/*
+ * netlink/route/class.h Classes
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_CLASS_H_
+#define NETLINK_CLASS_H_
+
+#include <netlink/netlink.h>
+#include <netlink/route/tc.h>
+#include <netlink/route/qdisc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_class;
+
+extern struct nl_object_ops class_obj_ops;
+
+extern struct rtnl_class * rtnl_class_alloc(void);
+extern void rtnl_class_put(struct rtnl_class *);
+extern int rtnl_class_alloc_cache(struct nl_sock *, int,
+ struct nl_cache **);
+extern struct rtnl_class *rtnl_class_get(struct nl_cache *, int, uint32_t);
+
+/* leaf qdisc access */
+extern struct rtnl_qdisc * rtnl_class_leaf_qdisc(struct rtnl_class *,
+ struct nl_cache *);
+
+extern int rtnl_class_build_add_request(struct rtnl_class *, int,
+ struct nl_msg **);
+extern int rtnl_class_add(struct nl_sock *, struct rtnl_class *,
+ int);
+
+extern int rtnl_class_build_delete_request(struct rtnl_class *,
+ struct nl_msg **);
+extern int rtnl_class_delete(struct nl_sock *, struct rtnl_class *);
+
+extern void rtnl_class_set_ifindex(struct rtnl_class *, int);
+extern int rtnl_class_get_ifindex(struct rtnl_class *);
+extern void rtnl_class_set_handle(struct rtnl_class *, uint32_t);
+extern uint32_t rtnl_class_get_handle(struct rtnl_class *);
+extern void rtnl_class_set_parent(struct rtnl_class *, uint32_t);
+extern uint32_t rtnl_class_get_parent(struct rtnl_class *);
+extern void rtnl_class_set_kind(struct rtnl_class *, const char *);
+extern char * rtnl_class_get_kind(struct rtnl_class *);
+extern uint64_t rtnl_class_get_stat(struct rtnl_class *,
+ enum rtnl_tc_stats_id);
+
+/* iterators */
+extern void rtnl_class_foreach_child(struct rtnl_class *,
+ struct nl_cache *,
+ void (*cb)(struct nl_object *,
+ void *),
+ void *);
+extern void rtnl_class_foreach_cls(struct rtnl_class *,
+ struct nl_cache *,
+ void (*cb)(struct nl_object *,
+ void *),
+ void *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/classifier.h b/libnl_2/include/netlink/route/classifier.h
new file mode 100644
index 0000000..d9c3d21
--- /dev/null
+++ b/libnl_2/include/netlink/route/classifier.h
@@ -0,0 +1,62 @@
+/*
+ * netlink/route/classifier.h Classifiers
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_CLASSIFIER_H_
+#define NETLINK_CLASSIFIER_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/route/tc.h>
+#include <netlink/utils.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern struct nl_object_ops cls_obj_ops;
+
+extern struct rtnl_cls *rtnl_cls_alloc(void);
+extern void rtnl_cls_put(struct rtnl_cls *);
+
+extern int rtnl_cls_alloc_cache(struct nl_sock *, int, uint32_t,
+ struct nl_cache **);
+
+extern int rtnl_cls_build_add_request(struct rtnl_cls *, int,
+ struct nl_msg **);
+extern int rtnl_cls_add(struct nl_sock *, struct rtnl_cls *, int);
+
+extern int rtnl_cls_build_change_request(struct rtnl_cls *, int,
+ struct nl_msg **);
+extern int rtnl_cls_build_delete_request(struct rtnl_cls *, int,
+ struct nl_msg **);
+extern int rtnl_cls_delete(struct nl_sock *, struct rtnl_cls *, int);
+
+extern void rtnl_cls_set_ifindex(struct rtnl_cls *, int);
+extern int rtnl_cls_get_ifindex(struct rtnl_cls *);
+extern void rtnl_cls_set_handle(struct rtnl_cls *, uint32_t);
+extern void rtnl_cls_set_parent(struct rtnl_cls *, uint32_t);
+extern uint32_t rtnl_cls_get_parent(struct rtnl_cls *);
+extern int rtnl_cls_set_kind(struct rtnl_cls *, const char *);
+extern struct rtnl_cls_ops *rtnl_cls_get_ops(struct rtnl_cls *);
+
+extern void rtnl_cls_set_prio(struct rtnl_cls *, uint16_t);
+extern uint16_t rtnl_cls_get_prio(struct rtnl_cls *);
+
+extern void rtnl_cls_set_protocol(struct rtnl_cls *, uint16_t);
+extern uint16_t rtnl_cls_get_protocol(struct rtnl_cls *);
+
+extern void *rtnl_cls_data(struct rtnl_cls *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/cls/ematch.h b/libnl_2/include/netlink/route/cls/ematch.h
new file mode 100644
index 0000000..c4292bf
--- /dev/null
+++ b/libnl_2/include/netlink/route/cls/ematch.h
@@ -0,0 +1,73 @@
+/*
+ * netlink/route/cls/ematch.h Extended Matches
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_CLS_EMATCH_H_
+#define NETLINK_CLS_EMATCH_H_
+
+#include <netlink/netlink.h>
+#include <netlink/route/classifier.h>
+#include <linux/pkt_cls.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_ematch;
+struct rtnl_ematch_tree;
+
+struct rtnl_ematch_ops
+{
+ int eo_kind;
+ const char * eo_name;
+ size_t eo_datalen;
+
+ int (*eo_parse)(struct rtnl_ematch *,
+ void *, size_t);
+ void (*eo_dump)(struct rtnl_ematch *,
+ struct nl_dump_params *);
+ struct nl_list_head eo_list;
+};
+
+extern int rtnl_ematch_register(struct rtnl_ematch_ops *);
+extern int rtnl_ematch_unregister(struct rtnl_ematch_ops *);
+
+extern struct rtnl_ematch_ops *
+ rtnl_ematch_lookup_ops(int);
+extern struct rtnl_ematch_ops *
+ rtnl_ematch_lookup_ops_name(const char *);
+
+extern struct rtnl_ematch *
+ rtnl_ematch_alloc(struct rtnl_ematch_ops *);
+extern void rtnl_ematch_add_child(struct rtnl_ematch *,
+ struct rtnl_ematch *);
+extern void rtnl_ematch_unlink(struct rtnl_ematch *);
+extern void rtnl_ematch_free(struct rtnl_ematch *);
+
+extern void * rtnl_ematch_data(struct rtnl_ematch *);
+extern void rtnl_ematch_set_flags(struct rtnl_ematch *, uint16_t);
+extern void rtnl_ematch_unset_flags(struct rtnl_ematch *, uint16_t);
+extern uint16_t rtnl_ematch_get_flags(struct rtnl_ematch *);
+
+extern struct rtnl_ematch_tree *
+ rtnl_ematch_tree_alloc(uint16_t);
+extern void rtnl_ematch_tree_free(struct rtnl_ematch_tree *);
+
+extern int rtnl_ematch_parse(struct nlattr *, struct rtnl_ematch_tree **);
+extern void rtnl_ematch_tree_add_tail(struct rtnl_ematch_tree *,
+ struct rtnl_ematch *);
+extern void rtnl_ematch_tree_dump(struct rtnl_ematch_tree *,
+ struct nl_dump_params *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/link.h b/libnl_2/include/netlink/route/link.h
new file mode 100644
index 0000000..4b630f7
--- /dev/null
+++ b/libnl_2/include/netlink/route/link.h
@@ -0,0 +1,145 @@
+/*
+ * netlink/route/link.h Links (Interfaces)
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_LINK_H_
+#define NETLINK_LINK_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_link;
+
+enum rtnl_link_st {
+ RTNL_LINK_RX_PACKETS,
+ RTNL_LINK_TX_PACKETS,
+ RTNL_LINK_RX_BYTES,
+ RTNL_LINK_TX_BYTES,
+ RTNL_LINK_RX_ERRORS,
+ RTNL_LINK_TX_ERRORS,
+ RTNL_LINK_RX_DROPPED,
+ RTNL_LINK_TX_DROPPED,
+ RTNL_LINK_RX_COMPRESSED,
+ RTNL_LINK_TX_COMPRESSED,
+ RTNL_LINK_RX_FIFO_ERR,
+ RTNL_LINK_TX_FIFO_ERR,
+ RTNL_LINK_RX_LEN_ERR,
+ RTNL_LINK_RX_OVER_ERR,
+ RTNL_LINK_RX_CRC_ERR,
+ RTNL_LINK_RX_FRAME_ERR,
+ RTNL_LINK_RX_MISSED_ERR,
+ RTNL_LINK_TX_ABORT_ERR,
+ RTNL_LINK_TX_CARRIER_ERR,
+ RTNL_LINK_TX_HBEAT_ERR,
+ RTNL_LINK_TX_WIN_ERR,
+ RTNL_LINK_TX_COLLISIONS,
+ RTNL_LINK_MULTICAST,
+ __RTNL_LINK_STATS_MAX,
+};
+
+#define RTNL_LINK_STATS_MAX (__RTNL_LINK_STATS_MAX - 1)
+
+/* link object allocation/freeage */
+extern struct rtnl_link *rtnl_link_alloc(void);
+extern void rtnl_link_put(struct rtnl_link *);
+extern void rtnl_link_free(struct rtnl_link *);
+
+/* link cache management */
+extern int rtnl_link_alloc_cache(struct nl_sock *, struct nl_cache **);
+extern struct rtnl_link *rtnl_link_get(struct nl_cache *, int);
+extern struct rtnl_link *rtnl_link_get_by_name(struct nl_cache *, const char *);
+
+
+extern int rtnl_link_build_change_request(struct rtnl_link *,
+ struct rtnl_link *, int,
+ struct nl_msg **);
+extern int rtnl_link_change(struct nl_sock *, struct rtnl_link *,
+ struct rtnl_link *, int);
+
+/* Name <-> Index Translations */
+extern char * rtnl_link_i2name(struct nl_cache *, int, char *, size_t);
+extern int rtnl_link_name2i(struct nl_cache *, const char *);
+
+/* Name <-> Statistic Translations */
+extern char * rtnl_link_stat2str(int, char *, size_t);
+extern int rtnl_link_str2stat(const char *);
+
+/* Link Flags Translations */
+extern char * rtnl_link_flags2str(int, char *, size_t);
+extern int rtnl_link_str2flags(const char *);
+
+extern char * rtnl_link_operstate2str(int, char *, size_t);
+extern int rtnl_link_str2operstate(const char *);
+
+extern char * rtnl_link_mode2str(int, char *, size_t);
+extern int rtnl_link_str2mode(const char *);
+
+/* Access Functions */
+extern void rtnl_link_set_qdisc(struct rtnl_link *, const char *);
+extern char * rtnl_link_get_qdisc(struct rtnl_link *);
+
+extern void rtnl_link_set_name(struct rtnl_link *, const char *);
+extern char * rtnl_link_get_name(struct rtnl_link *);
+
+extern void rtnl_link_set_flags(struct rtnl_link *, unsigned int);
+extern void rtnl_link_unset_flags(struct rtnl_link *, unsigned int);
+extern unsigned int rtnl_link_get_flags(struct rtnl_link *);
+
+extern void rtnl_link_set_mtu(struct rtnl_link *, unsigned int);
+extern unsigned int rtnl_link_get_mtu(struct rtnl_link *);
+
+extern void rtnl_link_set_txqlen(struct rtnl_link *, unsigned int);
+extern unsigned int rtnl_link_get_txqlen(struct rtnl_link *);
+
+extern void rtnl_link_set_weight(struct rtnl_link *, unsigned int);
+extern unsigned int rtnl_link_get_weight(struct rtnl_link *);
+
+extern void rtnl_link_set_ifindex(struct rtnl_link *, int);
+extern int rtnl_link_get_ifindex(struct rtnl_link *);
+
+extern void rtnl_link_set_family(struct rtnl_link *, int);
+extern int rtnl_link_get_family(struct rtnl_link *);
+
+extern void rtnl_link_set_arptype(struct rtnl_link *, unsigned int);
+extern unsigned int rtnl_link_get_arptype(struct rtnl_link *);
+
+extern void rtnl_link_set_addr(struct rtnl_link *, struct nl_addr *);
+extern struct nl_addr *rtnl_link_get_addr(struct rtnl_link *);
+
+extern void rtnl_link_set_broadcast(struct rtnl_link *, struct nl_addr *);
+extern struct nl_addr *rtnl_link_get_broadcast(struct rtnl_link *);
+
+extern void rtnl_link_set_link(struct rtnl_link *, int);
+extern int rtnl_link_get_link(struct rtnl_link *);
+
+extern void rtnl_link_set_master(struct rtnl_link *, int);
+extern int rtnl_link_get_master(struct rtnl_link *);
+
+extern void rtnl_link_set_operstate(struct rtnl_link *, uint8_t);
+extern uint8_t rtnl_link_get_operstate(struct rtnl_link *);
+
+extern void rtnl_link_set_linkmode(struct rtnl_link *, uint8_t);
+extern uint8_t rtnl_link_get_linkmode(struct rtnl_link *);
+
+extern uint64_t rtnl_link_get_stat(struct rtnl_link *, int);
+
+extern int rtnl_link_set_info_type(struct rtnl_link *, const char *);
+extern char * rtnl_link_get_info_type(struct rtnl_link *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/neighbour.h b/libnl_2/include/netlink/route/neighbour.h
new file mode 100644
index 0000000..698539a
--- /dev/null
+++ b/libnl_2/include/netlink/route/neighbour.h
@@ -0,0 +1,79 @@
+/*
+ * netlink/route/neighbour.h Neighbours
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_NEIGHBOUR_H_
+#define NETLINK_NEIGHBOUR_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_neigh;
+
+extern struct rtnl_neigh *rtnl_neigh_alloc(void);
+extern void rtnl_neigh_put(struct rtnl_neigh *);
+
+extern int rtnl_neigh_alloc_cache(struct nl_sock *, struct nl_cache **);
+extern struct rtnl_neigh *rtnl_neigh_get(struct nl_cache *, int,
+ struct nl_addr *);
+
+extern char * rtnl_neigh_state2str(int, char *, size_t);
+extern int rtnl_neigh_str2state(const char *);
+
+extern char * rtnl_neigh_flags2str(int, char *, size_t);
+extern int rtnl_neigh_str2flag(const char *);
+
+extern int rtnl_neigh_add(struct nl_sock *, struct rtnl_neigh *, int);
+extern int rtnl_neigh_build_add_request(struct rtnl_neigh *, int,
+ struct nl_msg **);
+
+extern int rtnl_neigh_delete(struct nl_sock *, struct rtnl_neigh *, int);
+extern int rtnl_neigh_build_delete_request(struct rtnl_neigh *, int,
+ struct nl_msg **);
+
+extern void rtnl_neigh_set_state(struct rtnl_neigh *, int);
+extern int rtnl_neigh_get_state(struct rtnl_neigh *);
+extern void rtnl_neigh_unset_state(struct rtnl_neigh *,
+ int);
+
+extern void rtnl_neigh_set_flags(struct rtnl_neigh *,
+ unsigned int);
+extern void rtnl_neigh_unset_flags(struct rtnl_neigh *,
+ unsigned int);
+extern unsigned int rtnl_neigh_get_flags(struct rtnl_neigh *);
+
+extern void rtnl_neigh_set_ifindex(struct rtnl_neigh *,
+ int);
+extern int rtnl_neigh_get_ifindex(struct rtnl_neigh *);
+
+extern void rtnl_neigh_set_lladdr(struct rtnl_neigh *,
+ struct nl_addr *);
+extern struct nl_addr * rtnl_neigh_get_lladdr(struct rtnl_neigh *);
+
+extern int rtnl_neigh_set_dst(struct rtnl_neigh *,
+ struct nl_addr *);
+extern struct nl_addr * rtnl_neigh_get_dst(struct rtnl_neigh *);
+
+extern void rtnl_neigh_set_type(struct rtnl_neigh *, int);
+extern int rtnl_neigh_get_type(struct rtnl_neigh *);
+
+extern void rtnl_neigh_set_family(struct rtnl_neigh *, int);
+extern int rtnl_neigh_get_family(struct rtnl_neigh *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/neightbl.h b/libnl_2/include/netlink/route/neightbl.h
new file mode 100644
index 0000000..412c3e9
--- /dev/null
+++ b/libnl_2/include/netlink/route/neightbl.h
@@ -0,0 +1,65 @@
+/*
+ * netlink/route/neightbl.h Neighbour Tables
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_NEIGHTBL_H_
+#define NETLINK_NEIGHTBL_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_neightbl;
+
+extern struct rtnl_neightbl *rtnl_neightbl_alloc(void);
+extern void rtnl_neightbl_put(struct rtnl_neightbl *);
+extern void rtnl_neightbl_free(struct rtnl_neightbl *);
+extern int rtnl_neightbl_alloc_cache(struct nl_sock *, struct nl_cache **);
+extern struct rtnl_neightbl *rtnl_neightbl_get(struct nl_cache *,
+ const char *, int);
+extern void rtnl_neightbl_dump(struct rtnl_neightbl *, FILE *,
+ struct nl_dump_params *);
+
+extern int rtnl_neightbl_build_change_request(struct rtnl_neightbl *,
+ struct rtnl_neightbl *,
+ struct nl_msg **);
+extern int rtnl_neightbl_change(struct nl_sock *, struct rtnl_neightbl *,
+ struct rtnl_neightbl *);
+
+extern void rtnl_neightbl_set_family(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_gc_tresh1(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_gc_tresh2(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_gc_tresh3(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_name(struct rtnl_neightbl *, const char *);
+extern void rtnl_neightbl_set_dev(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_queue_len(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_proxy_queue_len(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_app_probes(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_ucast_probes(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_mcast_probes(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_base_reachable_time(struct rtnl_neightbl *,
+ uint64_t);
+extern void rtnl_neightbl_set_retrans_time(struct rtnl_neightbl *, uint64_t);
+extern void rtnl_neightbl_set_gc_stale_time(struct rtnl_neightbl *, uint64_t);
+extern void rtnl_neightbl_set_delay_probe_time(struct rtnl_neightbl *,
+ uint64_t);
+extern void rtnl_neightbl_set_anycast_delay(struct rtnl_neightbl *, uint64_t);
+extern void rtnl_neightbl_set_proxy_delay(struct rtnl_neightbl *, uint64_t);
+extern void rtnl_neightbl_set_locktime(struct rtnl_neightbl *, uint64_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/nexthop.h b/libnl_2/include/netlink/route/nexthop.h
new file mode 100644
index 0000000..2aa44dc
--- /dev/null
+++ b/libnl_2/include/netlink/route/nexthop.h
@@ -0,0 +1,65 @@
+/*
+ * netlink/route/nexthop.h Routing Nexthop
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_ROUTE_NEXTHOP_H_
+#define NETLINK_ROUTE_NEXTHOP_H_
+
+#include <netlink/netlink.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_nexthop;
+
+enum {
+ NH_DUMP_FROM_ONELINE = -2,
+ NH_DUMP_FROM_DETAILS = -1,
+ NH_DUMP_FROM_ENV = 0,
+ /* > 0 reserved for nexthop index */
+};
+
+extern struct rtnl_nexthop * rtnl_route_nh_alloc(void);
+extern struct rtnl_nexthop * rtnl_route_nh_clone(struct rtnl_nexthop *);
+extern void rtnl_route_nh_free(struct rtnl_nexthop *);
+
+extern int rtnl_route_nh_compare(struct rtnl_nexthop *,
+ struct rtnl_nexthop *,
+ uint32_t, int);
+
+extern void rtnl_route_nh_dump(struct rtnl_nexthop *,
+ struct nl_dump_params *);
+
+extern void rtnl_route_nh_set_weight(struct rtnl_nexthop *, uint8_t);
+extern uint8_t rtnl_route_nh_get_weight(struct rtnl_nexthop *);
+extern void rtnl_route_nh_set_ifindex(struct rtnl_nexthop *, int);
+extern int rtnl_route_nh_get_ifindex(struct rtnl_nexthop *);
+extern void rtnl_route_nh_set_gateway(struct rtnl_nexthop *,
+ struct nl_addr *);
+extern struct nl_addr * rtnl_route_nh_get_gateway(struct rtnl_nexthop *);
+extern void rtnl_route_nh_set_flags(struct rtnl_nexthop *,
+ unsigned int);
+extern void rtnl_route_nh_unset_flags(struct rtnl_nexthop *,
+ unsigned int);
+extern unsigned int rtnl_route_nh_get_flags(struct rtnl_nexthop *);
+extern void rtnl_route_nh_set_realms(struct rtnl_nexthop *,
+ uint32_t);
+extern uint32_t rtnl_route_nh_get_realms(struct rtnl_nexthop *);
+
+extern char * rtnl_route_nh_flags2str(int, char *, size_t);
+extern int rtnl_route_nh_str2flags(const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/qdisc.h b/libnl_2/include/netlink/route/qdisc.h
new file mode 100644
index 0000000..5acd6e1
--- /dev/null
+++ b/libnl_2/include/netlink/route/qdisc.h
@@ -0,0 +1,73 @@
+/*
+ * netlink/route/qdisc.h Queueing Disciplines
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_QDISC_H_
+#define NETLINK_QDISC_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/route/tc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_qdisc;
+
+extern struct nl_object_ops qdisc_obj_ops;
+
+extern struct rtnl_qdisc *rtnl_qdisc_alloc(void);
+extern void rtnl_qdisc_put(struct rtnl_qdisc *);
+
+extern int rtnl_qdisc_alloc_cache(struct nl_sock *, struct nl_cache **);
+extern struct rtnl_qdisc *rtnl_qdisc_get(struct nl_cache *, int, uint32_t);
+extern struct rtnl_qdisc *rtnl_qdisc_get_by_parent(struct nl_cache *,
+ int, uint32_t);
+
+extern int rtnl_qdisc_build_add_request(struct rtnl_qdisc *, int,
+ struct nl_msg **);
+extern int rtnl_qdisc_add(struct nl_sock *, struct rtnl_qdisc *, int);
+
+extern int rtnl_qdisc_build_change_request(struct rtnl_qdisc *,
+ struct rtnl_qdisc *,
+ struct nl_msg **);
+extern int rtnl_qdisc_change(struct nl_sock *, struct rtnl_qdisc *,
+ struct rtnl_qdisc *);
+
+extern int rtnl_qdisc_build_delete_request(struct rtnl_qdisc *,
+ struct nl_msg **);
+extern int rtnl_qdisc_delete(struct nl_sock *, struct rtnl_qdisc *);
+
+extern void rtnl_qdisc_set_ifindex(struct rtnl_qdisc *, int);
+extern int rtnl_qdisc_get_ifindex(struct rtnl_qdisc *);
+extern void rtnl_qdisc_set_handle(struct rtnl_qdisc *, uint32_t);
+extern uint32_t rtnl_qdisc_get_handle(struct rtnl_qdisc *);
+extern void rtnl_qdisc_set_parent(struct rtnl_qdisc *, uint32_t);
+extern uint32_t rtnl_qdisc_get_parent(struct rtnl_qdisc *);
+extern void rtnl_qdisc_set_kind(struct rtnl_qdisc *, const char *);
+extern char * rtnl_qdisc_get_kind(struct rtnl_qdisc *);
+extern uint64_t rtnl_qdisc_get_stat(struct rtnl_qdisc *, enum rtnl_tc_stats_id);
+
+extern void rtnl_qdisc_foreach_child(struct rtnl_qdisc *, struct nl_cache *,
+ void (*cb)(struct nl_object *, void *),
+ void *);
+
+extern void rtnl_qdisc_foreach_cls(struct rtnl_qdisc *, struct nl_cache *,
+ void (*cb)(struct nl_object *, void *),
+ void *);
+
+extern struct nl_msg * rtnl_qdisc_get_opts(struct rtnl_qdisc *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/route.h b/libnl_2/include/netlink/route/route.h
new file mode 100644
index 0000000..5729cd7
--- /dev/null
+++ b/libnl_2/include/netlink/route/route.h
@@ -0,0 +1,124 @@
+/*
+ * netlink/route/route.h Routes
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_ROUTE_H_
+#define NETLINK_ROUTE_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+#include <netlink/data.h>
+#include <netlink/route/nexthop.h>
+#include <netlink/route/rtnl.h>
+#include <linux/in_route.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* flags */
+#define ROUTE_CACHE_CONTENT 1
+
+struct rtnl_route;
+
+struct rtnl_rtcacheinfo
+{
+ uint32_t rtci_clntref;
+ uint32_t rtci_last_use;
+ uint32_t rtci_expires;
+ int32_t rtci_error;
+ uint32_t rtci_used;
+ uint32_t rtci_id;
+ uint32_t rtci_ts;
+ uint32_t rtci_tsage;
+};
+
+extern struct nl_object_ops route_obj_ops;
+
+extern struct rtnl_route * rtnl_route_alloc(void);
+extern void rtnl_route_put(struct rtnl_route *);
+extern int rtnl_route_alloc_cache(struct nl_sock *, int, int,
+ struct nl_cache **);
+
+extern void rtnl_route_get(struct rtnl_route *);
+extern void rtnl_route_put(struct rtnl_route *);
+
+extern int rtnl_route_parse(struct nlmsghdr *, struct rtnl_route **);
+extern int rtnl_route_build_msg(struct nl_msg *, struct rtnl_route *);
+
+extern int rtnl_route_build_add_request(struct rtnl_route *, int,
+ struct nl_msg **);
+extern int rtnl_route_add(struct nl_sock *, struct rtnl_route *, int);
+extern int rtnl_route_build_del_request(struct rtnl_route *, int,
+ struct nl_msg **);
+extern int rtnl_route_delete(struct nl_sock *, struct rtnl_route *, int);
+
+extern void rtnl_route_set_table(struct rtnl_route *, uint32_t);
+extern uint32_t rtnl_route_get_table(struct rtnl_route *);
+extern void rtnl_route_set_scope(struct rtnl_route *, uint8_t);
+extern uint8_t rtnl_route_get_scope(struct rtnl_route *);
+extern void rtnl_route_set_tos(struct rtnl_route *, uint8_t);
+extern uint8_t rtnl_route_get_tos(struct rtnl_route *);
+extern void rtnl_route_set_protocol(struct rtnl_route *, uint8_t);
+extern uint8_t rtnl_route_get_protocol(struct rtnl_route *);
+extern void rtnl_route_set_priority(struct rtnl_route *, uint32_t);
+extern uint32_t rtnl_route_get_priority(struct rtnl_route *);
+extern int rtnl_route_set_family(struct rtnl_route *, uint8_t);
+extern uint8_t rtnl_route_get_family(struct rtnl_route *);
+extern int rtnl_route_set_type(struct rtnl_route *, uint8_t);
+extern uint8_t rtnl_route_get_type(struct rtnl_route *);
+extern void rtnl_route_set_flags(struct rtnl_route *, uint32_t);
+extern void rtnl_route_unset_flags(struct rtnl_route *, uint32_t);
+extern uint32_t rtnl_route_get_flags(struct rtnl_route *);
+extern int rtnl_route_set_metric(struct rtnl_route *, int, unsigned int);
+extern int rtnl_route_unset_metric(struct rtnl_route *, int);
+extern int rtnl_route_get_metric(struct rtnl_route *, int, uint32_t *);
+extern int rtnl_route_set_dst(struct rtnl_route *, struct nl_addr *);
+extern struct nl_addr *rtnl_route_get_dst(struct rtnl_route *);
+extern int rtnl_route_set_src(struct rtnl_route *, struct nl_addr *);
+extern struct nl_addr *rtnl_route_get_src(struct rtnl_route *);
+extern int rtnl_route_set_pref_src(struct rtnl_route *, struct nl_addr *);
+extern struct nl_addr *rtnl_route_get_pref_src(struct rtnl_route *);
+extern void rtnl_route_set_iif(struct rtnl_route *, int);
+extern int rtnl_route_get_iif(struct rtnl_route *);
+extern int rtnl_route_get_src_len(struct rtnl_route *);
+
+extern void rtnl_route_add_nexthop(struct rtnl_route *,
+ struct rtnl_nexthop *);
+extern void rtnl_route_remove_nexthop(struct rtnl_route *,
+ struct rtnl_nexthop *);
+extern struct nl_list_head *rtnl_route_get_nexthops(struct rtnl_route *);
+extern int rtnl_route_get_nnexthops(struct rtnl_route *);
+
+extern void rtnl_route_foreach_nexthop(struct rtnl_route *r,
+ void (*cb)(struct rtnl_nexthop *, void *),
+ void *arg);
+
+extern struct rtnl_nexthop * rtnl_route_nexthop_n(struct rtnl_route *r, int n);
+
+extern int rtnl_route_guess_scope(struct rtnl_route *);
+
+extern char * rtnl_route_table2str(int, char *, size_t);
+extern int rtnl_route_str2table(const char *);
+extern int rtnl_route_read_table_names(const char *);
+
+extern char * rtnl_route_proto2str(int, char *, size_t);
+extern int rtnl_route_str2proto(const char *);
+extern int rtnl_route_read_protocol_names(const char *);
+
+extern char * rtnl_route_metric2str(int, char *, size_t);
+extern int rtnl_route_str2metric(const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/rtnl.h b/libnl_2/include/netlink/route/rtnl.h
new file mode 100644
index 0000000..f551a5d
--- /dev/null
+++ b/libnl_2/include/netlink/route/rtnl.h
@@ -0,0 +1,69 @@
+/*
+ * netlink/route/rtnl.h Routing Netlink
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_RTNL_H_
+#define NETLINK_RTNL_H_
+
+#include <netlink/netlink.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @name Realms
+ * @{
+ */
+
+/**
+ * Mask specying the size of each realm part
+ * @ingroup rtnl
+ */
+#define RTNL_REALM_MASK (0xFFFF)
+
+/**
+ * Extract FROM realm from a realms field
+ */
+#define RTNL_REALM_FROM(realm) ((realm) >> 16)
+
+/**
+ * Extract TO realm from a realms field
+ */
+#define RTNL_REALM_TO(realm) ((realm) & RTNL_REALM_MASK)
+
+/**
+ * Build a realms field
+ */
+#define RTNL_MAKE_REALM(from, to) \
+ ((RTNL_REALM_TO(from) << 16) & RTNL_REALM_TO(to))
+
+/** @} */
+
+
+/* General */
+extern int nl_rtgen_request(struct nl_sock *, int, int, int);
+
+/* Routing Type Translations */
+extern char * nl_rtntype2str(int, char *, size_t);
+extern int nl_str2rtntype(const char *);
+
+/* Scope Translations */
+extern char * rtnl_scope2str(int, char *, size_t);
+extern int rtnl_str2scope(const char *);
+
+/* Realms Translations */
+extern char * rtnl_realms2str(uint32_t, char *, size_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/rule.h b/libnl_2/include/netlink/route/rule.h
new file mode 100644
index 0000000..928dc0f
--- /dev/null
+++ b/libnl_2/include/netlink/route/rule.h
@@ -0,0 +1,78 @@
+/*
+ * netlink/route/rule.h Rules
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_RULE_H_
+#define NETLINK_RULE_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+#include <netlink/route/route.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_rule;
+
+/* General */
+extern struct rtnl_rule * rtnl_rule_alloc(void);
+extern void rtnl_rule_put(struct rtnl_rule *);
+
+extern int rtnl_rule_alloc_cache(struct nl_sock *, int,
+ struct nl_cache **);
+extern void rtnl_rule_dump(struct rtnl_rule *, FILE *, struct nl_dump_params *);
+
+extern int rtnl_rule_build_add_request(struct rtnl_rule *, int,
+ struct nl_msg **);
+extern int rtnl_rule_add(struct nl_sock *, struct rtnl_rule *, int);
+extern int rtnl_rule_build_delete_request(struct rtnl_rule *, int,
+ struct nl_msg **);
+extern int rtnl_rule_delete(struct nl_sock *, struct rtnl_rule *, int);
+
+
+/* attribute modification */
+extern void rtnl_rule_set_family(struct rtnl_rule *, int);
+extern int rtnl_rule_get_family(struct rtnl_rule *);
+extern void rtnl_rule_set_prio(struct rtnl_rule *, int);
+extern int rtnl_rule_get_prio(struct rtnl_rule *);
+extern void rtnl_rule_set_mark(struct rtnl_rule *, uint64_t);
+extern uint64_t rtnl_rule_get_mark(struct rtnl_rule *);
+extern void rtnl_rule_set_table(struct rtnl_rule *, int);
+extern int rtnl_rule_get_table(struct rtnl_rule *);
+extern void rtnl_rule_set_dsfield(struct rtnl_rule *, int);
+extern int rtnl_rule_get_dsfield(struct rtnl_rule *);
+extern int rtnl_rule_set_src(struct rtnl_rule *, struct nl_addr *);
+extern struct nl_addr * rtnl_rule_get_src(struct rtnl_rule *);
+extern int rtnl_rule_set_dst(struct rtnl_rule *, struct nl_addr *);
+extern struct nl_addr * rtnl_rule_get_dst(struct rtnl_rule *);
+extern void rtnl_rule_set_src_len(struct rtnl_rule *, int);
+extern int rtnl_rule_get_src_len(struct rtnl_rule *);
+extern void rtnl_rule_set_dst_len(struct rtnl_rule *, int);
+extern int rtnl_rule_get_dst_len(struct rtnl_rule *);
+
+extern void rtnl_rule_set_action(struct rtnl_rule *, int);
+extern int rtnl_rule_get_action(struct rtnl_rule *);
+
+extern int rtnl_rule_set_iif(struct rtnl_rule *, const char *);
+extern char * rtnl_rule_get_iif(struct rtnl_rule *);
+
+extern void rtnl_rule_set_classid(struct rtnl_rule *, uint32_t);
+extern uint32_t rtnl_rule_get_classid(struct rtnl_rule *);
+
+extern void rtnl_rule_set_realms(struct rtnl_rule *, uint32_t);
+extern uint32_t rtnl_rule_get_realms(struct rtnl_rule *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/route/tc.h b/libnl_2/include/netlink/route/tc.h
new file mode 100644
index 0000000..3cb876f
--- /dev/null
+++ b/libnl_2/include/netlink/route/tc.h
@@ -0,0 +1,63 @@
+/*
+ * netlink/route/tc.h Traffic Control
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_TC_H_
+#define NETLINK_TC_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/data.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * TC statistics identifiers
+ * @ingroup tc
+ */
+enum rtnl_tc_stats_id {
+ RTNL_TC_PACKETS, /**< Packets seen */
+ RTNL_TC_BYTES, /**< Bytes seen */
+ RTNL_TC_RATE_BPS, /**< Current bits/s (rate estimator) */
+ RTNL_TC_RATE_PPS, /**< Current packet/s (rate estimator) */
+ RTNL_TC_QLEN, /**< Queue length */
+ RTNL_TC_BACKLOG, /**< Backlog length */
+ RTNL_TC_DROPS, /**< Packets dropped */
+ RTNL_TC_REQUEUES, /**< Number of requeues */
+ RTNL_TC_OVERLIMITS, /**< Number of overlimits */
+ __RTNL_TC_STATS_MAX,
+};
+
+#define RTNL_TC_STATS_MAX (__RTNL_TC_STATS_MAX - 1)
+
+extern int rtnl_tc_calc_txtime(int, int);
+extern int rtnl_tc_calc_bufsize(int, int);
+extern int rtnl_tc_calc_cell_log(int);
+
+/**
+ * Number of entries in a transmission time lookup table
+ * @ingroup tc
+ */
+#define RTNL_TC_RTABLE_SIZE 256
+
+extern int rtnl_tc_build_rate_table(uint32_t *, uint8_t, uint8_t, int, int);
+
+
+/* TC Handle Translations */
+extern char * rtnl_tc_handle2str(uint32_t, char *, size_t);
+extern int rtnl_tc_str2handle(const char *, uint32_t *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/socket.h b/libnl_2/include/netlink/socket.h
new file mode 100644
index 0000000..7e71aed
--- /dev/null
+++ b/libnl_2/include/netlink/socket.h
@@ -0,0 +1,66 @@
+/*
+ * netlink/socket.h Netlink Socket
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_SOCKET_H_
+#define NETLINK_SOCKET_H_
+
+#include <netlink/types.h>
+#include <netlink/handlers.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern struct nl_sock * nl_socket_alloc(void);
+extern struct nl_sock * nl_socket_alloc_cb(struct nl_cb *);
+extern void nl_socket_free(struct nl_sock *);
+
+extern uint32_t nl_socket_get_local_port(struct nl_sock *);
+extern void nl_socket_set_local_port(struct nl_sock *, uint32_t);
+
+extern int nl_socket_add_memberships(struct nl_sock *, int, ...);
+extern int nl_socket_add_membership(struct nl_sock *, int);
+extern int nl_socket_drop_memberships(struct nl_sock *, int, ...);
+extern int nl_socket_drop_membership(struct nl_sock *,
+ int);
+extern void nl_join_groups(struct nl_sock *, int);
+
+
+extern uint32_t nl_socket_get_peer_port(struct nl_sock *);
+extern void nl_socket_set_peer_port(struct nl_sock *,
+ uint32_t);
+
+extern struct nl_cb * nl_socket_get_cb(struct nl_sock *);
+extern void nl_socket_set_cb(struct nl_sock *,
+ struct nl_cb *);
+extern int nl_socket_modify_cb(struct nl_sock *, enum nl_cb_type,
+ enum nl_cb_kind,
+ nl_recvmsg_msg_cb_t, void *);
+
+extern int nl_socket_set_buffer_size(struct nl_sock *, int, int);
+extern int nl_socket_set_passcred(struct nl_sock *, int);
+extern int nl_socket_recv_pktinfo(struct nl_sock *, int);
+
+extern void nl_socket_disable_seq_check(struct nl_sock *);
+extern unsigned int nl_socket_use_seq(struct nl_sock *);
+extern void nl_socket_disable_auto_ack(struct nl_sock *);
+extern void nl_socket_enable_auto_ack(struct nl_sock *);
+
+extern int nl_socket_get_fd(struct nl_sock *);
+extern int nl_socket_set_nonblocking(struct nl_sock *);
+extern void nl_socket_enable_msg_peek(struct nl_sock *);
+extern void nl_socket_disable_msg_peek(struct nl_sock *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/types.h b/libnl_2/include/netlink/types.h
new file mode 100644
index 0000000..2e0b9c3
--- /dev/null
+++ b/libnl_2/include/netlink/types.h
@@ -0,0 +1,111 @@
+/*
+ * netlink/netlink-types.h Netlink Types
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef __NETLINK_TYPES_H_
+#define __NETLINK_TYPES_H_
+
+#include <stdio.h>
+
+/**
+ * Dumping types (dp_type)
+ * @ingroup utils
+ */
+enum nl_dump_type {
+ NL_DUMP_LINE, /**< Dump object briefly on one line */
+ NL_DUMP_DETAILS, /**< Dump all attributes but no statistics */
+ NL_DUMP_STATS, /**< Dump all attributes including statistics */
+ NL_DUMP_ENV, /**< Dump all attribtues as env variables */
+ __NL_DUMP_MAX,
+};
+#define NL_DUMP_MAX (__NL_DUMP_MAX - 1)
+
+/**
+ * Dumping parameters
+ * @ingroup utils
+ */
+struct nl_dump_params
+{
+ /**
+ * Specifies the type of dump that is requested.
+ */
+ enum nl_dump_type dp_type;
+
+ /**
+ * Specifies the number of whitespaces to be put in front
+ * of every new line (indentation).
+ */
+ int dp_prefix;
+
+ /**
+ * Causes the cache index to be printed for each element.
+ */
+ int dp_print_index;
+
+ /**
+ * Causes each element to be prefixed with the message type.
+ */
+ int dp_dump_msgtype;
+
+ /**
+ * A callback invoked for output
+ *
+ * Passed arguments are:
+ * - dumping parameters
+ * - string to append to the output
+ */
+ void (*dp_cb)(struct nl_dump_params *, char *);
+
+ /**
+ * A callback invoked for every new line, can be used to
+ * customize the indentation.
+ *
+ * Passed arguments are:
+ * - dumping parameters
+ * - line number starting from 0
+ */
+ void (*dp_nl_cb)(struct nl_dump_params *, int);
+
+ /**
+ * User data pointer, can be used to pass data to callbacks.
+ */
+ void *dp_data;
+
+ /**
+ * File descriptor the dumping output should go to
+ */
+ FILE * dp_fd;
+
+ /**
+ * Alternatively the output may be redirected into a buffer
+ */
+ char * dp_buf;
+
+ /**
+ * Length of the buffer dp_buf
+ */
+ size_t dp_buflen;
+
+ /**
+ * PRIVATE
+ * Set if a dump was performed prior to the actual dump handler.
+ */
+ int dp_pre_dump;
+
+ /**
+ * PRIVATE
+ * Owned by the current caller
+ */
+ int dp_ivar;
+
+ unsigned int dp_line;
+};
+
+#endif
diff --git a/libnl_2/include/netlink/utils.h b/libnl_2/include/netlink/utils.h
new file mode 100644
index 0000000..480bab6
--- /dev/null
+++ b/libnl_2/include/netlink/utils.h
@@ -0,0 +1,78 @@
+/*
+ * netlink/utils.h Utility Functions
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_UTILS_H_
+#define NETLINK_UTILS_H_
+
+#include <netlink/netlink.h>
+#include <netlink/list.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @name Probability Constants
+ * @{
+ */
+
+/**
+ * Lower probability limit
+ * @ingroup utils
+ */
+#define NL_PROB_MIN 0x0
+
+/**
+ * Upper probability limit
+ * @ingroup utils
+ */
+#define NL_PROB_MAX 0xffffffff
+
+/** @} */
+
+/* unit pretty-printing */
+extern double nl_cancel_down_bytes(unsigned long long, char **);
+extern double nl_cancel_down_bits(unsigned long long, char **);
+extern double nl_cancel_down_us(uint32_t, char **);
+
+/* generic unit translations */
+extern long nl_size2int(const char *);
+extern long nl_prob2int(const char *);
+
+/* time translations */
+extern int nl_get_hz(void);
+extern uint32_t nl_us2ticks(uint32_t);
+extern uint32_t nl_ticks2us(uint32_t);
+extern int nl_str2msec(const char *, uint64_t *);
+extern char * nl_msec2str(uint64_t, char *, size_t);
+
+/* link layer protocol translations */
+extern char * nl_llproto2str(int, char *, size_t);
+extern int nl_str2llproto(const char *);
+
+/* ethernet protocol translations */
+extern char * nl_ether_proto2str(int, char *, size_t);
+extern int nl_str2ether_proto(const char *);
+
+/* IP protocol translations */
+extern char * nl_ip_proto2str(int, char *, size_t);
+extern int nl_str2ip_proto(const char *);
+
+/* Dumping helpers */
+extern void nl_new_line(struct nl_dump_params *);
+extern void nl_dump(struct nl_dump_params *, const char *, ...);
+extern void nl_dump_line(struct nl_dump_params *, const char *, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libnl_2/include/netlink/version.h b/libnl_2/include/netlink/version.h
new file mode 100644
index 0000000..84af8f3
--- /dev/null
+++ b/libnl_2/include/netlink/version.h
@@ -0,0 +1,18 @@
+/*
+ * netlink/version.h Compile Time Versioning Information
+ *
+ * This 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 version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_VERSION_H_
+#define NETLINK_VERSION_H_
+
+#define LIBNL_STRING "libnl 2.0"
+#define LIBNL_VERSION "2.0"
+
+#endif
diff --git a/libnl_2/msg.c b/libnl_2/msg.c
new file mode 100644
index 0000000..d7276b7
--- /dev/null
+++ b/libnl_2/msg.c
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* NOTICE: This is a clean room re-implementation of libnl */
+
+#include <malloc.h>
+#include <unistd.h>
+#include <linux/netlink.h>
+#include "netlink-types.h"
+
+/* Allocate a new netlink message with the default maximum payload size. */
+struct nl_msg *nlmsg_alloc(void)
+{
+ /* Whole page will store nl_msg + nlmsghdr + genlmsghdr + payload */
+ const int page_sz = getpagesize();
+ struct nl_msg *nm;
+ struct nlmsghdr *nlh;
+
+ /* Netlink message */
+ nm = (struct nl_msg *) malloc(page_sz);
+ if (!nm)
+ goto fail;
+
+ /* Netlink message header pointer */
+ nlh = (struct nlmsghdr *) ((char *) nm + sizeof(struct nl_msg));
+
+ /* Initialize */
+ memset(nm, 0, page_sz);
+ nm->nm_size = page_sz;
+
+ nm->nm_src.nl_family = AF_NETLINK;
+ nm->nm_src.nl_pid = getpid();
+
+ nm->nm_dst.nl_family = AF_NETLINK;
+ nm->nm_dst.nl_pid = 0; /* Kernel */
+
+ /* Initialize and add to netlink message */
+ nlh->nlmsg_len = NLMSG_HDRLEN;
+ nm->nm_nlh = nlh;
+
+ /* Add to reference count and return nl_msg */
+ nlmsg_get(nm);
+ return nm;
+fail:
+ return NULL;
+}
+
+/* Return pointer to message payload. */
+void *nlmsg_data(const struct nlmsghdr *nlh)
+{
+ return (char *) nlh + NLMSG_HDRLEN;
+}
+
+/* Add reference count to nl_msg */
+void nlmsg_get(struct nl_msg *nm)
+{
+ nm->nm_refcnt++;
+}
+
+/* Release a reference from an netlink message. */
+void nlmsg_free(struct nl_msg *nm)
+{
+ if (nm) {
+ nm->nm_refcnt--;
+ if (nm->nm_refcnt <= 0)
+ free(nm);
+ }
+
+}
+
+/* Return actual netlink message. */
+struct nlmsghdr *nlmsg_hdr(struct nl_msg *n)
+{
+ return n->nm_nlh;
+}
+
+/* Return head of attributes data / payload section */
+struct nlattr *nlmsg_attrdata(const struct nlmsghdr *nlh, int hdrlen)
+{
+ unsigned char *data = nlmsg_data(nlh);
+ return (struct nlattr *) (data + NLMSG_ALIGN(hdrlen));
+}
+
+/* Returns pointer to end of netlink message */
+void *nlmsg_tail(const struct nlmsghdr *nlh)
+{
+ return (void *)((char *) nlh + nlh->nlmsg_len);
+}
+
+/* Next netlink message in message stream */
+struct nlmsghdr *nlmsg_next(struct nlmsghdr *nlh, int *remaining)
+{
+ struct nlmsghdr *next_nlh = NULL;
+ if (*remaining > 0 &&
+ nlmsg_len(nlh) <= *remaining &&
+ nlmsg_len(nlh) >= (int) sizeof(struct nlmsghdr)) {
+ next_nlh = (struct nlmsghdr *) \
+ ((char *) nlh + nlmsg_len(nlh));
+
+ if (next_nlh && nlmsg_len(nlh) <= *remaining) {
+ *remaining -= nlmsg_len(nlh);
+ next_nlh = (struct nlmsghdr *) \
+ ((char *) nlh + nlmsg_len(nlh));
+ }
+ }
+
+ return next_nlh;
+}
+
+/* Length of attributes data */
+int nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen)
+{
+ return nlmsg_len(nlh) - NLMSG_HDRLEN - hdrlen;
+}
+
+/* Length of netlink message */
+int nlmsg_len(const struct nlmsghdr *nlh)
+{
+ return nlh->nlmsg_len;
+}
+
+/* Check if the netlink message fits into the remaining bytes */
+int nlmsg_ok(const struct nlmsghdr *nlh, int rem)
+{
+ return rem >= (int)sizeof(struct nlmsghdr) &&
+ rem >= nlmsg_len(nlh) &&
+ nlmsg_len(nlh) >= (int) sizeof(struct nlmsghdr) &&
+ nlmsg_len(nlh) <= (rem);
+}
+
+int nlmsg_padlen(int payload)
+{
+ return NLMSG_ALIGN(payload) - payload;
+}
+
+int nlmsg_datalen(const struct nlmsghdr *nlh)
+{
+ return nlh->nlmsg_len - NLMSG_HDRLEN;
+}
+
diff --git a/libnl_2/netlink.c b/libnl_2/netlink.c
new file mode 100644
index 0000000..cc2f88e
--- /dev/null
+++ b/libnl_2/netlink.c
@@ -0,0 +1,273 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* NOTICE: This is a clean room re-implementation of libnl */
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include "netlink-types.h"
+
+#define NL_BUFFER_SZ (32768U)
+
+/* Checks message for completeness and sends it out */
+int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg)
+{
+ struct nlmsghdr *nlh = msg->nm_nlh;
+ struct timeval tv;
+
+ if (!nlh) {
+ int errsv = errno;
+ fprintf(stderr, "Netlink message header is NULL!\n");
+ return -errsv;
+ }
+
+ /* Complete the nl_msg header */
+ if (gettimeofday(&tv, NULL))
+ nlh->nlmsg_seq = 1;
+ else
+ nlh->nlmsg_seq = (int) tv.tv_sec;
+ nlh->nlmsg_pid = sk->s_local.nl_pid;
+ nlh->nlmsg_flags |= NLM_F_REQUEST | NLM_F_ACK;
+
+ return nl_send(sk, msg);
+}
+
+/* Receives a netlink message, allocates a buffer in *buf and stores
+ * the message content. The peer's netlink address is stored in
+ * *nla. The caller is responsible for freeing the buffer allocated in
+ * *buf if a positive value is returned. Interrupted system calls are
+ * handled by repeating the read. The input buffer size is determined
+ * by peeking before the actual read is done */
+int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla, \
+ unsigned char **buf, struct ucred **creds)
+{
+ int rc = -1;
+ int sk_flags;
+ int RECV_BUF_SIZE;
+ int errsv;
+ struct iovec recvmsg_iov;
+ struct msghdr msg;
+
+ /* Allocate buffer */
+ RECV_BUF_SIZE = getpagesize();
+ *buf = (unsigned char *) malloc(RECV_BUF_SIZE);
+ if (!buf) {
+ rc = -ENOMEM;
+ goto fail;
+ }
+
+ /* Prepare to receive message */
+ recvmsg_iov.iov_base = *buf;
+ recvmsg_iov.iov_len = RECV_BUF_SIZE;
+
+ msg.msg_name = (void *) &sk->s_peer;
+ msg.msg_namelen = sizeof(sk->s_peer);
+ msg.msg_iov = &recvmsg_iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+ msg.msg_flags = 0;
+
+ /* Make non blocking and then restore previous setting */
+ sk_flags = fcntl(sk->s_fd, F_GETFL, 0);
+ fcntl(sk->s_fd, F_SETFL, O_NONBLOCK);
+ rc = recvmsg(sk->s_fd, &msg, 0);
+ errsv = errno;
+ fcntl(sk->s_fd, F_SETFL, sk_flags);
+
+ if (rc < 0)
+ rc = -errsv;
+
+fail:
+ return rc;
+}
+
+/* Receive a set of messages from a netlink socket */
+/* NOTE: Does not currently support callback replacements!!! */
+int nl_recvmsgs(struct nl_sock *sk, struct nl_cb *cb)
+{
+ struct sockaddr_nl nla;
+ struct ucred *creds;
+
+ int rc, cb_rc = NL_OK, done = 0;
+
+ do {
+
+ unsigned char *buf;
+ int i, rem, flags;
+ struct nlmsghdr *nlh;
+ struct nlmsgerr *nlme;
+ struct nl_msg *msg;
+
+ done = 0;
+ rc = nl_recv(sk, &nla, &buf, &creds);
+ if (rc < 0)
+ break;
+
+ nlmsg_for_each_msg(nlh, (struct nlmsghdr *) buf, rc, rem) {
+
+ if (rc <= 0 || cb_rc == NL_STOP)
+ break;
+
+ /* Check for callbacks */
+
+ msg = (struct nl_msg *)malloc(sizeof(struct nl_msg));
+ memset(msg, 0, sizeof(*msg));
+ msg->nm_nlh = nlh;
+
+ /* Check netlink message type */
+
+ switch (msg->nm_nlh->nlmsg_type) {
+ case NLMSG_ERROR: /* Used for ACK too */
+ /* Certainly we should be doing some
+ * checking here to make sure this
+ * message is intended for us */
+ nlme = nlmsg_data(msg->nm_nlh);
+ if (nlme->error == 0)
+ msg->nm_nlh->nlmsg_flags |= NLM_F_ACK;
+
+ rc = nlme->error;
+ cb_rc = cb->cb_err(&nla, nlme, cb->cb_err_arg);
+ nlme = NULL;
+ break;
+
+ case NLMSG_DONE:
+ done = 1;
+
+ case NLMSG_OVERRUN:
+ case NLMSG_NOOP:
+ default:
+ break;
+ };
+
+ for (i = 0; i <= NL_CB_TYPE_MAX; i++) {
+
+ if (cb->cb_set[i]) {
+ switch (i) {
+ case NL_CB_VALID:
+ if (rc > 0)
+ cb_rc = cb->cb_set[i](msg, cb->cb_args[i]);
+ break;
+
+ case NL_CB_FINISH:
+ if ((msg->nm_nlh->nlmsg_flags & NLM_F_MULTI) &&
+ (msg->nm_nlh->nlmsg_type & NLMSG_DONE))
+ cb_rc = cb->cb_set[i](msg, cb->cb_args[i]);
+
+ break;
+
+ case NL_CB_ACK:
+ if (msg->nm_nlh->nlmsg_flags & NLM_F_ACK)
+ cb_rc = cb->cb_set[i](msg, cb->cb_args[i]);
+
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ free(msg);
+ if (done)
+ break;
+ }
+
+ free(buf);
+ buf = NULL;
+
+ if (done)
+ break;
+ } while (rc > 0 && cb_rc != NL_STOP);
+
+success:
+fail:
+ return rc;
+}
+
+/* Send raw data over netlink socket */
+int nl_send(struct nl_sock *sk, struct nl_msg *msg)
+{
+ struct nlmsghdr *nlh = nlmsg_hdr(msg);
+ struct iovec msg_iov;
+
+ /* Create IO vector with Netlink message */
+ msg_iov.iov_base = nlh;
+ msg_iov.iov_len = nlh->nlmsg_len;
+
+ return nl_send_iovec(sk, msg, &msg_iov, 1);
+}
+
+/* Send netlink message */
+int nl_send_iovec(struct nl_sock *sk, struct nl_msg *msg,
+ struct iovec *iov, unsigned iovlen)
+{
+ int rc;
+
+ /* Socket message */
+ struct msghdr mh = {
+ .msg_name = (void *) &sk->s_peer,
+ .msg_namelen = sizeof(sk->s_peer),
+ .msg_iov = iov,
+ .msg_iovlen = iovlen,
+ .msg_control = NULL,
+ .msg_controllen = 0,
+ .msg_flags = 0
+ };
+
+ /* Send message and verify sent */
+ rc = nl_sendmsg(sk, (struct nl_msg *) &mh, 0);
+ if (rc < 0)
+ fprintf(stderr, "Error sending netlink message: %d\n", errno);
+ return rc;
+
+}
+
+/* Send netlink message with control over sendmsg() message header */
+int nl_sendmsg(struct nl_sock *sk, struct nl_msg *msg, struct msghdr *hdr)
+{
+ return sendmsg(sk->s_fd, (struct msghdr *) msg, (int) hdr);
+}
+
+/* Create and connect netlink socket */
+int nl_connect(struct nl_sock *sk, int protocol)
+{
+ struct sockaddr addr;
+ socklen_t addrlen;
+ int rc;
+
+ /* Create RX socket */
+ sk->s_fd = socket(PF_NETLINK, SOCK_RAW, protocol);
+ if (sk->s_fd < 0)
+ return -errno;
+
+ /* Set size of RX and TX buffers */
+ if (nl_socket_set_buffer_size(sk, NL_BUFFER_SZ, NL_BUFFER_SZ) < 0)
+ return -errno;
+
+ /* Bind RX socket */
+ rc = bind(sk->s_fd, (struct sockaddr *)&sk->s_local, \
+ sizeof(sk->s_local));
+ if (rc < 0)
+ return -errno;
+ addrlen = sizeof(addr);
+ getsockname(sk->s_fd, &addr, &addrlen);
+
+ return 0;
+
+}
diff --git a/libnl_2/object.c b/libnl_2/object.c
new file mode 100644
index 0000000..c53accf
--- /dev/null
+++ b/libnl_2/object.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* NOTICE: This is a clean room re-implementation of libnl */
+
+#include "netlink-types.h"
+
+void nl_object_put(struct nl_object *obj)
+{
+ obj->ce_refcnt--;
+ if (!obj->ce_refcnt)
+ nl_object_free(obj);
+}
+
+void nl_object_free(struct nl_object *obj)
+{
+ nl_cache_remove(obj);
+}
+
+
diff --git a/libnl_2/socket.c b/libnl_2/socket.c
new file mode 100644
index 0000000..3bcf210
--- /dev/null
+++ b/libnl_2/socket.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* NOTICE: This is a clean room re-implementation of libnl */
+
+#include <errno.h>
+#include <unistd.h>
+#include <malloc.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include "netlink-types.h"
+
+/* Join group */
+int nl_socket_add_membership(struct nl_sock *sk, int group)
+{
+ return setsockopt(sk->s_fd, SOL_NETLINK,
+ NETLINK_ADD_MEMBERSHIP, &group, sizeof(group));
+}
+
+/* Allocate new netlink socket. */
+struct nl_sock *nl_socket_alloc(void)
+{
+ struct nl_sock *sk;
+ struct timeval tv;
+ struct nl_cb *cb;
+
+ sk = (struct nl_sock *) malloc(sizeof(struct nl_sock));
+ if (!sk)
+ goto fail;
+ memset(sk, 0, sizeof(*sk));
+
+ /* Get current time */
+
+ if (gettimeofday(&tv, NULL))
+ return NULL;
+ else
+ sk->s_seq_next = (int) tv.tv_sec;
+
+ /* Create local socket */
+ sk->s_local.nl_family = AF_NETLINK;
+ sk->s_local.nl_pid = 0; /* Kernel fills in pid */
+ sk->s_local.nl_groups = 0; /* No groups */
+
+ /* Create peer socket */
+ sk->s_peer.nl_family = AF_NETLINK;
+ sk->s_peer.nl_pid = 0; /* Kernel */
+ sk->s_peer.nl_groups = 0; /* No groups */
+
+ cb = (struct nl_cb *) malloc(sizeof(struct nl_cb));
+ if (!cb)
+ goto cb_fail;
+ memset(cb, 0, sizeof(*cb));
+ sk->s_cb = nl_cb_alloc(NL_CB_DEFAULT);
+
+
+ return sk;
+cb_fail:
+ free(sk);
+fail:
+ return NULL;
+}
+
+/* Allocate new socket with custom callbacks. */
+struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb)
+{
+ struct nl_sock *sk = nl_socket_alloc();
+ if (!sk)
+ return NULL;
+
+ sk->s_cb = cb;
+ nl_cb_get(cb);
+
+ return sk;
+
+}
+
+/* Free a netlink socket. */
+void nl_socket_free(struct nl_sock *sk)
+{
+ nl_cb_put(sk->s_cb);
+ free(sk);
+}
+
+/* Sets socket buffer size of netlink socket */
+int nl_socket_set_buffer_size(struct nl_sock *sk, int rxbuf, int txbuf)
+{
+ if (setsockopt(sk->s_fd, SOL_SOCKET, SO_SNDBUF, \
+ &rxbuf, (socklen_t) sizeof(rxbuf)))
+ goto error;
+
+ if (setsockopt(sk->s_fd, SOL_SOCKET, SO_RCVBUF, \
+ &txbuf, (socklen_t) sizeof(txbuf)))
+ goto error;
+
+ return 0;
+error:
+ return -errno;
+
+}
+
+int nl_socket_get_fd(struct nl_sock *sk)
+{
+ return sk->s_fd;
+}
+
+
diff --git a/libsysutils/Android.mk b/libsysutils/Android.mk
index 3b1f618..cccf484 100644
--- a/libsysutils/Android.mk
+++ b/libsysutils/Android.mk
@@ -1,10 +1,4 @@
ifneq ($(BUILD_TINY_ANDROID),true)
-BUILD_LIBSYSUTILS := false
-ifneq ($(TARGET_SIMULATOR),true)
- BUILD_LIBSYSUTILS := true
-endif
-
-ifeq ($(BUILD_LIBSYSUTILS),true)
LOCAL_PATH:= $(call my-dir)
@@ -27,11 +21,6 @@
LOCAL_SHARED_LIBRARIES := libcutils
-ifeq ($(TARGET_SIMULATOR),true)
- LOCAL_LDLIBS += -lpthread
-endif
-
include $(BUILD_SHARED_LIBRARY)
endif
-endif
diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp
index c8d3b1f..f2eb664 100644
--- a/libsysutils/src/NetlinkEvent.cpp
+++ b/libsysutils/src/NetlinkEvent.cpp
@@ -21,10 +21,17 @@
#include <sysutils/NetlinkEvent.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <linux/rtnetlink.h>
+#include <linux/if.h>
+
const int NetlinkEvent::NlActionUnknown = 0;
const int NetlinkEvent::NlActionAdd = 1;
const int NetlinkEvent::NlActionRemove = 2;
const int NetlinkEvent::NlActionChange = 3;
+const int NetlinkEvent::NlActionLinkUp = 4;
+const int NetlinkEvent::NlActionLinkDown = 5;
NetlinkEvent::NetlinkEvent() {
mAction = NlActionUnknown;
@@ -56,6 +63,51 @@
}
}
+/*
+ * Parse an binary message from a NETLINK_ROUTE netlink socket.
+ */
+bool NetlinkEvent::parseBinaryNetlinkMessage(char *buffer, int size) {
+ size_t sz = size;
+ const struct nlmsghdr *nh = (struct nlmsghdr *) buffer;
+
+ while (NLMSG_OK(nh, sz) && (nh->nlmsg_type != NLMSG_DONE)) {
+ if (nh->nlmsg_type == RTM_NEWLINK) {
+ int len = nh->nlmsg_len - sizeof(*nh);
+ struct ifinfomsg *ifi;
+
+ if (sizeof(*ifi) <= (size_t) len) {
+ ifi = (ifinfomsg *)NLMSG_DATA(nh);
+
+ if ((ifi->ifi_flags & IFF_LOOPBACK) == 0) {
+ struct rtattr *rta = (struct rtattr *)
+ ((char *) ifi + NLMSG_ALIGN(sizeof(*ifi)));
+ len = NLMSG_PAYLOAD(nh, sizeof(*ifi));
+
+ while(RTA_OK(rta, len)) {
+ switch(rta->rta_type) {
+ case IFLA_IFNAME:
+ char buffer[16 + IFNAMSIZ];
+ snprintf(buffer, sizeof(buffer), "INTERFACE=%s",
+ (char *) RTA_DATA(rta));
+ mParams[0] = strdup(buffer);
+ mAction = (ifi->ifi_flags & IFF_LOWER_UP) ?
+ NlActionLinkUp : NlActionLinkDown;
+ mSubsystem = strdup("net");
+ break;
+ }
+
+ rta = RTA_NEXT(rta, len);
+ }
+ }
+ }
+ }
+
+ nh = NLMSG_NEXT(nh, size);
+ }
+
+ return true;
+}
+
/* If the string between 'str' and 'end' begins with 'prefixlen' characters
* from the 'prefix' array, then return 'str + prefixlen', otherwise return
* NULL.
@@ -76,7 +128,11 @@
#define HAS_CONST_PREFIX(str,end,prefix) has_prefix((str),(end),prefix,CONST_STRLEN(prefix))
-bool NetlinkEvent::decode(char *buffer, int size) {
+/*
+ * Parse an ASCII-formatted message from a NETLINK_KOBJECT_UEVENT
+ * netlink socket.
+ */
+bool NetlinkEvent::parseAsciiNetlinkMessage(char *buffer, int size) {
const char *s = buffer;
const char *end;
int param_idx = 0;
@@ -123,6 +179,14 @@
return true;
}
+bool NetlinkEvent::decode(char *buffer, int size, int format) {
+ if (format == NetlinkListener::NETLINK_FORMAT_BINARY) {
+ return parseBinaryNetlinkMessage(buffer, size);
+ } else {
+ return parseAsciiNetlinkMessage(buffer, size);
+ }
+}
+
const char *NetlinkEvent::findParam(const char *paramName) {
size_t len = strlen(paramName);
for (int i = 0; i < NL_PARAMS_MAX && mParams[i] != NULL; ++i) {
diff --git a/libsysutils/src/NetlinkListener.cpp b/libsysutils/src/NetlinkListener.cpp
index ddf6537..e67b5c6 100644
--- a/libsysutils/src/NetlinkListener.cpp
+++ b/libsysutils/src/NetlinkListener.cpp
@@ -22,55 +22,43 @@
#define LOG_TAG "NetlinkListener"
#include <cutils/log.h>
+#include <cutils/uevent.h>
-#include <sysutils/NetlinkListener.h>
#include <sysutils/NetlinkEvent.h>
+#if 1
+/* temporary version until we can get Motorola to update their
+ * ril.so. Their prebuilt ril.so is using this private class
+ * so changing the NetlinkListener() constructor breaks their ril.
+ */
NetlinkListener::NetlinkListener(int socket) :
SocketListener(socket, false) {
+ mFormat = NETLINK_FORMAT_ASCII;
+}
+#endif
+
+NetlinkListener::NetlinkListener(int socket, int format) :
+ SocketListener(socket, false), mFormat(format) {
}
bool NetlinkListener::onDataAvailable(SocketClient *cli)
{
int socket = cli->getSocket();
ssize_t count;
- char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
- struct sockaddr_nl snl;
- struct iovec iov = {mBuffer, sizeof(mBuffer)};
- struct msghdr hdr = {&snl, sizeof(snl), &iov, 1, cred_msg, sizeof(cred_msg), 0};
- count = TEMP_FAILURE_RETRY(recvmsg(socket, &hdr, 0));
+ count = TEMP_FAILURE_RETRY(uevent_kernel_multicast_recv(socket, mBuffer, sizeof(mBuffer)));
if (count < 0) {
SLOGE("recvmsg failed (%s)", strerror(errno));
return false;
}
- if ((snl.nl_groups != 1) || (snl.nl_pid != 0)) {
- SLOGE("ignoring non-kernel netlink multicast message");
- return false;
- }
-
- struct cmsghdr * cmsg = CMSG_FIRSTHDR(&hdr);
-
- if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
- SLOGE("ignoring message with no sender credentials");
- return false;
- }
-
- struct ucred * cred = (struct ucred *)CMSG_DATA(cmsg);
- if (cred->uid != 0) {
- SLOGE("ignoring message from non-root UID %d", cred->uid);
- return false;
- }
-
NetlinkEvent *evt = new NetlinkEvent();
- if (!evt->decode(mBuffer, count)) {
+ if (!evt->decode(mBuffer, count, mFormat)) {
SLOGE("Error decoding NetlinkEvent");
- goto out;
+ } else {
+ onEvent(evt);
}
- onEvent(evt);
-out:
delete evt;
return true;
}
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 54f4be2..0d476d4 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -19,7 +19,7 @@
export ANDROID_DATA /data
export ASEC_MOUNTPOINT /mnt/asec
export LOOP_MOUNTPOINT /mnt/obb
- export BOOTCLASSPATH /system/framework/core.jar:/system/framework/apache-xml.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/core-junit.jar
+ export BOOTCLASSPATH /system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/filterfw.jar
# Backward compatibility
symlink /system/etc /etc
@@ -115,11 +115,7 @@
chmod 0220 /proc/sysrq-trigger
# create the lost+found directories, so as to enforce our permissions
- mkdir /cache/lost+found 0770
-
- # double check the perms, in case lost+found already exists, and set owner
- chown root root /cache/lost+found
- chmod 0770 /cache/lost+found
+ mkdir /cache/lost+found 0770 root root
on post-fs-data
# We chown/chmod /data again so because mount is run as root + defaults
@@ -129,10 +125,7 @@
# Create dump dir and collect dumps.
# Do this before we mount cache so eventually we can use cache for
# storing dumps on platforms which do not have a dedicated dump partition.
-
- mkdir /data/dontpanic
- chown root log /data/dontpanic
- chmod 0750 /data/dontpanic
+ mkdir /data/dontpanic 0750 root log
# Collect apanic data, free resources and re-arm trigger
copy /proc/apanic_console /data/dontpanic/apanic_console
@@ -150,12 +143,11 @@
mkdir /data/misc/bluetoothd 0770 bluetooth bluetooth
mkdir /data/misc/bluetooth 0770 system system
mkdir /data/misc/keystore 0700 keystore keystore
- mkdir /data/misc/vpn 0770 system system
+ mkdir /data/misc/keychain 0771 system system
+ mkdir /data/misc/vpn 0770 system vpn
mkdir /data/misc/systemkeys 0700 system system
- mkdir /data/misc/vpn/profiles 0770 system system
# give system access to wpa_supplicant.conf for backup and restore
mkdir /data/misc/wifi 0770 wifi wifi
- chmod 0770 /data/misc/wifi
chmod 0660 /data/misc/wifi/wpa_supplicant.conf
mkdir /data/local 0771 shell shell
mkdir /data/local/tmp 0771 shell shell
@@ -164,10 +156,8 @@
mkdir /data/app 0771 system system
mkdir /data/property 0700 root root
- # create dalvik-cache and double-check the perms
+ # create dalvik-cache, so as to enforce our permissions
mkdir /data/dalvik-cache 0771 system system
- chown system system /data/dalvik-cache
- chmod 0771 /data/dalvik-cache
# create resource-cache and double-check the perms
mkdir /data/resource-cache 0771 system system
@@ -175,11 +165,7 @@
chmod 0771 /data/resource-cache
# create the lost+found directories, so as to enforce our permissions
- mkdir /data/lost+found 0770
-
- # double check the perms, in case lost+found already exists, and set owner
- chown root root /data/lost+found
- chmod 0770 /data/lost+found
+ mkdir /data/lost+found 0770 root root
# create directory for DRM plug-ins
mkdir /data/drm 0774 drm drm
@@ -190,6 +176,11 @@
# Set indication (checked by vold) that we have finished this action
#setprop vold.post_fs_data_done 1
+ chown system system /sys/class/android_usb/android0/f_mass_storage/lun/file
+ chmod 0660 /sys/class/android_usb/android0/f_mass_storage/lun/file
+ chown system system /sys/class/android_usb/android0/f_rndis/ethaddr
+ chmod 0660 /sys/class/android_usb/android0/f_rndis/ethaddr
+
on boot
# basic network init
ifup lo
@@ -329,6 +320,28 @@
class_reset late_start
class_reset main
+# USB accessory configuration
+on property:sys.usb.config=accessory
+ write /sys/class/android_usb/android0/enable 0
+ write /sys/class/android_usb/android0/idVendor 18d1
+ write /sys/class/android_usb/android0/idProduct 2d00
+ write /sys/class/android_usb/android0/functions $sys.usb.config
+ write /sys/class/android_usb/android0/enable 1
+ setprop sys.usb.state $sys.usb.config
+
+# USB accessory configuration, with adb
+on property:sys.usb.config=accessory,adb
+ write /sys/class/android_usb/android0/enable 0
+ write /sys/class/android_usb/android0/idVendor 18d1
+ write /sys/class/android_usb/android0/idProduct 2d01
+ write /sys/class/android_usb/android0/functions $sys.usb.config
+ write /sys/class/android_usb/android0/enable 1
+ start adbd
+ setprop sys.usb.state $sys.usb.config
+
+on property:persist.sys.usb.config=*
+ setprop sys.usb.config $persist.sys.usb.config
+
## Daemon processes to be run by init.
##
service ueventd /sbin/ueventd
@@ -345,7 +358,7 @@
on property:ro.debuggable=1
start console
-# adbd is controlled by the persist.service.adb.enable system property
+# adbd is controlled via property triggers in init.<platform>.usb.rc
service adbd /sbin/adbd
class core
disabled
@@ -354,11 +367,17 @@
on property:ro.kernel.qemu=1
start adbd
-on property:persist.service.adb.enable=1
- start adbd
-
-on property:persist.service.adb.enable=0
- stop adbd
+# This property trigger has added to imitiate the previous behavior of "adb root".
+# The adb gadget driver used to reset the USB bus when the adbd daemon exited,
+# and the host side adb relied on this behavior to force it to reconnect with the
+# new adbd instance after init relaunches it. So now we force the USB bus to reset
+# here when adbd sets the service.adb.root property to 1. We also restart adbd here
+# rather than waiting for init to notice its death and restarting it so the timing
+# of USB resetting and adb restarting more closely matches the previous behavior.
+on property:service.adb.root=1
+ write /sys/class/android_usb/android0/enable 0
+ restart adbd
+ write /sys/class/android_usb/android0/enable 1
service servicemanager /system/bin/servicemanager
class core
@@ -399,7 +418,6 @@
socket zygote stream 666
onrestart write /sys/android_power/request_state wake
onrestart write /sys/power/state on
- onrestart restart surfaceflinger
onrestart restart media
onrestart restart netd
@@ -411,7 +429,8 @@
service media /system/bin/mediaserver
class main
user media
- group audio camera inet net_bt net_bt_admin
+ # STOPSHIP: remove system from mediaserver groups
+ group audio camera inet net_bt net_bt_admin system
ioprio rt 4
service bootanim /system/bin/bootanimation
@@ -447,8 +466,8 @@
service racoon /system/bin/racoon
class main
socket racoon stream 600 system system
- # racoon will setuid to vpn after getting necessary resources.
- group net_admin
+ # IKE uses UDP port 500. Racoon will setuid to vpn after binding the port.
+ group vpn net_admin
disabled
oneshot
diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc
index 51a4337..438cf0a 100644
--- a/rootdir/ueventd.rc
+++ b/rootdir/ueventd.rc
@@ -70,11 +70,11 @@
/dev/bus/usb/* 0660 root usb
/dev/mtp_usb 0660 root mtp
/dev/usb_accessory 0660 root usb
+/dev/tun 0660 system vpn
# CDMA radio interface MUX
/dev/ts0710mux* 0640 radio radio
/dev/ppp 0660 radio vpn
-/dev/tun 0640 vpn vpn
# sysfs properties
/sys/devices/virtual/input/input* enable 0660 root input
diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c
index 7112ebf..bd00311 100644
--- a/sdcard/sdcard.c
+++ b/sdcard/sdcard.c
@@ -326,15 +326,9 @@
fuse->all = &fuse->root;
+ memset(&fuse->root, 0, sizeof(fuse->root));
fuse->root.nid = FUSE_ROOT_ID; /* 1 */
- fuse->root.next = 0;
- fuse->root.child = 0;
- fuse->root.parent = 0;
-
- fuse->root.all = 0;
fuse->root.refcount = 2;
-
- fuse->root.name = 0;
rename_node(&fuse->root, path);
}
diff --git a/toolbox/Android.mk b/toolbox/Android.mk
index ff01172..d7a675a 100644
--- a/toolbox/Android.mk
+++ b/toolbox/Android.mk
@@ -54,8 +54,13 @@
vmstat \
nandread \
ionice \
+ touch \
lsof
+ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+TOOLS += r
+endif
+
LOCAL_SRC_FILES:= \
dynarray.c \
toolbox.c \
diff --git a/toolbox/getevent.c b/toolbox/getevent.c
index 256720d..c0ac94a 100644
--- a/toolbox/getevent.c
+++ b/toolbox/getevent.c
@@ -8,9 +8,11 @@
#include <sys/inotify.h>
#include <sys/limits.h>
#include <sys/poll.h>
-#include <linux/input.h> // this does not compile
+#include <linux/input.h>
#include <errno.h>
+#include "getevent.h"
+
static struct pollfd *ufds;
static char **device_names;
static int nfds;
@@ -22,18 +24,65 @@
PRINT_DEVICE_INFO = 1U << 3,
PRINT_VERSION = 1U << 4,
PRINT_POSSIBLE_EVENTS = 1U << 5,
+ PRINT_INPUT_PROPS = 1U << 6,
+
+ PRINT_ALL_INFO = (1U << 7) - 1,
+
+ PRINT_LABELS = 1U << 16,
};
-static int print_possible_events(int fd)
+static const char *get_label(const struct label *labels, int value)
+{
+ while(labels->name && value != labels->value) {
+ labels++;
+ }
+ return labels->name;
+}
+
+static int print_input_props(int fd)
+{
+ uint8_t bits[INPUT_PROP_CNT / 8];
+ int i, j;
+ int res;
+ int count;
+ const char *bit_label;
+
+ printf(" input props:\n");
+ res = ioctl(fd, EVIOCGPROP(sizeof(bits)), bits);
+ if(res < 0) {
+ printf(" <not available\n");
+ return 1;
+ }
+ count = 0;
+ for(i = 0; i < res; i++) {
+ for(j = 0; j < 8; j++) {
+ if (bits[i] & 1 << j) {
+ bit_label = get_label(input_prop_labels, i * 8 + j);
+ if(bit_label)
+ printf(" %s\n", bit_label);
+ else
+ printf(" %04x\n", i * 8 + j);
+ count++;
+ }
+ }
+ }
+ if (!count)
+ printf(" <none>\n");
+ return 0;
+}
+
+static int print_possible_events(int fd, int print_flags)
{
uint8_t *bits = NULL;
ssize_t bits_size = 0;
const char* label;
int i, j, k;
int res, res2;
-
+ struct label* bit_labels;
+ const char *bit_label;
+
printf(" events:\n");
- for(i = 0; i <= EV_MAX; i++) {
+ for(i = EV_KEY; i <= EV_MAX; i++) { // skip EV_SYN since we cannot query its available codes
int count = 0;
while(1) {
res = ioctl(fd, EVIOCGBIT(i, bits_size), bits);
@@ -42,52 +91,64 @@
bits_size = res + 16;
bits = realloc(bits, bits_size * 2);
if(bits == NULL) {
- fprintf(stderr, "failed to allocate buffer of size %d\n", bits_size);
+ fprintf(stderr, "failed to allocate buffer of size %d\n", (int)bits_size);
return 1;
}
}
res2 = 0;
switch(i) {
- case EV_SYN:
- label = "SYN";
- break;
case EV_KEY:
res2 = ioctl(fd, EVIOCGKEY(res), bits + bits_size);
label = "KEY";
+ bit_labels = key_labels;
break;
case EV_REL:
label = "REL";
+ bit_labels = rel_labels;
break;
case EV_ABS:
label = "ABS";
+ bit_labels = abs_labels;
break;
case EV_MSC:
label = "MSC";
+ bit_labels = msc_labels;
break;
case EV_LED:
res2 = ioctl(fd, EVIOCGLED(res), bits + bits_size);
label = "LED";
+ bit_labels = led_labels;
break;
case EV_SND:
res2 = ioctl(fd, EVIOCGSND(res), bits + bits_size);
label = "SND";
+ bit_labels = snd_labels;
break;
case EV_SW:
res2 = ioctl(fd, EVIOCGSW(bits_size), bits + bits_size);
label = "SW ";
+ bit_labels = sw_labels;
break;
case EV_REP:
label = "REP";
+ bit_labels = rep_labels;
break;
case EV_FF:
label = "FF ";
+ bit_labels = ff_labels;
break;
case EV_PWR:
label = "PWR";
+ bit_labels = NULL;
+ break;
+ case EV_FF_STATUS:
+ label = "FFS";
+ bit_labels = ff_status_labels;
break;
default:
res2 = 0;
label = "???";
+ bit_labels = NULL;
}
for(j = 0; j < res; j++) {
for(k = 0; k < 8; k++)
@@ -99,13 +160,21 @@
down = ' ';
if(count == 0)
printf(" %s (%04x):", label, i);
- else if((count & 0x7) == 0 || i == EV_ABS)
+ else if((count & (print_flags & PRINT_LABELS ? 0x3 : 0x7)) == 0 || i == EV_ABS)
printf("\n ");
- printf(" %04x%c", j * 8 + k, down);
+ if(bit_labels && (print_flags & PRINT_LABELS)) {
+ bit_label = get_label(bit_labels, j * 8 + k);
+ if(bit_label)
+ printf(" %.20s%c%*s", bit_label, down, 20 - strlen(bit_label), "");
+ else
+ printf(" %04x%c ", j * 8 + k, down);
+ } else {
+ printf(" %04x%c", j * 8 + k, down);
+ }
if(i == EV_ABS) {
struct input_absinfo abs;
if(ioctl(fd, EVIOCGABS(j * 8 + k), &abs) == 0) {
- printf(" value %d, min %d, max %d, fuzz %d flat %d", abs.value, abs.minimum, abs.maximum, abs.fuzz, abs.flat);
+ printf(" : value %d, min %d, max %d, fuzz %d flat %d", abs.value, abs.minimum, abs.maximum, abs.fuzz, abs.flat);
}
}
count++;
@@ -118,6 +187,73 @@
return 0;
}
+static void print_event(int type, int code, int value, int print_flags)
+{
+ const char *type_label, *code_label, *value_label;
+
+ if (print_flags & PRINT_LABELS) {
+ type_label = get_label(ev_labels, type);
+ code_label = NULL;
+ value_label = NULL;
+
+ switch(type) {
+ case EV_SYN:
+ code_label = get_label(syn_labels, code);
+ break;
+ case EV_KEY:
+ code_label = get_label(key_labels, code);
+ value_label = get_label(key_value_labels, value);
+ break;
+ case EV_REL:
+ code_label = get_label(rel_labels, code);
+ break;
+ case EV_ABS:
+ code_label = get_label(abs_labels, code);
+ switch(code) {
+ case ABS_MT_TOOL_TYPE:
+ value_label = get_label(mt_tool_labels, value);
+ }
+ break;
+ case EV_MSC:
+ code_label = get_label(msc_labels, code);
+ break;
+ case EV_LED:
+ code_label = get_label(led_labels, code);
+ break;
+ case EV_SND:
+ code_label = get_label(snd_labels, code);
+ break;
+ case EV_SW:
+ code_label = get_label(sw_labels, code);
+ break;
+ case EV_REP:
+ code_label = get_label(rep_labels, code);
+ break;
+ case EV_FF:
+ code_label = get_label(ff_labels, code);
+ break;
+ case EV_FF_STATUS:
+ code_label = get_label(ff_status_labels, code);
+ break;
+ }
+
+ if (type_label)
+ printf("%-12.12s", type_label);
+ else
+ printf("%04x ", type);
+ if (code_label)
+ printf(" %-20.20s", code_label);
+ else
+ printf(" %04x ", code);
+ if (value_label)
+ printf(" %-20.20s", value_label);
+ else
+ printf(" %08x ", value);
+ } else {
+ printf("%04x %04x %08x", type, code, value);
+ }
+}
+
static int open_device(const char *device, int print_flags)
{
int version;
@@ -193,7 +329,11 @@
version >> 16, (version >> 8) & 0xff, version & 0xff);
if(print_flags & PRINT_POSSIBLE_EVENTS) {
- print_possible_events(fd);
+ print_possible_events(fd, print_flags);
+ }
+
+ if(print_flags & PRINT_INPUT_PROPS) {
+ print_input_props(fd);
}
ufds[nfds].fd = fd;
@@ -292,13 +432,15 @@
static void usage(int argc, char *argv[])
{
- fprintf(stderr, "Usage: %s [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-p] [-q] [-c count] [-r] [device]\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-p] [-i] [-l] [-q] [-c count] [-r] [device]\n", argv[0]);
fprintf(stderr, " -t: show time stamps\n");
fprintf(stderr, " -n: don't print newlines\n");
fprintf(stderr, " -s: print switch states for given bits\n");
fprintf(stderr, " -S: print all switch states\n");
- fprintf(stderr, " -v: verbosity mask (errs=1, dev=2, name=4, info=8, vers=16, pos. events=32)\n");
+ fprintf(stderr, " -v: verbosity mask (errs=1, dev=2, name=4, info=8, vers=16, pos. events=32, props=64)\n");
fprintf(stderr, " -p: show possible events (errs, dev, name, pos. events)\n");
+ fprintf(stderr, " -i: show all device info and possible events\n");
+ fprintf(stderr, " -l: label event types and names in plain text\n");
fprintf(stderr, " -q: quiet (clear verbosity mask)\n");
fprintf(stderr, " -c: print given number of events then exit\n");
fprintf(stderr, " -r: print rate events are received\n");
@@ -316,7 +458,7 @@
uint16_t get_switch = 0;
struct input_event event;
int version;
- int print_flags = PRINT_DEVICE_ERRORS | PRINT_DEVICE | PRINT_DEVICE_NAME;
+ int print_flags = 0;
int print_flags_set = 0;
int dont_block = -1;
int event_count = 0;
@@ -327,7 +469,7 @@
opterr = 0;
do {
- c = getopt(argc, argv, "tns:Sv::pqc:rh");
+ c = getopt(argc, argv, "tns:Sv::pilqc:rh");
if (c == EOF)
break;
switch (c) {
@@ -349,19 +491,27 @@
break;
case 'v':
if(optarg)
- print_flags = strtoul(optarg, NULL, 0);
+ print_flags |= strtoul(optarg, NULL, 0);
else
print_flags |= PRINT_DEVICE | PRINT_DEVICE_NAME | PRINT_DEVICE_INFO | PRINT_VERSION;
print_flags_set = 1;
break;
case 'p':
- print_flags = PRINT_DEVICE_ERRORS | PRINT_DEVICE | PRINT_DEVICE_NAME | PRINT_POSSIBLE_EVENTS;
+ print_flags |= PRINT_DEVICE_ERRORS | PRINT_DEVICE | PRINT_DEVICE_NAME | PRINT_POSSIBLE_EVENTS;
print_flags_set = 1;
if(dont_block == -1)
dont_block = 1;
break;
+ case 'i':
+ print_flags |= PRINT_ALL_INFO;
+ print_flags_set = 1;
+ if(dont_block == -1)
+ dont_block = 1;
+ break;
+ case 'l':
+ print_flags |= PRINT_LABELS;
+ break;
case 'q':
- print_flags = 0;
print_flags_set = 1;
break;
case 'c':
@@ -396,13 +546,14 @@
ufds[0].events = POLLIN;
if(device) {
if(!print_flags_set)
- print_flags = PRINT_DEVICE_ERRORS;
+ print_flags |= PRINT_DEVICE_ERRORS;
res = open_device(device, print_flags);
if(res < 0) {
return 1;
}
- }
- else {
+ } else {
+ if(!print_flags_set)
+ print_flags |= PRINT_DEVICE_ERRORS | PRINT_DEVICE | PRINT_DEVICE_NAME;
print_device = 1;
res = inotify_add_watch(ufds[0].fd, device_path, IN_DELETE | IN_CREATE);
if(res < 0) {
@@ -451,7 +602,7 @@
}
if(print_device)
printf("%s: ", device_names[i]);
- printf("%04x %04x %08x", event.type, event.code, event.value);
+ print_event(event.type, event.code, event.value, print_flags);
if(sync_rate && event.type == 0 && event.code == 0) {
int64_t now = event.time.tv_sec * 1000000LL + event.time.tv_usec;
if(last_sync_time)
diff --git a/toolbox/getevent.h b/toolbox/getevent.h
new file mode 100644
index 0000000..2b76209
--- /dev/null
+++ b/toolbox/getevent.h
@@ -0,0 +1,725 @@
+#include <linux/input.h>
+
+struct label {
+ const char *name;
+ int value;
+};
+
+#define LABEL(constant) { #constant, constant }
+#define LABEL_END { NULL, -1 }
+
+static struct label input_prop_labels[] = {
+ LABEL(INPUT_PROP_POINTER),
+ LABEL(INPUT_PROP_DIRECT),
+ LABEL(INPUT_PROP_BUTTONPAD),
+ LABEL(INPUT_PROP_SEMI_MT),
+ LABEL_END,
+};
+
+static struct label ev_labels[] = {
+ LABEL(EV_SYN),
+ LABEL(EV_KEY),
+ LABEL(EV_REL),
+ LABEL(EV_ABS),
+ LABEL(EV_MSC),
+ LABEL(EV_SW),
+ LABEL(EV_LED),
+ LABEL(EV_SND),
+ LABEL(EV_REP),
+ LABEL(EV_FF),
+ LABEL(EV_PWR),
+ LABEL(EV_FF_STATUS),
+ LABEL_END,
+};
+
+static struct label syn_labels[] = {
+ LABEL(SYN_REPORT),
+ LABEL(SYN_CONFIG),
+ LABEL(SYN_MT_REPORT),
+ LABEL(SYN_DROPPED),
+ LABEL_END,
+};
+
+static struct label key_labels[] = {
+ LABEL(KEY_RESERVED),
+ LABEL(KEY_ESC),
+ LABEL(KEY_1),
+ LABEL(KEY_2),
+ LABEL(KEY_3),
+ LABEL(KEY_4),
+ LABEL(KEY_5),
+ LABEL(KEY_6),
+ LABEL(KEY_7),
+ LABEL(KEY_8),
+ LABEL(KEY_9),
+ LABEL(KEY_0),
+ LABEL(KEY_MINUS),
+ LABEL(KEY_EQUAL),
+ LABEL(KEY_BACKSPACE),
+ LABEL(KEY_TAB),
+ LABEL(KEY_Q),
+ LABEL(KEY_W),
+ LABEL(KEY_E),
+ LABEL(KEY_R),
+ LABEL(KEY_T),
+ LABEL(KEY_Y),
+ LABEL(KEY_U),
+ LABEL(KEY_I),
+ LABEL(KEY_O),
+ LABEL(KEY_P),
+ LABEL(KEY_LEFTBRACE),
+ LABEL(KEY_RIGHTBRACE),
+ LABEL(KEY_ENTER),
+ LABEL(KEY_LEFTCTRL),
+ LABEL(KEY_A),
+ LABEL(KEY_S),
+ LABEL(KEY_D),
+ LABEL(KEY_F),
+ LABEL(KEY_G),
+ LABEL(KEY_H),
+ LABEL(KEY_J),
+ LABEL(KEY_K),
+ LABEL(KEY_L),
+ LABEL(KEY_SEMICOLON),
+ LABEL(KEY_APOSTROPHE),
+ LABEL(KEY_GRAVE),
+ LABEL(KEY_LEFTSHIFT),
+ LABEL(KEY_BACKSLASH),
+ LABEL(KEY_Z),
+ LABEL(KEY_X),
+ LABEL(KEY_C),
+ LABEL(KEY_V),
+ LABEL(KEY_B),
+ LABEL(KEY_N),
+ LABEL(KEY_M),
+ LABEL(KEY_COMMA),
+ LABEL(KEY_DOT),
+ LABEL(KEY_SLASH),
+ LABEL(KEY_RIGHTSHIFT),
+ LABEL(KEY_KPASTERISK),
+ LABEL(KEY_LEFTALT),
+ LABEL(KEY_SPACE),
+ LABEL(KEY_CAPSLOCK),
+ LABEL(KEY_F1),
+ LABEL(KEY_F2),
+ LABEL(KEY_F3),
+ LABEL(KEY_F4),
+ LABEL(KEY_F5),
+ LABEL(KEY_F6),
+ LABEL(KEY_F7),
+ LABEL(KEY_F8),
+ LABEL(KEY_F9),
+ LABEL(KEY_F10),
+ LABEL(KEY_NUMLOCK),
+ LABEL(KEY_SCROLLLOCK),
+ LABEL(KEY_KP7),
+ LABEL(KEY_KP8),
+ LABEL(KEY_KP9),
+ LABEL(KEY_KPMINUS),
+ LABEL(KEY_KP4),
+ LABEL(KEY_KP5),
+ LABEL(KEY_KP6),
+ LABEL(KEY_KPPLUS),
+ LABEL(KEY_KP1),
+ LABEL(KEY_KP2),
+ LABEL(KEY_KP3),
+ LABEL(KEY_KP0),
+ LABEL(KEY_KPDOT),
+ LABEL(KEY_ZENKAKUHANKAKU),
+ LABEL(KEY_102ND),
+ LABEL(KEY_F11),
+ LABEL(KEY_F12),
+ LABEL(KEY_RO),
+ LABEL(KEY_KATAKANA),
+ LABEL(KEY_HIRAGANA),
+ LABEL(KEY_HENKAN),
+ LABEL(KEY_KATAKANAHIRAGANA),
+ LABEL(KEY_MUHENKAN),
+ LABEL(KEY_KPJPCOMMA),
+ LABEL(KEY_KPENTER),
+ LABEL(KEY_RIGHTCTRL),
+ LABEL(KEY_KPSLASH),
+ LABEL(KEY_SYSRQ),
+ LABEL(KEY_RIGHTALT),
+ LABEL(KEY_LINEFEED),
+ LABEL(KEY_HOME),
+ LABEL(KEY_UP),
+ LABEL(KEY_PAGEUP),
+ LABEL(KEY_LEFT),
+ LABEL(KEY_RIGHT),
+ LABEL(KEY_END),
+ LABEL(KEY_DOWN),
+ LABEL(KEY_PAGEDOWN),
+ LABEL(KEY_INSERT),
+ LABEL(KEY_DELETE),
+ LABEL(KEY_MACRO),
+ LABEL(KEY_MUTE),
+ LABEL(KEY_VOLUMEDOWN),
+ LABEL(KEY_VOLUMEUP),
+ LABEL(KEY_POWER),
+ LABEL(KEY_KPEQUAL),
+ LABEL(KEY_KPPLUSMINUS),
+ LABEL(KEY_PAUSE),
+ LABEL(KEY_SCALE),
+ LABEL(KEY_KPCOMMA),
+ LABEL(KEY_HANGEUL),
+ LABEL(KEY_HANGUEL),
+ LABEL(KEY_HANJA),
+ LABEL(KEY_YEN),
+ LABEL(KEY_LEFTMETA),
+ LABEL(KEY_RIGHTMETA),
+ LABEL(KEY_COMPOSE),
+ LABEL(KEY_STOP),
+ LABEL(KEY_AGAIN),
+ LABEL(KEY_PROPS),
+ LABEL(KEY_UNDO),
+ LABEL(KEY_FRONT),
+ LABEL(KEY_COPY),
+ LABEL(KEY_OPEN),
+ LABEL(KEY_PASTE),
+ LABEL(KEY_FIND),
+ LABEL(KEY_CUT),
+ LABEL(KEY_HELP),
+ LABEL(KEY_MENU),
+ LABEL(KEY_CALC),
+ LABEL(KEY_SETUP),
+ LABEL(KEY_SLEEP),
+ LABEL(KEY_WAKEUP),
+ LABEL(KEY_FILE),
+ LABEL(KEY_SENDFILE),
+ LABEL(KEY_DELETEFILE),
+ LABEL(KEY_XFER),
+ LABEL(KEY_PROG1),
+ LABEL(KEY_PROG2),
+ LABEL(KEY_WWW),
+ LABEL(KEY_MSDOS),
+ LABEL(KEY_COFFEE),
+ LABEL(KEY_SCREENLOCK),
+ LABEL(KEY_DIRECTION),
+ LABEL(KEY_CYCLEWINDOWS),
+ LABEL(KEY_MAIL),
+ LABEL(KEY_BOOKMARKS),
+ LABEL(KEY_COMPUTER),
+ LABEL(KEY_BACK),
+ LABEL(KEY_FORWARD),
+ LABEL(KEY_CLOSECD),
+ LABEL(KEY_EJECTCD),
+ LABEL(KEY_EJECTCLOSECD),
+ LABEL(KEY_NEXTSONG),
+ LABEL(KEY_PLAYPAUSE),
+ LABEL(KEY_PREVIOUSSONG),
+ LABEL(KEY_STOPCD),
+ LABEL(KEY_RECORD),
+ LABEL(KEY_REWIND),
+ LABEL(KEY_PHONE),
+ LABEL(KEY_ISO),
+ LABEL(KEY_CONFIG),
+ LABEL(KEY_HOMEPAGE),
+ LABEL(KEY_REFRESH),
+ LABEL(KEY_EXIT),
+ LABEL(KEY_MOVE),
+ LABEL(KEY_EDIT),
+ LABEL(KEY_SCROLLUP),
+ LABEL(KEY_SCROLLDOWN),
+ LABEL(KEY_KPLEFTPAREN),
+ LABEL(KEY_KPRIGHTPAREN),
+ LABEL(KEY_NEW),
+ LABEL(KEY_REDO),
+ LABEL(KEY_F13),
+ LABEL(KEY_F14),
+ LABEL(KEY_F15),
+ LABEL(KEY_F16),
+ LABEL(KEY_F17),
+ LABEL(KEY_F18),
+ LABEL(KEY_F19),
+ LABEL(KEY_F20),
+ LABEL(KEY_F21),
+ LABEL(KEY_F22),
+ LABEL(KEY_F23),
+ LABEL(KEY_F24),
+ LABEL(KEY_PLAYCD),
+ LABEL(KEY_PAUSECD),
+ LABEL(KEY_PROG3),
+ LABEL(KEY_PROG4),
+ LABEL(KEY_DASHBOARD),
+ LABEL(KEY_SUSPEND),
+ LABEL(KEY_CLOSE),
+ LABEL(KEY_PLAY),
+ LABEL(KEY_FASTFORWARD),
+ LABEL(KEY_BASSBOOST),
+ LABEL(KEY_PRINT),
+ LABEL(KEY_HP),
+ LABEL(KEY_CAMERA),
+ LABEL(KEY_SOUND),
+ LABEL(KEY_QUESTION),
+ LABEL(KEY_EMAIL),
+ LABEL(KEY_CHAT),
+ LABEL(KEY_SEARCH),
+ LABEL(KEY_CONNECT),
+ LABEL(KEY_FINANCE),
+ LABEL(KEY_SPORT),
+ LABEL(KEY_SHOP),
+ LABEL(KEY_ALTERASE),
+ LABEL(KEY_CANCEL),
+ LABEL(KEY_BRIGHTNESSDOWN),
+ LABEL(KEY_BRIGHTNESSUP),
+ LABEL(KEY_MEDIA),
+ LABEL(KEY_SWITCHVIDEOMODE),
+ LABEL(KEY_KBDILLUMTOGGLE),
+ LABEL(KEY_KBDILLUMDOWN),
+ LABEL(KEY_KBDILLUMUP),
+ LABEL(KEY_SEND),
+ LABEL(KEY_REPLY),
+ LABEL(KEY_FORWARDMAIL),
+ LABEL(KEY_SAVE),
+ LABEL(KEY_DOCUMENTS),
+ LABEL(KEY_BATTERY),
+ LABEL(KEY_BLUETOOTH),
+ LABEL(KEY_WLAN),
+ LABEL(KEY_UWB),
+ LABEL(KEY_UNKNOWN),
+ LABEL(KEY_VIDEO_NEXT),
+ LABEL(KEY_VIDEO_PREV),
+ LABEL(KEY_BRIGHTNESS_CYCLE),
+ LABEL(KEY_BRIGHTNESS_ZERO),
+ LABEL(KEY_DISPLAY_OFF),
+ LABEL(KEY_WIMAX),
+ LABEL(KEY_RFKILL),
+ LABEL(BTN_0),
+ LABEL(BTN_1),
+ LABEL(BTN_2),
+ LABEL(BTN_3),
+ LABEL(BTN_4),
+ LABEL(BTN_5),
+ LABEL(BTN_6),
+ LABEL(BTN_7),
+ LABEL(BTN_8),
+ LABEL(BTN_9),
+ LABEL(BTN_LEFT),
+ LABEL(BTN_RIGHT),
+ LABEL(BTN_MIDDLE),
+ LABEL(BTN_SIDE),
+ LABEL(BTN_EXTRA),
+ LABEL(BTN_FORWARD),
+ LABEL(BTN_BACK),
+ LABEL(BTN_TASK),
+ LABEL(BTN_JOYSTICK),
+ LABEL(BTN_TRIGGER),
+ LABEL(BTN_THUMB),
+ LABEL(BTN_THUMB2),
+ LABEL(BTN_TOP),
+ LABEL(BTN_TOP2),
+ LABEL(BTN_PINKIE),
+ LABEL(BTN_BASE),
+ LABEL(BTN_BASE2),
+ LABEL(BTN_BASE3),
+ LABEL(BTN_BASE4),
+ LABEL(BTN_BASE5),
+ LABEL(BTN_BASE6),
+ LABEL(BTN_DEAD),
+ LABEL(BTN_A),
+ LABEL(BTN_B),
+ LABEL(BTN_C),
+ LABEL(BTN_X),
+ LABEL(BTN_Y),
+ LABEL(BTN_Z),
+ LABEL(BTN_TL),
+ LABEL(BTN_TR),
+ LABEL(BTN_TL2),
+ LABEL(BTN_TR2),
+ LABEL(BTN_SELECT),
+ LABEL(BTN_START),
+ LABEL(BTN_MODE),
+ LABEL(BTN_THUMBL),
+ LABEL(BTN_THUMBR),
+ LABEL(BTN_TOOL_PEN),
+ LABEL(BTN_TOOL_RUBBER),
+ LABEL(BTN_TOOL_BRUSH),
+ LABEL(BTN_TOOL_PENCIL),
+ LABEL(BTN_TOOL_AIRBRUSH),
+ LABEL(BTN_TOOL_FINGER),
+ LABEL(BTN_TOOL_MOUSE),
+ LABEL(BTN_TOOL_LENS),
+ LABEL(BTN_TOUCH),
+ LABEL(BTN_STYLUS),
+ LABEL(BTN_STYLUS2),
+ LABEL(BTN_TOOL_DOUBLETAP),
+ LABEL(BTN_TOOL_TRIPLETAP),
+ LABEL(BTN_TOOL_QUADTAP),
+ LABEL(BTN_GEAR_DOWN),
+ LABEL(BTN_GEAR_UP),
+ LABEL(KEY_OK),
+ LABEL(KEY_SELECT),
+ LABEL(KEY_GOTO),
+ LABEL(KEY_CLEAR),
+ LABEL(KEY_POWER2),
+ LABEL(KEY_OPTION),
+ LABEL(KEY_INFO),
+ LABEL(KEY_TIME),
+ LABEL(KEY_VENDOR),
+ LABEL(KEY_ARCHIVE),
+ LABEL(KEY_PROGRAM),
+ LABEL(KEY_CHANNEL),
+ LABEL(KEY_FAVORITES),
+ LABEL(KEY_EPG),
+ LABEL(KEY_PVR),
+ LABEL(KEY_MHP),
+ LABEL(KEY_LANGUAGE),
+ LABEL(KEY_TITLE),
+ LABEL(KEY_SUBTITLE),
+ LABEL(KEY_ANGLE),
+ LABEL(KEY_ZOOM),
+ LABEL(KEY_MODE),
+ LABEL(KEY_KEYBOARD),
+ LABEL(KEY_SCREEN),
+ LABEL(KEY_PC),
+ LABEL(KEY_TV),
+ LABEL(KEY_TV2),
+ LABEL(KEY_VCR),
+ LABEL(KEY_VCR2),
+ LABEL(KEY_SAT),
+ LABEL(KEY_SAT2),
+ LABEL(KEY_CD),
+ LABEL(KEY_TAPE),
+ LABEL(KEY_RADIO),
+ LABEL(KEY_TUNER),
+ LABEL(KEY_PLAYER),
+ LABEL(KEY_TEXT),
+ LABEL(KEY_DVD),
+ LABEL(KEY_AUX),
+ LABEL(KEY_MP3),
+ LABEL(KEY_AUDIO),
+ LABEL(KEY_VIDEO),
+ LABEL(KEY_DIRECTORY),
+ LABEL(KEY_LIST),
+ LABEL(KEY_MEMO),
+ LABEL(KEY_CALENDAR),
+ LABEL(KEY_RED),
+ LABEL(KEY_GREEN),
+ LABEL(KEY_YELLOW),
+ LABEL(KEY_BLUE),
+ LABEL(KEY_CHANNELUP),
+ LABEL(KEY_CHANNELDOWN),
+ LABEL(KEY_FIRST),
+ LABEL(KEY_LAST),
+ LABEL(KEY_AB),
+ LABEL(KEY_NEXT),
+ LABEL(KEY_RESTART),
+ LABEL(KEY_SLOW),
+ LABEL(KEY_SHUFFLE),
+ LABEL(KEY_BREAK),
+ LABEL(KEY_PREVIOUS),
+ LABEL(KEY_DIGITS),
+ LABEL(KEY_TEEN),
+ LABEL(KEY_TWEN),
+ LABEL(KEY_VIDEOPHONE),
+ LABEL(KEY_GAMES),
+ LABEL(KEY_ZOOMIN),
+ LABEL(KEY_ZOOMOUT),
+ LABEL(KEY_ZOOMRESET),
+ LABEL(KEY_WORDPROCESSOR),
+ LABEL(KEY_EDITOR),
+ LABEL(KEY_SPREADSHEET),
+ LABEL(KEY_GRAPHICSEDITOR),
+ LABEL(KEY_PRESENTATION),
+ LABEL(KEY_DATABASE),
+ LABEL(KEY_NEWS),
+ LABEL(KEY_VOICEMAIL),
+ LABEL(KEY_ADDRESSBOOK),
+ LABEL(KEY_MESSENGER),
+ LABEL(KEY_DISPLAYTOGGLE),
+ LABEL(KEY_SPELLCHECK),
+ LABEL(KEY_LOGOFF),
+ LABEL(KEY_DOLLAR),
+ LABEL(KEY_EURO),
+ LABEL(KEY_FRAMEBACK),
+ LABEL(KEY_FRAMEFORWARD),
+ LABEL(KEY_CONTEXT_MENU),
+ LABEL(KEY_MEDIA_REPEAT),
+ LABEL(KEY_10CHANNELSUP),
+ LABEL(KEY_10CHANNELSDOWN),
+ LABEL(KEY_IMAGES),
+ LABEL(KEY_DEL_EOL),
+ LABEL(KEY_DEL_EOS),
+ LABEL(KEY_INS_LINE),
+ LABEL(KEY_DEL_LINE),
+ LABEL(KEY_FN),
+ LABEL(KEY_FN_ESC),
+ LABEL(KEY_FN_F1),
+ LABEL(KEY_FN_F2),
+ LABEL(KEY_FN_F3),
+ LABEL(KEY_FN_F4),
+ LABEL(KEY_FN_F5),
+ LABEL(KEY_FN_F6),
+ LABEL(KEY_FN_F7),
+ LABEL(KEY_FN_F8),
+ LABEL(KEY_FN_F9),
+ LABEL(KEY_FN_F10),
+ LABEL(KEY_FN_F11),
+ LABEL(KEY_FN_F12),
+ LABEL(KEY_FN_1),
+ LABEL(KEY_FN_2),
+ LABEL(KEY_FN_D),
+ LABEL(KEY_FN_E),
+ LABEL(KEY_FN_F),
+ LABEL(KEY_FN_S),
+ LABEL(KEY_FN_B),
+ LABEL(KEY_BRL_DOT1),
+ LABEL(KEY_BRL_DOT2),
+ LABEL(KEY_BRL_DOT3),
+ LABEL(KEY_BRL_DOT4),
+ LABEL(KEY_BRL_DOT5),
+ LABEL(KEY_BRL_DOT6),
+ LABEL(KEY_BRL_DOT7),
+ LABEL(KEY_BRL_DOT8),
+ LABEL(KEY_BRL_DOT9),
+ LABEL(KEY_BRL_DOT10),
+ LABEL(KEY_NUMERIC_0),
+ LABEL(KEY_NUMERIC_1),
+ LABEL(KEY_NUMERIC_2),
+ LABEL(KEY_NUMERIC_3),
+ LABEL(KEY_NUMERIC_4),
+ LABEL(KEY_NUMERIC_5),
+ LABEL(KEY_NUMERIC_6),
+ LABEL(KEY_NUMERIC_7),
+ LABEL(KEY_NUMERIC_8),
+ LABEL(KEY_NUMERIC_9),
+ LABEL(KEY_NUMERIC_STAR),
+ LABEL(KEY_NUMERIC_POUND),
+ LABEL(KEY_CAMERA_FOCUS),
+ LABEL(KEY_WPS_BUTTON),
+ LABEL(KEY_TOUCHPAD_TOGGLE),
+ LABEL(KEY_TOUCHPAD_ON),
+ LABEL(KEY_TOUCHPAD_OFF),
+ LABEL(KEY_CAMERA_ZOOMIN),
+ LABEL(KEY_CAMERA_ZOOMOUT),
+ LABEL(KEY_CAMERA_UP),
+ LABEL(KEY_CAMERA_DOWN),
+ LABEL(KEY_CAMERA_LEFT),
+ LABEL(KEY_CAMERA_RIGHT),
+ LABEL(BTN_TRIGGER_HAPPY1),
+ LABEL(BTN_TRIGGER_HAPPY2),
+ LABEL(BTN_TRIGGER_HAPPY3),
+ LABEL(BTN_TRIGGER_HAPPY4),
+ LABEL(BTN_TRIGGER_HAPPY5),
+ LABEL(BTN_TRIGGER_HAPPY6),
+ LABEL(BTN_TRIGGER_HAPPY7),
+ LABEL(BTN_TRIGGER_HAPPY8),
+ LABEL(BTN_TRIGGER_HAPPY9),
+ LABEL(BTN_TRIGGER_HAPPY10),
+ LABEL(BTN_TRIGGER_HAPPY11),
+ LABEL(BTN_TRIGGER_HAPPY12),
+ LABEL(BTN_TRIGGER_HAPPY13),
+ LABEL(BTN_TRIGGER_HAPPY14),
+ LABEL(BTN_TRIGGER_HAPPY15),
+ LABEL(BTN_TRIGGER_HAPPY16),
+ LABEL(BTN_TRIGGER_HAPPY17),
+ LABEL(BTN_TRIGGER_HAPPY18),
+ LABEL(BTN_TRIGGER_HAPPY19),
+ LABEL(BTN_TRIGGER_HAPPY20),
+ LABEL(BTN_TRIGGER_HAPPY21),
+ LABEL(BTN_TRIGGER_HAPPY22),
+ LABEL(BTN_TRIGGER_HAPPY23),
+ LABEL(BTN_TRIGGER_HAPPY24),
+ LABEL(BTN_TRIGGER_HAPPY25),
+ LABEL(BTN_TRIGGER_HAPPY26),
+ LABEL(BTN_TRIGGER_HAPPY27),
+ LABEL(BTN_TRIGGER_HAPPY28),
+ LABEL(BTN_TRIGGER_HAPPY29),
+ LABEL(BTN_TRIGGER_HAPPY30),
+ LABEL(BTN_TRIGGER_HAPPY31),
+ LABEL(BTN_TRIGGER_HAPPY32),
+ LABEL(BTN_TRIGGER_HAPPY33),
+ LABEL(BTN_TRIGGER_HAPPY34),
+ LABEL(BTN_TRIGGER_HAPPY35),
+ LABEL(BTN_TRIGGER_HAPPY36),
+ LABEL(BTN_TRIGGER_HAPPY37),
+ LABEL(BTN_TRIGGER_HAPPY38),
+ LABEL(BTN_TRIGGER_HAPPY39),
+ LABEL(BTN_TRIGGER_HAPPY40),
+ LABEL_END,
+};
+
+static struct label rel_labels[] = {
+ LABEL(REL_X),
+ LABEL(REL_Y),
+ LABEL(REL_Z),
+ LABEL(REL_RX),
+ LABEL(REL_RY),
+ LABEL(REL_RZ),
+ LABEL(REL_HWHEEL),
+ LABEL(REL_DIAL),
+ LABEL(REL_WHEEL),
+ LABEL(REL_MISC),
+ LABEL_END,
+};
+
+static struct label abs_labels[] = {
+ LABEL(ABS_X),
+ LABEL(ABS_Y),
+ LABEL(ABS_Z),
+ LABEL(ABS_RX),
+ LABEL(ABS_RY),
+ LABEL(ABS_RZ),
+ LABEL(ABS_THROTTLE),
+ LABEL(ABS_RUDDER),
+ LABEL(ABS_WHEEL),
+ LABEL(ABS_GAS),
+ LABEL(ABS_BRAKE),
+ LABEL(ABS_HAT0X),
+ LABEL(ABS_HAT0Y),
+ LABEL(ABS_HAT1X),
+ LABEL(ABS_HAT1Y),
+ LABEL(ABS_HAT2X),
+ LABEL(ABS_HAT2Y),
+ LABEL(ABS_HAT3X),
+ LABEL(ABS_HAT3Y),
+ LABEL(ABS_PRESSURE),
+ LABEL(ABS_DISTANCE),
+ LABEL(ABS_TILT_X),
+ LABEL(ABS_TILT_Y),
+ LABEL(ABS_TOOL_WIDTH),
+ LABEL(ABS_VOLUME),
+ LABEL(ABS_MISC),
+ LABEL(ABS_MT_SLOT),
+ LABEL(ABS_MT_TOUCH_MAJOR),
+ LABEL(ABS_MT_TOUCH_MINOR),
+ LABEL(ABS_MT_WIDTH_MAJOR),
+ LABEL(ABS_MT_WIDTH_MINOR),
+ LABEL(ABS_MT_ORIENTATION),
+ LABEL(ABS_MT_POSITION_X),
+ LABEL(ABS_MT_POSITION_Y),
+ LABEL(ABS_MT_TOOL_TYPE),
+ LABEL(ABS_MT_BLOB_ID),
+ LABEL(ABS_MT_TRACKING_ID),
+ LABEL(ABS_MT_PRESSURE),
+ LABEL(ABS_MT_DISTANCE),
+ LABEL_END,
+};
+
+static struct label sw_labels[] = {
+ LABEL(SW_LID),
+ LABEL(SW_TABLET_MODE),
+ LABEL(SW_HEADPHONE_INSERT),
+ LABEL(SW_RFKILL_ALL),
+ LABEL(SW_RADIO),
+ LABEL(SW_MICROPHONE_INSERT),
+ LABEL(SW_DOCK),
+ LABEL(SW_LINEOUT_INSERT),
+ LABEL(SW_JACK_PHYSICAL_INSERT),
+ LABEL(SW_VIDEOOUT_INSERT),
+ LABEL(SW_CAMERA_LENS_COVER),
+ LABEL(SW_KEYPAD_SLIDE),
+ LABEL(SW_FRONT_PROXIMITY),
+ LABEL(SW_ROTATE_LOCK),
+ LABEL_END,
+};
+
+static struct label msc_labels[] = {
+ LABEL(MSC_SERIAL),
+ LABEL(MSC_PULSELED),
+ LABEL(MSC_GESTURE),
+ LABEL(MSC_RAW),
+ LABEL(MSC_SCAN),
+ LABEL_END,
+};
+
+static struct label led_labels[] = {
+ LABEL(LED_NUML),
+ LABEL(LED_CAPSL),
+ LABEL(LED_SCROLLL),
+ LABEL(LED_COMPOSE),
+ LABEL(LED_KANA),
+ LABEL(LED_SLEEP),
+ LABEL(LED_SUSPEND),
+ LABEL(LED_MUTE),
+ LABEL(LED_MISC),
+ LABEL(LED_MAIL),
+ LABEL(LED_CHARGING),
+ LABEL_END,
+};
+
+static struct label rep_labels[] = {
+ LABEL(REP_DELAY),
+ LABEL(REP_PERIOD),
+ LABEL_END,
+};
+
+static struct label snd_labels[] = {
+ LABEL(SND_CLICK),
+ LABEL(SND_BELL),
+ LABEL(SND_TONE),
+ LABEL_END,
+};
+
+static struct label id_labels[] = {
+ LABEL(ID_BUS),
+ LABEL(ID_VENDOR),
+ LABEL(ID_PRODUCT),
+ LABEL(ID_VERSION),
+ LABEL_END,
+};
+
+static struct label bus_labels[] = {
+ LABEL(BUS_PCI),
+ LABEL(BUS_ISAPNP),
+ LABEL(BUS_USB),
+ LABEL(BUS_HIL),
+ LABEL(BUS_BLUETOOTH),
+ LABEL(BUS_VIRTUAL),
+ LABEL(BUS_ISA),
+ LABEL(BUS_I8042),
+ LABEL(BUS_XTKBD),
+ LABEL(BUS_RS232),
+ LABEL(BUS_GAMEPORT),
+ LABEL(BUS_PARPORT),
+ LABEL(BUS_AMIGA),
+ LABEL(BUS_ADB),
+ LABEL(BUS_I2C),
+ LABEL(BUS_HOST),
+ LABEL(BUS_GSC),
+ LABEL(BUS_ATARI),
+ LABEL(BUS_SPI),
+ LABEL_END,
+};
+
+static struct label mt_tool_labels[] = {
+ LABEL(MT_TOOL_FINGER),
+ LABEL(MT_TOOL_PEN),
+ LABEL(MT_TOOL_MAX),
+ LABEL_END,
+};
+
+static struct label ff_status_labels[] = {
+ LABEL(FF_STATUS_STOPPED),
+ LABEL(FF_STATUS_PLAYING),
+ LABEL(FF_STATUS_MAX),
+ LABEL_END,
+};
+
+static struct label ff_labels[] = {
+ LABEL(FF_RUMBLE),
+ LABEL(FF_PERIODIC),
+ LABEL(FF_CONSTANT),
+ LABEL(FF_SPRING),
+ LABEL(FF_FRICTION),
+ LABEL(FF_DAMPER),
+ LABEL(FF_INERTIA),
+ LABEL(FF_RAMP),
+ LABEL(FF_SQUARE),
+ LABEL(FF_TRIANGLE),
+ LABEL(FF_SINE),
+ LABEL(FF_SAW_UP),
+ LABEL(FF_SAW_DOWN),
+ LABEL(FF_CUSTOM),
+ LABEL(FF_GAIN),
+ LABEL(FF_AUTOCENTER),
+ LABEL_END,
+};
+
+static struct label key_value_labels[] = {
+ { "UP", 0 },
+ { "DOWN", 1 },
+ { "REPEAT", 2 },
+ LABEL_END,
+};
diff --git a/toolbox/lsof.c b/toolbox/lsof.c
index c55384b..4e2f77a 100644
--- a/toolbox/lsof.c
+++ b/toolbox/lsof.c
@@ -37,11 +37,16 @@
#include <stdlib.h>
#include <unistd.h>
+#include <pwd.h>
+#include <sys/stat.h>
+
#define BUF_MAX 1024
-#define CMD_DISPLAY_MAX 10
+#define CMD_DISPLAY_MAX (9 + 1)
+#define USER_DISPLAY_MAX (10 + 1)
struct pid_info_t {
pid_t pid;
+ char user[USER_DISPLAY_MAX];
char cmdline[CMD_DISPLAY_MAX];
@@ -82,7 +87,8 @@
if (!strcmp(link_dest, "/"))
goto out;
- printf("%-9s %5d %10s %4s %9s %18s %9s %10s %s\n", info->cmdline, info->pid, "???", type,
+ printf("%-9s %5d %10s %4s %9s %18s %9s %10s %s\n",
+ info->cmdline, info->pid, info->user, type,
"???", "???", "???", "???", link_dest);
out:
@@ -113,7 +119,8 @@
if (inode == 0 || !strcmp(device, "00:00"))
continue;
- printf("%-9s %5d %10s %4s %9s %18s %9zd %10ld %s\n", info->cmdline, info->pid, "???", "mem",
+ printf("%-9s %5d %10s %4s %9s %18s %9zd %10ld %s\n",
+ info->cmdline, info->pid, info->user, "mem",
"???", device, offset, inode, file);
}
@@ -136,7 +143,8 @@
if (dir == NULL) {
char msg[BUF_MAX];
snprintf(msg, sizeof(msg), "%s (opendir: %s)", info->path, strerror(errno));
- printf("%-9s %5d %10s %4s %9s %18s %9s %10s %s\n", info->cmdline, info->pid, "???", "FDS",
+ printf("%-9s %5d %10s %4s %9s %18s %9s %10s %s\n",
+ info->cmdline, info->pid, info->user, "FDS",
"", "", "", "", msg);
goto out;
}
@@ -159,12 +167,26 @@
{
int fd;
struct pid_info_t info;
+ struct stat pidstat;
+ struct passwd *pw;
+
info.pid = pid;
-
snprintf(info.path, sizeof(info.path), "/proc/%d/", pid);
-
info.parent_length = strlen(info.path);
+ // Get the UID by calling stat on the proc/pid directory.
+ if (!stat(info.path, &pidstat)) {
+ pw = getpwuid(pidstat.st_uid);
+ if (pw) {
+ strncpy(info.user, pw->pw_name, USER_DISPLAY_MAX - 1);
+ info.user[USER_DISPLAY_MAX - 1] = '\0';
+ } else {
+ snprintf(info.user, USER_DISPLAY_MAX, "%d", (int)pidstat.st_uid);
+ }
+ } else {
+ strcpy(info.user, "???");
+ }
+
// Read the command line information; each argument is terminated with NULL.
strncat(info.path, "cmdline", sizeof(info.path));
fd = open(info.path, O_RDONLY);
@@ -219,7 +241,7 @@
continue;
// Only inspect directories that are PID numbers
- pid = strtol(de->d_name, &endptr, 10);
+ pid = strtol(de->d_name, &endptr, 10);
if (*endptr != '\0')
continue;
diff --git a/toolbox/mount.c b/toolbox/mount.c
index 82ecc56..27cf3c9 100644
--- a/toolbox/mount.c
+++ b/toolbox/mount.c
@@ -15,8 +15,8 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
-// FIXME - only one loop mount is supported at a time
-#define LOOP_DEVICE "/dev/block/loop0"
+#define DEFAULT_LOOP_DEVICE "/dev/block/loop0"
+#define LOOPDEV_MAXLEN 64
struct mount_opts {
const char str[8];
@@ -87,7 +87,7 @@
}
static unsigned long
-parse_mount_options(char *arg, unsigned long rwflag, struct extra_opts *extra, int* loop)
+parse_mount_options(char *arg, unsigned long rwflag, struct extra_opts *extra, int* loop, char *loopdev)
{
char *s;
@@ -100,8 +100,15 @@
if (no)
s += 2;
+ if (strncmp(s, "loop=", 5) == 0) {
+ *loop = 1;
+ strlcpy(loopdev, s + 5, LOOPDEV_MAXLEN);
+ continue;
+ }
+
if (strcmp(s, "loop") == 0) {
*loop = 1;
+ strlcpy(loopdev, DEFAULT_LOOP_DEVICE, LOOPDEV_MAXLEN);
continue;
}
for (i = 0, res = 1; i < ARRAY_SIZE(options); i++) {
@@ -131,7 +138,8 @@
static unsigned long rwflag;
static int
-do_mount(char *dev, char *dir, char *type, unsigned long rwflag, void *data, int loop)
+do_mount(char *dev, char *dir, char *type, unsigned long rwflag, void *data, int loop,
+ char *loopdev)
{
char *s;
int error = 0;
@@ -142,14 +150,13 @@
flags = (rwflag & MS_RDONLY) ? O_RDONLY : O_RDWR;
- // FIXME - only one loop mount supported at a time
file_fd = open(dev, flags);
- if (file_fd < -1) {
+ if (file_fd < 0) {
perror("open backing file failed");
return 1;
}
- device_fd = open(LOOP_DEVICE, flags);
- if (device_fd < -1) {
+ device_fd = open(loopdev, flags);
+ if (device_fd < 0) {
perror("open loop device failed");
close(file_fd);
return 1;
@@ -163,7 +170,7 @@
close(file_fd);
close(device_fd);
- dev = LOOP_DEVICE;
+ dev = loopdev;
}
while ((s = strsep(&type, ",")) != NULL) {
@@ -268,6 +275,7 @@
char *dir = NULL;
int c;
int loop = 0;
+ char loopdev[LOOPDEV_MAXLEN];
progname = argv[0];
rwflag = MS_VERBOSE;
@@ -281,7 +289,7 @@
break;
switch (c) {
case 'o':
- rwflag = parse_mount_options(optarg, rwflag, &extra, &loop);
+ rwflag = parse_mount_options(optarg, rwflag, &extra, &loop, loopdev);
break;
case 'r':
rwflag |= MS_RDONLY;
@@ -319,6 +327,6 @@
exit(1);
}
- return do_mount(dev, dir, type, rwflag, extra.str, loop);
+ return do_mount(dev, dir, type, rwflag, extra.str, loop, loopdev);
/* We leak dev and dir in some cases, but we're about to exit */
}
diff --git a/toolbox/start.c b/toolbox/start.c
index 3bd9fbb..665a941 100644
--- a/toolbox/start.c
+++ b/toolbox/start.c
@@ -8,13 +8,14 @@
int start_main(int argc, char *argv[])
{
char buf[1024];
+
if(argc > 1) {
property_set("ctl.start", argv[1]);
} else {
- /* default to "start zygote" "start runtime" */
+ /* defaults to starting the common services stopped by stop.c */
+ property_set("ctl.start", "surfaceflinger");
property_set("ctl.start", "zygote");
- property_set("ctl.start", "runtime");
}
-
+
return 0;
}
diff --git a/toolbox/stop.c b/toolbox/stop.c
index 05baffd..460f377 100644
--- a/toolbox/stop.c
+++ b/toolbox/stop.c
@@ -10,11 +10,10 @@
if(argc > 1) {
property_set("ctl.stop", argv[1]);
} else{
- /* default to "stop runtime" "stop zygote" */
- property_set("ctl.stop", "runtime");
+ /* defaults to stopping the common services */
property_set("ctl.stop", "zygote");
+ property_set("ctl.stop", "surfaceflinger");
}
return 0;
}
-
diff --git a/toolbox/touch.c b/toolbox/touch.c
new file mode 100644
index 0000000..b8ab310
--- /dev/null
+++ b/toolbox/touch.c
@@ -0,0 +1,87 @@
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+static void usage(void)
+{
+ fprintf(stderr, "touch: usage: touch [-alm] [-t time_t] <file>\n");
+ exit(1);
+}
+
+int touch_main(int argc, char *argv[])
+{
+ int i, fd, aflag = 0, mflag = 0, debug = 0, flags = 0;
+ struct timespec specified_time, times[2];
+ char *file = 0;
+
+ specified_time.tv_nsec = UTIME_NOW;
+
+ for (i = 1; i < argc; i++) {
+ if (argv[i][0] == '-') {
+ /* an option */
+ const char *arg = argv[i]+1;
+ while (arg[0]) {
+ switch (arg[0]) {
+ case 'a': aflag = 1; break;
+ case 'm': mflag = 1; break;
+ case 't':
+ if ((i+1) >= argc)
+ usage();
+ specified_time.tv_sec = atol(argv[++i]);
+ if (specified_time.tv_sec == 0) {
+ fprintf(stderr, "touch: invalid time_t\n");
+ exit(1);
+ }
+ specified_time.tv_nsec = 0;
+ break;
+ case 'l': flags |= AT_SYMLINK_NOFOLLOW; break;
+ case 'd': debug = 1; break;
+ default:
+ usage();
+ }
+ arg++;
+ }
+ } else {
+ /* not an option, and only accept one filename */
+ if (i+1 != argc)
+ usage();
+ file = argv[i];
+ }
+ }
+
+ if (! file) {
+ fprintf(stderr, "touch: no file specified\n");
+ exit(1);
+ }
+
+ if (access(file, F_OK))
+ if ((fd=creat(file, 0666)) != -1)
+ close(fd);
+
+ if ((mflag == 0) && (aflag == 0))
+ aflag = mflag = 1;
+
+ if (aflag)
+ times[0] = specified_time;
+ else
+ times[0].tv_nsec = UTIME_OMIT;
+
+ if (mflag)
+ times[1] = specified_time;
+ else
+ times[1].tv_nsec = UTIME_OMIT;
+
+ if (debug) {
+ fprintf(stderr, "file = %s\n", file);
+ fprintf(stderr, "times[0].tv_sec = %ld, times[0].tv_nsec = %ld\n", times[0].tv_sec, times[0].tv_nsec);
+ fprintf(stderr, "times[1].tv_sec = %ld, times[1].tv_nsec = %ld\n", times[1].tv_sec, times[1].tv_nsec);
+ fprintf(stderr, "flags = 0x%8.8x\n", flags);
+ }
+
+ return utimensat(AT_FDCWD, file, times, flags);
+}
+
diff --git a/toolbox/umount.c b/toolbox/umount.c
index 92c6076..890e870 100644
--- a/toolbox/umount.c
+++ b/toolbox/umount.c
@@ -6,11 +6,26 @@
#include <string.h>
#include <unistd.h>
#include <linux/loop.h>
+#include <errno.h>
-// FIXME - only one loop mount is supported at a time
-#define LOOP_DEVICE "/dev/block/loop0"
+#define LOOPDEV_MAXLEN 64
+#define LOOP_MAJOR 7
-static int is_loop_mount(const char* path)
+static int is_loop(char *dev)
+{
+ struct stat st;
+ int ret = 0;
+
+ if (stat(dev, &st) == 0) {
+ if (S_ISBLK(st.st_mode) && (major(st.st_rdev) == LOOP_MAJOR)) {
+ ret = 1;
+ }
+ }
+
+ return ret;
+}
+
+static int is_loop_mount(const char* path, char *loopdev)
{
FILE* f;
int count;
@@ -22,14 +37,15 @@
f = fopen("/proc/mounts", "r");
if (!f) {
- fprintf(stdout, "could not open /proc/mounts\n");
+ fprintf(stdout, "could not open /proc/mounts: %s\n", strerror(errno));
return -1;
}
do {
count = fscanf(f, "%255s %255s %255s\n", device, mount_path, rest);
if (count == 3) {
- if (strcmp(LOOP_DEVICE, device) == 0 && strcmp(path, mount_path) == 0) {
+ if (is_loop(device) && strcmp(path, mount_path) == 0) {
+ strlcpy(loopdev, device, LOOPDEV_MAXLEN);
result = 1;
break;
}
@@ -43,27 +59,28 @@
int umount_main(int argc, char *argv[])
{
int loop, loop_fd;
-
+ char loopdev[LOOPDEV_MAXLEN];
+
if(argc != 2) {
fprintf(stderr,"umount <path>\n");
return 1;
}
- loop = is_loop_mount(argv[1]);
- if(umount(argv[1])){
- fprintf(stderr,"failed.\n");
+ loop = is_loop_mount(argv[1], loopdev);
+ if (umount(argv[1])) {
+ fprintf(stderr, "failed: %s\n", strerror(errno));
return 1;
}
if (loop) {
// free the loop device
- loop_fd = open(LOOP_DEVICE, O_RDONLY);
- if (loop_fd < -1) {
- perror("open loop device failed");
+ loop_fd = open(loopdev, O_RDONLY);
+ if (loop_fd < 0) {
+ fprintf(stderr, "open loop device failed: %s\n", strerror(errno));
return 1;
}
if (ioctl(loop_fd, LOOP_CLR_FD, 0) < 0) {
- perror("ioctl LOOP_CLR_FD failed");
+ fprintf(stderr, "ioctl LOOP_CLR_FD failed: %s\n", strerror(errno));
return 1;
}