Revision 7fac6521 flowspec/models.py

b/flowspec/models.py
8 8
from ipaddr import *
9 9
import datetime
10 10
import logging
11
from flowspec.tasks import *
12 11
from time import sleep
13 12

  
14 13
import beanstalkc
15 14
from flowspy.utils.randomizer import id_generator as id_gen
16 15

  
16
from flowspec.tasks import *
17 17

  
18 18
FORMAT = '%(asctime)s %(levelname)s: %(message)s'
19 19
logging.basicConfig(format=FORMAT)
......
39 39
    ("sample", "Sample")                
40 40
)
41 41

  
42
MATCH_PROTOCOL = (
43
    ("ah", "ah"),
44
    ("egp", "egp"),
45
    ("esp", "esp"),
46
    ("gre", "gre"),
47
    ("icmp", "icmp"),
48
    ("icmp6", "icmp6"),
49
    ("igmp", "igmp"),
50
    ("ipip", "ipip"),
51
    ("ospf", "ospf"),
52
    ("pim", "pim"),
53
    ("rsvp", "rsvp"),
54
    ("sctp", "sctp"),
55
    ("tcp", "tcp"),
56
    ("udp", "udp"),
57
)
58

  
42 59
ROUTE_STATES = (
43 60
    ("ACTIVE", "ACTIVE"),
44 61
    ("ERROR", "ERROR"),
......
66 83
    class Meta:
67 84
        db_table = u'match_dscp'
68 85

  
86
class MatchProtocol(models.Model):
87
    protocol = models.CharField(max_length=24, unique=True)
88
    def __unicode__(self):
89
        return self.protocol
90
    class Meta:
91
        db_table = u'match_protocol'
92

  
69 93
   
70 94
class ThenAction(models.Model):
71 95
    action = models.CharField(max_length=60, choices=THEN_CHOICES, verbose_name="Action")
......
91 115
    icmpcode = models.CharField(max_length=32, blank=True, null=True, verbose_name="ICMP Code")
92 116
    icmptype = models.CharField(max_length=32, blank=True, null=True, verbose_name="ICMP Type")
93 117
    packetlength = models.IntegerField(blank=True, null=True, verbose_name="Packet Length")
94
    protocol = models.CharField(max_length=32, blank=True, null=True, verbose_name="Protocol")
118
    protocol = models.ManyToManyField(MatchProtocol, blank=True, null=True, verbose_name="Protocol")
95 119
    tcpflag = models.CharField(max_length=128, blank=True, null=True, verbose_name="TCP flag")
96 120
    then = models.ManyToManyField(ThenAction, verbose_name="Then")
97 121
    filed = models.DateTimeField(auto_now_add=True)
......
284 308
            ret = "%s ICMP Type:<strong>%s</strong><br/>" %(ret, self.icmptype)
285 309
        if self.packetlength:
286 310
            ret = "%s Packet Length:<strong>%s</strong><br/>" %(ret, self.packetlength)
287
        if self.protocol:
288
            ret = "%s Protocol:<strong>%s</strong><br/>" %(ret, self.protocol)
289 311
        if self.source:
290 312
            ret = "%s Src Addr:<strong>%s</strong> <br/>" %(ret, self.source)
291 313
        if self.tcpflag:
......
293 315
        if self.port:
294 316
            for port in self.port.all():
295 317
                    ret = ret + "Port:<strong>%s</strong> <br/>" %(port)
318
        if self.protocol:
319
            for protocol in self.protocol.all():
320
                    ret = ret + "Protocol:<strong>%s</strong> <br/>" %(protocol)
296 321
        if self.destinationport:
297 322
            for port in self.destinationport.all():
298 323
                    ret = ret + "Dst Port:<strong>%s</strong> <br/>" %(port)

Also available in: Unified diff