root/include/net/head_explode.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. exp_getu16
  2. exp_getn16
  3. imp_putu16
  4. imp_putn16
  5. exp_getu32
  6. exp_getn32
  7. imp_putu32
  8. imp_putn32
  9. ip_explode
  10. icmp_explode
  11. igmp_explode
  12. tcp_explode
  13. udp_explode

   1 /*
   2  *      Header exploders. We inline those only appearing once.
   3  *
   4  *      We assume 8 bit bytes.
   5  *
   6  *      This is oriented to getting good code out of GCC. It may need
   7  *      tuning for other processors.
   8  *
   9  *      Note only IGMP uses this so far. Just as an experiment.
  10  */
  11  
  12  
  13 extern __inline__ unsigned char *exp_getu16(unsigned char *bp, unsigned short *u)
     /* [previous][next][first][last][top][bottom][index][help] */
  14 {
  15         *u=(*bp<<8)|bp[1];
  16         return bp+2;
  17 }
  18 
  19 extern __inline__ unsigned char *exp_getn16(unsigned char *bp, unsigned short *u)
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21         unsigned char *tp=(unsigned char *)u;
  22         *tp++=*bp++;
  23         *tp++=*bp++;
  24         return bp;
  25 }
  26 
  27 extern __inline__ unsigned char *imp_putu16(unsigned char *bp, unsigned short n)
     /* [previous][next][first][last][top][bottom][index][help] */
  28 {
  29         *bp=(n>>8);
  30         bp[1]=n&0xFF;
  31         return bp+2;
  32 }
  33 
  34 extern __inline__ unsigned char *imp_putn16(unsigned char *bp, unsigned short n)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36         unsigned char *sp=(unsigned char *)&n;
  37         *bp++=*sp++;
  38         *bp++=*sp++;
  39         return bp;
  40 }
  41 
  42 extern __inline__ unsigned char *exp_getu32(unsigned char *bp, unsigned long *u)
     /* [previous][next][first][last][top][bottom][index][help] */
  43 {
  44         *u=(bp[0]<<24)|(bp[1]<<16)|(bp[2]<<8)|bp[3];
  45         return bp+4;
  46 }
  47 
  48 extern __inline__ unsigned char *exp_getn32(unsigned char *bp, unsigned long *u)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50         unsigned char *tp=(unsigned char *)u;
  51         *tp++=*bp++;
  52         *tp++=*bp++;
  53         *tp++=*bp++;
  54         *tp++=*bp++;
  55         return bp;
  56 }
  57 
  58 extern __inline__ unsigned char *imp_putu32(unsigned char *bp, unsigned long n)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60         bp[0]=n>>24;
  61         bp[1]=(n>>16)&0xFF;
  62         bp[2]=(n>>8)&0xFF;
  63         bp[3]=n&0xFF;
  64         return bp+4;
  65 }
  66 
  67 extern __inline__ unsigned char *imp_putn32(unsigned char *bp, unsigned long n)
     /* [previous][next][first][last][top][bottom][index][help] */
  68 {
  69         unsigned char *sp=(unsigned char *)&n;
  70         *bp++=*sp++;
  71         *bp++=*sp++;
  72         *bp++=*sp++;
  73         *bp++=*sp++;
  74         return bp;
  75 }
  76 
  77 #if 0
  78 
  79 extern __inline__ unsigned char *ip_explode(unsigned char *iph, struct ip_header *ip)
     /* [previous][next][first][last][top][bottom][index][help] */
  80 {
  81         ip->version=*iph>>4;            /* Avoid the shift. We do our equality checks shifted too */
  82         ip->ihl=(*iph++)&0xF;           /* Length in long words */
  83         ip->tos=*iph++;                 /* Service type */
  84         iph=exp_getu16(iph,&ip->tot_len);       /* Length of packet */
  85         iph=exp_getu16(iph,&ip->id);            /* Packet identity */
  86         iph=exp_getu16(iph,&ip->frag_off);      /* Fragment offset */
  87         ip->ttl=*iph++;
  88         ip->protocol=*iph++;
  89         iph=exp_getn16(iph,&ip->check);
  90         iph=exp_getn32(iph,&ip->saddr);
  91         iph=exp_getn32(iph,&ip->daddr);
  92         return iph;
  93 }
  94 
  95 extern __inline__ unsigned char *icmp_explode(unsigned char *icmph, struct icmp_header *icmp)
     /* [previous][next][first][last][top][bottom][index][help] */
  96 {
  97         icmp->type=*icmp++;
  98         icmp->code=*icmp++;
  99         icmph=exp_getn16(icmph,&icmp->checksum);
 100         /* These two pairs are a union... expand both */
 101         exp_getu32(icmph,&icmp->gateway);       
 102         icmph=exp_getu16(icmph,&icmp->id);
 103         icmph=exp_getu16(icmph,&icmp->sequence);
 104         return icmph;
 105 }
 106 
 107 #endif
 108 
 109 extern __inline__ unsigned char *igmp_explode(unsigned char *igmph, struct igmp_header *igmp)
     /* [previous][next][first][last][top][bottom][index][help] */
 110 {
 111         igmp->type=*igmph++;
 112         igmph++;        /* unused */
 113         igmph=exp_getn16(igmph,&igmp->csum);
 114         igmph=exp_getn32(igmph,&igmp->group);
 115         return igmph;
 116 }
 117 
 118 #if 0
 119 extern __inline__ unsigned char *tcp_explode(unsigned char *tcph, struct tcp_header *tcp)
     /* [previous][next][first][last][top][bottom][index][help] */
 120 {
 121         tcph=exp_getu16(tcph,&tcp->source);
 122         tcph=exp_getu16(tcph,&tcp->dest);
 123         tcph=exp_getu32(tcph,&tcp->seq);
 124         tcph=exp_getu32(tcph,&tcp->ack_seq);
 125         tcph=exp_getu16(tcph,&tcp->u.bitmask);
 126         tcph=exp_getu16(tcph,&tcp->window);
 127         tcph=exp_getn16(tcph,&tcp->check);
 128         tcph=exp_getu16(tcph,&tcp->urg_ptr);
 129         return tcph;
 130 }
 131 
 132 extern __inline__ unsigned char *udp_explode(unsigned char *udph, struct udp_header *udp)
     /* [previous][next][first][last][top][bottom][index][help] */
 133 {
 134         udph=exp_getu16(tcph,&udp->source);
 135         udph=exp_getu16(udph,&udp->dest);
 136         udph=exp_getu16(udph,&udp->len);
 137         udph=exp_getn16(udph,&udp->check);
 138         return udph;
 139 }
 140 #endif

/* [previous][next][first][last][top][bottom][index][help] */