in6_gif.c (54263) | in6_gif.c (55009) |
---|---|
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 --- 12 unchanged lines hidden (view full) --- 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 * | 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 --- 12 unchanged lines hidden (view full) --- 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 * $FreeBSD: head/sys/netinet6/in6_gif.c 54263 1999-12-07 17:39:16Z shin $ | 29 * $FreeBSD: head/sys/netinet6/in6_gif.c 55009 1999-12-22 19:13:38Z shin $ |
30 */ 31 32/* 33 * in6_gif.c 34 */ 35 36#include "opt_inet.h" 37 --- 12 unchanged lines hidden (view full) --- 50#include <netinet/in_systm.h> 51#ifdef INET 52#include <netinet/ip.h> 53#endif 54#include <netinet6/ip6.h> 55#include <netinet6/ip6_var.h> 56#include <netinet6/in6_gif.h> 57#include <netinet6/ip6.h> | 30 */ 31 32/* 33 * in6_gif.c 34 */ 35 36#include "opt_inet.h" 37 --- 12 unchanged lines hidden (view full) --- 50#include <netinet/in_systm.h> 51#ifdef INET 52#include <netinet/ip.h> 53#endif 54#include <netinet6/ip6.h> 55#include <netinet6/ip6_var.h> 56#include <netinet6/in6_gif.h> 57#include <netinet6/ip6.h> |
58#include <netinet/ip_ecn.h> 59#include <netinet6/ip6_ecn.h> |
|
58 59#include <net/if_gif.h> 60 61#include <net/net_osdep.h> 62 63int 64in6_gif_output(ifp, family, m, rt) 65 struct ifnet *ifp; 66 int family; /* family of the packet to be encapsulate. */ 67 struct mbuf *m; 68 struct rtentry *rt; 69{ 70 struct gif_softc *sc = (struct gif_softc*)ifp; 71 struct sockaddr_in6 *dst = (struct sockaddr_in6 *)&sc->gif_ro6.ro_dst; 72 struct sockaddr_in6 *sin6_src = (struct sockaddr_in6 *)sc->gif_psrc; 73 struct sockaddr_in6 *sin6_dst = (struct sockaddr_in6 *)sc->gif_pdst; 74 struct ip6_hdr *ip6; 75 int proto; | 60 61#include <net/if_gif.h> 62 63#include <net/net_osdep.h> 64 65int 66in6_gif_output(ifp, family, m, rt) 67 struct ifnet *ifp; 68 int family; /* family of the packet to be encapsulate. */ 69 struct mbuf *m; 70 struct rtentry *rt; 71{ 72 struct gif_softc *sc = (struct gif_softc*)ifp; 73 struct sockaddr_in6 *dst = (struct sockaddr_in6 *)&sc->gif_ro6.ro_dst; 74 struct sockaddr_in6 *sin6_src = (struct sockaddr_in6 *)sc->gif_psrc; 75 struct sockaddr_in6 *sin6_dst = (struct sockaddr_in6 *)sc->gif_pdst; 76 struct ip6_hdr *ip6; 77 int proto; |
78 u_int8_t itos, otos; |
|
76 77 if (sin6_src == NULL || sin6_dst == NULL || 78 sin6_src->sin6_family != AF_INET6 || 79 sin6_dst->sin6_family != AF_INET6) { 80 m_freem(m); 81 return EAFNOSUPPORT; 82 } 83 --- 5 unchanged lines hidden (view full) --- 89 90 proto = IPPROTO_IPV4; 91 if (m->m_len < sizeof(*ip)) { 92 m = m_pullup(m, sizeof(*ip)); 93 if (!m) 94 return ENOBUFS; 95 } 96 ip = mtod(m, struct ip *); | 79 80 if (sin6_src == NULL || sin6_dst == NULL || 81 sin6_src->sin6_family != AF_INET6 || 82 sin6_dst->sin6_family != AF_INET6) { 83 m_freem(m); 84 return EAFNOSUPPORT; 85 } 86 --- 5 unchanged lines hidden (view full) --- 92 93 proto = IPPROTO_IPV4; 94 if (m->m_len < sizeof(*ip)) { 95 m = m_pullup(m, sizeof(*ip)); 96 if (!m) 97 return ENOBUFS; 98 } 99 ip = mtod(m, struct ip *); |
100 itos = ip->ip_tos; |
|
97 break; 98 } 99#endif 100 case AF_INET6: 101 { 102 struct ip6_hdr *ip6; 103 proto = IPPROTO_IPV6; 104 if (m->m_len < sizeof(*ip6)) { 105 m = m_pullup(m, sizeof(*ip6)); 106 if (!m) 107 return ENOBUFS; 108 } 109 ip6 = mtod(m, struct ip6_hdr *); | 101 break; 102 } 103#endif 104 case AF_INET6: 105 { 106 struct ip6_hdr *ip6; 107 proto = IPPROTO_IPV6; 108 if (m->m_len < sizeof(*ip6)) { 109 m = m_pullup(m, sizeof(*ip6)); 110 if (!m) 111 return ENOBUFS; 112 } 113 ip6 = mtod(m, struct ip6_hdr *); |
114 itos = (ntohl(ip6->ip6_flow) >> 20) & 0xff; |
|
110 break; 111 } 112 default: 113#ifdef DIAGNOSTIC 114 printf("in6_gif_output: warning: unknown family %d passed\n", 115 family); 116#endif 117 m_freem(m); --- 30 unchanged lines hidden (view full) --- 148 /* bidirectional configured tunnel mode */ 149 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6_dst->sin6_addr)) 150 ip6->ip6_dst = sin6_dst->sin6_addr; 151 else { 152 m_freem(m); 153 return ENETUNREACH; 154 } 155 } | 115 break; 116 } 117 default: 118#ifdef DIAGNOSTIC 119 printf("in6_gif_output: warning: unknown family %d passed\n", 120 family); 121#endif 122 m_freem(m); --- 30 unchanged lines hidden (view full) --- 153 /* bidirectional configured tunnel mode */ 154 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6_dst->sin6_addr)) 155 ip6->ip6_dst = sin6_dst->sin6_addr; 156 else { 157 m_freem(m); 158 return ENETUNREACH; 159 } 160 } |
161 if (ifp->if_flags & IFF_LINK1) { 162 otos = 0; 163 ip_ecn_ingress(ECN_ALLOWED, &otos, &itos); 164 ip6->ip6_flow |= htonl((u_int32_t)otos << 20); 165 } |
|
156 157 if (dst->sin6_family != sin6_dst->sin6_family || 158 !IN6_ARE_ADDR_EQUAL(&dst->sin6_addr, &sin6_dst->sin6_addr)) { 159 /* cache route doesn't match */ 160 bzero(dst, sizeof(*dst)); 161 dst->sin6_family = sin6_dst->sin6_family; 162 dst->sin6_len = sizeof(struct sockaddr_in6); 163 dst->sin6_addr = sin6_dst->sin6_addr; --- 6 unchanged lines hidden (view full) --- 170 if (sc->gif_ro6.ro_rt == NULL) { 171 rtalloc((struct route *)&sc->gif_ro6); 172 if (sc->gif_ro6.ro_rt == NULL) { 173 m_freem(m); 174 return ENETUNREACH; 175 } 176 } 177 | 166 167 if (dst->sin6_family != sin6_dst->sin6_family || 168 !IN6_ARE_ADDR_EQUAL(&dst->sin6_addr, &sin6_dst->sin6_addr)) { 169 /* cache route doesn't match */ 170 bzero(dst, sizeof(*dst)); 171 dst->sin6_family = sin6_dst->sin6_family; 172 dst->sin6_len = sizeof(struct sockaddr_in6); 173 dst->sin6_addr = sin6_dst->sin6_addr; --- 6 unchanged lines hidden (view full) --- 180 if (sc->gif_ro6.ro_rt == NULL) { 181 rtalloc((struct route *)&sc->gif_ro6); 182 if (sc->gif_ro6.ro_rt == NULL) { 183 m_freem(m); 184 return ENETUNREACH; 185 } 186 } 187 |
178#ifdef IPSEC 179 m->m_pkthdr.rcvif = NULL; 180#endif /*IPSEC*/ | |
181 return(ip6_output(m, 0, &sc->gif_ro6, 0, 0, NULL)); 182} 183 184int in6_gif_input(mp, offp, proto) 185 struct mbuf **mp; 186 int *offp, proto; 187{ 188 struct mbuf *m = *mp; 189 struct gif_softc *sc; 190 struct ifnet *gifp = NULL; 191 struct ip6_hdr *ip6; 192 int i; 193 int af = 0; | 188 return(ip6_output(m, 0, &sc->gif_ro6, 0, 0, NULL)); 189} 190 191int in6_gif_input(mp, offp, proto) 192 struct mbuf **mp; 193 int *offp, proto; 194{ 195 struct mbuf *m = *mp; 196 struct gif_softc *sc; 197 struct ifnet *gifp = NULL; 198 struct ip6_hdr *ip6; 199 int i; 200 int af = 0; |
201 u_int32_t otos; |
|
194 195 ip6 = mtod(m, struct ip6_hdr *); 196 197#define satoin6(sa) (((struct sockaddr_in6 *)(sa))->sin6_addr) 198 for (i = 0, sc = gif; i < ngif; i++, sc++) { 199 if (sc->gif_psrc == NULL || 200 sc->gif_pdst == NULL || 201 sc->gif_psrc->sa_family != AF_INET6 || --- 15 unchanged lines hidden (view full) --- 217 } 218 } 219 220 if (gifp == NULL) { 221 m_freem(m); 222 ip6stat.ip6s_nogif++; 223 return IPPROTO_DONE; 224 } | 202 203 ip6 = mtod(m, struct ip6_hdr *); 204 205#define satoin6(sa) (((struct sockaddr_in6 *)(sa))->sin6_addr) 206 for (i = 0, sc = gif; i < ngif; i++, sc++) { 207 if (sc->gif_psrc == NULL || 208 sc->gif_pdst == NULL || 209 sc->gif_psrc->sa_family != AF_INET6 || --- 15 unchanged lines hidden (view full) --- 225 } 226 } 227 228 if (gifp == NULL) { 229 m_freem(m); 230 ip6stat.ip6s_nogif++; 231 return IPPROTO_DONE; 232 } |
225 | 233 234 otos = ip6->ip6_flow; |
226 m_adj(m, *offp); 227 228 switch (proto) { 229#ifdef INET 230 case IPPROTO_IPV4: 231 { 232 struct ip *ip; | 235 m_adj(m, *offp); 236 237 switch (proto) { 238#ifdef INET 239 case IPPROTO_IPV4: 240 { 241 struct ip *ip; |
242 u_int8_t otos8; |
|
233 af = AF_INET; | 243 af = AF_INET; |
244 otos8 = (ntohl(otos) >> 20) & 0xff; |
|
234 if (m->m_len < sizeof(*ip)) { 235 m = m_pullup(m, sizeof(*ip)); 236 if (!m) 237 return IPPROTO_DONE; 238 } 239 ip = mtod(m, struct ip *); | 245 if (m->m_len < sizeof(*ip)) { 246 m = m_pullup(m, sizeof(*ip)); 247 if (!m) 248 return IPPROTO_DONE; 249 } 250 ip = mtod(m, struct ip *); |
251 if (gifp->if_flags & IFF_LINK1) 252 ip_ecn_egress(ECN_ALLOWED, &otos8, &ip->ip_tos); |
|
240 break; 241 } 242#endif /* INET */ 243 case IPPROTO_IPV6: 244 { 245 struct ip6_hdr *ip6; 246 af = AF_INET6; 247 if (m->m_len < sizeof(*ip6)) { 248 m = m_pullup(m, sizeof(*ip6)); 249 if (!m) 250 return IPPROTO_DONE; 251 } 252 ip6 = mtod(m, struct ip6_hdr *); | 253 break; 254 } 255#endif /* INET */ 256 case IPPROTO_IPV6: 257 { 258 struct ip6_hdr *ip6; 259 af = AF_INET6; 260 if (m->m_len < sizeof(*ip6)) { 261 m = m_pullup(m, sizeof(*ip6)); 262 if (!m) 263 return IPPROTO_DONE; 264 } 265 ip6 = mtod(m, struct ip6_hdr *); |
266 if (gifp->if_flags & IFF_LINK1) 267 ip6_ecn_egress(ECN_ALLOWED, &otos, &ip6->ip6_flow); |
|
253 break; 254 } 255 default: 256 ip6stat.ip6s_nogif++; 257 m_freem(m); 258 return IPPROTO_DONE; 259 } 260 261 gif_input(m, af, gifp); 262 return IPPROTO_DONE; 263} | 268 break; 269 } 270 default: 271 ip6stat.ip6s_nogif++; 272 m_freem(m); 273 return IPPROTO_DONE; 274 } 275 276 gif_input(m, af, gifp); 277 return IPPROTO_DONE; 278} |