Changeset a7a85d16 in mainline
- Timestamp:
- 2010-10-16T17:16:30Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 668f8cbf, e0e568ff, f14291b
- Parents:
- ef689ef0 (diff), c62ae1d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace
- Files:
-
- 41 edited
- 8 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/ipc/arp.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup arp30 * 29 /** @addtogroup libc 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * ARP module messages. 35 * @see arp_interface.h 36 36 */ 37 37 38 #ifndef __NET_ARP_MESSAGES__39 #define __NET_ARP_MESSAGES__38 #ifndef LIBC_ARP_MESSAGES_ 39 #define LIBC_ARP_MESSAGES_ 40 40 41 41 #include <ipc/ipc.h> 42 42 #include <ipc/net.h> 43 43 44 /** ARP module messages. 45 */ 46 typedef enum{ 44 /** ARP module messages. */ 45 typedef enum { 47 46 /** Clean cache message. 48 * 47 * @see arp_clean_cache() 49 48 */ 50 49 NET_ARP_CLEAN_CACHE = NET_ARP_FIRST, 51 50 /** Clear address cache message. 52 * 51 * @see arp_clear_address_msg() 53 52 */ 54 53 NET_ARP_CLEAR_ADDRESS, 55 54 /** Clear device cache message. 56 * 55 * @see arp_clear_device_req() 57 56 */ 58 57 NET_ARP_CLEAR_DEVICE, 59 58 /** New device message. 60 * 59 * @see arp_device_req() 61 60 */ 62 61 NET_ARP_DEVICE, 63 62 /** Address translation message. 64 * 63 * @see arp_translate_req() 65 64 */ 66 65 NET_ARP_TRANSLATE 67 66 } arp_messages; 68 67 69 /** @name ARP specific message parameters definitions 70 */ 68 /** @name ARP specific message parameters definitions */ 71 69 /*@{*/ 72 70 73 71 /** Returns the protocol service message parameter. 74 * 72 * @param[in] call The message call structure. 75 73 */ 76 74 #define ARP_GET_NETIF(call) \ 77 ({services_t service = (services_t) IPC_GET_ARG2(*call); service;}) 75 ({ \ 76 services_t service = (services_t) IPC_GET_ARG2(*call); \ 77 service; \ 78 }) 78 79 79 80 /*@}*/ -
uspace/lib/c/include/ipc/il.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net_il29 /** @addtogroup libc 30 30 * @{ 31 31 */ … … 37 37 */ 38 38 39 #ifndef __NET_IL_MESSAGES_H__40 #define __NET_IL_MESSAGES_H__39 #ifndef LIBC_IL_MESSAGES_H_ 40 #define LIBC_IL_MESSAGES_H_ 41 41 42 42 #include <ipc/ipc.h> 43 43 #include <ipc/net.h> 44 44 45 /** Internet layer modules messages. 46 */ 45 /** Internet layer modules messages. */ 47 46 typedef enum { 48 47 /** New device message. 49 * 48 * @see ip_device_req() 50 49 */ 51 50 NET_IL_DEVICE = NET_IL_FIRST, 52 51 /** Device state changed message. 53 * 52 * @see il_device_state_msg() 54 53 */ 55 54 NET_IL_DEVICE_STATE, 56 55 /** Device MTU changed message. 57 * 56 * @see il_mtu_changed_msg() 58 57 */ 59 58 NET_IL_MTU_CHANGED, 60 59 /** Packet size message. 61 * 60 * @see il_packet_size_req() 62 61 */ 63 62 NET_IL_PACKET_SPACE, 64 63 /** Packet received message. 65 * 64 * @see il_received_msg() 66 65 */ 67 66 NET_IL_RECEIVED, 68 67 /** Packet send message. 69 * 68 * @see il_send_msg() 70 69 */ 71 70 NET_IL_SEND 72 71 } il_messages; 73 72 74 /** @name Internetwork layer specific message parameters definitions 75 * 76 */ 73 /** @name Internetwork layer specific message parameters definitions */ 77 74 /*@{*/ 78 75 79 76 /** Return the protocol number message parameter. 80 77 * @param[in] call The message call structure. 81 *82 78 */ 83 #define IL_GET_PROTO(call) 79 #define IL_GET_PROTO(call) (int) IPC_GET_ARG1(*call) 84 80 85 81 /** Return the registering service message parameter. 86 82 * @param[in] call The message call structure. 87 *88 83 */ 89 #define IL_GET_SERVICE(call) 84 #define IL_GET_SERVICE(call) (services_t) IPC_GET_ARG2(*call) 90 85 91 86 /*@}*/ -
uspace/lib/c/include/ipc/ip.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup ip30 * 29 /** @addtogroup libc 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * IP module messages. 35 * @see ip_interface.h 36 36 */ 37 37 38 #ifndef __NET_IP_MESSAGES_H__39 #define __NET_IP_MESSAGES_H__38 #ifndef LIBC_IP_MESSAGES_H_ 39 #define LIBC_IP_MESSAGES_H_ 40 40 41 41 #include <ipc/ipc.h> … … 45 45 #include <net/ip_codes.h> 46 46 47 /** IP module messages. 48 */ 49 typedef enum{ 47 /** IP module messages. */ 48 typedef enum { 50 49 /** Adds the routing entry. 51 * 50 * @see ip_add_route() 52 51 */ 53 52 NET_IP_ADD_ROUTE = NET_IP_FIRST, 54 53 /** Gets the actual route information. 55 * 54 * @see ip_get_route() 56 55 */ 57 56 NET_IP_GET_ROUTE, 58 57 /** Processes the received error notification. 59 * 58 * @see ip_received_error_msg() 60 59 */ 61 60 NET_IP_RECEIVED_ERROR, 62 61 /** Sets the default gateway. 63 * 62 * @see ip_set_default_gateway() 64 63 */ 65 64 NET_IP_SET_GATEWAY 66 65 } ip_messages; 67 66 68 /** @name IP specific message parameters definitions 69 */ 67 /** @name IP specific message parameters definitions */ 70 68 /*@{*/ 71 69 72 70 /** Returns the address message parameter. 73 * 71 * @param[in] call The message call structure. 74 72 */ 75 73 #define IP_GET_ADDRESS(call) \ 76 ({in_addr_t addr; addr.s_addr = IPC_GET_ARG3(*call); addr;}) 74 ({ \ 75 in_addr_t addr; \ 76 addr.s_addr = IPC_GET_ARG3(*call); \ 77 addr; \ 78 }) 77 79 78 80 /** Returns the gateway message parameter. 79 * 81 * @param[in] call The message call structure. 80 82 */ 81 83 #define IP_GET_GATEWAY(call) \ 82 ({in_addr_t addr; addr.s_addr = IPC_GET_ARG2(*call); addr;}) 84 ({ \ 85 in_addr_t addr; \ 86 addr.s_addr = IPC_GET_ARG2(*call); \ 87 addr; \ 88 }) 83 89 84 90 /** Sets the header length in the message answer. 85 * 91 * @param[out] answer The message answer structure. 86 92 */ 87 93 #define IP_SET_HEADERLEN(answer, value) \ 88 {ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG2(*answer, argument);} 94 do { \ 95 ipcarg_t argument = (ipcarg_t) (value); \ 96 IPC_SET_ARG2(*answer, argument); \ 97 } while (0) 89 98 90 99 /** Returns the network mask message parameter. 91 * 100 * @param[in] call The message call structure. 92 101 */ 93 102 #define IP_GET_NETMASK(call) \ 94 ({in_addr_t addr; addr.s_addr = IPC_GET_ARG4(*call); addr;}) 103 ({ \ 104 in_addr_t addr; \ 105 addr.s_addr = IPC_GET_ARG4(*call); \ 106 addr; \ 107 }) 95 108 96 109 /** Returns the protocol message parameter. 97 * 110 * @param[in] call The message call structure. 98 111 */ 99 112 #define IP_GET_PROTOCOL(call) \ 100 ({ip_protocol_t protocol = (ip_protocol_t) IPC_GET_ARG1(*call); protocol;}) 113 ({ \ 114 ip_protocol_t protocol = (ip_protocol_t) IPC_GET_ARG1(*call); \ 115 protocol; \ 116 }) 101 117 102 118 /*@}*/ -
uspace/lib/c/include/ipc/net_net.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net30 * 29 /** @addtogroup libc 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * Networking subsystem central module messages. 35 * @see net_interface.h 36 36 */ 37 37 38 #ifndef __NET_NET_MESSAGES_H__39 #define __NET_NET_MESSAGES_H__38 #ifndef LIBC_NET_NET_MESSAGES_H_ 39 #define LIBC_NET_NET_MESSAGES_H_ 40 40 41 41 #include <ipc/ipc.h> 42 42 #include <ipc/net.h> 43 43 44 /** Networking subsystem central module messages. 45 */ 46 typedef enum{ 44 /** Networking subsystem central module messages. */ 45 typedef enum { 47 46 /** Returns the general configuration 48 * 47 * @see net_get_conf_req() 49 48 */ 50 49 NET_NET_GET_CONF = NET_FIRST, 51 50 /** Returns the device specific configuration 52 * 51 * @see net_get_device_conf_req() 53 52 */ 54 53 NET_NET_GET_DEVICE_CONF, 55 /** Starts the networking stack. 56 */ 54 /** Starts the networking stack. */ 57 55 NET_NET_STARTUP, 58 56 } net_messages; -
uspace/lib/c/include/ipc/netif.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup netif29 /** @addtogroup libc 30 30 * @{ 31 31 */ … … 35 35 */ 36 36 37 #ifndef __NET_NETIF_MESSAGES_H__38 #define __NET_NETIF_MESSAGES_H__37 #ifndef LIBC_NETIF_MESSAGES_H_ 38 #define LIBC_NETIF_MESSAGES_H_ 39 39 40 40 #include <ipc/ipc.h> 41 41 #include <ipc/net.h> 42 42 43 /** Network interface common module messages. 44 */ 43 /** Network interface common module messages. */ 45 44 typedef enum { 46 45 /** Probe device message. 47 * 46 * @see netif_probe_req() 48 47 */ 49 48 NET_NETIF_PROBE = NET_NETIF_FIRST, 50 49 /** Send packet message. 51 * 50 * @see netif_send_msg() 52 51 */ 53 52 NET_NETIF_SEND, 54 53 /** Start device message. 55 * 54 * @see netif_start_req() 56 55 */ 57 56 NET_NETIF_START, 58 57 /** Get device usage statistics message. 59 * 58 * @see netif_stats_req() 60 59 */ 61 60 NET_NETIF_STATS, 62 61 /** Stop device message. 63 * 62 * @see netif_stop_req() 64 63 */ 65 64 NET_NETIF_STOP, 66 65 /** Get device address message. 67 * 66 * @see netif_get_addr_req() 68 67 */ 69 68 NET_NETIF_GET_ADDR, 70 69 } netif_messages; 71 70 72 /** @name Network interface specific message parameters definitions 73 */ 71 /** @name Network interface specific message parameters definitions */ 74 72 /*@{*/ 75 73 … … 78 76 */ 79 77 #define NETIF_GET_IRQ(call) \ 80 ({int irq = (int) IPC_GET_ARG2(*call); irq;}) 78 ({ \ 79 int irq = (int) IPC_GET_ARG2(*call); \ 80 irq; \ 81 }) 81 82 82 83 /** Return the input/output address message parameter. … … 84 85 */ 85 86 #define NETIF_GET_IO(call) \ 86 ({int io = (int) IPC_GET_ARG3(*call); io;}) 87 ({ \ 88 int io = (int) IPC_GET_ARG3(*call); \ 89 io; \ 90 }) 87 91 88 92 /*@}*/ -
uspace/lib/c/include/ipc/nil.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net_nil29 /** @addtogroup libc 30 30 * @{ 31 31 */ … … 35 35 */ 36 36 37 #ifndef __NET_NIL_MESSAGES_H__38 #define __NET_NIL_MESSAGES_H__37 #ifndef LIBC_NIL_MESSAGES_H_ 38 #define LIBC_NIL_MESSAGES_H_ 39 39 40 40 #include <ipc/ipc.h> 41 41 #include <ipc/net.h> 42 42 43 /** Network interface layer module messages. 44 */ 43 /** Network interface layer module messages. */ 45 44 typedef enum { 46 45 /** New device or update MTU message. 47 * 46 * @see nil_device_req() 48 47 */ 49 48 NET_NIL_DEVICE = NET_NIL_FIRST, 50 49 /** New device state message. 51 * 50 * @see nil_device_state_msg() 52 51 */ 53 52 NET_NIL_DEVICE_STATE, 54 53 /** Received packet queue message. 55 * 54 * @see nil_received_msg() 56 55 */ 57 56 NET_NIL_RECEIVED, 58 57 /** Send packet queue message. 59 * 58 * @see nil_send_msg() 60 59 */ 61 60 NET_NIL_SEND, 62 61 /** Packet size message. 63 * 62 * @see nil_packet_size_req() 64 63 */ 65 64 NET_NIL_PACKET_SPACE, 66 65 /** Device local hardware address message. 67 * 66 * @see nil_get_addr() 68 67 */ 69 68 NET_NIL_ADDR, 70 69 /** Device broadcast hardware address message. 71 * 70 * @see nil_get_broadcast_addr() 72 71 */ 73 72 NET_NIL_BROADCAST_ADDR, 74 73 } nil_messages; 75 74 76 /** @name Network interface layer specific message parameters definitions 77 */ 75 /** @name Network interface layer specific message parameters definitions */ 78 76 /*@{*/ 79 77 80 /** Return the protocol service message parameter. 81 */ 78 /** Return the protocol service message parameter. */ 82 79 #define NIL_GET_PROTO(call) \ 83 ({services_t service = (services_t) IPC_GET_ARG2(*call); service;}) 80 ({ \ 81 services_t service = (services_t) IPC_GET_ARG2(*call); \ 82 service; \ 83 }) 84 84 85 85 /*@}*/ -
uspace/lib/c/include/ipc/tl.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net_tl30 * 29 /** @addtogroup libc 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * Transport layer modules messages. 35 * @see tl_interface.h 36 36 */ 37 37 38 #ifndef __NET_TL_MESSAGES_H__39 #define __NET_TL_MESSAGES_H__38 #ifndef LIBC_TL_MESSAGES_H_ 39 #define LIBC_TL_MESSAGES_H_ 40 40 41 41 #include <ipc/ipc.h> 42 42 #include <ipc/net.h> 43 43 44 /** Transport layer modules messages. 45 */ 46 typedef enum{ 44 /** Transport layer modules messages. */ 45 typedef enum { 47 46 /** Packet received message. 48 * 47 * @see tl_received_msg() 49 48 */ 50 49 NET_TL_RECEIVED = NET_TL_FIRST -
uspace/lib/c/include/net/icmp_api.h
ref689ef0 ra7a85d16 44 44 45 45 #include <adt/measured_strings.h> 46 #include <net/packet.h>47 46 #include <net/ip_codes.h> 48 47 #include <net/icmp_codes.h> -
uspace/lib/net/adt/module_map.c
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * Character string to module map implementation. 35 35 */ 36 36 … … 49 49 GENERIC_CHAR_MAP_IMPLEMENT(modules, module_t) 50 50 51 int add_module(module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id, connect_module_t connect_module){ 51 /** Adds module to the module map. 52 * 53 * @param[out] module The module structure added. 54 * @param[in] modules The module map. 55 * @param[in] name The module name. 56 * @param[in] filename The full path filename. 57 * @param[in] service The module service. 58 * @param[in] task_id The module current task identifier. Zero means not 59 * running. 60 * @param[in] connect_module The module connecting function. 61 * @returns EOK on success. 62 * @returns ENOMEM if there is not enough memory left. 63 */ 64 int 65 add_module(module_ref *module, modules_ref modules, const char *name, 66 const char *filename, services_t service, task_id_t task_id, 67 connect_module_t connect_module) 68 { 52 69 ERROR_DECLARE; 53 70 … … 55 72 56 73 tmp_module = (module_ref) malloc(sizeof(module_t)); 57 if (! tmp_module){74 if (!tmp_module) 58 75 return ENOMEM; 59 } 76 60 77 tmp_module->task_id = task_id; 61 78 tmp_module->phone = 0; … … 65 82 tmp_module->service = service; 66 83 tmp_module->connect_module = connect_module; 67 if(ERROR_OCCURRED(modules_add(modules, tmp_module->name, 0, tmp_module))){ 84 85 if (ERROR_OCCURRED(modules_add(modules, tmp_module->name, 0, 86 tmp_module))) { 68 87 free(tmp_module); 69 88 return ERROR_CODE; 70 89 } 71 if (module){90 if (module) 72 91 *module = tmp_module; 73 } 92 74 93 return EOK; 75 94 } 76 95 77 module_ref get_running_module(modules_ref modules, char * name){ 96 /** Searches and returns the specified module. 97 * 98 * If the module is not running, the module filaname is spawned. 99 * If the module is not connected, the connect_function is called. 100 * 101 * @param[in] modules The module map. 102 * @param[in] name The module name. 103 * @returns The running module found. It does not have to be 104 * connected. 105 * @returns NULL if there is no such module. 106 */ 107 module_ref get_running_module(modules_ref modules, char *name) 108 { 78 109 module_ref module; 79 110 80 111 module = modules_find(modules, name, 0); 81 if (! module){112 if (!module) 82 113 return NULL; 114 115 if (!module->task_id) { 116 module->task_id = spawn(module->filename); 117 if (!module->task_id) 118 return NULL; 83 119 } 84 if(! module->task_id){ 85 module->task_id = spawn(module->filename); 86 if(! module->task_id){ 87 return NULL; 88 } 89 } 90 if(! module->phone){ 120 if (!module->phone) 91 121 module->phone = module->connect_module(module->service); 92 } 122 93 123 return module; 94 124 } 95 125 126 /** Starts the given module. 127 * 128 * @param[in] fname The module full or relative path filename. 129 * @returns The new module task identifier on success. 130 * @returns Zero if there is no such module. 131 */ 96 132 task_id_t spawn(const char *fname) 97 133 { -
uspace/lib/net/generic/generic.c
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net29 /** @addtogroup libnet 30 30 * @{ 31 31 */ -
uspace/lib/net/generic/net_checksum.c
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * General CRC and checksum computation implementation. 35 35 */ 36 36 … … 39 39 #include <net_checksum.h> 40 40 41 /** Big-endian encoding CRC divider. 42 */ 43 #define CRC_DIVIDER_BE 0x04C11DB7 44 45 /** Little-endian encoding CRC divider. 46 */ 47 #define CRC_DIVIDER_LE 0xEDB88320 48 49 uint16_t compact_checksum(uint32_t sum){ 41 /** Big-endian encoding CRC divider. */ 42 #define CRC_DIVIDER_BE 0x04c11db7 43 44 /** Little-endian encoding CRC divider. */ 45 #define CRC_DIVIDER_LE 0xedb88320 46 47 /** Compacts the computed checksum to the 16 bit number adding the carries. 48 * 49 * @param[in] sum Computed checksum. 50 * @returns Compacted computed checksum to the 16 bits. 51 */ 52 uint16_t compact_checksum(uint32_t sum) 53 { 50 54 // shorten to the 16 bits 51 while(sum >> 16){ 52 sum = (sum &0xFFFF) + (sum >> 16); 53 } 55 while (sum >> 16) 56 sum = (sum & 0xffff) + (sum >> 16); 54 57 55 58 return (uint16_t) sum; 56 59 } 57 60 58 uint32_t compute_checksum(uint32_t seed, uint8_t * data, size_t length){ 61 /** Computes sum of the 2 byte fields. 62 * 63 * Padds one zero (0) byte if odd. 64 * 65 * @param[in] seed Initial value. Often used as 0 or ~0. 66 * @param[in] data Pointer to the beginning of data to process. 67 * @param[in] length Length of the data in bytes. 68 * @returns The computed checksum of the length bytes of the data. 69 */ 70 uint32_t compute_checksum(uint32_t seed, uint8_t *data, size_t length) 71 { 59 72 size_t index; 60 73 61 74 // sum all the 16 bit fields 62 for (index = 0; index + 1 < length; index += 2){75 for (index = 0; index + 1 < length; index += 2) 63 76 seed += (data[index] << 8) + data[index + 1]; 64 }65 77 66 78 // last odd byte with zero padding 67 if (index + 1 == length){79 if (index + 1 == length) 68 80 seed += data[index] << 8; 69 }70 81 71 82 return seed; 72 83 } 73 84 74 uint32_t compute_crc32_be(uint32_t seed, uint8_t * data, size_t length){ 85 /** Computes CRC32 value in the big-endian environment. 86 * 87 * @param[in] seed Initial value. Often used as 0 or ~0. 88 * @param[in] data Pointer to the beginning of data to process. 89 * @param[in] length Length of the data in bits. 90 * @returns The computed CRC32 of the length bits of the data. 91 */ 92 uint32_t compute_crc32_be(uint32_t seed, uint8_t * data, size_t length) 93 { 75 94 size_t index; 76 95 77 96 // process full bytes 78 while (length >= 8){97 while (length >= 8) { 79 98 // add the data 80 99 seed ^= (*data) << 24; 100 81 101 // for each added bit 82 for (index = 0; index < 8; ++ index){102 for (index = 0; index < 8; ++index) { 83 103 // if the first bit is set 84 if (seed &0x80000000){104 if (seed & 0x80000000) { 85 105 // shift and divide the checksum 86 106 seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE); 87 } else{107 } else { 88 108 // shift otherwise 89 109 seed <<= 1; 90 110 } 91 111 } 112 92 113 // move to the next byte 93 ++ 114 ++data; 94 115 length -= 8; 95 116 } 96 117 97 118 // process the odd bits 98 if (length > 0){119 if (length > 0) { 99 120 // add the data with zero padding 100 seed ^= ((*data) &(0xFF << (8 - length))) << 24; 121 seed ^= ((*data) & (0xff << (8 - length))) << 24; 122 101 123 // for each added bit 102 for (index = 0; index < length; ++ index){124 for (index = 0; index < length; ++index) { 103 125 // if the first bit is set 104 if (seed &0x80000000){126 if (seed & 0x80000000) { 105 127 // shift and divide the checksum 106 128 seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE); 107 } else{129 } else { 108 130 // shift otherwise 109 131 seed <<= 1; … … 115 137 } 116 138 117 uint32_t compute_crc32_le(uint32_t seed, uint8_t * data, size_t length){ 139 /** Computes CRC32 value in the little-endian environment. 140 * 141 * @param[in] seed Initial value. Often used as 0 or ~0. 142 * @param[in] data Pointer to the beginning of data to process. 143 * @param[in] length Length of the data in bits. 144 * @returns The computed CRC32 of the length bits of the data. 145 */ 146 uint32_t compute_crc32_le(uint32_t seed, uint8_t * data, size_t length) 147 { 118 148 size_t index; 119 149 120 150 // process full bytes 121 while (length >= 8){151 while (length >= 8) { 122 152 // add the data 123 153 seed ^= (*data); 154 124 155 // for each added bit 125 for (index = 0; index < 8; ++ index){156 for (index = 0; index < 8; ++index) { 126 157 // if the last bit is set 127 if (seed &1){158 if (seed & 1) { 128 159 // shift and divide the checksum 129 160 seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE); 130 } else{161 } else { 131 162 // shift otherwise 132 163 seed >>= 1; 133 164 } 134 165 } 166 135 167 // move to the next byte 136 ++ 168 ++data; 137 169 length -= 8; 138 170 } 139 171 140 172 // process the odd bits 141 if (length > 0){173 if (length > 0) { 142 174 // add the data with zero padding 143 175 seed ^= (*data) >> (8 - length); 144 for(index = 0; index < length; ++ index){ 176 177 for (index = 0; index < length; ++index) { 145 178 // if the last bit is set 146 if (seed &1){179 if (seed & 1) { 147 180 // shift and divide the checksum 148 181 seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE); 149 } else{182 } else { 150 183 // shift otherwise 151 184 seed >>= 1; … … 157 190 } 158 191 159 uint16_t flip_checksum(uint16_t checksum){ 192 /** Returns or flips the checksum if zero. 193 * 194 * @param[in] checksum The computed checksum. 195 * @returns The internet protocol header checksum. 196 * @returns 0xFFFF if the computed checksum is zero. 197 */ 198 uint16_t flip_checksum(uint16_t checksum) 199 { 160 200 // flip, zero is returned as 0xFFFF (not flipped) 161 checksum = ~ 201 checksum = ~checksum; 162 202 return checksum ? checksum : IP_CHECKSUM_ZERO; 163 203 } 164 204 165 uint16_t ip_checksum(uint8_t * data, size_t length){ 205 /** Computes the ip header checksum. 206 * 207 * To compute the checksum of a new packet, the checksum header field must be 208 * zero. To check the checksum of a received packet, the checksum may be left 209 * set. Zero will be returned in this case if valid. 210 * 211 * @param[in] data The header data. 212 * @param[in] length The header length in bytes. 213 * @returns The internet protocol header checksum. 214 * @returns 0xFFFF if the computed checksum is zero. 215 */ 216 uint16_t ip_checksum(uint8_t *data, size_t length) 217 { 166 218 // compute, compact and flip the data checksum 167 return flip_checksum(compact_checksum(compute_checksum(0, data, length))); 219 return flip_checksum(compact_checksum(compute_checksum(0, data, 220 length))); 168 221 } 169 222 -
uspace/lib/net/generic/net_remote.c
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * Networking interface implementation for remote modules. 35 * @see net_interface.h 36 36 */ 37 37 38 38 #include <ipc/services.h> 39 #include <ipc/net_net.h> 39 40 40 41 #include <malloc.h> … … 45 46 #include <net_interface.h> 46 47 #include <adt/measured_strings.h> 47 #include <net_net_messages.h>48 48 49 int net_connect_module(services_t service) 49 /** Connects to the networking module. 50 * 51 * @returns The networking module phone on success. 52 */ 53 int net_connect_module(void) 50 54 { 51 55 return connect_to_service(SERVICE_NETWORKING); 52 56 } 53 57 54 void net_free_settings(measured_string_ref settings, char * data) 58 /** Frees the received settings. 59 * 60 * @param[in] settings The received settings. 61 * @param[in] data The received settings data. 62 * @see net_get_device_conf_req() 63 * @see net_get_conf_req() 64 */ 65 void net_free_settings(measured_string_ref settings, char *data) 55 66 { 56 67 if (settings) 57 68 free(settings); 58 59 69 if (data) 60 70 free(data); 61 71 } 62 72 73 /** Returns the global configuration. 74 * 75 * The configuration names are read and the appropriate settings are set 76 * instead. Call net_free_settings() function to release the returned 77 * configuration. 78 * 79 * @param[in] net_phone The networking module phone. 80 * @param[in,out] configuration The requested configuration. The names are read 81 * and the appropriate settings are set instead. 82 * 83 * @param[in] count The configuration entries count. 84 * @param[in,out] data The configuration and settings data. 85 * @returns EOK on success. 86 * @returns EINVAL if the configuration is NULL. 87 * @returns EINVAL if the count is zero. 88 * @returns Other error codes as defined for the 89 * generic_translate_req() function. 90 */ 63 91 int 64 net_get_conf_req(int net_phone, measured_string_ref * 65 size_t count, char ** 92 net_get_conf_req(int net_phone, measured_string_ref *configuration, 93 size_t count, char **data) 66 94 { 67 95 return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, 0, 0, … … 69 97 } 70 98 99 /** Returns the device specific configuration. 100 * 101 * Returns the global configuration if the device specific is not found. 102 * The configuration names are read and the appropriate settings are set 103 * instead. Call net_free_settings() function to release the returned 104 * configuration. 105 * 106 * @param[in] net_phone The networking module phone. 107 * @param[in] device_id The device identifier. 108 * @param[in,out] configuration The requested device configuration. The names 109 * are read and the appropriate settings are set instead. 110 * @param[in] count The configuration entries count. 111 * @param[in,out] data The configuration and settings data. 112 * @returns EOK on success. 113 * @returns EINVAL if the configuration is NULL. 114 * @returns EINVAL if the count is zero. 115 * @returns Other error codes as defined for the 116 * generic_translate_req() function. 117 */ 71 118 int 72 119 net_get_device_conf_req(int net_phone, device_id_t device_id, 73 measured_string_ref * configuration, size_t count, char **data)120 measured_string_ref *configuration, size_t count, char **data) 74 121 { 75 122 return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, -
uspace/lib/net/generic/packet_client.c
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup packet30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * Packet client implementation. 35 35 */ 36 36 … … 38 38 #include <mem.h> 39 39 #include <unistd.h> 40 41 40 #include <sys/mman.h> 42 41 43 42 #include <packet_client.h> 43 #include <packet_remote.h> 44 44 45 45 #include <net/packet.h> 46 46 #include <net/packet_header.h> 47 47 48 int packet_copy_data(packet_t packet, const void * data, size_t length) 48 /** Copies the specified data to the beginning of the actual packet content. 49 * 50 * Pushes the content end if needed. 51 * 52 * @param[in] packet The packet to be filled. 53 * @param[in] data The data to be copied. 54 * @param[in] length The length of the copied data. 55 * @returns EOK on success. 56 * @returns EINVAL if the packet is not valid. 57 * @returns ENOMEM if there is not enough memory left. 58 */ 59 int packet_copy_data(packet_t packet, const void *data, size_t length) 49 60 { 50 61 if (!packet_is_valid(packet)) … … 61 72 } 62 73 74 /** Allocates the specified space right before the actual packet content and 75 * returns its pointer. 76 * 77 * @param[in] packet The packet to be used. 78 * @param[in] length The space length to be allocated at the beginning of the 79 * packet content. 80 * @returns The pointer to the allocated memory. 81 * @returns NULL if there is not enough memory left. 82 */ 63 83 void *packet_prefix(packet_t packet, size_t length) 64 84 { … … 73 93 } 74 94 95 /** Allocates the specified space right after the actual packet content and 96 * returns its pointer. 97 * 98 * @param[in] packet The packet to be used. 99 * @param[in] length The space length to be allocated at the end of the 100 * packet content. 101 * @returns The pointer to the allocated memory. 102 * @returns NULL if there is not enough memory left. 103 */ 75 104 void *packet_suffix(packet_t packet, size_t length) 76 105 { … … 84 113 } 85 114 115 /** Trims the actual packet content by the specified prefix and suffix lengths. 116 * 117 * @param[in] packet The packet to be trimmed. 118 * @param[in] prefix The prefix length to be removed from the beginning of 119 * the packet content. 120 * @param[in] suffix The suffix length to be removed from the end of the 121 * packet content. 122 * @returns EOK on success. 123 * @returns EINVAL if the packet is not valid. 124 * @returns ENOMEM if there is not enough memory left. 125 */ 86 126 int packet_trim(packet_t packet, size_t prefix, size_t suffix) 87 127 { … … 97 137 } 98 138 139 /** Returns the packet identifier. 140 * 141 * @param[in] packet The packet. 142 * @returns The packet identifier. 143 * @returns Zero if the packet is not valid. 144 */ 99 145 packet_id_t packet_get_id(const packet_t packet) 100 146 { … … 102 148 } 103 149 104 int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest) 150 /** Returns the stored packet addresses and their length. 151 * 152 * @param[in] packet The packet. 153 * @param[out] src The source address. May be NULL if not desired. 154 * @param[out] dest The destination address. May be NULL if not desired. 155 * @returns The stored addresses length. 156 * @returns Zero if the addresses are not present. 157 * @returns EINVAL if the packet is not valid. 158 */ 159 int packet_get_addr(const packet_t packet, uint8_t **src, uint8_t **dest) 105 160 { 106 161 if (!packet_is_valid(packet)) … … 116 171 } 117 172 173 /** Returns the packet content length. 174 * 175 * @param[in] packet The packet. 176 * @returns The packet content length in bytes. 177 * @returns Zero if the packet is not valid. 178 */ 118 179 size_t packet_get_data_length(const packet_t packet) 119 180 { … … 124 185 } 125 186 187 /** Returns the pointer to the beginning of the packet content. 188 * 189 * @param[in] packet The packet. 190 * @returns The pointer to the beginning of the packet content. 191 * @returns NULL if the packet is not valid. 192 */ 126 193 void *packet_get_data(const packet_t packet) 127 194 { … … 132 199 } 133 200 201 /** Sets the packet addresses. 202 * 203 * @param[in] packet The packet. 204 * @param[in] src The new source address. May be NULL. 205 * @param[in] dest The new destination address. May be NULL. 206 * @param[in] addr_len The addresses length. 207 * @returns EOK on success. 208 * @returns EINVAL if the packet is not valid. 209 * @returns ENOMEM if there is not enough memory left. 210 */ 134 211 int 135 packet_set_addr(packet_t packet, const uint8_t * src, const uint8_t *dest,212 packet_set_addr(packet_t packet, const uint8_t *src, const uint8_t *dest, 136 213 size_t addr_len) 137 214 { … … 170 247 } 171 248 249 /** Returns the packet copy. 250 * 251 * Copies the addresses, data, order and metric values. 252 * Does not copy the queue placement. 253 * 254 * @param[in] phone The packet server module phone. 255 * @param[in] packet The original packet. 256 * @returns The packet copy. 257 * @returns NULL on error. 258 */ 172 259 packet_t packet_get_copy(int phone, packet_t packet) 173 260 { -
uspace/lib/net/generic/packet_remote.c
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup packet30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * Packet client interface implementation for remote modules. 35 * @see packet_client.h 36 36 */ 37 37 … … 86 86 } 87 87 88 /** Translates the packet identifier to the packet reference. 89 * 90 * Tries to find mapping first. 91 * Contacts the packet server to share the packet if the mapping is not present. 92 * 93 * @param[in] phone The packet server module phone. 94 * @param[out] packet The packet reference. 95 * @param[in] packet_id The packet identifier. 96 * @returns EOK on success. 97 * @returns EINVAL if the packet parameter is NULL. 98 * @returns Other error codes as defined for the NET_PACKET_GET_SIZE 99 * message. 100 * @returns Other error codes as defined for the packet_return() 101 * function. 102 */ 88 103 int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id) 89 104 { … … 110 125 } 111 126 127 /** Obtains the packet of the given dimensions. 128 * 129 * Contacts the packet server to return the appropriate packet. 130 * 131 * @param[in] phone The packet server module phone. 132 * @param[in] addr_len The source and destination addresses maximal length in 133 * bytes. 134 * @param[in] max_prefix The maximal prefix length in bytes. 135 * @param[in] max_content The maximal content length in bytes. 136 * @param[in] max_suffix The maximal suffix length in bytes. 137 * @returns The packet reference. 138 * @returns NULL on error. 139 */ 112 140 packet_t packet_get_4_remote(int phone, size_t max_content, size_t addr_len, 113 141 size_t max_prefix, size_t max_suffix) … … 133 161 } 134 162 163 /** Obtains the packet of the given content size. 164 * 165 * Contacts the packet server to return the appropriate packet. 166 * 167 * @param[in] phone The packet server module phone. 168 * @param[in] content The maximal content length in bytes. 169 * @returns The packet reference. 170 * @returns NULL on error. 171 */ 135 172 packet_t packet_get_1_remote(int phone, size_t content) 136 173 { … … 154 191 } 155 192 193 /** Releases the packet queue. 194 * 195 * All packets in the queue are marked as free for use. 196 * The packet queue may be one packet only. 197 * The module should not use the packets after this point until they are 198 * received or obtained again. 199 * 200 * @param[in] phone The packet server module phone. 201 * @param[in] packet_id The packet identifier. 202 */ 156 203 void pq_release_remote(int phone, packet_id_t packet_id) 157 204 { -
uspace/lib/net/generic/socket_core.c
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup socket30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Socket common core implementation. 35 */ 34 * Socket common core implementation. 35 */ 36 37 #include <socket_core.h> 38 #include <packet_client.h> 39 #include <packet_remote.h> 36 40 37 41 #include <net/socket_codes.h> 38 42 #include <net/in.h> 39 43 #include <net/inet.h> 44 #include <net/packet.h> 45 #include <net/modules.h> 40 46 41 47 #include <stdint.h> … … 46 52 #include <adt/dynamic_fifo.h> 47 53 #include <adt/int_map.h> 48 #include <net/packet.h> 49 #include <packet_client.h> 50 #include <packet_remote.h> 51 #include <net/modules.h> 52 #include <socket_core.h> 53 54 /** Maximum number of random attempts to find a new socket identifier before switching to the sequence. 55 */ 56 #define SOCKET_ID_TRIES 100 57 58 /** Bound port sockets. 59 */ 60 struct socket_port{ 61 /** The bound sockets map. 62 */ 54 55 /** 56 * Maximum number of random attempts to find a new socket identifier before 57 * switching to the sequence. 58 */ 59 #define SOCKET_ID_TRIES 100 60 61 /** Bound port sockets.*/ 62 struct socket_port { 63 /** The bound sockets map. */ 63 64 socket_port_map_t map; 64 /** The bound sockets count. 65 */ 65 /** The bound sockets count. */ 66 66 int count; 67 67 }; … … 74 74 75 75 /** Destroys the socket. 76 * If the socket is bound, the port is released. 77 * Releases all buffered packets, calls the release function and removes the socket from the local sockets. 78 * @param[in] packet_phone The packet server phone to release buffered packets. 79 * @param[in] socket The socket to be destroyed. 80 * @param[in,out] local_sockets The local sockets to be updated. 81 * @param[in,out] global_sockets The global sockets to be updated. 82 * @param[in] socket_release The client release callback function. 83 */ 84 static void socket_destroy_core(int packet_phone, socket_core_ref socket, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket)){ 76 * 77 * If the socket is bound, the port is released. 78 * Releases all buffered packets, calls the release function and removes the 79 * socket from the local sockets. 80 * 81 * @param[in] packet_phone The packet server phone to release buffered packets. 82 * @param[in] socket The socket to be destroyed. 83 * @param[in,out] local_sockets The local sockets to be updated. 84 * @param[in,out] global_sockets The global sockets to be updated. 85 * @param[in] socket_release The client release callback function. 86 */ 87 static void 88 socket_destroy_core(int packet_phone, socket_core_ref socket, 89 socket_cores_ref local_sockets, socket_ports_ref global_sockets, 90 void (* socket_release)(socket_core_ref socket)) 91 { 85 92 int packet_id; 86 93 87 94 // if bound 88 if (socket->port){95 if (socket->port) { 89 96 // release the port 90 97 socket_port_release(global_sockets, socket); 91 98 } 99 92 100 // release all received packets 93 while ((packet_id = dyn_fifo_pop(&socket->received)) >= 0){101 while ((packet_id = dyn_fifo_pop(&socket->received)) >= 0) 94 102 pq_release_remote(packet_phone, packet_id); 95 } 103 96 104 dyn_fifo_destroy(&socket->received); 97 105 dyn_fifo_destroy(&socket->accepted); 98 if(socket_release){ 106 107 if (socket_release) 99 108 socket_release(socket); 100 } 109 101 110 socket_cores_exclude(local_sockets, socket->socket_id); 102 111 } 103 112 104 void socket_cores_release(int packet_phone, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket)){ 105 if(socket_cores_is_valid(local_sockets)){ 106 int index; 107 108 local_sockets->magic = 0; 109 for(index = 0; index < local_sockets->next; ++ index){ 110 if(socket_cores_item_is_valid(&(local_sockets->items[index]))){ 111 local_sockets->items[index].magic = 0; 112 if(local_sockets->items[index].value){ 113 socket_destroy_core(packet_phone, local_sockets->items[index].value, local_sockets, global_sockets, socket_release); 114 free(local_sockets->items[index].value); 115 local_sockets->items[index].value = NULL; 116 } 113 /** Destroys local sockets. 114 * 115 * Releases all buffered packets and calls the release function for each of the 116 * sockets. 117 * 118 * @param[in] packet_phone The packet server phone to release buffered packets. 119 * @param[in] local_sockets The local sockets to be destroyed. 120 * @param[in,out] global_sockets The global sockets to be updated. 121 * @param[in] socket_release The client release callback function. 122 */ 123 void 124 socket_cores_release(int packet_phone, socket_cores_ref local_sockets, 125 socket_ports_ref global_sockets, 126 void (* socket_release)(socket_core_ref socket)) 127 { 128 int index; 129 130 if (!socket_cores_is_valid(local_sockets)) 131 return; 132 133 local_sockets->magic = 0; 134 135 for (index = 0; index < local_sockets->next; ++index) { 136 if (socket_cores_item_is_valid(&local_sockets->items[index])) { 137 local_sockets->items[index].magic = 0; 138 139 if (local_sockets->items[index].value) { 140 socket_destroy_core(packet_phone, 141 local_sockets->items[index].value, 142 local_sockets, global_sockets, 143 socket_release); 144 free(local_sockets->items[index].value); 145 local_sockets->items[index].value = NULL; 117 146 } 118 147 } 119 free(local_sockets->items); 120 } 148 } 149 150 free(local_sockets->items); 121 151 } 122 152 123 153 /** Adds the socket to a socket port. 124 * @param[in,out] socket_port The socket port structure. 125 * @param[in] socket The socket to be added. 126 * @param[in] key The socket key identifier. 127 * @param[in] key_length The socket key length. 128 * @returns EOK on success. 129 * @returns ENOMEM if there is not enough memory left. 130 */ 131 static int socket_port_add_core(socket_port_ref socket_port, socket_core_ref socket, const char * key, size_t key_length){ 154 * 155 * @param[in,out] socket_port The socket port structure. 156 * @param[in] socket The socket to be added. 157 * @param[in] key The socket key identifier. 158 * @param[in] key_length The socket key length. 159 * @returns EOK on success. 160 * @returns ENOMEM if there is not enough memory left. 161 */ 162 static int 163 socket_port_add_core(socket_port_ref socket_port, socket_core_ref socket, 164 const char *key, size_t key_length) 165 { 132 166 ERROR_DECLARE; 133 167 134 socket_core_ref * 168 socket_core_ref *socket_ref; 135 169 136 170 // create a wrapper 137 171 socket_ref = malloc(sizeof(*socket_ref)); 138 if (! socket_ref){172 if (!socket_ref) 139 173 return ENOMEM; 140 } 174 141 175 *socket_ref = socket; 142 176 // add the wrapper 143 if(ERROR_OCCURRED(socket_port_map_add(&socket_port->map, key, key_length, socket_ref))){ 177 if (ERROR_OCCURRED(socket_port_map_add(&socket_port->map, key, 178 key_length, socket_ref))) { 144 179 free(socket_ref); 145 180 return ERROR_CODE; 146 181 } 147 ++ socket_port->count; 182 183 ++socket_port->count; 148 184 socket->key = key; 149 185 socket->key_length = key_length; 186 150 187 return EOK; 151 188 } 152 189 153 190 /** Binds the socket to the port. 154 * The SOCKET_MAP_KEY_LISTENING key identifier is used. 155 * @param[in] global_sockets The global sockets to be updated. 156 * @param[in] socket The socket to be added. 157 * @param[in] port The port number to be bound to. 158 * @returns EOK on success. 159 * @returns ENOMEM if there is not enough memory left. 160 * @returns Other error codes as defined for the socket_ports_add() function. 161 */ 162 static int socket_bind_insert(socket_ports_ref global_sockets, socket_core_ref socket, int port){ 191 * 192 * The SOCKET_MAP_KEY_LISTENING key identifier is used. 193 * 194 * @param[in] global_sockets The global sockets to be updated. 195 * @param[in] socket The socket to be added. 196 * @param[in] port The port number to be bound to. 197 * @returns EOK on success. 198 * @returns ENOMEM if there is not enough memory left. 199 * @returns Other error codes as defined for the 200 * socket_ports_add() function. 201 */ 202 static int 203 socket_bind_insert(socket_ports_ref global_sockets, socket_core_ref socket, 204 int port) 205 { 163 206 ERROR_DECLARE; 164 207 … … 167 210 // create a wrapper 168 211 socket_port = malloc(sizeof(*socket_port)); 169 if (! socket_port){212 if (!socket_port) 170 213 return ENOMEM; 171 } 214 172 215 socket_port->count = 0; 173 if(ERROR_OCCURRED(socket_port_map_initialize(&socket_port->map)) 174 || ERROR_OCCURRED(socket_port_add_core(socket_port, socket, SOCKET_MAP_KEY_LISTENING, 0))){ 216 if (ERROR_OCCURRED(socket_port_map_initialize(&socket_port->map)) || 217 ERROR_OCCURRED(socket_port_add_core(socket_port, socket, 218 SOCKET_MAP_KEY_LISTENING, 0))) { 175 219 socket_port_map_destroy(&socket_port->map); 176 220 free(socket_port); 177 221 return ERROR_CODE; 178 222 } 223 179 224 // register the incomming port 180 225 ERROR_CODE = socket_ports_add(global_sockets, port, socket_port); 181 if (ERROR_CODE < 0){226 if (ERROR_CODE < 0) { 182 227 socket_port_map_destroy(&socket_port->map); 183 228 free(socket_port); 184 229 return ERROR_CODE; 185 230 } 231 186 232 socket->port = port; 187 233 return EOK; 188 234 } 189 235 190 int socket_bind(socket_cores_ref local_sockets, socket_ports_ref global_sockets, int socket_id, void * addr, size_t addrlen, int free_ports_start, int free_ports_end, int last_used_port){ 236 /** Binds the socket to the port. 237 * 238 * The address port is used if set, a free port is used if not. 239 * 240 * @param[in] local_sockets The local sockets to be searched. 241 * @param[in,out] global_sockets The global sockets to be updated. 242 * @param[in] socket_id The new socket identifier. 243 * @param[in] addr The address to be bound to. 244 * @param[in] addrlen The address length. 245 * @param[in] free_ports_start The minimum free port. 246 * @param[in] free_ports_end The maximum free port. 247 * @param[in] last_used_port The last used free port. 248 * @returns EOK on success. 249 * @returns ENOTSOCK if the socket was not found. 250 * @returns EAFNOSUPPORT if the address family is not supported. 251 * @returns EADDRINUSE if the port is already in use. 252 * @returns Other error codes as defined for the 253 * socket_bind_free_port() function. 254 * @returns Other error codes as defined for the 255 * socket_bind_insert() function. 256 */ 257 int 258 socket_bind(socket_cores_ref local_sockets, socket_ports_ref global_sockets, 259 int socket_id, void *addr, size_t addrlen, int free_ports_start, 260 int free_ports_end, int last_used_port) 261 { 191 262 socket_core_ref socket; 192 263 socket_port_ref socket_port; 193 struct sockaddr * 194 struct sockaddr_in * 195 196 if (addrlen < sizeof(struct sockaddr)){264 struct sockaddr *address; 265 struct sockaddr_in *address_in; 266 267 if (addrlen < sizeof(struct sockaddr)) 197 268 return EINVAL; 198 } 269 199 270 address = (struct sockaddr *) addr; 200 switch(address->sa_family){ 201 case AF_INET: 202 if(addrlen != sizeof(struct sockaddr_in)){ 203 return EINVAL; 204 } 205 address_in = (struct sockaddr_in *) addr; 206 // find the socket 207 socket = socket_cores_find(local_sockets, socket_id); 208 if(! socket){ 209 return ENOTSOCK; 210 } 211 // bind a free port? 212 if(address_in->sin_port <= 0){ 213 return socket_bind_free_port(global_sockets, socket, free_ports_start, free_ports_end, last_used_port); 214 } 215 // try to find the port 216 socket_port = socket_ports_find(global_sockets, ntohs(address_in->sin_port)); 217 if(socket_port){ 218 // already used 219 return EADDRINUSE; 220 } 221 // if bound 222 if(socket->port){ 223 // release the port 224 socket_port_release(global_sockets, socket); 225 } 226 socket->port = -1; 227 return socket_bind_insert(global_sockets, socket, ntohs(address_in->sin_port)); 228 break; 271 switch (address->sa_family) { 272 case AF_INET: 273 if (addrlen != sizeof(struct sockaddr_in)) 274 return EINVAL; 275 276 address_in = (struct sockaddr_in *) addr; 277 // find the socket 278 socket = socket_cores_find(local_sockets, socket_id); 279 if (!socket) 280 return ENOTSOCK; 281 282 // bind a free port? 283 if (address_in->sin_port <= 0) 284 return socket_bind_free_port(global_sockets, socket, 285 free_ports_start, free_ports_end, last_used_port); 286 287 // try to find the port 288 socket_port = socket_ports_find(global_sockets, 289 ntohs(address_in->sin_port)); 290 if (socket_port) { 291 // already used 292 return EADDRINUSE; 293 } 294 295 // if bound 296 if (socket->port) { 297 // release the port 298 socket_port_release(global_sockets, socket); 299 } 300 socket->port = -1; 301 302 return socket_bind_insert(global_sockets, socket, 303 ntohs(address_in->sin_port)); 304 305 case AF_INET6: 229 306 // TODO IPv6 230 } 307 break; 308 } 309 231 310 return EAFNOSUPPORT; 232 311 } 233 312 234 int socket_bind_free_port(socket_ports_ref global_sockets, socket_core_ref socket, int free_ports_start, int free_ports_end, int last_used_port){ 313 /** Binds the socket to a free port. 314 * 315 * The first free port is used. 316 * 317 * @param[in,out] global_sockets The global sockets to be updated. 318 * @param[in,out] socket The socket to be bound. 319 * @param[in] free_ports_start The minimum free port. 320 * @param[in] free_ports_end The maximum free port. 321 * @param[in] last_used_port The last used free port. 322 * @returns EOK on success. 323 * @returns ENOTCONN if no free port was found. 324 * @returns Other error codes as defined for the 325 * socket_bind_insert() function. 326 */ 327 int 328 socket_bind_free_port(socket_ports_ref global_sockets, socket_core_ref socket, 329 int free_ports_start, int free_ports_end, int last_used_port) 330 { 235 331 int index; 236 332 237 333 // from the last used one 238 334 index = last_used_port; 239 do{ 240 ++ index; 335 336 do { 337 ++index; 338 241 339 // til the range end 242 if (index >= free_ports_end){340 if (index >= free_ports_end) { 243 341 // start from the range beginning 244 342 index = free_ports_start - 1; 245 do {246 ++ 343 do { 344 ++index; 247 345 // til the last used one 248 if (index >= last_used_port){346 if (index >= last_used_port) { 249 347 // none found 250 348 return ENOTCONN; 251 349 } 252 }while(socket_ports_find(global_sockets, index) != NULL); 350 } while (socket_ports_find(global_sockets, index)); 351 253 352 // found, break immediately 254 353 break; 255 354 } 256 }while(socket_ports_find(global_sockets, index) != NULL); 355 356 } while (socket_ports_find(global_sockets, index)); 357 257 358 return socket_bind_insert(global_sockets, socket, index); 258 359 } 259 360 260 361 /** Tries to find a new free socket identifier. 261 * @param[in] local_sockets The local sockets to be searched. 262 * @param[in] positive A value indicating whether a positive identifier is requested. A negative identifier is requested if set to false. 263 * @returns The new socket identifier. 264 * @returns ELIMIT if there is no socket identifier available. 265 */ 266 static int socket_generate_new_id(socket_cores_ref local_sockets, int positive){ 362 * 363 * @param[in] local_sockets The local sockets to be searched. 364 * @param[in] positive A value indicating whether a positive identifier is 365 * requested. A negative identifier is requested if set to 366 * false. 367 * @returns The new socket identifier. 368 * @returns ELIMIT if there is no socket identifier available. 369 */ 370 static int socket_generate_new_id(socket_cores_ref local_sockets, int positive) 371 { 267 372 int socket_id; 268 373 int count; … … 270 375 count = 0; 271 376 // socket_id = socket_globals.last_id; 272 do {273 if (count < SOCKET_ID_TRIES){377 do { 378 if (count < SOCKET_ID_TRIES) { 274 379 socket_id = rand() % INT_MAX; 275 ++ 276 } else if(count == SOCKET_ID_TRIES){380 ++count; 381 } else if (count == SOCKET_ID_TRIES) { 277 382 socket_id = 1; 278 ++ 383 ++count; 279 384 // only this branch for last_id 280 } else{281 if (socket_id < INT_MAX){385 } else { 386 if (socket_id < INT_MAX) { 282 387 ++ socket_id; 283 /* } else if(socket_globals.last_id){388 /* } else if(socket_globals.last_id) { 284 389 * socket_globals.last_id = 0; 285 390 * socket_id = 1; 286 */ } else{391 */ } else { 287 392 return ELIMIT; 288 393 } 289 394 } 290 }while(socket_cores_find(local_sockets, ((positive ? 1 : -1) * socket_id))); 395 } while (socket_cores_find(local_sockets, 396 ((positive ? 1 : -1) * socket_id))); 397 291 398 // last_id = socket_id 292 399 return socket_id; 293 400 } 294 401 295 int socket_create(socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id){ 402 /** Creates a new socket. 403 * 404 * @param[in,out] local_sockets The local sockets to be updated. 405 * @param[in] app_phone The application phone. 406 * @param[in] specific_data The socket specific data. 407 * @param[in,out] socket_id The new socket identifier. A new identifier is 408 * chosen if set to zero or negative. A negative identifier 409 * is chosen if set to negative. 410 * @returns EOK on success. 411 * @returns EINVAL if the socket_id parameter is NULL. 412 * @returns ENOMEM if there is not enough memory left. 413 */ 414 int 415 socket_create(socket_cores_ref local_sockets, int app_phone, 416 void *specific_data, int *socket_id) 417 { 296 418 ERROR_DECLARE; 297 419 … … 300 422 int positive; 301 423 302 if (! socket_id){424 if (!socket_id) 303 425 return EINVAL; 304 }426 305 427 // store the socket 306 if (*socket_id <= 0){428 if (*socket_id <= 0) { 307 429 positive = (*socket_id == 0); 308 430 *socket_id = socket_generate_new_id(local_sockets, positive); 309 if(*socket_id <= 0){ 310 return * socket_id; 311 } 312 if(! positive){ 431 if (*socket_id <= 0) 432 return *socket_id; 433 if (!positive) 313 434 *socket_id *= -1; 314 } 315 }else if(socket_cores_find(local_sockets, * socket_id)){ 435 } else if(socket_cores_find(local_sockets, *socket_id)) { 316 436 return EEXIST; 317 437 } 438 318 439 socket = (socket_core_ref) malloc(sizeof(*socket)); 319 if (! socket){440 if (!socket) 320 441 return ENOMEM; 321 }442 322 443 // initialize 323 444 socket->phone = app_phone; … … 326 447 socket->key_length = 0; 327 448 socket->specific_data = specific_data; 328 if(ERROR_OCCURRED(dyn_fifo_initialize(&socket->received, SOCKET_INITIAL_RECEIVED_SIZE))){ 449 if (ERROR_OCCURRED(dyn_fifo_initialize(&socket->received, 450 SOCKET_INITIAL_RECEIVED_SIZE))) { 329 451 free(socket); 330 452 return ERROR_CODE; 331 453 } 332 if(ERROR_OCCURRED(dyn_fifo_initialize(&socket->accepted, SOCKET_INITIAL_ACCEPTED_SIZE))){ 454 if (ERROR_OCCURRED(dyn_fifo_initialize(&socket->accepted, 455 SOCKET_INITIAL_ACCEPTED_SIZE))) { 333 456 dyn_fifo_destroy(&socket->received); 334 457 free(socket); 335 458 return ERROR_CODE; 336 459 } 337 socket->socket_id = * 460 socket->socket_id = *socket_id; 338 461 res = socket_cores_add(local_sockets, socket->socket_id, socket); 339 if (res < 0){462 if (res < 0) { 340 463 dyn_fifo_destroy(&socket->received); 341 464 dyn_fifo_destroy(&socket->accepted); … … 343 466 return res; 344 467 } 468 345 469 return EOK; 346 470 } 347 471 348 int socket_destroy(int packet_phone, int socket_id, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket)){ 472 /** Destroys the socket. 473 * 474 * If the socket is bound, the port is released. 475 * Releases all buffered packets, calls the release function and removes the 476 * socket from the local sockets. 477 * 478 * @param[in] packet_phone The packet server phone to release buffered packets. 479 * @param[in] socket_id The socket identifier. 480 * @param[in,out] local_sockets The local sockets to be updated. 481 * @param[in,out] global_sockets The global sockets to be updated. 482 * @param[in] socket_release The client release callback function. 483 * @returns EOK on success. 484 * @returns ENOTSOCK if the socket is not found. 485 */ 486 int 487 socket_destroy(int packet_phone, int socket_id, socket_cores_ref local_sockets, 488 socket_ports_ref global_sockets, 489 void (*socket_release)(socket_core_ref socket)) 490 { 349 491 socket_core_ref socket; 350 492 int accepted_id; … … 352 494 // find the socket 353 495 socket = socket_cores_find(local_sockets, socket_id); 354 if (! socket){496 if (!socket) 355 497 return ENOTSOCK; 356 }498 357 499 // destroy all accepted sockets 358 while((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0){ 359 socket_destroy(packet_phone, accepted_id, local_sockets, global_sockets, socket_release); 360 } 361 socket_destroy_core(packet_phone, socket, local_sockets, global_sockets, socket_release); 500 while ((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0) 501 socket_destroy(packet_phone, accepted_id, local_sockets, 502 global_sockets, socket_release); 503 504 socket_destroy_core(packet_phone, socket, local_sockets, global_sockets, 505 socket_release); 506 362 507 return EOK; 363 508 } 364 509 365 int socket_reply_packets(packet_t packet, size_t * length){ 510 /** Replies the packet or the packet queue data to the application via the 511 * socket. 512 * 513 * Uses the current message processing fibril. 514 * 515 * @param[in] packet The packet to be transfered. 516 * @param[out] length The total data length. 517 * @returns EOK on success. 518 * @returns EBADMEM if the length parameter is NULL. 519 * @returns ENOMEM if there is not enough memory left. 520 * @returns Other error codes as defined for the data_reply() 521 * function. 522 */ 523 int socket_reply_packets(packet_t packet, size_t *length) 524 { 366 525 ERROR_DECLARE; 367 526 368 527 packet_t next_packet; 369 528 size_t fragments; 370 size_t * 529 size_t *lengths; 371 530 size_t index; 372 531 373 if (! length){532 if (!length) 374 533 return EBADMEM; 375 } 534 376 535 next_packet = pq_next(packet); 377 if (! next_packet){536 if (!next_packet) { 378 537 // write all if only one fragment 379 ERROR_PROPAGATE(data_reply(packet_get_data(packet), packet_get_data_length(packet))); 538 ERROR_PROPAGATE(data_reply(packet_get_data(packet), 539 packet_get_data_length(packet))); 380 540 // store the total length 381 541 *length = packet_get_data_length(packet); 382 } else{542 } else { 383 543 // count the packet fragments 384 544 fragments = 1; 385 545 next_packet = pq_next(packet); 386 while ((next_packet = pq_next(next_packet))){387 ++ 388 }546 while ((next_packet = pq_next(next_packet))) 547 ++fragments; 548 389 549 // compute and store the fragment lengths 390 lengths = (size_t *) malloc(sizeof(size_t) * fragments + sizeof(size_t)); 391 if(! lengths){ 550 lengths = (size_t *) malloc(sizeof(size_t) * fragments + 551 sizeof(size_t)); 552 if (!lengths) 392 553 return ENOMEM; 393 }554 394 555 lengths[0] = packet_get_data_length(packet); 395 556 lengths[fragments] = lengths[0]; 396 557 next_packet = pq_next(packet); 397 for(index = 1; index < fragments; ++ index){ 558 559 for (index = 1; index < fragments; ++index) { 398 560 lengths[index] = packet_get_data_length(next_packet); 399 561 lengths[fragments] += lengths[index]; 400 562 next_packet = pq_next(packet); 401 }while(next_packet); 563 } 564 402 565 // write the fragment lengths 403 ERROR_PROPAGATE(data_reply(lengths, sizeof(int) * (fragments + 1))); 566 if (ERROR_OCCURRED(data_reply(lengths, 567 sizeof(int) * (fragments + 1)))) { 568 free(lengths); 569 return ERROR_CODE; 570 } 404 571 next_packet = packet; 572 405 573 // write the fragments 406 for(index = 0; index < fragments; ++ index){ 407 ERROR_PROPAGATE(data_reply(packet_get_data(next_packet), lengths[index])); 574 for (index = 0; index < fragments; ++index) { 575 ERROR_CODE = data_reply(packet_get_data(next_packet), 576 lengths[index]); 577 if (ERROR_OCCURRED(ERROR_CODE)) { 578 free(lengths); 579 return ERROR_CODE; 580 } 408 581 next_packet = pq_next(next_packet); 409 }while(next_packet); 582 } 583 410 584 // store the total length 411 585 *length = lengths[fragments]; 412 586 free(lengths); 413 587 } 588 414 589 return EOK; 415 590 } 416 591 417 socket_core_ref socket_port_find(socket_ports_ref global_sockets, int port, const char * key, size_t key_length){ 592 /** Finds the bound port socket. 593 * 594 * @param[in] global_sockets The global sockets to be searched. 595 * @param[in] port The port number. 596 * @param[in] key The socket key identifier. 597 * @param[in] key_length The socket key length. 598 * @returns The found socket. 599 * @returns NULL if no socket was found. 600 */ 601 socket_core_ref 602 socket_port_find(socket_ports_ref global_sockets, int port, const char *key, 603 size_t key_length) 604 { 418 605 socket_port_ref socket_port; 419 socket_core_ref * 606 socket_core_ref *socket_ref; 420 607 421 608 socket_port = socket_ports_find(global_sockets, port); 422 if(socket_port && (socket_port->count > 0)){ 423 socket_ref = socket_port_map_find(&socket_port->map, key, key_length); 424 if(socket_ref){ 425 return * socket_ref; 426 } 427 } 609 if (socket_port && (socket_port->count > 0)) { 610 socket_ref = socket_port_map_find(&socket_port->map, key, 611 key_length); 612 if (socket_ref) 613 return *socket_ref; 614 } 615 428 616 return NULL; 429 617 } 430 618 431 void socket_port_release(socket_ports_ref global_sockets, socket_core_ref socket){ 619 /** Releases the socket port. 620 * 621 * If the socket is bound the port entry is released. 622 * If there are no more port entries the port is release. 623 * 624 * @param[in] global_sockets The global sockets to be updated. 625 * @param[in] socket The socket to be unbound. 626 */ 627 void 628 socket_port_release(socket_ports_ref global_sockets, socket_core_ref socket) 629 { 432 630 socket_port_ref socket_port; 433 socket_core_ref * socket_ref; 434 435 if(socket->port){ 436 // find ports 437 socket_port = socket_ports_find(global_sockets, socket->port); 438 if(socket_port){ 439 // find the socket 440 socket_ref = socket_port_map_find(&socket_port->map, socket->key, socket->key_length); 441 if(socket_ref){ 442 -- socket_port->count; 443 // release if empty 444 if(socket_port->count <= 0){ 445 // destroy the map 446 socket_port_map_destroy(&socket_port->map); 447 // release the port 448 socket_ports_exclude(global_sockets, socket->port); 449 }else{ 450 // remove 451 socket_port_map_exclude(&socket_port->map, socket->key, socket->key_length); 452 } 631 socket_core_ref *socket_ref; 632 633 if (!socket->port) 634 return; 635 636 // find ports 637 socket_port = socket_ports_find(global_sockets, socket->port); 638 if (socket_port) { 639 // find the socket 640 socket_ref = socket_port_map_find(&socket_port->map, 641 socket->key, socket->key_length); 642 643 if (socket_ref) { 644 --socket_port->count; 645 646 // release if empty 647 if (socket_port->count <= 0) { 648 // destroy the map 649 socket_port_map_destroy(&socket_port->map); 650 // release the port 651 socket_ports_exclude(global_sockets, 652 socket->port); 653 } else { 654 // remove 655 socket_port_map_exclude(&socket_port->map, 656 socket->key, socket->key_length); 453 657 } 454 658 } 455 socket->port = 0; 456 socket->key = NULL; 457 socket->key_length = 0; 458 } 459 } 460 461 int socket_port_add(socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length){ 659 } 660 661 socket->port = 0; 662 socket->key = NULL; 663 socket->key_length = 0; 664 } 665 666 /** Adds the socket to an already bound port. 667 * 668 * @param[in] global_sockets The global sockets to be updated. 669 * @param[in] port The port number to be bound to. 670 * @param[in] socket The socket to be added. 671 * @param[in] key The socket key identifier. 672 * @param[in] key_length The socket key length. 673 * @returns EOK on success. 674 * @returns ENOENT if the port is not already used. 675 * @returns Other error codes as defined for the 676 * socket_port_add_core() function. 677 */ 678 int 679 socket_port_add(socket_ports_ref global_sockets, int port, 680 socket_core_ref socket, const char *key, size_t key_length) 681 { 462 682 ERROR_DECLARE; 463 683 … … 466 686 // find ports 467 687 socket_port = socket_ports_find(global_sockets, port); 468 if (! socket_port){688 if (!socket_port) 469 689 return ENOENT; 470 }690 471 691 // add the socket 472 ERROR_PROPAGATE(socket_port_add_core(socket_port, socket, key, key_length)); 692 ERROR_PROPAGATE(socket_port_add_core(socket_port, socket, key, 693 key_length)); 694 473 695 socket->port = port; 474 696 return EOK; -
uspace/lib/net/il/arp_remote.c
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup arp30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * ARP interface implementation for remote modules. 35 * @see arp_interface.h 36 36 */ 37 37 38 38 #include <arp_interface.h> 39 #include <arp_messages.h>40 39 #include <generic.h> 41 40 … … 44 43 #include <ipc/ipc.h> 45 44 #include <ipc/services.h> 45 #include <ipc/arp.h> 46 46 47 47 #include <net/modules.h> … … 49 49 #include <adt/measured_strings.h> 50 50 51 int arp_connect_module(services_t service){ 52 if(service != SERVICE_ARP){ 51 /** Connects to the ARP module. 52 * 53 * @param service The ARP module service. Ignored parameter. 54 * @returns The ARP module phone on success. 55 */ 56 int arp_connect_module(services_t service) 57 { 58 if (service != SERVICE_ARP) 53 59 return EINVAL; 54 } 60 55 61 return connect_to_service(SERVICE_ARP); 56 62 } 57 63 58 int arp_clean_cache_req(int arp_phone){ 64 /** Cleans the cache. 65 * 66 * @param[in] arp_phone The ARP module phone used for (semi)remote calls. 67 * @returns EOK on success. 68 */ 69 int arp_clean_cache_req(int arp_phone) 70 { 59 71 return (int) async_req_0_0(arp_phone, NET_ARP_CLEAN_CACHE); 60 72 } 61 73 62 int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address){ 74 /** Clears the given protocol address from the cache. 75 * 76 * @param[in] arp_phone The ARP module phone used for (semi)remote calls. 77 * @param[in] device_id The device identifier. 78 * @param[in] protocol The requesting protocol service. 79 * @param[in] address The protocol address to be cleared. 80 * @returns EOK on success. 81 * @returns ENOENT if the mapping is not found. 82 */ 83 int 84 arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, 85 measured_string_ref address) 86 { 63 87 aid_t message_id; 64 88 ipcarg_t result; 65 89 66 message_id = async_send_2(arp_phone, NET_ARP_CLEAR_ADDRESS, (ipcarg_t) device_id, protocol, NULL); 90 message_id = async_send_2(arp_phone, NET_ARP_CLEAR_ADDRESS, 91 (ipcarg_t) device_id, protocol, NULL); 67 92 measured_strings_send(arp_phone, address, 1); 68 93 async_wait_for(message_id, &result); 94 69 95 return (int) result; 70 96 } 71 97 72 int arp_clear_device_req(int arp_phone, device_id_t device_id){ 73 return (int) async_req_1_0(arp_phone, NET_ARP_CLEAR_DEVICE, (ipcarg_t) device_id); 98 /** Clears the device cache. 99 * 100 * @param[in] arp_phone The ARP module phone used for (semi)remote calls. 101 * @param[in] device_id The device identifier. 102 * @returns EOK on success. 103 * @returns ENOENT if the device is not found. 104 */ 105 int arp_clear_device_req(int arp_phone, device_id_t device_id) 106 { 107 return (int) async_req_1_0(arp_phone, NET_ARP_CLEAR_DEVICE, 108 (ipcarg_t) device_id); 74 109 } 75 110 76 int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){ 111 /** Registers the new device and the requesting protocol service. 112 * 113 * Connects to the network interface layer service. 114 * Determines the device broadcast address, its address lengths and packet size. 115 * 116 * @param[in] arp_phone The ARP module phone used for (semi)remote calls. 117 * @param[in] device_id The new device identifier. 118 * @param[in] protocol The requesting protocol service. 119 * @param[in] netif The underlying device network interface layer service. 120 * @param[in] address The local requesting protocol address of the device. 121 * @returns EOK on success. 122 * @returns EEXIST if the device is already used. 123 * @returns ENOMEM if there is not enough memory left. 124 * @returns ENOENT if the network interface service is not known. 125 * @returns EREFUSED if the network interface service is not 126 * responding. 127 * @returns Other error codes as defined for the 128 * nil_packet_get_size() function. 129 * @returns Other error codes as defined for the nil_get_addr() 130 * function. 131 * @returns Other error codes as defined for the 132 * nil_get_broadcast_addr() function. 133 */ 134 int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, 135 services_t netif, measured_string_ref address) 136 { 77 137 aid_t message_id; 78 138 ipcarg_t result; 79 139 80 message_id = async_send_3(arp_phone, NET_ARP_DEVICE, (ipcarg_t) device_id, protocol, netif, NULL); 140 message_id = async_send_3(arp_phone, NET_ARP_DEVICE, 141 (ipcarg_t) device_id, protocol, netif, NULL); 81 142 measured_strings_send(arp_phone, address, 1); 82 143 async_wait_for(message_id, &result); 144 83 145 return (int) result; 84 146 } 85 147 86 task_id_t arp_task_get_id(void){ 87 return 0; 88 } 89 90 int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data){ 91 return generic_translate_req(arp_phone, NET_ARP_TRANSLATE, device_id, protocol, address, 1, translation, data); 148 /** Translates the given protocol address to the network interface address. 149 * 150 * Broadcasts the ARP request if the mapping is not found. 151 * Allocates and returns the needed memory block as the data parameter. 152 * 153 * @param[in] arp_phone The ARP module phone used for (semi)remote calls. 154 * @param[in] device_id The device identifier. 155 * @param[in] protocol The requesting protocol service. 156 * @param[in] address The local requesting protocol address. 157 * @param[out] translation The translation of the local protocol address. 158 * @param[out] data The allocated raw translation data container. 159 * @returns EOK on success. 160 * @returns EINVAL if the address parameter is NULL. 161 * @returns EBADMEM if the translation or the data parameters are 162 * NULL. 163 * @returns ENOENT if the mapping is not found. 164 */ 165 int 166 arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, 167 measured_string_ref address, measured_string_ref *translation, char **data) 168 { 169 return generic_translate_req(arp_phone, NET_ARP_TRANSLATE, device_id, 170 protocol, address, 1, translation, data); 92 171 } 93 172 -
uspace/lib/net/il/ip_client.c
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup ip30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 35 * 34 * IP client interface implementation. 35 * @see ip_client.h 36 36 */ 37 37 … … 45 45 #include <net/packet.h> 46 46 47 size_t ip_client_header_length(packet_t packet){ 47 /** Returns the IP header length. 48 * 49 * @param[in] packet The packet. 50 * @returns The IP header length in bytes. 51 * @returns Zero if there is no IP header. 52 */ 53 size_t ip_client_header_length(packet_t packet) 54 { 48 55 ip_header_ref header; 49 56 50 57 header = (ip_header_ref) packet_get_data(packet); 51 if((! header) 52 || (packet_get_data_length(packet) < sizeof(ip_header_t))){ 58 if (!header || (packet_get_data_length(packet) < sizeof(ip_header_t))) 53 59 return 0; 54 } 60 55 61 return IP_HEADER_LENGTH(header); 56 62 } 57 63 58 int ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, void **header, size_t * headerlen){ 64 /** Constructs the IPv4 pseudo header. 65 * 66 * @param[in] protocol The transport protocol. 67 * @param[in] src The source address. 68 * @param[in] srclen The source address length. 69 * @param[in] dest The destination address. 70 * @param[in] destlen The destination address length. 71 * @param[in] data_length The data length to be set. 72 * @param[out] header The constructed IPv4 pseudo header. 73 * @param[out] headerlen The length of the IP pseudo header in bytes. 74 * @returns EOK on success. 75 * @returns EBADMEM if the header and/or the headerlen parameter is 76 * NULL. 77 * @returns EINVAL if the source address and/or the destination 78 * address parameter is NULL. 79 * @returns EINVAL if the source address length is less than struct 80 * sockaddr length. 81 * @returns EINVAL if the source address length differs from the 82 * destination address length. 83 * @returns EINVAL if the source address family differs from the 84 * destination family. 85 * @returns EAFNOSUPPORT if the address family is not supported. 86 * @returns ENOMEM if there is not enough memory left. 87 */ 88 int 89 ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr *src, 90 socklen_t srclen, struct sockaddr *dest, socklen_t destlen, 91 size_t data_length, void **header, size_t *headerlen) 92 { 59 93 ipv4_pseudo_header_ref header_in; 60 struct sockaddr_in * 61 62 if (!(header && headerlen)){94 struct sockaddr_in *address_in; 95 96 if (!header || !headerlen) 63 97 return EBADMEM; 64 } 65 if(!(src && dest && (srclen > 0) && ((size_t) srclen >= sizeof(struct sockaddr)) && (srclen == destlen) && (src->sa_family == dest->sa_family))){ 98 99 if (!src || !dest || srclen <= 0 || 100 (((size_t) srclen < sizeof(struct sockaddr))) || 101 (srclen != destlen) || (src->sa_family != dest->sa_family)) { 66 102 return EINVAL; 67 103 } 68 104 69 switch(src->sa_family){ 70 case AF_INET: 71 if(srclen != sizeof(struct sockaddr_in)){ 72 return EINVAL; 73 } 74 *headerlen = sizeof(*header_in); 75 header_in = (ipv4_pseudo_header_ref) malloc(*headerlen); 76 if(! header_in){ 77 return ENOMEM; 78 } 79 bzero(header_in, * headerlen); 80 address_in = (struct sockaddr_in *) dest; 81 header_in->destination_address = address_in->sin_addr.s_addr; 82 address_in = (struct sockaddr_in *) src; 83 header_in->source_address = address_in->sin_addr.s_addr; 84 header_in->protocol = protocol; 85 header_in->data_length = htons(data_length); 86 *header = header_in; 87 return EOK; 88 // TODO IPv6 89 /* case AF_INET6: 90 if(addrlen != sizeof(struct sockaddr_in6)){ 91 return EINVAL; 92 } 93 address_in6 = (struct sockaddr_in6 *) addr; 94 return EOK; 95 */ default: 96 return EAFNOSUPPORT; 97 } 98 } 99 100 int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length){ 105 switch (src->sa_family) { 106 case AF_INET: 107 if (srclen != sizeof(struct sockaddr_in)) 108 return EINVAL; 109 110 *headerlen = sizeof(*header_in); 111 header_in = (ipv4_pseudo_header_ref) malloc(*headerlen); 112 if (!header_in) 113 return ENOMEM; 114 115 bzero(header_in, *headerlen); 116 address_in = (struct sockaddr_in *) dest; 117 header_in->destination_address = address_in->sin_addr.s_addr; 118 address_in = (struct sockaddr_in *) src; 119 header_in->source_address = address_in->sin_addr.s_addr; 120 header_in->protocol = protocol; 121 header_in->data_length = htons(data_length); 122 *header = header_in; 123 return EOK; 124 125 // TODO IPv6 126 /* case AF_INET6: 127 if (addrlen != sizeof(struct sockaddr_in6)) 128 return EINVAL; 129 130 address_in6 = (struct sockaddr_in6 *) addr; 131 return EOK; 132 */ 133 134 default: 135 return EAFNOSUPPORT; 136 } 137 } 138 139 /** Prepares the packet to be transfered via IP. 140 * 141 * The IP header is prefixed. 142 * 143 * @param[in,out] packet The packet to be prepared. 144 * @param[in] protocol The transport protocol. 145 * @param[in] ttl The time to live counter. The IPDEFTTL is set if zero. 146 * @param[in] tos The type of service. 147 * @param[in] dont_fragment The value indicating whether fragmentation is 148 * disabled. 149 * @param[in] ipopt_length The prefixed IP options length in bytes. 150 * @returns EOK on success. 151 * @returns ENOMEM if there is not enough memory left in the packet. 152 */ 153 int 154 ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, 155 ip_tos_t tos, int dont_fragment, size_t ipopt_length) 156 { 101 157 ip_header_ref header; 102 uint8_t * 158 uint8_t *data; 103 159 size_t padding; 104 160 … … 106 162 // multiple of 4 bytes 107 163 padding = ipopt_length % 4; 108 if (padding){164 if (padding) { 109 165 padding = 4 - padding; 110 166 ipopt_length += padding; … … 113 169 // prefix the header 114 170 data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding); 115 if (! data){171 if (!data) 116 172 return ENOMEM; 117 }118 173 119 174 // add the padding 120 while (padding --){175 while (padding--) 121 176 data[sizeof(ip_header_t) + padding] = IPOPT_NOOP; 122 }123 177 124 178 // set the header 125 179 header = (ip_header_ref) data; 126 header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length); 127 header->ttl = (ttl ? ttl : IPDEFTTL); //(((ttl) <= MAXTTL) ? ttl : MAXTTL) : IPDEFTTL; 180 header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + 181 ipopt_length); 182 header->ttl = (ttl ? ttl : IPDEFTTL); 128 183 header->tos = tos; 129 184 header->protocol = protocol; 130 185 131 if (dont_fragment){186 if (dont_fragment) 132 187 header->flags = IPFLAG_DONT_FRAGMENT; 133 } 188 134 189 return EOK; 135 190 } 136 191 137 int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length){ 192 /** Processes the received IP packet. 193 * 194 * Fills set header fields. 195 * Returns the prefixed IP header length. 196 * 197 * @param[in] packet The received packet. 198 * @param[out] protocol The transport protocol. May be NULL if not desired. 199 * @param[out] ttl The time to live counter. May be NULL if not desired. 200 * @param[out] tos The type of service. May be NULL if not desired. 201 * @param[out] dont_fragment The value indicating whether the fragmentation is 202 * disabled. May be NULL if not desired. 203 * @param[out] ipopt_length The IP options length in bytes. May be NULL if not 204 * desired. 205 * @returns The prefixed IP header length in bytes on success. 206 * @returns ENOMEM if the packet is too short to contain the IP 207 * header. 208 */ 209 int 210 ip_client_process_packet(packet_t packet, ip_protocol_t *protocol, 211 ip_ttl_t *ttl, ip_tos_t *tos, int *dont_fragment, size_t *ipopt_length) 212 { 138 213 ip_header_ref header; 139 214 140 215 header = (ip_header_ref) packet_get_data(packet); 141 if((! header) 142 || (packet_get_data_length(packet) < sizeof(ip_header_t))){ 216 if (!header || (packet_get_data_length(packet) < sizeof(ip_header_t))) 143 217 return ENOMEM; 144 } 145 146 if(protocol){ 218 219 if (protocol) 147 220 *protocol = header->protocol; 148 } 149 if(ttl){ 221 if (ttl) 150 222 *ttl = header->ttl; 151 } 152 if(tos){ 223 if (tos) 153 224 *tos = header->tos; 154 } 155 if(dont_fragment){ 156 *dont_fragment = header->flags &IPFLAG_DONT_FRAGMENT; 157 } 158 if(ipopt_length){ 225 if (dont_fragment) 226 *dont_fragment = header->flags & IPFLAG_DONT_FRAGMENT; 227 if (ipopt_length) { 159 228 *ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t); 160 229 return sizeof(ip_header_t); 161 } else{230 } else { 162 231 return IP_HEADER_LENGTH(header); 163 232 } 164 233 } 165 234 166 int ip_client_set_pseudo_header_data_length(void *header, size_t headerlen, size_t data_length){ 235 /** Updates the IPv4 pseudo header data length field. 236 * 237 * @param[in,out] header The IPv4 pseudo header to be updated. 238 * @param[in] headerlen The length of the IP pseudo header in bytes. 239 * @param[in] data_length The data length to be set. 240 * @returns EOK on success. 241 * @returns EBADMEM if the header parameter is NULL. 242 * @returns EINVAL if the headerlen parameter is not IPv4 pseudo 243 * header length. 244 */ 245 int 246 ip_client_set_pseudo_header_data_length(void *header, size_t headerlen, 247 size_t data_length) 248 { 167 249 ipv4_pseudo_header_ref header_in; 168 250 169 if (! header){251 if (!header) 170 252 return EBADMEM; 171 } 172 173 if(headerlen == sizeof(ipv4_pseudo_header_t)){ 253 254 if (headerlen == sizeof(ipv4_pseudo_header_t)) { 174 255 header_in = (ipv4_pseudo_header_ref) header; 175 256 header_in->data_length = htons(data_length); 176 257 return EOK; 177 258 // TODO IPv6 178 } else{259 } else { 179 260 return EINVAL; 180 261 } -
uspace/lib/net/il/ip_remote.c
ref689ef0 ra7a85d16 42 42 #include <ip_remote.h> 43 43 #include <ip_interface.h> 44 #include <ip_messages.h>45 #include <il_messages.h>46 44 #include <packet_client.h> 47 45 #include <generic.h> 48 46 49 47 #include <ipc/services.h> 48 #include <ipc/il.h> 49 #include <ipc/ip.h> 50 50 51 51 #include <net/modules.h> -
uspace/lib/net/include/adt/module_map.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * Character string to module map. 35 35 */ 36 36 37 #ifndef __NET_MODULES_MAP_H__38 #define __NET_MODULES_MAP_H__37 #ifndef LIBNET_MODULES_MAP_H_ 38 #define LIBNET_MODULES_MAP_H_ 39 39 40 40 #include <task.h> 41 42 41 #include <ipc/services.h> 43 44 42 #include <net/modules.h> 45 46 43 #include <adt/generic_char_map.h> 47 44 48 45 /** Type definition of the module structure. 49 * 46 * @see module_struct 50 47 */ 51 typedef struct module_struct 48 typedef struct module_struct module_t; 52 49 53 50 /** Type definition of the module structure pointer. 54 * 51 * @see module_struct 55 52 */ 56 typedef module_t * 53 typedef module_t *module_ref; 57 54 58 55 /** Module map. 59 * 60 * 56 * Sorted by module names. 57 * @see generic_char_map.h 61 58 */ 62 59 GENERIC_CHAR_MAP_DECLARE(modules, module_t) 63 60 64 /** Module structure. 65 */ 66 struct module_struct{ 67 /** Module task identifier if running. 68 */ 61 /** Module structure. */ 62 struct module_struct { 63 /** Module task identifier if running. */ 69 64 task_id_t task_id; 70 /** Module service identifier. 71 */ 65 /** Module service identifier. */ 72 66 services_t service; 73 /** Module phone if running and connected. 74 */ 67 /** Module phone if running and connected. */ 75 68 int phone; 76 /** Usage counter. 77 */ 69 /** Usage counter. */ 78 70 int usage; 79 /** Module name. 80 */ 81 const char * name; 82 /** Module full path filename. 83 */ 84 const char * filename; 85 /** Connecting function. 86 */ 87 connect_module_t * connect_module; 71 /** Module name. */ 72 const char *name; 73 /** Module full path filename. */ 74 const char *filename; 75 /** Connecting function. */ 76 connect_module_t *connect_module; 88 77 }; 89 78 90 /** Adds module to the module map. 91 * @param[out] module The module structure added. 92 * @param[in] modules The module map. 93 * @param[in] name The module name. 94 * @param[in] filename The full path filename. 95 * @param[in] service The module service. 96 * @param[in] task_id The module current task identifier. Zero (0) means not running. 97 * @param[in] connect_module The module connecting function. 98 * @returns EOK on success. 99 * @returns ENOMEM if there is not enough memory left. 100 */ 101 int add_module(module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id, connect_module_t * connect_module); 102 103 /** Searches and returns the specified module. 104 * If the module is not running, the module filaname is spawned. 105 * If the module is not connected, the connect_function is called. 106 * @param[in] modules The module map. 107 * @param[in] name The module name. 108 * @returns The running module found. It does not have to be connected. 109 * @returns NULL if there is no such module. 110 */ 111 module_ref get_running_module(modules_ref modules, char * name); 112 113 /** Starts the given module. 114 * @param[in] fname The module full or relative path filename. 115 * @returns The new module task identifier on success. 116 * @returns 0 if there is no such module. 117 */ 118 task_id_t spawn(const char * fname); 79 extern int add_module(module_ref *, modules_ref, const char *, const char *, 80 services_t, task_id_t, connect_module_t *); 81 extern module_ref get_running_module(modules_ref, char *); 82 extern task_id_t spawn(const char *); 119 83 120 84 #endif -
uspace/lib/net/include/arp_interface.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup arp30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 #ifndef __NET_ARP_INTERFACE_H__34 #define __NET_ARP_INTERFACE_H__33 #ifndef LIBNET_ARP_INTERFACE_H_ 34 #define LIBNET_ARP_INTERFACE_H_ 35 35 36 36 #include <adt/measured_strings.h> … … 43 43 44 44 /** @name ARP module interface 45 * 45 * This interface is used by other modules. 46 46 */ 47 47 /*@{*/ 48 48 49 /** Registers the new device and the requesting protocol service. 50 * Connects to the network interface layer service. 51 * Determines the device broadcast address, its address lengths and packet size. 52 * @param[in] arp_phone The ARP module phone used for (semi)remote calls. 53 * @param[in] device_id The new device identifier. 54 * @param[in] protocol The requesting protocol service. 55 * @param[in] netif The underlying device network interface layer service. 56 * @param[in] address The local requesting protocol address of the device. 57 * @returns EOK on success. 58 * @returns EEXIST if the device is already used. 59 * @returns ENOMEM if there is not enough memory left. 60 * @returns ENOENT if the network interface service is not known. 61 * @returns EREFUSED if the network interface service is not responding. 62 * @returns Other error codes as defined for the nil_packet_get_size() function. 63 * @returns Other error codes as defined for the nil_get_addr() function. 64 * @returns Other error codes as defined for the nil_get_broadcast_addr() function. 65 */ 66 extern int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address); 67 68 /** Translates the given protocol address to the network interface address. 69 * Broadcasts the ARP request if the mapping is not found. 70 * Allocates and returns the needed memory block as the data parameter. 71 * @param[in] arp_phone The ARP module phone used for (semi)remote calls. 72 * @param[in] device_id The device identifier. 73 * @param[in] protocol The requesting protocol service. 74 * @param[in] address The local requesting protocol address. 75 * @param[out] translation The translation of the local protocol address. 76 * @param[out] data The allocated raw translation data container. 77 * @returns EOK on success. 78 * @returns EINVAL if the address parameter is NULL. 79 * @returns EBADMEM if the translation or the data parameters are NULL. 80 * @returns ENOENT if the mapping is not found. 81 */ 82 extern int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data); 83 84 /** Clears the device cache. 85 * @param[in] arp_phone The ARP module phone used for (semi)remote calls. 86 * @param[in] device_id The device identifier. 87 * @returns EOK on success. 88 * @returns ENOENT if the device is not found. 89 */ 90 extern int arp_clear_device_req(int arp_phone, device_id_t device_id); 91 92 /** Clears the given protocol address from the cache. 93 * @param[in] arp_phone The ARP module phone used for (semi)remote calls. 94 * @param[in] device_id The device identifier. 95 * @param[in] protocol The requesting protocol service. 96 * @param[in] address The protocol address to be cleared. 97 * @returns EOK on success. 98 * @returns ENOENT if the mapping is not found. 99 */ 100 extern int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address); 101 102 /** Cleans the cache. 103 * @param[in] arp_phone The ARP module phone used for (semi)remote calls. 104 * @returns EOK on success. 105 */ 106 extern int arp_clean_cache_req(int arp_phone); 107 108 /** Connects to the ARP module. 109 * @param service The ARP module service. Ignored parameter. 110 * @returns The ARP module phone on success. 111 */ 112 extern int arp_connect_module(services_t service); 113 114 /** Returns the ARP task identifier. 115 * @returns 0 if called by the remote module. 116 */ 117 extern task_id_t arp_task_get_id(void); 49 extern int arp_device_req(int, device_id_t, services_t, services_t, 50 measured_string_ref); 51 extern int arp_translate_req(int, device_id_t, services_t, measured_string_ref, 52 measured_string_ref *, char **); 53 extern int arp_clear_device_req(int, device_id_t); 54 extern int arp_clear_address_req(int, device_id_t, services_t, 55 measured_string_ref); 56 extern int arp_clean_cache_req(int); 57 extern int arp_connect_module(services_t); 118 58 119 59 /*@}*/ -
uspace/lib/net/include/generic.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net29 /** @addtogroup libnet 30 30 * @{ 31 31 */ … … 35 35 */ 36 36 37 #ifndef NET_GENERIC_H_38 #define NET_GENERIC_H_37 #ifndef LIBNET_GENERIC_H_ 38 #define LIBNET_GENERIC_H_ 39 39 40 40 #include <async.h> -
uspace/lib/net/include/il_interface.h
ref689ef0 ra7a85d16 42 42 43 43 #include <ipc/services.h> 44 #include <ipc/il.h> 44 45 45 46 #include <net/device.h> 46 47 #include <net/packet.h> 47 #include <il_messages.h>48 48 49 49 #include <packet_client.h> -
uspace/lib/net/include/ip_client.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup ip30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * IP client interface. 35 35 */ 36 36 37 #ifndef __NET_IP_CLIENT_H__38 #define __NET_IP_CLIENT_H__37 #ifndef LIBNET_IP_CLIENT_H_ 38 #define LIBNET_IP_CLIENT_H_ 39 39 40 40 #include <net/socket_codes.h> … … 45 45 #include <ip_interface.h> 46 46 47 /** Prepares the packet to be transfered via IP. 48 * The IP header is prefixed. 49 * @param[in,out] packet The packet to be prepared. 50 * @param[in] protocol The transport protocol. 51 * @param[in] ttl The time to live counter. The IPDEFTTL is set if zero (0). 52 * @param[in] tos The type of service. 53 * @param[in] dont_fragment The value indicating whether fragmentation is disabled. 54 * @param[in] ipopt_length The prefixed IP options length in bytes. 55 * @returns EOK on success. 56 * @returns ENOMEM if there is not enough memory left in the packet. 57 */ 58 extern int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length); 59 60 /** Processes the received IP packet. 61 * Fills set header fields. 62 * Returns the prefixed IP header length. 63 * @param[in] packet The received packet. 64 * @param[out] protocol The transport protocol. May be NULL if not desired. 65 * @param[out] ttl The time to live counter. May be NULL if not desired. 66 * @param[out] tos The type of service. May be NULL if not desired. 67 * @param[out] dont_fragment The value indicating whether the fragmentation is disabled. May be NULL if not desired. 68 * @param[out] ipopt_length The IP options length in bytes. May be NULL if not desired. 69 * @returns The prefixed IP header length in bytes on success. 70 * @returns ENOMEM if the packet is too short to contain the IP header. 71 */ 72 extern int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length); 73 74 /** Returns the IP header length. 75 * @param[in] packet The packet. 76 * @returns The IP header length in bytes. 77 * @returns Zero (0) if there is no IP header. 78 */ 79 extern size_t ip_client_header_length(packet_t packet); 80 81 /** Updates the IPv4 pseudo header data length field. 82 * @param[in,out] header The IPv4 pseudo header to be updated. 83 * @param[in] headerlen The length of the IP pseudo header in bytes. 84 * @param[in] data_length The data length to be set. 85 * @returns EOK on success. 86 * @returns EBADMEM if the header parameter is NULL. 87 * @returns EINVAL if the headerlen parameter is not IPv4 pseudo header length. 88 */ 89 extern int ip_client_set_pseudo_header_data_length(void *header, size_t headerlen, size_t data_length); 90 91 /** Constructs the IPv4 pseudo header. 92 * @param[in] protocol The transport protocol. 93 * @param[in] src The source address. 94 * @param[in] srclen The source address length. 95 * @param[in] dest The destination address. 96 * @param[in] destlen The destination address length. 97 * @param[in] data_length The data length to be set. 98 * @param[out] header The constructed IPv4 pseudo header. 99 * @param[out] headerlen The length of the IP pseudo header in bytes. 100 * @returns EOK on success. 101 * @returns EBADMEM if the header and/or the headerlen parameter is NULL. 102 * @returns EINVAL if the source address and/or the destination address parameter is NULL. 103 * @returns EINVAL if the source address length is less than struct sockaddr length. 104 * @returns EINVAL if the source address length differs from the destination address length. 105 * @returns EINVAL if the source address family differs from the destination family. 106 * @returns EAFNOSUPPORT if the address family is not supported. 107 * @returns ENOMEM if there is not enough memory left. 108 */ 109 extern int ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, void **header, size_t * headerlen); 47 extern int ip_client_prepare_packet(packet_t, ip_protocol_t, ip_ttl_t, ip_tos_t, 48 int, size_t); 49 extern int ip_client_process_packet(packet_t, ip_protocol_t *, ip_ttl_t *, 50 ip_tos_t *, int *, size_t *); 51 extern size_t ip_client_header_length(packet_t); 52 extern int ip_client_set_pseudo_header_data_length(void *, size_t, size_t); 53 extern int ip_client_get_pseudo_header(ip_protocol_t, struct sockaddr *, 54 socklen_t, struct sockaddr *, socklen_t, size_t, void **, size_t *); 110 55 111 56 // TODO ipopt manipulation -
uspace/lib/net/include/net_checksum.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net30 * 29 /** @addtogroup libnet 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * General CRC and checksum computation. 35 35 */ 36 36 37 #ifndef __NET_CHECKSUM_H__38 #define __NET_CHECKSUM_H__37 #ifndef LIBNET_CHECKSUM_H_ 38 #define LIBNET_CHECKSUM_H_ 39 39 40 40 #include <byteorder.h> 41 42 41 #include <sys/types.h> 43 42 44 43 /** IP checksum value for computed zero checksum. 45 * 44 * Zero is returned as 0xFFFF (not flipped) 46 45 */ 47 #define IP_CHECKSUM_ZERO 0xFFFFu46 #define IP_CHECKSUM_ZERO 0xffffU 48 47 49 /** Computes CRC32 value.50 * @param[in] seed Initial value. Often used as 0 or ~0.51 * @param[in] data Pointer to the beginning of data to process.52 * @param[in] length Length of the data in bits.53 * @returns The computed CRC32 of the length bits of the data.54 */55 48 #ifdef ARCH_IS_BIG_ENDIAN 56 #define compute_crc32(seed, data, length) compute_crc32_be(seed, (uint8_t *) data, length) 49 #define compute_crc32(seed, data, length) \ 50 compute_crc32_be(seed, (uint8_t *) data, length) 57 51 #else 58 #define compute_crc32(seed, data, length) compute_crc32_le(seed, (uint8_t *) data, length) 52 #define compute_crc32(seed, data, length) \ 53 compute_crc32_le(seed, (uint8_t *) data, length) 59 54 #endif 60 55 61 /** Computes CRC32 value in the little-endian environment. 62 * @param[in] seed Initial value. Often used as 0 or ~0. 63 * @param[in] data Pointer to the beginning of data to process. 64 * @param[in] length Length of the data in bits. 65 * @returns The computed CRC32 of the length bits of the data. 66 */ 67 extern uint32_t compute_crc32_le(uint32_t seed, uint8_t * data, size_t length); 68 69 /** Computes CRC32 value in the big-endian environment. 70 * @param[in] seed Initial value. Often used as 0 or ~0. 71 * @param[in] data Pointer to the beginning of data to process. 72 * @param[in] length Length of the data in bits. 73 * @returns The computed CRC32 of the length bits of the data. 74 */ 75 extern uint32_t compute_crc32_be(uint32_t seed, uint8_t * data, size_t length); 76 77 /** Computes sum of the 2 byte fields. 78 * Padds one zero (0) byte if odd. 79 * @param[in] seed Initial value. Often used as 0 or ~0. 80 * @param[in] data Pointer to the beginning of data to process. 81 * @param[in] length Length of the data in bytes. 82 * @returns The computed checksum of the length bytes of the data. 83 */ 84 extern uint32_t compute_checksum(uint32_t seed, uint8_t * data, size_t length); 85 86 /** Compacts the computed checksum to the 16 bit number adding the carries. 87 * @param[in] sum Computed checksum. 88 * @returns Compacted computed checksum to the 16 bits. 89 */ 90 extern uint16_t compact_checksum(uint32_t sum); 91 92 /** Returns or flips the checksum if zero. 93 * @param[in] checksum The computed checksum. 94 * @returns The internet protocol header checksum. 95 * @returns 0xFFFF if the computed checksum is zero. 96 */ 97 extern uint16_t flip_checksum(uint16_t checksum); 98 99 /** Computes the ip header checksum. 100 * To compute the checksum of a new packet, the checksum header field must be zero. 101 * To check the checksum of a received packet, the checksum may be left set. 102 * The zero (0) value will be returned in this case if valid. 103 * @param[in] data The header data. 104 * @param[in] length The header length in bytes. 105 * @returns The internet protocol header checksum. 106 * @returns 0xFFFF if the computed checksum is zero. 107 */ 108 extern uint16_t ip_checksum(uint8_t * data, size_t length); 56 extern uint32_t compute_crc32_le(uint32_t, uint8_t *, size_t); 57 extern uint32_t compute_crc32_be(uint32_t, uint8_t *, size_t); 58 extern uint32_t compute_checksum(uint32_t, uint8_t *, size_t); 59 extern uint16_t compact_checksum(uint32_t); 60 extern uint16_t flip_checksum(uint16_t); 61 extern uint16_t ip_checksum(uint8_t *, size_t); 109 62 110 63 #endif -
uspace/lib/net/include/net_interface.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup net29 /** @addtogroup libnet 30 30 * @{ 31 31 */ 32 32 33 #ifndef __NET_NET_INTERFACE_H__34 #define __NET_NET_INTERFACE_H__33 #ifndef LIBNET_NET_INTERFACE_H_ 34 #define LIBNET_NET_INTERFACE_H_ 35 35 36 36 #include <ipc/services.h> … … 40 40 41 41 /** @name Networking module interface 42 * 42 * This interface is used by other modules. 43 43 */ 44 44 /*@{*/ 45 45 46 /** Returns the device specific configuration. 47 * Returns the global configuration if the device specific is not found. 48 * The configuration names are read and the appropriate settings are set instead. 49 * Call net_free_settings() function to release the returned configuration. 50 * @param[in] net_phone The networking module phone. 51 * @param[in] device_id The device identifier. 52 * @param[in,out] configuration The requested device configuration. The names are read and the appropriate settings are set instead. 53 * @param[in] count The configuration entries count. 54 * @param[in,out] data The configuration and settings data. 55 * @returns EOK on success. 56 * @returns EINVAL if the configuration is NULL. 57 * @returns EINVAL if the count is zero (0). 58 * @returns Other error codes as defined for the generic_translate_req() function. 59 */ 60 extern int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data); 61 62 /** Returns the global configuration. 63 * The configuration names are read and the appropriate settings are set instead. 64 * Call net_free_settings() function to release the returned configuration. 65 * @param[in] net_phone The networking module phone. 66 * @param[in,out] configuration The requested configuration. The names are read and the appropriate settings are set instead. 67 * @param[in] count The configuration entries count. 68 * @param[in,out] data The configuration and settings data. 69 * @returns EOK on success. 70 * @returns EINVAL if the configuration is NULL. 71 * @returns EINVAL if the count is zero (0). 72 * @returns Other error codes as defined for the generic_translate_req() function. 73 */ 74 extern int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data); 75 76 /** Frees the received settings. 77 * @param[in] settings The received settings. 78 * @param[in] data The received settings data. 79 * @see net_get_device_conf_req() 80 * @see net_get_conf_req() 81 */ 82 extern void net_free_settings(measured_string_ref settings, char * data); 83 84 /** Connects to the networking module. 85 * @param service The networking module service. Ignored parameter. 86 * @returns The networking module phone on success. 87 */ 88 extern int net_connect_module(services_t service); 46 extern int net_get_device_conf_req(int, device_id_t, measured_string_ref *, 47 size_t, char **); 48 extern int net_get_conf_req(int, measured_string_ref *, size_t, char **); 49 extern void net_free_settings(measured_string_ref, char *); 50 extern int net_connect_module(void); 89 51 90 52 /*@}*/ -
uspace/lib/net/include/nil_interface.h
ref689ef0 ra7a85d16 38 38 39 39 #include <ipc/ipc.h> 40 #include <ipc/nil.h> 40 41 41 42 #include <generic.h> 42 #include <nil_messages.h>43 43 #include <nil_remote.h> 44 44 -
uspace/lib/net/include/packet_client.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup packet29 /** @addtogroup libnet 30 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Packet client. 35 * The hosting module has to be compiled with both the packet.c and the packet_client.c source files. 36 * To function correctly, initialization of the packet map by the pm_init() function has to happen at the first place. 37 * The module should not send the packet messages to the packet server but use the functions provided. 38 * The packet map should be released by the pm_destroy() function during the module termination. 39 * The packets and the packet queues can't be locked at all. 40 * The processing modules should process them sequentially - by passing the packets to the next module and stopping using the passed ones. 41 * @see packet.h 34 * Packet client. 35 * 36 * To function correctly, initialization of the packet map by the pm_init() 37 * function has to happen at the first place. The module should not send the 38 * packet messages to the packet server but use the functions provided. The 39 * packet map should be released by the pm_destroy() function during the module 40 * termination. The packets and the packet queues can't be locked at all. The 41 * processing modules should process them sequentially - by passing the packets 42 * to the next module and stopping using the passed ones. 43 * 44 * @see packet.h 42 45 */ 43 46 44 #ifndef __NET_PACKET_CLIENT_H__45 #define __NET_PACKET_CLIENT_H__47 #ifndef LIBNET_PACKET_CLIENT_H_ 48 #define LIBNET_PACKET_CLIENT_H_ 46 49 47 50 #include <net/packet.h> 48 51 49 /** @name Packet client interface 50 */ 52 /** @name Packet client interface */ 51 53 /*@{*/ 52 54 53 /** Allocates the specified type right before the actual packet content and returns its pointer. 54 * The wrapper of the packet_prepend() function. 55 * @param[in] packet The packet to be used. 56 * @param[in] type The type to be allocated at the beginning of the packet content. 57 * @returns The typed pointer to the allocated memory. 58 * @returns NULL if the packet is not valid. 59 * @returns NULL if there is not enough memory left. 55 /** Allocates the specified type right before the actual packet content and 56 * returns its pointer. 57 * 58 * The wrapper of the packet_prepend() function. 59 * 60 * @param[in] packet The packet to be used. 61 * @param[in] type The type to be allocated at the beginning of the packet 62 * content. 63 * @returns The typed pointer to the allocated memory. 64 * @returns NULL if the packet is not valid. 65 * @returns NULL if there is not enough memory left. 60 66 */ 61 #define PACKET_PREFIX(packet, type) (type *) packet_prefix((packet), sizeof(type)) 67 #define PACKET_PREFIX(packet, type) \ 68 (type *) packet_prefix((packet), sizeof(type)) 62 69 63 /** Allocates the specified type right after the actual packet content and returns its pointer. 64 * The wrapper of the packet_append() function. 65 * @param[in] packet The packet to be used. 66 * @param[in] type The type to be allocated at the end of the packet content. 67 * @returns The typed pointer to the allocated memory. 68 * @returns NULL if the packet is not valid. 69 * @returns NULL if there is not enough memory left. 70 /** Allocates the specified type right after the actual packet content and 71 * returns its pointer. 72 * 73 * The wrapper of the packet_append() function. 74 * 75 * @param[in] packet The packet to be used. 76 * @param[in] type The type to be allocated at the end of the packet 77 * content. 78 * @returns The typed pointer to the allocated memory. 79 * @returns NULL if the packet is not valid. 80 * @returns NULL if there is not enough memory left. 70 81 */ 71 #define PACKET_SUFFIX(packet, type) (type *) packet_suffix((packet), sizeof(type)) 82 #define PACKET_SUFFIX(packet, type) \ 83 (type *) packet_suffix((packet), sizeof(type)) 72 84 73 85 /** Trims the actual packet content by the specified prefix and suffix types. 74 * The wrapper of the packet_trim() function. 75 * @param[in] packet The packet to be trimmed. 76 * @param[in] prefix The type of the prefix to be removed from the beginning of the packet content. 77 * @param[in] suffix The type of the suffix to be removed from the end of the packet content. 78 * @returns EOK on success. 79 * @returns EINVAL if the packet is not valid. 80 * @returns ENOMEM if there is not enough memory left. 86 * 87 * The wrapper of the packet_trim() function. 88 * 89 * @param[in] packet The packet to be trimmed. 90 * @param[in] prefix The type of the prefix to be removed from the beginning 91 * of the packet content. 92 * @param[in] suffix The type of the suffix to be removed from the end of 93 * the packet content. 94 * @returns EOK on success. 95 * @returns EINVAL if the packet is not valid. 96 * @returns ENOMEM if there is not enough memory left. 81 97 */ 82 #define PACKET_TRIM(packet, prefix, suffix) packet_trim((packet), sizeof(prefix), sizeof(suffix)) 98 #define PACKET_TRIM(packet, prefix, suffix) \ 99 packet_trim((packet), sizeof(prefix), sizeof(suffix)) 83 100 84 /** Allocates the specified space right before the actual packet content and returns its pointer. 85 * @param[in] packet The packet to be used. 86 * @param[in] length The space length to be allocated at the beginning of the packet content. 87 * @returns The pointer to the allocated memory. 88 * @returns NULL if there is not enough memory left. 89 */ 90 extern void * packet_prefix(packet_t packet, size_t length); 91 92 /** Allocates the specified space right after the actual packet content and returns its pointer. 93 * @param[in] packet The packet to be used. 94 * @param[in] length The space length to be allocated at the end of the packet content. 95 * @returns The pointer to the allocated memory. 96 * @returns NULL if there is not enough memory left. 97 */ 98 extern void * packet_suffix(packet_t packet, size_t length); 99 100 /** Trims the actual packet content by the specified prefix and suffix lengths. 101 * @param[in] packet The packet to be trimmed. 102 * @param[in] prefix The prefix length to be removed from the beginning of the packet content. 103 * @param[in] suffix The suffix length to be removed from the end of the packet content. 104 * @returns EOK on success. 105 * @returns EINVAL if the packet is not valid. 106 * @returns ENOMEM if there is not enough memory left. 107 */ 108 extern int packet_trim(packet_t packet, size_t prefix, size_t suffix); 109 110 /** Copies the specified data to the beginning of the actual packet content. 111 * Pushes the content end if needed. 112 * @param[in] packet The packet to be filled. 113 * @param[in] data The data to be copied. 114 * @param[in] length The length of the copied data. 115 * @returns EOK on success. 116 * @returns EINVAL if the packet is not valid. 117 * @returns ENOMEM if there is not enough memory left. 118 */ 119 extern int packet_copy_data(packet_t packet, const void * data, size_t length); 120 121 /** Returns the packet identifier. 122 * @param[in] packet The packet. 123 * @returns The packet identifier. 124 * @returns Zero (0) if the packet is not valid. 125 */ 126 extern packet_id_t packet_get_id(const packet_t packet); 127 128 /** Returns the packet content length. 129 * @param[in] packet The packet. 130 * @returns The packet content length in bytes. 131 * @returns Zero (0) if the packet is not valid. 132 */ 133 extern size_t packet_get_data_length(const packet_t packet); 134 135 /** Returns the pointer to the beginning of the packet content. 136 * @param[in] packet The packet. 137 * @returns The pointer to the beginning of the packet content. 138 * @returns NULL if the packet is not valid. 139 */ 140 extern void * packet_get_data(const packet_t packet); 141 142 /** Returns the stored packet addresses and their length. 143 * @param[in] packet The packet. 144 * @param[out] src The source address. May be NULL if not desired. 145 * @param[out] dest The destination address. May be NULL if not desired. 146 * @returns The stored addresses length. 147 * @returns Zero (0) if the addresses are not present. 148 * @returns EINVAL if the packet is not valid. 149 */ 150 extern int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest); 151 152 /** Sets the packet addresses. 153 * @param[in] packet The packet. 154 * @param[in] src The new source address. May be NULL. 155 * @param[in] dest The new destination address. May be NULL. 156 * @param[in] addr_len The addresses length. 157 * @returns EOK on success. 158 * @returns EINVAL if the packet is not valid. 159 * @returns ENOMEM if there is not enough memory left. 160 */ 161 extern int packet_set_addr(packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len); 162 163 /** Translates the packet identifier to the packet reference. 164 * Tries to find mapping first. 165 * Contacts the packet server to share the packet if the mapping is not present. 166 * @param[in] phone The packet server module phone. 167 * @param[out] packet The packet reference. 168 * @param[in] packet_id The packet identifier. 169 * @returns EOK on success. 170 * @returns EINVAL if the packet parameter is NULL. 171 * @returns Other error codes as defined for the NET_PACKET_GET_SIZE message. 172 * @returns Other error codes as defined for the packet_return() function. 173 */ 174 extern int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id); 175 176 /** Obtains the packet of the given dimensions. 177 * Contacts the packet server to return the appropriate packet. 178 * @param[in] phone The packet server module phone. 179 * @param[in] addr_len The source and destination addresses maximal length in bytes. 180 * @param[in] max_prefix The maximal prefix length in bytes. 181 * @param[in] max_content The maximal content length in bytes. 182 * @param[in] max_suffix The maximal suffix length in bytes. 183 * @returns The packet reference. 184 * @returns NULL on error. 185 */ 186 extern packet_t packet_get_4_remote(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix); 187 188 /** Obtains the packet of the given content size. 189 * Contacts the packet server to return the appropriate packet. 190 * @param[in] phone The packet server module phone. 191 * @param[in] content The maximal content length in bytes. 192 * @returns The packet reference. 193 * @returns NULL on error. 194 */ 195 extern packet_t packet_get_1_remote(int phone, size_t content); 196 197 /** Releases the packet queue. 198 * All packets in the queue are marked as free for use. 199 * The packet queue may be one packet only. 200 * The module should not use the packets after this point until they are received or obtained again. 201 * @param[in] phone The packet server module phone. 202 * @param[in] packet_id The packet identifier. 203 */ 204 extern void pq_release_remote(int phone, packet_id_t packet_id); 205 206 /** Returns the packet copy. 207 * Copies the addresses, data, order and metric values. 208 * Does not copy the queue placement. 209 * @param[in] phone The packet server module phone. 210 * @param[in] packet The original packet. 211 * @returns The packet copy. 212 * @returns NULL on error. 213 */ 101 extern void *packet_prefix(packet_t, size_t); 102 extern void *packet_suffix(packet_t, size_t); 103 extern int packet_trim(packet_t, size_t, size_t); 104 extern int packet_copy_data(packet_t, const void *, size_t); 105 extern packet_id_t packet_get_id(const packet_t); 106 extern size_t packet_get_data_length(const packet_t); 107 extern void *packet_get_data(const packet_t); 108 extern int packet_get_addr(const packet_t, uint8_t **, uint8_t **); 109 extern int packet_set_addr(packet_t, const uint8_t *, const uint8_t *, size_t); 214 110 extern packet_t packet_get_copy(int phone, packet_t packet); 215 111 -
uspace/lib/net/include/packet_remote.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup packet29 /** @addtogroup libnet 30 30 * @{ 31 31 */ 32 32 33 #ifndef __NET_PACKET_REMOTE_H__34 #define __NET_PACKET_REMOTE_H__33 #ifndef LIBNET_PACKET_REMOTE_H_ 34 #define LIBNET_PACKET_REMOTE_H_ 35 35 36 36 #include <net/packet.h> 37 #include <sys/types.h> 37 38 38 39 extern int packet_translate_remote(int, packet_ref, packet_id_t); -
uspace/lib/net/include/socket_core.h
ref689ef0 ra7a85d16 27 27 */ 28 28 29 /** @addtogroup socket29 /** @addtogroup libnet 30 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * Socket common core. 35 35 */ 36 36 37 #ifndef __NET_SOCKET_CORE_H__38 #define __NET_SOCKET_CORE_H__37 #ifndef LIBNET_SOCKET_CORE_H_ 38 #define LIBNET_SOCKET_CORE_H_ 39 39 40 40 #include <sys/types.h> 41 42 #include <net/in.h>43 #include <net/device.h>44 41 #include <adt/generic_char_map.h> 45 42 #include <adt/dynamic_fifo.h> 46 43 #include <adt/int_map.h> 44 #include <net/in.h> 45 #include <net/device.h> 47 46 #include <net/packet.h> 48 47 49 /** Initial size of the received packet queue. 50 */ 48 /** Initial size of the received packet queue. */ 51 49 #define SOCKET_INITIAL_RECEIVED_SIZE 4 52 50 53 /** Maximum size of the received packet queue. 54 */ 55 #define SOCKET_MAX_RECEIVED_SIZE 0 51 /** Maximum size of the received packet queue. */ 52 #define SOCKET_MAX_RECEIVED_SIZE 0 56 53 57 /** Initial size of the sockets for acceptance queue. 58 */ 54 /** Initial size of the sockets for acceptance queue. */ 59 55 #define SOCKET_INITIAL_ACCEPTED_SIZE 1 60 56 61 /** Maximum size of the sockets for acceptance queue. 62 */ 63 #define SOCKET_MAX_ACCEPTEDED_SIZE 0 57 /** Maximum size of the sockets for acceptance queue. */ 58 #define SOCKET_MAX_ACCEPTEDED_SIZE 0 64 59 65 /** Listening sockets' port map key. 66 */ 60 /** Listening sockets' port map key. */ 67 61 #define SOCKET_MAP_KEY_LISTENING "L" 68 62 69 63 /** Type definition of the socket core. 70 * 64 * @see socket_core 71 65 */ 72 typedef struct socket_core 66 typedef struct socket_core socket_core_t; 73 67 74 68 /** Type definition of the socket core pointer. 75 * 69 * @see socket_core 76 70 */ 77 typedef socket_core_t * 71 typedef socket_core_t *socket_core_ref; 78 72 79 73 /** Type definition of the socket port. 80 * 74 * @see socket_port 81 75 */ 82 typedef struct socket_port 76 typedef struct socket_port socket_port_t; 83 77 84 78 /** Type definition of the socket port pointer. 85 * 79 * @see socket_port 86 80 */ 87 typedef socket_port_t * 81 typedef socket_port_t *socket_port_ref; 88 82 89 /** Socket core. 90 */ 91 struct socket_core{ 92 /** Socket identifier. 93 */ 83 /** Socket core. */ 84 struct socket_core { 85 /** Socket identifier. */ 94 86 int socket_id; 95 /** Client application phone. 96 */ 87 /** Client application phone. */ 97 88 int phone; 98 /** Bound port. 99 */ 89 /** Bound port. */ 100 90 int port; 101 /** Received packets queue. 102 */ 91 /** Received packets queue. */ 103 92 dyn_fifo_t received; 104 /** Sockets for acceptance queue. 105 */ 93 /** Sockets for acceptance queue. */ 106 94 dyn_fifo_t accepted; 107 /** Protocol specific data. 108 */ 109 void * specific_data; 110 /** Socket ports map key. 111 */ 112 const char * key; 113 /** Length of the Socket ports map key. 114 */ 95 /** Protocol specific data. */ 96 void *specific_data; 97 /** Socket ports map key. */ 98 const char *key; 99 /** Length of the Socket ports map key. */ 115 100 size_t key_length; 116 101 }; 117 102 118 103 /** Sockets map. 119 * 104 * The key is the socket identifier. 120 105 */ 121 106 INT_MAP_DECLARE(socket_cores, socket_core_t); 122 107 123 108 /** Bount port sockets map. 124 * The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas the other use the remote addresses. 109 * 110 * The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas 111 * the other use the remote addresses. 125 112 */ 126 113 GENERIC_CHAR_MAP_DECLARE(socket_port_map, socket_core_ref); 127 114 128 115 /** Ports map. 129 * 116 * The key is the port number. 130 117 */ 131 118 INT_MAP_DECLARE(socket_ports, socket_port_t); 132 119 133 /** Destroys local sockets. 134 * Releases all buffered packets and calls the release function for each of the sockets. 135 * @param[in] packet_phone The packet server phone to release buffered packets. 136 * @param[in] local_sockets The local sockets to be destroyed. 137 * @param[in,out] global_sockets The global sockets to be updated. 138 * @param[in] socket_release The client release callback function. 139 */ 140 extern void socket_cores_release(int packet_phone, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket)); 141 142 /** Binds the socket to the port. 143 * The address port is used if set, a free port is used if not. 144 * @param[in] local_sockets The local sockets to be searched. 145 * @param[in,out] global_sockets The global sockets to be updated. 146 * @param[in] socket_id The new socket identifier. 147 * @param[in] addr The address to be bound to. 148 * @param[in] addrlen The address length. 149 * @param[in] free_ports_start The minimum free port. 150 * @param[in] free_ports_end The maximum free port. 151 * @param[in] last_used_port The last used free port. 152 * @returns EOK on success. 153 * @returns ENOTSOCK if the socket was not found. 154 * @returns EAFNOSUPPORT if the address family is not supported. 155 * @returns EADDRINUSE if the port is already in use. 156 * @returns Other error codes as defined for the socket_bind_free_port() function. 157 * @returns Other error codes as defined for the socket_bind_insert() function. 158 */ 159 extern int socket_bind(socket_cores_ref local_sockets, socket_ports_ref global_sockets, int socket_id, void * addr, size_t addrlen, int free_ports_start, int free_ports_end, int last_used_port); 160 161 /** Binds the socket to a free port. 162 * The first free port is used. 163 * @param[in,out] global_sockets The global sockets to be updated. 164 * @param[in,out] socket The socket to be bound. 165 * @param[in] free_ports_start The minimum free port. 166 * @param[in] free_ports_end The maximum free port. 167 * @param[in] last_used_port The last used free port. 168 * @returns EOK on success. 169 * @returns ENOTCONN if no free port was found. 170 * @returns Other error codes as defined for the socket_bind_insert() function. 171 */ 172 extern int socket_bind_free_port(socket_ports_ref global_sockets, socket_core_ref socket, int free_ports_start, int free_ports_end, int last_used_port); 173 174 /** Creates a new socket. 175 * @param[in,out] local_sockets The local sockets to be updated. 176 * @param[in] app_phone The application phone. 177 * @param[in] specific_data The socket specific data. 178 * @param[in,out] socket_id The new socket identifier. A new identifier is chosen if set to zero (0) or negative. A negative identifier is chosen if set to negative. 179 * @returns EOK on success. 180 * @returns EINVAL if the socket_id parameter is NULL. 181 * @returns ENOMEM if there is not enough memory left. 182 */ 183 extern int socket_create(socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id); 184 185 /** Destroys the socket. 186 * If the socket is bound, the port is released. 187 * Releases all buffered packets, calls the release function and removes the socket from the local sockets. 188 * @param[in] packet_phone The packet server phone to release buffered packets. 189 * @param[in] socket_id The socket identifier. 190 * @param[in,out] local_sockets The local sockets to be updated. 191 * @param[in,out] global_sockets The global sockets to be updated. 192 * @param[in] socket_release The client release callback function. 193 * @returns EOK on success. 194 * @returns ENOTSOCK if the socket is not found. 195 */ 196 extern int socket_destroy(int packet_phone, int socket_id, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket)); 197 198 /** Replies the packet or the packet queue data to the application via the socket. 199 * Uses the current message processing fibril. 200 * @param[in] packet The packet to be transfered. 201 * @param[out] length The total data length. 202 * @returns EOK on success. 203 * @returns EBADMEM if the length parameter is NULL. 204 * @returns ENOMEM if there is not enough memory left. 205 * @returns Other error codes as defined for the data_reply() function. 206 */ 207 extern int socket_reply_packets(packet_t packet, size_t * length); 208 209 /** Finds the bound port socket. 210 * @param[in] global_sockets The global sockets to be searched. 211 * @param[in] port The port number. 212 * @param[in] key The socket key identifier. 213 * @param[in] key_length The socket key length. 214 * @returns The found socket. 215 * @returns NULL if no socket was found. 216 */ 217 extern socket_core_ref socket_port_find(socket_ports_ref global_sockets, int port, const char * key, size_t key_length); 218 219 /** Releases the socket port. 220 * If the socket is bound the port entry is released. 221 * If there are no more port entries the port is release. 222 * @param[in] global_sockets The global sockets to be updated. 223 * @param[in] socket The socket to be unbound. 224 */ 225 extern void socket_port_release(socket_ports_ref global_sockets, socket_core_ref socket); 226 227 /** Adds the socket to an already bound port. 228 * @param[in] global_sockets The global sockets to be updated. 229 * @param[in] port The port number to be bound to. 230 * @param[in] socket The socket to be added. 231 * @param[in] key The socket key identifier. 232 * @param[in] key_length The socket key length. 233 * @returns EOK on success. 234 * @returns ENOENT if the port is not already used. 235 * @returns Other error codes as defined for the socket_port_add_core() function. 236 */ 237 extern int socket_port_add(socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length); 120 extern void socket_cores_release(int, socket_cores_ref, socket_ports_ref, 121 void (*)(socket_core_ref)); 122 extern int socket_bind(socket_cores_ref, socket_ports_ref, int, void *, size_t, 123 int, int, int); 124 extern int socket_bind_free_port(socket_ports_ref, socket_core_ref, int, int, 125 int); 126 extern int socket_create(socket_cores_ref, int, void *, int *); 127 extern int socket_destroy(int, int, socket_cores_ref, socket_ports_ref, 128 void (*)(socket_core_ref)); 129 extern int socket_reply_packets(packet_t, size_t *); 130 extern socket_core_ref socket_port_find(socket_ports_ref, int, const char *, 131 size_t); 132 extern void socket_port_release(socket_ports_ref, socket_core_ref); 133 extern int socket_port_add(socket_ports_ref, int, socket_core_ref, 134 const char *, size_t); 238 135 239 136 #endif -
uspace/lib/net/include/tl_interface.h
ref689ef0 ra7a85d16 40 40 #include <async.h> 41 41 #include <ipc/services.h> 42 #include <ipc/tl.h> 42 43 43 44 #include <generic.h> … … 45 46 #include <net/packet.h> 46 47 #include <packet_client.h> 47 #include <tl_messages.h>48 48 49 49 /** @name Transport layer module interface -
uspace/lib/net/netif/netif_local.c
ref689ef0 ra7a85d16 42 42 #include <ipc/ipc.h> 43 43 #include <ipc/services.h> 44 #include <ipc/netif.h> 44 45 #include <err.h> 45 46 … … 53 54 #include <nil_interface.h> 54 55 #include <netif_local.h> 55 #include <netif_messages.h>56 56 #include <netif_interface.h> 57 57 -
uspace/lib/net/netif/netif_remote.c
ref689ef0 ra7a85d16 36 36 37 37 #include <ipc/services.h> 38 #include <ipc/netif.h> 38 39 39 40 #include <net/modules.h> … … 43 44 #include <net/device.h> 44 45 #include <netif_remote.h> 45 #include <netif_messages.h>46 46 #include <generic.h> 47 47 -
uspace/lib/net/nil/nil_remote.c
ref689ef0 ra7a85d16 38 38 #include <nil_remote.h> 39 39 #include <nil_interface.h> 40 #include <nil_messages.h>41 40 #include <generic.h> 42 41 #include <net/device.h> 43 42 #include <net/packet.h> 44 43 #include <packet_client.h> 44 45 #include <ipc/nil.h> 45 46 46 47 /** Notify the network interface layer about the device state change. -
uspace/srv/net/il/arp/arp.c
ref689ef0 ra7a85d16 46 46 #include <ipc/services.h> 47 47 #include <ipc/net.h> 48 #include <ipc/arp.h> 49 #include <ipc/il.h> 48 50 #include <byteorder.h> 49 51 #include <err.h> … … 58 60 #include <packet_client.h> 59 61 #include <packet_remote.h> 60 #include <il_messages.h>61 62 #include <il_interface.h> 62 63 #include <il_local.h> 63 #include <arp_messages.h>64 64 65 65 #include "arp.h" … … 534 534 } 535 535 return EOK; 536 }537 538 task_id_t arp_task_get_id(void){539 return task_get_id();540 536 } 541 537 -
uspace/srv/net/il/arp/arp_module.c
ref689ef0 ra7a85d16 80 80 81 81 async_set_client_connection(client_connection); 82 arp_globals.net_phone = net_connect_module( SERVICE_NETWORKING);82 arp_globals.net_phone = net_connect_module(); 83 83 ERROR_PROPAGATE(pm_init()); 84 84 -
uspace/srv/net/il/ip/ip.c
ref689ef0 ra7a85d16 45 45 #include <ipc/services.h> 46 46 #include <ipc/net.h> 47 #include <ipc/nil.h> 48 #include <ipc/il.h> 49 #include <ipc/ip.h> 47 50 #include <sys/types.h> 48 51 #include <byteorder.h> … … 71 74 #include <packet_client.h> 72 75 #include <packet_remote.h> 73 #include <nil_messages.h>74 #include <il_messages.h>75 76 #include <il_local.h> 76 #include <ip_local.h>77 77 78 78 #include "ip.h" 79 79 #include "ip_header.h" 80 #include "ip_messages.h"81 80 #include "ip_module.h" 81 #include "ip_local.h" 82 82 83 83 /** IP module name. … … 423 423 ip_globals.client_connection = client_connection; 424 424 ERROR_PROPAGATE(modules_initialize(&ip_globals.modules)); 425 ERROR_PROPAGATE(add_module(NULL, &ip_globals.modules, ARP_NAME, ARP_FILENAME, SERVICE_ARP, arp_task_get_id(), arp_connect_module));425 ERROR_PROPAGATE(add_module(NULL, &ip_globals.modules, ARP_NAME, ARP_FILENAME, SERVICE_ARP, 0, arp_connect_module)); 426 426 fibril_rwlock_write_unlock(&ip_globals.lock); 427 427 return EOK; -
uspace/srv/net/il/ip/ip_local.h
ref689ef0 ra7a85d16 31 31 */ 32 32 33 #ifndef __NET_IP_LOCAL_H__34 #define __NET_IP_LOCAL_H__33 #ifndef NET_IP_LOCAL_H_ 34 #define NET_IP_LOCAL_H_ 35 35 36 36 #include <async.h> -
uspace/srv/net/il/ip/ip_module.c
ref689ef0 ra7a85d16 79 79 80 80 async_set_client_connection(client_connection); 81 ip_globals.net_phone = net_connect_module( SERVICE_NETWORKING);81 ip_globals.net_phone = net_connect_module(); 82 82 ERROR_PROPAGATE(pm_init()); 83 83 -
uspace/srv/net/net/net.c
ref689ef0 ra7a85d16 46 46 47 47 #include <ipc/ipc.h> 48 #include <ipc/services.h> 48 49 #include <ipc/net.h> 49 #include <ipc/services.h> 50 #include <ipc/net_net.h> 51 #include <ipc/il.h> 50 52 51 53 #include <net/modules.h> … … 55 57 #include <adt/module_map.h> 56 58 #include <net/packet.h> 57 #include <il_messages.h>58 59 #include <netif_remote.h> 59 60 #include <net/device.h> … … 61 62 #include <net_interface.h> 62 63 #include <ip_interface.h> 63 #include <net_net_messages.h>64 64 65 65 #include "net.h" -
uspace/srv/net/netif/lo/lo.c
ref689ef0 ra7a85d16 43 43 #include <ipc/ipc.h> 44 44 #include <ipc/services.h> 45 #include <ipc/nil.h> 45 46 46 47 #include <net/modules.h> … … 49 50 #include <net/device.h> 50 51 #include <nil_interface.h> 51 #include <nil_messages.h>52 52 #include <netif_interface.h> 53 53 #include <netif_local.h> -
uspace/srv/net/netstart/netstart.c
ref689ef0 ra7a85d16 48 48 #include <ipc/ipc.h> 49 49 #include <ipc/services.h> 50 #include <ipc/net_net.h> 50 51 51 52 #include <net/modules.h> 52 #include <net_net_messages.h>53 53 54 54 #include "self_test.h" -
uspace/srv/net/nil/eth/eth_module.c
ref689ef0 ra7a85d16 63 63 64 64 async_set_client_connection(client_connection); 65 int net_phone = net_connect_module( SERVICE_NETWORKING);65 int net_phone = net_connect_module(); 66 66 ERROR_PROPAGATE(pm_init()); 67 67 -
uspace/srv/net/nil/nildummy/nildummy_module.c
ref689ef0 ra7a85d16 71 71 72 72 async_set_client_connection(client_connection); 73 int net_phone = net_connect_module( SERVICE_NETWORKING);73 int net_phone = net_connect_module(); 74 74 ERROR_PROPAGATE(pm_init()); 75 75 -
uspace/srv/net/tl/icmp/icmp.c
ref689ef0 ra7a85d16 45 45 #include <ipc/services.h> 46 46 #include <ipc/net.h> 47 #include <ipc/tl.h> 47 48 #include <ipc/icmp.h> 48 49 #include <sys/time.h> … … 69 70 #include <ip_interface.h> 70 71 #include <net_interface.h> 71 #include <tl_messages.h>72 72 #include <tl_interface.h> 73 73 #include <tl_local.h> -
uspace/srv/net/tl/icmp/icmp_module.c
ref689ef0 ra7a85d16 69 69 70 70 async_set_client_connection(client_connection); 71 icmp_globals.net_phone = net_connect_module( SERVICE_NETWORKING);71 icmp_globals.net_phone = net_connect_module(); 72 72 if(icmp_globals.net_phone < 0){ 73 73 return icmp_globals.net_phone; -
uspace/srv/net/tl/tcp/tcp.c
ref689ef0 ra7a85d16 48 48 #include <ipc/services.h> 49 49 #include <ipc/net.h> 50 #include <ipc/tl.h> 50 51 #include <ipc/socket.h> 51 52 … … 68 69 #include <socket_core.h> 69 70 #include <tl_common.h> 70 #include <tl_messages.h>71 71 #include <tl_local.h> 72 72 #include <tl_interface.h> -
uspace/srv/net/tl/tcp/tcp_module.c
ref689ef0 ra7a85d16 71 71 72 72 async_set_client_connection(client_connection); 73 tcp_globals.net_phone = net_connect_module( SERVICE_NETWORKING);73 tcp_globals.net_phone = net_connect_module(); 74 74 ERROR_PROPAGATE(pm_init()); 75 75 -
uspace/srv/net/tl/udp/udp.c
ref689ef0 ra7a85d16 43 43 #include <ipc/services.h> 44 44 #include <ipc/net.h> 45 #include <ipc/tl.h> 45 46 #include <ipc/socket.h> 46 47 #include <errno.h> … … 67 68 #include <tl_local.h> 68 69 #include <tl_interface.h> 69 #include <tl_messages.h>70 70 71 71 #include "udp.h" -
uspace/srv/net/tl/udp/udp_module.c
ref689ef0 ra7a85d16 69 69 70 70 async_set_client_connection(client_connection); 71 udp_globals.net_phone = net_connect_module( SERVICE_NETWORKING);71 udp_globals.net_phone = net_connect_module(); 72 72 if(udp_globals.net_phone < 0){ 73 73 return udp_globals.net_phone;
Note:
See TracChangeset
for help on using the changeset viewer.