lkml.org 
[lkml]   [2014]   [Aug]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH net-next v3 4/4 RFC] pktgen: Allow sending IPv4 TCP packets
On 01/08/14 05:32, David Miller wrote:
> From: Zoltan Kiss <zoltan.kiss@citrix.com>
>> @@ -3017,29 +3029,40 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
>> iph = (struct iphdr *) skb_put(skb, sizeof(struct iphdr));
>>
>> skb_set_transport_header(skb, skb->len);
>> - udph = (struct udphdr *) skb_put(skb, sizeof(struct udphdr));
>> +
>> + if (pkt_dev->flags & F_TCP) {
>> + datalen = pkt_dev->cur_pkt_size - ETH_HLEN - 20 -
>> + sizeof(struct tcphdr) - pkt_dev->pkt_overhead;
>> + tcph = (struct tcphdr *)skb_put(skb, sizeof(struct tcphdr));
>> + memset(tcph, 0, sizeof(*tcph));
>> + tcph->source = htons(pkt_dev->cur_udp_src);
>> + tcph->dest = htons(pkt_dev->cur_udp_dst);
>> + tcph->doff = sizeof(struct tcphdr) >> 2;
>> + } else {
>> + datalen = pkt_dev->cur_pkt_size - ETH_HLEN - 20 -
>> + sizeof(struct udphdr) - pkt_dev->pkt_overhead;
>> + udph = (struct udphdr *)skb_put(skb, sizeof(struct udphdr));
>> + udph->source = htons(pkt_dev->cur_udp_src);
>> + udph->dest = htons(pkt_dev->cur_udp_dst);
>> + udph->len = htons(datalen + sizeof(struct udphdr));
>> + udph->check = 0;
>> + }
>> +
>
> As more protocols (SCTP, etc.) get supported, this is going to become
> completely unmanageable. Please use callbacks or something like that
> so this function doesn't turn into even more spaghetti.
OK

>
>> + } else if (pkt_dev->flags & F_TCP) {
>> + struct inet_sock inet;
>> +
>> + inet.inet_saddr = iph->saddr;
>> + inet.inet_daddr = iph->daddr;
>> + skb->ip_summed = CHECKSUM_NONE;
>> + tcp_v4_send_check((struct sock *)&inet, skb);
>
> Please don't do things like this. Making fake sockets on the stack, don't
> do it.
>
> Do other non-socket contexts compute TCP checksums this way? Check
> netfilter or similar, see what they do.
>
> Worst case export __tcp_v4_send_check() or just duplicate it's contents
> in the tcp case here.
Indeed, it was a quick and dirty solution. I'll duplicate the relevant
bits __tcp_v4_send_check



\
 
 \ /
  Last update: 2014-08-04 16:01    [W:1.710 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site