1/* $NetBSD: if_gre.c,v 1.49 2003/12/11 00:22:29 itojun Exp $ */
2/* $FreeBSD: head/sys/net/if_gre.c 147643 2005-06-28 06:55:45Z bz $ */
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 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
--- 15 unchanged lines hidden (view full) ---
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40/*
41 * Encapsulate L3 protocols into IP
42 * See RFC 1701 and 1702 for more details.
43 * If_gre is compatible with Cisco GRE tunnels, so you can
44 * have a NetBSD box as the other end of a tunnel interface of a Cisco
45 * router. See gre(4) for more details.
46 * Also supported: IP in IP encaps (proto 55) as of RFC 2004
47 */
48
49#include "opt_atalk.h"
50#include "opt_inet.h"
--- 181 unchanged lines hidden (view full) ---
232static int
233gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
234 struct rtentry *rt)
235{
236 int error = 0;
237 struct gre_softc *sc = ifp->if_softc;
238 struct greip *gh;
239 struct ip *ip;
240 u_int16_t etype = 0;
241 struct mobile_h mob_h;
242 u_int32_t af;
243
244 /*
245 * gre may cause infinite recursion calls when misconfigured.
246 * We'll prevent this by introducing upper limit.
247 */
--- 99 unchanged lines hidden (view full) ---
347 m_freem(m);
348 error = EINVAL;
349 goto end;
350 }
351 } else if (sc->g_proto == IPPROTO_GRE) {
352 switch (dst->sa_family) {
353 case AF_INET:
354 ip = mtod(m, struct ip *);
355 etype = ETHERTYPE_IP;
356 break;
357#ifdef NETATALK
358 case AF_APPLETALK:
359 etype = ETHERTYPE_ATALK;
360 break;
361#endif
362 default:
363 _IF_DROP(&ifp->if_snd);
364 m_freem(m);
--- 23 unchanged lines hidden (view full) ---
388
389 gh->gi_pr = sc->g_proto;
390 if (sc->g_proto != IPPROTO_MOBILE) {
391 gh->gi_src = sc->g_src;
392 gh->gi_dst = sc->g_dst;
393 ((struct ip*)gh)->ip_v = IPPROTO_IPV4;
394 ((struct ip*)gh)->ip_hl = (sizeof(struct ip)) >> 2;
395 ((struct ip*)gh)->ip_ttl = GRE_TTL;
396 ((struct ip*)gh)->ip_tos = ip->ip_tos;
397 ((struct ip*)gh)->ip_id = ip->ip_id;
398 gh->gi_len = m->m_pkthdr.len;
399 }
400
401 ifp->if_opackets++;
402 ifp->if_obytes += m->m_pkthdr.len;
403 /*
404 * Send it off and with IP_FORWARD flag to prevent it from
405 * overwriting the ip_id again. ip_id is already set to the
--- 62 unchanged lines hidden (view full) ---
468 error = EAFNOSUPPORT;
469 break;
470 }
471 switch (ifr->ifr_addr.sa_family) {
472#ifdef INET
473 case AF_INET:
474 break;
475#endif
476 default:
477 error = EAFNOSUPPORT;
478 break;
479 }
480 break;
481 case GRESPROTO:
482 if ((error = suser(curthread)) != 0)
483 break;
--- 315 unchanged lines hidden ---
2/* $FreeBSD: head/sys/net/if_gre.c 147643 2005-06-28 06:55:45Z bz $ */
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 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
--- 15 unchanged lines hidden (view full) ---
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40/*
41 * Encapsulate L3 protocols into IP
42 * See RFC 1701 and 1702 for more details.
43 * If_gre is compatible with Cisco GRE tunnels, so you can
44 * have a NetBSD box as the other end of a tunnel interface of a Cisco
45 * router. See gre(4) for more details.
46 * Also supported: IP in IP encaps (proto 55) as of RFC 2004
47 */
48
49#include "opt_atalk.h"
50#include "opt_inet.h"
--- 181 unchanged lines hidden (view full) ---
232static int
233gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
234 struct rtentry *rt)
235{
236 int error = 0;
237 struct gre_softc *sc = ifp->if_softc;
238 struct greip *gh;
239 struct ip *ip;
240 u_int16_t etype = 0;
241 struct mobile_h mob_h;
242 u_int32_t af;
243
244 /*
245 * gre may cause infinite recursion calls when misconfigured.
246 * We'll prevent this by introducing upper limit.
247 */
--- 99 unchanged lines hidden (view full) ---
347 m_freem(m);
348 error = EINVAL;
349 goto end;
350 }
351 } else if (sc->g_proto == IPPROTO_GRE) {
352 switch (dst->sa_family) {
353 case AF_INET:
354 ip = mtod(m, struct ip *);
355 etype = ETHERTYPE_IP;
356 break;
357#ifdef NETATALK
358 case AF_APPLETALK:
359 etype = ETHERTYPE_ATALK;
360 break;
361#endif
362 default:
363 _IF_DROP(&ifp->if_snd);
364 m_freem(m);
--- 23 unchanged lines hidden (view full) ---
388
389 gh->gi_pr = sc->g_proto;
390 if (sc->g_proto != IPPROTO_MOBILE) {
391 gh->gi_src = sc->g_src;
392 gh->gi_dst = sc->g_dst;
393 ((struct ip*)gh)->ip_v = IPPROTO_IPV4;
394 ((struct ip*)gh)->ip_hl = (sizeof(struct ip)) >> 2;
395 ((struct ip*)gh)->ip_ttl = GRE_TTL;
396 ((struct ip*)gh)->ip_tos = ip->ip_tos;
397 ((struct ip*)gh)->ip_id = ip->ip_id;
398 gh->gi_len = m->m_pkthdr.len;
399 }
400
401 ifp->if_opackets++;
402 ifp->if_obytes += m->m_pkthdr.len;
403 /*
404 * Send it off and with IP_FORWARD flag to prevent it from
405 * overwriting the ip_id again. ip_id is already set to the
--- 62 unchanged lines hidden (view full) ---
468 error = EAFNOSUPPORT;
469 break;
470 }
471 switch (ifr->ifr_addr.sa_family) {
472#ifdef INET
473 case AF_INET:
474 break;
475#endif
476 default:
477 error = EAFNOSUPPORT;
478 break;
479 }
480 break;
481 case GRESPROTO:
482 if ((error = suser(curthread)) != 0)
483 break;
--- 315 unchanged lines hidden ---