![]() |
|
|||
File indexing completed on 2025-02-22 10:47:27
0001 /* 0002 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana 0003 * University Research and Technology 0004 * Corporation. All rights reserved. 0005 * Copyright (c) 2004-2005 The University of Tennessee and The University 0006 * of Tennessee Research Foundation. All rights 0007 * reserved. 0008 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, 0009 * University of Stuttgart. All rights reserved. 0010 * Copyright (c) 2004-2005 The Regents of the University of California. 0011 * All rights reserved. 0012 * Copyright (c) 2007 Los Alamos National Security, LLC. All rights 0013 * reserved. 0014 * Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved. 0015 * Copyright (c) 2013 Cisco Systems, Inc. All rights reserved. 0016 * Copyright (c) 2016-2020 Intel, Inc. All rights reserved. 0017 * Copyright (c) 2021-2023 Nanook Consulting. All rights reserved. 0018 * $COPYRIGHT$ 0019 * 0020 * Additional copyrights may follow 0021 * 0022 * $HEADER$ 0023 */ 0024 0025 /* @file */ 0026 0027 #ifndef PMIX_PIF_UTIL_ 0028 #define PMIX_PIF_UTIL_ 0029 0030 #include "src/include/pmix_config.h" 0031 0032 #ifdef HAVE_SYS_TYPES_H 0033 # include <sys/types.h> 0034 #endif 0035 #ifdef HAVE_SYS_SOCKET_H 0036 # include <sys/socket.h> 0037 #endif 0038 #ifdef HAVE_NETINET_IN_H 0039 # include <netinet/in.h> 0040 #endif 0041 0042 #include "pmix_common.h" 0043 #include "src/class/pmix_list.h" 0044 0045 #define PMIX_IF_NAMESIZE 256 0046 0047 BEGIN_C_DECLS 0048 0049 #define PMIX_PIF_FORMAT_ADDR(n) \ 0050 (((n) >> 24) & 0x000000FF), (((n) >> 16) & 0x000000FF), (((n) >> 8) & 0x000000FF), \ 0051 ((n) &0x000000FF) 0052 0053 #define PMIX_PIF_ASSEMBLE_FABRIC(n1, n2, n3, n4) \ 0054 (((n1) << 24) & 0xFF000000) | (((n2) << 16) & 0x00FF0000) | (((n3) << 8) & 0x0000FF00) \ 0055 | ((n4) &0x000000FF) 0056 0057 typedef struct pmix_pif_t { 0058 pmix_list_item_t super; 0059 char if_name[PMIX_IF_NAMESIZE + 1]; 0060 int if_index; 0061 uint16_t if_kernel_index; 0062 uint16_t af_family; 0063 int if_flags; 0064 int if_speed; 0065 struct sockaddr_storage if_addr; 0066 uint32_t if_mask; 0067 uint32_t if_bandwidth; 0068 uint8_t if_mac[6]; 0069 int ifmtu; /* Can't use if_mtu because of a 0070 #define collision on some BSDs */ 0071 } pmix_pif_t; 0072 PMIX_EXPORT PMIX_CLASS_DECLARATION(pmix_pif_t); 0073 0074 0075 /* "global" list of available interfaces */ 0076 PMIX_EXPORT extern pmix_list_t pmix_if_list; 0077 0078 /* global flags */ 0079 PMIX_EXPORT extern bool pmix_if_do_not_resolve; 0080 PMIX_EXPORT extern bool pmix_if_retain_loopback; 0081 0082 /** 0083 * Lookup an interface by address and return its name. 0084 * 0085 * @param if_addr (IN) Interface address (hostname or dotted-quad) 0086 * @param if_name (OUT) Interface name buffer 0087 * @param size (IN) Interface name buffer size 0088 */ 0089 PMIX_EXPORT int pmix_ifaddrtoname(const char *if_addr, char *if_name, int size); 0090 0091 /** 0092 * Lookup an interface by name and return its pmix_list index. 0093 * 0094 * @param if_name (IN) Interface name 0095 * @return Interface pmix_list index 0096 */ 0097 PMIX_EXPORT int pmix_ifnametoindex(const char *if_name); 0098 0099 /** 0100 * Lookup an interface by name and return its kernel index. 0101 * 0102 * @param if_name (IN) Interface name 0103 * @return Interface kernel index 0104 */ 0105 PMIX_EXPORT int16_t pmix_ifnametokindex(const char *if_name); 0106 0107 /* 0108 * Attempt to resolve an address (given as either IPv4/IPv6 string 0109 * or hostname) and return the kernel index of the interface 0110 * that is on the same network as the specified address 0111 */ 0112 PMIX_EXPORT int16_t pmix_ifaddrtokindex(const char *if_addr); 0113 0114 /** 0115 * Lookup an interface by pmix_list index and return its kernel index. 0116 * 0117 * @param if_name (IN) Interface pmix_list index 0118 * @return Interface kernel index 0119 */ 0120 PMIX_EXPORT int pmix_ifindextokindex(int if_index); 0121 0122 /** 0123 * Returns the number of available interfaces. 0124 */ 0125 PMIX_EXPORT int pmix_ifcount(void); 0126 0127 /** 0128 * Returns the index of the first available interface. 0129 */ 0130 PMIX_EXPORT int pmix_ifbegin(void); 0131 0132 /** 0133 * Lookup the current position in the interface list by 0134 * index and return the next available index (if it exists). 0135 * 0136 * @param if_index Returns the next available index from the 0137 * current position. 0138 */ 0139 PMIX_EXPORT int pmix_ifnext(int if_index); 0140 0141 /** 0142 * Lookup an interface by index and return its name. 0143 * 0144 * @param if_index (IN) Interface index 0145 * @param if_name (OUT) Interface name buffer 0146 * @param size (IN) Interface name buffer size 0147 */ 0148 PMIX_EXPORT int pmix_ifindextoname(int if_index, char *if_name, int); 0149 0150 /** 0151 * Lookup an interface by kernel index and return its name. 0152 * 0153 * @param if_index (IN) Interface kernel index 0154 * @param if_name (OUT) Interface name buffer 0155 * @param size (IN) Interface name buffer size 0156 */ 0157 PMIX_EXPORT int pmix_ifkindextoname(int if_kindex, char *if_name, int); 0158 0159 /** 0160 * Lookup an interface by index and return its primary address. 0161 * 0162 * @param if_index (IN) Interface index 0163 * @param if_name (OUT) Interface address buffer 0164 * @param size (IN) Interface address buffer size 0165 */ 0166 PMIX_EXPORT int pmix_ifindextoaddr(int if_index, struct sockaddr *, unsigned int); 0167 PMIX_EXPORT int pmix_ifkindextoaddr(int if_kindex, struct sockaddr *if_addr, unsigned int length); 0168 0169 /** 0170 * Lookup an interface by index and return its network mask (in CIDR 0171 * notation -- NOT the actual netmask itself!). 0172 * 0173 * @param if_index (IN) Interface index 0174 * @param if_name (OUT) Interface address buffer 0175 * @param size (IN) Interface address buffer size 0176 */ 0177 PMIX_EXPORT int pmix_ifindextomask(int if_index, uint32_t *, int); 0178 0179 /** 0180 * Lookup an interface by index and return its MAC address. 0181 * 0182 * @param if_index (IN) Interface index 0183 * @param if_mac (OUT) Interface's MAC address 0184 */ 0185 PMIX_EXPORT int pmix_ifindextomac(int if_index, uint8_t if_mac[6]); 0186 0187 /** 0188 * Lookup an interface by index and return its MTU. 0189 * 0190 * @param if_index (IN) Interface index 0191 * @param if_mtu (OUT) Interface's MTU 0192 */ 0193 PMIX_EXPORT int pmix_ifindextomtu(int if_index, int *mtu); 0194 0195 /** 0196 * Lookup an interface by index and return its flags. 0197 * 0198 * @param if_index (IN) Interface index 0199 * @param if_flags (OUT) Interface flags 0200 */ 0201 PMIX_EXPORT int pmix_ifindextoflags(int if_index, uint32_t *); 0202 0203 /** 0204 * Determine if given hostname / IP address is a local address 0205 * 0206 * @param hostname (IN) Hostname (or stringified IP address) 0207 * @return true if \c hostname is local, false otherwise 0208 */ 0209 PMIX_EXPORT bool pmix_ifislocal(const char *hostname); 0210 0211 /** 0212 * Convert a dot-delimited network tuple to an IP address 0213 * 0214 * @param addr (IN) character string tuple 0215 * @param net (IN) Pointer to returned network address 0216 * @param mask (IN) Pointer to returned netmask 0217 * @return PMIX_SUCCESS if no problems encountered 0218 * @return PMIX_ERROR if data could not be released 0219 */ 0220 PMIX_EXPORT int pmix_iftupletoaddr(const char *addr, uint32_t *net, uint32_t *mask); 0221 0222 /** 0223 * Determine if given interface is loopback 0224 * 0225 * @param if_index (IN) Interface index 0226 */ 0227 PMIX_EXPORT bool pmix_ifisloopback(int if_index); 0228 0229 /* 0230 * Determine if a specified interface is included in a NULL-terminated argv array 0231 */ 0232 PMIX_EXPORT int pmix_ifmatches(int kidx, char **nets); 0233 0234 /* 0235 * Provide a list of strings that contain all known aliases for this node 0236 */ 0237 PMIX_EXPORT void pmix_ifgetaliases(char ***aliases); 0238 0239 END_C_DECLS 0240 0241 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |