root/net/ipv4/protocol.c

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

DEFINITIONS

This source file includes following definitions.
  1. inet_get_protocol
  2. inet_add_protocol
  3. inet_del_protocol

   1 /*
   2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3  *              operating system.  INET is implemented using the  BSD Socket
   4  *              interface as the means of communication with the user level.
   5  *
   6  *              INET protocol dispatch tables.
   7  *
   8  * Version:     @(#)protocol.c  1.0.5   05/25/93
   9  *
  10  * Authors:     Ross Biro, <bir7@leland.Stanford.Edu>
  11  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12  *
  13  * Fixes:
  14  *              Alan Cox        : Ahah! udp icmp errors don't work because
  15  *                                udp_err is never called!
  16  *              Alan Cox        : Added new fields for init and ready for
  17  *                                proper fragmentation (_NO_ 4K limits!)
  18  *
  19  *              This program is free software; you can redistribute it and/or
  20  *              modify it under the terms of the GNU General Public License
  21  *              as published by the Free Software Foundation; either version
  22  *              2 of the License, or (at your option) any later version.
  23  */
  24 #include <asm/segment.h>
  25 #include <asm/system.h>
  26 #include <linux/types.h>
  27 #include <linux/kernel.h>
  28 #include <linux/sched.h>
  29 #include <linux/string.h>
  30 #include <linux/config.h>
  31 #include <linux/socket.h>
  32 #include <linux/in.h>
  33 #include <linux/inet.h>
  34 #include <linux/netdevice.h>
  35 #include <linux/timer.h>
  36 #include <net/ip.h>
  37 #include <net/protocol.h>
  38 #include <net/tcp.h>
  39 #include <linux/skbuff.h>
  40 #include <net/sock.h>
  41 #include <net/icmp.h>
  42 #include <net/udp.h>
  43 #include <net/ipip.h>
  44 #include <linux/igmp.h>
  45 
  46 
  47 #ifdef CONFIG_IP_FORWARD
  48 #ifdef CONFIG_NET_IPIP
  49 
  50 static struct inet_protocol ipip_protocol = {
  51   ipip_rcv,             /* IPIP handler          */
  52   NULL,                 /* Will be UDP fraglist handler */
  53   NULL,                 /* TUNNEL error control    */
  54   0,                    /* next                 */
  55   IPPROTO_IPIP,         /* protocol ID          */
  56   0,                    /* copy                 */
  57   NULL,                 /* data                 */
  58   "IPIP"                /* name                 */
  59 };
  60 
  61 
  62 #endif
  63 #endif
  64 
  65 static struct inet_protocol tcp_protocol = {
  66   tcp_rcv,              /* TCP handler          */
  67   NULL,                 /* No fragment handler (and won't be for a long time) */
  68   tcp_err,              /* TCP error control    */  
  69 #if defined(CONFIG_NET_IPIP) && defined(CONFIG_IP_FORWARD)
  70   &ipip_protocol,
  71 #else  
  72   NULL,                 /* next                 */
  73 #endif  
  74   IPPROTO_TCP,          /* protocol ID          */
  75   0,                    /* copy                 */
  76   NULL,                 /* data                 */
  77   "TCP"                 /* name                 */
  78 };
  79 
  80 
  81 static struct inet_protocol udp_protocol = {
  82   udp_rcv,              /* UDP handler          */
  83   NULL,                 /* Will be UDP fraglist handler */
  84   udp_err,              /* UDP error control    */
  85   &tcp_protocol,        /* next                 */
  86   IPPROTO_UDP,          /* protocol ID          */
  87   0,                    /* copy                 */
  88   NULL,                 /* data                 */
  89   "UDP"                 /* name                 */
  90 };
  91 
  92 
  93 static struct inet_protocol icmp_protocol = {
  94   icmp_rcv,             /* ICMP handler         */
  95   NULL,                 /* ICMP never fragments anyway */
  96   NULL,                 /* ICMP error control   */
  97   &udp_protocol,        /* next                 */
  98   IPPROTO_ICMP,         /* protocol ID          */
  99   0,                    /* copy                 */
 100   NULL,                 /* data                 */
 101   "ICMP"                /* name                 */
 102 };
 103 
 104 #ifndef CONFIG_IP_MULTICAST
 105 struct inet_protocol *inet_protocol_base = &icmp_protocol;
 106 #else
 107 static struct inet_protocol igmp_protocol = {
 108   igmp_rcv,             /* IGMP handler         */
 109   NULL,                 /* IGMP never fragments anyway */
 110   NULL,                 /* IGMP error control   */
 111   &icmp_protocol,       /* next                 */
 112   IPPROTO_IGMP,         /* protocol ID          */
 113   0,                    /* copy                 */
 114   NULL,                 /* data                 */
 115   "IGMP"                /* name                 */
 116 };
 117 
 118 struct inet_protocol *inet_protocol_base = &igmp_protocol;
 119 #endif
 120 
 121 struct inet_protocol *inet_protos[MAX_INET_PROTOS] = {
 122   NULL
 123 };
 124 
 125 
 126 struct inet_protocol *
 127 inet_get_protocol(unsigned char prot)
     /* [previous][next][first][last][top][bottom][index][help] */
 128 {
 129   unsigned char hash;
 130   struct inet_protocol *p;
 131 
 132   hash = prot & (MAX_INET_PROTOS - 1);
 133   for (p = inet_protos[hash] ; p != NULL; p=p->next) {
 134         if (p->protocol == prot) return((struct inet_protocol *) p);
 135   }
 136   return(NULL);
 137 }
 138 
 139 
 140 void
 141 inet_add_protocol(struct inet_protocol *prot)
     /* [previous][next][first][last][top][bottom][index][help] */
 142 {
 143   unsigned char hash;
 144   struct inet_protocol *p2;
 145 
 146   hash = prot->protocol & (MAX_INET_PROTOS - 1);
 147   prot ->next = inet_protos[hash];
 148   inet_protos[hash] = prot;
 149   prot->copy = 0;
 150 
 151   /* Set the copy bit if we need to. */
 152   p2 = (struct inet_protocol *) prot->next;
 153   while(p2 != NULL) {
 154         if (p2->protocol == prot->protocol) {
 155                 prot->copy = 1;
 156                 break;
 157         }
 158         p2 = (struct inet_protocol *) prot->next;
 159   }
 160 }
 161 
 162 
 163 int
 164 inet_del_protocol(struct inet_protocol *prot)
     /* [previous][next][first][last][top][bottom][index][help] */
 165 {
 166   struct inet_protocol *p;
 167   struct inet_protocol *lp = NULL;
 168   unsigned char hash;
 169 
 170   hash = prot->protocol & (MAX_INET_PROTOS - 1);
 171   if (prot == inet_protos[hash]) {
 172         inet_protos[hash] = (struct inet_protocol *) inet_protos[hash]->next;
 173         return(0);
 174   }
 175 
 176   p = (struct inet_protocol *) inet_protos[hash];
 177   while(p != NULL) {
 178         /*
 179          * We have to worry if the protocol being deleted is
 180          * the last one on the list, then we may need to reset
 181          * someone's copied bit.
 182          */
 183         if (p->next != NULL && p->next == prot) {
 184                 /*
 185                  * if we are the last one with this protocol and
 186                  * there is a previous one, reset its copy bit.
 187                  */
 188              if (p->copy == 0 && lp != NULL) lp->copy = 0;
 189              p->next = prot->next;
 190              return(0);
 191         }
 192 
 193         if (p->next != NULL && p->next->protocol == prot->protocol) {
 194                 lp = p;
 195         }
 196 
 197         p = (struct inet_protocol *) p->next;
 198   }
 199   return(-1);
 200 }

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