]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/missing.h
Merge pull request #2608 from poettering/resolved-prop-fix
[thirdparty/systemd.git] / src / basic / missing.h
CommitLineData
c2f1db8f 1#pragma once
b9f880f4 2
15ae422b
LP
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
5430f7f2
LP
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
15ae422b
LP
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
5430f7f2 16 Lesser General Public License for more details.
15ae422b 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
15ae422b
LP
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
b9f880f4
LP
22/* Missing glibc definitions to access certain kernel APIs */
23
3b794314 24#include <errno.h>
8ae4b6d1 25#include <fcntl.h>
875c2e22 26#include <linux/audit.h>
2822da4f 27#include <linux/capability.h>
8ae4b6d1
TG
28#include <linux/if_link.h>
29#include <linux/input.h>
30#include <linux/loop.h>
cf1755ba 31#include <linux/neighbour.h>
8ae4b6d1
TG
32#include <linux/oom.h>
33#include <linux/rtnetlink.h>
34#include <stdlib.h>
35#include <sys/resource.h>
36#include <sys/syscall.h>
c932fb71 37#include <uchar.h>
8ae4b6d1 38#include <unistd.h>
dd6c17b1
LP
39
40#ifdef HAVE_AUDIT
41#include <libaudit.h>
42#endif
b9f880f4 43
d59d0a2b 44#ifdef ARCH_MIPS
45#include <asm/sgidefs.h>
46#endif
47
700c6087
LP
48#ifdef HAVE_LINUX_BTRFS_H
49#include <linux/btrfs.h>
50#endif
51
a60e9f7f
LP
52#include "macro.h"
53
b9f880f4
LP
54#ifndef RLIMIT_RTTIME
55#define RLIMIT_RTTIME 15
56#endif
57
517d56b1
LP
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
4fd5948e
LP
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
a6082d77
DM
73#ifndef F_ADD_SEALS
74#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
a6082d77 75#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
a6082d77 76
a6082d77 77#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
a6082d77 78#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
a6082d77 79#define F_SEAL_GROW 0x0004 /* prevent file from growing */
a6082d77
DM
80#define F_SEAL_WRITE 0x0008 /* prevent writes */
81#endif
82
f4a53250
MM
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
a6082d77 89#ifndef MFD_ALLOW_SEALING
45071fca
LP
90#define MFD_ALLOW_SEALING 0x0002U
91#endif
92
93#ifndef MFD_CLOEXEC
94#define MFD_CLOEXEC 0x0001U
a6082d77
DM
95#endif
96
16c42ce1
KS
97#ifndef IP_FREEBIND
98#define IP_FREEBIND 15
99#endif
100
dd6c17b1
LP
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
15ae422b 108
4927fcae 109#ifndef AUDIT_SERVICE_START
dd6c17b1 110#define AUDIT_SERVICE_START 1130 /* Service (daemon) start */
4927fcae
LP
111#endif
112
113#ifndef AUDIT_SERVICE_STOP
dd6c17b1 114#define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */
4927fcae
LP
115#endif
116
6ea832a2
LP
117#ifndef TIOCVHANGUP
118#define TIOCVHANGUP 0x5437
119#endif
120
b90865ba
KS
121#ifndef IP_TRANSPARENT
122#define IP_TRANSPARENT 19
123#endif
124
66269b05
TG
125#ifndef SOL_NETLINK
126#define SOL_NETLINK 270
127#endif
128
9c5a882b
TG
129#ifndef NETLINK_LIST_MEMBERSHIPS
130#define NETLINK_LIST_MEMBERSHIPS 9
131#endif
132
62bc4efc
SS
133#ifndef SOL_SCTP
134#define SOL_SCTP 132
135#endif
136
a8348796 137#if !HAVE_DECL_PIVOT_ROOT
dd6c17b1
LP
138static inline int pivot_root(const char *new_root, const char *put_old) {
139 return syscall(SYS_pivot_root, new_root, put_old);
140}
a8348796 141#endif
dd6c17b1 142
b244d9f3
LP
143#ifndef __NR_memfd_create
144# if defined __x86_64__
a6082d77 145# define __NR_memfd_create 319
b244d9f3 146# elif defined __arm__
a6082d77 147# define __NR_memfd_create 385
7fd68245
MO
148# elif defined __aarch64__
149# define __NR_memfd_create 279
7bcff8da
HB
150# elif defined __s390__
151# define __NR_memfd_create 350
b244d9f3 152# elif defined _MIPS_SIM
e6c01902
VOR
153# if _MIPS_SIM == _MIPS_SIM_ABI32
154# define __NR_memfd_create 4354
155# endif
156# if _MIPS_SIM == _MIPS_SIM_NABI32
157# define __NR_memfd_create 6318
158# endif
159# if _MIPS_SIM == _MIPS_SIM_ABI64
160# define __NR_memfd_create 5314
161# endif
03e8fdb3 162# elif defined __i386__
a6082d77 163# define __NR_memfd_create 356
03e8fdb3
DH
164# else
165# warning "__NR_memfd_create unknown for your architecture"
166# define __NR_memfd_create 0xffffffff
a6082d77 167# endif
22be093f
LP
168#endif
169
a6082d77 170#ifndef HAVE_MEMFD_CREATE
06b7f7bd 171static inline int memfd_create(const char *name, unsigned int flags) {
46327770 172 return syscall(__NR_memfd_create, name, flags);
a6082d77
DM
173}
174#endif
175
539618a0
LP
176#ifndef __NR_getrandom
177# if defined __x86_64__
74a550c5 178# define __NR_getrandom 318
568981d2
ZJS
179# elif defined(__i386__)
180# define __NR_getrandom 355
7fd68245 181# elif defined(__arm__)
568981d2 182# define __NR_getrandom 384
7fd68245
MO
183# elif defined(__aarch64__)
184# define __NR_getrandom 278
568981d2
ZJS
185# elif defined(__ia64__)
186# define __NR_getrandom 1339
187# elif defined(__m68k__)
188# define __NR_getrandom 352
189# elif defined(__s390x__)
190# define __NR_getrandom 349
d01efa07
MH
191# elif defined(__powerpc__)
192# define __NR_getrandom 359
3bec6d46
AK
193# elif defined _MIPS_SIM
194# if _MIPS_SIM == _MIPS_SIM_ABI32
195# define __NR_getrandom 4353
196# endif
197# if _MIPS_SIM == _MIPS_SIM_NABI32
198# define __NR_getrandom 6317
199# endif
200# if _MIPS_SIM == _MIPS_SIM_ABI64
201# define __NR_getrandom 5313
202# endif
539618a0
LP
203# else
204# warning "__NR_getrandom unknown for your architecture"
205# define __NR_getrandom 0xffffffff
206# endif
207#endif
208
209#if !HAVE_DECL_GETRANDOM
210static inline int getrandom(void *buffer, size_t count, unsigned flags) {
211 return syscall(__NR_getrandom, buffer, count, flags);
212}
213#endif
214
97768fc5
LP
215#ifndef GRND_NONBLOCK
216#define GRND_NONBLOCK 0x0001
217#endif
218
219#ifndef GRND_RANDOM
220#define GRND_RANDOM 0x0002
221#endif
222
4b357e15
MM
223#ifndef BTRFS_IOCTL_MAGIC
224#define BTRFS_IOCTL_MAGIC 0x94
225#endif
226
227#ifndef BTRFS_PATH_NAME_MAX
228#define BTRFS_PATH_NAME_MAX 4087
229#endif
230
231#ifndef BTRFS_DEVICE_PATH_NAME_MAX
232#define BTRFS_DEVICE_PATH_NAME_MAX 1024
233#endif
234
235#ifndef BTRFS_FSID_SIZE
236#define BTRFS_FSID_SIZE 16
237#endif
238
239#ifndef BTRFS_UUID_SIZE
240#define BTRFS_UUID_SIZE 16
241#endif
242
8e8ba792
MO
243#ifndef BTRFS_SUBVOL_RDONLY
244#define BTRFS_SUBVOL_RDONLY (1ULL << 1)
245#endif
246
247#ifndef BTRFS_SUBVOL_NAME_MAX
248#define BTRFS_SUBVOL_NAME_MAX 4039
249#endif
250
251#ifndef BTRFS_INO_LOOKUP_PATH_MAX
252#define BTRFS_INO_LOOKUP_PATH_MAX 4080
253#endif
254
255#ifndef BTRFS_SEARCH_ARGS_BUFSIZE
256#define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
257#endif
258
3f952f92
LP
259#ifndef BTRFS_QGROUP_LEVEL_SHIFT
260#define BTRFS_QGROUP_LEVEL_SHIFT 48
261#endif
262
4b357e15
MM
263#ifndef HAVE_LINUX_BTRFS_H
264struct btrfs_ioctl_vol_args {
265 int64_t fd;
266 char name[BTRFS_PATH_NAME_MAX + 1];
267};
268
8e8ba792
MO
269struct btrfs_qgroup_limit {
270 __u64 flags;
271 __u64 max_rfer;
272 __u64 max_excl;
273 __u64 rsv_rfer;
274 __u64 rsv_excl;
275};
276
277struct 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
d97fb408
MO
286struct btrfs_ioctl_qgroup_limit_args {
287 __u64 qgroupid;
288 struct btrfs_qgroup_limit lim;
289};
290
8e8ba792
MO
291struct 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
4b357e15
MM
305struct 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
314struct 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};
8e8ba792
MO
320
321struct btrfs_ioctl_ino_lookup_args {
322 __u64 treeid;
323 __u64 objectid;
324 char name[BTRFS_INO_LOOKUP_PATH_MAX];
325};
326
327struct 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
363struct btrfs_ioctl_search_header {
364 __u64 transid;
365 __u64 objectid;
366 __u64 offset;
367 __u32 type;
368 __u32 len;
369};
370
371
372struct btrfs_ioctl_search_args {
373 struct btrfs_ioctl_search_key key;
374 char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
375};
376
377struct btrfs_ioctl_clone_range_args {
378 __s64 src_fd;
379 __u64 src_offset, src_length;
380 __u64 dest_offset;
381};
d97fb408
MO
382
383#define BTRFS_QUOTA_CTL_ENABLE 1
384#define BTRFS_QUOTA_CTL_DISABLE 2
385#define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
386struct btrfs_ioctl_quota_ctl_args {
387 __u64 cmd;
388 __u64 status;
389};
4b357e15
MM
390#endif
391
392#ifndef BTRFS_IOC_DEFRAG
7bed7f0e
ZJS
393#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
394 struct btrfs_ioctl_vol_args)
4b357e15
MM
395#endif
396
d97fb408
MO
397#ifndef BTRFS_IOC_RESIZE
398#define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
399 struct btrfs_ioctl_vol_args)
400#endif
401
8e8ba792
MO
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
4b357e15
MM
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, \
7bed7f0e
ZJS
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)
4b357e15
MM
457#endif
458
d97fb408
MO
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
10f9c755
LP
469#ifndef BTRFS_FIRST_FREE_OBJECTID
470#define BTRFS_FIRST_FREE_OBJECTID 256
471#endif
472
d9e2daaf
LP
473#ifndef BTRFS_LAST_FREE_OBJECTID
474#define BTRFS_LAST_FREE_OBJECTID -256ULL
475#endif
476
b6b18498
LP
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
10f9c755
LP
485#ifndef BTRFS_ROOT_ITEM_KEY
486#define BTRFS_ROOT_ITEM_KEY 132
487#endif
488
b6b18498
LP
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
5bcd08db
LP
501#ifndef BTRFS_QGROUP_RELATION_KEY
502#define BTRFS_QGROUP_RELATION_KEY 246
503#endif
504
d9e2daaf
LP
505#ifndef BTRFS_ROOT_BACKREF_KEY
506#define BTRFS_ROOT_BACKREF_KEY 144
507#endif
508
746f8906
LP
509#ifndef BTRFS_SUPER_MAGIC
510#define BTRFS_SUPER_MAGIC 0x9123683E
511#endif
512
efdb0237
LP
513#ifndef CGROUP_SUPER_MAGIC
514#define CGROUP_SUPER_MAGIC 0x27e0eb
515#endif
516
517#ifndef TMPFS_MAGIC
518#define TMPFS_MAGIC 0x01021994
519#endif
520
94d82985
LP
521#ifndef MS_MOVE
522#define MS_MOVE 8192
523#endif
524
7cb1094a
HH
525#ifndef MS_PRIVATE
526#define MS_PRIVATE (1 << 18)
527#endif
528
a8348796 529#if !HAVE_DECL_GETTID
4d14be09
LP
530static inline pid_t gettid(void) {
531 return (pid_t) syscall(SYS_gettid);
532}
a8348796 533#endif
4d14be09 534
54ecda32
LP
535#ifndef SCM_SECURITY
536#define SCM_SECURITY 0x03
537#endif
538
48ac500b
LP
539#ifndef MS_STRICTATIME
540#define MS_STRICTATIME (1<<24)
541#endif
542
a9621528
AM
543#ifndef MS_REC
544#define MS_REC 16384
545#endif
546
547#ifndef MS_SHARED
548#define MS_SHARED (1<<20)
549#endif
550
8351ceae
LP
551#ifndef PR_SET_NO_NEW_PRIVS
552#define PR_SET_NO_NEW_PRIVS 38
553#endif
d4447f4d
AK
554
555#ifndef PR_SET_CHILD_SUBREAPER
556#define PR_SET_CHILD_SUBREAPER 36
557#endif
a8348796
LP
558
559#ifndef MAX_HANDLE_SZ
560#define MAX_HANDLE_SZ 128
561#endif
562
66330455
LP
563#ifndef __NR_name_to_handle_at
564# if defined(__x86_64__)
848af055 565# define __NR_name_to_handle_at 303
66330455 566# elif defined(__i386__)
848af055 567# define __NR_name_to_handle_at 341
66330455 568# elif defined(__arm__)
f527b6b8 569# define __NR_name_to_handle_at 370
66330455 570# elif defined(__powerpc__)
f527b6b8 571# define __NR_name_to_handle_at 345
66330455
LP
572# else
573# error "__NR_name_to_handle_at is not defined"
f527b6b8 574# endif
a8348796
LP
575#endif
576
9388e99e 577#if !HAVE_DECL_NAME_TO_HANDLE_AT
a8348796
LP
578struct file_handle {
579 unsigned int handle_bytes;
580 int handle_type;
581 unsigned char f_handle[0];
582};
583
584static inline int name_to_handle_at(int fd, const char *name, struct file_handle *handle, int *mnt_id, int flags) {
585 return syscall(__NR_name_to_handle_at, fd, name, handle, mnt_id, flags);
586}
587#endif
4db17f29
ZJS
588
589#ifndef HAVE_SECURE_GETENV
590# ifdef HAVE___SECURE_GETENV
591# define secure_getenv __secure_getenv
592# else
66330455 593# error "neither secure_getenv nor __secure_getenv are available"
4db17f29
ZJS
594# endif
595#endif
85210bff
LP
596
597#ifndef CIFS_MAGIC_NUMBER
65b3903f 598# define CIFS_MAGIC_NUMBER 0xFF534D42
85210bff 599#endif
8742514c
LP
600
601#ifndef TFD_TIMER_CANCEL_ON_SET
65b3903f 602# define TFD_TIMER_CANCEL_ON_SET (1 << 1)
8742514c 603#endif
f7db7a69
SL
604
605#ifndef SO_REUSEPORT
65b3903f 606# define SO_REUSEPORT 15
f7db7a69 607#endif
118ecf32
DH
608
609#ifndef EVIOCREVOKE
65b3903f 610# define EVIOCREVOKE _IOW('E', 0x91, int)
118ecf32
DH
611#endif
612
613#ifndef DRM_IOCTL_SET_MASTER
65b3903f 614# define DRM_IOCTL_SET_MASTER _IO('d', 0x1e)
118ecf32
DH
615#endif
616
617#ifndef DRM_IOCTL_DROP_MASTER
65b3903f
ZJS
618# define DRM_IOCTL_DROP_MASTER _IO('d', 0x1f)
619#endif
620
c09918f9
LP
621#if defined(__i386__) || defined(__x86_64__)
622
623/* The precise definition of __O_TMPFILE is arch specific, so let's
624 * just define this on x86 where we know the value. */
625
626#ifndef __O_TMPFILE
627#define __O_TMPFILE 020000000
628#endif
629
630/* a horrid kludge trying to make sure that this will fail on old kernels */
631#ifndef O_TMPFILE
632#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
633#endif
634
635#endif
3b794314
HS
636
637#ifndef __NR_setns
638# if defined(__x86_64__)
639# define __NR_setns 308
640# elif defined(__i386__)
641# define __NR_setns 346
642# else
643# error "__NR_setns is not defined"
644# endif
645#endif
646
647#if !HAVE_DECL_SETNS
648static inline int setns(int fd, int nstype) {
649 return syscall(__NR_setns, fd, nstype);
650}
651#endif
5f381b35
LP
652
653#if !HAVE_DECL_LO_FLAGS_PARTSCAN
654#define LO_FLAGS_PARTSCAN 8
655#endif
a853c45d
LP
656
657#ifndef LOOP_CTL_REMOVE
658#define LOOP_CTL_REMOVE 0x4C81
659#endif
660
661#ifndef LOOP_CTL_GET_FREE
662#define LOOP_CTL_GET_FREE 0x4C82
663#endif
0830ba61 664
84dd59b5
DH
665#if !HAVE_DECL_IFLA_INET6_ADDR_GEN_MODE
666#define IFLA_INET6_UNSPEC 0
667#define IFLA_INET6_FLAGS 1
668#define IFLA_INET6_CONF 2
669#define IFLA_INET6_STATS 3
670#define IFLA_INET6_MCAST 4
671#define IFLA_INET6_CACHEINFO 5
672#define IFLA_INET6_ICMP6STATS 6
673#define IFLA_INET6_TOKEN 7
674#define IFLA_INET6_ADDR_GEN_MODE 8
675#define __IFLA_INET6_MAX 9
676
677#define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
678
679#define IN6_ADDR_GEN_MODE_EUI64 0
680#define IN6_ADDR_GEN_MODE_NONE 1
681#endif
682
75616a13
ZJS
683#if !HAVE_DECL_IFLA_MACVLAN_FLAGS
684#define IFLA_MACVLAN_UNSPEC 0
685#define IFLA_MACVLAN_MODE 1
686#define IFLA_MACVLAN_FLAGS 2
687#define __IFLA_MACVLAN_MAX 3
688
689#define IFLA_MACVLAN_MAX (__IFLA_MACVLAN_MAX - 1)
690#endif
691
c4a5ddc9
TG
692#if !HAVE_DECL_IFLA_IPVLAN_MODE
693#define IFLA_IPVLAN_UNSPEC 0
694#define IFLA_IPVLAN_MODE 1
695#define __IFLA_IPVLAN_MAX 2
696
697#define IFLA_IPVLAN_MAX (__IFLA_IPVLAN_MAX - 1)
698
699#define IPVLAN_MODE_L2 0
700#define IPVLAN_MODE_L3 1
701#define IPVLAN_MAX 2
702#endif
703
6589d0db
JAS
704#if !HAVE_DECL_IFLA_VTI_REMOTE
705#define IFLA_VTI_UNSPEC 0
706#define IFLA_VTI_LINK 1
707#define IFLA_VTI_IKEY 2
708#define IFLA_VTI_OKEY 3
709#define IFLA_VTI_LOCAL 4
710#define IFLA_VTI_REMOTE 5
711#define __IFLA_VTI_MAX 6
712
713#define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1)
714#endif
715
81577dc2
ZJS
716#if !HAVE_DECL_IFLA_PHYS_PORT_ID
717#undef IFLA_PROMISCUITY
718#define IFLA_PROMISCUITY 30
719#define IFLA_NUM_TX_QUEUES 31
720#define IFLA_NUM_RX_QUEUES 32
721#define IFLA_CARRIER 33
722#define IFLA_PHYS_PORT_ID 34
723#define __IFLA_MAX 35
724
725#define IFLA_MAX (__IFLA_MAX - 1)
726#endif
727
728#if !HAVE_DECL_IFLA_BOND_AD_INFO
729#define IFLA_BOND_UNSPEC 0
730#define IFLA_BOND_MODE 1
731#define IFLA_BOND_ACTIVE_SLAVE 2
732#define IFLA_BOND_MIIMON 3
733#define IFLA_BOND_UPDELAY 4
734#define IFLA_BOND_DOWNDELAY 5
735#define IFLA_BOND_USE_CARRIER 6
736#define IFLA_BOND_ARP_INTERVAL 7
737#define IFLA_BOND_ARP_IP_TARGET 8
738#define IFLA_BOND_ARP_VALIDATE 9
739#define IFLA_BOND_ARP_ALL_TARGETS 10
740#define IFLA_BOND_PRIMARY 11
741#define IFLA_BOND_PRIMARY_RESELECT 12
742#define IFLA_BOND_FAIL_OVER_MAC 13
743#define IFLA_BOND_XMIT_HASH_POLICY 14
744#define IFLA_BOND_RESEND_IGMP 15
745#define IFLA_BOND_NUM_PEER_NOTIF 16
746#define IFLA_BOND_ALL_SLAVES_ACTIVE 17
747#define IFLA_BOND_MIN_LINKS 18
748#define IFLA_BOND_LP_INTERVAL 19
749#define IFLA_BOND_PACKETS_PER_SLAVE 20
750#define IFLA_BOND_AD_LACP_RATE 21
751#define IFLA_BOND_AD_SELECT 22
752#define IFLA_BOND_AD_INFO 23
753#define __IFLA_BOND_MAX 24
0830ba61 754
79306206 755#define IFLA_BOND_MAX (__IFLA_BOND_MAX - 1)
0830ba61 756#endif
81577dc2
ZJS
757
758#if !HAVE_DECL_IFLA_VLAN_PROTOCOL
759#define IFLA_VLAN_UNSPEC 0
760#define IFLA_VLAN_ID 1
761#define IFLA_VLAN_FLAGS 2
762#define IFLA_VLAN_EGRESS_QOS 3
763#define IFLA_VLAN_INGRESS_QOS 4
764#define IFLA_VLAN_PROTOCOL 5
765#define __IFLA_VLAN_MAX 6
766
767#define IFLA_VLAN_MAX (__IFLA_VLAN_MAX - 1)
768#endif
769
583c14fc 770#if !HAVE_DECL_IFLA_VXLAN_REMCSUM_NOPARTIAL
81577dc2
ZJS
771#define IFLA_VXLAN_UNSPEC 0
772#define IFLA_VXLAN_ID 1
773#define IFLA_VXLAN_GROUP 2
774#define IFLA_VXLAN_LINK 3
775#define IFLA_VXLAN_LOCAL 4
776#define IFLA_VXLAN_TTL 5
777#define IFLA_VXLAN_TOS 6
778#define IFLA_VXLAN_LEARNING 7
779#define IFLA_VXLAN_AGEING 8
780#define IFLA_VXLAN_LIMIT 9
781#define IFLA_VXLAN_PORT_RANGE 10
782#define IFLA_VXLAN_PROXY 11
783#define IFLA_VXLAN_RSC 12
784#define IFLA_VXLAN_L2MISS 13
785#define IFLA_VXLAN_L3MISS 14
786#define IFLA_VXLAN_PORT 15
787#define IFLA_VXLAN_GROUP6 16
788#define IFLA_VXLAN_LOCAL6 17
583c14fc
MO
789#define IFLA_VXLAN_UDP_CSUM 18
790#define IFLA_VXLAN_UDP_ZERO_CSUM6_TX 19
791#define IFLA_VXLAN_UDP_ZERO_CSUM6_RX 20
792#define IFLA_VXLAN_REMCSUM_TX 21
793#define IFLA_VXLAN_REMCSUM_RX 22
794#define IFLA_VXLAN_GBP 23
795#define IFLA_VXLAN_REMCSUM_NOPARTIAL 24
796#define __IFLA_VXLAN_MAX 25
81577dc2
ZJS
797
798#define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)
799#endif
800
56bf3853 801#if !HAVE_DECL_IFLA_IPTUN_ENCAP_DPORT
81577dc2
ZJS
802#define IFLA_IPTUN_UNSPEC 0
803#define IFLA_IPTUN_LINK 1
804#define IFLA_IPTUN_LOCAL 2
805#define IFLA_IPTUN_REMOTE 3
806#define IFLA_IPTUN_TTL 4
807#define IFLA_IPTUN_TOS 5
808#define IFLA_IPTUN_ENCAP_LIMIT 6
809#define IFLA_IPTUN_FLOWINFO 7
810#define IFLA_IPTUN_FLAGS 8
811#define IFLA_IPTUN_PROTO 9
812#define IFLA_IPTUN_PMTUDISC 10
813#define IFLA_IPTUN_6RD_PREFIX 11
814#define IFLA_IPTUN_6RD_RELAY_PREFIX 12
815#define IFLA_IPTUN_6RD_PREFIXLEN 13
816#define IFLA_IPTUN_6RD_RELAY_PREFIXLEN 14
56bf3853
SS
817#define IFLA_IPTUN_ENCAP_TYPE 15
818#define IFLA_IPTUN_ENCAP_FLAGS 16
819#define IFLA_IPTUN_ENCAP_SPORT 17
820#define IFLA_IPTUN_ENCAP_DPORT 18
821
822#define __IFLA_IPTUN_MAX 19
81577dc2
ZJS
823
824#define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1)
825#endif
826
66f4bc77
SS
827#if !HAVE_DECL_IFLA_GRE_ENCAP_DPORT
828#define IFLA_GRE_UNSPEC 0
829#define IFLA_GRE_LINK 1
830#define IFLA_GRE_IFLAGS 2
831#define IFLA_GRE_OFLAGS 3
832#define IFLA_GRE_IKEY 4
833#define IFLA_GRE_OKEY 5
834#define IFLA_GRE_LOCAL 6
835#define IFLA_GRE_REMOTE 7
836#define IFLA_GRE_TTL 8
837#define IFLA_GRE_TOS 9
838#define IFLA_GRE_PMTUDISC 10
839#define IFLA_GRE_ENCAP_LIMIT 11
840#define IFLA_GRE_FLOWINFO 12
841#define IFLA_GRE_FLAGS 13
842#define IFLA_GRE_ENCAP_TYPE 14
843#define IFLA_GRE_ENCAP_FLAGS 15
844#define IFLA_GRE_ENCAP_SPORT 16
845#define IFLA_GRE_ENCAP_DPORT 17
846
847#define __IFLA_GRE_MAX 18
848
849#define IFLA_GRE_MAX (__IFLA_GRE_MAX - 1)
850#endif
851
81577dc2
ZJS
852#if !HAVE_DECL_IFLA_BRIDGE_VLAN_INFO
853#define IFLA_BRIDGE_FLAGS 0
854#define IFLA_BRIDGE_MODE 1
855#define IFLA_BRIDGE_VLAN_INFO 2
856#define __IFLA_BRIDGE_MAX 3
857
858#define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
859#endif
623a4c97 860
c3eae485
SS
861#if !HAVE_DECL_IFLA_BR_PRIORITY
862#define IFLA_BR_UNSPEC 0
863#define IFLA_BR_FORWARD_DELAY 1
864#define IFLA_BR_HELLO_TIME 2
865#define IFLA_BR_MAX_AGE 3
866#define IFLA_BR_AGEING_TIME 4
867#define IFLA_BR_STP_STATE 5
868#define IFLA_BR_PRIORITY 6
869#define __IFLA_BR_MAX 7
870
871#define IFLA_BR_MAX (__IFLA_BR_MAX - 1)
872#endif
873
38a0245f 874#if !HAVE_DECL_IFLA_BRPORT_LEARNING_SYNC
8ecec322
ZJS
875#define IFLA_BRPORT_UNSPEC 0
876#define IFLA_BRPORT_STATE 1
877#define IFLA_BRPORT_PRIORITY 2
878#define IFLA_BRPORT_COST 3
879#define IFLA_BRPORT_MODE 4
880#define IFLA_BRPORT_GUARD 5
881#define IFLA_BRPORT_PROTECT 6
882#define IFLA_BRPORT_FAST_LEAVE 7
883#define IFLA_BRPORT_LEARNING 8
884#define IFLA_BRPORT_UNICAST_FLOOD 9
38a0245f
SS
885#define IFLA_BRPORT_PROXYARP 10
886#define IFLA_BRPORT_LEARNING_SYNC 11
887#define __IFLA_BRPORT_MAX 12
8ecec322
ZJS
888
889#define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
890#endif
891
cf1755ba
MO
892#if !HAVE_DECL_NDA_IFINDEX
893#define NDA_UNSPEC 0
894#define NDA_DST 1
895#define NDA_LLADDR 2
896#define NDA_CACHEINFO 3
897#define NDA_PROBES 4
898#define NDA_VLAN 5
899#define NDA_PORT 6
900#define NDA_VNI 7
901#define NDA_IFINDEX 8
902#define __NDA_MAX 9
903
904#define NDA_MAX (__NDA_MAX - 1)
905#endif
906
b69015ef
TG
907#ifndef RTA_PREF
908#define RTA_PREF 20
909#endif
910
623a4c97
LP
911#ifndef IPV6_UNICAST_IF
912#define IPV6_UNICAST_IF 76
913#endif
ec2c5e43 914
04d180c8
TG
915#ifndef IFF_MULTI_QUEUE
916#define IFF_MULTI_QUEUE 0x100
917#endif
918
ec2c5e43
LP
919#ifndef IFF_LOWER_UP
920#define IFF_LOWER_UP 0x10000
921#endif
922
923#ifndef IFF_DORMANT
924#define IFF_DORMANT 0x20000
925#endif
91988149
LP
926
927#ifndef BOND_XMIT_POLICY_ENCAP23
928#define BOND_XMIT_POLICY_ENCAP23 3
929#endif
930
931#ifndef BOND_XMIT_POLICY_ENCAP34
932#define BOND_XMIT_POLICY_ENCAP34 4
933#endif
04b67d49
TG
934
935#ifndef NET_ADDR_RANDOM
936# define NET_ADDR_RANDOM 1
937#endif
938
1cb636d9
CW
939#ifndef NET_NAME_UNKNOWN
940# define NET_NAME_UNKNOWN 0
941#endif
942
04b67d49
TG
943#ifndef NET_NAME_ENUM
944# define NET_NAME_ENUM 1
945#endif
946
947#ifndef NET_NAME_PREDICTABLE
948# define NET_NAME_PREDICTABLE 2
949#endif
950
951#ifndef NET_NAME_USER
952# define NET_NAME_USER 3
953#endif
954
955#ifndef NET_NAME_RENAMED
956# define NET_NAME_RENAMED 4
957#endif
7965435e
MO
958
959#ifndef BPF_XOR
960# define BPF_XOR 0xa0
961#endif
a5f03596
LP
962
963/* Note that LOOPBACK_IFINDEX is currently not exported by the
964 * kernel/glibc, but hardcoded internally by the kernel. However, as
965 * it is exported to userspace indirectly via rtnetlink and the
966 * ioctls, and made use of widely we define it here too, in a way that
967 * is compatible with the kernel's internal definition. */
968#ifndef LOOPBACK_IFINDEX
969#define LOOPBACK_IFINDEX 1
970#endif
875c2e22 971
34f7b9f9
LP
972#if !HAVE_DECL_IFA_FLAGS
973#define IFA_FLAGS 8
974#endif
975
f217be19
DH
976#ifndef IFA_F_MANAGETEMPADDR
977#define IFA_F_MANAGETEMPADDR 0x100
978#endif
979
b06ac35c
AS
980#ifndef IFA_F_NOPREFIXROUTE
981#define IFA_F_NOPREFIXROUTE 0x200
982#endif
983
875c2e22
LP
984#ifndef MAX_AUDIT_MESSAGE_LENGTH
985#define MAX_AUDIT_MESSAGE_LENGTH 8970
986#endif
987
988#ifndef AUDIT_NLGRP_MAX
989#define AUDIT_NLGRP_READLOG 1
990#endif
2822da4f
LP
991
992#ifndef CAP_MAC_OVERRIDE
993#define CAP_MAC_OVERRIDE 32
994#endif
995
996#ifndef CAP_MAC_ADMIN
997#define CAP_MAC_ADMIN 33
998#endif
999
1000#ifndef CAP_SYSLOG
1001#define CAP_SYSLOG 34
1002#endif
1003
1004#ifndef CAP_WAKE_ALARM
1005#define CAP_WAKE_ALARM 35
1006#endif
1007
1008#ifndef CAP_BLOCK_SUSPEND
1009#define CAP_BLOCK_SUSPEND 36
1010#endif
1011
1012#ifndef CAP_AUDIT_READ
1013#define CAP_AUDIT_READ 37
1014#endif
60e1651a 1015
ee05e779 1016static inline int raw_clone(unsigned long flags, void *child_stack) {
60e1651a
KW
1017#if defined(__s390__) || defined(__CRIS__)
1018 /* On s390 and cris the order of the first and second arguments
1019 * of the raw clone() system call is reversed. */
ee05e779 1020 return (int) syscall(__NR_clone, child_stack, flags);
60e1651a 1021#else
ee05e779 1022 return (int) syscall(__NR_clone, flags, child_stack);
60e1651a
KW
1023#endif
1024}
ee05e779
ZJS
1025
1026static inline pid_t raw_getpid(void) {
a242a99d
MT
1027#if defined(__alpha__)
1028 return (pid_t) syscall(__NR_getxpid);
1029#else
ee05e779 1030 return (pid_t) syscall(__NR_getpid);
a242a99d 1031#endif
ee05e779 1032}
ebd93cb6
LP
1033
1034#if !HAVE_DECL_RENAMEAT2
e65ef51d
ZJS
1035
1036#ifndef __NR_renameat2
1037# if defined __x86_64__
1038# define __NR_renameat2 316
1039# elif defined __arm__
1040# define __NR_renameat2 382
1041# elif defined _MIPS_SIM
1042# if _MIPS_SIM == _MIPS_SIM_ABI32
1043# define __NR_renameat2 4351
1044# endif
1045# if _MIPS_SIM == _MIPS_SIM_NABI32
1046# define __NR_renameat2 6315
1047# endif
1048# if _MIPS_SIM == _MIPS_SIM_ABI64
1049# define __NR_renameat2 5311
1050# endif
1051# elif defined __i386__
1052# define __NR_renameat2 353
1053# else
1054# warning "__NR_renameat2 unknown for your architecture"
1055# define __NR_renameat2 0xffffffff
1056# endif
1057#endif
1058
ebd93cb6
LP
1059static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
1060 return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
1061}
1062#endif
1063
1064#ifndef RENAME_NOREPLACE
1065#define RENAME_NOREPLACE (1 << 0)
1066#endif
f7ad54a3
LP
1067
1068#if !HAVE_DECL_KCMP
1069static inline int kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) {
75b55457 1070#if defined(__NR_kcmp)
f7ad54a3 1071 return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2);
75b55457
MG
1072#else
1073 errno = ENOSYS;
1074 return -1;
1075#endif
f7ad54a3
LP
1076}
1077#endif
1078
1079#ifndef KCMP_FILE
1080#define KCMP_FILE 0
1081#endif
606df97b
PH
1082
1083#ifndef INPUT_PROP_POINTING_STICK
1084#define INPUT_PROP_POINTING_STICK 0x05
1085#endif
bd1acc9f
HG
1086
1087#ifndef INPUT_PROP_ACCELEROMETER
1088#define INPUT_PROP_ACCELEROMETER 0x06
1089#endif
e287086b
LP
1090
1091#if !HAVE_DECL_KEY_SERIAL_T
1092typedef int32_t key_serial_t;
1093#endif
1094
1095#if !HAVE_DECL_KEYCTL
1096static inline long keyctl(int cmd, unsigned long arg2, unsigned long arg3, unsigned long arg4,unsigned long arg5) {
1097#if defined(__NR_keyctl)
1098 return syscall(__NR_keyctl, cmd, arg2, arg3, arg4, arg5);
1099#else
1100 errno = ENOSYS;
1101 return -1;
1102#endif
1103}
1104
1105static inline key_serial_t add_key(const char *type, const char *description, const void *payload, size_t plen, key_serial_t ringid) {
1106#if defined (__NR_add_key)
1107 return syscall(__NR_add_key, type, description, payload, plen, ringid);
1108#else
1109 errno = ENOSYS;
1110 return -1;
1111#endif
1112}
1113
1114static inline key_serial_t request_key(const char *type, const char *description, const char * callout_info, key_serial_t destringid) {
1115#if defined (__NR_request_key)
1116 return syscall(__NR_request_key, type, description, callout_info, destringid);
1117#else
1118 errno = ENOSYS;
1119 return -1;
1120#endif
1121}
1122#endif
1123
1124#ifndef KEYCTL_READ
1125#define KEYCTL_READ 11
1126#endif
1127
1128#ifndef KEYCTL_SET_TIMEOUT
1129#define KEYCTL_SET_TIMEOUT 15
1130#endif
1131
1132#ifndef KEY_SPEC_USER_KEYRING
1133#define KEY_SPEC_USER_KEYRING -4
1134#endif
755d4b67
IP
1135
1136#ifndef PR_CAP_AMBIENT
1137#define PR_CAP_AMBIENT 47
1138#endif
1139
1140#ifndef PR_CAP_AMBIENT_IS_SET
1141#define PR_CAP_AMBIENT_IS_SET 1
1142#endif
1143
1144#ifndef PR_CAP_AMBIENT_RAISE
1145#define PR_CAP_AMBIENT_RAISE 2
1146#endif
1147
1148#ifndef PR_CAP_AMBIENT_CLEAR_ALL
1149#define PR_CAP_AMBIENT_CLEAR_ALL 4
1150#endif
6955a3ba
LP
1151
1152/* The following two defines are actually available in the kernel headers for longer, but we define them here anyway,
1153 * since that makes it easier to use them in conjunction with the glibc net/if.h header which conflicts with
1154 * linux/if.h. */
1155#ifndef IF_OPER_UNKNOWN
1156#define IF_OPER_UNKNOWN 0
1157#endif
1158
1159#ifndef IF_OPER_UP
1160#define IF_OPER_UP 6
c932fb71
SL
1161
1162#ifndef HAVE_DECL_CHAR32_T
1163#define char32_t uint32_t
1164#endif
1165
1166#ifndef HAVE_DECL_CHAR16_T
1167#define char16_t uint16_t
1168#endif
1169
6955a3ba 1170#endif