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