* Copyright (c) 1991 The Regents of the University of California.
* %sccs.include.redist.c%
* @(#)clnp_options.c 7.8 (Berkeley) %G%
/***********************************************************
Copyright IBM Corporation 1987
Permission 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 that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of IBM not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
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
******************************************************************/
* ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
/* $Header: /var/src/sys/netiso/RCS/clnp_options.c,v 5.1 89/02/09 16:20:37 hagens Exp $ */
/* $Source: /var/src/sys/netiso/RCS/clnp_options.c,v $ */
#include "../net/route.h"
* FUNCTION: clnp_update_srcrt
* PURPOSE: Process src rt option accompanying a clnp datagram.
* - bump src route ptr if src routing and
* we appear current in src route list.
* NOTES: If source routing has been terminated, do nothing.
clnp_update_srcrt(options
, oidx
)
struct mbuf
*options
; /* ptr to options mbuf */
struct clnp_optidx
*oidx
; /* ptr to option index */
u_char len
; /* length of current address */
struct iso_addr isoa
; /* copy current address into here */
if (CLNPSRCRT_TERM(oidx
, options
)) {
printf("clnp_update_srcrt: src rt terminated\n");
len
= CLNPSRCRT_CLEN(oidx
, options
);
bcopy(CLNPSRCRT_CADDR(oidx
, options
), (caddr_t
)&isoa
, len
);
printf("clnp_update_srcrt: current src rt: %s\n",
printf("clnp_update_srcrt: updating src rt\n");
/* update pointer to next src route */
len
++; /* count length byte too! */
CLNPSRCRT_OFF(oidx
, options
) += len
;
* FUNCTION: clnp_dooptions
* PURPOSE: Process options accompanying a clnp datagram.
* - log our address if recording route
clnp_dooptions(options
, oidx
, ifp
, isoa
)
struct mbuf
*options
; /* ptr to options mbuf */
struct clnp_optidx
*oidx
; /* ptr to option index */
struct ifnet
*ifp
; /* ptr to interface pkt is leaving on */
struct iso_addr
*isoa
; /* ptr to our address for this ifp */
* If record route is specified, move all
* existing records over, and insert the address of
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 */
opt
= CLNP_OFFTOOPT(options
, oidx
->cni_recrtp
);
rec_start
= opt
+ off
- 1;
printf("clnp_dooptions: record route: option x%x for %d bytes\n",
opt
, oidx
->cni_recrt_len
);
printf("\tfree slot offset x%x\n", off
);
printf("clnp_dooptions: recording %s\n", clnp_iso_addrp(isoa
));
printf("clnp_dooptions: option dump:\n");
dump_buf(opt
, oidx
->cni_recrt_len
);
/* proceed only if recording has not been terminated */
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
if (oidx
->cni_recrt_len
- (off
- 1) < new_addrlen
) {
*(opt
+ 1) = 0xff; /* terminate recording */
printf("clnp_dooptions: new addr at x%x for %d\n",
bcopy((caddr_t
)isoa
, rec_start
, new_addrlen
);
/* update offset field */
*(opt
+ 1) += new_addrlen
;
printf("clnp_dooptions: new option dump:\n");
dump_buf(opt
, oidx
->cni_recrt_len
);
* FUNCTION: clnp_set_opts
* 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
* RETURNS: unix error code
clnp_set_opts(options
, data
)
struct mbuf
**options
; /* target for option information */
struct mbuf
**data
; /* source of option information */
int error
= 0; /* error return value */
struct clnp_optidx dummy
; /* dummy index - not used */
* remove any existing options
* 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.
if ((clnp_opt_sanity(*data
, mtod(*data
, caddr_t
), (*data
)->m_len
,
(dummy
.cni_er_reason
!= ER_INVALREAS
)) {
*data
= NULL
; /* so caller won't free mbuf @ *data */
* FUNCTION: clnp_opt_sanity
* 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.
* RETURNS: success (options check out) - 0
* failure - an ER pdu error code describing failure
* NOTES: Each pointer field of the option index is filled in with
* the offset from the beginning of the mbuf data, not the
clnp_opt_sanity(m
, opts
, len
, oidx
)
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 info */
u_char opcode
; /* 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 */
printf("clnp_opt_sanity: checking %d bytes of data:\n", len
);
/* clear option index field if passed */
bzero((caddr_t
)oidx
, sizeof(struct clnp_optidx
));
* We need to indicate whether the ER option is present. This is done
* by overloading the er_reason field to also indicate presense of
* 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
;
while (opts
< opts_end
) {
/* must have at least 2 bytes per option (opcode and len) */
printf("clnp_opt_sanity: opcode is %x and oplen %d\n",
printf("clnp_opt_sanity: clnpoval_SRCRT is %x\n", CLNPOVAL_SRCRT
);
printf("CLNPOVAL_PAD\n");
printf("CLNPOVAL_SECURE\n");
printf("CLNPOVAL_SRCRT\n");
printf("CLNPOVAL_RECRT\n");
printf("CLNPOVAL_QOS\n");
printf("CLNPOVAL_PRIOR\n");
printf("CLNPOVAL_ERREAS\n");
printf("UKNOWN option %x\n", opcode
);
/* don't allow crazy length values */
if (opts
+ oplen
> opts_end
)
* Padding: increment pointer by length of padding
if (pad
++) /* duplicate ? */
if (secure
++) /* duplicate ? */
* Security: high 2 bits of first octet indicate format
* (00 in high bits is reserved).
* Remaining bits must be 0. Remaining octets indicate
if (((format
& 0x3f) > 0) || /* low 6 bits set ? */
((format
& 0xc0) == 0)) /* high 2 bits zero ? */
oidx
->cni_securep
= CLNP_OPTTOOFF(m
, opts
);
oidx
->cni_secure_len
= oplen
;
u_char type
, offset
; /* type of rt, offset of start */
caddr_t route_end
; /* address of end of route option */
printf("clnp_opt_sanity: SRC RT\n");
if (srcrt
++) /* duplicate ? */
* 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
* 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
route_end
= opts
+ oplen
;
if (opts
+ 2 > route_end
)
/* type must be partial or complete */
if (!((type
== CLNPOVAL_PARTRT
) || (type
== CLNPOVAL_COMPRT
)))
oidx
->cni_srcrt_s
= CLNP_OPTTOOFF(m
, opts
);
oidx
->cni_srcrt_len
= oplen
;
opts
+= offset
-1; /*set opts to first addr in rt */
* Offset must be reasonable:
* less than end of options, or equal to end of options
printf("clnp_opt_sanity: end of src route info\n");
while (opts
< route_end
) {
u_char addrlen
= *opts
++;
if (opts
+ addrlen
> route_end
)
u_char type
, offset
; /* type of rt, offset of start */
caddr_t record_end
; /* address of end of record option */
if (recrt
++) /* duplicate ? */
* 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
)
/* type must be partial or complete */
if (!((type
== CLNPOVAL_PARTRT
) || (type
== CLNPOVAL_COMPRT
)))
/* offset must be reasonable */
if ((offset
< 0xff) && (opts
+ offset
> record_end
))
if (qos
++) /* duplicate ? */
* 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 ? */
(((format
& 0xc0) != CLNPOVAL_GLOBAL
) &&
((format
& 0x3f) > 0))) /* not global,low bits used ? */
oidx
->cni_qos_formatp
= CLNP_OPTTOOFF(m
, opts
);
oidx
->cni_qos_len
= oplen
;
if (prior
++) /* duplicate ? */
* priority: value must be one byte long
oidx
->cni_priorp
= CLNP_OPTTOOFF(m
, opts
);
* er reason: value must be two bytes long
oidx
->cni_er_reason
= *opts
;
printf("clnp_opt_sanity: UNKNOWN OPTION 0x%x\n", opcode
);
printf("clnp_opt_sanity: return(0)\n", opcode
);