- 论坛徽章:
- 0
|
static int skb_clone_xmit( struct sk_buff *pskb, const struct net_device *in )
{
int retval = 0;
struct sk_buff *nskb;
struct iphdr *oiph;
struct tcphdr *tcph;
unsigned char eth_addr[ETH_ALEN];
struct ethhdr *oeth;
__be32 addr;
__be16 port;
u32 tcplen;
oiph = ip_hdr( pskb );
tcph = (struct tcphdr *)((u_int32_t *)oiph + oiph->ihl);
if(ntohs(tcph->dest) != 80)
{
return -1;
}
nskb = skb_clone(pskb, GFP_ATOMIC);
if ( !nskb ) {
printk( "skb_clone occur error!\n" );
return -1;
}
nskb->pkt_type = PACKET_OUTGOING; //OUTGOING;
nskb->dev = (struct net_device *)in;
print_block(pskb->data - ETH_HLEN,ETH_HLEN);
nskb->data = skb_mac_header(nskb);
nskb->len += ETH_HLEN;
ALERT("nskb->len is %d \r\n", nskb->len);
//mac
if (pskb->mac_header != NULL) {
oeth = (struct ethhdr *)nskb->mac_header;
memcpy( eth_addr, oeth->h_source, ETH_ALEN );
memcpy( oeth->h_source, oeth->h_dest, ETH_ALEN );
memcpy( oeth->h_dest, eth_addr, ETH_ALEN );
}
oeth = skb_mac_header(pskb);
oiph = ip_hdr(nskb );
tcph = (struct tcphdr *)((u_int32_t *)oiph + oiph->ihl);
addr = oiph->daddr;
oiph->daddr = oiph->saddr;
oiph->saddr = addr;
ALERT("IP packet with packet from %d.%d.%d.%d to %d.%d.%d.%d\r\n",NIPQUAD(oiph->saddr),NIPQUAD(oiph->daddr));
// tcp
port = tcph->source;
tcph->source = tcph->dest;
tcph->dest = port;
//memset(nskb->data,0xff,6);
if(tcph->ack && !(tcph->psh))
{
return 0;
}
else if(tcph->syn){
tcph->ack_seq = htonl( ntohl(tcph->seq) + 1 );
tcph->seq = 0;
tcph->ack = 1;
}
else if(tcph->psh)
{
unsigned int recv_len = nskb->len - ETH_HLEN - sizeof(struct iphdr) - 32;
unsigned int ack_seq = ntohl(tcph->ack_seq);
tcph->ack_seq = htonl( ntohl(tcph->seq) + recv_len);
tcph->seq = htonl(ack_seq);
ALERT("recevie http request rec_len = %d ~~~~~~~~~~~~~~~~~~~~",recv_len);
tcph->fin = 1;
tcph->window = htons(930);
char *buf = nskb->data + ETH_HLEN+sizeof(struct tcphdr)+sizeof(struct iphdr);
memcpy(buf,content,strlen(content));
nskb->len = ETH_HLEN+sizeof(struct iphdr)+sizeof(struct tcphdr) + strlen(content);
nskb->len =ETH_HLEN+sizeof(struct iphdr)+sizeof(struct tcphdr);
oiph->tot_len = htons(nskb->len - ETH_HLEN);
oiph->id = htons(273;
oiph->ttl = 255 ;
}
ALERT("IP packet with packet from %d to %d\r\n",ntohs(tcph->source),ntohs(tcph->dest));
if(tcph->syn)
tcplen = ntohs( oiph->tot_len ) - oiph->ihl * 4;
else
{
tcplen = sizeof(struct tcphdr)+strlen(content);
tcph->doff = sizeof(struct tcphdr)>>2;
}
ALERT("tcplen %d nskblen %d\r\n",tcplen,nskb->len);
tcph->check = 0;
tcph->check = tcp_v4_check( tcplen,
oiph->saddr, oiph->daddr,
csum_partial(tcph,
tcplen, 0));
ip_send_check( oiph );
retval = dev_queue_xmit(nskb);
printk( "dev_queue_xmit return %d\n", retval );
return retval;
}
|
|