if_stf.c (129880) | if_stf.c (130933) |
---|---|
1/* $FreeBSD: head/sys/net/if_stf.c 129880 2004-05-30 20:27:19Z phk $ */ | 1/* $FreeBSD: head/sys/net/if_stf.c 130933 2004-06-22 20:13:25Z brooks $ */ |
2/* $KAME: if_stf.c,v 1.73 2001/12/03 11:08:30 keiichi Exp $ */ 3 4/* 5 * Copyright (C) 2000 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 79 unchanged lines hidden (view full) --- 89#include <sys/module.h> 90#include <sys/protosw.h> 91#include <sys/queue.h> 92#include <machine/cpu.h> 93 94#include <sys/malloc.h> 95 96#include <net/if.h> | 2/* $KAME: if_stf.c,v 1.73 2001/12/03 11:08:30 keiichi Exp $ */ 3 4/* 5 * Copyright (C) 2000 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 79 unchanged lines hidden (view full) --- 89#include <sys/module.h> 90#include <sys/protosw.h> 91#include <sys/queue.h> 92#include <machine/cpu.h> 93 94#include <sys/malloc.h> 95 96#include <net/if.h> |
97#include <net/if_clone.h> |
|
97#include <net/route.h> 98#include <net/netisr.h> 99#include <net/if_types.h> 100#include <net/if_stf.h> 101 102#include <netinet/in.h> 103#include <netinet/in_systm.h> 104#include <netinet/ip.h> --- 9 unchanged lines hidden (view full) --- 114 115#include <machine/stdarg.h> 116 117#include <net/net_osdep.h> 118 119#include <net/bpf.h> 120 121#define STFNAME "stf" | 98#include <net/route.h> 99#include <net/netisr.h> 100#include <net/if_types.h> 101#include <net/if_stf.h> 102 103#include <netinet/in.h> 104#include <netinet/in_systm.h> 105#include <netinet/ip.h> --- 9 unchanged lines hidden (view full) --- 115 116#include <machine/stdarg.h> 117 118#include <net/net_osdep.h> 119 120#include <net/bpf.h> 121 122#define STFNAME "stf" |
123#define STFUNIT 0 |
|
122 123#define IN6_IS_ADDR_6TO4(x) (ntohs((x)->s6_addr16[0]) == 0x2002) 124 125/* 126 * XXX: Return a pointer with 16-bit aligned. Don't cast it to 127 * struct in_addr *; use bcopy() instead. 128 */ 129#define GET_V4(x) ((caddr_t)(&(x)->s6_addr16[1])) --- 25 unchanged lines hidden (view full) --- 155struct protosw in_stf_protosw = 156{ SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 157 in_stf_input, (pr_output_t*)rip_output, 0, rip_ctloutput, 158 0, 159 0, 0, 0, 0, 160 &rip_usrreqs 161}; 162 | 124 125#define IN6_IS_ADDR_6TO4(x) (ntohs((x)->s6_addr16[0]) == 0x2002) 126 127/* 128 * XXX: Return a pointer with 16-bit aligned. Don't cast it to 129 * struct in_addr *; use bcopy() instead. 130 */ 131#define GET_V4(x) ((caddr_t)(&(x)->s6_addr16[1])) --- 25 unchanged lines hidden (view full) --- 157struct protosw in_stf_protosw = 158{ SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR, 159 in_stf_input, (pr_output_t*)rip_output, 0, rip_ctloutput, 160 0, 161 0, 0, 0, 0, 162 &rip_usrreqs 163}; 164 |
165static char *stfnames[] = {"stf0", "stf", "6to4", NULL}; 166 |
|
163static int stfmodevent(module_t, int, void *); 164static int stf_encapcheck(const struct mbuf *, int, int, void *); 165static struct in6_ifaddr *stf_getsrcifa6(struct ifnet *); 166static int stf_output(struct ifnet *, struct mbuf *, struct sockaddr *, 167 struct rtentry *); 168static int isrfc1918addr(struct in_addr *); 169static int stf_checkaddr4(struct stf_softc *, struct in_addr *, 170 struct ifnet *); 171static int stf_checkaddr6(struct stf_softc *, struct in6_addr *, 172 struct ifnet *); 173static void stf_rtrequest(int, struct rtentry *, struct rt_addrinfo *); 174static int stf_ioctl(struct ifnet *, u_long, caddr_t); 175 | 167static int stfmodevent(module_t, int, void *); 168static int stf_encapcheck(const struct mbuf *, int, int, void *); 169static struct in6_ifaddr *stf_getsrcifa6(struct ifnet *); 170static int stf_output(struct ifnet *, struct mbuf *, struct sockaddr *, 171 struct rtentry *); 172static int isrfc1918addr(struct in_addr *); 173static int stf_checkaddr4(struct stf_softc *, struct in_addr *, 174 struct ifnet *); 175static int stf_checkaddr6(struct stf_softc *, struct in6_addr *, 176 struct ifnet *); 177static void stf_rtrequest(int, struct rtentry *, struct rt_addrinfo *); 178static int stf_ioctl(struct ifnet *, u_long, caddr_t); 179 |
176static int stf_clone_create(struct if_clone *, int); 177static void stf_clone_destroy(struct ifnet *); | 180static int stf_clone_match(struct if_clone *, const char *); 181static int stf_clone_create(struct if_clone *, char *, size_t); 182static int stf_clone_destroy(struct if_clone *, struct ifnet *); 183struct if_clone stf_cloner = IFC_CLONE_INITIALIZER(STFNAME, NULL, 0, 184 NULL, stf_clone_match, stf_clone_create, stf_clone_destroy); |
178 | 185 |
179/* only one clone is currently allowed */ 180struct if_clone stf_cloner = 181 IF_CLONE_INITIALIZER(STFNAME, stf_clone_create, stf_clone_destroy, 0, 0); | 186static int 187stf_clone_match(struct if_clone *ifc, const char *name) 188{ 189 int i; |
182 | 190 |
191 for(i = 0; stfnames[i] != NULL; i++) { 192 if (strcmp(stfnames[i], name) == 0) 193 return (1); 194 } 195 196 return (0); 197} 198 |
|
183static int | 199static int |
184stf_clone_create(ifc, unit) 185 struct if_clone *ifc; 186 int unit; | 200stf_clone_create(struct if_clone *ifc, char *name, size_t len) |
187{ | 201{ |
202 int err, unit; |
|
188 struct stf_softc *sc; 189 struct ifnet *ifp; 190 | 203 struct stf_softc *sc; 204 struct ifnet *ifp; 205 |
206 /* 207 * We can only have one unit, but since unit allocation is 208 * already locked, we use it to keep from allocating extra 209 * interfaces. 210 */ 211 unit = STFUNIT; 212 err = ifc_alloc_unit(ifc, &unit); 213 if (err != 0) 214 return (err); 215 |
|
191 sc = malloc(sizeof(struct stf_softc), M_STF, M_WAITOK | M_ZERO); 192 ifp = &sc->sc_if; | 216 sc = malloc(sizeof(struct stf_softc), M_STF, M_WAITOK | M_ZERO); 217 ifp = &sc->sc_if; |
193 if_initname(ifp, ifc->ifc_name, unit); | 218 /* 219 * Set the name manually rather then using if_initname because 220 * we don't conform to the default naming convention for interfaces. 221 */ 222 strlcpy(ifp->if_xname, name, IFNAMSIZ); 223 ifp->if_dname = ifc->ifc_name; 224 ifp->if_dunit = IF_DUNIT_NONE; |
194 195 sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6, 196 stf_encapcheck, &in_stf_protosw, sc); 197 if (sc->encap_cookie == NULL) { 198 if_printf(ifp, "attach failed\n"); 199 free(sc, M_STF); | 225 226 sc->encap_cookie = encap_attach_func(AF_INET, IPPROTO_IPV6, 227 stf_encapcheck, &in_stf_protosw, sc); 228 if (sc->encap_cookie == NULL) { 229 if_printf(ifp, "attach failed\n"); 230 free(sc, M_STF); |
231 ifc_free_unit(ifc, unit); |
|
200 return (ENOMEM); 201 } 202 203 ifp->if_mtu = IPV6_MMTU; 204 ifp->if_ioctl = stf_ioctl; 205 ifp->if_output = stf_output; 206 ifp->if_type = IFT_STF; 207 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; --- 13 unchanged lines hidden (view full) --- 221 err = encap_detach(sc->encap_cookie); 222 KASSERT(err == 0, ("Unexpected error detaching encap_cookie")); 223 bpfdetach(&sc->sc_if); 224 if_detach(&sc->sc_if); 225 226 free(sc, M_STF); 227} 228 | 232 return (ENOMEM); 233 } 234 235 ifp->if_mtu = IPV6_MMTU; 236 ifp->if_ioctl = stf_ioctl; 237 ifp->if_output = stf_output; 238 ifp->if_type = IFT_STF; 239 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; --- 13 unchanged lines hidden (view full) --- 253 err = encap_detach(sc->encap_cookie); 254 KASSERT(err == 0, ("Unexpected error detaching encap_cookie")); 255 bpfdetach(&sc->sc_if); 256 if_detach(&sc->sc_if); 257 258 free(sc, M_STF); 259} 260 |
229static void 230stf_clone_destroy(ifp) 231 struct ifnet *ifp; | 261static int 262stf_clone_destroy(struct if_clone *ifc, struct ifnet *ifp) |
232{ 233 struct stf_softc *sc = (void *) ifp; 234 235 mtx_lock(&stf_mtx); 236 LIST_REMOVE(sc, sc_list); 237 mtx_unlock(&stf_mtx); 238 239 stf_destroy(sc); | 263{ 264 struct stf_softc *sc = (void *) ifp; 265 266 mtx_lock(&stf_mtx); 267 LIST_REMOVE(sc, sc_list); 268 mtx_unlock(&stf_mtx); 269 270 stf_destroy(sc); |
271 ifc_free_unit(ifc, STFUNIT); 272 273 return (0); |
|
240} 241 242static int 243stfmodevent(mod, type, data) 244 module_t mod; 245 int type; 246 void *data; 247{ --- 563 unchanged lines hidden --- | 274} 275 276static int 277stfmodevent(mod, type, data) 278 module_t mod; 279 int type; 280 void *data; 281{ --- 563 unchanged lines hidden --- |