diff options
-rw-r--r-- | Android.mk | 67 | ||||
-rw-r--r-- | main.c | 93 | ||||
-rw-r--r-- | src/racoon/crypto_openssl.c | 5 | ||||
-rw-r--r-- | src/racoon/isakmp.c | 3 | ||||
-rw-r--r-- | src/racoon/pfkey.c | 2 |
5 files changed, 164 insertions, 6 deletions
diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000..f3b0630 --- /dev/null +++ b/Android.mk @@ -0,0 +1,67 @@ +# +# Copyright (C) 2009 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. +# + +ifneq ($(TARGET_SIMULATOR),true) + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + src/libipsec/pfkey.c \ + src/libipsec/ipsec_strerror.c \ + src/racoon/isakmp.c \ + src/racoon/isakmp_agg.c \ + src/racoon/isakmp_base.c \ + src/racoon/isakmp_frag.c \ + src/racoon/isakmp_ident.c \ + src/racoon/isakmp_inf.c \ + src/racoon/isakmp_newg.c \ + src/racoon/isakmp_quick.c \ + src/racoon/handler.c \ + src/racoon/pfkey.c \ + src/racoon/ipsec_doi.c \ + src/racoon/oakley.c \ + src/racoon/vendorid.c \ + src/racoon/policy.c \ + src/racoon/crypto_openssl.c \ + src/racoon/algorithm.c \ + src/racoon/proposal.c \ + src/racoon/strnames.c \ + src/racoon/schedule.c \ + src/racoon/str2val.c \ + src/racoon/genlist.c \ + src/racoon/vmbuf.c \ + src/racoon/sockmisc.c \ + src/racoon/nattraversal.c \ + main.c \ + setup.c + +LOCAL_C_INCLUDES += \ + $(LOCAL_PATH) \ + $(LOCAL_PATH)/src/include-glibc \ + $(LOCAL_PATH)/src/libipsec \ + $(LOCAL_PATH)/src/racoon \ + $(LOCAL_PATH)/src/racoon/missing + +LOCAL_SHARED_LIBRARIES := libcutils libcrypto + +LOCAL_CFLAGS := -DANDROID_CHANGES -DHAVE_CONFIG_H -Iexternal/openssl/include + +LOCAL_MODULE := racoon + +include $(BUILD_EXECUTABLE) + +endif @@ -24,6 +24,12 @@ #include <sys/socket.h> #include <sys/select.h> +#ifdef ANDROID_CHANGES +#include <fcntl.h> +#include <android/log.h> +#include <cutils/sockets.h> +#endif + #include "config.h" #include "libpfkey.h" #include "ipsec_strerror.h" @@ -52,11 +58,68 @@ static void interrupt(int signal) exit(1); } +#ifdef ANDROID_CHANGES + +static int get_control_and_arguments(int *argc, char ***argv) +{ + static char *args[256]; + int control; + int i; + + if ((i = android_get_control_socket("racoon")) == -1) { + return -1; + } + do_plog(LLV_DEBUG, "Waiting for control socket"); + if (listen(i, 1) == -1 || (control = accept(i, NULL, 0)) == -1) { + do_plog(LLV_ERROR, "Cannot get control socket"); + exit(-1); + } + close(i); + fcntl(control, F_SETFD, FD_CLOEXEC); + + args[0] = (*argv)[0]; + for (i = 1; i < 256; ++i) { + unsigned char length; + if (recv(control, &length, 1, 0) != 1) { + do_plog(LLV_ERROR, "Cannot get argument length"); + exit(-1); + } + if (length == 0xFF) { + break; + } else { + int offset = 0; + args[i] = malloc(length + 1); + while (offset < length) { + int n = recv(control, &args[i][offset], length - offset, 0); + if (n > 0) { + offset += n; + } else { + do_plog(LLV_ERROR, "Cannot get argument value"); + exit(-1); + } + } + args[i][length] = 0; + } + } + do_plog(LLV_DEBUG, "Received %d arguments", i - 1); + + *argc = i; + *argv = args; + return control; +} + +#endif + + int main(int argc, char **argv) { fd_set fdset; int fdset_size; struct myaddrs *p; +#ifdef ANDROID_CHANGES + unsigned char code; + int control = get_control_and_arguments(&argc, &argv); +#endif do_plog(LLV_INFO, "ipsec-tools 0.7.2 (http://ipsec-tools.sf.net)\n"); @@ -75,6 +138,11 @@ int main(int argc, char **argv) exit(1); } +#ifdef ANDROID_CHANGES + code = argc - 1; + send(control, &code, 1, 0); +#endif + #ifdef ENABLE_NATT natt_keepalive_init(); #endif @@ -112,12 +180,25 @@ int main(int argc, char **argv) void do_plog(int level, char *format, ...) { - static char *levels = "EWNIDD"; - fprintf(stderr, "%c: ", levels[level]); - va_list ap; - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); + if (level >= 0 && level <= 5) { +#ifdef ANDROID_CHANGES + static int levels[6] = { + ANDROID_LOG_ERROR, ANDROID_LOG_WARN, ANDROID_LOG_INFO, + ANDROID_LOG_INFO, ANDROID_LOG_DEBUG, ANDROID_LOG_VERBOSE + }; + va_list ap; + va_start(ap, format); + __android_log_vprint(levels[level], "racoon", format, ap); + va_end(ap); +#else + static char *levels = "EWNIDV"; + fprintf(stderr, "%c: ", levels[level]); + va_list ap; + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); +#endif + } } char *binsanitize(char *data, size_t length) diff --git a/src/racoon/crypto_openssl.c b/src/racoon/crypto_openssl.c index 41c4931..f281c29 100644 --- a/src/racoon/crypto_openssl.c +++ b/src/racoon/crypto_openssl.c @@ -63,8 +63,13 @@ #ifdef HAVE_OPENSSL_ENGINE_H #include <openssl/engine.h> #endif +#ifndef ANDROID_CHANGES #include <openssl/blowfish.h> #include <openssl/cast.h> +#else +#define EVP_bf_cbc() NULL +#define EVP_cast5_cbc() NULL +#endif #include <openssl/err.h> #ifdef HAVE_OPENSSL_RC5_H #include <openssl/rc5.h> diff --git a/src/racoon/isakmp.c b/src/racoon/isakmp.c index 83741fc..12eb5a0 100644 --- a/src/racoon/isakmp.c +++ b/src/racoon/isakmp.c @@ -116,6 +116,9 @@ # ifndef SOL_UDP # define SOL_UDP 17 # endif +#ifdef ANDROID_CHANGES +#define __linux +#endif # endif /* __linux__ */ # if defined(__NetBSD__) || defined(__FreeBSD__) || \ (defined(__APPLE__) && defined(__MACH__)) diff --git a/src/racoon/pfkey.c b/src/racoon/pfkey.c index cefd161..cbbf042 100644 --- a/src/racoon/pfkey.c +++ b/src/racoon/pfkey.c @@ -59,7 +59,9 @@ #include <sys/param.h> #include <sys/socket.h> #include <sys/queue.h> +#ifndef ANDROID_CHANGES #include <sys/sysctl.h> +#endif #include <net/route.h> #include <net/pfkeyv2.h> |