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