Changeset 45aa22c in mainline
- Timestamp:
- 2012-03-07T23:05:42Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a88a6eac
- Parents:
- 0e25780
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/inetcfg/inetcfg.c
r0e25780 r45aa22c 38 38 #include <errno.h> 39 39 #include <inet/inetcfg.h> 40 #include <loc.h> 40 41 #include <stdio.h> 41 42 #include <str_error.h> … … 46 47 static void print_syntax(void) 47 48 { 48 printf("syntax: " NAME " xxx\n"); 49 printf("syntax: " NAME " create <addr>/<width> <link-name> <addr-name>\n"); 50 } 51 52 static int naddr_parse(const char *text, inet_naddr_t *naddr) 53 { 54 unsigned long a[4], bits; 55 char *cp = (char *)text; 56 int i; 57 58 for (i = 0; i < 3; i++) { 59 a[i] = strtoul(cp, &cp, 10); 60 if (*cp != '.') 61 return EINVAL; 62 ++cp; 63 } 64 65 a[3] = strtoul(cp, &cp, 10); 66 if (*cp != '/') 67 return EINVAL; 68 ++cp; 69 70 bits = strtoul(cp, &cp, 10); 71 if (*cp != '\0') 72 return EINVAL; 73 74 naddr->ipv4 = 0; 75 for (i = 0; i < 4; i++) { 76 if (a[i] > 255) 77 return EINVAL; 78 naddr->ipv4 = (naddr->ipv4 << 8) | a[i]; 79 } 80 81 if (bits < 1 || bits > 31) 82 return EINVAL; 83 84 naddr->bits = bits; 85 return EOK; 86 } 87 88 static int addr_create_static(int argc, char *argv[]) 89 { 90 char *aobj_name; 91 char *addr_spec; 92 char *link_name; 93 94 inet_naddr_t naddr; 95 sysarg_t link_id; 96 sysarg_t addr_id; 97 int rc; 98 99 if (argc < 3) { 100 printf(NAME ": Missing arguments.\n"); 101 print_syntax(); 102 return EINVAL; 103 } 104 105 if (argc > 3) { 106 printf(NAME ": Too many arguments.\n"); 107 print_syntax(); 108 return EINVAL; 109 } 110 111 addr_spec = argv[0]; 112 link_name = argv[1]; 113 aobj_name = argv[2]; 114 115 rc = loc_service_get_id(link_name, &link_id, 0); 116 if (rc != EOK) { 117 printf(NAME ": Service '%s' not found (%d).\n", link_name, rc); 118 return ENOENT; 119 } 120 121 rc = naddr_parse(addr_spec, &naddr); 122 if (rc != EOK) { 123 printf(NAME ": Invalid address format '%s'.\n", addr_spec); 124 return EINVAL; 125 } 126 127 rc = inetcfg_addr_create_static(aobj_name, &naddr, link_id, &addr_id); 128 if (rc != EOK) { 129 printf(NAME ": Failed creating static address '%s' (%d)\n", 130 "v4s", rc); 131 return 1; 132 } 133 134 return EOK; 49 135 } 50 136 … … 52 138 { 53 139 int rc; 54 inet_naddr_t naddr;55 sysarg_t addr_id;56 140 57 if (argc > 1) {58 printf(NAME ": Invalid argument '%s'.\n", argv[1]);141 if (argc < 2) { 142 printf(NAME ": Missing argument.\n"); 59 143 print_syntax(); 60 144 return 1; 61 145 } 62 63 printf("initialize\n");64 146 65 147 rc = inetcfg_init(); … … 70 152 } 71 153 72 printf("sleep\n"); 73 async_usleep(10*1000*1000); 74 printf("create static addr\n"); 75 76 rc = inetcfg_addr_create_static("v4s", &naddr, &addr_id); 77 if (rc != EOK) { 78 printf(NAME ": Failed creating static address '%s' (%d)\n", 79 "v4s", rc); 154 if (str_cmp(argv[1], "create") == 0) { 155 rc = addr_create_static(argc - 2, argv + 2); 156 if (rc != EOK) 157 return 1; 158 } else { 159 printf(NAME ": Unknown command '%s'.\n", argv[1]); 160 print_syntax(); 80 161 return 1; 81 162 } 82 163 83 printf("Success!\n");84 164 return 0; 85 165 } -
uspace/lib/c/generic/inetcfg.c
r0e25780 r45aa22c 133 133 134 134 int inetcfg_addr_create_static(const char *name, inet_naddr_t *naddr, 135 sysarg_t *addr_id)136 { 137 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 138 139 int rc = async_req_ 2_1(exch, INETCFG_ADDR_CREATE_STATIC, naddr->ipv4,140 naddr->bits, addr_id);135 sysarg_t link_id, sysarg_t *addr_id) 136 { 137 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 138 139 int rc = async_req_3_1(exch, INETCFG_ADDR_CREATE_STATIC, naddr->ipv4, 140 naddr->bits, link_id, addr_id); 141 141 async_exchange_end(exch); 142 142 -
uspace/lib/c/include/inet/inetcfg.h
r0e25780 r45aa22c 59 59 60 60 extern int inetcfg_init(void); 61 extern int inetcfg_addr_create_static(const char *, inet_naddr_t *, sysarg_t *);61 extern int inetcfg_addr_create_static(const char *, inet_naddr_t *, sysarg_t, sysarg_t *); 62 62 extern int inetcfg_addr_delete(sysarg_t); 63 63 extern int inetcfg_addr_get(sysarg_t, inet_addr_info_t *); -
uspace/srv/inet/inet.c
r0e25780 r45aa22c 276 276 sysarg_t port; 277 277 278 log_msg(LVL_DEBUG, "inet_client_conn(%d, %d, %d)",279 (int)IPC_GET_ARG1(*icall), (int)IPC_GET_ARG2(*icall),280 (int)IPC_GET_ARG3(*icall));281 282 278 port = IPC_GET_ARG1(*icall); 283 279 -
uspace/srv/inet/inet_link.c
r0e25780 r45aa22c 159 159 return ENOMEM; 160 160 161 ilink->svc_id = sid; 162 161 163 rc = loc_service_get_name(sid, &ilink->svc_name); 162 164 if (rc != EOK) { … … 260 262 } 261 263 264 inet_link_t *inet_link_get_by_id(sysarg_t link_id) 265 { 266 fibril_mutex_lock(&inet_discovery_lock); 267 268 list_foreach(inet_link_list, elem) { 269 inet_link_t *ilink = list_get_instance(elem, inet_link_t, 270 link_list); 271 272 if (ilink->svc_id == link_id) { 273 fibril_mutex_unlock(&inet_discovery_lock); 274 return ilink; 275 } 276 } 277 278 fibril_mutex_unlock(&inet_discovery_lock); 279 return NULL; 280 } 262 281 263 282 /** @} -
uspace/srv/inet/inet_link.h
r0e25780 r45aa22c 38 38 #define INET_LINK_H_ 39 39 40 #include <sys/types.h> 40 41 #include "inet.h" 41 42 … … 43 44 extern int inet_link_send_dgram(inet_link_t *, inet_addr_t *, 44 45 inet_addr_t *, inet_dgram_t *, uint8_t, uint8_t, int); 46 extern inet_link_t *inet_link_get_by_id(sysarg_t); 45 47 46 48 #endif -
uspace/srv/inet/inetcfg.c
r0e25780 r45aa22c 35 35 */ 36 36 37 #include <adt/list.h>38 37 #include <async.h> 39 38 #include <errno.h> 40 39 #include <macros.h> 41 #include <fibril_synch.h>42 40 #include <io/log.h> 43 41 #include <ipc/inet.h> 44 #include <ipc/services.h>45 42 #include <loc.h> 46 #include <stdio.h>47 43 #include <stdlib.h> 48 44 #include <sys/types.h> 49 45 46 #include "addrobj.h" 50 47 #include "inet.h" 48 #include "inet_link.h" 51 49 #include "inetcfg.h" 52 50 53 static int inetcfg_addr_create_static(inet_naddr_t *naddr, sysarg_t *addr_id) 54 { 55 return ENOTSUP; 51 static int inetcfg_addr_create_static(inet_naddr_t *naddr, sysarg_t link_id, 52 sysarg_t *addr_id) 53 { 54 inet_link_t *ilink; 55 inet_addrobj_t *addr; 56 iplink_addr_t iaddr; 57 int rc; 58 59 ilink = inet_link_get_by_id(link_id); 60 if (ilink == NULL) { 61 log_msg(LVL_DEBUG, "Link %lu not found.", 62 (unsigned long) link_id); 63 return ENOENT; 64 } 65 66 addr = inet_addrobj_new(); 67 addr->naddr = *naddr; 68 addr->ilink = ilink; 69 inet_addrobj_add(addr); 70 71 iaddr.ipv4 = addr->naddr.ipv4; 72 rc = iplink_addr_add(ilink->iplink, &iaddr); 73 if (rc != EOK) { 74 log_msg(LVL_ERROR, "Failed setting IP address on internet link."); 75 inet_addrobj_remove(addr); 76 inet_addrobj_delete(addr); 77 return rc; 78 } 79 80 return EOK; 56 81 } 57 82 … … 85 110 { 86 111 inet_naddr_t naddr; 112 sysarg_t link_id; 87 113 sysarg_t addr_id; 88 114 int rc; … … 92 118 naddr.ipv4 = IPC_GET_ARG1(*call); 93 119 naddr.bits = IPC_GET_ARG2(*call); 120 link_id = IPC_GET_ARG3(*call); 94 121 95 122 addr_id = 0; 96 rc = inetcfg_addr_create_static(&naddr, &addr_id);123 rc = inetcfg_addr_create_static(&naddr, link_id, &addr_id); 97 124 async_answer_1(callid, rc, addr_id); 98 125 }
Note:
See TracChangeset
for help on using the changeset viewer.