141edb306SCy Schubert /* $FreeBSD$ */ 241edb306SCy Schubert 341edb306SCy Schubert /* 441edb306SCy Schubert * Copyright (C) 2012 by Darren Reed. 541edb306SCy Schubert * 641edb306SCy Schubert * See the IPFILTER.LICENCE file for details on licencing. 741edb306SCy Schubert * 841edb306SCy Schubert * $Id$ 941edb306SCy Schubert */ 1041edb306SCy Schubert 1141edb306SCy Schubert #include "ipf.h" 1241edb306SCy Schubert 1341edb306SCy Schubert 14*efeb8bffSCy Schubert u_32_t 15*efeb8bffSCy Schubert optname(char ***cp, u_short *sp, int linenum) 1641edb306SCy Schubert { 1741edb306SCy Schubert struct ipopt_names *io, *so; 1841edb306SCy Schubert u_long msk = 0; 1941edb306SCy Schubert u_short smsk = 0; 2041edb306SCy Schubert char *s; 2141edb306SCy Schubert int sec = 0; 2241edb306SCy Schubert 2341edb306SCy Schubert for (s = strtok(**cp, ","); s; s = strtok(NULL, ",")) { 2441edb306SCy Schubert for (io = ionames; io->on_name; io++) 2541edb306SCy Schubert if (!strcasecmp(s, io->on_name)) { 2641edb306SCy Schubert msk |= io->on_bit; 2741edb306SCy Schubert break; 2841edb306SCy Schubert } 2941edb306SCy Schubert if (!io->on_name) { 3041edb306SCy Schubert fprintf(stderr, "%d: unknown IP option name %s\n", 3141edb306SCy Schubert linenum, s); 3241edb306SCy Schubert return 0; 3341edb306SCy Schubert } 3441edb306SCy Schubert if (!strcasecmp(s, "sec-class")) 3541edb306SCy Schubert sec = 1; 3641edb306SCy Schubert } 3741edb306SCy Schubert 3841edb306SCy Schubert if (sec && !*(*cp + 1)) { 3941edb306SCy Schubert fprintf(stderr, "%d: missing security level after sec-class\n", 4041edb306SCy Schubert linenum); 4141edb306SCy Schubert return 0; 4241edb306SCy Schubert } 4341edb306SCy Schubert 4441edb306SCy Schubert if (sec) { 4541edb306SCy Schubert (*cp)++; 4641edb306SCy Schubert for (s = strtok(**cp, ","); s; s = strtok(NULL, ",")) { 4741edb306SCy Schubert for (so = secclass; so->on_name; so++) 4841edb306SCy Schubert if (!strcasecmp(s, so->on_name)) { 4941edb306SCy Schubert smsk |= so->on_bit; 5041edb306SCy Schubert break; 5141edb306SCy Schubert } 5241edb306SCy Schubert if (!so->on_name) { 5341edb306SCy Schubert fprintf(stderr, 5441edb306SCy Schubert "%d: no such security level: %s\n", 5541edb306SCy Schubert linenum, s); 5641edb306SCy Schubert return 0; 5741edb306SCy Schubert } 5841edb306SCy Schubert } 5941edb306SCy Schubert if (smsk) 6041edb306SCy Schubert *sp = smsk; 6141edb306SCy Schubert } 6241edb306SCy Schubert return msk; 6341edb306SCy Schubert } 64