]>
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>
25 #include <linux/if_link.h>
26 #include <linux/loop.h>
27 #include <linux/netlink.h>
28 #include <linux/rtnetlink.h>
29 #include <linux/types.h>
32 #include <sys/mount.h>
33 #include <sys/socket.h>
41 /* Define __S_ISTYPE if missing from the C library. */
43 #define __S_ISTYPE(mode, mask) (((mode)&S_IFMT) == (mask))
48 #define CAP_SYS_ADMIN 21
52 #define CAP_SETFCAP 31
55 #ifndef CAP_MAC_OVERRIDE
56 #define CAP_MAC_OVERRIDE 32
60 #define CAP_MAC_ADMIN 33
72 #ifndef PR_CAPBSET_READ
73 #define PR_CAPBSET_READ 23
76 #ifndef PR_CAPBSET_DROP
77 #define PR_CAPBSET_DROP 24
80 /* Control the ambient capability set */
81 #ifndef PR_CAP_AMBIENT
82 #define PR_CAP_AMBIENT 47
85 #ifndef PR_CAP_AMBIENT_IS_SET
86 #define PR_CAP_AMBIENT_IS_SET 1
89 #ifndef PR_CAP_AMBIENT_RAISE
90 #define PR_CAP_AMBIENT_RAISE 2
93 #ifndef PR_CAP_AMBIENT_LOWER
94 #define PR_CAP_AMBIENT_LOWER 3
97 #ifndef PR_CAP_AMBIENT_CLEAR_ALL
98 #define PR_CAP_AMBIENT_CLEAR_ALL 4
101 #ifndef PR_SET_NO_NEW_PRIVS
102 #define PR_SET_NO_NEW_PRIVS 38
105 #ifndef PR_GET_NO_NEW_PRIVS
106 #define PR_GET_NO_NEW_PRIVS 39
109 /* filesystem magic values */
110 #ifndef CGROUP_SUPER_MAGIC
111 #define CGROUP_SUPER_MAGIC 0x27e0eb
114 #ifndef CGROUP2_SUPER_MAGIC
115 #define CGROUP2_SUPER_MAGIC 0x63677270
119 #define NSFS_MAGIC 0x6e736673
122 /* current overlayfs */
123 #ifndef OVERLAY_SUPER_MAGIC
124 #define OVERLAY_SUPER_MAGIC 0x794c7630
127 /* legacy overlayfs */
128 #ifndef OVERLAYFS_SUPER_MAGIC
129 #define OVERLAYFS_SUPER_MAGIC 0x794c764f
132 /* Calculate the number of chars needed to represent a given integer as a C
133 * string. Include room for '-' to indicate negative numbers and the \0 byte.
134 * This is based on systemd.
136 #define INTTYPE_TO_STRLEN(type) \
137 (2 + (sizeof(type) <= 1 \
139 : sizeof(type) <= 2 \
141 : sizeof(type) <= 4 \
143 : sizeof(type) <= 8 \
145 : sizeof(int[-2 * (sizeof(type) > 8)])))
148 #define LXC_LINELEN 4096
149 #define LXC_IDMAPLEN 4096
150 #define LXC_MAX_BUFFER 4096
154 * <pid-as-str> = INTTYPE_TO_STRLEN(pid_t)
158 * <fd-as-str> = INTTYPE_TO_STRLEN(int)
162 #define LXC_PROC_PID_FD_LEN \
163 (6 + INTTYPE_TO_STRLEN(pid_t) + 4 + INTTYPE_TO_STRLEN(int) + 1)
167 * <pid-as-str> = INTTYPE_TO_STRLEN(pid_t)
173 #define LXC_PROC_STATUS_LEN (6 + INTTYPE_TO_STRLEN(pid_t) + 7 + 1)
177 * <pid-as-str> = INTTYPE_TO_STRLEN(pid_t)
185 #define LXC_LSMATTRLEN (6 + INTTYPE_TO_STRLEN(pid_t) + 6 + 8 + 1)
187 #define LXC_CMD_DATA_MAX (PATH_MAX * 2)
190 #ifndef LO_FLAGS_AUTOCLEAR
191 #define LO_FLAGS_AUTOCLEAR 4
194 #ifndef LOOP_CTL_GET_FREE
195 #define LOOP_CTL_GET_FREE 0x4C82
200 #define MFD_CLOEXEC 0x0001U
203 #ifndef MFD_ALLOW_SEALING
204 #define MFD_ALLOW_SEALING 0x0002U
208 * BUILD_BUG_ON - break compile if a condition is true.
209 * @condition: the condition which the compiler should know is false.
211 * If you have some code which relies on certain constants being equal, or
212 * other compile-time-evaluated condition, you should use BUILD_BUG_ON to
213 * detect if someone changes it.
215 * The implementation uses gcc's reluctance to create a negative array, but
216 * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments
217 * to inline functions). So as a fallback we use the optimizer; if it can't
218 * prove the condition is false, it will cause a link error on the undefined
219 * "__build_bug_on_failed". This error message can be harder to track down
220 * though, hence the two different methods.
223 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
225 extern int __build_bug_on_failed
;
226 #define BUILD_BUG_ON(condition) \
228 ((void)sizeof(char[1 - 2 * !!(condition)])); \
230 __build_bug_on_failed = 1; \
234 #define lxc_iterate_parts(__iterator, __splitme, __separators) \
235 for (char *__p = NULL, *__it = strtok_r(__splitme, __separators, &__p); \
236 (__iterator = __it); \
237 __iterator = __it = strtok_r(NULL, __separators, &__p))
239 #define prctl_arg(x) ((unsigned long)x)
242 #ifndef IFLA_LINKMODE
243 #define IFLA_LINKMODE 17
246 #ifndef IFLA_LINKINFO
247 #define IFLA_LINKINFO 18
250 #ifndef IFLA_NET_NS_PID
251 #define IFLA_NET_NS_PID 19
254 #ifndef IFLA_INFO_KIND
255 #define IFLA_INFO_KIND 1
259 #define IFLA_VLAN_ID 1
262 #ifndef IFLA_INFO_DATA
263 #define IFLA_INFO_DATA 2
266 #ifndef VETH_INFO_PEER
267 #define VETH_INFO_PEER 1
270 #ifndef IFLA_MACVLAN_MODE
271 #define IFLA_MACVLAN_MODE 1
274 #ifndef IFLA_NEW_NETNSID
275 #define IFLA_NEW_NETNSID 45
278 #ifdef IFLA_IF_NETNSID
279 #ifndef IFLA_TARGET_NETNSID
280 #define IFLA_TARGET_NETNSID = IFLA_IF_NETNSID
283 #define IFLA_IF_NETNSID 46
284 #define IFLA_TARGET_NETNSID 46
287 #ifndef IFA_TARGET_NETNSID
288 #define IFA_TARGET_NETNSID 10
296 #define IFLA_STATS64 23
300 #define RTM_NEWNSID 88
304 #define RTM_GETNSID 90
308 #define NLMSG_ERROR 0x2
311 #ifndef MACVLAN_MODE_PRIVATE
312 #define MACVLAN_MODE_PRIVATE 1
315 #ifndef MACVLAN_MODE_VEPA
316 #define MACVLAN_MODE_VEPA 2
319 #ifndef MACVLAN_MODE_BRIDGE
320 #define MACVLAN_MODE_BRIDGE 4
323 #ifndef MACVLAN_MODE_PASSTHRU
324 #define MACVLAN_MODE_PASSTHRU 8
327 /* Attributes of RTM_NEWNSID/RTM_GETNSID messages */
330 #define __LXC_NETNSA_NSID_NOT_ASSIGNED -1
337 /* Length of abstract unix domain socket socket address. */
338 #define LXC_AUDS_ADDR_LEN sizeof(((struct sockaddr_un *)0)->sun_path)
342 #define MS_PRIVATE (1<<18)
346 #define MS_SLAVE (1 << 19)
350 #define MS_LAZYTIME (1<<25)
359 #define O_PATH 010000000
363 #define O_NOFOLLOW 00400000
368 #define SOCK_CLOEXEC 02000000
371 /* pointer conversion macros */
372 #define PTR_TO_INT(p) ((int)((intptr_t)(p)))
373 #define INT_TO_PTR(u) ((void *)((intptr_t)(u)))
375 #define PTR_TO_INTMAX(p) ((intmax_t)((intptr_t)(p)))
376 #define INTMAX_TO_PTR(u) ((void *)((intptr_t)(u)))
378 #define LXC_INVALID_UID ((uid_t)-1)
379 #define LXC_INVALID_GID ((gid_t)-1)
381 #define STRLITERALLEN(x) (sizeof(""x"") - 1)
382 #define STRARRAYLEN(x) (sizeof(x) - 1)
384 #endif /* __LXC_MACRO_H */