Changeset View
Changeset View
Standalone View
Standalone View
head/sys/net/if_gre.c
Show First 20 Lines • Show All 545 Lines • ▼ Show 20 Lines | if (sc->gre_options & GRE_ENABLE_SEQ) { | ||||
sc->gre_hlen += sizeof(uint32_t); | sc->gre_hlen += sizeof(uint32_t); | ||||
*opts++ = 0; | *opts++ = 0; | ||||
} else | } else | ||||
sc->gre_oseq = 0; | sc->gre_oseq = 0; | ||||
gh->gre_flags = htons(flags); | gh->gre_flags = htons(flags); | ||||
} | } | ||||
static void | static void | ||||
gre_detach(struct gre_softc *sc) | gre_detach(struct gre_softc *sc, int family) | ||||
{ | { | ||||
sx_assert(&gre_ioctl_sx, SA_XLOCKED); | sx_assert(&gre_ioctl_sx, SA_XLOCKED); | ||||
if (sc->gre_ecookie != NULL) | if (sc->gre_ecookie != NULL) { | ||||
encap_detach(sc->gre_ecookie); | switch (family) { | ||||
#ifdef INET | |||||
case AF_INET: | |||||
ip_encap_detach(sc->gre_ecookie); | |||||
break; | |||||
#endif | |||||
#ifdef INET6 | |||||
case AF_INET6: | |||||
ip6_encap_detach(sc->gre_ecookie); | |||||
break; | |||||
#endif | |||||
} | |||||
} | |||||
sc->gre_ecookie = NULL; | sc->gre_ecookie = NULL; | ||||
} | } | ||||
static int | static int | ||||
gre_set_tunnel(struct ifnet *ifp, struct sockaddr *src, | gre_set_tunnel(struct ifnet *ifp, struct sockaddr *src, | ||||
struct sockaddr *dst) | struct sockaddr *dst) | ||||
{ | { | ||||
struct gre_softc *sc, *tsc; | struct gre_softc *sc, *tsc; | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | case AF_INET6: | ||||
ip6->ip6_src = satosin6(src)->sin6_addr; | ip6->ip6_src = satosin6(src)->sin6_addr; | ||||
ip6->ip6_dst = satosin6(dst)->sin6_addr; | ip6->ip6_dst = satosin6(dst)->sin6_addr; | ||||
break; | break; | ||||
#endif | #endif | ||||
default: | default: | ||||
return (EAFNOSUPPORT); | return (EAFNOSUPPORT); | ||||
} | } | ||||
if (sc->gre_family != 0) | if (sc->gre_family != 0) | ||||
gre_detach(sc); | gre_detach(sc, sc->gre_family); | ||||
GRE_WLOCK(sc); | GRE_WLOCK(sc); | ||||
if (sc->gre_family != 0) | if (sc->gre_family != 0) | ||||
free(sc->gre_hdr, M_GRE); | free(sc->gre_hdr, M_GRE); | ||||
sc->gre_family = src->sa_family; | sc->gre_family = src->sa_family; | ||||
sc->gre_hdr = hdr; | sc->gre_hdr = hdr; | ||||
sc->gre_oseq = 0; | sc->gre_oseq = 0; | ||||
sc->gre_iseq = UINT32_MAX; | sc->gre_iseq = UINT32_MAX; | ||||
gre_updatehdr(sc); | gre_updatehdr(sc); | ||||
Show All 25 Lines | gre_delete_tunnel(struct ifnet *ifp) | ||||
struct gre_softc *sc = ifp->if_softc; | struct gre_softc *sc = ifp->if_softc; | ||||
int family; | int family; | ||||
GRE_WLOCK(sc); | GRE_WLOCK(sc); | ||||
family = sc->gre_family; | family = sc->gre_family; | ||||
sc->gre_family = 0; | sc->gre_family = 0; | ||||
GRE_WUNLOCK(sc); | GRE_WUNLOCK(sc); | ||||
if (family != 0) { | if (family != 0) { | ||||
gre_detach(sc); | gre_detach(sc, family); | ||||
free(sc->gre_hdr, M_GRE); | free(sc->gre_hdr, M_GRE); | ||||
} | } | ||||
ifp->if_drv_flags &= ~IFF_DRV_RUNNING; | ifp->if_drv_flags &= ~IFF_DRV_RUNNING; | ||||
if_link_state_change(ifp, LINK_STATE_DOWN); | if_link_state_change(ifp, LINK_STATE_DOWN); | ||||
} | } | ||||
int | int | ||||
gre_input(struct mbuf **mp, int *offp, int proto) | gre_input(struct mbuf *m, int off, int proto, void *arg) | ||||
{ | { | ||||
struct gre_softc *sc; | struct gre_softc *sc = arg; | ||||
struct grehdr *gh; | struct grehdr *gh; | ||||
struct ifnet *ifp; | struct ifnet *ifp; | ||||
struct mbuf *m; | |||||
uint32_t *opts; | uint32_t *opts; | ||||
#ifdef notyet | #ifdef notyet | ||||
uint32_t key; | uint32_t key; | ||||
#endif | #endif | ||||
uint16_t flags; | uint16_t flags; | ||||
int hlen, isr, af; | int hlen, isr, af; | ||||
m = *mp; | |||||
sc = encap_getarg(m); | |||||
KASSERT(sc != NULL, ("encap_getarg returned NULL")); | |||||
ifp = GRE2IFP(sc); | ifp = GRE2IFP(sc); | ||||
hlen = *offp + sizeof(struct grehdr) + 4 * sizeof(uint32_t); | hlen = off + sizeof(struct grehdr) + 4 * sizeof(uint32_t); | ||||
if (m->m_pkthdr.len < hlen) | if (m->m_pkthdr.len < hlen) | ||||
goto drop; | goto drop; | ||||
if (m->m_len < hlen) { | if (m->m_len < hlen) { | ||||
m = m_pullup(m, hlen); | m = m_pullup(m, hlen); | ||||
if (m == NULL) | if (m == NULL) | ||||
goto drop; | goto drop; | ||||
} | } | ||||
gh = (struct grehdr *)mtodo(m, *offp); | gh = (struct grehdr *)mtodo(m, off); | ||||
flags = ntohs(gh->gre_flags); | flags = ntohs(gh->gre_flags); | ||||
if (flags & ~GRE_FLAGS_MASK) | if (flags & ~GRE_FLAGS_MASK) | ||||
goto drop; | goto drop; | ||||
opts = gh->gre_opts; | opts = gh->gre_opts; | ||||
hlen = 2 * sizeof(uint16_t); | hlen = 2 * sizeof(uint16_t); | ||||
if (flags & GRE_FLAGS_CP) { | if (flags & GRE_FLAGS_CP) { | ||||
/* reserved1 field must be zero */ | /* reserved1 field must be zero */ | ||||
if (((uint16_t *)opts)[1] != 0) | if (((uint16_t *)opts)[1] != 0) | ||||
goto drop; | goto drop; | ||||
if (in_cksum_skip(m, m->m_pkthdr.len, *offp) != 0) | if (in_cksum_skip(m, m->m_pkthdr.len, off) != 0) | ||||
goto drop; | goto drop; | ||||
hlen += 2 * sizeof(uint16_t); | hlen += 2 * sizeof(uint16_t); | ||||
opts++; | opts++; | ||||
} | } | ||||
if (flags & GRE_FLAGS_KP) { | if (flags & GRE_FLAGS_KP) { | ||||
#ifdef notyet | #ifdef notyet | ||||
/* | /* | ||||
* XXX: The current implementation uses the key only for outgoing | * XXX: The current implementation uses the key only for outgoing | ||||
Show All 33 Lines | case ETHERTYPE_IP: | ||||
break; | break; | ||||
case ETHERTYPE_IPV6: | case ETHERTYPE_IPV6: | ||||
isr = NETISR_IPV6; | isr = NETISR_IPV6; | ||||
af = AF_INET6; | af = AF_INET6; | ||||
break; | break; | ||||
default: | default: | ||||
goto drop; | goto drop; | ||||
} | } | ||||
m_adj(m, *offp + hlen); | m_adj(m, off + hlen); | ||||
m_clrprotoflags(m); | m_clrprotoflags(m); | ||||
m->m_pkthdr.rcvif = ifp; | m->m_pkthdr.rcvif = ifp; | ||||
M_SETFIB(m, ifp->if_fib); | M_SETFIB(m, ifp->if_fib); | ||||
#ifdef MAC | #ifdef MAC | ||||
mac_ifnet_create_mbuf(ifp, m); | mac_ifnet_create_mbuf(ifp, m); | ||||
#endif | #endif | ||||
BPF_MTAP2(ifp, &af, sizeof(af), m); | BPF_MTAP2(ifp, &af, sizeof(af), m); | ||||
if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); | if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); | ||||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |