xref: /netbsd-src/external/bsd/ipf/dist/lib/ipoptsec.c (revision 13885a665959c62f13a82b3caedf986eaa17aa31)
1*13885a66Sdarrenr /*	$NetBSD: ipoptsec.c,v 1.2 2012/07/22 14:27:36 darrenr Exp $	*/
2bc4097aaSchristos 
3bc4097aaSchristos /*
4c9d5dc6cSdarrenr  * Copyright (C) 2012 by Darren Reed.
5bc4097aaSchristos  *
6bc4097aaSchristos  * See the IPFILTER.LICENCE file for details on licencing.
7bc4097aaSchristos  *
8*13885a66Sdarrenr  * Id: ipoptsec.c,v 1.1.1.2 2012/07/22 13:44:39 darrenr Exp $
9bc4097aaSchristos  */
10bc4097aaSchristos 
11bc4097aaSchristos #include "ipf.h"
12bc4097aaSchristos 
13bc4097aaSchristos 
14bc4097aaSchristos struct	ipopt_names	secclass[] = {
15bc4097aaSchristos 	{ IPSO_CLASS_RES4,	0x01,	0, "reserv-4" },
16bc4097aaSchristos 	{ IPSO_CLASS_TOPS,	0x02,	0, "topsecret" },
17bc4097aaSchristos 	{ IPSO_CLASS_SECR,	0x04,	0, "secret" },
18bc4097aaSchristos 	{ IPSO_CLASS_RES3,	0x08,	0, "reserv-3" },
19bc4097aaSchristos 	{ IPSO_CLASS_CONF,	0x10,	0, "confid" },
20bc4097aaSchristos 	{ IPSO_CLASS_UNCL,	0x20,	0, "unclass" },
21bc4097aaSchristos 	{ IPSO_CLASS_RES2,	0x40,	0, "reserv-2" },
22bc4097aaSchristos 	{ IPSO_CLASS_RES1,	0x80,	0, "reserv-1" },
23bc4097aaSchristos 	{ 0, 0, 0, NULL }	/* must be last */
24bc4097aaSchristos };
25bc4097aaSchristos 
26bc4097aaSchristos 
seclevel(slevel)27bc4097aaSchristos u_char seclevel(slevel)
28bc4097aaSchristos 	char *slevel;
29bc4097aaSchristos {
30bc4097aaSchristos 	struct ipopt_names *so;
31bc4097aaSchristos 
32bc4097aaSchristos 	if (slevel == NULL || *slevel == '\0')
33bc4097aaSchristos 		return 0;
34bc4097aaSchristos 
35bc4097aaSchristos 	for (so = secclass; so->on_name; so++)
36bc4097aaSchristos 		if (!strcasecmp(slevel, so->on_name))
37bc4097aaSchristos 			break;
38bc4097aaSchristos 
39bc4097aaSchristos 	if (!so->on_name) {
40bc4097aaSchristos 		fprintf(stderr, "no such security level: '%s'\n", slevel);
41bc4097aaSchristos 		return 0;
42bc4097aaSchristos 	}
43bc4097aaSchristos 	return (u_char)so->on_value;
44bc4097aaSchristos }
45bc4097aaSchristos 
46bc4097aaSchristos 
secbit(class)47bc4097aaSchristos u_char secbit(class)
48bc4097aaSchristos 	int class;
49bc4097aaSchristos {
50bc4097aaSchristos 	struct ipopt_names *so;
51bc4097aaSchristos 
52bc4097aaSchristos 	for (so = secclass; so->on_name; so++)
53bc4097aaSchristos 		if (so->on_value == class)
54bc4097aaSchristos 			break;
55bc4097aaSchristos 
56bc4097aaSchristos 	if (!so->on_name) {
57bc4097aaSchristos 		fprintf(stderr, "no such security class: %d.\n", class);
58bc4097aaSchristos 		return 0;
59bc4097aaSchristos 	}
60bc4097aaSchristos 	return (u_char)so->on_bit;
61bc4097aaSchristos }
62