~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ipv6/tunnel6.c

Version: ~ [ linux-5.16 ] ~ [ linux-5.15.13 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.90 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.170 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.224 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.261 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.296 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.298 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/ipv6/tunnel6.c (Version linux-4.13.16) and /net/ipv6/tunnel6.c (Version linux-3.10.108)


  1 /*                                                  1 /*
  2  * Copyright (C)2003,2004 USAGI/WIDE Project        2  * Copyright (C)2003,2004 USAGI/WIDE Project
  3  *                                                  3  *
  4  * This program is free software; you can redi      4  * This program is free software; you can redistribute it and/or modify
  5  * it under the terms of the GNU General Publi      5  * it under the terms of the GNU General Public License as published by
  6  * the Free Software Foundation; either versio      6  * the Free Software Foundation; either version 2 of the License, or
  7  * (at your option) any later version.              7  * (at your option) any later version.
  8  *                                                  8  *
  9  * This program is distributed in the hope tha      9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the      10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  * GNU General Public License for more details     12  * GNU General Public License for more details.
 13  *                                                 13  *
 14  * You should have received a copy of the GNU      14  * You should have received a copy of the GNU General Public License
 15  * along with this program; if not, see <http: !!  15  * along with this program; if not, write to the Free Software
                                                   >>  16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 16  *                                                 17  *
 17  * Authors      Mitsuru KANDA  <mk@linux-ipv6.     18  * Authors      Mitsuru KANDA  <mk@linux-ipv6.org>
 18  *              YOSHIFUJI Hideaki <yoshfuji@li !!  19  *              YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
 19  */                                                20  */
 20                                                    21 
 21 #define pr_fmt(fmt) "IPv6: " fmt                   22 #define pr_fmt(fmt) "IPv6: " fmt
 22                                                    23 
 23 #include <linux/icmpv6.h>                          24 #include <linux/icmpv6.h>
 24 #include <linux/init.h>                            25 #include <linux/init.h>
 25 #include <linux/module.h>                          26 #include <linux/module.h>
 26 #include <linux/mutex.h>                           27 #include <linux/mutex.h>
 27 #include <linux/netdevice.h>                       28 #include <linux/netdevice.h>
 28 #include <linux/skbuff.h>                          29 #include <linux/skbuff.h>
 29 #include <linux/slab.h>                            30 #include <linux/slab.h>
 30 #include <net/ipv6.h>                              31 #include <net/ipv6.h>
 31 #include <net/protocol.h>                          32 #include <net/protocol.h>
 32 #include <net/xfrm.h>                              33 #include <net/xfrm.h>
 33                                                    34 
 34 static struct xfrm6_tunnel __rcu *tunnel6_hand     35 static struct xfrm6_tunnel __rcu *tunnel6_handlers __read_mostly;
 35 static struct xfrm6_tunnel __rcu *tunnel46_han     36 static struct xfrm6_tunnel __rcu *tunnel46_handlers __read_mostly;
 36 static DEFINE_MUTEX(tunnel6_mutex);                37 static DEFINE_MUTEX(tunnel6_mutex);
 37                                                    38 
 38 int xfrm6_tunnel_register(struct xfrm6_tunnel      39 int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family)
 39 {                                                  40 {
 40         struct xfrm6_tunnel __rcu **pprev;         41         struct xfrm6_tunnel __rcu **pprev;
 41         struct xfrm6_tunnel *t;                    42         struct xfrm6_tunnel *t;
 42         int ret = -EEXIST;                         43         int ret = -EEXIST;
 43         int priority = handler->priority;          44         int priority = handler->priority;
 44                                                    45 
 45         mutex_lock(&tunnel6_mutex);                46         mutex_lock(&tunnel6_mutex);
 46                                                    47 
 47         for (pprev = (family == AF_INET6) ? &t     48         for (pprev = (family == AF_INET6) ? &tunnel6_handlers : &tunnel46_handlers;
 48              (t = rcu_dereference_protected(*p     49              (t = rcu_dereference_protected(*pprev,
 49                         lockdep_is_held(&tunne     50                         lockdep_is_held(&tunnel6_mutex))) != NULL;
 50              pprev = &t->next) {                   51              pprev = &t->next) {
 51                 if (t->priority > priority)        52                 if (t->priority > priority)
 52                         break;                     53                         break;
 53                 if (t->priority == priority)       54                 if (t->priority == priority)
 54                         goto err;                  55                         goto err;
 55         }                                          56         }
 56                                                    57 
 57         handler->next = *pprev;                    58         handler->next = *pprev;
 58         rcu_assign_pointer(*pprev, handler);       59         rcu_assign_pointer(*pprev, handler);
 59                                                    60 
 60         ret = 0;                                   61         ret = 0;
 61                                                    62 
 62 err:                                               63 err:
 63         mutex_unlock(&tunnel6_mutex);              64         mutex_unlock(&tunnel6_mutex);
 64                                                    65 
 65         return ret;                                66         return ret;
 66 }                                                  67 }
                                                   >>  68 
 67 EXPORT_SYMBOL(xfrm6_tunnel_register);              69 EXPORT_SYMBOL(xfrm6_tunnel_register);
 68                                                    70 
 69 int xfrm6_tunnel_deregister(struct xfrm6_tunne     71 int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family)
 70 {                                                  72 {
 71         struct xfrm6_tunnel __rcu **pprev;         73         struct xfrm6_tunnel __rcu **pprev;
 72         struct xfrm6_tunnel *t;                    74         struct xfrm6_tunnel *t;
 73         int ret = -ENOENT;                         75         int ret = -ENOENT;
 74                                                    76 
 75         mutex_lock(&tunnel6_mutex);                77         mutex_lock(&tunnel6_mutex);
 76                                                    78 
 77         for (pprev = (family == AF_INET6) ? &t     79         for (pprev = (family == AF_INET6) ? &tunnel6_handlers : &tunnel46_handlers;
 78              (t = rcu_dereference_protected(*p     80              (t = rcu_dereference_protected(*pprev,
 79                         lockdep_is_held(&tunne     81                         lockdep_is_held(&tunnel6_mutex))) != NULL;
 80              pprev = &t->next) {                   82              pprev = &t->next) {
 81                 if (t == handler) {                83                 if (t == handler) {
 82                         *pprev = handler->next     84                         *pprev = handler->next;
 83                         ret = 0;                   85                         ret = 0;
 84                         break;                     86                         break;
 85                 }                                  87                 }
 86         }                                          88         }
 87                                                    89 
 88         mutex_unlock(&tunnel6_mutex);              90         mutex_unlock(&tunnel6_mutex);
 89                                                    91 
 90         synchronize_net();                         92         synchronize_net();
 91                                                    93 
 92         return ret;                                94         return ret;
 93 }                                                  95 }
                                                   >>  96 
 94 EXPORT_SYMBOL(xfrm6_tunnel_deregister);            97 EXPORT_SYMBOL(xfrm6_tunnel_deregister);
 95                                                    98 
 96 #define for_each_tunnel_rcu(head, handler)         99 #define for_each_tunnel_rcu(head, handler)              \
 97         for (handler = rcu_dereference(head);     100         for (handler = rcu_dereference(head);           \
 98              handler != NULL;                     101              handler != NULL;                           \
 99              handler = rcu_dereference(handler    102              handler = rcu_dereference(handler->next))  \
100                                                   103 
101 static int tunnel6_rcv(struct sk_buff *skb)       104 static int tunnel6_rcv(struct sk_buff *skb)
102 {                                                 105 {
103         struct xfrm6_tunnel *handler;             106         struct xfrm6_tunnel *handler;
104                                                   107 
105         if (!pskb_may_pull(skb, sizeof(struct     108         if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
106                 goto drop;                        109                 goto drop;
107                                                   110 
108         for_each_tunnel_rcu(tunnel6_handlers,     111         for_each_tunnel_rcu(tunnel6_handlers, handler)
109                 if (!handler->handler(skb))       112                 if (!handler->handler(skb))
110                         return 0;                 113                         return 0;
111                                                   114 
112         icmpv6_send(skb, ICMPV6_DEST_UNREACH,     115         icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
113                                                   116 
114 drop:                                             117 drop:
115         kfree_skb(skb);                           118         kfree_skb(skb);
116         return 0;                                 119         return 0;
117 }                                                 120 }
118                                                   121 
119 static int tunnel46_rcv(struct sk_buff *skb)      122 static int tunnel46_rcv(struct sk_buff *skb)
120 {                                                 123 {
121         struct xfrm6_tunnel *handler;             124         struct xfrm6_tunnel *handler;
122                                                   125 
123         if (!pskb_may_pull(skb, sizeof(struct     126         if (!pskb_may_pull(skb, sizeof(struct iphdr)))
124                 goto drop;                        127                 goto drop;
125                                                   128 
126         for_each_tunnel_rcu(tunnel46_handlers,    129         for_each_tunnel_rcu(tunnel46_handlers, handler)
127                 if (!handler->handler(skb))       130                 if (!handler->handler(skb))
128                         return 0;                 131                         return 0;
129                                                   132 
130         icmpv6_send(skb, ICMPV6_DEST_UNREACH,     133         icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
131                                                   134 
132 drop:                                             135 drop:
133         kfree_skb(skb);                           136         kfree_skb(skb);
134         return 0;                                 137         return 0;
135 }                                                 138 }
136                                                   139 
137 static void tunnel6_err(struct sk_buff *skb, s    140 static void tunnel6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
138                         u8 type, u8 code, int     141                         u8 type, u8 code, int offset, __be32 info)
139 {                                                 142 {
140         struct xfrm6_tunnel *handler;             143         struct xfrm6_tunnel *handler;
141                                                   144 
142         for_each_tunnel_rcu(tunnel6_handlers,     145         for_each_tunnel_rcu(tunnel6_handlers, handler)
143                 if (!handler->err_handler(skb,    146                 if (!handler->err_handler(skb, opt, type, code, offset, info))
144                         break;                    147                         break;
145 }                                                 148 }
146                                                   149 
147 static void tunnel46_err(struct sk_buff *skb,  << 
148                          u8 type, u8 code, int << 
149 {                                              << 
150         struct xfrm6_tunnel *handler;          << 
151                                                << 
152         for_each_tunnel_rcu(tunnel46_handlers, << 
153                 if (!handler->err_handler(skb, << 
154                         break;                 << 
155 }                                              << 
156                                                << 
157 static const struct inet6_protocol tunnel6_pro    150 static const struct inet6_protocol tunnel6_protocol = {
158         .handler        = tunnel6_rcv,            151         .handler        = tunnel6_rcv,
159         .err_handler    = tunnel6_err,            152         .err_handler    = tunnel6_err,
160         .flags          = INET6_PROTO_NOPOLICY    153         .flags          = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
161 };                                                154 };
162                                                   155 
163 static const struct inet6_protocol tunnel46_pr    156 static const struct inet6_protocol tunnel46_protocol = {
164         .handler        = tunnel46_rcv,           157         .handler        = tunnel46_rcv,
165         .err_handler    = tunnel46_err,        !! 158         .err_handler    = tunnel6_err,
166         .flags          = INET6_PROTO_NOPOLICY    159         .flags          = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
167 };                                                160 };
168                                                   161 
169 static int __init tunnel6_init(void)              162 static int __init tunnel6_init(void)
170 {                                                 163 {
171         if (inet6_add_protocol(&tunnel6_protoc    164         if (inet6_add_protocol(&tunnel6_protocol, IPPROTO_IPV6)) {
172                 pr_err("%s: can't add protocol    165                 pr_err("%s: can't add protocol\n", __func__);
173                 return -EAGAIN;                   166                 return -EAGAIN;
174         }                                         167         }
175         if (inet6_add_protocol(&tunnel46_proto    168         if (inet6_add_protocol(&tunnel46_protocol, IPPROTO_IPIP)) {
176                 pr_err("%s: can't add protocol    169                 pr_err("%s: can't add protocol\n", __func__);
177                 inet6_del_protocol(&tunnel6_pr    170                 inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6);
178                 return -EAGAIN;                   171                 return -EAGAIN;
179         }                                         172         }
180         return 0;                                 173         return 0;
181 }                                                 174 }
182                                                   175 
183 static void __exit tunnel6_fini(void)             176 static void __exit tunnel6_fini(void)
184 {                                                 177 {
185         if (inet6_del_protocol(&tunnel46_proto    178         if (inet6_del_protocol(&tunnel46_protocol, IPPROTO_IPIP))
186                 pr_err("%s: can't remove proto    179                 pr_err("%s: can't remove protocol\n", __func__);
187         if (inet6_del_protocol(&tunnel6_protoc    180         if (inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6))
188                 pr_err("%s: can't remove proto    181                 pr_err("%s: can't remove protocol\n", __func__);
189 }                                                 182 }
190                                                   183 
191 module_init(tunnel6_init);                        184 module_init(tunnel6_init);
192 module_exit(tunnel6_fini);                        185 module_exit(tunnel6_fini);
193 MODULE_LICENSE("GPL");                            186 MODULE_LICENSE("GPL");
194                                                   187 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp