]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing.h
Merge pull request #2495 from heftig/master
[thirdparty/systemd.git] / src / basic / missing.h
1 #pragma once
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 /* Missing glibc definitions to access certain kernel APIs */
23
24 #include <errno.h>
25 #include <fcntl.h>
26 #include <linux/audit.h>
27 #include <linux/capability.h>
28 #include <linux/if_link.h>
29 #include <linux/input.h>
30 #include <linux/loop.h>
31 #include <linux/neighbour.h>
32 #include <linux/oom.h>
33 #include <linux/rtnetlink.h>
34 #include <stdlib.h>
35 #include <sys/resource.h>
36 #include <sys/syscall.h>
37 #include <uchar.h>
38 #include <unistd.h>
39
40 #ifdef HAVE_AUDIT
41 #include <libaudit.h>
42 #endif
43
44 #ifdef ARCH_MIPS
45 #include <asm/sgidefs.h>
46 #endif
47
48 #ifdef HAVE_LINUX_BTRFS_H
49 #include <linux/btrfs.h>
50 #endif
51
52 #include "macro.h"
53
54 #ifndef RLIMIT_RTTIME
55 #define RLIMIT_RTTIME 15
56 #endif
57
58 /* If RLIMIT_RTTIME is not defined, then we cannot use RLIMIT_NLIMITS as is */
59 #define _RLIMIT_MAX (RLIMIT_RTTIME+1 > RLIMIT_NLIMITS ? RLIMIT_RTTIME+1 : RLIMIT_NLIMITS)
60
61 #ifndef F_LINUX_SPECIFIC_BASE
62 #define F_LINUX_SPECIFIC_BASE 1024
63 #endif
64
65 #ifndef F_SETPIPE_SZ
66 #define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
67 #endif
68
69 #ifndef F_GETPIPE_SZ
70 #define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)
71 #endif
72
73 #ifndef F_ADD_SEALS
74 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
75 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
76
77 #define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
78 #define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
79 #define F_SEAL_GROW 0x0004 /* prevent file from growing */
80 #define F_SEAL_WRITE 0x0008 /* prevent writes */
81 #endif
82
83 #ifndef F_OFD_GETLK
84 #define F_OFD_GETLK 36
85 #define F_OFD_SETLK 37
86 #define F_OFD_SETLKW 38
87 #endif
88
89 #ifndef MFD_ALLOW_SEALING
90 #define MFD_ALLOW_SEALING 0x0002U
91 #endif
92
93 #ifndef MFD_CLOEXEC
94 #define MFD_CLOEXEC 0x0001U
95 #endif
96
97 #ifndef IP_FREEBIND
98 #define IP_FREEBIND 15
99 #endif
100
101 #ifndef OOM_SCORE_ADJ_MIN
102 #define OOM_SCORE_ADJ_MIN (-1000)
103 #endif
104
105 #ifndef OOM_SCORE_ADJ_MAX
106 #define OOM_SCORE_ADJ_MAX 1000
107 #endif
108
109 #ifndef AUDIT_SERVICE_START
110 #define AUDIT_SERVICE_START 1130 /* Service (daemon) start */
111 #endif
112
113 #ifndef AUDIT_SERVICE_STOP
114 #define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */
115 #endif
116
117 #ifndef TIOCVHANGUP
118 #define TIOCVHANGUP 0x5437
119 #endif
120
121 #ifndef IP_TRANSPARENT
122 #define IP_TRANSPARENT 19
123 #endif
124
125 #ifndef SOL_NETLINK
126 #define SOL_NETLINK 270
127 #endif
128
129 #ifndef NETLINK_LIST_MEMBERSHIPS
130 #define NETLINK_LIST_MEMBERSHIPS 9
131 #endif
132
133 #ifndef SOL_SCTP
134 #define SOL_SCTP 132
135 #endif
136
137 #if !HAVE_DECL_PIVOT_ROOT
138 static inline int pivot_root(const char *new_root, const char *put_old) {
139 return syscall(SYS_pivot_root, new_root, put_old);
140 }
141 #endif
142
143 #ifndef __NR_memfd_create
144 # if defined __x86_64__
145 # define __NR_memfd_create 319
146 # elif defined __arm__
147 # define __NR_memfd_create 385
148 # elif defined __aarch64__
149 # define __NR_memfd_create 279
150 # elif defined __s390__
151 # define __NR_memfd_create 350
152 # elif defined _MIPS_SIM
153 # if _MIPS_SIM == _MIPS_SIM_ABI32
154 # define __NR_memfd_create 4354
155 # endif
156 # if _MIPS_SIM == _MIPS_SIM_NABI32
157 # define __NR_memfd_create 6318
158 # endif
159 # if _MIPS_SIM == _MIPS_SIM_ABI64
160 # define __NR_memfd_create 5314
161 # endif
162 # elif defined __i386__
163 # define __NR_memfd_create 356
164 # else
165 # warning "__NR_memfd_create unknown for your architecture"
166 # define __NR_memfd_create 0xffffffff
167 # endif
168 #endif
169
170 #ifndef HAVE_MEMFD_CREATE
171 static inline int memfd_create(const char *name, unsigned int flags) {
172 return syscall(__NR_memfd_create, name, flags);
173 }
174 #endif
175
176 #ifndef __NR_getrandom
177 # if defined __x86_64__
178 # define __NR_getrandom 318
179 # elif defined(__i386__)
180 # define __NR_getrandom 355
181 # elif defined(__arm__)
182 # define __NR_getrandom 384
183 # elif defined(__aarch64__)
184 # define __NR_getrandom 278
185 # elif defined(__ia64__)
186 # define __NR_getrandom 1339
187 # elif defined(__m68k__)
188 # define __NR_getrandom 352
189 # elif defined(__s390x__)
190 # define __NR_getrandom 349
191 # elif defined(__powerpc__)
192 # define __NR_getrandom 359
193 # elif defined _MIPS_SIM
194 # if _MIPS_SIM == _MIPS_SIM_ABI32
195 # define __NR_getrandom 4353
196 # endif
197 # if _MIPS_SIM == _MIPS_SIM_NABI32
198 # define __NR_getrandom 6317
199 # endif
200 # if _MIPS_SIM == _MIPS_SIM_ABI64
201 # define __NR_getrandom 5313
202 # endif
203 # else
204 # warning "__NR_getrandom unknown for your architecture"
205 # define __NR_getrandom 0xffffffff
206 # endif
207 #endif
208
209 #if !HAVE_DECL_GETRANDOM
210 static inline int getrandom(void *buffer, size_t count, unsigned flags) {
211 return syscall(__NR_getrandom, buffer, count, flags);
212 }
213 #endif
214
215 #ifndef GRND_NONBLOCK
216 #define GRND_NONBLOCK 0x0001
217 #endif
218
219 #ifndef GRND_RANDOM
220 #define GRND_RANDOM 0x0002
221 #endif
222
223 #ifndef BTRFS_IOCTL_MAGIC
224 #define BTRFS_IOCTL_MAGIC 0x94
225 #endif
226
227 #ifndef BTRFS_PATH_NAME_MAX
228 #define BTRFS_PATH_NAME_MAX 4087
229 #endif
230
231 #ifndef BTRFS_DEVICE_PATH_NAME_MAX
232 #define BTRFS_DEVICE_PATH_NAME_MAX 1024
233 #endif
234
235 #ifndef BTRFS_FSID_SIZE
236 #define BTRFS_FSID_SIZE 16
237 #endif
238
239 #ifndef BTRFS_UUID_SIZE
240 #define BTRFS_UUID_SIZE 16
241 #endif
242
243 #ifndef BTRFS_SUBVOL_RDONLY
244 #define BTRFS_SUBVOL_RDONLY (1ULL << 1)
245 #endif
246
247 #ifndef BTRFS_SUBVOL_NAME_MAX
248 #define BTRFS_SUBVOL_NAME_MAX 4039
249 #endif
250
251 #ifndef BTRFS_INO_LOOKUP_PATH_MAX
252 #define BTRFS_INO_LOOKUP_PATH_MAX 4080
253 #endif
254
255 #ifndef BTRFS_SEARCH_ARGS_BUFSIZE
256 #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
257 #endif
258
259 #ifndef BTRFS_QGROUP_LEVEL_SHIFT
260 #define BTRFS_QGROUP_LEVEL_SHIFT 48
261 #endif
262
263 #ifndef HAVE_LINUX_BTRFS_H
264 struct btrfs_ioctl_vol_args {
265 int64_t fd;
266 char name[BTRFS_PATH_NAME_MAX + 1];
267 };
268
269 struct btrfs_qgroup_limit {
270 __u64 flags;
271 __u64 max_rfer;
272 __u64 max_excl;
273 __u64 rsv_rfer;
274 __u64 rsv_excl;
275 };
276
277 struct btrfs_qgroup_inherit {
278 __u64 flags;
279 __u64 num_qgroups;
280 __u64 num_ref_copies;
281 __u64 num_excl_copies;
282 struct btrfs_qgroup_limit lim;
283 __u64 qgroups[0];
284 };
285
286 struct btrfs_ioctl_qgroup_limit_args {
287 __u64 qgroupid;
288 struct btrfs_qgroup_limit lim;
289 };
290
291 struct btrfs_ioctl_vol_args_v2 {
292 __s64 fd;
293 __u64 transid;
294 __u64 flags;
295 union {
296 struct {
297 __u64 size;
298 struct btrfs_qgroup_inherit *qgroup_inherit;
299 };
300 __u64 unused[4];
301 };
302 char name[BTRFS_SUBVOL_NAME_MAX + 1];
303 };
304
305 struct btrfs_ioctl_dev_info_args {
306 uint64_t devid; /* in/out */
307 uint8_t uuid[BTRFS_UUID_SIZE]; /* in/out */
308 uint64_t bytes_used; /* out */
309 uint64_t total_bytes; /* out */
310 uint64_t unused[379]; /* pad to 4k */
311 char path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */
312 };
313
314 struct btrfs_ioctl_fs_info_args {
315 uint64_t max_id; /* out */
316 uint64_t num_devices; /* out */
317 uint8_t fsid[BTRFS_FSID_SIZE]; /* out */
318 uint64_t reserved[124]; /* pad to 1k */
319 };
320
321 struct btrfs_ioctl_ino_lookup_args {
322 __u64 treeid;
323 __u64 objectid;
324 char name[BTRFS_INO_LOOKUP_PATH_MAX];
325 };
326
327 struct btrfs_ioctl_search_key {
328 /* which root are we searching. 0 is the tree of tree roots */
329 __u64 tree_id;
330
331 /* keys returned will be >= min and <= max */
332 __u64 min_objectid;
333 __u64 max_objectid;
334
335 /* keys returned will be >= min and <= max */
336 __u64 min_offset;
337 __u64 max_offset;
338
339 /* max and min transids to search for */
340 __u64 min_transid;
341 __u64 max_transid;
342
343 /* keys returned will be >= min and <= max */
344 __u32 min_type;
345 __u32 max_type;
346
347 /*
348 * how many items did userland ask for, and how many are we
349 * returning
350 */
351 __u32 nr_items;
352
353 /* align to 64 bits */
354 __u32 unused;
355
356 /* some extra for later */
357 __u64 unused1;
358 __u64 unused2;
359 __u64 unused3;
360 __u64 unused4;
361 };
362
363 struct btrfs_ioctl_search_header {
364 __u64 transid;
365 __u64 objectid;
366 __u64 offset;
367 __u32 type;
368 __u32 len;
369 };
370
371
372 struct btrfs_ioctl_search_args {
373 struct btrfs_ioctl_search_key key;
374 char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
375 };
376
377 struct btrfs_ioctl_clone_range_args {
378 __s64 src_fd;
379 __u64 src_offset, src_length;
380 __u64 dest_offset;
381 };
382
383 #define BTRFS_QUOTA_CTL_ENABLE 1
384 #define BTRFS_QUOTA_CTL_DISABLE 2
385 #define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
386 struct btrfs_ioctl_quota_ctl_args {
387 __u64 cmd;
388 __u64 status;
389 };
390 #endif
391
392 #ifndef BTRFS_IOC_DEFRAG
393 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
394 struct btrfs_ioctl_vol_args)
395 #endif
396
397 #ifndef BTRFS_IOC_RESIZE
398 #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
399 struct btrfs_ioctl_vol_args)
400 #endif
401
402 #ifndef BTRFS_IOC_CLONE
403 #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
404 #endif
405
406 #ifndef BTRFS_IOC_CLONE_RANGE
407 #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
408 struct btrfs_ioctl_clone_range_args)
409 #endif
410
411 #ifndef BTRFS_IOC_SUBVOL_CREATE
412 #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
413 struct btrfs_ioctl_vol_args)
414 #endif
415
416 #ifndef BTRFS_IOC_SNAP_DESTROY
417 #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
418 struct btrfs_ioctl_vol_args)
419 #endif
420
421 #ifndef BTRFS_IOC_TREE_SEARCH
422 #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
423 struct btrfs_ioctl_search_args)
424 #endif
425
426 #ifndef BTRFS_IOC_INO_LOOKUP
427 #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
428 struct btrfs_ioctl_ino_lookup_args)
429 #endif
430
431 #ifndef BTRFS_IOC_SNAP_CREATE_V2
432 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
433 struct btrfs_ioctl_vol_args_v2)
434 #endif
435
436 #ifndef BTRFS_IOC_SUBVOL_GETFLAGS
437 #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
438 #endif
439
440 #ifndef BTRFS_IOC_SUBVOL_SETFLAGS
441 #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
442 #endif
443
444 #ifndef BTRFS_IOC_DEV_INFO
445 #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
446 struct btrfs_ioctl_dev_info_args)
447 #endif
448
449 #ifndef BTRFS_IOC_FS_INFO
450 #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
451 struct btrfs_ioctl_fs_info_args)
452 #endif
453
454 #ifndef BTRFS_IOC_DEVICES_READY
455 #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
456 struct btrfs_ioctl_vol_args)
457 #endif
458
459 #ifndef BTRFS_IOC_QUOTA_CTL
460 #define BTRFS_IOC_QUOTA_CTL _IOWR(BTRFS_IOCTL_MAGIC, 40, \
461 struct btrfs_ioctl_quota_ctl_args)
462 #endif
463
464 #ifndef BTRFS_IOC_QGROUP_LIMIT
465 #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \
466 struct btrfs_ioctl_qgroup_limit_args)
467 #endif
468
469 #ifndef BTRFS_FIRST_FREE_OBJECTID
470 #define BTRFS_FIRST_FREE_OBJECTID 256
471 #endif
472
473 #ifndef BTRFS_LAST_FREE_OBJECTID
474 #define BTRFS_LAST_FREE_OBJECTID -256ULL
475 #endif
476
477 #ifndef BTRFS_ROOT_TREE_OBJECTID
478 #define BTRFS_ROOT_TREE_OBJECTID 1
479 #endif
480
481 #ifndef BTRFS_QUOTA_TREE_OBJECTID
482 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
483 #endif
484
485 #ifndef BTRFS_ROOT_ITEM_KEY
486 #define BTRFS_ROOT_ITEM_KEY 132
487 #endif
488
489 #ifndef BTRFS_QGROUP_STATUS_KEY
490 #define BTRFS_QGROUP_STATUS_KEY 240
491 #endif
492
493 #ifndef BTRFS_QGROUP_INFO_KEY
494 #define BTRFS_QGROUP_INFO_KEY 242
495 #endif
496
497 #ifndef BTRFS_QGROUP_LIMIT_KEY
498 #define BTRFS_QGROUP_LIMIT_KEY 244
499 #endif
500
501 #ifndef BTRFS_QGROUP_RELATION_KEY
502 #define BTRFS_QGROUP_RELATION_KEY 246
503 #endif
504
505 #ifndef BTRFS_ROOT_BACKREF_KEY
506 #define BTRFS_ROOT_BACKREF_KEY 144
507 #endif
508
509 #ifndef BTRFS_SUPER_MAGIC
510 #define BTRFS_SUPER_MAGIC 0x9123683E
511 #endif
512
513 #ifndef CGROUP_SUPER_MAGIC
514 #define CGROUP_SUPER_MAGIC 0x27e0eb
515 #endif
516
517 #ifndef TMPFS_MAGIC
518 #define TMPFS_MAGIC 0x01021994
519 #endif
520
521 #ifndef MS_MOVE
522 #define MS_MOVE 8192
523 #endif
524
525 #ifndef MS_PRIVATE
526 #define MS_PRIVATE (1 << 18)
527 #endif
528
529 #if !HAVE_DECL_GETTID
530 static inline pid_t gettid(void) {
531 return (pid_t) syscall(SYS_gettid);
532 }
533 #endif
534
535 #ifndef SCM_SECURITY
536 #define SCM_SECURITY 0x03
537 #endif
538
539 #ifndef MS_STRICTATIME
540 #define MS_STRICTATIME (1<<24)
541 #endif
542
543 #ifndef MS_REC
544 #define MS_REC 16384
545 #endif
546
547 #ifndef MS_SHARED
548 #define MS_SHARED (1<<20)
549 #endif
550
551 #ifndef PR_SET_NO_NEW_PRIVS
552 #define PR_SET_NO_NEW_PRIVS 38
553 #endif
554
555 #ifndef PR_SET_CHILD_SUBREAPER
556 #define PR_SET_CHILD_SUBREAPER 36
557 #endif
558
559 #ifndef MAX_HANDLE_SZ
560 #define MAX_HANDLE_SZ 128
561 #endif
562
563 #ifndef __NR_name_to_handle_at
564 # if defined(__x86_64__)
565 # define __NR_name_to_handle_at 303
566 # elif defined(__i386__)
567 # define __NR_name_to_handle_at 341
568 # elif defined(__arm__)
569 # define __NR_name_to_handle_at 370
570 # elif defined(__powerpc__)
571 # define __NR_name_to_handle_at 345
572 # else
573 # error "__NR_name_to_handle_at is not defined"
574 # endif
575 #endif
576
577 #if !HAVE_DECL_NAME_TO_HANDLE_AT
578 struct file_handle {
579 unsigned int handle_bytes;
580 int handle_type;
581 unsigned char f_handle[0];
582 };
583
584 static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
585 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
586 }
587 #endif
588
589 #ifndef HAVE_SECURE_GETENV
590 # ifdef HAVE___SECURE_GETENV
591 # define secure_getenv __secure_getenv
592 # else
593 # error "neither secure_getenv nor __secure_getenv are available"
594 # endif
595 #endif
596
597 #ifndef CIFS_MAGIC_NUMBER
598 # define CIFS_MAGIC_NUMBER 0xFF534D42
599 #endif
600
601 #ifndef TFD_TIMER_CANCEL_ON_SET
602 # define TFD_TIMER_CANCEL_ON_SET (1 << 1)
603 #endif
604
605 #ifndef SO_REUSEPORT
606 # define SO_REUSEPORT 15
607 #endif
608
609 #ifndef EVIOCREVOKE
610 # define EVIOCREVOKE _IOW('E', 0x91, int)
611 #endif
612
613 #ifndef DRM_IOCTL_SET_MASTER
614 # define DRM_IOCTL_SET_MASTER _IO('d', 0x1e)
615 #endif
616
617 #ifndef DRM_IOCTL_DROP_MASTER
618 # define DRM_IOCTL_DROP_MASTER _IO('d', 0x1f)
619 #endif
620
621 #if defined(__i386__) || defined(__x86_64__)
622
623 /* The precise definition of __O_TMPFILE is arch specific, so let's
624 * just define this on x86 where we know the value. */
625
626 #ifndef __O_TMPFILE
627 #define __O_TMPFILE 020000000
628 #endif
629
630 /* a horrid kludge trying to make sure that this will fail on old kernels */
631 #ifndef O_TMPFILE
632 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
633 #endif
634
635 #endif
636
637 #ifndef __NR_setns
638 # if defined(__x86_64__)
639 # define __NR_setns 308
640 # elif defined(__i386__)
641 # define __NR_setns 346
642 # else
643 # error "__NR_setns is not defined"
644 # endif
645 #endif
646
647 #if !HAVE_DECL_SETNS
648 static inline int setns(int fd, int nstype) {
649 return syscall(__NR_setns, fd, nstype);
650 }
651 #endif
652
653 #if !HAVE_DECL_LO_FLAGS_PARTSCAN
654 #define LO_FLAGS_PARTSCAN 8
655 #endif
656
657 #ifndef LOOP_CTL_REMOVE
658 #define LOOP_CTL_REMOVE 0x4C81
659 #endif
660
661 #ifndef LOOP_CTL_GET_FREE
662 #define LOOP_CTL_GET_FREE 0x4C82
663 #endif
664
665 #if !HAVE_DECL_IFLA_INET6_ADDR_GEN_MODE
666 #define IFLA_INET6_UNSPEC 0
667 #define IFLA_INET6_FLAGS 1
668 #define IFLA_INET6_CONF 2
669 #define IFLA_INET6_STATS 3
670 #define IFLA_INET6_MCAST 4
671 #define IFLA_INET6_CACHEINFO 5
672 #define IFLA_INET6_ICMP6STATS 6
673 #define IFLA_INET6_TOKEN 7
674 #define IFLA_INET6_ADDR_GEN_MODE 8
675 #define __IFLA_INET6_MAX 9
676
677 #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
678
679 #define IN6_ADDR_GEN_MODE_EUI64 0
680 #define IN6_ADDR_GEN_MODE_NONE 1
681 #endif
682
683 #if !HAVE_DECL_IFLA_MACVLAN_FLAGS
684 #define IFLA_MACVLAN_UNSPEC 0
685 #define IFLA_MACVLAN_MODE 1
686 #define IFLA_MACVLAN_FLAGS 2
687 #define __IFLA_MACVLAN_MAX 3
688
689 #define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
690 #endif
691
692 #if !HAVE_DECL_IFLA_IPVLAN_MODE
693 #define IFLA_IPVLAN_UNSPEC 0
694 #define IFLA_IPVLAN_MODE 1
695 #define __IFLA_IPVLAN_MAX 2
696
697 #define IFLA_IPVLAN_MAX (__IFLA_IPVLAN_MAX - 1)
698
699 #define IPVLAN_MODE_L2 0
700 #define IPVLAN_MODE_L3 1
701 #define IPVLAN_MAX 2
702 #endif
703
704 #if !HAVE_DECL_IFLA_VTI_REMOTE
705 #define IFLA_VTI_UNSPEC 0
706 #define IFLA_VTI_LINK 1
707 #define IFLA_VTI_IKEY 2
708 #define IFLA_VTI_OKEY 3
709 #define IFLA_VTI_LOCAL 4
710 #define IFLA_VTI_REMOTE 5
711 #define __IFLA_VTI_MAX 6
712
713 #define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1)
714 #endif
715
716 #if !HAVE_DECL_IFLA_PHYS_PORT_ID
717 #undef IFLA_PROMISCUITY
718 #define IFLA_PROMISCUITY 30
719 #define IFLA_NUM_TX_QUEUES 31
720 #define IFLA_NUM_RX_QUEUES 32
721 #define IFLA_CARRIER 33
722 #define IFLA_PHYS_PORT_ID 34
723 #define __IFLA_MAX 35
724
725 #define IFLA_MAX (__IFLA_MAX - 1)
726 #endif
727
728 #if !HAVE_DECL_IFLA_BOND_AD_INFO
729 #define IFLA_BOND_UNSPEC 0
730 #define IFLA_BOND_MODE 1
731 #define IFLA_BOND_ACTIVE_SLAVE 2
732 #define IFLA_BOND_MIIMON 3
733 #define IFLA_BOND_UPDELAY 4
734 #define IFLA_BOND_DOWNDELAY 5
735 #define IFLA_BOND_USE_CARRIER 6
736 #define IFLA_BOND_ARP_INTERVAL 7
737 #define IFLA_BOND_ARP_IP_TARGET 8
738 #define IFLA_BOND_ARP_VALIDATE 9
739 #define IFLA_BOND_ARP_ALL_TARGETS 10
740 #define IFLA_BOND_PRIMARY 11
741 #define IFLA_BOND_PRIMARY_RESELECT 12
742 #define IFLA_BOND_FAIL_OVER_MAC 13
743 #define IFLA_BOND_XMIT_HASH_POLICY 14
744 #define IFLA_BOND_RESEND_IGMP 15
745 #define IFLA_BOND_NUM_PEER_NOTIF 16
746 #define IFLA_BOND_ALL_SLAVES_ACTIVE 17
747 #define IFLA_BOND_MIN_LINKS 18
748 #define IFLA_BOND_LP_INTERVAL 19
749 #define IFLA_BOND_PACKETS_PER_SLAVE 20
750 #define IFLA_BOND_AD_LACP_RATE 21
751 #define IFLA_BOND_AD_SELECT 22
752 #define IFLA_BOND_AD_INFO 23
753 #define __IFLA_BOND_MAX 24
754
755 #define IFLA_BOND_MAX (__IFLA_BOND_MAX - 1)
756 #endif
757
758 #if !HAVE_DECL_IFLA_VLAN_PROTOCOL
759 #define IFLA_VLAN_UNSPEC 0
760 #define IFLA_VLAN_ID 1
761 #define IFLA_VLAN_FLAGS 2
762 #define IFLA_VLAN_EGRESS_QOS 3
763 #define IFLA_VLAN_INGRESS_QOS 4
764 #define IFLA_VLAN_PROTOCOL 5
765 #define __IFLA_VLAN_MAX 6
766
767 #define IFLA_VLAN_MAX (__IFLA_VLAN_MAX - 1)
768 #endif
769
770 #if !HAVE_DECL_IFLA_VXLAN_REMCSUM_NOPARTIAL
771 #define IFLA_VXLAN_UNSPEC 0
772 #define IFLA_VXLAN_ID 1
773 #define IFLA_VXLAN_GROUP 2
774 #define IFLA_VXLAN_LINK 3
775 #define IFLA_VXLAN_LOCAL 4
776 #define IFLA_VXLAN_TTL 5
777 #define IFLA_VXLAN_TOS 6
778 #define IFLA_VXLAN_LEARNING 7
779 #define IFLA_VXLAN_AGEING 8
780 #define IFLA_VXLAN_LIMIT 9
781 #define IFLA_VXLAN_PORT_RANGE 10
782 #define IFLA_VXLAN_PROXY 11
783 #define IFLA_VXLAN_RSC 12
784 #define IFLA_VXLAN_L2MISS 13
785 #define IFLA_VXLAN_L3MISS 14
786 #define IFLA_VXLAN_PORT 15
787 #define IFLA_VXLAN_GROUP6 16
788 #define IFLA_VXLAN_LOCAL6 17
789 #define IFLA_VXLAN_UDP_CSUM 18
790 #define IFLA_VXLAN_UDP_ZERO_CSUM6_TX 19
791 #define IFLA_VXLAN_UDP_ZERO_CSUM6_RX 20
792 #define IFLA_VXLAN_REMCSUM_TX 21
793 #define IFLA_VXLAN_REMCSUM_RX 22
794 #define IFLA_VXLAN_GBP 23
795 #define IFLA_VXLAN_REMCSUM_NOPARTIAL 24
796 #define __IFLA_VXLAN_MAX 25
797
798 #define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)
799 #endif
800
801 #if !HAVE_DECL_IFLA_IPTUN_ENCAP_DPORT
802 #define IFLA_IPTUN_UNSPEC 0
803 #define IFLA_IPTUN_LINK 1
804 #define IFLA_IPTUN_LOCAL 2
805 #define IFLA_IPTUN_REMOTE 3
806 #define IFLA_IPTUN_TTL 4
807 #define IFLA_IPTUN_TOS 5
808 #define IFLA_IPTUN_ENCAP_LIMIT 6
809 #define IFLA_IPTUN_FLOWINFO 7
810 #define IFLA_IPTUN_FLAGS 8
811 #define IFLA_IPTUN_PROTO 9
812 #define IFLA_IPTUN_PMTUDISC 10
813 #define IFLA_IPTUN_6RD_PREFIX 11
814 #define IFLA_IPTUN_6RD_RELAY_PREFIX 12
815 #define IFLA_IPTUN_6RD_PREFIXLEN 13
816 #define IFLA_IPTUN_6RD_RELAY_PREFIXLEN 14
817 #define IFLA_IPTUN_ENCAP_TYPE 15
818 #define IFLA_IPTUN_ENCAP_FLAGS 16
819 #define IFLA_IPTUN_ENCAP_SPORT 17
820 #define IFLA_IPTUN_ENCAP_DPORT 18
821
822 #define __IFLA_IPTUN_MAX 19
823
824 #define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1)
825 #endif
826
827 #if !HAVE_DECL_IFLA_GRE_ENCAP_DPORT
828 #define IFLA_GRE_UNSPEC 0
829 #define IFLA_GRE_LINK 1
830 #define IFLA_GRE_IFLAGS 2
831 #define IFLA_GRE_OFLAGS 3
832 #define IFLA_GRE_IKEY 4
833 #define IFLA_GRE_OKEY 5
834 #define IFLA_GRE_LOCAL 6
835 #define IFLA_GRE_REMOTE 7
836 #define IFLA_GRE_TTL 8
837 #define IFLA_GRE_TOS 9
838 #define IFLA_GRE_PMTUDISC 10
839 #define IFLA_GRE_ENCAP_LIMIT 11
840 #define IFLA_GRE_FLOWINFO 12
841 #define IFLA_GRE_FLAGS 13
842 #define IFLA_GRE_ENCAP_TYPE 14
843 #define IFLA_GRE_ENCAP_FLAGS 15
844 #define IFLA_GRE_ENCAP_SPORT 16
845 #define IFLA_GRE_ENCAP_DPORT 17
846
847 #define __IFLA_GRE_MAX 18
848
849 #define IFLA_GRE_MAX (__IFLA_GRE_MAX - 1)
850 #endif
851
852 #if !HAVE_DECL_IFLA_BRIDGE_VLAN_INFO
853 #define IFLA_BRIDGE_FLAGS 0
854 #define IFLA_BRIDGE_MODE 1
855 #define IFLA_BRIDGE_VLAN_INFO 2
856 #define __IFLA_BRIDGE_MAX 3
857
858 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
859 #endif
860
861 #if !HAVE_DECL_IFLA_BR_PRIORITY
862 #define IFLA_BR_UNSPEC 0
863 #define IFLA_BR_FORWARD_DELAY 1
864 #define IFLA_BR_HELLO_TIME 2
865 #define IFLA_BR_MAX_AGE 3
866 #define IFLA_BR_AGEING_TIME 4
867 #define IFLA_BR_STP_STATE 5
868 #define IFLA_BR_PRIORITY 6
869 #define __IFLA_BR_MAX 7
870
871 #define IFLA_BR_MAX (__IFLA_BR_MAX - 1)
872 #endif
873
874 #if !HAVE_DECL_IFLA_BRPORT_LEARNING_SYNC
875 #define IFLA_BRPORT_UNSPEC 0
876 #define IFLA_BRPORT_STATE 1
877 #define IFLA_BRPORT_PRIORITY 2
878 #define IFLA_BRPORT_COST 3
879 #define IFLA_BRPORT_MODE 4
880 #define IFLA_BRPORT_GUARD 5
881 #define IFLA_BRPORT_PROTECT 6
882 #define IFLA_BRPORT_FAST_LEAVE 7
883 #define IFLA_BRPORT_LEARNING 8
884 #define IFLA_BRPORT_UNICAST_FLOOD 9
885 #define IFLA_BRPORT_PROXYARP 10
886 #define IFLA_BRPORT_LEARNING_SYNC 11
887 #define __IFLA_BRPORT_MAX 12
888
889 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
890 #endif
891
892 #if !HAVE_DECL_NDA_IFINDEX
893 #define NDA_UNSPEC 0
894 #define NDA_DST 1
895 #define NDA_LLADDR 2
896 #define NDA_CACHEINFO 3
897 #define NDA_PROBES 4
898 #define NDA_VLAN 5
899 #define NDA_PORT 6
900 #define NDA_VNI 7
901 #define NDA_IFINDEX 8
902 #define __NDA_MAX 9
903
904 #define NDA_MAX (__NDA_MAX - 1)
905 #endif
906
907 #ifndef RTA_PREF
908 #define RTA_PREF 20
909 #endif
910
911 #ifndef IPV6_UNICAST_IF
912 #define IPV6_UNICAST_IF 76
913 #endif
914
915 #ifndef IFF_MULTI_QUEUE
916 #define IFF_MULTI_QUEUE 0x100
917 #endif
918
919 #ifndef IFF_LOWER_UP
920 #define IFF_LOWER_UP 0x10000
921 #endif
922
923 #ifndef IFF_DORMANT
924 #define IFF_DORMANT 0x20000
925 #endif
926
927 #ifndef BOND_XMIT_POLICY_ENCAP23
928 #define BOND_XMIT_POLICY_ENCAP23 3
929 #endif
930
931 #ifndef BOND_XMIT_POLICY_ENCAP34
932 #define BOND_XMIT_POLICY_ENCAP34 4
933 #endif
934
935 #ifndef NET_ADDR_RANDOM
936 # define NET_ADDR_RANDOM 1
937 #endif
938
939 #ifndef NET_NAME_UNKNOWN
940 # define NET_NAME_UNKNOWN 0
941 #endif
942
943 #ifndef NET_NAME_ENUM
944 # define NET_NAME_ENUM 1
945 #endif
946
947 #ifndef NET_NAME_PREDICTABLE
948 # define NET_NAME_PREDICTABLE 2
949 #endif
950
951 #ifndef NET_NAME_USER
952 # define NET_NAME_USER 3
953 #endif
954
955 #ifndef NET_NAME_RENAMED
956 # define NET_NAME_RENAMED 4
957 #endif
958
959 #ifndef BPF_XOR
960 # define BPF_XOR 0xa0
961 #endif
962
963 /* Note that LOOPBACK_IFINDEX is currently not exported by the
964 * kernel/glibc, but hardcoded internally by the kernel. However, as
965 * it is exported to userspace indirectly via rtnetlink and the
966 * ioctls, and made use of widely we define it here too, in a way that
967 * is compatible with the kernel's internal definition. */
968 #ifndef LOOPBACK_IFINDEX
969 #define LOOPBACK_IFINDEX 1
970 #endif
971
972 #if !HAVE_DECL_IFA_FLAGS
973 #define IFA_FLAGS 8
974 #endif
975
976 #ifndef IFA_F_MANAGETEMPADDR
977 #define IFA_F_MANAGETEMPADDR 0x100
978 #endif
979
980 #ifndef IFA_F_NOPREFIXROUTE
981 #define IFA_F_NOPREFIXROUTE 0x200
982 #endif
983
984 #ifndef MAX_AUDIT_MESSAGE_LENGTH
985 #define MAX_AUDIT_MESSAGE_LENGTH 8970
986 #endif
987
988 #ifndef AUDIT_NLGRP_MAX
989 #define AUDIT_NLGRP_READLOG 1
990 #endif
991
992 #ifndef CAP_MAC_OVERRIDE
993 #define CAP_MAC_OVERRIDE 32
994 #endif
995
996 #ifndef CAP_MAC_ADMIN
997 #define CAP_MAC_ADMIN 33
998 #endif
999
1000 #ifndef CAP_SYSLOG
1001 #define CAP_SYSLOG 34
1002 #endif
1003
1004 #ifndef CAP_WAKE_ALARM
1005 #define CAP_WAKE_ALARM 35
1006 #endif
1007
1008 #ifndef CAP_BLOCK_SUSPEND
1009 #define CAP_BLOCK_SUSPEND 36
1010 #endif
1011
1012 #ifndef CAP_AUDIT_READ
1013 #define CAP_AUDIT_READ 37
1014 #endif
1015
1016 static inline int raw_clone(unsigned long flags, void *child_stack) {
1017 #if defined(__s390__) || defined(__CRIS__)
1018 /* On s390 and cris the order of the first and second arguments
1019 * of the raw clone() system call is reversed. */
1020 return (int) syscall(__NR_clone, child_stack, flags);
1021 #else
1022 return (int) syscall(__NR_clone, flags, child_stack);
1023 #endif
1024 }
1025
1026 static inline pid_t raw_getpid(void) {
1027 #if defined(__alpha__)
1028 return (pid_t) syscall(__NR_getxpid);
1029 #else
1030 return (pid_t) syscall(__NR_getpid);
1031 #endif
1032 }
1033
1034 #if !HAVE_DECL_RENAMEAT2
1035
1036 #ifndef __NR_renameat2
1037 # if defined __x86_64__
1038 # define __NR_renameat2 316
1039 # elif defined __arm__
1040 # define __NR_renameat2 382
1041 # elif defined _MIPS_SIM
1042 # if _MIPS_SIM == _MIPS_SIM_ABI32
1043 # define __NR_renameat2 4351
1044 # endif
1045 # if _MIPS_SIM == _MIPS_SIM_NABI32
1046 # define __NR_renameat2 6315
1047 # endif
1048 # if _MIPS_SIM == _MIPS_SIM_ABI64
1049 # define __NR_renameat2 5311
1050 # endif
1051 # elif defined __i386__
1052 # define __NR_renameat2 353
1053 # else
1054 # warning "__NR_renameat2 unknown for your architecture"
1055 # define __NR_renameat2 0xffffffff
1056 # endif
1057 #endif
1058
1059 static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
1060 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
1061 }
1062 #endif
1063
1064 #ifndef RENAME_NOREPLACE
1065 #define RENAME_NOREPLACE (1 << 0)
1066 #endif
1067
1068 #if !HAVE_DECL_KCMP
1069 static inline int kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
1070 #if defined(__NR_kcmp)
1071 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
1072 #else
1073 errno = ENOSYS;
1074 return -1;
1075 #endif
1076 }
1077 #endif
1078
1079 #ifndef KCMP_FILE
1080 #define KCMP_FILE 0
1081 #endif
1082
1083 #ifndef INPUT_PROP_POINTING_STICK
1084 #define INPUT_PROP_POINTING_STICK 0x05
1085 #endif
1086
1087 #ifndef INPUT_PROP_ACCELEROMETER
1088 #define INPUT_PROP_ACCELEROMETER 0x06
1089 #endif
1090
1091 #if !HAVE_DECL_KEY_SERIAL_T
1092 typedef int32_t key_serial_t;
1093 #endif
1094
1095 #if !HAVE_DECL_KEYCTL
1096 static inline long keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
1097 #if defined(__NR_keyctl)
1098 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
1099 #else
1100 errno = ENOSYS;
1101 return -1;
1102 #endif
1103 }
1104
1105 static inline key_serial_t add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
1106 #if defined (__NR_add_key)
1107 return syscall(__NR_add_key, type, description, payload, plen, ringid);
1108 #else
1109 errno = ENOSYS;
1110 return -1;
1111 #endif
1112 }
1113
1114 static inline key_serial_t request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
1115 #if defined (__NR_request_key)
1116 return syscall(__NR_request_key, type, description, callout_info, destringid);
1117 #else
1118 errno = ENOSYS;
1119 return -1;
1120 #endif
1121 }
1122 #endif
1123
1124 #ifndef KEYCTL_READ
1125 #define KEYCTL_READ 11
1126 #endif
1127
1128 #ifndef KEYCTL_SET_TIMEOUT
1129 #define KEYCTL_SET_TIMEOUT 15
1130 #endif
1131
1132 #ifndef KEY_SPEC_USER_KEYRING
1133 #define KEY_SPEC_USER_KEYRING -4
1134 #endif
1135
1136 #ifndef PR_CAP_AMBIENT
1137 #define PR_CAP_AMBIENT 47
1138 #endif
1139
1140 #ifndef PR_CAP_AMBIENT_IS_SET
1141 #define PR_CAP_AMBIENT_IS_SET 1
1142 #endif
1143
1144 #ifndef PR_CAP_AMBIENT_RAISE
1145 #define PR_CAP_AMBIENT_RAISE 2
1146 #endif
1147
1148 #ifndef PR_CAP_AMBIENT_CLEAR_ALL
1149 #define PR_CAP_AMBIENT_CLEAR_ALL 4
1150 #endif
1151
1152 /* The following two defines are actually available in the kernel headers for longer, but we define them here anyway,
1153 * since that makes it easier to use them in conjunction with the glibc net/if.h header which conflicts with
1154 * linux/if.h. */
1155 #ifndef IF_OPER_UNKNOWN
1156 #define IF_OPER_UNKNOWN 0
1157 #endif
1158
1159 #ifndef IF_OPER_UP
1160 #define IF_OPER_UP 6
1161
1162 #ifndef HAVE_DECL_CHAR32_T
1163 #define char32_t uint32_t
1164 #endif
1165
1166 #ifndef HAVE_DECL_CHAR16_T
1167 #define char16_t uint16_t
1168 #endif
1169
1170 #endif