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