xref: /csrg-svn/sys/netiso/clnp_options.c (revision 63222)
149267Sbostic /*-
2*63222Sbostic  * Copyright (c) 1991, 1993
3*63222Sbostic  *	The Regents of the University of California.  All rights reserved.
449267Sbostic  *
549267Sbostic  * %sccs.include.redist.c%
649267Sbostic  *
7*63222Sbostic  *	@(#)clnp_options.c	8.1 (Berkeley) 06/10/93
849267Sbostic  */
949267Sbostic 
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 
4156533Sbostic #include <sys/param.h>
4256533Sbostic #include <sys/mbuf.h>
4356533Sbostic #include <sys/domain.h>
4456533Sbostic #include <sys/protosw.h>
4556533Sbostic #include <sys/socket.h>
4656533Sbostic #include <sys/socketvar.h>
4756533Sbostic #include <sys/errno.h>
4836371Ssklower 
4956533Sbostic #include <net/if.h>
5056533Sbostic #include <net/route.h>
5136371Ssklower 
5256533Sbostic #include <netiso/iso.h>
5356533Sbostic #include <netiso/clnp.h>
5456533Sbostic #include <netiso/clnp_stat.h>
5556533Sbostic #include <netiso/argo_debug.h>
5636371Ssklower 
5736371Ssklower /*
5836371Ssklower  * FUNCTION:		clnp_update_srcrt
5936371Ssklower  *
6036371Ssklower  * PURPOSE:			Process src rt option accompanying a clnp datagram.
6136371Ssklower  *						- bump src route ptr if src routing and
6236371Ssklower  *							we appear current in src route list.
6336371Ssklower  *
6436371Ssklower  * RETURNS:			none
6536371Ssklower  *
6636371Ssklower  * SIDE EFFECTS:
6736371Ssklower  *
6836371Ssklower  * NOTES:			If source routing has been terminated, do nothing.
6936371Ssklower  */
7036371Ssklower clnp_update_srcrt(options, oidx)
7136371Ssklower struct mbuf			*options;	/* ptr to options mbuf */
7236371Ssklower struct clnp_optidx	*oidx;		/* ptr to option index */
7336371Ssklower {
7436371Ssklower 	u_char			len;	/* length of current address */
7536371Ssklower 	struct iso_addr	isoa;	/* copy current address into here */
7636371Ssklower 
7736371Ssklower 	if (CLNPSRCRT_TERM(oidx, options)) {
7836371Ssklower 		IFDEBUG(D_OPTIONS)
7936371Ssklower 			printf("clnp_update_srcrt: src rt terminated\n");
8036371Ssklower 		ENDDEBUG
8136371Ssklower 		return;
8236371Ssklower 	}
8336371Ssklower 
8436371Ssklower 	len = CLNPSRCRT_CLEN(oidx, options);
8536371Ssklower 	bcopy(CLNPSRCRT_CADDR(oidx, options), (caddr_t)&isoa, len);
8636371Ssklower 	isoa.isoa_len = len;
8736371Ssklower 
8836371Ssklower 	IFDEBUG(D_OPTIONS)
8936371Ssklower 		printf("clnp_update_srcrt: current src rt: %s\n",
9036371Ssklower 			clnp_iso_addrp(&isoa));
9136371Ssklower 	ENDDEBUG
9236371Ssklower 
9336371Ssklower 	if (clnp_ours(&isoa)) {
9436371Ssklower 		IFDEBUG(D_OPTIONS)
9536371Ssklower 			printf("clnp_update_srcrt: updating src rt\n");
9636371Ssklower 		ENDDEBUG
9736371Ssklower 
9836371Ssklower 		/* update pointer to next src route */
9936371Ssklower 		len++;	/* count length byte too! */
10036371Ssklower 		CLNPSRCRT_OFF(oidx, options) += len;
10136371Ssklower 	}
10236371Ssklower }
10336371Ssklower 
10436371Ssklower /*
10536371Ssklower  * FUNCTION:		clnp_dooptions
10636371Ssklower  *
10736371Ssklower  * PURPOSE:			Process options accompanying a clnp datagram.
10836371Ssklower  *					Processing includes
10936371Ssklower  *						- log our address if recording route
11036371Ssklower  *
11136371Ssklower  * RETURNS:			none
11236371Ssklower  *
11336371Ssklower  * SIDE EFFECTS:
11436371Ssklower  *
11536371Ssklower  * NOTES:
11636371Ssklower  */
11736371Ssklower clnp_dooptions(options, oidx, ifp, isoa)
11836371Ssklower struct mbuf			*options;	/* ptr to options mbuf */
11936371Ssklower struct clnp_optidx	*oidx;		/* ptr to option index */
12036371Ssklower struct ifnet		*ifp;		/* ptr to interface pkt is leaving on */
12136371Ssklower struct iso_addr		*isoa;		/* ptr to our address for this ifp */
12236371Ssklower {
12336371Ssklower 	/*
12436371Ssklower 	 *	If record route is specified, move all
12536371Ssklower 	 *	existing records over, and insert the address of
12636371Ssklower 	 *	interface passed
12736371Ssklower 	 */
12836371Ssklower 	if (oidx->cni_recrtp) {
12936371Ssklower 		char 	*opt;			/* ptr to beginning of recrt option */
13036371Ssklower 		u_char	off;			/* offset from opt of first free byte */
13139232Ssklower 		char	*rec_start;		/* beginning of new rt recorded */
13236371Ssklower 
13336767Ssklower 		opt = CLNP_OFFTOOPT(options, oidx->cni_recrtp);
13436371Ssklower 		off = *(opt + 1);
13539232Ssklower 		rec_start = opt + off - 1;
13636371Ssklower 
13736371Ssklower 		IFDEBUG(D_OPTIONS)
13836371Ssklower 			printf("clnp_dooptions: record route: option x%x for %d bytes\n",
13936371Ssklower 				opt, oidx->cni_recrt_len);
14036371Ssklower 			printf("\tfree slot offset x%x\n", off);
14136371Ssklower 			printf("clnp_dooptions: recording %s\n", clnp_iso_addrp(isoa));
14236371Ssklower 			printf("clnp_dooptions: option dump:\n");
14336371Ssklower 			dump_buf(opt, oidx->cni_recrt_len);
14436371Ssklower 		ENDDEBUG
14536371Ssklower 
14636371Ssklower 		/* proceed only if recording has not been terminated */
14736371Ssklower 		if (off != 0xff) {
14839232Ssklower 			int new_addrlen = isoa->isoa_len + 1;
14936371Ssklower 			/*
15036371Ssklower 			 *	if there is insufficient room to store the next address,
15136371Ssklower 			 *	then terminate recording. Plus 1 on isoa_len is for the
15236371Ssklower 			 *	length byte itself
15336371Ssklower 			 */
15439232Ssklower 			if (oidx->cni_recrt_len - (off - 1) < new_addrlen) {
15536371Ssklower 				*(opt + 1) = 0xff;	/* terminate recording */
15636371Ssklower 			} else {
15736371Ssklower 				IFDEBUG(D_OPTIONS)
15836371Ssklower 					printf("clnp_dooptions: new addr at x%x for %d\n",
15936371Ssklower 						rec_start, new_addrlen);
16036371Ssklower 				ENDDEBUG
16136371Ssklower 
16239232Ssklower 				bcopy((caddr_t)isoa, rec_start, new_addrlen);
16336371Ssklower 
16436371Ssklower 				/* update offset field */
16539232Ssklower 				*(opt + 1) += new_addrlen;
16636371Ssklower 
16736371Ssklower 				IFDEBUG(D_OPTIONS)
16836371Ssklower 					printf("clnp_dooptions: new option dump:\n");
16936371Ssklower 					dump_buf(opt, oidx->cni_recrt_len);
17036371Ssklower 				ENDDEBUG
17136371Ssklower 			}
17236371Ssklower 		}
17336371Ssklower 	}
17436371Ssklower }
17536371Ssklower 
17636371Ssklower /*
17736371Ssklower  * FUNCTION:		clnp_set_opts
17836371Ssklower  *
17936371Ssklower  * PURPOSE:			Check the data mbuf passed for option sanity. If it is
18036371Ssklower  *					ok, then set the options ptr to address the data mbuf.
18136371Ssklower  *					If an options mbuf exists, free it. This implies that
18236371Ssklower  *					any old options will be lost. If data is NULL, simply
18336371Ssklower  *					free any old options.
18436371Ssklower  *
18536371Ssklower  * RETURNS:			unix error code
18636371Ssklower  *
18736371Ssklower  * SIDE EFFECTS:
18836371Ssklower  *
18936371Ssklower  * NOTES:
19036371Ssklower  */
19136371Ssklower clnp_set_opts(options, data)
19236371Ssklower struct mbuf	**options;	/* target for option information */
19336371Ssklower struct mbuf	**data;		/* source of option information */
19436371Ssklower {
19536371Ssklower 	int					error = 0;	/* error return value */
19636371Ssklower 	struct clnp_optidx	dummy;		/* dummy index - not used */
19736371Ssklower 
19836371Ssklower 	/*
19936371Ssklower 	 *	remove any existing options
20036371Ssklower 	 */
20136371Ssklower 	if (*options != NULL) {
20236371Ssklower 		m_freem(*options);
20336371Ssklower 		*options = NULL;
20436371Ssklower 	}
20536371Ssklower 
20636371Ssklower 	if (*data != NULL) {
20736371Ssklower 		/*
20836371Ssklower 		 *	Insure that the options are reasonable.
20936371Ssklower 		 *
21039932Ssklower 		 *	Also, we do not support security, priority,
21136371Ssklower 		 *	nor do we allow one to send an ER option
21239932Ssklower 		 *
21339932Ssklower 		 *	The QOS parameter is checked for the DECBIT.
21436371Ssklower 		 */
21536371Ssklower 		if ((clnp_opt_sanity(*data, mtod(*data, caddr_t), (*data)->m_len,
21636371Ssklower 			&dummy) != 0) ||
21736371Ssklower 				(dummy.cni_securep) ||
21836371Ssklower 				(dummy.cni_priorp) ||
21936371Ssklower 				(dummy.cni_er_reason != ER_INVALREAS)) {
22036371Ssklower 			error = EINVAL;
22136371Ssklower 		} else {
22236371Ssklower 			*options = *data;
22336371Ssklower 			*data = NULL;	/* so caller won't free mbuf @ *data */
22436371Ssklower 		}
22536371Ssklower 	}
22636371Ssklower 	return error;
22736371Ssklower }
22836371Ssklower 
22936371Ssklower /*
23036371Ssklower  * FUNCTION:		clnp_opt_sanity
23136371Ssklower  *
23236371Ssklower  * PURPOSE:			Check the options (beginning at opts for len bytes) for
23336371Ssklower  *					sanity. In addition, fill in the option index structure
23436371Ssklower  *					in with information about each option discovered.
23536371Ssklower  *
23636371Ssklower  * RETURNS:			success (options check out) - 0
23736371Ssklower  *					failure - an ER pdu error code describing failure
23836371Ssklower  *
23936371Ssklower  * SIDE EFFECTS:
24036371Ssklower  *
24136371Ssklower  * NOTES:			Each pointer field of the option index is filled in with
24236767Ssklower  *					the offset from the beginning of the mbuf data, not the
24336371Ssklower  *					actual address.
24436371Ssklower  */
24536371Ssklower clnp_opt_sanity(m, opts, len, oidx)
24636371Ssklower struct mbuf 		*m;		/* mbuf options reside in */
24736371Ssklower caddr_t				opts;	/* ptr to buffer containing options */
24836371Ssklower int					len;	/* length of buffer */
24936371Ssklower struct clnp_optidx	*oidx;	/* RETURN: filled in with option idx info */
25036371Ssklower {
25136371Ssklower 	u_char	opcode;			/* code of particular option */
25236371Ssklower 	u_char	oplen;			/* length of a particular option */
25336371Ssklower 	caddr_t	opts_end;		/* ptr to end of options */
25436371Ssklower 	u_char	pad = 0, secure = 0, srcrt = 0, recrt = 0, qos = 0, prior = 0;
25536371Ssklower 							/* flags for catching duplicate options */
25636371Ssklower 
25736371Ssklower 	IFDEBUG(D_OPTIONS)
25836371Ssklower 		printf("clnp_opt_sanity: checking %d bytes of data:\n", len);
25936371Ssklower 		dump_buf(opts, len);
26036371Ssklower 	ENDDEBUG
26136371Ssklower 
26236371Ssklower 	/* clear option index field if passed */
26336371Ssklower 	bzero((caddr_t)oidx, sizeof(struct clnp_optidx));
26436371Ssklower 
26536371Ssklower 	/*
26636371Ssklower 	 *	We need to indicate whether the ER option is present. This is done
26736371Ssklower 	 *	by overloading the er_reason field to also indicate presense of
26836371Ssklower 	 *	the option along with the option value. I would like ER_INVALREAS
26936371Ssklower 	 *	to have value 0, but alas, 0 is a valid er reason...
27036371Ssklower 	 */
27136371Ssklower 	oidx->cni_er_reason = ER_INVALREAS;
27236371Ssklower 
27336371Ssklower 	opts_end = opts + len;
27436371Ssklower 	while (opts < opts_end) {
27536371Ssklower 		/* must have at least 2 bytes per option (opcode and len) */
27636371Ssklower 		if (opts + 2 > opts_end)
27736371Ssklower 			return(GEN_INCOMPLETE);
27836371Ssklower 
27936371Ssklower 		opcode = *opts++;
28036371Ssklower 		oplen = *opts++;
28136371Ssklower 		IFDEBUG(D_OPTIONS)
28236371Ssklower 			printf("clnp_opt_sanity: opcode is %x and oplen %d\n",
28336371Ssklower 				opcode, oplen);
28436371Ssklower 			printf("clnp_opt_sanity: clnpoval_SRCRT is %x\n", CLNPOVAL_SRCRT);
28536371Ssklower 
28636371Ssklower 				switch (opcode) {
28736371Ssklower 					case CLNPOVAL_PAD: {
28836371Ssklower 						printf("CLNPOVAL_PAD\n");
28936371Ssklower 					} break;
29036371Ssklower 					case CLNPOVAL_SECURE: {
29136371Ssklower 						printf("CLNPOVAL_SECURE\n");
29236371Ssklower 					} break;
29336371Ssklower 					case CLNPOVAL_SRCRT: {
29436371Ssklower 							printf("CLNPOVAL_SRCRT\n");
29536371Ssklower 					} break;
29636371Ssklower 					case CLNPOVAL_RECRT: {
29736371Ssklower 						printf("CLNPOVAL_RECRT\n");
29836371Ssklower 					} break;
29936371Ssklower 					case CLNPOVAL_QOS: {
30036371Ssklower 						printf("CLNPOVAL_QOS\n");
30136371Ssklower 					} break;
30236371Ssklower 					case CLNPOVAL_PRIOR: {
30336371Ssklower 						printf("CLNPOVAL_PRIOR\n");
30436371Ssklower 					} break;
30536371Ssklower 					case CLNPOVAL_ERREAS: {
30636371Ssklower 						printf("CLNPOVAL_ERREAS\n");
30736371Ssklower 					} break;
30836371Ssklower 					default:
30936371Ssklower 						printf("UKNOWN option %x\n", opcode);
31036371Ssklower 				}
31136371Ssklower 		ENDDEBUG
31236371Ssklower 
31336371Ssklower 		/* don't allow crazy length values */
31436371Ssklower 		if (opts + oplen > opts_end)
31536371Ssklower 			return(GEN_INCOMPLETE);
31636371Ssklower 
31736371Ssklower 		switch (opcode) {
31839232Ssklower 			case CLNPOVAL_PAD:
31936371Ssklower 				/*
32036371Ssklower 				 *	Padding: increment pointer by length of padding
32136371Ssklower 				 */
32236371Ssklower 				if (pad++)						/* duplicate ? */
32336371Ssklower 					return(GEN_DUPOPT);
32436371Ssklower 				opts += oplen;
32539232Ssklower 				break;
32636371Ssklower 
32736371Ssklower 			case CLNPOVAL_SECURE: {
32836371Ssklower 				u_char	format = *opts;
32936371Ssklower 
33036371Ssklower 				if (secure++)					/* duplicate ? */
33136371Ssklower 					return(GEN_DUPOPT);
33236371Ssklower 				/*
33336371Ssklower 				 *	Security: high 2 bits of first octet indicate format
33436371Ssklower 				 *	(00 in high bits is reserved).
33536371Ssklower 				 *	Remaining bits must be 0. Remaining octets indicate
33636371Ssklower 				 *	actual security
33736371Ssklower 				 */
33836371Ssklower 				if (((format & 0x3f) > 0) ||	/* low 6 bits set ? */
33936371Ssklower 					((format & 0xc0) == 0))		/* high 2 bits zero ? */
34036371Ssklower 					return(GEN_HDRSYNTAX);
34136371Ssklower 
34236767Ssklower 				oidx->cni_securep = CLNP_OPTTOOFF(m, opts);
34336371Ssklower 				oidx->cni_secure_len = oplen;
34436371Ssklower 				opts += oplen;
34536371Ssklower 			} break;
34636371Ssklower 
34736371Ssklower 			case CLNPOVAL_SRCRT: {
34836371Ssklower 				u_char	type, offset;	/* type of rt, offset of start */
34936371Ssklower 				caddr_t	route_end;		/* address of end of route option */
35036371Ssklower 
35136371Ssklower 				IFDEBUG(D_OPTIONS)
35236371Ssklower 					printf("clnp_opt_sanity: SRC RT\n");
35336371Ssklower 				ENDDEBUG
35436371Ssklower 
35536371Ssklower 				if (srcrt++)					/* duplicate ? */
35636371Ssklower 					return(GEN_DUPOPT);
35736371Ssklower 				/*
35836371Ssklower 				 *	source route: There must be 2 bytes following the length
35936371Ssklower 				 *	field: type and offset. The type must be either
36036371Ssklower 				 *	partial route or complete route. The offset field must
36136371Ssklower 				 *	be within the option. A single exception is made, however.
36236371Ssklower 				 *	The offset may be 1 greater than the length. This case
36336371Ssklower 				 *	occurs when the last source route record is consumed.
36436371Ssklower 				 *	In this case, we ignore the source route option.
36536371Ssklower 				 *	RAH? You should be able to set offset to 'ff' like in record
36636371Ssklower 				 *	route!
36736371Ssklower 				 *	Following this is a series of address fields.
36836371Ssklower 				 *	Each address field is composed of a (length, address) pair.
36936371Ssklower 				 *	Insure that the offset and each address length is reasonable
37036371Ssklower 				 */
37136371Ssklower 				route_end = opts + oplen;
37236371Ssklower 
37336371Ssklower 				if (opts + 2 > route_end)
37436371Ssklower 					return(SRCRT_SYNTAX);
37536371Ssklower 
37636371Ssklower 				type = *opts;
37736371Ssklower 				offset = *(opts+1);
37836371Ssklower 
37936371Ssklower 
38036371Ssklower 				/* type must be partial or complete */
38136371Ssklower 				if (!((type == CLNPOVAL_PARTRT) || (type == CLNPOVAL_COMPRT)))
38236371Ssklower 					return(SRCRT_SYNTAX);
38336371Ssklower 
38436767Ssklower 				oidx->cni_srcrt_s = CLNP_OPTTOOFF(m, opts);
38536371Ssklower 				oidx->cni_srcrt_len = oplen;
38636371Ssklower 
38736371Ssklower 				opts += offset-1;	/*set opts to first addr in rt */
38836371Ssklower 
38936371Ssklower 				/*
39036371Ssklower 				 *	Offset must be reasonable:
39136371Ssklower 				 *	less than end of options, or equal to end of options
39236371Ssklower 				 */
39336371Ssklower 				if (opts >= route_end) {
39436371Ssklower 					if (opts == route_end) {
39536371Ssklower 						IFDEBUG(D_OPTIONS)
39636371Ssklower 							printf("clnp_opt_sanity: end of src route info\n");
39736371Ssklower 						ENDDEBUG
39836371Ssklower 						break;
39936371Ssklower 					} else
40036371Ssklower 						return(SRCRT_SYNTAX);
40136371Ssklower 				}
40236371Ssklower 
40336371Ssklower 				while (opts < route_end) {
40436371Ssklower 					u_char	addrlen = *opts++;
40536371Ssklower 					if (opts + addrlen > route_end)
40636371Ssklower 						return(SRCRT_SYNTAX);
40736371Ssklower 					opts += addrlen;
40836371Ssklower 				}
40936371Ssklower 			} break;
41036371Ssklower 			case CLNPOVAL_RECRT: {
41136371Ssklower 				u_char	type, offset;	/* type of rt, offset of start */
41236371Ssklower 				caddr_t	record_end;		/* address of end of record option */
41336371Ssklower 
41436371Ssklower 				if (recrt++)					/* duplicate ? */
41536371Ssklower 					return(GEN_DUPOPT);
41636371Ssklower 				/*
41736371Ssklower 				 *	record route: after the length field, expect a
41836371Ssklower 				 *	type and offset. Type must be partial or complete.
41936371Ssklower 				 *	Offset indicates where to start recording. Insure it
42036371Ssklower 				 *	is within the option. All ones for offset means
42136371Ssklower 				 *	recording is terminated.
42236371Ssklower 				 */
42336371Ssklower 				record_end = opts + oplen;
42436371Ssklower 
42536767Ssklower 				oidx->cni_recrtp = CLNP_OPTTOOFF(m, opts);
42636371Ssklower 				oidx->cni_recrt_len = oplen;
42736371Ssklower 
42836371Ssklower 				if (opts + 2 > record_end)
42936371Ssklower 					return(GEN_INCOMPLETE);
43036371Ssklower 
43136371Ssklower 				type = *opts;
43236371Ssklower 				offset = *(opts+1);
43336371Ssklower 
43436371Ssklower 				/* type must be partial or complete */
43536371Ssklower 				if (!((type == CLNPOVAL_PARTRT) || (type == CLNPOVAL_COMPRT)))
43636371Ssklower 					return(GEN_HDRSYNTAX);
43736371Ssklower 
43836371Ssklower 				/* offset must be reasonable */
43936371Ssklower 				if ((offset < 0xff) && (opts + offset > record_end))
44036371Ssklower 					return(GEN_HDRSYNTAX);
44136371Ssklower 				opts += oplen;
44236371Ssklower 			} break;
44336371Ssklower 			case CLNPOVAL_QOS: {
44436371Ssklower 				u_char	format = *opts;
44536371Ssklower 
44636371Ssklower 				if (qos++)					/* duplicate ? */
44736371Ssklower 					return(GEN_DUPOPT);
44836371Ssklower 				/*
44936371Ssklower 				 *	qos: high 2 bits of first octet indicate format
45036371Ssklower 				 *	(00 in high bits is reserved).
45136371Ssklower 				 *	Remaining bits must be 0 (unless format indicates
45236371Ssklower 				 *	globally unique qos, in which case remaining bits indicate
45336371Ssklower 				 *	qos (except bit 6 which is reserved)).  Otherwise,
45436371Ssklower 				 *	remaining octets indicate actual qos.
45536371Ssklower 				 */
45636371Ssklower 				if (((format & 0xc0) == 0) ||	/* high 2 bits zero ? */
45736371Ssklower 					(((format & 0xc0) != CLNPOVAL_GLOBAL) &&
45836371Ssklower 						((format & 0x3f) > 0))) /* not global,low bits used ? */
45936371Ssklower 					return(GEN_HDRSYNTAX);
46036371Ssklower 
46136767Ssklower 				oidx->cni_qos_formatp = CLNP_OPTTOOFF(m, opts);
46236371Ssklower 				oidx->cni_qos_len = oplen;
46336371Ssklower 
46436371Ssklower 				opts += oplen;
46536371Ssklower 			} break;
46636371Ssklower 
46736371Ssklower 			case CLNPOVAL_PRIOR: {
46836371Ssklower 				if (prior++)				/* duplicate ? */
46936371Ssklower 					return(GEN_DUPOPT);
47036371Ssklower 				/*
47136371Ssklower 				 *	priority: value must be one byte long
47236371Ssklower 				 */
47336371Ssklower 				if (oplen != 1)
47436371Ssklower 					return(GEN_HDRSYNTAX);
47536371Ssklower 
47636767Ssklower 				oidx->cni_priorp = CLNP_OPTTOOFF(m, opts);
47736371Ssklower 
47836371Ssklower 				opts += oplen;
47936371Ssklower 			} break;
48036371Ssklower 
48136371Ssklower 			case CLNPOVAL_ERREAS: {
48236371Ssklower 				/*
48336371Ssklower 				 *	er reason: value must be two bytes long
48436371Ssklower 				 */
48536371Ssklower 				if (oplen != 2)
48636371Ssklower 					return(GEN_HDRSYNTAX);
48736371Ssklower 
48836371Ssklower 				oidx->cni_er_reason = *opts;
48936371Ssklower 
49036371Ssklower 				opts += oplen;
49136371Ssklower 			} break;
49236371Ssklower 
49336371Ssklower 			default: {
49436371Ssklower 				IFDEBUG(D_OPTIONS)
49536371Ssklower 					printf("clnp_opt_sanity: UNKNOWN OPTION 0x%x\n", opcode);
49636371Ssklower 				ENDDEBUG
49736371Ssklower 				return(DISC_UNSUPPOPT);
49836371Ssklower 			}
49936371Ssklower 		}
50036371Ssklower 	}
50136371Ssklower 		IFDEBUG(D_OPTIONS)
50236371Ssklower 			printf("clnp_opt_sanity: return(0)\n", opcode);
50336371Ssklower 		ENDDEBUG
50436371Ssklower 	return(0);
50536371Ssklower }
50661292Ssklower #endif	/* ISO */
507