Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
0002 /*
0003  * Copyright (c) 2010 Intel Corporation.  All rights reserved.
0004  */
0005 
0006 #ifndef _RDMA_IB_H
0007 #define _RDMA_IB_H
0008 
0009 #include <linux/types.h>
0010 #include <linux/sched.h>
0011 #include <linux/cred.h>
0012 #include <linux/uaccess.h>
0013 #include <linux/fs.h>
0014 
0015 struct ib_addr {
0016     union {
0017         __u8        uib_addr8[16];
0018         __be16      uib_addr16[8];
0019         __be32      uib_addr32[4];
0020         __be64      uib_addr64[2];
0021     } ib_u;
0022 #define sib_addr8       ib_u.uib_addr8
0023 #define sib_addr16      ib_u.uib_addr16
0024 #define sib_addr32      ib_u.uib_addr32
0025 #define sib_addr64      ib_u.uib_addr64
0026 #define sib_raw         ib_u.uib_addr8
0027 #define sib_subnet_prefix   ib_u.uib_addr64[0]
0028 #define sib_interface_id    ib_u.uib_addr64[1]
0029 };
0030 
0031 static inline bool ib_addr_any(const struct ib_addr *a)
0032 {
0033     return ((a->sib_addr64[0] | a->sib_addr64[1]) == 0);
0034 }
0035 
0036 static inline bool ib_addr_loopback(const struct ib_addr *a)
0037 {
0038     return ((a->sib_addr32[0] | a->sib_addr32[1] |
0039          a->sib_addr32[2] | (a->sib_addr32[3] ^ htonl(1))) == 0);
0040 }
0041 
0042 static inline void ib_addr_set(struct ib_addr *addr,
0043                    __be32 w1, __be32 w2, __be32 w3, __be32 w4)
0044 {
0045     addr->sib_addr32[0] = w1;
0046     addr->sib_addr32[1] = w2;
0047     addr->sib_addr32[2] = w3;
0048     addr->sib_addr32[3] = w4;
0049 }
0050 
0051 static inline int ib_addr_cmp(const struct ib_addr *a1, const struct ib_addr *a2)
0052 {
0053     return memcmp(a1, a2, sizeof(struct ib_addr));
0054 }
0055 
0056 struct sockaddr_ib {
0057     unsigned short int  sib_family; /* AF_IB */
0058     __be16          sib_pkey;
0059     __be32          sib_flowinfo;
0060     struct ib_addr      sib_addr;
0061     __be64          sib_sid;
0062     __be64          sib_sid_mask;
0063     __u64           sib_scope_id;
0064 };
0065 
0066 /*
0067  * The IB interfaces that use write() as bi-directional ioctl() are
0068  * fundamentally unsafe, since there are lots of ways to trigger "write()"
0069  * calls from various contexts with elevated privileges. That includes the
0070  * traditional suid executable error message writes, but also various kernel
0071  * interfaces that can write to file descriptors.
0072  *
0073  * This function provides protection for the legacy API by restricting the
0074  * calling context.
0075  */
0076 static inline bool ib_safe_file_access(struct file *filp)
0077 {
0078     return filp->f_cred == current_cred();
0079 }
0080 
0081 #endif /* _RDMA_IB_H */