xref: /csrg-svn/sys/netiso/clnp_options.c (revision 39932)
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*39932Ssklower /*	@(#)clnp_options.c	7.7 (Berkeley) 01/16/90 */
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 */
12839232Ssklower 		char	*rec_start;		/* beginning of new rt recorded */
12936371Ssklower 
13036767Ssklower 		opt = CLNP_OFFTOOPT(options, oidx->cni_recrtp);
13136371Ssklower 		off = *(opt + 1);
13239232Ssklower 		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) {
14539232Ssklower 			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 			 */
15139232Ssklower 			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 
15939232Ssklower 				bcopy((caddr_t)isoa, rec_start, new_addrlen);
16036371Ssklower 
16136371Ssklower 				/* update offset field */
16239232Ssklower 				*(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 		 *
207*39932Ssklower 		 *	Also, we do not support security, priority,
20836371Ssklower 		 *	nor do we allow one to send an ER option
209*39932Ssklower 		 *
210*39932Ssklower 		 *	The QOS parameter is checked for the DECBIT.
21136371Ssklower 		 */
21236371Ssklower 		if ((clnp_opt_sanity(*data, mtod(*data, caddr_t), (*data)->m_len,
21336371Ssklower 			&dummy) != 0) ||
21436371Ssklower 				(dummy.cni_securep) ||
21536371Ssklower 				(dummy.cni_priorp) ||
21636371Ssklower 				(dummy.cni_er_reason != ER_INVALREAS)) {
21736371Ssklower 			error = EINVAL;
21836371Ssklower 		} else {
21936371Ssklower 			*options = *data;
22036371Ssklower 			*data = NULL;	/* so caller won't free mbuf @ *data */
22136371Ssklower 		}
22236371Ssklower 	}
22336371Ssklower 	return error;
22436371Ssklower }
22536371Ssklower 
22636371Ssklower /*
22736371Ssklower  * FUNCTION:		clnp_opt_sanity
22836371Ssklower  *
22936371Ssklower  * PURPOSE:			Check the options (beginning at opts for len bytes) for
23036371Ssklower  *					sanity. In addition, fill in the option index structure
23136371Ssklower  *					in with information about each option discovered.
23236371Ssklower  *
23336371Ssklower  * RETURNS:			success (options check out) - 0
23436371Ssklower  *					failure - an ER pdu error code describing failure
23536371Ssklower  *
23636371Ssklower  * SIDE EFFECTS:
23736371Ssklower  *
23836371Ssklower  * NOTES:			Each pointer field of the option index is filled in with
23936767Ssklower  *					the offset from the beginning of the mbuf data, not the
24036371Ssklower  *					actual address.
24136371Ssklower  */
24236371Ssklower clnp_opt_sanity(m, opts, len, oidx)
24336371Ssklower struct mbuf 		*m;		/* mbuf options reside in */
24436371Ssklower caddr_t				opts;	/* ptr to buffer containing options */
24536371Ssklower int					len;	/* length of buffer */
24636371Ssklower struct clnp_optidx	*oidx;	/* RETURN: filled in with option idx info */
24736371Ssklower {
24836371Ssklower 	u_char	opcode;			/* code of particular option */
24936371Ssklower 	u_char	oplen;			/* length of a particular option */
25036371Ssklower 	caddr_t	opts_end;		/* ptr to end of options */
25136371Ssklower 	u_char	pad = 0, secure = 0, srcrt = 0, recrt = 0, qos = 0, prior = 0;
25236371Ssklower 							/* flags for catching duplicate options */
25336371Ssklower 
25436371Ssklower 	IFDEBUG(D_OPTIONS)
25536371Ssklower 		printf("clnp_opt_sanity: checking %d bytes of data:\n", len);
25636371Ssklower 		dump_buf(opts, len);
25736371Ssklower 	ENDDEBUG
25836371Ssklower 
25936371Ssklower 	/* clear option index field if passed */
26036371Ssklower 	bzero((caddr_t)oidx, sizeof(struct clnp_optidx));
26136371Ssklower 
26236371Ssklower 	/*
26336371Ssklower 	 *	We need to indicate whether the ER option is present. This is done
26436371Ssklower 	 *	by overloading the er_reason field to also indicate presense of
26536371Ssklower 	 *	the option along with the option value. I would like ER_INVALREAS
26636371Ssklower 	 *	to have value 0, but alas, 0 is a valid er reason...
26736371Ssklower 	 */
26836371Ssklower 	oidx->cni_er_reason = ER_INVALREAS;
26936371Ssklower 
27036371Ssklower 	opts_end = opts + len;
27136371Ssklower 	while (opts < opts_end) {
27236371Ssklower 		/* must have at least 2 bytes per option (opcode and len) */
27336371Ssklower 		if (opts + 2 > opts_end)
27436371Ssklower 			return(GEN_INCOMPLETE);
27536371Ssklower 
27636371Ssklower 		opcode = *opts++;
27736371Ssklower 		oplen = *opts++;
27836371Ssklower 		IFDEBUG(D_OPTIONS)
27936371Ssklower 			printf("clnp_opt_sanity: opcode is %x and oplen %d\n",
28036371Ssklower 				opcode, oplen);
28136371Ssklower 			printf("clnp_opt_sanity: clnpoval_SRCRT is %x\n", CLNPOVAL_SRCRT);
28236371Ssklower 
28336371Ssklower 				switch (opcode) {
28436371Ssklower 					case CLNPOVAL_PAD: {
28536371Ssklower 						printf("CLNPOVAL_PAD\n");
28636371Ssklower 					} break;
28736371Ssklower 					case CLNPOVAL_SECURE: {
28836371Ssklower 						printf("CLNPOVAL_SECURE\n");
28936371Ssklower 					} break;
29036371Ssklower 					case CLNPOVAL_SRCRT: {
29136371Ssklower 							printf("CLNPOVAL_SRCRT\n");
29236371Ssklower 					} break;
29336371Ssklower 					case CLNPOVAL_RECRT: {
29436371Ssklower 						printf("CLNPOVAL_RECRT\n");
29536371Ssklower 					} break;
29636371Ssklower 					case CLNPOVAL_QOS: {
29736371Ssklower 						printf("CLNPOVAL_QOS\n");
29836371Ssklower 					} break;
29936371Ssklower 					case CLNPOVAL_PRIOR: {
30036371Ssklower 						printf("CLNPOVAL_PRIOR\n");
30136371Ssklower 					} break;
30236371Ssklower 					case CLNPOVAL_ERREAS: {
30336371Ssklower 						printf("CLNPOVAL_ERREAS\n");
30436371Ssklower 					} break;
30536371Ssklower 					default:
30636371Ssklower 						printf("UKNOWN option %x\n", opcode);
30736371Ssklower 				}
30836371Ssklower 		ENDDEBUG
30936371Ssklower 
31036371Ssklower 		/* don't allow crazy length values */
31136371Ssklower 		if (opts + oplen > opts_end)
31236371Ssklower 			return(GEN_INCOMPLETE);
31336371Ssklower 
31436371Ssklower 		switch (opcode) {
31539232Ssklower 			case CLNPOVAL_PAD:
31636371Ssklower 				/*
31736371Ssklower 				 *	Padding: increment pointer by length of padding
31836371Ssklower 				 */
31936371Ssklower 				if (pad++)						/* duplicate ? */
32036371Ssklower 					return(GEN_DUPOPT);
32136371Ssklower 				opts += oplen;
32239232Ssklower 				break;
32336371Ssklower 
32436371Ssklower 			case CLNPOVAL_SECURE: {
32536371Ssklower 				u_char	format = *opts;
32636371Ssklower 
32736371Ssklower 				if (secure++)					/* duplicate ? */
32836371Ssklower 					return(GEN_DUPOPT);
32936371Ssklower 				/*
33036371Ssklower 				 *	Security: high 2 bits of first octet indicate format
33136371Ssklower 				 *	(00 in high bits is reserved).
33236371Ssklower 				 *	Remaining bits must be 0. Remaining octets indicate
33336371Ssklower 				 *	actual security
33436371Ssklower 				 */
33536371Ssklower 				if (((format & 0x3f) > 0) ||	/* low 6 bits set ? */
33636371Ssklower 					((format & 0xc0) == 0))		/* high 2 bits zero ? */
33736371Ssklower 					return(GEN_HDRSYNTAX);
33836371Ssklower 
33936767Ssklower 				oidx->cni_securep = CLNP_OPTTOOFF(m, opts);
34036371Ssklower 				oidx->cni_secure_len = oplen;
34136371Ssklower 				opts += oplen;
34236371Ssklower 			} break;
34336371Ssklower 
34436371Ssklower 			case CLNPOVAL_SRCRT: {
34536371Ssklower 				u_char	type, offset;	/* type of rt, offset of start */
34636371Ssklower 				caddr_t	route_end;		/* address of end of route option */
34736371Ssklower 
34836371Ssklower 				IFDEBUG(D_OPTIONS)
34936371Ssklower 					printf("clnp_opt_sanity: SRC RT\n");
35036371Ssklower 				ENDDEBUG
35136371Ssklower 
35236371Ssklower 				if (srcrt++)					/* duplicate ? */
35336371Ssklower 					return(GEN_DUPOPT);
35436371Ssklower 				/*
35536371Ssklower 				 *	source route: There must be 2 bytes following the length
35636371Ssklower 				 *	field: type and offset. The type must be either
35736371Ssklower 				 *	partial route or complete route. The offset field must
35836371Ssklower 				 *	be within the option. A single exception is made, however.
35936371Ssklower 				 *	The offset may be 1 greater than the length. This case
36036371Ssklower 				 *	occurs when the last source route record is consumed.
36136371Ssklower 				 *	In this case, we ignore the source route option.
36236371Ssklower 				 *	RAH? You should be able to set offset to 'ff' like in record
36336371Ssklower 				 *	route!
36436371Ssklower 				 *	Following this is a series of address fields.
36536371Ssklower 				 *	Each address field is composed of a (length, address) pair.
36636371Ssklower 				 *	Insure that the offset and each address length is reasonable
36736371Ssklower 				 */
36836371Ssklower 				route_end = opts + oplen;
36936371Ssklower 
37036371Ssklower 				if (opts + 2 > route_end)
37136371Ssklower 					return(SRCRT_SYNTAX);
37236371Ssklower 
37336371Ssklower 				type = *opts;
37436371Ssklower 				offset = *(opts+1);
37536371Ssklower 
37636371Ssklower 
37736371Ssklower 				/* type must be partial or complete */
37836371Ssklower 				if (!((type == CLNPOVAL_PARTRT) || (type == CLNPOVAL_COMPRT)))
37936371Ssklower 					return(SRCRT_SYNTAX);
38036371Ssklower 
38136767Ssklower 				oidx->cni_srcrt_s = CLNP_OPTTOOFF(m, opts);
38236371Ssklower 				oidx->cni_srcrt_len = oplen;
38336371Ssklower 
38436371Ssklower 				opts += offset-1;	/*set opts to first addr in rt */
38536371Ssklower 
38636371Ssklower 				/*
38736371Ssklower 				 *	Offset must be reasonable:
38836371Ssklower 				 *	less than end of options, or equal to end of options
38936371Ssklower 				 */
39036371Ssklower 				if (opts >= route_end) {
39136371Ssklower 					if (opts == route_end) {
39236371Ssklower 						IFDEBUG(D_OPTIONS)
39336371Ssklower 							printf("clnp_opt_sanity: end of src route info\n");
39436371Ssklower 						ENDDEBUG
39536371Ssklower 						break;
39636371Ssklower 					} else
39736371Ssklower 						return(SRCRT_SYNTAX);
39836371Ssklower 				}
39936371Ssklower 
40036371Ssklower 				while (opts < route_end) {
40136371Ssklower 					u_char	addrlen = *opts++;
40236371Ssklower 					if (opts + addrlen > route_end)
40336371Ssklower 						return(SRCRT_SYNTAX);
40436371Ssklower 					opts += addrlen;
40536371Ssklower 				}
40636371Ssklower 			} break;
40736371Ssklower 			case CLNPOVAL_RECRT: {
40836371Ssklower 				u_char	type, offset;	/* type of rt, offset of start */
40936371Ssklower 				caddr_t	record_end;		/* address of end of record option */
41036371Ssklower 
41136371Ssklower 				if (recrt++)					/* duplicate ? */
41236371Ssklower 					return(GEN_DUPOPT);
41336371Ssklower 				/*
41436371Ssklower 				 *	record route: after the length field, expect a
41536371Ssklower 				 *	type and offset. Type must be partial or complete.
41636371Ssklower 				 *	Offset indicates where to start recording. Insure it
41736371Ssklower 				 *	is within the option. All ones for offset means
41836371Ssklower 				 *	recording is terminated.
41936371Ssklower 				 */
42036371Ssklower 				record_end = opts + oplen;
42136371Ssklower 
42236767Ssklower 				oidx->cni_recrtp = CLNP_OPTTOOFF(m, opts);
42336371Ssklower 				oidx->cni_recrt_len = oplen;
42436371Ssklower 
42536371Ssklower 				if (opts + 2 > record_end)
42636371Ssklower 					return(GEN_INCOMPLETE);
42736371Ssklower 
42836371Ssklower 				type = *opts;
42936371Ssklower 				offset = *(opts+1);
43036371Ssklower 
43136371Ssklower 				/* type must be partial or complete */
43236371Ssklower 				if (!((type == CLNPOVAL_PARTRT) || (type == CLNPOVAL_COMPRT)))
43336371Ssklower 					return(GEN_HDRSYNTAX);
43436371Ssklower 
43536371Ssklower 				/* offset must be reasonable */
43636371Ssklower 				if ((offset < 0xff) && (opts + offset > record_end))
43736371Ssklower 					return(GEN_HDRSYNTAX);
43836371Ssklower 				opts += oplen;
43936371Ssklower 			} break;
44036371Ssklower 			case CLNPOVAL_QOS: {
44136371Ssklower 				u_char	format = *opts;
44236371Ssklower 
44336371Ssklower 				if (qos++)					/* duplicate ? */
44436371Ssklower 					return(GEN_DUPOPT);
44536371Ssklower 				/*
44636371Ssklower 				 *	qos: high 2 bits of first octet indicate format
44736371Ssklower 				 *	(00 in high bits is reserved).
44836371Ssklower 				 *	Remaining bits must be 0 (unless format indicates
44936371Ssklower 				 *	globally unique qos, in which case remaining bits indicate
45036371Ssklower 				 *	qos (except bit 6 which is reserved)).  Otherwise,
45136371Ssklower 				 *	remaining octets indicate actual qos.
45236371Ssklower 				 */
45336371Ssklower 				if (((format & 0xc0) == 0) ||	/* high 2 bits zero ? */
45436371Ssklower 					(((format & 0xc0) != CLNPOVAL_GLOBAL) &&
45536371Ssklower 						((format & 0x3f) > 0))) /* not global,low bits used ? */
45636371Ssklower 					return(GEN_HDRSYNTAX);
45736371Ssklower 
45836767Ssklower 				oidx->cni_qos_formatp = CLNP_OPTTOOFF(m, opts);
45936371Ssklower 				oidx->cni_qos_len = oplen;
46036371Ssklower 
46136371Ssklower 				opts += oplen;
46236371Ssklower 			} break;
46336371Ssklower 
46436371Ssklower 			case CLNPOVAL_PRIOR: {
46536371Ssklower 				if (prior++)				/* duplicate ? */
46636371Ssklower 					return(GEN_DUPOPT);
46736371Ssklower 				/*
46836371Ssklower 				 *	priority: value must be one byte long
46936371Ssklower 				 */
47036371Ssklower 				if (oplen != 1)
47136371Ssklower 					return(GEN_HDRSYNTAX);
47236371Ssklower 
47336767Ssklower 				oidx->cni_priorp = CLNP_OPTTOOFF(m, opts);
47436371Ssklower 
47536371Ssklower 				opts += oplen;
47636371Ssklower 			} break;
47736371Ssklower 
47836371Ssklower 			case CLNPOVAL_ERREAS: {
47936371Ssklower 				/*
48036371Ssklower 				 *	er reason: value must be two bytes long
48136371Ssklower 				 */
48236371Ssklower 				if (oplen != 2)
48336371Ssklower 					return(GEN_HDRSYNTAX);
48436371Ssklower 
48536371Ssklower 				oidx->cni_er_reason = *opts;
48636371Ssklower 
48736371Ssklower 				opts += oplen;
48836371Ssklower 			} break;
48936371Ssklower 
49036371Ssklower 			default: {
49136371Ssklower 				IFDEBUG(D_OPTIONS)
49236371Ssklower 					printf("clnp_opt_sanity: UNKNOWN OPTION 0x%x\n", opcode);
49336371Ssklower 				ENDDEBUG
49436371Ssklower 				return(DISC_UNSUPPOPT);
49536371Ssklower 			}
49636371Ssklower 		}
49736371Ssklower 	}
49836371Ssklower 		IFDEBUG(D_OPTIONS)
49936371Ssklower 			printf("clnp_opt_sanity: return(0)\n", opcode);
50036371Ssklower 		ENDDEBUG
50136371Ssklower 	return(0);
50236371Ssklower }
50336371Ssklower #endif	ISO
504