chiark / gitweb /
Prep v229: Add missing fixes from upstream [1/6] src/basic
[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 #ifndef HAVE_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 TMPFS_MAGIC
523 #define TMPFS_MAGIC 0x01021994
524 #endif
525
526 #ifndef MS_MOVE
527 #define MS_MOVE 8192
528 #endif
529
530 #ifndef MS_PRIVATE
531 #define MS_PRIVATE  (1 << 18)
532 #endif
533
534 #if !HAVE_DECL_GETTID
535 static inline pid_t gettid(void) {
536         return (pid_t) syscall(SYS_gettid);
537 }
538 #endif
539
540 #ifndef SCM_SECURITY
541 #define SCM_SECURITY 0x03
542 #endif
543
544 #ifndef MS_STRICTATIME
545 #define MS_STRICTATIME (1<<24)
546 #endif
547
548 #ifndef MS_REC
549 #define MS_REC 16384
550 #endif
551
552 #ifndef MS_SHARED
553 #define MS_SHARED (1<<20)
554 #endif
555
556 #ifndef PR_SET_NO_NEW_PRIVS
557 #define PR_SET_NO_NEW_PRIVS 38
558 #endif
559
560 #ifndef PR_SET_CHILD_SUBREAPER
561 #define PR_SET_CHILD_SUBREAPER 36
562 #endif
563
564 #ifndef MAX_HANDLE_SZ
565 #define MAX_HANDLE_SZ 128
566 #endif
567
568 #ifndef __NR_name_to_handle_at
569 #  if defined(__x86_64__)
570 #    define __NR_name_to_handle_at 303
571 #  elif defined(__i386__)
572 #    define __NR_name_to_handle_at 341
573 #  elif defined(__arm__)
574 #    define __NR_name_to_handle_at 370
575 #  elif defined(__powerpc__)
576 #    define __NR_name_to_handle_at 345
577 #  else
578 #    error "__NR_name_to_handle_at is not defined"
579 #  endif
580 #endif
581
582 #if !HAVE_DECL_NAME_TO_HANDLE_AT
583 struct file_handle {
584         unsigned int handle_bytes;
585         int handle_type;
586         unsigned char f_handle[0];
587 };
588
589 static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
590         return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
591 }
592 #endif
593
594 #ifndef HAVE_SECURE_GETENV
595 #  ifdef HAVE___SECURE_GETENV
596 #    define secure_getenv __secure_getenv
597 #  else
598 #    error "neither secure_getenv nor __secure_getenv are available"
599 #  endif
600 #endif
601
602 #ifndef CIFS_MAGIC_NUMBER
603 #  define CIFS_MAGIC_NUMBER 0xFF534D42
604 #endif
605
606 #ifndef TFD_TIMER_CANCEL_ON_SET
607 #  define TFD_TIMER_CANCEL_ON_SET (1 << 1)
608 #endif
609
610 #ifndef SO_REUSEPORT
611 #  define SO_REUSEPORT 15
612 #endif
613
614 #ifndef EVIOCREVOKE
615 #  define EVIOCREVOKE _IOW('E', 0x91, int)
616 #endif
617
618 #ifndef DRM_IOCTL_SET_MASTER
619 #  define DRM_IOCTL_SET_MASTER _IO('d', 0x1e)
620 #endif
621
622 #ifndef DRM_IOCTL_DROP_MASTER
623 #  define DRM_IOCTL_DROP_MASTER _IO('d', 0x1f)
624 #endif
625
626 #if defined(__i386__) || defined(__x86_64__)
627
628 /* The precise definition of __O_TMPFILE is arch specific, so let's
629  * just define this on x86 where we know the value. */
630
631 #ifndef __O_TMPFILE
632 #define __O_TMPFILE     020000000
633 #endif
634
635 /* a horrid kludge trying to make sure that this will fail on old kernels */
636 #ifndef O_TMPFILE
637 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
638 #endif
639
640 #endif
641
642 #ifndef __NR_setns
643 #  if defined(__x86_64__)
644 #    define __NR_setns 308
645 #  elif defined(__i386__)
646 #    define __NR_setns 346
647 #  else
648 #    error "__NR_setns is not defined"
649 #  endif
650 #endif
651
652 #if !HAVE_DECL_SETNS
653 static inline int setns(int fd, int nstype) {
654         return syscall(__NR_setns, fd, nstype);
655 }
656 #endif
657
658 #if !HAVE_DECL_LO_FLAGS_PARTSCAN
659 #define LO_FLAGS_PARTSCAN 8
660 #endif
661
662 #ifndef LOOP_CTL_REMOVE
663 #define LOOP_CTL_REMOVE 0x4C81
664 #endif
665
666 #ifndef LOOP_CTL_GET_FREE
667 #define LOOP_CTL_GET_FREE 0x4C82
668 #endif
669
670 #if !HAVE_DECL_IFLA_INET6_ADDR_GEN_MODE
671 #define IFLA_INET6_UNSPEC 0
672 #define IFLA_INET6_FLAGS 1
673 #define IFLA_INET6_CONF 2
674 #define IFLA_INET6_STATS 3
675 #define IFLA_INET6_MCAST 4
676 #define IFLA_INET6_CACHEINFO 5
677 #define IFLA_INET6_ICMP6STATS 6
678 #define IFLA_INET6_TOKEN 7
679 #define IFLA_INET6_ADDR_GEN_MODE 8
680 #define __IFLA_INET6_MAX 9
681
682 #define IFLA_INET6_MAX  (__IFLA_INET6_MAX - 1)
683
684 #define IN6_ADDR_GEN_MODE_EUI64 0
685 #define IN6_ADDR_GEN_MODE_NONE 1
686 #endif
687
688 #if !HAVE_DECL_IFLA_MACVLAN_FLAGS
689 #define IFLA_MACVLAN_UNSPEC 0
690 #define IFLA_MACVLAN_MODE 1
691 #define IFLA_MACVLAN_FLAGS 2
692 #define __IFLA_MACVLAN_MAX 3
693
694 #define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
695 #endif
696
697 #if !HAVE_DECL_IFLA_IPVLAN_MODE
698 #define IFLA_IPVLAN_UNSPEC 0
699 #define IFLA_IPVLAN_MODE 1
700 #define __IFLA_IPVLAN_MAX 2
701
702 #define IFLA_IPVLAN_MAX (__IFLA_IPVLAN_MAX - 1)
703
704 #define IPVLAN_MODE_L2 0
705 #define IPVLAN_MODE_L3 1
706 #define IPVLAN_MAX 2
707 #endif
708
709 #if !HAVE_DECL_IFLA_VTI_REMOTE
710 #define IFLA_VTI_UNSPEC 0
711 #define IFLA_VTI_LINK 1
712 #define IFLA_VTI_IKEY 2
713 #define IFLA_VTI_OKEY 3
714 #define IFLA_VTI_LOCAL 4
715 #define IFLA_VTI_REMOTE 5
716 #define __IFLA_VTI_MAX 6
717
718 #define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1)
719 #endif
720
721 #if !HAVE_DECL_IFLA_PHYS_PORT_ID
722 #undef IFLA_PROMISCUITY
723 #define IFLA_PROMISCUITY 30
724 #define IFLA_NUM_TX_QUEUES 31
725 #define IFLA_NUM_RX_QUEUES 32
726 #define IFLA_CARRIER 33
727 #define IFLA_PHYS_PORT_ID 34
728 #define __IFLA_MAX 35
729
730 #define IFLA_MAX (__IFLA_MAX - 1)
731 #endif
732
733 #if !HAVE_DECL_IFLA_BOND_AD_INFO
734 #define IFLA_BOND_UNSPEC 0
735 #define IFLA_BOND_MODE 1
736 #define IFLA_BOND_ACTIVE_SLAVE 2
737 #define IFLA_BOND_MIIMON 3
738 #define IFLA_BOND_UPDELAY 4
739 #define IFLA_BOND_DOWNDELAY 5
740 #define IFLA_BOND_USE_CARRIER 6
741 #define IFLA_BOND_ARP_INTERVAL 7
742 #define IFLA_BOND_ARP_IP_TARGET 8
743 #define IFLA_BOND_ARP_VALIDATE 9
744 #define IFLA_BOND_ARP_ALL_TARGETS 10
745 #define IFLA_BOND_PRIMARY 11
746 #define IFLA_BOND_PRIMARY_RESELECT 12
747 #define IFLA_BOND_FAIL_OVER_MAC 13
748 #define IFLA_BOND_XMIT_HASH_POLICY 14
749 #define IFLA_BOND_RESEND_IGMP 15
750 #define IFLA_BOND_NUM_PEER_NOTIF 16
751 #define IFLA_BOND_ALL_SLAVES_ACTIVE 17
752 #define IFLA_BOND_MIN_LINKS 18
753 #define IFLA_BOND_LP_INTERVAL 19
754 #define IFLA_BOND_PACKETS_PER_SLAVE 20
755 #define IFLA_BOND_AD_LACP_RATE 21
756 #define IFLA_BOND_AD_SELECT 22
757 #define IFLA_BOND_AD_INFO 23
758 #define __IFLA_BOND_MAX 24
759
760 #define IFLA_BOND_MAX   (__IFLA_BOND_MAX - 1)
761 #endif
762
763 #if !HAVE_DECL_IFLA_VLAN_PROTOCOL
764 #define IFLA_VLAN_UNSPEC 0
765 #define IFLA_VLAN_ID 1
766 #define IFLA_VLAN_FLAGS 2
767 #define IFLA_VLAN_EGRESS_QOS 3
768 #define IFLA_VLAN_INGRESS_QOS 4
769 #define IFLA_VLAN_PROTOCOL 5
770 #define __IFLA_VLAN_MAX 6
771
772 #define IFLA_VLAN_MAX   (__IFLA_VLAN_MAX - 1)
773 #endif
774
775 #if !HAVE_DECL_IFLA_VXLAN_REMCSUM_NOPARTIAL
776 #define IFLA_VXLAN_UNSPEC 0
777 #define IFLA_VXLAN_ID 1
778 #define IFLA_VXLAN_GROUP 2
779 #define IFLA_VXLAN_LINK 3
780 #define IFLA_VXLAN_LOCAL 4
781 #define IFLA_VXLAN_TTL 5
782 #define IFLA_VXLAN_TOS 6
783 #define IFLA_VXLAN_LEARNING 7
784 #define IFLA_VXLAN_AGEING 8
785 #define IFLA_VXLAN_LIMIT 9
786 #define IFLA_VXLAN_PORT_RANGE 10
787 #define IFLA_VXLAN_PROXY 11
788 #define IFLA_VXLAN_RSC 12
789 #define IFLA_VXLAN_L2MISS 13
790 #define IFLA_VXLAN_L3MISS 14
791 #define IFLA_VXLAN_PORT 15
792 #define IFLA_VXLAN_GROUP6 16
793 #define IFLA_VXLAN_LOCAL6 17
794 #define IFLA_VXLAN_UDP_CSUM 18
795 #define IFLA_VXLAN_UDP_ZERO_CSUM6_TX 19
796 #define IFLA_VXLAN_UDP_ZERO_CSUM6_RX 20
797 #define IFLA_VXLAN_REMCSUM_TX 21
798 #define IFLA_VXLAN_REMCSUM_RX 22
799 #define IFLA_VXLAN_GBP 23
800 #define IFLA_VXLAN_REMCSUM_NOPARTIAL 24
801 #define __IFLA_VXLAN_MAX 25
802
803 #define IFLA_VXLAN_MAX  (__IFLA_VXLAN_MAX - 1)
804 #endif
805
806 #if !HAVE_DECL_IFLA_IPTUN_ENCAP_DPORT
807 #define IFLA_IPTUN_UNSPEC 0
808 #define IFLA_IPTUN_LINK 1
809 #define IFLA_IPTUN_LOCAL 2
810 #define IFLA_IPTUN_REMOTE 3
811 #define IFLA_IPTUN_TTL 4
812 #define IFLA_IPTUN_TOS 5
813 #define IFLA_IPTUN_ENCAP_LIMIT 6
814 #define IFLA_IPTUN_FLOWINFO 7
815 #define IFLA_IPTUN_FLAGS 8
816 #define IFLA_IPTUN_PROTO 9
817 #define IFLA_IPTUN_PMTUDISC 10
818 #define IFLA_IPTUN_6RD_PREFIX 11
819 #define IFLA_IPTUN_6RD_RELAY_PREFIX 12
820 #define IFLA_IPTUN_6RD_PREFIXLEN 13
821 #define IFLA_IPTUN_6RD_RELAY_PREFIXLEN 14
822 #define IFLA_IPTUN_ENCAP_TYPE 15
823 #define IFLA_IPTUN_ENCAP_FLAGS 16
824 #define IFLA_IPTUN_ENCAP_SPORT 17
825 #define IFLA_IPTUN_ENCAP_DPORT 18
826
827 #define __IFLA_IPTUN_MAX 19
828
829 #define IFLA_IPTUN_MAX  (__IFLA_IPTUN_MAX - 1)
830 #endif
831
832 #if !HAVE_DECL_IFLA_GRE_ENCAP_DPORT
833 #define IFLA_GRE_UNSPEC 0
834 #define IFLA_GRE_LINK 1
835 #define IFLA_GRE_IFLAGS 2
836 #define IFLA_GRE_OFLAGS 3
837 #define IFLA_GRE_IKEY 4
838 #define IFLA_GRE_OKEY 5
839 #define IFLA_GRE_LOCAL 6
840 #define IFLA_GRE_REMOTE 7
841 #define IFLA_GRE_TTL 8
842 #define IFLA_GRE_TOS 9
843 #define IFLA_GRE_PMTUDISC 10
844 #define IFLA_GRE_ENCAP_LIMIT 11
845 #define IFLA_GRE_FLOWINFO 12
846 #define IFLA_GRE_FLAGS 13
847 #define IFLA_GRE_ENCAP_TYPE 14
848 #define IFLA_GRE_ENCAP_FLAGS 15
849 #define IFLA_GRE_ENCAP_SPORT 16
850 #define IFLA_GRE_ENCAP_DPORT 17
851
852 #define __IFLA_GRE_MAX 18
853
854 #define IFLA_GRE_MAX  (__IFLA_GRE_MAX - 1)
855 #endif
856
857 #if !HAVE_DECL_IFLA_BRIDGE_VLAN_INFO
858 #define IFLA_BRIDGE_FLAGS 0
859 #define IFLA_BRIDGE_MODE 1
860 #define IFLA_BRIDGE_VLAN_INFO 2
861 #define __IFLA_BRIDGE_MAX 3
862
863 #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
864 #endif
865
866 #if !HAVE_DECL_IFLA_BR_PRIORITY
867 #define IFLA_BR_UNSPEC 0
868 #define IFLA_BR_FORWARD_DELAY 1
869 #define IFLA_BR_HELLO_TIME 2
870 #define IFLA_BR_MAX_AGE 3
871 #define IFLA_BR_AGEING_TIME 4
872 #define IFLA_BR_STP_STATE 5
873 #define IFLA_BR_PRIORITY 6
874 #define __IFLA_BR_MAX 7
875
876 #define IFLA_BR_MAX (__IFLA_BR_MAX - 1)
877 #endif
878
879 #if !HAVE_DECL_IFLA_BRPORT_LEARNING_SYNC
880 #define IFLA_BRPORT_UNSPEC 0
881 #define IFLA_BRPORT_STATE 1
882 #define IFLA_BRPORT_PRIORITY 2
883 #define IFLA_BRPORT_COST 3
884 #define IFLA_BRPORT_MODE 4
885 #define IFLA_BRPORT_GUARD 5
886 #define IFLA_BRPORT_PROTECT 6
887 #define IFLA_BRPORT_FAST_LEAVE 7
888 #define IFLA_BRPORT_LEARNING 8
889 #define IFLA_BRPORT_UNICAST_FLOOD 9
890 #define IFLA_BRPORT_PROXYARP 10
891 #define IFLA_BRPORT_LEARNING_SYNC 11
892 #define __IFLA_BRPORT_MAX 12
893
894 #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
895 #endif
896
897 #if !HAVE_DECL_NDA_IFINDEX
898 #define NDA_UNSPEC 0
899 #define NDA_DST 1
900 #define NDA_LLADDR 2
901 #define NDA_CACHEINFO 3
902 #define NDA_PROBES 4
903 #define NDA_VLAN 5
904 #define NDA_PORT 6
905 #define NDA_VNI 7
906 #define NDA_IFINDEX 8
907 #define __NDA_MAX 9
908
909 #define NDA_MAX (__NDA_MAX - 1)
910 #endif
911
912 #ifndef RTA_PREF
913 #define RTA_PREF 20
914 #endif
915
916 #ifndef IPV6_UNICAST_IF
917 #define IPV6_UNICAST_IF 76
918 #endif
919
920 #ifndef IFF_MULTI_QUEUE
921 #define IFF_MULTI_QUEUE 0x100
922 #endif
923
924 #ifndef IFF_LOWER_UP
925 #define IFF_LOWER_UP 0x10000
926 #endif
927
928 #ifndef IFF_DORMANT
929 #define IFF_DORMANT 0x20000
930 #endif
931
932 #ifndef BOND_XMIT_POLICY_ENCAP23
933 #define BOND_XMIT_POLICY_ENCAP23 3
934 #endif
935
936 #ifndef BOND_XMIT_POLICY_ENCAP34
937 #define BOND_XMIT_POLICY_ENCAP34 4
938 #endif
939
940 #ifndef NET_ADDR_RANDOM
941 #  define NET_ADDR_RANDOM 1
942 #endif
943
944 #ifndef NET_NAME_UNKNOWN
945 #  define NET_NAME_UNKNOWN 0
946 #endif
947
948 #ifndef NET_NAME_ENUM
949 #  define NET_NAME_ENUM 1
950 #endif
951
952 #ifndef NET_NAME_PREDICTABLE
953 #  define NET_NAME_PREDICTABLE 2
954 #endif
955
956 #ifndef NET_NAME_USER
957 #  define NET_NAME_USER 3
958 #endif
959
960 #ifndef NET_NAME_RENAMED
961 #  define NET_NAME_RENAMED 4
962 #endif
963
964 #ifndef BPF_XOR
965 #  define BPF_XOR 0xa0
966 #endif
967
968 /* Note that LOOPBACK_IFINDEX is currently not exported by the
969  * kernel/glibc, but hardcoded internally by the kernel.  However, as
970  * it is exported to userspace indirectly via rtnetlink and the
971  * ioctls, and made use of widely we define it here too, in a way that
972  * is compatible with the kernel's internal definition. */
973 #ifndef LOOPBACK_IFINDEX
974 #define LOOPBACK_IFINDEX 1
975 #endif
976
977 #if !HAVE_DECL_IFA_FLAGS
978 #define IFA_FLAGS 8
979 #endif
980
981 #ifndef IFA_F_MANAGETEMPADDR
982 #define IFA_F_MANAGETEMPADDR 0x100
983 #endif
984
985 #ifndef IFA_F_NOPREFIXROUTE
986 #define IFA_F_NOPREFIXROUTE 0x200
987 #endif
988
989 #ifndef MAX_AUDIT_MESSAGE_LENGTH
990 #define MAX_AUDIT_MESSAGE_LENGTH 8970
991 #endif
992
993 #ifndef AUDIT_NLGRP_MAX
994 #define AUDIT_NLGRP_READLOG 1
995 #endif
996
997 #ifndef CAP_MAC_OVERRIDE
998 #define CAP_MAC_OVERRIDE 32
999 #endif
1000
1001 #ifndef CAP_MAC_ADMIN
1002 #define CAP_MAC_ADMIN 33
1003 #endif
1004
1005 #ifndef CAP_SYSLOG
1006 #define CAP_SYSLOG 34
1007 #endif
1008
1009 #ifndef CAP_WAKE_ALARM
1010 #define CAP_WAKE_ALARM 35
1011 #endif
1012
1013 #ifndef CAP_BLOCK_SUSPEND
1014 #define CAP_BLOCK_SUSPEND 36
1015 #endif
1016
1017 #ifndef CAP_AUDIT_READ
1018 #define CAP_AUDIT_READ 37
1019 #endif
1020
1021 static inline int raw_clone(unsigned long flags, void *child_stack) {
1022 #if defined(__s390__) || defined(__CRIS__)
1023         /* On s390 and cris the order of the first and second arguments
1024          * of the raw clone() system call is reversed. */
1025         return (int) syscall(__NR_clone, child_stack, flags);
1026 #else
1027         return (int) syscall(__NR_clone, flags, child_stack);
1028 #endif
1029 }
1030
1031 static inline pid_t raw_getpid(void) {
1032 #if defined(__alpha__)
1033         return (pid_t) syscall(__NR_getxpid);
1034 #else
1035         return (pid_t) syscall(__NR_getpid);
1036 #endif
1037 }
1038
1039 #if 0 /// UNNEEDED by elogind
1040
1041 #if !HAVE_DECL_RENAMEAT2
1042
1043
1044 #ifndef __NR_renameat2
1045 #  if defined __x86_64__
1046 #    define __NR_renameat2 316
1047 #  elif defined __arm__
1048 #    define __NR_renameat2 382
1049 #  elif defined _MIPS_SIM
1050 #    if _MIPS_SIM == _MIPS_SIM_ABI32
1051 #      define __NR_renameat2 4351
1052 #    endif
1053 #    if _MIPS_SIM == _MIPS_SIM_NABI32
1054 #      define __NR_renameat2 6315
1055 #    endif
1056 #    if _MIPS_SIM == _MIPS_SIM_ABI64
1057 #      define __NR_renameat2 5311
1058 #    endif
1059 #  elif defined __i386__
1060 #    define __NR_renameat2 353
1061 #  else
1062 #    warning "__NR_renameat2 unknown for your architecture"
1063 #    define __NR_renameat2 0xffffffff
1064 #  endif
1065 #endif
1066
1067 static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
1068         return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
1069 }
1070 #endif
1071
1072 #ifndef RENAME_NOREPLACE
1073 #define RENAME_NOREPLACE (1 << 0)
1074 #endif
1075
1076 #if !HAVE_DECL_KCMP
1077 static inline int kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
1078 #if defined(__NR_kcmp)
1079         return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
1080 #else
1081         errno = ENOSYS;
1082         return -1;
1083 #endif
1084 }
1085 #endif
1086
1087 #ifndef KCMP_FILE
1088 #define KCMP_FILE 0
1089 #endif
1090
1091 #ifndef INPUT_PROP_POINTING_STICK
1092 #define INPUT_PROP_POINTING_STICK 0x05
1093 #endif
1094
1095 #ifndef INPUT_PROP_ACCELEROMETER
1096 #define INPUT_PROP_ACCELEROMETER  0x06
1097 #endif
1098
1099 #if !HAVE_DECL_KEY_SERIAL_T
1100 typedef int32_t key_serial_t;
1101 #endif
1102
1103 #if !HAVE_DECL_KEYCTL
1104 static inline long keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
1105 #if defined(__NR_keyctl)
1106         return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
1107 #else
1108         errno = ENOSYS;
1109         return -1;
1110 #endif
1111 }
1112
1113 static inline key_serial_t add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
1114 #if defined (__NR_add_key)
1115         return syscall(__NR_add_key, type, description, payload, plen, ringid);
1116 #else
1117         errno = ENOSYS;
1118         return -1;
1119 #endif
1120 }
1121
1122 static inline key_serial_t request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
1123 #if defined (__NR_request_key)
1124         return syscall(__NR_request_key, type, description, callout_info, destringid);
1125 #else
1126         errno = ENOSYS;
1127         return -1;
1128 #endif
1129 }
1130 #endif
1131
1132 #ifndef KEYCTL_READ
1133 #define KEYCTL_READ 11
1134 #endif
1135
1136 #ifndef KEYCTL_SET_TIMEOUT
1137 #define KEYCTL_SET_TIMEOUT 15
1138 #endif
1139
1140 #ifndef KEY_SPEC_USER_KEYRING
1141 #define KEY_SPEC_USER_KEYRING -4
1142 #endif
1143 #endif // 0
1144
1145 #ifndef PR_CAP_AMBIENT
1146 #define PR_CAP_AMBIENT 47
1147 #endif
1148
1149 #ifndef PR_CAP_AMBIENT_IS_SET
1150 #define PR_CAP_AMBIENT_IS_SET 1
1151 #endif
1152
1153 #ifndef PR_CAP_AMBIENT_RAISE
1154 #define PR_CAP_AMBIENT_RAISE 2
1155 #endif
1156
1157 #ifndef PR_CAP_AMBIENT_CLEAR_ALL
1158 #define PR_CAP_AMBIENT_CLEAR_ALL 4
1159 #endif
1160
1161 /* The following two defines are actually available in the kernel headers for longer, but we define them here anyway,
1162  * since that makes it easier to use them in conjunction with the glibc net/if.h header which conflicts with
1163  * linux/if.h. */
1164 #ifndef IF_OPER_UNKNOWN
1165 #define IF_OPER_UNKNOWN 0
1166 #endif
1167
1168 #ifndef IF_OPER_UP
1169 #define IF_OPER_UP 6
1170
1171 #ifndef HAVE_DECL_CHAR32_T
1172 #define char32_t uint32_t
1173 #endif
1174
1175 #ifndef HAVE_DECL_CHAR16_T
1176 #define char16_t uint16_t
1177 #endif
1178
1179 #endif