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