summaryrefslogtreecommitdiff
path: root/sys/net/if_gre.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2001-06-22 14:28:59 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2001-06-22 14:28:59 +0000
commitf42d8b99248945a02177adb0c2d42667133940d2 (patch)
treec835e56b3625e78d18a911fc368d9c403ffc733a /sys/net/if_gre.c
parentcd65ba11166aadcf84cf8c227662024ae1126d75 (diff)
KNF
Diffstat (limited to 'sys/net/if_gre.c')
-rw-r--r--sys/net/if_gre.c129
1 files changed, 63 insertions, 66 deletions
diff --git a/sys/net/if_gre.c b/sys/net/if_gre.c
index 00fca76d4ac..e7a07d162e6 100644
--- a/sys/net/if_gre.c
+++ b/sys/net/if_gre.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_gre.c,v 1.12 2001/06/05 23:43:45 maja Exp $ */
+/* $OpenBSD: if_gre.c,v 1.13 2001/06/22 14:28:58 deraadt Exp $ */
/* $NetBSD: if_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */
/*
@@ -94,9 +94,9 @@
#endif /* GRE_RECURSION_LIMIT */
#define GREMTU 1450 /* XXX this is below the standard MTU of
- 1500 Bytes, allowing for headers,
+ 1500 Bytes, allowing for headers,
but we should possibly do path mtu discovery
- before changing if state to up to find the
+ before changing if state to up to find the
correct value */
#define LINK_MASK (IFF_LINK0|IFF_LINK1|IFF_LINK2)
@@ -132,7 +132,7 @@ greattach(n)
sc->sc_if.if_type = IFT_OTHER;
sc->sc_if.if_addrlen = 4;
sc->sc_if.if_hdrlen = 24; /* IP + GRE */
- sc->sc_if.if_mtu = GREMTU;
+ sc->sc_if.if_mtu = GREMTU;
sc->sc_if.if_flags = IFF_POINTOPOINT|IFF_MULTICAST;
sc->sc_if.if_output = gre_output;
sc->sc_if.if_ioctl = gre_ioctl;
@@ -153,7 +153,7 @@ greattach(n)
}
}
-/*
+/*
* The output routine. Takes a packet and encapsulates it in the protocol
* given by sc->g_proto. See also RFC 1701 and RFC 2004.
*/
@@ -184,8 +184,8 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
#endif
if (sc->g_proto == IPPROTO_MOBILE) {
- if (ip_mobile_allow == 0) {
- IF_DROP(&ifp->if_snd);
+ if (ip_mobile_allow == 0) {
+ IF_DROP(&ifp->if_snd);
m_freem(m);
recursions = 0;
return (EACCES);
@@ -199,22 +199,20 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
* Make sure the complete IP header (with options)
* is in the first mbuf.
*/
- if (m->m_len < sizeof(struct ip))
- {
- m = m_pullup(m, sizeof(struct ip));
- if (m == NULL) {
+ if (m->m_len < sizeof(struct ip)) {
+ m = m_pullup(m, sizeof(struct ip));
+ if (m == NULL) {
IF_DROP(&ifp->if_snd);
recursions = 0;
return (ENOBUFS);
- }
- else
- inp = mtod(m, struct ip *);
+ } else
+ inp = mtod(m, struct ip *);
if (m->m_len < inp->ip_hl << 2) {
- m = m_pullup(m,
- sizeof(inp->ip_hl << 2));
+ m = m_pullup(m,
+ sizeof(inp->ip_hl << 2));
if (m == NULL) {
- IF_DROP(&ifp->if_snd);
+ IF_DROP(&ifp->if_snd);
recursions = 0;
return (ENOBUFS);
}
@@ -266,7 +264,7 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
m->m_len -= inp->ip_hl << 2;
bcopy((caddr_t) inp, mtod(m0, caddr_t),
- sizeof(struct ip));
+ sizeof(struct ip));
m0->m_next = m;
m = m0;
@@ -274,8 +272,8 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
m->m_data -= msiz;
m->m_len += msiz;
m->m_pkthdr.len += msiz;
- bcopy(inp, mtod(m, caddr_t),
- inp->ip_hl << 2);
+ bcopy(inp, mtod(m, caddr_t),
+ inp->ip_hl << 2);
}
/* Copy Mobility header */
@@ -290,8 +288,8 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
return (EINVAL);
}
} else if (sc->g_proto == IPPROTO_GRE) {
- if (gre_allow == 0) {
- IF_DROP(&ifp->if_snd);
+ if (gre_allow == 0) {
+ IF_DROP(&ifp->if_snd);
m_freem(m);
recursions = 0;
return (EACCES);
@@ -299,10 +297,10 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
switch(dst->sa_family) {
case AF_INET:
- if (m->m_len < sizeof(struct ip)) {
- m = m_pullup(m, sizeof(struct ip));
+ if (m->m_len < sizeof(struct ip)) {
+ m = m_pullup(m, sizeof(struct ip));
if (m == NULL) {
- IF_DROP(&ifp->if_snd);
+ IF_DROP(&ifp->if_snd);
recursions = 0;
return (ENOBUFS);
}
@@ -336,7 +334,7 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
recursions = 0;
return (error);
}
-
+
if (m == NULL) {
IF_DROP(&ifp->if_snd);
recursions = 0;
@@ -355,7 +353,7 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
if (sc->g_proto != IPPROTO_MOBILE) {
gh->gi_src = sc->g_src;
gh->gi_dst = sc->g_dst;
- ((struct ip *) gh)->ip_hl = (sizeof(struct ip)) >> 2;
+ ((struct ip *) gh)->ip_hl = (sizeof(struct ip)) >> 2;
((struct ip *) gh)->ip_ttl = ip_defttl;
((struct ip *) gh)->ip_tos = inp->ip_tos;
gh->gi_len = m->m_pkthdr.len;
@@ -384,17 +382,17 @@ gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
struct sockaddr_in si;
struct sockaddr *sa = NULL;
int error = 0;
- struct proc *prc = curproc; /* XXX */
+ struct proc *prc = curproc; /* XXX */
s = splimp();
switch(cmd) {
- case SIOCSIFADDR:
- case SIOCSIFDSTADDR:
- /*
- * set tunnel endpoints in case that we "only"
- * have ip over ip encapsulation. This allows to
- * set tunnel endpoints with ifconfig.
- */
+ case SIOCSIFADDR:
+ case SIOCSIFDSTADDR:
+ /*
+ * set tunnel endpoints in case that we "only"
+ * have ip over ip encapsulation. This allows to
+ * set tunnel endpoints with ifconfig.
+ */
if (ifa->ifa_addr->sa_family == AF_INET) {
sa = ifa->ifa_addr;
sc->g_src = (satosin(sa))->sin_addr;
@@ -402,7 +400,7 @@ gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
if ((sc->g_src.s_addr != INADDR_ANY) &&
(sc->g_dst.s_addr != INADDR_ANY)) {
if (sc->route.ro_rt != 0) {
- /* free old route */
+ /* free old route */
RTFREE(sc->route.ro_rt);
sc->route.ro_rt = (struct rtentry *) 0;
}
@@ -420,7 +418,7 @@ gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
}
break;
case SIOCSIFFLAGS:
- if ((sc->g_dst.s_addr == INADDR_ANY) ||
+ if ((sc->g_dst.s_addr == INADDR_ANY) ||
(sc->g_src.s_addr == INADDR_ANY))
ifp->if_flags &= ~IFF_UP;
@@ -454,9 +452,9 @@ gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
}
break;
case GRESPROTO:
- /* Check for superuser */
- if ((error = suser(prc->p_ucred, &prc->p_acflag)) != 0)
- break;
+ /* Check for superuser */
+ if ((error = suser(prc->p_ucred, &prc->p_acflag)) != 0)
+ break;
sc->g_proto = ifr->ifr_flags;
switch (sc->g_proto) {
@@ -477,14 +475,14 @@ gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
break;
case GRESADDRS:
case GRESADDRD:
- /* Check for superuser */
- if ((error = suser(prc->p_ucred, &prc->p_acflag)) != 0)
- break;
+ /* Check for superuser */
+ if ((error = suser(prc->p_ucred, &prc->p_acflag)) != 0)
+ break;
/*
- * set tunnel endpoints, compute a less specific route
- * to the remote end and mark if as up
- */
+ * set tunnel endpoints, compute a less specific route
+ * to the remote end and mark if as up
+ */
sa = &ifr->ifr_addr;
if (cmd == GRESADDRS )
sc->g_src = (satosin(sa))->sin_addr;
@@ -493,7 +491,7 @@ gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
if ((sc->g_src.s_addr != INADDR_ANY) &&
(sc->g_dst.s_addr != INADDR_ANY)) {
if (sc->route.ro_rt != 0) {
- /* free old route */
+ /* free old route */
RTFREE(sc->route.ro_rt);
sc->route.ro_rt = (struct rtentry *) 0;
}
@@ -527,12 +525,12 @@ gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
return (error);
}
-/*
+/*
* computes a route to our destination that is not the one
* which would be taken by ip_output(), as this one will loop back to
* us. If the interface is p2p as a--->b, then a routing entry exists
* If we now send a packet to b (e.g. ping b), this will come down here
- * gets src=a, dst=b tacked on and would from ip_ouput() sent back to
+ * gets src=a, dst=b tacked on and would from ip_ouput() sent back to
* if_gre.
* Goal here is to compute a route to b that is less specific than
* a-->b. We know that this one exists as in normal operation we have
@@ -546,7 +544,7 @@ gre_compute_route(struct gre_softc *sc)
u_int32_t a, b, c;
ro = &sc->route;
-
+
bzero(ro, sizeof(struct route));
((struct sockaddr_in *) &ro->ro_dst)->sin_addr = sc->g_dst;
ro->ro_dst.sa_family = AF_INET;
@@ -554,10 +552,10 @@ gre_compute_route(struct gre_softc *sc)
/*
* toggle last bit, so our interface is not found, but a less
- * specific route. I'd rather like to specify a shorter mask,
+ * specific route. I'd rather like to specify a shorter mask,
* but this is not possible. Should work though. XXX
* there is a simpler way ...
- */
+ */
if ((sc->sc_if.if_flags & IFF_LINK1) == 0) {
a = ntohl(sc->g_dst.s_addr);
b = a & 0x01;
@@ -577,43 +575,42 @@ gre_compute_route(struct gre_softc *sc)
* not allow people to link GRE tunnels.
*/
if (ro->ro_rt->rt_ifp == &sc->sc_if) {
- RTFREE(ro->ro_rt);
- ro->ro_rt = (struct rtentry *) 0;
+ RTFREE(ro->ro_rt);
+ ro->ro_rt = (struct rtentry *) 0;
return;
}
/*
- * now change it back - else ip_output will just drop
- * the route and search one to this interface ...
- */
+ * now change it back - else ip_output will just drop
+ * the route and search one to this interface ...
+ */
if ((sc->sc_if.if_flags & IFF_LINK1) == 0)
((struct sockaddr_in *) &ro->ro_dst)->sin_addr = sc->g_dst;
}
/*
- * do a checksum of a buffer - much like in_cksum, which operates on
- * mbufs.
+ * 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_int sum = 0;
+ u_int sum = 0;
int nwords = len >> 1;
-
+
while (nwords-- != 0)
sum += *p++;
-
+
if (len & 1) {
union {
u_short w;
- u_char c[2];
+ u_char c[2];
} u;
u.c[0] = *(u_char *) p;
u.c[1] = 0;
sum += u.w;
- }
-
+ }
+
/* end-around-carry */
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);