ib.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
  2. /*
  3. * Copyright (c) 2010 Intel Corporation. All rights reserved.
  4. */
  5. #ifndef _RDMA_IB_H
  6. #define _RDMA_IB_H
  7. #include <linux/types.h>
  8. #include <linux/sched.h>
  9. #include <linux/cred.h>
  10. #include <linux/uaccess.h>
  11. #include <linux/fs.h>
  12. struct ib_addr {
  13. union {
  14. __u8 uib_addr8[16];
  15. __be16 uib_addr16[8];
  16. __be32 uib_addr32[4];
  17. __be64 uib_addr64[2];
  18. } ib_u;
  19. #define sib_addr8 ib_u.uib_addr8
  20. #define sib_addr16 ib_u.uib_addr16
  21. #define sib_addr32 ib_u.uib_addr32
  22. #define sib_addr64 ib_u.uib_addr64
  23. #define sib_raw ib_u.uib_addr8
  24. #define sib_subnet_prefix ib_u.uib_addr64[0]
  25. #define sib_interface_id ib_u.uib_addr64[1]
  26. };
  27. static inline bool ib_addr_any(const struct ib_addr *a)
  28. {
  29. return ((a->sib_addr64[0] | a->sib_addr64[1]) == 0);
  30. }
  31. static inline bool ib_addr_loopback(const struct ib_addr *a)
  32. {
  33. return ((a->sib_addr32[0] | a->sib_addr32[1] |
  34. a->sib_addr32[2] | (a->sib_addr32[3] ^ htonl(1))) == 0);
  35. }
  36. static inline void ib_addr_set(struct ib_addr *addr,
  37. __be32 w1, __be32 w2, __be32 w3, __be32 w4)
  38. {
  39. addr->sib_addr32[0] = w1;
  40. addr->sib_addr32[1] = w2;
  41. addr->sib_addr32[2] = w3;
  42. addr->sib_addr32[3] = w4;
  43. }
  44. static inline int ib_addr_cmp(const struct ib_addr *a1, const struct ib_addr *a2)
  45. {
  46. return memcmp(a1, a2, sizeof(struct ib_addr));
  47. }
  48. struct sockaddr_ib {
  49. unsigned short int sib_family; /* AF_IB */
  50. __be16 sib_pkey;
  51. __be32 sib_flowinfo;
  52. struct ib_addr sib_addr;
  53. __be64 sib_sid;
  54. __be64 sib_sid_mask;
  55. __u64 sib_scope_id;
  56. };
  57. /*
  58. * The IB interfaces that use write() as bi-directional ioctl() are
  59. * fundamentally unsafe, since there are lots of ways to trigger "write()"
  60. * calls from various contexts with elevated privileges. That includes the
  61. * traditional suid executable error message writes, but also various kernel
  62. * interfaces that can write to file descriptors.
  63. *
  64. * This function provides protection for the legacy API by restricting the
  65. * calling context.
  66. */
  67. static inline bool ib_safe_file_access(struct file *filp)
  68. {
  69. return filp->f_cred == current_cred();
  70. }
  71. #endif /* _RDMA_IB_H */