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