14 |
#include <linux/inet.h> |
#include <linux/inet.h> |
15 |
#include <linux/in.h> |
#include <linux/in.h> |
16 |
#include <linux/in6.h> |
#include <linux/in6.h> |
17 |
|
#include <linux/un.h> |
18 |
#include <net/ip.h> |
#include <net/ip.h> |
19 |
#include <net/ipv6.h> |
#include <net/ipv6.h> |
20 |
#include <net/udp.h> |
#include <net/udp.h> |
21 |
#include "internal.h" |
#include "internal.h" |
22 |
|
|
23 |
struct ccs_addr_info { |
struct ccs_inet_addr_info { |
|
u8 protocol; |
|
|
u8 operation; |
|
24 |
u16 port; /* In network byte order. */ |
u16 port; /* In network byte order. */ |
25 |
const u32 *address; /* In network byte order. */ |
const u32 *address; /* In network byte order. */ |
26 |
bool is_ipv6; |
bool is_ipv6; |
27 |
}; |
}; |
28 |
|
|
29 |
const char *ccs_net_protocol_keyword[CCS_MAX_NETWORK_PROTOCOL] = { |
struct ccs_unix_addr_info { |
30 |
[CCS_NETWORK_TCP_PROTOCOL] = "TCP", |
u8 *addr; |
31 |
[CCS_NETWORK_UDP_PROTOCOL] = "UDP", |
unsigned int addr_len; |
32 |
[CCS_NETWORK_RAW_PROTOCOL] = "RAW", |
}; |
33 |
|
|
34 |
|
struct ccs_addr_info { |
35 |
|
u8 protocol; |
36 |
|
u8 operation; |
37 |
|
struct ccs_inet_addr_info inet; |
38 |
|
struct ccs_unix_addr_info unix0; |
39 |
|
}; |
40 |
|
|
41 |
|
const char *ccs_inet_keyword[CCS_MAX_INET_PROTOCOL] = { |
42 |
|
[CCS_NETWORK_INET_TCP_PROTOCOL] = "TCP", |
43 |
|
[CCS_NETWORK_INET_UDP_PROTOCOL] = "UDP", |
44 |
|
[CCS_NETWORK_INET_RAW_PROTOCOL] = "RAW", |
45 |
|
}; |
46 |
|
|
47 |
|
const char *ccs_unix_keyword[CCS_MAX_UNIX_PROTOCOL] = { |
48 |
|
[CCS_NETWORK_UNIX_STREAM_PROTOCOL] = "stream", |
49 |
|
[CCS_NETWORK_UNIX_DGRAM_PROTOCOL] = "dgram", |
50 |
|
[CCS_NETWORK_UNIX_SEQPACKET_PROTOCOL] = "seqpacket", |
51 |
}; |
}; |
52 |
|
|
53 |
const char *ccs_net_keyword[CCS_MAX_NETWORK_OPERATION] = { |
const char *ccs_net_keyword[CCS_MAX_NETWORK_OPERATION] = { |
60 |
}; |
}; |
61 |
|
|
62 |
/** |
/** |
63 |
* ccs_audit_network_log - Audit network log. |
* ccs_audit_inet_log - Audit INET network log. |
64 |
* |
* |
65 |
* @r: Pointer to "struct ccs_request_info". |
* @r: Pointer to "struct ccs_request_info". |
66 |
* |
* |
67 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
68 |
*/ |
*/ |
69 |
static int ccs_audit_network_log(struct ccs_request_info *r) |
static int ccs_audit_inet_log(struct ccs_request_info *r) |
70 |
{ |
{ |
71 |
char buf[128]; |
char buf[128]; |
72 |
const char *protocol = |
const char *protocol = |
73 |
ccs_net_protocol_keyword[r->param.network.protocol]; |
ccs_inet_keyword[r->param.inet_network.protocol]; |
74 |
const char *operation = ccs_net_keyword[r->param.network.operation]; |
const char *operation = ccs_net_keyword[r->param.inet_network.operation]; |
75 |
const u32 *address = r->param.network.address; |
const u32 *address = r->param.inet_network.address; |
76 |
const u16 port = r->param.network.port; |
const u16 port = r->param.inet_network.port; |
77 |
if (r->param.network.is_ipv6) |
if (r->param.inet_network.is_ipv6) |
78 |
ccs_print_ipv6(buf, sizeof(buf), (const struct in6_addr *) |
ccs_print_ipv6(buf, sizeof(buf), (const struct in6_addr *) |
79 |
address, (const struct in6_addr *) address); |
address, (const struct in6_addr *) address); |
80 |
else |
else |
81 |
ccs_print_ipv4(buf, sizeof(buf), r->param.network.ip, |
ccs_print_ipv4(buf, sizeof(buf), r->param.inet_network.ip, |
82 |
r->param.network.ip); |
r->param.inet_network.ip); |
83 |
ccs_write_log(r, "network %s %s %s %u\n", protocol, operation, buf, |
ccs_write_log(r, "network inet %s %s %s %u\n", protocol, operation, |
84 |
port); |
buf, port); |
85 |
|
if (r->granted) |
86 |
|
return 0; |
87 |
|
ccs_warn_log(r, "network inet %s %s %s %u", protocol, operation, buf, |
88 |
|
port); |
89 |
|
return ccs_supervisor(r, "network inet %s %s %s %u\n", protocol, |
90 |
|
operation, buf, port); |
91 |
|
} |
92 |
|
|
93 |
|
/** |
94 |
|
* ccs_audit_unix_log - Audit UNIX network log. |
95 |
|
* |
96 |
|
* @r: Pointer to "struct ccs_request_info". |
97 |
|
* |
98 |
|
* Returns 0 on success, negative value otherwise. |
99 |
|
*/ |
100 |
|
static int ccs_audit_unix_log(struct ccs_request_info *r) |
101 |
|
{ |
102 |
|
const char *protocol = |
103 |
|
ccs_unix_keyword[r->param.unix_network.protocol]; |
104 |
|
const char *operation = |
105 |
|
ccs_net_keyword[r->param.unix_network.operation]; |
106 |
|
const char *address = r->param.unix_network.address->name; |
107 |
|
ccs_write_log(r, "network unix %s %s %s\n", protocol, operation, |
108 |
|
address); |
109 |
if (r->granted) |
if (r->granted) |
110 |
return 0; |
return 0; |
111 |
ccs_warn_log(r, "network %s %s %s %u", protocol, operation, buf, port); |
ccs_warn_log(r, "network unix %s %s %s", protocol, operation, address); |
112 |
return ccs_supervisor(r, "network %s %s %s %u\n", protocol, operation, |
return ccs_supervisor(r, "network unix %s %s %s\n", protocol, |
113 |
buf, port); |
operation, address); |
114 |
} |
} |
115 |
|
|
116 |
/** |
/** |
207 |
NIP6(*max_ip)); |
NIP6(*max_ip)); |
208 |
} |
} |
209 |
|
|
210 |
static bool ccs_check_network_acl(struct ccs_request_info *r, |
static bool ccs_check_inet_acl(struct ccs_request_info *r, |
211 |
const struct ccs_acl_info *ptr) |
const struct ccs_acl_info *ptr) |
212 |
{ |
{ |
213 |
const struct ccs_ip_network_acl *acl = |
const struct ccs_inet_acl *acl = container_of(ptr, typeof(*acl), head); |
|
container_of(ptr, typeof(*acl), head); |
|
214 |
bool ret; |
bool ret; |
215 |
if (!(acl->perm & (1 << r->param.network.operation)) || |
if (!(acl->perm & (1 << r->param.inet_network.operation)) || |
216 |
!ccs_compare_number_union(r->param.network.port, &acl->port)) |
!ccs_compare_number_union(r->param.inet_network.port, &acl->port)) |
217 |
return false; |
return false; |
218 |
switch (acl->address_type) { |
switch (acl->address_type) { |
219 |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
220 |
ret = ccs_address_matches_group(r->param.network.is_ipv6, |
ret = ccs_address_matches_group(r->param.inet_network.is_ipv6, |
221 |
r->param.network.address, |
r->param.inet_network.address, |
222 |
acl->address.group); |
acl->address.group); |
223 |
break; |
break; |
224 |
case CCS_IP_ADDRESS_TYPE_IPv4: |
case CCS_IP_ADDRESS_TYPE_IPv4: |
225 |
ret = !r->param.network.is_ipv6 && |
ret = !r->param.inet_network.is_ipv6 && |
226 |
acl->address.ipv4.min <= r->param.network.ip && |
acl->address.ipv4.min <= r->param.inet_network.ip && |
227 |
r->param.network.ip <= acl->address.ipv4.max; |
r->param.inet_network.ip <= acl->address.ipv4.max; |
228 |
break; |
break; |
229 |
default: |
default: |
230 |
ret = r->param.network.is_ipv6 && |
ret = r->param.inet_network.is_ipv6 && |
231 |
memcmp(acl->address.ipv6.min, r->param.network.address, |
memcmp(acl->address.ipv6.min, |
232 |
16) <= 0 && |
r->param.inet_network.address, 16) <= 0 && |
233 |
memcmp(r->param.network.address, acl->address.ipv6.max, |
memcmp(r->param.inet_network.address, |
234 |
16) <= 0; |
acl->address.ipv6.max, 16) <= 0; |
235 |
break; |
break; |
236 |
} |
} |
237 |
return ret; |
return ret; |
238 |
} |
} |
239 |
|
|
240 |
|
static bool ccs_check_unix_acl(struct ccs_request_info *r, |
241 |
|
const struct ccs_acl_info *ptr) |
242 |
|
{ |
243 |
|
const struct ccs_unix_acl *acl = container_of(ptr, typeof(*acl), head); |
244 |
|
return (acl->perm & (1 << r->param.unix_network.operation)) && |
245 |
|
ccs_compare_name_union(r->param.unix_network.address, |
246 |
|
&acl->name); |
247 |
|
} |
248 |
|
|
249 |
|
static const u8 |
250 |
|
ccs_inet2mac[CCS_MAX_INET_PROTOCOL][CCS_MAX_NETWORK_OPERATION] = { |
251 |
|
[CCS_NETWORK_INET_TCP_PROTOCOL] = { |
252 |
|
[CCS_NETWORK_BIND] = CCS_MAC_NETWORK_INET_TCP_BIND, |
253 |
|
[CCS_NETWORK_LISTEN] = CCS_MAC_NETWORK_INET_TCP_LISTEN, |
254 |
|
[CCS_NETWORK_CONNECT] = CCS_MAC_NETWORK_INET_TCP_CONNECT, |
255 |
|
[CCS_NETWORK_ACCEPT] = CCS_MAC_NETWORK_INET_TCP_ACCEPT, |
256 |
|
}, |
257 |
|
[CCS_NETWORK_INET_UDP_PROTOCOL] = { |
258 |
|
[CCS_NETWORK_BIND] = CCS_MAC_NETWORK_INET_UDP_BIND, |
259 |
|
[CCS_NETWORK_CONNECT] = CCS_MAC_NETWORK_INET_UDP_CONNECT, |
260 |
|
[CCS_NETWORK_SEND] = CCS_MAC_NETWORK_INET_UDP_SEND, |
261 |
|
[CCS_NETWORK_RECV] = CCS_MAC_NETWORK_INET_UDP_RECV, |
262 |
|
}, |
263 |
|
[CCS_NETWORK_INET_RAW_PROTOCOL] = { |
264 |
|
[CCS_NETWORK_BIND] = CCS_MAC_NETWORK_INET_RAW_BIND, |
265 |
|
[CCS_NETWORK_CONNECT] = CCS_MAC_NETWORK_INET_RAW_CONNECT, |
266 |
|
[CCS_NETWORK_SEND] = CCS_MAC_NETWORK_INET_RAW_SEND, |
267 |
|
[CCS_NETWORK_RECV] = CCS_MAC_NETWORK_INET_RAW_RECV, |
268 |
|
}, |
269 |
|
}; |
270 |
|
|
271 |
static const u8 |
static const u8 |
272 |
ccs_net2mac[CCS_MAX_NETWORK_PROTOCOL][CCS_MAX_NETWORK_OPERATION] = { |
ccs_unix2mac[CCS_MAX_UNIX_PROTOCOL][CCS_MAX_NETWORK_OPERATION] = { |
273 |
[CCS_NETWORK_TCP_PROTOCOL] = { |
[CCS_NETWORK_UNIX_STREAM_PROTOCOL] = { |
274 |
[CCS_NETWORK_BIND] = CCS_MAC_NETWORK_TCP_BIND, |
[CCS_NETWORK_BIND] = CCS_MAC_NETWORK_UNIX_STREAM_BIND, |
275 |
[CCS_NETWORK_LISTEN] = CCS_MAC_NETWORK_TCP_LISTEN, |
[CCS_NETWORK_LISTEN] = CCS_MAC_NETWORK_UNIX_STREAM_LISTEN, |
276 |
[CCS_NETWORK_CONNECT] = CCS_MAC_NETWORK_TCP_CONNECT, |
[CCS_NETWORK_CONNECT] = CCS_MAC_NETWORK_UNIX_STREAM_CONNECT, |
|
[CCS_NETWORK_ACCEPT] = CCS_MAC_NETWORK_TCP_ACCEPT, |
|
277 |
}, |
}, |
278 |
[CCS_NETWORK_UDP_PROTOCOL] = { |
[CCS_NETWORK_UNIX_DGRAM_PROTOCOL] = { |
279 |
[CCS_NETWORK_BIND] = CCS_MAC_NETWORK_UDP_BIND, |
[CCS_NETWORK_BIND] = CCS_MAC_NETWORK_UNIX_DGRAM_BIND, |
280 |
[CCS_NETWORK_CONNECT] = CCS_MAC_NETWORK_UDP_SEND, |
[CCS_NETWORK_CONNECT] = CCS_MAC_NETWORK_UNIX_DGRAM_CONNECT, |
281 |
[CCS_NETWORK_SEND] = CCS_MAC_NETWORK_UDP_SEND, |
[CCS_NETWORK_SEND] = CCS_MAC_NETWORK_UNIX_DGRAM_SEND, |
|
[CCS_NETWORK_RECV] = CCS_MAC_NETWORK_UDP_RECV, |
|
282 |
}, |
}, |
283 |
[CCS_NETWORK_RAW_PROTOCOL] = { |
[CCS_NETWORK_UNIX_SEQPACKET_PROTOCOL] = { |
284 |
[CCS_NETWORK_BIND] = CCS_MAC_NETWORK_RAW_BIND, |
[CCS_NETWORK_BIND] = CCS_MAC_NETWORK_UNIX_SEQPACKET_BIND, |
285 |
[CCS_NETWORK_CONNECT] = CCS_MAC_NETWORK_RAW_SEND, |
[CCS_NETWORK_LISTEN] = CCS_MAC_NETWORK_UNIX_SEQPACKET_LISTEN, |
286 |
[CCS_NETWORK_SEND] = CCS_MAC_NETWORK_RAW_SEND, |
[CCS_NETWORK_CONNECT] = CCS_MAC_NETWORK_UNIX_SEQPACKET_CONNECT, |
|
[CCS_NETWORK_RECV] = CCS_MAC_NETWORK_RAW_RECV, |
|
287 |
}, |
}, |
288 |
}; |
}; |
289 |
|
|
290 |
/** |
/** |
291 |
* ccs_network_entry - Check permission for network operation. |
* ccs_inet_entry - Check permission for INET network operation. |
292 |
* |
* |
293 |
* @address: Pointer to "struct ccs_ip_address". |
* @address: Pointer to "struct ccs_addr_info". |
294 |
* |
* |
295 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
296 |
*/ |
*/ |
297 |
static int ccs_network_entry(const struct ccs_addr_info *address) |
static int ccs_inet_entry(const struct ccs_addr_info *address) |
298 |
{ |
{ |
299 |
const int idx = ccs_read_lock(); |
const int idx = ccs_read_lock(); |
300 |
struct ccs_request_info r; |
struct ccs_request_info r; |
301 |
int error = 0; |
int error = 0; |
302 |
const u8 type = ccs_net2mac[address->protocol][address->operation]; |
const u8 type = ccs_inet2mac[address->protocol][address->operation]; |
303 |
if (!type || ccs_init_request_info(&r, type) != CCS_CONFIG_DISABLED) { |
if (type && ccs_init_request_info(&r, type) != CCS_CONFIG_DISABLED) { |
304 |
r.param_type = CCS_TYPE_IP_NETWORK_ACL; |
r.param_type = CCS_TYPE_INET_ACL; |
305 |
r.param.network.protocol = address->protocol; |
r.param.inet_network.protocol = address->protocol; |
306 |
r.param.network.operation = address->operation; |
r.param.inet_network.operation = address->operation; |
307 |
r.param.network.is_ipv6 = address->is_ipv6; |
r.param.inet_network.is_ipv6 = address->inet.is_ipv6; |
308 |
r.param.network.address = address->address; |
r.param.inet_network.address = address->inet.address; |
309 |
r.param.network.port = ntohs(address->port); |
r.param.inet_network.port = ntohs(address->inet.port); |
310 |
/* use host byte order to allow u32 comparison than memcmp().*/ |
/* use host byte order to allow u32 comparison than memcmp().*/ |
311 |
r.param.network.ip = ntohl(*address->address); |
r.param.inet_network.ip = ntohl(*address->inet.address); |
312 |
do { |
do { |
313 |
ccs_check_acl(&r, ccs_check_network_acl); |
ccs_check_acl(&r, ccs_check_inet_acl); |
314 |
error = ccs_audit_network_log(&r); |
error = ccs_audit_inet_log(&r); |
315 |
} while (error == CCS_RETRY_REQUEST); |
} while (error == CCS_RETRY_REQUEST); |
316 |
} |
} |
317 |
ccs_read_unlock(idx); |
ccs_read_unlock(idx); |
318 |
return error; |
return error; |
319 |
} |
} |
320 |
|
|
321 |
static bool ccs_same_ip_network_acl(const struct ccs_acl_info *a, |
/** |
322 |
const struct ccs_acl_info *b) |
* ccs_unix_entry - Check permission for UNIX network operation. |
323 |
|
* |
324 |
|
* @address: Pointer to "struct ccs_addr_info". |
325 |
|
* |
326 |
|
* Returns 0 on success, negative value otherwise. |
327 |
|
*/ |
328 |
|
static int ccs_unix_entry(const struct ccs_addr_info *address) |
329 |
|
{ |
330 |
|
const int idx = ccs_read_lock(); |
331 |
|
struct ccs_request_info r; |
332 |
|
int error = 0; |
333 |
|
const u8 type = ccs_unix2mac[address->protocol][address->operation]; |
334 |
|
if (type && address->unix0.addr_len > sizeof(sa_family_t) && |
335 |
|
ccs_init_request_info(&r, type) != CCS_CONFIG_DISABLED) { |
336 |
|
char *buf; |
337 |
|
if (address->unix0.addr[0]) |
338 |
|
buf = ccs_encode(address->unix0.addr); |
339 |
|
else |
340 |
|
buf = ccs_encode2(address->unix0.addr, |
341 |
|
address->unix0.addr_len |
342 |
|
- sizeof(sa_family_t)); |
343 |
|
if (buf) { |
344 |
|
struct ccs_path_info addr; |
345 |
|
addr.name = buf; |
346 |
|
ccs_fill_path_info(&addr); |
347 |
|
r.param_type = CCS_TYPE_UNIX_ACL; |
348 |
|
r.param.unix_network.protocol = address->protocol; |
349 |
|
r.param.unix_network.operation = address->operation; |
350 |
|
r.param.unix_network.address = &addr; |
351 |
|
do { |
352 |
|
ccs_check_acl(&r, ccs_check_unix_acl); |
353 |
|
error = ccs_audit_unix_log(&r); |
354 |
|
} while (error == CCS_RETRY_REQUEST); |
355 |
|
kfree(buf); |
356 |
|
} else |
357 |
|
error = -ENOMEM; |
358 |
|
} |
359 |
|
ccs_read_unlock(idx); |
360 |
|
return error; |
361 |
|
} |
362 |
|
|
363 |
|
static bool ccs_same_inet_acl(const struct ccs_acl_info *a, |
364 |
|
const struct ccs_acl_info *b) |
365 |
{ |
{ |
366 |
const struct ccs_ip_network_acl *p1 = container_of(a, typeof(*p1), |
const struct ccs_inet_acl *p1 = container_of(a, typeof(*p1), |
367 |
head); |
head); |
368 |
const struct ccs_ip_network_acl *p2 = container_of(b, typeof(*p2), |
const struct ccs_inet_acl *p2 = container_of(b, typeof(*p2), |
369 |
head); |
head); |
370 |
return ccs_same_acl_head(&p1->head, &p2->head) |
return ccs_same_acl_head(&p1->head, &p2->head) |
371 |
&& p1->protocol == p2->protocol |
&& p1->protocol == p2->protocol |
372 |
&& p1->address_type == p2->address_type && |
&& p1->address_type == p2->address_type && |
378 |
ccs_same_number_union(&p1->port, &p2->port); |
ccs_same_number_union(&p1->port, &p2->port); |
379 |
} |
} |
380 |
|
|
381 |
static bool ccs_merge_ip_network_acl(struct ccs_acl_info *a, |
static bool ccs_same_unix_acl(const struct ccs_acl_info *a, |
382 |
struct ccs_acl_info *b, |
const struct ccs_acl_info *b) |
383 |
const bool is_delete) |
{ |
384 |
|
const struct ccs_unix_acl *p1 = container_of(a, typeof(*p1), |
385 |
|
head); |
386 |
|
const struct ccs_unix_acl *p2 = container_of(b, typeof(*p2), |
387 |
|
head); |
388 |
|
return ccs_same_acl_head(&p1->head, &p2->head) && |
389 |
|
p1->protocol == p2->protocol && |
390 |
|
ccs_same_name_union(&p1->name, &p2->name); |
391 |
|
} |
392 |
|
|
393 |
|
static bool ccs_merge_inet_acl(struct ccs_acl_info *a, |
394 |
|
struct ccs_acl_info *b, |
395 |
|
const bool is_delete) |
396 |
|
{ |
397 |
|
u8 * const a_perm = &container_of(a, struct ccs_inet_acl, head) |
398 |
|
->perm; |
399 |
|
u8 perm = *a_perm; |
400 |
|
const u8 b_perm = container_of(b, struct ccs_inet_acl, head) |
401 |
|
->perm; |
402 |
|
if (is_delete) |
403 |
|
perm &= ~b_perm; |
404 |
|
else |
405 |
|
perm |= b_perm; |
406 |
|
*a_perm = perm; |
407 |
|
return !perm; |
408 |
|
} |
409 |
|
|
410 |
|
static bool ccs_merge_unix_acl(struct ccs_acl_info *a, |
411 |
|
struct ccs_acl_info *b, |
412 |
|
const bool is_delete) |
413 |
{ |
{ |
414 |
u8 * const a_perm = &container_of(a, struct ccs_ip_network_acl, head) |
u8 * const a_perm = &container_of(a, struct ccs_unix_acl, head) |
415 |
->perm; |
->perm; |
416 |
u8 perm = *a_perm; |
u8 perm = *a_perm; |
417 |
const u8 b_perm = container_of(b, struct ccs_ip_network_acl, head) |
const u8 b_perm = container_of(b, struct ccs_unix_acl, head) |
418 |
->perm; |
->perm; |
419 |
if (is_delete) |
if (is_delete) |
420 |
perm &= ~b_perm; |
perm &= ~b_perm; |
425 |
} |
} |
426 |
|
|
427 |
/** |
/** |
428 |
* ccs_write_network - Write "struct ccs_ip_network_acl" list. |
* ccs_write_inet_network - Write "struct ccs_inet_acl" list. |
429 |
* |
* |
430 |
* @data: String to parse. |
* @data: String to parse. |
431 |
* @domain: Pointer to "struct ccs_domain_info". |
* @domain: Pointer to "struct ccs_domain_info". |
434 |
* |
* |
435 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
436 |
*/ |
*/ |
437 |
int ccs_write_network(char *data, struct ccs_domain_info *domain, |
int ccs_write_inet_network(char *data, struct ccs_domain_info *domain, |
438 |
struct ccs_condition *condition, const bool is_delete) |
struct ccs_condition *condition, |
439 |
|
const bool is_delete) |
440 |
{ |
{ |
441 |
struct ccs_ip_network_acl e = { |
struct ccs_inet_acl e = { |
442 |
.head.type = CCS_TYPE_IP_NETWORK_ACL, |
.head.type = CCS_TYPE_INET_ACL, |
443 |
.head.cond = condition, |
.head.cond = condition, |
444 |
}; |
}; |
445 |
u16 min_address[8]; |
u16 min_address[8]; |
449 |
char *w[4]; |
char *w[4]; |
450 |
if (!ccs_tokenize(data, w, sizeof(w)) || !w[3][0]) |
if (!ccs_tokenize(data, w, sizeof(w)) || !w[3][0]) |
451 |
return -EINVAL; |
return -EINVAL; |
452 |
for (e.protocol = 0; e.protocol < CCS_MAX_NETWORK_PROTOCOL; |
for (e.protocol = 0; e.protocol < CCS_MAX_INET_PROTOCOL; |
453 |
e.protocol++) |
e.protocol++) |
454 |
if (!strcmp(w[0], ccs_net_protocol_keyword[e.protocol])) |
if (!strcmp(w[0], ccs_inet_keyword[e.protocol])) |
455 |
break; |
break; |
456 |
for (type = 0; type < CCS_MAX_NETWORK_OPERATION; type++) |
for (type = 0; type < CCS_MAX_NETWORK_OPERATION; type++) |
457 |
if (ccs_permstr(w[1], ccs_net_keyword[type])) |
if (ccs_permstr(w[1], ccs_net_keyword[type])) |
458 |
e.perm |= 1 << type; |
e.perm |= 1 << type; |
459 |
if (e.protocol == CCS_MAX_NETWORK_PROTOCOL || !e.perm) |
if (e.protocol == CCS_MAX_INET_PROTOCOL || !e.perm) |
460 |
return -EINVAL; |
return -EINVAL; |
461 |
switch (ccs_parse_ip_address(w[2], min_address, max_address)) { |
switch (ccs_parse_ip_address(w[2], min_address, max_address)) { |
462 |
case CCS_IP_ADDRESS_TYPE_IPv6: |
case CCS_IP_ADDRESS_TYPE_IPv6: |
463 |
e.address_type = CCS_IP_ADDRESS_TYPE_IPv6; |
e.address_type = CCS_IP_ADDRESS_TYPE_IPv6; |
464 |
e.address.ipv6.min = ccs_get_ipv6_address((struct in6_addr *) |
e.address.ipv6.min = ccs_get_ipv6_address((struct in6_addr *) |
465 |
min_address); |
min_address); |
466 |
e.address.ipv6.max = ccs_get_ipv6_address((struct in6_addr *) |
e.address.ipv6.max = ccs_get_ipv6_address((struct in6_addr *) |
467 |
max_address); |
max_address); |
468 |
if (!e.address.ipv6.min || !e.address.ipv6.max) |
if (!e.address.ipv6.min || !e.address.ipv6.max) |
469 |
goto out; |
goto out; |
470 |
break; |
break; |
486 |
if (!ccs_parse_number_union(w[3], &e.port)) |
if (!ccs_parse_number_union(w[3], &e.port)) |
487 |
goto out; |
goto out; |
488 |
error = ccs_update_domain(&e.head, sizeof(e), is_delete, domain, |
error = ccs_update_domain(&e.head, sizeof(e), is_delete, domain, |
489 |
ccs_same_ip_network_acl, |
ccs_same_inet_acl, ccs_merge_inet_acl); |
|
ccs_merge_ip_network_acl); |
|
490 |
out: |
out: |
491 |
if (e.address_type == CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP) |
if (e.address_type == CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP) |
492 |
ccs_put_group(e.address.group); |
ccs_put_group(e.address.group); |
498 |
return error; |
return error; |
499 |
} |
} |
500 |
|
|
501 |
|
/** |
502 |
|
* ccs_write_unix_network - Write "struct ccs_unix_acl" list. |
503 |
|
* |
504 |
|
* @data: String to parse. |
505 |
|
* @domain: Pointer to "struct ccs_domain_info". |
506 |
|
* @condition: Pointer to "struct ccs_condition". Maybe NULL. |
507 |
|
* @is_delete: True if it is a delete request. |
508 |
|
* |
509 |
|
* Returns 0 on success, negative value otherwise. |
510 |
|
*/ |
511 |
|
int ccs_write_unix_network(char *data, struct ccs_domain_info *domain, |
512 |
|
struct ccs_condition *condition, |
513 |
|
const bool is_delete) |
514 |
|
{ |
515 |
|
struct ccs_unix_acl e = { |
516 |
|
.head.type = CCS_TYPE_UNIX_ACL, |
517 |
|
.head.cond = condition, |
518 |
|
}; |
519 |
|
int error = is_delete ? -ENOENT : -ENOMEM; |
520 |
|
u8 type; |
521 |
|
char *w[3]; |
522 |
|
if (!ccs_tokenize(data, w, sizeof(w)) || !w[2][0]) |
523 |
|
return -EINVAL; |
524 |
|
for (e.protocol = 0; e.protocol < CCS_MAX_UNIX_PROTOCOL; |
525 |
|
e.protocol++) |
526 |
|
if (!strcmp(w[0], ccs_unix_keyword[e.protocol])) |
527 |
|
break; |
528 |
|
for (type = 0; type < CCS_MAX_NETWORK_OPERATION; type++) |
529 |
|
if (ccs_permstr(w[1], ccs_net_keyword[type])) |
530 |
|
e.perm |= 1 << type; |
531 |
|
if (e.protocol == CCS_MAX_UNIX_PROTOCOL || !e.perm) |
532 |
|
return -EINVAL; |
533 |
|
if (!ccs_parse_name_union(w[2], &e.name)) |
534 |
|
return -EINVAL; |
535 |
|
error = ccs_update_domain(&e.head, sizeof(e), is_delete, domain, |
536 |
|
ccs_same_unix_acl, ccs_merge_unix_acl); |
537 |
|
ccs_put_name_union(&e.name); |
538 |
|
return error; |
539 |
|
} |
540 |
|
|
541 |
#ifndef CONFIG_NET |
#ifndef CONFIG_NET |
542 |
|
|
543 |
void __init ccs_network_init(void) |
void __init ccs_network_init(void) |
546 |
|
|
547 |
#else |
#else |
548 |
|
|
549 |
static bool ccs_check_address(const struct sockaddr *addr, |
static bool ccs_check_inet_address(const struct sockaddr *addr, |
550 |
const unsigned int addr_len, |
const unsigned int addr_len, |
551 |
struct ccs_addr_info *address) |
struct ccs_inet_addr_info *address) |
552 |
{ |
{ |
553 |
switch (addr->sa_family) { |
switch (addr->sa_family) { |
554 |
case AF_INET6: |
case AF_INET6: |
575 |
return false; |
return false; |
576 |
} |
} |
577 |
|
|
578 |
|
static void ccs_check_unix_address(struct sockaddr *addr, |
579 |
|
const unsigned int addr_len, |
580 |
|
struct ccs_unix_addr_info *address) |
581 |
|
{ |
582 |
|
address->addr = ((struct sockaddr_un *) addr)->sun_path; |
583 |
|
address->addr_len = addr_len; |
584 |
|
if (address->addr[0] && addr_len > sizeof(short) && |
585 |
|
addr_len <= sizeof(struct sockaddr_un)) |
586 |
|
((char *) addr)[addr_len] = '\0'; |
587 |
|
} |
588 |
|
|
589 |
|
static bool ccs_kernel_service(void) |
590 |
|
{ |
591 |
|
/* Nothing to do if I am a kernel service. */ |
592 |
|
return segment_eq(get_fs(), KERNEL_DS); |
593 |
|
} |
594 |
|
|
595 |
|
static u8 ccs_sock_family(struct socket *sock) |
596 |
|
{ |
597 |
|
if (ccs_kernel_service()) |
598 |
|
return 0; |
599 |
|
switch (sock->sk->sk_family) { |
600 |
|
case PF_INET: |
601 |
|
case PF_INET6: |
602 |
|
return 1; |
603 |
|
case PF_UNIX: |
604 |
|
return 2; |
605 |
|
default: |
606 |
|
return 0; |
607 |
|
} |
608 |
|
} |
609 |
|
|
610 |
/* Check permission for creating a socket. */ |
/* Check permission for creating a socket. */ |
611 |
static int __ccs_socket_create_permission(int family, int type, int protocol) |
static int __ccs_socket_create_permission(int family, int type, int protocol) |
612 |
{ |
{ |
613 |
/* Nothing to do if I am a kernel service. */ |
if (ccs_kernel_service()) |
|
if (segment_eq(get_fs(), KERNEL_DS)) |
|
614 |
return 0; |
return 0; |
615 |
if (family == PF_PACKET && !ccs_capable(CCS_USE_PACKET_SOCKET)) |
if (family == PF_PACKET && !ccs_capable(CCS_USE_PACKET_SOCKET)) |
616 |
return -EPERM; |
return -EPERM; |
619 |
return 0; |
return 0; |
620 |
} |
} |
621 |
|
|
622 |
/* Check permission for listening a TCP socket. */ |
/* Check permission for listening a socket. */ |
623 |
static int __ccs_socket_listen_permission(struct socket *sock) |
static int __ccs_socket_listen_permission(struct socket *sock) |
624 |
{ |
{ |
625 |
struct sockaddr_storage addr; |
struct sockaddr_storage addr; |
626 |
int error = 0; |
int error; |
627 |
int addr_len; |
int addr_len; |
628 |
struct ccs_addr_info address; |
struct ccs_addr_info address; |
629 |
/* Nothing to do if I am a kernel service. */ |
const u8 family = ccs_sock_family(sock); |
630 |
if (segment_eq(get_fs(), KERNEL_DS)) |
if (!family || (sock->type != SOCK_STREAM && |
631 |
return 0; |
sock->type != SOCK_SEQPACKET)) |
|
if (sock->type != SOCK_STREAM) |
|
632 |
return 0; |
return 0; |
633 |
switch (sock->sk->sk_family) { |
error = sock->ops->getname(sock, (struct sockaddr *) &addr, &addr_len, |
634 |
case PF_INET: |
0); |
635 |
case PF_INET6: |
if (error) |
636 |
break; |
return error; |
|
default: |
|
|
return 0; |
|
|
} |
|
|
if (sock->ops->getname(sock, (struct sockaddr *) &addr, &addr_len, 0)) |
|
|
return -EPERM; |
|
|
address.protocol = CCS_NETWORK_TCP_PROTOCOL; |
|
637 |
address.operation = CCS_NETWORK_LISTEN; |
address.operation = CCS_NETWORK_LISTEN; |
638 |
if (ccs_check_address((struct sockaddr *) &addr, addr_len, &address)) |
if (family == 2) { |
639 |
error = ccs_network_entry(&address); |
address.protocol = CCS_NETWORK_UNIX_STREAM_PROTOCOL; |
640 |
|
ccs_check_unix_address((struct sockaddr *) &addr, addr_len, |
641 |
|
&address.unix0); |
642 |
|
error = ccs_unix_entry(&address); |
643 |
|
} else { |
644 |
|
address.protocol = CCS_NETWORK_INET_TCP_PROTOCOL; |
645 |
|
if (ccs_check_inet_address((struct sockaddr *) &addr, addr_len, |
646 |
|
&address.inet)) |
647 |
|
error = ccs_inet_entry(&address); |
648 |
|
} |
649 |
return error; |
return error; |
650 |
} |
} |
651 |
|
|
652 |
/* Check permission for setting the remote IP address/port pair of a socket. */ |
/* Check permission for setting the remote address of a socket. */ |
653 |
static int __ccs_socket_connect_permission(struct socket *sock, |
static int __ccs_socket_connect_permission(struct socket *sock, |
654 |
struct sockaddr *addr, int addr_len) |
struct sockaddr *addr, int addr_len) |
655 |
{ |
{ |
656 |
int error = 0; |
int error = 0; |
657 |
const unsigned int type = sock->type; |
const unsigned int type = sock->type; |
658 |
struct ccs_addr_info address; |
struct ccs_addr_info address; |
659 |
/* Nothing to do if I am a kernel service. */ |
const u8 family = ccs_sock_family(sock); |
660 |
if (segment_eq(get_fs(), KERNEL_DS)) |
if (!family) |
661 |
return 0; |
return 0; |
|
switch (type) { |
|
|
case SOCK_STREAM: |
|
|
address.protocol = CCS_NETWORK_TCP_PROTOCOL; |
|
|
break; |
|
|
case SOCK_DGRAM: |
|
|
address.protocol = CCS_NETWORK_UDP_PROTOCOL; |
|
|
break; |
|
|
case SOCK_RAW: |
|
|
address.protocol = CCS_NETWORK_RAW_PROTOCOL; |
|
|
break; |
|
|
default: |
|
|
return 0; |
|
|
} |
|
662 |
address.operation = CCS_NETWORK_CONNECT; |
address.operation = CCS_NETWORK_CONNECT; |
663 |
if (!ccs_check_address(addr, addr_len, &address)) |
if (family == 2) { |
664 |
goto skip; |
switch (type) { |
665 |
if (type == SOCK_RAW) |
case SOCK_STREAM: |
666 |
address.port = htons(sock->sk->sk_protocol); |
address.protocol = CCS_NETWORK_UNIX_STREAM_PROTOCOL; |
667 |
error = ccs_network_entry(&address); |
break; |
668 |
skip: |
case SOCK_DGRAM: |
669 |
|
address.protocol = CCS_NETWORK_UNIX_DGRAM_PROTOCOL; |
670 |
|
break; |
671 |
|
case SOCK_SEQPACKET: |
672 |
|
address.protocol = CCS_NETWORK_UNIX_SEQPACKET_PROTOCOL; |
673 |
|
break; |
674 |
|
default: |
675 |
|
return 0; |
676 |
|
} |
677 |
|
ccs_check_unix_address(addr, addr_len, &address.unix0); |
678 |
|
error = ccs_unix_entry(&address); |
679 |
|
} else { |
680 |
|
switch (type) { |
681 |
|
case SOCK_STREAM: |
682 |
|
address.protocol = CCS_NETWORK_INET_TCP_PROTOCOL; |
683 |
|
break; |
684 |
|
case SOCK_DGRAM: |
685 |
|
address.protocol = CCS_NETWORK_INET_UDP_PROTOCOL; |
686 |
|
break; |
687 |
|
case SOCK_RAW: |
688 |
|
address.protocol = CCS_NETWORK_INET_RAW_PROTOCOL; |
689 |
|
break; |
690 |
|
default: |
691 |
|
return 0; |
692 |
|
} |
693 |
|
ccs_check_inet_address(addr, addr_len, &address.inet); |
694 |
|
if (type == SOCK_RAW) |
695 |
|
address.inet.port = htons(sock->sk->sk_protocol); |
696 |
|
error = ccs_inet_entry(&address); |
697 |
|
} |
698 |
return error; |
return error; |
699 |
} |
} |
700 |
|
|
701 |
/* Check permission for setting the local IP address/port pair of a socket. */ |
/* Check permission for setting the local address of a socket. */ |
702 |
static int __ccs_socket_bind_permission(struct socket *sock, |
static int __ccs_socket_bind_permission(struct socket *sock, |
703 |
struct sockaddr *addr, int addr_len) |
struct sockaddr *addr, int addr_len) |
704 |
{ |
{ |
705 |
int error = 0; |
int error = 0; |
706 |
const unsigned int type = sock->type; |
const unsigned int type = sock->type; |
707 |
struct ccs_addr_info address; |
struct ccs_addr_info address; |
708 |
/* Nothing to do if I am a kernel service. */ |
const u8 family = ccs_sock_family(sock); |
709 |
if (segment_eq(get_fs(), KERNEL_DS)) |
if (!family) |
710 |
return 0; |
return 0; |
711 |
switch (type) { |
address.operation = CCS_NETWORK_BIND; |
712 |
case SOCK_STREAM: |
if (family == 2) { |
713 |
address.protocol = CCS_NETWORK_TCP_PROTOCOL; |
switch (type) { |
714 |
break; |
case SOCK_STREAM: |
715 |
case SOCK_DGRAM: |
address.protocol = CCS_NETWORK_UNIX_STREAM_PROTOCOL; |
716 |
address.protocol = CCS_NETWORK_UDP_PROTOCOL; |
break; |
717 |
break; |
case SOCK_DGRAM: |
718 |
case SOCK_RAW: |
address.protocol = CCS_NETWORK_UNIX_DGRAM_PROTOCOL; |
719 |
address.protocol = CCS_NETWORK_RAW_PROTOCOL; |
break; |
720 |
break; |
case SOCK_SEQPACKET: |
721 |
default: |
address.protocol = CCS_NETWORK_UNIX_SEQPACKET_PROTOCOL; |
722 |
|
break; |
723 |
|
default: |
724 |
|
return 0; |
725 |
|
} |
726 |
|
ccs_check_unix_address(addr, addr_len, &address.unix0); |
727 |
|
error = ccs_unix_entry(&address); |
728 |
|
} else { |
729 |
|
switch (type) { |
730 |
|
case SOCK_STREAM: |
731 |
|
address.protocol = CCS_NETWORK_INET_TCP_PROTOCOL; |
732 |
|
break; |
733 |
|
case SOCK_DGRAM: |
734 |
|
address.protocol = CCS_NETWORK_INET_UDP_PROTOCOL; |
735 |
|
break; |
736 |
|
case SOCK_RAW: |
737 |
|
address.protocol = CCS_NETWORK_INET_RAW_PROTOCOL; |
738 |
|
break; |
739 |
|
default: |
740 |
|
return 0; |
741 |
|
} |
742 |
|
ccs_check_inet_address(addr, addr_len, &address.inet); |
743 |
|
if (type == SOCK_RAW) |
744 |
|
address.inet.port = htons(sock->sk->sk_protocol); |
745 |
|
error = ccs_inet_entry(&address); |
746 |
|
} |
747 |
|
return error; |
748 |
|
} |
749 |
|
|
750 |
|
/* Check permission for sending a datagram via a UDP or RAW socket. */ |
751 |
|
static int __ccs_socket_sendmsg_permission(struct socket *sock, |
752 |
|
struct msghdr *msg, int size) |
753 |
|
{ |
754 |
|
int error = 0; |
755 |
|
const int type = sock->type; |
756 |
|
struct ccs_addr_info address; |
757 |
|
const u8 family = ccs_sock_family(sock); |
758 |
|
if (!msg->msg_name || !family) |
759 |
return 0; |
return 0; |
760 |
|
address.operation = CCS_NETWORK_SEND; |
761 |
|
if (family == 2) { |
762 |
|
if (type != SOCK_DGRAM) |
763 |
|
return 0; |
764 |
|
address.protocol = CCS_NETWORK_UNIX_DGRAM_PROTOCOL; |
765 |
|
ccs_check_unix_address((struct sockaddr *) msg->msg_name, |
766 |
|
msg->msg_namelen, &address.unix0); |
767 |
|
error = ccs_unix_entry(&address); |
768 |
|
} else { |
769 |
|
switch (type) { |
770 |
|
case SOCK_DGRAM: |
771 |
|
address.protocol = CCS_NETWORK_INET_UDP_PROTOCOL; |
772 |
|
break; |
773 |
|
case SOCK_RAW: |
774 |
|
address.protocol = CCS_NETWORK_INET_RAW_PROTOCOL; |
775 |
|
break; |
776 |
|
default: |
777 |
|
return 0; |
778 |
|
} |
779 |
|
ccs_check_inet_address((struct sockaddr *) msg->msg_name, |
780 |
|
msg->msg_namelen, &address.inet); |
781 |
|
if (type == SOCK_RAW) |
782 |
|
address.inet.port = htons(sock->sk->sk_protocol); |
783 |
|
error = ccs_inet_entry(&address); |
784 |
} |
} |
|
address.operation = CCS_NETWORK_BIND; |
|
|
if (!ccs_check_address(addr, addr_len, &address)) |
|
|
goto skip; |
|
|
if (type == SOCK_RAW) |
|
|
address.port = htons(sock->sk->sk_protocol); |
|
|
error = ccs_network_entry(&address); |
|
|
skip: |
|
785 |
return error; |
return error; |
786 |
} |
} |
787 |
|
|
791 |
{ |
{ |
792 |
struct sockaddr_storage addr; |
struct sockaddr_storage addr; |
793 |
struct task_struct * const task = current; |
struct task_struct * const task = current; |
794 |
int error = 0; |
int error; |
795 |
int addr_len; |
int addr_len; |
796 |
|
const u8 family = ccs_sock_family(sock); |
797 |
struct ccs_addr_info address; |
struct ccs_addr_info address; |
798 |
/* Nothing to do if I am a kernel service. */ |
if (family != 1 || sock->type != SOCK_STREAM) |
|
if (segment_eq(get_fs(), KERNEL_DS)) |
|
799 |
return 0; |
return 0; |
|
switch (newsock->sk->sk_family) { |
|
|
case PF_INET: |
|
|
case PF_INET6: |
|
|
break; |
|
|
default: |
|
|
return 0; |
|
|
} |
|
800 |
error = newsock->ops->getname(newsock, (struct sockaddr *) &addr, |
error = newsock->ops->getname(newsock, (struct sockaddr *) &addr, |
801 |
&addr_len, 2); |
&addr_len, 2); |
802 |
if (error) |
if (error) |
803 |
return error; |
return error; |
804 |
if (!ccs_check_address((struct sockaddr *) &addr, addr_len, |
address.protocol = CCS_NETWORK_INET_TCP_PROTOCOL; |
|
&address)) |
|
|
goto skip; |
|
|
address.protocol = CCS_NETWORK_TCP_PROTOCOL; |
|
805 |
address.operation = CCS_NETWORK_ACCEPT; |
address.operation = CCS_NETWORK_ACCEPT; |
806 |
task->ccs_flags |= CCS_DONT_SLEEP_ON_ENFORCE_ERROR; |
task->ccs_flags |= CCS_DONT_SLEEP_ON_ENFORCE_ERROR; |
807 |
error = ccs_network_entry(&address); |
if (ccs_check_inet_address((struct sockaddr *) &addr, addr_len, |
808 |
|
&address.inet)) |
809 |
|
error = ccs_inet_entry(&address); |
810 |
task->ccs_flags &= ~CCS_DONT_SLEEP_ON_ENFORCE_ERROR; |
task->ccs_flags &= ~CCS_DONT_SLEEP_ON_ENFORCE_ERROR; |
|
skip: |
|
|
return error; |
|
|
} |
|
|
|
|
|
/* Check permission for sending a datagram via a UDP or RAW socket. */ |
|
|
static int __ccs_socket_sendmsg_permission(struct socket *sock, |
|
|
struct msghdr *msg, int size) |
|
|
{ |
|
|
int error = 0; |
|
|
const int type = sock->type; |
|
|
struct ccs_addr_info address; |
|
|
if (!msg->msg_name) |
|
|
return 0; |
|
|
/* Nothing to do if I am a kernel service. */ |
|
|
if (segment_eq(get_fs(), KERNEL_DS)) |
|
|
return 0; |
|
|
switch (type) { |
|
|
case SOCK_DGRAM: |
|
|
address.protocol = CCS_NETWORK_UDP_PROTOCOL; |
|
|
break; |
|
|
case SOCK_RAW: |
|
|
address.protocol = CCS_NETWORK_RAW_PROTOCOL; |
|
|
break; |
|
|
default: |
|
|
return 0; |
|
|
} |
|
|
address.operation = CCS_NETWORK_SEND; |
|
|
if (!ccs_check_address((struct sockaddr *) msg->msg_name, |
|
|
msg->msg_namelen, &address)) |
|
|
goto skip; |
|
|
if (type == SOCK_RAW) |
|
|
address.port = htons(sock->sk->sk_protocol); |
|
|
error = ccs_network_entry(&address); |
|
|
skip: |
|
811 |
return error; |
return error; |
812 |
} |
} |
813 |
|
|
848 |
} ip_address; |
} ip_address; |
849 |
switch (type) { |
switch (type) { |
850 |
case SOCK_DGRAM: |
case SOCK_DGRAM: |
851 |
address.protocol = CCS_NETWORK_UDP_PROTOCOL; |
address.protocol = CCS_NETWORK_INET_UDP_PROTOCOL; |
852 |
break; |
break; |
853 |
case SOCK_RAW: |
case SOCK_RAW: |
854 |
address.protocol = CCS_NETWORK_RAW_PROTOCOL; |
address.protocol = CCS_NETWORK_INET_RAW_PROTOCOL; |
855 |
break; |
break; |
856 |
default: |
default: |
857 |
return 0; |
return 0; |
858 |
} |
} |
859 |
/* Nothing to do if I am a kernel service. */ |
if (ccs_kernel_service()) |
|
if (segment_eq(get_fs(), KERNEL_DS)) |
|
860 |
return 0; |
return 0; |
861 |
switch (sk->sk_family) { |
switch (sk->sk_family) { |
862 |
case PF_INET6: |
case PF_INET6: |
863 |
address.is_ipv6 = true; |
address.inet.is_ipv6 = true; |
864 |
if (type == SOCK_DGRAM && skb->protocol == htons(ETH_P_IP)) |
if (type == SOCK_DGRAM && skb->protocol == htons(ETH_P_IP)) |
865 |
ipv6_addr_set(&ip_address.sin6, 0, 0, htonl(0xffff), |
ipv6_addr_set(&ip_address.sin6, 0, 0, htonl(0xffff), |
866 |
ip_hdr(skb)->saddr); |
ip_hdr(skb)->saddr); |
867 |
else |
else |
868 |
ipv6_addr_copy(&ip_address.sin6, &ipv6_hdr(skb)->saddr); |
ipv6_addr_copy(&ip_address.sin6, |
869 |
|
&ipv6_hdr(skb)->saddr); |
870 |
break; |
break; |
871 |
case PF_INET: |
case PF_INET: |
872 |
address.is_ipv6 = false; |
address.inet.is_ipv6 = false; |
873 |
ip_address.sin4.s_addr = ip_hdr(skb)->saddr; |
ip_address.sin4.s_addr = ip_hdr(skb)->saddr; |
874 |
break; |
break; |
875 |
default: |
default: |
876 |
goto skip; |
goto skip; |
877 |
} |
} |
878 |
address.address = (u32 *) &ip_address; |
address.inet.address = (u32 *) &ip_address; |
879 |
if (type == SOCK_DGRAM) |
if (type == SOCK_DGRAM) |
880 |
address.port = udp_hdr(skb)->source; |
address.inet.port = udp_hdr(skb)->source; |
881 |
else |
else |
882 |
address.port = htons(sk->sk_protocol); |
address.inet.port = htons(sk->sk_protocol); |
883 |
address.operation = CCS_NETWORK_RECV; |
address.operation = CCS_NETWORK_RECV; |
884 |
task->ccs_flags |= CCS_DONT_SLEEP_ON_ENFORCE_ERROR; |
task->ccs_flags |= CCS_DONT_SLEEP_ON_ENFORCE_ERROR; |
885 |
error = ccs_network_entry(&address); |
error = ccs_inet_entry(&address); |
886 |
task->ccs_flags &= ~CCS_DONT_SLEEP_ON_ENFORCE_ERROR; |
task->ccs_flags &= ~CCS_DONT_SLEEP_ON_ENFORCE_ERROR; |
887 |
skip: |
skip: |
888 |
return error; |
return error; |