Changes in uspace/srv/net/inetsrv/addrobj.c [a1a101d:feeac0d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/addrobj.c
ra1a101d rfeeac0d 42 42 #include <stdlib.h> 43 43 #include <str.h> 44 44 #include <net/socket_codes.h> 45 45 #include "addrobj.h" 46 46 #include "inetsrv.h" 47 47 #include "inet_link.h" 48 #include " inet_util.h"48 #include "ndp.h" 49 49 50 50 static inet_addrobj_t *inet_addrobj_find_by_name_locked(const char *, inet_link_t *); … … 106 106 /** Find address object matching address @a addr. 107 107 * 108 * @param addr Address 109 * @oaram find iaf_net to find network (using mask), 110 * iaf_addr to find local address (exact match) 108 * @param addr Address 109 * @oaram find iaf_net to find network (using mask), 110 * iaf_addr to find local address (exact match) 111 * 111 112 */ 112 113 inet_addrobj_t *inet_addrobj_find(inet_addr_t *addr, inet_addrobj_find_t find) 113 114 { 114 uint32_t mask; 115 116 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find(%x)", (unsigned)addr->ipv4); 117 118 fibril_mutex_lock(&addr_list_lock); 119 120 list_foreach(addr_list, link) { 121 inet_addrobj_t *naddr = list_get_instance(link, 122 inet_addrobj_t, addr_list); 123 124 mask = inet_netmask(naddr->naddr.bits); 125 if ((naddr->naddr.ipv4 & mask) == (addr->ipv4 & mask)) { 126 fibril_mutex_unlock(&addr_list_lock); 127 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: found %p", 128 naddr); 129 return naddr; 115 fibril_mutex_lock(&addr_list_lock); 116 117 list_foreach(addr_list, addr_list, inet_addrobj_t, naddr) { 118 switch (find) { 119 case iaf_net: 120 if (inet_naddr_compare_mask(&naddr->naddr, addr)) { 121 fibril_mutex_unlock(&addr_list_lock); 122 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: found %p", 123 naddr); 124 return naddr; 125 } 126 break; 127 case iaf_addr: 128 if (inet_naddr_compare(&naddr->naddr, addr)) { 129 fibril_mutex_unlock(&addr_list_lock); 130 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: found %p", 131 naddr); 132 return naddr; 133 } 134 break; 130 135 } 131 136 } 132 137 133 138 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: Not found"); 134 139 fibril_mutex_unlock(&addr_list_lock); 135 140 136 141 return NULL; 137 142 } … … 150 155 name, ilink->svc_name); 151 156 152 list_foreach(addr_list, link) { 153 inet_addrobj_t *naddr = list_get_instance(link, 154 inet_addrobj_t, addr_list); 155 157 list_foreach(addr_list, addr_list, inet_addrobj_t, naddr) { 156 158 if (naddr->ilink == ilink && str_cmp(naddr->name, name) == 0) { 157 159 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find_by_name_locked: found %p", … … 198 200 fibril_mutex_lock(&addr_list_lock); 199 201 200 list_foreach(addr_list, link) { 201 inet_addrobj_t *naddr = list_get_instance(link, 202 inet_addrobj_t, addr_list); 203 202 list_foreach(addr_list, addr_list, inet_addrobj_t, naddr) { 204 203 if (naddr->id == id) { 205 204 fibril_mutex_unlock(&addr_list_lock); … … 218 217 { 219 218 inet_addr_t lsrc_addr; 220 inet_addr_t *ldest_addr; 221 222 lsrc_addr.ipv4 = addr->naddr.ipv4; 223 ldest_addr = &dgram->dest; 224 225 return inet_link_send_dgram(addr->ilink, &lsrc_addr, ldest_addr, dgram, 226 proto, ttl, df); 219 inet_naddr_addr(&addr->naddr, &lsrc_addr); 220 221 addr32_t lsrc_v4; 222 addr128_t lsrc_v6; 223 uint16_t lsrc_af = inet_addr_get(&lsrc_addr, &lsrc_v4, &lsrc_v6); 224 225 addr32_t ldest_v4; 226 addr128_t ldest_v6; 227 uint16_t ldest_af = inet_addr_get(ldest, &ldest_v4, &ldest_v6); 228 229 if (lsrc_af != ldest_af) 230 return EINVAL; 231 232 int rc; 233 addr48_t ldest_mac; 234 235 switch (ldest_af) { 236 case AF_INET: 237 return inet_link_send_dgram(addr->ilink, lsrc_v4, ldest_v4, 238 dgram, proto, ttl, df); 239 case AF_INET6: 240 /* 241 * Translate local destination IPv6 address. 242 */ 243 rc = ndp_translate(lsrc_v6, ldest_v6, ldest_mac, addr->ilink); 244 if (rc != EOK) 245 return rc; 246 247 return inet_link_send_dgram6(addr->ilink, ldest_mac, dgram, 248 proto, ttl, df); 249 } 250 251 return ENOTSUP; 227 252 } 228 253 … … 243 268 244 269 i = 0; 245 list_foreach(addr_list, link) { 246 inet_addrobj_t *addr = list_get_instance(link, 247 inet_addrobj_t, addr_list); 248 270 list_foreach(addr_list, addr_list, inet_addrobj_t, addr) { 249 271 id_list[i++] = addr->id; 250 272 }
Note:
See TracChangeset
for help on using the changeset viewer.