if_gre.c (125226) | if_gre.c (127307) |
---|---|
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 125226 2004-01-30 09:03:01Z sobomax $ */ | 2/* $FreeBSD: head/sys/net/if_gre.c 127307 2004-03-22 16:04:43Z rwatson $ */ |
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 * --- 75 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 | 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 * --- 75 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; |
|
94static MALLOC_DEFINE(M_GRE, GRENAME, "Generic Routing Encapsulation"); 95 96struct gre_softc_head gre_softc_list; 97 98static int gre_clone_create(struct if_clone *, int); 99static void gre_clone_destroy(struct ifnet *); 100static int gre_ioctl(struct ifnet *, u_long, caddr_t); 101static int gre_output(struct ifnet *, struct mbuf *, struct sockaddr *, --- 42 unchanged lines hidden (view full) --- 144SYSCTL_INT(_net_link_gre, OID_AUTO, max_nesting, CTLFLAG_RW, 145 &max_gre_nesting, 0, "Max nested tunnels"); 146 147/* ARGSUSED */ 148static void 149greattach(void) 150{ 151 | 99static MALLOC_DEFINE(M_GRE, GRENAME, "Generic Routing Encapsulation"); 100 101struct gre_softc_head gre_softc_list; 102 103static int gre_clone_create(struct if_clone *, int); 104static void gre_clone_destroy(struct ifnet *); 105static int gre_ioctl(struct ifnet *, u_long, caddr_t); 106static int gre_output(struct ifnet *, struct mbuf *, struct sockaddr *, --- 42 unchanged lines hidden (view full) --- 149SYSCTL_INT(_net_link_gre, OID_AUTO, max_nesting, CTLFLAG_RW, 150 &max_gre_nesting, 0, "Max nested tunnels"); 151 152/* ARGSUSED */ 153static void 154greattach(void) 155{ 156 |
157 mtx_init(&gre_mtx, "gre_mtx", NULL, MTX_DEF); |
|
152 LIST_INIT(&gre_softc_list); 153 if_clone_attach(&gre_cloner); 154} 155 156static int 157gre_clone_create(ifc, unit) 158 struct if_clone *ifc; 159 int unit; --- 16 unchanged lines hidden (view full) --- 176 sc->g_dst.s_addr = sc->g_src.s_addr = INADDR_ANY; 177 sc->g_proto = IPPROTO_GRE; 178 sc->sc_if.if_flags |= IFF_LINK0; 179 sc->encap = NULL; 180 sc->called = 0; 181 sc->wccp_ver = WCCP_V1; 182 if_attach(&sc->sc_if); 183 bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int32_t)); | 158 LIST_INIT(&gre_softc_list); 159 if_clone_attach(&gre_cloner); 160} 161 162static int 163gre_clone_create(ifc, unit) 164 struct if_clone *ifc; 165 int unit; --- 16 unchanged lines hidden (view full) --- 182 sc->g_dst.s_addr = sc->g_src.s_addr = INADDR_ANY; 183 sc->g_proto = IPPROTO_GRE; 184 sc->sc_if.if_flags |= IFF_LINK0; 185 sc->encap = NULL; 186 sc->called = 0; 187 sc->wccp_ver = WCCP_V1; 188 if_attach(&sc->sc_if); 189 bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int32_t)); |
190 mtx_lock(&gre_mtx); |
|
184 LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list); | 191 LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list); |
192 mtx_unlock(&gre_mtx); |
|
185 return (0); 186} 187 188static void | 193 return (0); 194} 195 196static void |
189gre_clone_destroy(ifp) 190 struct ifnet *ifp; | 197gre_destroy(struct gre_softc *sc) |
191{ | 198{ |
192 struct gre_softc *sc = ifp->if_softc; | |
193 194#ifdef INET 195 if (sc->encap != NULL) 196 encap_detach(sc->encap); 197#endif | 199 200#ifdef INET 201 if (sc->encap != NULL) 202 encap_detach(sc->encap); 203#endif |
198 LIST_REMOVE(sc, sc_list); 199 bpfdetach(ifp); 200 if_detach(ifp); | 204 bpfdetach(&sc->sc_if); 205 if_detach(&sc->sc_if); |
201 free(sc, M_GRE); 202} 203 | 206 free(sc, M_GRE); 207} 208 |
209static void 210gre_clone_destroy(ifp) 211 struct ifnet *ifp; 212{ 213 struct gre_softc *sc = ifp->if_softc; 214 215 mtx_lock(&gre_mtx); 216 LIST_REMOVE(sc, sc_list); 217 mtx_unlock(&gre_mtx); 218 gre_destroy(sc); 219} 220 |
|
204/* 205 * The output routine. Takes a packet and encapsulates it in the protocol 206 * given by sc->g_proto. See also RFC 1701 and RFC 2004 207 */ 208static int 209gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, 210 struct rtentry *rt) 211{ --- 510 unchanged lines hidden (view full) --- 722 sum = (sum >> 16) + (sum & 0xffff); 723 sum += (sum >> 16); 724 return (~sum); 725} 726 727static int 728gremodevent(module_t mod, int type, void *data) 729{ | 221/* 222 * The output routine. Takes a packet and encapsulates it in the protocol 223 * given by sc->g_proto. See also RFC 1701 and RFC 2004 224 */ 225static int 226gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, 227 struct rtentry *rt) 228{ --- 510 unchanged lines hidden (view full) --- 739 sum = (sum >> 16) + (sum & 0xffff); 740 sum += (sum >> 16); 741 return (~sum); 742} 743 744static int 745gremodevent(module_t mod, int type, void *data) 746{ |
747 struct gre_softc *sc; |
|
730 731 switch (type) { 732 case MOD_LOAD: 733 greattach(); 734 break; 735 case MOD_UNLOAD: 736 if_clone_detach(&gre_cloner); 737 | 748 749 switch (type) { 750 case MOD_LOAD: 751 greattach(); 752 break; 753 case MOD_UNLOAD: 754 if_clone_detach(&gre_cloner); 755 |
738 while (!LIST_EMPTY(&gre_softc_list)) 739 gre_clone_destroy(&LIST_FIRST(&gre_softc_list)->sc_if); | 756 mtx_lock(&gre_mtx); 757 while ((sc = LIST_FIRST(&gre_softc_list)) != NULL) { 758 LIST_REMOVE(sc, sc_list); 759 mtx_unlock(&gre_mtx); 760 gre_destroy(sc); 761 mtx_lock(&gre_mtx); 762 } 763 mtx_unlock(&gre_mtx); 764 mtx_destroy(&gre_mtx); |
740 break; 741 } 742 return 0; 743} 744 745static moduledata_t gre_mod = { 746 "if_gre", 747 gremodevent, 748 0 749}; 750 751DECLARE_MODULE(if_gre, gre_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); 752MODULE_VERSION(if_gre, 1); | 765 break; 766 } 767 return 0; 768} 769 770static moduledata_t gre_mod = { 771 "if_gre", 772 gremodevent, 773 0 774}; 775 776DECLARE_MODULE(if_gre, gre_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); 777MODULE_VERSION(if_gre, 1); |