From: 최익성 <pnk003@naver.com>
To: dev@dpdk.org
Subject: [dpdk-dev] Questions about reading/writing/modifying packet header.
Date: Mon, 18 Apr 2016 21:14:12 +0900 (KST) [thread overview]
Message-ID: <6b15729351b224d4ad9a7ae4ceeb13@cweb23.nm.nhnsystem.com> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 4259 bytes --]
Dear DPDK exports.
I am Ick-Sung Choi living in South Korea.
Thank you very much for your contributions.
I studied a lot from your source codes.
However, actually I have a lot of codes/algorithms that I can't understand.
The codes seems to be incomplete, but it works in my test case.
If I take an example, the worker assignment method using & (not %) in load balancing was not fixed yet.
There are a lot of similar codes such as in rte_distributor_process() in distributor.
I have a few questions about reading/writing/modifying packet header. I know it is complex.
I will really appreciate if I can be given answer and some example codes.
Question #1) I would like to know how can I read/write/modify TCP/UDP/ICMP/IGMP/... headers from packet in rte_mbuf.
I will really appreciate if I can be given an example code. I guess it would be somewhat complex.
Question #2) The IP checksum does not include 6 the ptr. 6 th ptr (ptr16[5]) is missing in the example code. Is it right?
( ip_cksum += ptr16[5]; in the following code.)
The following code reads headers and write modified headers (used in DPDK source codes).
void swap_header_in_a_packet ( struct rte_mbuf *buf )
{
struct ether_hdr *eth_hdr;
struct ether_addr eth_src_addr, eth_dest_addr ;
struct ipv4_hdr *ip_hdr;
uint32_t ip_src_addr, ip_dest_addr ;
// Read Eternet header.
eth_hdr = rte_pktmbuf_mtod( buf, struct ether_hdr *);
// Extract MAC addresses.
ether_addr_copy(&eth_hdr->s_addr, &eth_src_addr );
ether_addr_copy(&eth_hdr->d_addr, &eth_dest_addr );
// Swap MAC addresses.
ether_addr_copy(&eth_src_addr, &eth_hdr->d_addr);
ether_addr_copy(&eth_dest_addr, &eth_hdr->s_addr);
// Swap IP addresses.
ip_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod( buf, unsigned char *) + sizeof(struct ether_hdr));
ip_src_addr = (uint32_t) ip_hdr->src_addr; // source IP address.
ip_dest_addr = (uint32_t) ip_hdr->dst_addr; // destination IP address.
ip_hdr->src_addr = (uint32_t) ip_dest_addr ;
ip_hdr->dst_addr = (uint32_t) ip_src_addr ;
setup_simple_example_pkt_ip_headers( (char *) ip_hdr );
copy_buf_to_pkt(&eth_hdr, sizeof(eth_hdr), buf, 0);
copy_buf_to_pkt(&ip_hdr, sizeof(ip_hdr), buf, sizeof(struct ether_hdr));
}
static void setup_simple_example_pkt_ip_headers( char *ip_hdr )
{
uint16_t *ptr16; uint32_t ip_cksum; // uint16_t pkt_len;
struct ipv4_hdr *ip_hdr1 = (struct ipv4_hdr *) ip_hdr ;
// Initialize UDP header.
/*
pkt_len = (uint16_t) (pkt_data_len + sizeof(struct udp_hdr));
udp_hdr->src_port = rte_cpu_to_be_16(UDP_SRC_PORT);
udp_hdr->dst_port = rte_cpu_to_be_16(UDP_DST_PORT);
udp_hdr->dgram_len = RTE_CPU_TO_BE_16(pkt_len);
udp_hdr->dgram_cksum = 0; // No UDP checksum.
*/
// Compute IP header checksum.
ptr16 = (uint16_t*) ip_hdr1;
ip_cksum = 0;
ip_cksum += ptr16[0]; ip_cksum += ptr16[1]; ip_cksum += ptr16[2]; ip_cksum += ptr16[3]; ip_cksum += ptr16[4];
ip_cksum += ptr16[5]; ? // 6 th ptr (ptr16[5]) is missing in the example code. Is it right?
ip_cksum += ptr16[6]; ip_cksum += ptr16[7];
ip_cksum += ptr16[8]; ip_cksum += ptr16[9];
// Reduce 32 bit checksum to 16 bits and complement it.
ip_cksum = ((ip_cksum & 0xFFFF0000) >> 16) + (ip_cksum & 0x0000FFFF);
if (ip_cksum > 65535) ip_cksum -= 65535;
ip_cksum = (~ip_cksum) & 0x0000FFFF;
if (ip_cksum == 0) ip_cksum = 0xFFFF;
ip_hdr1->hdr_checksum = (uint16_t) ip_cksum;
}
Is the Ben really coding machine? (as in the presentation.) ^^
Thank you very much.
Sincerely Yours,
Ick-Sung Choi.
\x16º&'!ié_«\x1cjÚrW¢c(
k×Íxã]9ÛMzEën®sÚ¶\x19¢r\x16úڱƨ§%yÊ&Eç\x1e÷~º&ºÇ«§]8ÒÚrW¢k¬zºuÓ(§%yÊ&×µç]õóVòvd¢¸\x0f¢Ë_\x1c"¶\x11\x1213ât\x1d×]½\a§èׯvd¢¸\f¢}|\x02öÓ^µãtãí6Ó@I4^qè¯y×ë¢f¬z»ôÓmh§%yÊ&jÇ«¿M6ÖÚrW¢mx×^:×n¶ßvòºÇ«§]8ÒÚrW¢dÚâ¢s\x13\x03öý'§¶¸¨ÄÀã}°ØDHÄÏÛ· '÷A\r6ç]x½êì
next reply other threads:[~2016-04-18 12:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-18 12:14 최익성 [this message]
2016-04-18 15:47 ` Andriy Berestovskyy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6b15729351b224d4ad9a7ae4ceeb13@cweb23.nm.nhnsystem.com \
--to=pnk003@naver.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).