Revision 7fac6521

b/flowspec/admin.py
74 74

  
75 75
admin.site.unregister(User)
76 76
admin.site.register(MatchPort)
77
admin.site.register(MatchProtocol)
77 78
admin.site.register(MatchDscp)
78 79
admin.site.register(ThenAction)
79 80
admin.site.register(Route, RouteAdmin)
b/flowspec/fixtures/initial_data.json
30 30
            "action": "rate-limit", 
31 31
            "action_value": "100k"
32 32
        }
33
    },
34
    {
35
        "pk": 1,
36
        "model": "flowspec.matchprotocol",
37
        "fields": {
38
            "protocol": "icmp"
39
        }
40
    },
41
    {
42
        "pk": 2,
43
        "model": "flowspec.matchprotocol",
44
        "fields": {
45
            "protocol": "tcp"
46
        }
47
    },
48
    {
49
        "pk": 3,
50
        "model": "flowspec.matchprotocol",
51
        "fields": {
52
            "protocol": "udp"
53
        }
33 54
    }
55

  
34 56
]
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)
b/templates/apply.html
285 285
                        {{ form.destination.help_text }}
286 286
                    </p>
287 287
                </div>
288
				<div class="roundbox">
289
                    {{ form.protocol.label_tag }}{{ form.protocol }}{% if form.protocol.errors %}
290
                    <br>
291
                    <p class="error" style="clear:both;">
292
                        {{ form.protocol.errors|join:", " }}
293
                    </p>
294
                    {% endif %}
295
                </div>
288 296
                <div id='portsacc'>
289 297
                <h3 style="padding: 0.5em 0.5em 0.5em 0.7em;">Advanced Settings (Ports)</h3>
290 298
                <div class='accord_wrapper' style="height: 452px !important;">
b/utils/proxy.py
92 92
                route.match['source'].append(route_obj.source)
93 93
            if route_obj.destination:
94 94
                route.match['destination'].append(route_obj.destination)
95
            if route_obj.protocol:
96
                route.match['protocol'].append(route_obj.protocol)
95
            try:
96
                if route_obj.protocol:
97
                    for protocol in route_obj.protocol.all():
98
                        route.match['protocol'].append(protocol.protocol)
99
            except:
100
                pass
97 101
            try:
98 102
                if route_obj.port:
99 103
                    for port in route_obj.port.all():

Also available in: Unified diff