2016-01-18 11:19:40 +00:00
|
|
|
#include <jni.h>
|
2016-02-09 12:39:49 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2016-02-09 15:31:56 +00:00
|
|
|
#include <sys/types.h>
|
2016-02-09 12:39:49 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <dlfcn.h>
|
2016-02-13 12:41:38 +00:00
|
|
|
#include <sys/stat.h>
|
2016-02-11 07:48:14 +00:00
|
|
|
#include <sys/resource.h>
|
2016-02-09 12:39:49 +00:00
|
|
|
|
2016-02-09 15:31:56 +00:00
|
|
|
#include <netdb.h>
|
2016-02-09 12:39:49 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip6.h>
|
|
|
|
#include <netinet/udp.h>
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/ip_icmp.h>
|
|
|
|
#include <netinet/icmp6.h>
|
|
|
|
|
|
|
|
#include <android/log.h>
|
2016-01-18 11:19:40 +00:00
|
|
|
|
2016-01-17 16:41:54 +00:00
|
|
|
#define TAG "NetGuard.JNI"
|
2016-01-21 12:46:57 +00:00
|
|
|
|
2016-02-09 12:39:49 +00:00
|
|
|
// #define PROFILE_EVENTS 5
|
|
|
|
// #define PROFILE_UID 5
|
|
|
|
// #define PROFILE_JNI 5
|
|
|
|
|
2016-02-11 13:46:43 +00:00
|
|
|
#define SELECT_TIMEOUT 3600 // seconds
|
2016-01-21 12:46:57 +00:00
|
|
|
|
2016-01-22 18:03:32 +00:00
|
|
|
#define TUN_MAXMSG 32768 // bytes (device)
|
2016-02-03 06:58:25 +00:00
|
|
|
#define ICMP4_MAXMSG (IP_MAXPACKET - 20 - 8) // bytes (socket)
|
|
|
|
#define ICMP6_MAXMSG (IPV6_MAXPACKET - 40 - 8) // bytes (socket)
|
|
|
|
#define UDP4_MAXMSG (IP_MAXPACKET - 20 - 8) // bytes (socket)
|
|
|
|
#define UDP6_MAXMSG (IPV6_MAXPACKET - 40 - 8) // bytes (socket)
|
2016-01-22 18:03:32 +00:00
|
|
|
|
2016-02-03 06:42:06 +00:00
|
|
|
#define ICMP_TIMEOUT 15 // seconds
|
2016-02-02 13:31:44 +00:00
|
|
|
|
2016-01-24 12:39:04 +00:00
|
|
|
#define UDP_TIMEOUT_53 15 // seconds
|
2016-02-08 18:26:28 +00:00
|
|
|
#define UDP_TIMEOUT_ANY 300 // seconds
|
|
|
|
#define UDP_KEEP_TIMEOUT 60 // seconds
|
2016-01-21 12:46:57 +00:00
|
|
|
|
2016-02-08 20:59:24 +00:00
|
|
|
#define TCP_RECV_WINDOW 16384 // bytes (maximum)
|
2016-02-05 13:52:52 +00:00
|
|
|
#define TCP_SEND_WINDOW 16384 // bytes (maximum)
|
2016-01-18 19:57:49 +00:00
|
|
|
#define TCP_INIT_TIMEOUT 30 // seconds ~net.inet.tcp.keepinit
|
2016-02-08 18:26:28 +00:00
|
|
|
#define TCP_IDLE_TIMEOUT 300 // seconds ~net.inet.tcp.keepidle
|
2016-02-09 18:55:28 +00:00
|
|
|
#define TCP_CLOSE_TIMEOUT 30 // seconds
|
2016-02-08 18:26:28 +00:00
|
|
|
#define TCP_KEEP_TIMEOUT 300 // seconds
|
2016-02-06 07:03:34 +00:00
|
|
|
// https://en.wikipedia.org/wiki/Maximum_segment_lifetime
|
2016-01-21 12:46:57 +00:00
|
|
|
|
2016-01-20 09:27:18 +00:00
|
|
|
#define UID_DELAY 1 // milliseconds
|
|
|
|
#define UID_DELAYTRY 10 // milliseconds
|
2016-01-18 19:57:49 +00:00
|
|
|
#define UID_MAXTRY 3
|
2016-01-21 12:46:57 +00:00
|
|
|
|
2016-02-02 14:11:09 +00:00
|
|
|
#define RTLD_NOLOAD 4
|
|
|
|
|
2016-01-17 16:41:54 +00:00
|
|
|
struct arguments {
|
2016-01-18 11:19:40 +00:00
|
|
|
JNIEnv *env;
|
2016-01-17 16:41:54 +00:00
|
|
|
jobject instance;
|
|
|
|
int tun;
|
2016-02-08 13:33:33 +00:00
|
|
|
jboolean fwd53;
|
2016-01-17 16:41:54 +00:00
|
|
|
};
|
|
|
|
|
2016-02-07 16:44:23 +00:00
|
|
|
struct allowed {
|
2016-02-08 15:34:54 +00:00
|
|
|
char raddr[INET6_ADDRSTRLEN + 1];
|
|
|
|
uint16_t rport; // host notation
|
2016-02-06 11:25:20 +00:00
|
|
|
};
|
|
|
|
|
2016-02-05 09:43:28 +00:00
|
|
|
struct segment {
|
|
|
|
uint32_t seq;
|
|
|
|
uint16_t len;
|
|
|
|
int psh;
|
|
|
|
uint8_t *data;
|
|
|
|
struct segment *next;
|
|
|
|
};
|
|
|
|
|
2016-02-02 13:31:44 +00:00
|
|
|
struct icmp_session {
|
|
|
|
time_t time;
|
|
|
|
jint uid;
|
|
|
|
int version;
|
|
|
|
|
|
|
|
union {
|
|
|
|
__be32 ip4; // network notation
|
|
|
|
struct in6_addr ip6;
|
|
|
|
} saddr;
|
|
|
|
|
|
|
|
union {
|
|
|
|
__be32 ip4; // network notation
|
|
|
|
struct in6_addr ip6;
|
|
|
|
} daddr;
|
|
|
|
|
|
|
|
uint16_t id;
|
|
|
|
|
|
|
|
uint8_t stop;
|
|
|
|
jint socket;
|
|
|
|
|
|
|
|
struct icmp_session *next;
|
|
|
|
};
|
|
|
|
|
2016-02-04 09:09:31 +00:00
|
|
|
#define UDP_ACTIVE 0
|
|
|
|
#define UDP_FINISHING 1
|
|
|
|
#define UDP_CLOSED 2
|
|
|
|
#define UDP_BLOCKED 3
|
|
|
|
|
2016-01-20 13:11:04 +00:00
|
|
|
struct udp_session {
|
|
|
|
time_t time;
|
|
|
|
jint uid;
|
2016-01-20 15:52:38 +00:00
|
|
|
int version;
|
2016-01-24 14:39:56 +00:00
|
|
|
|
2016-02-15 16:48:53 +00:00
|
|
|
uint64_t sent;
|
|
|
|
uint64_t received;
|
|
|
|
|
2016-01-24 14:39:56 +00:00
|
|
|
union {
|
2016-01-24 21:46:25 +00:00
|
|
|
__be32 ip4; // network notation
|
|
|
|
struct in6_addr ip6;
|
|
|
|
} saddr;
|
2016-01-20 13:11:04 +00:00
|
|
|
__be16 source; // network notation
|
2016-01-24 14:39:56 +00:00
|
|
|
|
|
|
|
union {
|
2016-01-24 21:46:25 +00:00
|
|
|
__be32 ip4; // network notation
|
|
|
|
struct in6_addr ip6;
|
|
|
|
} daddr;
|
2016-01-20 13:11:04 +00:00
|
|
|
__be16 dest; // network notation
|
2016-01-26 10:41:03 +00:00
|
|
|
|
2016-02-04 09:09:31 +00:00
|
|
|
uint8_t state;
|
2016-01-20 13:11:04 +00:00
|
|
|
jint socket;
|
2016-01-26 10:41:03 +00:00
|
|
|
|
2016-01-20 13:11:04 +00:00
|
|
|
struct udp_session *next;
|
|
|
|
};
|
|
|
|
|
2016-01-20 11:35:51 +00:00
|
|
|
struct tcp_session {
|
2016-01-19 19:58:51 +00:00
|
|
|
jint uid;
|
2016-01-22 18:03:32 +00:00
|
|
|
time_t time;
|
2016-02-11 16:16:02 +00:00
|
|
|
time_t keep_alive;
|
2016-01-20 15:52:38 +00:00
|
|
|
int version;
|
2016-02-09 06:58:34 +00:00
|
|
|
uint16_t recv_window; // host notation
|
2016-01-22 18:03:32 +00:00
|
|
|
uint16_t send_window; // host notation
|
2016-01-24 14:39:56 +00:00
|
|
|
|
2016-01-17 16:41:54 +00:00
|
|
|
uint32_t remote_seq; // confirmed bytes received, host notation
|
|
|
|
uint32_t local_seq; // confirmed bytes sent, host notation
|
|
|
|
uint32_t remote_start;
|
|
|
|
uint32_t local_start;
|
2016-01-24 14:39:56 +00:00
|
|
|
|
2016-02-13 13:46:03 +00:00
|
|
|
uint32_t acked; // host notation
|
|
|
|
|
2016-02-15 16:48:53 +00:00
|
|
|
uint64_t sent;
|
|
|
|
uint64_t received;
|
|
|
|
|
2016-01-24 14:39:56 +00:00
|
|
|
union {
|
2016-01-24 21:46:25 +00:00
|
|
|
__be32 ip4; // network notation
|
|
|
|
struct in6_addr ip6;
|
2016-01-24 14:39:56 +00:00
|
|
|
} saddr;
|
2016-01-17 16:41:54 +00:00
|
|
|
__be16 source; // network notation
|
2016-01-24 14:39:56 +00:00
|
|
|
|
|
|
|
union {
|
2016-01-24 21:46:25 +00:00
|
|
|
__be32 ip4; // network notation
|
|
|
|
struct in6_addr ip6;
|
2016-01-24 14:39:56 +00:00
|
|
|
} daddr;
|
2016-01-17 16:41:54 +00:00
|
|
|
__be16 dest; // network notation
|
2016-01-24 14:39:56 +00:00
|
|
|
|
2016-01-17 16:41:54 +00:00
|
|
|
uint8_t state;
|
|
|
|
jint socket;
|
2016-02-06 07:04:15 +00:00
|
|
|
struct segment *forward;
|
2016-02-05 09:43:28 +00:00
|
|
|
|
2016-01-20 11:35:51 +00:00
|
|
|
struct tcp_session *next;
|
2016-01-17 16:41:54 +00:00
|
|
|
};
|
|
|
|
|
2016-01-26 15:54:17 +00:00
|
|
|
// IPv6
|
|
|
|
|
|
|
|
struct ip6_hdr_pseudo {
|
|
|
|
struct in6_addr ip6ph_src;
|
|
|
|
struct in6_addr ip6ph_dst;
|
|
|
|
u_int32_t ip6ph_len;
|
|
|
|
u_int8_t ip6ph_zero[3];
|
|
|
|
u_int8_t ip6ph_nxt;
|
|
|
|
} __packed;
|
|
|
|
|
2016-01-26 10:41:03 +00:00
|
|
|
// PCAP
|
2016-01-17 16:41:54 +00:00
|
|
|
// https://wiki.wireshark.org/Development/LibpcapFileFormat
|
|
|
|
|
2016-01-23 14:50:18 +00:00
|
|
|
typedef uint16_t guint16_t;
|
|
|
|
typedef uint32_t guint32_t;
|
|
|
|
typedef int32_t gint32_t;
|
2016-01-17 16:41:54 +00:00
|
|
|
|
2016-01-24 14:39:56 +00:00
|
|
|
typedef struct pcap_hdr_s {
|
2016-01-17 16:41:54 +00:00
|
|
|
guint32_t magic_number;
|
|
|
|
guint16_t version_major;
|
|
|
|
guint16_t version_minor;
|
|
|
|
gint32_t thiszone;
|
|
|
|
guint32_t sigfigs;
|
|
|
|
guint32_t snaplen;
|
|
|
|
guint32_t network;
|
2016-01-24 14:39:56 +00:00
|
|
|
} __packed;
|
2016-01-17 16:41:54 +00:00
|
|
|
|
2016-01-24 14:39:56 +00:00
|
|
|
typedef struct pcaprec_hdr_s {
|
2016-01-17 16:41:54 +00:00
|
|
|
guint32_t ts_sec;
|
|
|
|
guint32_t ts_usec;
|
|
|
|
guint32_t incl_len;
|
|
|
|
guint32_t orig_len;
|
2016-01-24 14:39:56 +00:00
|
|
|
} __packed;
|
2016-01-17 16:41:54 +00:00
|
|
|
|
|
|
|
#define LINKTYPE_RAW 101
|
|
|
|
|
2016-01-26 10:41:03 +00:00
|
|
|
// DNS
|
|
|
|
|
2016-01-29 18:10:23 +00:00
|
|
|
#define DNS_QCLASS_IN 1
|
2016-01-26 10:41:03 +00:00
|
|
|
#define DNS_QTYPE_A 1 // IPv4
|
|
|
|
#define DNS_QTYPE_AAAA 28 // IPv6
|
|
|
|
|
2016-02-14 10:54:06 +00:00
|
|
|
#define DNS_QNAME_MAX 255
|
2016-01-26 10:41:03 +00:00
|
|
|
#define DNS_TTL (10 * 60) // seconds
|
|
|
|
|
2016-01-24 22:33:47 +00:00
|
|
|
struct dns_header {
|
|
|
|
uint16_t id; // identification number
|
|
|
|
# if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
uint16_t rd :1; // recursion desired
|
|
|
|
uint16_t tc :1; // truncated message
|
|
|
|
uint16_t aa :1; // authoritive answer
|
|
|
|
uint16_t opcode :4; // purpose of message
|
|
|
|
uint16_t qr :1; // query/response flag
|
|
|
|
uint16_t rcode :4; // response code
|
|
|
|
uint16_t cd :1; // checking disabled
|
|
|
|
uint16_t ad :1; // authenticated data
|
|
|
|
uint16_t z :1; // its z! reserved
|
|
|
|
uint16_t ra :1; // recursion available
|
|
|
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
uint16_t qr :1; // query/response flag
|
|
|
|
uint16_t opcode :4; // purpose of message
|
|
|
|
uint16_t aa :1; // authoritive answer
|
|
|
|
uint16_t tc :1; // truncated message
|
|
|
|
uint16_t rd :1; // recursion desired
|
|
|
|
uint16_t ra :1; // recursion available
|
|
|
|
uint16_t z :1; // its z! reserved
|
|
|
|
uint16_t ad :1; // authenticated data
|
|
|
|
uint16_t cd :1; // checking disabled
|
|
|
|
uint16_t rcode :4; // response code
|
|
|
|
# else
|
|
|
|
# error "Adjust your <bits/endian.h> defines"
|
|
|
|
#endif
|
|
|
|
uint16_t q_count; // number of question entries
|
|
|
|
uint16_t ans_count; // number of answer entries
|
|
|
|
uint16_t auth_count; // number of authority entries
|
|
|
|
uint16_t add_count; // number of resource entries
|
2016-01-24 14:39:56 +00:00
|
|
|
} __packed;
|
2016-01-23 08:39:21 +00:00
|
|
|
|
2016-01-25 14:21:21 +00:00
|
|
|
typedef struct dns_rr {
|
2016-01-23 14:50:18 +00:00
|
|
|
__be16 qname_ptr;
|
|
|
|
__be16 qtype;
|
|
|
|
__be16 qclass;
|
|
|
|
__be32 ttl;
|
|
|
|
__be16 rdlength;
|
2016-01-24 14:39:56 +00:00
|
|
|
} __packed;
|
2016-01-23 14:50:18 +00:00
|
|
|
|
2016-01-26 15:54:17 +00:00
|
|
|
// DHCP
|
|
|
|
|
|
|
|
#define DHCP_OPTION_MAGIC_NUMBER (0x63825363)
|
|
|
|
|
|
|
|
typedef struct dhcp_packet {
|
|
|
|
uint8_t opcode;
|
|
|
|
uint8_t htype;
|
|
|
|
uint8_t hlen;
|
|
|
|
uint8_t hops;
|
|
|
|
uint32_t xid;
|
|
|
|
uint16_t secs;
|
|
|
|
uint16_t flags;
|
|
|
|
uint32_t ciaddr;
|
|
|
|
uint32_t yiaddr;
|
|
|
|
uint32_t siaddr;
|
|
|
|
uint32_t giaddr;
|
|
|
|
uint8_t chaddr[16];
|
|
|
|
uint8_t sname[64];
|
|
|
|
uint8_t file[128];
|
|
|
|
uint32_t option_format;
|
|
|
|
} __packed;
|
2016-01-23 14:50:18 +00:00
|
|
|
|
2016-01-26 15:54:17 +00:00
|
|
|
typedef struct dhcp_option {
|
|
|
|
uint8_t code;
|
|
|
|
uint8_t length;
|
2016-01-24 21:46:25 +00:00
|
|
|
} __packed;
|
|
|
|
|
2016-01-26 10:41:03 +00:00
|
|
|
// Prototypes
|
|
|
|
|
2016-01-18 18:37:52 +00:00
|
|
|
void handle_signal(int sig, siginfo_t *info, void *context);
|
2016-01-18 14:29:01 +00:00
|
|
|
|
2016-01-23 19:46:27 +00:00
|
|
|
void *handle_events(void *a);
|
2016-01-18 11:19:40 +00:00
|
|
|
|
2016-01-25 08:27:12 +00:00
|
|
|
void report_exit(const struct arguments *args, const char *fmt, ...);
|
2016-01-21 11:55:08 +00:00
|
|
|
|
2016-02-14 13:40:45 +00:00
|
|
|
void report_error(const struct arguments *args, jint error, const char *fmt, ...);
|
2016-02-14 12:30:36 +00:00
|
|
|
|
2016-01-28 10:58:39 +00:00
|
|
|
void check_allowed(const struct arguments *args);
|
|
|
|
|
2016-02-11 08:51:50 +00:00
|
|
|
void check_icmp_sessions(const struct arguments *args, int sessions, int maxsessions);
|
2016-02-09 18:55:28 +00:00
|
|
|
|
2016-02-11 08:51:50 +00:00
|
|
|
void check_udp_sessions(const struct arguments *args, int sessions, int maxsessions);
|
2016-02-09 18:55:28 +00:00
|
|
|
|
2016-02-11 08:51:50 +00:00
|
|
|
void check_tcp_sessions(const struct arguments *args, int sessions, int maxsessions);
|
2016-01-21 11:04:41 +00:00
|
|
|
|
2016-02-11 08:51:50 +00:00
|
|
|
int get_select_timeout(int sessions, int maxsessions);
|
2016-02-08 11:52:09 +00:00
|
|
|
|
2016-02-11 08:51:50 +00:00
|
|
|
int get_icmp_timeout(const struct icmp_session *u, int sessions, int maxsessions);
|
2016-02-08 11:52:09 +00:00
|
|
|
|
2016-02-11 08:51:50 +00:00
|
|
|
int get_udp_timeout(const struct udp_session *u, int sessions, int maxsessions);
|
|
|
|
|
|
|
|
int get_tcp_timeout(const struct tcp_session *t, int sessions, int maxsessions);
|
2016-02-08 11:52:09 +00:00
|
|
|
|
2016-01-20 13:11:04 +00:00
|
|
|
int get_selects(const struct arguments *args, fd_set *rfds, fd_set *wfds, fd_set *efds);
|
2016-01-20 08:24:34 +00:00
|
|
|
|
2016-02-11 08:12:00 +00:00
|
|
|
int check_tun(const struct arguments *args,
|
|
|
|
fd_set *rfds, fd_set *wfds, fd_set *efds,
|
|
|
|
int sessions, int maxsessions);
|
2016-01-18 11:19:40 +00:00
|
|
|
|
2016-02-02 13:31:44 +00:00
|
|
|
void check_icmp_sockets(const struct arguments *args, fd_set *rfds, fd_set *wfds, fd_set *efds);
|
|
|
|
|
2016-01-20 13:11:04 +00:00
|
|
|
void check_udp_sockets(const struct arguments *args, fd_set *rfds, fd_set *wfds, fd_set *efds);
|
2016-01-18 14:29:01 +00:00
|
|
|
|
2016-01-31 15:38:38 +00:00
|
|
|
int32_t get_qname(const uint8_t *data, const size_t datalen, uint16_t off, char *qname);
|
2016-01-29 18:10:23 +00:00
|
|
|
|
|
|
|
void parse_dns_response(const struct arguments *args, const uint8_t *data, const size_t datalen);
|
|
|
|
|
2016-02-15 11:50:03 +00:00
|
|
|
size_t get_send_window(const struct tcp_session *cur);
|
|
|
|
|
2016-01-20 13:11:04 +00:00
|
|
|
void check_tcp_sockets(const struct arguments *args, fd_set *rfds, fd_set *wfds, fd_set *efds);
|
2016-01-18 14:29:01 +00:00
|
|
|
|
2016-01-26 14:00:54 +00:00
|
|
|
int is_lower_layer(int protocol);
|
|
|
|
|
|
|
|
int is_upper_layer(int protocol);
|
|
|
|
|
2016-02-11 08:12:00 +00:00
|
|
|
void handle_ip(const struct arguments *args,
|
|
|
|
const uint8_t *buffer, size_t length,
|
|
|
|
int sessions, int maxsessions);
|
2016-01-20 08:24:34 +00:00
|
|
|
|
2016-02-10 18:28:40 +00:00
|
|
|
void init_icmp(const struct arguments *args);
|
|
|
|
|
|
|
|
void clear_icmp();
|
|
|
|
|
|
|
|
int get_icmp_sessions();
|
|
|
|
|
2016-02-02 13:31:44 +00:00
|
|
|
jboolean handle_icmp(const struct arguments *args,
|
2016-02-04 09:09:31 +00:00
|
|
|
const uint8_t *pkt, size_t length,
|
|
|
|
const uint8_t *payload,
|
2016-02-02 13:31:44 +00:00
|
|
|
int uid);
|
|
|
|
|
2016-02-10 18:28:40 +00:00
|
|
|
void init_udp(const struct arguments *args);
|
|
|
|
|
|
|
|
void clear_udp();
|
|
|
|
|
|
|
|
int get_udp_sessions();
|
|
|
|
|
2016-02-08 13:33:33 +00:00
|
|
|
int has_udp_session(const struct arguments *args, const uint8_t *pkt, const uint8_t *payload);
|
2016-02-04 09:09:31 +00:00
|
|
|
|
|
|
|
void block_udp(const struct arguments *args,
|
|
|
|
const uint8_t *pkt, size_t length,
|
|
|
|
const uint8_t *payload,
|
|
|
|
int uid);
|
2016-01-28 11:46:22 +00:00
|
|
|
|
2016-01-26 10:41:03 +00:00
|
|
|
jboolean handle_udp(const struct arguments *args,
|
2016-01-26 14:00:54 +00:00
|
|
|
const uint8_t *pkt, size_t length,
|
|
|
|
const uint8_t *payload,
|
2016-02-08 13:33:33 +00:00
|
|
|
int uid, struct allowed *redirect);
|
2016-01-26 10:41:03 +00:00
|
|
|
|
2016-01-29 06:59:35 +00:00
|
|
|
int get_dns_query(const struct arguments *args, const struct udp_session *u,
|
|
|
|
const uint8_t *data, const size_t datalen,
|
2016-01-29 18:10:23 +00:00
|
|
|
uint16_t *qtype, uint16_t *qclass, char *qname);
|
2016-01-18 14:29:01 +00:00
|
|
|
|
2016-01-26 17:53:17 +00:00
|
|
|
int check_domain(const struct arguments *args, const struct udp_session *u,
|
|
|
|
const uint8_t *data, const size_t datalen,
|
|
|
|
uint16_t qclass, uint16_t qtype, const char *name);
|
2016-01-23 14:50:18 +00:00
|
|
|
|
2016-01-26 15:54:17 +00:00
|
|
|
int check_dhcp(const struct arguments *args, const struct udp_session *u,
|
|
|
|
const uint8_t *data, const size_t datalen);
|
|
|
|
|
2016-02-10 18:28:40 +00:00
|
|
|
void init_tcp(const struct arguments *args);
|
|
|
|
|
|
|
|
void clear_tcp();
|
|
|
|
|
|
|
|
void clear_tcp_data(struct tcp_session *cur);
|
|
|
|
|
|
|
|
int get_tcp_sessions();
|
|
|
|
|
2016-01-26 15:54:17 +00:00
|
|
|
jboolean handle_tcp(const struct arguments *args,
|
|
|
|
const uint8_t *pkt, size_t length,
|
|
|
|
const uint8_t *payload,
|
2016-02-08 13:33:33 +00:00
|
|
|
int uid, struct allowed *redirect);
|
2016-01-26 15:54:17 +00:00
|
|
|
|
2016-02-09 17:59:20 +00:00
|
|
|
void queue_tcp(const struct arguments *args,
|
|
|
|
const struct tcphdr *tcphdr,
|
|
|
|
const char *session, struct tcp_session *cur,
|
|
|
|
const uint8_t *data, uint16_t datalen);
|
2016-02-07 19:15:40 +00:00
|
|
|
|
2016-02-03 17:32:25 +00:00
|
|
|
int open_icmp_socket(const struct arguments *args, const struct icmp_session *cur);
|
|
|
|
|
2016-01-25 12:28:52 +00:00
|
|
|
int open_udp_socket(const struct arguments *args, const struct udp_session *cur);
|
|
|
|
|
2016-02-08 13:33:33 +00:00
|
|
|
int open_tcp_socket(const struct arguments *args,
|
|
|
|
const struct tcp_session *cur, const struct allowed *redirect);
|
2016-01-18 14:29:01 +00:00
|
|
|
|
2016-01-23 19:46:27 +00:00
|
|
|
int32_t get_local_port(const int sock);
|
2016-01-17 16:41:54 +00:00
|
|
|
|
2016-01-24 11:50:40 +00:00
|
|
|
int write_syn_ack(const struct arguments *args, struct tcp_session *cur);
|
2016-01-17 16:41:54 +00:00
|
|
|
|
2016-02-10 09:46:00 +00:00
|
|
|
int write_ack(const struct arguments *args, struct tcp_session *cur);
|
2016-01-17 16:41:54 +00:00
|
|
|
|
2016-01-20 15:52:38 +00:00
|
|
|
int write_data(const struct arguments *args, struct tcp_session *cur,
|
2016-01-24 11:50:40 +00:00
|
|
|
const uint8_t *buffer, size_t length);
|
2016-01-17 16:41:54 +00:00
|
|
|
|
2016-02-05 11:03:44 +00:00
|
|
|
int write_fin_ack(const struct arguments *args, struct tcp_session *cur);
|
2016-01-17 16:41:54 +00:00
|
|
|
|
2016-01-24 11:50:40 +00:00
|
|
|
void write_rst(const struct arguments *args, struct tcp_session *cur);
|
2016-01-17 16:41:54 +00:00
|
|
|
|
2016-02-02 13:31:44 +00:00
|
|
|
ssize_t write_icmp(const struct arguments *args, const struct icmp_session *cur,
|
|
|
|
uint8_t *data, size_t datalen);
|
|
|
|
|
2016-01-23 19:46:27 +00:00
|
|
|
ssize_t write_udp(const struct arguments *args, const struct udp_session *cur,
|
2016-01-24 11:50:40 +00:00
|
|
|
uint8_t *data, size_t datalen);
|
2016-01-23 19:46:27 +00:00
|
|
|
|
|
|
|
ssize_t write_tcp(const struct arguments *args, const struct tcp_session *cur,
|
2016-02-10 09:46:00 +00:00
|
|
|
const uint8_t *data, size_t datalen,
|
2016-01-24 11:50:40 +00:00
|
|
|
int syn, int ack, int fin, int rst);
|
2016-01-20 13:11:04 +00:00
|
|
|
|
2016-01-23 19:46:27 +00:00
|
|
|
uint8_t char2nible(const char c);
|
|
|
|
|
|
|
|
void hex2bytes(const char *hex, uint8_t *buffer);
|
2016-01-17 16:41:54 +00:00
|
|
|
|
2016-02-15 07:01:25 +00:00
|
|
|
jint get_uid_retry(const int version, const int protocol,
|
2016-02-14 13:11:05 +00:00
|
|
|
const void *saddr, const uint16_t sport);
|
|
|
|
|
2016-02-15 07:01:25 +00:00
|
|
|
jint get_uid(const int version, const int protocol,
|
|
|
|
const void *saddr, const uint16_t sport,
|
|
|
|
int dump);
|
2016-01-17 16:41:54 +00:00
|
|
|
|
2016-01-23 19:46:27 +00:00
|
|
|
int protect_socket(const struct arguments *args, int socket);
|
|
|
|
|
|
|
|
uint16_t calc_checksum(uint16_t start, const uint8_t *buffer, size_t length);
|
2016-01-18 18:37:52 +00:00
|
|
|
|
2016-01-22 09:37:57 +00:00
|
|
|
jobject jniGlobalRef(JNIEnv *env, jobject cls);
|
|
|
|
|
|
|
|
jclass jniFindClass(JNIEnv *env, const char *name);
|
|
|
|
|
|
|
|
jmethodID jniGetMethodID(JNIEnv *env, jclass cls, const char *name, const char *signature);
|
|
|
|
|
|
|
|
jfieldID jniGetFieldID(JNIEnv *env, jclass cls, const char *name, const char *type);
|
|
|
|
|
|
|
|
jobject jniNewObject(JNIEnv *env, jclass cls, jmethodID constructor, const char *name);
|
|
|
|
|
|
|
|
int jniCheckException(JNIEnv *env);
|
|
|
|
|
2016-02-01 12:07:20 +00:00
|
|
|
int sdk_int(JNIEnv *env);
|
|
|
|
|
|
|
|
int __system_property_get(JNIEnv *env, const char *name, char *value);
|
2016-01-25 12:58:44 +00:00
|
|
|
|
2016-01-18 18:37:52 +00:00
|
|
|
void log_android(int prio, const char *fmt, ...);
|
2016-01-17 16:41:54 +00:00
|
|
|
|
2016-01-28 10:58:39 +00:00
|
|
|
void log_packet(const struct arguments *args, jobject jpacket);
|
|
|
|
|
2016-01-30 08:51:41 +00:00
|
|
|
void dns_resolved(const struct arguments *args,
|
|
|
|
const char *qname, const char *aname, const char *resource, int ttl);
|
|
|
|
|
2016-01-28 10:58:39 +00:00
|
|
|
jboolean is_domain_blocked(const struct arguments *args, const char *name);
|
|
|
|
|
2016-02-07 16:44:23 +00:00
|
|
|
struct allowed *is_address_allowed(const struct arguments *args, jobject objPacket);
|
2016-01-28 10:58:39 +00:00
|
|
|
|
|
|
|
jobject create_packet(const struct arguments *args,
|
|
|
|
jint version,
|
|
|
|
jint protocol,
|
|
|
|
const char *flags,
|
|
|
|
const char *source,
|
|
|
|
jint sport,
|
|
|
|
const char *dest,
|
|
|
|
jint dport,
|
|
|
|
const char *data,
|
|
|
|
jint uid,
|
|
|
|
jboolean allowed);
|
2016-01-18 18:37:52 +00:00
|
|
|
|
2016-02-15 16:48:53 +00:00
|
|
|
void account_usage(const struct arguments *args, jint version, jint protocol,
|
|
|
|
const char *daddr, jint dport, jint uid, jlong sent, jlong received);
|
|
|
|
|
2016-01-18 20:37:51 +00:00
|
|
|
void write_pcap_hdr();
|
|
|
|
|
2016-01-23 19:46:27 +00:00
|
|
|
void write_pcap_rec(const uint8_t *buffer, size_t len);
|
2016-01-18 20:37:51 +00:00
|
|
|
|
2016-01-22 12:06:50 +00:00
|
|
|
void write_pcap(const void *ptr, size_t len);
|
|
|
|
|
2016-02-15 11:50:03 +00:00
|
|
|
int compare_u32(uint32_t seq1, uint32_t seq2);
|
2016-02-05 15:30:18 +00:00
|
|
|
|
2016-01-17 16:41:54 +00:00
|
|
|
const char *strstate(const int state);
|
|
|
|
|
2016-01-23 19:46:27 +00:00
|
|
|
char *hex(const u_int8_t *data, const size_t len);
|