Deleted Added
sdiff udiff text old ( 219206 ) new ( 223223 )
full compact
1/* $NetBSD: if_gre.c,v 1.49 2003/12/11 00:22:29 itojun Exp $ */
2/* $FreeBSD: head/sys/net/if_gre.c 219206 2011-03-02 21:39:08Z 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 *

--- 32 unchanged lines hidden (view full) ---

43
44#include "opt_atalk.h"
45#include "opt_inet.h"
46#include "opt_inet6.h"
47
48#include <sys/param.h>
49#include <sys/jail.h>
50#include <sys/kernel.h>
51#include <sys/malloc.h>
52#include <sys/module.h>
53#include <sys/mbuf.h>
54#include <sys/priv.h>
55#include <sys/proc.h>
56#include <sys/protosw.h>
57#include <sys/socket.h>
58#include <sys/sockio.h>

--- 27 unchanged lines hidden (view full) ---

86 * It is not easy to calculate the right value for a GRE MTU.
87 * We leave this task to the admin and use the same default that
88 * other vendors use.
89 */
90#define GREMTU 1476
91
92#define GRENAME "gre"
93
94/*
95 * gre_mtx protects all global variables in if_gre.c.
96 * XXX: gre_softc data not protected yet.
97 */
98struct mtx gre_mtx;
99static MALLOC_DEFINE(M_GRE, GRENAME, "Generic Routing Encapsulation");
100
101struct gre_softc_head gre_softc_list;

--- 89 unchanged lines hidden (view full) ---

191 GRE2IFP(sc)->if_mtu = GREMTU;
192 GRE2IFP(sc)->if_flags = IFF_POINTOPOINT|IFF_MULTICAST;
193 GRE2IFP(sc)->if_output = gre_output;
194 GRE2IFP(sc)->if_ioctl = gre_ioctl;
195 sc->g_dst.s_addr = sc->g_src.s_addr = INADDR_ANY;
196 sc->g_proto = IPPROTO_GRE;
197 GRE2IFP(sc)->if_flags |= IFF_LINK0;
198 sc->encap = NULL;
199 sc->called = 0;
200 sc->gre_fibnum = curthread->td_proc->p_fibnum;
201 sc->wccp_ver = WCCP_V1;
202 sc->key = 0;
203 if_attach(GRE2IFP(sc));
204 bpfattach(GRE2IFP(sc), DLT_NULL, sizeof(u_int32_t));
205 mtx_lock(&gre_mtx);
206 LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list);
207 mtx_unlock(&gre_mtx);

--- 27 unchanged lines hidden (view full) ---

235static int
236gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
237 struct route *ro)
238{
239 int error = 0;
240 struct gre_softc *sc = ifp->if_softc;
241 struct greip *gh;
242 struct ip *ip;
243 u_short gre_ip_id = 0;
244 uint8_t gre_ip_tos = 0;
245 u_int16_t etype = 0;
246 struct mobile_h mob_h;
247 u_int32_t af;
248 int extra = 0;
249
250 /*
251 * gre may cause infinite recursion calls when misconfigured.
252 * We'll prevent this by introducing upper limit.
253 */
254 if (++(sc->called) > max_gre_nesting) {
255 printf("%s: gre_output: recursively called too many "
256 "times(%d)\n", if_name(GRE2IFP(sc)), sc->called);
257 m_freem(m);
258 error = EIO; /* is there better errno? */
259 goto end;
260 }
261
262 if (!((ifp->if_flags & IFF_UP) &&
263 (ifp->if_drv_flags & IFF_DRV_RUNNING)) ||
264 sc->g_src.s_addr == INADDR_ANY || sc->g_dst.s_addr == INADDR_ANY) {
265 m_freem(m);
266 error = ENETDOWN;
267 goto end;

--- 171 unchanged lines hidden (view full) ---

439 /*
440 * Send it off and with IP_FORWARD flag to prevent it from
441 * overwriting the ip_id again. ip_id is already set to the
442 * ip_id of the encapsulated packet.
443 */
444 error = ip_output(m, NULL, &sc->route, IP_FORWARDING,
445 (struct ip_moptions *)NULL, (struct inpcb *)NULL);
446 end:
447 sc->called = 0;
448 if (error)
449 ifp->if_oerrors++;
450 return (error);
451}
452
453static int
454gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
455{

--- 464 unchanged lines hidden ---