]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/macro.h
macro: move network macros from utils.h
[mirror_lxc.git] / src / lxc / macro.h
1 /* liblxcapi
2 *
3 * Copyright © 2018 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2018 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef __LXC_MACRO_H
21 #define __LXC_MACRO_H
22
23 /* Define __S_ISTYPE if missing from the C library. */
24 #ifndef __S_ISTYPE
25 #define __S_ISTYPE(mode, mask) (((mode)&S_IFMT) == (mask))
26 #endif
27
28 #if HAVE_LIBCAP
29 #ifndef CAP_SETFCAP
30 #define CAP_SETFCAP 31
31 #endif
32
33 #ifndef CAP_MAC_OVERRIDE
34 #define CAP_MAC_OVERRIDE 32
35 #endif
36
37 #ifndef CAP_MAC_ADMIN
38 #define CAP_MAC_ADMIN 33
39 #endif
40 #endif
41
42 #ifndef PR_CAPBSET_DROP
43 #define PR_CAPBSET_DROP 24
44 #endif
45
46 #ifndef LO_FLAGS_AUTOCLEAR
47 #define LO_FLAGS_AUTOCLEAR 4
48 #endif
49
50 #ifndef CAP_SETUID
51 #define CAP_SETUID 7
52 #endif
53
54 #ifndef CAP_SETGID
55 #define CAP_SETGID 6
56 #endif
57
58 /* needed for cgroup automount checks, regardless of whether we
59 * have included linux/capability.h or not */
60 #ifndef CAP_SYS_ADMIN
61 #define CAP_SYS_ADMIN 21
62 #endif
63
64 #ifndef CGROUP_SUPER_MAGIC
65 #define CGROUP_SUPER_MAGIC 0x27e0eb
66 #endif
67
68 #ifndef CGROUP2_SUPER_MAGIC
69 #define CGROUP2_SUPER_MAGIC 0x63677270
70 #endif
71
72 #ifndef NSFS_MAGIC
73 #define NSFS_MAGIC 0x6e736673
74 #endif
75
76 /* Useful macros */
77 /* Maximum number for 64 bit integer is a string with 21 digits: 2^64 - 1 = 21 */
78 #define LXC_NUMSTRLEN64 21
79 #define LXC_LINELEN 4096
80 #define LXC_IDMAPLEN 4096
81 #define LXC_MAX_BUFFER 4096
82 /* /proc/ = 6
83 * +
84 * <pid-as-str> = LXC_NUMSTRLEN64
85 * +
86 * /fd/ = 4
87 * +
88 * <fd-as-str> = LXC_NUMSTRLEN64
89 * +
90 * \0 = 1
91 */
92 #define LXC_PROC_PID_FD_LEN (6 + LXC_NUMSTRLEN64 + 4 + LXC_NUMSTRLEN64 + 1)
93
94 /* loop devices */
95 #ifndef LO_FLAGS_AUTOCLEAR
96 #define LO_FLAGS_AUTOCLEAR 4
97 #endif
98
99 #ifndef LOOP_CTL_GET_FREE
100 #define LOOP_CTL_GET_FREE 0x4C82
101 #endif
102
103 /* memfd_create() */
104 #ifndef MFD_CLOEXEC
105 #define MFD_CLOEXEC 0x0001U
106 #endif
107
108 #ifndef MFD_ALLOW_SEALING
109 #define MFD_ALLOW_SEALING 0x0002U
110 #endif
111
112 /**
113 * BUILD_BUG_ON - break compile if a condition is true.
114 * @condition: the condition which the compiler should know is false.
115 *
116 * If you have some code which relies on certain constants being equal, or
117 * other compile-time-evaluated condition, you should use BUILD_BUG_ON to
118 * detect if someone changes it.
119 *
120 * The implementation uses gcc's reluctance to create a negative array, but
121 * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments
122 * to inline functions). So as a fallback we use the optimizer; if it can't
123 * prove the condition is false, it will cause a link error on the undefined
124 * "__build_bug_on_failed". This error message can be harder to track down
125 * though, hence the two different methods.
126 */
127 #ifndef __OPTIMIZE__
128 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
129 #else
130 extern int __build_bug_on_failed;
131 #define BUILD_BUG_ON(condition) \
132 do { \
133 ((void)sizeof(char[1 - 2*!!(condition)])); \
134 if (condition) __build_bug_on_failed = 1; \
135 } while(0)
136 #endif
137
138 #define lxc_iterate_parts(__iterator, __splitme, __separators) \
139 for (char *__p = NULL, *__it = strtok_r(__splitme, __separators, &__p); \
140 (__iterator = __it); \
141 __iterator = __it = strtok_r(NULL, __separators, &__p))
142
143 #define prctl_arg(x) ((unsigned long)x)
144
145 /* networking */
146 #ifndef IFLA_LINKMODE
147 #define IFLA_LINKMODE 17
148 #endif
149
150 #ifndef IFLA_LINKINFO
151 #define IFLA_LINKINFO 18
152 #endif
153
154 #ifndef IFLA_NET_NS_PID
155 #define IFLA_NET_NS_PID 19
156 #endif
157
158 #ifndef IFLA_INFO_KIND
159 #define IFLA_INFO_KIND 1
160 #endif
161
162 #ifndef IFLA_VLAN_ID
163 #define IFLA_VLAN_ID 1
164 #endif
165
166 #ifndef IFLA_INFO_DATA
167 #define IFLA_INFO_DATA 2
168 #endif
169
170 #ifndef VETH_INFO_PEER
171 #define VETH_INFO_PEER 1
172 #endif
173
174 #ifndef IFLA_MACVLAN_MODE
175 #define IFLA_MACVLAN_MODE 1
176 #endif
177
178 #ifndef IFLA_NEW_NETNSID
179 #define IFLA_NEW_NETNSID 45
180 #endif
181
182 #ifndef IFLA_IF_NETNSID
183 #define IFLA_IF_NETNSID 46
184 #endif
185
186 #endif /* __LXC_MACRO_H */