Changeset 3aece36 in mainline for uspace/srv/net/inetsrv/inet_link.c
- Timestamp:
- 2013-07-12T17:25:09Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 956d4281
- Parents:
- bb9b0c6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inet_link.c
rbb9b0c6 r3aece36 49 49 #include "pdu.h" 50 50 51 static bool first_link = true; 52 static bool first_link6 = true; 53 51 54 static int inet_link_open(service_id_t); 52 55 static int inet_iplink_recv(iplink_t *, iplink_recv_sdu_t *, uint16_t); … … 58 61 static LIST_INITIALIZE(inet_link_list); 59 62 static FIBRIL_MUTEX_INITIALIZE(inet_discovery_lock); 63 64 static addr128_t link_local_node_ip = 65 {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0, 0, 0}; 66 67 static void inet_link_local_node_ip(addr48_t mac_addr, 68 addr128_t ip_addr) 69 { 70 memcpy(ip_addr, link_local_node_ip, 16); 71 72 ip_addr[8] = mac_addr[0] ^ 0x02; 73 ip_addr[9] = mac_addr[1]; 74 ip_addr[10] = mac_addr[2]; 75 ip_addr[13] = mac_addr[3]; 76 ip_addr[14] = mac_addr[4]; 77 ip_addr[15] = mac_addr[5]; 78 } 60 79 61 80 static int inet_iplink_recv(iplink_t *iplink, iplink_recv_sdu_t *sdu, uint16_t af) … … 159 178 if (ilink->svc_name != NULL) 160 179 free(ilink->svc_name); 180 161 181 free(ilink); 162 182 } … … 212 232 list_append(&ilink->link_list, &inet_link_list); 213 233 214 inet_addrobj_t *addr; 215 inet_addrobj_t *addr6; 216 217 static int first = 1; 218 219 addr = inet_addrobj_new(); 220 addr6 = inet_addrobj_new(); 221 222 if (first) { 234 inet_addrobj_t *addr = NULL; 235 236 if (first_link) { 237 addr = inet_addrobj_new(); 238 223 239 inet_naddr(&addr->naddr, 127, 0, 0, 1, 24); 224 inet_naddr6(&addr6->naddr, 0, 0, 0, 0, 0, 0, 0, 1, 128); 225 first = 0; 240 first_link = false; 226 241 } else { 227 242 /* 228 243 * FIXME 229 * Setting static IP addresses for testing purposes244 * Setting static IPv4 address for testing purposes: 230 245 * 10.0.2.15/24 231 * fd19:1680::4/120232 246 */ 247 addr = inet_addrobj_new(); 248 233 249 inet_naddr(&addr->naddr, 10, 0, 2, 15, 24); 234 inet_naddr6(&addr6->naddr, 0xfd19, 0x1680, 0, 0, 0, 0, 0, 4, 120); 235 } 236 237 addr->ilink = ilink; 238 addr6->ilink = ilink; 239 addr->name = str_dup("v4a"); 240 addr6->name = str_dup("v6a"); 241 242 rc = inet_addrobj_add(addr); 243 if (rc != EOK) { 244 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv4 address."); 245 inet_addrobj_delete(addr); 246 /* XXX Roll back */ 247 return rc; 248 } 249 250 rc = inet_addrobj_add(addr6); 251 if (rc != EOK) { 252 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv6 address."); 253 inet_addrobj_delete(addr6); 254 /* XXX Roll back */ 255 return rc; 256 } 257 258 inet_naddr_addr(&addr->naddr, &iaddr); 259 rc = iplink_addr_add(ilink->iplink, &iaddr); 260 if (rc != EOK) { 261 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed setting IPv4 address on internet link."); 262 inet_addrobj_remove(addr); 263 inet_addrobj_delete(addr); 264 /* XXX Roll back */ 265 return rc; 266 } 267 268 inet_naddr_addr(&addr6->naddr, &iaddr); 269 rc = iplink_addr_add(ilink->iplink, &iaddr); 270 if (rc != EOK) { 271 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed setting IPv6 address on internet link."); 272 inet_addrobj_remove(addr6); 273 inet_addrobj_delete(addr6); 274 /* XXX Roll back */ 275 return rc; 250 } 251 252 if (addr != NULL) { 253 addr->ilink = ilink; 254 addr->name = str_dup("v4a"); 255 256 rc = inet_addrobj_add(addr); 257 if (rc == EOK) { 258 inet_naddr_addr(&addr->naddr, &iaddr); 259 rc = iplink_addr_add(ilink->iplink, &iaddr); 260 if (rc != EOK) { 261 log_msg(LOG_DEFAULT, LVL_ERROR, 262 "Failed setting IPv4 address on internet link."); 263 inet_addrobj_remove(addr); 264 inet_addrobj_delete(addr); 265 } 266 } else { 267 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv4 address."); 268 inet_addrobj_delete(addr); 269 } 270 } 271 272 inet_addrobj_t *addr6 = NULL; 273 274 if (first_link6) { 275 addr6 = inet_addrobj_new(); 276 277 inet_naddr6(&addr6->naddr, 0, 0, 0, 0, 0, 0, 0, 1, 128); 278 first_link6 = false; 279 } else if (ilink->mac_valid) { 280 addr6 = inet_addrobj_new(); 281 282 addr128_t link_local; 283 inet_link_local_node_ip(ilink->mac, link_local); 284 285 inet_naddr_set6(link_local, 64, &addr6->naddr); 286 } 287 288 if (addr6 != NULL) { 289 addr6->ilink = ilink; 290 addr6->name = str_dup("v6a"); 291 292 rc = inet_addrobj_add(addr6); 293 if (rc == EOK) { 294 inet_naddr_addr(&addr6->naddr, &iaddr); 295 rc = iplink_addr_add(ilink->iplink, &iaddr); 296 if (rc != EOK) { 297 log_msg(LOG_DEFAULT, LVL_ERROR, 298 "Failed setting IPv6 address on internet link."); 299 inet_addrobj_remove(addr6); 300 inet_addrobj_delete(addr6); 301 } 302 } else { 303 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv6 address."); 304 inet_addrobj_delete(addr6); 305 } 276 306 } 277 307
Note:
See TracChangeset
for help on using the changeset viewer.