]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/macro.h
3 * Copyright © 2018 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2018 Canonical Ltd.
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.
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.
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.
23 #include <asm/types.h>
24 #include <linux/if_link.h>
25 #include <linux/loop.h>
26 #include <linux/netlink.h>
27 #include <linux/rtnetlink.h>
28 #include <linux/types.h>
31 #include <sys/mount.h>
32 #include <sys/socket.h>
36 /* Define __S_ISTYPE if missing from the C library. */
38 #define __S_ISTYPE(mode, mask) (((mode)&S_IFMT) == (mask))
43 #define CAP_SYS_ADMIN 21
47 #define CAP_SETFCAP 31
50 #ifndef CAP_MAC_OVERRIDE
51 #define CAP_MAC_OVERRIDE 32
55 #define CAP_MAC_ADMIN 33
67 #ifndef PR_CAPBSET_READ
68 #define PR_CAPBSET_READ 23
71 #ifndef PR_CAPBSET_DROP
72 #define PR_CAPBSET_DROP 24
75 /* Control the ambient capability set */
76 #ifndef PR_CAP_AMBIENT
77 #define PR_CAP_AMBIENT 47
80 #ifndef PR_CAP_AMBIENT_IS_SET
81 #define PR_CAP_AMBIENT_IS_SET 1
84 #ifndef PR_CAP_AMBIENT_RAISE
85 #define PR_CAP_AMBIENT_RAISE 2
88 #ifndef PR_CAP_AMBIENT_LOWER
89 #define PR_CAP_AMBIENT_LOWER 3
92 #ifndef PR_CAP_AMBIENT_CLEAR_ALL
93 #define PR_CAP_AMBIENT_CLEAR_ALL 4
96 #ifndef PR_SET_NO_NEW_PRIVS
97 #define PR_SET_NO_NEW_PRIVS 38
100 #ifndef PR_GET_NO_NEW_PRIVS
101 #define PR_GET_NO_NEW_PRIVS 39
104 /* filesystem magic values */
105 #ifndef CGROUP_SUPER_MAGIC
106 #define CGROUP_SUPER_MAGIC 0x27e0eb
109 #ifndef CGROUP2_SUPER_MAGIC
110 #define CGROUP2_SUPER_MAGIC 0x63677270
114 #define NSFS_MAGIC 0x6e736673
117 /* current overlayfs */
118 #ifndef OVERLAY_SUPER_MAGIC
119 #define OVERLAY_SUPER_MAGIC 0x794c7630
122 /* legacy overlayfs */
123 #ifndef OVERLAYFS_SUPER_MAGIC
124 #define OVERLAYFS_SUPER_MAGIC 0x794c764f
127 /* Calculate the number of chars needed to represent a given integer as a C
128 * string. Include room for '-' to indicate negative numbers and the \0 byte.
129 * This is based on systemd.
131 #define INTTYPE_TO_STRLEN(type) \
132 (2 + (sizeof(type) <= 1 \
134 : sizeof(type) <= 2 \
136 : sizeof(type) <= 4 \
138 : sizeof(type) <= 8 \
140 : sizeof(int[-2 * (sizeof(type) > 8)])))
143 #define LXC_LINELEN 4096
144 #define LXC_IDMAPLEN 4096
145 #define LXC_MAX_BUFFER 4096
149 * <pid-as-str> = INTTYPE_TO_STRLEN(pid_t)
153 * <fd-as-str> = INTTYPE_TO_STRLEN(int)
157 #define LXC_PROC_PID_FD_LEN \
158 (6 + INTTYPE_TO_STRLEN(pid_t) + 4 + INTTYPE_TO_STRLEN(int) + 1)
162 * <pid-as-str> = INTTYPE_TO_STRLEN(pid_t)
168 #define LXC_PROC_STATUS_LEN (6 + INTTYPE_TO_STRLEN(pid_t) + 7 + 1)
172 * <pid-as-str> = INTTYPE_TO_STRLEN(pid_t)
180 #define LXC_LSMATTRLEN (6 + INTTYPE_TO_STRLEN(pid_t) + 6 + 8 + 1)
182 #define LXC_CMD_DATA_MAX (MAXPATHLEN * 2)
185 #ifndef LO_FLAGS_AUTOCLEAR
186 #define LO_FLAGS_AUTOCLEAR 4
189 #ifndef LOOP_CTL_GET_FREE
190 #define LOOP_CTL_GET_FREE 0x4C82
195 #define MFD_CLOEXEC 0x0001U
198 #ifndef MFD_ALLOW_SEALING
199 #define MFD_ALLOW_SEALING 0x0002U
203 * BUILD_BUG_ON - break compile if a condition is true.
204 * @condition: the condition which the compiler should know is false.
206 * If you have some code which relies on certain constants being equal, or
207 * other compile-time-evaluated condition, you should use BUILD_BUG_ON to
208 * detect if someone changes it.
210 * The implementation uses gcc's reluctance to create a negative array, but
211 * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments
212 * to inline functions). So as a fallback we use the optimizer; if it can't
213 * prove the condition is false, it will cause a link error on the undefined
214 * "__build_bug_on_failed". This error message can be harder to track down
215 * though, hence the two different methods.
218 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
220 extern int __build_bug_on_failed
;
221 #define BUILD_BUG_ON(condition) \
223 ((void)sizeof(char[1 - 2 * !!(condition)])); \
225 __build_bug_on_failed = 1; \
229 #define lxc_iterate_parts(__iterator, __splitme, __separators) \
230 for (char *__p = NULL, *__it = strtok_r(__splitme, __separators, &__p); \
231 (__iterator = __it); \
232 __iterator = __it = strtok_r(NULL, __separators, &__p))
234 #define prctl_arg(x) ((unsigned long)x)
237 #ifndef IFLA_LINKMODE
238 #define IFLA_LINKMODE 17
241 #ifndef IFLA_LINKINFO
242 #define IFLA_LINKINFO 18
245 #ifndef IFLA_NET_NS_PID
246 #define IFLA_NET_NS_PID 19
249 #ifndef IFLA_INFO_KIND
250 #define IFLA_INFO_KIND 1
254 #define IFLA_VLAN_ID 1
257 #ifndef IFLA_INFO_DATA
258 #define IFLA_INFO_DATA 2
261 #ifndef VETH_INFO_PEER
262 #define VETH_INFO_PEER 1
265 #ifndef IFLA_MACVLAN_MODE
266 #define IFLA_MACVLAN_MODE 1
269 #ifndef IFLA_NEW_NETNSID
270 #define IFLA_NEW_NETNSID 45
273 #ifdef IFLA_IF_NETNSID
274 #ifndef IFLA_TARGET_NETNSID
275 #define IFLA_TARGET_NETNSID = IFLA_IF_NETNSID
278 #define IFLA_IF_NETNSID 46
279 #define IFLA_TARGET_NETNSID 46
282 #ifndef IFA_TARGET_NETNSID
283 #define IFA_TARGET_NETNSID 10
291 #define IFLA_STATS64 23
295 #define RTM_NEWNSID 88
299 #define RTM_GETNSID 90
303 #define NLMSG_ERROR 0x2
306 #ifndef MACVLAN_MODE_PRIVATE
307 #define MACVLAN_MODE_PRIVATE 1
310 #ifndef MACVLAN_MODE_VEPA
311 #define MACVLAN_MODE_VEPA 2
314 #ifndef MACVLAN_MODE_BRIDGE
315 #define MACVLAN_MODE_BRIDGE 4
318 #ifndef MACVLAN_MODE_PASSTHRU
319 #define MACVLAN_MODE_PASSTHRU 8
322 /* Attributes of RTM_NEWNSID/RTM_GETNSID messages */
325 #define __LXC_NETNSA_NSID_NOT_ASSIGNED -1
332 /* Length of abstract unix domain socket socket address. */
333 #define LXC_AUDS_ADDR_LEN sizeof(((struct sockaddr_un *)0)->sun_path)
337 #define MS_PRIVATE (1<<18)
341 #define MS_SLAVE (1 << 19)
345 #define MS_LAZYTIME (1<<25)
354 #define O_PATH 010000000
358 #define O_NOFOLLOW 00400000
363 #define SOCK_CLOEXEC 02000000
366 /* pointer conversion macros */
367 #define PTR_TO_INT(p) ((int)((intptr_t)(p)))
368 #define INT_TO_PTR(u) ((void *)((intptr_t)(u)))
370 #define PTR_TO_INTMAX(p) ((intmax_t)((intptr_t)(p)))
371 #define INTMAX_TO_PTR(u) ((void *)((intptr_t)(u)))
373 #define LXC_INVALID_UID ((uid_t)-1)
374 #define LXC_INVALID_GID ((gid_t)-1)
376 #define STRLITERALLEN(x) (sizeof(""x"") - 1)
377 #define STRARRAYLEN(x) (sizeof(x) - 1)
379 #endif /* __LXC_MACRO_H */