Lines Matching refs:pkt

52 void net_rx_pkt_init(struct NetRxPkt **pkt)  in net_rx_pkt_init()  argument
57 *pkt = p; in net_rx_pkt_init()
60 void net_rx_pkt_uninit(struct NetRxPkt *pkt) in net_rx_pkt_uninit() argument
62 if (pkt->vec_len_total != 0) { in net_rx_pkt_uninit()
63 g_free(pkt->vec); in net_rx_pkt_uninit()
66 g_free(pkt); in net_rx_pkt_uninit()
69 struct virtio_net_hdr *net_rx_pkt_get_vhdr(struct NetRxPkt *pkt) in net_rx_pkt_get_vhdr() argument
71 assert(pkt); in net_rx_pkt_get_vhdr()
72 return &pkt->virt_hdr; in net_rx_pkt_get_vhdr()
76 net_rx_pkt_iovec_realloc(struct NetRxPkt *pkt, in net_rx_pkt_iovec_realloc() argument
79 if (pkt->vec_len_total < new_iov_len) { in net_rx_pkt_iovec_realloc()
80 g_free(pkt->vec); in net_rx_pkt_iovec_realloc()
81 pkt->vec = g_malloc(sizeof(*pkt->vec) * new_iov_len); in net_rx_pkt_iovec_realloc()
82 pkt->vec_len_total = new_iov_len; in net_rx_pkt_iovec_realloc()
87 net_rx_pkt_pull_data(struct NetRxPkt *pkt, in net_rx_pkt_pull_data() argument
93 if (pkt->ehdr_buf_len) { in net_rx_pkt_pull_data()
94 net_rx_pkt_iovec_realloc(pkt, iovcnt + 1); in net_rx_pkt_pull_data()
96 pkt->vec[0].iov_base = &pkt->ehdr_buf; in net_rx_pkt_pull_data()
97 pkt->vec[0].iov_len = pkt->ehdr_buf_len; in net_rx_pkt_pull_data()
99 pkt->tot_len = pllen + pkt->ehdr_buf_len; in net_rx_pkt_pull_data()
100 pkt->vec_len = iov_copy(pkt->vec + 1, pkt->vec_len_total - 1, in net_rx_pkt_pull_data()
103 net_rx_pkt_iovec_realloc(pkt, iovcnt); in net_rx_pkt_pull_data()
105 pkt->tot_len = pllen; in net_rx_pkt_pull_data()
106 pkt->vec_len = iov_copy(pkt->vec, pkt->vec_len_total, in net_rx_pkt_pull_data()
107 iov, iovcnt, ploff, pkt->tot_len); in net_rx_pkt_pull_data()
110 eth_get_protocols(pkt->vec, pkt->vec_len, 0, &pkt->hasip4, &pkt->hasip6, in net_rx_pkt_pull_data()
111 &pkt->l3hdr_off, &pkt->l4hdr_off, &pkt->l5hdr_off, in net_rx_pkt_pull_data()
112 &pkt->ip6hdr_info, &pkt->ip4hdr_info, &pkt->l4hdr_info); in net_rx_pkt_pull_data()
114 trace_net_rx_pkt_parsed(pkt->hasip4, pkt->hasip6, pkt->l4hdr_info.proto, in net_rx_pkt_pull_data()
115 pkt->l3hdr_off, pkt->l4hdr_off, pkt->l5hdr_off); in net_rx_pkt_pull_data()
118 void net_rx_pkt_attach_iovec(struct NetRxPkt *pkt, in net_rx_pkt_attach_iovec() argument
124 assert(pkt); in net_rx_pkt_attach_iovec()
127 pkt->ehdr_buf_len = eth_strip_vlan(iov, iovcnt, iovoff, &pkt->ehdr_buf, in net_rx_pkt_attach_iovec()
130 pkt->ehdr_buf_len = 0; in net_rx_pkt_attach_iovec()
133 pkt->tci = tci; in net_rx_pkt_attach_iovec()
135 net_rx_pkt_pull_data(pkt, iov, iovcnt, ploff); in net_rx_pkt_attach_iovec()
138 void net_rx_pkt_attach_iovec_ex(struct NetRxPkt *pkt, in net_rx_pkt_attach_iovec_ex() argument
145 assert(pkt); in net_rx_pkt_attach_iovec_ex()
147 pkt->ehdr_buf_len = eth_strip_vlan_ex(iov, iovcnt, iovoff, in net_rx_pkt_attach_iovec_ex()
149 &pkt->ehdr_buf, in net_rx_pkt_attach_iovec_ex()
152 pkt->tci = tci; in net_rx_pkt_attach_iovec_ex()
154 net_rx_pkt_pull_data(pkt, iov, iovcnt, ploff); in net_rx_pkt_attach_iovec_ex()
157 void net_rx_pkt_dump(struct NetRxPkt *pkt) in net_rx_pkt_dump() argument
160 assert(pkt); in net_rx_pkt_dump()
163 pkt->tot_len, pkt->ehdr_buf_len, pkt->tci); in net_rx_pkt_dump()
167 void net_rx_pkt_set_packet_type(struct NetRxPkt *pkt, in net_rx_pkt_set_packet_type() argument
170 assert(pkt); in net_rx_pkt_set_packet_type()
172 pkt->packet_type = packet_type; in net_rx_pkt_set_packet_type()
176 eth_pkt_types_e net_rx_pkt_get_packet_type(struct NetRxPkt *pkt) in net_rx_pkt_get_packet_type() argument
178 assert(pkt); in net_rx_pkt_get_packet_type()
180 return pkt->packet_type; in net_rx_pkt_get_packet_type()
183 size_t net_rx_pkt_get_total_len(struct NetRxPkt *pkt) in net_rx_pkt_get_total_len() argument
185 assert(pkt); in net_rx_pkt_get_total_len()
187 return pkt->tot_len; in net_rx_pkt_get_total_len()
190 void net_rx_pkt_set_protocols(struct NetRxPkt *pkt, in net_rx_pkt_set_protocols() argument
194 assert(pkt); in net_rx_pkt_set_protocols()
196 eth_get_protocols(iov, iovcnt, iovoff, &pkt->hasip4, &pkt->hasip6, in net_rx_pkt_set_protocols()
197 &pkt->l3hdr_off, &pkt->l4hdr_off, &pkt->l5hdr_off, in net_rx_pkt_set_protocols()
198 &pkt->ip6hdr_info, &pkt->ip4hdr_info, &pkt->l4hdr_info); in net_rx_pkt_set_protocols()
201 void net_rx_pkt_get_protocols(struct NetRxPkt *pkt, in net_rx_pkt_get_protocols() argument
205 assert(pkt); in net_rx_pkt_get_protocols()
207 *hasip4 = pkt->hasip4; in net_rx_pkt_get_protocols()
208 *hasip6 = pkt->hasip6; in net_rx_pkt_get_protocols()
209 *l4hdr_proto = pkt->l4hdr_info.proto; in net_rx_pkt_get_protocols()
212 size_t net_rx_pkt_get_l3_hdr_offset(struct NetRxPkt *pkt) in net_rx_pkt_get_l3_hdr_offset() argument
214 assert(pkt); in net_rx_pkt_get_l3_hdr_offset()
215 return pkt->l3hdr_off; in net_rx_pkt_get_l3_hdr_offset()
218 size_t net_rx_pkt_get_l4_hdr_offset(struct NetRxPkt *pkt) in net_rx_pkt_get_l4_hdr_offset() argument
220 assert(pkt); in net_rx_pkt_get_l4_hdr_offset()
221 return pkt->l4hdr_off; in net_rx_pkt_get_l4_hdr_offset()
224 size_t net_rx_pkt_get_l5_hdr_offset(struct NetRxPkt *pkt) in net_rx_pkt_get_l5_hdr_offset() argument
226 assert(pkt); in net_rx_pkt_get_l5_hdr_offset()
227 return pkt->l5hdr_off; in net_rx_pkt_get_l5_hdr_offset()
230 eth_ip6_hdr_info *net_rx_pkt_get_ip6_info(struct NetRxPkt *pkt) in net_rx_pkt_get_ip6_info() argument
232 return &pkt->ip6hdr_info; in net_rx_pkt_get_ip6_info()
235 eth_ip4_hdr_info *net_rx_pkt_get_ip4_info(struct NetRxPkt *pkt) in net_rx_pkt_get_ip4_info() argument
237 return &pkt->ip4hdr_info; in net_rx_pkt_get_ip4_info()
251 struct NetRxPkt *pkt, in _net_rx_rss_prepare_ip4() argument
254 struct ip_header *ip4_hdr = &pkt->ip4hdr_info.ip4_hdr; in _net_rx_rss_prepare_ip4()
265 struct NetRxPkt *pkt, in _net_rx_rss_prepare_ip6() argument
268 eth_ip6_hdr_info *ip6info = &pkt->ip6hdr_info; in _net_rx_rss_prepare_ip6()
283 struct NetRxPkt *pkt, in _net_rx_rss_prepare_tcp() argument
286 struct tcp_header *tcphdr = &pkt->l4hdr_info.hdr.tcp; in _net_rx_rss_prepare_tcp()
297 struct NetRxPkt *pkt, in _net_rx_rss_prepare_udp() argument
300 struct udp_header *udphdr = &pkt->l4hdr_info.hdr.udp; in _net_rx_rss_prepare_udp()
310 net_rx_pkt_calc_rss_hash(struct NetRxPkt *pkt, in net_rx_pkt_calc_rss_hash() argument
321 assert(pkt->hasip4); in net_rx_pkt_calc_rss_hash()
323 _net_rx_rss_prepare_ip4(&rss_input[0], pkt, &rss_length); in net_rx_pkt_calc_rss_hash()
326 assert(pkt->hasip4); in net_rx_pkt_calc_rss_hash()
327 assert(pkt->l4hdr_info.proto == ETH_L4_HDR_PROTO_TCP); in net_rx_pkt_calc_rss_hash()
329 _net_rx_rss_prepare_ip4(&rss_input[0], pkt, &rss_length); in net_rx_pkt_calc_rss_hash()
330 _net_rx_rss_prepare_tcp(&rss_input[0], pkt, &rss_length); in net_rx_pkt_calc_rss_hash()
333 assert(pkt->hasip6); in net_rx_pkt_calc_rss_hash()
334 assert(pkt->l4hdr_info.proto == ETH_L4_HDR_PROTO_TCP); in net_rx_pkt_calc_rss_hash()
336 _net_rx_rss_prepare_ip6(&rss_input[0], pkt, false, &rss_length); in net_rx_pkt_calc_rss_hash()
337 _net_rx_rss_prepare_tcp(&rss_input[0], pkt, &rss_length); in net_rx_pkt_calc_rss_hash()
340 assert(pkt->hasip6); in net_rx_pkt_calc_rss_hash()
342 _net_rx_rss_prepare_ip6(&rss_input[0], pkt, false, &rss_length); in net_rx_pkt_calc_rss_hash()
345 assert(pkt->hasip6); in net_rx_pkt_calc_rss_hash()
347 _net_rx_rss_prepare_ip6(&rss_input[0], pkt, true, &rss_length); in net_rx_pkt_calc_rss_hash()
350 assert(pkt->hasip6); in net_rx_pkt_calc_rss_hash()
351 assert(pkt->l4hdr_info.proto == ETH_L4_HDR_PROTO_TCP); in net_rx_pkt_calc_rss_hash()
353 _net_rx_rss_prepare_ip6(&rss_input[0], pkt, true, &rss_length); in net_rx_pkt_calc_rss_hash()
354 _net_rx_rss_prepare_tcp(&rss_input[0], pkt, &rss_length); in net_rx_pkt_calc_rss_hash()
357 assert(pkt->hasip4); in net_rx_pkt_calc_rss_hash()
358 assert(pkt->l4hdr_info.proto == ETH_L4_HDR_PROTO_UDP); in net_rx_pkt_calc_rss_hash()
360 _net_rx_rss_prepare_ip4(&rss_input[0], pkt, &rss_length); in net_rx_pkt_calc_rss_hash()
361 _net_rx_rss_prepare_udp(&rss_input[0], pkt, &rss_length); in net_rx_pkt_calc_rss_hash()
364 assert(pkt->hasip6); in net_rx_pkt_calc_rss_hash()
365 assert(pkt->l4hdr_info.proto == ETH_L4_HDR_PROTO_UDP); in net_rx_pkt_calc_rss_hash()
367 _net_rx_rss_prepare_ip6(&rss_input[0], pkt, false, &rss_length); in net_rx_pkt_calc_rss_hash()
368 _net_rx_rss_prepare_udp(&rss_input[0], pkt, &rss_length); in net_rx_pkt_calc_rss_hash()
371 assert(pkt->hasip6); in net_rx_pkt_calc_rss_hash()
372 assert(pkt->l4hdr_info.proto == ETH_L4_HDR_PROTO_UDP); in net_rx_pkt_calc_rss_hash()
374 _net_rx_rss_prepare_ip6(&rss_input[0], pkt, true, &rss_length); in net_rx_pkt_calc_rss_hash()
375 _net_rx_rss_prepare_udp(&rss_input[0], pkt, &rss_length); in net_rx_pkt_calc_rss_hash()
390 uint16_t net_rx_pkt_get_ip_id(struct NetRxPkt *pkt) in net_rx_pkt_get_ip_id() argument
392 assert(pkt); in net_rx_pkt_get_ip_id()
394 if (pkt->hasip4) { in net_rx_pkt_get_ip_id()
395 return be16_to_cpu(pkt->ip4hdr_info.ip4_hdr.ip_id); in net_rx_pkt_get_ip_id()
401 bool net_rx_pkt_is_tcp_ack(struct NetRxPkt *pkt) in net_rx_pkt_is_tcp_ack() argument
403 assert(pkt); in net_rx_pkt_is_tcp_ack()
405 if (pkt->l4hdr_info.proto == ETH_L4_HDR_PROTO_TCP) { in net_rx_pkt_is_tcp_ack()
406 return TCP_HEADER_FLAGS(&pkt->l4hdr_info.hdr.tcp) & TCP_FLAG_ACK; in net_rx_pkt_is_tcp_ack()
412 bool net_rx_pkt_has_tcp_data(struct NetRxPkt *pkt) in net_rx_pkt_has_tcp_data() argument
414 assert(pkt); in net_rx_pkt_has_tcp_data()
416 if (pkt->l4hdr_info.proto == ETH_L4_HDR_PROTO_TCP) { in net_rx_pkt_has_tcp_data()
417 return pkt->l4hdr_info.has_tcp_data; in net_rx_pkt_has_tcp_data()
423 struct iovec *net_rx_pkt_get_iovec(struct NetRxPkt *pkt) in net_rx_pkt_get_iovec() argument
425 assert(pkt); in net_rx_pkt_get_iovec()
427 return pkt->vec; in net_rx_pkt_get_iovec()
430 uint16_t net_rx_pkt_get_iovec_len(struct NetRxPkt *pkt) in net_rx_pkt_get_iovec_len() argument
432 assert(pkt); in net_rx_pkt_get_iovec_len()
434 return pkt->vec_len; in net_rx_pkt_get_iovec_len()
437 void net_rx_pkt_set_vhdr(struct NetRxPkt *pkt, in net_rx_pkt_set_vhdr() argument
440 assert(pkt); in net_rx_pkt_set_vhdr()
442 memcpy(&pkt->virt_hdr, vhdr, sizeof pkt->virt_hdr); in net_rx_pkt_set_vhdr()
445 void net_rx_pkt_set_vhdr_iovec(struct NetRxPkt *pkt, in net_rx_pkt_set_vhdr_iovec() argument
448 assert(pkt); in net_rx_pkt_set_vhdr_iovec()
450 iov_to_buf(iov, iovcnt, 0, &pkt->virt_hdr, sizeof pkt->virt_hdr); in net_rx_pkt_set_vhdr_iovec()
453 void net_rx_pkt_unset_vhdr(struct NetRxPkt *pkt) in net_rx_pkt_unset_vhdr() argument
455 assert(pkt); in net_rx_pkt_unset_vhdr()
457 memset(&pkt->virt_hdr, 0, sizeof(pkt->virt_hdr)); in net_rx_pkt_unset_vhdr()
460 bool net_rx_pkt_is_vlan_stripped(struct NetRxPkt *pkt) in net_rx_pkt_is_vlan_stripped() argument
462 assert(pkt); in net_rx_pkt_is_vlan_stripped()
464 return pkt->ehdr_buf_len ? true : false; in net_rx_pkt_is_vlan_stripped()
467 uint16_t net_rx_pkt_get_vlan_tag(struct NetRxPkt *pkt) in net_rx_pkt_get_vlan_tag() argument
469 assert(pkt); in net_rx_pkt_get_vlan_tag()
471 return pkt->tci; in net_rx_pkt_get_vlan_tag()
474 bool net_rx_pkt_validate_l3_csum(struct NetRxPkt *pkt, bool *csum_valid) in net_rx_pkt_validate_l3_csum() argument
482 if (!pkt->hasip4) { in net_rx_pkt_validate_l3_csum()
487 csl = pkt->l4hdr_off - pkt->l3hdr_off; in net_rx_pkt_validate_l3_csum()
489 cntr = net_checksum_add_iov(pkt->vec, pkt->vec_len, in net_rx_pkt_validate_l3_csum()
490 pkt->l3hdr_off, in net_rx_pkt_validate_l3_csum()
497 trace_net_rx_pkt_l3_csum_validate_csum(pkt->l3hdr_off, csl, in net_rx_pkt_validate_l3_csum()
504 _net_rx_pkt_calc_l4_csum(struct NetRxPkt *pkt) in _net_rx_pkt_calc_l4_csum() argument
513 if (pkt->hasip4) { in _net_rx_pkt_calc_l4_csum()
514 if (pkt->l4hdr_info.proto == ETH_L4_HDR_PROTO_UDP) { in _net_rx_pkt_calc_l4_csum()
515 csl = be16_to_cpu(pkt->l4hdr_info.hdr.udp.uh_ulen); in _net_rx_pkt_calc_l4_csum()
518 csl = be16_to_cpu(pkt->ip4hdr_info.ip4_hdr.ip_len) - in _net_rx_pkt_calc_l4_csum()
519 IP_HDR_GET_LEN(&pkt->ip4hdr_info.ip4_hdr); in _net_rx_pkt_calc_l4_csum()
523 cntr = eth_calc_ip4_pseudo_hdr_csum(&pkt->ip4hdr_info.ip4_hdr, in _net_rx_pkt_calc_l4_csum()
527 if (pkt->l4hdr_info.proto == ETH_L4_HDR_PROTO_UDP) { in _net_rx_pkt_calc_l4_csum()
528 csl = be16_to_cpu(pkt->l4hdr_info.hdr.udp.uh_ulen); in _net_rx_pkt_calc_l4_csum()
531 struct ip6_header *ip6hdr = &pkt->ip6hdr_info.ip6_hdr; in _net_rx_pkt_calc_l4_csum()
532 size_t full_ip6hdr_len = pkt->l4hdr_off - pkt->l3hdr_off; in _net_rx_pkt_calc_l4_csum()
540 cntr = eth_calc_ip6_pseudo_hdr_csum(&pkt->ip6hdr_info.ip6_hdr, csl, in _net_rx_pkt_calc_l4_csum()
541 pkt->ip6hdr_info.l4proto, &cso); in _net_rx_pkt_calc_l4_csum()
545 cntr += net_checksum_add_iov(pkt->vec, pkt->vec_len, in _net_rx_pkt_calc_l4_csum()
546 pkt->l4hdr_off, csl, cso); in _net_rx_pkt_calc_l4_csum()
550 trace_net_rx_pkt_l4_csum_calc_csum(pkt->l4hdr_off, csl, cntr, csum); in _net_rx_pkt_calc_l4_csum()
556 _net_rx_pkt_validate_sctp_sum(struct NetRxPkt *pkt) in _net_rx_pkt_validate_sctp_sum() argument
559 size_t off = pkt->l4hdr_off; in _net_rx_pkt_validate_sctp_sum()
560 size_t vec_len = pkt->vec_len; in _net_rx_pkt_validate_sctp_sum()
566 for (vec = pkt->vec; vec->iov_len < off; vec++) { in _net_rx_pkt_validate_sctp_sum()
591 bool net_rx_pkt_validate_l4_csum(struct NetRxPkt *pkt, bool *csum_valid) in net_rx_pkt_validate_l4_csum() argument
597 if (pkt->hasip4 && pkt->ip4hdr_info.fragment) { in net_rx_pkt_validate_l4_csum()
602 switch (pkt->l4hdr_info.proto) { in net_rx_pkt_validate_l4_csum()
604 if (pkt->l4hdr_info.hdr.udp.uh_sum == 0) { in net_rx_pkt_validate_l4_csum()
610 csum = _net_rx_pkt_calc_l4_csum(pkt); in net_rx_pkt_validate_l4_csum()
615 *csum_valid = _net_rx_pkt_validate_sctp_sum(pkt); in net_rx_pkt_validate_l4_csum()
628 bool net_rx_pkt_fix_l4_csum(struct NetRxPkt *pkt) in net_rx_pkt_fix_l4_csum() argument
635 switch (pkt->l4hdr_info.proto) { in net_rx_pkt_fix_l4_csum()
642 if (pkt->l4hdr_info.hdr.udp.uh_sum == 0) { in net_rx_pkt_fix_l4_csum()
655 if (pkt->hasip4 && pkt->ip4hdr_info.fragment) { in net_rx_pkt_fix_l4_csum()
661 iov_from_buf(pkt->vec, pkt->vec_len, in net_rx_pkt_fix_l4_csum()
662 pkt->l4hdr_off + l4_cso, in net_rx_pkt_fix_l4_csum()
666 csum = cpu_to_be16(_net_rx_pkt_calc_l4_csum(pkt)); in net_rx_pkt_fix_l4_csum()
669 iov_from_buf(pkt->vec, pkt->vec_len, in net_rx_pkt_fix_l4_csum()
670 pkt->l4hdr_off + l4_cso, in net_rx_pkt_fix_l4_csum()
673 trace_net_rx_pkt_l4_csum_fix_csum(pkt->l4hdr_off + l4_cso, csum); in net_rx_pkt_fix_l4_csum()