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