bpf.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
  2. *
  3. * This program is free software; you can redistribute it and/or
  4. * modify it under the terms of version 2 of the GNU General Public
  5. * License as published by the Free Software Foundation.
  6. */
  7. #ifndef _LINUX_BPF_H
  8. #define _LINUX_BPF_H 1
  9. #include <uapi/linux/bpf.h>
  10. #include <linux/workqueue.h>
  11. #include <linux/file.h>
  12. #include <linux/percpu.h>
  13. #include <linux/err.h>
  14. #include <linux/rbtree_latch.h>
  15. #include <linux/numa.h>
  16. #include <linux/wait.h>
  17. struct bpf_verifier_env;
  18. struct perf_event;
  19. struct bpf_prog;
  20. struct bpf_map;
  21. /* map is generic key/value storage optionally accesible by eBPF programs */
  22. struct bpf_map_ops {
  23. /* funcs callable from userspace (via syscall) */
  24. struct bpf_map *(*map_alloc)(union bpf_attr *attr);
  25. void (*map_release)(struct bpf_map *map, struct file *map_file);
  26. void (*map_free)(struct bpf_map *map);
  27. int (*map_get_next_key)(struct bpf_map *map, void *key, void *next_key);
  28. /* funcs callable from userspace and from eBPF programs */
  29. void *(*map_lookup_elem)(struct bpf_map *map, void *key);
  30. int (*map_update_elem)(struct bpf_map *map, void *key, void *value, u64 flags);
  31. int (*map_delete_elem)(struct bpf_map *map, void *key);
  32. /* funcs called by prog_array and perf_event_array map */
  33. void *(*map_fd_get_ptr)(struct bpf_map *map, struct file *map_file,
  34. int fd);
  35. void (*map_fd_put_ptr)(void *ptr);
  36. u32 (*map_gen_lookup)(struct bpf_map *map, struct bpf_insn *insn_buf);
  37. u32 (*map_fd_sys_lookup_elem)(void *ptr);
  38. };
  39. struct bpf_map {
  40. atomic_t refcnt;
  41. enum bpf_map_type map_type;
  42. u32 key_size;
  43. u32 value_size;
  44. u32 max_entries;
  45. u32 map_flags;
  46. u32 pages;
  47. u32 id;
  48. int numa_node;
  49. struct user_struct *user;
  50. const struct bpf_map_ops *ops;
  51. struct work_struct work;
  52. atomic_t usercnt;
  53. struct bpf_map *inner_map_meta;
  54. char name[BPF_OBJ_NAME_LEN];
  55. #ifdef CONFIG_SECURITY
  56. void *security;
  57. #endif
  58. };
  59. /* function argument constraints */
  60. enum bpf_arg_type {
  61. ARG_DONTCARE = 0, /* unused argument in helper function */
  62. /* the following constraints used to prototype
  63. * bpf_map_lookup/update/delete_elem() functions
  64. */
  65. ARG_CONST_MAP_PTR, /* const argument used as pointer to bpf_map */
  66. ARG_PTR_TO_MAP_KEY, /* pointer to stack used as map key */
  67. ARG_PTR_TO_MAP_VALUE, /* pointer to stack used as map value */
  68. /* the following constraints used to prototype bpf_memcmp() and other
  69. * functions that access data on eBPF program stack
  70. */
  71. ARG_PTR_TO_MEM, /* pointer to valid memory (stack, packet, map value) */
  72. ARG_PTR_TO_MEM_OR_NULL, /* pointer to valid memory or NULL */
  73. ARG_PTR_TO_UNINIT_MEM, /* pointer to memory does not need to be initialized,
  74. * helper function must fill all bytes or clear
  75. * them in error case.
  76. */
  77. ARG_CONST_SIZE, /* number of bytes accessed from memory */
  78. ARG_CONST_SIZE_OR_ZERO, /* number of bytes accessed from memory or 0 */
  79. ARG_PTR_TO_CTX, /* pointer to context */
  80. ARG_ANYTHING, /* any (initialized) argument is ok */
  81. };
  82. /* type of values returned from helper functions */
  83. enum bpf_return_type {
  84. RET_INTEGER, /* function returns integer */
  85. RET_VOID, /* function doesn't return anything */
  86. RET_PTR_TO_MAP_VALUE_OR_NULL, /* returns a pointer to map elem value or NULL */
  87. };
  88. /* eBPF function prototype used by verifier to allow BPF_CALLs from eBPF programs
  89. * to in-kernel helper functions and for adjusting imm32 field in BPF_CALL
  90. * instructions after verifying
  91. */
  92. struct bpf_func_proto {
  93. u64 (*func)(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
  94. bool gpl_only;
  95. bool pkt_access;
  96. enum bpf_return_type ret_type;
  97. enum bpf_arg_type arg1_type;
  98. enum bpf_arg_type arg2_type;
  99. enum bpf_arg_type arg3_type;
  100. enum bpf_arg_type arg4_type;
  101. enum bpf_arg_type arg5_type;
  102. };
  103. /* bpf_context is intentionally undefined structure. Pointer to bpf_context is
  104. * the first argument to eBPF programs.
  105. * For socket filters: 'struct bpf_context *' == 'struct sk_buff *'
  106. */
  107. struct bpf_context;
  108. enum bpf_access_type {
  109. BPF_READ = 1,
  110. BPF_WRITE = 2
  111. };
  112. /* types of values stored in eBPF registers */
  113. /* Pointer types represent:
  114. * pointer
  115. * pointer + imm
  116. * pointer + (u16) var
  117. * pointer + (u16) var + imm
  118. * if (range > 0) then [ptr, ptr + range - off) is safe to access
  119. * if (id > 0) means that some 'var' was added
  120. * if (off > 0) means that 'imm' was added
  121. */
  122. enum bpf_reg_type {
  123. NOT_INIT = 0, /* nothing was written into register */
  124. SCALAR_VALUE, /* reg doesn't contain a valid pointer */
  125. PTR_TO_CTX, /* reg points to bpf_context */
  126. CONST_PTR_TO_MAP, /* reg points to struct bpf_map */
  127. PTR_TO_MAP_VALUE, /* reg points to map element value */
  128. PTR_TO_MAP_VALUE_OR_NULL,/* points to map elem value or NULL */
  129. PTR_TO_STACK, /* reg == frame_pointer + offset */
  130. PTR_TO_PACKET_META, /* skb->data - meta_len */
  131. PTR_TO_PACKET, /* reg points to skb->data */
  132. PTR_TO_PACKET_END, /* skb->data + headlen */
  133. };
  134. /* The information passed from prog-specific *_is_valid_access
  135. * back to the verifier.
  136. */
  137. struct bpf_insn_access_aux {
  138. enum bpf_reg_type reg_type;
  139. int ctx_field_size;
  140. };
  141. static inline void
  142. bpf_ctx_record_field_size(struct bpf_insn_access_aux *aux, u32 size)
  143. {
  144. aux->ctx_field_size = size;
  145. }
  146. struct bpf_prog_ops {
  147. int (*test_run)(struct bpf_prog *prog, const union bpf_attr *kattr,
  148. union bpf_attr __user *uattr);
  149. };
  150. struct bpf_verifier_ops {
  151. /* return eBPF function prototype for verification */
  152. const struct bpf_func_proto *(*get_func_proto)(enum bpf_func_id func_id);
  153. /* return true if 'size' wide access at offset 'off' within bpf_context
  154. * with 'type' (read or write) is allowed
  155. */
  156. bool (*is_valid_access)(int off, int size, enum bpf_access_type type,
  157. struct bpf_insn_access_aux *info);
  158. int (*gen_prologue)(struct bpf_insn *insn, bool direct_write,
  159. const struct bpf_prog *prog);
  160. u32 (*convert_ctx_access)(enum bpf_access_type type,
  161. const struct bpf_insn *src,
  162. struct bpf_insn *dst,
  163. struct bpf_prog *prog, u32 *target_size);
  164. };
  165. struct bpf_prog_offload_ops {
  166. int (*insn_hook)(struct bpf_verifier_env *env,
  167. int insn_idx, int prev_insn_idx);
  168. };
  169. struct bpf_dev_offload {
  170. struct bpf_prog *prog;
  171. struct net_device *netdev;
  172. void *dev_priv;
  173. struct list_head offloads;
  174. bool dev_state;
  175. const struct bpf_prog_offload_ops *dev_ops;
  176. };
  177. struct bpf_prog_aux {
  178. atomic_t refcnt;
  179. u32 used_map_cnt;
  180. u32 max_ctx_offset;
  181. u32 stack_depth;
  182. u32 id;
  183. u32 func_cnt;
  184. bool offload_requested;
  185. struct bpf_prog **func;
  186. void *jit_data; /* JIT specific data. arch dependent */
  187. struct latch_tree_node ksym_tnode;
  188. struct list_head ksym_lnode;
  189. const struct bpf_prog_ops *ops;
  190. struct bpf_map **used_maps;
  191. struct bpf_prog *prog;
  192. struct user_struct *user;
  193. u64 load_time; /* ns since boottime */
  194. char name[BPF_OBJ_NAME_LEN];
  195. #ifdef CONFIG_SECURITY
  196. void *security;
  197. #endif
  198. struct bpf_dev_offload *offload;
  199. union {
  200. struct work_struct work;
  201. struct rcu_head rcu;
  202. };
  203. };
  204. struct bpf_array {
  205. struct bpf_map map;
  206. u32 elem_size;
  207. /* 'ownership' of prog_array is claimed by the first program that
  208. * is going to use this map or by the first program which FD is stored
  209. * in the map to make sure that all callers and callees have the same
  210. * prog_type and JITed flag
  211. */
  212. enum bpf_prog_type owner_prog_type;
  213. bool owner_jited;
  214. union {
  215. char value[0] __aligned(8);
  216. void *ptrs[0] __aligned(8);
  217. void __percpu *pptrs[0] __aligned(8);
  218. };
  219. };
  220. #define MAX_TAIL_CALL_CNT 32
  221. struct bpf_event_entry {
  222. struct perf_event *event;
  223. struct file *perf_file;
  224. struct file *map_file;
  225. struct rcu_head rcu;
  226. };
  227. bool bpf_prog_array_compatible(struct bpf_array *array, const struct bpf_prog *fp);
  228. int bpf_prog_calc_tag(struct bpf_prog *fp);
  229. const struct bpf_func_proto *bpf_get_trace_printk_proto(void);
  230. typedef unsigned long (*bpf_ctx_copy_t)(void *dst, const void *src,
  231. unsigned long off, unsigned long len);
  232. u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
  233. void *ctx, u64 ctx_size, bpf_ctx_copy_t ctx_copy);
  234. int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
  235. union bpf_attr __user *uattr);
  236. int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
  237. union bpf_attr __user *uattr);
  238. /* an array of programs to be executed under rcu_lock.
  239. *
  240. * Typical usage:
  241. * ret = BPF_PROG_RUN_ARRAY(&bpf_prog_array, ctx, BPF_PROG_RUN);
  242. *
  243. * the structure returned by bpf_prog_array_alloc() should be populated
  244. * with program pointers and the last pointer must be NULL.
  245. * The user has to keep refcnt on the program and make sure the program
  246. * is removed from the array before bpf_prog_put().
  247. * The 'struct bpf_prog_array *' should only be replaced with xchg()
  248. * since other cpus are walking the array of pointers in parallel.
  249. */
  250. struct bpf_prog_array {
  251. struct rcu_head rcu;
  252. struct bpf_prog *progs[0];
  253. };
  254. struct bpf_prog_array __rcu *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags);
  255. void bpf_prog_array_free(struct bpf_prog_array __rcu *progs);
  256. int bpf_prog_array_length(struct bpf_prog_array __rcu *progs);
  257. int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs,
  258. __u32 __user *prog_ids, u32 cnt);
  259. void bpf_prog_array_delete_safe(struct bpf_prog_array __rcu *progs,
  260. struct bpf_prog *old_prog);
  261. int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array,
  262. __u32 __user *prog_ids, u32 request_cnt,
  263. __u32 __user *prog_cnt);
  264. int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
  265. struct bpf_prog *exclude_prog,
  266. struct bpf_prog *include_prog,
  267. struct bpf_prog_array **new_array);
  268. #define __BPF_PROG_RUN_ARRAY(array, ctx, func, check_non_null) \
  269. ({ \
  270. struct bpf_prog **_prog, *__prog; \
  271. struct bpf_prog_array *_array; \
  272. u32 _ret = 1; \
  273. rcu_read_lock(); \
  274. _array = rcu_dereference(array); \
  275. if (unlikely(check_non_null && !_array))\
  276. goto _out; \
  277. _prog = _array->progs; \
  278. while ((__prog = READ_ONCE(*_prog))) { \
  279. _ret &= func(__prog, ctx); \
  280. _prog++; \
  281. } \
  282. _out: \
  283. rcu_read_unlock(); \
  284. _ret; \
  285. })
  286. #define BPF_PROG_RUN_ARRAY(array, ctx, func) \
  287. __BPF_PROG_RUN_ARRAY(array, ctx, func, false)
  288. #define BPF_PROG_RUN_ARRAY_CHECK(array, ctx, func) \
  289. __BPF_PROG_RUN_ARRAY(array, ctx, func, true)
  290. #ifdef CONFIG_BPF_SYSCALL
  291. DECLARE_PER_CPU(int, bpf_prog_active);
  292. extern const struct file_operations bpf_map_fops;
  293. extern const struct file_operations bpf_prog_fops;
  294. #define BPF_PROG_TYPE(_id, _name) \
  295. extern const struct bpf_prog_ops _name ## _prog_ops; \
  296. extern const struct bpf_verifier_ops _name ## _verifier_ops;
  297. #define BPF_MAP_TYPE(_id, _ops) \
  298. extern const struct bpf_map_ops _ops;
  299. #include <linux/bpf_types.h>
  300. #undef BPF_PROG_TYPE
  301. #undef BPF_MAP_TYPE
  302. extern const struct bpf_prog_ops bpf_offload_prog_ops;
  303. extern const struct bpf_verifier_ops tc_cls_act_analyzer_ops;
  304. extern const struct bpf_verifier_ops xdp_analyzer_ops;
  305. struct bpf_prog *bpf_prog_get(u32 ufd);
  306. struct bpf_prog *bpf_prog_get_type_dev(u32 ufd, enum bpf_prog_type type,
  307. bool attach_drv);
  308. struct bpf_prog * __must_check bpf_prog_add(struct bpf_prog *prog, int i);
  309. void bpf_prog_sub(struct bpf_prog *prog, int i);
  310. struct bpf_prog * __must_check bpf_prog_inc(struct bpf_prog *prog);
  311. struct bpf_prog * __must_check bpf_prog_inc_not_zero(struct bpf_prog *prog);
  312. void bpf_prog_put(struct bpf_prog *prog);
  313. int __bpf_prog_charge(struct user_struct *user, u32 pages);
  314. void __bpf_prog_uncharge(struct user_struct *user, u32 pages);
  315. void bpf_prog_free_id(struct bpf_prog *prog, bool do_idr_lock);
  316. struct bpf_map *bpf_map_get_with_uref(u32 ufd);
  317. struct bpf_map *__bpf_map_get(struct fd f);
  318. struct bpf_map * __must_check bpf_map_inc(struct bpf_map *map, bool uref);
  319. void bpf_map_put_with_uref(struct bpf_map *map);
  320. void bpf_map_put(struct bpf_map *map);
  321. int bpf_map_precharge_memlock(u32 pages);
  322. void *bpf_map_area_alloc(size_t size, int numa_node);
  323. void bpf_map_area_free(void *base);
  324. extern int sysctl_unprivileged_bpf_disabled;
  325. int bpf_map_new_fd(struct bpf_map *map, int flags);
  326. int bpf_prog_new_fd(struct bpf_prog *prog);
  327. int bpf_obj_pin_user(u32 ufd, const char __user *pathname);
  328. int bpf_obj_get_user(const char __user *pathname, int flags);
  329. int bpf_percpu_hash_copy(struct bpf_map *map, void *key, void *value);
  330. int bpf_percpu_array_copy(struct bpf_map *map, void *key, void *value);
  331. int bpf_percpu_hash_update(struct bpf_map *map, void *key, void *value,
  332. u64 flags);
  333. int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value,
  334. u64 flags);
  335. int bpf_stackmap_copy(struct bpf_map *map, void *key, void *value);
  336. int bpf_fd_array_map_update_elem(struct bpf_map *map, struct file *map_file,
  337. void *key, void *value, u64 map_flags);
  338. int bpf_fd_array_map_lookup_elem(struct bpf_map *map, void *key, u32 *value);
  339. void bpf_fd_array_map_clear(struct bpf_map *map);
  340. int bpf_fd_htab_map_update_elem(struct bpf_map *map, struct file *map_file,
  341. void *key, void *value, u64 map_flags);
  342. int bpf_fd_htab_map_lookup_elem(struct bpf_map *map, void *key, u32 *value);
  343. int bpf_get_file_flag(int flags);
  344. /* memcpy that is used with 8-byte aligned pointers, power-of-8 size and
  345. * forced to use 'long' read/writes to try to atomically copy long counters.
  346. * Best-effort only. No barriers here, since it _will_ race with concurrent
  347. * updates from BPF programs. Called from bpf syscall and mostly used with
  348. * size 8 or 16 bytes, so ask compiler to inline it.
  349. */
  350. static inline void bpf_long_memcpy(void *dst, const void *src, u32 size)
  351. {
  352. const long *lsrc = src;
  353. long *ldst = dst;
  354. size /= sizeof(long);
  355. while (size--)
  356. *ldst++ = *lsrc++;
  357. }
  358. /* verify correctness of eBPF program */
  359. int bpf_check(struct bpf_prog **fp, union bpf_attr *attr);
  360. void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth);
  361. /* Map specifics */
  362. struct net_device *__dev_map_lookup_elem(struct bpf_map *map, u32 key);
  363. void __dev_map_insert_ctx(struct bpf_map *map, u32 index);
  364. void __dev_map_flush(struct bpf_map *map);
  365. struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key);
  366. void __cpu_map_insert_ctx(struct bpf_map *map, u32 index);
  367. void __cpu_map_flush(struct bpf_map *map);
  368. struct xdp_buff;
  369. int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_buff *xdp,
  370. struct net_device *dev_rx);
  371. /* Return map's numa specified by userspace */
  372. static inline int bpf_map_attr_numa_node(const union bpf_attr *attr)
  373. {
  374. return (attr->map_flags & BPF_F_NUMA_NODE) ?
  375. attr->numa_node : NUMA_NO_NODE;
  376. }
  377. #else /* !CONFIG_BPF_SYSCALL */
  378. static inline struct bpf_prog *bpf_prog_get(u32 ufd)
  379. {
  380. return ERR_PTR(-EOPNOTSUPP);
  381. }
  382. static inline struct bpf_prog *bpf_prog_get_type_dev(u32 ufd,
  383. enum bpf_prog_type type,
  384. bool attach_drv)
  385. {
  386. return ERR_PTR(-EOPNOTSUPP);
  387. }
  388. static inline struct bpf_prog * __must_check bpf_prog_add(struct bpf_prog *prog,
  389. int i)
  390. {
  391. return ERR_PTR(-EOPNOTSUPP);
  392. }
  393. static inline void bpf_prog_sub(struct bpf_prog *prog, int i)
  394. {
  395. }
  396. static inline void bpf_prog_put(struct bpf_prog *prog)
  397. {
  398. }
  399. static inline struct bpf_prog * __must_check bpf_prog_inc(struct bpf_prog *prog)
  400. {
  401. return ERR_PTR(-EOPNOTSUPP);
  402. }
  403. static inline struct bpf_prog *__must_check
  404. bpf_prog_inc_not_zero(struct bpf_prog *prog)
  405. {
  406. return ERR_PTR(-EOPNOTSUPP);
  407. }
  408. static inline int __bpf_prog_charge(struct user_struct *user, u32 pages)
  409. {
  410. return 0;
  411. }
  412. static inline void __bpf_prog_uncharge(struct user_struct *user, u32 pages)
  413. {
  414. }
  415. static inline int bpf_obj_get_user(const char __user *pathname, int flags)
  416. {
  417. return -EOPNOTSUPP;
  418. }
  419. static inline struct net_device *__dev_map_lookup_elem(struct bpf_map *map,
  420. u32 key)
  421. {
  422. return NULL;
  423. }
  424. static inline void __dev_map_insert_ctx(struct bpf_map *map, u32 index)
  425. {
  426. }
  427. static inline void __dev_map_flush(struct bpf_map *map)
  428. {
  429. }
  430. static inline
  431. struct bpf_cpu_map_entry *__cpu_map_lookup_elem(struct bpf_map *map, u32 key)
  432. {
  433. return NULL;
  434. }
  435. static inline void __cpu_map_insert_ctx(struct bpf_map *map, u32 index)
  436. {
  437. }
  438. static inline void __cpu_map_flush(struct bpf_map *map)
  439. {
  440. }
  441. struct xdp_buff;
  442. static inline int cpu_map_enqueue(struct bpf_cpu_map_entry *rcpu,
  443. struct xdp_buff *xdp,
  444. struct net_device *dev_rx)
  445. {
  446. return 0;
  447. }
  448. #endif /* CONFIG_BPF_SYSCALL */
  449. static inline struct bpf_prog *bpf_prog_get_type(u32 ufd,
  450. enum bpf_prog_type type)
  451. {
  452. return bpf_prog_get_type_dev(ufd, type, false);
  453. }
  454. int bpf_prog_offload_compile(struct bpf_prog *prog);
  455. void bpf_prog_offload_destroy(struct bpf_prog *prog);
  456. int bpf_prog_offload_info_fill(struct bpf_prog_info *info,
  457. struct bpf_prog *prog);
  458. #if defined(CONFIG_NET) && defined(CONFIG_BPF_SYSCALL)
  459. int bpf_prog_offload_init(struct bpf_prog *prog, union bpf_attr *attr);
  460. static inline bool bpf_prog_is_dev_bound(struct bpf_prog_aux *aux)
  461. {
  462. return aux->offload_requested;
  463. }
  464. #else
  465. static inline int bpf_prog_offload_init(struct bpf_prog *prog,
  466. union bpf_attr *attr)
  467. {
  468. return -EOPNOTSUPP;
  469. }
  470. static inline bool bpf_prog_is_dev_bound(struct bpf_prog_aux *aux)
  471. {
  472. return false;
  473. }
  474. #endif /* CONFIG_NET && CONFIG_BPF_SYSCALL */
  475. #if defined(CONFIG_STREAM_PARSER) && defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_INET)
  476. struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key);
  477. int sock_map_prog(struct bpf_map *map, struct bpf_prog *prog, u32 type);
  478. #else
  479. static inline struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key)
  480. {
  481. return NULL;
  482. }
  483. static inline int sock_map_prog(struct bpf_map *map,
  484. struct bpf_prog *prog,
  485. u32 type)
  486. {
  487. return -EOPNOTSUPP;
  488. }
  489. #endif
  490. /* verifier prototypes for helper functions called from eBPF programs */
  491. extern const struct bpf_func_proto bpf_map_lookup_elem_proto;
  492. extern const struct bpf_func_proto bpf_map_update_elem_proto;
  493. extern const struct bpf_func_proto bpf_map_delete_elem_proto;
  494. extern const struct bpf_func_proto bpf_get_prandom_u32_proto;
  495. extern const struct bpf_func_proto bpf_get_smp_processor_id_proto;
  496. extern const struct bpf_func_proto bpf_get_numa_node_id_proto;
  497. extern const struct bpf_func_proto bpf_tail_call_proto;
  498. extern const struct bpf_func_proto bpf_ktime_get_ns_proto;
  499. extern const struct bpf_func_proto bpf_get_current_pid_tgid_proto;
  500. extern const struct bpf_func_proto bpf_get_current_uid_gid_proto;
  501. extern const struct bpf_func_proto bpf_get_current_comm_proto;
  502. extern const struct bpf_func_proto bpf_skb_vlan_push_proto;
  503. extern const struct bpf_func_proto bpf_skb_vlan_pop_proto;
  504. extern const struct bpf_func_proto bpf_get_stackid_proto;
  505. extern const struct bpf_func_proto bpf_sock_map_update_proto;
  506. /* Shared helpers among cBPF and eBPF. */
  507. void bpf_user_rnd_init_once(void);
  508. u64 bpf_user_rnd_u32(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
  509. #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
  510. #ifdef CONFIG_BPF_KPROBE_OVERRIDE
  511. #define BPF_ALLOW_ERROR_INJECTION(fname) \
  512. static unsigned long __used \
  513. __attribute__((__section__("_kprobe_error_inject_list"))) \
  514. _eil_addr_##fname = (unsigned long)fname;
  515. #else
  516. #define BPF_ALLOW_ERROR_INJECTION(fname)
  517. #endif
  518. #endif
  519. #endif /* _LINUX_BPF_H */