xref: /csrg-svn/sys/netiso/clnp_options.c (revision 49267)
1*49267Sbostic /*-
2*49267Sbostic  * Copyright (c) 1991 The Regents of the University of California.
3*49267Sbostic  * All rights reserved.
4*49267Sbostic  *
5*49267Sbostic  * %sccs.include.redist.c%
6*49267Sbostic  *
7*49267Sbostic  *	@(#)clnp_options.c	7.8 (Berkeley) 05/06/91
8*49267Sbostic  */
9*49267Sbostic 
1036371Ssklower /***********************************************************
1136371Ssklower 		Copyright IBM Corporation 1987
1236371Ssklower 
1336371Ssklower                       All Rights Reserved
1436371Ssklower 
1536371Ssklower Permission to use, copy, modify, and distribute this software and its
1636371Ssklower documentation for any purpose and without fee is hereby granted,
1736371Ssklower provided that the above copyright notice appear in all copies and that
1836371Ssklower both that copyright notice and this permission notice appear in
1936371Ssklower supporting documentation, and that the name of IBM not be
2036371Ssklower used in advertising or publicity pertaining to distribution of the
2136371Ssklower software without specific, written prior permission.
2236371Ssklower 
2336371Ssklower IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
2436371Ssklower ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
2536371Ssklower IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
2636371Ssklower ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
2736371Ssklower WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
2836371Ssklower ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
2936371Ssklower SOFTWARE.
3036371Ssklower 
3136371Ssklower ******************************************************************/
3236371Ssklower 
3336371Ssklower /*
3436371Ssklower  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
3536371Ssklower  */
3636767Ssklower /* $Header: /var/src/sys/netiso/RCS/clnp_options.c,v 5.1 89/02/09 16:20:37 hagens Exp $ */
3736767Ssklower /* $Source: /var/src/sys/netiso/RCS/clnp_options.c,v $ */
3836371Ssklower 
3936371Ssklower #ifdef ISO
4036371Ssklower 
4137536Smckusick #include "types.h"
4237536Smckusick #include "param.h"
4337536Smckusick #include "mbuf.h"
4437536Smckusick #include "domain.h"
4537536Smckusick #include "protosw.h"
4637536Smckusick #include "socket.h"
4737536Smckusick #include "socketvar.h"
4837536Smckusick #include "errno.h"
4936371Ssklower 
5036371Ssklower #include "../net/if.h"
5136371Ssklower #include "../net/route.h"
5236371Ssklower 
5337469Ssklower #include "iso.h"
5437469Ssklower #include "clnp.h"
5537469Ssklower #include "clnp_stat.h"
5637469Ssklower #include "argo_debug.h"
5736371Ssklower 
5836371Ssklower /*
5936371Ssklower  * FUNCTION:		clnp_update_srcrt
6036371Ssklower  *
6136371Ssklower  * PURPOSE:			Process src rt option accompanying a clnp datagram.
6236371Ssklower  *						- bump src route ptr if src routing and
6336371Ssklower  *							we appear current in src route list.
6436371Ssklower  *
6536371Ssklower  * RETURNS:			none
6636371Ssklower  *
6736371Ssklower  * SIDE EFFECTS:
6836371Ssklower  *
6936371Ssklower  * NOTES:			If source routing has been terminated, do nothing.
7036371Ssklower  */
7136371Ssklower clnp_update_srcrt(options, oidx)
7236371Ssklower struct mbuf			*options;	/* ptr to options mbuf */
7336371Ssklower struct clnp_optidx	*oidx;		/* ptr to option index */
7436371Ssklower {
7536371Ssklower 	u_char			len;	/* length of current address */
7636371Ssklower 	struct iso_addr	isoa;	/* copy current address into here */
7736371Ssklower 
7836371Ssklower 	if (CLNPSRCRT_TERM(oidx, options)) {
7936371Ssklower 		IFDEBUG(D_OPTIONS)
8036371Ssklower 			printf("clnp_update_srcrt: src rt terminated\n");
8136371Ssklower 		ENDDEBUG
8236371Ssklower 		return;
8336371Ssklower 	}
8436371Ssklower 
8536371Ssklower 	len = CLNPSRCRT_CLEN(oidx, options);
8636371Ssklower 	bcopy(CLNPSRCRT_CADDR(oidx, options), (caddr_t)&isoa, len);
8736371Ssklower 	isoa.isoa_len = len;
8836371Ssklower 
8936371Ssklower 	IFDEBUG(D_OPTIONS)
9036371Ssklower 		printf("clnp_update_srcrt: current src rt: %s\n",
9136371Ssklower 			clnp_iso_addrp(&isoa));
9236371Ssklower 	ENDDEBUG
9336371Ssklower 
9436371Ssklower 	if (clnp_ours(&isoa)) {
9536371Ssklower 		IFDEBUG(D_OPTIONS)
9636371Ssklower 			printf("clnp_update_srcrt: updating src rt\n");
9736371Ssklower 		ENDDEBUG
9836371Ssklower 
9936371Ssklower 		/* update pointer to next src route */
10036371Ssklower 		len++;	/* count length byte too! */
10136371Ssklower 		CLNPSRCRT_OFF(oidx, options) += len;
10236371Ssklower 	}
10336371Ssklower }
10436371Ssklower 
10536371Ssklower /*
10636371Ssklower  * FUNCTION:		clnp_dooptions
10736371Ssklower  *
10836371Ssklower  * PURPOSE:			Process options accompanying a clnp datagram.
10936371Ssklower  *					Processing includes
11036371Ssklower  *						- log our address if recording route
11136371Ssklower  *
11236371Ssklower  * RETURNS:			none
11336371Ssklower  *
11436371Ssklower  * SIDE EFFECTS:
11536371Ssklower  *
11636371Ssklower  * NOTES:
11736371Ssklower  */
11836371Ssklower clnp_dooptions(options, oidx, ifp, isoa)
11936371Ssklower struct mbuf			*options;	/* ptr to options mbuf */
12036371Ssklower struct clnp_optidx	*oidx;		/* ptr to option index */
12136371Ssklower struct ifnet		*ifp;		/* ptr to interface pkt is leaving on */
12236371Ssklower struct iso_addr		*isoa;		/* ptr to our address for this ifp */
12336371Ssklower {
12436371Ssklower 	/*
12536371Ssklower 	 *	If record route is specified, move all
12636371Ssklower 	 *	existing records over, and insert the address of
12736371Ssklower 	 *	interface passed
12836371Ssklower 	 */
12936371Ssklower 	if (oidx->cni_recrtp) {
13036371Ssklower 		char 	*opt;			/* ptr to beginning of recrt option */
13136371Ssklower 		u_char	off;			/* offset from opt of first free byte */
13239232Ssklower 		char	*rec_start;		/* beginning of new rt recorded */
13336371Ssklower 
13436767Ssklower 		opt = CLNP_OFFTOOPT(options, oidx->cni_recrtp);
13536371Ssklower 		off = *(opt + 1);
13639232Ssklower 		rec_start = opt + off - 1;
13736371Ssklower 
13836371Ssklower 		IFDEBUG(D_OPTIONS)
13936371Ssklower 			printf("clnp_dooptions: record route: option x%x for %d bytes\n",
14036371Ssklower 				opt, oidx->cni_recrt_len);
14136371Ssklower 			printf("\tfree slot offset x%x\n", off);
14236371Ssklower 			printf("clnp_dooptions: recording %s\n", clnp_iso_addrp(isoa));
14336371Ssklower 			printf("clnp_dooptions: option dump:\n");
14436371Ssklower 			dump_buf(opt, oidx->cni_recrt_len);
14536371Ssklower 		ENDDEBUG
14636371Ssklower 
14736371Ssklower 		/* proceed only if recording has not been terminated */
14836371Ssklower 		if (off != 0xff) {
14939232Ssklower 			int new_addrlen = isoa->isoa_len + 1;
15036371Ssklower 			/*
15136371Ssklower 			 *	if there is insufficient room to store the next address,
15236371Ssklower 			 *	then terminate recording. Plus 1 on isoa_len is for the
15336371Ssklower 			 *	length byte itself
15436371Ssklower 			 */
15539232Ssklower 			if (oidx->cni_recrt_len - (off - 1) < new_addrlen) {
15636371Ssklower 				*(opt + 1) = 0xff;	/* terminate recording */
15736371Ssklower 			} else {
15836371Ssklower 				IFDEBUG(D_OPTIONS)
15936371Ssklower 					printf("clnp_dooptions: new addr at x%x for %d\n",
16036371Ssklower 						rec_start, new_addrlen);
16136371Ssklower 				ENDDEBUG
16236371Ssklower 
16339232Ssklower 				bcopy((caddr_t)isoa, rec_start, new_addrlen);
16436371Ssklower 
16536371Ssklower 				/* update offset field */
16639232Ssklower 				*(opt + 1) += new_addrlen;
16736371Ssklower 
16836371Ssklower 				IFDEBUG(D_OPTIONS)
16936371Ssklower 					printf("clnp_dooptions: new option dump:\n");
17036371Ssklower 					dump_buf(opt, oidx->cni_recrt_len);
17136371Ssklower 				ENDDEBUG
17236371Ssklower 			}
17336371Ssklower 		}
17436371Ssklower 	}
17536371Ssklower }
17636371Ssklower 
17736371Ssklower /*
17836371Ssklower  * FUNCTION:		clnp_set_opts
17936371Ssklower  *
18036371Ssklower  * PURPOSE:			Check the data mbuf passed for option sanity. If it is
18136371Ssklower  *					ok, then set the options ptr to address the data mbuf.
18236371Ssklower  *					If an options mbuf exists, free it. This implies that
18336371Ssklower  *					any old options will be lost. If data is NULL, simply
18436371Ssklower  *					free any old options.
18536371Ssklower  *
18636371Ssklower  * RETURNS:			unix error code
18736371Ssklower  *
18836371Ssklower  * SIDE EFFECTS:
18936371Ssklower  *
19036371Ssklower  * NOTES:
19136371Ssklower  */
19236371Ssklower clnp_set_opts(options, data)
19336371Ssklower struct mbuf	**options;	/* target for option information */
19436371Ssklower struct mbuf	**data;		/* source of option information */
19536371Ssklower {
19636371Ssklower 	int					error = 0;	/* error return value */
19736371Ssklower 	struct clnp_optidx	dummy;		/* dummy index - not used */
19836371Ssklower 
19936371Ssklower 	/*
20036371Ssklower 	 *	remove any existing options
20136371Ssklower 	 */
20236371Ssklower 	if (*options != NULL) {
20336371Ssklower 		m_freem(*options);
20436371Ssklower 		*options = NULL;
20536371Ssklower 	}
20636371Ssklower 
20736371Ssklower 	if (*data != NULL) {
20836371Ssklower 		/*
20936371Ssklower 		 *	Insure that the options are reasonable.
21036371Ssklower 		 *
21139932Ssklower 		 *	Also, we do not support security, priority,
21236371Ssklower 		 *	nor do we allow one to send an ER option
21339932Ssklower 		 *
21439932Ssklower 		 *	The QOS parameter is checked for the DECBIT.
21536371Ssklower 		 */
21636371Ssklower 		if ((clnp_opt_sanity(*data, mtod(*data, caddr_t), (*data)->m_len,
21736371Ssklower 			&dummy) != 0) ||
21836371Ssklower 				(dummy.cni_securep) ||
21936371Ssklower 				(dummy.cni_priorp) ||
22036371Ssklower 				(dummy.cni_er_reason != ER_INVALREAS)) {
22136371Ssklower 			error = EINVAL;
22236371Ssklower 		} else {
22336371Ssklower 			*options = *data;
22436371Ssklower 			*data = NULL;	/* so caller won't free mbuf @ *data */
22536371Ssklower 		}
22636371Ssklower 	}
22736371Ssklower 	return error;
22836371Ssklower }
22936371Ssklower 
23036371Ssklower /*
23136371Ssklower  * FUNCTION:		clnp_opt_sanity
23236371Ssklower  *
23336371Ssklower  * PURPOSE:			Check the options (beginning at opts for len bytes) for
23436371Ssklower  *					sanity. In addition, fill in the option index structure
23536371Ssklower  *					in with information about each option discovered.
23636371Ssklower  *
23736371Ssklower  * RETURNS:			success (options check out) - 0
23836371Ssklower  *					failure - an ER pdu error code describing failure
23936371Ssklower  *
24036371Ssklower  * SIDE EFFECTS:
24136371Ssklower  *
24236371Ssklower  * NOTES:			Each pointer field of the option index is filled in with
24336767Ssklower  *					the offset from the beginning of the mbuf data, not the
24436371Ssklower  *					actual address.
24536371Ssklower  */
24636371Ssklower clnp_opt_sanity(m, opts, len, oidx)
24736371Ssklower struct mbuf 		*m;		/* mbuf options reside in */
24836371Ssklower caddr_t				opts;	/* ptr to buffer containing options */
24936371Ssklower int					len;	/* length of buffer */
25036371Ssklower struct clnp_optidx	*oidx;	/* RETURN: filled in with option idx info */
25136371Ssklower {
25236371Ssklower 	u_char	opcode;			/* code of particular option */
25336371Ssklower 	u_char	oplen;			/* length of a particular option */
25436371Ssklower 	caddr_t	opts_end;		/* ptr to end of options */
25536371Ssklower 	u_char	pad = 0, secure = 0, srcrt = 0, recrt = 0, qos = 0, prior = 0;
25636371Ssklower 							/* flags for catching duplicate options */
25736371Ssklower 
25836371Ssklower 	IFDEBUG(D_OPTIONS)
25936371Ssklower 		printf("clnp_opt_sanity: checking %d bytes of data:\n", len);
26036371Ssklower 		dump_buf(opts, len);
26136371Ssklower 	ENDDEBUG
26236371Ssklower 
26336371Ssklower 	/* clear option index field if passed */
26436371Ssklower 	bzero((caddr_t)oidx, sizeof(struct clnp_optidx));
26536371Ssklower 
26636371Ssklower 	/*
26736371Ssklower 	 *	We need to indicate whether the ER option is present. This is done
26836371Ssklower 	 *	by overloading the er_reason field to also indicate presense of
26936371Ssklower 	 *	the option along with the option value. I would like ER_INVALREAS
27036371Ssklower 	 *	to have value 0, but alas, 0 is a valid er reason...
27136371Ssklower 	 */
27236371Ssklower 	oidx->cni_er_reason = ER_INVALREAS;
27336371Ssklower 
27436371Ssklower 	opts_end = opts + len;
27536371Ssklower 	while (opts < opts_end) {
27636371Ssklower 		/* must have at least 2 bytes per option (opcode and len) */
27736371Ssklower 		if (opts + 2 > opts_end)
27836371Ssklower 			return(GEN_INCOMPLETE);
27936371Ssklower 
28036371Ssklower 		opcode = *opts++;
28136371Ssklower 		oplen = *opts++;
28236371Ssklower 		IFDEBUG(D_OPTIONS)
28336371Ssklower 			printf("clnp_opt_sanity: opcode is %x and oplen %d\n",
28436371Ssklower 				opcode, oplen);
28536371Ssklower 			printf("clnp_opt_sanity: clnpoval_SRCRT is %x\n", CLNPOVAL_SRCRT);
28636371Ssklower 
28736371Ssklower 				switch (opcode) {
28836371Ssklower 					case CLNPOVAL_PAD: {
28936371Ssklower 						printf("CLNPOVAL_PAD\n");
29036371Ssklower 					} break;
29136371Ssklower 					case CLNPOVAL_SECURE: {
29236371Ssklower 						printf("CLNPOVAL_SECURE\n");
29336371Ssklower 					} break;
29436371Ssklower 					case CLNPOVAL_SRCRT: {
29536371Ssklower 							printf("CLNPOVAL_SRCRT\n");
29636371Ssklower 					} break;
29736371Ssklower 					case CLNPOVAL_RECRT: {
29836371Ssklower 						printf("CLNPOVAL_RECRT\n");
29936371Ssklower 					} break;
30036371Ssklower 					case CLNPOVAL_QOS: {
30136371Ssklower 						printf("CLNPOVAL_QOS\n");
30236371Ssklower 					} break;
30336371Ssklower 					case CLNPOVAL_PRIOR: {
30436371Ssklower 						printf("CLNPOVAL_PRIOR\n");
30536371Ssklower 					} break;
30636371Ssklower 					case CLNPOVAL_ERREAS: {
30736371Ssklower 						printf("CLNPOVAL_ERREAS\n");
30836371Ssklower 					} break;
30936371Ssklower 					default:
31036371Ssklower 						printf("UKNOWN option %x\n", opcode);
31136371Ssklower 				}
31236371Ssklower 		ENDDEBUG
31336371Ssklower 
31436371Ssklower 		/* don't allow crazy length values */
31536371Ssklower 		if (opts + oplen > opts_end)
31636371Ssklower 			return(GEN_INCOMPLETE);
31736371Ssklower 
31836371Ssklower 		switch (opcode) {
31939232Ssklower 			case CLNPOVAL_PAD:
32036371Ssklower 				/*
32136371Ssklower 				 *	Padding: increment pointer by length of padding
32236371Ssklower 				 */
32336371Ssklower 				if (pad++)						/* duplicate ? */
32436371Ssklower 					return(GEN_DUPOPT);
32536371Ssklower 				opts += oplen;
32639232Ssklower 				break;
32736371Ssklower 
32836371Ssklower 			case CLNPOVAL_SECURE: {
32936371Ssklower 				u_char	format = *opts;
33036371Ssklower 
33136371Ssklower 				if (secure++)					/* duplicate ? */
33236371Ssklower 					return(GEN_DUPOPT);
33336371Ssklower 				/*
33436371Ssklower 				 *	Security: high 2 bits of first octet indicate format
33536371Ssklower 				 *	(00 in high bits is reserved).
33636371Ssklower 				 *	Remaining bits must be 0. Remaining octets indicate
33736371Ssklower 				 *	actual security
33836371Ssklower 				 */
33936371Ssklower 				if (((format & 0x3f) > 0) ||	/* low 6 bits set ? */
34036371Ssklower 					((format & 0xc0) == 0))		/* high 2 bits zero ? */
34136371Ssklower 					return(GEN_HDRSYNTAX);
34236371Ssklower 
34336767Ssklower 				oidx->cni_securep = CLNP_OPTTOOFF(m, opts);
34436371Ssklower 				oidx->cni_secure_len = oplen;
34536371Ssklower 				opts += oplen;
34636371Ssklower 			} break;
34736371Ssklower 
34836371Ssklower 			case CLNPOVAL_SRCRT: {
34936371Ssklower 				u_char	type, offset;	/* type of rt, offset of start */
35036371Ssklower 				caddr_t	route_end;		/* address of end of route option */
35136371Ssklower 
35236371Ssklower 				IFDEBUG(D_OPTIONS)
35336371Ssklower 					printf("clnp_opt_sanity: SRC RT\n");
35436371Ssklower 				ENDDEBUG
35536371Ssklower 
35636371Ssklower 				if (srcrt++)					/* duplicate ? */
35736371Ssklower 					return(GEN_DUPOPT);
35836371Ssklower 				/*
35936371Ssklower 				 *	source route: There must be 2 bytes following the length
36036371Ssklower 				 *	field: type and offset. The type must be either
36136371Ssklower 				 *	partial route or complete route. The offset field must
36236371Ssklower 				 *	be within the option. A single exception is made, however.
36336371Ssklower 				 *	The offset may be 1 greater than the length. This case
36436371Ssklower 				 *	occurs when the last source route record is consumed.
36536371Ssklower 				 *	In this case, we ignore the source route option.
36636371Ssklower 				 *	RAH? You should be able to set offset to 'ff' like in record
36736371Ssklower 				 *	route!
36836371Ssklower 				 *	Following this is a series of address fields.
36936371Ssklower 				 *	Each address field is composed of a (length, address) pair.
37036371Ssklower 				 *	Insure that the offset and each address length is reasonable
37136371Ssklower 				 */
37236371Ssklower 				route_end = opts + oplen;
37336371Ssklower 
37436371Ssklower 				if (opts + 2 > route_end)
37536371Ssklower 					return(SRCRT_SYNTAX);
37636371Ssklower 
37736371Ssklower 				type = *opts;
37836371Ssklower 				offset = *(opts+1);
37936371Ssklower 
38036371Ssklower 
38136371Ssklower 				/* type must be partial or complete */
38236371Ssklower 				if (!((type == CLNPOVAL_PARTRT) || (type == CLNPOVAL_COMPRT)))
38336371Ssklower 					return(SRCRT_SYNTAX);
38436371Ssklower 
38536767Ssklower 				oidx->cni_srcrt_s = CLNP_OPTTOOFF(m, opts);
38636371Ssklower 				oidx->cni_srcrt_len = oplen;
38736371Ssklower 
38836371Ssklower 				opts += offset-1;	/*set opts to first addr in rt */
38936371Ssklower 
39036371Ssklower 				/*
39136371Ssklower 				 *	Offset must be reasonable:
39236371Ssklower 				 *	less than end of options, or equal to end of options
39336371Ssklower 				 */
39436371Ssklower 				if (opts >= route_end) {
39536371Ssklower 					if (opts == route_end) {
39636371Ssklower 						IFDEBUG(D_OPTIONS)
39736371Ssklower 							printf("clnp_opt_sanity: end of src route info\n");
39836371Ssklower 						ENDDEBUG
39936371Ssklower 						break;
40036371Ssklower 					} else
40136371Ssklower 						return(SRCRT_SYNTAX);
40236371Ssklower 				}
40336371Ssklower 
40436371Ssklower 				while (opts < route_end) {
40536371Ssklower 					u_char	addrlen = *opts++;
40636371Ssklower 					if (opts + addrlen > route_end)
40736371Ssklower 						return(SRCRT_SYNTAX);
40836371Ssklower 					opts += addrlen;
40936371Ssklower 				}
41036371Ssklower 			} break;
41136371Ssklower 			case CLNPOVAL_RECRT: {
41236371Ssklower 				u_char	type, offset;	/* type of rt, offset of start */
41336371Ssklower 				caddr_t	record_end;		/* address of end of record option */
41436371Ssklower 
41536371Ssklower 				if (recrt++)					/* duplicate ? */
41636371Ssklower 					return(GEN_DUPOPT);
41736371Ssklower 				/*
41836371Ssklower 				 *	record route: after the length field, expect a
41936371Ssklower 				 *	type and offset. Type must be partial or complete.
42036371Ssklower 				 *	Offset indicates where to start recording. Insure it
42136371Ssklower 				 *	is within the option. All ones for offset means
42236371Ssklower 				 *	recording is terminated.
42336371Ssklower 				 */
42436371Ssklower 				record_end = opts + oplen;
42536371Ssklower 
42636767Ssklower 				oidx->cni_recrtp = CLNP_OPTTOOFF(m, opts);
42736371Ssklower 				oidx->cni_recrt_len = oplen;
42836371Ssklower 
42936371Ssklower 				if (opts + 2 > record_end)
43036371Ssklower 					return(GEN_INCOMPLETE);
43136371Ssklower 
43236371Ssklower 				type = *opts;
43336371Ssklower 				offset = *(opts+1);
43436371Ssklower 
43536371Ssklower 				/* type must be partial or complete */
43636371Ssklower 				if (!((type == CLNPOVAL_PARTRT) || (type == CLNPOVAL_COMPRT)))
43736371Ssklower 					return(GEN_HDRSYNTAX);
43836371Ssklower 
43936371Ssklower 				/* offset must be reasonable */
44036371Ssklower 				if ((offset < 0xff) && (opts + offset > record_end))
44136371Ssklower 					return(GEN_HDRSYNTAX);
44236371Ssklower 				opts += oplen;
44336371Ssklower 			} break;
44436371Ssklower 			case CLNPOVAL_QOS: {
44536371Ssklower 				u_char	format = *opts;
44636371Ssklower 
44736371Ssklower 				if (qos++)					/* duplicate ? */
44836371Ssklower 					return(GEN_DUPOPT);
44936371Ssklower 				/*
45036371Ssklower 				 *	qos: high 2 bits of first octet indicate format
45136371Ssklower 				 *	(00 in high bits is reserved).
45236371Ssklower 				 *	Remaining bits must be 0 (unless format indicates
45336371Ssklower 				 *	globally unique qos, in which case remaining bits indicate
45436371Ssklower 				 *	qos (except bit 6 which is reserved)).  Otherwise,
45536371Ssklower 				 *	remaining octets indicate actual qos.
45636371Ssklower 				 */
45736371Ssklower 				if (((format & 0xc0) == 0) ||	/* high 2 bits zero ? */
45836371Ssklower 					(((format & 0xc0) != CLNPOVAL_GLOBAL) &&
45936371Ssklower 						((format & 0x3f) > 0))) /* not global,low bits used ? */
46036371Ssklower 					return(GEN_HDRSYNTAX);
46136371Ssklower 
46236767Ssklower 				oidx->cni_qos_formatp = CLNP_OPTTOOFF(m, opts);
46336371Ssklower 				oidx->cni_qos_len = oplen;
46436371Ssklower 
46536371Ssklower 				opts += oplen;
46636371Ssklower 			} break;
46736371Ssklower 
46836371Ssklower 			case CLNPOVAL_PRIOR: {
46936371Ssklower 				if (prior++)				/* duplicate ? */
47036371Ssklower 					return(GEN_DUPOPT);
47136371Ssklower 				/*
47236371Ssklower 				 *	priority: value must be one byte long
47336371Ssklower 				 */
47436371Ssklower 				if (oplen != 1)
47536371Ssklower 					return(GEN_HDRSYNTAX);
47636371Ssklower 
47736767Ssklower 				oidx->cni_priorp = CLNP_OPTTOOFF(m, opts);
47836371Ssklower 
47936371Ssklower 				opts += oplen;
48036371Ssklower 			} break;
48136371Ssklower 
48236371Ssklower 			case CLNPOVAL_ERREAS: {
48336371Ssklower 				/*
48436371Ssklower 				 *	er reason: value must be two bytes long
48536371Ssklower 				 */
48636371Ssklower 				if (oplen != 2)
48736371Ssklower 					return(GEN_HDRSYNTAX);
48836371Ssklower 
48936371Ssklower 				oidx->cni_er_reason = *opts;
49036371Ssklower 
49136371Ssklower 				opts += oplen;
49236371Ssklower 			} break;
49336371Ssklower 
49436371Ssklower 			default: {
49536371Ssklower 				IFDEBUG(D_OPTIONS)
49636371Ssklower 					printf("clnp_opt_sanity: UNKNOWN OPTION 0x%x\n", opcode);
49736371Ssklower 				ENDDEBUG
49836371Ssklower 				return(DISC_UNSUPPOPT);
49936371Ssklower 			}
50036371Ssklower 		}
50136371Ssklower 	}
50236371Ssklower 		IFDEBUG(D_OPTIONS)
50336371Ssklower 			printf("clnp_opt_sanity: return(0)\n", opcode);
50436371Ssklower 		ENDDEBUG
50536371Ssklower 	return(0);
50636371Ssklower }
50736371Ssklower #endif	ISO
508