summaryrefslogtreecommitdiffstats
path: root/sys/netatalk/ddp_output.c
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2007-01-12 15:07:51 +0000
committerrwatson <rwatson@FreeBSD.org>2007-01-12 15:07:51 +0000
commit3f89da14403203e909a8cc15129f552d6d3ef3dc (patch)
tree0c7da38e01fe89ae2fb1dd585f10f4540df68ca0 /sys/netatalk/ddp_output.c
parent80c43bc68bbcfdb98c932aa8b59f81f7eb3f7e10 (diff)
downloadFreeBSD-src-3f89da14403203e909a8cc15129f552d6d3ef3dc.zip
FreeBSD-src-3f89da14403203e909a8cc15129f552d6d3ef3dc.tar.gz
Clean up DDP layer netatalk code:
- General style(9) cleanup -- white space, braces, line wraps, etc. - Annotate a lack of synchronization the global route cache if the input routine is invoked with parallelism. - Remove unused debugging code.
Diffstat (limited to 'sys/netatalk/ddp_output.c')
-rw-r--r--sys/netatalk/ddp_output.c296
1 files changed, 143 insertions, 153 deletions
diff --git a/sys/netatalk/ddp_output.c b/sys/netatalk/ddp_output.c
index c48f043..c67264e 100644
--- a/sys/netatalk/ddp_output.c
+++ b/sys/netatalk/ddp_output.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 1990,1991 Regents of The University of Michigan.
+ * Copyright (c) 1990, 1991 Regents of The University of Michigan.
* All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software and
@@ -49,197 +49,187 @@ int ddp_cksum = 1;
int
ddp_output(struct mbuf *m, struct socket *so)
{
- struct ddpehdr *deh;
- struct ddpcb *ddp = sotoddpcb(so);
+ struct ddpehdr *deh;
+ struct ddpcb *ddp = sotoddpcb(so);
#ifdef MAC
- SOCK_LOCK(so);
- mac_create_mbuf_from_socket(so, m);
- SOCK_UNLOCK(so);
+ SOCK_LOCK(so);
+ mac_create_mbuf_from_socket(so, m);
+ SOCK_UNLOCK(so);
#endif
- M_PREPEND(m, sizeof(struct ddpehdr), M_DONTWAIT);
- if (m == NULL)
+ M_PREPEND(m, sizeof(struct ddpehdr), M_DONTWAIT);
+ if (m == NULL)
return (ENOBUFS);
- deh = mtod(m, struct ddpehdr *);
- deh->deh_pad = 0;
- deh->deh_hops = 0;
-
- deh->deh_len = m->m_pkthdr.len;
-
- deh->deh_dnet = ddp->ddp_fsat.sat_addr.s_net;
- deh->deh_dnode = ddp->ddp_fsat.sat_addr.s_node;
- deh->deh_dport = ddp->ddp_fsat.sat_port;
- deh->deh_snet = ddp->ddp_lsat.sat_addr.s_net;
- deh->deh_snode = ddp->ddp_lsat.sat_addr.s_node;
- deh->deh_sport = ddp->ddp_lsat.sat_port;
-
- /*
- * The checksum calculation is done after all of the other bytes have
- * been filled in.
- */
- if (ddp_cksum) {
- deh->deh_sum = at_cksum(m, sizeof(int));
- } else {
- deh->deh_sum = 0;
- }
- deh->deh_bytes = htonl(deh->deh_bytes);
+ deh = mtod(m, struct ddpehdr *);
+ deh->deh_pad = 0;
+ deh->deh_hops = 0;
+
+ deh->deh_len = m->m_pkthdr.len;
+
+ deh->deh_dnet = ddp->ddp_fsat.sat_addr.s_net;
+ deh->deh_dnode = ddp->ddp_fsat.sat_addr.s_node;
+ deh->deh_dport = ddp->ddp_fsat.sat_port;
+ deh->deh_snet = ddp->ddp_lsat.sat_addr.s_net;
+ deh->deh_snode = ddp->ddp_lsat.sat_addr.s_node;
+ deh->deh_sport = ddp->ddp_lsat.sat_port;
+
+ /*
+ * The checksum calculation is done after all of the other bytes have
+ * been filled in.
+ */
+ if (ddp_cksum)
+ deh->deh_sum = at_cksum(m, sizeof(int));
+ else
+ deh->deh_sum = 0;
+ deh->deh_bytes = htonl(deh->deh_bytes);
#ifdef NETATALK_DEBUG
- printf ("ddp_output: from %d.%d:%d to %d.%d:%d\n",
+ printf ("ddp_output: from %d.%d:%d to %d.%d:%d\n",
ntohs(deh->deh_snet), deh->deh_snode, deh->deh_sport,
ntohs(deh->deh_dnet), deh->deh_dnode, deh->deh_dport);
#endif
- return (ddp_route(m, &ddp->ddp_route));
+ return (ddp_route(m, &ddp->ddp_route));
}
u_short
at_cksum(struct mbuf *m, int skip)
{
- u_char *data, *end;
- u_long cksum = 0;
-
- for (; m; m = m->m_next) {
- for (data = mtod(m, u_char *), end = data + m->m_len; data < end;
- data++) {
- if (skip) {
- skip--;
- continue;
- }
- cksum = (cksum + *data) << 1;
- if (cksum & 0x00010000) {
- cksum++;
- }
- cksum &= 0x0000ffff;
+ u_char *data, *end;
+ u_long cksum = 0;
+
+ for (; m; m = m->m_next) {
+ for (data = mtod(m, u_char *), end = data + m->m_len;
+ data < end; data++) {
+ if (skip) {
+ skip--;
+ continue;
+ }
+ cksum = (cksum + *data) << 1;
+ if (cksum & 0x00010000)
+ cksum++;
+ cksum &= 0x0000ffff;
+ }
}
- }
- if (cksum == 0) {
- cksum = 0x0000ffff;
- }
- return ((u_short)cksum);
+ if (cksum == 0)
+ cksum = 0x0000ffff;
+ return ((u_short)cksum);
}
int
ddp_route(struct mbuf *m, struct route *ro)
{
- struct sockaddr_at gate;
- struct elaphdr *elh;
- struct mbuf *m0;
- struct at_ifaddr *aa = NULL;
- struct ifnet *ifp = NULL;
- u_short net;
+ struct sockaddr_at gate;
+ struct elaphdr *elh;
+ struct mbuf *m0;
+ struct at_ifaddr *aa = NULL;
+ struct ifnet *ifp = NULL;
+ u_short net;
#if 0
- /* Check for net zero, node zero ("myself") */
- if (satosat(&ro->ro_dst)->sat_addr.s_net == ATADDR_ANYNET
- && satosat(&ro->ro_dst)->sat_addr.s_node == ATADDR_ANYNODE) {
- /* Find the loopback interface */
- }
+ /* Check for net zero, node zero ("myself") */
+ if (satosat(&ro->ro_dst)->sat_addr.s_net == ATADDR_ANYNET
+ && satosat(&ro->ro_dst)->sat_addr.s_node == ATADDR_ANYNODE) {
+ /* Find the loopback interface */
+ }
#endif
- /*
- * if we have a route, find the ifa that refers to this route.
- * I.e The ifa used to get to the gateway.
- */
- if ((ro->ro_rt == NULL)
- || (ro->ro_rt->rt_ifa == NULL)
- || ((ifp = ro->ro_rt->rt_ifa->ifa_ifp) == NULL)) {
- rtalloc(ro);
- }
- if ((ro->ro_rt != NULL)
- && (ro->ro_rt->rt_ifa)
- && (ifp = ro->ro_rt->rt_ifa->ifa_ifp)) {
- net = ntohs(satosat(ro->ro_rt->rt_gateway)->sat_addr.s_net);
- for (aa = at_ifaddr_list; aa != NULL; aa = aa->aa_next) {
- if (((net == 0) || (aa->aa_ifp == ifp)) &&
- net >= ntohs(aa->aa_firstnet) &&
- net <= ntohs(aa->aa_lastnet)) {
- break;
- }
- }
- } else {
- m_freem(m);
+ /*
+ * If we have a route, find the ifa that refers to this route. I.e
+ * the ifa used to get to the gateway.
+ */
+ if ((ro->ro_rt == NULL) || (ro->ro_rt->rt_ifa == NULL) ||
+ ((ifp = ro->ro_rt->rt_ifa->ifa_ifp) == NULL))
+ rtalloc(ro);
+ if ((ro->ro_rt != NULL) && (ro->ro_rt->rt_ifa) &&
+ (ifp = ro->ro_rt->rt_ifa->ifa_ifp)) {
+ net = ntohs(satosat(ro->ro_rt->rt_gateway)->sat_addr.s_net);
+ for (aa = at_ifaddr_list; aa != NULL; aa = aa->aa_next) {
+ if (((net == 0) || (aa->aa_ifp == ifp)) &&
+ net >= ntohs(aa->aa_firstnet) &&
+ net <= ntohs(aa->aa_lastnet))
+ break;
+ }
+ } else {
+ m_freem(m);
#ifdef NETATALK_DEBUG
- if (ro->ro_rt == NULL)
- printf ("ddp_route: no ro_rt.\n");
- else if (ro->ro_rt->rt_ifa == NULL)
- printf ("ddp_route: no ro_rt->rt_ifa\n");
- else
- printf ("ddp_route: no ro_rt->rt_ifa->ifa_ifp\n");
+ if (ro->ro_rt == NULL)
+ printf ("ddp_route: no ro_rt.\n");
+ else if (ro->ro_rt->rt_ifa == NULL)
+ printf ("ddp_route: no ro_rt->rt_ifa\n");
+ else
+ printf ("ddp_route: no ro_rt->rt_ifa->ifa_ifp\n");
#endif
- return (ENETUNREACH);
- }
+ return (ENETUNREACH);
+ }
- if (aa == NULL) {
+ if (aa == NULL) {
#ifdef NETATALK_DEBUG
- printf("ddp_route: no atalk address found for %s\n",
- ifp->if_xname);
+ printf("ddp_route: no atalk address found for %s\n",
+ ifp->if_xname);
#endif
- m_freem(m);
- return (ENETUNREACH);
- }
-
- /*
- * if the destination address is on a directly attached node use that,
- * else use the official gateway.
- */
- if (ntohs(satosat(&ro->ro_dst)->sat_addr.s_net) >=
+ m_freem(m);
+ return (ENETUNREACH);
+ }
+
+ /*
+ * If the destination address is on a directly attached node use
+ * that, else use the official gateway.
+ */
+ if (ntohs(satosat(&ro->ro_dst)->sat_addr.s_net) >=
ntohs(aa->aa_firstnet) &&
ntohs(satosat(&ro->ro_dst)->sat_addr.s_net) <=
- ntohs(aa->aa_lastnet)) {
- gate = *satosat(&ro->ro_dst);
- } else {
- gate = *satosat(ro->ro_rt->rt_gateway);
- }
-
- /*
- * There are several places in the kernel where data is added to
- * an mbuf without ensuring that the mbuf pointer is aligned.
- * This is bad for transition routing, since phase 1 and phase 2
- * packets end up poorly aligned due to the three byte elap header.
- */
- if (!(aa->aa_flags & AFA_PHASE2)) {
- MGET(m0, M_DONTWAIT, MT_DATA);
- if (m0 == NULL) {
- m_freem(m);
- printf("ddp_route: no buffers\n");
- return (ENOBUFS);
- }
+ ntohs(aa->aa_lastnet))
+ gate = *satosat(&ro->ro_dst);
+ else
+ gate = *satosat(ro->ro_rt->rt_gateway);
+
+ /*
+ * There are several places in the kernel where data is added to an
+ * mbuf without ensuring that the mbuf pointer is aligned. This is
+ * bad for transition routing, since phase 1 and phase 2 packets end
+ * up poorly aligned due to the three byte elap header.
+ */
+ if (!(aa->aa_flags & AFA_PHASE2)) {
+ MGET(m0, M_DONTWAIT, MT_DATA);
+ if (m0 == NULL) {
+ m_freem(m);
+ printf("ddp_route: no buffers\n");
+ return (ENOBUFS);
+ }
#ifdef MAC
- mac_copy_mbuf(m, m0);
+ mac_copy_mbuf(m, m0);
#endif
- m0->m_next = m;
- /* XXX perhaps we ought to align the header? */
- m0->m_len = SZ_ELAPHDR;
- m = m0;
-
- elh = mtod(m, struct elaphdr *);
- elh->el_snode = satosat(&aa->aa_addr)->sat_addr.s_node;
- elh->el_type = ELAP_DDPEXTEND;
- elh->el_dnode = gate.sat_addr.s_node;
- }
- ro->ro_rt->rt_use++;
+ m0->m_next = m;
+ /* XXX perhaps we ought to align the header? */
+ m0->m_len = SZ_ELAPHDR;
+ m = m0;
+
+ elh = mtod(m, struct elaphdr *);
+ elh->el_snode = satosat(&aa->aa_addr)->sat_addr.s_node;
+ elh->el_type = ELAP_DDPEXTEND;
+ elh->el_dnode = gate.sat_addr.s_node;
+ }
+ ro->ro_rt->rt_use++;
#ifdef NETATALK_DEBUG
- printf ("ddp_route: from %d.%d to %d.%d, via %d.%d (%s)\n",
- ntohs(satosat(&aa->aa_addr)->sat_addr.s_net),
- satosat(&aa->aa_addr)->sat_addr.s_node,
- ntohs(satosat(&ro->ro_dst)->sat_addr.s_net),
- satosat(&ro->ro_dst)->sat_addr.s_node,
- ntohs(gate.sat_addr.s_net),
- gate.sat_addr.s_node,
- ifp->if_xname);
+ printf ("ddp_route: from %d.%d to %d.%d, via %d.%d (%s)\n",
+ ntohs(satosat(&aa->aa_addr)->sat_addr.s_net),
+ satosat(&aa->aa_addr)->sat_addr.s_node,
+ ntohs(satosat(&ro->ro_dst)->sat_addr.s_net),
+ satosat(&ro->ro_dst)->sat_addr.s_node,
+ ntohs(gate.sat_addr.s_net), gate.sat_addr.s_node, ifp->if_xname);
#endif
- /* short-circuit the output if we're sending this to ourself */
- if ((satosat(&aa->aa_addr)->sat_addr.s_net == satosat(&ro->ro_dst)->sat_addr.s_net) &&
- (satosat(&aa->aa_addr)->sat_addr.s_node == satosat(&ro->ro_dst)->sat_addr.s_node))
- {
- return (if_simloop(ifp, m, gate.sat_family, 0));
- }
+ /* Short-circuit the output if we're sending this to ourself. */
+ if ((satosat(&aa->aa_addr)->sat_addr.s_net ==
+ satosat(&ro->ro_dst)->sat_addr.s_net) &&
+ (satosat(&aa->aa_addr)->sat_addr.s_node ==
+ satosat(&ro->ro_dst)->sat_addr.s_node))
+ return (if_simloop(ifp, m, gate.sat_family, 0));
- return ((*ifp->if_output)(ifp,
- m, (struct sockaddr *)&gate, NULL)); /* XXX */
+ /* XXX */
+ return ((*ifp->if_output)(ifp, m, (struct sockaddr *)&gate, NULL));
}
OpenPOWER on IntegriCloud