From 05f0c3e7058f4679c3fd37f9e8fd6237bba1bf13 Mon Sep 17 00:00:00 2001 From: itojun Date: Fri, 7 Jun 2002 14:29:10 +0000 Subject: [PATCH] KNF a bit --- sys/netinet6/ip6_output.c | 136 ++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 80 deletions(-) diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index 7c0c792a7086..94fba032cf35 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_output.c,v 1.48 2002/06/07 04:18:12 itojun Exp $ */ +/* $NetBSD: ip6_output.c,v 1.49 2002/06/07 14:29:10 itojun Exp $ */ /* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ /* @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.48 2002/06/07 04:18:12 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.49 2002/06/07 14:29:10 itojun Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" @@ -118,12 +118,12 @@ struct ip6_exthdrs { }; static int ip6_pcbopts __P((struct ip6_pktopts **, struct mbuf *, - struct socket *)); + struct socket *)); static int ip6_setmoptions __P((int, struct ip6_moptions **, struct mbuf *)); static int ip6_getmoptions __P((int, struct ip6_moptions *, struct mbuf **)); static int ip6_copyexthdr __P((struct mbuf **, caddr_t, int)); static int ip6_insertfraghdr __P((struct mbuf *, struct mbuf *, int, - struct ip6_frag **)); + struct ip6_frag **)); static int ip6_insert_jumboopt __P((struct ip6_exthdrs *, u_int32_t)); static int ip6_splithdr __P((struct mbuf *, struct ip6_exthdrs *)); static int ip6_getpmtu __P((struct route_in6 *, struct route_in6 *, @@ -178,7 +178,7 @@ ip6_output(m0, opt, ro, flags, im6o, ifpp) if (hp) { \ struct ip6_ext *eh = (struct ip6_ext *)(hp); \ error = ip6_copyexthdr((mp), (caddr_t)(hp), \ - ((eh)->ip6e_len + 1) << 3); \ + ((eh)->ip6e_len + 1) << 3); \ if (error) \ goto freehdrs; \ } \ @@ -339,12 +339,11 @@ ip6_output(m0, opt, ro, flags, im6o, ifpp) * m will point to IPv6 header. mprev will point to the * extension header prior to dest2 (rthdr in the above case). */ - MAKE_CHAIN(exthdrs.ip6e_hbh, mprev, - nexthdrp, IPPROTO_HOPOPTS); - MAKE_CHAIN(exthdrs.ip6e_dest1, mprev, - nexthdrp, IPPROTO_DSTOPTS); - MAKE_CHAIN(exthdrs.ip6e_rthdr, mprev, - nexthdrp, IPPROTO_ROUTING); + MAKE_CHAIN(exthdrs.ip6e_hbh, mprev, nexthdrp, IPPROTO_HOPOPTS); + MAKE_CHAIN(exthdrs.ip6e_dest1, mprev, nexthdrp, + IPPROTO_DSTOPTS); + MAKE_CHAIN(exthdrs.ip6e_rthdr, mprev, nexthdrp, + IPPROTO_ROUTING); #ifdef IPSEC if (!needipsec) @@ -407,20 +406,19 @@ skip_ipsec2:; * with the first hop of the routing header. */ if (exthdrs.ip6e_rthdr) { - struct ip6_rthdr *rh = - (struct ip6_rthdr *)(mtod(exthdrs.ip6e_rthdr, - struct ip6_rthdr *)); + struct ip6_rthdr *rh; struct ip6_rthdr0 *rh0; + rh = (struct ip6_rthdr *)(mtod(exthdrs.ip6e_rthdr, + struct ip6_rthdr *)); finaldst = ip6->ip6_dst; switch (rh->ip6r_type) { case IPV6_RTHDR_TYPE_0: rh0 = (struct ip6_rthdr0 *)rh; ip6->ip6_dst = rh0->ip6r0_addr[0]; bcopy((caddr_t)&rh0->ip6r0_addr[1], - (caddr_t)&rh0->ip6r0_addr[0], - sizeof(struct in6_addr) * (rh0->ip6r0_segleft - 1) - ); + (caddr_t)&rh0->ip6r0_addr[0], + sizeof(struct in6_addr) * (rh0->ip6r0_segleft - 1)); rh0->ip6r0_addr[rh0->ip6r0_segleft - 1] = finaldst; break; default: /* is it possible? */ @@ -461,8 +459,8 @@ skip_ipsec2:; * and is still up. If not, free it and try again. */ if (ro->ro_rt && ((ro->ro_rt->rt_flags & RTF_UP) == 0 || - dst->sin6_family != AF_INET6 || - !IN6_ARE_ADDR_EQUAL(&dst->sin6_addr, &ip6->ip6_dst))) { + dst->sin6_family != AF_INET6 || + !IN6_ARE_ADDR_EQUAL(&dst->sin6_addr, &ip6->ip6_dst))) { RTFREE(ro->ro_rt); ro->ro_rt = (struct rtentry *)0; } @@ -633,8 +631,7 @@ skip_ipsec2:; if (ifp == NULL) { if (ro->ro_rt == 0) { ro->ro_rt = rtalloc1((struct sockaddr *) - &ro->ro_dst, 0 - ); + &ro->ro_dst, 0); } if (ro->ro_rt == 0) { ip6stat.ip6s_noroute++; @@ -759,8 +756,7 @@ skip_ipsec2:; */ if (origifp == NULL) origifp = ifp; - } - else + } else origifp = ifp; if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src)) ip6->ip6_src.s6_addr16[1] = 0; @@ -785,11 +781,9 @@ skip_ipsec2:; */ m->m_flags |= M_LOOP; m->m_pkthdr.rcvif = ifp; - if (ip6_process_hopopts(m, - (u_int8_t *)(hbh + 1), - ((hbh->ip6h_len + 1) << 3) - - sizeof(struct ip6_hbh), - &dummy1, &dummy2) < 0) { + if (ip6_process_hopopts(m, (u_int8_t *)(hbh + 1), + ((hbh->ip6h_len + 1) << 3) - sizeof(struct ip6_hbh), + &dummy1, &dummy2) < 0) { /* m was already freed at this point */ error = EINVAL;/* better error? */ goto done; @@ -802,8 +796,7 @@ skip_ipsec2:; /* * Run through list of hooks for output packets. */ - if ((error = pfil_run_hooks(&inet6_pfil_hook, &m, ifp, - PFIL_OUT)) != 0) + if ((error = pfil_run_hooks(&inet6_pfil_hook, &m, ifp, PFIL_OUT)) != 0) goto done; if (m == NULL) goto done; @@ -814,22 +807,7 @@ skip_ipsec2:; * If necessary, do IPv6 fragmentation before sending. */ tlen = m->m_pkthdr.len; - if (tlen <= mtu -#ifdef notyet - /* - * On any link that cannot convey a 1280-octet packet in one piece, - * link-specific fragmentation and reassembly must be provided at - * a layer below IPv6. [RFC 2460, sec.5] - * Thus if the interface has ability of link-level fragmentation, - * we can just send the packet even if the packet size is - * larger than the link's MTU. - * XXX: IFF_FRAGMENTABLE (or such) flag has not been defined yet... - */ - - || ifp->if_flags & IFF_FRAGMENTABLE -#endif - ) - { + if (tlen <= mtu) { #ifdef IFA_STATS struct in6_ifaddr *ia6; ip6 = mtod(m, struct ip6_hdr *); @@ -930,8 +908,7 @@ skip_ipsec2:; else ip6f->ip6f_offlg |= IP6F_MORE_FRAG; mhip6->ip6_plen = htons((u_short)(len + hlen + - sizeof(*ip6f) - - sizeof(struct ip6_hdr))); + sizeof(*ip6f) - sizeof(struct ip6_hdr))); if ((m_frgpart = m_copy(m0, off, len)) == 0) { error = ENOBUFS; ip6stat.ip6s_odropped++; @@ -1151,7 +1128,7 @@ ip6_insertfraghdr(m0, m, hlen, frghdrp) if (hlen > sizeof(struct ip6_hdr)) { n = m_copym(m0, sizeof(struct ip6_hdr), - hlen - sizeof(struct ip6_hdr), M_DONTWAIT); + hlen - sizeof(struct ip6_hdr), M_DONTWAIT); if (n == 0) return(ENOBUFS); m->m_next = n; @@ -1165,8 +1142,8 @@ ip6_insertfraghdr(m0, m, hlen, frghdrp) if ((mlast->m_flags & M_EXT) == 0 && M_TRAILINGSPACE(mlast) >= sizeof(struct ip6_frag)) { /* use the trailing space of the last mbuf for the fragment hdr */ - *frghdrp = - (struct ip6_frag *)(mtod(mlast, caddr_t) + mlast->m_len); + *frghdrp = (struct ip6_frag *)(mtod(mlast, caddr_t) + + mlast->m_len); mlast->m_len += sizeof(struct ip6_frag); m->m_pkthdr.len += sizeof(struct ip6_frag); } else { @@ -1271,7 +1248,7 @@ ip6_ctloutput(op, so, level, optname, mp) case IPV6_PKTOPTIONS: /* m is freed in ip6_pcbopts */ return(ip6_pcbopts(&in6p->in6p_outputopts, - m, so)); + m, so)); case IPV6_HOPOPTS: case IPV6_DSTOPTS: if (p == 0 || suser(p->p_ucred, &p->p_acflag)) { @@ -1304,10 +1281,12 @@ ip6_ctloutput(op, so, level, optname, mp) } break; #define OPTSET(bit) \ -if (optval) \ - in6p->in6p_flags |= bit; \ -else \ - in6p->in6p_flags &= ~bit; +do { \ + if (optval) \ + in6p->in6p_flags |= (bit); \ + else \ + in6p->in6p_flags &= ~(bit); \ +} while (0) case IPV6_RECVOPTS: OPTSET(IN6P_RECVOPTS); @@ -1352,8 +1331,7 @@ else \ * see ipng mailing list, Jun 22 2001. */ if (in6p->in6p_lport || - !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) - { + !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) { error = EINVAL; break; } @@ -1373,7 +1351,8 @@ else \ case IPV6_MULTICAST_LOOP: case IPV6_JOIN_GROUP: case IPV6_LEAVE_GROUP: - error = ip6_setmoptions(optname, &in6p->in6p_moptions, m); + error = ip6_setmoptions(optname, + &in6p->in6p_moptions, m); break; case IPV6_PORTRANGE: @@ -1440,8 +1419,8 @@ else \ if (in6p->in6p_options) { m->m_len = in6p->in6p_options->m_len; bcopy(mtod(in6p->in6p_options, caddr_t), - mtod(m, caddr_t), - (unsigned)m->m_len); + mtod(m, caddr_t), + (unsigned)m->m_len); } else m->m_len = 0; break; @@ -1453,7 +1432,7 @@ else \ case IPV6_PKTOPTIONS: if (in6p->in6p_options) { *mp = m_copym(in6p->in6p_options, 0, - M_COPYALL, M_WAIT); + M_COPYALL, M_WAIT); } else { *mp = m_get(M_WAIT, MT_SOOPTS); (*mp)->m_len = 0; @@ -1801,8 +1780,8 @@ ip6_setmoptions(optname, im6op, m) * if the address has link-local scope. */ if (IN6_IS_ADDR_MC_LINKLOCAL(&mreq->ipv6mr_multiaddr)) { - mreq->ipv6mr_multiaddr.s6_addr16[1] - = htons(mreq->ipv6mr_interface); + mreq->ipv6mr_multiaddr.s6_addr16[1] = + htons(mreq->ipv6mr_interface); } /* * See if the membership already exists. @@ -1811,7 +1790,7 @@ ip6_setmoptions(optname, im6op, m) imm != NULL; imm = imm->i6mm_chain.le_next) if (imm->i6mm_maddr->in6m_ifp == ifp && IN6_ARE_ADDR_EQUAL(&imm->i6mm_maddr->in6m_addr, - &mreq->ipv6mr_multiaddr)) + &mreq->ipv6mr_multiaddr)) break; if (imm != NULL) { error = EADDRINUSE; @@ -1862,18 +1841,17 @@ ip6_setmoptions(optname, im6op, m) * if the address has link-local scope. */ if (IN6_IS_ADDR_MC_LINKLOCAL(&mreq->ipv6mr_multiaddr)) { - mreq->ipv6mr_multiaddr.s6_addr16[1] - = htons(mreq->ipv6mr_interface); + mreq->ipv6mr_multiaddr.s6_addr16[1] = + htons(mreq->ipv6mr_interface); } /* * Find the membership in the membership list. */ for (imm = im6o->im6o_memberships.lh_first; imm != NULL; imm = imm->i6mm_chain.le_next) { - if ((ifp == NULL || - imm->i6mm_maddr->in6m_ifp == ifp) && + if ((ifp == NULL || imm->i6mm_maddr->in6m_ifp == ifp) && IN6_ARE_ADDR_EQUAL(&imm->i6mm_maddr->in6m_addr, - &mreq->ipv6mr_multiaddr)) + &mreq->ipv6mr_multiaddr)) break; } if (imm == NULL) { @@ -2001,7 +1979,7 @@ ip6_setpktoptions(control, opt, priv) opt->ip6po_m = control; for (; control->m_len; control->m_data += CMSG_ALIGN(cm->cmsg_len), - control->m_len -= CMSG_ALIGN(cm->cmsg_len)) { + control->m_len -= CMSG_ALIGN(cm->cmsg_len)) { cm = mtod(control, struct cmsghdr *); if (cm->cmsg_len == 0 || cm->cmsg_len > control->m_len) return(EINVAL); @@ -2018,8 +1996,8 @@ ip6_setpktoptions(control, opt, priv) opt->ip6po_pktinfo->ipi6_addr.s6_addr16[1] = htons(opt->ip6po_pktinfo->ipi6_ifindex); - if (opt->ip6po_pktinfo->ipi6_ifindex > if_index - || opt->ip6po_pktinfo->ipi6_ifindex < 0) { + if (opt->ip6po_pktinfo->ipi6_ifindex > if_index || + opt->ip6po_pktinfo->ipi6_ifindex < 0) { return(ENXIO); } @@ -2074,8 +2052,8 @@ ip6_setpktoptions(control, opt, priv) if (!priv) return(EPERM); + /* check if cmsg_len is large enough for sa_len */ if (cm->cmsg_len < sizeof(u_char) || - /* check if cmsg_len is large enough for sa_len */ cm->cmsg_len < CMSG_LEN(*CMSG_DATA(cm))) return(EINVAL); @@ -2104,18 +2082,16 @@ ip6_setpktoptions(control, opt, priv) */ if (opt->ip6po_rthdr == NULL) { opt->ip6po_dest1 = - (struct ip6_dest *)CMSG_DATA(cm); + (struct ip6_dest *)CMSG_DATA(cm); if (cm->cmsg_len != - CMSG_LEN((opt->ip6po_dest1->ip6d_len + 1) - << 3)) + CMSG_LEN((opt->ip6po_dest1->ip6d_len + 1) << 3)); return(EINVAL); } else { opt->ip6po_dest2 = - (struct ip6_dest *)CMSG_DATA(cm); + (struct ip6_dest *)CMSG_DATA(cm); if (cm->cmsg_len != - CMSG_LEN((opt->ip6po_dest2->ip6d_len + 1) - << 3)) + CMSG_LEN((opt->ip6po_dest2->ip6d_len + 1) << 3)) return(EINVAL); } break;