- 论坛徽章:
- 0
|
本帖最后由 lujian19861986 于 2012-08-07 18:03 编辑
struct iphdr *iph = (*pskb)->nh.iph;
struct tcphdr *tcph = (void *)iph + iph->ihl*4;
unsigned char *data = (void *)tcph + tcph->doff*4;
unsigned int datalen = (*pskb)->len - (iph->ihl*4) - (tcph->doff*4);
struct sk_buff *mc=NULL;
struct rtable *rt;
struct flowi fl={ .oif = 0,
.nl_u = { .ip4_u =
{ .daddr = iph->saddr,
.saddr = 0,
.tos = 0 } },
.proto = IPPROTO_TCP,
.uli_u = { .ports =
{ .sport = tcph->dest,
.dport =tcph->source } } };
mc = skb_copy(*pskb,GFP_ATOMIC);
if(mc == NULL)
{
return -1;
}
mc->input_dev=NULL;
mc->dev=NULL;
mc->pkt_type = PACKET_HOST;
//printk(KERN_EMERG"http_format_info:%s\n","ippr_send_eboard_notification");
if( __ip_route_output_key(&rt,&fl) )
{
kfree_skb(mc);
printk("lujian ippr_send_eboard_notification() return -1;\n");
return -1;
}
mc->csum=0;
mc->dst = &rt->u.dst;//Derek
mc->dev = mc->dst->dev;
//header definition
struct iphdr *new_iph = (mc)->nh.iph;
struct tcphdr *new_tcph = (void *)new_iph + new_iph->ihl*4;
unsigned char *new_data = (void *)new_tcph + new_tcph->doff*4;
/* clear memory */
memset((char *)new_data,0, datalen);
//lujian 8-6
memcpy(new_data, block_htm, strlen(block_htm));
//printk("lujian new_data: %s\n", new_data);
/* fill ip header */
iph->protocol = IPPROTO_TCP;
new_iph->saddr = iph->daddr;
new_iph->daddr = iph->saddr;
new_iph->ttl = 127;
new_iph->check =0;
new_iph->check = ip_fast_csum((void *)new_iph, new_iph->ihl);
/* fill tcp header */
new_tcph->source = tcph->dest;
new_tcph->dest = tcph->source;
tcp_flag_word(new_tcph) = (TCP_FLAG_ACK | TCP_FLAG_PSH);
if (tcp_flag_word(new_tcph) & TCP_FLAG_ACK)
new_tcph->seq = tcph->ack_seq;
else
new_tcph->seq = htonl(1);
new_tcph->doff = (sizeof(tcphdr_t)>>2);
/* the ack should acknowledge all the packet, find the size */
new_tcph->ack_seq = htonl(ntohl(tcph->seq) + datalen);
//lujian 8-6
//memcpy((char *)new_tcph + sizeof(tcphdr_t), block_htm, strlen(block_htm));
//lujian test
//new_tcph->check = csum_tcpudp_magic(new_iph->saddr, new_iph->daddr, datalen, IPPROTO_TCP,csum_partial((char *)new_tcph,datalen,0));
printk("lujian ###before ip_finish_output(mc); mc->csum:%u, mc->dev:%s, new_tcph->check=%u\n", mc->csum, (char *)mc->dev, new_tcph->check);
ip_finish_output(mc);
printk("lujian ###after ip_finish_output(mc); mc->csum:%u, new_tcph->ack_seq:%u, new_iph->check:%u\n", mc->csum, new_tcph->ack_seq, new_iph->check);
|
|