xref: /freebsd/sbin/ipf/libipf/optprint.c (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
141edb306SCy Schubert 
241edb306SCy Schubert /*
341edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert  *
541edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert  *
741edb306SCy Schubert  * $Id$
841edb306SCy Schubert  */
941edb306SCy Schubert #include "ipf.h"
1041edb306SCy Schubert 
1141edb306SCy Schubert 
12*efeb8bffSCy Schubert void
optprint(u_short * sec,u_long optmsk,u_long optbits)13*efeb8bffSCy Schubert optprint(u_short *sec, u_long optmsk, u_long optbits)
1441edb306SCy Schubert {
1541edb306SCy Schubert 	u_short secmsk = sec[0], secbits = sec[1];
1641edb306SCy Schubert 	struct ipopt_names *io, *so;
1741edb306SCy Schubert 	char *s;
1841edb306SCy Schubert 
1941edb306SCy Schubert 	s = " opt ";
2041edb306SCy Schubert 	for (io = ionames; io->on_name; io++)
2141edb306SCy Schubert 		if ((io->on_bit & optmsk) &&
2241edb306SCy Schubert 		    ((io->on_bit & optmsk) == (io->on_bit & optbits))) {
2341edb306SCy Schubert 			if ((io->on_value != IPOPT_SECURITY) ||
2441edb306SCy Schubert 			    (!secmsk && !secbits)) {
2541edb306SCy Schubert 				printf("%s%s", s, io->on_name);
2641edb306SCy Schubert 				/*
2741edb306SCy Schubert 				 * Because the ionames table has this entry
2841edb306SCy Schubert 				 * twice.
2941edb306SCy Schubert 				 */
3041edb306SCy Schubert 				if (io->on_value == IPOPT_SECURITY)
3141edb306SCy Schubert 					io++;
3241edb306SCy Schubert 				s = ",";
3341edb306SCy Schubert 			}
3441edb306SCy Schubert 		}
3541edb306SCy Schubert 
3641edb306SCy Schubert 
3741edb306SCy Schubert 	if (secmsk & secbits) {
3841edb306SCy Schubert 		printf("%ssec-class", s);
3941edb306SCy Schubert 		s = " ";
4041edb306SCy Schubert 		for (so = secclass; so->on_name; so++)
4141edb306SCy Schubert 			if ((secmsk & so->on_bit) &&
4241edb306SCy Schubert 			    ((so->on_bit & secmsk) == (so->on_bit & secbits))) {
4341edb306SCy Schubert 				printf("%s%s", s, so->on_name);
4441edb306SCy Schubert 				s = ",";
4541edb306SCy Schubert 			}
4641edb306SCy Schubert 	}
4741edb306SCy Schubert 
4841edb306SCy Schubert 	if ((optmsk && (optmsk != optbits)) ||
4941edb306SCy Schubert 	    (secmsk && (secmsk != secbits))) {
5041edb306SCy Schubert 		s = " ";
5141edb306SCy Schubert 		printf(" not opt");
5241edb306SCy Schubert 		if (optmsk != optbits) {
5341edb306SCy Schubert 			for (io = ionames; io->on_name; io++)
5441edb306SCy Schubert 				if ((io->on_bit & optmsk) &&
5541edb306SCy Schubert 				    ((io->on_bit & optmsk) !=
5641edb306SCy Schubert 				     (io->on_bit & optbits))) {
5741edb306SCy Schubert 					if ((io->on_value != IPOPT_SECURITY) ||
5841edb306SCy Schubert 					    (!secmsk && !secbits)) {
5941edb306SCy Schubert 						printf("%s%s", s, io->on_name);
6041edb306SCy Schubert 						s = ",";
6141edb306SCy Schubert 						if (io->on_value ==
6241edb306SCy Schubert 						    IPOPT_SECURITY)
6341edb306SCy Schubert 							io++;
6441edb306SCy Schubert 					} else
6541edb306SCy Schubert 						io++;
6641edb306SCy Schubert 				}
6741edb306SCy Schubert 		}
6841edb306SCy Schubert 
6941edb306SCy Schubert 		if (secmsk != secbits) {
7041edb306SCy Schubert 			printf("%ssec-class", s);
7141edb306SCy Schubert 			s = " ";
7241edb306SCy Schubert 			for (so = secclass; so->on_name; so++)
7341edb306SCy Schubert 				if ((so->on_bit & secmsk) &&
7441edb306SCy Schubert 				    ((so->on_bit & secmsk) !=
7541edb306SCy Schubert 				     (so->on_bit & secbits))) {
7641edb306SCy Schubert 					printf("%s%s", s, so->on_name);
7741edb306SCy Schubert 					s = ",";
7841edb306SCy Schubert 				}
7941edb306SCy Schubert 		}
8041edb306SCy Schubert 	}
8141edb306SCy Schubert }
82