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