chiark / gitweb /
Remove SysV compat
[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 #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_qgroup_limit_args {
269         __u64 qgroupid;
270         struct btrfs_qgroup_limit lim;
271 };
272
273 struct btrfs_ioctl_vol_args_v2 {
274         __s64 fd;
275         __u64 transid;
276         __u64 flags;
277         union {
278                 struct {
279                         __u64 size;
280                         struct btrfs_qgroup_inherit *qgroup_inherit;
281                 };
282                 __u64 unused[4];
283         };
284         char name[BTRFS_SUBVOL_NAME_MAX + 1];
285 };
286
287 struct btrfs_ioctl_dev_info_args {
288         uint64_t devid;                         /* in/out */
289         uint8_t uuid[BTRFS_UUID_SIZE];          /* in/out */
290         uint64_t bytes_used;                    /* out */
291         uint64_t total_bytes;                   /* out */
292         uint64_t unused[379];                   /* pad to 4k */
293         char path[BTRFS_DEVICE_PATH_NAME_MAX];  /* out */
294 };
295
296 struct btrfs_ioctl_fs_info_args {
297         uint64_t max_id;                        /* out */
298         uint64_t num_devices;                   /* out */
299         uint8_t fsid[BTRFS_FSID_SIZE];          /* out */
300         uint64_t reserved[124];                 /* pad to 1k */
301 };
302
303 struct btrfs_ioctl_ino_lookup_args {
304         __u64 treeid;
305         __u64 objectid;
306         char name[BTRFS_INO_LOOKUP_PATH_MAX];
307 };
308
309 struct btrfs_ioctl_search_key {
310         /* which root are we searching.  0 is the tree of tree roots */
311         __u64 tree_id;
312
313         /* keys returned will be >= min and <= max */
314         __u64 min_objectid;
315         __u64 max_objectid;
316
317         /* keys returned will be >= min and <= max */
318         __u64 min_offset;
319         __u64 max_offset;
320
321         /* max and min transids to search for */
322         __u64 min_transid;
323         __u64 max_transid;
324
325         /* keys returned will be >= min and <= max */
326         __u32 min_type;
327         __u32 max_type;
328
329         /*
330          * how many items did userland ask for, and how many are we
331          * returning
332          */
333         __u32 nr_items;
334
335         /* align to 64 bits */
336         __u32 unused;
337
338         /* some extra for later */
339         __u64 unused1;
340         __u64 unused2;
341         __u64 unused3;
342         __u64 unused4;
343 };
344
345 struct btrfs_ioctl_search_header {
346         __u64 transid;
347         __u64 objectid;
348         __u64 offset;
349         __u32 type;
350         __u32 len;
351 };
352
353
354 struct btrfs_ioctl_search_args {
355         struct btrfs_ioctl_search_key key;
356         char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
357 };
358
359 struct btrfs_ioctl_clone_range_args {
360         __s64 src_fd;
361         __u64 src_offset, src_length;
362         __u64 dest_offset;
363 };
364
365 #define BTRFS_QUOTA_CTL_ENABLE  1
366 #define BTRFS_QUOTA_CTL_DISABLE 2
367 #define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
368 struct btrfs_ioctl_quota_ctl_args {
369         __u64 cmd;
370         __u64 status;
371 };
372 #endif
373
374 #ifndef BTRFS_IOC_DEFRAG
375 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
376                                  struct btrfs_ioctl_vol_args)
377 #endif
378
379 #ifndef BTRFS_IOC_RESIZE
380 #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
381                                  struct btrfs_ioctl_vol_args)
382 #endif
383
384 #ifndef BTRFS_IOC_CLONE
385 #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int)
386 #endif
387
388 #ifndef BTRFS_IOC_CLONE_RANGE
389 #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
390                                  struct btrfs_ioctl_clone_range_args)
391 #endif
392
393 #ifndef BTRFS_IOC_SUBVOL_CREATE
394 #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
395                                  struct btrfs_ioctl_vol_args)
396 #endif
397
398 #ifndef BTRFS_IOC_SNAP_DESTROY
399 #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
400                                  struct btrfs_ioctl_vol_args)
401 #endif
402
403 #ifndef BTRFS_IOC_TREE_SEARCH
404 #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
405                                  struct btrfs_ioctl_search_args)
406 #endif
407
408 #ifndef BTRFS_IOC_INO_LOOKUP
409 #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
410                                  struct btrfs_ioctl_ino_lookup_args)
411 #endif
412
413 #ifndef BTRFS_IOC_SNAP_CREATE_V2
414 #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
415                                  struct btrfs_ioctl_vol_args_v2)
416 #endif
417
418 #ifndef BTRFS_IOC_SUBVOL_GETFLAGS
419 #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
420 #endif
421
422 #ifndef BTRFS_IOC_SUBVOL_SETFLAGS
423 #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
424 #endif
425
426 #ifndef BTRFS_IOC_DEV_INFO
427 #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
428                                  struct btrfs_ioctl_dev_info_args)
429 #endif
430
431 #ifndef BTRFS_IOC_FS_INFO
432 #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
433                                  struct btrfs_ioctl_fs_info_args)
434 #endif
435
436 #ifndef BTRFS_IOC_DEVICES_READY
437 #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
438                                  struct btrfs_ioctl_vol_args)
439 #endif
440
441 #ifndef BTRFS_IOC_QUOTA_CTL
442 #define BTRFS_IOC_QUOTA_CTL _IOWR(BTRFS_IOCTL_MAGIC, 40, \
443                                struct btrfs_ioctl_quota_ctl_args)
444 #endif
445
446 #ifndef BTRFS_IOC_QGROUP_LIMIT
447 #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \
448                                struct btrfs_ioctl_qgroup_limit_args)
449 #endif
450
451 #ifndef BTRFS_FIRST_FREE_OBJECTID
452 #define BTRFS_FIRST_FREE_OBJECTID 256
453 #endif
454
455 #ifndef BTRFS_ROOT_TREE_OBJECTID
456 #define BTRFS_ROOT_TREE_OBJECTID 1
457 #endif
458
459 #ifndef BTRFS_QUOTA_TREE_OBJECTID
460 #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
461 #endif
462
463 #ifndef BTRFS_ROOT_ITEM_KEY
464 #define BTRFS_ROOT_ITEM_KEY 132
465 #endif
466
467 #ifndef BTRFS_QGROUP_STATUS_KEY
468 #define BTRFS_QGROUP_STATUS_KEY 240
469 #endif
470
471 #ifndef BTRFS_QGROUP_INFO_KEY
472 #define BTRFS_QGROUP_INFO_KEY 242
473 #endif
474
475 #ifndef BTRFS_QGROUP_LIMIT_KEY
476 #define BTRFS_QGROUP_LIMIT_KEY 244
477 #endif
478
479 #ifndef BTRFS_SUPER_MAGIC
480 #define BTRFS_SUPER_MAGIC 0x9123683E
481 #endif
482
483 #ifndef CGROUP_SUPER_MAGIC
484 #define CGROUP_SUPER_MAGIC 0x27e0eb
485 #endif
486
487 #ifndef TMPFS_MAGIC
488 #define TMPFS_MAGIC 0x01021994
489 #endif
490
491 #ifndef MS_MOVE
492 #define MS_MOVE 8192
493 #endif
494
495 #ifndef MS_PRIVATE
496 #define MS_PRIVATE  (1 << 18)
497 #endif
498
499 #if !HAVE_DECL_GETTID
500 static inline pid_t gettid(void) {
501         return (pid_t) syscall(SYS_gettid);
502 }
503 #endif
504
505 #ifndef SCM_SECURITY
506 #define SCM_SECURITY 0x03
507 #endif
508
509 #ifndef MS_STRICTATIME
510 #define MS_STRICTATIME (1<<24)
511 #endif
512
513 #ifndef MS_REC
514 #define MS_REC 16384
515 #endif
516
517 #ifndef MS_SHARED
518 #define MS_SHARED (1<<20)
519 #endif
520
521 #ifndef PR_SET_NO_NEW_PRIVS
522 #define PR_SET_NO_NEW_PRIVS 38
523 #endif
524
525 #ifndef PR_SET_CHILD_SUBREAPER
526 #define PR_SET_CHILD_SUBREAPER 36
527 #endif
528
529 #ifndef MAX_HANDLE_SZ
530 #define MAX_HANDLE_SZ 128
531 #endif
532
533 #ifndef __NR_name_to_handle_at
534 #  if defined(__x86_64__)
535 #    define __NR_name_to_handle_at 303
536 #  elif defined(__i386__)
537 #    define __NR_name_to_handle_at 341
538 #  elif defined(__arm__)
539 #    define __NR_name_to_handle_at 370
540 #  elif defined(__powerpc__)
541 #    define __NR_name_to_handle_at 345
542 #  else
543 #    error "__NR_name_to_handle_at is not defined"
544 #  endif
545 #endif
546
547 #if !HAVE_DECL_NAME_TO_HANDLE_AT
548 struct file_handle {
549         unsigned int handle_bytes;
550         int handle_type;
551         unsigned char f_handle[0];
552 };
553
554 static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
555         return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
556 }
557 #endif
558
559 #ifndef HAVE_SECURE_GETENV
560 #  ifdef HAVE___SECURE_GETENV
561 #    define secure_getenv __secure_getenv
562 #  else
563 #    error "neither secure_getenv nor __secure_getenv are available"
564 #  endif
565 #endif
566
567 #ifndef CIFS_MAGIC_NUMBER
568 #  define CIFS_MAGIC_NUMBER 0xFF534D42
569 #endif
570
571 #ifndef TFD_TIMER_CANCEL_ON_SET
572 #  define TFD_TIMER_CANCEL_ON_SET (1 << 1)
573 #endif
574
575 #ifndef SO_REUSEPORT
576 #  define SO_REUSEPORT 15
577 #endif
578
579 #ifndef EVIOCREVOKE
580 #  define EVIOCREVOKE _IOW('E', 0x91, int)
581 #endif
582
583 #ifndef DRM_IOCTL_SET_MASTER
584 #  define DRM_IOCTL_SET_MASTER _IO('d', 0x1e)
585 #endif
586
587 #ifndef DRM_IOCTL_DROP_MASTER
588 #  define DRM_IOCTL_DROP_MASTER _IO('d', 0x1f)
589 #endif
590
591 #if defined(__i386__) || defined(__x86_64__)
592
593 /* The precise definition of __O_TMPFILE is arch specific, so let's
594  * just define this on x86 where we know the value. */
595
596 #ifndef __O_TMPFILE
597 #define __O_TMPFILE     020000000
598 #endif
599
600 /* a horrid kludge trying to make sure that this will fail on old kernels */
601 #ifndef O_TMPFILE
602 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
603 #endif
604
605 #endif
606
607 #ifndef __NR_setns
608 #  if defined(__x86_64__)
609 #    define __NR_setns 308
610 #  elif defined(__i386__)
611 #    define __NR_setns 346
612 #  else
613 #    error "__NR_setns is not defined"
614 #  endif
615 #endif
616
617 #if !HAVE_DECL_SETNS
618 static inline int setns(int fd, int nstype) {
619         return syscall(__NR_setns, fd, nstype);
620 }
621 #endif
622
623 #if !HAVE_DECL_LO_FLAGS_PARTSCAN
624 #define LO_FLAGS_PARTSCAN 8
625 #endif
626
627 #ifndef LOOP_CTL_REMOVE
628 #define LOOP_CTL_REMOVE 0x4C81
629 #endif
630
631 #ifndef LOOP_CTL_GET_FREE
632 #define LOOP_CTL_GET_FREE 0x4C82
633 #endif
634
635 #if !HAVE_DECL_IFLA_INET6_ADDR_GEN_MODE
636 #define IFLA_INET6_UNSPEC 0
637 #define IFLA_INET6_FLAGS 1
638 #define IFLA_INET6_CONF 2
639 #define IFLA_INET6_STATS 3
640 #define IFLA_INET6_MCAST 4
641 #define IFLA_INET6_CACHEINFO 5
642 #define IFLA_INET6_ICMP6STATS 6
643 #define IFLA_INET6_TOKEN 7
644 #define IFLA_INET6_ADDR_GEN_MODE 8
645 #define __IFLA_INET6_MAX 9
646
647 #define IFLA_INET6_MAX  (__IFLA_INET6_MAX - 1)
648
649 #define IN6_ADDR_GEN_MODE_EUI64 0
650 #define IN6_ADDR_GEN_MODE_NONE 1
651 #endif
652
653 #if !HAVE_DECL_IFLA_MACVLAN_FLAGS
654 #define IFLA_MACVLAN_UNSPEC 0
655 #define IFLA_MACVLAN_MODE 1
656 #define IFLA_MACVLAN_FLAGS 2
657 #define __IFLA_MACVLAN_MAX 3
658
659 #define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
660 #endif
661
662 #if !HAVE_DECL_IFLA_IPVLAN_MODE
663 #define IFLA_IPVLAN_UNSPEC 0
664 #define IFLA_IPVLAN_MODE 1
665 #define __IFLA_IPVLAN_MAX 2
666
667 #define IFLA_IPVLAN_MAX (__IFLA_IPVLAN_MAX - 1)
668
669 #define IPVLAN_MODE_L2 0
670 #define IPVLAN_MODE_L3 1
671 #define IPVLAN_MAX 2
672 #endif
673
674 #if !HAVE_DECL_IFLA_VTI_REMOTE
675 #define IFLA_VTI_UNSPEC 0
676 #define IFLA_VTI_LINK 1
677 #define IFLA_VTI_IKEY 2
678 #define IFLA_VTI_OKEY 3
679 #define IFLA_VTI_LOCAL 4
680 #define IFLA_VTI_REMOTE 5
681 #define __IFLA_VTI_MAX 6
682
683 #define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1)
684 #endif
685
686 #if !HAVE_DECL_IFLA_PHYS_PORT_ID
687 #undef IFLA_PROMISCUITY
688 #define IFLA_PROMISCUITY 30
689 #define IFLA_NUM_TX_QUEUES 31
690 #define IFLA_NUM_RX_QUEUES 32
691 #define IFLA_CARRIER 33
692 #define IFLA_PHYS_PORT_ID 34
693 #define __IFLA_MAX 35
694
695 #define IFLA_MAX (__IFLA_MAX - 1)
696 #endif
697
698 #if !HAVE_DECL_IFLA_BOND_AD_INFO
699 #define IFLA_BOND_UNSPEC 0
700 #define IFLA_BOND_MODE 1
701 #define IFLA_BOND_ACTIVE_SLAVE 2
702 #define IFLA_BOND_MIIMON 3
703 #define IFLA_BOND_UPDELAY 4
704 #define IFLA_BOND_DOWNDELAY 5
705 #define IFLA_BOND_USE_CARRIER 6
706 #define IFLA_BOND_ARP_INTERVAL 7
707 #define IFLA_BOND_ARP_IP_TARGET 8
708 #define IFLA_BOND_ARP_VALIDATE 9
709 #define IFLA_BOND_ARP_ALL_TARGETS 10
710 #define IFLA_BOND_PRIMARY 11
711 #define IFLA_BOND_PRIMARY_RESELECT 12
712 #define IFLA_BOND_FAIL_OVER_MAC 13
713 #define IFLA_BOND_XMIT_HASH_POLICY 14
714 #define IFLA_BOND_RESEND_IGMP 15
715 #define IFLA_BOND_NUM_PEER_NOTIF 16
716 #define IFLA_BOND_ALL_SLAVES_ACTIVE 17
717 #define IFLA_BOND_MIN_LINKS 18
718 #define IFLA_BOND_LP_INTERVAL 19
719 #define IFLA_BOND_PACKETS_PER_SLAVE 20
720 #define IFLA_BOND_AD_LACP_RATE 21
721 #define IFLA_BOND_AD_SELECT 22
722 #define IFLA_BOND_AD_INFO 23
723 #define __IFLA_BOND_MAX 24
724
725 #define IFLA_BOND_MAX   (__IFLA_BOND_MAX - 1)
726 #endif
727
728 #if !HAVE_DECL_IFLA_VLAN_PROTOCOL
729 #define IFLA_VLAN_UNSPEC 0
730 #define IFLA_VLAN_ID 1
731 #define IFLA_VLAN_FLAGS 2
732 #define IFLA_VLAN_EGRESS_QOS 3
733 #define IFLA_VLAN_INGRESS_QOS 4
734 #define IFLA_VLAN_PROTOCOL 5
735 #define __IFLA_VLAN_MAX 6
736
737 #define IFLA_VLAN_MAX   (__IFLA_VLAN_MAX - 1)
738 #endif
739
740 #if !HAVE_DECL_IFLA_VXLAN_REMCSUM_NOPARTIAL
741 #define IFLA_VXLAN_UNSPEC 0
742 #define IFLA_VXLAN_ID 1
743 #define IFLA_VXLAN_GROUP 2
744 #define IFLA_VXLAN_LINK 3
745 #define IFLA_VXLAN_LOCAL 4
746 #define IFLA_VXLAN_TTL 5
747 #define IFLA_VXLAN_TOS 6
748 #define IFLA_VXLAN_LEARNING 7
749 #define IFLA_VXLAN_AGEING 8
750 #define IFLA_VXLAN_LIMIT 9
751 #define IFLA_VXLAN_PORT_RANGE 10
752 #define IFLA_VXLAN_PROXY 11
753 #define IFLA_VXLAN_RSC 12
754 #define IFLA_VXLAN_L2MISS 13
755 #define IFLA_VXLAN_L3MISS 14
756 #define IFLA_VXLAN_PORT 15
757 #define IFLA_VXLAN_GROUP6 16
758 #define IFLA_VXLAN_LOCAL6 17
759 #define IFLA_VXLAN_UDP_CSUM 18
760 #define IFLA_VXLAN_UDP_ZERO_CSUM6_TX 19
761 #define IFLA_VXLAN_UDP_ZERO_CSUM6_RX 20
762 #define IFLA_VXLAN_REMCSUM_TX 21
763 #define IFLA_VXLAN_REMCSUM_RX 22
764 #define IFLA_VXLAN_GBP 23
765 #define IFLA_VXLAN_REMCSUM_NOPARTIAL 24
766 #define __IFLA_VXLAN_MAX 25
767
768 #define IFLA_VXLAN_MAX  (__IFLA_VXLAN_MAX - 1)
769 #endif
770
771 #if !HAVE_DECL_IFLA_IPTUN_ENCAP_DPORT
772 #define IFLA_IPTUN_UNSPEC 0
773 #define IFLA_IPTUN_LINK 1
774 #define IFLA_IPTUN_LOCAL 2
775 #define IFLA_IPTUN_REMOTE 3
776 #define IFLA_IPTUN_TTL 4
777 #define IFLA_IPTUN_TOS 5
778 #define IFLA_IPTUN_ENCAP_LIMIT 6
779 #define IFLA_IPTUN_FLOWINFO 7
780 #define IFLA_IPTUN_FLAGS 8
781 #define IFLA_IPTUN_PROTO 9
782 #define IFLA_IPTUN_PMTUDISC 10
783 #define IFLA_IPTUN_6RD_PREFIX 11
784 #define IFLA_IPTUN_6RD_RELAY_PREFIX 12
785 #define IFLA_IPTUN_6RD_PREFIXLEN 13
786 #define IFLA_IPTUN_6RD_RELAY_PREFIXLEN 14
787 #define IFLA_IPTUN_ENCAP_TYPE 15
788 #define IFLA_IPTUN_ENCAP_FLAGS 16
789 #define IFLA_IPTUN_ENCAP_SPORT 17
790 #define IFLA_IPTUN_ENCAP_DPORT 18
791
792 #define __IFLA_IPTUN_MAX 19
793
794 #define IFLA_IPTUN_MAX  (__IFLA_IPTUN_MAX - 1)
795 #endif
796
797 #if !HAVE_DECL_IFLA_GRE_ENCAP_DPORT
798 #define IFLA_GRE_UNSPEC 0
799 #define IFLA_GRE_LINK 1
800 #define IFLA_GRE_IFLAGS 2
801 #define IFLA_GRE_OFLAGS 3
802 #define IFLA_GRE_IKEY 4
803 #define IFLA_GRE_OKEY 5
804 #define IFLA_GRE_LOCAL 6
805 #define IFLA_GRE_REMOTE 7
806 #define IFLA_GRE_TTL 8
807 #define IFLA_GRE_TOS 9
808 #define IFLA_GRE_PMTUDISC 10
809 #define IFLA_GRE_ENCAP_LIMIT 11
810 #define IFLA_GRE_FLOWINFO 12
811 #define IFLA_GRE_FLAGS 13
812 #define IFLA_GRE_ENCAP_TYPE 14
813 #define IFLA_GRE_ENCAP_FLAGS 15
814 #define IFLA_GRE_ENCAP_SPORT 16
815 #define IFLA_GRE_ENCAP_DPORT 17
816
817 #define __IFLA_GRE_MAX 18
818
819 #define IFLA_GRE_MAX  (__IFLA_GRE_MAX - 1)
820 #endif
821
822 #if !HAVE_DECL_IFLA_BRIDGE_VLAN_INFO
823 #define IFLA_BRIDGE_FLAGS 0
824 #define IFLA_BRIDGE_MODE 1
825 #define IFLA_BRIDGE_VLAN_INFO 2
826 #define __IFLA_BRIDGE_MAX 3
827
828 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
829 #endif
830
831 #if !HAVE_DECL_IFLA_BRPORT_LEARNING_SYNC
832 #define IFLA_BRPORT_UNSPEC 0
833 #define IFLA_BRPORT_STATE 1
834 #define IFLA_BRPORT_PRIORITY 2
835 #define IFLA_BRPORT_COST 3
836 #define IFLA_BRPORT_MODE 4
837 #define IFLA_BRPORT_GUARD 5
838 #define IFLA_BRPORT_PROTECT 6
839 #define IFLA_BRPORT_FAST_LEAVE 7
840 #define IFLA_BRPORT_LEARNING 8
841 #define IFLA_BRPORT_UNICAST_FLOOD 9
842 #define IFLA_BRPORT_PROXYARP 10
843 #define IFLA_BRPORT_LEARNING_SYNC 11
844 #define __IFLA_BRPORT_MAX 12
845
846 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
847 #endif
848
849 #if !HAVE_DECL_NDA_IFINDEX
850 #define NDA_UNSPEC 0
851 #define NDA_DST 1
852 #define NDA_LLADDR 2
853 #define NDA_CACHEINFO 3
854 #define NDA_PROBES 4
855 #define NDA_VLAN 5
856 #define NDA_PORT 6
857 #define NDA_VNI 7
858 #define NDA_IFINDEX 8
859 #define __NDA_MAX 9
860
861 #define NDA_MAX (__NDA_MAX - 1)
862 #endif
863
864 #ifndef IPV6_UNICAST_IF
865 #define IPV6_UNICAST_IF 76
866 #endif
867
868 #ifndef IFF_MULTI_QUEUE
869 #define IFF_MULTI_QUEUE 0x100
870 #endif
871
872 #ifndef IFF_LOWER_UP
873 #define IFF_LOWER_UP 0x10000
874 #endif
875
876 #ifndef IFF_DORMANT
877 #define IFF_DORMANT 0x20000
878 #endif
879
880 #ifndef BOND_XMIT_POLICY_ENCAP23
881 #define BOND_XMIT_POLICY_ENCAP23 3
882 #endif
883
884 #ifndef BOND_XMIT_POLICY_ENCAP34
885 #define BOND_XMIT_POLICY_ENCAP34 4
886 #endif
887
888 #ifndef NET_ADDR_RANDOM
889 #  define NET_ADDR_RANDOM 1
890 #endif
891
892 #ifndef NET_NAME_UNKNOWN
893 #  define NET_NAME_UNKNOWN 0
894 #endif
895
896 #ifndef NET_NAME_ENUM
897 #  define NET_NAME_ENUM 1
898 #endif
899
900 #ifndef NET_NAME_PREDICTABLE
901 #  define NET_NAME_PREDICTABLE 2
902 #endif
903
904 #ifndef NET_NAME_USER
905 #  define NET_NAME_USER 3
906 #endif
907
908 #ifndef NET_NAME_RENAMED
909 #  define NET_NAME_RENAMED 4
910 #endif
911
912 #ifndef BPF_XOR
913 #  define BPF_XOR 0xa0
914 #endif
915
916 /* Note that LOOPBACK_IFINDEX is currently not exported by the
917  * kernel/glibc, but hardcoded internally by the kernel.  However, as
918  * it is exported to userspace indirectly via rtnetlink and the
919  * ioctls, and made use of widely we define it here too, in a way that
920  * is compatible with the kernel's internal definition. */
921 #ifndef LOOPBACK_IFINDEX
922 #define LOOPBACK_IFINDEX 1
923 #endif
924
925 #ifndef MAX_AUDIT_MESSAGE_LENGTH
926 #define MAX_AUDIT_MESSAGE_LENGTH 8970
927 #endif
928
929 #ifndef AUDIT_NLGRP_MAX
930 #define AUDIT_NLGRP_READLOG 1
931 #endif
932
933 #ifndef CAP_MAC_OVERRIDE
934 #define CAP_MAC_OVERRIDE 32
935 #endif
936
937 #ifndef CAP_MAC_ADMIN
938 #define CAP_MAC_ADMIN 33
939 #endif
940
941 #ifndef CAP_SYSLOG
942 #define CAP_SYSLOG 34
943 #endif
944
945 #ifndef CAP_WAKE_ALARM
946 #define CAP_WAKE_ALARM 35
947 #endif
948
949 #ifndef CAP_BLOCK_SUSPEND
950 #define CAP_BLOCK_SUSPEND 36
951 #endif
952
953 #ifndef CAP_AUDIT_READ
954 #define CAP_AUDIT_READ 37
955 #endif
956
957 static inline int raw_clone(unsigned long flags, void *child_stack) {
958 #if defined(__s390__) || defined(__CRIS__)
959         /* On s390 and cris the order of the first and second arguments
960          * of the raw clone() system call is reversed. */
961         return (int) syscall(__NR_clone, child_stack, flags);
962 #else
963         return (int) syscall(__NR_clone, flags, child_stack);
964 #endif
965 }
966
967 static inline pid_t raw_getpid(void) {
968 #if defined(__alpha__)
969         return (pid_t) syscall(__NR_getxpid);
970 #else
971         return (pid_t) syscall(__NR_getpid);
972 #endif
973 }
974
975 #if !HAVE_DECL_RENAMEAT2
976
977 #ifndef __NR_renameat2
978 #  if defined __x86_64__
979 #    define __NR_renameat2 316
980 #  elif defined __arm__
981 #    define __NR_renameat2 382
982 #  elif defined _MIPS_SIM
983 #    if _MIPS_SIM == _MIPS_SIM_ABI32
984 #      define __NR_renameat2 4351
985 #    endif
986 #    if _MIPS_SIM == _MIPS_SIM_NABI32
987 #      define __NR_renameat2 6315
988 #    endif
989 #    if _MIPS_SIM == _MIPS_SIM_ABI64
990 #      define __NR_renameat2 5311
991 #    endif
992 #  elif defined __i386__
993 #    define __NR_renameat2 353
994 #  else
995 #    warning "__NR_renameat2 unknown for your architecture"
996 #    define __NR_renameat2 0xffffffff
997 #  endif
998 #endif
999
1000 static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
1001         return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
1002 }
1003 #endif
1004
1005 #ifndef RENAME_NOREPLACE
1006 #define RENAME_NOREPLACE (1 << 0)
1007 #endif