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 * PF_INET6 protocol dispatch tables.
7 *
8 * Version: $Id: protocol.c,v 1.9 2000/10/03 07:29:01 anton Exp $
9 *
10 * Authors: Pedro Roque <roque@di.fc.ul.pt>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 */
17
18 #include <linux/errno.h>
19 #include <linux/types.h>
20 #include <linux/socket.h>
21 #include <linux/sockios.h>
22 #include <linux/sched.h>
23 #include <linux/net.h>
24 #include <linux/in6.h>
25 #include <linux/netdevice.h>
26 #include <linux/if_arp.h>
27 #include <linux/brlock.h>
28
29 #include <net/sock.h>
30 #include <net/snmp.h>
31
32 #include <net/ipv6.h>
33 #include <net/protocol.h>
34
35 struct inet6_protocol *inet6_protocol_base;
36 struct inet6_protocol *inet6_protos[MAX_INET_PROTOS];
37
38 void inet6_add_protocol(struct inet6_protocol *prot)
39 {
40 unsigned char hash;
41 struct inet6_protocol *p2;
42
43 hash = prot->protocol & (MAX_INET_PROTOS - 1);
44 br_write_lock_bh(BR_NETPROTO_LOCK);
45 prot->next = inet6_protos[hash];
46 inet6_protos[hash] = prot;
47 prot->copy = 0;
48
49 /*
50 * Set the copy bit if we need to.
51 */
52
53 p2 = (struct inet6_protocol *) prot->next;
54 while(p2 != NULL) {
55 if (p2->protocol == prot->protocol) {
56 prot->copy = 1;
57 break;
58 }
59 p2 = (struct inet6_protocol *) p2->next;
60 }
61 br_write_unlock_bh(BR_NETPROTO_LOCK);
62 }
63
64 /*
65 * Remove a protocol from the hash tables.
66 */
67
68 int inet6_del_protocol(struct inet6_protocol *prot)
69 {
70 struct inet6_protocol *p;
71 struct inet6_protocol *lp = NULL;
72 unsigned char hash;
73
74 hash = prot->protocol & (MAX_INET_PROTOS - 1);
75 br_write_lock_bh(BR_NETPROTO_LOCK);
76 if (prot == inet6_protos[hash]) {
77 inet6_protos[hash] = (struct inet6_protocol *) inet6_protos[hash]->next;
78 br_write_unlock_bh(BR_NETPROTO_LOCK);
79 return(0);
80 }
81
82 p = (struct inet6_protocol *) inet6_protos[hash];
83 while(p != NULL) {
84 /*
85 * We have to worry if the protocol being deleted is
86 * the last one on the list, then we may need to reset
87 * someone's copied bit.
88 */
89 if (p->next != NULL && p->next == prot) {
90 /*
91 * if we are the last one with this protocol and
92 * there is a previous one, reset its copy bit.
93 */
94 if (p->copy == 0 && lp != NULL)
95 lp->copy = 0;
96 p->next = prot->next;
97 br_write_unlock_bh(BR_NETPROTO_LOCK);
98 return(0);
99 }
100 if (p->next != NULL && p->next->protocol == prot->protocol)
101 lp = p;
102
103 p = (struct inet6_protocol *) p->next;
104 }
105 br_write_unlock_bh(BR_NETPROTO_LOCK);
106 return(-1);
107 }
108
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.