summaryrefstree
path: root/kernel/include/net/ncm.h
blob: 6c2939385d74ddce5c4698828265461f799f1ea1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
 *
 * Network Context Metadata Module[NCM]:Implementation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/* START_OF_KNOX_NPA */

#ifndef NCM_COMMON_H__
#define NCM_COMMON_H__

/* Address length consistent with com_android_server_enterprise_nap_NetworkAnalyticsDriver.cpp */
#define INET6_ADDRSTRLEN_NAP 48

#define NCM_VERSION 10

#define INIT_UID_NAP 0
#define INIT_PID_NAP 1

#define DNS_PORT_NAP 53

#define IPV4_FAMILY_NAP 2
#define IPV6_FAMILY_NAP 10

#define NCM_FLOW_TYPE_DEFAULT -1
#define NCM_FLOW_TYPE_ALL 0
#define NCM_FLOW_TYPE_OPEN 1
#define NCM_FLOW_TYPE_CLOSE 2

#include <linux/kernel.h>
#include <linux/inet.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <net/netfilter/nf_conntrack.h>

/* Struct Socket definition */
struct knox_socket_metadata {
/* The source port of the socket */
	__u16   srcport;
/* The destination port of the socket */
	__u16   dstport;
/* The Transport layer protocol of the socket*/
	__u16   trans_proto;
/* The number of application layer bytes sent by the socket */
	__u64   knox_sent;
/* The number of application layer bytes recieved by the socket */
	__u64   knox_recv;
/* The uid which created the socket */
	uid_t   knox_uid;
/* The pid under which the socket was created */
	pid_t   knox_pid;
/* The parent user id under which the socket was created */
	uid_t   knox_puid;
/* The epoch time at which the socket was opened */
	__u64   open_time;
/* The epoch time at which the socket was closed */
	__u64   close_time;
/* The source address of the socket */
	char srcaddr[INET6_ADDRSTRLEN_NAP];
/* The destination address of the socket */
	char dstaddr[INET6_ADDRSTRLEN_NAP];
/* The name of the process which created the socket */
	char process_name[PROCESS_NAME_LEN_NAP];
/* The name of the parent process which created the socket */
	char parent_process_name[PROCESS_NAME_LEN_NAP];
/*  The Domain name associated with the ip address of the socket. The size needs to be in sync with the userspace implementation */
	char domain_name[DOMAIN_NAME_LEN_NAP];
/* The uid which originated the dns request */
	uid_t   knox_uid_dns;
/* The parent process id under which the socket was created */
	pid_t   knox_ppid;
/* The interface used by the flow to transmit packet */
	char interface_name[IFNAMSIZ];
/* The flow type is used identify the current state of the network flow*/
	int flow_type;
/* The struct defined is responsible for inserting the socket meta-data into kfifo */
	struct work_struct work_kfifo;
};

/* Struct Socket definition */
struct knox_user_socket_metadata {
/* The source port of the socket */
	__u16   srcport;
/* The destination port of the socket */
	__u16   dstport;
/* The Transport layer protocol of the socket*/
	__u16   trans_proto;
/* The number of application layer bytes sent by the socket */
	__u64   knox_sent;
/* The number of application layer bytes recieved by the socket */
	__u64   knox_recv;
/* The uid which created the socket */
	uid_t   knox_uid;
/* The pid under which the socket was created */
	pid_t   knox_pid;
/* The parent user id under which the socket was created */
	uid_t   knox_puid;
/* The epoch time at which the socket was opened */
	__u64   open_time;
/* The epoch time at which the socket was closed */
	__u64   close_time;
/* The source address of the socket */
	char srcaddr[INET6_ADDRSTRLEN_NAP];
/* The destination address of the socket */
	char dstaddr[INET6_ADDRSTRLEN_NAP];
/* The name of the process which created the socket */
	char process_name[PROCESS_NAME_LEN_NAP];
/* The name of the parent process which created the socket */
	char parent_process_name[PROCESS_NAME_LEN_NAP];
/*  The Domain name associated with the ip address of the socket. The size needs to be in sync with the userspace implementation */
	char domain_name[DOMAIN_NAME_LEN_NAP];
/* The uid which originated the dns request */
	uid_t   knox_uid_dns;
/* The parent process id under which the socket was created */
	pid_t   knox_ppid;
/* The interface used by the flow to transmit packet */
	char interface_name[IFNAMSIZ];
/* The flow type is used identify the current state of the network flow*/
	int flow_type;
};

/* The list of function which is being referenced */
extern unsigned int check_ncm_flag(void);
extern void knox_collect_conntrack_data(struct nf_conn *ct, int startStop, int where);

extern bool kfifo_status(void);
extern void insert_data_kfifo_kthread(struct knox_socket_metadata* knox_socket_metadata);

/* Debug */
#define NCM_DEBUG        1
#if NCM_DEBUG
#define NCM_LOGD(...) printk("ncm: "__VA_ARGS__)
#else
#define NCM_LOGD(...)
#endif /* NCM_DEBUG */
#define NCM_LOGE(...) printk("ncm: "__VA_ARGS__)



/* IOCTL definitions*/
#define __NCMIOC    0x120
#define NCM_ACTIVATED_OPEN       _IO(__NCMIOC, 2)
#define NCM_DEACTIVATED          _IO(__NCMIOC, 4)
#define NCM_ACTIVATED_CLOSE      _IO(__NCMIOC, 8)
#define NCM_ACTIVATED_ALL        _IO(__NCMIOC, 16)
#define NCM_GETVERSION           _IO(__NCMIOC, 32)
#define NCM_MATCH_VERSION        _IO(__NCMIOC, 64)

#endif

/* END_OF_KNOX_NPA */