if_gre.c (180041) | if_gre.c (180639) |
---|---|
1/* $NetBSD: if_gre.c,v 1.49 2003/12/11 00:22:29 itojun Exp $ */ | 1/* $NetBSD: if_gre.c,v 1.49 2003/12/11 00:22:29 itojun Exp $ */ |
2/* $FreeBSD: head/sys/net/if_gre.c 180041 2008-06-26 22:59:49Z julian $ */ | 2/* $FreeBSD: head/sys/net/if_gre.c 180639 2008-07-20 21:45:15Z julian $ */ |
3 4/*- 5 * Copyright (c) 1998 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Heiko W.Rupp <hwr@pilhuhn.de> 10 * --- 234 unchanged lines hidden (view full) --- 245 struct gre_softc *sc = ifp->if_softc; 246 struct greip *gh; 247 struct ip *ip; 248 u_short gre_ip_id = 0; 249 uint8_t gre_ip_tos = 0; 250 u_int16_t etype = 0; 251 struct mobile_h mob_h; 252 u_int32_t af; | 3 4/*- 5 * Copyright (c) 1998 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Heiko W.Rupp <hwr@pilhuhn.de> 10 * --- 234 unchanged lines hidden (view full) --- 245 struct gre_softc *sc = ifp->if_softc; 246 struct greip *gh; 247 struct ip *ip; 248 u_short gre_ip_id = 0; 249 uint8_t gre_ip_tos = 0; 250 u_int16_t etype = 0; 251 struct mobile_h mob_h; 252 u_int32_t af; |
253 int extra = 0; |
|
253 254 /* 255 * gre may cause infinite recursion calls when misconfigured. 256 * We'll prevent this by introducing upper limit. 257 */ 258 if (++(sc->called) > max_gre_nesting) { 259 printf("%s: gre_output: recursively called too many " 260 "times(%d)\n", if_name(GRE2IFP(sc)), sc->called); --- 99 unchanged lines hidden (view full) --- 360 goto end; 361 } 362 } else if (sc->g_proto == IPPROTO_GRE) { 363 switch (dst->sa_family) { 364 case AF_INET: 365 ip = mtod(m, struct ip *); 366 gre_ip_tos = ip->ip_tos; 367 gre_ip_id = ip->ip_id; | 254 255 /* 256 * gre may cause infinite recursion calls when misconfigured. 257 * We'll prevent this by introducing upper limit. 258 */ 259 if (++(sc->called) > max_gre_nesting) { 260 printf("%s: gre_output: recursively called too many " 261 "times(%d)\n", if_name(GRE2IFP(sc)), sc->called); --- 99 unchanged lines hidden (view full) --- 361 goto end; 362 } 363 } else if (sc->g_proto == IPPROTO_GRE) { 364 switch (dst->sa_family) { 365 case AF_INET: 366 ip = mtod(m, struct ip *); 367 gre_ip_tos = ip->ip_tos; 368 gre_ip_id = ip->ip_id; |
368 etype = ETHERTYPE_IP; | 369 if (sc->wccp_ver == WCCP_V2) { 370 extra = sizeof(uint32_t); 371 etype = WCCP_PROTOCOL_TYPE; 372 } else { 373 etype = ETHERTYPE_IP; 374 } |
369 break; 370#ifdef INET6 371 case AF_INET6: 372 gre_ip_id = ip_newid(); 373 etype = ETHERTYPE_IPV6; 374 break; 375#endif 376#ifdef NETATALK --- 4 unchanged lines hidden (view full) --- 381 default: 382 _IF_DROP(&ifp->if_snd); 383 m_freem(m); 384 error = EAFNOSUPPORT; 385 goto end; 386 } 387 388 /* Reserve space for GRE header + optional GRE key */ | 375 break; 376#ifdef INET6 377 case AF_INET6: 378 gre_ip_id = ip_newid(); 379 etype = ETHERTYPE_IPV6; 380 break; 381#endif 382#ifdef NETATALK --- 4 unchanged lines hidden (view full) --- 387 default: 388 _IF_DROP(&ifp->if_snd); 389 m_freem(m); 390 error = EAFNOSUPPORT; 391 goto end; 392 } 393 394 /* Reserve space for GRE header + optional GRE key */ |
389 int hdrlen = sizeof(struct greip); | 395 int hdrlen = sizeof(struct greip) + extra; |
390 if (sc->key) 391 hdrlen += sizeof(uint32_t); 392 M_PREPEND(m, hdrlen, M_DONTWAIT); 393 } else { 394 _IF_DROP(&ifp->if_snd); 395 m_freem(m); 396 error = EINVAL; 397 goto end; --- 6 unchanged lines hidden (view full) --- 404 } 405 406 M_SETFIB(m, sc->gre_fibnum); /* The envelope may use a different FIB */ 407 408 gh = mtod(m, struct greip *); 409 if (sc->g_proto == IPPROTO_GRE) { 410 uint32_t *options = gh->gi_options; 411 | 396 if (sc->key) 397 hdrlen += sizeof(uint32_t); 398 M_PREPEND(m, hdrlen, M_DONTWAIT); 399 } else { 400 _IF_DROP(&ifp->if_snd); 401 m_freem(m); 402 error = EINVAL; 403 goto end; --- 6 unchanged lines hidden (view full) --- 410 } 411 412 M_SETFIB(m, sc->gre_fibnum); /* The envelope may use a different FIB */ 413 414 gh = mtod(m, struct greip *); 415 if (sc->g_proto == IPPROTO_GRE) { 416 uint32_t *options = gh->gi_options; 417 |
412 memset((void *)gh, 0, sizeof(struct greip)); | 418 memset((void *)gh, 0, sizeof(struct greip) + extra); |
413 gh->gi_ptype = htons(etype); 414 gh->gi_flags = 0; 415 416 /* Add key option */ 417 if (sc->key) 418 { 419 gh->gi_flags |= htons(GRE_KP); 420 *(options++) = htonl(sc->key); --- 480 unchanged lines hidden --- | 419 gh->gi_ptype = htons(etype); 420 gh->gi_flags = 0; 421 422 /* Add key option */ 423 if (sc->key) 424 { 425 gh->gi_flags |= htons(GRE_KP); 426 *(options++) = htonl(sc->key); --- 480 unchanged lines hidden --- |