1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2010 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 /* Missing glibc definitions to access certain kernel APIs */
26 #include <sys/resource.h>
27 #include <sys/syscall.h>
32 #include <linux/oom.h>
33 #include <linux/input.h>
34 #include <linux/if_link.h>
35 #include <linux/loop.h>
36 #include <linux/audit.h>
37 #include <linux/capability.h>
38 #include <linux/neighbour.h>
40 #include "musl_missing.h"
43 #include <asm/sgidefs.h>
46 #ifdef HAVE_LINUX_BTRFS_H
47 #include <linux/btrfs.h>
53 #define RLIMIT_RTTIME 15
56 /* If RLIMIT_RTTIME is not defined, then we cannot use RLIMIT_NLIMITS as is */
57 #define _RLIMIT_MAX (RLIMIT_RTTIME+1 > RLIMIT_NLIMITS ? RLIMIT_RTTIME+1 : RLIMIT_NLIMITS)
59 #ifndef F_LINUX_SPECIFIC_BASE
60 #define F_LINUX_SPECIFIC_BASE 1024
64 #define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
68 #define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)
72 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
73 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
75 #define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
76 #define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
77 #define F_SEAL_GROW 0x0004 /* prevent file from growing */
78 #define F_SEAL_WRITE 0x0008 /* prevent writes */
82 #define F_OFD_GETLK 36
83 #define F_OFD_SETLK 37
84 #define F_OFD_SETLKW 38
87 #ifndef MFD_ALLOW_SEALING
88 #define MFD_ALLOW_SEALING 0x0002U
92 #define MFD_CLOEXEC 0x0001U
96 #define IP_FREEBIND 15
99 #ifndef OOM_SCORE_ADJ_MIN
100 #define OOM_SCORE_ADJ_MIN (-1000)
103 #ifndef OOM_SCORE_ADJ_MAX
104 #define OOM_SCORE_ADJ_MAX 1000
107 #ifndef AUDIT_SERVICE_START
108 #define AUDIT_SERVICE_START 1130 /* Service (daemon) start */
111 #ifndef AUDIT_SERVICE_STOP
112 #define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */
116 #define TIOCVHANGUP 0x5437
119 #ifndef IP_TRANSPARENT
120 #define IP_TRANSPARENT 19
124 #define SOL_NETLINK 270
127 #if !HAVE_DECL_PIVOT_ROOT
128 static inline int pivot_root(const char *new_root, const char *put_old) {
129 return syscall(SYS_pivot_root, new_root, put_old);
133 #ifndef __NR_memfd_create
134 # if defined __x86_64__
135 # define __NR_memfd_create 319
136 # elif defined __arm__
137 # define __NR_memfd_create 385
138 # elif defined __aarch64__
139 # define __NR_memfd_create 279
140 # elif defined _MIPS_SIM
141 # if _MIPS_SIM == _MIPS_SIM_ABI32
142 # define __NR_memfd_create 4354
144 # if _MIPS_SIM == _MIPS_SIM_NABI32
145 # define __NR_memfd_create 6318
147 # if _MIPS_SIM == _MIPS_SIM_ABI64
148 # define __NR_memfd_create 5314
150 # elif defined __i386__
151 # define __NR_memfd_create 356
153 # warning "__NR_memfd_create unknown for your architecture"
154 # define __NR_memfd_create 0xffffffff
158 #ifndef HAVE_MEMFD_CREATE
159 static inline int memfd_create(const char *name, unsigned int flags) {
160 return syscall(__NR_memfd_create, name, flags);
164 #ifndef __NR_getrandom
165 # if defined __x86_64__
166 # define __NR_getrandom 318
167 # elif defined(__i386__)
168 # define __NR_getrandom 355
169 # elif defined(__arm__)
170 # define __NR_getrandom 384
171 # elif defined(__aarch64__)
172 # define __NR_getrandom 278
173 # elif defined(__ia64__)
174 # define __NR_getrandom 1339
175 # elif defined(__m68k__)
176 # define __NR_getrandom 352
177 # elif defined(__s390x__)
178 # define __NR_getrandom 349
179 # elif defined(__powerpc__)
180 # define __NR_getrandom 359
181 # elif defined _MIPS_SIM
182 # if _MIPS_SIM == _MIPS_SIM_ABI32
183 # define __NR_getrandom 4353
185 # if _MIPS_SIM == _MIPS_SIM_NABI32
186 # define __NR_getrandom 6317
188 # if _MIPS_SIM == _MIPS_SIM_ABI64
189 # define __NR_getrandom 5313
192 # warning "__NR_getrandom unknown for your architecture"
193 # define __NR_getrandom 0xffffffff
197 #if !HAVE_DECL_GETRANDOM
198 static inline int getrandom(void *buffer, size_t count, unsigned flags) {
199 return syscall(__NR_getrandom, buffer, count, flags);
203 #ifndef GRND_NONBLOCK
204 #define GRND_NONBLOCK 0x0001
208 #define GRND_RANDOM 0x0002
211 #ifndef BTRFS_IOCTL_MAGIC
212 #define BTRFS_IOCTL_MAGIC 0x94
215 #ifndef BTRFS_PATH_NAME_MAX
216 #define BTRFS_PATH_NAME_MAX 4087
219 #ifndef BTRFS_DEVICE_PATH_NAME_MAX
220 #define BTRFS_DEVICE_PATH_NAME_MAX 1024
223 #ifndef BTRFS_FSID_SIZE
224 #define BTRFS_FSID_SIZE 16
227 #ifndef BTRFS_UUID_SIZE
228 #define BTRFS_UUID_SIZE 16
231 #ifndef BTRFS_SUBVOL_RDONLY
232 #define BTRFS_SUBVOL_RDONLY (1ULL << 1)
235 #ifndef BTRFS_SUBVOL_NAME_MAX
236 #define BTRFS_SUBVOL_NAME_MAX 4039
239 #ifndef BTRFS_INO_LOOKUP_PATH_MAX
240 #define BTRFS_INO_LOOKUP_PATH_MAX 4080
243 #ifndef BTRFS_SEARCH_ARGS_BUFSIZE
244 #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
247 #ifndef HAVE_LINUX_BTRFS_H
248 struct btrfs_ioctl_vol_args {
250 char name[BTRFS_PATH_NAME_MAX + 1];
253 struct btrfs_qgroup_limit {
261 struct btrfs_qgroup_inherit {
264 __u64 num_ref_copies;
265 __u64 num_excl_copies;
266 struct btrfs_qgroup_limit lim;
270 struct btrfs_ioctl_qgroup_limit_args {
272 struct btrfs_qgroup_limit lim;
275 struct btrfs_ioctl_vol_args_v2 {
282 struct btrfs_qgroup_inherit *qgroup_inherit;
286 char name[BTRFS_SUBVOL_NAME_MAX + 1];
289 struct btrfs_ioctl_dev_info_args {
290 uint64_t devid; /* in/out */
291 uint8_t uuid[BTRFS_UUID_SIZE]; /* in/out */
292 uint64_t bytes_used; /* out */
293 uint64_t total_bytes; /* out */
294 uint64_t unused[379]; /* pad to 4k */
295 char path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */
298 struct btrfs_ioctl_fs_info_args {
299 uint64_t max_id; /* out */
300 uint64_t num_devices; /* out */
301 uint8_t fsid[BTRFS_FSID_SIZE]; /* out */
302 uint64_t reserved[124]; /* pad to 1k */
305 struct btrfs_ioctl_ino_lookup_args {
308 char name[BTRFS_INO_LOOKUP_PATH_MAX];
311 struct btrfs_ioctl_search_key {
312 /* which root are we searching. 0 is the tree of tree roots */
315 /* keys returned will be >= min and <= max */
319 /* keys returned will be >= min and <= max */
323 /* max and min transids to search for */
327 /* keys returned will be >= min and <= max */
332 * how many items did userland ask for, and how many are we
337 /* align to 64 bits */
340 /* some extra for later */
347 struct btrfs_ioctl_search_header {
356 struct btrfs_ioctl_search_args {
357 struct btrfs_ioctl_search_key key;
358 char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
361 struct btrfs_ioctl_clone_range_args {
363 __u64 src_offset, src_length;
367 #define BTRFS_QUOTA_CTL_ENABLE 1
368 #define BTRFS_QUOTA_CTL_DISABLE 2
369 #define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
370 struct btrfs_ioctl_quota_ctl_args {
376 #ifndef BTRFS_IOC_DEFRAG
377 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
378 struct btrfs_ioctl_vol_args)
381 #ifndef BTRFS_IOC_RESIZE
382 #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
383 struct btrfs_ioctl_vol_args)
386 #ifndef BTRFS_IOC_CLONE
387 #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
390 #ifndef BTRFS_IOC_CLONE_RANGE
391 #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
392 struct btrfs_ioctl_clone_range_args)
395 #ifndef BTRFS_IOC_SUBVOL_CREATE
396 #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
397 struct btrfs_ioctl_vol_args)
400 #ifndef BTRFS_IOC_SNAP_DESTROY
401 #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
402 struct btrfs_ioctl_vol_args)
405 #ifndef BTRFS_IOC_TREE_SEARCH
406 #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
407 struct btrfs_ioctl_search_args)
410 #ifndef BTRFS_IOC_INO_LOOKUP
411 #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
412 struct btrfs_ioctl_ino_lookup_args)
415 #ifndef BTRFS_IOC_SNAP_CREATE_V2
416 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
417 struct btrfs_ioctl_vol_args_v2)
420 #ifndef BTRFS_IOC_SUBVOL_GETFLAGS
421 #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
424 #ifndef BTRFS_IOC_SUBVOL_SETFLAGS
425 #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
428 #ifndef BTRFS_IOC_DEV_INFO
429 #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
430 struct btrfs_ioctl_dev_info_args)
433 #ifndef BTRFS_IOC_FS_INFO
434 #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
435 struct btrfs_ioctl_fs_info_args)
438 #ifndef BTRFS_IOC_DEVICES_READY
439 #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
440 struct btrfs_ioctl_vol_args)
443 #ifndef BTRFS_IOC_QUOTA_CTL
444 #define BTRFS_IOC_QUOTA_CTL _IOWR(BTRFS_IOCTL_MAGIC, 40, \
445 struct btrfs_ioctl_quota_ctl_args)
448 #ifndef BTRFS_IOC_QGROUP_LIMIT
449 #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \
450 struct btrfs_ioctl_qgroup_limit_args)
453 #ifndef BTRFS_FIRST_FREE_OBJECTID
454 #define BTRFS_FIRST_FREE_OBJECTID 256
457 #ifndef BTRFS_ROOT_TREE_OBJECTID
458 #define BTRFS_ROOT_TREE_OBJECTID 1
461 #ifndef BTRFS_QUOTA_TREE_OBJECTID
462 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
465 #ifndef BTRFS_ROOT_ITEM_KEY
466 #define BTRFS_ROOT_ITEM_KEY 132
469 #ifndef BTRFS_QGROUP_STATUS_KEY
470 #define BTRFS_QGROUP_STATUS_KEY 240
473 #ifndef BTRFS_QGROUP_INFO_KEY
474 #define BTRFS_QGROUP_INFO_KEY 242
477 #ifndef BTRFS_QGROUP_LIMIT_KEY
478 #define BTRFS_QGROUP_LIMIT_KEY 244
481 #ifndef BTRFS_SUPER_MAGIC
482 #define BTRFS_SUPER_MAGIC 0x9123683E
485 #ifndef CGROUP_SUPER_MAGIC
486 #define CGROUP_SUPER_MAGIC 0x27e0eb
490 #define TMPFS_MAGIC 0x01021994
498 #define MS_PRIVATE (1 << 18)
501 #if !HAVE_DECL_GETTID
502 static inline pid_t gettid(void) {
503 return (pid_t) syscall(SYS_gettid);
508 #define SCM_SECURITY 0x03
511 #ifndef MS_STRICTATIME
512 #define MS_STRICTATIME (1<<24)
520 #define MS_SHARED (1<<20)
523 #ifndef PR_SET_NO_NEW_PRIVS
524 #define PR_SET_NO_NEW_PRIVS 38
527 #ifndef PR_SET_CHILD_SUBREAPER
528 #define PR_SET_CHILD_SUBREAPER 36
531 #ifndef MAX_HANDLE_SZ
532 #define MAX_HANDLE_SZ 128
535 #ifndef __NR_name_to_handle_at
536 # if defined(__x86_64__)
537 # define __NR_name_to_handle_at 303
538 # elif defined(__i386__)
539 # define __NR_name_to_handle_at 341
540 # elif defined(__arm__)
541 # define __NR_name_to_handle_at 370
542 # elif defined(__powerpc__)
543 # define __NR_name_to_handle_at 345
545 # error "__NR_name_to_handle_at is not defined"
549 #if !HAVE_DECL_NAME_TO_HANDLE_AT
551 unsigned int handle_bytes;
553 unsigned char f_handle[0];
556 static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
557 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
561 #ifndef HAVE_SECURE_GETENV
562 # ifdef HAVE___SECURE_GETENV
563 # define secure_getenv __secure_getenv
565 # error "neither secure_getenv nor __secure_getenv are available"
569 #ifndef CIFS_MAGIC_NUMBER
570 # define CIFS_MAGIC_NUMBER 0xFF534D42
573 #ifndef TFD_TIMER_CANCEL_ON_SET
574 # define TFD_TIMER_CANCEL_ON_SET (1 << 1)
578 # define SO_REUSEPORT 15
582 # define EVIOCREVOKE _IOW('E', 0x91, int)
585 #ifndef DRM_IOCTL_SET_MASTER
586 # define DRM_IOCTL_SET_MASTER _IO('d', 0x1e)
589 #ifndef DRM_IOCTL_DROP_MASTER
590 # define DRM_IOCTL_DROP_MASTER _IO('d', 0x1f)
593 #if defined(__i386__) || defined(__x86_64__)
595 /* The precise definition of __O_TMPFILE is arch specific, so let's
596 * just define this on x86 where we know the value. */
599 #define __O_TMPFILE 020000000
602 /* a horrid kludge trying to make sure that this will fail on old kernels */
604 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
610 # if defined(__x86_64__)
611 # define __NR_setns 308
612 # elif defined(__i386__)
613 # define __NR_setns 346
615 # error "__NR_setns is not defined"
620 static inline int setns(int fd, int nstype) {
621 return syscall(__NR_setns, fd, nstype);
625 #if !HAVE_DECL_LO_FLAGS_PARTSCAN
626 #define LO_FLAGS_PARTSCAN 8
629 #ifndef LOOP_CTL_REMOVE
630 #define LOOP_CTL_REMOVE 0x4C81
633 #ifndef LOOP_CTL_GET_FREE
634 #define LOOP_CTL_GET_FREE 0x4C82
637 #if !HAVE_DECL_IFLA_INET6_ADDR_GEN_MODE
638 #define IFLA_INET6_UNSPEC 0
639 #define IFLA_INET6_FLAGS 1
640 #define IFLA_INET6_CONF 2
641 #define IFLA_INET6_STATS 3
642 #define IFLA_INET6_MCAST 4
643 #define IFLA_INET6_CACHEINFO 5
644 #define IFLA_INET6_ICMP6STATS 6
645 #define IFLA_INET6_TOKEN 7
646 #define IFLA_INET6_ADDR_GEN_MODE 8
647 #define __IFLA_INET6_MAX 9
649 #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
651 #define IN6_ADDR_GEN_MODE_EUI64 0
652 #define IN6_ADDR_GEN_MODE_NONE 1
655 #if !HAVE_DECL_IFLA_MACVLAN_FLAGS
656 #define IFLA_MACVLAN_UNSPEC 0
657 #define IFLA_MACVLAN_MODE 1
658 #define IFLA_MACVLAN_FLAGS 2
659 #define __IFLA_MACVLAN_MAX 3
661 #define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
664 #if !HAVE_DECL_IFLA_IPVLAN_MODE
665 #define IFLA_IPVLAN_UNSPEC 0
666 #define IFLA_IPVLAN_MODE 1
667 #define __IFLA_IPVLAN_MAX 2
669 #define IFLA_IPVLAN_MAX (__IFLA_IPVLAN_MAX - 1)
671 #define IPVLAN_MODE_L2 0
672 #define IPVLAN_MODE_L3 1
676 #if !HAVE_DECL_IFLA_VTI_REMOTE
677 #define IFLA_VTI_UNSPEC 0
678 #define IFLA_VTI_LINK 1
679 #define IFLA_VTI_IKEY 2
680 #define IFLA_VTI_OKEY 3
681 #define IFLA_VTI_LOCAL 4
682 #define IFLA_VTI_REMOTE 5
683 #define __IFLA_VTI_MAX 6
685 #define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1)
688 #if !HAVE_DECL_IFLA_PHYS_PORT_ID
689 #undef IFLA_PROMISCUITY
690 #define IFLA_PROMISCUITY 30
691 #define IFLA_NUM_TX_QUEUES 31
692 #define IFLA_NUM_RX_QUEUES 32
693 #define IFLA_CARRIER 33
694 #define IFLA_PHYS_PORT_ID 34
695 #define __IFLA_MAX 35
697 #define IFLA_MAX (__IFLA_MAX - 1)
700 #if !HAVE_DECL_IFLA_BOND_AD_INFO
701 #define IFLA_BOND_UNSPEC 0
702 #define IFLA_BOND_MODE 1
703 #define IFLA_BOND_ACTIVE_SLAVE 2
704 #define IFLA_BOND_MIIMON 3
705 #define IFLA_BOND_UPDELAY 4
706 #define IFLA_BOND_DOWNDELAY 5
707 #define IFLA_BOND_USE_CARRIER 6
708 #define IFLA_BOND_ARP_INTERVAL 7
709 #define IFLA_BOND_ARP_IP_TARGET 8
710 #define IFLA_BOND_ARP_VALIDATE 9
711 #define IFLA_BOND_ARP_ALL_TARGETS 10
712 #define IFLA_BOND_PRIMARY 11
713 #define IFLA_BOND_PRIMARY_RESELECT 12
714 #define IFLA_BOND_FAIL_OVER_MAC 13
715 #define IFLA_BOND_XMIT_HASH_POLICY 14
716 #define IFLA_BOND_RESEND_IGMP 15
717 #define IFLA_BOND_NUM_PEER_NOTIF 16
718 #define IFLA_BOND_ALL_SLAVES_ACTIVE 17
719 #define IFLA_BOND_MIN_LINKS 18
720 #define IFLA_BOND_LP_INTERVAL 19
721 #define IFLA_BOND_PACKETS_PER_SLAVE 20
722 #define IFLA_BOND_AD_LACP_RATE 21
723 #define IFLA_BOND_AD_SELECT 22
724 #define IFLA_BOND_AD_INFO 23
725 #define __IFLA_BOND_MAX 24
727 #define IFLA_BOND_MAX (__IFLA_BOND_MAX - 1)
730 #if !HAVE_DECL_IFLA_VLAN_PROTOCOL
731 #define IFLA_VLAN_UNSPEC 0
732 #define IFLA_VLAN_ID 1
733 #define IFLA_VLAN_FLAGS 2
734 #define IFLA_VLAN_EGRESS_QOS 3
735 #define IFLA_VLAN_INGRESS_QOS 4
736 #define IFLA_VLAN_PROTOCOL 5
737 #define __IFLA_VLAN_MAX 6
739 #define IFLA_VLAN_MAX (__IFLA_VLAN_MAX - 1)
742 #if !HAVE_DECL_IFLA_VXLAN_REMCSUM_NOPARTIAL
743 #define IFLA_VXLAN_UNSPEC 0
744 #define IFLA_VXLAN_ID 1
745 #define IFLA_VXLAN_GROUP 2
746 #define IFLA_VXLAN_LINK 3
747 #define IFLA_VXLAN_LOCAL 4
748 #define IFLA_VXLAN_TTL 5
749 #define IFLA_VXLAN_TOS 6
750 #define IFLA_VXLAN_LEARNING 7
751 #define IFLA_VXLAN_AGEING 8
752 #define IFLA_VXLAN_LIMIT 9
753 #define IFLA_VXLAN_PORT_RANGE 10
754 #define IFLA_VXLAN_PROXY 11
755 #define IFLA_VXLAN_RSC 12
756 #define IFLA_VXLAN_L2MISS 13
757 #define IFLA_VXLAN_L3MISS 14
758 #define IFLA_VXLAN_PORT 15
759 #define IFLA_VXLAN_GROUP6 16
760 #define IFLA_VXLAN_LOCAL6 17
761 #define IFLA_VXLAN_UDP_CSUM 18
762 #define IFLA_VXLAN_UDP_ZERO_CSUM6_TX 19
763 #define IFLA_VXLAN_UDP_ZERO_CSUM6_RX 20
764 #define IFLA_VXLAN_REMCSUM_TX 21
765 #define IFLA_VXLAN_REMCSUM_RX 22
766 #define IFLA_VXLAN_GBP 23
767 #define IFLA_VXLAN_REMCSUM_NOPARTIAL 24
768 #define __IFLA_VXLAN_MAX 25
770 #define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)
773 #if !HAVE_DECL_IFLA_IPTUN_ENCAP_DPORT
774 #define IFLA_IPTUN_UNSPEC 0
775 #define IFLA_IPTUN_LINK 1
776 #define IFLA_IPTUN_LOCAL 2
777 #define IFLA_IPTUN_REMOTE 3
778 #define IFLA_IPTUN_TTL 4
779 #define IFLA_IPTUN_TOS 5
780 #define IFLA_IPTUN_ENCAP_LIMIT 6
781 #define IFLA_IPTUN_FLOWINFO 7
782 #define IFLA_IPTUN_FLAGS 8
783 #define IFLA_IPTUN_PROTO 9
784 #define IFLA_IPTUN_PMTUDISC 10
785 #define IFLA_IPTUN_6RD_PREFIX 11
786 #define IFLA_IPTUN_6RD_RELAY_PREFIX 12
787 #define IFLA_IPTUN_6RD_PREFIXLEN 13
788 #define IFLA_IPTUN_6RD_RELAY_PREFIXLEN 14
789 #define IFLA_IPTUN_ENCAP_TYPE 15
790 #define IFLA_IPTUN_ENCAP_FLAGS 16
791 #define IFLA_IPTUN_ENCAP_SPORT 17
792 #define IFLA_IPTUN_ENCAP_DPORT 18
794 #define __IFLA_IPTUN_MAX 19
796 #define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1)
799 #if !HAVE_DECL_IFLA_GRE_ENCAP_DPORT
800 #define IFLA_GRE_UNSPEC 0
801 #define IFLA_GRE_LINK 1
802 #define IFLA_GRE_IFLAGS 2
803 #define IFLA_GRE_OFLAGS 3
804 #define IFLA_GRE_IKEY 4
805 #define IFLA_GRE_OKEY 5
806 #define IFLA_GRE_LOCAL 6
807 #define IFLA_GRE_REMOTE 7
808 #define IFLA_GRE_TTL 8
809 #define IFLA_GRE_TOS 9
810 #define IFLA_GRE_PMTUDISC 10
811 #define IFLA_GRE_ENCAP_LIMIT 11
812 #define IFLA_GRE_FLOWINFO 12
813 #define IFLA_GRE_FLAGS 13
814 #define IFLA_GRE_ENCAP_TYPE 14
815 #define IFLA_GRE_ENCAP_FLAGS 15
816 #define IFLA_GRE_ENCAP_SPORT 16
817 #define IFLA_GRE_ENCAP_DPORT 17
819 #define __IFLA_GRE_MAX 18
821 #define IFLA_GRE_MAX (__IFLA_GRE_MAX - 1)
824 #if !HAVE_DECL_IFLA_BRIDGE_VLAN_INFO
825 #define IFLA_BRIDGE_FLAGS 0
826 #define IFLA_BRIDGE_MODE 1
827 #define IFLA_BRIDGE_VLAN_INFO 2
828 #define __IFLA_BRIDGE_MAX 3
830 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
833 #if !HAVE_DECL_IFLA_BRPORT_LEARNING_SYNC
834 #define IFLA_BRPORT_UNSPEC 0
835 #define IFLA_BRPORT_STATE 1
836 #define IFLA_BRPORT_PRIORITY 2
837 #define IFLA_BRPORT_COST 3
838 #define IFLA_BRPORT_MODE 4
839 #define IFLA_BRPORT_GUARD 5
840 #define IFLA_BRPORT_PROTECT 6
841 #define IFLA_BRPORT_FAST_LEAVE 7
842 #define IFLA_BRPORT_LEARNING 8
843 #define IFLA_BRPORT_UNICAST_FLOOD 9
844 #define IFLA_BRPORT_PROXYARP 10
845 #define IFLA_BRPORT_LEARNING_SYNC 11
846 #define __IFLA_BRPORT_MAX 12
848 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
851 #if !HAVE_DECL_NDA_IFINDEX
855 #define NDA_CACHEINFO 3
860 #define NDA_IFINDEX 8
863 #define NDA_MAX (__NDA_MAX - 1)
866 #ifndef IPV6_UNICAST_IF
867 #define IPV6_UNICAST_IF 76
870 #ifndef IFF_MULTI_QUEUE
871 #define IFF_MULTI_QUEUE 0x100
875 #define IFF_LOWER_UP 0x10000
879 #define IFF_DORMANT 0x20000
882 #ifndef BOND_XMIT_POLICY_ENCAP23
883 #define BOND_XMIT_POLICY_ENCAP23 3
886 #ifndef BOND_XMIT_POLICY_ENCAP34
887 #define BOND_XMIT_POLICY_ENCAP34 4
890 #ifndef NET_ADDR_RANDOM
891 # define NET_ADDR_RANDOM 1
894 #ifndef NET_NAME_UNKNOWN
895 # define NET_NAME_UNKNOWN 0
898 #ifndef NET_NAME_ENUM
899 # define NET_NAME_ENUM 1
902 #ifndef NET_NAME_PREDICTABLE
903 # define NET_NAME_PREDICTABLE 2
906 #ifndef NET_NAME_USER
907 # define NET_NAME_USER 3
910 #ifndef NET_NAME_RENAMED
911 # define NET_NAME_RENAMED 4
915 # define BPF_XOR 0xa0
918 /* Note that LOOPBACK_IFINDEX is currently not exported by the
919 * kernel/glibc, but hardcoded internally by the kernel. However, as
920 * it is exported to userspace indirectly via rtnetlink and the
921 * ioctls, and made use of widely we define it here too, in a way that
922 * is compatible with the kernel's internal definition. */
923 #ifndef LOOPBACK_IFINDEX
924 #define LOOPBACK_IFINDEX 1
927 #ifndef MAX_AUDIT_MESSAGE_LENGTH
928 #define MAX_AUDIT_MESSAGE_LENGTH 8970
931 #ifndef AUDIT_NLGRP_MAX
932 #define AUDIT_NLGRP_READLOG 1
935 #ifndef CAP_MAC_OVERRIDE
936 #define CAP_MAC_OVERRIDE 32
939 #ifndef CAP_MAC_ADMIN
940 #define CAP_MAC_ADMIN 33
944 #define CAP_SYSLOG 34
947 #ifndef CAP_WAKE_ALARM
948 #define CAP_WAKE_ALARM 35
951 #ifndef CAP_BLOCK_SUSPEND
952 #define CAP_BLOCK_SUSPEND 36
955 #ifndef CAP_AUDIT_READ
956 #define CAP_AUDIT_READ 37
959 static inline int raw_clone(unsigned long flags, void *child_stack) {
960 #if defined(__s390__) || defined(__CRIS__)
961 /* On s390 and cris the order of the first and second arguments
962 * of the raw clone() system call is reversed. */
963 return (int) syscall(__NR_clone, child_stack, flags);
965 return (int) syscall(__NR_clone, flags, child_stack);
969 static inline pid_t raw_getpid(void) {
970 #if defined(__alpha__)
971 return (pid_t) syscall(__NR_getxpid);
973 return (pid_t) syscall(__NR_getpid);
977 #if !HAVE_DECL_RENAMEAT2
979 #ifndef __NR_renameat2
980 # if defined __x86_64__
981 # define __NR_renameat2 316
982 # elif defined __arm__
983 # define __NR_renameat2 382
984 # elif defined _MIPS_SIM
985 # if _MIPS_SIM == _MIPS_SIM_ABI32
986 # define __NR_renameat2 4351
988 # if _MIPS_SIM == _MIPS_SIM_NABI32
989 # define __NR_renameat2 6315
991 # if _MIPS_SIM == _MIPS_SIM_ABI64
992 # define __NR_renameat2 5311
994 # elif defined __i386__
995 # define __NR_renameat2 353
997 # warning "__NR_renameat2 unknown for your architecture"
998 # define __NR_renameat2 0xffffffff
1002 static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
1003 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
1007 #ifndef RENAME_NOREPLACE
1008 #define RENAME_NOREPLACE (1 << 0)