summaryrefslogtreecommitdiffstats
path: root/framework/src/suricata/qa/coccinelle/struct-flags.py
diff options
context:
space:
mode:
authorAshlee Young <ashlee@onosfw.com>2015-09-09 22:21:41 -0700
committerAshlee Young <ashlee@onosfw.com>2015-09-09 22:21:41 -0700
commit8879b125d26e8db1a5633de5a9c692eb2d1c4f83 (patch)
treec7259d85a991b83dfa85ab2e339360669fc1f58e /framework/src/suricata/qa/coccinelle/struct-flags.py
parent13d05bc8458758ee39cb829098241e89616717ee (diff)
suricata checkin based on commit id a4bce14770beee46a537eda3c3f6e8e8565d5d0a
Change-Id: I9a214fa0ee95e58fc640e50bd604dac7f42db48f
Diffstat (limited to 'framework/src/suricata/qa/coccinelle/struct-flags.py')
-rwxr-xr-xframework/src/suricata/qa/coccinelle/struct-flags.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/framework/src/suricata/qa/coccinelle/struct-flags.py b/framework/src/suricata/qa/coccinelle/struct-flags.py
new file mode 100755
index 00000000..3a91157b
--- /dev/null
+++ b/framework/src/suricata/qa/coccinelle/struct-flags.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+import re
+from os import listdir
+
+SRC_DIR="../../src/"
+
+class Structure:
+ def __init__(self, string):
+ (self.struct, self.flags, self.values) = string.split(":")
+
+cmd = "grep -h coccinelle ../../src/*[ch] | sed -e 's/.*coccinelle: \(.*\) \*\//\1/'"
+
+struct_list = []
+
+dirList = listdir(SRC_DIR)
+for fname in dirList:
+ if re.search("\.[ch]$", fname):
+ for line in open(SRC_DIR + fname):
+ if "coccinelle:" in line:
+ m = re.search("coccinelle: (.*) \*\/", line)
+ struct = Structure(m.group(1))
+ struct_list.append(struct)
+
+header = "@flags@"
+body = []
+
+i = 0
+for struct in struct_list:
+ header += """
+%s *struct%d;
+identifier struct_flags%d =~ "^(?!%s).+";""" % ( struct.struct, i, i, struct.values)
+
+ body.append("""
+struct%d->%s@p1 |= struct_flags%d
+|
+struct%d->%s@p1 & struct_flags%d
+|
+struct%d->%s@p1 &= ~struct_flags%d
+""" % (i, struct.flags, i, i, struct.flags, i, i, struct.flags, i))
+
+ i+=1
+
+print header
+print "position p1;"
+print "@@"
+print ""
+print "(" + "|".join(body) + ")"
+print ""
+print """@script:python@
+p1 << flags.p1;
+@@
+
+print "Invalid usage of flags field at %s:%s, flags value is incorrect (wrong family)." % (p1[0].file, p1[0].line)
+import sys
+sys.exit(1)"""