[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]

FreeBSD/Linux Kernel Cross Reference
sys/netinet6/route6.c

Version: -  FREEBSD  -  FREEBSD7  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  OPENSOLARIS  -  minix-3-1-1  -  TRUSTEDBSD-SEBSD  -  FREEBSD-LIBC  -  FREEBSD7-LIBC  -  FREEBSD6-LIBC  -  GLIBC27 
SearchContext: -  none  -  excerpts  -  bigexcerpts 

  1 /*-
  2  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  3  * All rights reserved.
  4  *
  5  * Redistribution and use in source and binary forms, with or without
  6  * modification, are permitted provided that the following conditions
  7  * are met:
  8  * 1. Redistributions of source code must retain the above copyright
  9  *    notice, this list of conditions and the following disclaimer.
 10  * 2. Redistributions in binary form must reproduce the above copyright
 11  *    notice, this list of conditions and the following disclaimer in the
 12  *    documentation and/or other materials provided with the distribution.
 13  * 3. Neither the name of the project nor the names of its contributors
 14  *    may be used to endorse or promote products derived from this software
 15  *    without specific prior written permission.
 16  *
 17  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
 18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
 21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 27  * SUCH DAMAGE.
 28  *
 29  *      $KAME: route6.c,v 1.24 2001/03/14 03:07:05 itojun Exp $
 30  */
 31 
 32 #include <sys/cdefs.h>
 33 __FBSDID("$FreeBSD: src/sys/netinet6/route6.c,v 1.18 2008/12/02 21:37:28 bz Exp $");
 34 
 35 #include "opt_inet.h"
 36 #include "opt_inet6.h"
 37 
 38 #include <sys/param.h>
 39 #include <sys/mbuf.h>
 40 #include <sys/socket.h>
 41 #include <sys/systm.h>
 42 #include <sys/queue.h>
 43 #include <sys/vimage.h>
 44 
 45 #include <net/if.h>
 46 
 47 #include <netinet/in.h>
 48 #include <netinet6/in6_var.h>
 49 #include <netinet/ip6.h>
 50 #include <netinet6/ip6_var.h>
 51 #include <netinet6/scope6_var.h>
 52 
 53 #include <netinet/icmp6.h>
 54 #include <netinet6/vinet6.h>
 55 
 56 #if 0
 57 static int ip6_rthdr0 __P((struct mbuf *, struct ip6_hdr *,
 58     struct ip6_rthdr0 *));
 59 
 60 #endif /* Disable route header processing. */
 61 
 62 /*
 63  * proto - is unused
 64  */
 65 
 66 int
 67 route6_input(struct mbuf **mp, int *offp, int proto)
 68 {
 69         INIT_VNET_INET6(curvnet);
 70         struct ip6_hdr *ip6;
 71         struct mbuf *m = *mp;
 72         struct ip6_rthdr *rh;
 73         int off = *offp, rhlen;
 74         struct ip6aux *ip6a;
 75 
 76         ip6a = ip6_findaux(m);
 77         if (ip6a) {
 78                 /* XXX reject home-address option before rthdr */
 79                 if (ip6a->ip6a_flags & IP6A_SWAP) {
 80                         V_ip6stat.ip6s_badoptions++;
 81                         m_freem(m);
 82                         return IPPROTO_DONE;
 83                 }
 84         }
 85 
 86 #ifndef PULLDOWN_TEST
 87         IP6_EXTHDR_CHECK(m, off, sizeof(*rh), IPPROTO_DONE);
 88         ip6 = mtod(m, struct ip6_hdr *);
 89         rh = (struct ip6_rthdr *)((caddr_t)ip6 + off);
 90 #else
 91         ip6 = mtod(m, struct ip6_hdr *);
 92         IP6_EXTHDR_GET(rh, struct ip6_rthdr *, m, off, sizeof(*rh));
 93         if (rh == NULL) {
 94                 V_ip6stat.ip6s_tooshort++;
 95                 return IPPROTO_DONE;
 96         }
 97 #endif
 98 
 99         switch (rh->ip6r_type) {
100 #if 0
101         case IPV6_RTHDR_TYPE_0:
102                 rhlen = (rh->ip6r_len + 1) << 3;
103 #ifndef PULLDOWN_TEST
104                 /*
105                  * note on option length:
106                  * due to IP6_EXTHDR_CHECK assumption, we cannot handle
107                  * very big routing header (max rhlen == 2048).
108                  */
109                 IP6_EXTHDR_CHECK(m, off, rhlen, IPPROTO_DONE);
110 #else
111                 /*
112                  * note on option length:
113                  * maximum rhlen: 2048
114                  * max mbuf m_pulldown can handle: MCLBYTES == usually 2048
115                  * so, here we are assuming that m_pulldown can handle
116                  * rhlen == 2048 case.  this may not be a good thing to
117                  * assume - we may want to avoid pulling it up altogether.
118                  */
119                 IP6_EXTHDR_GET(rh, struct ip6_rthdr *, m, off, rhlen);
120                 if (rh == NULL) {
121                         V_ip6stat.ip6s_tooshort++;
122                         return IPPROTO_DONE;
123                 }
124 #endif
125                 if (ip6_rthdr0(m, ip6, (struct ip6_rthdr0 *)rh))
126                         return (IPPROTO_DONE);
127                 break;
128 #endif /* Disable route header 0 */
129         default:
130                 /* unknown routing type */
131                 if (rh->ip6r_segleft == 0) {
132                         rhlen = (rh->ip6r_len + 1) << 3;
133                         break;  /* Final dst. Just ignore the header. */
134                 }
135                 V_ip6stat.ip6s_badoptions++;
136                 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
137                             (caddr_t)&rh->ip6r_type - (caddr_t)ip6);
138                 return (IPPROTO_DONE);
139         }
140 
141         *offp += rhlen;
142         return (rh->ip6r_nxt);
143 }
144 
145 /*
146  * Type0 routing header processing
147  *
148  * RFC2292 backward compatibility warning: no support for strict/loose bitmap,
149  * as it was dropped between RFC1883 and RFC2460.
150  */
151 #if 0
152 static int
153 ip6_rthdr0(struct mbuf *m, struct ip6_hdr *ip6, struct ip6_rthdr0 *rh0)
154 {
155         INIT_VNET_INET6(curvnet);
156         int addrs, index;
157         struct in6_addr *nextaddr, tmpaddr;
158         struct in6_ifaddr *ifa;
159 
160         if (rh0->ip6r0_segleft == 0)
161                 return (0);
162 
163         if (rh0->ip6r0_len % 2
164 #ifdef COMPAT_RFC1883
165             || rh0->ip6r0_len > 46
166 #endif
167                 ) {
168                 /*
169                  * Type 0 routing header can't contain more than 23 addresses.
170                  * RFC 2462: this limitation was removed since strict/loose
171                  * bitmap field was deleted.
172                  */
173                 V_ip6stat.ip6s_badoptions++;
174                 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
175                             (caddr_t)&rh0->ip6r0_len - (caddr_t)ip6);
176                 return (-1);
177         }
178 
179         if ((addrs = rh0->ip6r0_len / 2) < rh0->ip6r0_segleft) {
180                 V_ip6stat.ip6s_badoptions++;
181                 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
182                             (caddr_t)&rh0->ip6r0_segleft - (caddr_t)ip6);
183                 return (-1);
184         }
185 
186         index = addrs - rh0->ip6r0_segleft;
187         rh0->ip6r0_segleft--;
188         nextaddr = ((struct in6_addr *)(rh0 + 1)) + index;
189 
190         /*
191          * reject invalid addresses.  be proactive about malicious use of
192          * IPv4 mapped/compat address.
193          * XXX need more checks?
194          */
195         if (IN6_IS_ADDR_MULTICAST(nextaddr) ||
196             IN6_IS_ADDR_UNSPECIFIED(nextaddr) ||
197             IN6_IS_ADDR_V4MAPPED(nextaddr) ||
198             IN6_IS_ADDR_V4COMPAT(nextaddr)) {
199                 V_ip6stat.ip6s_badoptions++;
200                 m_freem(m);
201                 return (-1);
202         }
203         if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
204             IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_dst) ||
205             IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst) ||
206             IN6_IS_ADDR_V4COMPAT(&ip6->ip6_dst)) {
207                 V_ip6stat.ip6s_badoptions++;
208                 m_freem(m);
209                 return (-1);
210         }
211 
212         /*
213          * Determine the scope zone of the next hop, based on the interface
214          * of the current hop. [RFC4007, Section 9]
215          * Then disambiguate the scope zone for the next hop (if necessary).
216          */
217         if ((ifa = ip6_getdstifaddr(m)) == NULL)
218                 goto bad;
219         if (in6_setscope(nextaddr, ifa->ia_ifp, NULL) != 0) {
220                 V_ip6stat.ip6s_badscope++;
221                 goto bad;
222         }
223 
224         /*
225          * Swap the IPv6 destination address and nextaddr. Forward the packet.
226          */
227         tmpaddr = *nextaddr;
228         *nextaddr = ip6->ip6_dst;
229         in6_clearscope(nextaddr); /* XXX */
230         ip6->ip6_dst = tmpaddr;
231 
232 #ifdef COMPAT_RFC1883
233         if (rh0->ip6r0_slmap[index / 8] & (1 << (7 - (index % 8))))
234                 ip6_forward(m, IPV6_SRCRT_NEIGHBOR);
235         else
236                 ip6_forward(m, IPV6_SRCRT_NOTNEIGHBOR);
237 #else
238         ip6_forward(m, 1);
239 #endif
240 
241         return (-1);                    /* m would be freed in ip6_forward() */
242 
243   bad:
244         m_freem(m);
245         return (-1);
246 }
247 #endif
248 

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.