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