Branch data Line data Source code
1 : : #ifndef __CR_UTIL_NET_H__
2 : : #define __CR_UTIL_NET_H__
3 : :
4 : : #include <sys/socket.h>
5 : : #include <sys/un.h>
6 : :
7 : : #include "asm/types.h"
8 : :
9 : : #define UNIX_PATH_MAX (sizeof(struct sockaddr_un) - \
10 : : (size_t)((struct sockaddr_un *) 0)->sun_path)
11 : :
12 : : #ifndef SO_PEEK_OFF
13 : : #define SO_PEEK_OFF 42
14 : : #endif
15 : :
16 : : /*
17 : : * Because of kernel doing kmalloc for user data passed
18 : : * in SCM messages, and there is kernel's SCM_MAX_FD as a limit
19 : : * for descriptors passed at once we're trying to reduce
20 : : * the pressue on kernel memory manager and use predefined
21 : : * known to work well size of the message buffer.
22 : : */
23 : : #define CR_SCM_MSG_SIZE (1024)
24 : : #define CR_SCM_MAX_FD (252)
25 : :
26 : : struct fd_opts {
27 : : char flags;
28 : : struct {
29 : : u32 uid;
30 : : u32 euid;
31 : : u32 signum;
32 : : u32 pid_type;
33 : : u32 pid;
34 : : } fown;
35 : : };
36 : :
37 : : struct scm_fdset {
38 : : struct msghdr hdr;
39 : : struct iovec iov;
40 : : char msg_buf[CR_SCM_MSG_SIZE];
41 : : struct fd_opts opts[CR_SCM_MAX_FD];
42 : : };
43 : :
44 : : extern int send_fds(int sock, struct sockaddr_un *saddr, int saddr_len,
45 : : int *fds, int nr_fds, bool with_flags);
46 : : extern int recv_fds(int sock, int *fds, int nr_fds, struct fd_opts *opts);
47 : :
48 : : static inline int send_fd(int sock, struct sockaddr_un *saddr, int saddr_len, int fd)
49 : : {
50 : 9107 : return send_fds(sock, saddr, saddr_len, &fd, 1, false);
51 : : }
52 : :
53 : 737 : static inline int recv_fd(int sock)
54 : : {
55 : : int fd, ret;
56 : :
57 : 737 : ret = recv_fds(sock, &fd, 1, NULL);
58 [ + - ]: 737 : if (ret)
59 : : return -1;
60 : :
61 : 737 : return fd;
62 : : }
63 : :
64 : : extern int open_detach_mount(char *dir);
65 : :
66 : : #endif /* __CR_UTIL_NET_H__ */
|