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