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