]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/ipfilter/lib/optname.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / ipfilter / lib / optname.c
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 u_32_t optname(cp, sp, linenum)
15         char ***cp;
16         u_short *sp;
17         int linenum;
18 {
19         struct ipopt_names *io, *so;
20         u_long msk = 0;
21         u_short smsk = 0;
22         char *s;
23         int sec = 0;
24
25         for (s = strtok(**cp, ","); s; s = strtok(NULL, ",")) {
26                 for (io = ionames; io->on_name; io++)
27                         if (!strcasecmp(s, io->on_name)) {
28                                 msk |= io->on_bit;
29                                 break;
30                         }
31                 if (!io->on_name) {
32                         fprintf(stderr, "%d: unknown IP option name %s\n",
33                                 linenum, s);
34                         return 0;
35                 }
36                 if (!strcasecmp(s, "sec-class"))
37                         sec = 1;
38         }
39
40         if (sec && !*(*cp + 1)) {
41                 fprintf(stderr, "%d: missing security level after sec-class\n",
42                         linenum);
43                 return 0;
44         }
45
46         if (sec) {
47                 (*cp)++;
48                 for (s = strtok(**cp, ","); s; s = strtok(NULL, ",")) {
49                         for (so = secclass; so->on_name; so++)
50                                 if (!strcasecmp(s, so->on_name)) {
51                                         smsk |= so->on_bit;
52                                         break;
53                                 }
54                         if (!so->on_name) {
55                                 fprintf(stderr,
56                                         "%d: no such security level: %s\n",
57                                         linenum, s);
58                                 return 0;
59                         }
60                 }
61                 if (smsk)
62                         *sp = smsk;
63         }
64         return msk;
65 }