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>
41 #include <asm/sgidefs.h>
44 #ifdef HAVE_LINUX_BTRFS_H
45 #include <linux/btrfs.h>
51 #define RLIMIT_RTTIME 15
54 /* If RLIMIT_RTTIME is not defined, then we cannot use RLIMIT_NLIMITS as is */
55 #define _RLIMIT_MAX (RLIMIT_RTTIME+1 > RLIMIT_NLIMITS ? RLIMIT_RTTIME+1 : RLIMIT_NLIMITS)
57 #ifndef F_LINUX_SPECIFIC_BASE
58 #define F_LINUX_SPECIFIC_BASE 1024
62 #define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
66 #define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)
70 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
71 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
73 #define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
74 #define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
75 #define F_SEAL_GROW 0x0004 /* prevent file from growing */
76 #define F_SEAL_WRITE 0x0008 /* prevent writes */
80 #define F_OFD_GETLK 36
81 #define F_OFD_SETLK 37
82 #define F_OFD_SETLKW 38
85 #ifndef MFD_ALLOW_SEALING
86 #define MFD_ALLOW_SEALING 0x0002U
90 #define MFD_CLOEXEC 0x0001U
94 #define IP_FREEBIND 15
97 #ifndef OOM_SCORE_ADJ_MIN
98 #define OOM_SCORE_ADJ_MIN (-1000)
101 #ifndef OOM_SCORE_ADJ_MAX
102 #define OOM_SCORE_ADJ_MAX 1000
105 #ifndef AUDIT_SERVICE_START
106 #define AUDIT_SERVICE_START 1130 /* Service (daemon) start */
109 #ifndef AUDIT_SERVICE_STOP
110 #define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */
114 #define TIOCVHANGUP 0x5437
117 #ifndef IP_TRANSPARENT
118 #define IP_TRANSPARENT 19
122 #define SOL_NETLINK 270
125 #if !HAVE_DECL_PIVOT_ROOT
126 static inline int pivot_root(const char *new_root, const char *put_old) {
127 return syscall(SYS_pivot_root, new_root, put_old);
131 #ifndef __NR_memfd_create
132 # if defined __x86_64__
133 # define __NR_memfd_create 319
134 # elif defined __arm__
135 # define __NR_memfd_create 385
136 # elif defined __aarch64__
137 # define __NR_memfd_create 279
138 # elif defined _MIPS_SIM
139 # if _MIPS_SIM == _MIPS_SIM_ABI32
140 # define __NR_memfd_create 4354
142 # if _MIPS_SIM == _MIPS_SIM_NABI32
143 # define __NR_memfd_create 6318
145 # if _MIPS_SIM == _MIPS_SIM_ABI64
146 # define __NR_memfd_create 5314
148 # elif defined __i386__
149 # define __NR_memfd_create 356
151 # warning "__NR_memfd_create unknown for your architecture"
152 # define __NR_memfd_create 0xffffffff
156 #ifndef HAVE_MEMFD_CREATE
157 static inline int memfd_create(const char *name, unsigned int flags) {
158 return syscall(__NR_memfd_create, name, flags);
162 #ifndef __NR_getrandom
163 # if defined __x86_64__
164 # define __NR_getrandom 318
165 # elif defined(__i386__)
166 # define __NR_getrandom 355
167 # elif defined(__arm__)
168 # define __NR_getrandom 384
169 # elif defined(__aarch64__)
170 # define __NR_getrandom 278
171 # elif defined(__ia64__)
172 # define __NR_getrandom 1339
173 # elif defined(__m68k__)
174 # define __NR_getrandom 352
175 # elif defined(__s390x__)
176 # define __NR_getrandom 349
177 # elif defined(__powerpc__)
178 # define __NR_getrandom 359
179 # elif defined _MIPS_SIM
180 # if _MIPS_SIM == _MIPS_SIM_ABI32
181 # define __NR_getrandom 4353
183 # if _MIPS_SIM == _MIPS_SIM_NABI32
184 # define __NR_getrandom 6317
186 # if _MIPS_SIM == _MIPS_SIM_ABI64
187 # define __NR_getrandom 5313
190 # warning "__NR_getrandom unknown for your architecture"
191 # define __NR_getrandom 0xffffffff
195 #if !HAVE_DECL_GETRANDOM
196 static inline int getrandom(void *buffer, size_t count, unsigned flags) {
197 return syscall(__NR_getrandom, buffer, count, flags);
201 #ifndef GRND_NONBLOCK
202 #define GRND_NONBLOCK 0x0001
206 #define GRND_RANDOM 0x0002
209 #ifndef BTRFS_IOCTL_MAGIC
210 #define BTRFS_IOCTL_MAGIC 0x94
213 #ifndef BTRFS_PATH_NAME_MAX
214 #define BTRFS_PATH_NAME_MAX 4087
217 #ifndef BTRFS_DEVICE_PATH_NAME_MAX
218 #define BTRFS_DEVICE_PATH_NAME_MAX 1024
221 #ifndef BTRFS_FSID_SIZE
222 #define BTRFS_FSID_SIZE 16
225 #ifndef BTRFS_UUID_SIZE
226 #define BTRFS_UUID_SIZE 16
229 #ifndef BTRFS_SUBVOL_RDONLY
230 #define BTRFS_SUBVOL_RDONLY (1ULL << 1)
233 #ifndef BTRFS_SUBVOL_NAME_MAX
234 #define BTRFS_SUBVOL_NAME_MAX 4039
237 #ifndef BTRFS_INO_LOOKUP_PATH_MAX
238 #define BTRFS_INO_LOOKUP_PATH_MAX 4080
241 #ifndef BTRFS_SEARCH_ARGS_BUFSIZE
242 #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
245 #ifndef HAVE_LINUX_BTRFS_H
246 struct btrfs_ioctl_vol_args {
248 char name[BTRFS_PATH_NAME_MAX + 1];
251 struct btrfs_qgroup_limit {
259 struct btrfs_qgroup_inherit {
262 __u64 num_ref_copies;
263 __u64 num_excl_copies;
264 struct btrfs_qgroup_limit lim;
268 struct btrfs_ioctl_vol_args_v2 {
275 struct btrfs_qgroup_inherit *qgroup_inherit;
279 char name[BTRFS_SUBVOL_NAME_MAX + 1];
282 struct btrfs_ioctl_dev_info_args {
283 uint64_t devid; /* in/out */
284 uint8_t uuid[BTRFS_UUID_SIZE]; /* in/out */
285 uint64_t bytes_used; /* out */
286 uint64_t total_bytes; /* out */
287 uint64_t unused[379]; /* pad to 4k */
288 char path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */
291 struct btrfs_ioctl_fs_info_args {
292 uint64_t max_id; /* out */
293 uint64_t num_devices; /* out */
294 uint8_t fsid[BTRFS_FSID_SIZE]; /* out */
295 uint64_t reserved[124]; /* pad to 1k */
298 struct btrfs_ioctl_ino_lookup_args {
301 char name[BTRFS_INO_LOOKUP_PATH_MAX];
304 struct btrfs_ioctl_search_key {
305 /* which root are we searching. 0 is the tree of tree roots */
308 /* keys returned will be >= min and <= max */
312 /* keys returned will be >= min and <= max */
316 /* max and min transids to search for */
320 /* keys returned will be >= min and <= max */
325 * how many items did userland ask for, and how many are we
330 /* align to 64 bits */
333 /* some extra for later */
340 struct btrfs_ioctl_search_header {
349 struct btrfs_ioctl_search_args {
350 struct btrfs_ioctl_search_key key;
351 char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
354 struct btrfs_ioctl_clone_range_args {
356 __u64 src_offset, src_length;
361 #ifndef BTRFS_IOC_DEFRAG
362 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
363 struct btrfs_ioctl_vol_args)
366 #ifndef BTRFS_IOC_CLONE
367 #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
370 #ifndef BTRFS_IOC_CLONE_RANGE
371 #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
372 struct btrfs_ioctl_clone_range_args)
375 #ifndef BTRFS_IOC_SUBVOL_CREATE
376 #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
377 struct btrfs_ioctl_vol_args)
380 #ifndef BTRFS_IOC_SNAP_DESTROY
381 #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
382 struct btrfs_ioctl_vol_args)
385 #ifndef BTRFS_IOC_TREE_SEARCH
386 #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
387 struct btrfs_ioctl_search_args)
390 #ifndef BTRFS_IOC_INO_LOOKUP
391 #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
392 struct btrfs_ioctl_ino_lookup_args)
395 #ifndef BTRFS_IOC_SNAP_CREATE_V2
396 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
397 struct btrfs_ioctl_vol_args_v2)
400 #ifndef BTRFS_IOC_SUBVOL_GETFLAGS
401 #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
404 #ifndef BTRFS_IOC_SUBVOL_SETFLAGS
405 #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
408 #ifndef BTRFS_IOC_DEV_INFO
409 #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
410 struct btrfs_ioctl_dev_info_args)
413 #ifndef BTRFS_IOC_FS_INFO
414 #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
415 struct btrfs_ioctl_fs_info_args)
418 #ifndef BTRFS_IOC_DEVICES_READY
419 #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
420 struct btrfs_ioctl_vol_args)
423 #ifndef BTRFS_FIRST_FREE_OBJECTID
424 #define BTRFS_FIRST_FREE_OBJECTID 256
427 #ifndef BTRFS_LAST_FREE_OBJECTID
428 #define BTRFS_LAST_FREE_OBJECTID -256ULL
431 #ifndef BTRFS_ROOT_TREE_OBJECTID
432 #define BTRFS_ROOT_TREE_OBJECTID 1
435 #ifndef BTRFS_QUOTA_TREE_OBJECTID
436 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
439 #ifndef BTRFS_ROOT_ITEM_KEY
440 #define BTRFS_ROOT_ITEM_KEY 132
443 #ifndef BTRFS_QGROUP_STATUS_KEY
444 #define BTRFS_QGROUP_STATUS_KEY 240
447 #ifndef BTRFS_QGROUP_INFO_KEY
448 #define BTRFS_QGROUP_INFO_KEY 242
451 #ifndef BTRFS_QGROUP_LIMIT_KEY
452 #define BTRFS_QGROUP_LIMIT_KEY 244
455 #ifndef BTRFS_ROOT_BACKREF_KEY
456 #define BTRFS_ROOT_BACKREF_KEY 144
459 #ifndef BTRFS_SUPER_MAGIC
460 #define BTRFS_SUPER_MAGIC 0x9123683E
468 #define MS_PRIVATE (1 << 18)
471 #if !HAVE_DECL_GETTID
472 static inline pid_t gettid(void) {
473 return (pid_t) syscall(SYS_gettid);
478 #define SCM_SECURITY 0x03
481 #ifndef MS_STRICTATIME
482 #define MS_STRICTATIME (1<<24)
490 #define MS_SHARED (1<<20)
493 #ifndef PR_SET_NO_NEW_PRIVS
494 #define PR_SET_NO_NEW_PRIVS 38
497 #ifndef PR_SET_CHILD_SUBREAPER
498 #define PR_SET_CHILD_SUBREAPER 36
501 #ifndef MAX_HANDLE_SZ
502 #define MAX_HANDLE_SZ 128
505 #ifndef __NR_name_to_handle_at
506 # if defined(__x86_64__)
507 # define __NR_name_to_handle_at 303
508 # elif defined(__i386__)
509 # define __NR_name_to_handle_at 341
510 # elif defined(__arm__)
511 # define __NR_name_to_handle_at 370
512 # elif defined(__powerpc__)
513 # define __NR_name_to_handle_at 345
515 # error "__NR_name_to_handle_at is not defined"
519 #if !HAVE_DECL_NAME_TO_HANDLE_AT
521 unsigned int handle_bytes;
523 unsigned char f_handle[0];
526 static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
527 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
531 #ifndef HAVE_SECURE_GETENV
532 # ifdef HAVE___SECURE_GETENV
533 # define secure_getenv __secure_getenv
535 # error "neither secure_getenv nor __secure_getenv are available"
539 #ifndef CIFS_MAGIC_NUMBER
540 # define CIFS_MAGIC_NUMBER 0xFF534D42
543 #ifndef TFD_TIMER_CANCEL_ON_SET
544 # define TFD_TIMER_CANCEL_ON_SET (1 << 1)
548 # define SO_REUSEPORT 15
552 # define EVIOCREVOKE _IOW('E', 0x91, int)
555 #ifndef DRM_IOCTL_SET_MASTER
556 # define DRM_IOCTL_SET_MASTER _IO('d', 0x1e)
559 #ifndef DRM_IOCTL_DROP_MASTER
560 # define DRM_IOCTL_DROP_MASTER _IO('d', 0x1f)
563 #if defined(__i386__) || defined(__x86_64__)
565 /* The precise definition of __O_TMPFILE is arch specific, so let's
566 * just define this on x86 where we know the value. */
569 #define __O_TMPFILE 020000000
572 /* a horrid kludge trying to make sure that this will fail on old kernels */
574 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
580 # if defined(__x86_64__)
581 # define __NR_setns 308
582 # elif defined(__i386__)
583 # define __NR_setns 346
585 # error "__NR_setns is not defined"
590 static inline int setns(int fd, int nstype) {
591 return syscall(__NR_setns, fd, nstype);
595 #if !HAVE_DECL_LO_FLAGS_PARTSCAN
596 #define LO_FLAGS_PARTSCAN 8
599 #ifndef LOOP_CTL_REMOVE
600 #define LOOP_CTL_REMOVE 0x4C81
603 #ifndef LOOP_CTL_GET_FREE
604 #define LOOP_CTL_GET_FREE 0x4C82
607 #if !HAVE_DECL_IFLA_INET6_ADDR_GEN_MODE
608 #define IFLA_INET6_UNSPEC 0
609 #define IFLA_INET6_FLAGS 1
610 #define IFLA_INET6_CONF 2
611 #define IFLA_INET6_STATS 3
612 #define IFLA_INET6_MCAST 4
613 #define IFLA_INET6_CACHEINFO 5
614 #define IFLA_INET6_ICMP6STATS 6
615 #define IFLA_INET6_TOKEN 7
616 #define IFLA_INET6_ADDR_GEN_MODE 8
617 #define __IFLA_INET6_MAX 9
619 #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
621 #define IN6_ADDR_GEN_MODE_EUI64 0
622 #define IN6_ADDR_GEN_MODE_NONE 1
625 #if !HAVE_DECL_IFLA_MACVLAN_FLAGS
626 #define IFLA_MACVLAN_UNSPEC 0
627 #define IFLA_MACVLAN_MODE 1
628 #define IFLA_MACVLAN_FLAGS 2
629 #define __IFLA_MACVLAN_MAX 3
631 #define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
634 #if !HAVE_DECL_IFLA_IPVLAN_MODE
635 #define IFLA_IPVLAN_UNSPEC 0
636 #define IFLA_IPVLAN_MODE 1
637 #define __IFLA_IPVLAN_MAX 2
639 #define IFLA_IPVLAN_MAX (__IFLA_IPVLAN_MAX - 1)
641 #define IPVLAN_MODE_L2 0
642 #define IPVLAN_MODE_L3 1
646 #if !HAVE_DECL_IFLA_VTI_REMOTE
647 #define IFLA_VTI_UNSPEC 0
648 #define IFLA_VTI_LINK 1
649 #define IFLA_VTI_IKEY 2
650 #define IFLA_VTI_OKEY 3
651 #define IFLA_VTI_LOCAL 4
652 #define IFLA_VTI_REMOTE 5
653 #define __IFLA_VTI_MAX 6
655 #define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1)
658 #if !HAVE_DECL_IFLA_PHYS_PORT_ID
659 #undef IFLA_PROMISCUITY
660 #define IFLA_PROMISCUITY 30
661 #define IFLA_NUM_TX_QUEUES 31
662 #define IFLA_NUM_RX_QUEUES 32
663 #define IFLA_CARRIER 33
664 #define IFLA_PHYS_PORT_ID 34
665 #define __IFLA_MAX 35
667 #define IFLA_MAX (__IFLA_MAX - 1)
670 #if !HAVE_DECL_IFLA_BOND_AD_INFO
671 #define IFLA_BOND_UNSPEC 0
672 #define IFLA_BOND_MODE 1
673 #define IFLA_BOND_ACTIVE_SLAVE 2
674 #define IFLA_BOND_MIIMON 3
675 #define IFLA_BOND_UPDELAY 4
676 #define IFLA_BOND_DOWNDELAY 5
677 #define IFLA_BOND_USE_CARRIER 6
678 #define IFLA_BOND_ARP_INTERVAL 7
679 #define IFLA_BOND_ARP_IP_TARGET 8
680 #define IFLA_BOND_ARP_VALIDATE 9
681 #define IFLA_BOND_ARP_ALL_TARGETS 10
682 #define IFLA_BOND_PRIMARY 11
683 #define IFLA_BOND_PRIMARY_RESELECT 12
684 #define IFLA_BOND_FAIL_OVER_MAC 13
685 #define IFLA_BOND_XMIT_HASH_POLICY 14
686 #define IFLA_BOND_RESEND_IGMP 15
687 #define IFLA_BOND_NUM_PEER_NOTIF 16
688 #define IFLA_BOND_ALL_SLAVES_ACTIVE 17
689 #define IFLA_BOND_MIN_LINKS 18
690 #define IFLA_BOND_LP_INTERVAL 19
691 #define IFLA_BOND_PACKETS_PER_SLAVE 20
692 #define IFLA_BOND_AD_LACP_RATE 21
693 #define IFLA_BOND_AD_SELECT 22
694 #define IFLA_BOND_AD_INFO 23
695 #define __IFLA_BOND_MAX 24
697 #define IFLA_BOND_MAX (__IFLA_BOND_MAX - 1)
700 #if !HAVE_DECL_IFLA_VLAN_PROTOCOL
701 #define IFLA_VLAN_UNSPEC 0
702 #define IFLA_VLAN_ID 1
703 #define IFLA_VLAN_FLAGS 2
704 #define IFLA_VLAN_EGRESS_QOS 3
705 #define IFLA_VLAN_INGRESS_QOS 4
706 #define IFLA_VLAN_PROTOCOL 5
707 #define __IFLA_VLAN_MAX 6
709 #define IFLA_VLAN_MAX (__IFLA_VLAN_MAX - 1)
712 #if !HAVE_DECL_IFLA_VXLAN_LOCAL6
713 #define IFLA_VXLAN_UNSPEC 0
714 #define IFLA_VXLAN_ID 1
715 #define IFLA_VXLAN_GROUP 2
716 #define IFLA_VXLAN_LINK 3
717 #define IFLA_VXLAN_LOCAL 4
718 #define IFLA_VXLAN_TTL 5
719 #define IFLA_VXLAN_TOS 6
720 #define IFLA_VXLAN_LEARNING 7
721 #define IFLA_VXLAN_AGEING 8
722 #define IFLA_VXLAN_LIMIT 9
723 #define IFLA_VXLAN_PORT_RANGE 10
724 #define IFLA_VXLAN_PROXY 11
725 #define IFLA_VXLAN_RSC 12
726 #define IFLA_VXLAN_L2MISS 13
727 #define IFLA_VXLAN_L3MISS 14
728 #define IFLA_VXLAN_PORT 15
729 #define IFLA_VXLAN_GROUP6 16
730 #define IFLA_VXLAN_LOCAL6 17
731 #define __IFLA_VXLAN_MAX 18
733 #define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)
736 #if !HAVE_DECL_IFLA_IPTUN_6RD_RELAY_PREFIXLEN
737 #define IFLA_IPTUN_UNSPEC 0
738 #define IFLA_IPTUN_LINK 1
739 #define IFLA_IPTUN_LOCAL 2
740 #define IFLA_IPTUN_REMOTE 3
741 #define IFLA_IPTUN_TTL 4
742 #define IFLA_IPTUN_TOS 5
743 #define IFLA_IPTUN_ENCAP_LIMIT 6
744 #define IFLA_IPTUN_FLOWINFO 7
745 #define IFLA_IPTUN_FLAGS 8
746 #define IFLA_IPTUN_PROTO 9
747 #define IFLA_IPTUN_PMTUDISC 10
748 #define IFLA_IPTUN_6RD_PREFIX 11
749 #define IFLA_IPTUN_6RD_RELAY_PREFIX 12
750 #define IFLA_IPTUN_6RD_PREFIXLEN 13
751 #define IFLA_IPTUN_6RD_RELAY_PREFIXLEN 14
752 #define __IFLA_IPTUN_MAX 15
754 #define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1)
757 #if !HAVE_DECL_IFLA_BRIDGE_VLAN_INFO
758 #define IFLA_BRIDGE_FLAGS 0
759 #define IFLA_BRIDGE_MODE 1
760 #define IFLA_BRIDGE_VLAN_INFO 2
761 #define __IFLA_BRIDGE_MAX 3
763 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
766 #if !HAVE_DECL_IFLA_BRPORT_UNICAST_FLOOD
767 #define IFLA_BRPORT_UNSPEC 0
768 #define IFLA_BRPORT_STATE 1
769 #define IFLA_BRPORT_PRIORITY 2
770 #define IFLA_BRPORT_COST 3
771 #define IFLA_BRPORT_MODE 4
772 #define IFLA_BRPORT_GUARD 5
773 #define IFLA_BRPORT_PROTECT 6
774 #define IFLA_BRPORT_FAST_LEAVE 7
775 #define IFLA_BRPORT_LEARNING 8
776 #define IFLA_BRPORT_UNICAST_FLOOD 9
777 #define __IFLA_BRPORT_MAX 10
779 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
782 #if !HAVE_DECL_NDA_IFINDEX
786 #define NDA_CACHEINFO 3
791 #define NDA_IFINDEX 8
794 #define NDA_MAX (__NDA_MAX - 1)
797 #ifndef IPV6_UNICAST_IF
798 #define IPV6_UNICAST_IF 76
801 #ifndef IFF_MULTI_QUEUE
802 #define IFF_MULTI_QUEUE 0x100
806 #define IFF_LOWER_UP 0x10000
810 #define IFF_DORMANT 0x20000
813 #ifndef BOND_XMIT_POLICY_ENCAP23
814 #define BOND_XMIT_POLICY_ENCAP23 3
817 #ifndef BOND_XMIT_POLICY_ENCAP34
818 #define BOND_XMIT_POLICY_ENCAP34 4
821 #ifndef NET_ADDR_RANDOM
822 # define NET_ADDR_RANDOM 1
825 #ifndef NET_NAME_UNKNOWN
826 # define NET_NAME_UNKNOWN 0
829 #ifndef NET_NAME_ENUM
830 # define NET_NAME_ENUM 1
833 #ifndef NET_NAME_PREDICTABLE
834 # define NET_NAME_PREDICTABLE 2
837 #ifndef NET_NAME_USER
838 # define NET_NAME_USER 3
841 #ifndef NET_NAME_RENAMED
842 # define NET_NAME_RENAMED 4
846 # define BPF_XOR 0xa0
849 /* Note that LOOPBACK_IFINDEX is currently not exported by the
850 * kernel/glibc, but hardcoded internally by the kernel. However, as
851 * it is exported to userspace indirectly via rtnetlink and the
852 * ioctls, and made use of widely we define it here too, in a way that
853 * is compatible with the kernel's internal definition. */
854 #ifndef LOOPBACK_IFINDEX
855 #define LOOPBACK_IFINDEX 1
858 #if !HAVE_DECL_IFA_FLAGS
862 #ifndef IFA_F_NOPREFIXROUTE
863 #define IFA_F_NOPREFIXROUTE 0x200
866 #ifndef MAX_AUDIT_MESSAGE_LENGTH
867 #define MAX_AUDIT_MESSAGE_LENGTH 8970
870 #ifndef AUDIT_NLGRP_MAX
871 #define AUDIT_NLGRP_READLOG 1
874 #ifndef CAP_MAC_OVERRIDE
875 #define CAP_MAC_OVERRIDE 32
878 #ifndef CAP_MAC_ADMIN
879 #define CAP_MAC_ADMIN 33
883 #define CAP_SYSLOG 34
886 #ifndef CAP_WAKE_ALARM
887 #define CAP_WAKE_ALARM 35
890 #ifndef CAP_BLOCK_SUSPEND
891 #define CAP_BLOCK_SUSPEND 36
894 #ifndef CAP_AUDIT_READ
895 #define CAP_AUDIT_READ 37
898 static inline int raw_clone(unsigned long flags, void *child_stack) {
899 #if defined(__s390__) || defined(__CRIS__)
900 /* On s390 and cris the order of the first and second arguments
901 * of the raw clone() system call is reversed. */
902 return (int) syscall(__NR_clone, child_stack, flags);
904 return (int) syscall(__NR_clone, flags, child_stack);
908 static inline pid_t raw_getpid(void) {
909 return (pid_t) syscall(__NR_getpid);
912 #if !HAVE_DECL_RENAMEAT2
914 #ifndef __NR_renameat2
915 # if defined __x86_64__
916 # define __NR_renameat2 316
917 # elif defined __arm__
918 # define __NR_renameat2 382
919 # elif defined _MIPS_SIM
920 # if _MIPS_SIM == _MIPS_SIM_ABI32
921 # define __NR_renameat2 4351
923 # if _MIPS_SIM == _MIPS_SIM_NABI32
924 # define __NR_renameat2 6315
926 # if _MIPS_SIM == _MIPS_SIM_ABI64
927 # define __NR_renameat2 5311
929 # elif defined __i386__
930 # define __NR_renameat2 353
932 # warning "__NR_renameat2 unknown for your architecture"
933 # define __NR_renameat2 0xffffffff
937 static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
938 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
942 #ifndef RENAME_NOREPLACE
943 #define RENAME_NOREPLACE (1 << 0)
947 #ifndef INPUT_PROP_POINTING_STICK
948 #define INPUT_PROP_POINTING_STICK 0x05
951 #ifndef INPUT_PROP_ACCELEROMETER
952 #define INPUT_PROP_ACCELEROMETER 0x06