raw.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * INET An implementation of the TCP/IP protocol suite for the LINUX
  4. * operating system. INET is implemented using the BSD Socket
  5. * interface as the means of communication with the user level.
  6. *
  7. * Definitions for the RAW-IP module.
  8. *
  9. * Version: @(#)raw.h 1.0.2 05/07/93
  10. *
  11. * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12. */
  13. #ifndef _RAW_H
  14. #define _RAW_H
  15. #include <net/inet_sock.h>
  16. #include <net/protocol.h>
  17. #include <net/netns/hash.h>
  18. #include <linux/hash.h>
  19. #include <linux/icmp.h>
  20. extern struct proto raw_prot;
  21. extern struct raw_hashinfo raw_v4_hashinfo;
  22. bool raw_v4_match(struct net *net, const struct sock *sk, unsigned short num,
  23. __be32 raddr, __be32 laddr, int dif, int sdif);
  24. int raw_abort(struct sock *sk, int err);
  25. void raw_icmp_error(struct sk_buff *, int, u32);
  26. int raw_local_deliver(struct sk_buff *, int);
  27. int raw_rcv(struct sock *, struct sk_buff *);
  28. #define RAW_HTABLE_LOG 8
  29. #define RAW_HTABLE_SIZE (1U << RAW_HTABLE_LOG)
  30. struct raw_hashinfo {
  31. spinlock_t lock;
  32. struct hlist_head ht[RAW_HTABLE_SIZE] ____cacheline_aligned;
  33. };
  34. static inline u32 raw_hashfunc(const struct net *net, u32 proto)
  35. {
  36. return hash_32(net_hash_mix(net) ^ proto, RAW_HTABLE_LOG);
  37. }
  38. static inline void raw_hashinfo_init(struct raw_hashinfo *hashinfo)
  39. {
  40. int i;
  41. spin_lock_init(&hashinfo->lock);
  42. for (i = 0; i < RAW_HTABLE_SIZE; i++)
  43. INIT_HLIST_HEAD(&hashinfo->ht[i]);
  44. }
  45. #ifdef CONFIG_PROC_FS
  46. int raw_proc_init(void);
  47. void raw_proc_exit(void);
  48. struct raw_iter_state {
  49. struct seq_net_private p;
  50. int bucket;
  51. };
  52. static inline struct raw_iter_state *raw_seq_private(struct seq_file *seq)
  53. {
  54. return seq->private;
  55. }
  56. void *raw_seq_start(struct seq_file *seq, loff_t *pos);
  57. void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos);
  58. void raw_seq_stop(struct seq_file *seq, void *v);
  59. #endif
  60. int raw_hash_sk(struct sock *sk);
  61. void raw_unhash_sk(struct sock *sk);
  62. void raw_init(void);
  63. struct raw_sock {
  64. /* inet_sock has to be the first member */
  65. struct inet_sock inet;
  66. struct icmp_filter filter;
  67. u32 ipmr_table;
  68. struct numa_drop_counters drop_counters;
  69. };
  70. #define raw_sk(ptr) container_of_const(ptr, struct raw_sock, inet.sk)
  71. static inline bool raw_sk_bound_dev_eq(struct net *net, int bound_dev_if,
  72. int dif, int sdif)
  73. {
  74. #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
  75. return inet_bound_dev_eq(READ_ONCE(net->ipv4.sysctl_raw_l3mdev_accept),
  76. bound_dev_if, dif, sdif);
  77. #else
  78. return inet_bound_dev_eq(true, bound_dev_if, dif, sdif);
  79. #endif
  80. }
  81. #endif /* _RAW_H */