Changeset 609243f4 in mainline for uspace/srv/net
- Timestamp:
- 2011-10-07T15:46:01Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e2c50e1
- Parents:
- f51b1d3
- Location:
- uspace/srv/net
- Files:
-
- 3 deleted
- 15 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/cfg/lo.nic
rf51b1d3 r609243f4 3 3 NAME=lo 4 4 5 NETIF=lo 5 HWPATH=/virt/lo/port0 6 6 NIL=nildummy 7 7 IL=ip -
uspace/srv/net/cfg/ne2k.nic
rf51b1d3 r609243f4 1 # DP8390 (NE2k)configuration1 # NE2000 configuration 2 2 3 3 NAME=ne2k 4 4 5 NETIF=ne20005 HWPATH=/hw/pci0/00:01.0/ne2000/port0 6 6 NIL=eth 7 7 IL=ip 8 9 IRQ=510 IO=30011 8 12 9 # 8023_2_LSAP, 8023_2_SNAP … … 17 14 IP_ADDR=10.0.2.15 18 15 IP_ROUTING=yes 19 IP_NETMASK=255.255.255. 016 IP_NETMASK=255.255.255.240 20 17 IP_BROADCAST=10.0.2.255 21 18 IP_GATEWAY=10.0.2.2 22 19 ARP=arp 23 20 24 MTU=1 50021 MTU=1492 -
uspace/srv/net/il/arp/arp.c
rf51b1d3 r609243f4 174 174 count); 175 175 176 if (device) {176 if (device) 177 177 arp_clear_device(device); 178 if (device->addr_data)179 free(device->addr_data);180 181 if (device->broadcast_data)182 free(device->broadcast_data);183 }184 178 } 185 179 … … 190 184 } 191 185 192 static int arp_clear_address_req( device_id_t device_id, services_t protocol,193 measured_string_t *address)186 static int arp_clear_address_req(nic_device_id_t device_id, 187 services_t protocol, measured_string_t *address) 194 188 { 195 189 fibril_mutex_lock(&arp_globals.lock); … … 218 212 } 219 213 220 static int arp_clear_device_req( device_id_t device_id)214 static int arp_clear_device_req(nic_device_id_t device_id) 221 215 { 222 216 fibril_mutex_lock(&arp_globals.lock); … … 289 283 * 290 284 */ 291 static int arp_receive_message( device_id_t device_id, packet_t *packet)285 static int arp_receive_message(nic_device_id_t device_id, packet_t *packet) 292 286 { 293 287 int rc; … … 365 359 memcpy(src_proto, proto->addr->value, 366 360 header->protocol_length); 367 memcpy(src_hw, device->addr ->value,361 memcpy(src_hw, device->addr, 368 362 device->packet_dimension.addr_len); 369 363 memcpy(des_hw, trans->hw_addr->value, … … 393 387 * 394 388 */ 395 static int arp_mtu_changed_message( device_id_t device_id, size_t mtu)389 static int arp_mtu_changed_message(nic_device_id_t device_id, size_t mtu) 396 390 { 397 391 fibril_mutex_lock(&arp_globals.lock); … … 409 403 printf("%s: Device %d changed MTU to %zu\n", NAME, device_id, mtu); 410 404 405 return EOK; 406 } 407 408 static int arp_addr_changed_message(nic_device_id_t device_id) 409 { 410 uint8_t addr_buffer[NIC_MAX_ADDRESS_LENGTH]; 411 size_t length; 412 ipc_callid_t data_callid; 413 if (!async_data_write_receive(&data_callid, &length)) { 414 async_answer_0(data_callid, EINVAL); 415 return EINVAL; 416 } 417 if (length > NIC_MAX_ADDRESS_LENGTH) { 418 async_answer_0(data_callid, ELIMIT); 419 return ELIMIT; 420 } 421 if (async_data_write_finalize(data_callid, addr_buffer, length) != EOK) { 422 return EINVAL; 423 } 424 425 fibril_mutex_lock(&arp_globals.lock); 426 427 arp_device_t *device = arp_cache_find(&arp_globals.cache, device_id); 428 if (!device) { 429 fibril_mutex_unlock(&arp_globals.lock); 430 return ENOENT; 431 } 432 433 memcpy(device->addr, addr_buffer, length); 434 device->addr_len = length; 435 436 fibril_mutex_unlock(&arp_globals.lock); 411 437 return EOK; 412 438 } … … 456 482 async_answer_0(iid, (sysarg_t) rc); 457 483 break; 484 case NET_IL_ADDR_CHANGED: 485 rc = arp_addr_changed_message(IPC_GET_DEVICE(*icall)); 486 async_answer_0(iid, (sysarg_t) rc); 458 487 459 488 default: … … 483 512 * 484 513 */ 485 static int arp_device_message( device_id_t device_id, services_t service,514 static int arp_device_message(nic_device_id_t device_id, services_t service, 486 515 services_t protocol, measured_string_t *address) 487 516 { … … 586 615 587 616 /* Get hardware address */ 588 rc = nil_get_addr_req(device->sess, device_id, &device->addr,589 &device->addr_data);590 if ( rc != EOK) {617 int len = nil_get_addr_req(device->sess, device_id, device->addr, 618 NIC_MAX_ADDRESS_LENGTH); 619 if (len < 0) { 591 620 fibril_mutex_unlock(&arp_globals.lock); 592 621 arp_protos_destroy(&device->protos, free); 593 622 free(device); 594 return rc; 595 } 623 return len; 624 } 625 626 device->addr_len = len; 596 627 597 628 /* Get broadcast address */ 598 rc = nil_get_broadcast_addr_req(device->sess, device_id, 599 &device->broadcast_addr, &device->broadcast_data); 600 if (rc != EOK) { 601 fibril_mutex_unlock(&arp_globals.lock); 602 free(device->addr); 603 free(device->addr_data); 629 len = nil_get_broadcast_addr_req(device->sess, device_id, 630 device->broadcast_addr, NIC_MAX_ADDRESS_LENGTH); 631 if (len < 0) { 632 fibril_mutex_unlock(&arp_globals.lock); 604 633 arp_protos_destroy(&device->protos, free); 605 634 free(device); 606 return rc; 607 } 635 return len; 636 } 637 638 device->broadcast_addr_len = len; 608 639 609 640 rc = arp_cache_add(&arp_globals.cache, device->device_id, … … 611 642 if (rc != EOK) { 612 643 fibril_mutex_unlock(&arp_globals.lock); 613 free(device->addr);614 free(device->addr_data);615 free(device->broadcast_addr);616 free(device->broadcast_data);617 644 arp_protos_destroy(&device->protos, free); 618 645 free(device); … … 640 667 } 641 668 642 static int arp_send_request( device_id_t device_id, services_t protocol,669 static int arp_send_request(nic_device_id_t device_id, services_t protocol, 643 670 measured_string_t *target, arp_device_t *device, arp_proto_t *proto) 644 671 { 645 672 /* ARP packet content size = header + (address + translation) * 2 */ 646 size_t length = 8 + 2 * (proto->addr->length + device->addr ->length);673 size_t length = 8 + 2 * (proto->addr->length + device->addr_len); 647 674 if (length > device->packet_dimension.content) 648 675 return ELIMIT; … … 661 688 662 689 header->hardware = htons(device->hardware); 663 header->hardware_length = (uint8_t) device->addr ->length;690 header->hardware_length = (uint8_t) device->addr_len; 664 691 header->protocol = htons(protocol_map(device->service, protocol)); 665 692 header->protocol_length = (uint8_t) proto->addr->length; … … 667 694 668 695 length = sizeof(arp_header_t); 669 670 memcpy(((uint8_t *) header) + length, device->addr->value, 671 device->addr->length); 672 length += device->addr->length; 696 memcpy(((uint8_t *) header) + length, device->addr, 697 device->addr_len); 698 length += device->addr_len; 673 699 memcpy(((uint8_t *) header) + length, proto->addr->value, 674 700 proto->addr->length); 675 701 length += proto->addr->length; 676 bzero(((uint8_t *) header) + length, device->addr ->length);677 length += device->addr ->length;702 bzero(((uint8_t *) header) + length, device->addr_len); 703 length += device->addr_len; 678 704 memcpy(((uint8_t *) header) + length, target->value, target->length); 679 680 int rc = packet_set_addr(packet, (uint8_t *) device->addr->value,681 (uint8_t *) device->broadcast_addr->value, device->addr->length);705 706 int rc = packet_set_addr(packet, device->addr, device->broadcast_addr, 707 device->addr_len); 682 708 if (rc != EOK) { 683 709 pq_release_remote(arp_globals.net_sess, packet_get_id(packet)); … … 704 730 * 705 731 */ 706 static int arp_translate_message( device_id_t device_id, services_t protocol,732 static int arp_translate_message(nic_device_id_t device_id, services_t protocol, 707 733 measured_string_t *target, measured_string_t **translation) 708 734 { -
uspace/srv/net/il/arp/arp.h
rf51b1d3 r609243f4 92 92 struct arp_device { 93 93 /** Actual device hardware address. */ 94 measured_string_t *addr;95 /** Actual device hardware address data. */96 uint8_t *addr_data;94 uint8_t addr[NIC_MAX_ADDRESS_LENGTH]; 95 /** Actual device hardware address length. */ 96 size_t addr_len; 97 97 /** Broadcast device hardware address. */ 98 measured_string_t *broadcast_addr;99 /** Broadcast device hardware address data. */100 uint8_t *broadcast_data;98 uint8_t broadcast_addr[NIC_MAX_ADDRESS_LENGTH]; 99 /** Broadcast device hardware address length. */ 100 size_t broadcast_addr_len; 101 101 /** Device identifier. */ 102 device_id_t device_id;102 nic_device_id_t device_id; 103 103 /** Hardware type. */ 104 104 hw_type_t hardware; -
uspace/srv/net/il/ip/ip.c
rf51b1d3 r609243f4 482 482 } 483 483 484 static int ip_device_req_local( device_id_t device_id, services_t netif)484 static int ip_device_req_local(nic_device_id_t device_id, services_t netif) 485 485 { 486 486 ip_netif_t *ip_netif; … … 501 501 ip_netif->device_id = device_id; 502 502 ip_netif->service = netif; 503 ip_netif->state = N ETIF_STOPPED;503 ip_netif->state = NIC_STATE_STOPPED; 504 504 505 505 fibril_rwlock_write_lock(&ip_globals.netifs_lock); … … 594 594 while (index >= 0) { 595 595 netif = ip_netifs_get_index(&ip_globals.netifs, index); 596 if (netif && (netif->state == N ETIF_ACTIVE)) {596 if (netif && (netif->state == NIC_STATE_ACTIVE)) { 597 597 route = ip_netif_find_route(netif, destination); 598 598 if (route) … … 1142 1142 } 1143 1143 1144 static int ip_send_msg_local( device_id_t device_id, packet_t *packet,1144 static int ip_send_msg_local(nic_device_id_t device_id, packet_t *packet, 1145 1145 services_t sender, services_t error) 1146 1146 { … … 1258 1258 * @return ENOENT if device is not found. 1259 1259 */ 1260 static int ip_device_state_message(device_id_t device_id, device_state_t state) 1260 static int ip_device_state_message(nic_device_id_t device_id, 1261 nic_device_state_t state) 1261 1262 { 1262 1263 ip_netif_t *netif; … … 1272 1273 fibril_rwlock_write_unlock(&ip_globals.netifs_lock); 1273 1274 1274 printf("%s: Device %d changed state to %d\n", NAME, device_id, state); 1275 printf("%s: Device %d changed state to '%s'\n", NAME, device_id, 1276 nic_device_state_to_string(state)); 1275 1277 1276 1278 return EOK; … … 1312 1314 * tl_received_msg() function. 1313 1315 */ 1314 static int ip_deliver_local( device_id_t device_id, packet_t *packet,1316 static int ip_deliver_local(nic_device_id_t device_id, packet_t *packet, 1315 1317 ip_header_t *header, services_t error) 1316 1318 { … … 1413 1415 * is disabled. 1414 1416 */ 1415 static int ip_process_packet( device_id_t device_id, packet_t *packet)1417 static int ip_process_packet(nic_device_id_t device_id, packet_t *packet) 1416 1418 { 1417 1419 ip_header_t *header; … … 1514 1516 * 1515 1517 */ 1516 static int ip_packet_size_message( device_id_t device_id, size_t *addr_len,1518 static int ip_packet_size_message(nic_device_id_t device_id, size_t *addr_len, 1517 1519 size_t *prefix, size_t *content, size_t *suffix) 1518 1520 { … … 1572 1574 * @return ENOENT if device is not found. 1573 1575 */ 1574 static int ip_mtu_changed_message( device_id_t device_id, size_t mtu)1576 static int ip_mtu_changed_message(nic_device_id_t device_id, size_t mtu) 1575 1577 { 1576 1578 ip_netif_t *netif; … … 1629 1631 async_answer_0(iid, (sysarg_t) rc); 1630 1632 break; 1631 1633 case NET_IL_ADDR_CHANGED: 1634 async_answer_0(iid, (sysarg_t) EOK); 1635 break; 1636 1632 1637 default: 1633 1638 async_answer_0(iid, (sysarg_t) ENOTSUP); … … 1689 1694 } 1690 1695 1691 static int ip_add_route_req_local( device_id_t device_id, in_addr_t address,1696 static int ip_add_route_req_local(nic_device_id_t device_id, in_addr_t address, 1692 1697 in_addr_t netmask, in_addr_t gateway) 1693 1698 { … … 1723 1728 } 1724 1729 1725 static int ip_set_gateway_req_local(device_id_t device_id, in_addr_t gateway) 1730 static int ip_set_gateway_req_local(nic_device_id_t device_id, 1731 in_addr_t gateway) 1726 1732 { 1727 1733 ip_netif_t *netif; … … 1757 1763 * 1758 1764 */ 1759 static int ip_received_error_msg_local( device_id_t device_id,1765 static int ip_received_error_msg_local(nic_device_id_t device_id, 1760 1766 packet_t *packet, services_t target, services_t error) 1761 1767 { … … 1818 1824 static int ip_get_route_req_local(ip_protocol_t protocol, 1819 1825 const struct sockaddr *destination, socklen_t addrlen, 1820 device_id_t *device_id, void **header, size_t *headerlen)1826 nic_device_id_t *device_id, void **header, size_t *headerlen) 1821 1827 { 1822 1828 struct sockaddr_in *address_in; … … 1909 1915 size_t suffix; 1910 1916 size_t content; 1911 device_id_t device_id;1917 nic_device_id_t device_id; 1912 1918 int rc; 1913 1919 -
uspace/srv/net/il/ip/ip.h
rf51b1d3 r609243f4 92 92 in_addr_t broadcast; 93 93 /** Device identifier. */ 94 device_id_t device_id;94 nic_device_id_t device_id; 95 95 /** Indicates whether using DHCP. */ 96 96 int dhcp; … … 108 108 services_t service; 109 109 /** Device state. */ 110 device_state_t state;110 nic_device_state_t state; 111 111 }; 112 112 -
uspace/srv/net/net/Makefile
rf51b1d3 r609243f4 30 30 USPACE_PREFIX = ../../.. 31 31 ROOT_PATH = $(USPACE_PREFIX)/.. 32 LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBPACKET_PREFIX)/libpacket.a33 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBPACKET_PREFIX)/include32 LIBS = $(LIBNET_PREFIX)/libnet.a 33 EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include 34 34 35 35 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common … … 43 43 SOURCES = \ 44 44 net.c \ 45 net_standalone.c 45 net_standalone.c \ 46 packet_server.c 46 47 47 48 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/net/net/net.c
rf51b1d3 r609243f4 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 36 37 */ 37 38 39 #include <assert.h> 38 40 #include <async.h> 39 41 #include <ctype.h> 40 42 #include <ddi.h> 41 43 #include <errno.h> 44 #include <str_error.h> 42 45 #include <malloc.h> 43 46 #include <stdio.h> 44 47 #include <str.h> 48 #include <devman.h> 45 49 #include <str_error.h> 46 50 #include <ns.h> … … 49 53 #include <ipc/net_net.h> 50 54 #include <ipc/il.h> 55 #include <ipc/ip.h> 51 56 #include <ipc/nil.h> 52 57 #include <net/modules.h> … … 57 62 #include <adt/measured_strings.h> 58 63 #include <adt/module_map.h> 59 #include <netif_remote.h>60 64 #include <nil_remote.h> 61 65 #include <net_interface.h> 62 66 #include <ip_interface.h> 67 #include <device/nic.h> 68 #include <dirent.h> 69 #include <fcntl.h> 70 #include <cfg.h> 63 71 #include "net.h" 72 #include "packet_server.h" 64 73 65 74 /** Networking module name. */ 66 75 #define NAME "net" 67 76 68 /** File read buffer size. */ 69 #define BUFFER_SIZE 256 77 #define MAX_PATH_LENGTH 1024 70 78 71 79 /** Networking module global data. */ … … 109 117 /** Generate new system-unique device identifier. 110 118 * 111 * @return The system-unique devic identifier. 112 */ 113 static device_id_t generate_new_device_id(void) 119 * @return The system-unique devic identifier. 120 * 121 */ 122 static nic_device_id_t generate_new_device_id(void) 114 123 { 115 124 return device_assign_devno(); 116 }117 118 static int parse_line(measured_strings_t *configuration, uint8_t *line)119 {120 int rc;121 122 /* From the beginning */123 uint8_t *name = line;124 125 /* Skip comments and blank lines */126 if ((*name == '#') || (*name == '\0'))127 return EOK;128 129 /* Skip spaces */130 while (isspace(*name))131 name++;132 133 /* Remember the name start */134 uint8_t *value = name;135 136 /* Skip the name */137 while (isalnum(*value) || (*value == '_'))138 value++;139 140 if (*value == '=') {141 /* Terminate the name */142 *value = '\0';143 } else {144 /* Terminate the name */145 *value = '\0';146 147 /* Skip until '=' */148 value++;149 while ((*value) && (*value != '='))150 value++;151 152 /* Not found? */153 if (*value != '=')154 return EINVAL;155 }156 157 value++;158 159 /* Skip spaces */160 while (isspace(*value))161 value++;162 163 /* Create a bulk measured string till the end */164 measured_string_t *setting =165 measured_string_create_bulk(value, 0);166 if (!setting)167 return ENOMEM;168 169 /* Add the configuration setting */170 rc = measured_strings_add(configuration, name, 0, setting);171 if (rc != EOK) {172 free(setting);173 return rc;174 }175 176 return EOK;177 125 } 178 126 … … 182 130 printf("%s: Reading configuration file %s/%s\n", NAME, directory, filename); 183 131 184 /* Construct the full filename */ 185 char fname[BUFFER_SIZE]; 186 if (snprintf(fname, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE) 187 return EOVERFLOW; 188 189 /* Open the file */ 190 FILE *cfg = fopen(fname, "r"); 191 if (!cfg) 132 cfg_file_t cfg; 133 int rc = cfg_load_path(directory, filename, &cfg); 134 if (rc != EOK) 135 return rc; 136 137 if (cfg_anonymous(&cfg) == NULL) { 138 cfg_unload(&cfg); 192 139 return ENOENT; 193 194 /* 195 * Read the configuration line by line 196 * until an error or the end of file 197 */ 198 unsigned int line_number = 0; 199 size_t index = 0; 200 uint8_t line[BUFFER_SIZE]; 201 202 while (!ferror(cfg) && !feof(cfg)) { 203 int read = fgetc(cfg); 204 if ((read > 0) && (read != '\n') && (read != '\r')) { 205 if (index >= BUFFER_SIZE) { 206 line[BUFFER_SIZE - 1] = '\0'; 207 fprintf(stderr, "%s: Configuration line %u too " 208 "long: %s\n", NAME, line_number, (char *) line); 209 210 /* No space left in the line buffer */ 211 return EOVERFLOW; 212 } 213 /* Append the character */ 214 line[index] = (uint8_t) read; 215 index++; 216 } else { 217 /* On error or new line */ 218 line[index] = '\0'; 219 line_number++; 220 if (parse_line(configuration, line) != EOK) { 221 fprintf(stderr, "%s: Configuration error on " 222 "line %u: %s\n", NAME, line_number, (char *) line); 223 } 224 225 index = 0; 226 } 227 } 228 229 fclose(cfg); 140 } 141 142 cfg_section_foreach(cfg_anonymous(&cfg), link) { 143 const cfg_entry_t *entry = cfg_entry_instance(link); 144 145 rc = add_configuration(configuration, 146 (uint8_t *) entry->key, (uint8_t *) entry->value); 147 if (rc != EOK) { 148 printf("%s: Error processing configuration\n", NAME); 149 cfg_unload(&cfg); 150 return rc; 151 } 152 } 153 154 cfg_unload(&cfg); 230 155 return EOK; 231 156 } … … 272 197 273 198 netifs_initialize(&net_globals.netifs); 274 char_map_initialize(&net_globals.netif_ names);199 char_map_initialize(&net_globals.netif_hwpaths); 275 200 modules_initialize(&net_globals.modules); 276 201 measured_strings_initialize(&net_globals.configuration); 277 202 278 /* TODO: dynamic configuration */279 203 rc = read_configuration(); 280 if (rc != EOK)281 return rc;282 283 rc = add_module(NULL, &net_globals.modules, (uint8_t *) LO_NAME,284 (uint8_t *) LO_FILENAME, SERVICE_LO, 0, connect_to_service);285 if (rc != EOK)286 return rc;287 288 rc = add_module(NULL, &net_globals.modules, (uint8_t *) NE2000_NAME,289 (uint8_t *) NE2000_FILENAME, SERVICE_NE2000, 0, connect_to_service);290 204 if (rc != EOK) 291 205 return rc; … … 331 245 return rc; 332 246 247 rc = packet_server_init(); 248 if (rc != EOK) 249 goto out; 250 333 251 rc = net_initialize(client_connection); 334 252 if (rc != EOK) 335 253 goto out; 336 254 255 rc = startup(); 256 if (rc != EOK) 257 goto out; 258 337 259 rc = service_register(SERVICE_NETWORKING); 338 if (rc != EOK)339 goto out;340 341 rc = startup();342 260 if (rc != EOK) 343 261 goto out; … … 364 282 */ 365 283 static int net_get_conf(measured_strings_t *netif_conf, 366 measured_string_t *configuration, size_t count , uint8_t **data)367 { 368 if ( data)369 *data = NULL;284 measured_string_t *configuration, size_t count) 285 { 286 if ((!configuration) || (count <= 0)) 287 return EINVAL; 370 288 371 289 size_t index; … … 389 307 } 390 308 391 static int net_get_conf_req_local(measured_string_t **configuration, 392 size_t count, uint8_t **data) 393 { 394 if (!configuration || (count <= 0)) 395 return EINVAL; 396 397 return net_get_conf(NULL, *configuration, count, data); 398 } 399 400 static int net_get_device_conf_req_local(device_id_t device_id, 401 measured_string_t **configuration, size_t count, uint8_t **data) 402 { 403 if ((!configuration) || (count == 0)) 404 return EINVAL; 405 309 static int net_get_device_conf(nic_device_id_t device_id, 310 measured_string_t *configuration, size_t count) 311 { 406 312 netif_t *netif = netifs_find(&net_globals.netifs, device_id); 407 313 if (netif) 408 return net_get_conf(&netif->configuration, *configuration, count, data);314 return net_get_conf(&netif->configuration, configuration, count); 409 315 else 410 return net_get_conf(NULL, *configuration, count, data); 411 } 412 413 void net_free_settings(measured_string_t *settings, uint8_t *data) 414 { 316 return net_get_conf(NULL, configuration, count); 317 } 318 319 static int net_get_devices(measured_string_t **devices, size_t *dev_count) 320 { 321 if (!devices) 322 return EBADMEM; 323 324 size_t max_count = netifs_count(&net_globals.netifs); 325 *devices = malloc(max_count * sizeof(measured_string_t)); 326 if (*devices == NULL) 327 return ENOMEM; 328 329 size_t count = 0; 330 for (size_t i = 0; i < max_count; i++) { 331 netif_t *item = netifs_get_index(&net_globals.netifs, i); 332 if (item->sess != NULL) { 333 /* 334 * Use format "device_id:device_name" 335 * FIXME: This typecasting looks really ugly 336 */ 337 (*devices)[count].length = asprintf( 338 (char **) &((*devices)[count].value), 339 NIC_DEVICE_PRINT_FMT ":%s", item->id, 340 (const char *) item->name); 341 count++; 342 } 343 } 344 345 *dev_count = (size_t) count; 346 return EOK; 347 } 348 349 static int net_get_devices_count() 350 { 351 size_t max_count = netifs_count(&net_globals.netifs); 352 353 size_t count = 0; 354 for (size_t i = 0; i < max_count; i++) { 355 netif_t *item = netifs_get_index(&net_globals.netifs, i); 356 if (item->sess != NULL) 357 count++; 358 } 359 360 return count; 361 } 362 363 static void net_free_devices(measured_string_t *devices, size_t count) 364 { 365 size_t i; 366 for (i = 0; i < count; ++i) 367 free(devices[i].value); 368 369 free(devices); 415 370 } 416 371 … … 431 386 * 432 387 */ 433 static int start_device(netif_t *netif) 434 { 435 int rc; 436 437 /* Mandatory netif */ 438 measured_string_t *setting = 439 measured_strings_find(&netif->configuration, (uint8_t *) CONF_NETIF, 0); 440 441 netif->driver = get_running_module(&net_globals.modules, setting->value); 442 if (!netif->driver) { 443 fprintf(stderr, "%s: Failed to start network interface driver '%s'\n", 388 static int init_device(netif_t *netif, devman_handle_t handle) 389 { 390 netif->handle = handle; 391 netif->sess = devman_device_connect(EXCHANGE_SERIALIZE, netif->handle, 392 IPC_FLAG_BLOCKING); 393 if (netif->sess == NULL) { 394 printf("%s: Unable to connect to device\n", NAME); 395 return EREFUSED; 396 } 397 398 /* Optional network interface layer */ 399 measured_string_t *setting = measured_strings_find(&netif->configuration, 400 (uint8_t *) CONF_NIL, 0); 401 if (setting) { 402 netif->nil = get_running_module(&net_globals.modules, 403 setting->value); 404 if (!netif->nil) { 405 printf("%s: Unable to connect to network interface layer '%s'\n", 406 NAME, setting->value); 407 return EINVAL; 408 } 409 } else 410 netif->nil = NULL; 411 412 /* Mandatory internet layer */ 413 setting = measured_strings_find(&netif->configuration, 414 (uint8_t *) CONF_IL, 0); 415 netif->il = get_running_module(&net_globals.modules, 416 setting->value); 417 if (!netif->il) { 418 printf("%s: Unable to connect to internet layer '%s'\n", 444 419 NAME, setting->value); 445 420 return EINVAL; 446 421 } 447 422 448 /* Optional network interface layer */449 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_NIL, 0);450 if (setting) {451 netif->nil = get_running_module(&net_globals.modules, setting->value);452 if (!netif->nil) {453 fprintf(stderr, "%s: Failed to start network interface layer '%s'\n",454 NAME, setting->value);455 return EINVAL;456 }457 } else458 netif->nil = NULL;459 460 /* Mandatory internet layer */461 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IL, 0);462 netif->il = get_running_module(&net_globals.modules, setting->value);463 if (!netif->il) {464 fprintf(stderr, "%s: Failed to start internet layer '%s'\n",465 NAME, setting->value);466 return EINVAL;467 }468 469 /* Hardware configuration */470 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IRQ, 0);471 int irq = setting ? strtol((char *) setting->value, NULL, 10) : 0;472 473 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IO, 0);474 uintptr_t io = setting ? strtol((char *) setting->value, NULL, 16) : 0;475 476 rc = netif_probe_req(netif->driver->sess, netif->id, irq, (void *) io);477 if (rc != EOK)478 return rc;479 480 423 /* Network interface layer startup */ 481 services_t internet_service; 424 int rc; 425 services_t nil_service; 482 426 if (netif->nil) { 483 setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_MTU, 0); 427 setting = measured_strings_find(&netif->configuration, 428 (uint8_t *) CONF_MTU, 0); 484 429 if (!setting) 485 430 setting = measured_strings_find(&net_globals.configuration, 486 431 (uint8_t *) CONF_MTU, 0); 487 432 488 int mtu = setting ? strtol((char *) setting->value, NULL, 10) : 0; 489 rc = nil_device_req(netif->nil->sess, netif->id, mtu, 490 netif->driver->service); 433 int mtu = setting ? 434 strtol((const char *) setting->value, NULL, 10) : 0; 435 rc = nil_device_req(netif->nil->sess, netif->id, 436 netif->handle, mtu); 437 if (rc != EOK) { 438 printf("%s: Unable to start network interface layer\n", 439 NAME); 440 return rc; 441 } 442 443 nil_service = netif->nil->service; 444 } else 445 nil_service = -1; 446 447 /* Inter-network layer startup */ 448 switch (netif->il->service) { 449 case SERVICE_IP: 450 rc = ip_device_req(netif->il->sess, netif->id, nil_service); 451 if (rc != EOK) { 452 printf("%s: Unable to start internet layer\n", NAME); 453 return rc; 454 } 455 456 break; 457 default: 458 return ENOENT; 459 } 460 461 return nic_set_state(netif->sess, NIC_STATE_ACTIVE); 462 } 463 464 static int net_driver_port_ready(devman_handle_t handle) 465 { 466 char hwpath[MAX_PATH_LENGTH]; 467 int rc = devman_fun_get_path(handle, hwpath, MAX_PATH_LENGTH); 468 if (rc != EOK) 469 return EINVAL; 470 471 int index = char_map_find(&net_globals.netif_hwpaths, 472 (uint8_t *) hwpath, 0); 473 if (index == CHAR_MAP_NULL) 474 return ENOENT; 475 476 netif_t *netif = netifs_get_index(&net_globals.netifs, index); 477 if (netif == NULL) 478 return ENOENT; 479 480 rc = init_device(netif, handle); 481 if (rc != EOK) 482 return rc; 483 484 /* Increment module usage */ 485 if (netif->nil) 486 netif->nil->usage++; 487 488 netif->il->usage++; 489 490 return EOK; 491 } 492 493 static int net_driver_ready_local(devman_handle_t handle) 494 { 495 devman_handle_t *funs; 496 size_t count; 497 int rc = devman_dev_get_functions(handle, &funs, &count); 498 if (rc != EOK) 499 return rc; 500 501 for (size_t i = 0; i < count; i++) { 502 rc = net_driver_port_ready(funs[i]); 491 503 if (rc != EOK) 492 504 return rc; 493 494 internet_service = netif->nil->service; 495 } else 496 internet_service = netif->driver->service; 497 498 /* Inter-network layer startup */ 499 rc = ip_device_req(netif->il->sess, netif->id, internet_service); 500 if (rc != EOK) 501 return rc; 502 503 return netif_start_req(netif->driver->sess, netif->id); 505 } 506 507 return EOK; 504 508 } 505 509 … … 519 523 static int startup(void) 520 524 { 521 const char *conf_files[] = {522 "lo",523 "ne2k"524 };525 size_t count = sizeof(conf_files) / sizeof(char *);526 525 int rc; 527 526 528 size_t i; 529 for (i = 0; i < count; i++) { 527 DIR *config_dir = opendir(CONF_DIR); 528 if (config_dir == NULL) 529 return ENOENT; 530 531 struct dirent *dir_entry; 532 while ((dir_entry = readdir(config_dir))) { 533 if (str_cmp(dir_entry->d_name + str_length(dir_entry->d_name) 534 - str_length(CONF_EXT), CONF_EXT) != 0) 535 continue; 536 530 537 netif_t *netif = (netif_t *) malloc(sizeof(netif_t)); 531 538 if (!netif) 532 return ENOMEM; 539 continue; 540 541 netif->handle = -1; 542 netif->sess = NULL; 533 543 534 544 netif->id = generate_new_device_id(); 535 if (!netif->id) 536 return EXDEV; 545 if (!netif->id) { 546 free(netif); 547 continue; 548 } 537 549 538 550 rc = measured_strings_initialize(&netif->configuration); 539 if (rc != EOK)540 return rc;541 542 /* Read configuration files */543 rc = read_netif_configuration(conf_files[i], netif);544 551 if (rc != EOK) { 552 free(netif); 553 continue; 554 } 555 556 rc = read_netif_configuration(dir_entry->d_name, netif); 557 if (rc != EOK) { 558 free(netif); 559 continue; 560 } 561 562 /* Mandatory name */ 563 measured_string_t *name = measured_strings_find(&netif->configuration, 564 (uint8_t *) CONF_NAME, 0); 565 if (!name) { 566 printf("%s: Network interface name is missing\n", NAME); 545 567 measured_strings_destroy(&netif->configuration, free); 546 568 free(netif); 547 return rc; 548 } 549 550 /* Mandatory name */ 551 measured_string_t *setting = 552 measured_strings_find(&netif->configuration, (uint8_t *) CONF_NAME, 0); 553 if (!setting) { 554 fprintf(stderr, "%s: Network interface name is missing\n", NAME); 569 continue; 570 } 571 572 netif->name = name->value; 573 574 /* Mandatory hardware path */ 575 measured_string_t *hwpath = measured_strings_find( 576 &netif->configuration, (const uint8_t *) CONF_HWPATH, 0); 577 if (!hwpath) { 555 578 measured_strings_destroy(&netif->configuration, free); 556 579 free(netif); 557 return EINVAL; 558 } 559 netif->name = setting->value; 580 } 560 581 561 582 /* Add to the netifs map */ … … 564 585 measured_strings_destroy(&netif->configuration, free); 565 586 free(netif); 566 return index;587 continue; 567 588 } 568 589 569 590 /* 570 * Add to the netif names map and start network interfaces591 * Add to the hardware paths map and init network interfaces 571 592 * and needed modules. 572 593 */ 573 rc = char_map_add(&net_globals.netif_names, netif->name, 0, 574 index); 594 rc = char_map_add(&net_globals.netif_hwpaths, hwpath->value, 0, index); 575 595 if (rc != EOK) { 576 596 measured_strings_destroy(&netif->configuration, free); 577 597 netifs_exclude_index(&net_globals.netifs, index, free); 578 return rc;579 }580 581 rc = start_device(netif);582 if (rc != EOK) {583 printf("%s: Ignoring failed interface %s (%s)\n", NAME,584 netif->name, str_error(rc));585 measured_strings_destroy(&netif->configuration, free);586 netifs_exclude_index(&net_globals.netifs, index, free);587 598 continue; 588 599 } 589 590 /* Increment modules' usage */ 591 netif->driver->usage++; 592 if (netif->nil) 593 netif->nil->usage++; 594 netif->il->usage++; 595 596 printf("%s: Network interface started (name: %s, id: %d, driver: %s, " 597 "nil: %s, il: %s)\n", NAME, netif->name, netif->id, 598 netif->driver->name, netif->nil ? (char *) netif->nil->name : "[none]", 599 netif->il->name); 600 } 601 600 } 601 602 closedir(config_dir); 602 603 return EOK; 603 604 } … … 624 625 uint8_t *data; 625 626 int rc; 627 size_t count; 626 628 627 629 *answer_count = 0; … … 636 638 if (rc != EOK) 637 639 return rc; 638 net_get_device_conf_req_local(IPC_GET_DEVICE(*call), &strings, 639 IPC_GET_COUNT(*call), NULL); 640 641 /* Strings should not contain received data anymore */ 642 free(data); 640 641 net_get_device_conf(IPC_GET_DEVICE(*call), strings, 642 IPC_GET_COUNT(*call)); 643 643 644 644 rc = measured_strings_reply(strings, IPC_GET_COUNT(*call)); 645 645 free(strings); 646 free(data); 646 647 return rc; 647 648 case NET_NET_GET_CONF: … … 650 651 if (rc != EOK) 651 652 return rc; 652 net_get_conf_req_local(&strings, IPC_GET_COUNT(*call), NULL); 653 654 /* Strings should not contain received data anymore */ 655 free(data); 653 654 net_get_conf(NULL, strings, IPC_GET_COUNT(*call)); 656 655 657 656 rc = measured_strings_reply(strings, IPC_GET_COUNT(*call)); 658 657 free(strings); 659 return rc; 660 case NET_NET_STARTUP: 661 return startup(); 662 } 663 664 return ENOTSUP; 658 free(data); 659 return rc; 660 case NET_NET_GET_DEVICES_COUNT: 661 count = (size_t) net_get_devices_count(); 662 IPC_SET_ARG1(*answer, count); 663 *answer_count = 1; 664 return EOK; 665 case NET_NET_GET_DEVICES: 666 rc = net_get_devices(&strings, &count); 667 if (rc != EOK) 668 return rc; 669 670 rc = measured_strings_reply(strings, count); 671 net_free_devices(strings, count); 672 return rc; 673 case NET_NET_DRIVER_READY: 674 rc = net_driver_ready_local(IPC_GET_ARG1(*call)); 675 *answer_count = 0; 676 return rc; 677 default: 678 return ENOTSUP; 679 } 665 680 } 666 681 -
uspace/srv/net/net/net.h
rf51b1d3 r609243f4 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 45 46 #include <adt/module_map.h> 46 47 #include <net/packet.h> 48 #include <devman.h> 47 49 48 50 /** @name Modules definitions 49 51 * @{ 50 52 */ 51 52 #define NE2000_FILENAME "/srv/ne2000"53 #define NE2000_NAME "ne2000"54 53 55 54 #define ETHERNET_FILENAME "/srv/eth" … … 58 57 #define IP_FILENAME "/srv/ip" 59 58 #define IP_NAME "ip" 60 61 #define LO_FILENAME "/srv/lo"62 #define LO_NAME "lo"63 59 64 60 #define NILDUMMY_FILENAME "/srv/nildummy" … … 77 73 #define CONF_MTU "MTU" /**< Maximum transmission unit configuration label. */ 78 74 #define CONF_NAME "NAME" /**< Network interface name configuration label. */ 79 #define CONF_ NETIF "NETIF" /**< Network interface module name configurationlabel. */75 #define CONF_HWPATH "HWPATH" /**< Network interface hardware pathname label. */ 80 76 #define CONF_NIL "NIL" /**< Network interface layer module name configuration label. */ 81 77 … … 85 81 #define CONF_DIR "/cfg/net" /**< Configuration directory. */ 86 82 #define CONF_GENERAL_FILE "general" /**< General configuration file. */ 83 #define CONF_EXT ".nic" /**< Extension for NIC's configuration files. */ 87 84 88 85 /** Configuration settings. … … 98 95 */ 99 96 typedef struct { 97 uint8_t *name; /**< System-unique network interface name. */ 98 nic_device_id_t id; /**< System-unique network interface identifier. */ 100 99 measured_strings_t configuration; /**< Configuration. */ 101 100 102 101 /** Serving network interface driver module index. */ 103 module_t *driver; 102 devman_handle_t handle; /**< Handle for devman */ 103 async_sess_t *sess; /**< Driver session. */ 104 104 105 device_id_t id; /**< System-unique network interface identifier. */105 module_t *nil; /**< Serving link layer module index. */ 106 106 module_t *il; /**< Serving internet layer module index. */ 107 uint8_t *name; /**< System-unique network interface name. */108 module_t *nil; /**< Serving link layer module index. */109 107 } netif_t; 110 108 … … 124 122 modules_t modules; /**< Available modules. */ 125 123 126 /** Network interface structure indices by names. */127 char_map_t netif_ names;124 /** Network interface structure indices by hardware path. */ 125 char_map_t netif_hwpaths; 128 126 129 127 /** Present network interfaces. */ -
uspace/srv/net/net/net_standalone.c
rf51b1d3 r609243f4 35 35 */ 36 36 37 #include "net.h"38 39 37 #include <str.h> 40 38 #include <adt/measured_strings.h> … … 42 40 #include <ipc/net.h> 43 41 #include <errno.h> 44 45 42 #include <ip_interface.h> 46 #include <packet_server.h> 43 #include "net.h" 44 #include "packet_server.h" 47 45 48 46 /** Networking module global data. */ … … 62 60 int rc; 63 61 64 task_id_t task_id = net_spawn((uint8_t *) "/srv/ip");62 task_id_t task_id = net_spawn((uint8_t *) IP_FILENAME); 65 63 if (!task_id) 66 64 return EINVAL; -
uspace/srv/net/net/packet_server.c
rf51b1d3 r609243f4 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 35 36 */ 36 37 37 #include <packet_server.h>38 38 #include <align.h> 39 39 #include <assert.h> 40 40 #include <async.h> 41 41 #include <errno.h> 42 #include <str_error.h> 43 #include <stdio.h> 42 44 #include <fibril_synch.h> 43 45 #include <unistd.h> … … 48 50 #include <net/packet_header.h> 49 51 52 #include "packet_server.h" 53 54 #define PACKET_SERVER_PROFILE 1 55 56 /** Number of queues cacheing the unused packets */ 50 57 #define FREE_QUEUES_COUNT 7 58 /** Maximum number of packets in each queue */ 59 #define FREE_QUEUE_MAX_LENGTH 16 51 60 52 61 /** The default address length reserved for new packets. */ … … 58 67 /** The default suffix reserved for new packets. */ 59 68 #define DEFAULT_SUFFIX 64 69 70 /** The queue with unused packets */ 71 typedef struct packet_queue { 72 packet_t *first; /**< First packet in the queue */ 73 size_t packet_size; /**< Maximal size of the packets in this queue */ 74 int count; /**< Length of the queue */ 75 } packet_queue_t; 60 76 61 77 /** Packet server global data. */ … … 64 80 fibril_mutex_t lock; 65 81 /** Free packet queues. */ 66 packet_t *free[FREE_QUEUES_COUNT]; 67 68 /** 69 * Packet length upper bounds of the free packet queues. The maximal 70 * lengths of packets in each queue in the ascending order. The last 71 * queue is not limited. 72 */ 73 size_t sizes[FREE_QUEUES_COUNT]; 82 packet_queue_t free_queues[FREE_QUEUES_COUNT]; 74 83 75 84 /** Total packets allocated. */ 76 unsigned int count;85 packet_id_t next_id; 77 86 } ps_globals = { 78 87 .lock = FIBRIL_MUTEX_INITIALIZER(ps_globals.lock), 79 .free = {80 NULL,81 NULL,82 NULL,83 NULL,84 NULL,85 NULL,86 NULL88 .free_queues = { 89 { NULL, PAGE_SIZE, 0}, 90 { NULL, PAGE_SIZE * 2, 0}, 91 { NULL, PAGE_SIZE * 4, 0}, 92 { NULL, PAGE_SIZE * 8, 0}, 93 { NULL, PAGE_SIZE * 16, 0}, 94 { NULL, PAGE_SIZE * 32, 0}, 95 { NULL, PAGE_SIZE * 64, 0}, 87 96 }, 88 .sizes = { 89 PAGE_SIZE, 90 PAGE_SIZE * 2, 91 PAGE_SIZE * 4, 92 PAGE_SIZE * 8, 93 PAGE_SIZE * 16, 94 PAGE_SIZE * 32, 95 PAGE_SIZE * 64 96 }, 97 .count = 0 97 .next_id = 1 98 98 }; 99 99 … … 107 107 * @param[in] max_suffix The maximal suffix length in bytes. 108 108 */ 109 static void 110 packet_init(packet_t *packet, size_t addr_len, size_t max_prefix, 111 size_t max_content, size_t max_suffix) 109 static void packet_init(packet_t *packet, 110 size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix) 112 111 { 113 112 /* Clear the packet content */ … … 120 119 packet->previous = 0; 121 120 packet->next = 0; 121 packet->offload_info = 0; 122 packet->offload_mask = 0; 122 123 packet->addr_len = 0; 123 124 packet->src_addr = sizeof(packet_t); … … 127 128 packet->data_start = packet->dest_addr + addr_len + packet->max_prefix; 128 129 packet->data_end = packet->data_start; 130 } 131 132 /** 133 * Releases the memory allocated for the packet 134 * 135 * @param[in] packet Pointer to the memory where the packet was allocated 136 */ 137 static void packet_dealloc(packet_t *packet) 138 { 139 pm_remove(packet); 140 munmap(packet, packet->length); 129 141 } 130 142 … … 141 153 * @return NULL if there is not enough memory left. 142 154 */ 143 static packet_t * 144 packet_create(size_t length, size_t addr_len, size_t max_prefix, 145 size_t max_content, size_t max_suffix) 155 static packet_t *packet_alloc(size_t length, size_t addr_len, 156 size_t max_prefix, size_t max_content, size_t max_suffix) 146 157 { 147 158 packet_t *packet; 148 159 int rc; 149 160 161 /* Global lock is locked */ 150 162 assert(fibril_mutex_is_locked(&ps_globals.lock)); 151 152 /* Already locked */ 163 /* The length is some multiple of PAGE_SIZE */ 164 assert(!(length & (PAGE_SIZE - 1))); 165 153 166 packet = (packet_t *) mmap(NULL, length, PROTO_READ | PROTO_WRITE, 154 167 MAP_SHARED | MAP_ANONYMOUS, 0, 0); 155 168 if (packet == MAP_FAILED) 156 169 return NULL; 157 158 ps_globals.count++; 159 packet->packet_id = ps_globals.count; 170 171 /* Using 32bit packet_id the id could overflow */ 172 packet_id_t pid; 173 do { 174 pid = ps_globals.next_id; 175 ps_globals.next_id++; 176 } while (!pid || pm_find(pid)); 177 packet->packet_id = pid; 178 160 179 packet->length = length; 161 180 packet_init(packet, addr_len, max_prefix, max_content, max_suffix); … … 163 182 rc = pm_add(packet); 164 183 if (rc != EOK) { 165 munmap(packet, packet->length);184 packet_dealloc(packet); 166 185 return NULL; 167 186 } … … 184 203 * @return NULL if there is not enough memory left. 185 204 */ 186 static packet_t * 187 packet_get_local(size_t addr_len, size_t max_prefix, size_t max_content, 188 size_t max_suffix) 189 { 190 size_t length = ALIGN_UP(sizeof(packet_t) + 2 * addr_len + 191 max_prefix + max_content + max_suffix, PAGE_SIZE); 192 205 static packet_t *packet_get_local(size_t addr_len, 206 size_t max_prefix, size_t max_content, size_t max_suffix) 207 { 208 size_t length = ALIGN_UP(sizeof(packet_t) + 2 * addr_len 209 + max_prefix + max_content + max_suffix, PAGE_SIZE); 210 211 if (length > PACKET_MAX_LENGTH) 212 return NULL; 213 193 214 fibril_mutex_lock(&ps_globals.lock); 194 215 … … 197 218 198 219 for (index = 0; index < FREE_QUEUES_COUNT; index++) { 199 if ((length > ps_globals. sizes[index]) &&200 220 if ((length > ps_globals.free_queues[index].packet_size) && 221 (index < FREE_QUEUES_COUNT - 1)) 201 222 continue; 202 223 203 packet = ps_globals.free [index];224 packet = ps_globals.free_queues[index].first; 204 225 while (packet_is_valid(packet) && (packet->length < length)) 205 226 packet = pm_find(packet->next); 206 227 207 228 if (packet_is_valid(packet)) { 208 if (packet == ps_globals.free[index]) 209 ps_globals.free[index] = pq_detach(packet); 210 else 229 ps_globals.free_queues[index].count--; 230 if (packet == ps_globals.free_queues[index].first) { 231 ps_globals.free_queues[index].first = pq_detach(packet); 232 } else { 211 233 pq_detach(packet); 234 } 212 235 213 packet_init(packet, addr_len, max_prefix, max_content, 214 max_suffix); 236 packet_init(packet, addr_len, max_prefix, max_content, max_suffix); 215 237 fibril_mutex_unlock(&ps_globals.lock); 216 238 … … 219 241 } 220 242 221 packet = packet_ create(length, addr_len, max_prefix, max_content,222 243 packet = packet_alloc(length, addr_len, 244 max_prefix, max_content, max_suffix); 223 245 224 246 fibril_mutex_unlock(&ps_globals.lock); … … 240 262 241 263 for (index = 0; (index < FREE_QUEUES_COUNT - 1) && 242 (packet->length > ps_globals. sizes[index]); index++) {264 (packet->length > ps_globals.free_queues[index].packet_size); index++) { 243 265 ; 244 266 } 245 267 246 result = pq_add(&ps_globals.free[index], packet, packet->length, 247 packet->length); 268 ps_globals.free_queues[index].count++; 269 result = pq_add(&ps_globals.free_queues[index].first, packet, 270 packet->length, packet->length); 248 271 assert(result == EOK); 249 272 } … … 328 351 case NET_PACKET_CREATE_1: 329 352 packet = packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, 330 353 IPC_GET_CONTENT(*call), DEFAULT_SUFFIX); 331 354 if (!packet) 332 355 return ENOMEM; … … 338 361 case NET_PACKET_CREATE_4: 339 362 packet = packet_get_local( 340 363 ((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(*call)) ? 341 364 IPC_GET_ADDR_LEN(*call) : DEFAULT_ADDR_LEN), 342 365 DEFAULT_PREFIX + IPC_GET_PREFIX(*call), … … 352 375 case NET_PACKET_GET: 353 376 packet = pm_find(IPC_GET_ID(*call)); 354 if (!packet_is_valid(packet)) 377 if (!packet_is_valid(packet)) { 355 378 return ENOENT; 379 } 356 380 return packet_reply(packet); 357 381 … … 371 395 } 372 396 397 int packet_server_init() 398 { 399 return EOK; 400 } 401 373 402 /** @} 374 403 */ -
uspace/srv/net/net/packet_server.h
rf51b1d3 r609243f4 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 47 48 #include <ipc/common.h> 48 49 50 extern int packet_server_init(void); 49 51 extern int packet_server_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, 50 52 size_t *); -
uspace/srv/net/nil/eth/eth.c
rf51b1d3 r609243f4 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 36 37 */ 37 38 39 #include <assert.h> 38 40 #include <async.h> 39 41 #include <malloc.h> … … 52 54 #include <protocol_map.h> 53 55 #include <net/device.h> 54 #include <netif_remote.h>55 56 #include <net_interface.h> 56 57 #include <il_remote.h> … … 58 59 #include <packet_client.h> 59 60 #include <packet_remote.h> 61 #include <device/nic.h> 60 62 #include <nil_skel.h> 61 63 #include "eth.h" … … 167 169 INT_MAP_IMPLEMENT(eth_protos, eth_proto_t); 168 170 169 int nil_device_state_msg_local( device_id_t device_id, sysarg_t state)171 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state) 170 172 { 171 173 int index; … … 196 198 fibril_rwlock_write_lock(ð_globals.protos_lock); 197 199 eth_globals.net_sess = sess; 198 199 eth_globals.broadcast_addr = 200 measured_string_create_bulk((uint8_t *) "\xFF\xFF\xFF\xFF\xFF\xFF", ETH_ADDR); 201 if (!eth_globals.broadcast_addr) { 202 rc = ENOMEM; 203 goto out; 204 } 200 memcpy(eth_globals.broadcast_addr, "\xFF\xFF\xFF\xFF\xFF\xFF", 201 ETH_ADDR); 205 202 206 203 rc = eth_devices_initialize(ð_globals.devices); … … 215 212 eth_devices_destroy(ð_globals.devices, free); 216 213 } 214 217 215 out: 218 216 fibril_rwlock_write_unlock(ð_globals.protos_lock); … … 222 220 } 223 221 224 /** Process IPC messages from the registered device driver modules in an 225 * infinite loop. 226 * 227 * @param[in] iid Message identifier. 228 * @param[in,out] icall Message parameters. 229 * @param[in] arg Local argument. 230 * 231 */ 232 static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg) 233 { 234 packet_t *packet; 235 int rc; 236 237 while (true) { 238 switch (IPC_GET_IMETHOD(*icall)) { 239 case NET_NIL_DEVICE_STATE: 240 nil_device_state_msg_local(IPC_GET_DEVICE(*icall), 241 IPC_GET_STATE(*icall)); 242 async_answer_0(iid, EOK); 243 break; 244 case NET_NIL_RECEIVED: 245 rc = packet_translate_remote(eth_globals.net_sess, 246 &packet, IPC_GET_PACKET(*icall)); 247 if (rc == EOK) 248 rc = nil_received_msg_local(IPC_GET_DEVICE(*icall), 249 packet, 0); 250 251 async_answer_0(iid, (sysarg_t) rc); 252 break; 253 default: 254 async_answer_0(iid, (sysarg_t) ENOTSUP); 255 } 256 257 iid = async_get_call(icall); 258 } 259 } 260 261 /** Registers new device or updates the MTU of an existing one. 262 * 263 * Determines the device local hardware address. 264 * 265 * @param[in] device_id The new device identifier. 266 * @param[in] service The device driver service. 267 * @param[in] mtu The device maximum transmission unit. 268 * @return EOK on success. 269 * @return EEXIST if the device with the different service exists. 270 * @return ENOMEM if there is not enough memory left. 271 * @return Other error codes as defined for the 272 * net_get_device_conf_req() function. 273 * @return Other error codes as defined for the 274 * netif_bind_service() function. 275 * @return Other error codes as defined for the 276 * netif_get_addr_req() function. 277 */ 278 static int eth_device_message(device_id_t device_id, services_t service, 222 /** Register new device or updates the MTU of an existing one. 223 * 224 * Determine the device local hardware address. 225 * 226 * @param[in] device_id New device identifier. 227 * @param[in] handle Device driver handle. 228 * @param[in] mtu Device maximum transmission unit. 229 * 230 * @return EOK on success. 231 * @return EEXIST if the device with the different service exists. 232 * @return ENOMEM if there is not enough memory left. 233 * 234 */ 235 static int eth_device_message(nic_device_id_t device_id, devman_handle_t handle, 279 236 size_t mtu) 280 237 { … … 301 258 device = eth_devices_find(ð_globals.devices, device_id); 302 259 if (device) { 303 if (device-> service != service) {260 if (device->handle != handle) { 304 261 printf("Device %d already exists\n", device->device_id); 305 262 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 340 297 341 298 device->device_id = device_id; 342 device-> service = service;299 device->handle = handle; 343 300 device->flags = 0; 344 301 if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags))) … … 377 334 378 335 /* Bind the device driver */ 379 device->sess = netif_bind_service(device->service, device->device_id,380 SERVICE_ETHERNET, eth_receiver);336 device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle, 337 IPC_FLAG_BLOCKING); 381 338 if (device->sess == NULL) { 382 339 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 385 342 } 386 343 344 nic_connect_to_nil(device->sess, SERVICE_ETHERNET, device_id); 345 387 346 /* Get hardware address */ 388 rc = netif_get_addr_req(device->sess, device->device_id, &device->addr, 389 &device->addr_data); 347 rc = nic_get_address(device->sess, &device->addr); 390 348 if (rc != EOK) { 391 349 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 399 357 if (index < 0) { 400 358 fibril_rwlock_write_unlock(ð_globals.devices_lock); 401 free(device->addr);402 free(device->addr_data);403 359 free(device); 404 360 return index; 405 361 } 406 362 407 printf("%s: Device registered (id: %d, service: %d: mtu: %zu, " 408 "mac: %02x:%02x:%02x:%02x:%02x:%02x, flags: 0x%x)\n", 409 NAME, device->device_id, device->service, device->mtu, 410 device->addr_data[0], device->addr_data[1], 411 device->addr_data[2], device->addr_data[3], 412 device->addr_data[4], device->addr_data[5], device->flags); 363 printf("%s: Device registered (id: %d, handle: %zu: mtu: %zu, " 364 "mac: " PRIMAC ", flags: 0x%x)\n", NAME, 365 device->device_id, device->handle, device->mtu, 366 ARGSMAC(device->addr.address), device->flags); 413 367 414 368 fibril_rwlock_write_unlock(ð_globals.devices_lock); … … 456 410 fcs = (eth_fcs_t *) data + length - sizeof(eth_fcs_t); 457 411 length -= sizeof(eth_fcs_t); 458 } else if (type <= ETH_MAX_CONTENT) {412 } else if (type <= ETH_MAX_CONTENT) { 459 413 /* Translate "LSAP" values */ 460 414 if ((header->lsap.dsap == ETH_LSAP_GLSAP) && … … 462 416 /* Raw packet -- discard */ 463 417 return NULL; 464 } else if ((header->lsap.dsap == ETH_LSAP_SNAP) &&418 } else if ((header->lsap.dsap == ETH_LSAP_SNAP) && 465 419 (header->lsap.ssap == ETH_LSAP_SNAP)) { 466 420 /* … … 469 423 */ 470 424 type = ntohs(header->snap.ethertype); 471 prefix = sizeof(eth_header_t) + 472 sizeof(eth_header_lsap_t) + 425 prefix = sizeof(eth_header_t) + sizeof(eth_header_lsap_t) + 473 426 sizeof(eth_header_snap_t); 474 427 } else { 475 428 /* IEEE 802.3 + 802.2 LSAP */ 476 429 type = lsap_map(header->lsap.dsap); 477 prefix = sizeof(eth_header_t) + 478 sizeof(eth_header_lsap_t); 430 prefix = sizeof(eth_header_t) + sizeof(eth_header_lsap_t); 479 431 } 480 432 … … 506 458 } 507 459 508 int nil_received_msg_local(device_id_t device_id, packet_t *packet, 509 services_t target) 460 int nil_received_msg_local(nic_device_id_t device_id, packet_t *packet) 510 461 { 511 462 eth_proto_t *proto; … … 523 474 flags = device->flags; 524 475 fibril_rwlock_read_unlock(ð_globals.devices_lock); 525 526 476 fibril_rwlock_read_lock(ð_globals.protos_lock); 477 527 478 do { 528 479 next = pq_detach(packet); … … 537 488 } 538 489 packet = next; 539 } while (packet);490 } while (packet); 540 491 541 492 fibril_rwlock_read_unlock(ð_globals.protos_lock); … … 554 505 * @return ENOENT if there is no such device. 555 506 */ 556 static int eth_packet_space_message( device_id_t device_id, size_t *addr_len,507 static int eth_packet_space_message(nic_device_id_t device_id, size_t *addr_len, 557 508 size_t *prefix, size_t *content, size_t *suffix) 558 509 { … … 579 530 } 580 531 581 /** Returnsthe device hardware address.532 /** Send the device hardware address. 582 533 * 583 534 * @param[in] device_id The device identifier. 584 535 * @param[in] type Type of the desired address. 585 * @param[out] address The device hardware address.586 536 * @return EOK on success. 587 537 * @return EBADMEM if the address parameter is NULL. 588 538 * @return ENOENT if there no such device. 589 539 */ 590 static int eth_addr_message(device_id_t device_id, eth_addr_type_t type, 591 measured_string_t **address) 592 { 593 eth_device_t *device; 594 595 if (!address) 596 return EBADMEM; 597 598 if (type == ETH_BROADCAST_ADDR) { 599 *address = eth_globals.broadcast_addr; 600 } else { 540 static int eth_addr_message(nic_device_id_t device_id, eth_addr_type_t type) 541 { 542 eth_device_t *device = NULL; 543 uint8_t *address; 544 size_t max_len; 545 ipc_callid_t callid; 546 547 if (type == ETH_BROADCAST_ADDR) 548 address = eth_globals.broadcast_addr; 549 else { 601 550 fibril_rwlock_read_lock(ð_globals.devices_lock); 602 551 device = eth_devices_find(ð_globals.devices, device_id); … … 605 554 return ENOENT; 606 555 } 607 *address = device->addr; 556 557 address = (uint8_t *) &device->addr.address; 558 } 559 560 int rc = EOK; 561 if (!async_data_read_receive(&callid, &max_len)) { 562 rc = EREFUSED; 563 goto end; 564 } 565 566 if (max_len < ETH_ADDR) { 567 async_data_read_finalize(callid, NULL, 0); 568 rc = ELIMIT; 569 goto end; 570 } 571 572 rc = async_data_read_finalize(callid, address, ETH_ADDR); 573 if (rc != EOK) 574 goto end; 575 576 end: 577 578 if (type == ETH_LOCAL_ADDR) 608 579 fibril_rwlock_read_unlock(ð_globals.devices_lock); 609 } 610 611 return (*address) ? EOK : ENOENT; 580 581 return rc; 612 582 } 613 583 … … 697 667 if (i < 0) 698 668 return i; 669 699 670 if (i != ETH_ADDR) 700 671 return EINVAL; 672 673 for (i = 0; i < ETH_ADDR; i++) { 674 if (src[i]) { 675 src_addr = src; 676 break; 677 } 678 } 701 679 702 680 length = packet_get_data_length(packet); … … 722 700 memcpy(header_dix->destination_address, dest, ETH_ADDR); 723 701 src = &header_dix->destination_address[0]; 724 } else if (IS_8023_2_LSAP(flags)) {702 } else if (IS_8023_2_LSAP(flags)) { 725 703 header_lsap = PACKET_PREFIX(packet, eth_header_lsap_t); 726 704 if (!header_lsap) … … 735 713 memcpy(header_lsap->header.destination_address, dest, ETH_ADDR); 736 714 src = &header_lsap->header.destination_address[0]; 737 } else if (IS_8023_2_SNAP(flags)) {715 } else if (IS_8023_2_SNAP(flags)) { 738 716 header = PACKET_PREFIX(packet, eth_header_snap_t); 739 717 if (!header) … … 746 724 header->lsap.ctrl = IEEE_8023_2_UI; 747 725 748 for (i = 0; i < 3; ++ i)726 for (i = 0; i < 3; i++) 749 727 header->snap.protocol[i] = 0; 750 728 … … 760 738 return ENOMEM; 761 739 762 for (i = 0; i < 7; ++ i)740 for (i = 0; i < 7; i++) 763 741 preamble->preamble[i] = ETH_PREAMBLE; 764 742 … … 787 765 * @return EINVAL if the service parameter is not known. 788 766 */ 789 static int eth_send_message( device_id_t device_id, packet_t *packet,767 static int eth_send_message(nic_device_id_t device_id, packet_t *packet, 790 768 services_t sender) 791 769 { … … 813 791 do { 814 792 rc = eth_prepare_packet(device->flags, next, 815 (uint8_t *) device->addr->value, ethertype, device->mtu);793 (uint8_t *) &device->addr.address, ethertype, device->mtu); 816 794 if (rc != EOK) { 817 795 /* Release invalid packet */ … … 825 803 next = pq_next(next); 826 804 } 827 } while (next);805 } while (next); 828 806 829 807 /* Send packet queue */ 830 if (packet) { 831 netif_send_msg(device->sess, device_id, packet, 832 SERVICE_ETHERNET); 833 } 834 808 if (packet) 809 nic_send_message(device->sess, packet_get_id(packet)); 810 835 811 fibril_rwlock_read_unlock(ð_globals.devices_lock); 836 812 return EOK; 837 813 } 838 814 815 static int eth_addr_changed(nic_device_id_t device_id) 816 { 817 nic_address_t address; 818 size_t length; 819 ipc_callid_t data_callid; 820 if (!async_data_write_receive(&data_callid, &length)) { 821 async_answer_0(data_callid, EINVAL); 822 return EINVAL; 823 } 824 if (length > sizeof (nic_address_t)) { 825 async_answer_0(data_callid, ELIMIT); 826 return ELIMIT; 827 } 828 if (async_data_write_finalize(data_callid, &address, length) != EOK) { 829 return EINVAL; 830 } 831 832 fibril_rwlock_write_lock(ð_globals.devices_lock); 833 /* An existing device? */ 834 eth_device_t *device = eth_devices_find(ð_globals.devices, device_id); 835 if (device) { 836 printf("Device %d changing address from " PRIMAC " to " PRIMAC "\n", 837 device_id, ARGSMAC(device->addr.address), ARGSMAC(address.address)); 838 memcpy(&device->addr, &address, sizeof (nic_address_t)); 839 fibril_rwlock_write_unlock(ð_globals.devices_lock); 840 841 /* Notify all upper layer modules */ 842 fibril_rwlock_read_lock(ð_globals.protos_lock); 843 int index; 844 for (index = 0; index < eth_protos_count(ð_globals.protos); index++) { 845 eth_proto_t *proto = eth_protos_get_index(ð_globals.protos, index); 846 if (proto->sess != NULL) { 847 il_addr_changed_msg(proto->sess, device->device_id, 848 ETH_ADDR, address.address); 849 } 850 } 851 852 fibril_rwlock_read_unlock(ð_globals.protos_lock); 853 return EOK; 854 } else { 855 return ENOENT; 856 } 857 } 858 839 859 int nil_module_message(ipc_callid_t callid, ipc_call_t *call, 840 860 ipc_call_t *answer, size_t *answer_count) 841 861 { 842 measured_string_t *address;843 862 packet_t *packet; 844 863 size_t addrlen; … … 861 880 case NET_NIL_DEVICE: 862 881 return eth_device_message(IPC_GET_DEVICE(*call), 863 IPC_GET_ SERVICE(*call), IPC_GET_MTU(*call));882 IPC_GET_DEVICE_HANDLE(*call), IPC_GET_MTU(*call)); 864 883 case NET_NIL_SEND: 865 884 rc = packet_translate_remote(eth_globals.net_sess, &packet, … … 867 886 if (rc != EOK) 868 887 return rc; 888 869 889 return eth_send_message(IPC_GET_DEVICE(*call), packet, 870 890 IPC_GET_SERVICE(*call)); … … 874 894 if (rc != EOK) 875 895 return rc; 896 876 897 IPC_SET_ADDR(*answer, addrlen); 877 898 IPC_SET_PREFIX(*answer, prefix); … … 879 900 IPC_SET_SUFFIX(*answer, suffix); 880 901 *answer_count = 4; 902 881 903 return EOK; 882 904 case NET_NIL_ADDR: 883 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_LOCAL_ADDR, 884 &address); 905 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_LOCAL_ADDR); 885 906 if (rc != EOK) 886 907 return rc; 887 return measured_strings_reply(address, 1); 908 909 IPC_SET_ADDR(*answer, ETH_ADDR); 910 *answer_count = 1; 911 912 return EOK; 888 913 case NET_NIL_BROADCAST_ADDR: 889 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_BROADCAST_ADDR, 890 &address); 914 rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_BROADCAST_ADDR); 891 915 if (rc != EOK) 892 return EOK; 893 return measured_strings_reply(address, 1); 916 return rc; 917 918 IPC_SET_ADDR(*answer, ETH_ADDR); 919 *answer_count = 1; 920 921 return EOK; 922 case NET_NIL_DEVICE_STATE: 923 nil_device_state_msg_local(IPC_GET_DEVICE(*call), IPC_GET_STATE(*call)); 924 async_answer_0(callid, EOK); 925 return EOK; 926 case NET_NIL_RECEIVED: 927 rc = packet_translate_remote(eth_globals.net_sess, &packet, 928 IPC_GET_ARG2(*call)); 929 if (rc == EOK) 930 rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet); 931 932 async_answer_0(callid, (sysarg_t) rc); 933 return rc; 934 case NET_NIL_ADDR_CHANGED: 935 rc = eth_addr_changed(IPC_GET_DEVICE(*call)); 936 async_answer_0(callid, (sysarg_t) rc); 937 return rc; 894 938 } 895 939 -
uspace/srv/net/nil/eth/eth.h
rf51b1d3 r609243f4 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 43 44 #include <net/device.h> 44 45 #include <adt/measured_strings.h> 46 #include <devman.h> 45 47 46 48 /** Ethernet address length. */ … … 220 222 struct eth_device { 221 223 /** Device identifier. */ 222 device_id_t device_id;223 /** Device driver service.*/224 services_t service;224 nic_device_id_t device_id; 225 /** Device handle */ 226 devman_handle_t handle; 225 227 /** Driver session. */ 226 228 async_sess_t *sess; … … 236 238 237 239 /** Actual device hardware address. */ 238 measured_string_t *addr; 239 240 /** Actual device hardware address data. */ 241 uint8_t *addr_data; 240 nic_address_t addr; 242 241 }; 243 242 … … 270 269 271 270 /** Broadcast device hardware address. */ 272 measured_string_t *broadcast_addr;271 uint8_t broadcast_addr[ETH_ADDR]; 273 272 }; 274 273 -
uspace/srv/net/nil/nildummy/nildummy.c
rf51b1d3 r609243f4 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 36 37 */ 37 38 39 #include <assert.h> 38 40 #include <async.h> 39 41 #include <malloc.h> … … 50 52 #include <net/packet.h> 51 53 #include <packet_remote.h> 52 #include <netif_remote.h> 54 #include <packet_client.h> 55 #include <devman.h> 56 #include <device/nic.h> 53 57 #include <nil_skel.h> 54 58 #include "nildummy.h" … … 65 69 DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t); 66 70 67 int nil_device_state_msg_local( device_id_t device_id, sysarg_t state)71 int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state) 68 72 { 69 73 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); … … 91 95 92 96 return rc; 93 }94 95 /** Process IPC messages from the registered device driver modules96 *97 * @param[in] iid Message identifier.98 * @param[in,out] icall Message parameters.99 * @param[in] arg Local argument.100 *101 */102 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)103 {104 packet_t *packet;105 int rc;106 107 while (true) {108 switch (IPC_GET_IMETHOD(*icall)) {109 case NET_NIL_DEVICE_STATE:110 rc = nil_device_state_msg_local(IPC_GET_DEVICE(*icall),111 IPC_GET_STATE(*icall));112 async_answer_0(iid, (sysarg_t) rc);113 break;114 115 case NET_NIL_RECEIVED:116 rc = packet_translate_remote(nildummy_globals.net_sess,117 &packet, IPC_GET_PACKET(*icall));118 if (rc == EOK)119 rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),120 packet, 0);121 122 async_answer_0(iid, (sysarg_t) rc);123 break;124 125 default:126 async_answer_0(iid, (sysarg_t) ENOTSUP);127 }128 129 iid = async_get_call(icall);130 }131 97 } 132 98 … … 148 114 * 149 115 */ 150 static int nildummy_device_message( device_id_t device_id, services_t service,151 size_t mtu)116 static int nildummy_device_message(nic_device_id_t device_id, 117 devman_handle_t handle, size_t mtu) 152 118 { 153 119 fibril_rwlock_write_lock(&nildummy_globals.devices_lock); … … 157 123 nildummy_devices_find(&nildummy_globals.devices, device_id); 158 124 if (device) { 159 if (device-> service != service) {160 printf("Device %d already exists\n", device->device_id);161 fibril_rwlock_write_unlock(162 125 if (device->handle != handle) { 126 printf("Device %d exists, handles do not match\n", 127 device->device_id); 128 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 163 129 return EEXIST; 164 130 } … … 170 136 device->mtu = NET_DEFAULT_MTU; 171 137 172 printf("Device %d already exists:\tMTU\t= %zu\n", 173 device-> device_id, device->mtu);138 printf("Device %d already exists:\tMTU\t= %zu\n", device->device_id, 139 device->mtu); 174 140 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 175 141 … … 192 158 193 159 device->device_id = device_id; 194 device-> service = service;160 device->handle = handle; 195 161 if (mtu > 0) 196 162 device->mtu = mtu; 197 163 else 198 164 device->mtu = NET_DEFAULT_MTU; 199 165 200 166 /* Bind the device driver */ 201 device->sess = netif_bind_service(device->service, device->device_id,202 SERVICE_ETHERNET, nildummy_receiver);167 device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle, 168 IPC_FLAG_BLOCKING); 203 169 if (device->sess == NULL) { 204 170 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 207 173 } 208 174 175 nic_connect_to_nil(device->sess, SERVICE_NILDUMMY, device_id); 176 209 177 /* Get hardware address */ 210 int rc = netif_get_addr_req(device->sess, device->device_id, 211 &device->addr, &device->addr_data); 178 int rc = nic_get_address(device->sess, &device->addr); 212 179 if (rc != EOK) { 213 180 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); … … 215 182 return rc; 216 183 } 184 185 device->addr_len = ETH_ADDR; 217 186 218 187 /* Add to the cache */ … … 221 190 if (index < 0) { 222 191 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 223 free(device->addr);224 free(device->addr_data);225 192 free(device); 226 193 return index; 227 194 } 228 195 229 printf("%s: Device registered (id: %d, service: %d, mtu: %zu)\n",230 NAME, device->device_id, device->service, device->mtu);196 printf("%s: Device registered (id: %d, mtu: %zu)\n", NAME, 197 device->device_id, device->mtu); 231 198 fibril_rwlock_write_unlock(&nildummy_globals.devices_lock); 232 199 return EOK; … … 243 210 * 244 211 */ 245 static int nildummy_addr_message(device_id_t device_id, 246 measured_string_t **address) 247 { 248 if (!address) 212 static int nildummy_addr_message(nic_device_id_t device_id, size_t *addrlen) 213 { 214 if (!addrlen) 249 215 return EBADMEM; 250 216 … … 258 224 } 259 225 260 *address = device->addr; 226 ipc_callid_t callid; 227 size_t max_len; 228 if (!async_data_read_receive(&callid, &max_len)) { 229 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 230 return EREFUSED; 231 } 232 233 if (max_len < device->addr_len) { 234 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 235 async_data_read_finalize(callid, NULL, 0); 236 return ELIMIT; 237 } 238 239 int rc = async_data_read_finalize(callid, 240 (uint8_t *) &device->addr.address, device->addr_len); 241 if (rc != EOK) { 242 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 243 return rc; 244 } 245 246 *addrlen = device->addr_len; 261 247 262 248 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); 263 264 return (*address) ? EOK : ENOENT; 249 return EOK; 265 250 } 266 251 … … 278 263 * 279 264 */ 280 static int nildummy_packet_space_message( device_id_t device_id, size_t *addr_len,281 size_t * prefix, size_t *content, size_t *suffix)265 static int nildummy_packet_space_message(nic_device_id_t device_id, 266 size_t *addr_len, size_t *prefix, size_t *content, size_t *suffix) 282 267 { 283 268 if ((!addr_len) || (!prefix) || (!content) || (!suffix)) … … 303 288 } 304 289 305 int nil_received_msg_local(device_id_t device_id, packet_t *packet, 306 services_t target) 290 int nil_received_msg_local(nic_device_id_t device_id, packet_t *packet) 307 291 { 308 292 fibril_rwlock_read_lock(&nildummy_globals.protos_lock); … … 358 342 * 359 343 */ 360 static int nildummy_send_message( device_id_t device_id, packet_t *packet,344 static int nildummy_send_message(nic_device_id_t device_id, packet_t *packet, 361 345 services_t sender) 362 346 { … … 372 356 /* Send packet queue */ 373 357 if (packet) 374 netif_send_msg(device->sess, device_id, packet, 375 SERVICE_NILDUMMY); 358 nic_send_message(device->sess, packet_get_id(packet)); 376 359 377 360 fibril_rwlock_read_unlock(&nildummy_globals.devices_lock); … … 383 366 ipc_call_t *answer, size_t *answer_count) 384 367 { 385 measured_string_t *address;386 368 packet_t *packet; 387 369 size_t addrlen; … … 404 386 case NET_NIL_DEVICE: 405 387 return nildummy_device_message(IPC_GET_DEVICE(*call), 406 IPC_GET_ SERVICE(*call), IPC_GET_MTU(*call));388 IPC_GET_DEVICE_HANDLE(*call), IPC_GET_MTU(*call)); 407 389 408 390 case NET_NIL_SEND: … … 427 409 428 410 case NET_NIL_ADDR: 429 rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &address); 411 case NET_NIL_BROADCAST_ADDR: 412 rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &addrlen); 430 413 if (rc != EOK) 431 414 return rc; 432 return measured_strings_reply(address, 1); 433 434 case NET_NIL_BROADCAST_ADDR: 435 rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &address); 436 if (rc != EOK) 437 return rc; 438 return measured_strings_reply(address, 1); 415 416 IPC_SET_ADDR(*answer, addrlen); 417 *answer_count = 1; 418 return rc; 419 case NET_NIL_DEVICE_STATE: 420 rc = nil_device_state_msg_local(IPC_GET_DEVICE(*call), 421 IPC_GET_STATE(*call)); 422 async_answer_0(callid, (sysarg_t) rc); 423 return rc; 424 425 case NET_NIL_RECEIVED: 426 rc = packet_translate_remote(nildummy_globals.net_sess, &packet, 427 IPC_GET_ARG2(*call)); 428 if (rc == EOK) 429 rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet); 430 431 async_answer_0(callid, (sysarg_t) rc); 432 return rc; 439 433 } 440 434 -
uspace/srv/net/nil/nildummy/nildummy.h
rf51b1d3 r609243f4 1 1 /* 2 2 * Copyright (c) 2009 Lukas Mejdrech 3 * Copyright (c) 2011 Radim Vansa 3 4 * All rights reserved. 4 5 * … … 41 42 #include <fibril_synch.h> 42 43 #include <ipc/services.h> 44 #include <ipc/devman.h> 43 45 #include <net/device.h> 44 46 #include <adt/measured_strings.h> … … 76 78 struct nildummy_device { 77 79 /** Device identifier. */ 78 device_id_t device_id; 79 80 /** Device driver service. */ 81 services_t service; 82 80 nic_device_id_t device_id; 81 /** Device driver handle. */ 82 devman_handle_t handle; 83 83 /** Driver session. */ 84 84 async_sess_t *sess; … … 88 88 89 89 /** Actual device hardware address. */ 90 measured_string_t *addr; 91 92 /** Actual device hardware address data. */ 93 uint8_t *addr_data; 90 nic_address_t addr; 91 /** Actual device hardware address length. */ 92 size_t addr_len; 94 93 }; 95 94 -
uspace/srv/net/tl/tcp/tcp.c
rf51b1d3 r609243f4 169 169 static int tcp_release_after_timeout(void *); 170 170 171 static int tcp_process_packet( device_id_t, packet_t *, services_t);171 static int tcp_process_packet(nic_device_id_t, packet_t *, services_t); 172 172 static int tcp_connect_core(socket_core_t *, socket_cores_t *, 173 173 struct sockaddr *, socklen_t); … … 177 177 size_t); 178 178 static packet_t *tcp_get_packets_to_send(socket_core_t *, tcp_socket_data_t *); 179 static void tcp_send_packets( device_id_t, packet_t *);179 static void tcp_send_packets(nic_device_id_t, packet_t *); 180 180 181 181 static void tcp_process_acknowledgement(socket_core_t *, tcp_socket_data_t *, … … 205 205 static void tcp_queue_received_end_of_data(socket_core_t *socket); 206 206 207 static int tcp_received_msg( device_id_t, packet_t *, services_t, services_t);207 static int tcp_received_msg(nic_device_id_t, packet_t *, services_t, services_t); 208 208 static int tcp_process_client_messages(async_sess_t *, ipc_callid_t, 209 209 ipc_call_t); … … 220 220 tcp_globals_t tcp_globals; 221 221 222 int tcp_received_msg( device_id_t device_id, packet_t *packet,222 int tcp_received_msg(nic_device_id_t device_id, packet_t *packet, 223 223 services_t receiver, services_t error) 224 224 { … … 238 238 } 239 239 240 int tcp_process_packet( device_id_t device_id, packet_t *packet, services_t error)240 int tcp_process_packet(nic_device_id_t device_id, packet_t *packet, services_t error) 241 241 { 242 242 size_t length; … … 1251 1251 bzero(socket_data, sizeof(*socket_data)); 1252 1252 socket_data->state = TCP_SOCKET_INITIAL; 1253 socket_data->device_id = DEVICE_INVALID_ID;1253 socket_data->device_id = NIC_DEVICE_INVALID_ID; 1254 1254 socket_data->window = NET_DEFAULT_TCP_WINDOW; 1255 1255 socket_data->treshold = socket_data->window; … … 1335 1335 } 1336 1336 if (tl_get_ip_packet_dimension(tcp_globals.ip_sess, 1337 &tcp_globals.dimensions, DEVICE_INVALID_ID,1337 &tcp_globals.dimensions, NIC_DEVICE_INVALID_ID, 1338 1338 &packet_dimension) == EOK) { 1339 1339 SOCKET_SET_DATA_FRAGMENT_SIZE(answer, … … 1651 1651 /* Sent packet? */ 1652 1652 packet = pq_find(socket_data->outgoing, sequence_number); 1653 printf("retransmit % d\n", packet_get_id(packet));1653 printf("retransmit %lu\n", packet_get_id(packet)); 1654 1654 if (packet) { 1655 1655 pq_get_order(packet, NULL, &data_length); … … 1790 1790 1791 1791 /* Send the packet */ 1792 printf("connecting % d\n", packet_get_id(packet));1792 printf("connecting %lu\n", packet_get_id(packet)); 1793 1793 tcp_send_packets(socket_data->device_id, packet); 1794 1794 … … 2004 2004 } 2005 2005 2006 void tcp_send_packets( device_id_t device_id, packet_t *packet)2006 void tcp_send_packets(nic_device_id_t device_id, packet_t *packet) 2007 2007 { 2008 2008 packet_t *next; -
uspace/srv/net/tl/tcp/tcp.h
rf51b1d3 r609243f4 182 182 183 183 /** Device identifier. */ 184 device_id_t device_id;184 nic_device_id_t device_id; 185 185 186 186 /** -
uspace/srv/net/tl/udp/udp.c
rf51b1d3 r609243f4 124 124 * ip_client_process_packet() function. 125 125 */ 126 static int udp_process_packet( device_id_t device_id, packet_t *packet,126 static int udp_process_packet(nic_device_id_t device_id, packet_t *packet, 127 127 services_t error) 128 128 { … … 322 322 * udp_process_packet() function. 323 323 */ 324 static int udp_received_msg( device_id_t device_id, packet_t *packet,324 static int udp_received_msg(nic_device_id_t device_id, packet_t *packet, 325 325 services_t receiver, services_t error) 326 326 { … … 499 499 void *ip_header; 500 500 size_t headerlen; 501 device_id_t device_id;501 nic_device_id_t device_id; 502 502 packet_dimension_t *packet_dimension; 503 503 size_t size; … … 617 617 htons(flip_checksum(compact_checksum(checksum))); 618 618 free(ip_header); 619 } else { 620 device_id = DEVICE_INVALID_ID; 621 } 619 } else 620 device_id = NIC_DEVICE_INVALID_ID; 622 621 623 622 /* Prepare the first packet fragment */ … … 806 805 size = MAX_UDP_FRAGMENT_SIZE; 807 806 if (tl_get_ip_packet_dimension(udp_globals.ip_sess, 808 &udp_globals.dimensions, DEVICE_INVALID_ID,807 &udp_globals.dimensions, NIC_DEVICE_INVALID_ID, 809 808 &packet_dimension) == EOK) { 810 809 if (packet_dimension->content < size)
Note:
See TracChangeset
for help on using the changeset viewer.