📄 clnp_output.c
字号:
/*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)clnp_output.c 8.1 (Berkeley) 6/10/93 *//*********************************************************** Copyright IBM Corporation 1987 All Rights ReservedPermission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear in supporting documentation, and that the name of IBM not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLIBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.******************************************************************//* * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison *//* $Header: /var/src/sys/netiso/RCS/clnp_output.c,v 5.0 89/02/08 12:00:15 hagens Exp $ *//* $Source: /var/src/sys/netiso/RCS/clnp_output.c,v $ */#include <sys/param.h>#include <sys/mbuf.h>#include <sys/domain.h>#include <sys/protosw.h>#include <sys/socket.h>#include <sys/socketvar.h>#include <sys/errno.h>#include <sys/time.h>#include <net/if.h>#include <net/route.h>#include <netiso/iso.h>#include <netiso/iso_var.h>#include <netiso/iso_pcb.h>#include <netiso/clnp.h>#include <netiso/clnp_stat.h>#include <netiso/argo_debug.h>static struct clnp_fixed dt_template = { ISO8473_CLNP, /* network identifier */ 0, /* length */ ISO8473_V1, /* version */ CLNP_TTL, /* ttl */ CLNP_DT|CNF_SEG_OK|CNF_ERR_OK, /* type */ 0, /* segment length */ 0 /* checksum */};static struct clnp_fixed raw_template = { ISO8473_CLNP, /* network identifier */ 0, /* length */ ISO8473_V1, /* version */ CLNP_TTL, /* ttl */ CLNP_RAW|CNF_SEG_OK|CNF_ERR_OK, /* type */ 0, /* segment length */ 0 /* checksum */};static struct clnp_fixed echo_template = { ISO8473_CLNP, /* network identifier */ 0, /* length */ ISO8473_V1, /* version */ CLNP_TTL, /* ttl */ CLNP_EC|CNF_SEG_OK|CNF_ERR_OK, /* type */ 0, /* segment length */ 0 /* checksum */};static struct clnp_fixed echor_template = { ISO8473_CLNP, /* network identifier */ 0, /* length */ ISO8473_V1, /* version */ CLNP_TTL, /* ttl */ CLNP_ECR|CNF_SEG_OK|CNF_ERR_OK, /* type */ 0, /* segment length */ 0 /* checksum */};#ifdef DECBITu_char qos_option[] = {CLNPOVAL_QOS, 1, CLNPOVAL_GLOBAL|CLNPOVAL_SEQUENCING|CLNPOVAL_LOWDELAY};#endif /* DECBIT */int clnp_id = 0; /* id for segmented dgrams *//* * FUNCTION: clnp_output * * PURPOSE: output the data in the mbuf as a clnp datagram * * The data specified by m0 is sent as a clnp datagram. * The mbuf chain m0 will be freed when this routine has * returned. * * If options is non-null, it points to an mbuf which contains * options to be sent with the datagram. The options must * be formatted in the mbuf according to clnp rules. Options * will not be freed. * * Datalen specifies the length of the data in m0. * * Src and dst are the addresses for the packet. * * If route is non-null, it is used as the route for * the packet. * * By default, a DT is sent. However, if flags & CNLP_SEND_ER * then an ER will be sent. If flags & CLNP_SEND_RAW, then * the packet will be send as raw clnp. * * RETURNS: 0 success * appropriate error code * * SIDE EFFECTS: none * * NOTES: * Flags are interpretated as follows: * CLNP_NO_SEG - do not allow this pkt to be segmented. * CLNP_NO_ER - have pkt request ER suppression. * CLNP_SEND_RAW - send pkt as RAW DT rather than TP DT * CLNP_NO_CKSUM - don't compute clnp checksum * CLNP_ECHO - send as ECHO packet * * When checking for a cached packet, clnp checks * that the route taken is still up. It does not * check that the route is still to the same destination. * This means that any entity that alters an existing * route for an isopcb (such as when a redirect arrives) * must invalidate the clnp cache. It might be perferable * to have clnp check that the route has the same dest, but * by avoiding this check, we save a call to iso_addrmatch1. */clnp_output(m0, isop, datalen, flags)struct mbuf *m0; /* data for the packet */struct isopcb *isop; /* iso pcb */int datalen; /* number of bytes of data in m0 */int flags; /* flags */{ int error = 0; /* return value of function */ register struct mbuf *m = m0; /* mbuf for clnp header chain */ register struct clnp_fixed *clnp; /* ptr to fixed part of hdr */ register caddr_t hoff; /* offset into header */ int total_len; /* total length of packet */ struct iso_addr *src; /* ptr to source address */ struct iso_addr *dst; /* ptr to destination address */ struct clnp_cache clc; /* storage for cache information */ struct clnp_cache *clcp = NULL; /* ptr to clc */ int hdrlen = 0; dst = &isop->isop_faddr->siso_addr; if (isop->isop_laddr == 0) { struct iso_ifaddr *ia = 0; clnp_route(dst, &isop->isop_route, flags, 0, &ia); if (ia == 0 || ia->ia_ifa.ifa_addr->sa_family != AF_ISO) return (ENETUNREACH); src = &ia->ia_addr.siso_addr; } else src = &isop->isop_laddr->siso_addr; IFDEBUG(D_OUTPUT) printf("clnp_output: to %s", clnp_iso_addrp(dst)); printf(" from %s of %d bytes\n", clnp_iso_addrp(src), datalen); printf("\toptions x%x, flags x%x, isop_clnpcache x%x\n", isop->isop_options, flags, isop->isop_clnpcache); ENDDEBUG if (isop->isop_clnpcache != NULL) { clcp = mtod(isop->isop_clnpcache, struct clnp_cache *); } /* * Check if cache is valid ... */ IFDEBUG(D_OUTPUT) printf("clnp_output: ck cache: clcp %x\n", clcp); if (clcp != NULL) { printf("\tclc_dst %s\n", clnp_iso_addrp(&clcp->clc_dst)); printf("\tisop_opts x%x, clc_opts x%x\n", isop->isop_options, clcp->clc_options); if (isop->isop_route.ro_rt) printf("\tro_rt x%x, rt_flags x%x\n", isop->isop_route.ro_rt, isop->isop_route.ro_rt->rt_flags); printf("\tflags x%x, clc_flags x%x\n", flags, clcp->clc_flags); printf("\tclc_hdr x%x\n", clcp->clc_hdr); } ENDDEBUG if ((clcp != NULL) && /* cache exists */ (isop->isop_options == clcp->clc_options) && /* same options */ (iso_addrmatch1(dst, &clcp->clc_dst)) && /* dst still same */ (isop->isop_route.ro_rt != NULL) && /* route exists */ (isop->isop_route.ro_rt == clcp->clc_rt) && /* and is cached */ (isop->isop_route.ro_rt->rt_flags & RTF_UP) && /* route still up */ (flags == clcp->clc_flags) && /* same flags */ (clcp->clc_hdr != NULL)) { /* hdr mbuf exists */ /* * The cache is valid */ IFDEBUG(D_OUTPUT) printf("clnp_output: using cache\n"); ENDDEBUG m = m_copy(clcp->clc_hdr, 0, (int)M_COPYALL); if (m == NULL) { /* * No buffers left to copy cached packet header. Use * the cached packet header this time, and * mark the hdr as vacant */ m = clcp->clc_hdr; clcp->clc_hdr = NULL; } m->m_next = m0; /* ASSUMES pkt hdr is 1 mbuf long */ clnp = mtod(m, struct clnp_fixed *); } else { struct clnp_optidx *oidx = NULL; /* index to clnp options */ /* * The cache is not valid. Allocate an mbuf (if necessary) * to hold cached info. If one is not available, then * don't bother with the cache */ INCSTAT(cns_cachemiss); if (flags & CLNP_NOCACHE) { clcp = &clc; } else { if (isop->isop_clnpcache == NULL) { /* * There is no clnpcache. Allocate an mbuf to hold one */ if ((isop->isop_clnpcache = m_get(M_DONTWAIT, MT_HEADER)) == NULL) { /* * No mbufs available. Pretend that we don't want * caching this time. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -