Changeset 60ab6c3 in mainline for uspace/srv/net/il/ip/ip_client.c
- Timestamp:
- 2010-03-10T05:46:54Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5782081
- Parents:
- 71b00dcc (diff), b48ebd19 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/il/ip/ip_client.c
r71b00dcc r60ab6c3 48 48 #include "ip_header.h" 49 49 50 int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length){51 ip_header_ref header;52 uint8_t * data;53 size_t padding;54 55 padding = ipopt_length % 4;56 if(padding){57 padding = 4 - padding;58 ipopt_length += padding;59 }60 data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding);61 if(! data){62 return ENOMEM;63 }64 while(padding --){65 data[sizeof(ip_header_t) + padding] = IPOPT_NOOP;66 }67 header = (ip_header_ref) data;68 header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length);69 header->ttl = (ttl ? ttl : IPDEFTTL); //(((ttl) <= MAXTTL) ? ttl : MAXTTL) : IPDEFTTL;70 header->tos = tos;71 header->protocol = protocol;72 if(dont_fragment){73 header->flags = IPFLAG_DONT_FRAGMENT;74 }75 return EOK;76 }77 78 int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length){79 ip_header_ref header;80 81 header = (ip_header_ref) packet_get_data(packet);82 if((! header)83 || (packet_get_data_length(packet) < sizeof(ip_header_t))){84 return ENOMEM;85 }86 if(protocol){87 *protocol = header->protocol;88 }89 if(ttl){90 *ttl = header->ttl;91 }92 if(tos){93 *tos = header->tos;94 }95 if(dont_fragment){96 *dont_fragment = header->flags &IPFLAG_DONT_FRAGMENT;97 }98 if(ipopt_length){99 *ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t);100 return sizeof(ip_header_t);101 }else{102 return IP_HEADER_LENGTH(header);103 }104 }105 106 50 size_t ip_client_header_length(packet_t packet){ 107 51 ip_header_ref header; … … 113 57 } 114 58 return IP_HEADER_LENGTH(header); 115 }116 117 int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length){118 ipv4_pseudo_header_ref header_in;119 120 if(! header){121 return EBADMEM;122 }123 if(headerlen == sizeof(ipv4_pseudo_header_t)){124 header_in = (ipv4_pseudo_header_ref) header;125 header_in->data_length = htons(data_length);126 return EOK;127 }else{128 return EINVAL;129 }130 59 } 131 60 … … 140 69 return EINVAL; 141 70 } 71 142 72 switch(src->sa_family){ 143 73 case AF_INET: … … 171 101 } 172 102 103 int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length){ 104 ip_header_ref header; 105 uint8_t * data; 106 size_t padding; 107 108 // compute the padding if IP options are set 109 // multiple of 4 bytes 110 padding = ipopt_length % 4; 111 if(padding){ 112 padding = 4 - padding; 113 ipopt_length += padding; 114 } 115 116 // prefix the header 117 data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding); 118 if(! data){ 119 return ENOMEM; 120 } 121 122 // add the padding 123 while(padding --){ 124 data[sizeof(ip_header_t) + padding] = IPOPT_NOOP; 125 } 126 127 // set the header 128 header = (ip_header_ref) data; 129 header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length); 130 header->ttl = (ttl ? ttl : IPDEFTTL); //(((ttl) <= MAXTTL) ? ttl : MAXTTL) : IPDEFTTL; 131 header->tos = tos; 132 header->protocol = protocol; 133 134 if(dont_fragment){ 135 header->flags = IPFLAG_DONT_FRAGMENT; 136 } 137 return EOK; 138 } 139 140 int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length){ 141 ip_header_ref header; 142 143 header = (ip_header_ref) packet_get_data(packet); 144 if((! header) 145 || (packet_get_data_length(packet) < sizeof(ip_header_t))){ 146 return ENOMEM; 147 } 148 149 if(protocol){ 150 *protocol = header->protocol; 151 } 152 if(ttl){ 153 *ttl = header->ttl; 154 } 155 if(tos){ 156 *tos = header->tos; 157 } 158 if(dont_fragment){ 159 *dont_fragment = header->flags &IPFLAG_DONT_FRAGMENT; 160 } 161 if(ipopt_length){ 162 *ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t); 163 return sizeof(ip_header_t); 164 }else{ 165 return IP_HEADER_LENGTH(header); 166 } 167 } 168 169 int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length){ 170 ipv4_pseudo_header_ref header_in; 171 172 if(! header){ 173 return EBADMEM; 174 } 175 176 if(headerlen == sizeof(ipv4_pseudo_header_t)){ 177 header_in = (ipv4_pseudo_header_ref) header; 178 header_in->data_length = htons(data_length); 179 return EOK; 180 // TODO IPv6 181 }else{ 182 return EINVAL; 183 } 184 } 185 173 186 /** @} 174 187 */
Note:
See TracChangeset
for help on using the changeset viewer.