+static inline int nid_is_nid4(const struct lnet_nid *nid)
+{
+ return NID_ADDR_BYTES(nid) == 4;
+}
+
+/* LOLND may not be defined yet, so we cannot use an inline */
+#define nid_is_lo0(__nid) \
+ ((__nid)->nid_type == LOLND && \
+ nid_is_nid4(__nid) && \
+ (__nid)->nid_num == 0 && \
+ (__nid)->nid_addr[0] == 0)
+
+static inline __u32 LNET_NID_NET(const struct lnet_nid *nid)
+{
+ if (LNET_NID_IS_ANY(nid))
+ return LNET_NET_ANY;
+ else
+ return LNET_MKNET(nid->nid_type, __be16_to_cpu(nid->nid_num));
+}
+
+static inline void lnet_nid4_to_nid(lnet_nid_t nid4, struct lnet_nid *nid)
+{
+ if (nid4 == LNET_NID_ANY) {
+ /* equal to setting to LNET_ANY_NID */
+ memset(nid, 0xff, sizeof(*nid));
+ return;
+ }
+
+ nid->nid_size = 0;
+ nid->nid_type = LNET_NETTYP(LNET_NIDNET(nid4));
+ nid->nid_num = __cpu_to_be16(LNET_NETNUM(LNET_NIDNET(nid4)));
+ nid->nid_addr[0] = __cpu_to_be32(LNET_NIDADDR(nid4));
+ nid->nid_addr[1] = nid->nid_addr[2] = nid->nid_addr[3] = 0;
+}
+
+static inline lnet_nid_t lnet_nid_to_nid4(const struct lnet_nid *nid)
+{
+ if (LNET_NID_IS_ANY(nid))
+ return LNET_NID_ANY;
+
+ return LNET_MKNID(LNET_NID_NET(nid), __be32_to_cpu(nid->nid_addr[0]));
+}
+
+static inline int nid_same(const struct lnet_nid *n1,
+ const struct lnet_nid *n2)
+{
+ return n1->nid_size == n2->nid_size &&
+ n1->nid_type == n2->nid_type &&
+ n1->nid_num == n2->nid_num &&
+ n1->nid_addr[0] == n2->nid_addr[0] &&
+ n1->nid_addr[1] == n2->nid_addr[1] &&
+ n1->nid_addr[2] == n2->nid_addr[2] &&
+ n1->nid_addr[3] == n2->nid_addr[3];
+}
+
+/* This can be used when we need to hash a nid */
+static inline unsigned long nidhash(const struct lnet_nid *nid)
+{
+ int i;
+ unsigned long hash = 0;
+
+ hash ^= LNET_NID_NET(nid);
+ for (i = 0; i < 4; i++)
+ hash ^= nid->nid_addr[i];
+ return hash;
+}
+