Revision 7a8a4da4
b/flowspec/models.py | ||
---|---|---|
63 | 63 |
class Meta: |
64 | 64 |
db_table = u'match_dscp' |
65 | 65 |
|
66 |
class MatchFragmentType(models.Model): |
|
67 |
fragmenttype = models.CharField(max_length=20, choices=FRAGMENT_CODES) |
|
68 |
def __unicode__(self): |
|
69 |
return self.fragmenttype |
|
70 |
class Meta: |
|
71 |
db_table = u'match_fragment_type' |
|
72 |
|
|
73 |
class MatchIcmpCode(models.Model): |
|
74 |
icmp_code = models.CharField(max_length=64) |
|
75 |
def __unicode__(self): |
|
76 |
return self.icmp_code |
|
77 |
class Meta: |
|
78 |
db_table = u'match_icmp_code' |
|
79 |
|
|
80 |
class MatchIcmpType(models.Model): |
|
81 |
icmp_type = models.CharField(max_length=64) |
|
82 |
class Meta: |
|
83 |
db_table = u'match_icmp_type' |
|
84 |
|
|
85 |
class MatchPacketLength(models.Model): |
|
86 |
packet_length = models.IntegerField() |
|
87 |
class Meta: |
|
88 |
db_table = u'match_packet_length' |
|
89 |
|
|
90 |
class MatchProtocol(models.Model): |
|
91 |
protocol = models.CharField(max_length=64) |
|
92 |
def __unicode__(self): |
|
93 |
return self.protocol |
|
94 |
class Meta: |
|
95 |
db_table = u'match_protocol' |
|
96 |
|
|
97 |
class MatchTcpFlag(models.Model): |
|
98 |
tcp_flag = models.CharField(max_length=255) |
|
99 |
def __unicode__(self): |
|
100 |
return self.tcp_flag |
|
101 |
class Meta: |
|
102 |
db_table = u'match_tcp_flag' |
|
103 |
|
|
66 |
|
|
104 | 67 |
class ThenAction(models.Model): |
105 | 68 |
action = models.CharField(max_length=60, choices=THEN_CHOICES) |
106 | 69 |
action_value = models.CharField(max_length=255, blank=True, null=True) |
... | ... | |
109 | 72 |
class Meta: |
110 | 73 |
db_table = u'then_action' |
111 | 74 |
|
112 |
class ThenStatement(models.Model): |
|
113 |
thenaction = models.ManyToManyField(ThenAction) |
|
114 |
class Meta: |
|
115 |
db_table = u'then' |
|
116 |
|
|
117 |
class MatchStatement(models.Model): |
|
118 |
matchDestination = models.ForeignKey(MatchAddress, blank=True, null=True, related_name="matchDestination") |
|
119 |
matchDestinationPort = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchDestinationPort") |
|
120 |
matchdscp = models.ManyToManyField(MatchDscp, blank=True, null=True) |
|
121 |
matchfragmenttype = models.ForeignKey(MatchFragmentType, blank=True, null=True) |
|
122 |
matchicmpcode = models.ForeignKey(MatchIcmpCode, blank=True, null=True) |
|
123 |
matchicmptype = models.ForeignKey(MatchIcmpType, blank=True, null=True) |
|
124 |
matchpacketlength = models.ForeignKey(MatchPacketLength, blank=True, null=True) |
|
125 |
matchport = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchPort") |
|
126 |
matchprotocol = models.ForeignKey(MatchProtocol, blank=True, null=True) |
|
127 |
matchSource = models.ForeignKey(MatchAddress, blank=True, null=True, related_name="matchSource") |
|
128 |
matchSourcePort = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchSourcePort") |
|
129 |
matchTcpFlag = models.ForeignKey(MatchTcpFlag, blank=True, null=True) |
|
130 |
|
|
131 |
# def clean(self, *args, **kwargs): |
|
132 |
# clean_error = True |
|
133 |
# from django.core.exceptions import ValidationError |
|
134 |
# if not (self.matchDestination or self.matchfragmenttype or self.matchicmpcode or self.matchicmptype |
|
135 |
# or self.matchpacketlength or self.matchprotocol or self.matchSource or self.matchTcpFlag): |
|
136 |
# clean_error = False |
|
137 |
# try: |
|
138 |
# assert(self.matchDestinationPort) |
|
139 |
# clean_error = False |
|
140 |
# except: |
|
141 |
# pass |
|
142 |
# try: |
|
143 |
# assert(self.matchSourcePort) |
|
144 |
# clean_error = False |
|
145 |
# except: |
|
146 |
# pass |
|
147 |
# try: |
|
148 |
# assert(self.matchport) |
|
149 |
# clean_error = False |
|
150 |
# except: |
|
151 |
# pass |
|
152 |
# try: |
|
153 |
# print self.matchdscp |
|
154 |
# assert(self.matchdscp) |
|
155 |
# clean_error = False |
|
156 |
# except: |
|
157 |
# pass |
|
158 |
# if clean_error: |
|
159 |
# raise ValidationError('At least one match statement has to be declared') |
|
160 |
|
|
161 |
class Meta: |
|
162 |
db_table = u'match' |
|
163 |
|
|
164 | 75 |
class Route(models.Model): |
165 | 76 |
name = models.CharField(max_length=128) |
166 | 77 |
applier = models.ForeignKey(User) |
167 |
match = models.ForeignKey(MatchStatement) |
|
168 |
then = models.ForeignKey(ThenStatement) |
|
78 |
destination = models.CharField(max_length=32, blank=True, null=True, help_text=u"Network address. Use address/CIDR notation") |
|
79 |
destinationport = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchDestinationPort") |
|
80 |
dscp = models.ManyToManyField(MatchDscp, blank=True, null=True) |
|
81 |
fragmenttype = models.CharField(max_length=20, choices=FRAGMENT_CODES, blank=True, null=True) |
|
82 |
icmpcode = models.CharField(max_length=32, blank=True, null=True) |
|
83 |
icmptype = models.CharField(max_length=32, blank=True, null=True) |
|
84 |
packetlength = models.IntegerField(blank=True, null=True) |
|
85 |
port = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchPort") |
|
86 |
protocol = models.CharField(max_length=32, blank=True, null=True) |
|
87 |
source = models.CharField(max_length=32, blank=True, null=True, help_text=u"Network address. Use address/CIDR notation") |
|
88 |
sourceport = models.ManyToManyField(MatchPort, blank=True, null=True, related_name="matchSourcePort") |
|
89 |
tcpflag = models.CharField(max_length=128, blank=True, null=True) |
|
90 |
then = models.ManyToManyField(ThenAction) |
|
169 | 91 |
filed = models.DateTimeField(auto_now_add=True) |
170 | 92 |
last_updated = models.DateTimeField(auto_now=True) |
171 | 93 |
is_online = models.BooleanField(default=False) |
94 |
is_active = models.BooleanField(default=False) |
|
172 | 95 |
expires = models.DateTimeField() |
173 | 96 |
response = models.CharField(max_length=512, blank=True, null=True) |
97 |
comments = models.TextField(null=True, blank=True) |
|
174 | 98 |
|
175 | 99 |
|
176 | 100 |
def __unicode__(self): |
... | ... | |
178 | 102 |
|
179 | 103 |
class Meta: |
180 | 104 |
db_table = u'route' |
181 |
|
|
105 |
|
|
106 |
def clean(self, *args, **kwargs): |
|
107 |
from django.core.exceptions import ValidationError |
|
108 |
if self.destination: |
|
109 |
try: |
|
110 |
address = IPNetwork(self.address) |
|
111 |
self.address = address.exploded |
|
112 |
except Exception: |
|
113 |
raise ValidationError('Invalid network address format') |
|
114 |
if self.source: |
|
115 |
try: |
|
116 |
address = IPNetwork(self.address) |
|
117 |
self.address = address.exploded |
|
118 |
except Exception: |
|
119 |
raise ValidationError('Invalid network address format') |
|
120 |
|
|
182 | 121 |
def save(self, *args, **kwargs): |
183 | 122 |
applier = PR.Applier(route_object=self) |
184 | 123 |
commit, response = applier.apply() |
Also available in: Unified diff