chiark / gitweb /
util: rework rm_rf() logic
[elogind.git] / src / shared / missing.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2010 Lennart Poettering
9
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.
14
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.
19
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/>.
22 ***/
23
24 /* Missing glibc definitions to access certain kernel APIs */
25
26 #include <sys/resource.h>
27 #include <sys/syscall.h>
28 #include <fcntl.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <errno.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>
39
40 #ifdef ARCH_MIPS
41 #include <asm/sgidefs.h>
42 #endif
43
44 #ifdef HAVE_LINUX_BTRFS_H
45 #include <linux/btrfs.h>
46 #endif
47
48 #include "macro.h"
49
50 #ifndef RLIMIT_RTTIME
51 #define RLIMIT_RTTIME 15
52 #endif
53
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)
56
57 #ifndef F_LINUX_SPECIFIC_BASE
58 #define F_LINUX_SPECIFIC_BASE 1024
59 #endif
60
61 #ifndef F_SETPIPE_SZ
62 #define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
63 #endif
64
65 #ifndef F_GETPIPE_SZ
66 #define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)
67 #endif
68
69 #ifndef F_ADD_SEALS
70 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
71 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
72
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 */
77 #endif
78
79 #ifndef F_OFD_GETLK
80 #define F_OFD_GETLK     36
81 #define F_OFD_SETLK     37
82 #define F_OFD_SETLKW    38
83 #endif
84
85 #ifndef MFD_ALLOW_SEALING
86 #define MFD_ALLOW_SEALING 0x0002U
87 #endif
88
89 #ifndef MFD_CLOEXEC
90 #define MFD_CLOEXEC 0x0001U
91 #endif
92
93 #ifndef IP_FREEBIND
94 #define IP_FREEBIND 15
95 #endif
96
97 #ifndef OOM_SCORE_ADJ_MIN
98 #define OOM_SCORE_ADJ_MIN (-1000)
99 #endif
100
101 #ifndef OOM_SCORE_ADJ_MAX
102 #define OOM_SCORE_ADJ_MAX 1000
103 #endif
104
105 #ifndef AUDIT_SERVICE_START
106 #define AUDIT_SERVICE_START 1130 /* Service (daemon) start */
107 #endif
108
109 #ifndef AUDIT_SERVICE_STOP
110 #define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */
111 #endif
112
113 #ifndef TIOCVHANGUP
114 #define TIOCVHANGUP 0x5437
115 #endif
116
117 #ifndef IP_TRANSPARENT
118 #define IP_TRANSPARENT 19
119 #endif
120
121 #ifndef SOL_NETLINK
122 #define SOL_NETLINK 270
123 #endif
124
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);
128 }
129 #endif
130
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
141 #    endif
142 #    if _MIPS_SIM == _MIPS_SIM_NABI32
143 #      define __NR_memfd_create 6318
144 #    endif
145 #    if _MIPS_SIM == _MIPS_SIM_ABI64
146 #      define __NR_memfd_create 5314
147 #    endif
148 #  elif defined __i386__
149 #    define __NR_memfd_create 356
150 #  else
151 #    warning "__NR_memfd_create unknown for your architecture"
152 #    define __NR_memfd_create 0xffffffff
153 #  endif
154 #endif
155
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);
159 }
160 #endif
161
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
182 #    endif
183 #    if _MIPS_SIM == _MIPS_SIM_NABI32
184 #      define __NR_getrandom 6317
185 #    endif
186 #    if _MIPS_SIM == _MIPS_SIM_ABI64
187 #      define __NR_getrandom 5313
188 #    endif
189 #  else
190 #    warning "__NR_getrandom unknown for your architecture"
191 #    define __NR_getrandom 0xffffffff
192 #  endif
193 #endif
194
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);
198 }
199 #endif
200
201 #ifndef GRND_NONBLOCK
202 #define GRND_NONBLOCK 0x0001
203 #endif
204
205 #ifndef GRND_RANDOM
206 #define GRND_RANDOM 0x0002
207 #endif
208
209 #ifndef BTRFS_IOCTL_MAGIC
210 #define BTRFS_IOCTL_MAGIC 0x94
211 #endif
212
213 #ifndef BTRFS_PATH_NAME_MAX
214 #define BTRFS_PATH_NAME_MAX 4087
215 #endif
216
217 #ifndef BTRFS_DEVICE_PATH_NAME_MAX
218 #define BTRFS_DEVICE_PATH_NAME_MAX 1024
219 #endif
220
221 #ifndef BTRFS_FSID_SIZE
222 #define BTRFS_FSID_SIZE 16
223 #endif
224
225 #ifndef BTRFS_UUID_SIZE
226 #define BTRFS_UUID_SIZE 16
227 #endif
228
229 #ifndef BTRFS_SUBVOL_RDONLY
230 #define BTRFS_SUBVOL_RDONLY (1ULL << 1)
231 #endif
232
233 #ifndef BTRFS_SUBVOL_NAME_MAX
234 #define BTRFS_SUBVOL_NAME_MAX 4039
235 #endif
236
237 #ifndef BTRFS_INO_LOOKUP_PATH_MAX
238 #define BTRFS_INO_LOOKUP_PATH_MAX 4080
239 #endif
240
241 #ifndef BTRFS_SEARCH_ARGS_BUFSIZE
242 #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
243 #endif
244
245 #ifndef HAVE_LINUX_BTRFS_H
246 struct btrfs_ioctl_vol_args {
247         int64_t fd;
248         char name[BTRFS_PATH_NAME_MAX + 1];
249 };
250
251 struct btrfs_qgroup_limit {
252         __u64 flags;
253         __u64 max_rfer;
254         __u64 max_excl;
255         __u64 rsv_rfer;
256         __u64 rsv_excl;
257 };
258
259 struct btrfs_qgroup_inherit {
260         __u64 flags;
261         __u64 num_qgroups;
262         __u64 num_ref_copies;
263         __u64 num_excl_copies;
264         struct btrfs_qgroup_limit lim;
265         __u64 qgroups[0];
266 };
267
268 struct btrfs_ioctl_vol_args_v2 {
269         __s64 fd;
270         __u64 transid;
271         __u64 flags;
272         union {
273                 struct {
274                         __u64 size;
275                         struct btrfs_qgroup_inherit *qgroup_inherit;
276                 };
277                 __u64 unused[4];
278         };
279         char name[BTRFS_SUBVOL_NAME_MAX + 1];
280 };
281
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 */
289 };
290
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 */
296 };
297
298 struct btrfs_ioctl_ino_lookup_args {
299         __u64 treeid;
300         __u64 objectid;
301         char name[BTRFS_INO_LOOKUP_PATH_MAX];
302 };
303
304 struct btrfs_ioctl_search_key {
305         /* which root are we searching.  0 is the tree of tree roots */
306         __u64 tree_id;
307
308         /* keys returned will be >= min and <= max */
309         __u64 min_objectid;
310         __u64 max_objectid;
311
312         /* keys returned will be >= min and <= max */
313         __u64 min_offset;
314         __u64 max_offset;
315
316         /* max and min transids to search for */
317         __u64 min_transid;
318         __u64 max_transid;
319
320         /* keys returned will be >= min and <= max */
321         __u32 min_type;
322         __u32 max_type;
323
324         /*
325          * how many items did userland ask for, and how many are we
326          * returning
327          */
328         __u32 nr_items;
329
330         /* align to 64 bits */
331         __u32 unused;
332
333         /* some extra for later */
334         __u64 unused1;
335         __u64 unused2;
336         __u64 unused3;
337         __u64 unused4;
338 };
339
340 struct btrfs_ioctl_search_header {
341         __u64 transid;
342         __u64 objectid;
343         __u64 offset;
344         __u32 type;
345         __u32 len;
346 };
347
348
349 struct btrfs_ioctl_search_args {
350         struct btrfs_ioctl_search_key key;
351         char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
352 };
353
354 struct btrfs_ioctl_clone_range_args {
355         __s64 src_fd;
356         __u64 src_offset, src_length;
357         __u64 dest_offset;
358 };
359 #endif
360
361 #ifndef BTRFS_IOC_DEFRAG
362 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
363                                  struct btrfs_ioctl_vol_args)
364 #endif
365
366 #ifndef BTRFS_IOC_CLONE
367 #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
368 #endif
369
370 #ifndef BTRFS_IOC_CLONE_RANGE
371 #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
372                                  struct btrfs_ioctl_clone_range_args)
373 #endif
374
375 #ifndef BTRFS_IOC_SUBVOL_CREATE
376 #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
377                                  struct btrfs_ioctl_vol_args)
378 #endif
379
380 #ifndef BTRFS_IOC_SNAP_DESTROY
381 #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
382                                  struct btrfs_ioctl_vol_args)
383 #endif
384
385 #ifndef BTRFS_IOC_TREE_SEARCH
386 #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
387                                  struct btrfs_ioctl_search_args)
388 #endif
389
390 #ifndef BTRFS_IOC_INO_LOOKUP
391 #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
392                                  struct btrfs_ioctl_ino_lookup_args)
393 #endif
394
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)
398 #endif
399
400 #ifndef BTRFS_IOC_SUBVOL_GETFLAGS
401 #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
402 #endif
403
404 #ifndef BTRFS_IOC_SUBVOL_SETFLAGS
405 #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
406 #endif
407
408 #ifndef BTRFS_IOC_DEV_INFO
409 #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
410                                  struct btrfs_ioctl_dev_info_args)
411 #endif
412
413 #ifndef BTRFS_IOC_FS_INFO
414 #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
415                                  struct btrfs_ioctl_fs_info_args)
416 #endif
417
418 #ifndef BTRFS_IOC_DEVICES_READY
419 #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
420                                  struct btrfs_ioctl_vol_args)
421 #endif
422
423 #ifndef BTRFS_FIRST_FREE_OBJECTID
424 #define BTRFS_FIRST_FREE_OBJECTID 256
425 #endif
426
427 #ifndef BTRFS_ROOT_TREE_OBJECTID
428 #define BTRFS_ROOT_TREE_OBJECTID 1
429 #endif
430
431 #ifndef BTRFS_QUOTA_TREE_OBJECTID
432 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
433 #endif
434
435 #ifndef BTRFS_ROOT_ITEM_KEY
436 #define BTRFS_ROOT_ITEM_KEY 132
437 #endif
438
439 #ifndef BTRFS_QGROUP_STATUS_KEY
440 #define BTRFS_QGROUP_STATUS_KEY 240
441 #endif
442
443 #ifndef BTRFS_QGROUP_INFO_KEY
444 #define BTRFS_QGROUP_INFO_KEY 242
445 #endif
446
447 #ifndef BTRFS_QGROUP_LIMIT_KEY
448 #define BTRFS_QGROUP_LIMIT_KEY 244
449 #endif
450
451 #ifndef BTRFS_SUPER_MAGIC
452 #define BTRFS_SUPER_MAGIC 0x9123683E
453 #endif
454
455 #ifndef MS_MOVE
456 #define MS_MOVE 8192
457 #endif
458
459 #ifndef MS_PRIVATE
460 #define MS_PRIVATE  (1 << 18)
461 #endif
462
463 #if !HAVE_DECL_GETTID
464 static inline pid_t gettid(void) {
465         return (pid_t) syscall(SYS_gettid);
466 }
467 #endif
468
469 #ifndef SCM_SECURITY
470 #define SCM_SECURITY 0x03
471 #endif
472
473 #ifndef MS_STRICTATIME
474 #define MS_STRICTATIME (1<<24)
475 #endif
476
477 #ifndef MS_REC
478 #define MS_REC 16384
479 #endif
480
481 #ifndef MS_SHARED
482 #define MS_SHARED (1<<20)
483 #endif
484
485 #ifndef PR_SET_NO_NEW_PRIVS
486 #define PR_SET_NO_NEW_PRIVS 38
487 #endif
488
489 #ifndef PR_SET_CHILD_SUBREAPER
490 #define PR_SET_CHILD_SUBREAPER 36
491 #endif
492
493 #ifndef MAX_HANDLE_SZ
494 #define MAX_HANDLE_SZ 128
495 #endif
496
497 #ifndef __NR_name_to_handle_at
498 #  if defined(__x86_64__)
499 #    define __NR_name_to_handle_at 303
500 #  elif defined(__i386__)
501 #    define __NR_name_to_handle_at 341
502 #  elif defined(__arm__)
503 #    define __NR_name_to_handle_at 370
504 #  elif defined(__powerpc__)
505 #    define __NR_name_to_handle_at 345
506 #  else
507 #    error "__NR_name_to_handle_at is not defined"
508 #  endif
509 #endif
510
511 #if !HAVE_DECL_NAME_TO_HANDLE_AT
512 struct file_handle {
513         unsigned int handle_bytes;
514         int handle_type;
515         unsigned char f_handle[0];
516 };
517
518 static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
519         return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
520 }
521 #endif
522
523 #ifndef HAVE_SECURE_GETENV
524 #  ifdef HAVE___SECURE_GETENV
525 #    define secure_getenv __secure_getenv
526 #  else
527 #    error "neither secure_getenv nor __secure_getenv are available"
528 #  endif
529 #endif
530
531 #ifndef CIFS_MAGIC_NUMBER
532 #  define CIFS_MAGIC_NUMBER 0xFF534D42
533 #endif
534
535 #ifndef TFD_TIMER_CANCEL_ON_SET
536 #  define TFD_TIMER_CANCEL_ON_SET (1 << 1)
537 #endif
538
539 #ifndef SO_REUSEPORT
540 #  define SO_REUSEPORT 15
541 #endif
542
543 #ifndef EVIOCREVOKE
544 #  define EVIOCREVOKE _IOW('E', 0x91, int)
545 #endif
546
547 #ifndef DRM_IOCTL_SET_MASTER
548 #  define DRM_IOCTL_SET_MASTER _IO('d', 0x1e)
549 #endif
550
551 #ifndef DRM_IOCTL_DROP_MASTER
552 #  define DRM_IOCTL_DROP_MASTER _IO('d', 0x1f)
553 #endif
554
555 #if defined(__i386__) || defined(__x86_64__)
556
557 /* The precise definition of __O_TMPFILE is arch specific, so let's
558  * just define this on x86 where we know the value. */
559
560 #ifndef __O_TMPFILE
561 #define __O_TMPFILE     020000000
562 #endif
563
564 /* a horrid kludge trying to make sure that this will fail on old kernels */
565 #ifndef O_TMPFILE
566 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
567 #endif
568
569 #endif
570
571 #ifndef __NR_setns
572 #  if defined(__x86_64__)
573 #    define __NR_setns 308
574 #  elif defined(__i386__)
575 #    define __NR_setns 346
576 #  else
577 #    error "__NR_setns is not defined"
578 #  endif
579 #endif
580
581 #if !HAVE_DECL_SETNS
582 static inline int setns(int fd, int nstype) {
583         return syscall(__NR_setns, fd, nstype);
584 }
585 #endif
586
587 #if !HAVE_DECL_LO_FLAGS_PARTSCAN
588 #define LO_FLAGS_PARTSCAN 8
589 #endif
590
591 #ifndef LOOP_CTL_REMOVE
592 #define LOOP_CTL_REMOVE 0x4C81
593 #endif
594
595 #ifndef LOOP_CTL_GET_FREE
596 #define LOOP_CTL_GET_FREE 0x4C82
597 #endif
598
599 #if !HAVE_DECL_IFLA_INET6_ADDR_GEN_MODE
600 #define IFLA_INET6_UNSPEC 0
601 #define IFLA_INET6_FLAGS 1
602 #define IFLA_INET6_CONF 2
603 #define IFLA_INET6_STATS 3
604 #define IFLA_INET6_MCAST 4
605 #define IFLA_INET6_CACHEINFO 5
606 #define IFLA_INET6_ICMP6STATS 6
607 #define IFLA_INET6_TOKEN 7
608 #define IFLA_INET6_ADDR_GEN_MODE 8
609 #define __IFLA_INET6_MAX 9
610
611 #define IFLA_INET6_MAX  (__IFLA_INET6_MAX - 1)
612
613 #define IN6_ADDR_GEN_MODE_EUI64 0
614 #define IN6_ADDR_GEN_MODE_NONE 1
615 #endif
616
617 #if !HAVE_DECL_IFLA_MACVLAN_FLAGS
618 #define IFLA_MACVLAN_UNSPEC 0
619 #define IFLA_MACVLAN_MODE 1
620 #define IFLA_MACVLAN_FLAGS 2
621 #define __IFLA_MACVLAN_MAX 3
622
623 #define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
624 #endif
625
626 #if !HAVE_DECL_IFLA_IPVLAN_MODE
627 #define IFLA_IPVLAN_UNSPEC 0
628 #define IFLA_IPVLAN_MODE 1
629 #define __IFLA_IPVLAN_MAX 2
630
631 #define IFLA_IPVLAN_MAX (__IFLA_IPVLAN_MAX - 1)
632
633 #define IPVLAN_MODE_L2 0
634 #define IPVLAN_MODE_L3 1
635 #define IPVLAN_MAX 2
636 #endif
637
638 #if !HAVE_DECL_IFLA_VTI_REMOTE
639 #define IFLA_VTI_UNSPEC 0
640 #define IFLA_VTI_LINK 1
641 #define IFLA_VTI_IKEY 2
642 #define IFLA_VTI_OKEY 3
643 #define IFLA_VTI_LOCAL 4
644 #define IFLA_VTI_REMOTE 5
645 #define __IFLA_VTI_MAX 6
646
647 #define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1)
648 #endif
649
650 #if !HAVE_DECL_IFLA_PHYS_PORT_ID
651 #undef IFLA_PROMISCUITY
652 #define IFLA_PROMISCUITY 30
653 #define IFLA_NUM_TX_QUEUES 31
654 #define IFLA_NUM_RX_QUEUES 32
655 #define IFLA_CARRIER 33
656 #define IFLA_PHYS_PORT_ID 34
657 #define __IFLA_MAX 35
658
659 #define IFLA_MAX (__IFLA_MAX - 1)
660 #endif
661
662 #if !HAVE_DECL_IFLA_BOND_AD_INFO
663 #define IFLA_BOND_UNSPEC 0
664 #define IFLA_BOND_MODE 1
665 #define IFLA_BOND_ACTIVE_SLAVE 2
666 #define IFLA_BOND_MIIMON 3
667 #define IFLA_BOND_UPDELAY 4
668 #define IFLA_BOND_DOWNDELAY 5
669 #define IFLA_BOND_USE_CARRIER 6
670 #define IFLA_BOND_ARP_INTERVAL 7
671 #define IFLA_BOND_ARP_IP_TARGET 8
672 #define IFLA_BOND_ARP_VALIDATE 9
673 #define IFLA_BOND_ARP_ALL_TARGETS 10
674 #define IFLA_BOND_PRIMARY 11
675 #define IFLA_BOND_PRIMARY_RESELECT 12
676 #define IFLA_BOND_FAIL_OVER_MAC 13
677 #define IFLA_BOND_XMIT_HASH_POLICY 14
678 #define IFLA_BOND_RESEND_IGMP 15
679 #define IFLA_BOND_NUM_PEER_NOTIF 16
680 #define IFLA_BOND_ALL_SLAVES_ACTIVE 17
681 #define IFLA_BOND_MIN_LINKS 18
682 #define IFLA_BOND_LP_INTERVAL 19
683 #define IFLA_BOND_PACKETS_PER_SLAVE 20
684 #define IFLA_BOND_AD_LACP_RATE 21
685 #define IFLA_BOND_AD_SELECT 22
686 #define IFLA_BOND_AD_INFO 23
687 #define __IFLA_BOND_MAX 24
688
689 #define IFLA_BOND_MAX   (__IFLA_BOND_MAX - 1)
690 #endif
691
692 #if !HAVE_DECL_IFLA_VLAN_PROTOCOL
693 #define IFLA_VLAN_UNSPEC 0
694 #define IFLA_VLAN_ID 1
695 #define IFLA_VLAN_FLAGS 2
696 #define IFLA_VLAN_EGRESS_QOS 3
697 #define IFLA_VLAN_INGRESS_QOS 4
698 #define IFLA_VLAN_PROTOCOL 5
699 #define __IFLA_VLAN_MAX 6
700
701 #define IFLA_VLAN_MAX   (__IFLA_VLAN_MAX - 1)
702 #endif
703
704 #if !HAVE_DECL_IFLA_VXLAN_LOCAL6
705 #define IFLA_VXLAN_UNSPEC 0
706 #define IFLA_VXLAN_ID 1
707 #define IFLA_VXLAN_GROUP 2
708 #define IFLA_VXLAN_LINK 3
709 #define IFLA_VXLAN_LOCAL 4
710 #define IFLA_VXLAN_TTL 5
711 #define IFLA_VXLAN_TOS 6
712 #define IFLA_VXLAN_LEARNING 7
713 #define IFLA_VXLAN_AGEING 8
714 #define IFLA_VXLAN_LIMIT 9
715 #define IFLA_VXLAN_PORT_RANGE 10
716 #define IFLA_VXLAN_PROXY 11
717 #define IFLA_VXLAN_RSC 12
718 #define IFLA_VXLAN_L2MISS 13
719 #define IFLA_VXLAN_L3MISS 14
720 #define IFLA_VXLAN_PORT 15
721 #define IFLA_VXLAN_GROUP6 16
722 #define IFLA_VXLAN_LOCAL6 17
723 #define __IFLA_VXLAN_MAX 18
724
725 #define IFLA_VXLAN_MAX  (__IFLA_VXLAN_MAX - 1)
726 #endif
727
728 #if !HAVE_DECL_IFLA_IPTUN_6RD_RELAY_PREFIXLEN
729 #define IFLA_IPTUN_UNSPEC 0
730 #define IFLA_IPTUN_LINK 1
731 #define IFLA_IPTUN_LOCAL 2
732 #define IFLA_IPTUN_REMOTE 3
733 #define IFLA_IPTUN_TTL 4
734 #define IFLA_IPTUN_TOS 5
735 #define IFLA_IPTUN_ENCAP_LIMIT 6
736 #define IFLA_IPTUN_FLOWINFO 7
737 #define IFLA_IPTUN_FLAGS 8
738 #define IFLA_IPTUN_PROTO 9
739 #define IFLA_IPTUN_PMTUDISC 10
740 #define IFLA_IPTUN_6RD_PREFIX 11
741 #define IFLA_IPTUN_6RD_RELAY_PREFIX 12
742 #define IFLA_IPTUN_6RD_PREFIXLEN 13
743 #define IFLA_IPTUN_6RD_RELAY_PREFIXLEN 14
744 #define __IFLA_IPTUN_MAX 15
745
746 #define IFLA_IPTUN_MAX  (__IFLA_IPTUN_MAX - 1)
747 #endif
748
749 #if !HAVE_DECL_IFLA_BRIDGE_VLAN_INFO
750 #define IFLA_BRIDGE_FLAGS 0
751 #define IFLA_BRIDGE_MODE 1
752 #define IFLA_BRIDGE_VLAN_INFO 2
753 #define __IFLA_BRIDGE_MAX 3
754
755 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
756 #endif
757
758 #if !HAVE_DECL_IFLA_BRPORT_UNICAST_FLOOD
759 #define IFLA_BRPORT_UNSPEC 0
760 #define IFLA_BRPORT_STATE 1
761 #define IFLA_BRPORT_PRIORITY 2
762 #define IFLA_BRPORT_COST 3
763 #define IFLA_BRPORT_MODE 4
764 #define IFLA_BRPORT_GUARD 5
765 #define IFLA_BRPORT_PROTECT 6
766 #define IFLA_BRPORT_FAST_LEAVE 7
767 #define IFLA_BRPORT_LEARNING 8
768 #define IFLA_BRPORT_UNICAST_FLOOD 9
769 #define __IFLA_BRPORT_MAX 10
770
771 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
772 #endif
773
774 #if !HAVE_DECL_NDA_IFINDEX
775 #define NDA_UNSPEC 0
776 #define NDA_DST 1
777 #define NDA_LLADDR 2
778 #define NDA_CACHEINFO 3
779 #define NDA_PROBES 4
780 #define NDA_VLAN 5
781 #define NDA_PORT 6
782 #define NDA_VNI 7
783 #define NDA_IFINDEX 8
784 #define __NDA_MAX 9
785
786 #define NDA_MAX (__NDA_MAX - 1)
787 #endif
788
789 #ifndef IPV6_UNICAST_IF
790 #define IPV6_UNICAST_IF 76
791 #endif
792
793 #ifndef IFF_MULTI_QUEUE
794 #define IFF_MULTI_QUEUE 0x100
795 #endif
796
797 #ifndef IFF_LOWER_UP
798 #define IFF_LOWER_UP 0x10000
799 #endif
800
801 #ifndef IFF_DORMANT
802 #define IFF_DORMANT 0x20000
803 #endif
804
805 #ifndef BOND_XMIT_POLICY_ENCAP23
806 #define BOND_XMIT_POLICY_ENCAP23 3
807 #endif
808
809 #ifndef BOND_XMIT_POLICY_ENCAP34
810 #define BOND_XMIT_POLICY_ENCAP34 4
811 #endif
812
813 #ifndef NET_ADDR_RANDOM
814 #  define NET_ADDR_RANDOM 1
815 #endif
816
817 #ifndef NET_NAME_UNKNOWN
818 #  define NET_NAME_UNKNOWN 0
819 #endif
820
821 #ifndef NET_NAME_ENUM
822 #  define NET_NAME_ENUM 1
823 #endif
824
825 #ifndef NET_NAME_PREDICTABLE
826 #  define NET_NAME_PREDICTABLE 2
827 #endif
828
829 #ifndef NET_NAME_USER
830 #  define NET_NAME_USER 3
831 #endif
832
833 #ifndef NET_NAME_RENAMED
834 #  define NET_NAME_RENAMED 4
835 #endif
836
837 #ifndef BPF_XOR
838 #  define BPF_XOR 0xa0
839 #endif
840
841 /* Note that LOOPBACK_IFINDEX is currently not exported by the
842  * kernel/glibc, but hardcoded internally by the kernel.  However, as
843  * it is exported to userspace indirectly via rtnetlink and the
844  * ioctls, and made use of widely we define it here too, in a way that
845  * is compatible with the kernel's internal definition. */
846 #ifndef LOOPBACK_IFINDEX
847 #define LOOPBACK_IFINDEX 1
848 #endif
849
850 #ifndef MAX_AUDIT_MESSAGE_LENGTH
851 #define MAX_AUDIT_MESSAGE_LENGTH 8970
852 #endif
853
854 #ifndef AUDIT_NLGRP_MAX
855 #define AUDIT_NLGRP_READLOG 1
856 #endif
857
858 #ifndef CAP_MAC_OVERRIDE
859 #define CAP_MAC_OVERRIDE 32
860 #endif
861
862 #ifndef CAP_MAC_ADMIN
863 #define CAP_MAC_ADMIN 33
864 #endif
865
866 #ifndef CAP_SYSLOG
867 #define CAP_SYSLOG 34
868 #endif
869
870 #ifndef CAP_WAKE_ALARM
871 #define CAP_WAKE_ALARM 35
872 #endif
873
874 #ifndef CAP_BLOCK_SUSPEND
875 #define CAP_BLOCK_SUSPEND 36
876 #endif
877
878 #ifndef CAP_AUDIT_READ
879 #define CAP_AUDIT_READ 37
880 #endif
881
882 static inline int raw_clone(unsigned long flags, void *child_stack) {
883 #if defined(__s390__) || defined(__CRIS__)
884         /* On s390 and cris the order of the first and second arguments
885          * of the raw clone() system call is reversed. */
886         return (int) syscall(__NR_clone, child_stack, flags);
887 #else
888         return (int) syscall(__NR_clone, flags, child_stack);
889 #endif
890 }
891
892 static inline pid_t raw_getpid(void) {
893         return (pid_t) syscall(__NR_getpid);
894 }
895
896 #if !HAVE_DECL_RENAMEAT2
897
898 #ifndef __NR_renameat2
899 #  if defined __x86_64__
900 #    define __NR_renameat2 316
901 #  elif defined __arm__
902 #    define __NR_renameat2 382
903 #  elif defined _MIPS_SIM
904 #    if _MIPS_SIM == _MIPS_SIM_ABI32
905 #      define __NR_renameat2 4351
906 #    endif
907 #    if _MIPS_SIM == _MIPS_SIM_NABI32
908 #      define __NR_renameat2 6315
909 #    endif
910 #    if _MIPS_SIM == _MIPS_SIM_ABI64
911 #      define __NR_renameat2 5311
912 #    endif
913 #  elif defined __i386__
914 #    define __NR_renameat2 353
915 #  else
916 #    warning "__NR_renameat2 unknown for your architecture"
917 #    define __NR_renameat2 0xffffffff
918 #  endif
919 #endif
920
921 static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
922         return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
923 }
924 #endif
925
926 #ifndef RENAME_NOREPLACE
927 #define RENAME_NOREPLACE (1 << 0)
928 #endif
929
930
931 #ifndef INPUT_PROP_POINTING_STICK
932 #define INPUT_PROP_POINTING_STICK 0x05
933 #endif
934
935 #ifndef INPUT_PROP_ACCELEROMETER
936 #define INPUT_PROP_ACCELEROMETER  0x06
937 #endif