4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
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.
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.
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/>.
22 /* Missing glibc definitions to access certain kernel APIs */
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 <net/ethernet.h>
36 #include <sys/resource.h>
37 #include <sys/syscall.h>
41 #include "musl_missing.h"
48 #include <asm/sgidefs.h>
51 #ifdef HAVE_LINUX_BTRFS_H
52 #include <linux/btrfs.h>
58 #define RLIMIT_RTTIME 15
61 /* If RLIMIT_RTTIME is not defined, then we cannot use RLIMIT_NLIMITS as is */
62 #define _RLIMIT_MAX (RLIMIT_RTTIME+1 > RLIMIT_NLIMITS ? RLIMIT_RTTIME+1 : RLIMIT_NLIMITS)
64 #ifndef F_LINUX_SPECIFIC_BASE
65 #define F_LINUX_SPECIFIC_BASE 1024
69 #define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
73 #define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)
77 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
78 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
80 #define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
81 #define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
82 #define F_SEAL_GROW 0x0004 /* prevent file from growing */
83 #define F_SEAL_WRITE 0x0008 /* prevent writes */
87 #define F_OFD_GETLK 36
88 #define F_OFD_SETLK 37
89 #define F_OFD_SETLKW 38
92 #ifndef MFD_ALLOW_SEALING
93 #define MFD_ALLOW_SEALING 0x0002U
97 #define MFD_CLOEXEC 0x0001U
101 #define IP_FREEBIND 15
104 #ifndef OOM_SCORE_ADJ_MIN
105 #define OOM_SCORE_ADJ_MIN (-1000)
108 #ifndef OOM_SCORE_ADJ_MAX
109 #define OOM_SCORE_ADJ_MAX 1000
112 #ifndef AUDIT_SERVICE_START
113 #define AUDIT_SERVICE_START 1130 /* Service (daemon) start */
116 #ifndef AUDIT_SERVICE_STOP
117 #define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */
121 #define TIOCVHANGUP 0x5437
124 #ifndef IP_TRANSPARENT
125 #define IP_TRANSPARENT 19
129 #define SOL_NETLINK 270
132 #ifndef NETLINK_LIST_MEMBERSHIPS
133 #define NETLINK_LIST_MEMBERSHIPS 9
140 #if !HAVE_DECL_PIVOT_ROOT
141 static inline int pivot_root(const char *new_root, const char *put_old) {
142 return syscall(SYS_pivot_root, new_root, put_old);
146 #ifndef __NR_memfd_create
147 # if defined __x86_64__
148 # define __NR_memfd_create 319
149 # elif defined __arm__
150 # define __NR_memfd_create 385
151 # elif defined __aarch64__
152 # define __NR_memfd_create 279
153 # elif defined __s390__
154 # define __NR_memfd_create 350
155 # elif defined _MIPS_SIM
156 # if _MIPS_SIM == _MIPS_SIM_ABI32
157 # define __NR_memfd_create 4354
159 # if _MIPS_SIM == _MIPS_SIM_NABI32
160 # define __NR_memfd_create 6318
162 # if _MIPS_SIM == _MIPS_SIM_ABI64
163 # define __NR_memfd_create 5314
165 # elif defined __i386__
166 # define __NR_memfd_create 356
168 # warning "__NR_memfd_create unknown for your architecture"
169 # define __NR_memfd_create 0xffffffff
173 #if !HAVE_DECL_MEMFD_CREATE
174 static inline int memfd_create(const char *name, unsigned int flags) {
175 return syscall(__NR_memfd_create, name, flags);
179 #ifndef __NR_getrandom
180 # if defined __x86_64__
181 # define __NR_getrandom 318
182 # elif defined(__i386__)
183 # define __NR_getrandom 355
184 # elif defined(__arm__)
185 # define __NR_getrandom 384
186 # elif defined(__aarch64__)
187 # define __NR_getrandom 278
188 # elif defined(__ia64__)
189 # define __NR_getrandom 1339
190 # elif defined(__m68k__)
191 # define __NR_getrandom 352
192 # elif defined(__s390x__)
193 # define __NR_getrandom 349
194 # elif defined(__powerpc__)
195 # define __NR_getrandom 359
196 # elif defined _MIPS_SIM
197 # if _MIPS_SIM == _MIPS_SIM_ABI32
198 # define __NR_getrandom 4353
200 # if _MIPS_SIM == _MIPS_SIM_NABI32
201 # define __NR_getrandom 6317
203 # if _MIPS_SIM == _MIPS_SIM_ABI64
204 # define __NR_getrandom 5313
207 # warning "__NR_getrandom unknown for your architecture"
208 # define __NR_getrandom 0xffffffff
212 #if !HAVE_DECL_GETRANDOM
213 static inline int getrandom(void *buffer, size_t count, unsigned flags) {
214 return syscall(__NR_getrandom, buffer, count, flags);
218 #ifndef GRND_NONBLOCK
219 #define GRND_NONBLOCK 0x0001
223 #define GRND_RANDOM 0x0002
226 #ifndef BTRFS_IOCTL_MAGIC
227 #define BTRFS_IOCTL_MAGIC 0x94
230 #ifndef BTRFS_PATH_NAME_MAX
231 #define BTRFS_PATH_NAME_MAX 4087
234 #ifndef BTRFS_DEVICE_PATH_NAME_MAX
235 #define BTRFS_DEVICE_PATH_NAME_MAX 1024
238 #ifndef BTRFS_FSID_SIZE
239 #define BTRFS_FSID_SIZE 16
242 #ifndef BTRFS_UUID_SIZE
243 #define BTRFS_UUID_SIZE 16
246 #ifndef BTRFS_SUBVOL_RDONLY
247 #define BTRFS_SUBVOL_RDONLY (1ULL << 1)
250 #ifndef BTRFS_SUBVOL_NAME_MAX
251 #define BTRFS_SUBVOL_NAME_MAX 4039
254 #ifndef BTRFS_INO_LOOKUP_PATH_MAX
255 #define BTRFS_INO_LOOKUP_PATH_MAX 4080
258 #ifndef BTRFS_SEARCH_ARGS_BUFSIZE
259 #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
262 #ifndef BTRFS_QGROUP_LEVEL_SHIFT
263 #define BTRFS_QGROUP_LEVEL_SHIFT 48
266 #if 0 /// UNNEEDED by elogind (It can not support BTRFS at all)
267 #ifndef HAVE_LINUX_BTRFS_H
268 struct btrfs_ioctl_vol_args {
270 char name[BTRFS_PATH_NAME_MAX + 1];
273 struct btrfs_qgroup_limit {
281 struct btrfs_qgroup_inherit {
284 __u64 num_ref_copies;
285 __u64 num_excl_copies;
286 struct btrfs_qgroup_limit lim;
290 struct btrfs_ioctl_qgroup_limit_args {
292 struct btrfs_qgroup_limit lim;
295 struct btrfs_ioctl_vol_args_v2 {
302 struct btrfs_qgroup_inherit *qgroup_inherit;
306 char name[BTRFS_SUBVOL_NAME_MAX + 1];
309 struct btrfs_ioctl_dev_info_args {
310 uint64_t devid; /* in/out */
311 uint8_t uuid[BTRFS_UUID_SIZE]; /* in/out */
312 uint64_t bytes_used; /* out */
313 uint64_t total_bytes; /* out */
314 uint64_t unused[379]; /* pad to 4k */
315 char path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */
318 struct btrfs_ioctl_fs_info_args {
319 uint64_t max_id; /* out */
320 uint64_t num_devices; /* out */
321 uint8_t fsid[BTRFS_FSID_SIZE]; /* out */
322 uint64_t reserved[124]; /* pad to 1k */
325 struct btrfs_ioctl_ino_lookup_args {
328 char name[BTRFS_INO_LOOKUP_PATH_MAX];
331 struct btrfs_ioctl_search_key {
332 /* which root are we searching. 0 is the tree of tree roots */
335 /* keys returned will be >= min and <= max */
339 /* keys returned will be >= min and <= max */
343 /* max and min transids to search for */
347 /* keys returned will be >= min and <= max */
352 * how many items did userland ask for, and how many are we
357 /* align to 64 bits */
360 /* some extra for later */
367 struct btrfs_ioctl_search_header {
376 struct btrfs_ioctl_search_args {
377 struct btrfs_ioctl_search_key key;
378 char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
381 struct btrfs_ioctl_clone_range_args {
383 __u64 src_offset, src_length;
387 #define BTRFS_QUOTA_CTL_ENABLE 1
388 #define BTRFS_QUOTA_CTL_DISABLE 2
389 #define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
390 struct btrfs_ioctl_quota_ctl_args {
396 #ifndef BTRFS_IOC_DEFRAG
397 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
398 struct btrfs_ioctl_vol_args)
401 #ifndef BTRFS_IOC_RESIZE
402 #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
403 struct btrfs_ioctl_vol_args)
406 #ifndef BTRFS_IOC_CLONE
407 #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
410 #ifndef BTRFS_IOC_CLONE_RANGE
411 #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
412 struct btrfs_ioctl_clone_range_args)
415 #ifndef BTRFS_IOC_SUBVOL_CREATE
416 #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
417 struct btrfs_ioctl_vol_args)
420 #ifndef BTRFS_IOC_SNAP_DESTROY
421 #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
422 struct btrfs_ioctl_vol_args)
425 #ifndef BTRFS_IOC_TREE_SEARCH
426 #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
427 struct btrfs_ioctl_search_args)
430 #ifndef BTRFS_IOC_INO_LOOKUP
431 #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
432 struct btrfs_ioctl_ino_lookup_args)
435 #ifndef BTRFS_IOC_SNAP_CREATE_V2
436 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
437 struct btrfs_ioctl_vol_args_v2)
440 #ifndef BTRFS_IOC_SUBVOL_GETFLAGS
441 #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
444 #ifndef BTRFS_IOC_SUBVOL_SETFLAGS
445 #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
448 #ifndef BTRFS_IOC_DEV_INFO
449 #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
450 struct btrfs_ioctl_dev_info_args)
453 #ifndef BTRFS_IOC_FS_INFO
454 #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
455 struct btrfs_ioctl_fs_info_args)
458 #ifndef BTRFS_IOC_DEVICES_READY
459 #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
460 struct btrfs_ioctl_vol_args)
463 #ifndef BTRFS_IOC_QUOTA_CTL
464 #define BTRFS_IOC_QUOTA_CTL _IOWR(BTRFS_IOCTL_MAGIC, 40, \
465 struct btrfs_ioctl_quota_ctl_args)
468 #ifndef BTRFS_IOC_QGROUP_LIMIT
469 #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \
470 struct btrfs_ioctl_qgroup_limit_args)
473 #ifndef BTRFS_IOC_QUOTA_RESCAN_WAIT
474 #define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
477 #ifndef BTRFS_FIRST_FREE_OBJECTID
478 #define BTRFS_FIRST_FREE_OBJECTID 256
481 #ifndef BTRFS_LAST_FREE_OBJECTID
482 #define BTRFS_LAST_FREE_OBJECTID -256ULL
485 #ifndef BTRFS_ROOT_TREE_OBJECTID
486 #define BTRFS_ROOT_TREE_OBJECTID 1
489 #ifndef BTRFS_QUOTA_TREE_OBJECTID
490 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
493 #ifndef BTRFS_ROOT_ITEM_KEY
494 #define BTRFS_ROOT_ITEM_KEY 132
497 #ifndef BTRFS_QGROUP_STATUS_KEY
498 #define BTRFS_QGROUP_STATUS_KEY 240
501 #ifndef BTRFS_QGROUP_INFO_KEY
502 #define BTRFS_QGROUP_INFO_KEY 242
505 #ifndef BTRFS_QGROUP_LIMIT_KEY
506 #define BTRFS_QGROUP_LIMIT_KEY 244
509 #ifndef BTRFS_QGROUP_RELATION_KEY
510 #define BTRFS_QGROUP_RELATION_KEY 246
513 #ifndef BTRFS_ROOT_BACKREF_KEY
514 #define BTRFS_ROOT_BACKREF_KEY 144
517 #ifndef BTRFS_SUPER_MAGIC
518 #define BTRFS_SUPER_MAGIC 0x9123683E
523 #ifndef CGROUP_SUPER_MAGIC
524 #define CGROUP_SUPER_MAGIC 0x27e0eb
527 #ifndef CGROUP2_SUPER_MAGIC
528 #define CGROUP2_SUPER_MAGIC 0x63677270
532 #define TMPFS_MAGIC 0x01021994
536 #define MQUEUE_MAGIC 0x19800202
544 #define MS_PRIVATE (1 << 18)
547 #if !HAVE_DECL_GETTID
548 static inline pid_t gettid(void) {
549 return (pid_t) syscall(SYS_gettid);
554 #define SCM_SECURITY 0x03
557 #ifndef MS_STRICTATIME
558 #define MS_STRICTATIME (1<<24)
566 #define MS_SHARED (1<<20)
569 #ifndef PR_SET_NO_NEW_PRIVS
570 #define PR_SET_NO_NEW_PRIVS 38
573 #ifndef PR_SET_CHILD_SUBREAPER
574 #define PR_SET_CHILD_SUBREAPER 36
577 #ifndef MAX_HANDLE_SZ
578 #define MAX_HANDLE_SZ 128
581 #ifndef __NR_name_to_handle_at
582 # if defined(__x86_64__)
583 # define __NR_name_to_handle_at 303
584 # elif defined(__i386__)
585 # define __NR_name_to_handle_at 341
586 # elif defined(__arm__)
587 # define __NR_name_to_handle_at 370
588 # elif defined(__powerpc__)
589 # define __NR_name_to_handle_at 345
591 # error "__NR_name_to_handle_at is not defined"
595 #if !HAVE_DECL_NAME_TO_HANDLE_AT
597 unsigned int handle_bytes;
599 unsigned char f_handle[0];
602 static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
603 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
607 #ifndef HAVE_SECURE_GETENV
608 # ifdef HAVE___SECURE_GETENV
609 # define secure_getenv __secure_getenv
611 # error "neither secure_getenv nor __secure_getenv are available"
615 #ifndef CIFS_MAGIC_NUMBER
616 # define CIFS_MAGIC_NUMBER 0xFF534D42
619 #ifndef TFD_TIMER_CANCEL_ON_SET
620 # define TFD_TIMER_CANCEL_ON_SET (1 << 1)
624 # define SO_REUSEPORT 15
628 # define EVIOCREVOKE _IOW('E', 0x91, int)
631 #ifndef DRM_IOCTL_SET_MASTER
632 # define DRM_IOCTL_SET_MASTER _IO('d', 0x1e)
635 #ifndef DRM_IOCTL_DROP_MASTER
636 # define DRM_IOCTL_DROP_MASTER _IO('d', 0x1f)
639 #if defined(__i386__) || defined(__x86_64__)
641 /* The precise definition of __O_TMPFILE is arch specific, so let's
642 * just define this on x86 where we know the value. */
645 #define __O_TMPFILE 020000000
648 /* a horrid kludge trying to make sure that this will fail on old kernels */
650 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
656 # if defined(__x86_64__)
657 # define __NR_setns 308
658 # elif defined(__i386__)
659 # define __NR_setns 346
661 # error "__NR_setns is not defined"
666 static inline int setns(int fd, int nstype) {
667 return syscall(__NR_setns, fd, nstype);
671 #if !HAVE_DECL_LO_FLAGS_PARTSCAN
672 #define LO_FLAGS_PARTSCAN 8
675 #ifndef LOOP_CTL_REMOVE
676 #define LOOP_CTL_REMOVE 0x4C81
679 #ifndef LOOP_CTL_GET_FREE
680 #define LOOP_CTL_GET_FREE 0x4C82
683 #if !HAVE_DECL_IFLA_INET6_ADDR_GEN_MODE
684 #define IFLA_INET6_UNSPEC 0
685 #define IFLA_INET6_FLAGS 1
686 #define IFLA_INET6_CONF 2
687 #define IFLA_INET6_STATS 3
688 #define IFLA_INET6_MCAST 4
689 #define IFLA_INET6_CACHEINFO 5
690 #define IFLA_INET6_ICMP6STATS 6
691 #define IFLA_INET6_TOKEN 7
692 #define IFLA_INET6_ADDR_GEN_MODE 8
693 #define __IFLA_INET6_MAX 9
695 #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
697 #define IN6_ADDR_GEN_MODE_EUI64 0
698 #define IN6_ADDR_GEN_MODE_NONE 1
701 #if !HAVE_DECL_IFLA_MACVLAN_FLAGS
702 #define IFLA_MACVLAN_UNSPEC 0
703 #define IFLA_MACVLAN_MODE 1
704 #define IFLA_MACVLAN_FLAGS 2
705 #define __IFLA_MACVLAN_MAX 3
707 #define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
710 #if !HAVE_DECL_IFLA_IPVLAN_MODE
711 #define IFLA_IPVLAN_UNSPEC 0
712 #define IFLA_IPVLAN_MODE 1
713 #define __IFLA_IPVLAN_MAX 2
715 #define IFLA_IPVLAN_MAX (__IFLA_IPVLAN_MAX - 1)
717 #define IPVLAN_MODE_L2 0
718 #define IPVLAN_MODE_L3 1
722 #if !HAVE_DECL_IFLA_VTI_REMOTE
723 #define IFLA_VTI_UNSPEC 0
724 #define IFLA_VTI_LINK 1
725 #define IFLA_VTI_IKEY 2
726 #define IFLA_VTI_OKEY 3
727 #define IFLA_VTI_LOCAL 4
728 #define IFLA_VTI_REMOTE 5
729 #define __IFLA_VTI_MAX 6
731 #define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1)
734 #if !HAVE_DECL_IFLA_PHYS_PORT_ID
735 #define IFLA_EXT_MASK 29
736 #undef IFLA_PROMISCUITY
737 #define IFLA_PROMISCUITY 30
738 #define IFLA_NUM_TX_QUEUES 31
739 #define IFLA_NUM_RX_QUEUES 32
740 #define IFLA_CARRIER 33
741 #define IFLA_PHYS_PORT_ID 34
742 #define __IFLA_MAX 35
744 #define IFLA_MAX (__IFLA_MAX - 1)
747 #if !HAVE_DECL_IFLA_BOND_AD_INFO
748 #define IFLA_BOND_UNSPEC 0
749 #define IFLA_BOND_MODE 1
750 #define IFLA_BOND_ACTIVE_SLAVE 2
751 #define IFLA_BOND_MIIMON 3
752 #define IFLA_BOND_UPDELAY 4
753 #define IFLA_BOND_DOWNDELAY 5
754 #define IFLA_BOND_USE_CARRIER 6
755 #define IFLA_BOND_ARP_INTERVAL 7
756 #define IFLA_BOND_ARP_IP_TARGET 8
757 #define IFLA_BOND_ARP_VALIDATE 9
758 #define IFLA_BOND_ARP_ALL_TARGETS 10
759 #define IFLA_BOND_PRIMARY 11
760 #define IFLA_BOND_PRIMARY_RESELECT 12
761 #define IFLA_BOND_FAIL_OVER_MAC 13
762 #define IFLA_BOND_XMIT_HASH_POLICY 14
763 #define IFLA_BOND_RESEND_IGMP 15
764 #define IFLA_BOND_NUM_PEER_NOTIF 16
765 #define IFLA_BOND_ALL_SLAVES_ACTIVE 17
766 #define IFLA_BOND_MIN_LINKS 18
767 #define IFLA_BOND_LP_INTERVAL 19
768 #define IFLA_BOND_PACKETS_PER_SLAVE 20
769 #define IFLA_BOND_AD_LACP_RATE 21
770 #define IFLA_BOND_AD_SELECT 22
771 #define IFLA_BOND_AD_INFO 23
772 #define __IFLA_BOND_MAX 24
774 #define IFLA_BOND_MAX (__IFLA_BOND_MAX - 1)
777 #if !HAVE_DECL_IFLA_VLAN_PROTOCOL
778 #define IFLA_VLAN_UNSPEC 0
779 #define IFLA_VLAN_ID 1
780 #define IFLA_VLAN_FLAGS 2
781 #define IFLA_VLAN_EGRESS_QOS 3
782 #define IFLA_VLAN_INGRESS_QOS 4
783 #define IFLA_VLAN_PROTOCOL 5
784 #define __IFLA_VLAN_MAX 6
786 #define IFLA_VLAN_MAX (__IFLA_VLAN_MAX - 1)
789 #if !HAVE_DECL_IFLA_VXLAN_REMCSUM_NOPARTIAL
790 #define IFLA_VXLAN_UNSPEC 0
791 #define IFLA_VXLAN_ID 1
792 #define IFLA_VXLAN_GROUP 2
793 #define IFLA_VXLAN_LINK 3
794 #define IFLA_VXLAN_LOCAL 4
795 #define IFLA_VXLAN_TTL 5
796 #define IFLA_VXLAN_TOS 6
797 #define IFLA_VXLAN_LEARNING 7
798 #define IFLA_VXLAN_AGEING 8
799 #define IFLA_VXLAN_LIMIT 9
800 #define IFLA_VXLAN_PORT_RANGE 10
801 #define IFLA_VXLAN_PROXY 11
802 #define IFLA_VXLAN_RSC 12
803 #define IFLA_VXLAN_L2MISS 13
804 #define IFLA_VXLAN_L3MISS 14
805 #define IFLA_VXLAN_PORT 15
806 #define IFLA_VXLAN_GROUP6 16
807 #define IFLA_VXLAN_LOCAL6 17
808 #define IFLA_VXLAN_UDP_CSUM 18
809 #define IFLA_VXLAN_UDP_ZERO_CSUM6_TX 19
810 #define IFLA_VXLAN_UDP_ZERO_CSUM6_RX 20
811 #define IFLA_VXLAN_REMCSUM_TX 21
812 #define IFLA_VXLAN_REMCSUM_RX 22
813 #define IFLA_VXLAN_GBP 23
814 #define IFLA_VXLAN_REMCSUM_NOPARTIAL 24
815 #define __IFLA_VXLAN_MAX 25
817 #define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)
820 #if !HAVE_DECL_IFLA_IPTUN_ENCAP_DPORT
821 #define IFLA_IPTUN_UNSPEC 0
822 #define IFLA_IPTUN_LINK 1
823 #define IFLA_IPTUN_LOCAL 2
824 #define IFLA_IPTUN_REMOTE 3
825 #define IFLA_IPTUN_TTL 4
826 #define IFLA_IPTUN_TOS 5
827 #define IFLA_IPTUN_ENCAP_LIMIT 6
828 #define IFLA_IPTUN_FLOWINFO 7
829 #define IFLA_IPTUN_FLAGS 8
830 #define IFLA_IPTUN_PROTO 9
831 #define IFLA_IPTUN_PMTUDISC 10
832 #define IFLA_IPTUN_6RD_PREFIX 11
833 #define IFLA_IPTUN_6RD_RELAY_PREFIX 12
834 #define IFLA_IPTUN_6RD_PREFIXLEN 13
835 #define IFLA_IPTUN_6RD_RELAY_PREFIXLEN 14
836 #define IFLA_IPTUN_ENCAP_TYPE 15
837 #define IFLA_IPTUN_ENCAP_FLAGS 16
838 #define IFLA_IPTUN_ENCAP_SPORT 17
839 #define IFLA_IPTUN_ENCAP_DPORT 18
841 #define __IFLA_IPTUN_MAX 19
843 #define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1)
846 #if !HAVE_DECL_IFLA_GRE_ENCAP_DPORT
847 #define IFLA_GRE_UNSPEC 0
848 #define IFLA_GRE_LINK 1
849 #define IFLA_GRE_IFLAGS 2
850 #define IFLA_GRE_OFLAGS 3
851 #define IFLA_GRE_IKEY 4
852 #define IFLA_GRE_OKEY 5
853 #define IFLA_GRE_LOCAL 6
854 #define IFLA_GRE_REMOTE 7
855 #define IFLA_GRE_TTL 8
856 #define IFLA_GRE_TOS 9
857 #define IFLA_GRE_PMTUDISC 10
858 #define IFLA_GRE_ENCAP_LIMIT 11
859 #define IFLA_GRE_FLOWINFO 12
860 #define IFLA_GRE_FLAGS 13
861 #define IFLA_GRE_ENCAP_TYPE 14
862 #define IFLA_GRE_ENCAP_FLAGS 15
863 #define IFLA_GRE_ENCAP_SPORT 16
864 #define IFLA_GRE_ENCAP_DPORT 17
866 #define __IFLA_GRE_MAX 18
868 #define IFLA_GRE_MAX (__IFLA_GRE_MAX - 1)
871 #if !HAVE_DECL_IFLA_BRIDGE_VLAN_INFO
872 #define IFLA_BRIDGE_FLAGS 0
873 #define IFLA_BRIDGE_MODE 1
874 #define IFLA_BRIDGE_VLAN_INFO 2
875 #define __IFLA_BRIDGE_MAX 3
877 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
880 #if !HAVE_DECL_IFLA_BR_VLAN_DEFAULT_PVID
881 #define IFLA_BR_UNSPEC 0
882 #define IFLA_BR_FORWARD_DELAY 1
883 #define IFLA_BR_HELLO_TIME 2
884 #define IFLA_BR_MAX_AGE 3
885 #define IFLA_BR_AGEING_TIME 4
886 #define IFLA_BR_STP_STATE 5
887 #define IFLA_BR_PRIORITY 6
888 #define IFLA_BR_VLAN_FILTERING 7
889 #define IFLA_BR_VLAN_PROTOCOL 8
890 #define IFLA_BR_GROUP_FWD_MASK 9
891 #define IFLA_BR_ROOT_ID 10
892 #define IFLA_BR_BRIDGE_ID 11
893 #define IFLA_BR_ROOT_PORT 12
894 #define IFLA_BR_ROOT_PATH_COST 13
895 #define IFLA_BR_TOPOLOGY_CHANGE 14
896 #define IFLA_BR_TOPOLOGY_CHANGE_DETECTED 15
897 #define IFLA_BR_HELLO_TIMER 16
898 #define IFLA_BR_TCN_TIMER 17
899 #define IFLA_BR_TOPOLOGY_CHANGE_TIMER 18
900 #define IFLA_BR_GC_TIMER 19
901 #define IFLA_BR_GROUP_ADDR 20
902 #define IFLA_BR_FDB_FLUSH 21
903 #define IFLA_BR_MCAST_ROUTER 22
904 #define IFLA_BR_MCAST_SNOOPING 23
905 #define IFLA_BR_MCAST_QUERY_USE_IFADDR 24
906 #define IFLA_BR_MCAST_QUERIER 25
907 #define IFLA_BR_MCAST_HASH_ELASTICITY 26
908 #define IFLA_BR_MCAST_HASH_MAX 27
909 #define IFLA_BR_MCAST_LAST_MEMBER_CNT 28
910 #define IFLA_BR_MCAST_STARTUP_QUERY_CNT 29
911 #define IFLA_BR_MCAST_LAST_MEMBER_INTVL 30
912 #define IFLA_BR_MCAST_MEMBERSHIP_INTVL 31
913 #define IFLA_BR_MCAST_QUERIER_INTVL 32
914 #define IFLA_BR_MCAST_QUERY_INTVL 33
915 #define IFLA_BR_MCAST_QUERY_RESPONSE_INTVL 34
916 #define IFLA_BR_MCAST_STARTUP_QUERY_INTVL 35
917 #define IFLA_BR_NF_CALL_IPTABLES 36
918 #define IFLA_BR_NF_CALL_IP6TABLES 37
919 #define IFLA_BR_NF_CALL_ARPTABLES 38
920 #define IFLA_BR_VLAN_DEFAULT_PVID 39
921 #define __IFLA_BR_MAX 40
923 #define IFLA_BR_MAX (__IFLA_BR_MAX - 1)
926 #if !HAVE_DECL_IFLA_BRPORT_LEARNING_SYNC
927 #define IFLA_BRPORT_UNSPEC 0
928 #define IFLA_BRPORT_STATE 1
929 #define IFLA_BRPORT_PRIORITY 2
930 #define IFLA_BRPORT_COST 3
931 #define IFLA_BRPORT_MODE 4
932 #define IFLA_BRPORT_GUARD 5
933 #define IFLA_BRPORT_PROTECT 6
934 #define IFLA_BRPORT_FAST_LEAVE 7
935 #define IFLA_BRPORT_LEARNING 8
936 #define IFLA_BRPORT_UNICAST_FLOOD 9
937 #define IFLA_BRPORT_LEARNING_SYNC 11
938 #define __IFLA_BRPORT_MAX 12
940 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
943 #if !HAVE_DECL_IFLA_BRPORT_PROXYARP
944 #define IFLA_BRPORT_PROXYARP 10
947 #if !HAVE_DECL_NDA_IFINDEX
951 #define NDA_CACHEINFO 3
956 #define NDA_IFINDEX 8
959 #define NDA_MAX (__NDA_MAX - 1)
966 #ifndef IPV6_UNICAST_IF
967 #define IPV6_UNICAST_IF 76
971 #define IPV6_MIN_MTU 1280
974 #ifndef IFF_MULTI_QUEUE
975 #define IFF_MULTI_QUEUE 0x100
979 #define IFF_LOWER_UP 0x10000
983 #define IFF_DORMANT 0x20000
986 #ifndef BOND_XMIT_POLICY_ENCAP23
987 #define BOND_XMIT_POLICY_ENCAP23 3
990 #ifndef BOND_XMIT_POLICY_ENCAP34
991 #define BOND_XMIT_POLICY_ENCAP34 4
994 #ifndef NET_ADDR_RANDOM
995 # define NET_ADDR_RANDOM 1
998 #ifndef NET_NAME_UNKNOWN
999 # define NET_NAME_UNKNOWN 0
1002 #ifndef NET_NAME_ENUM
1003 # define NET_NAME_ENUM 1
1006 #ifndef NET_NAME_PREDICTABLE
1007 # define NET_NAME_PREDICTABLE 2
1010 #ifndef NET_NAME_USER
1011 # define NET_NAME_USER 3
1014 #ifndef NET_NAME_RENAMED
1015 # define NET_NAME_RENAMED 4
1019 # define BPF_XOR 0xa0
1022 /* Note that LOOPBACK_IFINDEX is currently not exported by the
1023 * kernel/glibc, but hardcoded internally by the kernel. However, as
1024 * it is exported to userspace indirectly via rtnetlink and the
1025 * ioctls, and made use of widely we define it here too, in a way that
1026 * is compatible with the kernel's internal definition. */
1027 #ifndef LOOPBACK_IFINDEX
1028 #define LOOPBACK_IFINDEX 1
1031 #if !HAVE_DECL_IFA_FLAGS
1035 #ifndef IFA_F_MANAGETEMPADDR
1036 #define IFA_F_MANAGETEMPADDR 0x100
1039 #ifndef IFA_F_NOPREFIXROUTE
1040 #define IFA_F_NOPREFIXROUTE 0x200
1043 #ifndef MAX_AUDIT_MESSAGE_LENGTH
1044 #define MAX_AUDIT_MESSAGE_LENGTH 8970
1047 #ifndef AUDIT_NLGRP_MAX
1048 #define AUDIT_NLGRP_READLOG 1
1051 #ifndef CAP_MAC_OVERRIDE
1052 #define CAP_MAC_OVERRIDE 32
1055 #ifndef CAP_MAC_ADMIN
1056 #define CAP_MAC_ADMIN 33
1060 #define CAP_SYSLOG 34
1063 #ifndef CAP_WAKE_ALARM
1064 #define CAP_WAKE_ALARM 35
1067 #ifndef CAP_BLOCK_SUSPEND
1068 #define CAP_BLOCK_SUSPEND 36
1071 #ifndef CAP_AUDIT_READ
1072 #define CAP_AUDIT_READ 37
1075 static inline int raw_clone(unsigned long flags, void *child_stack) {
1076 #if defined(__s390__) || defined(__CRIS__)
1077 /* On s390 and cris the order of the first and second arguments
1078 * of the raw clone() system call is reversed. */
1079 return (int) syscall(__NR_clone, child_stack, flags);
1081 return (int) syscall(__NR_clone, flags, child_stack);
1085 static inline pid_t raw_getpid(void) {
1086 #if defined(__alpha__)
1087 return (pid_t) syscall(__NR_getxpid);
1089 return (pid_t) syscall(__NR_getpid);
1093 #if 0 /// UNNEEDED by elogind
1095 #if !HAVE_DECL_RENAMEAT2
1098 #ifndef __NR_renameat2
1099 # if defined __x86_64__
1100 # define __NR_renameat2 316
1101 # elif defined __arm__
1102 # define __NR_renameat2 382
1103 # elif defined _MIPS_SIM
1104 # if _MIPS_SIM == _MIPS_SIM_ABI32
1105 # define __NR_renameat2 4351
1107 # if _MIPS_SIM == _MIPS_SIM_NABI32
1108 # define __NR_renameat2 6315
1110 # if _MIPS_SIM == _MIPS_SIM_ABI64
1111 # define __NR_renameat2 5311
1113 # elif defined __i386__
1114 # define __NR_renameat2 353
1116 # warning "__NR_renameat2 unknown for your architecture"
1117 # define __NR_renameat2 0xffffffff
1121 static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
1122 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
1126 #ifndef RENAME_NOREPLACE
1127 #define RENAME_NOREPLACE (1 << 0)
1131 static inline int kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
1132 #if defined(__NR_kcmp)
1133 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
1145 #ifndef INPUT_PROP_POINTING_STICK
1146 #define INPUT_PROP_POINTING_STICK 0x05
1149 #ifndef INPUT_PROP_ACCELEROMETER
1150 #define INPUT_PROP_ACCELEROMETER 0x06
1153 #ifndef HAVE_KEY_SERIAL_T
1154 typedef int32_t key_serial_t;
1157 #if !HAVE_DECL_KEYCTL
1158 static inline long keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
1159 #if defined(__NR_keyctl)
1160 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
1167 static inline key_serial_t add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
1168 #if defined (__NR_add_key)
1169 return syscall(__NR_add_key, type, description, payload, plen, ringid);
1176 static inline key_serial_t request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
1177 #if defined (__NR_request_key)
1178 return syscall(__NR_request_key, type, description, callout_info, destringid);
1187 #define KEYCTL_READ 11
1190 #ifndef KEYCTL_SET_TIMEOUT
1191 #define KEYCTL_SET_TIMEOUT 15
1194 #ifndef KEY_SPEC_USER_KEYRING
1195 #define KEY_SPEC_USER_KEYRING -4
1199 #ifndef PR_CAP_AMBIENT
1200 #define PR_CAP_AMBIENT 47
1203 #ifndef PR_CAP_AMBIENT_IS_SET
1204 #define PR_CAP_AMBIENT_IS_SET 1
1207 #ifndef PR_CAP_AMBIENT_RAISE
1208 #define PR_CAP_AMBIENT_RAISE 2
1211 #ifndef PR_CAP_AMBIENT_CLEAR_ALL
1212 #define PR_CAP_AMBIENT_CLEAR_ALL 4
1215 /* The following two defines are actually available in the kernel headers for longer, but we define them here anyway,
1216 * since that makes it easier to use them in conjunction with the glibc net/if.h header which conflicts with
1218 #ifndef IF_OPER_UNKNOWN
1219 #define IF_OPER_UNKNOWN 0
1223 #define IF_OPER_UP 6
1225 #ifndef HAVE_CHAR32_T
1226 #define char32_t uint32_t
1229 #ifndef HAVE_CHAR16_T
1230 #define char16_t uint16_t
1233 #ifndef ETHERTYPE_LLDP
1234 #define ETHERTYPE_LLDP 0x88cc
1239 #ifndef __NR_copy_file_range
1240 # if defined(__x86_64__)
1241 # define __NR_copy_file_range 326
1242 # elif defined(__i386__)
1243 # define __NR_copy_file_range 377
1244 # elif defined __s390__
1245 # define __NR_copy_file_range 375
1246 # elif defined __arm__
1247 # define __NR_copy_file_range 391
1248 # elif defined __aarch64__
1249 # define __NR_copy_file_range 285
1251 # warning "__NR_copy_file_range not defined for your architecture"
1255 #if !HAVE_DECL_COPY_FILE_RANGE
1256 static inline ssize_t copy_file_range(int fd_in, loff_t *off_in,
1257 int fd_out, loff_t *off_out,
1259 unsigned int flags) {
1260 #ifdef __NR_copy_file_range
1261 return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);