]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/lib/addkeep.c
This commit was generated by cvs2svn to compensate for changes in r154439,
[FreeBSD/FreeBSD.git] / contrib / ipfilter / lib / addkeep.c
1 /*      $FreeBSD$       */
2
3 /*
4  * Copyright (C) 1993-2001 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * $Id: addkeep.c,v 1.12 2003/12/01 01:59:42 darrenr Exp $
9  */
10
11 #include "ipf.h"
12
13
14 /*
15  * Parses "keep state" and "keep frags" stuff on the end of a line.
16  */
17 int     addkeep(cp, fp, linenum)
18 char    ***cp;
19 struct  frentry *fp;
20 int     linenum;
21 {
22         char *s;
23
24         (*cp)++;
25         if (!**cp) {
26                 fprintf(stderr, "%d: Missing state/frag after keep\n",
27                         linenum);
28                 return -1;
29         }
30
31         if (!strcasecmp(**cp, "state")) {
32                 fp->fr_flags |= FR_KEEPSTATE;
33                 (*cp)++;
34                 if (**cp && !strcasecmp(**cp, "limit")) {
35                         (*cp)++;
36                         fp->fr_statemax = atoi(**cp);
37                         (*cp)++;
38                 }
39                 if (**cp && !strcasecmp(**cp, "scan")) {
40                         (*cp)++;
41                         if (!strcmp(**cp, "*")) {
42                                 fp->fr_isc = NULL;
43                                 fp->fr_isctag[0] = '\0';
44                         } else {
45                                 strncpy(fp->fr_isctag, **cp,
46                                         sizeof(fp->fr_isctag));
47                                 fp->fr_isctag[sizeof(fp->fr_isctag)-1] = '\0';
48                                 fp->fr_isc = NULL;
49                         }
50                         (*cp)++;
51                 } else
52                         fp->fr_isc = (struct ipscan *)-1;
53         } else if (!strncasecmp(**cp, "frag", 4)) {
54                 fp->fr_flags |= FR_KEEPFRAG;
55                 (*cp)++;
56         } else if (!strcasecmp(**cp, "state-age")) {
57                 if (fp->fr_ip.fi_p == IPPROTO_TCP) {
58                         fprintf(stderr, "%d: cannot use state-age with tcp\n",
59                                 linenum);
60                         return -1;
61                 }
62                 if ((fp->fr_flags & FR_KEEPSTATE) == 0) {
63                         fprintf(stderr, "%d: state-age with no 'keep state'\n",
64                                 linenum);
65                         return -1;
66                 }
67                 (*cp)++;
68                 if (!**cp) {
69                         fprintf(stderr, "%d: state-age with no arg\n",
70                                 linenum);
71                         return -1;
72                 }
73                 fp->fr_age[0] = atoi(**cp);
74                 s = strchr(**cp, '/');
75                 if (s != NULL) {
76                         s++;
77                         fp->fr_age[1] = atoi(s);
78                 } else
79                         fp->fr_age[1] = fp->fr_age[0];
80         } else {
81                 fprintf(stderr, "%d: Unrecognised state keyword \"%s\"\n",
82                         linenum, **cp);
83                 return -1;
84         }
85         return 0;
86 }