Browse Source

Merge pull request #290 from emanuele-f/protect_cleanup

Move android code to hin2n
pull/296/head
Luca Deri 4 years ago
committed by GitHub
parent
commit
edc48acb83
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      include/n2n.h
  2. 12
      src/edge_utils.c
  3. 50
      src/n2n.c

3
include/n2n.h

@ -240,6 +240,7 @@ typedef struct n2n_edge_callbacks {
* returned to drop the packet. The packet payload can be modified. */
n2n_verdict (*packet_from_tap)(n2n_edge_t *eee, uint8_t *payload, uint16_t payload_size);
/* Called whenever the IP address of the TAP interface changes. */
void (*ip_address_changed)(n2n_edge_t *eee, uint32_t old_ip, uint32_t new_ip);
} n2n_edge_callbacks_t;
@ -386,6 +387,8 @@ void edge_set_userdata(n2n_edge_t *eee, void *user_data);
void* edge_get_userdata(n2n_edge_t *eee);
void edge_send_packet2net(n2n_edge_t *eee, uint8_t *tap_pkt, size_t len);
void edge_read_from_tap(n2n_edge_t *eee);
int edge_get_n2n_socket(n2n_edge_t *eee);
int edge_get_management_socket(n2n_edge_t *eee);
int run_edge_loop(n2n_edge_t *eee, int *keep_running);
int quick_edge_init(char *device_name, char *community_name,
char *encrypt_key, char *device_mac,

12
src/edge_utils.c

@ -132,6 +132,18 @@ void* edge_get_userdata(n2n_edge_t *eee) {
/* ************************************** */
int edge_get_n2n_socket(n2n_edge_t *eee) {
return(eee->udp_sock);
}
/* ************************************** */
int edge_get_management_socket(n2n_edge_t *eee) {
return(eee->udp_mgmt_sock);
}
/* ************************************** */
const char* transop_str(enum n2n_transform tr) {
switch(tr) {
case N2N_TRANSFORM_ID_NULL: return("null");

50
src/n2n.c

@ -22,10 +22,6 @@
#include <assert.h>
#ifdef __ANDROID_NDK__
#include <edge_jni/edge_jni.h>
#endif
#define PURGE_REGISTRATION_FREQUENCY 30
#define REGISTRATION_TIMEOUT 60
@ -35,47 +31,6 @@ static const uint8_t ipv6_multicast_addr[6] = { 0x33, 0x33, 0x00, 0x00, 0x00, 0x
/* ************************************** */
#ifdef __ANDROID_NDK__
static int protect_socket(int sock) {
JNIEnv *env = NULL;
if(!g_status)
return(-1);
if ((*g_status->jvm)->GetEnv(g_status->jvm, &env, JNI_VERSION_1_1) != JNI_OK || !env) {
traceEvent(TRACE_ERROR, "GetEnv failed");
return(-1);
}
jclass vpn_service_cls = (*env)->GetObjectClass(env, g_status->jobj_service);
if(!vpn_service_cls) {
traceEvent(TRACE_ERROR, "GetObjectClass(VpnService) failed");
return(-1);
}
/* Call VpnService protect */
jmethodID midProtect = (*env)->GetMethodID(env, vpn_service_cls, "protect", "(I)Z");
if(!midProtect) {
traceEvent(TRACE_ERROR, "Could not resolve VpnService::protect");
return(-1);
}
jboolean isProtected = (*env)->CallBooleanMethod(env, g_status->jobj_service, midProtect, sock);
if(!isProtected) {
traceEvent(TRACE_ERROR, "VpnService::protect failed");
return(-1);
}
return(0);
}
#endif
/* ************************************** */
SOCKET open_socket(int local_port, int bind_any) {
SOCKET sock_fd;
struct sockaddr_in local_address;
@ -104,11 +59,6 @@ SOCKET open_socket(int local_port, int bind_any) {
return(-1);
}
#ifdef __ANDROID_NDK__
/* Protect the socket so that the supernode traffic won't go inside the n2n VPN */
protect_socket(sock_fd);
#endif
return(sock_fd);
}

Loading…
Cancel
Save