Deleted Added
full compact
if_gre.c (103026) if_gre.c (103032)
1/* $NetBSD: if_gre.c,v 1.42 2002/08/14 00:23:27 itojun Exp $ */
1/* $NetBSD: if_gre.c,v 1.42 2002/08/14 00:23:27 itojun Exp $ */
2/* $FreeBSD: head/sys/net/if_gre.c 103026 2002-09-06 17:12:50Z sobomax $ */
2/* $FreeBSD: head/sys/net/if_gre.c 103032 2002-09-06 18:16:03Z sobomax $ */
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 *

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

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 <sys/cdefs.h>
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 *

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

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 <sys/cdefs.h>
50__RCSID("@(#) $FreeBSD: head/sys/net/if_gre.c 103026 2002-09-06 17:12:50Z sobomax $");
50__RCSID("@(#) $FreeBSD: head/sys/net/if_gre.c 103032 2002-09-06 18:16:03Z sobomax $");
51
52#include "opt_inet.h"
53#include "opt_ns.h"
54#include "bpf.h"
55
56#include <sys/param.h>
57#include <sys/kernel.h>
58#include <sys/malloc.h>

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

110 */
111#define GREMTU 1476
112
113#define GRENAME "gre"
114
115static MALLOC_DEFINE(M_GRE, GRENAME, "Generic Routing Encapsulation");
116
117struct gre_softc_head gre_softc_list;
51
52#include "opt_inet.h"
53#include "opt_ns.h"
54#include "bpf.h"
55
56#include <sys/param.h>
57#include <sys/kernel.h>
58#include <sys/malloc.h>

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

110 */
111#define GREMTU 1476
112
113#define GRENAME "gre"
114
115static MALLOC_DEFINE(M_GRE, GRENAME, "Generic Routing Encapsulation");
116
117struct gre_softc_head gre_softc_list;
118int ip_gre_ttl = GRE_TTL;
119
118
120int gre_clone_create __P((struct if_clone *, int));
121void gre_clone_destroy __P((struct ifnet *));
119static int gre_clone_create __P((struct if_clone *, int));
120static void gre_clone_destroy __P((struct ifnet *));
121static int gre_ioctl(struct ifnet *, u_long, caddr_t);
122static int gre_output(struct ifnet *, struct mbuf *, struct sockaddr *,
123 struct rtentry *rt);
122
124
123struct if_clone gre_cloner =
125static struct if_clone gre_cloner =
124 IF_CLONE_INITIALIZER("gre", gre_clone_create, gre_clone_destroy, 0, IF_MAXUNIT);
125
126 IF_CLONE_INITIALIZER("gre", gre_clone_create, gre_clone_destroy, 0, IF_MAXUNIT);
127
126int gre_compute_route(struct gre_softc *sc);
128static int gre_compute_route(struct gre_softc *sc);
127
129
128void greattach __P((void));
130static void greattach __P((void));
129
130#ifdef INET
131extern struct domain inetdomain;
132static const struct protosw in_gre_protosw =
133{ SOCK_RAW, &inetdomain, IPPROTO_GRE, PR_ATOMIC|PR_ADDR,
134 (pr_input_t*)gre_input, (pr_output_t*)rip_output, rip_ctlinput, rip_ctloutput,
135 0,
136 0, 0, 0, 0,

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

159 */
160#define MAX_GRE_NEST 1
161#endif
162static int max_gre_nesting = MAX_GRE_NEST;
163SYSCTL_INT(_net_link_gre, OID_AUTO, max_nesting, CTLFLAG_RW,
164 &max_gre_nesting, 0, "Max nested tunnels");
165
166/* ARGSUSED */
131
132#ifdef INET
133extern struct domain inetdomain;
134static const struct protosw in_gre_protosw =
135{ SOCK_RAW, &inetdomain, IPPROTO_GRE, PR_ATOMIC|PR_ADDR,
136 (pr_input_t*)gre_input, (pr_output_t*)rip_output, rip_ctlinput, rip_ctloutput,
137 0,
138 0, 0, 0, 0,

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

161 */
162#define MAX_GRE_NEST 1
163#endif
164static int max_gre_nesting = MAX_GRE_NEST;
165SYSCTL_INT(_net_link_gre, OID_AUTO, max_nesting, CTLFLAG_RW,
166 &max_gre_nesting, 0, "Max nested tunnels");
167
168/* ARGSUSED */
167void
169static void
168greattach(void)
169{
170
171 LIST_INIT(&gre_softc_list);
172 if_clone_attach(&gre_cloner);
173}
174
170greattach(void)
171{
172
173 LIST_INIT(&gre_softc_list);
174 if_clone_attach(&gre_cloner);
175}
176
175int
177static int
176gre_clone_create(ifc, unit)
177 struct if_clone *ifc;
178 int unit;
179{
180 struct gre_softc *sc;
181
182 sc = malloc(sizeof(struct gre_softc), M_GRE, M_WAITOK);
183 memset(sc, 0, sizeof(struct gre_softc));

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

201 if_attach(&sc->sc_if);
202#if NBPF
203 bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int32_t));
204#endif
205 LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list);
206 return (0);
207}
208
178gre_clone_create(ifc, unit)
179 struct if_clone *ifc;
180 int unit;
181{
182 struct gre_softc *sc;
183
184 sc = malloc(sizeof(struct gre_softc), M_GRE, M_WAITOK);
185 memset(sc, 0, sizeof(struct gre_softc));

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

203 if_attach(&sc->sc_if);
204#if NBPF
205 bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int32_t));
206#endif
207 LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list);
208 return (0);
209}
210
209void
211static void
210gre_clone_destroy(ifp)
211 struct ifnet *ifp;
212{
213 struct gre_softc *sc = ifp->if_softc;
214
215#ifdef INET
216 if (sc->encap != NULL)
217 encap_detach(sc->encap);

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

223 if_detach(ifp);
224 free(sc, M_GRE);
225}
226
227/*
228 * The output routine. Takes a packet and encapsulates it in the protocol
229 * given by sc->g_proto. See also RFC 1701 and RFC 2004
230 */
212gre_clone_destroy(ifp)
213 struct ifnet *ifp;
214{
215 struct gre_softc *sc = ifp->if_softc;
216
217#ifdef INET
218 if (sc->encap != NULL)
219 encap_detach(sc->encap);

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

225 if_detach(ifp);
226 free(sc, M_GRE);
227}
228
229/*
230 * The output routine. Takes a packet and encapsulates it in the protocol
231 * given by sc->g_proto. See also RFC 1701 and RFC 2004
232 */
231int
233static int
232gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
233 struct rtentry *rt)
234{
235 int error = 0;
236 struct gre_softc *sc = ifp->if_softc;
237 struct greip *gh;
238 struct ip *ip;
239 u_char osrc;

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

395 gh->gi_ptype = htons(etype);
396 }
397
398 gh->gi_pr = sc->g_proto;
399 if (sc->g_proto != IPPROTO_MOBILE) {
400 gh->gi_src = sc->g_src;
401 gh->gi_dst = sc->g_dst;
402 ((struct ip*)gh)->ip_hl = (sizeof(struct ip)) >> 2;
234gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
235 struct rtentry *rt)
236{
237 int error = 0;
238 struct gre_softc *sc = ifp->if_softc;
239 struct greip *gh;
240 struct ip *ip;
241 u_char osrc;

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

397 gh->gi_ptype = htons(etype);
398 }
399
400 gh->gi_pr = sc->g_proto;
401 if (sc->g_proto != IPPROTO_MOBILE) {
402 gh->gi_src = sc->g_src;
403 gh->gi_dst = sc->g_dst;
404 ((struct ip*)gh)->ip_hl = (sizeof(struct ip)) >> 2;
403 ((struct ip*)gh)->ip_ttl = ip_gre_ttl;
405 ((struct ip*)gh)->ip_ttl = GRE_TTL;
404 ((struct ip*)gh)->ip_tos = ip->ip_tos;
405 ((struct ip*)gh)->ip_id = ip->ip_id;
406 gh->gi_len = m->m_pkthdr.len;
407 }
408
409 ifp->if_opackets++;
410 ifp->if_obytes += m->m_pkthdr.len;
411 /* send it off */
412 error = ip_output(m, NULL, &sc->route, 0, NULL);
413 end:
414 sc->called = 0;
415 if (error)
416 ifp->if_oerrors++;
417 return (error);
418}
419
406 ((struct ip*)gh)->ip_tos = ip->ip_tos;
407 ((struct ip*)gh)->ip_id = ip->ip_id;
408 gh->gi_len = m->m_pkthdr.len;
409 }
410
411 ifp->if_opackets++;
412 ifp->if_obytes += m->m_pkthdr.len;
413 /* send it off */
414 error = ip_output(m, NULL, &sc->route, 0, NULL);
415 end:
416 sc->called = 0;
417 if (error)
418 ifp->if_oerrors++;
419 return (error);
420}
421
420int
422static int
421gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
422{
423 struct ifreq *ifr = (struct ifreq *)data;
424 struct if_laddrreq *lifr = (struct if_laddrreq *)data;
425 struct in_aliasreq *aifr = (struct in_aliasreq *)data;
426 struct gre_softc *sc = ifp->if_softc;
427 int s;
428 struct sockaddr_in si;

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

653 * us. If the interface is p2p as a--->b, then a routing entry exists
654 * If we now send a packet to b (e.g. ping b), this will come down here
655 * gets src=a, dst=b tacked on and would from ip_ouput() sent back to
656 * if_gre.
657 * Goal here is to compute a route to b that is less specific than
658 * a-->b. We know that this one exists as in normal operation we have
659 * at least a default route which matches.
660 */
423gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
424{
425 struct ifreq *ifr = (struct ifreq *)data;
426 struct if_laddrreq *lifr = (struct if_laddrreq *)data;
427 struct in_aliasreq *aifr = (struct in_aliasreq *)data;
428 struct gre_softc *sc = ifp->if_softc;
429 int s;
430 struct sockaddr_in si;

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

655 * us. If the interface is p2p as a--->b, then a routing entry exists
656 * If we now send a packet to b (e.g. ping b), this will come down here
657 * gets src=a, dst=b tacked on and would from ip_ouput() sent back to
658 * if_gre.
659 * Goal here is to compute a route to b that is less specific than
660 * a-->b. We know that this one exists as in normal operation we have
661 * at least a default route which matches.
662 */
661int
663static int
662gre_compute_route(struct gre_softc *sc)
663{
664 struct route *ro;
665 u_int32_t a, b, c;
666
667 ro = &sc->route;
668
669 memset(ro, 0, sizeof(struct route));

--- 112 unchanged lines hidden ---
664gre_compute_route(struct gre_softc *sc)
665{
666 struct route *ro;
667 u_int32_t a, b, c;
668
669 ro = &sc->route;
670
671 memset(ro, 0, sizeof(struct route));

--- 112 unchanged lines hidden ---