root/net/inet/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/socket.h>
  31 #include <linux/in.h>
  32 #include <linux/inet.h>
  33 #include <linux/netdevice.h>
  34 #include <linux/timer.h>
  35 #include "ip.h"
  36 #include "protocol.h"
  37 #include "tcp.h"
  38 #include <linux/skbuff.h>
  39 #include "sock.h"
  40 #include "icmp.h"
  41 #include "udp.h"
  42 #include "igmp.h"
  43 
  44 
  45 static struct inet_protocol tcp_protocol = {
  46   tcp_rcv,              /* TCP handler          */
  47   NULL,                 /* No fragment handler (and won't be for a long time) */
  48   tcp_err,              /* TCP error control    */
  49   NULL,                 /* next                 */
  50   IPPROTO_TCP,          /* protocol ID          */
  51   0,                    /* copy                 */
  52   NULL,                 /* data                 */
  53   "TCP"                 /* name                 */
  54 };
  55 
  56 
  57 static struct inet_protocol udp_protocol = {
  58   udp_rcv,              /* UDP handler          */
  59   NULL,                 /* Will be UDP fraglist handler */
  60   udp_err,              /* UDP error control    */
  61   &tcp_protocol,        /* next                 */
  62   IPPROTO_UDP,          /* protocol ID          */
  63   0,                    /* copy                 */
  64   NULL,                 /* data                 */
  65   "UDP"                 /* name                 */
  66 };
  67 
  68 
  69 static struct inet_protocol icmp_protocol = {
  70   icmp_rcv,             /* ICMP handler         */
  71   NULL,                 /* ICMP never fragments anyway */
  72   NULL,                 /* ICMP error control   */
  73   &udp_protocol,        /* next                 */
  74   IPPROTO_ICMP,         /* protocol ID          */
  75   0,                    /* copy                 */
  76   NULL,                 /* data                 */
  77   "ICMP"                /* name                 */
  78 };
  79 
  80 #ifndef CONFIG_IP_MULTICAST
  81 struct inet_protocol *inet_protocol_base = &icmp_protocol;
  82 #else
  83 static struct inet_protocol igmp_protocol = {
  84   igmp_rcv,             /* IGMP handler         */
  85   NULL,                 /* IGMP never fragments anyway */
  86   NULL,                 /* IGMP error control   */
  87   &icmp_protocol,       /* next                 */
  88   IPPROTO_IGMP,         /* protocol ID          */
  89   0,                    /* copy                 */
  90   NULL,                 /* data                 */
  91   "IGMP"                /* name                 */
  92 };
  93 
  94 struct inet_protocol *inet_protocol_base = &igmp_protocol;
  95 #endif
  96 
  97 struct inet_protocol *inet_protos[MAX_INET_PROTOS] = {
  98   NULL
  99 };
 100 
 101 
 102 struct inet_protocol *
 103 inet_get_protocol(unsigned char prot)
     /* [previous][next][first][last][top][bottom][index][help] */
 104 {
 105   unsigned char hash;
 106   struct inet_protocol *p;
 107 
 108   hash = prot & (MAX_INET_PROTOS - 1);
 109   for (p = inet_protos[hash] ; p != NULL; p=p->next) {
 110         if (p->protocol == prot) return((struct inet_protocol *) p);
 111   }
 112   return(NULL);
 113 }
 114 
 115 
 116 void
 117 inet_add_protocol(struct inet_protocol *prot)
     /* [previous][next][first][last][top][bottom][index][help] */
 118 {
 119   unsigned char hash;
 120   struct inet_protocol *p2;
 121 
 122   hash = prot->protocol & (MAX_INET_PROTOS - 1);
 123   prot ->next = inet_protos[hash];
 124   inet_protos[hash] = prot;
 125   prot->copy = 0;
 126 
 127   /* Set the copy bit if we need to. */
 128   p2 = (struct inet_protocol *) prot->next;
 129   while(p2 != NULL) {
 130         if (p2->protocol == prot->protocol) {
 131                 prot->copy = 1;
 132                 break;
 133         }
 134         p2 = (struct inet_protocol *) prot->next;
 135   }
 136 }
 137 
 138 
 139 int
 140 inet_del_protocol(struct inet_protocol *prot)
     /* [previous][next][first][last][top][bottom][index][help] */
 141 {
 142   struct inet_protocol *p;
 143   struct inet_protocol *lp = NULL;
 144   unsigned char hash;
 145 
 146   hash = prot->protocol & (MAX_INET_PROTOS - 1);
 147   if (prot == inet_protos[hash]) {
 148         inet_protos[hash] = (struct inet_protocol *) inet_protos[hash]->next;
 149         return(0);
 150   }
 151 
 152   p = (struct inet_protocol *) inet_protos[hash];
 153   while(p != NULL) {
 154         /*
 155          * We have to worry if the protocol being deleted is
 156          * the last one on the list, then we may need to reset
 157          * someone's copied bit.
 158          */
 159         if (p->next != NULL && p->next == prot) {
 160                 /*
 161                  * if we are the last one with this protocol and
 162                  * there is a previous one, reset its copy bit.
 163                  */
 164              if (p->copy == 0 && lp != NULL) lp->copy = 0;
 165              p->next = prot->next;
 166              return(0);
 167         }
 168 
 169         if (p->next != NULL && p->next->protocol == prot->protocol) {
 170                 lp = p;
 171         }
 172 
 173         p = (struct inet_protocol *) p->next;
 174   }
 175   return(-1);
 176 }

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