diff options
author | Brad Smith <brad@cvs.openbsd.org> | 2005-05-14 19:24:24 +0000 |
---|---|---|
committer | Brad Smith <brad@cvs.openbsd.org> | 2005-05-14 19:24:24 +0000 |
commit | 83dbfd7568f339e559eb487792b655d2a030dd01 (patch) | |
tree | 38a731b891429485441e2d8917a70bb359a68c25 /sys | |
parent | 8af297edf23771f07bb3ccf6206d4e986c6d9dd4 (diff) |
- Add IPv6 over GRE.
- u_short -> u_int16_t
- Change default MTU to 1476 (same value that Cisco and other *BSD's use).
- Mark gre(4) interfaces as IFT_TUNNEL (Encapsulation interface).
From NetBSD
- Support setting the MTU
Be very careful when upgrading, the change in default MTU might cause
problems with an existing OpenBSD <-> OpenBSD setup.
Thanks to Stephen Marley <stephen dot marley at catwoman dot cl-is dot com>
for some testing.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/if_gre.c | 50 | ||||
-rw-r--r-- | sys/net/if_gre.h | 6 |
2 files changed, 40 insertions, 16 deletions
diff --git a/sys/net/if_gre.c b/sys/net/if_gre.c index fc20588a14c..f84091156a1 100644 --- a/sys/net/if_gre.c +++ b/sys/net/if_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_gre.c,v 1.32 2004/08/18 18:37:53 canacar Exp $ */ +/* $OpenBSD: if_gre.c,v 1.33 2005/05/14 19:24:23 brad Exp $ */ /* $NetBSD: if_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -8,6 +8,8 @@ * This code is derived from software contributed to The NetBSD Foundation * by Heiko W.Rupp <hwr@pilhuhn.de> * + * IPv6-over-GRE contributed by Gert Doering <gert@greenie.muc.de> + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -93,11 +95,12 @@ #define GRE_RECURSION_LIMIT 3 /* How many levels of recursion allowed */ #endif /* GRE_RECURSION_LIMIT */ -#define GREMTU 1450 /* XXX this is below the standard MTU of - 1500 Bytes, allowing for headers, - but we should possibly do path mtu discovery - before changing if state to up to find the - correct value */ +/* + * It is not easy to calculate the right value for a GRE MTU. + * We leave this task to the admin and use the same default that + * other vendors use. + */ +#define GREMTU 1476 int gre_clone_create(struct if_clone *, int); int gre_clone_destroy(struct ifnet *); @@ -141,7 +144,7 @@ gre_clone_create(struct if_clone *ifc, int unit) snprintf(sc->sc_if.if_xname, sizeof sc->sc_if.if_xname, "%s%d", ifc->ifc_name, unit); sc->sc_if.if_softc = sc; - sc->sc_if.if_type = IFT_OTHER; + sc->sc_if.if_type = IFT_TUNNEL; sc->sc_if.if_addrlen = 0; sc->sc_if.if_hdrlen = 24; /* IP + GRE */ sc->sc_if.if_mtu = GREMTU; @@ -203,7 +206,8 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct gre_softc *sc = (struct gre_softc *) (ifp->if_softc); struct greip *gh = NULL; struct ip *inp = NULL; - u_short etype = 0; + u_int8_t ip_tos = 0; + u_int16_t etype = 0; struct mobile_h mob_h; struct m_tag *mtag; @@ -314,7 +318,7 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, } HTONS(mob_h.proto); - mob_h.hcrc = gre_in_cksum((u_short *) &mob_h, msiz); + mob_h.hcrc = gre_in_cksum((u_int16_t *) &mob_h, msiz); /* Squeeze in the mobility header */ if ((m->m_data - msiz) < m->m_pktdat) { @@ -377,6 +381,7 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, } inp = mtod(m, struct ip *); + ip_tos = inp->ip_tos; etype = ETHERTYPE_IP; break; #ifdef NETATALK @@ -389,6 +394,11 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, etype = ETHERTYPE_NS; break; #endif +#ifdef INET6 + case AF_INET6: + etype = ETHERTYPE_IPV6; + break; +#endif default: IF_DROP(&ifp->if_snd); m_freem(m); @@ -424,7 +434,7 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, gh->gi_dst = sc->g_dst; ((struct ip *) gh)->ip_hl = (sizeof(struct ip)) >> 2; ((struct ip *) gh)->ip_ttl = ip_defttl; - ((struct ip *) gh)->ip_tos = inp->ip_tos; + ((struct ip *) gh)->ip_tos = ip_tos; gh->gi_len = htons(m->m_pkthdr.len); } @@ -465,6 +475,16 @@ gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) else sc->g_proto = IPPROTO_MOBILE; break; + case SIOCSIFMTU: + if (ifr->ifr_mtu < 576) { + error = EINVAL; + break; + } + ifp->if_mtu = ifr->ifr_mtu; + break; + case SIOCGIFMTU: + ifr->ifr_mtu = sc->sc_if.if_mtu; + break; case SIOCADDMULTI: case SIOCDELMULTI: if (ifr == 0) { @@ -476,6 +496,10 @@ gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) case AF_INET: break; #endif +#ifdef INET6 + case AF_INET6: + break; +#endif default: error = EAFNOSUPPORT; break; @@ -665,10 +689,10 @@ gre_compute_route(struct gre_softc *sc) * do a checksum of a buffer - much like in_cksum, which operates on * mbufs. */ -u_short -gre_in_cksum(u_short *p, u_int len) +u_int16_t +gre_in_cksum(u_int16_t *p, u_int len) { - u_int sum = 0; + u_int32_t sum = 0; int nwords = len >> 1; while (nwords-- != 0) diff --git a/sys/net/if_gre.h b/sys/net/if_gre.h index ed7fcbb67ca..d42429abaf0 100644 --- a/sys/net/if_gre.h +++ b/sys/net/if_gre.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_gre.h,v 1.9 2003/12/03 14:52:23 markus Exp $ */ +/* $OpenBSD: if_gre.h,v 1.10 2005/05/14 19:24:23 brad Exp $ */ /* $NetBSD: if_gre.h,v 1.5 1999/11/19 20:41:19 thorpej Exp $ */ /* @@ -147,7 +147,7 @@ extern int ip_mobile_allow; void greattach(int); int gre_ioctl(struct ifnet *, u_long, caddr_t); int gre_output(struct ifnet *, struct mbuf *, struct sockaddr *, - struct rtentry *rt); -u_short gre_in_cksum(u_short *p, u_int len); + struct rtentry *); +u_int16_t gre_in_cksum(u_int16_t *, u_int); #endif /* _KERNEL */ #endif /* _NET_IF_GRE_H_ */ |