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