Changeset bdae198 in mainline for uspace/srv
- Timestamp:
- 2013-08-04T12:01:10Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ea509069
- Parents:
- b08879c2 (diff), d856110 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/srv/net
- Files:
-
- 4 added
- 37 edited
-
dnsrsrv/dns_msg.c (modified) (3 diffs)
-
dnsrsrv/dns_msg.h (modified) (2 diffs)
-
dnsrsrv/dns_std.h (modified) (1 diff)
-
dnsrsrv/dnsrsrv.c (modified) (2 diffs)
-
dnsrsrv/query.c (modified) (4 diffs)
-
dnsrsrv/query.h (modified) (1 diff)
-
ethip/ethip.c (modified) (4 diffs)
-
ethip/ethip.h (modified) (2 diffs)
-
ethip/ethip_nic.c (modified) (13 diffs)
-
ethip/pdu.c (modified) (1 diff)
-
inetsrv/Makefile (modified) (1 diff)
-
inetsrv/addrobj.c (modified) (3 diffs)
-
inetsrv/icmp.c (modified) (1 diff)
-
inetsrv/icmpv6.c (modified) (7 diffs)
-
inetsrv/icmpv6_std.h (modified) (5 diffs)
-
inetsrv/inet_link.c (modified) (7 diffs)
-
inetsrv/inet_link.h (modified) (1 diff)
-
inetsrv/inet_std.h (modified) (4 diffs)
-
inetsrv/inetping6.c (modified) (2 diffs)
-
inetsrv/inetsrv.c (modified) (2 diffs)
-
inetsrv/inetsrv.h (modified) (2 diffs)
-
inetsrv/ndp.c (added)
-
inetsrv/ndp.h (added)
-
inetsrv/ntrans.c (added)
-
inetsrv/ntrans.h (added)
-
inetsrv/pdu.c (modified) (9 diffs)
-
inetsrv/pdu.h (modified) (2 diffs)
-
inetsrv/reass.c (modified) (1 diff)
-
loopip/loopip.c (modified) (7 diffs)
-
slip/slip.c (modified) (5 diffs)
-
tcp/conn.c (modified) (3 diffs)
-
tcp/pdu.c (modified) (1 diff)
-
tcp/sock.c (modified) (6 diffs)
-
tcp/std.h (modified) (3 diffs)
-
tcp/tcp.c (modified) (1 diff)
-
tcp/tqueue.c (modified) (1 diff)
-
tcp/ucall.c (modified) (1 diff)
-
udp/assoc.c (modified) (1 diff)
-
udp/pdu.c (modified) (1 diff)
-
udp/sock.c (modified) (5 diffs)
-
udp/std.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/dnsrsrv/dns_msg.c
rb08879c2 rbdae198 296 296 uint32_t dns_uint32_t_decode(uint8_t *buf, size_t buf_size) 297 297 { 298 uint32_t w;299 298 assert(buf_size >= 4); 300 301 w = ((uint32_t) buf[0] << 24) +299 300 uint32_t w = ((uint32_t) buf[0] << 24) + 302 301 ((uint32_t) buf[1] << 16) + 303 302 ((uint32_t) buf[2] << 8) + 304 303 buf[3]; 305 304 306 305 return w; 306 } 307 308 /** Decode unaligned big-endian 128-bit integer */ 309 void dns_addr128_t_decode(uint8_t *buf, size_t buf_size, addr128_t addr) 310 { 311 assert(buf_size >= 16); 312 313 addr128_t_be2host(buf, addr); 307 314 } 308 315 … … 400 407 int rc; 401 408 402 rr = calloc(1, sizeof (dns_rr_t));409 rr = calloc(1, sizeof(dns_rr_t)); 403 410 if (rr == NULL) 404 411 return ENOMEM; … … 427 434 428 435 rr->rtype = dns_uint16_t_decode(bp, bsz); 429 bp += sizeof(uint16_t); bsz -= sizeof(uint16_t); 436 bp += sizeof(uint16_t); 437 bsz -= sizeof(uint16_t); 430 438 431 439 rr->rclass = dns_uint16_t_decode(bp, bsz); 432 bp += sizeof(uint16_t); bsz -= sizeof(uint16_t); 440 bp += sizeof(uint16_t); 441 bsz -= sizeof(uint16_t); 433 442 434 443 rr->ttl = dns_uint32_t_decode(bp, bsz); 435 bp += sizeof(uint32_t); bsz -= sizeof(uint32_t); 444 bp += sizeof(uint32_t); 445 bsz -= sizeof(uint32_t); 436 446 437 447 rdlength = dns_uint16_t_decode(bp, bsz); 438 bp += sizeof(uint16_t); bsz -= sizeof(uint16_t); 448 bp += sizeof(uint16_t); 449 bsz -= sizeof(uint16_t); 439 450 440 451 if (rdlength > bsz) { -
uspace/srv/net/dnsrsrv/dns_msg.h
rb08879c2 rbdae198 40 40 #include <stdbool.h> 41 41 #include <stdint.h> 42 #include <inet/addr.h> 42 43 #include "dns_std.h" 43 44 #include "dns_type.h" … … 49 50 extern int dns_name_decode(dns_pdu_t *, size_t, char **, size_t *); 50 51 extern uint32_t dns_uint32_t_decode(uint8_t *, size_t); 52 extern void dns_addr128_t_decode(uint8_t *, size_t, addr128_t); 51 53 52 54 #endif -
uspace/srv/net/dnsrsrv/dns_std.h
rb08879c2 rbdae198 65 65 DTYPE_MX = 15, 66 66 DTYPE_TXT = 16, 67 DTYPE_AAAA = 28, 67 68 DQTYPE_AXFR = 252, 68 69 DQTYPE_MAILB = 253, -
uspace/srv/net/dnsrsrv/dnsrsrv.c
rb08879c2 rbdae198 89 89 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srvaddr_srv()"); 90 90 91 uint16_t af = IPC_GET_ARG1(*icall); 92 91 93 char *name; 92 94 int rc = async_data_write_accept((void **) &name, true, 0, … … 98 100 99 101 dns_host_info_t *hinfo; 100 rc = dns_name2host(name, &hinfo );102 rc = dns_name2host(name, &hinfo, af); 101 103 if (rc != EOK) { 102 104 async_answer_0(iid, rc); -
uspace/srv/net/dnsrsrv/query.c
rb08879c2 rbdae198 39 39 #include <stdlib.h> 40 40 #include <str.h> 41 41 #include <net/socket_codes.h> 42 42 #include "dns_msg.h" 43 43 #include "dns_std.h" … … 48 48 static uint16_t msg_id; 49 49 50 int dns_name2host(const char *name, dns_host_info_t **rinfo) 50 static int dns_name_query(const char *name, dns_qtype_t qtype, 51 dns_host_info_t *info) 51 52 { 52 dns_message_t *msg; 53 dns_message_t *amsg; 54 dns_question_t *question; 55 dns_host_info_t *info; 56 char *sname, *cname; 57 size_t eoff; 58 int rc; 59 60 question = calloc(1, sizeof(dns_question_t)); 61 if (question == NULL) 62 return ENOMEM; 63 64 question->qname = (char *)name; 65 question->qtype = DTYPE_A; 53 /* Start with the caller-provided name */ 54 char *sname = str_dup(name); 55 if (sname == NULL) 56 return ENOMEM; 57 58 char *qname = str_dup(name); 59 if (qname == NULL) { 60 free(sname); 61 return ENOMEM; 62 } 63 64 dns_question_t *question = calloc(1, sizeof(dns_question_t)); 65 if (question == NULL) { 66 free(qname); 67 free(sname); 68 return ENOMEM; 69 } 70 71 question->qname = qname; 72 question->qtype = qtype; 66 73 question->qclass = DC_IN; 67 68 msg = dns_message_new(); 69 if (msg == NULL) 70 return ENOMEM; 71 72 list_append(&question->msg, &msg->question); 73 74 75 dns_message_t *msg = dns_message_new(); 76 if (msg == NULL) { 77 free(question); 78 free(qname); 79 free(sname); 80 return ENOMEM; 81 } 82 74 83 msg->id = msg_id++; 75 84 msg->qr = QR_QUERY; … … 79 88 msg->rd = true; 80 89 msg->ra = false; 81 82 rc = dns_request(msg, &amsg); 90 91 list_append(&question->msg, &msg->question); 92 93 dns_message_t *amsg; 94 int rc = dns_request(msg, &amsg); 83 95 if (rc != EOK) { 96 dns_message_destroy(msg); 97 free(sname); 84 98 return rc; 85 99 } 86 87 /* Start with the caller-provided name */ 88 sname = str_dup(name); 89 100 90 101 list_foreach(amsg->answer, link) { 91 102 dns_rr_t *rr = list_get_instance(link, dns_rr_t, msg); 92 103 93 104 log_msg(LOG_DEFAULT, LVL_DEBUG, " - '%s' %u/%u, dsize %zu", 94 rr->name, rr->rtype, rr->rclass, rr->rdata_size); 95 96 if (rr->rtype == DTYPE_CNAME && rr->rclass == DC_IN && 97 str_cmp(rr->name, sname) == 0) { 105 rr->name, rr->rtype, rr->rclass, rr->rdata_size); 106 107 if ((rr->rtype == DTYPE_CNAME) && (rr->rclass == DC_IN) && 108 (str_cmp(rr->name, sname) == 0)) { 109 98 110 log_msg(LOG_DEFAULT, LVL_DEBUG, "decode cname (%p, %zu, %zu)", 99 111 amsg->pdu.data, amsg->pdu.size, rr->roff); 112 113 char *cname; 114 size_t eoff; 100 115 rc = dns_name_decode(&amsg->pdu, rr->roff, &cname, &eoff); 101 116 if (rc != EOK) { 102 log_msg(LOG_DEFAULT, LVL_DEBUG, 103 "error decoding cname"); 104 assert(rc == EINVAL || rc == ENOMEM); 117 assert((rc == EINVAL) || (rc == ENOMEM)); 118 119 log_msg(LOG_DEFAULT, LVL_DEBUG, "error decoding cname"); 120 105 121 dns_message_destroy(msg); 106 122 dns_message_destroy(amsg); 123 free(sname); 124 107 125 return rc; 108 126 } 109 127 110 128 log_msg(LOG_DEFAULT, LVL_DEBUG, "name = '%s' " 111 129 "cname = '%s'", sname, cname); 112 130 131 /* Continue looking for the more canonical name */ 113 132 free(sname); 114 /* Continue looking for the more canonical name */115 133 sname = cname; 116 134 } 117 118 if ( rr->rtype == DTYPE_A && rr->rclass == DC_IN&&119 rr->rdata_size == sizeof(uint32_t) &&120 str_cmp(rr->name, sname) == 0) {121 122 info = calloc(1, sizeof(dns_host_info_t));123 if (info == NULL) {135 136 if ((qtype == DTYPE_A) && (rr->rtype == DTYPE_A) && 137 (rr->rclass == DC_IN) && (rr->rdata_size == sizeof(addr32_t)) && 138 (str_cmp(rr->name, sname) == 0)) { 139 140 info->cname = str_dup(rr->name); 141 if (info->cname == NULL) { 124 142 dns_message_destroy(msg); 125 143 dns_message_destroy(amsg); 144 free(sname); 145 126 146 return ENOMEM; 127 147 } 128 129 info->cname = str_dup(rr->name); 148 130 149 inet_addr_set(dns_uint32_t_decode(rr->rdata, rr->rdata_size), 131 150 &info->addr); … … 133 152 dns_message_destroy(msg); 134 153 dns_message_destroy(amsg); 135 *rinfo = info; 154 free(sname); 155 136 156 return EOK; 137 157 } 138 } 139 158 159 if ((qtype == DTYPE_AAAA) && (rr->rtype == DTYPE_AAAA) && 160 (rr->rclass == DC_IN) && (rr->rdata_size == sizeof(addr128_t)) && 161 (str_cmp(rr->name, sname) == 0)) { 162 163 info->cname = str_dup(rr->name); 164 if (info->cname == NULL) { 165 dns_message_destroy(msg); 166 dns_message_destroy(amsg); 167 free(sname); 168 169 return ENOMEM; 170 } 171 172 addr128_t addr; 173 dns_addr128_t_decode(rr->rdata, rr->rdata_size, addr); 174 175 inet_addr_set6(addr, &info->addr); 176 177 dns_message_destroy(msg); 178 dns_message_destroy(amsg); 179 free(sname); 180 181 return EOK; 182 } 183 } 184 185 log_msg(LOG_DEFAULT, LVL_DEBUG, "'%s' not resolved, fail", sname); 186 140 187 dns_message_destroy(msg); 141 188 dns_message_destroy(amsg); 142 log_msg(LOG_DEFAULT, LVL_DEBUG, "'%s' not resolved, fail",sname);143 189 free(sname); 190 144 191 return EIO; 192 } 193 194 int dns_name2host(const char *name, dns_host_info_t **rinfo, uint16_t af) 195 { 196 dns_host_info_t *info = calloc(1, sizeof(dns_host_info_t)); 197 if (info == NULL) 198 return ENOMEM; 199 200 int rc; 201 202 switch (af) { 203 case AF_NONE: 204 rc = dns_name_query(name, DTYPE_AAAA, info); 205 206 if (rc != EOK) 207 rc = dns_name_query(name, DTYPE_A, info); 208 209 break; 210 case AF_INET: 211 rc = dns_name_query(name, DTYPE_A, info); 212 break; 213 case AF_INET6: 214 rc = dns_name_query(name, DTYPE_AAAA, info); 215 break; 216 default: 217 rc = EINVAL; 218 } 219 220 if (rc == EOK) 221 *rinfo = info; 222 else 223 free(info); 224 225 return rc; 145 226 } 146 227 -
uspace/srv/net/dnsrsrv/query.h
rb08879c2 rbdae198 39 39 #include "dns_type.h" 40 40 41 extern int dns_name2host(const char *, dns_host_info_t ** );41 extern int dns_name2host(const char *, dns_host_info_t **, uint16_t); 42 42 extern void dns_hostinfo_destroy(dns_host_info_t *); 43 43 -
uspace/srv/net/ethip/ethip.c
rb08879c2 rbdae198 56 56 static int ethip_close(iplink_srv_t *srv); 57 57 static int ethip_send(iplink_srv_t *srv, iplink_sdu_t *sdu); 58 static int ethip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu); 58 59 static int ethip_get_mtu(iplink_srv_t *srv, size_t *mtu); 60 static int ethip_get_mac48(iplink_srv_t *srv, addr48_t *mac); 59 61 static int ethip_addr_add(iplink_srv_t *srv, inet_addr_t *addr); 60 62 static int ethip_addr_remove(iplink_srv_t *srv, inet_addr_t *addr); … … 66 68 .close = ethip_close, 67 69 .send = ethip_send, 70 .send6 = ethip_send6, 68 71 .get_mtu = ethip_get_mtu, 72 .get_mac48 = ethip_get_mac48, 69 73 .addr_add = ethip_addr_add, 70 74 .addr_remove = ethip_addr_remove … … 169 173 170 174 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 171 172 addr32_t src_v4;173 addr128_t src_v6;174 uint16_t src_af = inet_addr_get(&sdu->src, &src_v4, &src_v6);175 176 addr32_t dest_v4;177 addr128_t dest_v6;178 uint16_t dest_af = inet_addr_get(&sdu->dest, &dest_v4, &dest_v6);179 180 if (src_af != dest_af)181 return EINVAL;182 183 int rc;184 175 eth_frame_t frame; 185 176 186 switch (src_af) { 187 case AF_INET: 188 rc = arp_translate(nic, src_v4, dest_v4, frame.dest); 189 if (rc != EOK) { 190 log_msg(LOG_DEFAULT, LVL_WARN, "Failed to look up IPv4 address 0x%" 191 PRIx32, dest_v4); 192 return rc; 193 } 194 195 addr48(nic->mac_addr, frame.src); 196 frame.etype_len = ETYPE_IP; 197 frame.data = sdu->data; 198 frame.size = sdu->size; 199 200 break; 201 case AF_INET6: 202 // FIXME TODO 203 return ENOTSUP; 204 default: 205 return EINVAL; 206 } 177 int rc = arp_translate(nic, sdu->src, sdu->dest, frame.dest); 178 if (rc != EOK) { 179 log_msg(LOG_DEFAULT, LVL_WARN, "Failed to look up IPv4 address 0x%" 180 PRIx32, sdu->dest); 181 return rc; 182 } 183 184 addr48(nic->mac_addr, frame.src); 185 frame.etype_len = ETYPE_IP; 186 frame.data = sdu->data; 187 frame.size = sdu->size; 207 188 208 189 void *data; 209 190 size_t size; 210 191 rc = eth_pdu_encode(&frame, &data, &size); 192 if (rc != EOK) 193 return rc; 194 195 rc = ethip_nic_send(nic, data, size); 196 free(data); 197 198 return rc; 199 } 200 201 static int ethip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu) 202 { 203 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_send6()"); 204 205 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 206 eth_frame_t frame; 207 208 addr48(sdu->dest, frame.dest); 209 addr48(nic->mac_addr, frame.src); 210 frame.etype_len = ETYPE_IPV6; 211 frame.data = sdu->data; 212 frame.size = sdu->size; 213 214 void *data; 215 size_t size; 216 int rc = eth_pdu_encode(&frame, &data, &size); 211 217 if (rc != EOK) 212 218 return rc; … … 268 274 } 269 275 276 static int ethip_get_mac48(iplink_srv_t *srv, addr48_t *mac) 277 { 278 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_get_mac48()"); 279 280 ethip_nic_t *nic = (ethip_nic_t *) srv->arg; 281 addr48(nic->mac_addr, *mac); 282 283 return EOK; 284 } 285 270 286 static int ethip_addr_add(iplink_srv_t *srv, inet_addr_t *addr) 271 287 { -
uspace/srv/net/ethip/ethip.h
rb08879c2 rbdae198 46 46 47 47 typedef struct { 48 link_t addr_list;48 link_t link; 49 49 inet_addr_t addr; 50 50 } ethip_link_addr_t; 51 51 52 52 typedef struct ethip_nic { 53 link_t nic_list;53 link_t link; 54 54 service_id_t svc_id; 55 55 char *svc_name; … … 61 61 /** MAC address */ 62 62 addr48_t mac_addr; 63 /** List of IP addresses configured on this link */ 64 list_t addr_list; /* of ethip_link_addr_t */ 63 64 /** 65 * List of IP addresses configured on this link 66 * (of the type ethip_link_addr_t) 67 */ 68 list_t addr_list; 65 69 } ethip_nic_t; 66 70 -
uspace/srv/net/ethip/ethip_nic.c
rb08879c2 rbdae198 45 45 #include <device/nic.h> 46 46 #include <stdlib.h> 47 47 #include <net/socket_codes.h> 48 #include <mem.h> 48 49 #include "ethip.h" 49 50 #include "ethip_nic.h" … … 83 84 already_known = false; 84 85 85 list_foreach(ethip_nic_list, nic_link) {86 ethip_nic_t *nic = list_get_instance( nic_link,87 ethip_nic_t, nic_list);86 list_foreach(ethip_nic_list, link) { 87 ethip_nic_t *nic = list_get_instance(link, 88 ethip_nic_t, link); 88 89 if (nic->svc_id == svcs[i]) { 89 90 already_known = true; … … 108 109 { 109 110 ethip_nic_t *nic = calloc(1, sizeof(ethip_nic_t)); 110 111 111 if (nic == NULL) { 112 112 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed allocating NIC structure. " … … 114 114 return NULL; 115 115 } 116 117 link_initialize(&nic-> nic_list);116 117 link_initialize(&nic->link); 118 118 list_initialize(&nic->addr_list); 119 119 120 120 return nic; 121 121 } … … 130 130 } 131 131 132 link_initialize(&laddr-> addr_list);132 link_initialize(&laddr->link); 133 133 laddr->addr = *addr; 134 134 … … 140 140 if (nic->svc_name != NULL) 141 141 free(nic->svc_name); 142 142 143 free(nic); 143 144 } … … 180 181 181 182 log_msg(LOG_DEFAULT, LVL_DEBUG, "Opened NIC '%s'", nic->svc_name); 182 list_append(&nic-> nic_list, ðip_nic_list);183 list_append(&nic->link, ðip_nic_list); 183 184 in_list = true; 184 185 … … 209 210 error: 210 211 if (in_list) 211 list_remove(&nic->nic_list); 212 list_remove(&nic->link); 213 212 214 if (nic->sess != NULL) 213 215 async_hangup(nic->sess); 216 214 217 ethip_nic_delete(nic); 215 218 return rc; … … 312 315 list_foreach(ethip_nic_list, link) { 313 316 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_find_by_iplink_sid - element"); 314 ethip_nic_t *nic = list_get_instance(link, ethip_nic_t, 315 nic_list); 317 ethip_nic_t *nic = list_get_instance(link, ethip_nic_t, link); 316 318 317 319 if (nic->iplink_sid == iplink_sid) { … … 334 336 } 335 337 338 /** Setup accepted multicast addresses 339 * 340 * Currently the set of accepted multicast addresses is 341 * determined only based on IPv6 addresses. 342 * 343 */ 344 static int ethip_nic_setup_multicast(ethip_nic_t *nic) 345 { 346 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_setup_multicast()"); 347 348 /* Count the number of multicast addresses */ 349 350 size_t count = 0; 351 352 list_foreach(nic->addr_list, link) { 353 ethip_link_addr_t *laddr = list_get_instance(link, 354 ethip_link_addr_t, link); 355 356 uint16_t af = inet_addr_get(&laddr->addr, NULL, NULL); 357 if (af == AF_INET6) 358 count++; 359 } 360 361 if (count == 0) 362 return nic_multicast_set_mode(nic->sess, NIC_MULTICAST_BLOCKED, 363 NULL, 0); 364 365 nic_address_t *mac_list = calloc(count, sizeof(nic_address_t)); 366 if (mac_list == NULL) 367 return ENOMEM; 368 369 /* Create the multicast MAC list */ 370 371 size_t i = 0; 372 373 list_foreach(nic->addr_list, link) { 374 assert(i < count); 375 376 ethip_link_addr_t *laddr = list_get_instance(link, 377 ethip_link_addr_t, link); 378 379 addr128_t v6; 380 uint16_t af = inet_addr_get(&laddr->addr, NULL, &v6); 381 if (af != AF_INET6) 382 continue; 383 384 addr48_t mac; 385 addr48_solicited_node(v6, mac); 386 387 /* Avoid duplicate addresses in the list */ 388 389 bool found = false; 390 391 for (size_t j = 0; j < i; j++) { 392 if (addr48_compare(mac_list[j].address, mac)) { 393 found = true; 394 break; 395 } 396 } 397 398 if (!found) { 399 addr48(mac, mac_list[i].address); 400 i++; 401 } else 402 count--; 403 } 404 405 /* Setup the multicast MAC list */ 406 407 int rc = nic_multicast_set_mode(nic->sess, NIC_MULTICAST_LIST, 408 mac_list, count); 409 410 free(mac_list); 411 return rc; 412 } 413 336 414 int ethip_nic_addr_add(ethip_nic_t *nic, inet_addr_t *addr) 337 415 { … … 342 420 return ENOMEM; 343 421 344 list_append(&laddr->addr_list, &nic->addr_list); 345 return EOK; 422 list_append(&laddr->link, &nic->addr_list); 423 424 return ethip_nic_setup_multicast(nic); 346 425 } 347 426 … … 354 433 return ENOENT; 355 434 356 list_remove(&laddr-> addr_list);435 list_remove(&laddr->link); 357 436 ethip_link_addr_delete(laddr); 358 return EOK; 437 438 return ethip_nic_setup_multicast(nic); 359 439 } 360 440 … … 366 446 list_foreach(nic->addr_list, link) { 367 447 ethip_link_addr_t *laddr = list_get_instance(link, 368 ethip_link_addr_t, addr_list);448 ethip_link_addr_t, link); 369 449 370 450 if (inet_addr_compare(addr, &laddr->addr)) -
uspace/srv/net/ethip/pdu.c
rb08879c2 rbdae198 46 46 #include "pdu.h" 47 47 48 #define MAC48_BYTES 649 50 48 /** Encode Ethernet PDU. */ 51 49 int eth_pdu_encode(eth_frame_t *frame, void **rdata, size_t *rsize) -
uspace/srv/net/inetsrv/Makefile
rb08879c2 rbdae198 39 39 inetping.c \ 40 40 inetping6.c \ 41 ndp.c \ 42 ntrans.c \ 41 43 pdu.c \ 42 44 reass.c \ -
uspace/srv/net/inetsrv/addrobj.c
rb08879c2 rbdae198 42 42 #include <stdlib.h> 43 43 #include <str.h> 44 #include <net/socket_codes.h> 44 45 #include "addrobj.h" 45 46 #include "inetsrv.h" 46 47 #include "inet_link.h" 48 #include "ndp.h" 47 49 48 50 static inet_addrobj_t *inet_addrobj_find_by_name_locked(const char *, inet_link_t *); … … 117 119 inet_addrobj_t, addr_list); 118 120 119 if (inet_naddr_compare_mask(&naddr->naddr, addr)) { 120 fibril_mutex_unlock(&addr_list_lock); 121 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: found %p", 122 naddr); 123 return naddr; 121 switch (find) { 122 case iaf_net: 123 if (inet_naddr_compare_mask(&naddr->naddr, addr)) { 124 fibril_mutex_unlock(&addr_list_lock); 125 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: found %p", 126 naddr); 127 return naddr; 128 } 129 break; 130 case iaf_addr: 131 if (inet_naddr_compare(&naddr->naddr, addr)) { 132 fibril_mutex_unlock(&addr_list_lock); 133 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_addrobj_find: found %p", 134 naddr); 135 return naddr; 136 } 137 break; 124 138 } 125 139 } … … 214 228 inet_naddr_addr(&addr->naddr, &lsrc_addr); 215 229 216 return inet_link_send_dgram(addr->ilink, &lsrc_addr, ldest, dgram, 217 proto, ttl, df); 230 addr32_t lsrc_v4; 231 addr128_t lsrc_v6; 232 uint16_t lsrc_af = inet_addr_get(&lsrc_addr, &lsrc_v4, &lsrc_v6); 233 234 addr32_t ldest_v4; 235 addr128_t ldest_v6; 236 uint16_t ldest_af = inet_addr_get(ldest, &ldest_v4, &ldest_v6); 237 238 if (lsrc_af != ldest_af) 239 return EINVAL; 240 241 int rc; 242 addr48_t ldest_mac; 243 244 switch (ldest_af) { 245 case AF_INET: 246 return inet_link_send_dgram(addr->ilink, lsrc_v4, ldest_v4, 247 dgram, proto, ttl, df); 248 case AF_INET6: 249 /* 250 * Translate local destination IPv6 address. 251 */ 252 rc = ndp_translate(lsrc_v6, ldest_v6, ldest_mac, addr->ilink); 253 if (rc != EOK) 254 return rc; 255 256 return inet_link_send_dgram6(addr->ilink, ldest_mac, dgram, 257 proto, ttl, df); 258 } 259 260 return ENOTSUP; 218 261 } 219 262 -
uspace/srv/net/inetsrv/icmp.c
rb08879c2 rbdae198 153 153 return ENOMEM; 154 154 155 icmp_echo_t *request = (icmp_echo_t *) rdata;155 icmp_echo_t *request = (icmp_echo_t *) rdata; 156 156 157 157 request->type = ICMP_ECHO_REQUEST; -
uspace/srv/net/inetsrv/icmpv6.c
rb08879c2 rbdae198 47 47 #include "pdu.h" 48 48 49 static int ndp_received(inet_dgram_t *dgram)50 {51 // FIXME TODO52 return ENOTSUP;53 }54 55 49 static int icmpv6_recv_echo_request(inet_dgram_t *dgram) 56 50 { … … 84 78 inet_dgram_t rdgram; 85 79 86 rdgram.src = dgram->dest;80 inet_get_srcaddr(&dgram->src, 0, &rdgram.src); 87 81 rdgram.dest = dgram->src; 88 82 rdgram.tos = 0; … … 90 84 rdgram.size = size; 91 85 92 icmpv6_p seudo_headerphdr;86 icmpv6_phdr_t phdr; 93 87 94 88 host2addr128_t_be(dest_v6, phdr.src_addr); … … 100 94 uint16_t cs_phdr = 101 95 inet_checksum_calc(INET_CHECKSUM_INIT, &phdr, 102 sizeof(icmpv6_p seudo_header));96 sizeof(icmpv6_phdr_t)); 103 97 104 98 uint16_t cs_all = inet_checksum_calc(cs_phdr, reply, size); … … 156 150 case ICMPV6_NEIGHBOUR_SOLICITATION: 157 151 case ICMPV6_NEIGHBOUR_ADVERTISEMENT: 158 #ifdef ACCEPT_RA159 152 case ICMPV6_ROUTER_ADVERTISEMENT: 160 #endif161 153 return ndp_received(dgram); 162 154 default: … … 192 184 dgram.size = rsize; 193 185 194 icmpv6_p seudo_headerphdr;186 icmpv6_phdr_t phdr; 195 187 196 188 host2addr128_t_be(sdu->src, phdr.src_addr); … … 202 194 uint16_t cs_phdr = 203 195 inet_checksum_calc(INET_CHECKSUM_INIT, &phdr, 204 sizeof(icmpv6_p seudo_header));196 sizeof(icmpv6_phdr_t)); 205 197 206 198 uint16_t cs_all = inet_checksum_calc(cs_phdr, rdata, rsize); -
uspace/srv/net/inetsrv/icmpv6_std.h
rb08879c2 rbdae198 47 47 #define INET6_HOP_LIMIT_MAX 255 48 48 49 #define NDP_FLAG_ROUTER 0x80 50 #define NDP_FLAG_OVERRIDE 0x40 51 #define NDP_FLAG_SOLICITED 0x20 52 49 53 /** ICMPv6 message type */ 50 54 enum icmpv6_type { … … 83 87 uint8_t flags; 84 88 /** Reserved bytes */ 85 uint8_t reserved [3];89 uint8_t reserved[3]; 86 90 } ndp; 87 91 } un; … … 91 95 typedef struct { 92 96 /** Source IPv6 address */ 93 uint8_t src_addr [16];97 uint8_t src_addr[16]; 94 98 /** Target IPv6 address */ 95 uint8_t dest_addr [16];99 uint8_t dest_addr[16]; 96 100 /** ICMPv6 length */ 97 101 uint32_t length; 98 102 /** Zeroes */ 99 uint8_t zeroes [3];103 uint8_t zeroes[3]; 100 104 /** Next header */ 101 105 uint8_t next; 102 } icmpv6_p seudo_header;106 } icmpv6_phdr_t; 103 107 104 108 /** NDP neighbour body */ 105 109 typedef struct { 106 110 /** Target IPv6 address */ 107 uint8_t target_address [16];111 uint8_t target_address[16]; 108 112 /** Option code */ 109 113 uint8_t option; … … 111 115 uint8_t length; 112 116 /** MAC address */ 113 uint8_t mac [6];117 uint8_t mac[6]; 114 118 } ndp_message_t; 115 119 … … 131 135 uint32_t reserved; 132 136 /** Prefix */ 133 uint8_t prefix [16];137 uint8_t prefix[16]; 134 138 } ndp_prefix_t; 135 139 -
uspace/srv/net/inetsrv/inet_link.c
rb08879c2 rbdae198 49 49 #include "pdu.h" 50 50 51 static bool first_link = true; 52 static bool first_link6 = true; 53 54 static FIBRIL_MUTEX_INITIALIZE(ip_ident_lock); 55 static uint16_t ip_ident = 0; 56 51 57 static int inet_link_open(service_id_t); 52 58 static int inet_iplink_recv(iplink_t *, iplink_recv_sdu_t *, uint16_t); … … 58 64 static LIST_INITIALIZE(inet_link_list); 59 65 static FIBRIL_MUTEX_INITIALIZE(inet_discovery_lock); 66 67 static addr128_t link_local_node_ip = 68 {0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xfe, 0, 0, 0}; 69 70 static void inet_link_local_node_ip(addr48_t mac_addr, 71 addr128_t ip_addr) 72 { 73 memcpy(ip_addr, link_local_node_ip, 16); 74 75 ip_addr[8] = mac_addr[0] ^ 0x02; 76 ip_addr[9] = mac_addr[1]; 77 ip_addr[10] = mac_addr[2]; 78 ip_addr[13] = mac_addr[3]; 79 ip_addr[14] = mac_addr[4]; 80 ip_addr[15] = mac_addr[5]; 81 } 60 82 61 83 static int inet_iplink_recv(iplink_t *iplink, iplink_recv_sdu_t *sdu, uint16_t af) … … 159 181 if (ilink->svc_name != NULL) 160 182 free(ilink->svc_name); 183 161 184 free(ilink); 162 185 } … … 201 224 goto error; 202 225 } 226 227 /* 228 * Get the MAC address of the link. If the link has a MAC 229 * address, we assume that it supports NDP. 230 */ 231 rc = iplink_get_mac48(ilink->iplink, &ilink->mac); 232 ilink->mac_valid = (rc == EOK); 203 233 204 234 log_msg(LOG_DEFAULT, LVL_DEBUG, "Opened IP link '%s'", ilink->svc_name); 205 235 list_append(&ilink->link_list, &inet_link_list); 206 236 207 inet_addrobj_t *addr; 208 inet_addrobj_t *addr6; 209 210 static int first = 1; 211 212 addr = inet_addrobj_new(); 213 addr6 = inet_addrobj_new(); 214 215 if (first) { 237 inet_addrobj_t *addr = NULL; 238 239 if (first_link) { 240 addr = inet_addrobj_new(); 241 216 242 inet_naddr(&addr->naddr, 127, 0, 0, 1, 24); 217 inet_naddr6(&addr6->naddr, 0, 0, 0, 0, 0, 0, 0, 1, 128); 218 first = 0; 243 first_link = false; 219 244 } else { 220 245 /* 221 246 * FIXME 222 * Setting static IP addresses for testing purposes247 * Setting static IPv4 address for testing purposes: 223 248 * 10.0.2.15/24 224 * fd19:1680::4/120225 249 */ 250 addr = inet_addrobj_new(); 251 226 252 inet_naddr(&addr->naddr, 10, 0, 2, 15, 24); 227 inet_naddr6(&addr6->naddr, 0xfd19, 0x1680, 0, 0, 0, 0, 0, 4, 120); 228 } 229 230 addr->ilink = ilink; 231 addr6->ilink = ilink; 232 addr->name = str_dup("v4a"); 233 addr6->name = str_dup("v6a"); 234 235 rc = inet_addrobj_add(addr); 236 if (rc != EOK) { 237 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv4 address."); 238 inet_addrobj_delete(addr); 239 /* XXX Roll back */ 240 return rc; 241 } 242 243 rc = inet_addrobj_add(addr6); 244 if (rc != EOK) { 245 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv6 address."); 246 inet_addrobj_delete(addr6); 247 /* XXX Roll back */ 248 return rc; 249 } 250 251 inet_naddr_addr(&addr->naddr, &iaddr); 252 rc = iplink_addr_add(ilink->iplink, &iaddr); 253 if (rc != EOK) { 254 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed setting IPv4 address on internet link."); 255 inet_addrobj_remove(addr); 256 inet_addrobj_delete(addr); 257 /* XXX Roll back */ 258 return rc; 259 } 260 261 inet_naddr_addr(&addr6->naddr, &iaddr); 262 rc = iplink_addr_add(ilink->iplink, &iaddr); 263 if (rc != EOK) { 264 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed setting IPv6 address on internet link."); 265 inet_addrobj_remove(addr6); 266 inet_addrobj_delete(addr6); 267 /* XXX Roll back */ 268 return rc; 253 } 254 255 if (addr != NULL) { 256 addr->ilink = ilink; 257 addr->name = str_dup("v4a"); 258 259 rc = inet_addrobj_add(addr); 260 if (rc == EOK) { 261 inet_naddr_addr(&addr->naddr, &iaddr); 262 rc = iplink_addr_add(ilink->iplink, &iaddr); 263 if (rc != EOK) { 264 log_msg(LOG_DEFAULT, LVL_ERROR, 265 "Failed setting IPv4 address on internet link."); 266 inet_addrobj_remove(addr); 267 inet_addrobj_delete(addr); 268 } 269 } else { 270 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv4 address."); 271 inet_addrobj_delete(addr); 272 } 273 } 274 275 inet_addrobj_t *addr6 = NULL; 276 277 if (first_link6) { 278 addr6 = inet_addrobj_new(); 279 280 inet_naddr6(&addr6->naddr, 0, 0, 0, 0, 0, 0, 0, 1, 128); 281 first_link6 = false; 282 } else if (ilink->mac_valid) { 283 addr6 = inet_addrobj_new(); 284 285 addr128_t link_local; 286 inet_link_local_node_ip(ilink->mac, link_local); 287 288 inet_naddr_set6(link_local, 64, &addr6->naddr); 289 } 290 291 if (addr6 != NULL) { 292 addr6->ilink = ilink; 293 addr6->name = str_dup("v6a"); 294 295 rc = inet_addrobj_add(addr6); 296 if (rc == EOK) { 297 inet_naddr_addr(&addr6->naddr, &iaddr); 298 rc = iplink_addr_add(ilink->iplink, &iaddr); 299 if (rc != EOK) { 300 log_msg(LOG_DEFAULT, LVL_ERROR, 301 "Failed setting IPv6 address on internet link."); 302 inet_addrobj_remove(addr6); 303 inet_addrobj_delete(addr6); 304 } 305 } else { 306 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding IPv6 address."); 307 inet_addrobj_delete(addr6); 308 } 269 309 } 270 310 … … 298 338 } 299 339 300 /** Send datagram over Internet link */ 301 int inet_link_send_dgram(inet_link_t *ilink, inet_addr_t *lsrc, 302 inet_addr_t *ldest, inet_dgram_t *dgram, uint8_t proto, uint8_t ttl, int df) 303 { 340 /** Send IPv4 datagram over Internet link 341 * 342 * @param ilink Internet link 343 * @param lsrc Source IPv4 address 344 * @param ldest Destination IPv4 address 345 * @param dgram IPv4 datagram body 346 * @param proto Protocol 347 * @param ttl Time-to-live 348 * @param df Do-not-Fragment flag 349 * 350 * @return EOK on success 351 * @return ENOMEM when not enough memory to create the datagram 352 * @return ENOTSUP if networking mode is not supported 353 * 354 */ 355 int inet_link_send_dgram(inet_link_t *ilink, addr32_t lsrc, addr32_t ldest, 356 inet_dgram_t *dgram, uint8_t proto, uint8_t ttl, int df) 357 { 358 addr32_t src_v4; 359 uint16_t src_af = inet_addr_get(&dgram->src, &src_v4, NULL); 360 if (src_af != AF_INET) 361 return EINVAL; 362 363 addr32_t dest_v4; 364 uint16_t dest_af = inet_addr_get(&dgram->dest, &dest_v4, NULL); 365 if (dest_af != AF_INET) 366 return EINVAL; 367 304 368 /* 305 369 * Fill packet structure. Fragmentation is performed by 306 370 * inet_pdu_encode(). 307 371 */ 372 373 iplink_sdu_t sdu; 374 375 sdu.src = lsrc; 376 sdu.dest = ldest; 308 377 309 378 inet_packet_t packet; … … 314 383 packet.proto = proto; 315 384 packet.ttl = ttl; 385 386 /* Allocate identifier */ 387 fibril_mutex_lock(&ip_ident_lock); 388 packet.ident = ++ip_ident; 389 fibril_mutex_unlock(&ip_ident_lock); 390 316 391 packet.df = df; 317 392 packet.data = dgram->data; 318 393 packet.size = dgram->size; 319 394 320 i plink_sdu_t sdu;395 int rc; 321 396 size_t offs = 0; 322 int rc;323 324 sdu.src = *lsrc;325 sdu.dest = *ldest;326 397 327 398 do { 328 399 /* Encode one fragment */ 400 329 401 size_t roffs; 330 rc = inet_pdu_encode(&packet, offs, ilink->def_mtu, &sdu.data,331 &sdu. size, &roffs);402 rc = inet_pdu_encode(&packet, src_v4, dest_v4, offs, ilink->def_mtu, 403 &sdu.data, &sdu.size, &roffs); 332 404 if (rc != EOK) 333 405 return rc; … … 335 407 /* Send the PDU */ 336 408 rc = iplink_send(ilink->iplink, &sdu); 409 337 410 free(sdu.data); 338 411 offs = roffs; 412 } while (offs < packet.size); 413 414 return rc; 415 } 416 417 /** Send IPv6 datagram over Internet link 418 * 419 * @param ilink Internet link 420 * @param ldest Destination MAC address 421 * @param dgram IPv6 datagram body 422 * @param proto Next header 423 * @param ttl Hop limit 424 * @param df Do-not-Fragment flag (unused) 425 * 426 * @return EOK on success 427 * @return ENOMEM when not enough memory to create the datagram 428 * 429 */ 430 int inet_link_send_dgram6(inet_link_t *ilink, addr48_t ldest, 431 inet_dgram_t *dgram, uint8_t proto, uint8_t ttl, int df) 432 { 433 addr128_t src_v6; 434 uint16_t src_af = inet_addr_get(&dgram->src, NULL, &src_v6); 435 if (src_af != AF_INET6) 436 return EINVAL; 437 438 addr128_t dest_v6; 439 uint16_t dest_af = inet_addr_get(&dgram->dest, NULL, &dest_v6); 440 if (dest_af != AF_INET6) 441 return EINVAL; 442 443 iplink_sdu6_t sdu6; 444 addr48(ldest, sdu6.dest); 445 446 /* 447 * Fill packet structure. Fragmentation is performed by 448 * inet_pdu_encode6(). 449 */ 450 451 inet_packet_t packet; 452 453 packet.src = dgram->src; 454 packet.dest = dgram->dest; 455 packet.tos = dgram->tos; 456 packet.proto = proto; 457 packet.ttl = ttl; 458 459 /* Allocate identifier */ 460 fibril_mutex_lock(&ip_ident_lock); 461 packet.ident = ++ip_ident; 462 fibril_mutex_unlock(&ip_ident_lock); 463 464 packet.df = df; 465 packet.data = dgram->data; 466 packet.size = dgram->size; 467 468 int rc; 469 size_t offs = 0; 470 471 do { 472 /* Encode one fragment */ 473 474 size_t roffs; 475 rc = inet_pdu_encode6(&packet, src_v6, dest_v6, offs, ilink->def_mtu, 476 &sdu6.data, &sdu6.size, &roffs); 477 if (rc != EOK) 478 return rc; 479 480 /* Send the PDU */ 481 rc = iplink_send6(ilink->iplink, &sdu6); 482 483 free(sdu6.data); 339 484 offs = roffs; 340 485 } while (offs < packet.size); -
uspace/srv/net/inetsrv/inet_link.h
rb08879c2 rbdae198 42 42 43 43 extern int inet_link_discovery_start(void); 44 extern int inet_link_send_dgram(inet_link_t *, inet_addr_t *, 45 inet_addr_t *, inet_dgram_t *, uint8_t, uint8_t, int); 44 extern int inet_link_send_dgram(inet_link_t *, addr32_t, 45 addr32_t, inet_dgram_t *, uint8_t, uint8_t, int); 46 extern int inet_link_send_dgram6(inet_link_t *, addr48_t, inet_dgram_t *, 47 uint8_t, uint8_t, int); 46 48 extern inet_link_t *inet_link_get_by_id(sysarg_t); 47 49 -
uspace/srv/net/inetsrv/inet_std.h
rb08879c2 rbdae198 40 40 #include <sys/types.h> 41 41 42 #define IP6_NEXT_FRAGMENT 44 43 42 44 /** IPv4 Datagram header (fixed part) */ 43 45 typedef struct { … … 48 50 /** Total Length */ 49 51 uint16_t tot_len; 50 /** Identifi cation*/52 /** Identifier */ 51 53 uint16_t id; 52 54 /** Flags, Fragment Offset */ … … 90 92 }; 91 93 94 /** Bits in ip6_header_fragment_t.offsmf */ 95 enum flags_offsmt_bits { 96 /** More fragments */ 97 OF_FLAG_M = 0, 98 /** Fragment offset, highest bit */ 99 OF_FRAGOFF_h = 15, 100 /** Fragment offset, lowest bit */ 101 OF_FRAGOFF_l = 3 102 }; 103 92 104 /** IPv6 Datagram header (fixed part) */ 93 105 typedef struct { … … 114 126 /** Reserved */ 115 127 uint8_t reserved; 116 /** Fragment Offset, Flags*/117 uint16_t foff_flags;118 /** Identifi cation*/128 /** Fragmentation offset, reserved and M flag */ 129 uint16_t offsmf; 130 /** Identifier */ 119 131 uint32_t id; 120 132 } ip6_header_fragment_t; -
uspace/srv/net/inetsrv/inetping6.c
rb08879c2 rbdae198 109 109 aid_t req = async_send_1(exch, INETPING6_EV_RECV, sdu->seq_no, &answer); 110 110 111 int rc = async_data_write_start(exch, sdu->src, 16);111 int rc = async_data_write_start(exch, sdu->src, sizeof(addr128_t)); 112 112 if (rc != EOK) { 113 113 async_exchange_end(exch); … … 116 116 } 117 117 118 rc = async_data_write_start(exch, sdu->dest, 16);118 rc = async_data_write_start(exch, sdu->dest, sizeof(addr128_t)); 119 119 if (rc != EOK) { 120 120 async_exchange_end(exch); -
uspace/srv/net/inetsrv/inetsrv.c
rb08879c2 rbdae198 62 62 #define NAME "inetsrv" 63 63 64 static inet_naddr_t solicited_node_mask = { 65 .family = AF_INET6, 66 .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0xff, 0, 0, 0}, 67 .prefix = 104 68 }; 69 70 static inet_addr_t multicast_all_nodes = { 71 .family = AF_INET6, 72 .addr6 = {0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01} 73 }; 74 64 75 static void inet_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg); 65 76 … … 514 525 515 526 addr = inet_addrobj_find(&packet->dest, iaf_addr); 516 if (addr != NULL) { 527 if ((addr != NULL) || 528 (inet_naddr_compare_mask(&solicited_node_mask, &packet->dest)) || 529 (inet_addr_compare(&multicast_all_nodes, &packet->dest))) { 517 530 /* Destined for one of the local addresses */ 518 531 -
uspace/srv/net/inetsrv/inetsrv.h
rb08879c2 rbdae198 113 113 uint8_t ttl; 114 114 /** Identifier */ 115 uint 16_t ident;115 uint32_t ident; 116 116 /** Do not fragment */ 117 117 bool df; … … 141 141 iplink_t *iplink; 142 142 size_t def_mtu; 143 addr48_t mac; 144 bool mac_valid; 143 145 } inet_link_t; 144 146 -
uspace/srv/net/inetsrv/pdu.c
rb08879c2 rbdae198 49 49 #include "pdu.h" 50 50 51 static FIBRIL_MUTEX_INITIALIZE(ip_ident_lock);52 static uint16_t ip_ident = 0;53 54 51 /** One's complement addition. 55 52 * … … 88 85 } 89 86 90 /** Encode I nternetPDU.87 /** Encode IPv4 PDU. 91 88 * 92 89 * Encode internet packet into PDU (serialized form). Will encode a … … 96 93 * be set in the header, otherwise the offset will equal @a packet->size. 97 94 * 98 * @param packet Packet to encode 99 * @param offs Offset into packet payload (in bytes) 100 * @param mtu MTU (Maximum Transmission Unit) in bytes 101 * @param rdata Place to store pointer to allocated data buffer 102 * @param rsize Place to store size of allocated data buffer 103 * @param roffs Place to store offset of remaning data 104 */ 105 int inet_pdu_encode(inet_packet_t *packet, size_t offs, size_t mtu, 106 void **rdata, size_t *rsize, size_t *roffs) 107 { 108 addr32_t src_v4; 109 addr128_t src_v6; 110 uint16_t src_af = inet_addr_get(&packet->src, &src_v4, &src_v6); 111 112 addr32_t dest_v4; 113 addr128_t dest_v6; 114 uint16_t dest_af = inet_addr_get(&packet->dest, &dest_v4, &dest_v6); 115 116 if (src_af != dest_af) 117 return EINVAL; 118 95 * @param packet Packet to encode 96 * @param src Source address 97 * @param dest Destination address 98 * @param offs Offset into packet payload (in bytes) 99 * @param mtu MTU (Maximum Transmission Unit) in bytes 100 * @param rdata Place to store pointer to allocated data buffer 101 * @param rsize Place to store size of allocated data buffer 102 * @param roffs Place to store offset of remaning data 103 * 104 */ 105 int inet_pdu_encode(inet_packet_t *packet, addr32_t src, addr32_t dest, 106 size_t offs, size_t mtu, void **rdata, size_t *rsize, size_t *roffs) 107 { 119 108 /* Upper bound for fragment offset field */ 120 109 size_t fragoff_limit = 1 << (FF_FRAGOFF_h - FF_FRAGOFF_l); … … 124 113 return ELIMIT; 125 114 126 size_t hdr_size; 127 128 switch (src_af) { 129 case AF_INET: 130 hdr_size = sizeof(ip_header_t); 131 break; 132 case AF_INET6: 133 hdr_size = sizeof(ip6_header_t); 134 break; 135 default: 136 assert(false); 137 } 138 139 size_t data_offs = ROUND_UP(hdr_size, 4); 140 115 size_t hdr_size = sizeof(ip_header_t); 116 if (hdr_size >= mtu) 117 return EINVAL; 118 119 assert(hdr_size % 4 == 0); 141 120 assert(offs % FRAG_OFFS_UNIT == 0); 142 121 assert(offs / FRAG_OFFS_UNIT < fragoff_limit); … … 144 123 /* Value for the fragment offset field */ 145 124 uint16_t foff = offs / FRAG_OFFS_UNIT; 146 147 if (hdr_size >= mtu)148 return EINVAL;149 125 150 126 /* Amount of space in the PDU available for payload */ … … 171 147 return ENOMEM; 172 148 173 /* Allocate identifier */174 fibril_mutex_lock(&ip_ident_lock);175 uint16_t ident = ++ip_ident;176 fibril_mutex_unlock(&ip_ident_lock);177 178 149 /* Encode header fields */ 179 ip_header_t *hdr; 180 ip6_header_t *hdr6; 181 182 switch (src_af) { 183 case AF_INET: 184 hdr = (ip_header_t *) data; 185 186 hdr->ver_ihl = 187 (4 << VI_VERSION_l) | (hdr_size / sizeof(uint32_t)); 188 hdr->tos = packet->tos; 189 hdr->tot_len = host2uint16_t_be(size); 190 hdr->id = host2uint16_t_be(ident); 191 hdr->flags_foff = host2uint16_t_be(flags_foff); 192 hdr->ttl = packet->ttl; 193 hdr->proto = packet->proto; 194 hdr->chksum = 0; 195 hdr->src_addr = host2uint32_t_be(src_v4); 196 hdr->dest_addr = host2uint32_t_be(dest_v4); 197 198 /* Compute checksum */ 199 uint16_t chksum = inet_checksum_calc(INET_CHECKSUM_INIT, 200 (void *) hdr, hdr_size); 201 hdr->chksum = host2uint16_t_be(chksum); 202 203 break; 204 case AF_INET6: 205 // TODO FIXME: fragmentation 206 207 hdr6 = (ip6_header_t *) data; 208 209 hdr6->ver_tc = (6 << (VI_VERSION_l)); 210 memset(hdr6->tc_fl, 0, 3); 211 hdr6->payload_len = host2uint16_t_be(packet->size); 212 hdr6->next = packet->proto; 213 hdr6->hop_limit = packet->ttl; 214 215 host2addr128_t_be(src_v6, hdr6->src_addr); 216 host2addr128_t_be(dest_v6, hdr6->dest_addr); 217 218 break; 219 default: 220 assert(false); 221 } 150 ip_header_t *hdr = (ip_header_t *) data; 151 152 hdr->ver_ihl = 153 (4 << VI_VERSION_l) | (hdr_size / sizeof(uint32_t)); 154 hdr->tos = packet->tos; 155 hdr->tot_len = host2uint16_t_be(size); 156 hdr->id = host2uint16_t_be(packet->ident); 157 hdr->flags_foff = host2uint16_t_be(flags_foff); 158 hdr->ttl = packet->ttl; 159 hdr->proto = packet->proto; 160 hdr->chksum = 0; 161 hdr->src_addr = host2uint32_t_be(src); 162 hdr->dest_addr = host2uint32_t_be(dest); 163 164 /* Compute checksum */ 165 uint16_t chksum = inet_checksum_calc(INET_CHECKSUM_INIT, 166 (void *) hdr, hdr_size); 167 hdr->chksum = host2uint16_t_be(chksum); 222 168 223 169 /* Copy payload */ 224 memcpy((uint8_t *) data + data_offs, packet->data + offs, xfer_size);170 memcpy((uint8_t *) data + hdr_size, packet->data + offs, xfer_size); 225 171 226 172 *rdata = data; … … 231 177 } 232 178 179 /** Encode IPv6 PDU. 180 * 181 * Encode internet packet into PDU (serialized form). Will encode a 182 * fragment of the payload starting at offset @a offs. The resulting 183 * PDU will have at most @a mtu bytes. @a *roffs will be set to the offset 184 * of remaining payload. If some data is remaining, the MF flag will 185 * be set in the header, otherwise the offset will equal @a packet->size. 186 * 187 * @param packet Packet to encode 188 * @param src Source address 189 * @param dest Destination address 190 * @param offs Offset into packet payload (in bytes) 191 * @param mtu MTU (Maximum Transmission Unit) in bytes 192 * @param rdata Place to store pointer to allocated data buffer 193 * @param rsize Place to store size of allocated data buffer 194 * @param roffs Place to store offset of remaning data 195 * 196 */ 197 int inet_pdu_encode6(inet_packet_t *packet, addr128_t src, addr128_t dest, 198 size_t offs, size_t mtu, void **rdata, size_t *rsize, size_t *roffs) 199 { 200 /* IPv6 mandates a minimal MTU of 1280 bytes */ 201 if (mtu < 1280) 202 return ELIMIT; 203 204 /* Upper bound for fragment offset field */ 205 size_t fragoff_limit = 1 << (OF_FRAGOFF_h - OF_FRAGOFF_l); 206 207 /* Verify that total size of datagram is within reasonable bounds */ 208 if (offs + packet->size > FRAG_OFFS_UNIT * fragoff_limit) 209 return ELIMIT; 210 211 /* Determine whether we need the Fragment extension header */ 212 bool fragment; 213 if (offs == 0) 214 fragment = (packet->size + sizeof(ip6_header_t) > mtu); 215 else 216 fragment = true; 217 218 size_t hdr_size; 219 if (fragment) 220 hdr_size = sizeof(ip6_header_t) + sizeof(ip6_header_fragment_t); 221 else 222 hdr_size = sizeof(ip6_header_t); 223 224 if (hdr_size >= mtu) 225 return EINVAL; 226 227 assert(sizeof(ip6_header_t) % 8 == 0); 228 assert(hdr_size % 8 == 0); 229 assert(offs % FRAG_OFFS_UNIT == 0); 230 assert(offs / FRAG_OFFS_UNIT < fragoff_limit); 231 232 /* Value for the fragment offset field */ 233 uint16_t foff = offs / FRAG_OFFS_UNIT; 234 235 /* Amount of space in the PDU available for payload */ 236 size_t spc_avail = mtu - hdr_size; 237 spc_avail -= (spc_avail % FRAG_OFFS_UNIT); 238 239 /* Amount of data (payload) to transfer */ 240 size_t xfer_size = min(packet->size - offs, spc_avail); 241 242 /* Total PDU size */ 243 size_t size = hdr_size + xfer_size; 244 245 /* Offset of remaining payload */ 246 size_t rem_offs = offs + xfer_size; 247 248 /* Flags */ 249 uint16_t offsmf = 250 (rem_offs < packet->size ? BIT_V(uint16_t, OF_FLAG_M) : 0) + 251 (foff << OF_FRAGOFF_l); 252 253 void *data = calloc(size, 1); 254 if (data == NULL) 255 return ENOMEM; 256 257 /* Encode header fields */ 258 ip6_header_t *hdr6 = (ip6_header_t *) data; 259 260 hdr6->ver_tc = (6 << (VI_VERSION_l)); 261 memset(hdr6->tc_fl, 0, 3); 262 hdr6->hop_limit = packet->ttl; 263 264 host2addr128_t_be(src, hdr6->src_addr); 265 host2addr128_t_be(dest, hdr6->dest_addr); 266 267 /* Optionally encode Fragment extension header fields */ 268 if (fragment) { 269 assert(offsmf != 0); 270 271 hdr6->payload_len = host2uint16_t_be(packet->size + 272 sizeof(ip6_header_fragment_t)); 273 hdr6->next = IP6_NEXT_FRAGMENT; 274 275 ip6_header_fragment_t *hdr6f = (ip6_header_fragment_t *) 276 (hdr6 + 1); 277 278 hdr6f->next = packet->proto; 279 hdr6f->reserved = 0; 280 hdr6f->offsmf = host2uint16_t_be(offsmf); 281 hdr6f->id = host2uint32_t_be(packet->ident); 282 } else { 283 assert(offsmf == 0); 284 285 hdr6->payload_len = host2uint16_t_be(packet->size); 286 hdr6->next = packet->proto; 287 } 288 289 /* Copy payload */ 290 memcpy((uint8_t *) data + hdr_size, packet->data + offs, xfer_size); 291 292 *rdata = data; 293 *rsize = size; 294 *roffs = rem_offs; 295 296 return EOK; 297 } 298 299 /** Decode IPv4 datagram 300 * 301 * @param data Serialized IPv4 datagram 302 * @param size Length of serialized IPv4 datagram 303 * @param packet IP datagram structure to be filled 304 * 305 * @return EOK on success 306 * @return EINVAL if the datagram is invalid or damaged 307 * @return ENOMEM if not enough memory 308 * 309 */ 233 310 int inet_pdu_decode(void *data, size_t size, inet_packet_t *packet) 234 311 { … … 257 334 if (tot_len > size) { 258 335 log_msg(LOG_DEFAULT, LVL_DEBUG, "Total Length = %zu > PDU size = %zu", 259 tot_len, size);336 tot_len, size); 260 337 return EINVAL; 261 338 } … … 294 371 } 295 372 373 /** Decode IPv6 datagram 374 * 375 * @param data Serialized IPv6 datagram 376 * @param size Length of serialized IPv6 datagram 377 * @param packet IP datagram structure to be filled 378 * 379 * @return EOK on success 380 * @return EINVAL if the datagram is invalid or damaged 381 * @return ENOMEM if not enough memory 382 * 383 */ 296 384 int inet_pdu_decode6(void *data, size_t size, inet_packet_t *packet) 297 385 { 298 // FIXME TODO 299 return ENOTSUP; 386 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_pdu_decode6()"); 387 388 if (size < sizeof(ip6_header_t)) { 389 log_msg(LOG_DEFAULT, LVL_DEBUG, "PDU too short (%zu)", size); 390 return EINVAL; 391 } 392 393 ip6_header_t *hdr6 = (ip6_header_t *) data; 394 395 uint8_t version = BIT_RANGE_EXTRACT(uint8_t, VI_VERSION_h, 396 VI_VERSION_l, hdr6->ver_tc); 397 if (version != 6) { 398 log_msg(LOG_DEFAULT, LVL_DEBUG, "Version (%d) != 6", version); 399 return EINVAL; 400 } 401 402 size_t payload_len = uint16_t_be2host(hdr6->payload_len); 403 if (payload_len + sizeof(ip6_header_t) > size) { 404 log_msg(LOG_DEFAULT, LVL_DEBUG, "Payload Length = %zu > PDU size = %zu", 405 payload_len + sizeof(ip6_header_t), size); 406 return EINVAL; 407 } 408 409 uint32_t ident; 410 uint16_t offsmf; 411 uint16_t foff; 412 uint16_t next; 413 size_t data_offs = sizeof(ip6_header_t); 414 415 /* Fragment extension header */ 416 if (hdr6->next == IP6_NEXT_FRAGMENT) { 417 ip6_header_fragment_t *hdr6f = (ip6_header_fragment_t *) 418 (hdr6 + 1); 419 420 ident = uint32_t_be2host(hdr6f->id); 421 offsmf = uint16_t_be2host(hdr6f->offsmf); 422 foff = BIT_RANGE_EXTRACT(uint16_t, OF_FRAGOFF_h, OF_FRAGOFF_l, 423 offsmf); 424 next = hdr6f->next; 425 data_offs += sizeof(ip6_header_fragment_t); 426 payload_len -= sizeof(ip6_header_fragment_t); 427 } else { 428 ident = 0; 429 offsmf = 0; 430 foff = 0; 431 next = hdr6->next; 432 } 433 434 addr128_t src; 435 addr128_t dest; 436 437 addr128_t_be2host(hdr6->src_addr, src); 438 inet_addr_set6(src, &packet->src); 439 440 addr128_t_be2host(hdr6->dest_addr, dest); 441 inet_addr_set6(dest, &packet->dest); 442 443 packet->tos = 0; 444 packet->proto = next; 445 packet->ttl = hdr6->hop_limit; 446 packet->ident = ident; 447 448 packet->df = 1; 449 packet->mf = (offsmf & BIT_V(uint16_t, OF_FLAG_M)) != 0; 450 packet->offs = foff * FRAG_OFFS_UNIT; 451 452 packet->size = payload_len; 453 packet->data = calloc(packet->size, 1); 454 if (packet->data == NULL) { 455 log_msg(LOG_DEFAULT, LVL_WARN, "Out of memory."); 456 return ENOMEM; 457 } 458 459 memcpy(packet->data, (uint8_t *) data + data_offs, packet->size); 460 461 return EOK; 462 } 463 464 /** Encode NDP packet 465 * 466 * @param ndp NDP packet structure to be serialized 467 * @param dgram IPv6 datagram structure to be filled 468 * 469 * @return EOK on success 470 * 471 */ 472 int ndp_pdu_encode(ndp_packet_t *ndp, inet_dgram_t *dgram) 473 { 474 inet_addr_set6(ndp->sender_proto_addr, &dgram->src); 475 inet_addr_set6(ndp->target_proto_addr, &dgram->dest); 476 dgram->tos = 0; 477 dgram->size = sizeof(icmpv6_message_t) + sizeof(ndp_message_t); 478 479 dgram->data = calloc(1, dgram->size); 480 if (dgram->data == NULL) 481 return ENOMEM; 482 483 icmpv6_message_t *icmpv6 = (icmpv6_message_t *) dgram->data; 484 485 icmpv6->type = ndp->opcode; 486 icmpv6->code = 0; 487 memset(icmpv6->un.ndp.reserved, 0, 3); 488 489 ndp_message_t *message = (ndp_message_t *) (icmpv6 + 1); 490 491 if (ndp->opcode == ICMPV6_NEIGHBOUR_SOLICITATION) { 492 host2addr128_t_be(ndp->solicited_ip, message->target_address); 493 message->option = 1; 494 icmpv6->un.ndp.flags = 0; 495 } else { 496 host2addr128_t_be(ndp->sender_proto_addr, message->target_address); 497 message->option = 2; 498 icmpv6->un.ndp.flags = NDP_FLAG_OVERRIDE | NDP_FLAG_SOLICITED; 499 } 500 501 message->length = 1; 502 addr48(ndp->sender_hw_addr, message->mac); 503 504 icmpv6_phdr_t phdr; 505 506 host2addr128_t_be(ndp->sender_proto_addr, phdr.src_addr); 507 host2addr128_t_be(ndp->target_proto_addr, phdr.dest_addr); 508 phdr.length = host2uint32_t_be(dgram->size); 509 memset(phdr.zeroes, 0, 3); 510 phdr.next = IP_PROTO_ICMPV6; 511 512 uint16_t cs_phdr = 513 inet_checksum_calc(INET_CHECKSUM_INIT, &phdr, 514 sizeof(icmpv6_phdr_t)); 515 516 uint16_t cs_all = inet_checksum_calc(cs_phdr, dgram->data, 517 dgram->size); 518 519 icmpv6->checksum = host2uint16_t_be(cs_all); 520 521 return EOK; 522 } 523 524 /** Decode NDP packet 525 * 526 * @param dgram Incoming IPv6 datagram encapsulating NDP packet 527 * @param ndp NDP packet structure to be filled 528 * 529 * @return EOK on success 530 * @return EINVAL if the Datagram is invalid 531 * 532 */ 533 int ndp_pdu_decode(inet_dgram_t *dgram, ndp_packet_t *ndp) 534 { 535 uint16_t src_af = inet_addr_get(&dgram->src, NULL, 536 &ndp->sender_proto_addr); 537 if (src_af != AF_INET6) 538 return EINVAL; 539 540 if (dgram->size < sizeof(icmpv6_message_t) + sizeof(ndp_message_t)) 541 return EINVAL; 542 543 icmpv6_message_t *icmpv6 = (icmpv6_message_t *) dgram->data; 544 545 ndp->opcode = icmpv6->type; 546 547 ndp_message_t *message = (ndp_message_t *) (icmpv6 + 1); 548 549 addr128_t_be2host(message->target_address, ndp->target_proto_addr); 550 addr48(message->mac, ndp->sender_hw_addr); 551 552 return EOK; 300 553 } 301 554 -
uspace/srv/net/inetsrv/pdu.h
rb08879c2 rbdae198 40 40 #include <sys/types.h> 41 41 #include "inetsrv.h" 42 #include "ndp.h" 42 43 43 44 #define INET_CHECKSUM_INIT 0xffff … … 45 46 extern uint16_t inet_checksum_calc(uint16_t, void *, size_t); 46 47 47 extern int inet_pdu_encode(inet_packet_t *, size_t, size_t, void **, 48 size_t *, size_t *); 48 extern int inet_pdu_encode(inet_packet_t *, addr32_t, addr32_t, size_t, size_t, 49 void **, size_t *, size_t *); 50 extern int inet_pdu_encode6(inet_packet_t *, addr128_t, addr128_t, size_t, 51 size_t, void **, size_t *, size_t *); 49 52 extern int inet_pdu_decode(void *, size_t, inet_packet_t *); 50 53 extern int inet_pdu_decode6(void *, size_t, inet_packet_t *); 54 55 extern int ndp_pdu_decode(inet_dgram_t *, ndp_packet_t *); 56 extern int ndp_pdu_encode(ndp_packet_t *, inet_dgram_t *); 51 57 52 58 #endif -
uspace/srv/net/inetsrv/reass.c
rb08879c2 rbdae198 164 164 return NULL; 165 165 166 li nk_initialize(&rdg->map_link);166 list_append(&rdg->map_link, &reass_dgram_map); 167 167 list_initialize(&rdg->frags); 168 168 -
uspace/srv/net/loopip/loopip.c
rb08879c2 rbdae198 40 40 #include <inet/iplink_srv.h> 41 41 #include <inet/addr.h> 42 #include <net/socket_codes.h> 42 43 #include <io/log.h> 43 44 #include <loc.h> … … 50 51 static int loopip_close(iplink_srv_t *srv); 51 52 static int loopip_send(iplink_srv_t *srv, iplink_sdu_t *sdu); 53 static int loopip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu); 52 54 static int loopip_get_mtu(iplink_srv_t *srv, size_t *mtu); 55 static int loopip_get_mac48(iplink_srv_t *srv, addr48_t *mac); 53 56 static int loopip_addr_add(iplink_srv_t *srv, inet_addr_t *addr); 54 57 static int loopip_addr_remove(iplink_srv_t *srv, inet_addr_t *addr); … … 60 63 .close = loopip_close, 61 64 .send = loopip_send, 65 .send6 = loopip_send6, 62 66 .get_mtu = loopip_get_mtu, 67 .get_mac48 = loopip_get_mac48, 63 68 .addr_add = loopip_addr_add, 64 69 .addr_remove = loopip_addr_remove … … 162 167 log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_send()"); 163 168 164 addr32_t src_v4;165 addr128_t src_v6;166 uint16_t src_af = inet_addr_get(&sdu->src, &src_v4, &src_v6);167 168 addr32_t dest_v4;169 addr128_t dest_v6;170 uint16_t dest_af = inet_addr_get(&sdu->dest, &dest_v4, &dest_v6);171 172 if (src_af != dest_af)173 return EINVAL;174 175 169 rqueue_entry_t *rqe = calloc(1, sizeof(rqueue_entry_t)); 176 170 if (rqe == NULL) … … 180 174 * Clone SDU 181 175 */ 182 rqe->af = src_af;176 rqe->af = AF_INET; 183 177 rqe->sdu.data = malloc(sdu->size); 184 178 if (rqe->sdu.data == NULL) { … … 198 192 } 199 193 194 static int loopip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu) 195 { 196 log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip6_send()"); 197 198 rqueue_entry_t *rqe = calloc(1, sizeof(rqueue_entry_t)); 199 if (rqe == NULL) 200 return ENOMEM; 201 202 /* 203 * Clone SDU 204 */ 205 rqe->af = AF_INET6; 206 rqe->sdu.data = malloc(sdu->size); 207 if (rqe->sdu.data == NULL) { 208 free(rqe); 209 return ENOMEM; 210 } 211 212 memcpy(rqe->sdu.data, sdu->data, sdu->size); 213 rqe->sdu.size = sdu->size; 214 215 /* 216 * Insert to receive queue 217 */ 218 prodcons_produce(&loopip_rcv_queue, &rqe->link); 219 220 return EOK; 221 } 222 200 223 static int loopip_get_mtu(iplink_srv_t *srv, size_t *mtu) 201 224 { … … 203 226 *mtu = 1500; 204 227 return EOK; 228 } 229 230 static int loopip_get_mac48(iplink_srv_t *src, addr48_t *mac) 231 { 232 log_msg(LOG_DEFAULT, LVL_DEBUG, "loopip_get_mac48()"); 233 return ENOTSUP; 205 234 } 206 235 -
uspace/srv/net/slip/slip.c
rb08879c2 rbdae198 58 58 static int slip_close(iplink_srv_t *); 59 59 static int slip_send(iplink_srv_t *, iplink_sdu_t *); 60 static int slip_send6(iplink_srv_t *, iplink_sdu6_t *); 60 61 static int slip_get_mtu(iplink_srv_t *, size_t *); 62 static int slip_get_mac48(iplink_srv_t *, addr48_t *); 61 63 static int slip_addr_add(iplink_srv_t *, inet_addr_t *); 62 64 static int slip_addr_remove(iplink_srv_t *, inet_addr_t *); … … 68 70 .close = slip_close, 69 71 .send = slip_send, 72 .send6 = slip_send6, 70 73 .get_mtu = slip_get_mtu, 74 .get_mac48 = slip_get_mac48, 71 75 .addr_add = slip_addr_add, 72 76 .addr_remove = slip_addr_remove … … 122 126 int slip_send(iplink_srv_t *srv, iplink_sdu_t *sdu) 123 127 { 128 log_msg(LOG_DEFAULT, LVL_DEBUG, "slip_send()"); 129 124 130 async_sess_t *sess = (async_sess_t *) srv->arg; 125 131 uint8_t *data = sdu->data; 126 unsigned i; 127 128 log_msg(LOG_DEFAULT, LVL_DEBUG, "slip_send()"); 129 132 130 133 /* 131 * Strictly speaking, this is not prescribed by the RFC, but the RFC132 * suggests to start with sending a SLIP_END byte as a synchronization133 * measure for dealing with previous possible noise on the line.134 */134 * Strictly speaking, this is not prescribed by the RFC, but the RFC 135 * suggests to start with sending a SLIP_END byte as a synchronization 136 * measure for dealing with previous possible noise on the line. 137 */ 135 138 write_buffered(sess, SLIP_END); 136 137 for ( i = 0; i < sdu->size; i++) {139 140 for (size_t i = 0; i < sdu->size; i++) { 138 141 switch (data[i]) { 139 142 case SLIP_END: … … 150 153 } 151 154 } 155 152 156 write_buffered(sess, SLIP_END); 153 157 write_flush(sess); 154 155 return EOK; 158 159 return EOK; 160 } 161 162 int slip_send6(iplink_srv_t *srv, iplink_sdu6_t *sdu) 163 { 164 log_msg(LOG_DEFAULT, LVL_DEBUG, "slip_send6()"); 165 166 return ENOTSUP; 156 167 } 157 168 … … 161 172 *mtu = SLIP_MTU; 162 173 return EOK; 174 } 175 176 int slip_get_mac48(iplink_srv_t *src, addr48_t *mac) 177 { 178 log_msg(LOG_DEFAULT, LVL_DEBUG, "slip_get_mac48()"); 179 return ENOTSUP; 163 180 } 164 181 -
uspace/srv/net/tcp/conn.c
rb08879c2 rbdae198 312 312 static bool tcp_socket_match(tcp_sock_t *sock, tcp_sock_t *patt) 313 313 { 314 log_msg(LOG_DEFAULT, LVL_DEBUG2, 315 "tcp_socket_match(sock=(%u), pat=(%u))", sock->port, patt->port); 316 314 317 if ((!inet_addr_is_any(&patt->addr)) && 315 318 (!inet_addr_compare(&patt->addr, &sock->addr))) … … 351 354 { 352 355 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_conn_find_ref(%p)", sp); 356 357 log_msg(LOG_DEFAULT, LVL_DEBUG2, "compare conn (f:(%u), l:(%u))", 358 sp->foreign.port, sp->local.port); 353 359 354 360 fibril_mutex_lock(&conn_list_lock); … … 357 363 tcp_conn_t *conn = list_get_instance(link, tcp_conn_t, link); 358 364 tcp_sockpair_t *csp = &conn->ident; 365 366 log_msg(LOG_DEFAULT, LVL_DEBUG2, " - with (f:(%u), l:(%u))", 367 csp->foreign.port, csp->local.port); 359 368 360 369 if (tcp_sockpair_match(sp, csp)) { -
uspace/srv/net/tcp/pdu.c
rb08879c2 rbdae198 172 172 phdr6->tcp_length = 173 173 host2uint32_t_be(pdu->header_size + pdu->text_size); 174 memset(phdr6->zero , 0, 3);174 memset(phdr6->zeroes, 0, 3); 175 175 phdr6->next = IP_PROTO_TCP; 176 176 break; -
uspace/srv/net/tcp/sock.c
rb08879c2 rbdae198 613 613 ipc_callid_t wcallid; 614 614 size_t length; 615 uint8_t buffer[TCP_SOCK_FRAGMENT_SIZE];616 615 tcp_error_t trc; 617 616 int rc; 617 618 uint8_t *buffer = calloc(TCP_SOCK_FRAGMENT_SIZE, 1); 619 if (buffer == NULL) { 620 async_answer_0(callid, ENOMEM); 621 return; 622 } 618 623 619 624 log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_sock_send()"); … … 625 630 if (sock_core == NULL) { 626 631 async_answer_0(callid, ENOTSOCK); 627 return;632 goto out; 628 633 } 629 634 … … 641 646 fibril_mutex_unlock(&socket->lock); 642 647 async_answer_0(callid, EINVAL); 643 return;648 goto out; 644 649 } 645 650 … … 651 656 fibril_mutex_unlock(&socket->lock); 652 657 async_answer_0(callid, rc); 653 return;658 goto out; 654 659 } 655 660 … … 676 681 fibril_mutex_unlock(&socket->lock); 677 682 async_answer_0(callid, rc); 678 return;683 goto out; 679 684 } 680 685 } … … 685 690 IPC_GET_ARG2(answer)); 686 691 fibril_mutex_unlock(&socket->lock); 692 693 out: 694 free(buffer); 687 695 } 688 696 -
uspace/srv/net/tcp/std.h
rb08879c2 rbdae198 75 75 }; 76 76 77 /** TCP IPv4pseudo header */77 /** TCP over IPv4 checksum pseudo header */ 78 78 typedef struct { 79 79 /** Source address */ … … 89 89 } tcp_phdr_t; 90 90 91 /** TCP IPv6pseudo header */91 /** TCP over IPv6 checksum pseudo header */ 92 92 typedef struct { 93 93 /** Source address */ … … 98 98 uint32_t tcp_length; 99 99 /** Zeroes */ 100 uint8_t zero [3];100 uint8_t zeroes[3]; 101 101 /** Next header */ 102 102 uint8_t next; -
uspace/srv/net/tcp/tcp.c
rb08879c2 rbdae198 54 54 #define NAME "tcp" 55 55 56 #define IP_PROTO_TCP 657 58 56 static int tcp_inet_ev_recv(inet_dgram_t *dgram); 59 57 static void tcp_received_pdu(tcp_pdu_t *pdu); -
uspace/srv/net/tcp/tqueue.c
rb08879c2 rbdae198 282 282 void tcp_transmit_segment(tcp_sockpair_t *sp, tcp_segment_t *seg) 283 283 { 284 log_msg(LOG_DEFAULT, LVL_DEBUG, 285 "tcp_transmit_segment(f:(%u),l:(%u), %p)", 286 sp->local.port, sp->foreign.port, seg); 287 284 288 log_msg(LOG_DEFAULT, LVL_DEBUG, "SEG.SEQ=%" PRIu32 ", SEG.WND=%" PRIu32, 285 289 seg->seq, seg->wnd); -
uspace/srv/net/tcp/ucall.c
rb08879c2 rbdae198 298 298 tcp_conn_t *conn; 299 299 300 log_msg(LOG_DEFAULT, LVL_DEBUG, 301 "tcp_as_segment_arrived(f:(%u), l:(%u))", 302 sp->foreign.port, sp->local.port); 303 300 304 conn = tcp_conn_find_ref(sp); 301 305 if (conn == NULL) { -
uspace/srv/net/udp/assoc.c
rb08879c2 rbdae198 372 372 static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt) 373 373 { 374 log_msg(LOG_DEFAULT, LVL_DEBUG, 375 "udp_socket_match(sock=(%u), pat=(%u))", sock->port, patt->port); 376 374 377 if ((!inet_addr_is_any(&patt->addr)) && 375 378 (!inet_addr_compare(&patt->addr, &sock->addr))) -
uspace/srv/net/udp/pdu.c
rb08879c2 rbdae198 110 110 host2addr128_t_be(dest_v6, phdr6->dest_addr); 111 111 phdr6->udp_length = host2uint32_t_be(pdu->data_size); 112 memset(phdr6->zero , 0, 3);112 memset(phdr6->zeroes, 0, 3); 113 113 phdr6->next = IP_PROTO_UDP; 114 114 break; -
uspace/srv/net/udp/sock.c
rb08879c2 rbdae198 265 265 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_send()"); 266 266 267 uint8_t *buffer = calloc(UDP_FRAGMENT_SIZE, 1); 268 if (buffer == NULL) { 269 async_answer_0(callid, ENOMEM); 270 return; 271 } 272 267 273 struct sockaddr_in6 *addr6 = NULL; 268 274 struct sockaddr_in *addr; … … 276 282 if (rc != EOK) { 277 283 async_answer_0(callid, rc); 278 return;284 goto out; 279 285 } 280 286 … … 357 363 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_sock_sendto: Failed to " 358 364 "determine local address."); 359 return;365 goto out; 360 366 } 361 367 … … 379 385 length = UDP_FRAGMENT_SIZE; 380 386 381 uint8_t buffer[UDP_FRAGMENT_SIZE];382 387 int rc = async_data_write_finalize(wcallid, buffer, length); 383 388 if (rc != EOK) { … … 425 430 if (addr6 != NULL) 426 431 free(addr6); 432 433 free(buffer); 427 434 } 428 435 -
uspace/srv/net/udp/std.h
rb08879c2 rbdae198 54 54 } udp_header_t; 55 55 56 /** UDP IPv4pseudo header */56 /** UDP over IPv4 checksum pseudo header */ 57 57 typedef struct { 58 58 /** Source address */ … … 68 68 } udp_phdr_t; 69 69 70 /** UDP IPv6pseudo header */70 /** UDP over IPv6 checksum pseudo header */ 71 71 typedef struct { 72 72 /** Source address */ … … 76 76 /** UDP length */ 77 77 uint32_t udp_length; 78 /** Reserved*/79 uint8_t zero [3];78 /** Zeroes */ 79 uint8_t zeroes[3]; 80 80 /** Next header */ 81 81 uint8_t next;
Note:
See TracChangeset
for help on using the changeset viewer.
