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