security/tomoyo/network.c
Source file repositories/reference/linux-study-clean/security/tomoyo/network.c
File Facts
- System
- Linux kernel
- Corpus path
security/tomoyo/network.c- Extension
.c- Size
- 22111 bytes
- Lines
- 781
- Domain
- Core OS
- Bucket
- Security And Isolation
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
common.hlinux/slab.h
Detected Declarations
struct tomoyo_inet_addr_infostruct tomoyo_unix_addr_infostruct tomoyo_addr_infofunction tomoyo_parse_ipaddr_unionfunction tomoyo_print_ipv4function tomoyo_print_ipv6function tomoyo_print_ipfunction tomoyo_same_inet_aclfunction tomoyo_same_unix_aclfunction tomoyo_merge_inet_aclfunction tomoyo_merge_unix_aclfunction tomoyo_read_lockfunction tomoyo_write_unix_networkfunction tomoyo_audit_net_logfunction tomoyo_audit_inet_logfunction tomoyo_audit_unix_logfunction tomoyo_check_inet_aclfunction tomoyo_check_unix_aclfunction tomoyo_inet_entryfunction tomoyo_check_inet_addressfunction tomoyo_unix_entryfunction tomoyo_check_unix_addressfunction tomoyo_kernel_servicefunction tomoyo_sock_familyfunction tomoyo_socket_listen_permissionfunction tomoyo_socket_connect_permissionfunction tomoyo_socket_bind_permissionfunction tomoyo_socket_sendmsg_permission
Annotated Snippet
struct tomoyo_inet_addr_info {
__be16 port; /* In network byte order. */
const __be32 *address; /* In network byte order. */
bool is_ipv6;
};
/* Structure for holding unix domain socket's address. */
struct tomoyo_unix_addr_info {
u8 *addr; /* This may not be '\0' terminated string. */
unsigned int addr_len;
};
/* Structure for holding socket address. */
struct tomoyo_addr_info {
u8 protocol;
u8 operation;
struct tomoyo_inet_addr_info inet;
struct tomoyo_unix_addr_info unix0;
};
/* String table for socket's protocols. */
const char * const tomoyo_proto_keyword[TOMOYO_SOCK_MAX] = {
[SOCK_STREAM] = "stream",
[SOCK_DGRAM] = "dgram",
[SOCK_RAW] = "raw",
[SOCK_SEQPACKET] = "seqpacket",
[0] = " ", /* Dummy for avoiding NULL pointer dereference. */
[4] = " ", /* Dummy for avoiding NULL pointer dereference. */
};
/**
* tomoyo_parse_ipaddr_union - Parse an IP address.
*
* @param: Pointer to "struct tomoyo_acl_param".
* @ptr: Pointer to "struct tomoyo_ipaddr_union".
*
* Returns true on success, false otherwise.
*/
bool tomoyo_parse_ipaddr_union(struct tomoyo_acl_param *param,
struct tomoyo_ipaddr_union *ptr)
{
u8 * const min = ptr->ip[0].in6_u.u6_addr8;
u8 * const max = ptr->ip[1].in6_u.u6_addr8;
char *address = tomoyo_read_token(param);
const char *end;
if (!strchr(address, ':') &&
in4_pton(address, -1, min, '-', &end) > 0) {
ptr->is_ipv6 = false;
if (!*end)
ptr->ip[1].s6_addr32[0] = ptr->ip[0].s6_addr32[0];
else if (*end++ != '-' ||
in4_pton(end, -1, max, '\0', &end) <= 0 || *end)
return false;
return true;
}
if (in6_pton(address, -1, min, '-', &end) > 0) {
ptr->is_ipv6 = true;
if (!*end)
memmove(max, min, sizeof(u16) * 8);
else if (*end++ != '-' ||
in6_pton(end, -1, max, '\0', &end) <= 0 || *end)
return false;
return true;
}
return false;
}
/**
* tomoyo_print_ipv4 - Print an IPv4 address.
*
* @buffer: Buffer to write to.
* @buffer_len: Size of @buffer.
* @min_ip: Pointer to __be32.
* @max_ip: Pointer to __be32.
*
* Returns nothing.
*/
static void tomoyo_print_ipv4(char *buffer, const unsigned int buffer_len,
const __be32 *min_ip, const __be32 *max_ip)
{
snprintf(buffer, buffer_len, "%pI4%c%pI4", min_ip,
*min_ip == *max_ip ? '\0' : '-', max_ip);
}
/**
* tomoyo_print_ipv6 - Print an IPv6 address.
*
* @buffer: Buffer to write to.
* @buffer_len: Size of @buffer.
Annotation
- Immediate include surface: `common.h`, `linux/slab.h`.
- Detected declarations: `struct tomoyo_inet_addr_info`, `struct tomoyo_unix_addr_info`, `struct tomoyo_addr_info`, `function tomoyo_parse_ipaddr_union`, `function tomoyo_print_ipv4`, `function tomoyo_print_ipv6`, `function tomoyo_print_ip`, `function tomoyo_same_inet_acl`, `function tomoyo_same_unix_acl`, `function tomoyo_merge_inet_acl`.
- Atlas domain: Core OS / Security And Isolation.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.