Changeset a2e3ee6 in mainline
- Timestamp:
- 2013-06-20T16:45:58Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 08bb73b
- Parents:
- 19a4f73
- Location:
- uspace
- Files:
-
- 2 deleted
- 61 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dnscfg/dnscfg.c
r19a4f73 ra2e3ee6 36 36 37 37 #include <errno.h> 38 #include <inet/addr 2.h>38 #include <inet/addr.h> 39 39 #include <inet/dnsr.h> 40 40 #include <ipc/services.h> … … 71 71 char *srv_addr = argv[0]; 72 72 73 inet 2_addr_t addr;74 int rc = inet 2_addr_parse(srv_addr, &addr);73 inet_addr_t addr; 74 int rc = inet_addr_parse(srv_addr, &addr); 75 75 76 76 if (rc != EOK) { … … 91 91 static int dnscfg_unset_ns(void) 92 92 { 93 inet 2_addr_t addr;94 inet 2_addr_empty(&addr);93 inet_addr_t addr; 94 inet_addr_any(&addr); 95 95 96 96 int rc = dnsr_set_srvaddr(&addr); … … 106 106 static int dnscfg_print(void) 107 107 { 108 inet 2_addr_t addr;108 inet_addr_t addr; 109 109 int rc = dnsr_get_srvaddr(&addr); 110 110 if (rc != EOK) { … … 114 114 115 115 char *addr_str; 116 rc = inet 2_addr_format(&addr, &addr_str);116 rc = inet_addr_format(&addr, &addr_str); 117 117 if (rc != EOK) { 118 118 printf("%s: Out of memory.\n", NAME); -
uspace/app/dnsres/dnsres.c
r19a4f73 ra2e3ee6 34 34 35 35 #include <errno.h> 36 #include <inet/addr 2.h>36 #include <inet/addr.h> 37 37 #include <inet/dnsr.h> 38 38 #include <stdio.h> … … 66 66 } 67 67 68 rc = inet 2_addr_format(&hinfo->addr, &saddr);68 rc = inet_addr_format(&hinfo->addr, &saddr); 69 69 if (rc != EOK) { 70 70 dnsr_hostinfo_destroy(hinfo); -
uspace/app/nettest1/nettest1.c
r19a4f73 ra2e3ee6 360 360 } 361 361 362 rc = inet 2_addr_sockaddr_in(&hinfo->addr, &address_in);362 rc = inet_addr_sockaddr_in(&hinfo->addr, &address_in); 363 363 if (rc != EOK) { 364 364 printf("Host '%s' not resolved as IPv4 address.\n", argv[argc - 1]); -
uspace/app/nettest2/nettest2.c
r19a4f73 ra2e3ee6 306 306 } 307 307 308 rc = inet 2_addr_sockaddr_in(&hinfo->addr, &address_in);308 rc = inet_addr_sockaddr_in(&hinfo->addr, &address_in); 309 309 if (rc != EOK) { 310 310 printf("Host '%s' not resolved as IPv4 address.\n", argv[argc - 1]); -
uspace/app/nettest3/nettest3.c
r19a4f73 ra2e3ee6 84 84 } 85 85 86 rc = inet 2_addr_sockaddr_in(&hinfo->addr, &addr);86 rc = inet_addr_sockaddr_in(&hinfo->addr, &addr); 87 87 if (rc != EOK) { 88 88 printf("Host '%s' not resolved as IPv4 address.\n", argv[1]); -
uspace/app/nterm/conn.c
r19a4f73 ra2e3ee6 91 91 } 92 92 93 rc = inet 2_addr_sockaddr_in(&hinfo->addr, &addr);93 rc = inet_addr_sockaddr_in(&hinfo->addr, &addr); 94 94 if (rc != EOK) { 95 95 printf("Host '%s' not resolved as IPv4 address.\n", addr_s); -
uspace/app/ping/ping.c
r19a4f73 ra2e3ee6 83 83 static int ping_ev_recv(inetping_sdu_t *sdu) 84 84 { 85 inet 2_addr_t src_addr;86 inet 2_addr_unpack(sdu->src, &src_addr);87 88 inet 2_addr_t dest_addr;89 inet 2_addr_unpack(sdu->dest, &dest_addr);85 inet_addr_t src_addr; 86 inet_addr_unpack(sdu->src, &src_addr); 87 88 inet_addr_t dest_addr; 89 inet_addr_unpack(sdu->dest, &dest_addr); 90 90 91 91 char *asrc; 92 int rc = inet 2_addr_format(&src_addr, &asrc);92 int rc = inet_addr_format(&src_addr, &asrc); 93 93 if (rc != EOK) 94 94 return ENOMEM; 95 95 96 96 char *adest; 97 rc = inet 2_addr_format(&dest_addr, &adest);97 rc = inet_addr_format(&dest_addr, &adest); 98 98 if (rc != EOK) { 99 99 free(asrc); … … 207 207 208 208 /* Parse destination address */ 209 inet 2_addr_t dest_addr;210 rc = inet 2_addr_parse(argv[argi], &dest_addr);209 inet_addr_t dest_addr; 210 rc = inet_addr_parse(argv[argi], &dest_addr); 211 211 if (rc != EOK) { 212 212 /* Try interpreting as a host name */ … … 220 220 } 221 221 222 rc = inet 2_addr_pack(&dest_addr, &dest);222 rc = inet_addr_pack(&dest_addr, &dest); 223 223 if (rc != EOK) { 224 224 printf(NAME ": Destination '%s' is not an IPv4 address.\n", … … 234 234 } 235 235 236 inet 2_addr_t src_addr;237 inet 2_addr_unpack(src, &src_addr);238 239 rc = inet 2_addr_format(&src_addr, &asrc);236 inet_addr_t src_addr; 237 inet_addr_unpack(src, &src_addr); 238 239 rc = inet_addr_format(&src_addr, &asrc); 240 240 if (rc != EOK) { 241 241 printf(NAME ": Out of memory.\n"); … … 243 243 } 244 244 245 rc = inet 2_addr_format(&dest_addr, &adest);245 rc = inet_addr_format(&dest_addr, &adest); 246 246 if (rc != EOK) { 247 247 printf(NAME ": Out of memory.\n"); -
uspace/lib/c/Makefile
r19a4f73 ra2e3ee6 93 93 generic/futex.c \ 94 94 generic/inet/addr.c \ 95 generic/inet/addr2.c \96 95 generic/inet.c \ 97 96 generic/inetcfg.c \ -
uspace/lib/c/generic/dnsr.c
r19a4f73 ra2e3ee6 108 108 109 109 info->cname = str_dup(cname_buf); 110 inet 2_addr_unpack(IPC_GET_ARG1(answer), &info->addr);110 inet_addr_unpack(IPC_GET_ARG1(answer), &info->addr); 111 111 112 112 *rinfo = info; … … 123 123 } 124 124 125 int dnsr_get_srvaddr(inet 2_addr_t *srvaddr)125 int dnsr_get_srvaddr(inet_addr_t *srvaddr) 126 126 { 127 127 async_exch_t *exch = dnsr_exchange_begin(); … … 129 129 ipc_call_t answer; 130 130 aid_t req = async_send_0(exch, DNSR_GET_SRVADDR, &answer); 131 int rc = async_data_read_start(exch, srvaddr, sizeof(inet 2_addr_t));131 int rc = async_data_read_start(exch, srvaddr, sizeof(inet_addr_t)); 132 132 133 133 loc_exchange_end(exch); … … 144 144 } 145 145 146 int dnsr_set_srvaddr(inet 2_addr_t *srvaddr)146 int dnsr_set_srvaddr(inet_addr_t *srvaddr) 147 147 { 148 148 async_exch_t *exch = dnsr_exchange_begin(); … … 150 150 ipc_call_t answer; 151 151 aid_t req = async_send_0(exch, DNSR_SET_SRVADDR, &answer); 152 int rc = async_data_write_start(exch, srvaddr, sizeof(inet 2_addr_t));152 int rc = async_data_write_start(exch, srvaddr, sizeof(inet_addr_t)); 153 153 154 154 loc_exchange_end(exch); -
uspace/lib/c/generic/inet.c
r19a4f73 ra2e3ee6 107 107 int inet_send(inet_dgram_t *dgram, uint8_t ttl, inet_df_t df) 108 108 { 109 async_exch_t *exch = async_exchange_begin(inet_sess); 110 109 uint32_t src; 110 int rc = inet_addr_pack(&dgram->src, &src); 111 if (rc != EOK) 112 return rc; 113 114 uint32_t dest; 115 rc = inet_addr_pack(&dgram->dest, &dest); 116 if (rc != EOK) 117 return EOK; 118 119 async_exch_t *exch = async_exchange_begin(inet_sess); 120 111 121 ipc_call_t answer; 112 aid_t req = async_send_5(exch, INET_SEND, dgram->src.ipv4, 113 dgram->dest.ipv4, dgram->tos, ttl, df, &answer); 114 int rc = async_data_write_start(exch, dgram->data, dgram->size); 115 async_exchange_end(exch); 116 122 aid_t req = async_send_5(exch, INET_SEND, (sysarg_t) src, 123 (sysarg_t) dest, dgram->tos, ttl, df, &answer); 124 rc = async_data_write_start(exch, dgram->data, dgram->size); 125 126 async_exchange_end(exch); 127 117 128 if (rc != EOK) { 118 129 async_forget(req); 119 130 return rc; 120 131 } 121 132 122 133 sysarg_t retval; 123 134 async_wait_for(req, &retval); 124 135 if (retval != EOK) 125 136 return retval; 126 137 127 138 return EOK; 128 139 } … … 130 141 int inet_get_srcaddr(inet_addr_t *remote, uint8_t tos, inet_addr_t *local) 131 142 { 132 sysarg_t local_addr;133 async_exch_t *exch = async_exchange_begin(inet_sess);134 135 int rc = async_req_2_1(exch, INET_GET_SRCADDR, remote->ipv4,136 tos, &local_addr);137 async_exchange_end(exch);138 139 if (rc != EOK)140 return rc;141 142 local->ipv4 = local_addr;143 return EOK;144 }145 146 int inet2_get_srcaddr(inet2_addr_t *remote, uint8_t tos, inet2_addr_t *local)147 {148 143 uint32_t remote_addr; 149 int rc = inet 2_addr_pack(remote, &remote_addr);144 int rc = inet_addr_pack(remote, &remote_addr); 150 145 if (rc != EOK) 151 146 return rc; … … 162 157 return rc; 163 158 164 inet 2_addr_unpack(local_addr, local);159 inet_addr_unpack(local_addr, local); 165 160 return EOK; 166 161 } … … 170 165 int rc; 171 166 inet_dgram_t dgram; 172 173 dgram.src.ipv4 = IPC_GET_ARG1(*call);174 dgram.dest.ipv4 = IPC_GET_ARG2(*call);167 168 inet_addr_unpack(IPC_GET_ARG1(*call), &dgram.src); 169 inet_addr_unpack(IPC_GET_ARG2(*call), &dgram.dest); 175 170 dgram.tos = IPC_GET_ARG3(*call); 176 171 -
uspace/lib/c/generic/inet/addr.c
r19a4f73 ra2e3ee6 34 34 35 35 #include <errno.h> 36 #include <unistd.h> 37 #include <net/socket_codes.h> 36 38 #include <inet/addr.h> 39 #include <net/inet.h> 37 40 #include <stdio.h> 38 41 42 static inet_addr_t inet_addr_any_addr = { 43 .family = AF_INET, 44 .addr = {0, 0, 0, 0} 45 }; 46 47 static inet_addr_t inet_addr_any_addr6 = { 48 .family = AF_INET6, 49 .addr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 50 }; 51 52 /** Parse network address family. 53 * 54 * @param text Network address in common notation. 55 * @param af Place to store network address family. 56 * 57 * @return EOK on success, EINVAL if input is not in valid format. 58 * 59 */ 60 int inet_addr_family(const char *text, uint16_t *af) 61 { 62 char *dot = str_chr(text, '.'); 63 if (dot != NULL) { 64 *af = AF_INET; 65 return EOK; 66 } 67 68 char *collon = str_chr(text, ':'); 69 if (collon != NULL) { 70 *af = AF_INET6; 71 return EOK; 72 } 73 74 *af = AF_NONE; 75 return EINVAL; 76 } 77 78 /** Parse node address. 79 * 80 * @param text Network address in common notation. 81 * @param addr Place to store node address. 82 * 83 * @return EOK on success, EINVAL if input is not in valid format. 84 * 85 */ 86 int inet_addr_parse(const char *text, inet_addr_t *addr) 87 { 88 int rc = inet_addr_family(text, &addr->family); 89 if (rc != EOK) 90 return rc; 91 92 rc = inet_pton(addr->family, text, addr->addr); 93 if (rc != EOK) 94 return rc; 95 96 return EOK; 97 } 98 39 99 /** Parse network address. 40 100 * 41 * @param text Network address in CIDR notation (a.b.c.d/w) 42 * @param naddr Place to store network address 43 * 44 * @return EOK on success, EINVAL if input is not in valid format 101 * @param text Network address in common notation. 102 * @param naddr Place to store network address. 103 * 104 * @return EOK on success, EINVAL if input is not in valid format. 105 * 45 106 */ 46 107 int inet_naddr_parse(const char *text, inet_naddr_t *naddr) 47 108 { 48 unsigned long a[4], bits; 49 char *cp = (char *)text; 50 int i; 51 52 for (i = 0; i < 3; i++) { 53 a[i] = strtoul(cp, &cp, 10); 54 if (*cp != '.') 109 char *slash = str_chr(text, '/'); 110 if (slash == NULL) 111 return EINVAL; 112 113 *slash = 0; 114 115 int rc = inet_addr_family(text, &naddr->family); 116 if (rc != EOK) 117 return rc; 118 119 rc = inet_pton(naddr->family, text, naddr->addr); 120 *slash = '/'; 121 122 if (rc != EOK) 123 return rc; 124 125 slash++; 126 127 switch (naddr->family) { 128 case AF_INET: 129 naddr->prefix = strtoul(slash, &slash, 10); 130 if (naddr->prefix > 32) 55 131 return EINVAL; 56 ++cp; 57 } 58 59 a[3] = strtoul(cp, &cp, 10); 60 if (*cp != '/') 61 return EINVAL; 62 ++cp; 63 64 bits = strtoul(cp, &cp, 10); 65 if (*cp != '\0') 66 return EINVAL; 67 68 naddr->ipv4 = 0; 69 for (i = 0; i < 4; i++) { 70 if (a[i] > 255) 132 break; 133 case AF_INET6: 134 naddr->prefix = strtoul(slash, &slash, 10); 135 if (naddr->prefix > 128) 71 136 return EINVAL; 72 naddr->ipv4 = (naddr->ipv4 << 8) | a[i]; 73 } 74 75 if (bits > 31) 76 return EINVAL; 77 78 naddr->bits = bits; 79 return EOK; 80 } 81 82 /** Parse node address. 83 * 84 * @param text Network address in dot notation (a.b.c.d) 85 * @param addr Place to store node address 86 * 87 * @return EOK on success, EINVAL if input is not in valid format 88 */ 89 int inet_addr_parse(const char *text, inet_addr_t *addr) 90 { 91 unsigned long a[4]; 92 char *cp = (char *)text; 93 int i; 94 95 for (i = 0; i < 3; i++) { 96 a[i] = strtoul(cp, &cp, 10); 97 if (*cp != '.') 98 return EINVAL; 99 ++cp; 100 } 101 102 a[3] = strtoul(cp, &cp, 10); 103 if (*cp != '\0') 104 return EINVAL; 105 106 addr->ipv4 = 0; 107 for (i = 0; i < 4; i++) { 108 if (a[i] > 255) 109 return EINVAL; 110 addr->ipv4 = (addr->ipv4 << 8) | a[i]; 111 } 112 113 return EOK; 114 } 115 116 /** Format network address. 117 * 118 * @param naddr Network address 119 * @param bufp Place to store pointer to formatted string (CIDR notation) 120 * 121 * @return EOK on success, ENOMEM if out of memory. 122 */ 123 int inet_naddr_format(inet_naddr_t *naddr, char **bufp) 137 break; 138 default: 139 return ENOTSUP; 140 } 141 142 return EOK; 143 } 144 145 /** Format node address. 146 * 147 * @param addr Node address. 148 * @param bufp Place to store pointer to formatted string. 149 * 150 * @return EOK on success. 151 * @return ENOMEM if out of memory. 152 * @return ENOTSUP on unsupported address family. 153 * 154 */ 155 int inet_addr_format(inet_addr_t *addr, char **bufp) 124 156 { 125 157 int rc; 126 127 rc = asprintf(bufp, "%d.%d.%d.%d/%d", naddr->ipv4 >> 24, 128 (naddr->ipv4 >> 16) & 0xff, (naddr->ipv4 >> 8) & 0xff, 129 naddr->ipv4 & 0xff, naddr->bits); 130 158 159 switch (addr->family) { 160 case AF_NONE: 161 rc = asprintf(bufp, "none"); 162 break; 163 case AF_INET: 164 rc = asprintf(bufp, "%u.%u.%u.%u", addr->addr[0], 165 addr->addr[1], addr->addr[2], addr->addr[3]); 166 break; 167 case AF_INET6: 168 // FIXME TODO 169 break; 170 default: 171 return ENOTSUP; 172 } 173 131 174 if (rc < 0) 132 175 return ENOMEM; 133 134 return EOK; 135 } 136 137 /** Format node address. 138 * 139 * @param addr Node address 140 * @param bufp Place to store pointer to formatted string (dot notation) 141 * 142 * @return EOK on success, ENOMEM if out of memory. 143 */ 144 int inet_addr_format(inet_addr_t *addr, char **bufp) 176 177 return EOK; 178 } 179 180 /** Format network address. 181 * 182 * @param naddr Network address. 183 * @param bufp Place to store pointer to formatted string. 184 * 185 * @return EOK on success. 186 * @return ENOMEM if out of memory. 187 * @return ENOTSUP on unsupported address family. 188 * 189 */ 190 int inet_naddr_format(inet_naddr_t *naddr, char **bufp) 145 191 { 146 192 int rc; 147 148 rc = asprintf(bufp, "%d.%d.%d.%d", addr->ipv4 >> 24, 149 (addr->ipv4 >> 16) & 0xff, (addr->ipv4 >> 8) & 0xff, 150 addr->ipv4 & 0xff); 151 193 194 switch (naddr->family) { 195 case AF_NONE: 196 rc = asprintf(bufp, "none"); 197 break; 198 case AF_INET: 199 rc = asprintf(bufp, "%u.%u.%u.%u/%u", naddr->addr[0], 200 naddr->addr[1], naddr->addr[2], naddr->addr[3], 201 naddr->prefix); 202 break; 203 case AF_INET6: 204 // FIXME TODO 205 break; 206 default: 207 return ENOTSUP; 208 } 209 152 210 if (rc < 0) 153 211 return ENOMEM; 154 155 return EOK; 212 213 return EOK; 214 } 215 216 /** Create packed IPv4 address 217 * 218 * Convert an IPv4 address to a packed 32 bit representation. 219 * 220 * @param addr Source address. 221 * @param packed Place to store the packed 32 bit representation. 222 * 223 * @return EOK on success. 224 * @return EINVAL if addr is not an IPv4 address. 225 * 226 */ 227 int inet_addr_pack(inet_addr_t *addr, uint32_t *packed) 228 { 229 if (addr->family != AF_INET) 230 return EINVAL; 231 232 *packed = (addr->addr[0] << 24) | (addr->addr[1] << 16) | 233 (addr->addr[2] << 8) | addr->addr[3]; 234 return EOK; 235 } 236 237 /** Create packed IPv4 address 238 * 239 * Convert an IPv4 address to a packed 32 bit representation. 240 * 241 * @param naddr Source address. 242 * @param packed Place to store the packed 32 bit representation. 243 * @param prefix Place to store the number of valid bits. 244 * 245 * @return EOK on success. 246 * @return EINVAL if addr is not an IPv4 address. 247 * 248 */ 249 int inet_naddr_pack(inet_naddr_t *naddr, uint32_t *packed, uint8_t *prefix) 250 { 251 if (naddr->family != AF_INET) 252 return EINVAL; 253 254 *packed = (naddr->addr[0] << 24) | (naddr->addr[1] << 16) | 255 (naddr->addr[2] << 8) | naddr->addr[3]; 256 *prefix = naddr->prefix; 257 258 return EOK; 259 } 260 261 void inet_addr_unpack(uint32_t packed, inet_addr_t *addr) 262 { 263 addr->family = AF_INET; 264 addr->addr[0] = (packed >> 24) & 0xff; 265 addr->addr[1] = (packed >> 16) & 0xff; 266 addr->addr[2] = (packed >> 8) & 0xff; 267 addr->addr[3] = packed & 0xff; 268 } 269 270 void inet_naddr_unpack(uint32_t packed, uint8_t prefix, inet_naddr_t *naddr) 271 { 272 naddr->family = AF_INET; 273 naddr->addr[0] = (packed >> 24) & 0xff; 274 naddr->addr[1] = (packed >> 16) & 0xff; 275 naddr->addr[2] = (packed >> 8) & 0xff; 276 naddr->addr[3] = packed & 0xff; 277 naddr->prefix = prefix; 278 } 279 280 int inet_addr_sockaddr_in(inet_addr_t *addr, sockaddr_in_t *sockaddr_in) 281 { 282 uint32_t packed; 283 int rc = inet_addr_pack(addr, &packed); 284 if (rc != EOK) 285 return rc; 286 287 sockaddr_in->sin_family = AF_INET; 288 sockaddr_in->sin_addr.s_addr = host2uint32_t_be(packed); 289 return EOK; 290 } 291 292 void inet_naddr_addr(inet_naddr_t *naddr, inet_addr_t *addr) 293 { 294 addr->family = naddr->family; 295 memcpy(addr->addr, naddr->addr, INET_ADDR_SIZE); 296 } 297 298 void inet_addr(inet_addr_t *addr, uint8_t a, uint8_t b, uint8_t c, uint8_t d) 299 { 300 addr->family = AF_INET; 301 addr->addr[0] = a; 302 addr->addr[1] = b; 303 addr->addr[2] = c; 304 addr->addr[3] = d; 305 } 306 307 void inet_naddr(inet_naddr_t *naddr, uint8_t a, uint8_t b, uint8_t c, uint8_t d, 308 uint8_t prefix) 309 { 310 naddr->family = AF_INET; 311 naddr->addr[0] = a; 312 naddr->addr[1] = b; 313 naddr->addr[2] = c; 314 naddr->addr[3] = d; 315 naddr->prefix = prefix; 316 } 317 318 void inet_addr_any(inet_addr_t *addr) 319 { 320 addr->family = 0; 321 memset(addr->addr, 0, INET_ADDR_SIZE); 322 } 323 324 void inet_naddr_any(inet_naddr_t *naddr) 325 { 326 naddr->family = 0; 327 memset(naddr->addr, 0, INET_ADDR_SIZE); 328 naddr->prefix = 0; 329 } 330 331 int inet_addr_compare(inet_addr_t *a, inet_addr_t *b) 332 { 333 if (a->family != b->family) 334 return 0; 335 336 switch (a->family) { 337 case AF_INET: 338 return ((a->addr[0] == b->addr[0]) && (a->addr[1] == b->addr[1]) && 339 (a->addr[2] == b->addr[2]) && (a->addr[3] == b->addr[3])); 340 case AF_INET6: 341 // FIXME TODO 342 return 0; 343 default: 344 return 0; 345 } 346 } 347 348 int inet_addr_is_any(inet_addr_t *addr) 349 { 350 return ((addr->family == 0) || 351 (inet_addr_compare(addr, &inet_addr_any_addr)) || 352 (inet_addr_compare(addr, &inet_addr_any_addr6))); 156 353 } 157 354 -
uspace/lib/c/generic/inetcfg.c
r19a4f73 ra2e3ee6 136 136 sysarg_t link_id, sysarg_t *addr_id) 137 137 { 138 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 139 140 ipc_call_t answer; 141 aid_t req = async_send_3(exch, INETCFG_ADDR_CREATE_STATIC, naddr->ipv4, 142 naddr->bits, link_id, &answer); 138 uint32_t naddr_addr; 139 uint8_t naddr_bits; 140 int rc = inet_naddr_pack(naddr, &naddr_addr, &naddr_bits); 141 if (rc != EOK) 142 return rc; 143 144 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 145 146 ipc_call_t answer; 147 aid_t req = async_send_3(exch, INETCFG_ADDR_CREATE_STATIC, 148 (sysarg_t) naddr_addr, (sysarg_t) naddr_bits, link_id, &answer); 143 149 sysarg_t retval = async_data_write_start(exch, name, str_size(name)); 144 145 async_exchange_end(exch); 146 147 if (retval != EOK) { 148 async_forget(req); 149 return retval; 150 } 151 150 151 async_exchange_end(exch); 152 153 if (retval != EOK) { 154 async_forget(req); 155 return retval; 156 } 157 152 158 async_wait_for(req, &retval); 153 159 *addr_id = IPC_GET_ARG1(answer); 154 160 155 161 return retval; 156 162 } … … 196 202 assert(act_size <= LOC_NAME_MAXLEN); 197 203 name_buf[act_size] = '\0'; 198 199 ainfo->naddr.ipv4 = IPC_GET_ARG1(answer);200 ainfo->naddr.bits = IPC_GET_ARG2(answer);204 205 inet_naddr_unpack(IPC_GET_ARG1(answer), IPC_GET_ARG2(answer), 206 &ainfo->naddr); 201 207 ainfo->ilink = IPC_GET_ARG3(answer); 202 208 ainfo->name = str_dup(name_buf); … … 284 290 inet_addr_t *router, sysarg_t *sroute_id) 285 291 { 286 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 287 292 uint32_t dest_addr; 293 uint8_t dest_bits; 294 int rc = inet_naddr_pack(dest, &dest_addr, &dest_bits); 295 if (rc != EOK) 296 return rc; 297 298 uint32_t router_addr; 299 rc = inet_addr_pack(router, &router_addr); 300 if (rc != EOK) 301 return rc; 302 303 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 304 288 305 ipc_call_t answer; 289 306 aid_t req = async_send_3(exch, INETCFG_SROUTE_CREATE, 290 dest->ipv4, dest->bits, router->ipv4, &answer); 307 (sysarg_t) dest_addr, (sysarg_t) dest_bits, (sysarg_t) router_addr, 308 &answer); 291 309 sysarg_t retval = async_data_write_start(exch, name, str_size(name)); 292 293 async_exchange_end(exch); 294 295 if (retval != EOK) { 296 async_forget(req); 297 return retval; 298 } 299 310 311 async_exchange_end(exch); 312 313 if (retval != EOK) { 314 async_forget(req); 315 return retval; 316 } 317 300 318 async_wait_for(req, &retval); 301 319 *sroute_id = IPC_GET_ARG1(answer); 302 320 303 321 return retval; 304 322 } … … 345 363 name_buf[act_size] = '\0'; 346 364 347 srinfo->dest.ipv4 = IPC_GET_ARG1(answer);348 srinfo->dest.bits = IPC_GET_ARG2(answer);349 srinfo->router.ipv4 = IPC_GET_ARG3(answer);365 inet_naddr_unpack(IPC_GET_ARG1(answer), IPC_GET_ARG2(answer), 366 &srinfo->dest); 367 inet_addr_unpack(IPC_GET_ARG3(answer), &srinfo->router); 350 368 srinfo->name = str_dup(name_buf); 351 369 -
uspace/lib/c/generic/iplink.c
r19a4f73 ra2e3ee6 39 39 #include <errno.h> 40 40 #include <inet/iplink.h> 41 #include <inet/addr.h> 41 42 #include <ipc/iplink.h> 42 43 #include <ipc/services.h> … … 83 84 { 84 85 async_exch_t *exch = async_exchange_begin(iplink->sess); 85 86 86 87 ipc_call_t answer; 87 aid_t req = async_send_2(exch, IPLINK_SEND, sdu->lsrc.ipv4,88 sdu->ldest.ipv4, &answer);88 aid_t req = async_send_2(exch, IPLINK_SEND, (sysarg_t) sdu->lsrc, 89 (sysarg_t) sdu->ldest, &answer); 89 90 int rc = async_data_write_start(exch, sdu->data, sdu->size); 91 90 92 async_exchange_end(exch); 91 93 92 94 if (rc != EOK) { 93 95 async_forget(req); 94 96 return rc; 95 97 } 96 98 97 99 sysarg_t retval; 98 100 async_wait_for(req, &retval); 99 101 if (retval != EOK) 100 102 return retval; 101 103 102 104 return EOK; 103 105 } … … 118 120 } 119 121 120 int iplink_addr_add(iplink_t *iplink, i plink_addr_t *addr)122 int iplink_addr_add(iplink_t *iplink, inet_addr_t *addr) 121 123 { 124 uint32_t addr_addr; 125 int rc = inet_addr_pack(addr, &addr_addr); 126 if (rc != EOK) 127 return rc; 128 122 129 async_exch_t *exch = async_exchange_begin(iplink->sess); 123 124 int rc = async_req_1_0(exch, IPLINK_ADDR_ADD, (sysarg_t)addr->ipv4); 130 rc = async_req_1_0(exch, IPLINK_ADDR_ADD, (sysarg_t) addr_addr); 125 131 async_exchange_end(exch); 126 132 127 133 return rc; 128 134 } 129 135 130 int iplink_addr_remove(iplink_t *iplink, i plink_addr_t *addr)136 int iplink_addr_remove(iplink_t *iplink, inet_addr_t *addr) 131 137 { 138 uint32_t addr_addr; 139 int rc = inet_addr_pack(addr, &addr_addr); 140 if (rc != EOK) 141 return rc; 142 132 143 async_exch_t *exch = async_exchange_begin(iplink->sess); 133 134 int rc = async_req_1_0(exch, IPLINK_ADDR_REMOVE, (sysarg_t)addr->ipv4); 144 rc = async_req_1_0(exch, IPLINK_ADDR_REMOVE, (sysarg_t) addr_addr); 135 145 async_exchange_end(exch); 136 146 137 147 return rc; 138 148 } … … 141 151 ipc_call_t *call) 142 152 { 143 int rc;144 153 iplink_sdu_t sdu; 145 146 sdu.lsrc .ipv4= IPC_GET_ARG1(*call);147 sdu.ldest .ipv4= IPC_GET_ARG2(*call);148 149 rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, &sdu.size);154 155 sdu.lsrc = IPC_GET_ARG1(*call); 156 sdu.ldest = IPC_GET_ARG2(*call); 157 158 int rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, &sdu.size); 150 159 if (rc != EOK) { 151 160 async_answer_0(callid, rc); 152 161 return; 153 162 } 154 163 155 164 rc = iplink->ev_ops->recv(iplink, &sdu); 156 165 free(sdu.data); -
uspace/lib/c/generic/iplink_srv.c
r19a4f73 ra2e3ee6 54 54 ipc_call_t *call) 55 55 { 56 int rc; 57 iplink_srv_addr_t addr; 58 59 addr.ipv4 = IPC_GET_ARG1(*call); 60 61 rc = srv->ops->addr_add(srv, &addr); 56 int rc = srv->ops->addr_add(srv, IPC_GET_ARG1(*call)); 62 57 async_answer_0(callid, rc); 63 58 } … … 66 61 ipc_call_t *call) 67 62 { 68 int rc; 69 iplink_srv_addr_t addr; 70 71 addr.ipv4 = IPC_GET_ARG1(*call); 72 73 rc = srv->ops->addr_remove(srv, &addr); 63 int rc = srv->ops->addr_remove(srv, IPC_GET_ARG1(*call)); 74 64 async_answer_0(callid, rc); 75 65 } … … 81 71 int rc; 82 72 83 sdu.lsrc .ipv4= IPC_GET_ARG1(*call);84 sdu.ldest .ipv4= IPC_GET_ARG2(*call);73 sdu.lsrc = IPC_GET_ARG1(*call); 74 sdu.ldest = IPC_GET_ARG2(*call); 85 75 86 76 rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, &sdu.size); … … 139 129 if (!method) { 140 130 /* The other side has hung up */ 141 131 fibril_mutex_lock(&srv->lock); 142 132 srv->connected = false; 143 133 fibril_mutex_unlock(&srv->lock); 144 134 async_answer_0(callid, EOK); 145 135 break; … … 175 165 176 166 ipc_call_t answer; 177 aid_t req = async_send_2(exch, IPLINK_EV_RECV, sdu->lsrc.ipv4,178 sdu->ldest.ipv4, &answer);167 aid_t req = async_send_2(exch, IPLINK_EV_RECV, (sysarg_t) sdu->lsrc, 168 (sysarg_t) sdu->ldest, &answer); 179 169 int rc = async_data_write_start(exch, sdu->data, sdu->size); 180 170 async_exchange_end(exch); -
uspace/lib/c/generic/net/inet.c
r19a4f73 ra2e3ee6 39 39 #include <net/in6.h> 40 40 #include <net/inet.h> 41 41 #include <inet/addr.h> 42 42 #include <errno.h> 43 43 #include <mem.h> -
uspace/lib/c/generic/net/socket_client.c
r19a4f73 ra2e3ee6 87 87 /** Parent module service. */ 88 88 services_t service; 89 /** Socket family */ 90 int family; 89 91 90 92 /** … … 395 397 switch (domain) { 396 398 case PF_INET: 399 case PF_INET6: 397 400 switch (type) { 398 401 case SOCK_STREAM: … … 433 436 break; 434 437 435 case PF_INET6:436 438 default: 437 439 return EPFNOSUPPORT; … … 447 449 448 450 memset(socket, 0, sizeof(*socket)); 451 socket->family = domain; 449 452 fibril_rwlock_write_lock(&socket_globals.lock); 450 453 -
uspace/lib/c/generic/net/socket_parse.c
r19a4f73 ra2e3ee6 79 79 int socket_parse_protocol_family(const char *name, int *pf) 80 80 { 81 if (str_lcmp(name, "PF_INET6", 8) == 0) { 82 *pf = PF_INET6; 83 return EOK; 84 } 85 81 86 if (str_lcmp(name, "PF_INET", 7) == 0) { 82 87 *pf = PF_INET; 83 return EOK;84 }85 86 if (str_lcmp(name, "PF_INET6", 8) == 0) {87 *pf = PF_INET6;88 88 return EOK; 89 89 } -
uspace/lib/c/include/inet/addr.h
r19a4f73 ra2e3ee6 37 37 38 38 #include <stdint.h> 39 #include <net/in.h> 40 41 #define INET_ADDR_SIZE 16 39 42 40 43 /** Node address */ 41 44 typedef struct { 42 uint32_t ipv4; 45 uint16_t family; 46 uint8_t addr[INET_ADDR_SIZE]; 43 47 } inet_addr_t; 44 48 45 49 /** Network address */ 46 50 typedef struct { 51 /** Address family */ 52 uint16_t family; 53 47 54 /** Address */ 48 uint32_t ipv4; 49 /** Number of valid bits in @c ipv4 */ 50 int bits; 55 uint8_t addr[INET_ADDR_SIZE]; 56 57 /** Number of valid bits */ 58 uint8_t prefix; 51 59 } inet_naddr_t; 52 60 61 extern int inet_addr_family(const char *, uint16_t *); 62 63 extern int inet_addr_parse(const char *, inet_addr_t *); 53 64 extern int inet_naddr_parse(const char *, inet_naddr_t *); 54 extern int inet_addr_parse(const char *, inet_addr_t *); 65 66 extern int inet_addr_format(inet_addr_t *, char **); 55 67 extern int inet_naddr_format(inet_naddr_t *, char **); 56 extern int inet_addr_format(inet_addr_t *, char **); 68 69 extern int inet_addr_pack(inet_addr_t *, uint32_t *); 70 extern int inet_naddr_pack(inet_naddr_t *, uint32_t *, uint8_t *); 71 72 extern void inet_addr_unpack(uint32_t, inet_addr_t *); 73 extern void inet_naddr_unpack(uint32_t, uint8_t, inet_naddr_t *); 74 75 extern int inet_addr_sockaddr_in(inet_addr_t *, sockaddr_in_t *); 76 extern void inet_naddr_addr(inet_naddr_t *, inet_addr_t *); 77 78 extern void inet_addr(inet_addr_t *, uint8_t, uint8_t, uint8_t, uint8_t); 79 extern void inet_naddr(inet_naddr_t *, uint8_t, uint8_t, uint8_t, uint8_t, 80 uint8_t); 81 82 extern void inet_addr_any(inet_addr_t *); 83 extern void inet_naddr_any(inet_naddr_t *); 84 85 extern int inet_addr_compare(inet_addr_t *, inet_addr_t *); 86 extern int inet_addr_is_any(inet_addr_t *); 57 87 58 88 #endif -
uspace/lib/c/include/inet/dnsr.h
r19a4f73 ra2e3ee6 37 37 38 38 #include <inet/inet.h> 39 #include <inet/addr 2.h>39 #include <inet/addr.h> 40 40 41 41 enum { … … 47 47 char *cname; 48 48 /** Host address */ 49 inet 2_addr_t addr;49 inet_addr_t addr; 50 50 } dnsr_hostinfo_t; 51 51 … … 53 53 extern int dnsr_name2host(const char *, dnsr_hostinfo_t **); 54 54 extern void dnsr_hostinfo_destroy(dnsr_hostinfo_t *); 55 extern int dnsr_get_srvaddr(inet 2_addr_t *);56 extern int dnsr_set_srvaddr(inet 2_addr_t *);55 extern int dnsr_get_srvaddr(inet_addr_t *); 56 extern int dnsr_set_srvaddr(inet_addr_t *); 57 57 58 58 #endif -
uspace/lib/c/include/inet/inet.h
r19a4f73 ra2e3ee6 37 37 38 38 #include <inet/addr.h> 39 #include <inet/addr2.h>40 39 #include <sys/types.h> 41 40 … … 61 60 extern int inet_send(inet_dgram_t *, uint8_t, inet_df_t); 62 61 extern int inet_get_srcaddr(inet_addr_t *, uint8_t, inet_addr_t *); 63 extern int inet2_get_srcaddr(inet2_addr_t *, uint8_t, inet2_addr_t *);64 62 65 63 #endif -
uspace/lib/c/include/inet/iplink.h
r19a4f73 ra2e3ee6 38 38 #include <async.h> 39 39 #include <sys/types.h> 40 #include <inet/addr.h> 40 41 41 42 struct iplink_ev_ops; … … 46 47 } iplink_t; 47 48 48 typedef struct { 49 uint32_t ipv4; 50 } iplink_addr_t; 51 52 /** IP link Service Data Unit */ 49 /** IPv4 link Service Data Unit */ 53 50 typedef struct { 54 51 /** Local source address */ 55 iplink_addr_t lsrc;52 uint32_t lsrc; 56 53 /** Local destination address */ 57 iplink_addr_t ldest;54 uint32_t ldest; 58 55 /** Serialized IP packet */ 59 56 void *data; … … 61 58 size_t size; 62 59 } iplink_sdu_t; 60 61 /** IPv6 link Service Data Unit */ 62 typedef struct { 63 /** Target MAC address */ 64 uint64_t hwaddr; 65 /** Serialized IP packet */ 66 void *data; 67 /** Size of @c data in bytes */ 68 size_t size; 69 } iplink_sdu6_t; 63 70 64 71 typedef struct iplink_ev_ops { … … 69 76 extern void iplink_close(iplink_t *); 70 77 extern int iplink_send(iplink_t *, iplink_sdu_t *); 71 extern int iplink_addr_add(iplink_t *, i plink_addr_t *);72 extern int iplink_addr_remove(iplink_t *, i plink_addr_t *);78 extern int iplink_addr_add(iplink_t *, inet_addr_t *); 79 extern int iplink_addr_remove(iplink_t *, inet_addr_t *); 73 80 extern int iplink_get_mtu(iplink_t *, size_t *); 74 81 -
uspace/lib/c/include/inet/iplink_srv.h
r19a4f73 ra2e3ee6 51 51 } iplink_srv_t; 52 52 53 typedef struct {54 uint32_t ipv4;55 } iplink_srv_addr_t;56 57 53 /** IP link Service Data Unit */ 58 54 typedef struct { 59 55 /** Local source address */ 60 iplink_srv_addr_t lsrc;56 uint32_t lsrc; 61 57 /** Local destination address */ 62 iplink_srv_addr_t ldest;58 uint32_t ldest; 63 59 /** Serialized IP packet */ 64 60 void *data; … … 72 68 int (*send)(iplink_srv_t *, iplink_srv_sdu_t *); 73 69 int (*get_mtu)(iplink_srv_t *, size_t *); 74 int (*addr_add)(iplink_srv_t *, iplink_srv_addr_t *);75 int (*addr_remove)(iplink_srv_t *, iplink_srv_addr_t *);70 int (*addr_add)(iplink_srv_t *, uint32_t); 71 int (*addr_remove)(iplink_srv_t *, uint32_t); 76 72 } iplink_ops_t; 77 73 -
uspace/srv/net/dnsrsrv/dns_type.h
r19a4f73 ra2e3ee6 39 39 #include <adt/list.h> 40 40 #include <inet/inet.h> 41 #include <inet/addr 2.h>41 #include <inet/addr.h> 42 42 #include <stdbool.h> 43 43 #include <stdint.h> … … 116 116 char *cname; 117 117 /** Host address */ 118 inet 2_addr_t addr;118 inet_addr_t addr; 119 119 } dns_host_info_t; 120 120 -
uspace/srv/net/dnsrsrv/dnsrsrv.c
r19a4f73 ra2e3ee6 118 118 119 119 uint32_t addr; 120 rc = inet 2_addr_pack(&hinfo->addr, &addr);120 rc = inet_addr_pack(&hinfo->addr, &addr); 121 121 if (rc != EOK) { 122 122 async_answer_0(rcallid, rc); … … 151 151 } 152 152 153 if (size != sizeof(inet 2_addr_t)) {153 if (size != sizeof(inet_addr_t)) { 154 154 async_answer_0(callid, EINVAL); 155 155 async_answer_0(iid, EINVAL); … … 177 177 } 178 178 179 if (size != sizeof(inet 2_addr_t)) {179 if (size != sizeof(inet_addr_t)) { 180 180 async_answer_0(callid, EINVAL); 181 181 async_answer_0(iid, EINVAL); -
uspace/srv/net/dnsrsrv/query.c
r19a4f73 ra2e3ee6 128 128 129 129 info->cname = str_dup(rr->name); 130 inet 2_addr_unpack(dns_uint32_t_decode(rr->rdata, rr->rdata_size),130 inet_addr_unpack(dns_uint32_t_decode(rr->rdata, rr->rdata_size), 131 131 &info->addr); 132 132 -
uspace/srv/net/dnsrsrv/transport.c
r19a4f73 ra2e3ee6 57 57 #define REQ_RETRY_MAX 3 58 58 59 inet 2_addr_t dns_server_addr;59 inet_addr_t dns_server_addr; 60 60 61 61 typedef struct { … … 195 195 addr.sin_family = AF_INET; 196 196 addr.sin_port = htons(DNS_SERVER_PORT); 197 inet 2_addr_sockaddr_in(&dns_server_addr, &addr);197 inet_addr_sockaddr_in(&dns_server_addr, &addr); 198 198 199 199 rc = dns_message_encode(req, &req_data, &req_size); -
uspace/srv/net/dnsrsrv/transport.h
r19a4f73 ra2e3ee6 37 37 #define TRANSPORT_H 38 38 39 #include <inet/addr 2.h>39 #include <inet/addr.h> 40 40 #include "dns_type.h" 41 41 42 extern inet 2_addr_t dns_server_addr;42 extern inet_addr_t dns_server_addr; 43 43 44 44 extern int transport_init(void); -
uspace/srv/net/ethip/arp.c
r19a4f73 ra2e3ee6 66 66 67 67 log_msg(LOG_DEFAULT, LVL_DEBUG, "ARP PDU decoded, opcode=%d, tpa=%x", 68 packet.opcode, packet.target_proto_addr .ipv4);68 packet.opcode, packet.target_proto_addr); 69 69 70 laddr = ethip_nic_addr_find(nic, &packet.target_proto_addr);70 laddr = ethip_nic_addr_find(nic, packet.target_proto_addr); 71 71 if (laddr != NULL) { 72 72 log_msg(LOG_DEFAULT, LVL_DEBUG, "Request/reply to my address"); 73 73 74 (void) atrans_add( &packet.sender_proto_addr,74 (void) atrans_add(packet.sender_proto_addr, 75 75 &packet.sender_hw_addr); 76 76 … … 87 87 } 88 88 89 int arp_translate(ethip_nic_t *nic, iplink_srv_addr_t *src_addr,90 iplink_srv_addr_t *ip_addr,mac48_addr_t *mac_addr)89 int arp_translate(ethip_nic_t *nic, uint32_t src_addr, uint32_t ip_addr, 90 mac48_addr_t *mac_addr) 91 91 { 92 92 int rc; … … 99 99 packet.opcode = aop_request; 100 100 packet.sender_hw_addr = nic->mac_addr; 101 packet.sender_proto_addr = *src_addr;101 packet.sender_proto_addr = src_addr; 102 102 packet.target_hw_addr.addr = MAC48_BROADCAST; 103 packet.target_proto_addr = *ip_addr;103 packet.target_proto_addr = ip_addr; 104 104 105 105 rc = arp_send_packet(nic, &packet); -
uspace/srv/net/ethip/arp.h
r19a4f73 ra2e3ee6 42 42 43 43 extern void arp_received(ethip_nic_t *, eth_frame_t *); 44 extern int arp_translate(ethip_nic_t *, iplink_srv_addr_t *, 45 iplink_srv_addr_t *, mac48_addr_t *); 44 extern int arp_translate(ethip_nic_t *, uint32_t, uint32_t, mac48_addr_t *); 46 45 47 46 #endif -
uspace/srv/net/ethip/atrans.c
r19a4f73 ra2e3ee6 49 49 static FIBRIL_CONDVAR_INITIALIZE(atrans_cv); 50 50 51 static ethip_atrans_t *atrans_find( iplink_srv_addr_t *ip_addr)51 static ethip_atrans_t *atrans_find(uint32_t ip_addr) 52 52 { 53 53 list_foreach(atrans_list, link) { … … 55 55 ethip_atrans_t, atrans_list); 56 56 57 if (atrans->ip_addr .ipv4 == ip_addr->ipv4)57 if (atrans->ip_addr == ip_addr) 58 58 return atrans; 59 59 } … … 62 62 } 63 63 64 int atrans_add( iplink_srv_addr_t *ip_addr, mac48_addr_t *mac_addr)64 int atrans_add(uint32_t ip_addr, mac48_addr_t *mac_addr) 65 65 { 66 66 ethip_atrans_t *atrans; … … 71 71 return ENOMEM; 72 72 73 atrans->ip_addr = *ip_addr;73 atrans->ip_addr = ip_addr; 74 74 atrans->mac_addr = *mac_addr; 75 75 … … 88 88 } 89 89 90 int atrans_remove( iplink_srv_addr_t *ip_addr)90 int atrans_remove(uint32_t ip_addr) 91 91 { 92 92 ethip_atrans_t *atrans; … … 106 106 } 107 107 108 int atrans_lookup( iplink_srv_addr_t *ip_addr, mac48_addr_t *mac_addr)108 int atrans_lookup(uint32_t ip_addr, mac48_addr_t *mac_addr) 109 109 { 110 110 ethip_atrans_t *atrans; -
uspace/srv/net/ethip/atrans.h
r19a4f73 ra2e3ee6 41 41 #include "ethip.h" 42 42 43 extern int atrans_add( iplink_srv_addr_t *, mac48_addr_t *);44 extern int atrans_remove( iplink_srv_addr_t *);45 extern int atrans_lookup( iplink_srv_addr_t *, mac48_addr_t *);43 extern int atrans_add(uint32_t, mac48_addr_t *); 44 extern int atrans_remove(uint32_t); 45 extern int atrans_lookup(uint32_t, mac48_addr_t *); 46 46 extern int atrans_wait_timeout(suseconds_t); 47 47 -
uspace/srv/net/ethip/ethip.c
r19a4f73 ra2e3ee6 57 57 static int ethip_send(iplink_srv_t *srv, iplink_srv_sdu_t *sdu); 58 58 static int ethip_get_mtu(iplink_srv_t *srv, size_t *mtu); 59 static int ethip_addr_add(iplink_srv_t *srv, iplink_srv_addr_t *addr);60 static int ethip_addr_remove(iplink_srv_t *srv, iplink_srv_addr_t *addr);59 static int ethip_addr_add(iplink_srv_t *srv, uint32_t addr); 60 static int ethip_addr_remove(iplink_srv_t *srv, uint32_t addr); 61 61 62 62 static void ethip_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); … … 175 175 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_send()"); 176 176 177 rc = arp_translate(nic, &sdu->lsrc, &sdu->ldest, &dest_mac_addr);177 rc = arp_translate(nic, sdu->lsrc, sdu->ldest, &dest_mac_addr); 178 178 if (rc != EOK) { 179 179 log_msg(LOG_DEFAULT, LVL_WARN, "Failed to look up IP address 0x%" PRIx32, 180 sdu->ldest .ipv4);180 sdu->ldest); 181 181 return rc; 182 182 } … … 221 221 case ETYPE_IP: 222 222 log_msg(LOG_DEFAULT, LVL_DEBUG, " - construct SDU"); 223 sdu.lsrc .ipv4= 0;224 sdu.ldest .ipv4= 0;223 sdu.lsrc = 0; 224 sdu.ldest = 0; 225 225 sdu.data = frame.data; 226 226 sdu.size = frame.size; … … 244 244 } 245 245 246 static int ethip_addr_add(iplink_srv_t *srv, iplink_srv_addr_t *addr) 247 { 246 static int ethip_addr_add(iplink_srv_t *srv, uint32_t addr) 247 { 248 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_addr_add(0x%" PRIx32 ")", addr); 249 250 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 251 252 return ethip_nic_addr_add(nic, addr); 253 } 254 255 static int ethip_addr_remove(iplink_srv_t *srv, uint32_t addr) 256 { 257 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_addr_remove(0x%" PRIx32 ")", addr); 258 248 259 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 249 250 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_addr_add(0x%" PRIx32 ")", addr->ipv4); 251 return ethip_nic_addr_add(nic, addr); 252 } 253 254 static int ethip_addr_remove(iplink_srv_t *srv, iplink_srv_addr_t *addr) 255 { 256 ethip_nic_t *nic = (ethip_nic_t *)srv->arg; 257 258 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_addr_remove(0x%" PRIx32 ")", addr->ipv4); 260 259 261 return ethip_nic_addr_add(nic, addr); 260 262 } -
uspace/srv/net/ethip/ethip.h
r19a4f73 ra2e3ee6 48 48 typedef struct { 49 49 link_t addr_list; 50 iplink_srv_addr_t addr;50 uint32_t addr; 51 51 } ethip_link_addr_t; 52 52 … … 104 104 mac48_addr_t sender_hw_addr; 105 105 /** Sender protocol address */ 106 iplink_srv_addr_t sender_proto_addr;106 uint32_t sender_proto_addr; 107 107 /** Target hardware address */ 108 108 mac48_addr_t target_hw_addr; 109 109 /** Target protocol address */ 110 iplink_srv_addr_t target_proto_addr;110 uint32_t target_proto_addr; 111 111 } arp_eth_packet_t; 112 112 … … 114 114 typedef struct { 115 115 link_t atrans_list; 116 iplink_srv_addr_t ip_addr;116 uint32_t ip_addr; 117 117 mac48_addr_t mac_addr; 118 118 } ethip_atrans_t; -
uspace/srv/net/ethip/ethip_nic.c
r19a4f73 ra2e3ee6 121 121 } 122 122 123 static ethip_link_addr_t *ethip_nic_addr_new( iplink_srv_addr_t *addr)123 static ethip_link_addr_t *ethip_nic_addr_new(uint32_t addr) 124 124 { 125 125 ethip_link_addr_t *laddr = calloc(1, sizeof(ethip_link_addr_t)); 126 127 126 if (laddr == NULL) { 128 127 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed allocating NIC address structure. " … … 130 129 return NULL; 131 130 } 132 131 133 132 link_initialize(&laddr->addr_list); 134 laddr->addr.ipv4 = addr->ipv4; 133 laddr->addr = addr; 134 135 135 return laddr; 136 136 } … … 335 335 } 336 336 337 int ethip_nic_addr_add(ethip_nic_t *nic, iplink_srv_addr_t *addr) 338 { 339 ethip_link_addr_t *laddr; 340 337 int ethip_nic_addr_add(ethip_nic_t *nic, uint32_t addr) 338 { 341 339 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_add()"); 342 laddr = ethip_nic_addr_new(addr); 340 341 ethip_link_addr_t *laddr = ethip_nic_addr_new(addr); 343 342 if (laddr == NULL) 344 343 return ENOMEM; 345 344 346 345 list_append(&laddr->addr_list, &nic->addr_list); 347 346 return EOK; 348 347 } 349 348 350 int ethip_nic_addr_remove(ethip_nic_t *nic, iplink_srv_addr_t *addr) 351 { 352 ethip_link_addr_t *laddr; 353 349 int ethip_nic_addr_remove(ethip_nic_t *nic, uint32_t addr) 350 { 354 351 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_remove()"); 355 356 laddr = ethip_nic_addr_find(nic, addr);352 353 ethip_link_addr_t *laddr = ethip_nic_addr_find(nic, addr); 357 354 if (laddr == NULL) 358 355 return ENOENT; 359 356 360 357 list_remove(&laddr->addr_list); 361 358 ethip_link_addr_delete(laddr); … … 364 361 365 362 ethip_link_addr_t *ethip_nic_addr_find(ethip_nic_t *nic, 366 iplink_srv_addr_t *addr)363 uint32_t addr) 367 364 { 368 365 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_find()"); … … 372 369 ethip_link_addr_t, addr_list); 373 370 374 if (addr ->ipv4 == laddr->addr.ipv4)371 if (addr == laddr->addr) 375 372 return laddr; 376 373 } -
uspace/srv/net/ethip/ethip_nic.h
r19a4f73 ra2e3ee6 44 44 extern ethip_nic_t *ethip_nic_find_by_iplink_sid(service_id_t); 45 45 extern int ethip_nic_send(ethip_nic_t *, void *, size_t); 46 extern int ethip_nic_addr_add(ethip_nic_t *, iplink_srv_addr_t *); 47 extern int ethip_nic_addr_remove(ethip_nic_t *, iplink_srv_addr_t *); 48 extern ethip_link_addr_t *ethip_nic_addr_find(ethip_nic_t *, 49 iplink_srv_addr_t *); 46 extern int ethip_nic_addr_add(ethip_nic_t *, uint32_t); 47 extern int ethip_nic_addr_remove(ethip_nic_t *, uint32_t); 48 extern ethip_link_addr_t *ethip_nic_addr_find(ethip_nic_t *, uint32_t); 50 49 51 50 #endif -
uspace/srv/net/ethip/pdu.c
r19a4f73 ra2e3ee6 170 170 mac48_encode(&packet->sender_hw_addr, pfmt->sender_hw_addr); 171 171 pfmt->sender_proto_addr = 172 host2uint32_t_be(packet->sender_proto_addr .ipv4);172 host2uint32_t_be(packet->sender_proto_addr); 173 173 mac48_encode(&packet->target_hw_addr, pfmt->target_hw_addr); 174 174 pfmt->target_proto_addr = 175 host2uint32_t_be(packet->target_proto_addr .ipv4);175 host2uint32_t_be(packet->target_proto_addr); 176 176 177 177 *rdata = data; … … 228 228 229 229 mac48_decode(pfmt->sender_hw_addr, &packet->sender_hw_addr); 230 packet->sender_proto_addr .ipv4=230 packet->sender_proto_addr = 231 231 uint32_t_be2host(pfmt->sender_proto_addr); 232 232 mac48_decode(pfmt->target_hw_addr, &packet->target_hw_addr); 233 packet->target_proto_addr .ipv4=233 packet->target_proto_addr = 234 234 uint32_t_be2host(pfmt->target_proto_addr); 235 235 log_msg(LOG_DEFAULT, LVL_DEBUG, "packet->tpa = %x\n", pfmt->target_proto_addr); … … 238 238 } 239 239 240 241 240 /** @} 242 241 */ -
uspace/srv/net/inetsrv/addrobj.c
r19a4f73 ra2e3ee6 112 112 inet_addrobj_t *inet_addrobj_find(inet_addr_t *addr, inet_addrobj_find_t find) 113 113 { 114 uint32_t mask; 115 116 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find(%x)", (unsigned)addr->ipv4); 117 118 fibril_mutex_lock(&addr_list_lock); 119 114 uint32_t addr_addr; 115 int rc = inet_addr_pack(addr, &addr_addr); 116 if (rc != EOK) 117 return NULL; 118 119 fibril_mutex_lock(&addr_list_lock); 120 120 121 list_foreach(addr_list, link) { 121 122 inet_addrobj_t *naddr = list_get_instance(link, 122 123 inet_addrobj_t, addr_list); 123 124 mask = inet_netmask(naddr->naddr.bits); 125 if ((naddr->naddr.ipv4 & mask) == (addr->ipv4 & mask)) { 124 125 uint32_t naddr_addr; 126 uint8_t naddr_bits; 127 rc = inet_naddr_pack(&naddr->naddr, &naddr_addr, &naddr_bits); 128 if (rc != EOK) 129 continue; 130 131 uint32_t mask = inet_netmask(naddr_bits); 132 if ((naddr_addr & mask) == (addr_addr & mask)) { 126 133 fibril_mutex_unlock(&addr_list_lock); 127 134 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: found %p", … … 218 225 { 219 226 inet_addr_t lsrc_addr; 220 inet_addr_t *ldest_addr; 221 222 lsrc_addr.ipv4 = addr->naddr.ipv4; 223 ldest_addr = ldest; 224 227 inet_naddr_addr(&addr->naddr, &lsrc_addr); 228 229 inet_addr_t *ldest_addr = ldest; 230 225 231 return inet_link_send_dgram(addr->ilink, &lsrc_addr, ldest_addr, dgram, 226 232 proto, ttl, df); -
uspace/srv/net/inetsrv/icmp.c
r19a4f73 ra2e3ee6 120 120 static int icmp_recv_echo_reply(inet_dgram_t *dgram) 121 121 { 122 icmp_echo_t *reply;123 inetping_sdu_t sdu;124 uint16_t ident;125 126 122 log_msg(LOG_DEFAULT, LVL_DEBUG, "icmp_recv_echo_reply()"); 127 123 128 124 if (dgram->size < sizeof(icmp_echo_t)) 129 125 return EINVAL; 130 131 reply = (icmp_echo_t *)dgram->data; 132 133 sdu.src = dgram->src; 134 sdu.dest = dgram->dest; 126 127 icmp_echo_t *reply = (icmp_echo_t *) dgram->data; 128 129 inetping_sdu_t sdu; 130 131 int rc = inet_addr_pack(&dgram->src, &sdu.src); 132 if (rc != EOK) 133 return rc; 134 135 rc = inet_addr_pack(&dgram->dest, &sdu.dest); 136 if (rc != EOK) 137 return rc; 138 135 139 sdu.seq_no = uint16_t_be2host(reply->seq_no); 136 140 sdu.data = reply + sizeof(icmp_echo_t); 137 141 sdu.size = dgram->size - sizeof(icmp_echo_t); 138 ident = uint16_t_be2host(reply->ident); 142 143 uint16_t ident = uint16_t_be2host(reply->ident); 139 144 140 145 return inetping_recv(ident, &sdu); … … 143 148 int icmp_ping_send(uint16_t ident, inetping_sdu_t *sdu) 144 149 { 145 inet_dgram_t dgram; 146 icmp_echo_t *request; 147 void *rdata; 148 size_t rsize; 149 uint16_t checksum; 150 int rc; 151 152 rsize = sizeof(icmp_echo_t) + sdu->size; 153 rdata = calloc(rsize, 1); 150 size_t rsize = sizeof(icmp_echo_t) + sdu->size; 151 void *rdata = calloc(rsize, 1); 154 152 if (rdata == NULL) 155 153 return ENOMEM; 156 157 request = (icmp_echo_t *)rdata;158 154 155 icmp_echo_t *request = (icmp_echo_t *)rdata; 156 159 157 request->type = ICMP_ECHO_REQUEST; 160 158 request->code = 0; … … 162 160 request->ident = host2uint16_t_be(ident); 163 161 request->seq_no = host2uint16_t_be(sdu->seq_no); 164 162 165 163 memcpy(rdata + sizeof(icmp_echo_t), sdu->data, sdu->size); 166 167 checksum = inet_checksum_calc(INET_CHECKSUM_INIT, rdata, rsize);164 165 uint16_t checksum = inet_checksum_calc(INET_CHECKSUM_INIT, rdata, rsize); 168 166 request->checksum = host2uint16_t_be(checksum); 169 170 dgram.src = sdu->src; 171 dgram.dest = sdu->dest; 167 168 inet_dgram_t dgram; 169 170 inet_addr_unpack(sdu->src, &dgram.src); 171 inet_addr_unpack(sdu->dest, &dgram.dest); 172 172 173 dgram.tos = ICMP_TOS; 173 174 dgram.data = rdata; 174 175 dgram.size = rsize; 175 176 rc = inet_route_packet(&dgram, IP_PROTO_ICMP, INET_TTL_MAX, 0);177 176 177 int rc = inet_route_packet(&dgram, IP_PROTO_ICMP, INET_TTL_MAX, 0); 178 178 179 free(rdata); 179 180 return rc; -
uspace/srv/net/inetsrv/inet_link.c
r19a4f73 ra2e3ee6 153 153 { 154 154 inet_link_t *ilink; 155 i plink_addr_t iaddr;155 inet_addr_t iaddr; 156 156 int rc; 157 157 … … 196 196 197 197 static int first = 1; 198 /* XXX For testing: set static IP address 10.0.2.15/24 */198 199 199 addr = inet_addrobj_new(); 200 200 201 if (first) { 201 addr->naddr.ipv4 = (127 << 24) + (0 << 16) + (0 << 8) + 1;202 inet_naddr(&addr->naddr, 127, 0, 0, 1, 24); 202 203 first = 0; 203 204 } else { 204 addr->naddr.ipv4 = (10 << 24) + (0 << 16) + (2 << 8) + 15; 205 } 206 addr->naddr.bits = 24; 205 /* XXX For testing: set static IP address 10.0.2.15/24 */ 206 inet_naddr(&addr->naddr, 10, 0, 2, 15, 24); 207 } 208 207 209 addr->ilink = ilink; 208 210 addr->name = str_dup("v4a"); … … 215 217 } 216 218 217 i addr.ipv4 = addr->naddr.ipv4;219 inet_naddr_addr(&addr->naddr, &iaddr); 218 220 rc = iplink_addr_add(ilink->iplink, &iaddr); 219 221 if (rc != EOK) { … … 257 259 inet_addr_t *ldest, inet_dgram_t *dgram, uint8_t proto, uint8_t ttl, int df) 258 260 { 259 iplink_sdu_t sdu;260 inet_packet_t packet;261 int rc;262 size_t offs, roffs;263 264 261 /* 265 262 * Fill packet structure. Fragmentation is performed by 266 263 * inet_pdu_encode(). 267 264 */ 265 inet_packet_t packet; 266 268 267 packet.src = dgram->src; 269 268 packet.dest = dgram->dest; … … 274 273 packet.data = dgram->data; 275 274 packet.size = dgram->size; 276 277 sdu.lsrc.ipv4 = lsrc->ipv4; 278 sdu.ldest.ipv4 = ldest->ipv4; 279 280 offs = 0; 275 276 iplink_sdu_t sdu; 277 278 int rc = inet_addr_pack(lsrc, &sdu.lsrc); 279 if (rc != EOK) 280 return rc; 281 282 rc = inet_addr_pack(ldest, &sdu.ldest); 283 if (rc != EOK) 284 return rc; 285 286 size_t offs = 0; 281 287 do { 288 size_t roffs; 289 282 290 /* Encode one fragment */ 283 291 rc = inet_pdu_encode(&packet, offs, ilink->def_mtu, &sdu.data, … … 285 293 if (rc != EOK) 286 294 return rc; 287 295 288 296 /* Send the PDU */ 289 297 rc = iplink_send(ilink->iplink, &sdu); 290 298 free(sdu.data); 291 299 292 300 offs = roffs; 293 301 } while (offs < packet.size); 294 302 295 303 return rc; 296 304 } -
uspace/srv/net/inetsrv/inetcfg.c
r19a4f73 ra2e3ee6 56 56 inet_link_t *ilink; 57 57 inet_addrobj_t *addr; 58 i plink_addr_t iaddr;58 inet_addr_t iaddr; 59 59 int rc; 60 60 … … 82 82 } 83 83 84 i addr.ipv4 = addr->naddr.ipv4;84 inet_naddr_addr(&addr->naddr, &iaddr); 85 85 rc = iplink_addr_add(ilink->iplink, &iaddr); 86 86 if (rc != EOK) { … … 254 254 } 255 255 256 naddr.ipv4 = IPC_GET_ARG1(*call); 257 naddr.bits = IPC_GET_ARG2(*call); 258 link_id = IPC_GET_ARG3(*call); 256 inet_naddr_unpack(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call), &naddr); 257 link_id = IPC_GET_ARG3(*call); 259 258 260 259 addr_id = 0; … … 279 278 static void inetcfg_addr_get_srv(ipc_callid_t callid, ipc_call_t *call) 280 279 { 280 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_get_srv()"); 281 282 sysarg_t addr_id = IPC_GET_ARG1(*call); 283 284 inet_addr_info_t ainfo; 285 286 inet_naddr_any(&ainfo.naddr); 287 ainfo.ilink = 0; 288 ainfo.name = NULL; 289 281 290 ipc_callid_t rcallid; 282 291 size_t max_size; 283 284 sysarg_t addr_id; 285 inet_addr_info_t ainfo; 286 int rc; 287 288 addr_id = IPC_GET_ARG1(*call); 289 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_addr_get_srv()"); 290 291 ainfo.naddr.ipv4 = 0; 292 ainfo.naddr.bits = 0; 293 ainfo.ilink = 0; 294 ainfo.name = NULL; 295 292 296 293 if (!async_data_read_receive(&rcallid, &max_size)) { 297 294 async_answer_0(rcallid, EREFUSED); … … 299 296 return; 300 297 } 301 302 rc = inetcfg_addr_get(addr_id, &ainfo); 303 if (rc != EOK) { 304 async_answer_0(callid, rc); 305 return; 306 } 307 298 299 int rc = inetcfg_addr_get(addr_id, &ainfo); 300 if (rc != EOK) { 301 async_answer_0(callid, rc); 302 return; 303 } 304 305 uint32_t naddr_addr; 306 uint8_t naddr_bits; 307 rc = inet_naddr_pack(&ainfo.naddr, &naddr_addr, &naddr_bits); 308 if (rc != EOK) { 309 async_answer_0(callid, rc); 310 return; 311 } 312 308 313 sysarg_t retval = async_data_read_finalize(rcallid, ainfo.name, 309 314 min(max_size, str_size(ainfo.name))); 310 315 free(ainfo.name); 311 312 async_answer_3(callid, retval, ainfo.naddr.ipv4, ainfo.naddr.bits,313 ainfo.ilink);316 317 async_answer_3(callid, retval, (sysarg_t) naddr_addr, 318 (sysarg_t) naddr_bits, ainfo.ilink); 314 319 } 315 320 … … 476 481 ipc_call_t *call) 477 482 { 483 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_create_srv()"); 484 478 485 char *name; 486 int rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN, 487 0, NULL); 488 if (rc != EOK) { 489 async_answer_0(callid, rc); 490 return; 491 } 492 479 493 inet_naddr_t dest; 480 494 inet_addr_t router; 481 sysarg_t sroute_id; 482 int rc; 483 484 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_create_srv()"); 485 486 rc = async_data_write_accept((void **) &name, true, 0, LOC_NAME_MAXLEN, 487 0, NULL); 488 if (rc != EOK) { 489 async_answer_0(callid, rc); 490 return; 491 } 492 493 dest.ipv4 = IPC_GET_ARG1(*call); 494 dest.bits = IPC_GET_ARG2(*call); 495 router.ipv4 = IPC_GET_ARG3(*call); 496 497 sroute_id = 0; 495 496 inet_naddr_unpack(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call), &dest); 497 inet_addr_unpack(IPC_GET_ARG3(*call), &router); 498 499 sysarg_t sroute_id = 0; 498 500 rc = inetcfg_sroute_create(name, &dest, &router, &sroute_id); 499 501 free(name); … … 516 518 static void inetcfg_sroute_get_srv(ipc_callid_t callid, ipc_call_t *call) 517 519 { 520 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_srv()"); 521 522 sysarg_t sroute_id = IPC_GET_ARG1(*call); 523 524 inet_sroute_info_t srinfo; 525 526 inet_naddr_any(&srinfo.dest); 527 inet_addr_any(&srinfo.router); 528 srinfo.name = NULL; 529 518 530 ipc_callid_t rcallid; 519 531 size_t max_size; 520 521 sysarg_t sroute_id;522 inet_sroute_info_t srinfo;523 int rc;524 525 sroute_id = IPC_GET_ARG1(*call);526 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_sroute_get_srv()");527 528 srinfo.dest.ipv4 = 0;529 srinfo.dest.bits = 0;530 srinfo.router.ipv4 = 0;531 srinfo.name = NULL;532 533 532 if (!async_data_read_receive(&rcallid, &max_size)) { 534 533 async_answer_0(rcallid, EREFUSED); … … 536 535 return; 537 536 } 538 539 rc = inetcfg_sroute_get(sroute_id, &srinfo); 540 if (rc != EOK) { 541 async_answer_0(callid, rc); 542 return; 543 } 544 537 538 int rc = inetcfg_sroute_get(sroute_id, &srinfo); 539 if (rc != EOK) { 540 async_answer_0(callid, rc); 541 return; 542 } 543 544 uint32_t dest_addr; 545 uint8_t dest_bits; 546 rc = inet_naddr_pack(&srinfo.dest, &dest_addr, &dest_bits); 547 if (rc != EOK) { 548 async_answer_0(callid, rc); 549 return; 550 } 551 552 uint32_t router_addr; 553 rc = inet_addr_pack(&srinfo.router, &router_addr); 554 if (rc != EOK) { 555 async_answer_0(callid, rc); 556 return; 557 } 558 545 559 sysarg_t retval = async_data_read_finalize(rcallid, srinfo.name, 546 560 min(max_size, str_size(srinfo.name))); 547 561 free(srinfo.name); 548 549 async_answer_3(callid, retval, srinfo.dest.ipv4, srinfo.dest.bits,550 srinfo.router.ipv4);562 563 async_answer_3(callid, retval, (sysarg_t) dest_addr, 564 (sysarg_t) dest_bits, (sysarg_t) router_addr); 551 565 } 552 566 -
uspace/srv/net/inetsrv/inetping.c
r19a4f73 ra2e3ee6 62 62 } 63 63 64 static int inetping_get_srcaddr(inetping_client_t *client, inet_addr_t *remote, 65 inet_addr_t *local) 66 { 67 return inet_get_srcaddr(remote, ICMP_TOS, local); 64 static int inetping_get_srcaddr(inetping_client_t *client, uint32_t remote, 65 uint32_t *local) 66 { 67 inet_addr_t remote_addr; 68 inet_addr_unpack(remote, &remote_addr); 69 70 inet_addr_t local_addr; 71 int rc = inet_get_srcaddr(&remote_addr, ICMP_TOS, &local_addr); 72 if (rc != EOK) 73 return rc; 74 75 return inet_addr_pack(&local_addr, local); 68 76 } 69 77 … … 82 90 exch = async_exchange_begin(client->sess); 83 91 84 aid_t req = async_send_3(exch, INETPING_EV_RECV, sdu->src.ipv4,85 sdu->dest.ipv4, sdu->seq_no, &answer);92 aid_t req = async_send_3(exch, INETPING_EV_RECV, (sysarg_t) sdu->src, 93 (sysarg_t) sdu->dest, sdu->seq_no, &answer); 86 94 int rc = async_data_write_start(exch, sdu->data, sdu->size); 87 95 async_exchange_end(exch); … … 116 124 } 117 125 118 sdu.src .ipv4= IPC_GET_ARG1(*call);119 sdu.dest .ipv4= IPC_GET_ARG2(*call);126 sdu.src = IPC_GET_ARG1(*call); 127 sdu.dest = IPC_GET_ARG2(*call); 120 128 sdu.seq_no = IPC_GET_ARG3(*call); 121 129 … … 129 137 ipc_callid_t callid, ipc_call_t *call) 130 138 { 131 inet_addr_t remote;132 inet_addr_t local;133 int rc;134 135 139 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetping_get_srcaddr_srv()"); 136 137 remote.ipv4= IPC_GET_ARG1(*call);138 local.ipv4= 0;139 140 rc = inetping_get_srcaddr(client, &remote, &local);141 async_answer_1(callid, rc, local.ipv4);140 141 uint32_t remote = IPC_GET_ARG1(*call); 142 uint32_t local = 0; 143 144 int rc = inetping_get_srcaddr(client, remote, &local); 145 async_answer_1(callid, rc, (sysarg_t) local); 142 146 } 143 147 -
uspace/srv/net/inetsrv/inetping.h
r19a4f73 ra2e3ee6 38 38 #define INETPING_H_ 39 39 40 #include "inetsrv.h" 41 40 42 extern void inetping_conn(ipc_callid_t, ipc_call_t *, void *); 41 43 extern int inetping_recv(uint16_t, inetping_sdu_t *); -
uspace/srv/net/inetsrv/inetsrv.c
r19a4f73 ra2e3ee6 104 104 } 105 105 106 sroute->dest.ipv4 = 0; 107 sroute->dest.bits = 0; 108 sroute->router.ipv4 = (10 << 24) | (0 << 16) | (2 << 8) | 2; 106 inet_naddr(&sroute->dest, 0, 0, 0, 0, 0); 107 inet_addr(&sroute->router, 10, 0, 2, 2); 109 108 sroute->name = str_dup("default"); 110 109 inet_sroute_add(sroute); 111 110 112 111 rc = inet_link_discovery_start(); 113 112 if (rc != EOK) 114 113 return EEXIST; … … 194 193 195 194 /* Take source address from the address object */ 196 local->ipv4 = dir.aobj->naddr.ipv4;195 inet_naddr_addr(&dir.aobj->naddr, local); 197 196 return EOK; 198 197 } … … 201 200 ipc_call_t *call) 202 201 { 202 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srcaddr_srv()"); 203 203 204 inet_addr_t remote; 204 uint8_t tos; 205 inet_addr_unpack(IPC_GET_ARG1(*call), &remote); 206 uint8_t tos = IPC_GET_ARG2(*call); 207 205 208 inet_addr_t local; 206 int rc; 207 208 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srcaddr_srv()"); 209 210 remote.ipv4 = IPC_GET_ARG1(*call); 211 tos = IPC_GET_ARG2(*call); 212 local.ipv4 = 0; 213 214 rc = inet_get_srcaddr(&remote, tos, &local); 215 async_answer_1(callid, rc, local.ipv4); 209 int rc = inet_get_srcaddr(&remote, tos, &local); 210 if (rc != EOK) { 211 async_answer_0(callid, rc); 212 return; 213 } 214 215 uint32_t local_addr; 216 rc = inet_addr_pack(&local, &local_addr); 217 if (rc != EOK) { 218 async_answer_0(callid, rc); 219 return; 220 } 221 222 async_answer_1(callid, rc, (sysarg_t) local_addr); 216 223 } 217 224 … … 219 226 ipc_call_t *call) 220 227 { 228 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send_srv()"); 229 221 230 inet_dgram_t dgram; 222 uint8_t ttl; 223 int df; 224 int rc; 225 226 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_send_srv()"); 227 228 dgram.src.ipv4 = IPC_GET_ARG1(*call); 229 dgram.dest.ipv4 = IPC_GET_ARG2(*call); 231 232 inet_addr_unpack(IPC_GET_ARG1(*call), &dgram.src); 233 inet_addr_unpack(IPC_GET_ARG2(*call), &dgram.dest); 230 234 dgram.tos = IPC_GET_ARG3(*call); 231 ttl = IPC_GET_ARG4(*call); 232 df = IPC_GET_ARG5(*call); 233 234 rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, &dgram.size); 235 236 uint8_t ttl = IPC_GET_ARG4(*call); 237 int df = IPC_GET_ARG5(*call); 238 239 int rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, 240 &dgram.size); 235 241 if (rc != EOK) { 236 242 async_answer_0(callid, rc); 237 243 return; 238 244 } 239 245 240 246 rc = inet_send(client, &dgram, client->protocol, ttl, df); 241 247 242 248 free(dgram.data); 243 249 async_answer_0(callid, rc); … … 365 371 int inet_ev_recv(inet_client_t *client, inet_dgram_t *dgram) 366 372 { 373 uint32_t src; 374 int rc = inet_addr_pack(&dgram->src, &src); 375 if (rc != EOK) 376 return rc; 377 378 uint32_t dest; 379 rc = inet_addr_pack(&dgram->dest, &dest); 380 if (rc != EOK) 381 return rc; 382 367 383 async_exch_t *exch = async_exchange_begin(client->sess); 368 384 369 385 ipc_call_t answer; 370 aid_t req = async_send_3(exch, INET_EV_RECV, dgram->src.ipv4,371 dgram->dest.ipv4, dgram->tos, &answer);372 intrc = async_data_write_start(exch, dgram->data, dgram->size);386 aid_t req = async_send_3(exch, INET_EV_RECV, (sysarg_t) src, 387 (sysarg_t) dest, dgram->tos, &answer); 388 rc = async_data_write_start(exch, dgram->data, dgram->size); 373 389 async_exchange_end(exch); 374 390 375 391 if (rc != EOK) { 376 392 async_forget(req); 377 393 return rc; 378 394 } 379 395 380 396 sysarg_t retval; 381 397 async_wait_for(req, &retval); 382 398 if (retval != EOK) 383 399 return retval; 384 400 385 401 return EOK; 386 402 } -
uspace/srv/net/inetsrv/inetsrv.h
r19a4f73 ra2e3ee6 172 172 173 173 typedef struct { 174 inet_addr_t src;175 inet_addr_t dest;174 uint32_t src; 175 uint32_t dest; 176 176 uint16_t seq_no; 177 177 void *data; -
uspace/srv/net/inetsrv/pdu.c
r19a4f73 ra2e3ee6 106 106 void **rdata, size_t *rsize, size_t *roffs) 107 107 { 108 void *data; 109 size_t size; 110 ip_header_t *hdr; 111 size_t hdr_size; 112 size_t data_offs; 113 uint16_t chksum; 114 uint16_t ident; 115 uint16_t flags_foff; 116 uint16_t foff; 117 size_t fragoff_limit; 118 size_t xfer_size; 119 size_t spc_avail; 120 size_t rem_offs; 121 108 uint32_t src_addr; 109 int rc = inet_addr_pack(&packet->src, &src_addr); 110 if (rc != EOK) 111 return rc; 112 113 uint32_t dest_addr; 114 rc = inet_addr_pack(&packet->dest, &dest_addr); 115 if (rc != EOK) 116 return rc; 117 122 118 /* Upper bound for fragment offset field */ 123 fragoff_limit = 1 << (FF_FRAGOFF_h - FF_FRAGOFF_l);124 119 size_t fragoff_limit = 1 << (FF_FRAGOFF_h - FF_FRAGOFF_l); 120 125 121 /* Verify that total size of datagram is within reasonable bounds */ 126 122 if (offs + packet->size > FRAG_OFFS_UNIT * fragoff_limit) 127 123 return ELIMIT; 128 129 hdr_size = sizeof(ip_header_t);130 data_offs = ROUND_UP(hdr_size, 4);131 124 125 size_t hdr_size = sizeof(ip_header_t); 126 size_t data_offs = ROUND_UP(hdr_size, 4); 127 132 128 assert(offs % FRAG_OFFS_UNIT == 0); 133 129 assert(offs / FRAG_OFFS_UNIT < fragoff_limit); 134 130 135 131 /* Value for the fragment offset field */ 136 foff = offs / FRAG_OFFS_UNIT;137 132 uint16_t foff = offs / FRAG_OFFS_UNIT; 133 138 134 if (hdr_size >= mtu) 139 135 return EINVAL; 140 136 141 137 /* Amount of space in the PDU available for payload */ 142 s pc_avail = mtu - hdr_size;138 size_t spc_avail = mtu - hdr_size; 143 139 spc_avail -= (spc_avail % FRAG_OFFS_UNIT); 144 140 145 141 /* Amount of data (payload) to transfer */ 146 xfer_size = min(packet->size - offs, spc_avail);147 142 size_t xfer_size = min(packet->size - offs, spc_avail); 143 148 144 /* Total PDU size */ 149 size = hdr_size + xfer_size;150 145 size_t size = hdr_size + xfer_size; 146 151 147 /* Offset of remaining payload */ 152 rem_offs = offs + xfer_size;153 148 size_t rem_offs = offs + xfer_size; 149 154 150 /* Flags */ 155 flags_foff =151 uint16_t flags_foff = 156 152 (packet->df ? BIT_V(uint16_t, FF_FLAG_DF) : 0) + 157 153 (rem_offs < packet->size ? BIT_V(uint16_t, FF_FLAG_MF) : 0) + 158 154 (foff << FF_FRAGOFF_l); 159 160 data = calloc(size, 1);155 156 void *data = calloc(size, 1); 161 157 if (data == NULL) 162 158 return ENOMEM; 163 159 164 160 /* Allocate identifier */ 165 161 fibril_mutex_lock(&ip_ident_lock); 166 ident = ++ip_ident;162 uint16_t ident = ++ip_ident; 167 163 fibril_mutex_unlock(&ip_ident_lock); 168 164 169 165 /* Encode header fields */ 170 hdr = (ip_header_t *)data; 166 ip_header_t *hdr = (ip_header_t *) data; 167 171 168 hdr->ver_ihl = (4 << VI_VERSION_l) | (hdr_size / sizeof(uint32_t)); 172 169 hdr->tos = packet->tos; … … 177 174 hdr->proto = packet->proto; 178 175 hdr->chksum = 0; 179 hdr->src_addr = host2uint32_t_be( packet->src.ipv4);180 hdr->dest_addr = host2uint32_t_be( packet->dest.ipv4);181 176 hdr->src_addr = host2uint32_t_be(src_addr); 177 hdr->dest_addr = host2uint32_t_be(dest_addr); 178 182 179 /* Compute checksum */ 183 chksum = inet_checksum_calc(INET_CHECKSUM_INIT, (void *)hdr, hdr_size); 180 uint16_t chksum = inet_checksum_calc(INET_CHECKSUM_INIT, (void *) hdr, 181 hdr_size); 184 182 hdr->chksum = host2uint16_t_be(chksum); 185 183 186 184 /* Copy payload */ 187 memcpy((uint8_t *) data + data_offs, packet->data + offs, xfer_size);188 185 memcpy((uint8_t *) data + data_offs, packet->data + offs, xfer_size); 186 189 187 *rdata = data; 190 188 *rsize = size; 191 189 *roffs = rem_offs; 192 190 193 191 return EOK; 194 192 } … … 238 236 /* XXX Checksum */ 239 237 240 packet->src.ipv4 = uint32_t_be2host(hdr->src_addr);241 packet->dest.ipv4 = uint32_t_be2host(hdr->dest_addr);238 inet_addr_unpack(uint32_t_be2host(hdr->src_addr), &packet->src); 239 inet_addr_unpack(uint32_t_be2host(hdr->dest_addr), &packet->dest); 242 240 packet->tos = hdr->tos; 243 241 packet->proto = hdr->proto; -
uspace/srv/net/inetsrv/reass.c
r19a4f73 ra2e3ee6 139 139 dgram_link); 140 140 141 if ( f1->packet.src.ipv4 == packet->src.ipv4&&142 f1->packet.dest.ipv4 == packet->dest.ipv4&&143 f1->packet.proto == packet->proto&&144 f1->packet.ident == packet->ident) {141 if ((inet_addr_compare(&f1->packet.src, &packet->src)) && 142 (inet_addr_compare(&f1->packet.dest, &packet->dest)) && 143 (f1->packet.proto == packet->proto) && 144 (f1->packet.ident == packet->ident)) { 145 145 /* Match */ 146 146 return rdg; -
uspace/srv/net/inetsrv/sroute.c
r19a4f73 ra2e3ee6 97 97 inet_sroute_t *inet_sroute_find(inet_addr_t *addr) 98 98 { 99 uint32_t mask; 100 inet_sroute_t *best; 101 102 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find(%x)", (unsigned)addr->ipv4); 103 104 fibril_mutex_lock(&sroute_list_lock); 105 106 best = NULL; 107 108 list_foreach(sroute_list, link) { 109 inet_sroute_t *sroute = list_get_instance(link, 110 inet_sroute_t, sroute_list); 111 99 uint32_t addr_addr; 100 int rc = inet_addr_pack(addr, &addr_addr); 101 if (rc != EOK) 102 return NULL; 103 104 inet_sroute_t *best = NULL; 105 uint8_t best_bits = 0; 106 107 fibril_mutex_lock(&sroute_list_lock); 108 109 list_foreach(sroute_list, link) { 110 inet_sroute_t *sroute = list_get_instance(link, 111 inet_sroute_t, sroute_list); 112 113 uint32_t dest_addr; 114 uint8_t dest_bits; 115 rc = inet_naddr_pack(&sroute->dest, &dest_addr, &dest_bits); 116 if (rc != EOK) 117 continue; 118 112 119 /* Look for the most specific route */ 113 if ( best != NULL && best->dest.bits >= sroute->dest.bits)120 if ((best != NULL) && (best_bits >= dest_bits)) 114 121 continue; 115 116 mask = inet_netmask(sroute->dest.bits); 117 if ((sroute->dest.ipv4 & mask) == (addr->ipv4 & mask)) { 118 fibril_mutex_unlock(&sroute_list_lock); 119 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: found %p", 122 123 uint32_t mask = inet_netmask(dest_bits); 124 if ((dest_addr & mask) == (addr_addr & mask)) { 125 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: found candidate %p", 120 126 sroute); 121 return sroute; 127 128 best = sroute; 129 best_bits = dest_bits; 122 130 } 123 131 } 124 125 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: Not found"); 126 fibril_mutex_unlock(&sroute_list_lock); 127 128 return NULL; 132 133 if (best == NULL) 134 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_sroute_find: Not found"); 135 136 fibril_mutex_unlock(&sroute_list_lock); 137 138 return best; 129 139 } 130 140 -
uspace/srv/net/loopip/loopip.c
r19a4f73 ra2e3ee6 50 50 static int loopip_send(iplink_srv_t *srv, iplink_srv_sdu_t *sdu); 51 51 static int loopip_get_mtu(iplink_srv_t *srv, size_t *mtu); 52 static int loopip_addr_add(iplink_srv_t *srv, iplink_srv_addr_t *addr);53 static int loopip_addr_remove(iplink_srv_t *srv, iplink_srv_addr_t *addr);52 static int loopip_addr_add(iplink_srv_t *srv, uint32_t addr); 53 static int loopip_addr_remove(iplink_srv_t *srv, uint32_t addr); 54 54 55 55 static void loopip_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); … … 189 189 } 190 190 191 static int loopip_addr_add(iplink_srv_t *srv, iplink_srv_addr_t *addr)192 { 193 log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_addr_add(0x%" PRIx32 ")", addr ->ipv4);194 return EOK; 195 } 196 197 static int loopip_addr_remove(iplink_srv_t *srv, iplink_srv_addr_t *addr)198 { 199 log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_addr_remove(0x%" PRIx32 ")", addr ->ipv4);191 static int loopip_addr_add(iplink_srv_t *srv, uint32_t addr) 192 { 193 log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_addr_add(0x%" PRIx32 ")", addr); 194 return EOK; 195 } 196 197 static int loopip_addr_remove(iplink_srv_t *srv, uint32_t addr) 198 { 199 log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_addr_remove(0x%" PRIx32 ")", addr); 200 200 return EOK; 201 201 } -
uspace/srv/net/tcp/conn.c
r19a4f73 ra2e3ee6 312 312 static bool tcp_socket_match(tcp_sock_t *sock, tcp_sock_t *patt) 313 313 { 314 log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_socket_match(sock=(%x,%u), pat=(%x,%u))", 315 sock->addr.ipv4, sock->port, patt->addr.ipv4, patt->port); 316 317 if (patt->addr.ipv4 != TCP_IPV4_ANY && 318 patt->addr.ipv4 != sock->addr.ipv4) 314 if ((!inet_addr_is_any(&patt->addr)) && 315 (!inet_addr_compare(&patt->addr, &sock->addr))) 319 316 return false; 320 317 321 if ( patt->port != TCP_PORT_ANY&&322 patt->port != sock->port)318 if ((patt->port != TCP_PORT_ANY) && 319 (patt->port != sock->port)) 323 320 return false; 324 321 … … 354 351 { 355 352 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref(%p)", sp); 356 357 log_msg(LOG_DEFAULT, LVL_DEBUG2, "compare conn (f:(%x,%u), l:(%x,%u))",358 sp->foreign.addr.ipv4, sp->foreign.port,359 sp->local.addr.ipv4, sp->local.port);360 353 361 354 fibril_mutex_lock(&conn_list_lock); … … 364 357 tcp_conn_t *conn = list_get_instance(link, tcp_conn_t, link); 365 358 tcp_sockpair_t *csp = &conn->ident; 366 367 log_msg(LOG_DEFAULT, LVL_DEBUG2, " - with (f:(%x,%u), l:(%x,%u))",368 csp->foreign.addr.ipv4, csp->foreign.port,369 csp->local.addr.ipv4, csp->local.port);370 359 371 360 if (tcp_sockpair_match(sp, csp)) { -
uspace/srv/net/tcp/pdu.c
r19a4f73 ra2e3ee6 146 146 static void tcp_phdr_setup(tcp_pdu_t *pdu, tcp_phdr_t *phdr) 147 147 { 148 phdr->src_addr = host2uint32_t_be(pdu->src_addr.ipv4); 149 phdr->dest_addr = host2uint32_t_be(pdu->dest_addr.ipv4); 148 // FIXME: Check for correctness 149 150 uint32_t src_addr; 151 inet_addr_pack(&pdu->src_addr, &src_addr); 152 153 uint32_t dest_addr; 154 inet_addr_pack(&pdu->dest_addr, &dest_addr); 155 156 phdr->src_addr = host2uint32_t_be(src_addr); 157 phdr->dest_addr = host2uint32_t_be(dest_addr); 150 158 phdr->zero = 0; 151 159 phdr->protocol = 6; /* XXX Magic number */ -
uspace/srv/net/tcp/sock.c
r19a4f73 ra2e3ee6 179 179 } 180 180 181 sock->laddr.ipv4 = TCP_IPV4_ANY;181 inet_addr_any(&sock->laddr); 182 182 sock->lconn = NULL; 183 183 sock->backlog = 0; … … 314 314 log_msg(LOG_DEFAULT, LVL_DEBUG, " - open connections"); 315 315 316 lsocket.addr.ipv4 = TCP_IPV4_ANY;316 inet_addr_any(&lsocket.addr); 317 317 lsocket.port = sock_core->port; 318 fsocket.addr.ipv4 = TCP_IPV4_ANY; 318 319 inet_addr_any(&fsocket.addr); 319 320 fsocket.port = TCP_PORT_ANY; 320 321 … … 396 397 fibril_mutex_lock(&socket->lock); 397 398 398 if ( socket->laddr.ipv4 == TCP_IPV4_ANY) {399 if (inet_addr_is_any(&socket->laddr)) { 399 400 /* Determine local IP address */ 400 inet_addr_t loc_addr, rem_addr; 401 402 rem_addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr); 401 inet_addr_t loc_addr; 402 inet_addr_t rem_addr; 403 404 inet_addr_unpack(uint32_t_be2host(addr->sin_addr.s_addr), 405 &rem_addr); 403 406 rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr); 404 407 if (rc != EOK) { … … 409 412 return; 410 413 } 411 412 socket->laddr.ipv4 = loc_addr.ipv4; 413 log_msg(LOG_DEFAULT, LVL_DEBUG, "Local IP address is %x", socket->laddr.ipv4); 414 } 415 416 lsocket.addr.ipv4 = socket->laddr.ipv4; 414 415 socket->laddr = loc_addr; 416 } 417 418 lsocket.addr = socket->laddr; 417 419 lsocket.port = sock_core->port; 418 fsocket.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr); 420 421 inet_addr_unpack(uint32_t_be2host(addr->sin_addr.s_addr), 422 &fsocket.addr); 419 423 fsocket.port = uint16_t_be2host(addr->sin_port); 420 424 … … 507 511 /* Replenish listening connection */ 508 512 509 lsocket.addr.ipv4 = TCP_IPV4_ANY;513 inet_addr_any(&lsocket.addr); 510 514 lsocket.port = sock_core->port; 511 fsocket.addr.ipv4 = TCP_IPV4_ANY; 515 516 inet_addr_any(&fsocket.addr); 512 517 fsocket.port = TCP_PORT_ANY; 513 518 … … 728 733 729 734 if (IPC_GET_IMETHOD(call) == NET_SOCKET_RECVFROM) { 730 /* Fill addr */735 /* Fill address */ 731 736 rsock = &socket->conn->ident.foreign; 737 738 uint32_t rsock_addr; 739 int rc = inet_addr_pack(&rsock->addr, &rsock_addr); 740 if (rc != EOK) { 741 fibril_mutex_unlock(&socket->recv_buffer_lock); 742 fibril_mutex_unlock(&socket->lock); 743 async_answer_0(callid, rc); 744 return; 745 } 746 732 747 addr.sin_family = AF_INET; 733 addr.sin_addr.s_addr = host2uint32_t_be(rsock ->addr.ipv4);748 addr.sin_addr.s_addr = host2uint32_t_be(rsock_addr); 734 749 addr.sin_port = host2uint16_t_be(rsock->port); 735 750 -
uspace/srv/net/tcp/tcp.c
r19a4f73 ra2e3ee6 115 115 } 116 116 117 pdu->src_addr.ipv4 = dgram->src.ipv4; 118 pdu->dest_addr.ipv4 = dgram->dest.ipv4; 119 log_msg(LOG_DEFAULT, LVL_DEBUG, "src: 0x%08x, dest: 0x%08x", 120 pdu->src_addr.ipv4, pdu->dest_addr.ipv4); 117 pdu->src_addr = dgram->src; 118 pdu->dest_addr = dgram->dest; 121 119 122 120 tcp_received_pdu(pdu); … … 145 143 pdu->text_size); 146 144 147 dgram.src .ipv4 = pdu->src_addr.ipv4;148 dgram.dest .ipv4 = pdu->dest_addr.ipv4;145 dgram.src = pdu->src_addr; 146 dgram.dest = pdu->dest_addr; 149 147 dgram.tos = 0; 150 148 dgram.data = pdu_raw; -
uspace/srv/net/tcp/tcp_type.h
r19a4f73 ra2e3ee6 43 43 #include <socket_core.h> 44 44 #include <sys/types.h> 45 #include <inet/addr.h> 45 46 46 47 struct tcp_conn; … … 112 113 113 114 typedef struct { 114 uint32_t ipv4; 115 } netaddr_t; 116 117 typedef struct { 118 netaddr_t addr; 115 inet_addr_t addr; 119 116 uint16_t port; 120 117 } tcp_sock_t; 121 122 enum netaddr {123 TCP_IPV4_ANY = 0124 };125 118 126 119 enum tcp_port { … … 313 306 typedef struct { 314 307 /** Source address */ 315 netaddr_t src_addr;308 inet_addr_t src_addr; 316 309 /** Destination address */ 317 netaddr_t dest_addr;318 310 inet_addr_t dest_addr; 311 319 312 /** Encoded header */ 320 313 void *header; … … 344 337 tcp_conn_t *conn; 345 338 /** Local address */ 346 netaddr_t laddr;339 inet_addr_t laddr; 347 340 /** Backlog size */ 348 341 int backlog; -
uspace/srv/net/tcp/test.c
r19a4f73 ra2e3ee6 57 57 58 58 printf("test_srv()\n"); 59 60 inet_addr(&lsock.addr, 127, 0, 0, 1); 59 61 lsock.port = 80; 60 lsock.addr.ipv4 = 0x7f000001; 62 63 inet_addr(&fsock.addr, 127, 0, 0, 1); 61 64 fsock.port = 1024; 62 fsock.addr.ipv4 = 0x7f000001;65 63 66 printf("S: User open...\n"); 64 67 tcp_uc_open(&lsock, &fsock, ap_passive, 0, &conn); … … 95 98 96 99 printf("test_cli()\n"); 97 100 101 inet_addr(&lsock.addr, 127, 0, 0, 1); 98 102 lsock.port = 1024; 99 lsock.addr.ipv4 = 0x7f000001; 103 104 inet_addr(&fsock.addr, 127, 0, 0, 1); 100 105 fsock.port = 80; 101 fsock.addr.ipv4 = 0x7f000001;102 106 103 107 async_usleep(1000*1000*3); -
uspace/srv/net/tcp/tqueue.c
r19a4f73 ra2e3ee6 282 282 void tcp_transmit_segment(tcp_sockpair_t *sp, tcp_segment_t *seg) 283 283 { 284 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_transmit_segment(f:(%x,%u),l:(%x,%u), %p)",285 sp->foreign.addr.ipv4, sp->foreign.port,286 sp->local.addr.ipv4, sp->local.port, seg);287 288 284 log_msg(LOG_DEFAULT, LVL_DEBUG, "SEG.SEQ=%" PRIu32 ", SEG.WND=%" PRIu32, 289 285 seg->seq, seg->wnd); -
uspace/srv/net/tcp/ucall.c
r19a4f73 ra2e3ee6 298 298 tcp_conn_t *conn; 299 299 300 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_as_segment_arrived(f:(%x,%u), l:(%x,%u))",301 sp->foreign.addr.ipv4, sp->foreign.port,302 sp->local.addr.ipv4, sp->local.port);303 304 300 conn = tcp_conn_find_ref(sp); 305 301 if (conn == NULL) { … … 319 315 } 320 316 321 if (conn->ident.foreign.addr.ipv4 == TCP_IPV4_ANY) 322 conn->ident.foreign.addr.ipv4 = sp->foreign.addr.ipv4; 317 if (inet_addr_is_any(&conn->ident.foreign.addr)) 318 conn->ident.foreign.addr = sp->foreign.addr; 319 323 320 if (conn->ident.foreign.port == TCP_PORT_ANY) 324 321 conn->ident.foreign.port = sp->foreign.port; 325 if (conn->ident.local.addr.ipv4 == TCP_IPV4_ANY) 326 conn->ident.local.addr.ipv4 = sp->local.addr.ipv4; 322 323 if (inet_addr_is_any(&conn->ident.local.addr)) 324 conn->ident.local.addr = sp->local.addr; 327 325 328 326 tcp_conn_segment_arrived(conn, seg); -
uspace/srv/net/udp/assoc.c
r19a4f73 ra2e3ee6 252 252 sp.foreign = *fsock; 253 253 254 if ((inet 2_addr_is_any(&sp.foreign.addr)) ||254 if ((inet_addr_is_any(&sp.foreign.addr)) || 255 255 (sp.foreign.port == UDP_PORT_ANY)) 256 256 return EINVAL; … … 372 372 static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt) 373 373 { 374 if ((!inet 2_addr_is_any(&patt->addr)) &&375 (!inet 2_addr_compare(&patt->addr, &sock->addr)))374 if ((!inet_addr_is_any(&patt->addr)) && 375 (!inet_addr_compare(&patt->addr, &sock->addr))) 376 376 return false; 377 377 -
uspace/srv/net/udp/pdu.c
r19a4f73 ra2e3ee6 89 89 90 90 uint32_t src; 91 inet 2_addr_pack(&pdu->src, &src);91 inet_addr_pack(&pdu->src, &src); 92 92 93 93 uint32_t dest; 94 inet 2_addr_pack(&pdu->dest, &dest);94 inet_addr_pack(&pdu->dest, &dest); 95 95 96 96 phdr->src_addr = host2uint32_t_be(src); -
uspace/srv/net/udp/sock.c
r19a4f73 ra2e3ee6 201 201 socket = (udp_sockdata_t *) sock_core->specific_data; 202 202 203 inet 2_addr_unpack(uint32_t_be2host(addr->sin_addr.s_addr),203 inet_addr_unpack(uint32_t_be2host(addr->sin_addr.s_addr), 204 204 &fsock.addr); 205 205 fsock.port = sock_core->port; … … 270 270 } 271 271 272 inet 2_addr_unpack(uint32_t_be2host(addr->sin_addr.s_addr),272 inet_addr_unpack(uint32_t_be2host(addr->sin_addr.s_addr), 273 273 &fsock.addr); 274 274 fsock.port = uint16_t_be2host(addr->sin_port); … … 316 316 fibril_mutex_lock(&socket->lock); 317 317 318 if (inet 2_addr_is_any(&socket->assoc->ident.local.addr)) {318 if (inet_addr_is_any(&socket->assoc->ident.local.addr)) { 319 319 /* Determine local IP address */ 320 inet 2_addr_t loc_addr;321 inet 2_addr_t rem_addr;320 inet_addr_t loc_addr; 321 inet_addr_t rem_addr; 322 322 323 323 rem_addr = fsock_ptr ? fsock.addr : 324 324 socket->assoc->ident.foreign.addr; 325 325 326 int rc = inet 2_get_srcaddr(&rem_addr, 0, &loc_addr);326 int rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr); 327 327 if (rc != EOK) { 328 328 fibril_mutex_unlock(&socket->lock); … … 479 479 /* Fill address */ 480 480 uint32_t rsock_addr; 481 int rc = inet 2_addr_pack(&rsock->addr, &rsock_addr);481 int rc = inet_addr_pack(&rsock->addr, &rsock_addr); 482 482 if (rc != EOK) { 483 483 fibril_mutex_unlock(&socket->recv_buffer_lock); -
uspace/srv/net/udp/udp_inet.c
r19a4f73 ra2e3ee6 66 66 pdu->data = dgram->data; 67 67 pdu->data_size = dgram->size; 68 69 inet_inet2(&dgram->src, &pdu->src);70 inet_inet2(&dgram->dest, &pdu->dest);68 69 pdu->src = dgram->src; 70 pdu->dest = dgram->dest; 71 71 72 72 udp_received_pdu(pdu); … … 84 84 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_transmit_pdu()"); 85 85 86 inet2_inet(&pdu->src, &dgram.src);87 inet2_inet(&pdu->dest, &dgram.dest);86 dgram.src = pdu->src; 87 dgram.dest = pdu->dest; 88 88 dgram.tos = 0; 89 89 dgram.data = pdu->data; -
uspace/srv/net/udp/udp_type.h
r19a4f73 ra2e3ee6 40 40 #include <socket_core.h> 41 41 #include <sys/types.h> 42 #include <inet/addr 2.h>42 #include <inet/addr.h> 43 43 44 44 #define UDP_FRAGMENT_SIZE 4096 … … 66 66 67 67 typedef struct { 68 inet 2_addr_t addr;68 inet_addr_t addr; 69 69 uint16_t port; 70 70 } udp_sock_t; … … 86 86 typedef struct { 87 87 /** Source address */ 88 inet 2_addr_t src;88 inet_addr_t src; 89 89 /** Destination address */ 90 inet 2_addr_t dest;90 inet_addr_t dest; 91 91 92 92 /** Encoded PDU data including header */
Note:
See TracChangeset
for help on using the changeset viewer.