Changeset 0e94b979 in mainline
- Timestamp:
- 2012-03-08T21:12:44Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 291c792
- Parents:
- a88a6eac
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/inetcfg/inetcfg.c
ra88a6eac r0e94b979 40 40 #include <loc.h> 41 41 #include <stdio.h> 42 #include <stdlib.h> 42 43 #include <str_error.h> 43 44 #include <sys/types.h> … … 86 87 } 87 88 89 static int naddr_format(inet_naddr_t *naddr, char **bufp) 90 { 91 int rc; 92 93 rc = asprintf(bufp, "%d.%d.%d.%d/%d", naddr->ipv4 >> 24, 94 (naddr->ipv4 >> 16) & 0xff, (naddr->ipv4 >> 8) & 0xff, 95 naddr->ipv4 & 0xff, naddr->bits); 96 97 if (rc < 0) 98 return ENOMEM; 99 100 return EOK; 101 } 102 88 103 static int addr_create_static(int argc, char *argv[]) 89 104 { … … 129 144 printf(NAME ": Failed creating static address '%s' (%d)\n", 130 145 "v4s", rc); 131 return 1; 132 } 146 return EIO; 147 } 148 149 return EOK; 150 } 151 152 static int addr_list(void) 153 { 154 sysarg_t *addr_list; 155 inet_addr_info_t ainfo; 156 inet_link_info_t linfo; 157 158 size_t count; 159 size_t i; 160 int rc; 161 char *astr; 162 163 rc = inetcfg_get_addr_list(&addr_list, &count); 164 if (rc != EOK) { 165 printf(NAME ": Failed getting address list.\n"); 166 return rc; 167 } 168 169 for (i = 0; i < count; i++) { 170 rc = inetcfg_addr_get(addr_list[i], &ainfo); 171 if (rc != EOK) { 172 printf("Failed getting properties of address %zu.\n", 173 (size_t)addr_list[i]); 174 continue; 175 } 176 177 rc = inetcfg_link_get(ainfo.ilink, &linfo); 178 if (rc != EOK) { 179 printf("Failed getting properties of link %zu.\n", 180 (size_t)ainfo.ilink); 181 continue; 182 } 183 184 rc = naddr_format(&ainfo.naddr, &astr); 185 if (rc != EOK) { 186 printf("Memory allocation failed.\n"); 187 goto out; 188 } 189 190 printf("%s %s %s\n", astr, linfo.name, 191 ainfo.name); 192 193 free(astr); 194 free(ainfo.name); 195 free(linfo.name); 196 } 197 out: 198 free(addr_list); 133 199 134 200 return EOK; … … 138 204 { 139 205 int rc; 140 141 if (argc < 2) {142 printf(NAME ": Missing argument.\n");143 print_syntax();144 return 1;145 }146 206 147 207 rc = inetcfg_init(); … … 150 210 rc); 151 211 return 1; 212 } 213 214 if (argc < 2) { 215 rc = addr_list(); 216 if (rc != EOK) 217 return 1; 218 return 0; 152 219 } 153 220 -
uspace/lib/c/generic/inetcfg.c
ra88a6eac r0e94b979 35 35 #include <loc.h> 36 36 #include <stdlib.h> 37 #include <str.h> 37 38 38 39 static async_sess_t *inetcfg_sess = NULL; … … 156 157 int inetcfg_addr_get(sysarg_t addr_id, inet_addr_info_t *ainfo) 157 158 { 158 sysarg_t ipv4, bits; 159 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 160 161 int rc = async_req_1_2(exch, INETCFG_ADDR_GET, addr_id, 162 &ipv4, &bits); 163 async_exchange_end(exch); 164 165 if (rc != EOK) 166 return rc; 167 168 ainfo->naddr.ipv4 = ipv4; 169 ainfo->naddr.bits = bits; 159 ipc_call_t dreply; 160 sysarg_t dretval; 161 size_t act_size; 162 char name_buf[LOC_NAME_MAXLEN + 1]; 163 164 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 165 166 ipc_call_t answer; 167 aid_t req = async_send_1(exch, INETCFG_ADDR_GET, addr_id, &answer); 168 aid_t dreq = async_data_read(exch, name_buf, LOC_NAME_MAXLEN, &dreply); 169 async_wait_for(dreq, &dretval); 170 171 async_exchange_end(exch); 172 173 if (dretval != EOK) { 174 async_wait_for(req, NULL); 175 return dretval; 176 } 177 178 sysarg_t retval; 179 async_wait_for(req, &retval); 180 181 if (retval != EOK) 182 return retval; 183 184 act_size = IPC_GET_ARG2(dreply); 185 assert(act_size <= LOC_NAME_MAXLEN); 186 name_buf[act_size] = '\0'; 187 188 ainfo->naddr.ipv4 = IPC_GET_ARG1(answer); 189 ainfo->naddr.bits = IPC_GET_ARG2(answer); 190 ainfo->ilink = IPC_GET_ARG3(answer); 191 ainfo->name = str_dup(name_buf); 192 170 193 return EOK; 171 194 } … … 185 208 int inetcfg_link_get(sysarg_t link_id, inet_link_info_t *linfo) 186 209 { 187 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 188 189 int rc = async_req_1_0(exch, INETCFG_LINK_GET, link_id); 190 async_exchange_end(exch); 191 192 if (rc != EOK) 193 return rc; 194 195 linfo->dummy = 0; 210 ipc_call_t dreply; 211 sysarg_t dretval; 212 size_t act_size; 213 char name_buf[LOC_NAME_MAXLEN + 1]; 214 215 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 216 217 ipc_call_t answer; 218 aid_t req = async_send_1(exch, INETCFG_LINK_GET, link_id, &answer); 219 aid_t dreq = async_data_read(exch, name_buf, LOC_NAME_MAXLEN, &dreply); 220 async_wait_for(dreq, &dretval); 221 222 async_exchange_end(exch); 223 224 if (dretval != EOK) { 225 async_wait_for(req, NULL); 226 return dretval; 227 } 228 229 sysarg_t retval; 230 async_wait_for(req, &retval); 231 232 if (retval != EOK) 233 return retval; 234 235 act_size = IPC_GET_ARG2(dreply); 236 assert(act_size <= LOC_NAME_MAXLEN); 237 name_buf[act_size] = '\0'; 238 239 linfo->name = str_dup(name_buf); 240 196 241 return EOK; 197 242 } -
uspace/lib/c/include/inet/inetcfg.h
ra88a6eac r0e94b979 51 51 /** Network address */ 52 52 inet_naddr_t naddr; 53 /** Link service ID */ 54 sysarg_t ilink; 55 /** Address object name */ 56 char *name; 53 57 } inet_addr_info_t; 54 58 55 59 /** IP link info */ 56 60 typedef struct { 57 int dummy; 61 /** Link service name */ 62 char *name; 58 63 } inet_link_info_t; 59 64 -
uspace/srv/inet/addrobj.c
ra88a6eac r0e94b979 36 36 37 37 #include <bitops.h> 38 #include <errno.h> 38 39 #include <fibril_synch.h> 39 40 #include <io/log.h> … … 47 48 static FIBRIL_MUTEX_INITIALIZE(addr_list_lock); 48 49 static LIST_INITIALIZE(addr_list); 50 static sysarg_t addr_id = 0; 49 51 50 52 static uint32_t inet_netmask(int bits) … … 67 69 68 70 link_initialize(&addr->addr_list); 71 fibril_mutex_lock(&addr_list_lock); 72 addr->id = ++addr_id; 73 fibril_mutex_unlock(&addr_list_lock); 69 74 70 75 return addr; … … 73 78 void inet_addrobj_delete(inet_addrobj_t *addr) 74 79 { 80 if (addr->name != NULL) 81 free(addr->name); 75 82 free(addr); 76 83 } … … 123 130 } 124 131 132 /** Find address object matching address @a addr. 133 * 134 * @param id Address object ID 135 * @return Address object 136 */ 137 inet_addrobj_t *inet_addrobj_get_by_id(sysarg_t id) 138 { 139 log_msg(LVL_DEBUG, "inet_addrobj_get_by_id(%zu)", (size_t)id); 140 141 fibril_mutex_lock(&addr_list_lock); 142 143 list_foreach(addr_list, link) { 144 inet_addrobj_t *naddr = list_get_instance(link, 145 inet_addrobj_t, addr_list); 146 147 if (naddr->id == id) { 148 fibril_mutex_unlock(&addr_list_lock); 149 return naddr; 150 } 151 } 152 153 fibril_mutex_unlock(&addr_list_lock); 154 155 return NULL; 156 } 157 125 158 /** Send datagram to directly reachable destination */ 126 159 int inet_addrobj_send_dgram(inet_addrobj_t *addr, inet_dgram_t *dgram, … … 137 170 } 138 171 172 /** Get IDs of all address objects. */ 173 int inet_addrobj_get_id_list(sysarg_t **rid_list, size_t *rcount) 174 { 175 sysarg_t *id_list; 176 size_t count, i; 177 178 fibril_mutex_lock(&addr_list_lock); 179 count = list_count(&addr_list); 180 181 id_list = calloc(count, sizeof(sysarg_t)); 182 if (id_list == NULL) { 183 fibril_mutex_unlock(&addr_list_lock); 184 return ENOMEM; 185 } 186 187 i = 0; 188 list_foreach(addr_list, link) { 189 inet_addrobj_t *addr = list_get_instance(link, 190 inet_addrobj_t, addr_list); 191 192 id_list[i++] = addr->id; 193 } 194 195 fibril_mutex_unlock(&addr_list_lock); 196 197 *rid_list = id_list; 198 *rcount = count; 199 200 return EOK; 201 } 202 139 203 /** @} 140 204 */ -
uspace/srv/inet/addrobj.h
ra88a6eac r0e94b979 38 38 #define INET_ADDROBJ_H_ 39 39 40 #include <sys/types.h> 40 41 #include "inet.h" 41 42 … … 52 53 extern void inet_addrobj_remove(inet_addrobj_t *); 53 54 extern inet_addrobj_t *inet_addrobj_find(inet_addr_t *, inet_addrobj_find_t); 55 extern inet_addrobj_t *inet_addrobj_get_by_id(sysarg_t); 54 56 extern int inet_addrobj_send_dgram(inet_addrobj_t *, inet_dgram_t *, 55 57 uint8_t, uint8_t, int); 58 extern int inet_addrobj_get_id_list(sysarg_t **, size_t *); 59 56 60 57 61 #endif -
uspace/srv/inet/inet.h
ra88a6eac r0e94b979 68 68 /** Network address */ 69 69 inet_naddr_t naddr; 70 /** Link service ID */ 71 sysarg_t ilink; 72 /** Address object name */ 73 char *name; 70 74 } inet_addr_info_t; 71 75 72 76 /** IP link info */ 73 77 typedef struct { 74 int dummy; 78 /** Link service name */ 79 char *name; 75 80 } inet_link_info_t; 76 81 … … 104 109 typedef struct { 105 110 link_t addr_list; 111 sysarg_t id; 106 112 inet_naddr_t naddr; 107 113 inet_link_t *ilink; 114 char *name; 108 115 } inet_addrobj_t; 109 116 -
uspace/srv/inet/inet_link.c
ra88a6eac r0e94b979 42 42 #include <loc.h> 43 43 #include <stdlib.h> 44 #include <str.h> 44 45 45 46 #include "addrobj.h" … … 196 197 addr->naddr.bits = 24; 197 198 addr->ilink = ilink; 199 addr->name = str_dup("v4a"); 198 200 inet_addrobj_add(addr); 199 201 -
uspace/srv/inet/inetcfg.c
ra88a6eac r0e94b979 42 42 #include <loc.h> 43 43 #include <stdlib.h> 44 #include <str.h> 44 45 #include <sys/types.h> 45 46 … … 67 68 addr->naddr = *naddr; 68 69 addr->ilink = ilink; 70 addr->name = str_dup("foo"); 69 71 inet_addrobj_add(addr); 70 72 … … 88 90 static int inetcfg_addr_get(sysarg_t addr_id, inet_addr_info_t *ainfo) 89 91 { 92 inet_addrobj_t *addr; 93 94 addr = inet_addrobj_get_by_id(addr_id); 95 if (addr == NULL) 96 return ENOENT; 97 98 ainfo->naddr = addr->naddr; 99 ainfo->ilink = addr->ilink->svc_id; 100 ainfo->name = str_dup(addr->name); 101 102 return EOK; 103 } 104 105 static int inetcfg_get_addr_list(sysarg_t **addrs, size_t *count) 106 { 107 return inet_addrobj_get_id_list(addrs, count); 108 } 109 110 static int inetcfg_get_link_list(sysarg_t **addrs, size_t *count) 111 { 90 112 return ENOTSUP; 91 113 } 92 114 93 static int inetcfg_get_addr_list(sysarg_t **addrs, size_t *count) 94 { 95 return ENOTSUP; 96 } 97 98 static int inetcfg_get_link_list(sysarg_t **addrs, size_t *count) 99 { 100 return ENOTSUP; 101 } 102 103 static int inetcfg_link_get(sysarg_t addr_id, inet_link_info_t *ainfo) 104 { 105 return ENOTSUP; 115 static int inetcfg_link_get(sysarg_t link_id, inet_link_info_t *linfo) 116 { 117 inet_link_t *ilink; 118 119 ilink = inet_link_get_by_id(link_id); 120 if (ilink == NULL) { 121 return ENOENT; 122 } 123 124 linfo->name = str_dup(ilink->svc_name); 125 return EOK; 106 126 } 107 127 … … 140 160 static void inetcfg_addr_get_srv(ipc_callid_t callid, ipc_call_t *call) 141 161 { 162 ipc_callid_t rcallid; 163 size_t max_size; 164 142 165 sysarg_t addr_id; 143 166 inet_addr_info_t ainfo; … … 147 170 log_msg(LVL_DEBUG, "inetcfg_addr_get_srv()"); 148 171 172 ainfo.naddr.ipv4 = 0; 173 ainfo.naddr.bits = 0; 174 ainfo.ilink = 0; 175 ainfo.name = NULL; 176 177 if (!async_data_read_receive(&rcallid, &max_size)) { 178 async_answer_0(rcallid, EREFUSED); 179 async_answer_0(callid, EREFUSED); 180 return; 181 } 182 149 183 rc = inetcfg_addr_get(addr_id, &ainfo); 150 async_answer_2(callid, rc, ainfo.naddr.ipv4, ainfo.naddr.bits); 184 if (rc != EOK) { 185 async_answer_0(callid, rc); 186 return; 187 } 188 189 sysarg_t retval = async_data_read_finalize(rcallid, ainfo.name, 190 min(max_size, str_size(ainfo.name))); 191 free(ainfo.name); 192 193 async_answer_3(callid, retval, ainfo.naddr.ipv4, ainfo.naddr.bits, 194 ainfo.ilink); 151 195 } 152 196 153 197 154 198 static void inetcfg_get_addr_list_srv(ipc_callid_t callid, ipc_call_t *call) 199 { 200 ipc_callid_t rcallid; 201 size_t count; 202 size_t max_size; 203 size_t act_size; 204 size_t size; 205 sysarg_t *id_buf; 206 int rc; 207 208 log_msg(LVL_DEBUG, "inetcfg_get_addr_list_srv()"); 209 210 if (!async_data_read_receive(&rcallid, &max_size)) { 211 async_answer_0(rcallid, EREFUSED); 212 async_answer_0(callid, EREFUSED); 213 return; 214 } 215 216 rc = inetcfg_get_addr_list(&id_buf, &count); 217 if (rc != EOK) { 218 async_answer_0(rcallid, rc); 219 async_answer_0(callid, rc); 220 return; 221 } 222 223 act_size = count * sizeof(sysarg_t); 224 size = min(act_size, max_size); 225 226 sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size); 227 free(id_buf); 228 229 async_answer_1(callid, retval, act_size); 230 } 231 232 static void inetcfg_link_get_srv(ipc_callid_t callid, ipc_call_t *call) 233 { 234 ipc_callid_t rcallid; 235 size_t max_size; 236 237 sysarg_t link_id; 238 inet_link_info_t linfo; 239 int rc; 240 241 link_id = IPC_GET_ARG1(*call); 242 log_msg(LVL_DEBUG, "inetcfg_link_get_srv()"); 243 244 linfo.name = NULL; 245 246 if (!async_data_read_receive(&rcallid, &max_size)) { 247 async_answer_0(rcallid, EREFUSED); 248 async_answer_0(callid, EREFUSED); 249 return; 250 } 251 252 rc = inetcfg_link_get(link_id, &linfo); 253 if (rc != EOK) { 254 async_answer_0(rcallid, rc); 255 async_answer_0(callid, rc); 256 return; 257 } 258 259 sysarg_t retval = async_data_read_finalize(rcallid, linfo.name, 260 min(max_size, str_size(linfo.name))); 261 free(linfo.name); 262 263 async_answer_0(callid, retval); 264 } 265 266 static void inetcfg_get_link_list_srv(ipc_callid_t callid, ipc_call_t *call) 155 267 { 156 268 ipc_callid_t rcallid; … … 161 273 int rc; 162 274 163 log_msg(LVL_DEBUG, "inetcfg_get_addr_list_srv()");164 165 if (!async_data_read_receive(&rcallid, &max_size)) {166 async_answer_0(rcallid, EREFUSED);167 async_answer_0(callid, EREFUSED);168 return;169 }170 171 rc = inetcfg_get_addr_list(&id_buf, &act_size);172 if (rc != EOK) {173 async_answer_0(rcallid, rc);174 async_answer_0(callid, rc);175 return;176 }177 178 size = min(act_size, max_size);179 180 sysarg_t retval = async_data_read_finalize(rcallid, id_buf, size);181 free(id_buf);182 183 async_answer_1(callid, retval, act_size);184 }185 186 static void inetcfg_link_get_srv(ipc_callid_t callid, ipc_call_t *call)187 {188 sysarg_t link_id;189 inet_link_info_t linfo;190 int rc;191 192 link_id = IPC_GET_ARG1(*call);193 log_msg(LVL_DEBUG, "inetcfg_link_get_srv()");194 195 rc = inetcfg_link_get(link_id, &linfo);196 async_answer_0(callid, rc);197 }198 199 static void inetcfg_get_link_list_srv(ipc_callid_t callid, ipc_call_t *call)200 {201 ipc_callid_t rcallid;202 size_t max_size;203 size_t act_size;204 size_t size;205 sysarg_t *id_buf;206 int rc;207 208 275 log_msg(LVL_DEBUG, "inetcfg_get_link_list_srv()"); 209 276
Note:
See TracChangeset
for help on using the changeset viewer.