dear everybody,

i have encountered a problem big enough for me to
handle.
Actually i am trying to compress the data contained
in the ip packets. 

i see that the data to be passed by ip to link layer 
output routine is contained in mbuf *m.

Now what i tried to do is I tried to copy the original
mbufs to newer mbufs and passed the newer mbufs to the
if_output() instead of the older ones. And I tried to 
release the older mbufs myself.

For this purpose i wrote the routine below.
But it doesn't seem to work.

The problem I encounter is the mbuf in the ip_output
doesnot seem to be released and gets printed(by my
custom routine) infinitely. 

What is the problem ???

Please help 

kamal

PS. i have put the code with which i tried to replace 
the original mbufs 


void copy_the_memorybuffer(struct mbuf **m)
{       struct mbuf *tmp_mbuf;
        
        struct mbuf *mbuf_pointer=*m;  //original mbuf header
        struct mbuf **mnext;
        struct mbuf **second_mbuf_pointer;      
                
        struct mbuf **second_packet_pointer;
        struct mbuf **next_packet;

        unsigned int ipheaderlength;
        unsigned int packet_length;
        unsigned char *ip_char_buffer;
        
        int i; //loop variable

        second_packet_pointer=&mbuf_pointer->m_nextpkt;
        next_packet=&mbuf_pointer->m_nextpkt;

for(;*next_packet;*next_packet=(*next_packet)->m_nextpkt)

        {       
        if(((*next_packet)->m_flags & M_PKTHDR)!=0)     
        { struct ip *dest_ip;
          dest_ip=mtod((*next_packet),struct ip *);     
          dest_ip->ip_tos=66;
          printf("\nDestination ip
(next_packet)=%s\n",inet_ntoa(dest_ip->ip_dst));          
        }
        
        second_mbuf_pointer=&(*next_packet)->m_next;
        mnext=&(*next_packet)->m_next; //keep the first
packet as it is
        for(;*mnext;*mnext=(*mnext)->m_next)  //loop until
the end of memory buffer
        {
           printf("\ninside the for loop(mnext)\n");
           if(((*mnext)->m_flags & M_PKTHDR)!=0) 
           //this is the start of the packet    
             { MGETHDR(tmp_mbuf,M_WAIT,(*mnext)->m_type);
                   
                   if(((*mnext)->m_flags & M_EXT)!=0)  //uses a
cluster
                          MCLGET(tmp_mbuf,M_WAIT); 
                   
                   struct ip *my_ip;
                   my_ip=mtod(*mnext,struct ip *);
                   my_ip->ip_tos=55;               
                   
                   printf("\nDestination
ip=%s\n",inet_ntoa(my_ip->ip_dst));
                   ipheaderlength=my_ip->ip_hl<<2; //4*ip header
length= real header length         
                   
                   packet_length=(*mnext)->m_len;
                   ip_char_buffer=(unsigned char *)my_ip;
                                        
                   for(i=0;i<ipheaderlength;i++)                        
                   {tmp_mbuf->m_data[i]=(*mnext)->m_data[i];
                   }
                  
                   for(i=ipheaderlength;i<packet_length;i++)                    
   
                   {tmp_mbuf->m_data[i]=(*mnext)->m_data[i];
                   }
                   tmp_mbuf->m_pkthdr.len=(*mnext)->m_pkthdr.len;
                   tmp_mbuf->m_pkthdr.rcvif=(struct ifnet *)0;
                  
tmp_mbuf->m_pkthdr.header=(*mnext)->m_pkthdr.header;
                  
tmp_mbuf->m_pkthdr.csum_flags=(*mnext)->m_pkthdr.csum_flags;
                  
tmp_mbuf->m_pkthdr.csum_data=(*mnext)->m_pkthdr.csum_data;
             }
           else  //the mbuf is not the packet header so it
does not contain the ip header
             { MGET(tmp_mbuf,M_WAIT,(*mnext)->m_type);                          
   
  
                   if(((*mnext)->m_flags & M_EXT)!=0)
                      MCLGET(tmp_mbuf,M_WAIT); 
        
                   packet_length=(*mnext)->m_len;
                   for(i=0;i<packet_length;i++) //copy all the
packet data
                   { tmp_mbuf->m_data[i]=(*mnext)->m_data[i];
                   }
                 }                      
                   tmp_mbuf->m_len=(*mnext)->m_len;
                   tmp_mbuf->m_flags=(*mnext)->m_flags;
                   tmp_mbuf->m_nextpkt=(*mnext)->m_nextpkt;
           
                   tmp_mbuf->m_next=(*mnext)->m_next;
                   *mnext=tmp_mbuf;
           }
           m_freem(*second_mbuf_pointer);
     }
         *m=mbuf_pointer;
         return;
}


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to