Changes in uspace/srv/net/netif/lo/lo.c [14f1db0:25271006] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/netif/lo/lo.c
r14f1db0 r25271006 28 28 29 29 /** @addtogroup lo 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * Loopback network interface implementation. 35 35 */ 36 36 37 37 #include <async.h> 38 38 #include <errno.h> 39 #include <err.h> 39 40 #include <stdio.h> 40 41 #include <str.h> … … 42 43 #include <ipc/ipc.h> 43 44 #include <ipc/services.h> 44 45 #include <net_err.h> 46 #include <net_messages.h> 47 #include <net_modules.h> 45 #include <ipc/nil.h> 46 47 #include <net/modules.h> 48 48 #include <adt/measured_strings.h> 49 #include <packet /packet_client.h>50 #include <net _device.h>49 #include <packet_client.h> 50 #include <net/device.h> 51 51 #include <nil_interface.h> 52 #include <nil_messages.h>53 52 #include <netif_interface.h> 54 53 #include <netif_local.h> 55 54 56 /** Default hardware address. 57 */ 55 /** Default hardware address. */ 58 56 #define DEFAULT_ADDR "\0\0\0\0\0\0" 59 57 60 /** Default address length. 61 */ 58 /** Default address length. */ 62 59 #define DEFAULT_ADDR_LEN (sizeof(DEFAULT_ADDR) / sizeof(char)) 63 60 64 /** Loopback module name. 65 */ 61 /** Loopback module name. */ 66 62 #define NAME "lo" 67 63 68 /** Network interface global data. 69 */ 64 /** Network interface global data. */ 70 65 netif_globals_t netif_globals; 71 66 72 /** Changes the loopback state. 73 * @param[in] device The device structure. 74 * @param[in] state The new device state. 75 * @returns The new state if changed. 76 * @returns EOK otherwise. 77 */ 78 int change_state_message(netif_device_t * device, device_state_t state); 79 80 /** Creates and returns the loopback network interface structure. 81 * @param[in] device_id The new devce identifier. 82 * @param[out] device The device structure. 83 * @returns EOK on success. 84 * @returns EXDEV if one loopback network interface already exists. 85 * @returns ENOMEM if there is not enough memory left. 86 */ 87 int create(device_id_t device_id, netif_device_t * * device); 88 89 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 67 int 68 netif_specific_message(ipc_callid_t callid, ipc_call_t *call, 69 ipc_call_t *answer, int *answer_count) 70 { 90 71 return ENOTSUP; 91 72 } 92 73 93 int netif_get_addr_message(device_id_t device_id, measured_string_ref address){ 94 if(! address){ 74 int netif_get_addr_message(device_id_t device_id, measured_string_ref address) 75 { 76 if (!address) 95 77 return EBADMEM; 96 }97 78 address->value = str_dup(DEFAULT_ADDR); 98 79 address->length = DEFAULT_ADDR_LEN; … … 100 81 } 101 82 102 int netif_get_device_stats(device_id_t device_id, device_stats_ref stats){ 103 ERROR_DECLARE; 104 105 netif_device_t * device; 106 107 if(! stats){ 83 int netif_get_device_stats(device_id_t device_id, device_stats_ref stats) 84 { 85 ERROR_DECLARE; 86 87 netif_device_t *device; 88 89 if (!stats) 108 90 return EBADMEM; 109 }110 91 ERROR_PROPAGATE(find_device(device_id, &device)); 111 memcpy(stats, (device_stats_ref) device->specific, sizeof(device_stats_t)); 112 return EOK; 113 } 114 115 int change_state_message(netif_device_t * device, device_state_t state) 92 memcpy(stats, (device_stats_ref) device->specific, 93 sizeof(device_stats_t)); 94 return EOK; 95 } 96 97 /** Changes the loopback state. 98 * 99 * @param[in] device The device structure. 100 * @param[in] state The new device state. 101 * @returns The new state if changed. 102 * @returns EOK otherwise. 103 */ 104 static int change_state_message(netif_device_t *device, device_state_t state) 116 105 { 117 106 if (device->state != state) { … … 127 116 } 128 117 129 int create(device_id_t device_id, netif_device_t * * device){ 118 /** Creates and returns the loopback network interface structure. 119 * 120 * @param[in] device_id The new devce identifier. 121 * @param[out] device The device structure. 122 * @returns EOK on success. 123 * @returns EXDEV if one loopback network interface already exists. 124 * @returns ENOMEM if there is not enough memory left. 125 */ 126 static int create(device_id_t device_id, netif_device_t **device) 127 { 130 128 int index; 131 129 132 if (netif_device_map_count(&netif_globals.device_map) > 0){130 if (netif_device_map_count(&netif_globals.device_map) > 0) 133 131 return EXDEV; 134 }else{ 135 *device = (netif_device_t *) malloc(sizeof(netif_device_t)); 136 if(!(*device)){ 137 return ENOMEM; 138 } 139 (** device).specific = malloc(sizeof(device_stats_t)); 140 if(! (** device).specific){ 141 free(*device); 142 return ENOMEM; 143 } 144 null_device_stats((device_stats_ref)(** device).specific); 145 (** device).device_id = device_id; 146 (** device).nil_phone = -1; 147 (** device).state = NETIF_STOPPED; 148 index = netif_device_map_add(&netif_globals.device_map, (** device).device_id, * device); 149 if(index < 0){ 150 free(*device); 151 free((** device).specific); 152 *device = NULL; 153 return index; 154 } 155 } 156 return EOK; 157 } 158 159 int netif_initialize(void){ 132 133 *device = (netif_device_t *) malloc(sizeof(netif_device_t)); 134 if (!*device) 135 return ENOMEM; 136 (*device)->specific = (device_stats_t *) malloc(sizeof(device_stats_t)); 137 if (!(*device)->specific) { 138 free(*device); 139 return ENOMEM; 140 } 141 null_device_stats((device_stats_ref) (*device)->specific); 142 (*device)->device_id = device_id; 143 (*device)->nil_phone = -1; 144 (*device)->state = NETIF_STOPPED; 145 index = netif_device_map_add(&netif_globals.device_map, 146 (*device)->device_id, *device); 147 if (index < 0) { 148 free(*device); 149 free((*device)->specific); 150 *device = NULL; 151 return index; 152 } 153 154 return EOK; 155 } 156 157 int netif_initialize(void) 158 { 160 159 ipcarg_t phonehash; 161 160 … … 163 162 } 164 163 165 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){ 166 ERROR_DECLARE; 167 168 netif_device_t * device; 164 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io) 165 { 166 ERROR_DECLARE; 167 168 netif_device_t *device; 169 169 170 170 // create a new device … … 175 175 } 176 176 177 int netif_send_message(device_id_t device_id, packet_t packet, services_t sender){ 178 ERROR_DECLARE; 179 180 netif_device_t * device; 177 int netif_send_message(device_id_t device_id, packet_t packet, services_t sender) 178 { 179 ERROR_DECLARE; 180 181 netif_device_t *device; 181 182 size_t length; 182 183 packet_t next; … … 184 185 185 186 ERROR_PROPAGATE(find_device(device_id, &device)); 186 if (device->state != NETIF_ACTIVE){187 if (device->state != NETIF_ACTIVE) { 187 188 netif_pq_release(packet_get_id(packet)); 188 189 return EFORWARD; 189 190 } 190 191 next = packet; 191 do {192 ++ ((device_stats_ref) device->specific)->send_packets;193 ++ ((device_stats_ref) device->specific)->receive_packets;192 do { 193 ((device_stats_ref) device->specific)->send_packets++; 194 ((device_stats_ref) device->specific)->receive_packets++; 194 195 length = packet_get_data_length(next); 195 196 ((device_stats_ref) device->specific)->send_bytes += length; 196 197 ((device_stats_ref) device->specific)->receive_bytes += length; 197 198 next = pq_next(next); 198 } while(next);199 } while(next); 199 200 phone = device->nil_phone; 200 201 fibril_rwlock_write_unlock(&netif_globals.lock); 201 202 nil_received_msg(phone, device_id, packet, sender); 202 203 fibril_rwlock_write_lock(&netif_globals.lock); 203 return EOK; 204 } 205 206 int netif_start_message(netif_device_t * device){ 204 205 return EOK; 206 } 207 208 int netif_start_message(netif_device_t *device) 209 { 207 210 return change_state_message(device, NETIF_ACTIVE); 208 211 } 209 212 210 int netif_stop_message(netif_device_t * device){ 213 int netif_stop_message(netif_device_t *device) 214 { 211 215 return change_state_message(device, NETIF_STOPPED); 212 216 } … … 214 218 /** Default thread for new connections. 215 219 * 216 * @param[in] iid The initial message identifier. 217 * @param[in] icall The initial message call structure. 218 * 220 * @param[in] iid The initial message identifier. 221 * @param[in] icall The initial message call structure. 219 222 */ 220 223 static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall) … … 226 229 ipc_answer_0(iid, EOK); 227 230 228 while (true) {231 while (true) { 229 232 ipc_call_t answer; 230 233 int answer_count; … … 241 244 &answer_count); 242 245 243 /* End if said to either by the message or the processing result */ 244 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP)) 246 /* 247 * End if told to either by the message or the processing 248 * result. 249 */ 250 if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || 251 (res == EHANGUP)) 245 252 return; 246 253 … … 255 262 256 263 /* Start the module */ 257 if (ERROR_OCCURRED(netif_module_start(netif_client_connection))) 258 return ERROR_CODE; 259 264 ERROR_PROPAGATE(netif_module_start(netif_client_connection)); 260 265 return EOK; 261 266 }
Note:
See TracChangeset
for help on using the changeset viewer.