xref: /freebsd/sbin/ipf/libipf/optprint.c (revision d27ba3088424e53eabc0b0186ed122ec43119501)
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 #include "ipf.h"
11 
12 
13 void optprint(sec, optmsk, optbits)
14 	u_short *sec;
15 	u_long optmsk, optbits;
16 {
17 	u_short secmsk = sec[0], secbits = sec[1];
18 	struct ipopt_names *io, *so;
19 	char *s;
20 
21 	s = " opt ";
22 	for (io = ionames; io->on_name; io++)
23 		if ((io->on_bit & optmsk) &&
24 		    ((io->on_bit & optmsk) == (io->on_bit & optbits))) {
25 			if ((io->on_value != IPOPT_SECURITY) ||
26 			    (!secmsk && !secbits)) {
27 				printf("%s%s", s, io->on_name);
28 				/*
29 				 * Because the ionames table has this entry
30 				 * twice.
31 				 */
32 				if (io->on_value == IPOPT_SECURITY)
33 					io++;
34 				s = ",";
35 			}
36 		}
37 
38 
39 	if (secmsk & secbits) {
40 		printf("%ssec-class", s);
41 		s = " ";
42 		for (so = secclass; so->on_name; so++)
43 			if ((secmsk & so->on_bit) &&
44 			    ((so->on_bit & secmsk) == (so->on_bit & secbits))) {
45 				printf("%s%s", s, so->on_name);
46 				s = ",";
47 			}
48 	}
49 
50 	if ((optmsk && (optmsk != optbits)) ||
51 	    (secmsk && (secmsk != secbits))) {
52 		s = " ";
53 		printf(" not opt");
54 		if (optmsk != optbits) {
55 			for (io = ionames; io->on_name; io++)
56 				if ((io->on_bit & optmsk) &&
57 				    ((io->on_bit & optmsk) !=
58 				     (io->on_bit & optbits))) {
59 					if ((io->on_value != IPOPT_SECURITY) ||
60 					    (!secmsk && !secbits)) {
61 						printf("%s%s", s, io->on_name);
62 						s = ",";
63 						if (io->on_value ==
64 						    IPOPT_SECURITY)
65 							io++;
66 					} else
67 						io++;
68 				}
69 		}
70 
71 		if (secmsk != secbits) {
72 			printf("%ssec-class", s);
73 			s = " ";
74 			for (so = secclass; so->on_name; so++)
75 				if ((so->on_bit & secmsk) &&
76 				    ((so->on_bit & secmsk) !=
77 				     (so->on_bit & secbits))) {
78 					printf("%s%s", s, so->on_name);
79 					s = ",";
80 				}
81 		}
82 	}
83 }
84