Commit 7fac6521 authored by Leonidas Poulopoulos's avatar Leonidas Poulopoulos

Added protocol to match conditions

parent 441a2d31
......@@ -74,6 +74,7 @@ class UserProfileAdmin(UserAdmin):
admin.site.unregister(User)
admin.site.register(MatchPort)
admin.site.register(MatchProtocol)
admin.site.register(MatchDscp)
admin.site.register(ThenAction)
admin.site.register(Route, RouteAdmin)
......
......@@ -30,5 +30,27 @@
"action": "rate-limit",
"action_value": "100k"
}
},
{
"pk": 1,
"model": "flowspec.matchprotocol",
"fields": {
"protocol": "icmp"
}
},
{
"pk": 2,
"model": "flowspec.matchprotocol",
"fields": {
"protocol": "tcp"
}
},
{
"pk": 3,
"model": "flowspec.matchprotocol",
"fields": {
"protocol": "udp"
}
}
]
\ No newline at end of file
......@@ -8,12 +8,12 @@ from utils import proxy as PR
from ipaddr import *
import datetime
import logging
from flowspec.tasks import *
from time import sleep
import beanstalkc
from flowspy.utils.randomizer import id_generator as id_gen
from flowspec.tasks import *
FORMAT = '%(asctime)s %(levelname)s: %(message)s'
logging.basicConfig(format=FORMAT)
......@@ -39,6 +39,23 @@ THEN_CHOICES = (
("sample", "Sample")
)
MATCH_PROTOCOL = (
("ah", "ah"),
("egp", "egp"),
("esp", "esp"),
("gre", "gre"),
("icmp", "icmp"),
("icmp6", "icmp6"),
("igmp", "igmp"),
("ipip", "ipip"),
("ospf", "ospf"),
("pim", "pim"),
("rsvp", "rsvp"),
("sctp", "sctp"),
("tcp", "tcp"),
("udp", "udp"),
)
ROUTE_STATES = (
("ACTIVE", "ACTIVE"),
("ERROR", "ERROR"),
......@@ -66,6 +83,13 @@ class MatchDscp(models.Model):
class Meta:
db_table = u'match_dscp'
class MatchProtocol(models.Model):
protocol = models.CharField(max_length=24, unique=True)
def __unicode__(self):
return self.protocol
class Meta:
db_table = u'match_protocol'
class ThenAction(models.Model):
action = models.CharField(max_length=60, choices=THEN_CHOICES, verbose_name="Action")
......@@ -91,7 +115,7 @@ class Route(models.Model):
icmpcode = models.CharField(max_length=32, blank=True, null=True, verbose_name="ICMP Code")
icmptype = models.CharField(max_length=32, blank=True, null=True, verbose_name="ICMP Type")
packetlength = models.IntegerField(blank=True, null=True, verbose_name="Packet Length")
protocol = models.CharField(max_length=32, blank=True, null=True, verbose_name="Protocol")
protocol = models.ManyToManyField(MatchProtocol, blank=True, null=True, verbose_name="Protocol")
tcpflag = models.CharField(max_length=128, blank=True, null=True, verbose_name="TCP flag")
then = models.ManyToManyField(ThenAction, verbose_name="Then")
filed = models.DateTimeField(auto_now_add=True)
......@@ -284,8 +308,6 @@ class Route(models.Model):
ret = "%s ICMP Type:<strong>%s</strong><br/>" %(ret, self.icmptype)
if self.packetlength:
ret = "%s Packet Length:<strong>%s</strong><br/>" %(ret, self.packetlength)
if self.protocol:
ret = "%s Protocol:<strong>%s</strong><br/>" %(ret, self.protocol)
if self.source:
ret = "%s Src Addr:<strong>%s</strong> <br/>" %(ret, self.source)
if self.tcpflag:
......@@ -293,6 +315,9 @@ class Route(models.Model):
if self.port:
for port in self.port.all():
ret = ret + "Port:<strong>%s</strong> <br/>" %(port)
if self.protocol:
for protocol in self.protocol.all():
ret = ret + "Protocol:<strong>%s</strong> <br/>" %(protocol)
if self.destinationport:
for port in self.destinationport.all():
ret = ret + "Dst Port:<strong>%s</strong> <br/>" %(port)
......
......@@ -284,6 +284,14 @@ div.roundbox, #portsacc, #id_comments{
<p style="clear:both;">
{{ form.destination.help_text }}
</p>
</div>
<div class="roundbox">
{{ form.protocol.label_tag }}{{ form.protocol }}{% if form.protocol.errors %}
<br>
<p class="error" style="clear:both;">
{{ form.protocol.errors|join:", " }}
</p>
{% endif %}
</div>
<div id='portsacc'>
<h3 style="padding: 0.5em 0.5em 0.5em 0.7em;">Advanced Settings (Ports)</h3>
......
......@@ -92,8 +92,12 @@ class Applier(object):
route.match['source'].append(route_obj.source)
if route_obj.destination:
route.match['destination'].append(route_obj.destination)
if route_obj.protocol:
route.match['protocol'].append(route_obj.protocol)
try:
if route_obj.protocol:
for protocol in route_obj.protocol.all():
route.match['protocol'].append(protocol.protocol)
except:
pass
try:
if route_obj.port:
for port in route_obj.port.all():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment