2006-11-16 04:32:37 +03:00
|
|
|
/* $NetBSD: clnp_options.c,v 1.17 2006/11/16 01:33:51 christos Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*-
|
1994-05-13 10:08:03 +04:00
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-04-09 16:00:07 +04:00
|
|
|
* 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.
|
|
|
|
*
|
1994-06-29 10:29:24 +04:00
|
|
|
* @(#)clnp_options.c 8.1 (Berkeley) 6/10/93
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
Copyright IBM Corporation 1987
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
1993-04-09 16:00:07 +04:00
|
|
|
provided that the above copyright notice appear in all copies and that
|
1996-02-14 01:07:57 +03:00
|
|
|
both that copyright notice and this permission notice appear in
|
1993-04-09 16:00:07 +04:00
|
|
|
supporting documentation, and that the name of IBM not be
|
|
|
|
used in advertising or publicity pertaining to distribution of the
|
1996-02-14 01:07:57 +03:00
|
|
|
software without specific, written prior permission.
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
ANY 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 THIS
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
|
|
|
|
*/
|
|
|
|
|
2001-11-13 03:56:55 +03:00
|
|
|
#include <sys/cdefs.h>
|
2006-11-16 04:32:37 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: clnp_options.c,v 1.17 2006/11/16 01:33:51 christos Exp $");
|
2001-11-13 03:56:55 +03:00
|
|
|
|
1998-07-05 08:37:35 +04:00
|
|
|
#include "opt_iso.h"
|
1993-04-09 16:00:07 +04:00
|
|
|
#ifdef ISO
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#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>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <sys/systm.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netiso/iso.h>
|
|
|
|
#include <netiso/clnp.h>
|
|
|
|
#include <netiso/clnp_stat.h>
|
|
|
|
#include <netiso/argo_debug.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_update_srcrt
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Process src rt option accompanying a clnp datagram.
|
|
|
|
* - bump src route ptr if src routing and
|
|
|
|
* we appear current in src route list.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: none
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES: If source routing has been terminated, do nothing.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
void
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_update_srcrt(
|
|
|
|
struct mbuf *options, /* ptr to options mbuf */
|
|
|
|
struct clnp_optidx *oidx) /* ptr to option index */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
u_char len; /* length of current address */
|
|
|
|
struct iso_addr isoa; /* copy current address into here */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (CLNPSRCRT_TERM(oidx, options)) {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_update_srcrt: src rt terminated\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
len = CLNPSRCRT_CLEN(oidx, options);
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy(CLNPSRCRT_CADDR(oidx, options), (caddr_t) & isoa, len);
|
1993-04-09 16:00:07 +04:00
|
|
|
isoa.isoa_len = len;
|
1996-02-14 01:07:57 +03:00
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_update_srcrt: current src rt: %s\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
clnp_iso_addrp(&isoa));
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (clnp_ours(&isoa)) {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_update_srcrt: updating src rt\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* update pointer to next src route */
|
1996-02-14 01:07:57 +03:00
|
|
|
len++; /* count length byte too! */
|
1993-04-09 16:00:07 +04:00
|
|
|
CLNPSRCRT_OFF(oidx, options) += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_dooptions
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Process options accompanying a clnp datagram.
|
|
|
|
* Processing includes
|
|
|
|
* - log our address if recording route
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* RETURNS: none
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
void
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_dooptions(
|
2006-10-12 05:30:41 +04:00
|
|
|
struct mbuf *options, /* ptr to options mbuf */
|
|
|
|
struct clnp_optidx *oidx, /* ptr to option index */
|
2006-11-16 04:32:37 +03:00
|
|
|
struct ifnet *ifp, /* ptr to interface pkt is leaving on */
|
2006-10-12 05:30:41 +04:00
|
|
|
struct iso_addr *isoa) /* ptr to our address for this ifp */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If record route is specified, move all
|
|
|
|
* existing records over, and insert the address of
|
|
|
|
* interface passed
|
|
|
|
*/
|
|
|
|
if (oidx->cni_recrtp) {
|
1996-02-14 01:07:57 +03:00
|
|
|
char *opt; /* ptr to beginning of recrt option */
|
|
|
|
u_char off; /* offset from opt of first free byte */
|
|
|
|
char *rec_start; /* beginning of new rt
|
|
|
|
* recorded */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
opt = CLNP_OFFTOOPT(options, oidx->cni_recrtp);
|
|
|
|
off = *(opt + 1);
|
|
|
|
rec_start = opt + off - 1;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_dooptions: record route: option %p for %d bytes\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
opt, oidx->cni_recrt_len);
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("\tfree slot offset x%x\n", off);
|
|
|
|
printf("clnp_dooptions: recording %s\n", clnp_iso_addrp(isoa));
|
|
|
|
printf("clnp_dooptions: option dump:\n");
|
1993-04-09 16:00:07 +04:00
|
|
|
dump_buf(opt, oidx->cni_recrt_len);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* proceed only if recording has not been terminated */
|
|
|
|
if (off != 0xff) {
|
1996-02-14 01:07:57 +03:00
|
|
|
int new_addrlen = isoa->isoa_len + 1;
|
|
|
|
/*
|
|
|
|
* if there is insufficient room to store the next
|
|
|
|
* address, then terminate recording. Plus 1 on
|
|
|
|
* isoa_len is for the length byte itself
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (oidx->cni_recrt_len - (off - 1) < new_addrlen) {
|
|
|
|
*(opt + 1) = 0xff; /* terminate recording */
|
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_dooptions: new addr at %p for %d\n",
|
1996-04-13 05:34:06 +04:00
|
|
|
rec_start, new_addrlen);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy((caddr_t) isoa, rec_start, new_addrlen);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* update offset field */
|
|
|
|
*(opt + 1) += new_addrlen;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_dooptions: new option dump:\n");
|
1993-04-09 16:00:07 +04:00
|
|
|
dump_buf(opt, oidx->cni_recrt_len);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_set_opts
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Check the data mbuf passed for option sanity. If it is
|
|
|
|
* ok, then set the options ptr to address the data mbuf.
|
|
|
|
* If an options mbuf exists, free it. This implies that
|
|
|
|
* any old options will be lost. If data is NULL, simply
|
|
|
|
* free any old options.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: unix error code
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES:
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_set_opts(
|
|
|
|
struct mbuf **options, /* target for option information */
|
|
|
|
struct mbuf **data) /* source of option information */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
int error = 0; /* error return value */
|
|
|
|
struct clnp_optidx dummy; /* dummy index - not used */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* remove any existing options
|
|
|
|
*/
|
|
|
|
if (*options != NULL) {
|
|
|
|
m_freem(*options);
|
|
|
|
*options = NULL;
|
|
|
|
}
|
|
|
|
if (*data != NULL) {
|
|
|
|
/*
|
|
|
|
* Insure that the options are reasonable.
|
|
|
|
*
|
|
|
|
* Also, we do not support security, priority,
|
|
|
|
* nor do we allow one to send an ER option
|
|
|
|
*
|
|
|
|
* The QOS parameter is checked for the DECBIT.
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((clnp_opt_sanity(*data, mtod(*data, caddr_t), (*data)->m_len,
|
|
|
|
&dummy) != 0) ||
|
|
|
|
(dummy.cni_securep) ||
|
|
|
|
(dummy.cni_priorp) ||
|
|
|
|
(dummy.cni_er_reason != ER_INVALREAS)) {
|
1993-04-09 16:00:07 +04:00
|
|
|
error = EINVAL;
|
|
|
|
} else {
|
|
|
|
*options = *data;
|
|
|
|
*data = NULL; /* so caller won't free mbuf @ *data */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION: clnp_opt_sanity
|
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* PURPOSE: Check the options (beginning at opts for len bytes) for
|
|
|
|
* sanity. In addition, fill in the option index structure
|
|
|
|
* in with information about each option discovered.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* RETURNS: success (options check out) - 0
|
|
|
|
* failure - an ER pdu error code describing failure
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* SIDE EFFECTS:
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
1996-02-14 01:07:57 +03:00
|
|
|
* NOTES: Each pointer field of the option index is filled in with
|
|
|
|
* the offset from the beginning of the mbuf data, not the
|
|
|
|
* actual address.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
2004-04-19 09:16:45 +04:00
|
|
|
clnp_opt_sanity(
|
|
|
|
struct mbuf *m, /* mbuf options reside in */
|
|
|
|
caddr_t opts, /* ptr to buffer containing options */
|
|
|
|
int len, /* length of buffer */
|
|
|
|
struct clnp_optidx *oidx) /* RETURN: filled in with option idx
|
1996-02-14 01:07:57 +03:00
|
|
|
* info */
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
u_char opcode = 0; /* code of particular option */
|
|
|
|
u_char oplen; /* length of a particular option */
|
|
|
|
caddr_t opts_end; /* ptr to end of options */
|
|
|
|
u_char pad = 0, secure = 0, srcrt = 0, recrt = 0,
|
|
|
|
qos = 0, prior = 0;
|
|
|
|
/* flags for catching duplicate options */
|
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_opt_sanity: checking %d bytes of data:\n", len);
|
1993-04-09 16:00:07 +04:00
|
|
|
dump_buf(opts, len);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* clear option index field if passed */
|
1996-02-14 01:07:57 +03:00
|
|
|
bzero((caddr_t) oidx, sizeof(struct clnp_optidx));
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to indicate whether the ER option is present. This is done
|
2001-11-21 22:01:31 +03:00
|
|
|
* by overloading the er_reason field to also indicate presence of
|
1993-04-09 16:00:07 +04:00
|
|
|
* the option along with the option value. I would like ER_INVALREAS
|
|
|
|
* to have value 0, but alas, 0 is a valid er reason...
|
|
|
|
*/
|
|
|
|
oidx->cni_er_reason = ER_INVALREAS;
|
|
|
|
|
|
|
|
opts_end = opts + len;
|
|
|
|
while (opts < opts_end) {
|
|
|
|
/* must have at least 2 bytes per option (opcode and len) */
|
|
|
|
if (opts + 2 > opts_end)
|
1996-02-14 01:07:57 +03:00
|
|
|
return (GEN_INCOMPLETE);
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
opcode = *opts++;
|
|
|
|
oplen = *opts++;
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_opt_sanity: opcode is %x and oplen %d\n",
|
1996-10-11 03:12:43 +04:00
|
|
|
opcode, oplen);
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_opt_sanity: clnpoval_SRCRT is %x\n", CLNPOVAL_SRCRT);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
switch (opcode) {
|
1996-10-11 03:12:43 +04:00
|
|
|
case CLNPOVAL_PAD:
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("CLNPOVAL_PAD\n");
|
1996-10-11 03:12:43 +04:00
|
|
|
break;
|
|
|
|
case CLNPOVAL_SECURE:
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("CLNPOVAL_SECURE\n");
|
1996-10-11 03:12:43 +04:00
|
|
|
break;
|
|
|
|
case CLNPOVAL_SRCRT:
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("CLNPOVAL_SRCRT\n");
|
1996-10-11 03:12:43 +04:00
|
|
|
break;
|
|
|
|
case CLNPOVAL_RECRT:
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("CLNPOVAL_RECRT\n");
|
1996-10-11 03:12:43 +04:00
|
|
|
break;
|
|
|
|
case CLNPOVAL_QOS:
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("CLNPOVAL_QOS\n");
|
1996-10-11 03:12:43 +04:00
|
|
|
break;
|
|
|
|
case CLNPOVAL_PRIOR:
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("CLNPOVAL_PRIOR\n");
|
1996-10-11 03:12:43 +04:00
|
|
|
break;
|
|
|
|
case CLNPOVAL_ERREAS:
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("CLNPOVAL_ERREAS\n");
|
1996-10-11 03:12:43 +04:00
|
|
|
break;
|
1996-02-14 01:07:57 +03:00
|
|
|
default:
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("UNKNOWN option %x\n", opcode);
|
1996-10-11 03:12:43 +04:00
|
|
|
break;
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* don't allow crazy length values */
|
|
|
|
if (opts + oplen > opts_end)
|
1996-02-14 01:07:57 +03:00
|
|
|
return (GEN_INCOMPLETE);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
switch (opcode) {
|
1996-02-14 01:07:57 +03:00
|
|
|
case CLNPOVAL_PAD:
|
|
|
|
/*
|
|
|
|
* Padding: increment pointer by length of padding
|
|
|
|
*/
|
|
|
|
if (pad++) /* duplicate ? */
|
|
|
|
return (GEN_DUPOPT);
|
|
|
|
opts += oplen;
|
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
case CLNPOVAL_SECURE:{
|
|
|
|
u_char format = *opts;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
if (secure++) /* duplicate ? */
|
|
|
|
return (GEN_DUPOPT);
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* Security: high 2 bits of first octet indicate format
|
|
|
|
* (00 in high bits is reserved).
|
|
|
|
* Remaining bits must be 0. Remaining octets indicate
|
|
|
|
* actual security
|
|
|
|
*/
|
|
|
|
if (((format & 0x3f) > 0) || /* low 6 bits set ? */
|
1996-02-14 01:07:57 +03:00
|
|
|
((format & 0xc0) == 0)) /* high 2 bits zero ? */
|
|
|
|
return (GEN_HDRSYNTAX);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
oidx->cni_securep = CLNP_OPTTOOFF(m, opts);
|
|
|
|
oidx->cni_secure_len = oplen;
|
|
|
|
opts += oplen;
|
|
|
|
} break;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
case CLNPOVAL_SRCRT:{
|
|
|
|
u_char type, offset; /* type of rt, offset of
|
|
|
|
* start */
|
|
|
|
caddr_t route_end; /* address of end of
|
|
|
|
* route option */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_opt_sanity: SRC RT\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (srcrt++) /* duplicate ? */
|
|
|
|
return (GEN_DUPOPT);
|
|
|
|
/*
|
|
|
|
* source route: There must be 2 bytes
|
|
|
|
* following the length field: type and
|
|
|
|
* offset. The type must be either partial
|
|
|
|
* route or complete route. The offset field
|
|
|
|
* must be within the option. A single
|
|
|
|
* exception is made, however. The offset may
|
|
|
|
* be 1 greater than the length. This case
|
|
|
|
* occurs when the last source route record
|
|
|
|
* is consumed. In this case, we ignore the
|
|
|
|
* source route option. RAH? You should be
|
|
|
|
* able to set offset to 'ff' like in record
|
|
|
|
* route! Following this is a series of
|
|
|
|
* address fields. Each address field is
|
|
|
|
* composed of a (length, address) pair.
|
|
|
|
* Insure that the offset and each address
|
|
|
|
* length is reasonable
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
route_end = opts + oplen;
|
|
|
|
|
|
|
|
if (opts + 2 > route_end)
|
1996-02-14 01:07:57 +03:00
|
|
|
return (SRCRT_SYNTAX);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
type = *opts;
|
1996-02-14 01:07:57 +03:00
|
|
|
offset = *(opts + 1);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* type must be partial or complete */
|
|
|
|
if (!((type == CLNPOVAL_PARTRT) || (type == CLNPOVAL_COMPRT)))
|
1996-02-14 01:07:57 +03:00
|
|
|
return (SRCRT_SYNTAX);
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
oidx->cni_srcrt_s = CLNP_OPTTOOFF(m, opts);
|
|
|
|
oidx->cni_srcrt_len = oplen;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
opts += offset - 1; /* set opts to first
|
|
|
|
* addr in rt */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* Offset must be reasonable: less than end
|
|
|
|
* of options, or equal to end of options
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
if (opts >= route_end) {
|
|
|
|
if (opts == route_end) {
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_opt_sanity: end of src route info\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
1996-02-14 01:07:57 +03:00
|
|
|
} else
|
|
|
|
return (SRCRT_SYNTAX);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
while (opts < route_end) {
|
1996-02-14 01:07:57 +03:00
|
|
|
u_char addrlen = *opts++;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (opts + addrlen > route_end)
|
1996-02-14 01:07:57 +03:00
|
|
|
return (SRCRT_SYNTAX);
|
1993-04-09 16:00:07 +04:00
|
|
|
opts += addrlen;
|
|
|
|
}
|
|
|
|
} break;
|
1996-02-14 01:07:57 +03:00
|
|
|
case CLNPOVAL_RECRT:{
|
|
|
|
u_char type, offset; /* type of rt, offset of
|
|
|
|
* start */
|
|
|
|
caddr_t record_end; /* address of end of
|
|
|
|
* record option */
|
|
|
|
|
|
|
|
if (recrt++) /* duplicate ? */
|
|
|
|
return (GEN_DUPOPT);
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* record route: after the length field, expect a
|
|
|
|
* type and offset. Type must be partial or complete.
|
|
|
|
* Offset indicates where to start recording. Insure it
|
|
|
|
* is within the option. All ones for offset means
|
|
|
|
* recording is terminated.
|
|
|
|
*/
|
|
|
|
record_end = opts + oplen;
|
|
|
|
|
|
|
|
oidx->cni_recrtp = CLNP_OPTTOOFF(m, opts);
|
|
|
|
oidx->cni_recrt_len = oplen;
|
|
|
|
|
|
|
|
if (opts + 2 > record_end)
|
1996-02-14 01:07:57 +03:00
|
|
|
return (GEN_INCOMPLETE);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
type = *opts;
|
1996-02-14 01:07:57 +03:00
|
|
|
offset = *(opts + 1);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/* type must be partial or complete */
|
|
|
|
if (!((type == CLNPOVAL_PARTRT) || (type == CLNPOVAL_COMPRT)))
|
1996-02-14 01:07:57 +03:00
|
|
|
return (GEN_HDRSYNTAX);
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/* offset must be reasonable */
|
|
|
|
if ((offset < 0xff) && (opts + offset > record_end))
|
1996-02-14 01:07:57 +03:00
|
|
|
return (GEN_HDRSYNTAX);
|
1993-04-09 16:00:07 +04:00
|
|
|
opts += oplen;
|
|
|
|
} break;
|
1996-02-14 01:07:57 +03:00
|
|
|
case CLNPOVAL_QOS:{
|
|
|
|
u_char format = *opts;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
if (qos++) /* duplicate ? */
|
|
|
|
return (GEN_DUPOPT);
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* qos: high 2 bits of first octet indicate format
|
|
|
|
* (00 in high bits is reserved).
|
|
|
|
* Remaining bits must be 0 (unless format indicates
|
|
|
|
* globally unique qos, in which case remaining bits indicate
|
|
|
|
* qos (except bit 6 which is reserved)). Otherwise,
|
|
|
|
* remaining octets indicate actual qos.
|
|
|
|
*/
|
|
|
|
if (((format & 0xc0) == 0) || /* high 2 bits zero ? */
|
1996-02-14 01:07:57 +03:00
|
|
|
(((format & 0xc0) != CLNPOVAL_GLOBAL) &&
|
|
|
|
((format & 0x3f) > 0))) /* not global,low bits
|
|
|
|
* used ? */
|
|
|
|
return (GEN_HDRSYNTAX);
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
oidx->cni_qos_formatp = CLNP_OPTTOOFF(m, opts);
|
|
|
|
oidx->cni_qos_len = oplen;
|
|
|
|
|
|
|
|
opts += oplen;
|
|
|
|
} break;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
case CLNPOVAL_PRIOR:{
|
|
|
|
if (prior++) /* duplicate ? */
|
|
|
|
return (GEN_DUPOPT);
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* priority: value must be one byte long
|
|
|
|
*/
|
|
|
|
if (oplen != 1)
|
1996-02-14 01:07:57 +03:00
|
|
|
return (GEN_HDRSYNTAX);
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
oidx->cni_priorp = CLNP_OPTTOOFF(m, opts);
|
|
|
|
|
|
|
|
opts += oplen;
|
|
|
|
} break;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
case CLNPOVAL_ERREAS:{
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* er reason: value must be two bytes long
|
|
|
|
*/
|
|
|
|
if (oplen != 2)
|
1996-02-14 01:07:57 +03:00
|
|
|
return (GEN_HDRSYNTAX);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
oidx->cni_er_reason = *opts;
|
|
|
|
|
|
|
|
opts += oplen;
|
|
|
|
} break;
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
default:{
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_opt_sanity: UNKNOWN OPTION 0x%x\n", opcode);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return (DISC_UNSUPPOPT);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_OPTIONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("clnp_opt_sanity: return(0)\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return (0);
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
#endif /* ISO */
|